From 4ac9fa081a7c045f6a9f1cfc529d82423f485b2e Mon Sep 17 00:00:00 2001 From: Pierre Schmitz Date: Sun, 8 Dec 2013 09:55:49 +0100 Subject: Update to MediaWiki 1.22.0 --- .../images/jquery.arrowSteps.divider-ltr.png | Bin 135 -> 126 bytes .../images/jquery.arrowSteps.divider-rtl.png | Bin 139 -> 127 bytes .../jquery/images/jquery.arrowSteps.head-ltr.png | Bin 390 -> 303 bytes .../jquery/images/jquery.arrowSteps.head-rtl.png | Bin 365 -> 311 bytes .../jquery/images/jquery.arrowSteps.tail-ltr.png | Bin 223 -> 222 bytes resources/jquery/images/marker.png | Bin 652 -> 472 bytes resources/jquery/images/mask.png | Bin 2020 -> 1795 bytes resources/jquery/jquery.badge.css | 9 +- resources/jquery/jquery.byteLength.js | 12 ++ resources/jquery/jquery.byteLimit.js | 3 +- resources/jquery/jquery.checkboxShiftClick.js | 16 +- resources/jquery/jquery.client.js | 100 +++++---- resources/jquery/jquery.makeCollapsible.js | 231 ++++++++++----------- resources/jquery/jquery.placeholder.js | 9 +- resources/jquery/jquery.spinner.css | 2 +- resources/jquery/jquery.spinner.js | 47 +++-- resources/jquery/jquery.suggestions.js | 4 +- resources/jquery/jquery.tablesorter.js | 180 +++++++++++----- resources/jquery/jquery.textSelection.js | 4 +- 19 files changed, 376 insertions(+), 241 deletions(-) (limited to 'resources/jquery') diff --git a/resources/jquery/images/jquery.arrowSteps.divider-ltr.png b/resources/jquery/images/jquery.arrowSteps.divider-ltr.png index 83d6ff84..84ed2a2d 100644 Binary files a/resources/jquery/images/jquery.arrowSteps.divider-ltr.png and b/resources/jquery/images/jquery.arrowSteps.divider-ltr.png differ diff --git a/resources/jquery/images/jquery.arrowSteps.divider-rtl.png b/resources/jquery/images/jquery.arrowSteps.divider-rtl.png index 529d7b84..7cfbfeba 100644 Binary files a/resources/jquery/images/jquery.arrowSteps.divider-rtl.png and b/resources/jquery/images/jquery.arrowSteps.divider-rtl.png differ diff --git a/resources/jquery/images/jquery.arrowSteps.head-ltr.png b/resources/jquery/images/jquery.arrowSteps.head-ltr.png index 3289617d..eb070280 100644 Binary files a/resources/jquery/images/jquery.arrowSteps.head-ltr.png and b/resources/jquery/images/jquery.arrowSteps.head-ltr.png differ diff --git a/resources/jquery/images/jquery.arrowSteps.head-rtl.png b/resources/jquery/images/jquery.arrowSteps.head-rtl.png index 3d9f70cb..7ea2fdb5 100644 Binary files a/resources/jquery/images/jquery.arrowSteps.head-rtl.png and b/resources/jquery/images/jquery.arrowSteps.head-rtl.png differ diff --git a/resources/jquery/images/jquery.arrowSteps.tail-ltr.png b/resources/jquery/images/jquery.arrowSteps.tail-ltr.png index 92b872b2..3ad990b6 100644 Binary files a/resources/jquery/images/jquery.arrowSteps.tail-ltr.png and b/resources/jquery/images/jquery.arrowSteps.tail-ltr.png differ diff --git a/resources/jquery/images/marker.png b/resources/jquery/images/marker.png index 3929bbb5..19efb6ce 100644 Binary files a/resources/jquery/images/marker.png and b/resources/jquery/images/marker.png differ diff --git a/resources/jquery/images/mask.png b/resources/jquery/images/mask.png index b0a4d406..fe08de0e 100644 Binary files a/resources/jquery/images/mask.png and b/resources/jquery/images/mask.png differ 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 ); @@ -179,45 +205,6 @@ toggleElement( $collapsible, wasCollapsed ? 'expand' : 'collapse', $toggle, options ); } - /** - * 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. * @@ -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 = - $( '' ) - .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 $( '' ) + .text( collapseText ) .wrap( '' ) .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( '
  • ' ).parent() ); + $toggleLink = buildDefaultToggleLink(); + $toggleLink.wrap( '
  • ' ).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 { //
    ,

    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 or a