MediaWiki:Common.js: Difference between revisions

Jump to navigation Jump to search
no edit summary
No edit summary
No edit summary
Line 1,739: Line 1,739:
         e.preventDefault();
         e.preventDefault();
         var $chooser = swEnsurePrintChooser();
         var $chooser = swEnsurePrintChooser();
        // make sure it sits on top & accepts clicks (diagnostic-safe)
        $chooser.css({
          position: "absolute",
          zIndex: 99999,
          background: "#fff",
          padding: "4px 6px",
          border: "1px solid #ddd",
        });
         $chooser.toggle();
         $chooser.toggle();
         var visible = $chooser.is(":visible");
         var visible = $chooser.is(":visible");
         jQuery("#show-article").toggleClass("print-opts-open", visible);
         jQuery("#show-article").toggleClass("print-opts-open", visible);


         // Bind native handlers to ALL matching nodes (ids are duplicated on Entry pages)
         // Bind native handlers to ALL nodes that currently exist with those IDs
         try {
         try {
           var nodes = Array.prototype.slice.call(
           var nodes = Array.prototype.slice.call(
Line 1,757: Line 1,767:


           nodes.forEach(function (el) {
           nodes.forEach(function (el) {
             if (el.__swprintBound) return; // idempotent
             if (el.__swprintBound) return;
             el.__swprintBound = true;
             el.__swprintBound = true;


Line 1,765: Line 1,775:
               if (ev.stopImmediatePropagation) ev.stopImmediatePropagation();
               if (ev.stopImmediatePropagation) ev.stopImmediatePropagation();
               var id = el.getAttribute("id") || "";
               var id = el.getAttribute("id") || "";
               console.log("[swprint] NATIVE anchor fired ->", id);
               console.log("[swprint] NATIVE choice fired ->", id);
               if (window.jQuery) {
               swHandlePrintChoice(id, (window.jQuery && jQuery(el)) || null);
                swHandlePrintChoice(id, jQuery(el));
              } else {
                swHandlePrintChoice(id, null);
              }
               return false;
               return false;
             };
             };


             // bind early in the chain
             // capture = see it before anything else
             el.addEventListener("click", handler, true); // capture
             el.addEventListener("click", handler, true);
             el.addEventListener("pointerup", handler, true); // extra safety for widgets
             el.addEventListener("pointerup", handler, true);
           });
           });
         } catch (err) {}
         } catch (err) {}


         return; // don't start printing yet
         // run visibility diagnostics on the two buttons
        (function swprintDebugChoices() {
          function dump(id) {
            var list = document.querySelectorAll('[id="' + id + '"]');
            for (var i = 0; i < list.length; i++) {
              var el = list[i];
              var cs = window.getComputedStyle(el);
              var r = el.getBoundingClientRect();
              console.log("[swprint][diag]", id, i, {
                tag: el.tagName,
                display: cs.display,
                visibility: cs.visibility,
                opacity: cs.opacity,
                pointerEvents: cs.pointerEvents,
                rect: {
                  x: Math.round(r.x),
                  y: Math.round(r.y),
                  w: Math.round(r.width),
                  h: Math.round(r.height),
                },
                zIndex: cs.zIndex,
              });
            }
          }
          dump("print-with-border");
          dump("print-no-border");
        })();
 
        return;
       }
       }


Line 1,863: Line 1,897:
   })();
   })();


   // ===== Window-level ultra catcher (earliest in the path) =====
   // Window-level chooser catcher: any click inside #print-chooser is routed.
   (function () {
   (function () {
     if (window.__swprintWindowCatcher) return;
     if (window.__swprintWindowChooserCatch) return;
     window.__swprintWindowCatcher = true;
     window.__swprintWindowChooserCatch = 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(
     window.addEventListener(
Line 1,883: Line 1,906:
       function (ev) {
       function (ev) {
         try {
         try {
           var id = route(ev.target);
           var chooser = document.getElementById("print-chooser");
           if (!id) return;
          if (!chooser || chooser.style.display === "none") return;
 
          // Did we click a WITH / NO element (or inside it)?
          var btn = ev.target.closest
            ? ev.target.closest(
                '#print-with-border, #print-no-border, [id="print-with-border"], [id="print-no-border"]'
              )
            : null;
 
           if (!btn || !chooser.contains(btn)) return;
 
           ev.preventDefault();
           ev.preventDefault();
           ev.stopPropagation();
           ev.stopPropagation();
           if (ev.stopImmediatePropagation) ev.stopImmediatePropagation();
           if (ev.stopImmediatePropagation) ev.stopImmediatePropagation();
           console.log("[swprint] WINDOW catcher routed:", id);
 
           var $btn =
          var id = btn.getAttribute("id") || "";
            (window.jQuery && jQuery(ev.target).closest('[id="' + id + '"]')) ||
           console.log("[swprint] WINDOW chooser catcher ->", id);
            null;
 
           var $btn = (window.jQuery && jQuery(btn)) || null;
           swHandlePrintChoice(id, $btn);
           swHandlePrintChoice(id, $btn);
         } catch (e) {}
         } catch (e) {}
       },
       },
       true // capture on window (earliest)
       true
     );
     ); // capture
   })();
   })();
  // If a widget uses <button> inside the chooser, map it to the nearest id node
  jQuery(document).on(
    "click.swprintChoiceBtn2",
    "#print-chooser button",
    function (e) {
      var host = this.closest(
        '[id="print-with-border"], [id="print-no-border"]'
      );
      if (!host) return;
      e.preventDefault();
      console.log("[swprint] BUTTON inside chooser ->", host.id);
      swHandlePrintChoice(host.id, (window.jQuery && jQuery(host)) || null);
    }
  );


   // also hide choices on ESC; your close-button handler already hides them
   // also hide choices on ESC; your close-button handler already hides them

Navigation menu