MediaWiki:Common.js: Difference between revisions

Jump to navigation Jump to search
no edit summary
No edit summary
Tag: Reverted
No edit summary
Tag: Reverted
Line 1,678: Line 1,678:
   });
   });


  /* ====== SW PRINT DEBUG INSTRUMENTATION (temporary) ====== */
  (function () {
    // 1) Boot log + quick DOM probes
    console.log("[swprint] debug wiring start");
    try {
      console.log("[swprint] probes:", {
        printButton: !!document.getElementById("print-button"),
        chooser: !!document.getElementById("print-chooser"),
        printOpts: !!document.getElementById("print-options"),
        anchorsInPage: {
          with: document.querySelectorAll("#print-with-border").length,
          noborder: document.querySelectorAll("#print-no-border").length,
        },
        hasLocalPrintOnly: document.querySelectorAll(".print-only").length,
        hasShowArticle: !!document.getElementById("show-article"),
      });
    } catch (e) {
      console.log("[swprint] probe error:", e);
    }
    // 2) Super-logger for all clicks (CAPTURE + BUBBLE)
    function targetInfo(t) {
      if (!t) return "<none>";
      var id = t.id ? "#" + t.id : "";
      var cls = t.className
        ? "." + String(t.className).split(/\s+/).join(".")
        : "";
      return t.tagName + id + cls;
    }
    document.addEventListener(
      "click",
      function (e) {
        var a = e.target.closest ? e.target.closest("a") : null;
        console.log("[swprint] CAPTURE click:", {
          target: targetInfo(e.target),
          closestA: a ? targetInfo(a) : "<none>",
          id: e.target.id || (a && a.id) || "<none>",
          x: e.clientX,
          y: e.clientY,
        });
      },
      true
    );
    document.addEventListener(
      "click",
      function (e) {
        var a = e.target.closest ? e.target.closest("a") : null;
        console.log("[swprint] BUBBLE click:", {
          target: targetInfo(e.target),
          closestA: a ? targetInfo(a) : "<none>",
          id: e.target.id || (a && a.id) || "<none>",
        });
      },
      false
    );
    // 3) Direct handlers for the two choices (native listeners)
    function handleChoiceClick(e) {
      var a = e.target.closest ? e.target.closest("a") : null;
      var id = (a && a.id) || e.target.id || "";
      console.log(
        "[swprint] NATIVE choice handler hit. id=",
        id,
        "target=",
        targetInfo(e.target)
      );
      if (id !== "print-with-border" && id !== "print-no-border") {
        return; // not our link
      }
      e.preventDefault();
      // route to the jQuery handler if present; otherwise inline minimal fallback
      if (window.jQuery && typeof window.jQuery === "function") {
        var $ = window.jQuery;
        var $anchor = a ? $(a) : $(e.target);
        if ($anchor.length) {
          console.log("[swprint] forwarding to jQuery flow…");
          // Simulate what your main handler expects
          try {
            // Trigger a jQuery click on the anchor’s exact selector (bubble path)
            $anchor.trigger("click.print");
          } catch (err) {
            console.warn(
              "[swprint] jQuery forward failed; using inline fallback:",
              err
            );
            inlineFallbackPrint(id);
          }
        } else {
          inlineFallbackPrint(id);
        }
      } else {
        inlineFallbackPrint(id);
      }
    }
    function inlineFallbackPrint(id) {
      console.log("[swprint] INLINE FALLBACK kick-off for", id);
      // very small fallback: try to find .print-only here and window.print() it
      var hasLocal = document.querySelector(".print-only");
      if (!hasLocal) {
        console.warn("[swprint] no .print-only on page; doing window.print()");
        window.print();
        return;
      }
      console.log("[swprint] .print-only exists; asking existing code to run…");
      // Try clicking the main button again to re-enter your handler
      var btn = document.getElementById("print-button");
      if (btn) btn.click();
    }
    // Attach the native handlers
    ["print-with-border", "print-no-border"].forEach(function (id) {
      var el = document.getElementById(id);
      if (el) {
        el.addEventListener("click", handleChoiceClick, false);
        console.log("[swprint] attached native click to", "#" + id);
      } else {
        console.log("[swprint] will delegate by document for", "#" + id);
      }
    });
    // Also catch via document (in case the anchors are injected later)
    document.addEventListener(
      "click",
      function (e) {
        var a = e.target.closest
          ? e.target.closest("a#print-with-border, a#print-no-border")
          : null;
        if (a) {
          handleChoiceClick(e);
        }
      },
      false
    );
    // 4) Sanity ping after DOM mutations (some skins inject late)
    setTimeout(function () {
      console.log("[swprint] late check:", {
        anchors: {
          with: document.querySelectorAll("#print-with-border").length,
          noborder: document.querySelectorAll("#print-no-border").length,
        },
      });
    }, 500);
  })();
  // ENDENDEND
   // Close modal and remove fade out also when clicking outside of card
   // Close modal and remove fade out also when clicking outside of card
   $(document).on("mousedown", function (event) {
   $(document).on("mousedown", function (event) {

Navigation menu