MediaWiki:Common.js: Difference between revisions

Jump to navigation Jump to search
no edit summary
No edit summary
No edit summary
Line 1,366: Line 1,366:


         // Remove “empty” optional sections so they don’t leave gaps in print.
         // Remove “empty” optional sections so they don’t leave gaps in print.
         // --- SQUASH VERTICAL GAPS ABOVE SECTIONS (print-only) ---
         // --- CLEAN: remove empty paragraphs/whitespace nodes that create phantom gaps
        (function () {
          // 1) Drop <p> that are visually empty or only &nbsp;/whitespace
          var ps = doc.querySelectorAll("#article-content p");
          Array.prototype.forEach.call(ps, function (p) {
            var txt = (p.textContent || "").replace(/\u00a0/g, " ").trim();
            // also ignore spans that were left with only <br>
            var onlyBr =
              p.children.length === 1 && p.firstElementChild.tagName === "BR";
            if (
              (!txt &&
                !p.querySelector("img, a, strong, em, span:not(:empty)")) ||
              onlyBr
            ) {
              p.parentNode && p.parentNode.removeChild(p);
            }
          });
 
          // 2) Remove pure-whitespace text nodes directly under #article-content
          var root = doc.getElementById("article-content");
          if (root) {
            Array.prototype.slice.call(root.childNodes).forEach(function (n) {
              if (n.nodeType === 3 && !n.textContent.replace(/\s+/g, "")) {
                root.removeChild(n);
              }
            });
          }
        })();
 
         (function () {
         (function () {
           var css =
           var css =
             "@media print{" +
             "@media print{" +
             /* 1) Kill all margins/paddings on direct children inside the print content */
             // Paragraphs inside rich text: no big UA margins, tiny rhythm
            "  #article-content > *{margin:0!important;padding:0!important;}" +
             "  .article-description p,.article-reflection p,.article-external-reference p,.article-quote p{margin:0 0 1.2mm!important;}" +
            /* 2) Ensure paragraphs inside rich text don’t re-introduce big gaps */
             "  .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,.article-reflection p,.article-external-reference p,.article-quote p{margin:0!important;}" +
             // Ruled sections: keep only tiny space for the hairline
             "  .article-description p + p,.article-reflection p + p{margin-top:1.2mm!important;}" +
             "  .article-entry-number,.link-pdf,.article-type,.article-metadata,.article-images,.article-description,.article-reflection,.article-external-reference,.article-quote,.article-mod-line{" +
             /* 3) All ruled blocks: keep only a tiny bottom padding for the hairline */
             "    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:1.2mm!important;" /* space for the hairline */ +
             "  }" +
             "  }" +
             /* 4) Labels: zero their own top margin by default */
             // Labels: reset default top margin, then add ONE small spacer when following any ruled block
             "  .article-label-description," +
             "  .article-label-description,.article-label-reflection,.article-label-external-reference,.article-label-quote,.article-label-modification-date{margin-top:0!important;}" +
            "  .article-label-reflection," +
            "  .article-label-external-reference," +
            "  .article-label-quote," +
            "  .article-label-modification-date{" +
            "    margin-top:0!important;" +
            "  }" +
            /* 5) Add ONE uniform spacer above labels when they follow any ruled block */
             "  .article-entry-number + .article-label-description," +
             "  .article-entry-number + .article-label-description," +
             "  .link-pdf + .article-label-description," +
             "  .link-pdf + .article-label-description," +
Line 1,406: Line 1,416:
             "  .article-external-reference + .article-label-quote," +
             "  .article-external-reference + .article-label-quote," +
             "  .article-quote + .article-label-modification-date{" +
             "  .article-quote + .article-label-modification-date{" +
             "    margin-top:1.2mm!important;" /* <- tweak this single value to taste */ +
             "    margin-top:0.9mm!important;" /* tweak this ONE value to taste */ +
             "  }" +
             "  }" +
             /* 6) Also no extra gap between a label and its body */
             // No gap between a label and its own body
             "  .article-label-description + .article-description," +
             "  .article-label-description + .article-description," +
             "  .article-label-reflection + .article-reflection," +
             "  .article-label-reflection + .article-reflection," +
             "  .article-label-external-reference + .article-external-reference," +
             "  .article-label-external-reference + .article-external-reference," +
             "  .article-label-quote + .article-quote," +
             "  .article-label-quote + .article-quote," +
             "  .article-label-modification-date + .article-modification-date{" +
             "  .article-label-modification-date + .article-modification-date{margin-top:0!important;}" +
             "   margin-top:0!important;" +
            // Metadata grid: avoid bottom gap
             "  }" +
             " .article-metadata{margin-bottom:0!important;}" +
             /* 7) Last block on the page: remove rule/padding to avoid tail gap */
            // Title/link row: avoid extra gap from inner elements
             "  .article-title-link{margin:0!important;padding:0!important;}" +
             "  .article-title-link > *{margin:0!important;}" +
            "  .link-pdf{margin-top:0!important;}" +
            // Final block: no trailing hairline
             "  #article-content > :last-child{padding-bottom:0!important;}" +
             "  #article-content > :last-child{padding-bottom:0!important;}" +
             "  #article-content > :last-child::after{content:none!important;}" +
             "  #article-content > :last-child::after{content:none!important;}" +

Navigation menu