User:Bawolff/sandbox/test.js

/** * 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; }