From c52a562d2c87ad440eae24863190642860c47e4b Mon Sep 17 00:00:00 2001 From: Krinkle Date: Thu, 9 Dec 2010 23:42:29 +0000 Subject: [PATCH] Added a way to hide the jsMessage by calling with empty string, null or no arguments --- resources/mediawiki.util/mediawiki.util.js | 53 +++++++++++++--------- 1 file changed, 31 insertions(+), 22 deletions(-) diff --git a/resources/mediawiki.util/mediawiki.util.js b/resources/mediawiki.util/mediawiki.util.js index 1db83842ca..a646eeb3b4 100644 --- a/resources/mediawiki.util/mediawiki.util.js +++ b/resources/mediawiki.util/mediawiki.util.js @@ -320,37 +320,46 @@ * Add a little box at the top of the screen to inform the user of * something, replacing any previous message. * - * @param message mixed DOM-element or HTML to be put inside the message box + * @param message mixed The DOM-element or HTML-string to be put inside the message box] + * Calling with no arguments, with an empty string or null will hide the message * @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 */ 'jsMessage' : function( message, className ) { - // 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 = $( '#mw-js-message' ); - if ( !$messageDiv.length ) { - $messageDiv = $( '
' ); - if ( mw.util.$content.parent().length ) { - mw.util.$content.parent().prepend( $messageDiv ); - } else { - return false; - } - } + + if ( !arguments.length || message === '' || message === null ) { - $messageDiv.show(); - if ( className ) { - $messageDiv.attr( 'class', 'mw-js-message-' + className ); - } + $( '#mw-js-message' ).empty().hide(); + return true; // Emptying and hiding message is intended behaviour, return true - if ( typeof message === 'object' ) { - $messageDiv.empty(); - $messageDiv.append( message ); // Append new content } else { - $messageDiv.html( message ); + // 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 = $( '#mw-js-message' ); + if ( !$messageDiv.length ) { + $messageDiv = $( '
' ); + if ( mw.util.$content.parent().length ) { + mw.util.$content.parent().prepend( $messageDiv ); + } else { + return false; + } + } + + $messageDiv.show(); + if ( className ) { + $messageDiv.attr( 'class', 'mw-js-message-' + className ); + } + + if ( typeof message === 'object' ) { + $messageDiv.empty(); + $messageDiv.append( message ); // Append new content + } else { + $messageDiv.html( message ); + } + return true; } - return true; } }; -- 2.20.1