MediaWiki:Common.js: Difference between revisions

Jump to navigation Jump to search
no edit summary
No edit summary
Tag: Manual revert
No edit summary
Line 1,368: Line 1,368:
         // Inject the printable HTML
         // Inject the printable HTML
         doc.body.innerHTML = $print.prop("outerHTML");
         doc.body.innerHTML = $print.prop("outerHTML");
        // --- PDF-friendly links for Chrome on macOS ---
        // 1) Add a tiny print-only CSS override to keep anchors as one box.
        var linkCssFix = doc.createElement("style");
        linkCssFix.textContent = `
        @media print {
          /* Keep anchor boxes intact so Chrome preserves the PDF annotation */
          .article-external-reference a,
          .link-pdf a {
            white-space: nowrap !important;
            word-break: normal !important;
            overflow-wrap: normal !important;
            text-decoration: underline;
          }
          /* Allow wrapping outside the anchor instead */
          .article-external-reference {
            overflow-wrap: anywhere;
            word-break: break-word;
          }
          /* Defensive: make sure anchors have a box */
          a[href] { position: relative; }
        }`;
        doc.head.appendChild(linkCssFix);
        // 2) Normalize long link text so it doesn't force wrapping inside anchors.
        (function () {
          // Shorten long visible URLs in external references, keep href intact
          var refs = doc.querySelectorAll(".article-external-reference a[href]");
          refs.forEach(function (a) {
            var txt = (a.textContent || "").trim();
            var href = a.getAttribute("href") || "";
            var looksLongUrl = /^https?:\/\//i.test(txt) && txt.length > 60;
            if (looksLongUrl) {
              try {
                var u = new URL(href, doc.baseURI);
                var label = u.hostname + (u.pathname.replace(/\/$/, "") ? u.pathname : "");
                if (label.length > 40) label = label.slice(0, 37) + "…";
                a.textContent = label;
              } catch (e) {
                a.textContent = "Link";
              }
            }
            // Ensure single-box anchors
            a.style.whiteSpace = "nowrap";
            a.style.wordBreak = "normal";
            a.style.overflowWrap = "normal";
          });
          // Icon links ([PDF⤴] [WEB⤴]) are short; still enforce single-box
          doc.querySelectorAll(".link-pdf a[href]").forEach(function (a) {
            a.style.whiteSpace = "nowrap";
            a.style.wordBreak = "normal";
            a.style.overflowWrap = "normal";
          });
        })();


         // Wait helpers
         // Wait helpers

Navigation menu