Index: trunk/phase3/resources/jquery/jquery.makeCollapsible.js |
— | — | @@ -90,13 +90,14 @@ |
91 | 91 | } |
92 | 92 | } |
93 | 93 | }, |
| 94 | + // Toggles collapsible and togglelink class and updates text label |
94 | 95 | toggleLinkDefault = function( that, e ) { |
95 | 96 | var $that = $(that), |
96 | 97 | $collapsible = $that.closest( '.mw-collapsible.mw-made-collapsible' ).toggleClass( 'mw-collapsed' ); |
97 | 98 | e.preventDefault(); |
98 | 99 | |
99 | 100 | // It's expanded right now |
100 | | - if ( $that.hasClass( 'mw-collapsible-toggle-expanded' ) ) { |
| 101 | + if ( !$that.hasClass( 'mw-collapsible-toggle-collapsed' ) ) { |
101 | 102 | // Change link to "Show" |
102 | 103 | $that.removeClass( 'mw-collapsible-toggle-expanded' ).addClass( 'mw-collapsible-toggle-collapsed' ); |
103 | 104 | if ( $that.find( '> a' ).size() ) { |
— | — | @@ -121,6 +122,29 @@ |
122 | 123 | } |
123 | 124 | return; |
124 | 125 | }, |
| 126 | + // Toggles collapsible and togglelink class |
| 127 | + toggleLinkPremade = function( that, e ) { |
| 128 | + var $that = $(that), |
| 129 | + $collapsible = $that.closest( '.mw-collapsible.mw-made-collapsible' ).toggleClass( 'mw-collapsed' ); |
| 130 | + e.preventDefault(); |
| 131 | + |
| 132 | + // It's expanded right now |
| 133 | + if ( !$that.hasClass( 'mw-collapsible-toggle-collapsed' ) ) { |
| 134 | + // Change toggle to collapsed |
| 135 | + $that.removeClass( 'mw-collapsible-toggle-expanded' ).addClass( 'mw-collapsible-toggle-collapsed' ); |
| 136 | + // Collapse element |
| 137 | + toggleElement( $collapsible, 'collapse', $that ); |
| 138 | + |
| 139 | + // It's collapsed right now |
| 140 | + } else { |
| 141 | + // Change toggle to expanded |
| 142 | + $that.removeClass( 'mw-collapsible-toggle-collapsed' ).addClass( 'mw-collapsible-toggle-expanded' ); |
| 143 | + // Expand element |
| 144 | + toggleElement( $collapsible, 'expand', $that ); |
| 145 | + } |
| 146 | + return; |
| 147 | + }, |
| 148 | + // Toggles customcollapsible |
125 | 149 | toggleLinkCustom = function( that, e ) { |
126 | 150 | var $that = $(that), |
127 | 151 | classes = that.className.split(' '); |
— | — | @@ -147,7 +171,7 @@ |
148 | 172 | } |
149 | 173 | |
150 | 174 | // Create toggle link with a space around the brackets ( [text] ) |
151 | | - var $toggleLink = $( '<a href="#">' ).text( collapsetext ).wrap( '<span class="mw-collapsible-toggle mw-collapsible-toggle-expanded">' ).parent().prepend( ' [' ).append( '] ' ).bind( 'click.mw-collapse', function(e){ |
| 175 | + var $toggleLink = $( '<a href="#">' ).text( collapsetext ).wrap( '<span class="mw-collapsible-toggle">' ).parent().prepend( ' [' ).append( '] ' ).bind( 'click.mw-collapse', function(e){ |
152 | 176 | toggleLinkDefault( this, e ); |
153 | 177 | } ); |
154 | 178 | |
— | — | @@ -195,7 +219,7 @@ |
196 | 220 | $firstRowCells.eq(-1).prepend( $toggleLink ); |
197 | 221 | } else { |
198 | 222 | $toggleLink = $toggle.unbind( 'click.mw-collapse' ).bind( 'click.mw-collapse', function( e ){ |
199 | | - toggleLinkDefault( this, e ); |
| 223 | + toggleLinkPremade( this, e ); |
200 | 224 | } ); |
201 | 225 | } |
202 | 226 | |
— | — | @@ -214,7 +238,7 @@ |
215 | 239 | $that.prepend( $toggleLink.wrap( '<li class="mw-collapsible-toggle-li">' ).parent() ); |
216 | 240 | } else { |
217 | 241 | $toggleLink = $toggle.unbind( 'click.mw-collapse' ).bind( 'click.mw-collapse', function( e ){ |
218 | | - toggleLinkDefault( this, e ); |
| 242 | + toggleLinkPremade( this, e ); |
219 | 243 | } ); |
220 | 244 | } |
221 | 245 | |
— | — | @@ -232,7 +256,7 @@ |
233 | 257 | $that.prepend( $toggleLink ); |
234 | 258 | } else { |
235 | 259 | $toggleLink = $toggle.unbind( 'click.mw-collapse' ).bind( 'click.mw-collapse', function( e ){ |
236 | | - toggleLinkDefault( this, e ); |
| 260 | + toggleLinkPremade( this, e ); |
237 | 261 | } ); |
238 | 262 | } |
239 | 263 | } |