MediaWiki:Gadget-GrAnnotations.js: Difference between revisions

No edit summary
No edit summary
Line 647: Line 647:


   function wireEvents() {
   function wireEvents() {
document.addEventListener('contextmenu', function(e) {
   var longPressTimer = null;
e.preventDefault();
   var tag = e.target.tagName;
  if (tag === 'INPUT' || tag === 'TEXTAREA' || tag === 'SELECT') return;
  var c = document.querySelector(CONTENT_SEL);
  if (c && c.contains(e.target)) e.preventDefault();
}, { passive: false });


  document.addEventListener('touchstart', function(e) {
    var tag = e.target.tagName;
    if (tag === 'INPUT' || tag === 'TEXTAREA' || tag === 'SELECT') return;
    var c = document.querySelector(CONTENT_SEL);
    if (!c || !c.contains(e.target)) return;
    longPressTimer = setTimeout(function() {
      // Interrupt the long press to suppress the context menu
      document.dispatchEvent(new Event('touchend'));
    }, 400);
  }, { passive: true });
  document.addEventListener('touchend', function() {
    if (longPressTimer) {
      clearTimeout(longPressTimer);
      longPressTimer = null;
    }
  }, { passive: true });
  document.addEventListener('touchmove', function() {
    if (longPressTimer) {
      clearTimeout(longPressTimer);
      longPressTimer = null;
    }
  }, { passive: true });
     /* ── Desktop mouseup ── */
     /* ── Desktop mouseup ── */
     $(document).on('mouseup', function(e){
     $(document).on('mouseup', function(e){