wiki.techinc.nl/resources/jquery/jquery.messageBox.js

99 lines
3 KiB
JavaScript
Raw Normal View History

Making a start with $.jsMessage. A more flexible way for messages. Supports grouping them and making the replacing of previous messages into option (the current jsMsg() function always replaces older messages. Time has shown that there is need for the ability to show older messages as well and grouping to avoid different scripts from erasing or clearing eachother's output (current Commons and a few other wikis have created similar functions to enable keeping previous messages) * See also bug 26888. Not resolving the bug yet, this plugins needs a little more testing and should then be called from within mw.util.jsMessage with some wiki specific things. Examples: // Show a simple message in the default group $.jsMessage( { message: 'Hello', target: 'mw-js-message' } ); // Add a new message this time stating the defaults $.jsMessage( { message: 'World', group: 'default', replace: false, target: 'mw-js-message' } ); // Post a new message, replacing the previous ones $.jsMessage( { message: 'New', group: 'default', replace: true, target: 'mw-js-message' } ); // Add a messages in a new group (groups separated by a line) $.jsMessage( { message: 'A new group', group: 'something', target: 'mw-js-message' } ); // Clear the default group // See code comments for more info $.jsMessage( { message: '', replace: true, target: 'mw-js-message' } ); // Clear the 'something'-group // Since this leaves no visible groups, the main box will hide (slideUp) right after $.jsMessage( { message: '', group: 'something', replace: true, target: 'mw-js-message' } ); If testing goes well, mw.util.jsMsg(message, className, replace) will call $.jsMessage( { message: message, group: className, replace: replace, target: $.jsMessage(ge' ); So it's more a backend plugin, not used directly by core modules. But this way extensions or third party sites can easily re-use this plugin and/or create multiple message boxes on one page, by calling $.jsMessageNew and giving an id and location for it on the page.
2011-02-04 02:17:14 +00:00
/**
* jQuery messageBox
Making a start with $.jsMessage. A more flexible way for messages. Supports grouping them and making the replacing of previous messages into option (the current jsMsg() function always replaces older messages. Time has shown that there is need for the ability to show older messages as well and grouping to avoid different scripts from erasing or clearing eachother's output (current Commons and a few other wikis have created similar functions to enable keeping previous messages) * See also bug 26888. Not resolving the bug yet, this plugins needs a little more testing and should then be called from within mw.util.jsMessage with some wiki specific things. Examples: // Show a simple message in the default group $.jsMessage( { message: 'Hello', target: 'mw-js-message' } ); // Add a new message this time stating the defaults $.jsMessage( { message: 'World', group: 'default', replace: false, target: 'mw-js-message' } ); // Post a new message, replacing the previous ones $.jsMessage( { message: 'New', group: 'default', replace: true, target: 'mw-js-message' } ); // Add a messages in a new group (groups separated by a line) $.jsMessage( { message: 'A new group', group: 'something', target: 'mw-js-message' } ); // Clear the default group // See code comments for more info $.jsMessage( { message: '', replace: true, target: 'mw-js-message' } ); // Clear the 'something'-group // Since this leaves no visible groups, the main box will hide (slideUp) right after $.jsMessage( { message: '', group: 'something', replace: true, target: 'mw-js-message' } ); If testing goes well, mw.util.jsMsg(message, className, replace) will call $.jsMessage( { message: message, group: className, replace: replace, target: $.jsMessage(ge' ); So it's more a backend plugin, not used directly by core modules. But this way extensions or third party sites can easily re-use this plugin and/or create multiple message boxes on one page, by calling $.jsMessageNew and giving an id and location for it on the page.
2011-02-04 02:17:14 +00:00
*
* Function to inform the user of something. Use sparingly (since there's mw.log for
* messages aimed at developers / debuggers). Based on the function in MediaWiki's
* legacy javascript (wikibits.js) by Aryeh Gregor called jsMsg() added in r23233.
*
* @author Krinkle <krinklemail@gmail.com>
*
* Dual license:
* @license CC-BY 3.0 <http://creativecommons.org/licenses/by/3.0>
* @license GPL2 <http://www.gnu.org/licenses/old-licenses/gpl-2.0.html>
*/
( function( $ ) {
Making a start with $.jsMessage. A more flexible way for messages. Supports grouping them and making the replacing of previous messages into option (the current jsMsg() function always replaces older messages. Time has shown that there is need for the ability to show older messages as well and grouping to avoid different scripts from erasing or clearing eachother's output (current Commons and a few other wikis have created similar functions to enable keeping previous messages) * See also bug 26888. Not resolving the bug yet, this plugins needs a little more testing and should then be called from within mw.util.jsMessage with some wiki specific things. Examples: // Show a simple message in the default group $.jsMessage( { message: 'Hello', target: 'mw-js-message' } ); // Add a new message this time stating the defaults $.jsMessage( { message: 'World', group: 'default', replace: false, target: 'mw-js-message' } ); // Post a new message, replacing the previous ones $.jsMessage( { message: 'New', group: 'default', replace: true, target: 'mw-js-message' } ); // Add a messages in a new group (groups separated by a line) $.jsMessage( { message: 'A new group', group: 'something', target: 'mw-js-message' } ); // Clear the default group // See code comments for more info $.jsMessage( { message: '', replace: true, target: 'mw-js-message' } ); // Clear the 'something'-group // Since this leaves no visible groups, the main box will hide (slideUp) right after $.jsMessage( { message: '', group: 'something', replace: true, target: 'mw-js-message' } ); If testing goes well, mw.util.jsMsg(message, className, replace) will call $.jsMessage( { message: message, group: className, replace: replace, target: $.jsMessage(ge' ); So it's more a backend plugin, not used directly by core modules. But this way extensions or third party sites can easily re-use this plugin and/or create multiple message boxes on one page, by calling $.jsMessageNew and giving an id and location for it on the page.
2011-02-04 02:17:14 +00:00
// @return jQuery object of the message box
$.messageBoxNew = function( options ) {
Making a start with $.jsMessage. A more flexible way for messages. Supports grouping them and making the replacing of previous messages into option (the current jsMsg() function always replaces older messages. Time has shown that there is need for the ability to show older messages as well and grouping to avoid different scripts from erasing or clearing eachother's output (current Commons and a few other wikis have created similar functions to enable keeping previous messages) * See also bug 26888. Not resolving the bug yet, this plugins needs a little more testing and should then be called from within mw.util.jsMessage with some wiki specific things. Examples: // Show a simple message in the default group $.jsMessage( { message: 'Hello', target: 'mw-js-message' } ); // Add a new message this time stating the defaults $.jsMessage( { message: 'World', group: 'default', replace: false, target: 'mw-js-message' } ); // Post a new message, replacing the previous ones $.jsMessage( { message: 'New', group: 'default', replace: true, target: 'mw-js-message' } ); // Add a messages in a new group (groups separated by a line) $.jsMessage( { message: 'A new group', group: 'something', target: 'mw-js-message' } ); // Clear the default group // See code comments for more info $.jsMessage( { message: '', replace: true, target: 'mw-js-message' } ); // Clear the 'something'-group // Since this leaves no visible groups, the main box will hide (slideUp) right after $.jsMessage( { message: '', group: 'something', replace: true, target: 'mw-js-message' } ); If testing goes well, mw.util.jsMsg(message, className, replace) will call $.jsMessage( { message: message, group: className, replace: replace, target: $.jsMessage(ge' ); So it's more a backend plugin, not used directly by core modules. But this way extensions or third party sites can easily re-use this plugin and/or create multiple message boxes on one page, by calling $.jsMessageNew and giving an id and location for it on the page.
2011-02-04 02:17:14 +00:00
options = $.extend( {
'id': 'js-messagebox', // unique identifier for this message box
Making a start with $.jsMessage. A more flexible way for messages. Supports grouping them and making the replacing of previous messages into option (the current jsMsg() function always replaces older messages. Time has shown that there is need for the ability to show older messages as well and grouping to avoid different scripts from erasing or clearing eachother's output (current Commons and a few other wikis have created similar functions to enable keeping previous messages) * See also bug 26888. Not resolving the bug yet, this plugins needs a little more testing and should then be called from within mw.util.jsMessage with some wiki specific things. Examples: // Show a simple message in the default group $.jsMessage( { message: 'Hello', target: 'mw-js-message' } ); // Add a new message this time stating the defaults $.jsMessage( { message: 'World', group: 'default', replace: false, target: 'mw-js-message' } ); // Post a new message, replacing the previous ones $.jsMessage( { message: 'New', group: 'default', replace: true, target: 'mw-js-message' } ); // Add a messages in a new group (groups separated by a line) $.jsMessage( { message: 'A new group', group: 'something', target: 'mw-js-message' } ); // Clear the default group // See code comments for more info $.jsMessage( { message: '', replace: true, target: 'mw-js-message' } ); // Clear the 'something'-group // Since this leaves no visible groups, the main box will hide (slideUp) right after $.jsMessage( { message: '', group: 'something', replace: true, target: 'mw-js-message' } ); If testing goes well, mw.util.jsMsg(message, className, replace) will call $.jsMessage( { message: message, group: className, replace: replace, target: $.jsMessage(ge' ); So it's more a backend plugin, not used directly by core modules. But this way extensions or third party sites can easily re-use this plugin and/or create multiple message boxes on one page, by calling $.jsMessageNew and giving an id and location for it on the page.
2011-02-04 02:17:14 +00:00
'parent': 'body', // jQuery/CSS selector
'insert': 'prepend' // 'prepend' or 'append'
}, options );
var $curBox = $( '#' + options.id );
Making a start with $.jsMessage. A more flexible way for messages. Supports grouping them and making the replacing of previous messages into option (the current jsMsg() function always replaces older messages. Time has shown that there is need for the ability to show older messages as well and grouping to avoid different scripts from erasing or clearing eachother's output (current Commons and a few other wikis have created similar functions to enable keeping previous messages) * See also bug 26888. Not resolving the bug yet, this plugins needs a little more testing and should then be called from within mw.util.jsMessage with some wiki specific things. Examples: // Show a simple message in the default group $.jsMessage( { message: 'Hello', target: 'mw-js-message' } ); // Add a new message this time stating the defaults $.jsMessage( { message: 'World', group: 'default', replace: false, target: 'mw-js-message' } ); // Post a new message, replacing the previous ones $.jsMessage( { message: 'New', group: 'default', replace: true, target: 'mw-js-message' } ); // Add a messages in a new group (groups separated by a line) $.jsMessage( { message: 'A new group', group: 'something', target: 'mw-js-message' } ); // Clear the default group // See code comments for more info $.jsMessage( { message: '', replace: true, target: 'mw-js-message' } ); // Clear the 'something'-group // Since this leaves no visible groups, the main box will hide (slideUp) right after $.jsMessage( { message: '', group: 'something', replace: true, target: 'mw-js-message' } ); If testing goes well, mw.util.jsMsg(message, className, replace) will call $.jsMessage( { message: message, group: className, replace: replace, target: $.jsMessage(ge' ); So it's more a backend plugin, not used directly by core modules. But this way extensions or third party sites can easily re-use this plugin and/or create multiple message boxes on one page, by calling $.jsMessageNew and giving an id and location for it on the page.
2011-02-04 02:17:14 +00:00
// Only create a new box if it doesn't exist already
if ( $curBox.length > 0 ) {
if ( $curBox.hasClass( 'js-messagebox' ) ) {
Making a start with $.jsMessage. A more flexible way for messages. Supports grouping them and making the replacing of previous messages into option (the current jsMsg() function always replaces older messages. Time has shown that there is need for the ability to show older messages as well and grouping to avoid different scripts from erasing or clearing eachother's output (current Commons and a few other wikis have created similar functions to enable keeping previous messages) * See also bug 26888. Not resolving the bug yet, this plugins needs a little more testing and should then be called from within mw.util.jsMessage with some wiki specific things. Examples: // Show a simple message in the default group $.jsMessage( { message: 'Hello', target: 'mw-js-message' } ); // Add a new message this time stating the defaults $.jsMessage( { message: 'World', group: 'default', replace: false, target: 'mw-js-message' } ); // Post a new message, replacing the previous ones $.jsMessage( { message: 'New', group: 'default', replace: true, target: 'mw-js-message' } ); // Add a messages in a new group (groups separated by a line) $.jsMessage( { message: 'A new group', group: 'something', target: 'mw-js-message' } ); // Clear the default group // See code comments for more info $.jsMessage( { message: '', replace: true, target: 'mw-js-message' } ); // Clear the 'something'-group // Since this leaves no visible groups, the main box will hide (slideUp) right after $.jsMessage( { message: '', group: 'something', replace: true, target: 'mw-js-message' } ); If testing goes well, mw.util.jsMsg(message, className, replace) will call $.jsMessage( { message: message, group: className, replace: replace, target: $.jsMessage(ge' ); So it's more a backend plugin, not used directly by core modules. But this way extensions or third party sites can easily re-use this plugin and/or create multiple message boxes on one page, by calling $.jsMessageNew and giving an id and location for it on the page.
2011-02-04 02:17:14 +00:00
return $curBox;
} else {
return $curBox.addClass( 'js-messagebox' );
Making a start with $.jsMessage. A more flexible way for messages. Supports grouping them and making the replacing of previous messages into option (the current jsMsg() function always replaces older messages. Time has shown that there is need for the ability to show older messages as well and grouping to avoid different scripts from erasing or clearing eachother's output (current Commons and a few other wikis have created similar functions to enable keeping previous messages) * See also bug 26888. Not resolving the bug yet, this plugins needs a little more testing and should then be called from within mw.util.jsMessage with some wiki specific things. Examples: // Show a simple message in the default group $.jsMessage( { message: 'Hello', target: 'mw-js-message' } ); // Add a new message this time stating the defaults $.jsMessage( { message: 'World', group: 'default', replace: false, target: 'mw-js-message' } ); // Post a new message, replacing the previous ones $.jsMessage( { message: 'New', group: 'default', replace: true, target: 'mw-js-message' } ); // Add a messages in a new group (groups separated by a line) $.jsMessage( { message: 'A new group', group: 'something', target: 'mw-js-message' } ); // Clear the default group // See code comments for more info $.jsMessage( { message: '', replace: true, target: 'mw-js-message' } ); // Clear the 'something'-group // Since this leaves no visible groups, the main box will hide (slideUp) right after $.jsMessage( { message: '', group: 'something', replace: true, target: 'mw-js-message' } ); If testing goes well, mw.util.jsMsg(message, className, replace) will call $.jsMessage( { message: message, group: className, replace: replace, target: $.jsMessage(ge' ); So it's more a backend plugin, not used directly by core modules. But this way extensions or third party sites can easily re-use this plugin and/or create multiple message boxes on one page, by calling $.jsMessageNew and giving an id and location for it on the page.
2011-02-04 02:17:14 +00:00
}
} else {
var $newBox = $( '<div>', {
Making a start with $.jsMessage. A more flexible way for messages. Supports grouping them and making the replacing of previous messages into option (the current jsMsg() function always replaces older messages. Time has shown that there is need for the ability to show older messages as well and grouping to avoid different scripts from erasing or clearing eachother's output (current Commons and a few other wikis have created similar functions to enable keeping previous messages) * See also bug 26888. Not resolving the bug yet, this plugins needs a little more testing and should then be called from within mw.util.jsMessage with some wiki specific things. Examples: // Show a simple message in the default group $.jsMessage( { message: 'Hello', target: 'mw-js-message' } ); // Add a new message this time stating the defaults $.jsMessage( { message: 'World', group: 'default', replace: false, target: 'mw-js-message' } ); // Post a new message, replacing the previous ones $.jsMessage( { message: 'New', group: 'default', replace: true, target: 'mw-js-message' } ); // Add a messages in a new group (groups separated by a line) $.jsMessage( { message: 'A new group', group: 'something', target: 'mw-js-message' } ); // Clear the default group // See code comments for more info $.jsMessage( { message: '', replace: true, target: 'mw-js-message' } ); // Clear the 'something'-group // Since this leaves no visible groups, the main box will hide (slideUp) right after $.jsMessage( { message: '', group: 'something', replace: true, target: 'mw-js-message' } ); If testing goes well, mw.util.jsMsg(message, className, replace) will call $.jsMessage( { message: message, group: className, replace: replace, target: $.jsMessage(ge' ); So it's more a backend plugin, not used directly by core modules. But this way extensions or third party sites can easily re-use this plugin and/or create multiple message boxes on one page, by calling $.jsMessageNew and giving an id and location for it on the page.
2011-02-04 02:17:14 +00:00
'id': options.id,
'class': 'js-messagebox',
Making a start with $.jsMessage. A more flexible way for messages. Supports grouping them and making the replacing of previous messages into option (the current jsMsg() function always replaces older messages. Time has shown that there is need for the ability to show older messages as well and grouping to avoid different scripts from erasing or clearing eachother's output (current Commons and a few other wikis have created similar functions to enable keeping previous messages) * See also bug 26888. Not resolving the bug yet, this plugins needs a little more testing and should then be called from within mw.util.jsMessage with some wiki specific things. Examples: // Show a simple message in the default group $.jsMessage( { message: 'Hello', target: 'mw-js-message' } ); // Add a new message this time stating the defaults $.jsMessage( { message: 'World', group: 'default', replace: false, target: 'mw-js-message' } ); // Post a new message, replacing the previous ones $.jsMessage( { message: 'New', group: 'default', replace: true, target: 'mw-js-message' } ); // Add a messages in a new group (groups separated by a line) $.jsMessage( { message: 'A new group', group: 'something', target: 'mw-js-message' } ); // Clear the default group // See code comments for more info $.jsMessage( { message: '', replace: true, target: 'mw-js-message' } ); // Clear the 'something'-group // Since this leaves no visible groups, the main box will hide (slideUp) right after $.jsMessage( { message: '', group: 'something', replace: true, target: 'mw-js-message' } ); If testing goes well, mw.util.jsMsg(message, className, replace) will call $.jsMessage( { message: message, group: className, replace: replace, target: $.jsMessage(ge' ); So it's more a backend plugin, not used directly by core modules. But this way extensions or third party sites can easily re-use this plugin and/or create multiple message boxes on one page, by calling $.jsMessageNew and giving an id and location for it on the page.
2011-02-04 02:17:14 +00:00
'css': {
'display': 'none'
}
});
if ( $( options.parent ).length < 1 ) {
options.parent = 'body';
}
Making a start with $.jsMessage. A more flexible way for messages. Supports grouping them and making the replacing of previous messages into option (the current jsMsg() function always replaces older messages. Time has shown that there is need for the ability to show older messages as well and grouping to avoid different scripts from erasing or clearing eachother's output (current Commons and a few other wikis have created similar functions to enable keeping previous messages) * See also bug 26888. Not resolving the bug yet, this plugins needs a little more testing and should then be called from within mw.util.jsMessage with some wiki specific things. Examples: // Show a simple message in the default group $.jsMessage( { message: 'Hello', target: 'mw-js-message' } ); // Add a new message this time stating the defaults $.jsMessage( { message: 'World', group: 'default', replace: false, target: 'mw-js-message' } ); // Post a new message, replacing the previous ones $.jsMessage( { message: 'New', group: 'default', replace: true, target: 'mw-js-message' } ); // Add a messages in a new group (groups separated by a line) $.jsMessage( { message: 'A new group', group: 'something', target: 'mw-js-message' } ); // Clear the default group // See code comments for more info $.jsMessage( { message: '', replace: true, target: 'mw-js-message' } ); // Clear the 'something'-group // Since this leaves no visible groups, the main box will hide (slideUp) right after $.jsMessage( { message: '', group: 'something', replace: true, target: 'mw-js-message' } ); If testing goes well, mw.util.jsMsg(message, className, replace) will call $.jsMessage( { message: message, group: className, replace: replace, target: $.jsMessage(ge' ); So it's more a backend plugin, not used directly by core modules. But this way extensions or third party sites can easily re-use this plugin and/or create multiple message boxes on one page, by calling $.jsMessageNew and giving an id and location for it on the page.
2011-02-04 02:17:14 +00:00
if ( options.insert === 'append' ) {
$newBox.appendTo( options.parent );
return $newBox;
} else {
$newBox.prependTo( options.parent );
return $newBox;
}
}
};
// Calling with no message or message set to empty string or null will hide the group,
// setting 'replace' to true as well will reset and hide the group entirely.
// If there are no visible groups the main message box is hidden automatically,
// and shown again once there are messages
// @return jQuery object of message group
$.messageBox = function( options ) {
Making a start with $.jsMessage. A more flexible way for messages. Supports grouping them and making the replacing of previous messages into option (the current jsMsg() function always replaces older messages. Time has shown that there is need for the ability to show older messages as well and grouping to avoid different scripts from erasing or clearing eachother's output (current Commons and a few other wikis have created similar functions to enable keeping previous messages) * See also bug 26888. Not resolving the bug yet, this plugins needs a little more testing and should then be called from within mw.util.jsMessage with some wiki specific things. Examples: // Show a simple message in the default group $.jsMessage( { message: 'Hello', target: 'mw-js-message' } ); // Add a new message this time stating the defaults $.jsMessage( { message: 'World', group: 'default', replace: false, target: 'mw-js-message' } ); // Post a new message, replacing the previous ones $.jsMessage( { message: 'New', group: 'default', replace: true, target: 'mw-js-message' } ); // Add a messages in a new group (groups separated by a line) $.jsMessage( { message: 'A new group', group: 'something', target: 'mw-js-message' } ); // Clear the default group // See code comments for more info $.jsMessage( { message: '', replace: true, target: 'mw-js-message' } ); // Clear the 'something'-group // Since this leaves no visible groups, the main box will hide (slideUp) right after $.jsMessage( { message: '', group: 'something', replace: true, target: 'mw-js-message' } ); If testing goes well, mw.util.jsMsg(message, className, replace) will call $.jsMessage( { message: message, group: className, replace: replace, target: $.jsMessage(ge' ); So it's more a backend plugin, not used directly by core modules. But this way extensions or third party sites can easily re-use this plugin and/or create multiple message boxes on one page, by calling $.jsMessageNew and giving an id and location for it on the page.
2011-02-04 02:17:14 +00:00
options = $.extend( {
'message': '',
'group': 'default',
'replace': false, // if true replaces any previous message in this group
'target': 'js-messagebox'
}, options );
var $target = $.messageBoxNew( { id: options.target } );
Making a start with $.jsMessage. A more flexible way for messages. Supports grouping them and making the replacing of previous messages into option (the current jsMsg() function always replaces older messages. Time has shown that there is need for the ability to show older messages as well and grouping to avoid different scripts from erasing or clearing eachother's output (current Commons and a few other wikis have created similar functions to enable keeping previous messages) * See also bug 26888. Not resolving the bug yet, this plugins needs a little more testing and should then be called from within mw.util.jsMessage with some wiki specific things. Examples: // Show a simple message in the default group $.jsMessage( { message: 'Hello', target: 'mw-js-message' } ); // Add a new message this time stating the defaults $.jsMessage( { message: 'World', group: 'default', replace: false, target: 'mw-js-message' } ); // Post a new message, replacing the previous ones $.jsMessage( { message: 'New', group: 'default', replace: true, target: 'mw-js-message' } ); // Add a messages in a new group (groups separated by a line) $.jsMessage( { message: 'A new group', group: 'something', target: 'mw-js-message' } ); // Clear the default group // See code comments for more info $.jsMessage( { message: '', replace: true, target: 'mw-js-message' } ); // Clear the 'something'-group // Since this leaves no visible groups, the main box will hide (slideUp) right after $.jsMessage( { message: '', group: 'something', replace: true, target: 'mw-js-message' } ); If testing goes well, mw.util.jsMsg(message, className, replace) will call $.jsMessage( { message: message, group: className, replace: replace, target: $.jsMessage(ge' ); So it's more a backend plugin, not used directly by core modules. But this way extensions or third party sites can easily re-use this plugin and/or create multiple message boxes on one page, by calling $.jsMessageNew and giving an id and location for it on the page.
2011-02-04 02:17:14 +00:00
var groupID = options.target + '-' + options.group;
var $group = $( '#' + groupID );
// Create group container if not existant
if ( $group.length < 1 ) {
$group = $( '<div>', {
Making a start with $.jsMessage. A more flexible way for messages. Supports grouping them and making the replacing of previous messages into option (the current jsMsg() function always replaces older messages. Time has shown that there is need for the ability to show older messages as well and grouping to avoid different scripts from erasing or clearing eachother's output (current Commons and a few other wikis have created similar functions to enable keeping previous messages) * See also bug 26888. Not resolving the bug yet, this plugins needs a little more testing and should then be called from within mw.util.jsMessage with some wiki specific things. Examples: // Show a simple message in the default group $.jsMessage( { message: 'Hello', target: 'mw-js-message' } ); // Add a new message this time stating the defaults $.jsMessage( { message: 'World', group: 'default', replace: false, target: 'mw-js-message' } ); // Post a new message, replacing the previous ones $.jsMessage( { message: 'New', group: 'default', replace: true, target: 'mw-js-message' } ); // Add a messages in a new group (groups separated by a line) $.jsMessage( { message: 'A new group', group: 'something', target: 'mw-js-message' } ); // Clear the default group // See code comments for more info $.jsMessage( { message: '', replace: true, target: 'mw-js-message' } ); // Clear the 'something'-group // Since this leaves no visible groups, the main box will hide (slideUp) right after $.jsMessage( { message: '', group: 'something', replace: true, target: 'mw-js-message' } ); If testing goes well, mw.util.jsMsg(message, className, replace) will call $.jsMessage( { message: message, group: className, replace: replace, target: $.jsMessage(ge' ); So it's more a backend plugin, not used directly by core modules. But this way extensions or third party sites can easily re-use this plugin and/or create multiple message boxes on one page, by calling $.jsMessageNew and giving an id and location for it on the page.
2011-02-04 02:17:14 +00:00
'id': groupID,
'class': 'js-messagebox-group'
Making a start with $.jsMessage. A more flexible way for messages. Supports grouping them and making the replacing of previous messages into option (the current jsMsg() function always replaces older messages. Time has shown that there is need for the ability to show older messages as well and grouping to avoid different scripts from erasing or clearing eachother's output (current Commons and a few other wikis have created similar functions to enable keeping previous messages) * See also bug 26888. Not resolving the bug yet, this plugins needs a little more testing and should then be called from within mw.util.jsMessage with some wiki specific things. Examples: // Show a simple message in the default group $.jsMessage( { message: 'Hello', target: 'mw-js-message' } ); // Add a new message this time stating the defaults $.jsMessage( { message: 'World', group: 'default', replace: false, target: 'mw-js-message' } ); // Post a new message, replacing the previous ones $.jsMessage( { message: 'New', group: 'default', replace: true, target: 'mw-js-message' } ); // Add a messages in a new group (groups separated by a line) $.jsMessage( { message: 'A new group', group: 'something', target: 'mw-js-message' } ); // Clear the default group // See code comments for more info $.jsMessage( { message: '', replace: true, target: 'mw-js-message' } ); // Clear the 'something'-group // Since this leaves no visible groups, the main box will hide (slideUp) right after $.jsMessage( { message: '', group: 'something', replace: true, target: 'mw-js-message' } ); If testing goes well, mw.util.jsMsg(message, className, replace) will call $.jsMessage( { message: message, group: className, replace: replace, target: $.jsMessage(ge' ); So it's more a backend plugin, not used directly by core modules. But this way extensions or third party sites can easily re-use this plugin and/or create multiple message boxes on one page, by calling $.jsMessageNew and giving an id and location for it on the page.
2011-02-04 02:17:14 +00:00
});
$target.prepend( $group );
}
// Replace ?
if ( options.replace === true ) {
$group.empty();
}
// Hide it ?
if ( options.message === '' || options.message === null ) {
$group.hide();
} else {
// Actual message addition
$group.prepend( $( '<p>' ).append( options.message ) ).show();
$target.slideDown();
Making a start with $.jsMessage. A more flexible way for messages. Supports grouping them and making the replacing of previous messages into option (the current jsMsg() function always replaces older messages. Time has shown that there is need for the ability to show older messages as well and grouping to avoid different scripts from erasing or clearing eachother's output (current Commons and a few other wikis have created similar functions to enable keeping previous messages) * See also bug 26888. Not resolving the bug yet, this plugins needs a little more testing and should then be called from within mw.util.jsMessage with some wiki specific things. Examples: // Show a simple message in the default group $.jsMessage( { message: 'Hello', target: 'mw-js-message' } ); // Add a new message this time stating the defaults $.jsMessage( { message: 'World', group: 'default', replace: false, target: 'mw-js-message' } ); // Post a new message, replacing the previous ones $.jsMessage( { message: 'New', group: 'default', replace: true, target: 'mw-js-message' } ); // Add a messages in a new group (groups separated by a line) $.jsMessage( { message: 'A new group', group: 'something', target: 'mw-js-message' } ); // Clear the default group // See code comments for more info $.jsMessage( { message: '', replace: true, target: 'mw-js-message' } ); // Clear the 'something'-group // Since this leaves no visible groups, the main box will hide (slideUp) right after $.jsMessage( { message: '', group: 'something', replace: true, target: 'mw-js-message' } ); If testing goes well, mw.util.jsMsg(message, className, replace) will call $.jsMessage( { message: message, group: className, replace: replace, target: $.jsMessage(ge' ); So it's more a backend plugin, not used directly by core modules. But this way extensions or third party sites can easily re-use this plugin and/or create multiple message boxes on one page, by calling $.jsMessageNew and giving an id and location for it on the page.
2011-02-04 02:17:14 +00:00
}
// If the last visible group was just hidden, slide the entire box up
// Othere wise slideDown (if already visible nothing will happen)
if ( $target.find( '> *:visible' ).length === 0 ) {
Making a start with $.jsMessage. A more flexible way for messages. Supports grouping them and making the replacing of previous messages into option (the current jsMsg() function always replaces older messages. Time has shown that there is need for the ability to show older messages as well and grouping to avoid different scripts from erasing or clearing eachother's output (current Commons and a few other wikis have created similar functions to enable keeping previous messages) * See also bug 26888. Not resolving the bug yet, this plugins needs a little more testing and should then be called from within mw.util.jsMessage with some wiki specific things. Examples: // Show a simple message in the default group $.jsMessage( { message: 'Hello', target: 'mw-js-message' } ); // Add a new message this time stating the defaults $.jsMessage( { message: 'World', group: 'default', replace: false, target: 'mw-js-message' } ); // Post a new message, replacing the previous ones $.jsMessage( { message: 'New', group: 'default', replace: true, target: 'mw-js-message' } ); // Add a messages in a new group (groups separated by a line) $.jsMessage( { message: 'A new group', group: 'something', target: 'mw-js-message' } ); // Clear the default group // See code comments for more info $.jsMessage( { message: '', replace: true, target: 'mw-js-message' } ); // Clear the 'something'-group // Since this leaves no visible groups, the main box will hide (slideUp) right after $.jsMessage( { message: '', group: 'something', replace: true, target: 'mw-js-message' } ); If testing goes well, mw.util.jsMsg(message, className, replace) will call $.jsMessage( { message: message, group: className, replace: replace, target: $.jsMessage(ge' ); So it's more a backend plugin, not used directly by core modules. But this way extensions or third party sites can easily re-use this plugin and/or create multiple message boxes on one page, by calling $.jsMessageNew and giving an id and location for it on the page.
2011-02-04 02:17:14 +00:00
// to avoid a sudden dissapearance of the last group followed by
// a slide up of only the outline, show it for a second
$group.show();
$target.slideUp();
$group.hide();
} else {
$target.slideDown();
}
return $group;
};
} )( jQuery );