MediaWiki:Common.js: Difference between revisions

Jump to navigation Jump to search
no edit summary
No edit summary
No edit summary
Line 1,743: Line 1,743:
         jQuery("#show-article").toggleClass("print-opts-open", visible);
         jQuery("#show-article").toggleClass("print-opts-open", visible);


         // --- DEBUG + one-time direct binding on the freshly inserted anchors
         // Bind native handlers to ALL matching nodes (ids are duplicated on Entry pages)
         try {
         try {
           var aWith = document.getElementById("print-with-border");
           var nodes = Array.prototype.slice.call(
          var aNo = document.getElementById("print-no-border");
            document.querySelectorAll(
              '[id="print-with-border"], [id="print-no-border"]'
            )
          );
           console.log("[swprint] chooser toggled; visible=", visible, {
           console.log("[swprint] chooser toggled; visible=", visible, {
            withExists: !!aWith,
             withCount: document.querySelectorAll('[id="print-with-border"]')
            noExists: !!aNo,
              .length,
             withCount: document.querySelectorAll("#print-with-border").length,
             noCount: document.querySelectorAll('[id="print-no-border"]').length,
             noCount: document.querySelectorAll("#print-no-border").length,
           });
           });


           // Bind native onclicks (idempotent)
           nodes.forEach(function (el) {
          [aWith, aNo].forEach(function (a) {
             if (el.__swprintBound) return; // idempotent
             if (!a) return;
             el.__swprintBound = true;
             if (!a.__swprintBound) {
 
              a.__swprintBound = true;
            var handler = function (ev) {
              a.onclick = function (ev) {
              ev.preventDefault();
                ev.preventDefault();
              ev.stopPropagation();
                ev.stopPropagation();
              if (ev.stopImmediatePropagation) ev.stopImmediatePropagation();
                if (ev.stopImmediatePropagation) ev.stopImmediatePropagation();
              var id = el.getAttribute("id") || "";
                console.log("[swprint] NATIVE anchor onclick ->", this.id);
              console.log("[swprint] NATIVE anchor fired ->", id);
                if (window.jQuery) {
              if (window.jQuery) {
                  swHandlePrintChoice(this.id, jQuery(this));
                swHandlePrintChoice(id, jQuery(el));
                } else {
              } else {
                  swHandlePrintChoice(this.id, null);
                swHandlePrintChoice(id, null);
                }
              }
                return false;
              return false;
              };
            };
             }
 
            // bind early in the chain
            el.addEventListener("click", handler, true); // capture
             el.addEventListener("pointerup", handler, true); // extra safety for widgets
           });
           });
         } catch (err) {}
         } catch (err) {}


         return;
         return; // don't start printing yet
       }
       }
       // click on a choice link
       // click on a choice link
       var $choice = jQuery(e.target).closest(
       var $choice = jQuery(e.target).closest(
Line 1,854: Line 1,860:
       },
       },
       true // capture
       true // capture
    );
  })();
  // ===== Window-level ultra catcher (earliest in the path) =====
  (function () {
    if (window.__swprintWindowCatcher) return;
    window.__swprintWindowCatcher = true;
    var route = function (node) {
      while (node && node !== document) {
        if (node.nodeType === 1) {
          var id = node.getAttribute && node.getAttribute("id");
          if (id === "print-with-border" || id === "print-no-border") return id;
        }
        node = node.parentNode;
      }
      return "";
    };
    window.addEventListener(
      "click",
      function (ev) {
        try {
          var id = route(ev.target);
          if (!id) return;
          ev.preventDefault();
          ev.stopPropagation();
          if (ev.stopImmediatePropagation) ev.stopImmediatePropagation();
          console.log("[swprint] WINDOW catcher routed:", id);
          var $btn =
            (window.jQuery && jQuery(ev.target).closest('[id="' + id + '"]')) ||
            null;
          swHandlePrintChoice(id, $btn);
        } catch (e) {}
      },
      true // capture on window (earliest)
     );
     );
   })();
   })();

Navigation menu