User:CannonProductions/monacobookbeta.css: Difference between revisions

From MediaWiki
Jump to navigationJump to search
No edit summary
No edit summary
Line 1: Line 1:
/* ===== TFWiki Mobile (MonacoBookBeta-ish) — clean + conflict-proof ===== */
/* User:CannonProductions/monacobookbeta.js
@media (max-width: 720px) {
  - Dynamically scales #top-ad iframe banner to fit available width on mobile
  - Locks background scroll when the sidebar (#column-one) is open on mobile
  - Adds html.tf-nav-open while the sidebar is open (for CSS styling)
  - Removes the redundant mobile logo portlet (#p-m-logo) so it doesn’t waste space
*/


  /* --- Base layout: full width, no weird centering --- */
(function () {
   html, body {
   "use strict";
    width: 100% !important;
    max-width: 100% !important;
    margin: 0 !important;
    padding: 0 !important;
    overflow-x: visible !important;
  }


   #globalWrapper,
   // === SETTINGS ===
   #column-content,
   var DEBUG_BADGE = false;
  #content,
   var MOBILE_MAX_WIDTH = 720;
   #bodyContent {
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
    margin: 0 !important;
    padding: 0 !important;
    box-sizing: border-box !important;
  }


   /* breathing room for article text */
   // Banner creative’s native size
   #content, #bodyContent {
   var BASE_W = 468;
    padding-left: 10px !important;
  var BASE_H = 60;
    padding-right: 10px !important;
    overflow-x: hidden !important;
  }


   /* keep "more" / action menus able to overflow */
   // Banner scale limits
  #p-cactions,
   var MIN_SCALE = 0.55;
   #p-cactions .pBody,
   var MAX_SCALE = 1.0;
  #column-content {
    overflow: visible !important;
   }
  #p-cactions {
    position: relative !important;
    z-index: 10000 !important;
  }


   /* Main Page columns stack */
   function onReady(fn) {
  #mw-content-text .mainleft,
    if (document.readyState === "loading") {
  #mw-content-text .mainright {
      document.addEventListener("DOMContentLoaded", fn);
    float: none !important;
     } else {
     width: auto !important;
      fn();
    max-width: 100% !important;
     }
     margin: 0 !important;
    box-sizing: border-box !important;
    text-align: center;
   }
   }


   /* Media never forces overflow */
   function addBadge() {
  img, video, iframe {
     if (!DEBUG_BADGE) return;
     max-width: 100% !important;
     if (!document.body) return;
     height: auto !important;
     if (document.getElementById("js-test-badge")) return;
  }
  .thumb, .thumbinner {
    max-width: 100% !important;
     box-sizing: border-box !important;
  }


  /* Wide tables scroll */
    var d = document.createElement("div");
  #mw-content-text table.wikitable,
    d.id = "js-test-badge";
  #mw-content-text .navbox,
    d.textContent = "User JS RUNNING";
  #mw-content-text table.navbox {
    d.style.cssText =
    display: block !important;
      "position:fixed;top:0;left:0;z-index:999999;" +
    max-width: 100% !important;
      "padding:6px 10px;background:#e11;color:#fff;" +
    overflow-x: auto !important;
      "font:12px sans-serif";
     -webkit-overflow-scrolling: touch;
     document.body.prepend(d);
   }
   }


   /* long text doesn't blow width */
   function isMobileWidth() {
  .mw-parser-output {
     return window.matchMedia("(max-width: " + MOBILE_MAX_WIDTH + "px)").matches;
     overflow-wrap: anywhere !important;
    word-break: break-word !important;
  }
  pre, code {
    white-space: pre-wrap !important;
    word-break: break-word !important;
   }
   }


   /* --- Layering defaults --- */
   // ===== Remove the redundant mobile logo portlet =====
   #p-personal {
   function removeMobileLogoPortlet() {
     position: relative !important;
     var p = document.getElementById("p-m-logo");
     z-index: auto !important;
     if (p && p.parentNode) p.parentNode.removeChild(p);
   }
   }


   /* keep top bar clickable */
   // ===== Banner scaling =====
   #sitemenutop,
   function resetBannerStyles(ad, iframe) {
  #usermenutop,
    if (ad) {
  #mobileusermenu {
      ad.style.height = "";
    position: relative !important;
      ad.style.overflow = "";
     z-index: 1000000 !important;
      ad.style.width = "";
    }
    if (iframe) {
      iframe.style.transform = "";
      iframe.style.transformOrigin = "";
      iframe.style.width = "";
      iframe.style.height = "";
      iframe.style.border = "";
      iframe.style.display = "";
     }
   }
   }


   /* keep banner ad low by default */
   function rescaleBanner() {
  #top-ad,
    var ad = document.getElementById("top-ad");
  #top-ad iframe {
     if (!ad) return;
    position: relative !important;
     z-index: 1 !important;
  }


  /* =========================================================
    var iframe = ad.querySelector("iframe");
    FULL-SCREEN NAV: ONLY when html.tf-nav-open is present
    if (!iframe) return;
    ========================================================= */


  html.tf-nav-open #column-one {
     if (!isMobileWidth()) {
     position: fixed !important;
      resetBannerStyles(ad, iframe);
    top: 0 !important;
      return;
    left: 0 !important;
     }
     right: 0 !important;


     width: 100vw !important;
     iframe.style.width = BASE_W + "px";
     min-width: 100vw !important;
     iframe.style.height = BASE_H + "px";
     max-width: none !important;
    iframe.style.border = "0";
    iframe.style.display = "block";
     iframe.style.transformOrigin = "top left";


     height: 100vh !important;
     var available = ad.getBoundingClientRect().width || window.innerWidth;


     margin: 0 !important;
     var scale = available / BASE_W;
     padding: 0 !important;
     if (scale > MAX_SCALE) scale = MAX_SCALE;
    if (scale < MIN_SCALE) scale = MIN_SCALE;


     overflow-y: auto !important;
     iframe.style.transform = "scale(" + scale.toFixed(4) + ")";
    overflow-x: hidden !important;
    -webkit-overflow-scrolling: touch;


     z-index: 999999 !important;
     ad.style.width = "100%";
     background: #fff !important;
     ad.style.overflow = "hidden";
     box-sizing: border-box !important;
     ad.style.height = (BASE_H * scale) + "px";
   }
   }


   /* Stretch the sidebar contents to match the full width */
   // ===== Nav open detection =====
  html.tf-nav-open #column-one .portlet,
   function isNavOpen() {
   html.tf-nav-open #column-one .pBody,
    var nav = document.getElementById("column-one");
  html.tf-nav-open #column-one ul,
     if (!nav) return false;
  html.tf-nav-open #column-one form,
 
  html.tf-nav-open #column-one fieldset {
     var cs = window.getComputedStyle(nav);
     width: 100% !important;
     if (!cs || cs.display === "none" || cs.visibility === "hidden") return false;
     max-width: none !important;
 
     box-sizing: border-box !important;
     var r = nav.getBoundingClientRect();
    float: none !important;
     return r.width > 40 && r.height > 40;
     margin: 0 !important;
     padding: 0 !important;
   }
   }


   /* Full-width menu lists + big tap targets */
   // ===== Nav scroll locking + html class =====
   html.tf-nav-open #column-one ul {
   function setScrollLocked(locked) {
    list-style: none !important;
    if (locked) {
      document.documentElement.style.overflow = "hidden";
      document.body.style.overflow = "hidden";
      document.body.setAttribute("data-nav-locked", "1");
    } else {
      if (document.body.getAttribute("data-nav-locked") === "1") {
        document.documentElement.style.overflow = "";
        document.body.style.overflow = "";
        document.body.removeAttribute("data-nav-locked");
      }
    }
   }
   }
   html.tf-nav-open #column-one li a {
 
    display: block !important;
   function updateNavLockAndClass() {
     width: 100% !important;
    if (!isMobileWidth()) {
     box-sizing: border-box !important;
      setScrollLocked(false);
     padding: 14px 16px !important;
      document.documentElement.classList.remove("tf-nav-open");
     font-size: 18px !important;
      return;
     line-height: 1.2 !important;
     }
    border-bottom: 1px solid rgba(0,0,0,0.10) !important;
 
     text-decoration: none !important;
     var open = isNavOpen();
     setScrollLocked(open);
 
     if (open) {
      document.documentElement.classList.add("tf-nav-open");
     } else {
      document.documentElement.classList.remove("tf-nav-open");
     }
   }
   }


   /* Hide the redundant big logo image above NAVIGATION */
   // ===== Plumbing =====
   html.tf-nav-open #column-one #p-m-logo {
   var t = null;
     display: none !important;
  function scheduleAll() {
    if (t) clearTimeout(t);
    t = setTimeout(function () {
      removeMobileLogoPortlet();
      rescaleBanner();
      updateNavLockAndClass();
     }, 60);
   }
   }


   /* (Optional) If another logo block shows up, hide it too */
   function installObservers() {
  html.tf-nav-open #column-one #p-logo {
    // Do ASAP
     display: none !important;
    removeMobileLogoPortlet();
 
    // Run once now
    rescaleBanner();
    updateNavLockAndClass();
 
    // Re-run on resize/rotate
    window.addEventListener("resize", scheduleAll);
    window.addEventListener("orientationchange", scheduleAll);
 
    // MediaWiki dynamic content hook
    if (window.mw && mw.hook) {
      mw.hook("wikipage.content").add(function () {
        scheduleAll();
      });
    }
 
    // Watch for DOM changes
    var obs = new MutationObserver(function () {
      scheduleAll();
     });
    obs.observe(document.documentElement, { childList: true, subtree: true, attributes: true });
 
    // Click safety
    document.addEventListener("click", function () {
      setTimeout(updateNavLockAndClass, 0);
    });
   }
   }


   /* Hide the banner ad while nav is open */
   onReady(function () {
  html.tf-nav-open #top-ad {
    addBadge();
     display: none !important;
     installObservers();
   }
   });
}
})();

Revision as of 12:58, 30 December 2025

/* User:CannonProductions/monacobookbeta.js
   - Dynamically scales #top-ad iframe banner to fit available width on mobile
   - Locks background scroll when the sidebar (#column-one) is open on mobile
   - Adds html.tf-nav-open while the sidebar is open (for CSS styling)
   - Removes the redundant mobile logo portlet (#p-m-logo) so it doesn’t waste space
*/

(function () {
  "use strict";

  // === SETTINGS ===
  var DEBUG_BADGE = false;
  var MOBILE_MAX_WIDTH = 720;

  // Banner creative’s native size
  var BASE_W = 468;
  var BASE_H = 60;

  // Banner scale limits
  var MIN_SCALE = 0.55;
  var MAX_SCALE = 1.0;

  function onReady(fn) {
    if (document.readyState === "loading") {
      document.addEventListener("DOMContentLoaded", fn);
    } else {
      fn();
    }
  }

  function addBadge() {
    if (!DEBUG_BADGE) return;
    if (!document.body) return;
    if (document.getElementById("js-test-badge")) return;

    var d = document.createElement("div");
    d.id = "js-test-badge";
    d.textContent = "User JS RUNNING";
    d.style.cssText =
      "position:fixed;top:0;left:0;z-index:999999;" +
      "padding:6px 10px;background:#e11;color:#fff;" +
      "font:12px sans-serif";
    document.body.prepend(d);
  }

  function isMobileWidth() {
    return window.matchMedia("(max-width: " + MOBILE_MAX_WIDTH + "px)").matches;
  }

  // ===== Remove the redundant mobile logo portlet =====
  function removeMobileLogoPortlet() {
    var p = document.getElementById("p-m-logo");
    if (p && p.parentNode) p.parentNode.removeChild(p);
  }

  // ===== Banner scaling =====
  function resetBannerStyles(ad, iframe) {
    if (ad) {
      ad.style.height = "";
      ad.style.overflow = "";
      ad.style.width = "";
    }
    if (iframe) {
      iframe.style.transform = "";
      iframe.style.transformOrigin = "";
      iframe.style.width = "";
      iframe.style.height = "";
      iframe.style.border = "";
      iframe.style.display = "";
    }
  }

  function rescaleBanner() {
    var ad = document.getElementById("top-ad");
    if (!ad) return;

    var iframe = ad.querySelector("iframe");
    if (!iframe) return;

    if (!isMobileWidth()) {
      resetBannerStyles(ad, iframe);
      return;
    }

    iframe.style.width = BASE_W + "px";
    iframe.style.height = BASE_H + "px";
    iframe.style.border = "0";
    iframe.style.display = "block";
    iframe.style.transformOrigin = "top left";

    var available = ad.getBoundingClientRect().width || window.innerWidth;

    var scale = available / BASE_W;
    if (scale > MAX_SCALE) scale = MAX_SCALE;
    if (scale < MIN_SCALE) scale = MIN_SCALE;

    iframe.style.transform = "scale(" + scale.toFixed(4) + ")";

    ad.style.width = "100%";
    ad.style.overflow = "hidden";
    ad.style.height = (BASE_H * scale) + "px";
  }

  // ===== Nav open detection =====
  function isNavOpen() {
    var nav = document.getElementById("column-one");
    if (!nav) return false;

    var cs = window.getComputedStyle(nav);
    if (!cs || cs.display === "none" || cs.visibility === "hidden") return false;

    var r = nav.getBoundingClientRect();
    return r.width > 40 && r.height > 40;
  }

  // ===== Nav scroll locking + html class =====
  function setScrollLocked(locked) {
    if (locked) {
      document.documentElement.style.overflow = "hidden";
      document.body.style.overflow = "hidden";
      document.body.setAttribute("data-nav-locked", "1");
    } else {
      if (document.body.getAttribute("data-nav-locked") === "1") {
        document.documentElement.style.overflow = "";
        document.body.style.overflow = "";
        document.body.removeAttribute("data-nav-locked");
      }
    }
  }

  function updateNavLockAndClass() {
    if (!isMobileWidth()) {
      setScrollLocked(false);
      document.documentElement.classList.remove("tf-nav-open");
      return;
    }

    var open = isNavOpen();
    setScrollLocked(open);

    if (open) {
      document.documentElement.classList.add("tf-nav-open");
    } else {
      document.documentElement.classList.remove("tf-nav-open");
    }
  }

  // ===== Plumbing =====
  var t = null;
  function scheduleAll() {
    if (t) clearTimeout(t);
    t = setTimeout(function () {
      removeMobileLogoPortlet();
      rescaleBanner();
      updateNavLockAndClass();
    }, 60);
  }

  function installObservers() {
    // Do ASAP
    removeMobileLogoPortlet();

    // Run once now
    rescaleBanner();
    updateNavLockAndClass();

    // Re-run on resize/rotate
    window.addEventListener("resize", scheduleAll);
    window.addEventListener("orientationchange", scheduleAll);

    // MediaWiki dynamic content hook
    if (window.mw && mw.hook) {
      mw.hook("wikipage.content").add(function () {
        scheduleAll();
      });
    }

    // Watch for DOM changes
    var obs = new MutationObserver(function () {
      scheduleAll();
    });
    obs.observe(document.documentElement, { childList: true, subtree: true, attributes: true });

    // Click safety
    document.addEventListener("click", function () {
      setTimeout(updateNavLockAndClass, 0);
    });
  }

  onReady(function () {
    addBadge();
    installObservers();
  });
})();