MediaWiki:Common.js: Difference between revisions

Jump to navigation Jump to search
no edit summary
No edit summary
No edit summary
Line 1,282: Line 1,282:
     if ($chooser.length) return $chooser;
     if ($chooser.length) return $chooser;


    // Keep your existing IDs (print-with-border / print-no-border)
     $chooser = jQuery(
     $chooser = jQuery(
       '<div id="print-chooser" class="print-chooser" style="display:none;">' +
       '<div id="print-chooser" class="print-chooser" style="display:none;">' +
         '<a href="#" id="sw-print-with" class="print-choice">border</a> ' +
         '<a href="#" id="print-with-border" class="print-choice">border</a> ' +
         '<a href="#" id="sw-print-no" class="print-choice">no border</a>' +
         '<a href="#" id="print-no-border" class="print-choice">no border</a>' +
         "</div>"
         "</div>"
     );
     );
     jQuery("#print-button").after($chooser);
     jQuery("#print-button").after($chooser);


     // Bind the choice clicks ONCE, scoped to this chooser
     // Bind ONCE, on the chooser itself (robust to nested elements)
     if (!$chooser.data("swBound")) {
     if (!$chooser.data("swBound")) {
       $chooser.on("click", "a#sw-print-with, a#sw-print-no", function (e) {
       $chooser.on("click", function (e) {
         e.preventDefault();
         var a = e.target && e.target.closest ? e.target.closest("a[id]") : null;
         var id =
        if (!a) return; // clicked outside a link in the chooser
          this.id === "sw-print-no" ? "print-no-border" : "print-with-border";
         var id = a.getAttribute("id");
        if (id !== "print-with-border" && id !== "print-no-border") return;
 
        e.preventDefault(); // stop navigation
         try {
         try {
           console.log("[swprint] chooser click ->", this.id, "=>", id);
           console.log("[swprint] chooser click ->", id);
         } catch (e2) {}
         } catch (e2) {}
         swHandlePrintChoice(id, jQuery(this));
         swHandlePrintChoice(id, jQuery(a));
       });
       });
       $chooser.data("swBound", true);
       $chooser.data("swBound", true);
      try {
        console.log("[swprint] chooser handler bound");
      } catch (e) {}
     }
     }


Navigation menu