MediaWiki:Gadget-GrAnnotations.js: Difference between revisions
No edit summary |
No edit summary |
||
| Line 468: | Line 468: | ||
+ commentText.slice(0,500) | + commentText.slice(0,500) | ||
+ ( commentText.length > 500 ? '\n...' : '' ) | + ( commentText.length > 500 ? '\n...' : '' ) | ||
+ '\n\n[[User:Chandrashekars|Chandrashekars]] ([[User talk:Chandrashekars|talk]]) 18: | + '\n\n[[User:Chandrashekars|Chandrashekars]] ([[User talk:Chandrashekars|talk]]) 18:21, 25 April 2026 (UTC)'; | ||
new mw.Api().postWithEditToken({ | new mw.Api().postWithEditToken({ | ||
action:'edit', title:'User_talk:' + ADMIN_USER, section:'new', | action:'edit', title:'User_talk:' + ADMIN_USER, section:'new', | ||
| Line 677: | Line 677: | ||
// ── Selection → show FAB ────────────────────────────────────── | // ── Selection → show FAB ────────────────────────────────────── | ||
$( document ).on('mouseup keyup', function(e){ | $( document ).on('mouseup keyup', function(e){ | ||
// | // Skip if a composer is open | ||
if ( $cmpComposer.hasClass('gra-composer-visible') ) return; | |||
if ( $bmComposer.hasClass('gra-composer-visible') ) return; | |||
// Skip mouseup that originated inside the FAB itself | |||
if ( $(e.target).closest('#gra-fab').length ) return; | |||
// Delay slightly so selection is fully committed by browser | |||
setTimeout(function(){ | setTimeout(function(){ | ||
if ( captureSelection() ) { | if ( captureSelection() ) { | ||
showFab( _selRect ); | showFab( _selRect ); | ||
} else { | } else { | ||
hideFab(); | // Only hide if a composer isn't open | ||
if ( !$cmpComposer.hasClass('gra-composer-visible') && | |||
!$bmComposer.hasClass('gra-composer-visible') ) { | |||
hideFab(); | |||
} | |||
} | } | ||
}, | }, 30); | ||
}); | |||
// ── FAB mousedown — prevent browser from collapsing selection ──── | |||
// Browsers collapse the text selection on mousedown. Calling | |||
// preventDefault() on the FAB buttons stops that, keeping _selRange | |||
// valid so the subsequent click handler can use it. | |||
$fab.on('mousedown', function(e){ | |||
e.preventDefault(); | |||
}); | }); | ||
| Line 700: | Line 715: | ||
// ── FAB: Comment ────────────────────────────────────────────── | // ── FAB: Comment ────────────────────────────────────────────── | ||
// Use saved _selRange — do NOT call captureSelection() here. | |||
// By the time a click fires, mousedown has already collapsed | |||
// the browser selection, so getSelection() returns empty. | |||
$( '#gra-fab-comment' ).on('click', function(e){ | $( '#gra-fab-comment' ).on('click', function(e){ | ||
e.preventDefault(); | e.preventDefault(); | ||
e.stopPropagation(); | e.stopPropagation(); | ||
if ( ! | if ( !_selRange ) return; | ||
openCommentComposer(); | openCommentComposer(); | ||
}); | }); | ||
| Line 711: | Line 729: | ||
e.preventDefault(); | e.preventDefault(); | ||
e.stopPropagation(); | e.stopPropagation(); | ||
if ( ! | if ( !_selRange ) return; | ||
openBookmarkComposer(); | openBookmarkComposer(); | ||
}); | }); | ||