MediaWiki:Common.js: Difference between revisions

Jump to navigation Jump to search
no edit summary
No edit summary
No edit summary
 
(30 intermediate revisions by the same user not shown)
Line 568: Line 568:
     var filterType = $(this).closest(".filter").data("filter");
     var filterType = $(this).closest(".filter").data("filter");
     var cardSelector = $(".card").length > 0 ? ".card" : ".community-card"; // Determine which card type is present
     var cardSelector = $(".card").length > 0 ? ".card" : ".community-card"; // Determine which card type is present
    console.log("Filter type:", filterType, "Card Selector:", cardSelector);


     $("#values-" + filterType).toggle();
     $("#values-" + filterType).toggle();
Line 584: Line 582:
     processEventCards(cardSelector);
     processEventCards(cardSelector);
     updateViews(cardSelector);
     updateViews(cardSelector);
    console.log("Updated views and borders after filter toggle");
   });
   });


Line 631: Line 627:
     updateViews(cardSelector);
     updateViews(cardSelector);
     updatePrintSelectionUI();
     updatePrintSelectionUI();
    hidePrintSelectionOptions();


     console.log("Filtering process complete, updated views and borders");
     console.log("Filtering process complete, updated views and borders");
Line 700: Line 697:
   // Reset function to remove active filters
   // Reset function to remove active filters
   $(".reset-filter").click(function (event) {
   $(".reset-filter").click(function (event) {
     event.stopPropagation(); // Prevent event bubbling
     event.stopPropagation();


    // Remove 'active' class from all filter buttons
     $("#filters .values button").removeClass("active");
     $("#filters .values button").removeClass("active");
     $(".open-filter").removeClass("active-filter");
     $(".open-filter").removeClass("active-filter");
    // Reset and hide the filter counts
     $(".count-filtered-cards").text("").hide();
     $(".count-filtered-cards").text("").hide();


     filterCards(); // Reapply filtering based on the updated active buttons
     filterCards();
 
     hidePrintSelectionOptions();
    // Update other UI elements as needed, excluding the general toggle button
    updateLastVisibleCard();
    updateWidthBlockView();
    processEventCards();
    updateViews();
     updatePrintSelectionUI();
   });
   });


   $("#filters .values button").click(function () {
   $("#filters .values button").click(function () {
    console.log("Filter is clicked!!!");
     $(this).toggleClass("active");
     $(this).toggleClass("active");
     filterCards(); // Re-apply the filters based on the updated active buttons
     filterCards();
 
    updateLastVisibleCard();
    updateWidthBlockView();
    processEventCards();
    updateViews();
   });
   });


Line 1,321: Line 1,303:


   function updatePrintSelectionUI() {
   function updatePrintSelectionUI() {
     var hasActiveFilters = jQuery("#filters .values button.active").length > 0;
     requestAnimationFrame(function () {
    var visibleCards = jQuery(".list-container .card:visible").not(".event").length;
        var activeCount = jQuery("#filters .values button.active").length;


    if (hasActiveFilters && visibleCards > 0) {
        if (activeCount > 0) {
         jQuery("#print-selection-wrapper").show();
         jQuery("#print-selection-wrapper").show();
    } else {
        } else {
         jQuery("#print-selection-wrapper").hide();
         jQuery("#print-selection-wrapper").hide();
         jQuery("#print-selection-options").hide();
         jQuery("#print-selection-options").hide();
     }
        }
     });
   }
   }


   /* small boot probe */
   function hidePrintSelectionOptions() {
  (function () {
         jQuery("#print-selection-options").hide();
    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 */
   function swHandleBatchPrint(borderPref) {
   function swBuildIframeAndPrint(printHtml, borderPref, $btn) {
     swPrintPreloadFont();
     // iframe
 
     var iframe = document.createElement("iframe");
     var $cards = jQuery(".card:visible").not(".event");
    iframe.style.position = "fixed";
 
     iframe.style.right = "0";
     if (!$cards.length) {
    iframe.style.bottom = "0";
        alert("No entries to print.");
     iframe.style.width = "0";
        return;
    iframe.style.height = "0";
     }
     iframe.style.border = "0";
 
    document.body.appendChild(iframe);
     var requests = [];


     var doc = iframe.contentDocument || iframe.contentWindow.document;
     $cards.each(function () {
    doc.open();
        var $card = jQuery(this);
    doc.write(
        var title = $card.data("page");
      '<!doctype html><html><head><meta charset="utf-8"><title>Print</title></head><body></body></html>'
    );
    doc.close();


    // make relative URLs resolve
        if (!title) return;
    var base = doc.createElement("base");
    base.href = location.origin + "/";
    doc.head.appendChild(base);


    // print.css
        var url =
    var linkCss = doc.createElement("link");
        window.mw && mw.util && mw.util.getUrl
    linkCss.rel = "stylesheet";
            ? swPrintCacheBust(mw.util.getUrl(title))
    linkCss.href = swPrintCacheBust(
            : swPrintCacheBust("/wiki/" + String(title));
      "/index.php?title=MediaWiki:Print.css&action=raw&ctype=text/css"
    );


    var cssLoaded = new Promise(function (resolve) {
        requests.push(
      linkCss.onload = resolve;
        jQuery.get(url).then(function (html) {
      linkCss.onerror = resolve;
            var $tmp = jQuery("<div>").html(html);
            var $print = $tmp.find(".print-only").first();
            return $print.length ? $print.prop("outerHTML") : "";
        })
        );
     });
     });


     // font preload (inside iframe)
     Promise.all(requests)
    var linkFont = doc.createElement("link");
        .then(function (results) {
    linkFont.rel = "preload";
        var combinedHtml = results.join("");
    linkFont.as = "font";
    linkFont.type = "font/woff2";
    linkFont.href = "/fonts/HALColant-TextRegular.woff2?v=20250820";
    linkFont.crossOrigin = "anonymous";


    doc.head.appendChild(linkFont);
        if (!combinedHtml.trim()) {
    doc.head.appendChild(linkCss);
            alert("Could not generate print content.");
            return;
        }


    // inject HTML
        swBuildIframeAndPrint(
    doc.body.innerHTML = printHtml;
            combinedHtml,
            borderPref,
            null,
            "filtered.softwear.directory"
        );
        })
        .catch(function () {
        alert("There was a problem preparing the print selection.");
        });
  }


    // sanitize: remove inner .print-no-border if user chose WITH border
  /* small boot probe */
    (function () {
  (function () {
       var stray = doc.querySelectorAll(".print-no-border");
    try {
      if (borderPref === "with" && stray.length) {
       console.log("[swprint] probe on load", {
         Array.prototype.forEach.call(stray, function (el) {
        printButton: !!document.getElementById("print-button"),
          el.className = (el.className || "")
        chooserExists: !!document.getElementById("print-chooser"),
            .replace(/\bprint-no-border\b/g, "")
         localPrintOnlyCount: jQuery(".print-only").length,
            .trim();
        showArticleExists: !!document.getElementById("show-article"),
        });
      });
      }
    } catch (e) {}
    })();
  })();


     // apply border preference to <html>
  /* core: build iframe and print */
     (function () {
  function swBuildIframeAndPrint(printHtml, borderPref, $btn, filenameOverride) {
       var htmlEl = doc.documentElement;
    // iframe
       if (borderPref === "without") {
    var iframe = document.createElement("iframe");
         if (htmlEl.classList) htmlEl.classList.add("print-no-border");
    iframe.style.position = "fixed";
         else if (
    iframe.style.right = "0";
           (" " + htmlEl.className + " ").indexOf(" print-no-border ") === -1
    iframe.style.bottom = "0";
         ) {
    iframe.style.width = "0";
           htmlEl.className += " print-no-border";
    iframe.style.height = "0";
         }
    iframe.style.border = "0";
       } else {
    document.body.appendChild(iframe);
         if (htmlEl.classList) htmlEl.classList.remove("print-no-border");
 
         else
    var doc = iframe.contentDocument || iframe.contentWindow.document;
           htmlEl.className = (htmlEl.className || "").replace(
    doc.open();
             /\bprint-no-border\b/g,
    doc.write(
             ""
      '<!doctype html><html><head><meta charset="utf-8"><title>Print</title></head><body></body></html>'
           );
    );
    doc.close();
 
    // make relative URLs resolve
    var base = doc.createElement("base");
    base.href = location.origin + "/";
    doc.head.appendChild(base);
 
    // print.css
    var linkCss = doc.createElement("link");
    linkCss.rel = "stylesheet";
    linkCss.href = swPrintCacheBust(
      "/index.php?title=MediaWiki:Print.css&action=raw&ctype=text/css"
    );
 
    var cssLoaded = new Promise(function (resolve) {
      linkCss.onload = resolve;
      linkCss.onerror = resolve;
    });
 
    // font preload (inside iframe)
    var linkFont = doc.createElement("link");
    linkFont.rel = "preload";
    linkFont.as = "font";
    linkFont.type = "font/woff2";
    linkFont.href = "/fonts/HALColant-TextRegular.woff2?v=20250820";
    linkFont.crossOrigin = "anonymous";
 
    doc.head.appendChild(linkFont);
    doc.head.appendChild(linkCss);
 
    // inject HTML
    doc.body.innerHTML = printHtml;
 
    (function () {
        var pres = doc.querySelectorAll(".link-pdf pre");
 
        Array.prototype.forEach.call(pres, function (pre) {
            // move its children out
            while (pre.firstChild) {
            pre.parentNode.insertBefore(pre.firstChild, pre);
            }
            // remove the <pre>
            pre.parentNode.removeChild(pre);
        });
    })();
 
    // sanitize: remove inner .print-no-border if user chose WITH border
    (function () {
      var stray = doc.querySelectorAll(".print-no-border");
      if (borderPref === "with" && stray.length) {
        Array.prototype.forEach.call(stray, function (el) {
          el.className = (el.className || "")
            .replace(/\bprint-no-border\b/g, "")
            .trim();
        });
      }
    })();
 
     // apply border preference to <html>
     (function () {
       var htmlEl = doc.documentElement;
       if (borderPref === "without") {
         if (htmlEl.classList) htmlEl.classList.add("print-no-border");
         else if (
           (" " + htmlEl.className + " ").indexOf(" print-no-border ") === -1
         ) {
           htmlEl.className += " print-no-border";
         }
       } else {
         if (htmlEl.classList) htmlEl.classList.remove("print-no-border");
         else
           htmlEl.className = (htmlEl.className || "").replace(
             /\bprint-no-border\b/g,
             ""
           );
      }
    })();
 
    // Glue label + body together (extra safety vs. page breaks)
    (function () {
      var style = doc.createElement("style");
      style.textContent =
        "@media print{.sw-keep{break-inside:avoid;page-break-inside:avoid;}}";
      doc.head.appendChild(style);
 
      var pairs = [
        [".article-label-description", ".article-description"],
        [".article-label-reflection", ".article-reflection"],
        [".article-label-external-reference", ".article-external-reference"],
        [".article-label-quote", ".article-quote"],
        [".article-label-modification-date", ".article-modification-date"],
      ];
 
      for (var i = 0; i < pairs.length; i++) {
        var labelSel = pairs[i][0];
        var bodySel = pairs[i][1];
        var labels = doc.querySelectorAll(labelSel);
        for (var j = 0; j < labels.length; j++) {
          var label = labels[j];
          var body = label.nextElementSibling;
          if (!body || !body.matches(bodySel)) continue;
          var wrap = doc.createElement("div");
          wrap.className = "sw-keep";
          label.parentNode.insertBefore(wrap, label);
          wrap.appendChild(label);
          wrap.appendChild(body);
        }
       }
       }
     })();
     })();


     // Glue label + body together (extra safety vs. page breaks)
     // clean empty paragraphs
     (function () {
     (function () {
       var style = doc.createElement("style");
       var ps = doc.querySelectorAll("#article-content p");
       style.textContent =
       Array.prototype.forEach.call(ps, function (p) {
         "@media print{.sw-keep{break-inside:avoid;page-break-inside:avoid;}}";
        var txt = (p.textContent || "").replace(/\u00a0/g, " ").trim();
       doc.head.appendChild(style);
        var onlyBr =
          p.children &&
          p.children.length === 1 &&
          p.firstElementChild &&
          p.firstElementChild.tagName === "BR";
         if (
          (!txt && !p.querySelector("img, a, strong, em, span:not(:empty)")) ||
          onlyBr
        ) {
          if (p.parentNode) p.parentNode.removeChild(p);
        }
      });
      var root = doc.getElementById("article-content");
       if (root) {
        var kids = Array.prototype.slice.call(root.childNodes);
        for (var k = 0; k < kids.length; k++) {
          var n = kids[k];
          if (n.nodeType === 3 && !n.textContent.replace(/\s+/g, "")) {
            root.removeChild(n);
          }
        }
      }
    })();


       var pairs = [
    // inline micro-tweaks for print spacing
         [".article-label-description", ".article-description"],
    (function () {
         [".article-label-reflection", ".article-reflection"],
       var css =
         [".article-label-external-reference", ".article-external-reference"],
         "@media print{" +
         [".article-label-quote", ".article-quote"],
        "  .article-description p,.article-reflection p,.article-external-reference p,.article-quote p{margin:0 0 1.2mm!important;}" +
         [".article-label-modification-date", ".article-modification-date"],
        "  .article-description p:last-child,.article-reflection p:last-child,.article-external-reference p:last-child,.article-quote p:last-child{margin-bottom:0!important;}" +
       ];
        "  .article-entry-number,.link-pdf,.article-type,.article-metadata,.article-images,.article-description,.article-reflection,.article-external-reference,.article-quote,.article-mod-line{padding-bottom:1mm!important;}" +
        "  .article-label-description + .article-description," +
         " .article-label-reflection + .article-reflection," +
         " .article-label-external-reference + .article-external-reference," +
         " .article-label-quote + .article-quote," +
         " .article-label-modification-date + .article-modification-date{margin-top:0!important;}" +
        "  .article-title-link{margin:0!important;padding:0!important;}" +
        " .article-title-link > *{margin:0!important;}" +
        " .link-pdf{margin-top:0!important;}" +
        "  #article-content > :last-child{padding-bottom:0!important;}" +
        "  #article-content > :last-child::after{content:none!important;}" +
        "}";
      var style = doc.createElement("style");
      style.type = "text/css";
      style.appendChild(doc.createTextNode(css));
       doc.head.appendChild(style);
    })();


      for (var i = 0; i < pairs.length; i++) {
    // link tweaks (wrapping / underline)
        var labelSel = pairs[i][0];
    (function () {
        var bodySel = pairs[i][1];
      var styleFix = doc.createElement("style");
        var labels = doc.querySelectorAll(labelSel);
      styleFix.textContent =
        for (var j = 0; j < labels.length; j++) {
        "@media print {.article-external-reference a,.link-pdf a{white-space:nowrap!important;word-break:normal!important;overflow-wrap:normal!important;text-decoration:underline}.article-external-reference{overflow-wrap:anywhere;word-break:break-word}a[href]{position:relative}}";
          var label = labels[j];
       doc.head.appendChild(styleFix);
          var body = label.nextElementSibling;
          if (!body || !body.matches(bodySel)) continue;
          var wrap = doc.createElement("div");
          wrap.className = "sw-keep";
          label.parentNode.insertBefore(wrap, label);
          wrap.appendChild(label);
          wrap.appendChild(body);
        }
       }
    })();


    // clean empty paragraphs
       var refs = doc.querySelectorAll(".article-external-reference a[href]");
    (function () {
       Array.prototype.forEach.call(refs, function (a) {
       var ps = doc.querySelectorAll("#article-content p");
         var txt = (a.textContent || "").trim();
       Array.prototype.forEach.call(ps, function (p) {
        var href = a.getAttribute("href") || "";
         var txt = (p.textContent || "").replace(/\u00a0/g, " ").trim();
         var looksLongUrl = /^https?:\/\//i.test(txt) && txt.length > 60;
         var onlyBr =
        if (looksLongUrl) {
          p.children &&
           try {
           p.children.length === 1 &&
            var u = new URL(href, doc.baseURI);
          p.firstElementChild &&
            var label =
          p.firstElementChild.tagName === "BR";
              u.hostname + (u.pathname.replace(/\/$/, "") ? u.pathname : "");
        if (
            if (label.length > 40) label = label.slice(0, 37) + "…";
          (!txt && !p.querySelector("img, a, strong, em, span:not(:empty)")) ||
            a.textContent = label;
           onlyBr
           } catch (e) {
        ) {
            a.textContent = "Link";
          if (p.parentNode) p.parentNode.removeChild(p);
          }
         }
         }
        a.style.whiteSpace = "nowrap";
        a.style.wordBreak = "normal";
        a.style.overflowWrap = "normal";
       });
       });
      var root = doc.getElementById("article-content");
      if (root) {
        var kids = Array.prototype.slice.call(root.childNodes);
        for (var k = 0; k < kids.length; k++) {
          var n = kids[k];
          if (n.nodeType === 3 && !n.textContent.replace(/\s+/g, "")) {
            root.removeChild(n);
          }
        }
      }
     })();
     })();


     // inline micro-tweaks for print spacing
     // waits
     (function () {
     function waitImages() {
       var css =
       var imgs = [].slice.call(doc.images || []);
        "@media print{" +
      if (!imgs.length) return Promise.resolve();
        "  .article-description p,.article-reflection p,.article-external-reference p,.article-quote p{margin:0 0 1.2mm!important;}" +
      return Promise.all(
        "  .article-description p:last-child,.article-reflection p:last-child,.article-external-reference p:last-child,.article-quote p:last-child{margin-bottom:0!important;}" +
         imgs.map(function (img) {
        "  .article-entry-number,.link-pdf,.article-type,.article-metadata,.article-images,.article-description,.article-reflection,.article-external-reference,.article-quote,.article-mod-line{padding-bottom:1mm!important;}" +
          if (img.decode) {
        "  .article-label-description + .article-description," +
            try {
         .article-label-reflection + .article-reflection," +
              return img.decode().catch(function () {});
        "  .article-label-external-reference + .article-external-reference," +
            } catch (e) {}
        "  .article-label-quote + .article-quote," +
          }
        "  .article-label-modification-date + .article-modification-date{margin-top:0!important;}" +
          return new Promise(function (res) {
        "  .article-title-link{margin:0!important;padding:0!important;}" +
            if (img.complete) return res();
        "  .article-title-link > *{margin:0!important;}" +
            img.onload = img.onerror = function () {
        "  .link-pdf{margin-top:0!important;}" +
              res();
        "  #article-content > :last-child{padding-bottom:0!important;}" +
            };
        "  #article-content > :last-child::after{content:none!important;}" +
          });
        "}";
        })
      var style = doc.createElement("style");
      );
      style.type = "text/css";
     }
      style.appendChild(doc.createTextNode(css));
     function waitFonts(timeoutMs) {
      doc.head.appendChild(style);
       if (!doc.fonts || !doc.fonts.ready) return Promise.resolve();
    })();
       var ready = doc.fonts.ready;
 
       var t = new Promise(function (res) {
     // link tweaks (wrapping / underline)
         setTimeout(res, timeoutMs || 1200);
     (function () {
      });
       var styleFix = doc.createElement("style");
      return Promise.race([ready, t]);
      styleFix.textContent =
    }
        "@media print {.article-external-reference a,.link-pdf a{white-space:nowrap!important;word-break:normal!important;overflow-wrap:normal!important;text-decoration:underline}.article-external-reference{overflow-wrap:anywhere;word-break:break-word}a[href]{position:relative}}";
    function waitSpecificFont(timeoutMs) {
      doc.head.appendChild(styleFix);
      if (!doc.fonts || !doc.fonts.load) return Promise.resolve();
 
      var p = Promise.all([
       var refs = doc.querySelectorAll(".article-external-reference a[href]");
        doc.fonts.load('400 16px "HALColant-TextRegular"'),
       Array.prototype.forEach.call(refs, function (a) {
        doc.fonts.load('normal 16px "HALColant-TextRegular"'),
         var txt = (a.textContent || "").trim();
      ]);
        var href = a.getAttribute("href") || "";
      var t = new Promise(function (res) {
        var looksLongUrl = /^https?:\/\//i.test(txt) && txt.length > 60;
        setTimeout(res, timeoutMs || 1200);
        if (looksLongUrl) {
      });
          try {
      return Promise.race([p, t]);
            var u = new URL(href, doc.baseURI);
    }
            var label =
    function nextFrame() {
              u.hostname + (u.pathname.replace(/\/$/, "") ? u.pathname : "");
      return new Promise(function (res) {
            if (label.length > 40) label = label.slice(0, 37) + "…";
         (iframe.contentWindow.requestAnimationFrame || setTimeout)(res, 0);
            a.textContent = label;
          } catch (e) {
            a.textContent = "Link";
          }
        }
        a.style.whiteSpace = "nowrap";
         a.style.wordBreak = "normal";
        a.style.overflowWrap = "normal";
       });
       });
    })();
    // waits
    function waitImages() {
      var imgs = [].slice.call(doc.images || []);
      if (!imgs.length) return Promise.resolve();
      return Promise.all(
        imgs.map(function (img) {
          if (img.decode) {
            try {
              return img.decode().catch(function () {});
            } catch (e) {}
          }
          return new Promise(function (res) {
            if (img.complete) return res();
            img.onload = img.onerror = function () {
              res();
            };
          });
        })
      );
     }
     }
    function waitFonts(timeoutMs) {
 
      if (!doc.fonts || !doc.fonts.ready) return Promise.resolve();
     Promise.all([
      var ready = doc.fonts.ready;
      var t = new Promise(function (res) {
        setTimeout(res, timeoutMs || 1200);
      });
      return Promise.race([ready, t]);
    }
    function waitSpecificFont(timeoutMs) {
      if (!doc.fonts || !doc.fonts.load) return Promise.resolve();
      var p = Promise.all([
        doc.fonts.load('400 16px "HALColant-TextRegular"'),
        doc.fonts.load('normal 16px "HALColant-TextRegular"'),
      ]);
      var t = new Promise(function (res) {
        setTimeout(res, timeoutMs || 1200);
      });
      return Promise.race([p, t]);
    }
    function nextFrame() {
      return new Promise(function (res) {
        (iframe.contentWindow.requestAnimationFrame || setTimeout)(res, 0);
      });
    }
 
     Promise.all([
       cssLoaded,
       cssLoaded,
       waitImages(),
       waitImages(),
Line 1,594: Line 1,647:
       .then(function () {
       .then(function () {
         // filename via document.title
         // filename via document.title
        var desiredTitle;
        if (filenameOverride) {
        desiredTitle = filenameOverride;
        } else {
         var entryNum = "";
         var entryNum = "";
         var numEl = doc.querySelector(".article-entry-number");
         var numEl = doc.querySelector(".article-entry-number");
         if (numEl) {
         if (numEl) {
          var m = (numEl.textContent || "").match(/\d+/);
            var m = (numEl.textContent || "").match(/\d+/);
          entryNum = m ? m[0] : "";
            entryNum = m ? m[0] : "";
         }
         }
         var desiredTitle =
         desiredTitle =
          (entryNum ? entryNum + "." : "") + "softwear.directory";
            (entryNum ? entryNum + "." : "") + "softwear.directory";
        }
 
         var oldIframeTitle = doc.title;
         var oldIframeTitle = doc.title;
         var oldParentTitle = document.title;
         var oldParentTitle = document.title;
Line 1,618: Line 1,678:
         doc.title = desiredTitle;
         doc.title = desiredTitle;
         document.title = desiredTitle;
         document.title = desiredTitle;
        //window._printDoc = doc;
        //window._printFrame = iframe;
        //console.log("PRINT DOC READY", doc);
        //console.log("PRINT HTML", doc.body.innerHTML);


         iframe.contentWindow.focus();
         iframe.contentWindow.focus();
Line 1,774: Line 1,839:
         return;
         return;
       }
       }
 
 
       // click directly on a choice link (fallback path)
       // click directly on a choice link (fallback path)
       var $choice = jQuery(e.target).closest(
       var $choice = jQuery(e.target).closest(
         "a#print-with-border, a#print-no-border"
         "a#print-with-border, a#print-no-border"
       );
       );
       if (!$choice.length) return;
       if (!$choice.length) return;
       e.preventDefault();
       e.preventDefault();
       swHandlePrintChoice($choice.attr("id"), $choice);
       swHandlePrintChoice($choice.attr("id"), $choice);
     }
     }
   );
   );
 
 
   // map any <button> inside chooser to its host anchor
   // map any <button> inside chooser to its host anchor
   jQuery(document).on(
   jQuery(document).on(
     "click.swprintChoiceBtn2",
     "click.swprintChoiceBtn2",
     "#print-chooser button",
     "#print-chooser button",
     function (e) {
     function (e) {
       var host = this.closest(
       var host = this.closest(
         '[id="print-with-border"], [id="print-no-border"]'
         '[id="print-with-border"], [id="print-no-border"]'
       );
       );
       if (!host) return;
       if (!host) return;
       e.preventDefault();
       e.preventDefault();
       swHandlePrintChoice(host.id, (window.jQuery && jQuery(host)) || null);
       swHandlePrintChoice(host.id, (window.jQuery && jQuery(host)) || null);
    }
  );
 
  // hide choices on ESC
  jQuery(document).on("keydown.swprint", function (e) {
    if (e && e.keyCode === 27) {
        swHidePrintUI();
        hidePrintSelectionOptions();
    }
  });
 
  // toggle filtered print options
  jQuery(document).on("click", ".print-selection-toggle", function (e) {
        e.preventDefault();
        jQuery("#print-selection-options").toggle();
    });
 
  // run filtered batch print
  jQuery(document).on(
    "click",
    ".print-selection-border, .print-selection-no-border",
    function (e) {
        e.preventDefault();
 
        var $btn = jQuery(this);
        var borderPref = $btn.hasClass("print-selection-no-border")
        ? "without"
        : "with";
 
        // disable all related buttons
        jQuery(".print-selection-border, .print-selection-no-border, .print-selection-toggle")
        .prop("disabled", true)
        .css("opacity", "0.5");
 
        // change ONLY clicked button text (native feeling)
        var originalText = $btn.text();
        $btn.text("working…");
 
        swHandleBatchPrint(borderPref);
 
        // optional reset (if user comes back)
        setTimeout(function () {
        $btn.text(originalText);
        jQuery(".print-selection-border, .print-selection-no-border, .print-selection-toggle")
            .prop("disabled", false)
            .css("opacity", "");
        }, 2000);
     }
     }
   );
   );
  // hide choices on ESC
  jQuery(document).on("keydown.swprint", function (e) {
    if (e && e.keyCode === 27) swHidePrintUI();
  });


   /* ---------- /Softwear PRINT ---------- */
   /* ---------- /Softwear PRINT ---------- */
Line 2,023: Line 2,130:


   updatePrintSelectionUI();
   updatePrintSelectionUI();
  hidePrintSelectionOptions();
});
});

Navigation menu