Index: trunk/phase3/resources/jquery/jquery.jsMessage.css |
— | — | @@ -0,0 +1,15 @@ |
| 2 | +.js-message-box { |
| 3 | + margin: 1em 5%; |
| 4 | + padding: 0.5em 2.5%; |
| 5 | + border: 1px solid #ccc; |
| 6 | + background-color: #fcfcfc; |
| 7 | + font-size: 0.8em; |
| 8 | +} |
| 9 | +.js-message-box .js-message-group { |
| 10 | + margin: 1px; |
| 11 | + padding: 0.5em 2.5%; |
| 12 | + border-bottom: 1px solid #ddd; |
| 13 | +} |
| 14 | +.js-message-box .js-message-group:last-child { |
| 15 | + border-bottom: thin none transparent; |
| 16 | +} |
\ No newline at end of file |
Property changes on: trunk/phase3/resources/jquery/jquery.jsMessage.css |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 17 | + native |
Index: trunk/phase3/resources/jquery/jquery.jsMessage.js |
— | — | @@ -0,0 +1,95 @@ |
| 2 | +/** |
| 3 | + * jQuery jsMessage |
| 4 | + * |
| 5 | + * Function to inform the user of something. Use sparingly (since there's mw.log for |
| 6 | + * messages aimed at developers / debuggers). Based on the function in MediaWiki's |
| 7 | + * legacy javascript (wikibits.js) by Aryeh Gregor called jsMsg() added in r23233. |
| 8 | + * |
| 9 | + * @author Krinkle <krinklemail@gmail.com> |
| 10 | + * |
| 11 | + * Dual license: |
| 12 | + * @license CC-BY 3.0 <http://creativecommons.org/licenses/by/3.0> |
| 13 | + * @license GPL2 <http://www.gnu.org/licenses/old-licenses/gpl-2.0.html> |
| 14 | + */ |
| 15 | +( function( $, mw ) { |
| 16 | +// @return jQuery object of the message box |
| 17 | +$.jsMessageNew = function( options ) { |
| 18 | + options = $.extend( { |
| 19 | + 'id': 'js-message', // unique identifier for this message box |
| 20 | + 'parent': 'body', // jQuery/CSS selector |
| 21 | + 'insert': 'prepend' // 'prepend' or 'append' |
| 22 | + }, options ); |
| 23 | + var $curBox = $( '#'+ options.id ); |
| 24 | + // Only create a new box if it doesn't exist already |
| 25 | + if ( $curBox.size() > 0 ) { |
| 26 | + if ( $curBox.hasClass( 'js-message-box' ) ) { |
| 27 | + return $curBox; |
| 28 | + } else { |
| 29 | + return $curBox.addClass( 'js-message-box' ); |
| 30 | + } |
| 31 | + } else { |
| 32 | + var $newBox = $( '<div/>', { |
| 33 | + 'id': options.id, |
| 34 | + 'class': 'js-message-box', |
| 35 | + 'css': { |
| 36 | + 'display': 'none' |
| 37 | + } |
| 38 | + }); |
| 39 | + if ( options.insert === 'append' ) { |
| 40 | + $newBox.appendTo( options.parent ); |
| 41 | + return $newBox; |
| 42 | + } else { |
| 43 | + $newBox.prependTo( options.parent ); |
| 44 | + return $newBox; |
| 45 | + } |
| 46 | + } |
| 47 | +}; |
| 48 | +// Calling with no message or message set to empty string or null will hide the group, |
| 49 | +// setting 'replace' to true as well will reset and hide the group entirely. |
| 50 | +// If there are no visible groups the main message box is hidden automatically, |
| 51 | +// and shown again once there are messages |
| 52 | +// @return jQuery object of message group |
| 53 | +$.jsMessage = function( options ) { |
| 54 | + options = $.extend( { |
| 55 | + 'message': '', |
| 56 | + 'group': 'default', |
| 57 | + 'replace': false, // if true replaces any previous message in this group |
| 58 | + 'target': 'js-message' |
| 59 | + }, options ); |
| 60 | + var $target = $.jsMessageNew( { id: options.target } ); |
| 61 | + var groupID = options.target + '-' + options.group; |
| 62 | + var $group = $( '#' + groupID ); |
| 63 | + // Create group container if not existant |
| 64 | + if ( $group.size() < 1 ) { |
| 65 | + $group = $( '<div/>', { |
| 66 | + 'id': groupID, |
| 67 | + 'class': 'js-message-group' |
| 68 | + }); |
| 69 | + $target.prepend( $group ); |
| 70 | + } |
| 71 | + // Replace ? |
| 72 | + if ( options.replace === true ) { |
| 73 | + $group.empty(); |
| 74 | + } |
| 75 | + // Hide it ? |
| 76 | + if ( options.message === '' || options.message === null ) { |
| 77 | + $group.hide(); |
| 78 | + } else { |
| 79 | + // Actual message addition |
| 80 | + $group.prepend( $( '<p/>' ).append( options.message ) ).show(); |
| 81 | + $target.slideDown() |
| 82 | + } |
| 83 | + // If the last visible group was just hidden, slide the entire box up |
| 84 | + // Othere wise slideDown (if already visible nothing will happen) |
| 85 | + if ( $target.find( '> *:visible' ).size() === 0 ) { |
| 86 | + // to avoid a sudden dissapearance of the last group followed by |
| 87 | + // a slide up of only the outline, show it for a second |
| 88 | + $group.show(); |
| 89 | + $target.slideUp(); |
| 90 | + $group.hide(); |
| 91 | + } else { |
| 92 | + $target.slideDown(); |
| 93 | + } |
| 94 | + return $group; |
| 95 | +}; |
| 96 | +} )( jQuery, mediaWiki ); |
\ No newline at end of file |
Property changes on: trunk/phase3/resources/jquery/jquery.jsMessage.js |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 97 | + native |
Index: trunk/phase3/resources/mediawiki.util/mediawiki.util.js |
— | — | @@ -14,6 +14,12 @@ |
15 | 15 | // Any initialisation after the DOM is ready |
16 | 16 | $( function() { |
17 | 17 | |
| 18 | + /* Set up $.jsMessage */ |
| 19 | + $.jsMessageNew( { |
| 20 | + 'id': 'mw-js-message', |
| 21 | + 'parent': '#content' |
| 22 | + } ); |
| 23 | + |
18 | 24 | // Shortcut to client profile return |
19 | 25 | var profile = $.client.profile(); |
20 | 26 | |
Index: trunk/phase3/resources/Resources.php |
— | — | @@ -89,6 +89,10 @@ |
90 | 90 | 'jquery.hoverIntent' => array( |
91 | 91 | 'scripts' => 'resources/jquery/jquery.hoverIntent.js', |
92 | 92 | ), |
| 93 | + 'jquery.jsMessage' => array( |
| 94 | + 'scripts' => 'resources/jquery/jquery.jsMessage.js', |
| 95 | + 'styles' => 'resources/jquery/jquery.jsMessage.css', |
| 96 | + ), |
93 | 97 | 'jquery.placeholder' => array( |
94 | 98 | 'scripts' => 'resources/jquery/jquery.placeholder.js', |
95 | 99 | ), |
— | — | @@ -366,8 +370,9 @@ |
367 | 371 | 'dependencies' => array( |
368 | 372 | 'jquery.checkboxShiftClick', |
369 | 373 | 'jquery.client', |
| 374 | + 'jquery.cookie', |
| 375 | + 'jquery.jsMessage', |
370 | 376 | 'jquery.makeCollapsible', |
371 | | - 'jquery.cookie', |
372 | 377 | 'jquery.placeholder', |
373 | 378 | ), |
374 | 379 | 'debugScripts' => 'resources/mediawiki.util/mediawiki.util.test.js', |