diff options
author | Pierre Schmitz <pierre@archlinux.de> | 2013-12-08 09:55:49 +0100 |
---|---|---|
committer | Pierre Schmitz <pierre@archlinux.de> | 2013-12-08 09:55:49 +0100 |
commit | 4ac9fa081a7c045f6a9f1cfc529d82423f485b2e (patch) | |
tree | af68743f2f4a47d13f2b0eb05f5c4aaf86d8ea37 /resources/jquery | |
parent | af4da56f1ad4d3ef7b06557bae365da2ea27a897 (diff) |
Update to MediaWiki 1.22.0
Diffstat (limited to 'resources/jquery')
19 files changed, 376 insertions, 241 deletions
diff --git a/resources/jquery/images/jquery.arrowSteps.divider-ltr.png b/resources/jquery/images/jquery.arrowSteps.divider-ltr.png Binary files differindex 83d6ff84..84ed2a2d 100644 --- a/resources/jquery/images/jquery.arrowSteps.divider-ltr.png +++ b/resources/jquery/images/jquery.arrowSteps.divider-ltr.png diff --git a/resources/jquery/images/jquery.arrowSteps.divider-rtl.png b/resources/jquery/images/jquery.arrowSteps.divider-rtl.png Binary files differindex 529d7b84..7cfbfeba 100644 --- a/resources/jquery/images/jquery.arrowSteps.divider-rtl.png +++ b/resources/jquery/images/jquery.arrowSteps.divider-rtl.png diff --git a/resources/jquery/images/jquery.arrowSteps.head-ltr.png b/resources/jquery/images/jquery.arrowSteps.head-ltr.png Binary files differindex 3289617d..eb070280 100644 --- a/resources/jquery/images/jquery.arrowSteps.head-ltr.png +++ b/resources/jquery/images/jquery.arrowSteps.head-ltr.png diff --git a/resources/jquery/images/jquery.arrowSteps.head-rtl.png b/resources/jquery/images/jquery.arrowSteps.head-rtl.png Binary files differindex 3d9f70cb..7ea2fdb5 100644 --- a/resources/jquery/images/jquery.arrowSteps.head-rtl.png +++ b/resources/jquery/images/jquery.arrowSteps.head-rtl.png diff --git a/resources/jquery/images/jquery.arrowSteps.tail-ltr.png b/resources/jquery/images/jquery.arrowSteps.tail-ltr.png Binary files differindex 92b872b2..3ad990b6 100644 --- a/resources/jquery/images/jquery.arrowSteps.tail-ltr.png +++ b/resources/jquery/images/jquery.arrowSteps.tail-ltr.png diff --git a/resources/jquery/images/marker.png b/resources/jquery/images/marker.png Binary files differindex 3929bbb5..19efb6ce 100644 --- a/resources/jquery/images/marker.png +++ b/resources/jquery/images/marker.png diff --git a/resources/jquery/images/mask.png b/resources/jquery/images/mask.png Binary files differindex b0a4d406..fe08de0e 100644 --- a/resources/jquery/images/mask.png +++ b/resources/jquery/images/mask.png diff --git a/resources/jquery/jquery.badge.css b/resources/jquery/jquery.badge.css index d961bf3d..f313663e 100644 --- a/resources/jquery/jquery.badge.css +++ b/resources/jquery/jquery.badge.css @@ -1,13 +1,12 @@ .mw-badge { min-width: 7px; - -moz-border-radius: 2px; - -webkit-border-radius: 2px; border-radius: 2px; padding: 1px 4px; text-align: center; font-size: 12px; line-height: 12px; background-color: #d2d2d2; + cursor: pointer; } .mw-badge-content { @@ -18,8 +17,12 @@ } .mw-badge-inline { - display: inline-block; margin-left: 3px; + display: inline-block; + /* Hack for IE6 and IE7 (bug 47926) */ + zoom: 1; + *display: inline; + } .mw-badge-overlay { position: absolute; diff --git a/resources/jquery/jquery.byteLength.js b/resources/jquery/jquery.byteLength.js index 3d5b7206..398937e6 100644 --- a/resources/jquery/jquery.byteLength.js +++ b/resources/jquery/jquery.byteLength.js @@ -4,6 +4,8 @@ * Calculate the byte length of a string (accounting for UTF-8). * * @author Jan Paul Posma, 2011 + * @author Timo Tijhof, 2012 + * @author David Chan, 2013 */ jQuery.byteLength = function ( str ) { @@ -12,8 +14,18 @@ jQuery.byteLength = function ( str ) { // Note, surrogate (\uD800-\uDFFF) characters are counted as 2 bytes, since there's two of them // and the actual character takes 4 bytes in UTF-8 (2*2=4). Might not work perfectly in // edge cases such as illegal sequences, but that should never happen. + + // https://en.wikipedia.org/wiki/UTF-8#Description + // The mapping from UTF-16 code units to UTF-8 bytes is as follows: + // > Range 0000-007F: codepoints that become 1 byte of UTF-8 + // > Range 0080-07FF: codepoints that become 2 bytes of UTF-8 + // > Range 0800-D7FF: codepoints that become 3 bytes of UTF-8 + // > Range D800-DFFF: Surrogates (each pair becomes 4 bytes of UTF-8) + // > Range E000-FFFF: codepoints that become 3 bytes of UTF-8 (continued) + return str .replace( /[\u0080-\u07FF\uD800-\uDFFF]/g, '**' ) .replace( /[\u0800-\uD7FF\uE000-\uFFFF]/g, '***' ) .length; + }; diff --git a/resources/jquery/jquery.byteLimit.js b/resources/jquery/jquery.byteLimit.js index f2b98f09..a8c0b065 100644 --- a/resources/jquery/jquery.byteLimit.js +++ b/resources/jquery/jquery.byteLimit.js @@ -78,7 +78,8 @@ // Chop off characters from the end of the "inserted content" string // until the limit is statisfied. if ( fn ) { - while ( $.byteLength( fn( inpParts.join( '' ) ) ) > byteLimit ) { + // stop, when there is nothing to slice - bug 41450 + while ( $.byteLength( fn( inpParts.join( '' ) ) ) > byteLimit && inpParts[1].length > 0 ) { inpParts[1] = inpParts[1].slice( 0, -1 ); } } else { diff --git a/resources/jquery/jquery.checkboxShiftClick.js b/resources/jquery/jquery.checkboxShiftClick.js index aced0633..b2065665 100644 --- a/resources/jquery/jquery.checkboxShiftClick.js +++ b/resources/jquery/jquery.checkboxShiftClick.js @@ -15,11 +15,17 @@ $box.click( function ( e ) { // And one has been clicked before... if ( prevCheckbox !== null && e.shiftKey ) { - // Check or uncheck this one and all in-between checkboxes - $box.slice( - Math.min( $box.index( prevCheckbox ), $box.index( e.target ) ), - Math.max( $box.index( prevCheckbox ), $box.index( e.target ) ) + 1 - ).prop( 'checked', !!e.target.checked ); + // Check or uncheck this one and all in-between checkboxes, + // except for disabled ones + $box + .slice( + Math.min( $box.index( prevCheckbox ), $box.index( e.target ) ), + Math.max( $box.index( prevCheckbox ), $box.index( e.target ) ) + 1 + ) + .filter( function () { + return !this.disabled; + } ) + .prop( 'checked', !!e.target.checked ); } // Either way, update the prevCheckbox variable to the one clicked now prevCheckbox = e.target; diff --git a/resources/jquery/jquery.client.js b/resources/jquery/jquery.client.js index b0bd6850..5a95dc5b 100644 --- a/resources/jquery/jquery.client.js +++ b/resources/jquery/jquery.client.js @@ -6,7 +6,7 @@ /* Private Members */ /** - * @var profileCache {Object} Keyed by userAgent string, + * @var {Object} profileCache Keyed by userAgent string, * value is the parsed $.client.profile object for that user agent. */ var profileCache = {}; @@ -18,9 +18,9 @@ /** * Get an object containing information about the client. * - * @param nav {Object} An object with atleast a 'userAgent' and 'platform' key. + * @param {Object} nav An object with atleast a 'userAgent' and 'platform' key. * Defaults to the global Navigator object. - * @return {Object} The resulting client object will be in the following format: + * @returns {Object} The resulting client object will be in the following format: * { * 'name': 'firefox', * 'layout': 'gecko', @@ -50,47 +50,47 @@ // Generic version digit x = 'x', // Strings found in user agent strings that need to be conformed - wildUserAgents = ['Opera', 'Navigator', 'Minefield', 'KHTML', 'Chrome', 'PLAYSTATION 3'], + wildUserAgents = ['Opera', 'Navigator', 'Minefield', 'KHTML', 'Chrome', 'PLAYSTATION 3', 'Iceweasel'], // Translations for conforming user agent strings userAgentTranslations = [ // Tons of browsers lie about being something they are not - [/(Firefox|MSIE|KHTML,\slike\sGecko|Konqueror)/, ''], + [/(Firefox|MSIE|KHTML,?\slike\sGecko|Konqueror)/, ''], // Chrome lives in the shadow of Safari still ['Chrome Safari', 'Chrome'], // KHTML is the layout engine not the browser - LIES! ['KHTML', 'Konqueror'], // Firefox nightly builds ['Minefield', 'Firefox'], - // This helps keep differnt versions consistent + // This helps keep different versions consistent ['Navigator', 'Netscape'], // This prevents version extraction issues, otherwise translation would happen later ['PLAYSTATION 3', 'PS3'] ], - // Strings which precede a version number in a user agent string - combined and used as match 1 in - // version detectection + // Strings which precede a version number in a user agent string - combined and used as + // match 1 in version detection versionPrefixes = [ 'camino', 'chrome', 'firefox', 'iceweasel', 'netscape', 'netscape6', 'opera', 'version', 'konqueror', - 'lynx', 'msie', 'safari', 'ps3' + 'lynx', 'msie', 'safari', 'ps3', 'android' ], // Used as matches 2, 3 and 4 in version extraction - 3 is used as actual version number versionSuffix = '(\\/|\\;?\\s|)([a-z0-9\\.\\+]*?)(\\;|dev|rel|\\)|\\s|$)', // Names of known browsers names = [ 'camino', 'chrome', 'firefox', 'iceweasel', 'netscape', 'konqueror', 'lynx', 'msie', 'opera', - 'safari', 'ipod', 'iphone', 'blackberry', 'ps3', 'rekonq' + 'safari', 'ipod', 'iphone', 'blackberry', 'ps3', 'rekonq', 'android' ], // Tanslations for conforming browser names nameTranslations = [], // Names of known layout engines - layouts = ['gecko', 'konqueror', 'msie', 'opera', 'webkit'], + layouts = ['gecko', 'konqueror', 'msie', 'trident', 'opera', 'webkit'], // Translations for conforming layout names layoutTranslations = [ ['konqueror', 'khtml'], ['msie', 'trident'], ['opera', 'presto'] ], // Names of supported layout engines for version number - layoutVersions = ['applewebkit', 'gecko'], + layoutVersions = ['applewebkit', 'gecko', 'trident'], // Names of known operating systems - platforms = ['win', 'mac', 'linux', 'sunos', 'solaris', 'iphone'], + platforms = ['win', 'wow64', 'mac', 'linux', 'sunos', 'solaris', 'iphone'], // Translations for conforming operating system names - platformTranslations = [ ['sunos', 'solaris'] ], + platformTranslations = [ ['sunos', 'solaris'], ['wow64', 'win'] ], /* Methods */ @@ -143,18 +143,33 @@ /* Edge Cases -- did I mention about how user agent string lie? */ // Decode Safari's crazy 400+ version numbers - if ( name.match( /safari/ ) && version > 400 ) { + if ( name === 'safari' && version > 400 ) { version = '2.0'; } // Expose Opera 10's lies about being Opera 9.8 - if ( name === 'opera' && version >= 9.8) { - match = ua.match( /version\/([0-9\.]*)/i ); + if ( name === 'opera' && version >= 9.8 ) { + match = ua.match( /\bversion\/([0-9\.]*)/ ); if ( match && match[1] ) { version = match[1]; } else { version = '10'; } } + // And Opera 15's lies about being Chrome + if ( name === 'chrome' && ( match = ua.match( /\bopr\/([0-9\.]*)/ ) ) ) { + if ( match[1] ) { + name = 'opera'; + version = match[1]; + } + } + // And IE 11's lies about being not being IE + if ( layout === 'trident' && layoutversion >= 7 && ( match = ua.match( /\brv[ :\/]([0-9\.]*)/ ) ) ) { + if ( match[1] ) { + name = 'msie'; + version = match[1]; + } + } + versionNumber = parseFloat( version, 10 ) || 0.0; /* Caching */ @@ -173,46 +188,61 @@ }, /** - * Checks the current browser against a support map object to determine if the browser has been black-listed or - * not. If the browser was not configured specifically it is assumed to work. It is assumed that the body - * element is classified as either "ltr" or "rtl". If neither is set, "ltr" is assumed. + * Checks the current browser against a support map object. * * A browser map is in the following format: * { + * // Multiple rules with configurable operators + * 'msie': [['>=', 7], ['!=', 9]], + * // Match no versions + * 'iphone': false, + * // Match any version + * 'android': null + * } + * + * It can optionally be split into ltr/rtl sections: + * { * 'ltr': { - * // Multiple rules with configurable operators - * 'msie': [['>=', 7], ['!=', 9]], - * // Blocked entirely + * 'android': null, * 'iphone': false * }, * 'rtl': { - * // Test against a string - * 'msie': [['!==', '8.1.2.3']], - * // RTL rules do not fall through to LTR rules, you must explicity set each of them + * 'android': false, + * // rules are not inherited from ltr * 'iphone': false * } * } * - * @param map {Object} Browser support map - * @param profile {Object} (optional) a client-profile object. + * @param {Object} map Browser support map + * @param {Object} [profile] A client-profile object + * @param {boolean} [exactMatchOnly=false] Only return true if the browser is matched, otherwise + * returns true if the browser is not found. * - * @return Boolean true if browser known or assumed to be supported, false if blacklisted + * @returns {boolean} The current browser is in the support map */ - test: function ( map, profile ) { + test: function ( map, profile, exactMatchOnly ) { /*jshint evil: true */ var conditions, dir, i, op, val; profile = $.isPlainObject( profile ) ? profile : $.client.profile(); - dir = $( 'body' ).is( '.rtl' ) ? 'rtl' : 'ltr'; + if ( map.ltr && map.rtl ) { + dir = $( 'body' ).is( '.rtl' ) ? 'rtl' : 'ltr'; + map = map[dir]; + } // Check over each browser condition to determine if we are running in a compatible client - if ( typeof map[dir] !== 'object' || map[dir][profile.name] === undefined ) { - // Unknown, so we assume it's working - return true; + if ( typeof map !== 'object' || map[profile.name] === undefined ) { + // Not found, return true if exactMatchOnly not set, false otherwise + return !exactMatchOnly; } - conditions = map[dir][profile.name]; + conditions = map[profile.name]; if ( conditions === false ) { + // Match no versions return false; } + if ( conditions === null ) { + // Match all versions + return true; + } for ( i = 0; i < conditions.length; i++ ) { op = conditions[i][0]; val = conditions[i][1]; diff --git a/resources/jquery/jquery.makeCollapsible.js b/resources/jquery/jquery.makeCollapsible.js index 1407f53b..0cd6417c 100644 --- a/resources/jquery/jquery.makeCollapsible.js +++ b/resources/jquery/jquery.makeCollapsible.js @@ -18,13 +18,15 @@ var lpx = 'jquery.makeCollapsible> '; /** + * Handler for a click on a collapsible toggler. + * * @param {jQuery} $collapsible * @param {string} action The action this function will take ('expand' or 'collapse'). * @param {jQuery|null} [optional] $defaultToggle * @param {Object|undefined} options */ function toggleElement( $collapsible, action, $defaultToggle, options ) { - var $collapsibleContent, $containers; + var $collapsibleContent, $containers, hookCallback; options = options || {}; // Validate parameters @@ -47,6 +49,14 @@ return; } + // Trigger a custom event to allow callers to hook to the collapsing/expanding, + // allowing the module to be testable, and making it possible to + // e.g. implement persistence via cookies + $collapsible.trigger( action === 'expand' ? 'beforeExpand.mw-collapsible' : 'beforeCollapse.mw-collapsible' ); + hookCallback = function () { + $collapsible.trigger( action === 'expand' ? 'afterExpand.mw-collapsible' : 'afterCollapse.mw-collapsible' ); + }; + // Handle different kinds of elements if ( !options.plainMode && $collapsible.is( 'table' ) ) { @@ -63,11 +73,12 @@ // http://stackoverflow.com/questions/467336#920480 if ( options.instantHide ) { $containers.hide(); + hookCallback(); } else { - $containers.stop( true, true ).fadeOut(); + $containers.stop( true, true ).fadeOut().promise().done( hookCallback ); } } else { - $containers.stop( true, true ).fadeIn(); + $containers.stop( true, true ).fadeIn().promise().done( hookCallback ); } } else if ( !options.plainMode && ( $collapsible.is( 'ul' ) || $collapsible.is( 'ol' ) ) ) { @@ -81,11 +92,12 @@ if ( action === 'collapse' ) { if ( options.instantHide ) { $containers.hide(); + hookCallback(); } else { - $containers.stop( true, true ).slideUp(); + $containers.stop( true, true ).slideUp().promise().done( hookCallback ); } } else { - $containers.stop( true, true ).slideDown(); + $containers.stop( true, true ).slideDown().promise().done( hookCallback ); } } else { @@ -97,11 +109,12 @@ if ( action === 'collapse' ) { if ( options.instantHide ) { $collapsibleContent.hide(); + hookCallback(); } else { - $collapsibleContent.slideUp(); + $collapsibleContent.slideUp().promise().done( hookCallback ); } } else { - $collapsibleContent.slideDown(); + $collapsibleContent.slideDown().promise().done( hookCallback ); } // Otherwise assume this is a customcollapse with a remote toggle @@ -110,18 +123,19 @@ if ( action === 'collapse' ) { if ( options.instantHide ) { $collapsible.hide(); + hookCallback(); } else { if ( $collapsible.is( 'tr' ) || $collapsible.is( 'td' ) || $collapsible.is( 'th' ) ) { - $collapsible.fadeOut(); + $collapsible.fadeOut().promise().done( hookCallback ); } else { - $collapsible.slideUp(); + $collapsible.slideUp().promise().done( hookCallback ); } } } else { if ( $collapsible.is( 'tr' ) || $collapsible.is( 'td' ) || $collapsible.is( 'th' ) ) { - $collapsible.fadeIn(); + $collapsible.fadeIn().promise().done( hookCallback ); } else { - $collapsible.slideDown(); + $collapsible.slideDown().promise().done( hookCallback ); } } } @@ -129,7 +143,7 @@ } /** - * Handles clicking on the collapsible element toggle and other + * Handles clicking/keypressing on the collapsible element toggle and other * situations where a collapsible element is toggled (e.g. the initial * toggle for collapsed ones). * @@ -138,20 +152,32 @@ * @param {jQuery.Event|null} e either the event or null if unavailable * @param {Object|undefined} options */ - function togglingHandler( $toggle, $collapsible, event, options ) { + function togglingHandler( $toggle, $collapsible, e, options ) { var wasCollapsed, $textContainer, collapseText, expandText; - if ( event ) { - // Don't fire if a link was clicked, if requested (for premade togglers by default) - if ( options.linksPassthru && $.nodeName( event.target, 'a' ) ) { - return true; + if ( options === undefined ) { + options = {}; + } + + if ( e ) { + if ( e.type === 'click' && options.linksPassthru && $.nodeName( e.target, 'a' ) ) { + // Don't fire if a link was clicked, if requested (for premade togglers by default) + return; + } else if ( e.type === 'keypress' && e.which !== 13 && e.which !== 32 ) { + // Only handle keypresses on the "Enter" or "Space" keys + return; } else { - event.preventDefault(); - event.stopPropagation(); + e.preventDefault(); + e.stopPropagation(); } } - wasCollapsed = $collapsible.hasClass( 'mw-collapsed' ); + // This allows the element to be hidden on initial toggle without fiddling with the class + if ( options.wasCollapsed !== undefined ) { + wasCollapsed = options.wasCollapsed; + } else { + wasCollapsed = $collapsible.hasClass( 'mw-collapsed' ); + } // Toggle the state of the collapsible element (that is, expand or collapse) $collapsible.toggleClass( 'mw-collapsed', !wasCollapsed ); @@ -180,45 +206,6 @@ } /** - * Toggles collapsible and togglelink class and updates text label. - * - * @param {jQuery} $that - * @param {jQuery.Event} e - * @param {Object|undefined} options - */ - function toggleLinkDefault( $that, e, options ) { - var $collapsible = $that.closest( '.mw-collapsible' ); - options = $.extend( { toggleClasses: true }, options ); - togglingHandler( $that, $collapsible, e, options ); - } - - /** - * Toggles collapsible and togglelink class. - * - * @param {jQuery} $that - * @param {jQuery.Event} e - * @param {Object|undefined} options - */ - function toggleLinkPremade( $that, e, options ) { - var $collapsible = $that.eq( 0 ).closest( '.mw-collapsible' ); - options = $.extend( { toggleClasses: true, linksPassthru: true }, options ); - togglingHandler( $that, $collapsible, e, options ); - } - - /** - * Toggles customcollapsible. - * - * @param {jQuery} $that - * @param {jQuery.Event} e - * @param {Object|undefined} options - * @param {jQuery} $collapsible - */ - function toggleLinkCustom( $that, e, options, $collapsible ) { - options = $.extend( {}, options ); - togglingHandler( $that, $collapsible, e, options ); - } - - /** * Make any element collapsible. * * Supported options: @@ -243,17 +230,17 @@ * div.mw-collapsible-content. May only be used with custom togglers. */ $.fn.makeCollapsible = function ( options ) { - return this.each(function () { - var $collapsible, collapsetext, expandtext, $toggle, $toggleLink, $firstItem, collapsibleId, - $customTogglers, firstval; + if ( options === undefined ) { + options = {}; + } - if ( options === undefined ) { - options = {}; - } + return this.each( function () { + var $collapsible, collapseText, expandText, $toggle, actionHandler, buildDefaultToggleLink, + premadeToggleHandler, $toggleLink, $firstItem, collapsibleId, $customTogglers, firstval; // Ensure class "mw-collapsible" is present in case .makeCollapsible() // is called on element(s) that don't have it yet. - $collapsible = $(this).addClass( 'mw-collapsible' ); + $collapsible = $( this ).addClass( 'mw-collapsible' ); // Return if it has been enabled already. if ( $collapsible.data( 'mw-made-collapsible' ) ) { @@ -263,21 +250,35 @@ } // Use custom text or default? - collapsetext = options.collapseText || $collapsible.attr( 'data-collapsetext' ) || mw.msg( 'collapsible-collapse' ); - expandtext = options.expandText || $collapsible.attr( 'data-expandtext' ) || mw.msg( 'collapsible-expand' ); - - // Create toggle link with a space around the brackets ( [text] ) - $toggleLink = - $( '<a href="#"></a>' ) - .text( collapsetext ) + collapseText = options.collapseText || $collapsible.attr( 'data-collapsetext' ) || mw.msg( 'collapsible-collapse' ); + expandText = options.expandText || $collapsible.attr( 'data-expandtext' ) || mw.msg( 'collapsible-expand' ); + + // Default click/keypress handler and toggle link to use when none is present + actionHandler = function ( e, opts ) { + var defaultOpts = { + toggleClasses: true, + toggleText: { collapseText: collapseText, expandText: expandText } + }; + opts = $.extend( defaultOpts, options, opts ); + togglingHandler( $( this ), $collapsible, e, opts ); + }; + // Default toggle link. Only build it when needed to avoid jQuery memory leaks (event data). + buildDefaultToggleLink = function () { + return $( '<a href="#"></a>' ) + .text( collapseText ) .wrap( '<span class="mw-collapsible-toggle"></span>' ) .parent() .prepend( ' [' ) .append( '] ' ) - .on( 'click.mw-collapse', function ( e, opts ) { - opts = $.extend( { toggleText: { collapseText: collapsetext, expandText: expandtext } }, options, opts ); - toggleLinkDefault( $(this), e, opts ); - } ); + .on( 'click.mw-collapsible keypress.mw-collapsible', actionHandler ); + }; + + // Default handler for clicking on premade toggles + premadeToggleHandler = function ( e, opts ) { + var defaultOpts = { toggleClasses: true, linksPassthru: true }; + opts = $.extend( defaultOpts, options, opts ); + togglingHandler( $( this ), $collapsible, e, opts ); + }; // Check if this element has a custom position for the toggle link // (ie. outside the container or deeper inside the tree) @@ -296,25 +297,21 @@ } } - // Bind the custom togglers + // Bind the togglers if ( $customTogglers && $customTogglers.length ) { - $customTogglers.on( 'click.mw-collapse', function ( e, opts ) { - opts = $.extend( {}, options, opts ); - toggleLinkCustom( $(this), e, opts, $collapsible ); - } ); - - // Initial state - if ( options.collapsed || $collapsible.hasClass( 'mw-collapsed' ) ) { - // Remove here so that the toggler goes in the right direction, - // It re-adds the class. - $collapsible.removeClass( 'mw-collapsed' ); - toggleLinkCustom( $customTogglers, null, $.extend( { instantHide: true }, options ), $collapsible ); - } + actionHandler = function ( e, opts ) { + var defaultOpts = {}; + opts = $.extend( defaultOpts, options, opts ); + togglingHandler( $( this ), $collapsible, e, opts ); + }; + + $toggleLink = $customTogglers; + $toggleLink.on( 'click.mw-collapsible keypress.mw-collapsible', actionHandler ); - // If this is not a custom case, do the default: - // Wrap the contents and add the toggle link } else { - // Elements are treated differently + // If this is not a custom case, do the default: wrap the + // contents and add the toggle link. Different elements are + // treated differently. if ( $collapsible.is( 'table' ) ) { // The toggle-link will be in one the the cells (td or th) of the first row $firstItem = $collapsible.find( 'tr:first th, tr:first td' ); @@ -322,12 +319,10 @@ // If theres no toggle link, add it to the last cell if ( !$toggle.length ) { - $firstItem.eq(-1).prepend( $toggleLink ); + $toggleLink = buildDefaultToggleLink().prependTo( $firstItem.eq( -1 ) ); } else { - $toggleLink = $toggle.off( 'click.mw-collapse' ).on( 'click.mw-collapse', function ( e, opts ) { - opts = $.extend( {}, options, opts ); - toggleLinkPremade( $toggle, e, opts ); - } ); + actionHandler = premadeToggleHandler; + $toggleLink = $toggle.on( 'click.mw-collapsible keypress.mw-collapsible', actionHandler ); } } else if ( $collapsible.is( 'ul' ) || $collapsible.is( 'ol' ) ) { @@ -339,17 +334,16 @@ if ( !$toggle.length ) { // Make sure the numeral order doesn't get messed up, force the first (soon to be second) item // to be "1". Except if the value-attribute is already used. - // If no value was set WebKit returns "", Mozilla returns '-1', others return null or undefined. + // If no value was set WebKit returns "", Mozilla returns '-1', others return 0, null or undefined. firstval = $firstItem.attr( 'value' ); if ( firstval === undefined || !firstval || firstval === '-1' || firstval === -1 ) { $firstItem.attr( 'value', '1' ); } - $collapsible.prepend( $toggleLink.wrap( '<li class="mw-collapsible-toggle-li"></li>' ).parent() ); + $toggleLink = buildDefaultToggleLink(); + $toggleLink.wrap( '<li class="mw-collapsible-toggle-li"></li>' ).parent().prependTo( $collapsible ); } else { - $toggleLink = $toggle.off( 'click.mw-collapse' ).on( 'click.mw-collapse', function ( e, opts ) { - opts = $.extend( {}, options, opts ); - toggleLinkPremade( $toggle, e, opts ); - } ); + actionHandler = premadeToggleHandler; + $toggleLink = $toggle.on( 'click.mw-collapsible keypress.mw-collapsible', actionHandler ); } } else { // <div>, <p> etc. @@ -364,28 +358,23 @@ // If theres no toggle link, add it if ( !$toggle.length ) { - $collapsible.prepend( $toggleLink ); + $toggleLink = buildDefaultToggleLink().prependTo( $collapsible ); } else { - $toggleLink = $toggle.off( 'click.mw-collapse' ).on( 'click.mw-collapse', function ( e, opts ) { - opts = $.extend( {}, options, opts ); - toggleLinkPremade( $toggle, e, opts ); - } ); + actionHandler = premadeToggleHandler; + $toggleLink = $toggle.on( 'click.mw-collapsible keypress.mw-collapsible', actionHandler ); } } } - // Initial state (only for those that are not custom, - // because the initial state of those has been taken care of already). - if ( - ( options.collapsed || $collapsible.hasClass( 'mw-collapsed' ) ) && - ( !$customTogglers || !$customTogglers.length ) - ) { - $collapsible.removeClass( 'mw-collapsed' ); - // The collapsible element could have multiple togglers - // To toggle the initial state only click one of them (ie. the first one, eq(0) ) - // Else it would go like: hide,show,hide,show for each toggle link. - // This is just like it would be in reality (only one toggle is clicked at a time). - $toggleLink.eq( 0 ).trigger( 'click', [ { instantHide: true } ] ); + // Attributes for accessibility. This isn't necessary when the toggler is already + // an <a> or a <button> etc., but it doesn't hurt either, and it's consistent. + $toggleLink.prop( 'tabIndex', 0 ); + + // Initial state + if ( options.collapsed || $collapsible.hasClass( 'mw-collapsed' ) ) { + // One toggler can hook to multiple elements, and one element can have + // multiple togglers. This is the sanest way to handle that. + actionHandler.call( $toggleLink.get( 0 ), null, { instantHide: true, wasCollapsed: false } ); } } ); }; diff --git a/resources/jquery/jquery.placeholder.js b/resources/jquery/jquery.placeholder.js index 7badb11a..8044d880 100644 --- a/resources/jquery/jquery.placeholder.js +++ b/resources/jquery/jquery.placeholder.js @@ -10,17 +10,22 @@ */ ( function ( $ ) { - $.fn.placeholder = function () { + $.fn.placeholder = function ( text ) { + var hasArg = arguments.length; return this.each( function () { var placeholder, $input; + if ( hasArg ) { + this.setAttribute( 'placeholder', text ); + } + // If the HTML5 placeholder attribute is supported, use it if ( this.placeholder && 'placeholder' in document.createElement( this.tagName ) ) { return; } - placeholder = this.getAttribute( 'placeholder' ); + placeholder = hasArg ? text : this.getAttribute( 'placeholder' ); $input = $(this); // Show initially, if empty diff --git a/resources/jquery/jquery.spinner.css b/resources/jquery/jquery.spinner.css index 4a775283..a9e06dbe 100644 --- a/resources/jquery/jquery.spinner.css +++ b/resources/jquery/jquery.spinner.css @@ -33,7 +33,7 @@ .mw-spinner-inline { display: inline-block; vertical-align: middle; - + /* IE < 8 */ zoom: 1; *display: inline; diff --git a/resources/jquery/jquery.spinner.js b/resources/jquery/jquery.spinner.js index 93e30b9a..27dabc6c 100644 --- a/resources/jquery/jquery.spinner.js +++ b/resources/jquery/jquery.spinner.js @@ -1,7 +1,9 @@ /** - * jQuery spinner + * jQuery Spinner * * Simple jQuery plugin to create, inject and remove spinners. + * + * @class jQuery.plugin.spinner */ ( function ( $ ) { @@ -15,36 +17,37 @@ $.extend({ /** - * Creates a spinner element. + * Create a spinner element * * The argument is an object with options used to construct the spinner. These can be: * * It is a good practice to keep a reference to the created spinner to be able to remove it later. - * Alternatively one can use the id option and removeSpinner() (but make sure to choose an id + * Alternatively one can use the id option and #removeSpinner (but make sure to choose an id * that's unlikely to cause conflicts, e.g. with extensions, gadgets or user scripts). * * CSS classes used: - * .mw-spinner for every spinner - * .mw-spinner-small / .mw-spinner-large for size - * .mw-spinner-block / .mw-spinner-inline for display types + * - .mw-spinner for every spinner + * - .mw-spinner-small / .mw-spinner-large for size + * - .mw-spinner-block / .mw-spinner-inline for display types * - * @example * // Create a large spinner reserving all available horizontal space. * var $spinner = $.createSpinner({ size: 'large', type: 'block' }); * // Insert above page content. * $( '#mw-content-text' ).prepend( $spinner ); - * @example + * * // Place a small inline spinner next to the "Save" button * var $spinner = $.createSpinner({ size: 'small', type: 'inline' }); * // Alternatively, just `$.createSpinner();` as these are the default options. * $( '#wpSave' ).after( $spinner ); - * @example + * * // The following two are equivalent: * $.createSpinner( 'magic' ); * $.createSpinner({ id: 'magic' }); * - * @param {Object|String} opts [optional] ID string or options: - * - id: If given, spinner will be given an id of "mw-spinner-<id>" + * @static + * @inheritable + * @param {Object|string} [opts] ID string or options: + * - id: If given, spinner will be given an id of "mw-spinner-{id}" * - size: 'small' (default) or 'large' for a 20-pixel or 32-pixel spinner * - type: 'inline' (default) or 'block'. Inline creates an inline-block with width and * height equal to spinner size. Block is a block-level element with width 100%, height @@ -72,10 +75,12 @@ }, /** - * Removes a spinner element. + * Remove a spinner element * - * @param {String} id [optional] Id of the spinner, as passed to createSpinner. - * @return {jQuery} The (now detached) spinner. + * @static + * @inheritable + * @param {string} id Id of the spinner, as passed to #createSpinner + * @return {jQuery} The (now detached) spinner element */ removeSpinner: function ( id ) { return $( '#mw-spinner-' + id ).remove(); @@ -83,13 +88,21 @@ }); /** - * Injects a spinner after the elements in the jQuery collection - * (as siblings, not children). Collection contents remain unchanged. + * Inject a spinner after each element in the collection + * + * Inserts spinner as siblings, not children, of the target elements. + * Collection contents remain unchanged. * - * @param {Object|String} opts See createSpinner() for description. + * @param {Object|string} [opts] See #createSpinner * @return {jQuery} */ $.fn.injectSpinner = function ( opts ) { return this.after( $.createSpinner( opts ) ); }; + + /** + * @class jQuery + * @mixins jQuery.plugin.spinner + */ + }( jQuery ) ); diff --git a/resources/jquery/jquery.suggestions.js b/resources/jquery/jquery.suggestions.js index 44382f0d..28e2afc4 100644 --- a/resources/jquery/jquery.suggestions.js +++ b/resources/jquery/jquery.suggestions.js @@ -220,7 +220,7 @@ $.suggestions = { } else { // Expand from right newCSS.left = 'auto'; - newCSS.right = $( 'body' ).width() - ( context.config.$region.offset().left + context.config.$region.outerWidth() ); + newCSS.right = $( document ).width() - ( context.config.$region.offset().left + context.config.$region.outerWidth() ); } context.data.$container.css( newCSS ); @@ -585,10 +585,12 @@ $.fn.suggestions = function () { switch ( context.data.keypressed ) { // This preventDefault logic is duplicated from // $.suggestions.keypress(), which sucks + // Arrow down case 40: e.preventDefault(); e.stopImmediatePropagation(); break; + // Arrow up, Escape and Enter case 38: case 27: case 13: diff --git a/resources/jquery/jquery.tablesorter.js b/resources/jquery/jquery.tablesorter.js index e08c9aaf..b3d7bb3d 100644 --- a/resources/jquery/jquery.tablesorter.js +++ b/resources/jquery/jquery.tablesorter.js @@ -8,8 +8,9 @@ * http://www.opensource.org/licenses/mit-license.php * http://www.gnu.org/licenses/gpl.html * - * Depends on mw.config (wgDigitTransformTable, wgMonthNames, wgMonthNamesShort, - * wgDefaultDateFormat, wgContentLanguage) + * Depends on mw.config (wgDigitTransformTable, wgDefaultDateFormat, wgContentLanguage) + * and mw.language.months. + * * Uses 'tableSorterCollation' in mw.config (if available) */ /** @@ -287,44 +288,113 @@ function buildHeaders( table, msg ) { var maxSeen = 0, + colspanOffset = 0, longest, - realCellIndex = 0, - $tableHeaders = $( 'thead:eq(0) > tr', table ); - if ( $tableHeaders.length > 1 ) { - $tableHeaders.each( function () { - if ( this.cells.length > maxSeen ) { - maxSeen = this.cells.length; - longest = this; + columns, + i, + $tableHeaders = $( [] ), + $tableRows = $( 'thead:eq(0) > tr', table ); + if ( $tableRows.length <= 1 ) { + $tableHeaders = $tableRows.children( 'th' ); + } else { + // We need to find the cells of the row containing the most columns + var rowspan, + headersIndex = []; + $tableRows.each( function ( rowIndex ) { + $.each( this.cells, function( index2, cell ) { + rowspan = Number( cell.rowSpan ); + for ( i = 0; i < rowspan; i++ ) { + if ( headersIndex[rowIndex+i] === undefined ) { + headersIndex[rowIndex+i] = $( [] ); + } + headersIndex[rowIndex+i].push( cell ); + } + } ); + } ); + $.each( headersIndex, function ( index, cellArray ) { + if ( cellArray.length >= maxSeen ) { + maxSeen = cellArray.length; + longest = index; } - }); - $tableHeaders = $( longest ); + } ); + $tableHeaders = headersIndex[longest]; } - $tableHeaders = $tableHeaders.children( 'th' ).each( function ( index ) { - this.column = realCellIndex; - var colspan = this.colspan; - colspan = colspan ? parseInt( colspan, 10 ) : 1; - realCellIndex += colspan; + // as each header can span over multiple columns (using colspan=N), + // we have to bidirectionally map headers to their columns and columns to their headers + table.headerToColumns = []; + table.columnToHeader = []; + + $tableHeaders.each( function ( headerIndex ) { + columns = []; + for ( i = 0; i < this.colSpan; i++ ) { + table.columnToHeader[ colspanOffset + i ] = headerIndex; + columns.push( colspanOffset + i ); + } + + table.headerToColumns[ headerIndex ] = columns; + colspanOffset += this.colSpan; + this.headerIndex = headerIndex; this.order = 0; this.count = 0; - if ( $( this ).is( '.unsortable' ) ) { + if ( $( this ).hasClass( table.config.unsortableClass ) ) { this.sortDisabled = true; } if ( !this.sortDisabled ) { - $( this ).addClass( table.config.cssHeader ).attr( 'title', msg[1] ); + $( this ) + .addClass( table.config.cssHeader ) + .prop( 'tabIndex', 0 ) + .attr( { + role: 'columnheader button', + title: msg[1] + } ); } // add cell to headerList - table.config.headerList[index] = this; + table.config.headerList[headerIndex] = this; } ); return $tableHeaders; } + /** + * Sets the sort count of the columns that are not affected by the sorting to have them sorted + * in default (ascending) order when their header cell is clicked the next time. + * + * @param {jQuery} $headers + * @param {Number[][]} sortList + * @param {Number[][]} headerToColumns + */ + function setHeadersOrder( $headers, sortList, headerToColumns ) { + // Loop through all headers to retrieve the indices of the columns the header spans across: + $.each( headerToColumns, function( headerIndex, columns ) { + + $.each( columns, function( i, columnIndex ) { + var header = $headers[headerIndex]; + + if ( !isValueInArray( columnIndex, sortList ) ) { + // Column shall not be sorted: Reset header count and order. + header.order = 0; + header.count = 0; + } else { + // Column shall be sorted: Apply designated count and order. + $.each( sortList, function( j, sortColumn ) { + if ( sortColumn[0] === i ) { + header.order = sortColumn[1]; + header.count = sortColumn[1] + 1; + return false; + } + } ); + } + } ); + + } ); + } + function isValueInArray( v, a ) { var l = a.length; for ( var i = 0; i < l; i++ ) { @@ -407,12 +477,15 @@ var regex = []; ts.monthNames = {}; - for ( var i = 1; i < 13; i++ ) { - var name = mw.config.get( 'wgMonthNames' )[i].toLowerCase(); - ts.monthNames[name] = i; + for ( var i = 0; i < 12; i++ ) { + var name = mw.language.months.names[i].toLowerCase(); + ts.monthNames[name] = i + 1; regex.push( $.escapeRE( name ) ); - name = mw.config.get( 'wgMonthNamesShort' )[i].toLowerCase().replace( '.', '' ); - ts.monthNames[name] = i; + name = mw.language.months.genitive[i].toLowerCase(); + ts.monthNames[name] = i + 1; + regex.push( $.escapeRE( name ) ); + name = mw.language.months.abbrev[i].toLowerCase().replace( '.', '' ); + ts.monthNames[name] = i + 1; regex.push( $.escapeRE( name ) ); } @@ -424,10 +497,10 @@ ts.dateRegex[0] = new RegExp( /^\s*(\d{1,2})[\,\.\-\/'\s]{1,2}(\d{1,2})[\,\.\-\/'\s]{1,2}(\d{2,4})\s*?/i); // Written Month name, dmy - ts.dateRegex[1] = new RegExp( '^\\s*(\\d{1,2})[\\,\\.\\-\\/\'\\s]*(' + regex + ')' + '[\\,\\.\\-\\/\'\\s]*(\\d{2,4})\\s*$', 'i' ); + ts.dateRegex[1] = new RegExp( '^\\s*(\\d{1,2})[\\,\\.\\-\\/\'\\s]+(' + regex + ')' + '[\\,\\.\\-\\/\'\\s]+(\\d{2,4})\\s*$', 'i' ); // Written Month name, mdy - ts.dateRegex[2] = new RegExp( '^\\s*(' + regex + ')' + '[\\,\\.\\-\\/\'\\s]*(\\d{1,2})[\\,\\.\\-\\/\'\\s]*(\\d{2,4})\\s*$', 'i' ); + ts.dateRegex[2] = new RegExp( '^\\s*(' + regex + ')' + '[\\,\\.\\-\\/\'\\s]+(\\d{1,2})[\\,\\.\\-\\/\'\\s]+(\\d{2,4})\\s*$', 'i' ); } @@ -572,7 +645,7 @@ $.each( sortObjects, function( i, sortObject ) { $.each ( sortObject, function( columnIndex, order ) { var orderIndex = ( order === 'desc' ) ? 1 : 0; - sortList.push( [columnIndex, orderIndex] ); + sortList.push( [parseInt( columnIndex, 10 ), orderIndex] ); } ); } ); return sortList; @@ -590,6 +663,7 @@ sortInitialOrder: 'asc', sortMultiSortKey: 'shiftKey', sortLocaleCompare: false, + unsortableClass: 'unsortable', parsers: {}, widgets: [], headers: {}, @@ -611,7 +685,6 @@ return $tables.each( function ( i, table ) { // Declare and cache. var $headers, cache, config, - headerToColumns, columnToHeader, colspanOffset, $table = $( table ), firstTime = true; @@ -648,10 +721,9 @@ // Build headers $headers = buildHeaders( table, sortMsg ); - // Grab and process locale settings + // Grab and process locale settings. buildTransformTable(); buildDateTable(); - buildCollationTable(); // Precaching regexps can bring 10 fold // performance improvements in some browsers. @@ -660,6 +732,12 @@ function setupForFirstSort() { firstTime = false; + // Defer buildCollationTable to first sort. As user and site scripts + // may customize tableSorterCollation but load after $.ready(), other + // scripts may call .tablesorter() before they have done the + // tableSorterCollation customizations. + buildCollationTable(); + // Legacy fix of .sortbottoms // Wrap them inside inside a tfoot (because that's what they actually want to be) & // and put the <tfoot> at the end of the <table> @@ -679,28 +757,17 @@ table.config.parsers = buildParserCache( table, $headers ); } - // as each header can span over multiple columns (using colspan=N), - // we have to bidirectionally map headers to their columns and columns to their headers - headerToColumns = []; - columnToHeader = []; - colspanOffset = 0; - $headers.each( function ( headerIndex ) { - var columns = []; - for ( var i = 0; i < this.colSpan; i++ ) { - columnToHeader[ colspanOffset + i ] = headerIndex; - columns.push( colspanOffset + i ); - } - - headerToColumns[ headerIndex ] = columns; - colspanOffset += this.colSpan; - } ); - // Apply event handling to headers // this is too big, perhaps break it out? - $headers.filter( ':not(.unsortable)' ).click( function ( e ) { - if ( e.target.nodeName.toLowerCase() === 'a' ) { - // The user clicked on a link inside a table header - // Do nothing and let the default link click action continue + $headers.not( '.' + table.config.unsortableClass ).on( 'keypress click', function ( e ) { + if ( e.type === 'click' && e.target.nodeName.toLowerCase() === 'a' ) { + // The user clicked on a link inside a table header. + // Do nothing and let the default link click action continue. + return true; + } + + if ( e.type === 'keypress' && e.which !== 13 ) { + // Only handle keypresses on the "Enter" key. return true; } @@ -724,7 +791,7 @@ var cell = this; // Get current column index - var columns = headerToColumns[this.column]; + var columns = table.headerToColumns[ this.headerIndex ]; var newSortList = $.map( columns, function (c) { // jQuery "helpfully" flattens the arrays... return [[c, cell.order]]; @@ -758,8 +825,11 @@ } } + // Reset order/counts of cells not affected by sorting + setHeadersOrder( $headers, config.sortList, table.headerToColumns ); + // Set CSS for headers - setHeadersCss( $table[0], $headers, config.sortList, sortCSS, sortMsg, columnToHeader ); + setHeadersCss( $table[0], $headers, config.sortList, sortCSS, sortMsg, table.columnToHeader ); appendToTable( $table[0], multisort( $table[0], config.sortList, cache ) ); @@ -798,11 +868,15 @@ sortList = convertSortList( sortList ); } + // Set each column's sort count to be able to determine the correct sort + // order when clicking on a header cell the next time + setHeadersOrder( $headers, sortList, table.headerToColumns ); + // re-build the cache for the tbody cells cache = buildCache( table ); // set css for headers - setHeadersCss( table, $headers, sortList, sortCSS, sortMsg, columnToHeader ); + setHeadersCss( table, $headers, sortList, sortCSS, sortMsg, table.columnToHeader ); // sort the table and append it to the dom appendToTable( table, multisort( table, sortList, cache ) ); diff --git a/resources/jquery/jquery.textSelection.js b/resources/jquery/jquery.textSelection.js index daff9d93..2b5a4406 100644 --- a/resources/jquery/jquery.textSelection.js +++ b/resources/jquery/jquery.textSelection.js @@ -89,7 +89,7 @@ * Ported from skins/common/edit.js by Trevor Parscal * (c) 2009 Wikimedia Foundation (GPLv2) - http://www.wikimedia.org * - * Inserts text at the begining and end of a text selection, optionally + * Inserts text at the beginning and end of a text selection, optionally * inserting text at the caret when selection is empty. * * @fixme document the options parameters @@ -257,7 +257,7 @@ * Some code copied from * http://www.dedestruct.com/2008/03/22/howto-cross-browser-cursor-position-in-textareas/ * - * Get the position (in resolution of bytes not nessecarily characters) + * Get the position (in resolution of bytes not necessarily characters) * in a textarea * * Will focus the textarea in some browsers (IE/Opera) |