Index: trunk/phase3/resources/jquery/jquery.makeCollapsible.js |
— | — | @@ -211,17 +211,24 @@ |
212 | 212 | }; |
213 | 213 | |
214 | 214 | // Use custom text or default ? |
215 | | - if( !collapsetext || collapsetext === '' ){ |
| 215 | + if( !collapsetext ) { |
216 | 216 | collapsetext = mw.msg( 'collapsible-collapse' ); |
217 | 217 | } |
218 | | - if ( !expandtext || expandtext === '' ){ |
| 218 | + if ( !expandtext ) { |
219 | 219 | expandtext = mw.msg( 'collapsible-expand' ); |
220 | 220 | } |
221 | 221 | |
222 | 222 | // Create toggle link with a space around the brackets ( [text] ) |
223 | | - var $toggleLink = $( '<a href="#"></a>' ).text( collapsetext ).wrap( '<span class="mw-collapsible-toggle"></span>' ).parent().prepend( ' [' ).append( '] ' ).bind( 'click.mw-collapse', function(e){ |
224 | | - toggleLinkDefault( this, e ); |
225 | | - } ); |
| 223 | + var $toggleLink = |
| 224 | + $( '<a href="#"></a>' ) |
| 225 | + .text( collapsetext ) |
| 226 | + .wrap( '<span class="mw-collapsible-toggle"></span>' ) |
| 227 | + .parent() |
| 228 | + .prepend( ' [' ) |
| 229 | + .append( '] ' ) |
| 230 | + .bind( 'click.mw-collapse', function(e) { |
| 231 | + toggleLinkDefault( this, e ); |
| 232 | + } ); |
226 | 233 | |
227 | 234 | // Return if it has been enabled already. |
228 | 235 | if ( $that.hasClass( 'mw-made-collapsible' ) ) { |
— | — | @@ -233,7 +240,7 @@ |
234 | 241 | // Check if this element has a custom position for the toggle link |
235 | 242 | // (ie. outside the container or deeper inside the tree) |
236 | 243 | // Then: Locate the custom toggle link(s) and bind them |
237 | | - if ( $that.attr( 'id' ).indexOf( 'mw-customcollapsible-' ) === 0 ) { |
| 244 | + if ( ( $that.attr( 'id' ) || '' ).indexOf( 'mw-customcollapsible-' ) === 0 ) { |
238 | 245 | |
239 | 246 | var thatId = $that.attr( 'id' ), |
240 | 247 | $customTogglers = $( '.' + thatId.replace( 'mw-customcollapsible', 'mw-customtoggle' ) ); |
— | — | @@ -268,7 +275,7 @@ |
269 | 276 | if ( !$toggle.length ) { |
270 | 277 | $firstRowCells.eq(-1).prepend( $toggleLink ); |
271 | 278 | } else { |
272 | | - $toggleLink = $toggle.unbind( 'click.mw-collapse' ).bind( 'click.mw-collapse', function( e ){ |
| 279 | + $toggleLink = $toggle.unbind( 'click.mw-collapse' ).bind( 'click.mw-collapse', function( e ) { |
273 | 280 | toggleLinkPremade( $toggle, e ); |
274 | 281 | } ); |
275 | 282 | } |
— | — | @@ -280,15 +287,16 @@ |
281 | 288 | |
282 | 289 | // If theres no toggle link, add it |
283 | 290 | if ( !$toggle.length ) { |
284 | | - // Make sure the numeral order doesn't get messed up, reset to 1 unless value-attribute is already used |
285 | | - // WebKit return '' if no value, Mozilla returns '-1' is no value. |
286 | | - // Needs ==, will fail with === |
287 | | - if ( $firstItem.attr( 'value' ) == '' || $firstItem.attr( 'value' ) == '-1' ) { |
| 291 | + // Make sure the numeral order doesn't get messed up, force the first (soon to be second) item |
| 292 | + // to be "1". Except if the value-attribute is already used. |
| 293 | + // If no value was set WebKit returns "", Mozilla returns '-1', others return null or undefined. |
| 294 | + var firstval = $firstItem.attr( 'value' ); |
| 295 | + if ( firstval === undefined || !firstval || firstval == '-1' ) { |
288 | 296 | $firstItem.attr( 'value', '1' ); |
289 | 297 | } |
290 | 298 | $that.prepend( $toggleLink.wrap( '<li class="mw-collapsible-toggle-li"></li>' ).parent() ); |
291 | 299 | } else { |
292 | | - $toggleLink = $toggle.unbind( 'click.mw-collapse' ).bind( 'click.mw-collapse', function( e ){ |
| 300 | + $toggleLink = $toggle.unbind( 'click.mw-collapse' ).bind( 'click.mw-collapse', function( e ) { |
293 | 301 | toggleLinkPremade( $toggle, e ); |
294 | 302 | } ); |
295 | 303 | } |
— | — | @@ -307,7 +315,7 @@ |
308 | 316 | if ( !$toggle.length ) { |
309 | 317 | $that.prepend( $toggleLink ); |
310 | 318 | } else { |
311 | | - $toggleLink = $toggle.unbind( 'click.mw-collapse' ).bind( 'click.mw-collapse', function( e ){ |
| 319 | + $toggleLink = $toggle.unbind( 'click.mw-collapse' ).bind( 'click.mw-collapse', function( e ) { |
312 | 320 | toggleLinkPremade( $toggle, e ); |
313 | 321 | } ); |
314 | 322 | } |
— | — | @@ -315,7 +323,7 @@ |
316 | 324 | } |
317 | 325 | |
318 | 326 | // Initial state (only for those that are not custom) |
319 | | - if ( $that.hasClass( 'mw-collapsed' ) && $that.attr( 'id' ).indexOf( 'mw-customcollapsible-' ) !== 0 ) { |
| 327 | + if ( $that.hasClass( 'mw-collapsed' ) && ( $that.attr( 'id' ) || '').indexOf( 'mw-customcollapsible-' ) !== 0 ) { |
320 | 328 | $that.removeClass( 'mw-collapsed' ); |
321 | 329 | // The collapsible element could have multiple togglers |
322 | 330 | // To toggle the initial state only click one of them (ie. the first one, eq(0) ) |