@@ -467,6 +467,7 @@ export class Yasqe extends CodeMirror {
467467 urlBtn . className = "yasqe_btn yasqe_btn-sm yasqe_shareBtn" ;
468468 buttonContainer . appendChild ( urlBtn ) ;
469469 urlBtn . onclick = async ( ) => {
470+ if ( ! this . config . createShareableLink ) return ;
470471 const url = this . config . createShareableLink ( this ) ;
471472 await copyToClipboard ( url , "URL" ) ;
472473 } ;
@@ -482,6 +483,7 @@ export class Yasqe extends CodeMirror {
482483 shortenBtn . disabled = true ;
483484 shortenBtn . innerText = "Shortening..." ;
484485 try {
486+ if ( ! this . config . createShareableLink ) return ;
485487 const longUrl = this . config . createShareableLink ( this ) ;
486488 const shortUrl = await createShortLink ( this , longUrl ) ;
487489 await copyToClipboard ( shortUrl , "Shortened URL" ) ;
@@ -537,9 +539,25 @@ export class Yasqe extends CodeMirror {
537539 // Position popup after layout is complete
538540 const positionPopup = ( ) => {
539541 if ( ! popup ) return ;
540- const sharePos = shareLinkWrapper . getBoundingClientRect ( ) ;
541- popup . style . top = shareLinkWrapper . offsetTop + sharePos . height + "px" ;
542- popup . style . left = shareLinkWrapper . offsetLeft + shareLinkWrapper . clientWidth - popup . clientWidth + "px" ;
542+ const buttonsRect = buttons . getBoundingClientRect ( ) ;
543+ const popupHeight = popup . offsetHeight || 300 ; // Estimated height
544+ const viewportHeight = window . innerHeight ;
545+ const spaceAbove = buttonsRect . top ;
546+ const spaceBelow = viewportHeight - buttonsRect . bottom ;
547+
548+ // If there's enough space above (with some padding), position above
549+ // Otherwise position below (will use scrolling if needed)
550+ if ( spaceAbove >= popupHeight + 20 ) {
551+ popup . style . bottom = ( buttons . clientHeight || 46 ) + "px" ;
552+ popup . style . top = "auto" ;
553+ popup . style . right = "0px" ;
554+ } else {
555+ // Not enough space above, use fixed positioning at top of viewport
556+ popup . style . position = "fixed" ;
557+ popup . style . bottom = "auto" ;
558+ popup . style . top = "20px" ;
559+ popup . style . right = "20px" ;
560+ }
543561 } ;
544562
545563 if ( typeof window !== "undefined" && typeof window . requestAnimationFrame === "function" ) {
0 commit comments