$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 ) {
* 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">\
);
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 );
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 ) {