MediaWiki:Common.js: Difference between revisions

Jump to navigation Jump to search
no edit summary
No edit summary
No edit summary
Line 1,281: Line 1,281:
     var $chooser = jQuery("#print-chooser");
     var $chooser = jQuery("#print-chooser");
     if ($chooser.length) return $chooser;
     if ($chooser.length) return $chooser;
     $chooser = jQuery(
     $chooser = jQuery(
       '<div id="print-chooser" class="print-chooser" style="display:none;">' +
       '<div id="print-chooser" class="print-chooser" style="display:none;">' +
Line 1,288: Line 1,289:
     );
     );
     jQuery("#print-button").after($chooser);
     jQuery("#print-button").after($chooser);
    // Bind the choice clicks ONCE, scoped to this chooser
    if (!$chooser.data("swBound")) {
      $chooser.on("click", "a#sw-print-with, a#sw-print-no", function (e) {
        e.preventDefault();
        var id =
          this.id === "sw-print-no" ? "print-no-border" : "print-with-border";
        try {
          console.log("[swprint] chooser click ->", this.id, "=>", id);
        } catch (e2) {}
        swHandlePrintChoice(id, jQuery(this));
      });
      $chooser.data("swBound", true);
    }
     return $chooser;
     return $chooser;
   }
   }
Line 1,824: Line 1,840:
       e.preventDefault();
       e.preventDefault();
       swHandlePrintChoice($choice.attr("id"), $choice);
       swHandlePrintChoice($choice.attr("id"), $choice);
    }
  );
  // --- extra safety bindings for Entry page / widgets ---
  // Delegated: clicks on choices inside the chooser
  jQuery(document).on(
    "click.swprintChoice",
    "#print-chooser a#sw-print-with, #print-chooser a#sw-print-no",
    function (e) {
      e.preventDefault();
      var id =
        this.id === "sw-print-no" ? "print-no-border" : "print-with-border";
      swHandlePrintChoice(id, jQuery(this));
    }
  );
  // If the UI uses <button> inside the <a>, map button → parent <a> (still scoped to chooser)
  jQuery(document).on(
    "click.swprintChoiceBtn",
    "#print-chooser button",
    function (e) {
      var host = this.closest(
        "#print-chooser a#sw-print-with, #print-chooser a#sw-print-no"
      );
      if (!host) return;
      e.preventDefault();
      var id =
        host.id === "sw-print-no" ? "print-no-border" : "print-with-border";
      swHandlePrintChoice(id, (window.jQuery && jQuery(host)) || null);
     }
     }
   );
   );

Navigation menu