MediaWiki:Gadget-GrAnnotations.js: Difference between revisions
No edit summary |
No edit summary |
||
| Line 359: | Line 359: | ||
function openCommentComposer() { | function openCommentComposer() { | ||
hideFab(); | hideFab(); | ||
positionComposer( $cmpComposer ); | positionComposer( $cmpComposer ); | ||
$cmpComposer.addClass('gra-composer-visible'); | $cmpComposer.addClass('gra-composer-visible'); | ||
$ | // Don't focus the textarea — it's hidden until "Others" chip is selected. | ||
// Focus the composer container so Escape key works. | |||
$cmpComposer[0].focus && $cmpComposer[0].setAttribute('tabindex', '-1'); | |||
} | } | ||
| Line 468: | Line 469: | ||
+ 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:31, 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 676: | Line 677: | ||
// ── Selection → show FAB ────────────────────────────────────── | // ── Selection → show FAB ────────────────────────────────────── | ||
$( document ).on('mouseup | // On mouseup: capture the selection and show the FAB strip. | ||
// | // We use mouseup (not click) so the selection is fully made. | ||
if ( $ | $( document ).on('mouseup', function(e){ | ||
if ( $ | // Ignore mouseup on FAB/composer — those are handled separately | ||
if ( $(e.target).closest('#gra-fab, .gra-composer, .gra-bm-composer').length ) return; | |||
// Ignore if a composer is already open | |||
if ( $cmpComposer.hasClass('gra-composer-visible') || | |||
$bmComposer.hasClass('gra-composer-visible') ) return; | |||
setTimeout(function(){ | setTimeout(function(){ | ||
if ( captureSelection() ) { | if ( captureSelection() ) { | ||
showFab( _selRect ); | showFab( _selRect ); | ||
} else { | } else { | ||
hideFab(); | |||
} | } | ||
}, | }, 10); | ||
}); | }); | ||
// ── FAB mousedown | // ── FAB mousedown: block selection collapse ─────────────────── | ||
// Browsers collapse | // Browsers collapse text selection on mousedown. preventDefault | ||
// | // keeps the selection alive so the click handler can wrap it. | ||
$fab.on('mousedown', function(e){ | $fab.on('mousedown', function(e){ | ||
e.preventDefault(); | e.preventDefault(); | ||
}); | }); | ||
// ── | // ── Mousedown outside: hide FAB ─────────────────────────────── | ||
$( document ).on('mousedown', function(e){ | $( document ).on('mousedown', function(e){ | ||
var $t = $(e.target); | var $t = $(e.target); | ||
if ( !$t.closest('#gra-fab | if ( !$t.closest('#gra-fab, .gra-composer, .gra-bm-composer, #gra-toggle, #gra-panel').length ) { | ||
hideFab(); | hideFab(); | ||
} | } | ||
}); | }); | ||
// ── FAB: Comment | // ── FAB: Comment button ─────────────────────────────────────── | ||
$( '#gra-fab-comment' ).on('click', function(e){ | $( '#gra-fab-comment' ).on('click', function(e){ | ||
e.stopPropagation(); | e.stopPropagation(); | ||
openCommentComposer(); | openCommentComposer(); | ||
}); | }); | ||
// ── FAB: Bookmark | // ── FAB: Bookmark button ────────────────────────────────────── | ||
$( '#gra-fab-bookmark' ).on('click', function(e){ | $( '#gra-fab-bookmark' ).on('click', function(e){ | ||
e.stopPropagation(); | e.stopPropagation(); | ||
openBookmarkComposer(); | openBookmarkComposer(); | ||
}); | }); | ||