MediaWiki:Common.js: Difference between revisions

Ensure darkModeNoticeElem always defined regardless of previous dismissal of prompt (in case user clicks 'Dark Mode' links)
(Rework dark mode implementation, prevents FOUC on page load)
(Ensure darkModeNoticeElem always defined regardless of previous dismissal of prompt (in case user clicks 'Dark Mode' links))
Line 603: Line 603:


// Dark mode
// Dark mode
// Initialize element
var newDiv = document.createElement('div');
newDiv.classList.toggle('noticebox');
newDiv.style.cssText = 'display:none; max-width:100%; width:100%; text-align:center;';
darkModeNoticeElem = newDiv;
if (!darkModeNoticeDismissed) {
if (!darkModeNoticeDismissed) {
// Initialize element
const cnElem = document.getElementById('mw-content');
var newDiv = document.createElement('div');
// TODO - Define new class called noticebox or something
newDiv.classList.toggle('noticebox');
newDiv.style.cssText = 'display:none; max-width:100%; width:100%; text-align:center;';
darkModeNoticeElem = newDiv;
 
const cnElem = document.getElementById('mw-content'); // centralNotice
if (cnElem !== null) {
if (cnElem !== null) {
cnElem.insertBefore(darkModeNoticeElem, cnElem.firstChild);
cnElem.insertBefore(darkModeNoticeElem, cnElem.firstChild);
//cnElem.appendChild(darkModeNoticeElem);
}
}