MediaWiki:Gadget-GrAnnotations.js: Difference between revisions

No edit summary
No edit summary
Line 469: 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:31, 25 April 2026 (UTC)';
                   + '\n\n[[User:Chandrashekars|Chandrashekars]] ([[User talk:Chandrashekars|talk]]) 18:58, 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 ──────────────────────────────────────
     // On mouseup: capture the selection and show the FAB strip.
     // Listen on the content area only, not the whole document,
     // We use mouseup (not click) so the selection is fully made.
     // so we never accidentally capture selections in the panel/composer.
     $( document ).on('mouseup', function(e){
     var $content = $( CONTENT_SEL );
       // Ignore mouseup on FAB/composer — those are handled separately
    if ( !$content.length ) $content = $( document );
       if ( $(e.target).closest('#gra-fab, .gra-composer, .gra-bm-composer').length ) return;
 
      // Ignore if a composer is already open
    $content.on('mouseup', function(){
      if ( $cmpComposer.hasClass('gra-composer-visible') ||
       // Brief delay so browser finalises the selection object
          $bmComposer.hasClass('gra-composer-visible') ) return;
       setTimeout( function(){
      setTimeout(function(){
        if ( $cmpComposer.hasClass('gra-composer-visible') ||
            $bmComposer.hasClass('gra-composer-visible') ) return;
         if ( captureSelection() ) {
         if ( captureSelection() ) {
           showFab( _selRect );
           showFab( _selRect );
Line 691: Line 692:
           hideFab();
           hideFab();
         }
         }
       }, 10);
       }, 50 );
     });
     });


     // ── FAB mousedown: block selection collapse ───────────────────
     // ── FAB buttons ──────────────────────────────────────────────
     // Browsers collapse text selection on mousedown. preventDefault
    // preventDefault on mousedown keeps the browser text-selection alive.
     // keeps the selection alive so the click handler can wrap it.
     // We also stopPropagation so the document mousedown handler below
     $fab.on('mousedown', function(e){
     // does NOT fire and hide the FAB before the click registers.
     $( '#gra-fab-comment' ).on('mousedown', function(e){
       e.preventDefault();
       e.preventDefault();
    });
    // ── Mousedown outside: hide FAB ───────────────────────────────
    $( document ).on('mousedown', function(e){
      var $t = $(e.target);
      if ( !$t.closest('#gra-fab, .gra-composer, .gra-bm-composer, #gra-toggle, #gra-panel').length ) {
        hideFab();
      }
    });
    // ── FAB: Comment button ───────────────────────────────────────
    $( '#gra-fab-comment' ).on('click', function(e){
       e.stopPropagation();
       e.stopPropagation();
    }).on('click', function(){
       openCommentComposer();
       openCommentComposer();
     });
     });


    // ── FAB: Bookmark button ──────────────────────────────────────
     $( '#gra-fab-bookmark' ).on('mousedown', function(e){
     $( '#gra-fab-bookmark' ).on('click', function(e){
      e.preventDefault();
       e.stopPropagation();
       e.stopPropagation();
    }).on('click', function(){
       openBookmarkComposer();
       openBookmarkComposer();
    });
    // ── Hide FAB when clicking elsewhere ─────────────────────────
    $( document ).on('mousedown', function(e){
      var $t = $( e.target );
      var inside = $t.closest(
        '#gra-fab, .gra-composer, .gra-bm-composer, #gra-toggle, #gra-panel'
      ).length;
      if ( !inside ) hideFab();
     });
     });