User:Bawolff/sandbox/test.js
< User:Bawolff | sandbox
Note: After saving, you may have to bypass your browser's cache to see the changes. Mozilla / Firefox / Safari: hold down Shift while clicking Reload, or press Ctrl-Shift-R (Cmd-Shift-R on Apple Mac); IE: hold Ctrl while clicking Refresh, or press Ctrl-F5; Konqueror: simply click the Reload button, or press F5; Opera users may need to completely clear their cache in Tools→Preferences. — More skins
/**
* Add a cute little box at the top of the screen to inform the user of
* something, replacing any preexisting message.
*
* @param String -or- Dom Object message HTML to be put inside the right div
* @param String className Used in adding a class; should be different for
each
* call to allow CSS/JS to hide different boxes. null = no class used.
* @return Boolean True on success, false on failure
*/
function jsMsg( message, className ) {
if ( !document.getElementById ) {
return false;
}
// We special-case skin structures provided by the software. Skins that
// choose to abandon or significantly modify our formatting can justdefine
// an mw-js-message div to start with.
var messageDiv = document.getElementById( 'mw-js-message' );
if ( !messageDiv ) {
messageDiv = document.createElement('div');
messageDiv.id = 'mw-js-message';
var container = document.getElementById('article')
|| document.getElementById('content')
|| document.getElementById('mw_content');
if (!container) return false;
container.insertBefore(messageDiv, container.firstChild);
}
if( className ) {
messageDiv.setAttribute( 'class', 'mw-js-message-'+className );
}
if (typeof message === 'object') {
while (messageDiv.hasChildNodes()) // Remove old content
messageDiv.removeChild(messageDiv.firstChild);
messageDiv.appendChild(message); // Append new content
}
else {
messageDiv.innerHTML = message;
}
return true;
}