MediaWiki:Common.js

From Eegmaster
Jump to navigation Jump to search

Note: After publishing, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5.
/* Any JavaScript here will be loaded for all users on every page load. */

// Check if "iframe=true" is in the URL
if ( window.location.search.indexOf('iframe=true') !== -1 ) {
    // Add the class to the <body> tag
    document.body.classList.add('hide-wiki-ui');
}

// Code to send height for use by iframe in atlas
// Send the height of the content to the parent window
(function() {
    function notifyParent() {
        // Calculate the actual height of the content
        var height = document.documentElement.scrollHeight;
        console.log("Reporting height:", height);
        console.log("Body height:", document.body.offsetHeight);
        
        // Send height to the parent window
        window.parent.postMessage({
            'frameHeight': height,
            'location': window.location.href
        }, 'https://eegmaster.com');
    }

    // Run on initial load
    window.addEventListener('load', notifyParent);
    // Run when the window resizes (handles orientation changes)
    // window.addEventListener('resize', notifyParent);

    // Minerva specific: Watch for DOM changes (like expanding sections)
    var observer = new MutationObserver(notifyParent);
    observer.observe(document.body, { 
        attributes: true, 
        childList: true, 
        subtree: true 
    });
})();

// Prevents clicks from working in iframe
// document.addEventListener('click', function(e) {
//     var target = e.target.closest('a');
//     if (target) {
//         e.preventDefault();
//         console.log("Navigation blocked: " + target.href);
//     }
// }, true);