MediaWiki:Common.js: Difference between revisions

Jump to navigation Jump to search
no edit summary
No edit summary
Tags: Manual revert Reverted
No edit summary
Tag: Reverted
Line 1,295: Line 1,295:
     jQuery("#show-article").removeClass("print-opts-open");
     jQuery("#show-article").removeClass("print-opts-open");
   }
   }
  (function () {
    try {
      console.log("[swprint] probe on load", {
        printButton: !!document.getElementById("print-button"),
        chooserExists: !!document.getElementById("print-chooser"),
        localPrintOnlyCount: jQuery(".print-only").length,
        showArticleExists: !!document.getElementById("show-article"),
      });
    } catch (e) {}
  })();


   /* core: build iframe and print */
   /* core: build iframe and print */
   function swBuildIframeAndPrint(printHtml, borderPref, $btn) {
   function swBuildIframeAndPrint(printHtml, borderPref, $btn) {
    console.log("[swprint] buildIframeAndPrint()", {
      borderPref: borderPref,
      htmlLen: printHtml ? printHtml.length : 0,
    });
     // iframe
     // iframe
     var iframe = document.createElement("iframe");
     var iframe = document.createElement("iframe");
Line 1,558: Line 1,573:
   /* decide source & kick print */
   /* decide source & kick print */
   function swHandlePrintChoice(id, $btn) {
   function swHandlePrintChoice(id, $btn) {
    try {
      console.log("[swprint] swHandlePrintChoice START", {
        id: id,
        btn:
          $btn && $btn[0] && $btn[0].outerHTML
            ? $btn[0].outerHTML.slice(0, 80) + "…"
            : "<none>",
        hasLocalPrintOnly: jQuery(".print-only").length,
      });
    } catch (e) {}
     if ($btn && $btn.data("busy")) return;
     if ($btn && $btn.data("busy")) return;
     if ($btn && $btn.length) $btn.data("busy", true);
     if ($btn && $btn.length) $btn.data("busy", true);
Line 1,568: Line 1,593:
     if (localPrintOnly.length) {
     if (localPrintOnly.length) {
       swHidePrintUI();
       swHidePrintUI();
      console.log("[swprint] using LOCAL .print-only (Entry page)");
       swBuildIframeAndPrint(localPrintOnly.prop("outerHTML"), borderPref, $btn);
       swBuildIframeAndPrint(localPrintOnly.prop("outerHTML"), borderPref, $btn);
       return;
       return;
Line 1,661: Line 1,687:
     }
     }
   );
   );
  // ------ HARD CATCHER (capture phase) ------
  // If some widget stops propagation or the click lands on a nested element,
  // this capture listener still sees it and routes to swHandlePrintChoice.
  (function () {
    if (window.__swprintHardCatcherInstalled) return;
    window.__swprintHardCatcherInstalled = true;
    document.addEventListener(
      "click",
      function (ev) {
        try {
          var target = ev.target;
          var a = target && target.closest ? target.closest("a") : null;
          var id = a && a.getAttribute ? a.getAttribute("id") : "";
          // Debug what we clicked
          // console.log("[swprint] CAPTURE", { tag: target && target.tagName, id: id });
          if (id === "print-with-border" || id === "print-no-border") {
            // prevent default once here; we'll handle printing
            ev.preventDefault();
            // Use jQuery wrapper if present, otherwise fall back to null
            var $a = (window.jQuery && jQuery(a)) || null;
            console.log("[swprint] CAPTURE routed to swHandlePrintChoice:", id);
            swHandlePrintChoice(id, $a);
          }
        } catch (e) {
          // swallow
        }
      },
      true
    ); // <-- capture phase
  })();


   // 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