MediaWiki:Gadget-GrAnnotations.js: Difference between revisions

No edit summary
No edit summary
Line 1: Line 1:
/**
/**
  * gr_annotations.js  —  grantha.io inline Notes + Bookmarks + Feedback  (v5)
  * gr_annotations.js  —  grantha.io inline Notes + Bookmarks + Feedback  (v5-patch1)
* ══════════════════════════════════════════════════════════════════════
  * ═════════════════════════════════════════════════════════════════════
*
* FIXES FROM v4
* ─────────────
* • BUG: "Cannot read properties of null (reading 'parentNode')" from
*  ToggleList.js crashing before wireEvents() completes.
*  FIX: wrapSelection() now null-guards every DOM operation. Also
*  wrapped surroundContents in a try/catch that falls back gracefully
*  instead of letting the exception propagate.
*
* • BUG: On mobile, _selRange is null when action buttons are tapped
*  because selectionchange fires again (collapsing the selection) right
*  as the user lifts their finger to tap the action bar.
*  FIX: captureSelection() now saves _selText + a serialized anchor/
  *   focus pair at selectionchange time (600ms debounce). We store a
*  *snapshot* of the range so it survives the selection being cleared
*  by the tap on the action button.
*
* • BUG: Mobile bar appeared underneath browser's copy/paste menu.
*  FIX: Delay increased to 700ms and bar z-index lifted to 99999.
*
* • MISC: $mobileBar z-index fixed so it renders above gr-static-bar.
  */
  */


Line 276: Line 255:
     if (ancestor.nodeType === 3) ancestor = ancestor.parentNode;
     if (ancestor.nodeType === 3) ancestor = ancestor.parentNode;
     if (!ancestor || !contentEl.contains(ancestor)) return false;
     if (!ancestor || !contentEl.contains(ancestor)) return false;
    /* ── Editor mode guard (v5-patch1) ────────────────────────────
    * Do not fire the annotation gadget when the selection is inside
    * the custom editor surface (#se-surface / .se-outer).
    * This is a purely additive check — no existing logic is changed.
    * ──────────────────────────────────────────────────────────── */
    var _editorEl = document.getElementById('se-surface') ||
                    document.querySelector('.se-outer');
    if ( _editorEl && _editorEl.contains(ancestor) ) return false;


     _selText  = text;
     _selText  = text;