MediaWiki:Gadget-GrAnnotations.js: Difference between revisions

Undo revision 6155 by Vaishnavi (talk)
Tags: Undo Reverted
Undo revision 6156 by Vaishnavi (talk)
Tag: Undo
Line 542: Line 542:
     });
     });


     /* Mobile: intercept selection as early as possible */
     /* selectionchange handles both mobile and desktop */
var _lastTouchEnd = 0;
document.addEventListener('touchend', function(e) {
  if (!_mobile) return;
  if ($fab[0] && $fab[0].contains(e.target)) return;
  _lastTouchEnd = Date.now();
  clearTimeout(_selTimer);
  /* Fire at 100ms before browser popup (~300ms) */
  _selTimer = setTimeout(tryShowActions, 100);
}, { passive: true });
 
    /* selectionchange debounced */
     var _selTimer = null;
     var _selTimer = null;
     document.addEventListener('selectionchange', function() {
     document.addEventListener('selectionchange', function() {
Line 559: Line 548:
       clearTimeout(_selTimer);
       clearTimeout(_selTimer);
       var v = _selVersion;
       var v = _selVersion;
      /* On mobile fire faster so fab appears before browser popup */
      var delay = _mobile ? 150 : 600;
       _selTimer = setTimeout(function(){
       _selTimer = setTimeout(function(){
         if (v !== _selVersion) return;
         if (v !== _selVersion) return;
         if (_fabSelVer === v) return;
         if (_fabSelVer === v) return;
         if (_mobile) return; /* mobile uses touchend instead */
        /* Only show if there's an actual non-collapsed selection */
        var sel = window.getSelection();
         if (!sel || sel.isCollapsed || !sel.toString().trim()) return;
         tryShowActions();
         tryShowActions();
       }, 600);
       }, delay);
     });
     });
    /* Mobile touchend: re-check after finger lifts (selection may settle) */
    document.addEventListener('touchend', function(e) {
      if (!_mobile) return;
      if ($fab[0] && $fab[0].contains(e.target)) return;
      clearTimeout(_selTimer);
      _selTimer = setTimeout(function() {
        var sel = window.getSelection();
        if (!sel || sel.isCollapsed || !sel.toString().trim()) return;
        tryShowActions();
      }, 200);
    }, { passive: true });


     /* ── KEY FIX: fab touchstart sets flag to prevent hideActions ── */
     /* ── KEY FIX: fab touchstart sets flag to prevent hideActions ── */