/**
* Implements mediaWiki.util library
*/
-( function ( $, mw ) {
- "use strict";
+( function ( mw, $ ) {
+ 'use strict';
// Local cache and alias
- var util = {
+ var hideMessageTimeout,
+ messageBoxEvents = false,
+ util = {
/**
* Initialisation
* Get address to a script in the wiki root.
* For index.php use mw.config.get( 'wgScript' )
*
+ * @since 1.18
* @param str string Name of script (eg. 'api'), defaults to 'index'
* @return string Address to script (eg. '/w/api.php' )
*/
wikiScript: function ( str ) {
- return mw.config.get( 'wgScriptPath' ) + '/' + ( str || 'index' ) +
- mw.config.get( 'wgScriptExtension' );
+ str = str || 'index';
+ if ( str === 'index' ) {
+ return mw.config.get( 'wgScript' );
+ } else if ( str === 'load' ) {
+ return mw.config.get( 'wgLoadScript' );
+ } else {
+ return mw.config.get( 'wgScriptPath' ) + '/' + str +
+ mw.config.get( 'wgScriptExtension' );
+ }
},
/**
// Get last match, stop at hash
var re = new RegExp( '^[^#]*[&?]' + $.escapeRE( param ) + '=([^&#]*)' ),
m = re.exec( url );
- if ( m && m.length > 1 ) {
+ if ( m ) {
// Beware that decodeURIComponent is not required to understand '+'
// by spec, as encodeURIComponent does not produce it.
return decodeURIComponent( m[1].replace( /\+/g, '%20' ) );
return null;
}
// Select the first (most likely only) unordered list inside the portlet
- $ul = $portlet.find( 'ul' );
+ $ul = $portlet.find( 'ul' ).eq( 0 );
// If it didn't have an unordered list yet, create it
if ( $ul.length === 0 ) {
+
+ $ul = $( '<ul>' );
+
// If there's no <div> inside, append it to the portlet directly
if ( $portlet.find( 'div:first' ).length === 0 ) {
- $portlet.append( '<ul></ul>' );
+ $portlet.append( $ul );
} else {
// otherwise if there's a div (such as div.body or div.pBody)
// append the <ul> to last (most likely only) div
- $portlet.find( 'div' ).eq( -1 ).append( '<ul></ul>' );
+ $portlet.find( 'div' ).eq( -1 ).append( $ul );
}
- // Select the created element
- $ul = $portlet.find( 'ul' ).eq( 0 );
}
// Just in case..
if ( $ul.length === 0 ) {
* @return {Boolean} True on success, false on failure.
*/
jsMessage: function ( message, className ) {
+ var $messageDiv = $( '#mw-js-message' );
+
if ( !arguments.length || message === '' || message === null ) {
- $( '#mw-js-message' ).empty().hide();
+ $messageDiv.empty().hide();
+ stopHideMessageTimeout();
return true; // Emptying and hiding message is intended behaviour, return true
-
} else {
// 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 = $( '<div id="mw-js-message"></div>' );
if ( util.$content.parent().length ) {
}
}
+ if ( !messageBoxEvents ) {
+ messageBoxEvents = true;
+ $messageDiv
+ .on( {
+ 'mouseenter': stopHideMessageTimeout,
+ 'mouseleave': startHideMessageTimeout,
+ 'click': hideMessage
+ } )
+ .on( 'click', 'a', function ( e ) {
+ // Prevent links, even those that don't exist yet, from causing the
+ // message box to close when clicked
+ e.stopPropagation();
+ } );
+ }
+
if ( className ) {
- $messageDiv.prop( 'class', 'mw-js-message-' + className );
+ $messageDiv.prop( 'className', 'mw-js-message-' + className );
}
if ( typeof message === 'object' ) {
}
$messageDiv.slideDown();
+ startHideMessageTimeout();
return true;
}
},
}
};
+ // Message auto-hide helpers
+ function hideMessage() {
+ $( '#mw-js-message' ).fadeOut( 'slow' );
+ }
+ function stopHideMessageTimeout() {
+ clearTimeout( hideMessageTimeout );
+ }
+ function startHideMessageTimeout() {
+ clearTimeout( hideMessageTimeout );
+ hideMessageTimeout = setTimeout( hideMessage, 5000 );
+ }
+
mw.util = util;
-} )( jQuery, mediaWiki );
+}( mediaWiki, jQuery ) );