mediawiki.util: Fix addPortletLink to allow jQuery objects
The docs already say jQuery is a supported type for nextnode, it just wasn't yet checking for it in the function. Change-Id: I0bdc7dacd24aac720b70c6fc0ca3154ceccd0ebb
This commit is contained in:
parent
c7f174bf68
commit
8d62955152
3 changed files with 16 additions and 6 deletions
|
|
@ -172,6 +172,7 @@ production.
|
|||
too. Can be used whenever several multicast group could be interested by a
|
||||
specific purge.
|
||||
* (bug 25931) Add Special:RandomInCategory.
|
||||
* mediawiki.util: addPortletLink now supports passing a jQuery object as nextnode.
|
||||
|
||||
=== Bug fixes in 1.22 ===
|
||||
* Disable Special:PasswordReset when $wgEnableEmail is false. Previously one
|
||||
|
|
|
|||
|
|
@ -432,10 +432,16 @@
|
|||
$link.attr( 'accesskey', accesskey );
|
||||
}
|
||||
|
||||
// nextnode is a DOM element (was the only option before MW 1.17, in wikibits.js)
|
||||
// so we make it a jQuery object!
|
||||
if ( nextnode && nextnode.nodeType ) {
|
||||
nextnode = $( nextnode );
|
||||
}
|
||||
|
||||
// Where to put our node ?
|
||||
// - nextnode is a DOM element (was the only option before MW 1.17, in wikibits.js)
|
||||
if ( nextnode && nextnode.parentNode === $ul[0] ) {
|
||||
$( nextnode ).before( $item );
|
||||
// - nextnode is a jQuery object that represents exactly one element
|
||||
if ( nextnode && nextnode.jquery && nextnode.length === 1 && nextnode[0].parentNode === $ul[0] ) {
|
||||
nextnode.before( $item );
|
||||
|
||||
// - nextnode is a CSS selector for jQuery
|
||||
} else if ( typeof nextnode === 'string' && $ul.find( nextnode ).length !== 0 ) {
|
||||
|
|
|
|||
|
|
@ -137,8 +137,8 @@
|
|||
* Previously, test elements where invisible to the selector since only
|
||||
* one element can have a given id.
|
||||
*/
|
||||
QUnit.test( 'addPortletLink', 10, function ( assert ) {
|
||||
var pTestTb, pCustom, vectorTabs, tbRL, cuQuux, $cuQuux, tbMW, $tbMW, tbRLDM, caFoo;
|
||||
QUnit.test( 'addPortletLink', 11, function ( assert ) {
|
||||
var pTestTb, pCustom, vectorTabs, tbRL, cuQuux, $cuQuux, tbMW, $tbMW, tbRLDM, caFoo, addedAfter;
|
||||
|
||||
pTestTb = '\
|
||||
<div class="portlet" id="p-test-tb">\
|
||||
|
|
@ -194,7 +194,7 @@
|
|||
);
|
||||
|
||||
assert.equal( $tbMW.closest( '.portlet' ).attr( 'id' ), 'p-test-tb', 'Link was inserted within correct portlet' );
|
||||
assert.equal( $tbMW.next().attr( 'id' ), 't-rl', 'Link is in the correct position (by passing nextnode)' );
|
||||
assert.strictEqual( $tbMW.next()[0], tbRL, 'Link is in the correct position (by passing nextnode)' );
|
||||
|
||||
cuQuux = mw.util.addPortletLink( 'p-test-custom', '#', 'Quux', null, 'Example [shift-x]', 'q' );
|
||||
$cuQuux = $( cuQuux );
|
||||
|
|
@ -216,6 +216,9 @@
|
|||
|
||||
assert.strictEqual( $tbMW.find( 'span' ).length, 0, 'No <span> element should be added for porlets without vectorTabs class.' );
|
||||
assert.strictEqual( $( caFoo ).find( 'span' ).length, 1, 'A <span> element should be added for porlets with vectorTabs class.' );
|
||||
|
||||
addedAfter = mw.util.addPortletLink( 'p-test-tb', '#', 'After foo', 'post-foo', 'After foo', null, $( tbRL ) );
|
||||
assert.strictEqual( $( addedAfter ).next()[0], tbRL, 'Link is in the correct position (by passing a jQuery object as nextnode)' );
|
||||
} );
|
||||
|
||||
QUnit.test( 'jsMessage', 1, function ( assert ) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue