X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;ds=sidebyside;f=resources%2Fjquery%2Fjquery.makeCollapsible.js;h=60c0afcd7bb91fd7d0890e187ed1972eaa478a83;hb=5df5a5b4a8ce61cda82af3c636a9b1f3016e6464;hp=27c4c6cc4d05146a961e6253d2e35a55c882fbae;hpb=de07d119203225f731fa2d0e5b2e5c16693ced1c;p=lhc%2Fweb%2Fwiklou.git diff --git a/resources/jquery/jquery.makeCollapsible.js b/resources/jquery/jquery.makeCollapsible.js index 27c4c6cc4d..60c0afcd7b 100644 --- a/resources/jquery/jquery.makeCollapsible.js +++ b/resources/jquery/jquery.makeCollapsible.js @@ -15,8 +15,6 @@ * @license GPL2 */ ( function ( $, mw ) { - var lpx = 'jquery.makeCollapsible> '; - /** * Handler for a click on a collapsible toggler. * @@ -61,7 +59,12 @@ if ( !options.plainMode && $collapsible.is( 'table' ) ) { // Tables - $containers = $collapsible.find( '> tbody > tr' ); + // If there is a caption, hide all rows; otherwise, only hide body rows + if ( $collapsible.find( '> caption' ).length ) { + $containers = $collapsible.find( '> * > tr' ); + } else { + $containers = $collapsible.find( '> tbody > tr' ); + } if ( $defaultToggle ) { // Exclude table row containing togglelink $containers = $containers.not( $defaultToggle.closest( 'tr' ) ); @@ -75,10 +78,10 @@ $containers.hide(); hookCallback(); } else { - $.when( $containers.stop( true, true ).fadeOut() ).then( hookCallback ); + $containers.stop( true, true ).fadeOut().promise().done( hookCallback ); } } else { - $.when( $containers.stop( true, true ).fadeIn() ).then( hookCallback ); + $containers.stop( true, true ).fadeIn().promise().done( hookCallback ); } } else if ( !options.plainMode && ( $collapsible.is( 'ul' ) || $collapsible.is( 'ol' ) ) ) { @@ -94,10 +97,10 @@ $containers.hide(); hookCallback(); } else { - $.when( $containers.stop( true, true ).slideUp() ).then( hookCallback ); + $containers.stop( true, true ).slideUp().promise().done( hookCallback ); } } else { - $.when( $containers.stop( true, true ).slideDown() ).then( hookCallback ); + $containers.stop( true, true ).slideDown().promise().done( hookCallback ); } } else { @@ -111,10 +114,10 @@ $collapsibleContent.hide(); hookCallback(); } else { - $.when( $collapsibleContent.slideUp() ).then( hookCallback ); + $collapsibleContent.slideUp().promise().done( hookCallback ); } } else { - $.when( $collapsibleContent.slideDown() ).then( hookCallback ); + $collapsibleContent.slideDown().promise().done( hookCallback ); } // Otherwise assume this is a customcollapse with a remote toggle @@ -126,16 +129,16 @@ hookCallback(); } else { if ( $collapsible.is( 'tr' ) || $collapsible.is( 'td' ) || $collapsible.is( 'th' ) ) { - $.when( $collapsible.fadeOut() ).then( hookCallback ); + $collapsible.fadeOut().promise().done( hookCallback ); } else { - $.when( $collapsible.slideUp() ).then( hookCallback ); + $collapsible.slideUp().promise().done( hookCallback ); } } } else { if ( $collapsible.is( 'tr' ) || $collapsible.is( 'td' ) || $collapsible.is( 'th' ) ) { - $.when( $collapsible.fadeIn() ).then( hookCallback ); + $collapsible.fadeIn().promise().done( hookCallback ); } else { - $.when( $collapsible.slideDown() ).then( hookCallback ); + $collapsible.slideDown().promise().done( hookCallback ); } } } @@ -235,7 +238,7 @@ } return this.each( function () { - var $collapsible, collapseText, expandText, $toggle, actionHandler, buildDefaultToggleLink, + var $collapsible, collapseText, expandText, $caption, $toggle, actionHandler, buildDefaultToggleLink, premadeToggleHandler, $toggleLink, $firstItem, collapsibleId, $customTogglers, firstval; // Ensure class "mw-collapsible" is present in case .makeCollapsible() @@ -287,17 +290,11 @@ } else { collapsibleId = $collapsible.attr( 'id' ) || ''; if ( collapsibleId.indexOf( 'mw-customcollapsible-' ) === 0 ) { - mw.log( lpx + 'Found custom collapsible: #' + collapsibleId ); $customTogglers = $( '.' + collapsibleId.replace( 'mw-customcollapsible', 'mw-customtoggle' ) ); - - // Double check that there is actually a customtoggle link - if ( !$customTogglers.length ) { - mw.log( lpx + '#' + collapsibleId + ': Missing toggler!' ); - } } } - // Bind the togglers + // Add event handlers to custom togglers or create our own ones if ( $customTogglers && $customTogglers.length ) { actionHandler = function ( e, opts ) { var defaultOpts = {}; @@ -313,16 +310,32 @@ // 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' ); - $toggle = $firstItem.find( '> .mw-collapsible-toggle' ); - // If theres no toggle link, add it to the last cell - if ( !$toggle.length ) { - $toggleLink = buildDefaultToggleLink().prependTo( $firstItem.eq( -1 ) ); + // If the table has a caption, collapse to the caption + // as opposed to the first row + $caption = $collapsible.find( '> caption' ); + if ( $caption.length ) { + $toggle = $caption.find( '> .mw-collapsible-toggle' ); + + // If there is no toggle link, add it to the end of the caption + if ( !$toggle.length ) { + $toggleLink = buildDefaultToggleLink().appendTo( $caption ); + } else { + actionHandler = premadeToggleHandler; + $toggleLink = $toggle.on( 'click.mw-collapsible keypress.mw-collapsible', actionHandler ); + } } else { - actionHandler = premadeToggleHandler; - $toggleLink = $toggle.on( 'click.mw-collapsible keypress.mw-collapsible', actionHandler ); + // 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' ); + $toggle = $firstItem.find( '> .mw-collapsible-toggle' ); + + // If theres no toggle link, add it to the last cell + if ( !$toggle.length ) { + $toggleLink = buildDefaultToggleLink().prependTo( $firstItem.eq( -1 ) ); + } else { + actionHandler = premadeToggleHandler; + $toggleLink = $toggle.on( 'click.mw-collapsible keypress.mw-collapsible', actionHandler ); + } } } else if ( $collapsible.is( 'ul' ) || $collapsible.is( 'ol' ) ) {