From 0f8d4d4481f789bfb2c3e4eb73b5a071882ed200 Mon Sep 17 00:00:00 2001 From: Krinkle Date: Mon, 27 Dec 2010 17:37:19 +0000 Subject: [PATCH] Treat premade toggle links as a custom instead of default case (ie. dont change the text) (Follow-up r78989 CR) --- resources/jquery/jquery.makeCollapsible.js | 34 ++++++++++++++++++---- 1 file changed, 29 insertions(+), 5 deletions(-) diff --git a/resources/jquery/jquery.makeCollapsible.js b/resources/jquery/jquery.makeCollapsible.js index e662dae0c6..887e468d46 100644 --- a/resources/jquery/jquery.makeCollapsible.js +++ b/resources/jquery/jquery.makeCollapsible.js @@ -90,13 +90,14 @@ $.fn.makeCollapsible = function() { } } }, + // Toggles collapsible and togglelink class and updates text label toggleLinkDefault = function( that, e ) { var $that = $(that), $collapsible = $that.closest( '.mw-collapsible.mw-made-collapsible' ).toggleClass( 'mw-collapsed' ); e.preventDefault(); // It's expanded right now - if ( $that.hasClass( 'mw-collapsible-toggle-expanded' ) ) { + if ( !$that.hasClass( 'mw-collapsible-toggle-collapsed' ) ) { // Change link to "Show" $that.removeClass( 'mw-collapsible-toggle-expanded' ).addClass( 'mw-collapsible-toggle-collapsed' ); if ( $that.find( '> a' ).size() ) { @@ -121,6 +122,29 @@ $.fn.makeCollapsible = function() { } return; }, + // Toggles collapsible and togglelink class + toggleLinkPremade = function( that, e ) { + var $that = $(that), + $collapsible = $that.closest( '.mw-collapsible.mw-made-collapsible' ).toggleClass( 'mw-collapsed' ); + e.preventDefault(); + + // It's expanded right now + if ( !$that.hasClass( 'mw-collapsible-toggle-collapsed' ) ) { + // Change toggle to collapsed + $that.removeClass( 'mw-collapsible-toggle-expanded' ).addClass( 'mw-collapsible-toggle-collapsed' ); + // Collapse element + toggleElement( $collapsible, 'collapse', $that ); + + // It's collapsed right now + } else { + // Change toggle to expanded + $that.removeClass( 'mw-collapsible-toggle-collapsed' ).addClass( 'mw-collapsible-toggle-expanded' ); + // Expand element + toggleElement( $collapsible, 'expand', $that ); + } + return; + }, + // Toggles customcollapsible toggleLinkCustom = function( that, e ) { var $that = $(that), classes = that.className.split(' '); @@ -147,7 +171,7 @@ $.fn.makeCollapsible = function() { } // Create toggle link with a space around the brackets ( [text] ) - var $toggleLink = $( '' ).text( collapsetext ).wrap( '' ).parent().prepend( ' [' ).append( '] ' ).bind( 'click.mw-collapse', function(e){ + var $toggleLink = $( '' ).text( collapsetext ).wrap( '' ).parent().prepend( ' [' ).append( '] ' ).bind( 'click.mw-collapse', function(e){ toggleLinkDefault( this, e ); } ); @@ -195,7 +219,7 @@ $.fn.makeCollapsible = function() { $firstRowCells.eq(-1).prepend( $toggleLink ); } else { $toggleLink = $toggle.unbind( 'click.mw-collapse' ).bind( 'click.mw-collapse', function( e ){ - toggleLinkDefault( this, e ); + toggleLinkPremade( this, e ); } ); } @@ -214,7 +238,7 @@ $.fn.makeCollapsible = function() { $that.prepend( $toggleLink.wrap( '
  • ' ).parent() ); } else { $toggleLink = $toggle.unbind( 'click.mw-collapse' ).bind( 'click.mw-collapse', function( e ){ - toggleLinkDefault( this, e ); + toggleLinkPremade( this, e ); } ); } @@ -232,7 +256,7 @@ $.fn.makeCollapsible = function() { $that.prepend( $toggleLink ); } else { $toggleLink = $toggle.unbind( 'click.mw-collapse' ).bind( 'click.mw-collapse', function( e ){ - toggleLinkDefault( this, e ); + toggleLinkPremade( this, e ); } ); } } -- 2.20.1