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>
15 // @return jQuery object of the message box
16 $.messageBoxNew = function( options
) {
18 'id': 'js-messagebox', // unique identifier for this message box
19 'parent': 'body', // jQuery/CSS selector
20 'insert': 'prepend' // 'prepend' or 'append'
22 var $curBox
= $( '#' + options
.id
);
23 // Only create a new box if it doesn't exist already
24 if ( $curBox
.length
> 0 ) {
25 if ( $curBox
.hasClass( 'js-messagebox' ) ) {
28 return $curBox
.addClass( 'js-messagebox' );
31 var $newBox
= $( '<div>', {
33 'class': 'js-messagebox',
38 if ( $( options
.parent
).length
< 1 ) {
39 options
.parent
= 'body';
41 if ( options
.insert
=== 'append' ) {
42 $newBox
.appendTo( options
.parent
);
45 $newBox
.prependTo( options
.parent
);
50 // Calling with no message or message set to empty string or null will hide the group,
51 // setting 'replace' to true as well will reset and hide the group entirely.
52 // If there are no visible groups the main message box is hidden automatically,
53 // and shown again once there are messages
54 // @return jQuery object of message group
55 $.messageBox = function( options
) {
59 'replace': false, // if true replaces any previous message in this group
60 'target': 'js-messagebox'
62 var $target
= $.messageBoxNew( { id
: options
.target
} );
63 var groupID
= options
.target
+ '-' + options
.group
;
64 var $group
= $( '#' + groupID
);
65 // Create group container if not existant
66 if ( $group
.length
< 1 ) {
67 $group
= $( '<div>', {
69 'class': 'js-messagebox-group'
71 $target
.prepend( $group
);
74 if ( options
.replace
=== true ) {
78 if ( options
.message
=== '' || options
.message
=== null ) {
81 // Actual message addition
82 $group
.prepend( $( '<p>' ).append( options
.message
) ).show();
85 // If the last visible group was just hidden, slide the entire box up
86 // Othere wise slideDown (if already visible nothing will happen)
87 if ( $target
.find( '> *:visible' ).length
=== 0 ) {
88 // to avoid a sudden dissapearance of the last group followed by
89 // a slide up of only the outline, show it for a second