MediaWiki:Common.js: Difference between revisions

Jump to navigation Jump to search
1,392 bytes removed ,  Yesterday at 11:59
no edit summary
No edit summary
No edit summary
Line 1,370: Line 1,370:


         // Remove “empty” optional sections so they don’t leave gaps in print.
         // Remove “empty” optional sections so they don’t leave gaps in print.
         // --- Compact vertical spacing & report gaps in the print iframe ---
         // Kill UA paragraph margins & set compact rhythm inside the print iframe
         (function compactAndReport(doc) {
         var compactCSS = doc.createElement("style");
          // 1) Trim margins everywhere in #article-content. Rely on your hairline padding instead.
        compactCSS.textContent = `
          var css = doc.createElement("style");
        @media print {
          css.textContent =
          /* nuke default <p> margins everywhere in the printable area */
            "@media print{" +
          .print-only p { margin: 0 !important; }
            "#article-content>*{margin-top:0!important;margin-bottom:0!important}" +
            // keep your hairline look but ensure it’s not huge
            ".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:6px!important}" +
            // remove hairline on the very last child to avoid a trailing gap
            "#article-content>:last-child{padding-bottom:0!important}" +
            "#article-content>:last-child::after{content:none!important}" +
            // kill any accidental block that’s truly empty (divs/spans)
            "#article-content div:empty,#article-content p:empty{display:none!important;height:0!important;padding:0!important;border:0!important}" +
            "}";
          doc.head.appendChild(css);


           // 2) Extra cleanup: remove empty DIV shells that still contain only whitespace
           /* compact vertical rhythm between top-level blocks */
           (function removeEmptyDivs() {
           #article-content > * { margin-top: 0 !important; margin-bottom: 0 !important; }
            var nodes = doc.querySelectorAll("#article-content div");
            for (var i = 0; i < nodes.length; i++) {
              var el = nodes[i];
              if (!el.firstElementChild) {
                var t = (el.textContent || "")
                  .replace(/\u00A0/g, " ")
                  .replace(/\u200B/g, "")
                  .trim();
                if (!t && el.parentNode) el.parentNode.removeChild(el);
              }
            }
          })();


           // 3) GAP reporter — logs where any unexpected space (>8px) occurs between siblings
           /* small, consistent space only between siblings (tweak as you like) */
          (function reportGaps() {
          #article-content > * + * { margin-top: 2mm !important; }
            var container = doc.getElementById("article-content");
 
            if (!container) return;
          /* paragraphs inside text sections: very small trailing space */
            var kids = [];
          .article-description p,
            for (
          .article-reflection p,
              var n = container.firstElementChild;
          .article-external-reference p,
              n;
          .article-quote { margin: 0 0 1.2mm 0 !important; }
              n = n.nextElementSibling
          .article-description p:last-child,
            ) {
          .article-reflection p:last-child,
              // skip nodes that are display:none (offsetParent null) or zero-height
          .article-external-reference p:last-child { margin-bottom: 0 !important; }
              if (!n.offsetParent || n.offsetHeight === 0) continue;
 
              kids.push(n);
          /* labels sit tight with the block that follows */
            }
          .article-label-description,
            for (var i = 0; i < kids.length - 1; i++) {
          .article-label-reflection,
              var a = kids[i],
          .article-label-external-reference,
                b = kids[i + 1];
          .article-label-quote,
              var gap =
          .article-label-modification-date { margin: 0 !important; }
                b.getBoundingClientRect().top -
 
                (a.getBoundingClientRect().top +
          /* hairline sections already use padding-bottom;
                  a.getBoundingClientRect().height);
            make sure there's no extra margin on either side */
              if (gap > 8) {
          .article-entry-number,
                console.log(
          .link-pdf,
                  "[print] GAP",
          .article-type,
                  Math.round(gap) + "px",
          .article-metadata,
                  "between",
          .article-images,
                  a.className || a.tagName,
          .article-description,
                  "→",
          .article-reflection,
                  b.className || b.tagName
          .article-external-reference,
                );
          .article-quote,
              }
          .article-mod-line { margin: 0 !important; }
            }
        }
          })();
        `;
         })(doc);
         doc.head.appendChild(compactCSS);


         // --- PDF-friendly links for Chrome on macOS ---
         // --- PDF-friendly links for Chrome on macOS ---

Navigation menu