MediaWiki:Common.js: Difference between revisions

Jump to navigation Jump to search
no edit summary
No edit summary
No edit summary
Line 1,734: Line 1,734:
     "#print-button, #print-chooser, #print-options",
     "#print-button, #print-chooser, #print-options",
     function (e) {
     function (e) {
      // click on the main [print]
       // click on the main [print]
       // click on the main [print]
       if (jQuery(e.target).closest("#print-button").length) {
       if (jQuery(e.target).closest("#print-button").length) {
Line 1,739: Line 1,740:
         var $chooser = swEnsurePrintChooser();
         var $chooser = swEnsurePrintChooser();
         $chooser.toggle();
         $chooser.toggle();
         jQuery("#show-article").toggleClass(
        var visible = $chooser.is(":visible");
          "print-opts-open",
         jQuery("#show-article").toggleClass("print-opts-open", visible);
           $chooser.is(":visible")
 
         );
        // --- DEBUG + one-time direct binding on the freshly inserted anchors
        try {
           var aWith = document.getElementById("print-with-border");
          var aNo = document.getElementById("print-no-border");
          console.log("[swprint] chooser toggled; visible=", visible, {
            withExists: !!aWith,
            noExists: !!aNo,
            withCount: document.querySelectorAll("#print-with-border").length,
            noCount: document.querySelectorAll("#print-no-border").length,
          });
 
          // Bind native onclicks (idempotent)
          [aWith, aNo].forEach(function (a) {
            if (!a) return;
            if (!a.__swprintBound) {
              a.__swprintBound = true;
              a.onclick = function (ev) {
                ev.preventDefault();
                ev.stopPropagation();
                if (ev.stopImmediatePropagation) ev.stopImmediatePropagation();
                console.log("[swprint] NATIVE anchor onclick ->", this.id);
                if (window.jQuery) {
                  swHandlePrintChoice(this.id, jQuery(this));
                } else {
                  swHandlePrintChoice(this.id, null);
                }
                return false;
              };
            }
          });
         } catch (err) {}
 
         return;
         return;
       }
       }
Line 1,785: Line 1,817:
   );
   );


   // ------ HARD CATCHER (capture phase) ------
   // ===== Ultra-hard native catcher (capture), no 'closest' dependency =====
  // If some widget stops propagation or the click lands on a nested element,
  // this capture listener still sees it and routes to swHandlePrintChoice.
   (function () {
   (function () {
     if (window.__swprintHardCatcherInstalled) return;
     if (window.__swprintUltraCatcher) return;
     window.__swprintHardCatcherInstalled = true;
     window.__swprintUltraCatcher = true;


     document.addEventListener(
     document.addEventListener(
Line 1,796: Line 1,826:
       function (ev) {
       function (ev) {
         try {
         try {
           var target = ev.target;
           var node = ev.target;
           var a = target && target.closest ? target.closest("a") : null;
           var foundId = "";
           var id = a && a.getAttribute ? a.getAttribute("id") : "";
          // manual ancestor walk (ES5-safe)
          // Debug what we clicked
           while (node && node !== document) {
          // console.log("[swprint] CAPTURE", { tag: target && target.tagName, id: id });
            if (node.nodeType === 1 && node.id) {
              if (
                node.id === "print-with-border" ||
                node.id === "print-no-border"
              ) {
                foundId = node.id;
                break;
              }
            }
            node = node.parentNode;
          }
          if (!foundId) return;


           if (id === "print-with-border" || id === "print-no-border") {
           // beat anything that tries to swallow the event
            // prevent default once here; we'll handle printing
          ev.preventDefault();
            ev.preventDefault();
          ev.stopPropagation();
            // Use jQuery wrapper if present, otherwise fall back to null
          if (ev.stopImmediatePropagation) ev.stopImmediatePropagation();
            var $a = (window.jQuery && jQuery(a)) || null;
 
            console.log("[swprint] CAPTURE routed to swHandlePrintChoice:", id);
          console.log("[swprint] ULTRA catcher routed:", foundId);
            swHandlePrintChoice(id, $a);
          var $btn = window.jQuery && node ? jQuery(node) : null;
          }
          swHandlePrintChoice(foundId, $btn);
         } catch (e) {
         } catch (e) {}
          // swallow
        }
       },
       },
       true
       true // capture
     ); // <-- capture phase
     );
   })();
   })();


Navigation menu