Index: trunk/phase3/resources/mediawiki.util/mediawiki.util.test.js |
— | — | @@ -326,6 +326,9 @@ |
327 | 327 | mw.test.addTest( 'var a = mw.util.addPortletLink( "p-tb", "http://mediawiki.org/", "MediaWiki.org", "t-mworg", "Go to MediaWiki.org ", "m", "#t-rl" ); $(a).text();', |
328 | 328 | 'MediaWiki.org (string)' ); |
329 | 329 | |
| 330 | + mw.test.addTest( 'typeof mw.util.addPortletLink( "p-tb", "http://www.mediawiki.org/wiki/ResourceLoader/Default_modules", "Default modules", "t-rl", "All default modules present in MediaWiki" )', |
| 331 | + 'object (string)' ); |
| 332 | + |
330 | 333 | mw.test.addTest( 'typeof mw.util.jsMessage', |
331 | 334 | 'function (string)' ); |
332 | 335 | |
Index: trunk/phase3/resources/mediawiki.util/mediawiki.util.js |
— | — | @@ -375,19 +375,23 @@ |
376 | 376 | this.updateTooltipAccessKeys( $link ); |
377 | 377 | } |
378 | 378 | |
379 | | - // Append using DOM-element passing |
380 | | - if ( nextnode && nextnode.parentNode == $ul[0] ) { |
| 379 | + // Where to put our node ? |
| 380 | + // - nextnode is a DOM element (before MW 1.17, in wikibits.js, this was the only option) |
| 381 | + if ( nextnode && nextnode.parentNode == $ul[0] ) { |
381 | 382 | $(nextnode).before( $item ); |
| 383 | + |
| 384 | + // - nextnode is a CSS selector for jQuery |
| 385 | + } else if ( typeof nextnode == 'string' && $ul.find( nextnode ).length !== 0 ) { |
| 386 | + $ul.find( nextnode ).eq( 0 ).before( $item ); |
| 387 | + |
| 388 | + |
| 389 | + // If the jQuery selector isn't found within the <ul>, |
| 390 | + // or if nextnode was invalid or not passed at all, |
| 391 | + // then just append it at the end of the <ul> (this is the default behaviour) |
382 | 392 | } else { |
383 | | - // If the jQuery selector isn't found within the <ul>, just |
384 | | - // append it at the end |
385 | | - if ( $ul.find( nextnode ).length === 0 ) { |
386 | | - $ul.append( $item ); |
387 | | - } else { |
388 | | - // Append using jQuery CSS selector |
389 | | - $ul.find( nextnode ).eq( 0 ).before( $item ); |
390 | | - } |
| 393 | + $ul.append( $item ); |
391 | 394 | } |
| 395 | + |
392 | 396 | |
393 | 397 | return $item[0]; |
394 | 398 | } |