Skip to content
This repository has been archived by the owner on Feb 4, 2021. It is now read-only.

Commit

Permalink
Create displaymessage.js
Browse files Browse the repository at this point in the history
We call this code, so we should have a local copy of it in the repo to be able to change and fix things.
  • Loading branch information
Technical-13 committed Oct 1, 2013
1 parent d547b12 commit cace168
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions src/User-Timotheus-Canens/displaymessage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/**
* The old mw.util.jsMessage function before https://gerrit.wikimedia.org/r/#/c/17605/, which
* introduced the silly auto-hide function. Also with the original styles.
* Add a little box at the top of the screen to inform the user of
* something, replacing any previous message.
* Calling with no arguments, with an empty string or null will hide the message
*
* @param message {mixed} The DOM-element, jQuery object or HTML-string to be put inside the message box.
* @param className {String} 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 displayMessage( message, className ){
if ( !arguments.length || message === '' || message === null ) {
$( '#display-message' ).empty().hide();
return true; // Emptying and hiding message is intended behaviour, return true
} else {
// We special-case skin structures provided by the software. Skins that
// choose to abandon or significantly modify our formatting can just define
// an mw-js-message div to start with.
var $messageDiv = $( '#display-message' );
if ( !$messageDiv.length ) {
$messageDiv = $( '<div id="display-message" style="margin:1em;padding:0.5em 2.5%;border:solid 1px #ddd;background-color:#fcfcfc;font-size: 0.8em"></div>' );
if ( mw.util.$content.length ) {
mw.util.$content.prepend( $messageDiv );
} else {
return false;
}
}
if ( className ) {
$messageDiv.prop( 'class', 'display-message-' + className );
}
if ( typeof message === 'object' ) {
$messageDiv.empty();
$messageDiv.append( message );
} else {
$messageDiv.html( message );
}
$messageDiv.slideDown();
return true;
}
}

0 comments on commit cace168

Please sign in to comment.