Index: trunk/phase3/resources/jquery/jquery.makeCollapsible.js |
— | — | @@ -26,7 +26,7 @@ |
27 | 27 | that = this, |
28 | 28 | collapsetext = $(this).attr( 'data-collapsetext' ), |
29 | 29 | expandtext = $(this).attr( 'data-expandtext' ), |
30 | | - toggleElement = function( $collapsible, action, $defaultToggle ) { |
| 30 | + toggleElement = function( $collapsible, action, $defaultToggle, instantHide ) { |
31 | 31 | // Validate parameters |
32 | 32 | if ( !$collapsible.jquery ) { // $collapsible must be an instance of jQuery |
33 | 33 | return; |
— | — | @@ -35,10 +35,11 @@ |
36 | 36 | // action must be string with 'expand' or 'collapse' |
37 | 37 | return; |
38 | 38 | } |
39 | | - if ( typeof $defaultToggle !== 'undefined' && !$defaultToggle.jquery ) { |
| 39 | + if ( $defaultToggle && !$defaultToggle.jquery ) { |
40 | 40 | // is optional, but if passed must be an instance of jQuery |
41 | 41 | return; |
42 | 42 | } |
| 43 | + var $containers = null; |
43 | 44 | |
44 | 45 | if ( action == 'collapse' ) { |
45 | 46 | |
— | — | @@ -47,20 +48,29 @@ |
48 | 49 | // Hide all table rows of this table |
49 | 50 | // Slide doens't work with tables, but fade does as of jQuery 1.1.3 |
50 | 51 | // http://stackoverflow.com/questions/467336#920480 |
51 | | - |
52 | | - if ( $defaultToggle.jquery ) { |
| 52 | + $containers = $collapsible.find( '>tbody>tr' ); |
| 53 | + if ( $defaultToggle && $defaultToggle.jquery ) { |
53 | 54 | // Exclude tablerow containing togglelink |
54 | | - $collapsible.find( '>tbody>tr' ).not( $defaultToggle.parent().parent() ).stop(true, true).fadeOut(); |
| 55 | + $containers.not( $defaultToggle.parent().parent() ).stop(true, true).fadeOut(); |
55 | 56 | } else { |
56 | | - $collapsible.find( '>tbody>tr' ).stop( true, true ).fadeOut(); |
| 57 | + if ( instantHide ) { |
| 58 | + $containers.hide(); |
| 59 | + } else { |
| 60 | + $containers.stop( true, true ).fadeOut(); |
| 61 | + } |
57 | 62 | } |
58 | 63 | |
59 | 64 | } else if ( $collapsible.is( 'ul' ) || $collapsible.is( 'ol' ) ) { |
60 | | - if ( $defaultToggle.jquery ) { |
| 65 | + $containers = $collapsible.find( '> li' ); |
| 66 | + if ( $defaultToggle && $defaultToggle.jquery ) { |
61 | 67 | // Exclude list-item containing togglelink |
62 | | - $collapsible.find( '> li' ).not( $defaultToggle.parent() ).stop( true, true ).slideUp(); |
| 68 | + $containers.not( $defaultToggle.parent() ).stop( true, true ).slideUp(); |
63 | 69 | } else { |
64 | | - $collapsible.find( '> li' ).stop( true, true ).slideUp(); |
| 70 | + if ( instantHide ) { |
| 71 | + $containers.hide(); |
| 72 | + } else { |
| 73 | + $containers.stop( true, true ).slideUp(); |
| 74 | + } |
65 | 75 | } |
66 | 76 | |
67 | 77 | } else { // <div>, <p> etc. |
— | — | @@ -68,7 +78,11 @@ |
69 | 79 | |
70 | 80 | // If a collapsible-content is defined, collapse it |
71 | 81 | if ( $collapsibleContent.size() ) { |
72 | | - $collapsibleContent.slideUp(); |
| 82 | + if ( instantHide ) { |
| 83 | + $collapsibleContent.hide(); |
| 84 | + } else { |
| 85 | + $collapsibleContent.slideUp(); |
| 86 | + } |
73 | 87 | |
74 | 88 | // Otherwise assume this is a customcollapse with a remote toggle |
75 | 89 | // .. and there is no collapsible-content because the entire element should be toggled |
— | — | @@ -85,19 +99,21 @@ |
86 | 100 | |
87 | 101 | // Expand the element |
88 | 102 | if ( $collapsible.is( 'table' ) ) { |
89 | | - if ( $defaultToggle.jquery ) { |
| 103 | + $containers = $collapsible.find( '>tbody>tr' ); |
| 104 | + if ( $defaultToggle && $defaultToggle.jquery ) { |
90 | 105 | // Exclude tablerow containing togglelink |
91 | | - $collapsible.find( '>tbody>tr' ).not( $defaultToggle.parent().parent() ).stop(true, true).fadeIn(); |
| 106 | + $containers.not( $defaultToggle.parent().parent() ).stop(true, true).fadeIn(); |
92 | 107 | } else { |
93 | | - $collapsible.find( '>tbody>tr' ).stop(true, true).fadeIn(); |
| 108 | + $containers.stop(true, true).fadeIn(); |
94 | 109 | } |
95 | 110 | |
96 | 111 | } else if ( $collapsible.is( 'ul' ) || $collapsible.is( 'ol' ) ) { |
97 | | - if ( $defaultToggle.jquery ) { |
| 112 | + $containers = $collapsible.find( '> li' ); |
| 113 | + if ( $defaultToggle && $defaultToggle.jquery ) { |
98 | 114 | // Exclude list-item containing togglelink |
99 | | - $collapsible.find( '> li' ).not( $defaultToggle.parent() ).stop( true, true ).slideDown(); |
| 115 | + $containers.not( $defaultToggle.parent() ).stop( true, true ).slideDown(); |
100 | 116 | } else { |
101 | | - $collapsible.find( '> li' ).stop( true, true ).slideDown(); |
| 117 | + $containers.stop( true, true ).slideDown(); |
102 | 118 | } |
103 | 119 | |
104 | 120 | } else { // <div>, <p> etc. |
— | — | @@ -293,6 +309,7 @@ |
294 | 310 | // The collapsible element could have multiple togglers |
295 | 311 | // To toggle the initial state only click one of them (ie. the first one, eq(0) ) |
296 | 312 | // Else it would go like: hide,show,hide,show for each toggle link. |
| 313 | + toggleElement( $that, 'collapse', null, /* instantHide = */ true ); |
297 | 314 | $toggleLink.eq(0).click(); |
298 | 315 | } |
299 | 316 | } ); |
Index: trunk/phase3/resources/mediawiki.util/mediawiki.util.js |
— | — | @@ -77,8 +77,8 @@ |
78 | 78 | |
79 | 79 | } else { |
80 | 80 | // #content is present on almost all if not all skins. Most skins (the above cases) |
81 | | - // have #content too, but as a outer wrapper instead of the article text container. |
82 | | - // The skins that don't have an outer wrapper have #content for everything |
| 81 | + // have #content too, but as an outer wrapper instead of the article text container. |
| 82 | + // The skins that don't have an outer wrapper do have #content for everything |
83 | 83 | // so it's a good fallback |
84 | 84 | mw.util.$content = $( '#content' ); |
85 | 85 | } |
— | — | @@ -323,17 +323,16 @@ |
324 | 324 | * |
325 | 325 | * @param portlet ID of the target portlet ( 'p-cactions' or 'p-personal' etc.) |
326 | 326 | * @param href Link URL |
327 | | - * @param text Link text (will be automatically converted to lower |
328 | | - * case by CSS for p-cactions in Monobook) |
| 327 | + * @param text Link text |
329 | 328 | * @param id ID of the new item, should be unique and preferably have |
330 | 329 | * the appropriate prefix ( 'ca-', 'pt-', 'n-' or 't-' ) |
331 | 330 | * @param tooltip Text to show when hovering over the link, without accesskey suffix |
332 | 331 | * @param accesskey Access key to activate this link (one character, try |
333 | | - * to avoid conflicts. Use $( '[accesskey=x' ).get() in the console to |
| 332 | + * to avoid conflicts. Use $( '[accesskey=x]' ).get() in the console to |
334 | 333 | * see if 'x' is already used. |
335 | | - * @param nextnode DOM node or jQuery-selector of the item that the new |
| 334 | + * @param nextnode DOM node or jQuery-selector string of the item that the new |
336 | 335 | * item should be added before, should be another item in the same |
337 | | - * list will be ignored if not the so |
| 336 | + * list, it will be ignored otherwise |
338 | 337 | * |
339 | 338 | * @return The DOM node of the new item (a LI element, or A element for |
340 | 339 | * older skins) or null. |
— | — | @@ -352,28 +351,28 @@ |
353 | 352 | |
354 | 353 | // Some skins don't have any portlets |
355 | 354 | // just add it to the bottom of their 'sidebar' element as a fallback |
356 | | - switch ( skin ) { |
| 355 | + switch ( mw.config.get( 'skin' ) ) { |
357 | 356 | case 'standard' : |
358 | 357 | case 'cologneblue' : |
359 | | - $("#quickbar").append($link.after( '<br />' )); |
360 | | - return $link.get(0); |
| 358 | + $( '#quickbar' ).append( $link.after( '<br />' ) ); |
| 359 | + return $link[0]; |
361 | 360 | case 'nostalgia' : |
362 | | - $("#searchform").before($link).before( ' | ' ); |
363 | | - return $link.get(0); |
| 361 | + $( '#searchform' ).before( $link).before( ' | ' ); |
| 362 | + return $link[0]; |
364 | 363 | default : // Skins like chick, modern, monobook, myskin, simple, vector... |
365 | 364 | |
366 | 365 | // Select the specified portlet |
367 | | - var $portlet = $( '#' + portlet); |
| 366 | + var $portlet = $( '#' + portlet ); |
368 | 367 | if ( $portlet.length === 0 ) { |
369 | 368 | return null; |
370 | 369 | } |
371 | 370 | // Select the first (most likely only) unordered list inside the portlet |
372 | | - var $ul = $portlet.find( 'ul' ).eq( 0 ); |
| 371 | + var $ul = $portlet.find( 'ul' ); |
373 | 372 | |
374 | 373 | // If it didn't have an unordered list yet, create it |
375 | | - if ($ul.length === 0) { |
| 374 | + if ( $ul.length === 0 ) { |
376 | 375 | // If there's no <div> inside, append it to the portlet directly |
377 | | - if ($portlet.find( 'div' ).length === 0) { |
| 376 | + if ( $portlet.find( 'div:first' ).length === 0 ) { |
378 | 377 | $portlet.append( '<ul/>' ); |
379 | 378 | } else { |
380 | 379 | // otherwise if there's a div (such as div.body or div.pBody) |
— | — | @@ -409,7 +408,7 @@ |
410 | 409 | } |
411 | 410 | |
412 | 411 | // Append using DOM-element passing |
413 | | - if ( nextnode && nextnode.parentNode == $ul.get( 0 ) ) { |
| 412 | + if ( nextnode && nextnode.parentNode == $ul[0] ) { |
414 | 413 | $(nextnode).before( $item ); |
415 | 414 | } else { |
416 | 415 | // If the jQuery selector isn't found within the <ul>, just |
— | — | @@ -422,7 +421,7 @@ |
423 | 422 | } |
424 | 423 | } |
425 | 424 | |
426 | | - return $item.get( 0 ); |
| 425 | + return $item[0]; |
427 | 426 | } |
428 | 427 | }, |
429 | 428 | |