Index: branches/liangent/makeCollapsible_custom/phase3/resources/jquery/jquery.makeCollapsible.js |
— | — | @@ -201,16 +201,30 @@ |
202 | 202 | }, |
203 | 203 | // Toggles customcollapsible |
204 | 204 | toggleLinkCustom = function( $that, e, $collapsible ) { |
| 205 | + var instantHide = true; |
205 | 206 | // For the initial state call of customtogglers there is no event passed |
206 | 207 | if (e) { |
207 | 208 | e.preventDefault(); |
208 | | - e.stopPropagation(); |
| 209 | + e.stopPropagation(); |
| 210 | + $collapsible.toggleClass( 'mw-collapsed' ); |
| 211 | + instantHide = false; |
209 | 212 | } |
210 | | - // Get current state and toggle to the opposite |
211 | | - var action = $collapsible.hasClass( 'mw-collapsed' ) ? 'expand' : 'collapse'; |
212 | | - $collapsible.toggleClass( 'mw-collapsed' ); |
213 | | - toggleElement( $collapsible, action, $that ); |
214 | 213 | |
| 214 | + // It's expanded right now |
| 215 | + if ( $collapsible.hasClass( 'mw-collapsed' ) ) { |
| 216 | + // Change text to "Show" |
| 217 | + $( '.mw-customtoggletext', $that ).text( expandtext ); |
| 218 | + // Collapse element |
| 219 | + toggleElement( $collapsible, 'collapse', $that, instantHide ); |
| 220 | + |
| 221 | + // It's collapsed right now |
| 222 | + } else { |
| 223 | + // Change text to "Hide" |
| 224 | + $( '.mw-customtoggletext', $that ).text( collapsetext ); |
| 225 | + // Expand element |
| 226 | + toggleElement( $collapsible, 'expand', $that, instantHide ); |
| 227 | + } |
| 228 | + return; |
215 | 229 | }; |
216 | 230 | |
217 | 231 | // Use custom text or default ? |
— | — | @@ -260,8 +274,9 @@ |
261 | 275 | |
262 | 276 | // Initial state |
263 | 277 | if ( $that.hasClass( 'mw-collapsed' ) ) { |
264 | | - $that.removeClass( 'mw-collapsed' ); |
265 | 278 | toggleLinkCustom( $customTogglers, null, $that ); |
| 279 | + } else { |
| 280 | + $( '.mw-customtoggletext', $customTogglers ).text( collapsetext ); |
266 | 281 | } |
267 | 282 | |
268 | 283 | // Custom toggle link specified by children with a certain class |
— | — | @@ -275,13 +290,14 @@ |
276 | 291 | toggleLinkCustom( $(this), e, $that ); |
277 | 292 | } ); |
278 | 293 | } else { |
279 | | - mw.log( _fn + '<children> .mw-customtoggle: Missing toggler!' ); |
| 294 | + mw.log( _fn + '.mw-customcollapsiblechildren: Missing toggler!' ); |
280 | 295 | } |
281 | 296 | |
282 | 297 | // Initial state |
283 | 298 | if ( $that.hasClass( 'mw-collapsed' ) ) { |
284 | | - $that.removeClass( 'mw-collapsed' ); |
285 | 299 | toggleLinkCustom( $customTogglers, null, $that ); |
| 300 | + } else { |
| 301 | + $( '.mw-customtoggletext', $customTogglers ).text( collapsetext ); |
286 | 302 | } |
287 | 303 | |
288 | 304 | // If this is not a custom case, do the default: |
— | — | @@ -346,7 +362,8 @@ |
347 | 363 | } |
348 | 364 | |
349 | 365 | // Initial state (only for those that are not custom) |
350 | | - if ( $that.hasClass( 'mw-collapsed' ) && ( $that.attr( 'id' ) || '').indexOf( 'mw-customcollapsible-' ) !== 0 ) { |
| 366 | + if ( $that.hasClass( 'mw-collapsed' ) && !$that.hasClass( 'mw-customcollapsiblechildren' ) |
| 367 | + && ( $that.attr( 'id' ) || '').indexOf( 'mw-customcollapsible-' ) !== 0 ) { |
351 | 368 | $that.removeClass( 'mw-collapsed' ); |
352 | 369 | // The collapsible element could have multiple togglers |
353 | 370 | // To toggle the initial state only click one of them (ie. the first one, eq(0) ) |