4 * Function to inform the user of something. Use sparingly (since there's mw.log for
5 * messages aimed at developers / debuggers). Based on the function in MediaWiki's
6 * legacy javascript (wikibits.js) by Aryeh Gregor called jsMsg() added in r23233.
8 * @author Krinkle <krinklemail@gmail.com>
11 * @license CC-BY 3.0 <http://creativecommons.org/licenses/by/3.0>
12 * @license GPL2 <http://www.gnu.org/licenses/old-licenses/gpl-2.0.html>
16 /** @return jQuery object of the message box */
17 $.messageBoxNew = function ( options ) {
19 // unique identifier for this message box
22 // jQuery/CSS selector
25 // 'prepend' or 'append'
28 var $curBox = $( '#' + options.id );
29 // Only create a new box if it doesn't exist already
30 if ( $curBox.length > 0 ) {
31 if ( $curBox.hasClass( 'js-messagebox' ) ) {
34 return $curBox.addClass( 'js-messagebox' );
37 var $newBox = $( '<div>', {
39 'class': 'js-messagebox',
44 if ( $( options.parent ).length < 1 ) {
45 options.parent = 'body';
47 if ( options.insert === 'append' ) {
48 $newBox.appendTo( options.parent );
51 $newBox.prependTo( options.parent );
58 * Calling with no message or message set to empty string or null will hide the group,
59 * setting 'replace' to true as well will reset and hide the group entirely.
60 * If there are no visible groups the main message box is hidden automatically,
61 * and shown again once there are messages
62 * @return {jQuery}: jQuery object of message group.
64 $.messageBox = function ( options ) {
68 // if replace=true, it replaces any previous message in this group
70 target: 'js-messagebox'
72 var $target = $.messageBoxNew( { id: options.target } );
73 var groupID = options.target + '-' + options.group;
74 var $group = $( '#' + groupID );
75 // Create group container if not existant
76 if ( $group.length < 1 ) {
77 $group = $( '<div>', {
79 'class': 'js-messagebox-group'
81 $target.prepend( $group );
84 if ( options.replace === true ) {
88 if ( options.message === '' || options.message === null ) {
91 // Actual message addition
92 $group.prepend( $( '<p>' ).append( options.message ) ).show();
95 // If the last visible group was just hidden, slide the entire box up
96 // Othere wise slideDown (if already visible nothing will happen)
97 if ( $target.find( '> *:visible' ).length === 0 ) {
98 // to avoid a sudden dissapearance of the last group followed by
99 // a slide up of only the outline, show it for a second