MediaWiki:Common.js: Difference between revisions

Jump to navigation Jump to search
no edit summary
No edit summary
No edit summary
 
(41 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 630: Line 626:
     processEventCards(cardSelector);
     processEventCards(cardSelector);
     updateViews(cardSelector);
     updateViews(cardSelector);
    updatePrintSelectionUI();
    hidePrintSelectionOptions();


     console.log("Filtering process complete, updated views and borders");
     console.log("Filtering process complete, updated views and borders");
Line 699: 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();
   });
   });


   $("#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,260: Line 1,244:
   });
   });


  // HERE SHOULD BE THE NEW CODE!!!!
   /* ---------- Softwear PRINT ---------- */
   /* ---------- Softwear PRINT (scoped, ES5-safe) ---------- */


   /* helpers */
   /* helpers */
Line 1,281: Line 1,264:
     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;">' +
         '<a href="#" id="sw-print-with" class="print-choice">border</a> ' +
         '<a href="#" id="print-with-border" class="print-choice">show border</a> ' +
         '<a href="#" id="sw-print-no" class="print-choice">no border</a>' +
         '<a href="#" id="print-no-border" class="print-choice">hide border</a>' +
         "</div>"
         "</div>"
     );
     );
     jQuery("#print-button").after($chooser);
     jQuery("#print-button").after($chooser);
    // Bind once on the chooser to catch nested elements
    if (!$chooser.data("swBound")) {
      function chooserFire(ev, where) {
        ev = ev || window.event;
        var t = ev && (ev.target || ev.srcElement);
        var a = t && t.closest ? t.closest("a[id]") : null;
        if (!a) return;
        var id = a.getAttribute("id");
        if (id !== "print-with-border" && id !== "print-no-border") return;
        if (ev.preventDefault) ev.preventDefault();
        if (ev.stopImmediatePropagation) ev.stopImmediatePropagation();
        if (ev.stopPropagation) ev.stopPropagation();
        swHandlePrintChoice(id, (window.jQuery && jQuery(a)) || null);
        return false;
      }
      $chooser.on("pointerdown", chooserFire);
      $chooser.on("touchstart", chooserFire);
      $chooser.on("mousedown", chooserFire);
      $chooser.on("click", chooserFire);
      $chooser.data("swBound", true);
    }
     return $chooser;
     return $chooser;
   }
   }
Line 1,296: Line 1,302:
   }
   }


  function updatePrintSelectionUI() {
    requestAnimationFrame(function () {
        var activeCount = jQuery("#filters .values button.active").length;
        if (activeCount > 0) {
        jQuery("#print-selection-wrapper").show();
        } else {
        jQuery("#print-selection-wrapper").hide();
        jQuery("#print-selection-options").hide();
        }
    });
  }
  function hidePrintSelectionOptions() {
        jQuery("#print-selection-options").hide();
    }
  function swHandleBatchPrint(borderPref) {
    swPrintPreloadFont();
    var $cards = jQuery(".card:visible").not(".event");
    if (!$cards.length) {
        alert("No entries to print.");
        return;
    }
    var requests = [];
    $cards.each(function () {
        var $card = jQuery(this);
        var title = $card.data("page");
        if (!title) return;
        var url =
        window.mw && mw.util && mw.util.getUrl
            ? swPrintCacheBust(mw.util.getUrl(title))
            : swPrintCacheBust("/wiki/" + String(title));
        requests.push(
        jQuery.get(url).then(function (html) {
            var $tmp = jQuery("<div>").html(html);
            var $print = $tmp.find(".print-only").first();
            return $print.length ? $print.prop("outerHTML") : "";
        })
        );
    });
    Promise.all(requests)
        .then(function (results) {
        var combinedHtml = results.join("");
        if (!combinedHtml.trim()) {
            alert("Could not generate print content.");
            return;
        }
        swBuildIframeAndPrint(
            combinedHtml,
            borderPref,
            null,
            "filtered.softwear.directory"
        );
        })
        .catch(function () {
        alert("There was a problem preparing the print selection.");
        });
  }
  /* small boot probe */
   (function () {
   (function () {
     try {
     try {
Line 1,308: Line 1,385:


   /* core: build iframe and print */
   /* core: build iframe and print */
   function swBuildIframeAndPrint(printHtml, borderPref, $btn) {
   function swBuildIframeAndPrint(printHtml, borderPref, $btn, filenameOverride) {
    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,343: Line 1,416:


     var cssLoaded = new Promise(function (resolve) {
     var cssLoaded = new Promise(function (resolve) {
       linkCss.onload = function () {
       linkCss.onload = resolve;
        resolve();
       linkCss.onerror = resolve;
      };
       linkCss.onerror = function () {
        resolve();
      };
     });
     });


Line 1,365: Line 1,434:
     doc.body.innerHTML = printHtml;
     doc.body.innerHTML = printHtml;


     // --- sanitize: kill any inner .print-no-border (when user chose WITH border) ---
    (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 () {
     (function () {
       var stray = doc.querySelectorAll(".print-no-border");
       var stray = doc.querySelectorAll(".print-no-border");
       if (borderPref === "with" && stray.length) {
       if (borderPref === "with" && stray.length) {
         Array.prototype.forEach.call(stray, function (el) {
         Array.prototype.forEach.call(stray, function (el) {
           el.className = el.className
           el.className = (el.className || "")
             .replace(/\bprint-no-border\b/g, "")
             .replace(/\bprint-no-border\b/g, "")
             .trim();
             .trim();
Line 1,377: Line 1,459:
     })();
     })();


    // apply border preference to <html>
     (function () {
     (function () {
       var htmlEl = doc.documentElement;
       var htmlEl = doc.documentElement;
Line 1,389: Line 1,472:
         if (htmlEl.classList) htmlEl.classList.remove("print-no-border");
         if (htmlEl.classList) htmlEl.classList.remove("print-no-border");
         else
         else
           htmlEl.className = htmlEl.className.replace(
           htmlEl.className = (htmlEl.className || "").replace(
             /\bprint-no-border\b/g,
             /\bprint-no-border\b/g,
             ""
             ""
           );
           );
       }
       }
      console.log(
        "[swprint] html class after apply:",
        htmlEl.className || "<empty>"
      );
     })();
     })();


     // Enforce via CSS (covers cases where wrapper class differs)
     // Glue label + body together (extra safety vs. page breaks)
     (function () {
     (function () {
      var css =
        borderPref === "without"
          ? "@media print{.entry-wrapper,.entry-wrapper.print-a4-narrow{border:0!important;box-shadow:none!important;}}"
          : "@media print{.entry-wrapper,.entry-wrapper.print-a4-narrow{border:1px solid #000!important;}}";
       var style = doc.createElement("style");
       var style = doc.createElement("style");
       style.appendChild(doc.createTextNode(css));
       style.textContent =
        "@media print{.sw-keep{break-inside:avoid;page-break-inside:avoid;}}";
       doc.head.appendChild(style);
       doc.head.appendChild(style);
      console.log("[swprint] CSS enforcement injected for:", borderPref);
    })();


    // FINAL INLINE FALLBACK: force the visible wrapper’s border directly
       var pairs = [
    (function () {
         [".article-label-description", ".article-description"],
      // try common wrappers; fall back to first element in body
         [".article-label-reflection", ".article-reflection"],
       var wrapper =
        [".article-label-external-reference", ".article-external-reference"],
         doc.querySelector(".entry-wrapper") ||
        [".article-label-quote", ".article-quote"],
         doc.querySelector(".print-a4-narrow") ||
         [".article-label-modification-date", ".article-modification-date"],
         doc.body.firstElementChild;
      ];


       if (!wrapper) {
       for (var i = 0; i < pairs.length; i++) {
         console.warn("[swprint] no wrapper found for inline border fallback");
         var labelSel = pairs[i][0];
         return;
         var bodySel = pairs[i][1];
      }
        var labels = doc.querySelectorAll(labelSel);
 
        for (var j = 0; j < labels.length; j++) {
      var old = wrapper.getAttribute("style") || "";
          var label = labels[j];
      var force =
          var body = label.nextElementSibling;
        borderPref === "without"
          if (!body || !body.matches(bodySel)) continue;
          ? "border:0!important;"
          var wrap = doc.createElement("div");
          : "border:1px solid #000!important;";
          wrap.className = "sw-keep";
 
          label.parentNode.insertBefore(wrap, label);
      wrapper.setAttribute("style", force + old);
           wrap.appendChild(label);
      console.log(
           wrap.appendChild(body);
        "[swprint] inline border fallback applied on:",
         }
        wrapper.className || wrapper.tagName,
        "pref:",
        borderPref
      );
    })();
 
    // DIAG 1: dump computed border style on the chosen wrapper
    (function () {
      var wrapper =
        doc.querySelector(".entry-wrapper") ||
        doc.querySelector(".print-a4-narrow") ||
        doc.body.firstElementChild;
      if (!wrapper) return;
      var cs = doc.defaultView.getComputedStyle(wrapper);
      console.log(
        "[swprint] computed border:",
        cs.borderTopWidth,
        cs.borderTopStyle,
        cs.borderTopColor,
        "|",
        cs.borderRightWidth,
        cs.borderRightStyle,
        cs.borderRightColor,
        "|",
        cs.borderBottomWidth,
        cs.borderBottomStyle,
        cs.borderBottomColor,
        "|",
        cs.borderLeftWidth,
        cs.borderLeftStyle,
        cs.borderLeftColor
      );
    })();
 
    // DIAG 2: optional loud border, easy to see (comment out after testing)
    (function () {
      if (borderPref === "with") {
        var wrapper =
           doc.querySelector(".entry-wrapper") ||
           doc.querySelector(".print-a4-narrow") ||
          doc.body.firstElementChild;
        if (!wrapper) return;
         // Strong visual to prove it’s applied; remove once confirmed
        wrapper.style.border = "2px dashed red !important";
        console.log("[swprint] TEMP diagnostic border applied (red dashed)");
       }
       }
     })();
     })();
Line 1,488: Line 1,517:
         var txt = (p.textContent || "").replace(/\u00a0/g, " ").trim();
         var txt = (p.textContent || "").replace(/\u00a0/g, " ").trim();
         var onlyBr =
         var onlyBr =
          p.children &&
           p.children.length === 1 &&
           p.children.length === 1 &&
           p.firstElementChild &&
           p.firstElementChild &&
Line 1,500: Line 1,530:
       var root = doc.getElementById("article-content");
       var root = doc.getElementById("article-content");
       if (root) {
       if (root) {
         Array.prototype.slice.call(root.childNodes).forEach(function (n) {
         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, "")) {
           if (n.nodeType === 3 && !n.textContent.replace(/\s+/g, "")) {
             root.removeChild(n);
             root.removeChild(n);
           }
           }
         });
         }
       }
       }
     })();
     })();


     // small inline tweaks
     // inline micro-tweaks for print spacing
     (function () {
     (function () {
       var css =
       var css =
Line 1,515: Line 1,547:
         "  .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-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-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;}" +
        '  [class^\\"article-label-\\"]{margin-top:0!important;}' +
        '  .article-entry-number + [class^\\"article-label-\\"],' +
        '  .link-pdf + [class^\\"article-label-\\"],' +
        '  .article-type + [class^\\"article-label-\\"],' +
        '  .article-metadata + [class^\\"article-label-\\"],' +
        '  .article-images + [class^\\"article-label-\\"],' +
        '  .article-description + [class^\\"article-label-\\"],' +
        '  .article-reflection + [class^\\"article-label-\\"],' +
        '  .article-external-reference + [class^\\"article-label-\\"],' +
        '  .article-quote + [class^\\"article-label-\\"],' +
        '  .article-mod-line + [class^\\"article-label-\\"]{margin-top:0.9mm!important;}' +
         "  .article-label-description + .article-description," +
         "  .article-label-description + .article-description," +
         "  .article-label-reflection + .article-reflection," +
         "  .article-label-reflection + .article-reflection," +
Line 1,543: Line 1,564:
     })();
     })();


     // link tweaks
     // link tweaks (wrapping / underline)
     (function () {
     (function () {
       var styleFix = doc.createElement("style");
       var styleFix = doc.createElement("style");
Line 1,549: Line 1,570:
         "@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}}";
         "@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}}";
       doc.head.appendChild(styleFix);
       doc.head.appendChild(styleFix);
       var refs = doc.querySelectorAll(".article-external-reference a[href]");
       var refs = doc.querySelectorAll(".article-external-reference a[href]");
       Array.prototype.forEach.call(refs, function (a) {
       Array.prototype.forEach.call(refs, function (a) {
Line 1,625: 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,649: 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,670: Line 1,704:
   /* 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,690: Line 1,714:
     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;
     }
     }


     // otherwise fetch by title (modal/home list flow)
     // otherwise fetch by title (modal/home)
     var title =
     var title =
       window.currentEntryTitle ||
       window.currentEntryTitle ||
Line 1,709: Line 1,732:
         ? mw.util.getUrl(title)
         ? mw.util.getUrl(title)
         : "/wiki/" + String(title);
         : "/wiki/" + String(title);
     jQuery
     jQuery
       .get(swPrintCacheBust(pageUrl))
       .get(swPrintCacheBust(pageUrl))
Line 1,727: Line 1,751:
       });
       });
   }
   }
  /* bind current choice anchors (defensive, for Entry pages) */
  function swBindChoiceAnchors() {
    var sel = "#print-with-border, #print-no-border";
    var els = document.querySelectorAll(sel);
    for (var i = 0; i < els.length; i++) {
      (function (el) {
        if (el.__swChoiceBound) return;
        el.__swChoiceBound = true;
        // ensure clickable/accessible
        try {
          el.style.pointerEvents = el.style.pointerEvents || "auto";
          if (!el.getAttribute("role")) el.setAttribute("role", "button");
          if (!el.getAttribute("tabindex")) el.setAttribute("tabindex", "0");
        } catch (e) {}
        function fire(ev) {
          if (ev && ev.preventDefault) ev.preventDefault();
          if (ev && ev.stopImmediatePropagation) ev.stopImmediatePropagation();
          if (ev && ev.stopPropagation) ev.stopPropagation();
          var $a = (window.jQuery && jQuery(el)) || null;
          swHandlePrintChoice(el.id, $a);
          return false;
        }
        // early + normal phases
        el.addEventListener("pointerdown", fire, true);
        el.addEventListener("touchstart", fire, true);
        el.addEventListener("mousedown", fire, true);
        el.addEventListener("click", fire, true);
        el.addEventListener("click", fire, false);
        if (!el.onclick) el.onclick = fire;
        // keyboard
        el.addEventListener(
          "keydown",
          function (e) {
            var k = e.key || e.keyCode;
            if (k === "Enter" || k === 13 || k === " " || k === 32) fire(e);
          },
          true
        );
      })(els[i]);
    }
  }
  /* early global catcher (minimal) */
  (function () {
    if (window.__swprintEarlyCatcher) return;
    window.__swprintEarlyCatcher = true;
    function routeEarly(ev) {
      var t = ev.target;
      if (!t || !t.closest) return;
      var a = t.closest("a#print-with-border, a#print-no-border");
      if (!a) return;
      if (ev.preventDefault) ev.preventDefault();
      if (ev.stopImmediatePropagation) ev.stopImmediatePropagation();
      if (ev.stopPropagation) ev.stopPropagation();
      swHandlePrintChoice(a.id, (window.jQuery && jQuery(a)) || null);
      return false;
    }
    window.addEventListener("pointerdown", routeEarly, true);
    window.addEventListener("touchstart", routeEarly, true);
    window.addEventListener("mousedown", routeEarly, true);
  })();


   /* wiring (namespaced) */
   /* wiring (namespaced) */
Line 1,734: Line 1,826:
     "#print-button, #print-chooser, #print-options",
     "#print-button, #print-chooser, #print-options",
     function (e) {
     function (e) {
       // click on the main [print]
       // main [print] toggler
      // click on the main [print]
       if (jQuery(e.target).closest("#print-button").length) {
       if (jQuery(e.target).closest("#print-button").length) {
         e.preventDefault();
         e.preventDefault();
         var $chooser = swEnsurePrintChooser();
         var $chooser = swEnsurePrintChooser();
 
         $chooser.css({ position: "absolute", zIndex: 99999 });
        // make sure it sits on top & accepts clicks (diagnostic-safe)
         $chooser.css({
          position: "absolute",
          zIndex: 99999,
          background: "#fff",
          padding: "4px 6px",
          border: "1px solid #ddd",
        });
 
         $chooser.toggle();
         $chooser.toggle();
         var visible = $chooser.is(":visible");
         var visible = $chooser.is(":visible");
         jQuery("#show-article").toggleClass("print-opts-open", visible);
         jQuery("#show-article").toggleClass("print-opts-open", visible);


         // Bind native handlers to ALL nodes that currently exist with those IDs
         // ensure anchors are bound (important on Entry pages)
        try {
         swBindChoiceAnchors();
          var nodes = Array.prototype.slice.call(
            document.querySelectorAll(
              '[id="print-with-border"], [id="print-no-border"]'
            )
          );
          console.log("[swprint] chooser toggled; visible=", visible, {
            withCount: document.querySelectorAll('[id="print-with-border"]')
              .length,
            noCount: document.querySelectorAll('[id="print-no-border"]').length,
          });
 
          nodes.forEach(function (el) {
            if (el.__swprintBound) return;
            el.__swprintBound = true;
 
            var handler = function (ev) {
              ev.preventDefault();
              ev.stopPropagation();
              if (ev.stopImmediatePropagation) ev.stopImmediatePropagation();
              var id = el.getAttribute("id") || "";
              console.log("[swprint] NATIVE choice fired ->", id);
              swHandlePrintChoice(id, (window.jQuery && jQuery(el)) || null);
              return false;
            };
 
            // capture = see it before anything else
            el.addEventListener("click", handler, true);
            el.addEventListener("pointerup", handler, true);
          });
        } catch (err) {}
 
        // run visibility diagnostics on the two buttons
        (function swprintDebugChoices() {
          function dump(id) {
            var list = document.querySelectorAll('[id="' + id + '"]');
            for (var i = 0; i < list.length; i++) {
              var el = list[i];
              var cs = window.getComputedStyle(el);
              var r = el.getBoundingClientRect();
              console.log("[swprint][diag]", id, i, {
                tag: el.tagName,
                display: cs.display,
                visibility: cs.visibility,
                opacity: cs.opacity,
                pointerEvents: cs.pointerEvents,
                rect: {
                  x: Math.round(r.x),
                  y: Math.round(r.y),
                  w: Math.round(r.width),
                  h: Math.round(r.height),
                },
                zIndex: cs.zIndex,
              });
            }
          }
          dump("print-with-border");
          dump("print-no-border");
         })();
 
         return;
         return;
       }
       }


       // click on a choice link
       // 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"
Line 1,827: Line 1,850:
   );
   );


   // --- extra safety bindings for Entry page / widgets ---
   // map any <button> inside chooser to its host anchor
 
  // 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);
    }
  );
 
  // If a widget uses <button> inside the chooser, map it to the nearest id node
   jQuery(document).on(
   jQuery(document).on(
     "click.swprintChoiceBtn2",
     "click.swprintChoiceBtn2",
Line 1,867: Line 1,860:
       if (!host) return;
       if (!host) return;
       e.preventDefault();
       e.preventDefault();
      console.log("[swprint] BUTTON inside chooser ->", host.id);
       swHandlePrintChoice(host.id, (window.jQuery && jQuery(host)) || null);
       swHandlePrintChoice(host.id, (window.jQuery && jQuery(host)) || null);
     }
     }
   );
   );


   // also hide choices on ESC; your close-button handler already hides them
   // hide choices on ESC
   jQuery(document).on("keydown.swprint", function (e) {
   jQuery(document).on("keydown.swprint", function (e) {
     if (e && e.keyCode === 27) swHidePrintUI();
     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);
    }
  );


   /* ---------- /Softwear PRINT ---------- */
   /* ---------- /Softwear PRINT ---------- */
Line 1,942: Line 1,976:
   }
   }


   if ($("#show-article-wrapper-entry").length) {
  // paragraph-formatting block
    // Your existing formatParagraphs function
   if (jQuery("#show-article-wrapper-entry").length) {
     function formatParagraphs(text) {
     function formatParagraphs(text) {
       var paragraphs = text.split("\n").filter(function (p) {
      // split on newlines, drop empty lines, wrap each in <p>
         return p.trim() !== "";
       var parts = String(text || "").split("\n");
      });
      var out = [];
      return paragraphs
      for (var i = 0; i < parts.length; i++) {
         .map(function (p) {
         var p = parts[i].replace(/^\s+|\s+$/g, "");
          return "<p>" + p.trim() + "</p>";
         if (p) out.push("<p>" + p + "</p>");
        })
      }
        .join("");
      return out.join("");
     }
     }


     // Check if ".article-description" exists and format its text
     jQuery(
    if ($(".article-description").length) {
      "#show-article .article-description, #show-article .article-reflection"
       var descriptionText = $(".article-description").text();
    ).each(function () {
       var formattedDescription = formatParagraphs(descriptionText);
       var $el = jQuery(this);
      $(".article-description").html(formattedDescription); // Set the formatted text
       if ($el.children("p").length > 0) return; // already formatted by PageForms
    }
       var rawText = $el.text();
 
       $el.html(formatParagraphs(rawText));
    // Check if ".article-reflection" exists and format its text
     });
    if ($(".article-reflection").length) {
       var reflectionText = $(".article-reflection").text();
      var formattedReflection = formatParagraphs(reflectionText);
       $(".article-reflection").html(formattedReflection); // Set the formatted text
     }
   }
   }


Line 2,099: Line 2,128:
     }
     }
   });
   });
  updatePrintSelectionUI();
  hidePrintSelectionOptions();
});
});

Navigation menu