X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=resources%2Fsrc%2Fjquery%2Fjquery.makeCollapsible.js;h=43b8f0d66708b8da5e62c320e471918b12795b33;hb=216c7d838012c52961c955f40a93af8a4087e68f;hp=eb4231199efa79154391647bcffb044d56adcc27;hpb=369b34f0ae64076b91df63e7432f5bf6f19a76a6;p=lhc%2Fweb%2Fwiklou.git diff --git a/resources/src/jquery/jquery.makeCollapsible.js b/resources/src/jquery/jquery.makeCollapsible.js index eb4231199e..43b8f0d667 100644 --- a/resources/src/jquery/jquery.makeCollapsible.js +++ b/resources/src/jquery/jquery.makeCollapsible.js @@ -10,7 +10,7 @@ * * @class jQuery.plugin.makeCollapsible */ -( function ( $, mw ) { +( function () { /** * Handler for a click on a collapsible toggler. * @@ -184,8 +184,8 @@ options = options || {}; this.each( function () { - var $collapsible, collapseText, expandText, $caption, $toggle, actionHandler, buildDefaultToggleLink, - $toggleLink, $firstItem, collapsibleId, $customTogglers, firstval; + var $collapsible, collapseText, expandText, $caption, $toggle, actionHandler, + buildDefaultToggleLink, $firstItem, collapsibleId, $customTogglers, firstval; // Ensure class "mw-collapsible" is present in case .makeCollapsible() // is called on element(s) that don't have it yet. @@ -225,8 +225,7 @@ .attr( { role: 'button', tabindex: 0 - } ) - .on( 'click.mw-collapsible keypress.mw-collapsible', actionHandler ); + } ); }; // Check if this element has a custom position for the toggle link @@ -249,9 +248,7 @@ togglingHandler( $( this ), $collapsible, e, opts ); }; - $toggleLink = $customTogglers - .on( 'click.mw-collapsible keypress.mw-collapsible', actionHandler ) - .prop( 'tabIndex', 0 ); + $toggle = $customTogglers; } else { // If this is not a custom case, do the default: wrap the @@ -268,10 +265,7 @@ // If there is no toggle link, add it to the end of the caption if ( !$toggle.length ) { - $toggleLink = buildDefaultToggleLink().appendTo( $caption ); - } else { - $toggleLink = $toggle.on( 'click.mw-collapsible keypress.mw-collapsible', actionHandler ) - .prop( 'tabIndex', 0 ); + $toggle = buildDefaultToggleLink().appendTo( $caption ); } } else { // The toggle-link will be in one of the cells (td or th) of the first row @@ -280,10 +274,7 @@ // If theres no toggle link, add it to the last cell if ( !$toggle.length ) { - $toggleLink = buildDefaultToggleLink().prependTo( $firstItem.eq( -1 ) ); - } else { - $toggleLink = $toggle.on( 'click.mw-collapsible keypress.mw-collapsible', actionHandler ) - .prop( 'tabIndex', 0 ); + $toggle = buildDefaultToggleLink().prependTo( $firstItem.eq( -1 ) ); } } @@ -292,8 +283,8 @@ $collapsible.find( '> .mw-collapsible-toggle' ).length === 0 ) { // special case of one collapsible in
  • tag - $toggleLink = buildDefaultToggleLink(); - $collapsible.before( $toggleLink ); + $toggle = buildDefaultToggleLink(); + $collapsible.before( $toggle ); } else if ( $collapsible.is( 'ul' ) || $collapsible.is( 'ol' ) ) { // The toggle-link will be in the first list-item $firstItem = $collapsible.find( 'li:first' ); @@ -308,11 +299,8 @@ if ( firstval === undefined || !firstval || firstval === '-1' || firstval === -1 ) { $firstItem.prop( 'value', '1' ); } - $toggleLink = buildDefaultToggleLink(); - $toggleLink.wrap( '
  • ' ).parent().prependTo( $collapsible ); - } else { - $toggleLink = $toggle.on( 'click.mw-collapsible keypress.mw-collapsible', actionHandler ) - .prop( 'tabIndex', 0 ); + $toggle = buildDefaultToggleLink(); + $toggle.wrap( '
  • ' ).parent().prependTo( $collapsible ); } } else { //
    ,

    etc. @@ -327,23 +315,24 @@ // If theres no toggle link, add it if ( !$toggle.length ) { - $toggleLink = buildDefaultToggleLink().prependTo( $collapsible ); - } else { - $toggleLink = $toggle.on( 'click.mw-collapsible keypress.mw-collapsible', actionHandler ) - .prop( 'tabIndex', 0 ); + $toggle = buildDefaultToggleLink().prependTo( $collapsible ); } } } + // Attach event handlers to togglelink + $toggle.on( 'click.mw-collapsible keypress.mw-collapsible', actionHandler ) + .prop( 'tabIndex', 0 ); + $( this ).data( 'mw-collapsible', { collapse: function () { - actionHandler.call( $toggleLink.get( 0 ), null, { wasCollapsed: false } ); + actionHandler.call( $toggle.get( 0 ), null, { wasCollapsed: false } ); }, expand: function () { - actionHandler.call( $toggleLink.get( 0 ), null, { wasCollapsed: true } ); + actionHandler.call( $toggle.get( 0 ), null, { wasCollapsed: true } ); }, toggle: function () { - actionHandler.call( $toggleLink.get( 0 ), null, null ); + actionHandler.call( $toggle.get( 0 ), null, null ); } } ); @@ -351,7 +340,7 @@ 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, { wasCollapsed: false } ); + actionHandler.call( $toggle.get( 0 ), null, { wasCollapsed: false } ); } } ); @@ -375,4 +364,4 @@ * @mixins jQuery.plugin.makeCollapsible */ -}( jQuery, mediaWiki ) ); +}() );