Jump to content

MediaWiki:Common.js: Difference between revisions

From Impact Evaluation Foundation
No edit summary
Run after the page is ready; header slogan moved to MediaWiki:Sitetitle; remove duplicate Termly loader; fix mobile footer bug
 
(38 intermediate revisions by the same user not shown)
Line 1: Line 1:
document.addEventListener('DOMContentLoaded', function () {
/* Site-wide JavaScript for IEF.wiki.
    console.log('JavaScript loaded successfully!');
* - The header slogan now comes from [[MediaWiki:Sitetitle]], so no script is needed for it.
    const toggleButton = document.createElement('button');
* - Termly's cookie banner is loaded by LocalSettings.php, so it is not loaded a second time here.
    toggleButton.innerText = 'Toggle Day/Night Mode';
* - Everything below waits until the page is ready (it used to run too early and fail).
    toggleButton.classList.add('toggle-button');
*/
    document.body.appendChild(toggleButton);
$( function () {
var disclaimer = 'IEF.wiki is open-source. All content, data, and information contributed to the IEF.wiki is made available under the CC0 1.0 Universal (Public Domain Dedication) license. This means that anyone is free to: Copy, modify, distribute, and use the content for any purpose, including commercial purposes, without asking for permission or providing attribution.';
var contact = 'IEF.wiki is a platform developed by We Are Not Limited (registered in Ireland, registration number 791583). For inquiries, you can reach us via email at hello@ief.wiki or by phone at +353 87 450 8112.';


    toggleButton.addEventListener('click', function () {
if ( document.body.classList.contains( 'skin-vector-2022' ) ) {
        const isDark = document.body.classList.toggle('dark-mode');
var footer = document.querySelector( '#footer-info' );
        localStorage.setItem('theme', isDark ? 'dark' : 'light');
if ( footer ) {
    });
[ disclaimer, contact ].forEach( function ( text ) {
 
var li = document.createElement( 'li' );
    if (localStorage.getItem('theme') === 'dark') {
li.textContent = text;
        document.body.classList.add('dark-mode');
footer.appendChild( li );
    }
} );
});
}
 
} else {
 
var footerMinerva = document.querySelector( '#footer-info-lastmod' );
 
if ( footerMinerva ) {
const lightThemeVars = {
footerMinerva.innerHTML = disclaimer + '<br><br>' + contact;
"background-color-base": "#e6e6dd", // Light Beige
"text-color-base": "#000000"
};
 
const darkThemeVars = {
"background-color-base": "#ededed", // light gray, dark theme turns to #121212
"text-color-base": "#2e2e2e"
};
 
// Function to update CSS variables
function applyThemeVariables(themeVars) {
Object.keys(themeVars).forEach(key => {
document.documentElement.style.setProperty(`--${key}`, themeVars[key]);
});
}
 
// Function to update .mw-logo-icon styles based on theme
function updateLogoIconStyles(isDarkMode) {
const logoIcon = document.querySelector('.mw-logo-icon');
if (logoIcon) {
if (isDarkMode) {
// Apply dark mode styles
logoIcon.style.mixBlendMode = 'difference';
logoIcon.style.backgroundColor = 'transparent';
} else {
// Reset styles for light mode
logoIcon.style.mixBlendMode = '';
logoIcon.style.backgroundColor = '';
}
}
}
}
}
} );
 
// Observer to monitor class changes on <html> element
const observer = new MutationObserver(() => {
const isDarkMode = document.documentElement.classList.contains("skin-theme-clientpref-night");
applyThemeVariables(isDarkMode ? darkThemeVars : lightThemeVars);
updateLogoIconStyles(isDarkMode); // Update logo icon styles based on theme
});
 
// Observe changes to the class attribute on <html>
observer.observe(document.documentElement, { attributes: true, attributeFilter: ["class"] });
 
// Initial application based on current class list
const isDarkMode = document.documentElement.classList.contains("skin-theme-clientpref-night");
applyThemeVariables(isDarkMode ? darkThemeVars : lightThemeVars);
updateLogoIconStyles(isDarkMode); // Apply logo icon styles based on the initial theme
 
 
 
(function () {
    // Check if the notification was shown within the last 30 days
    const lastShown = localStorage.getItem('bookBannerLastShown');
    const now = new Date().getTime();
    const ONE_MONTH = 30 * 24 * 60 * 60 * 1000;
 
    if (lastShown && now - lastShown < ONE_MONTH) {
        return; // Do not show the banner
    }
 
    // Function to display the popup
    const showPopup = () => {
        // Create the popup element
        const bannerHTML = `
            <div id="book-banner-popup" class="book-banner-popup">
                <h3>Subscribe to our newsletter for a free eBook, Regenaissance: The Call to Heal by Sharon Gal-Or, and expert MRV insights delivered to your inbox!</h3>
                <div>
                    <a href="https://iefwiki.substack.com/embed/" target="_blank" class="book-banner-link" style="color: #121212;">Click to Subscribe</a>
                </div>
                <button id="book-banner-close" class="book-banner-close">×</button>
            </div>
        `;
        const container = document.createElement('div');
        container.innerHTML = bannerHTML;
        document.body.appendChild(container);
 
        // Set display to block to ensure the popup is visible
        const bannerPopup = document.getElementById('book-banner-popup');
        bannerPopup.style.display = 'block';
 
        // Add event listener for the close button
        document.getElementById('book-banner-close').addEventListener('click', function () {
            bannerPopup.style.display = 'none';
            localStorage.setItem('bookBannerLastShown', new Date().getTime());
        });
    };
 
    // Delay the popup display by 5 seconds
    setTimeout(showPopup, 5000);
})();

Latest revision as of 08:38, 15 November 2026

/* Site-wide JavaScript for IEF.wiki.
 * - The header slogan now comes from [[MediaWiki:Sitetitle]], so no script is needed for it.
 * - Termly's cookie banner is loaded by LocalSettings.php, so it is not loaded a second time here.
 * - Everything below waits until the page is ready (it used to run too early and fail).
 */
$( function () {
	var disclaimer = 'IEF.wiki is open-source. All content, data, and information contributed to the IEF.wiki is made available under the CC0 1.0 Universal (Public Domain Dedication) license. This means that anyone is free to: Copy, modify, distribute, and use the content for any purpose, including commercial purposes, without asking for permission or providing attribution.';
	var contact = 'IEF.wiki is a platform developed by We Are Not Limited (registered in Ireland, registration number 791583). For inquiries, you can reach us via email at hello@ief.wiki or by phone at +353 87 450 8112.';

	if ( document.body.classList.contains( 'skin-vector-2022' ) ) {
		var footer = document.querySelector( '#footer-info' );
		if ( footer ) {
			[ disclaimer, contact ].forEach( function ( text ) {
				var li = document.createElement( 'li' );
				li.textContent = text;
				footer.appendChild( li );
			} );
		}
	} else {
		var footerMinerva = document.querySelector( '#footer-info-lastmod' );
		if ( footerMinerva ) {
			footerMinerva.innerHTML = disclaimer + '<br><br>' + contact;
		}
	}
} );