From: Timo Tijhof Date: Thu, 1 Aug 2013 23:38:16 +0000 (+0200) Subject: mediawiki.util: Optimise logic in addPortletLink X-Git-Tag: 1.31.0-rc.0~19058^2 X-Git-Url: http://git.cyclocoop.org/%22%20.%20generer_url_ecrire%28%22calendrier%22%2C%22type=semaine%22%29%20.%20%22?a=commitdiff_plain;h=5f3b75dd360c5b5e260b47eadce45a613b6de390;p=lhc%2Fweb%2Fwiklou.git mediawiki.util: Optimise logic in addPortletLink Optimised to no longer: * boolean cast "nextnode" twice. * assert nextnode.jquery when we know it is a jQuery object. > !!$( Node ).jquery * assert nextnode.length when we know it has only 1 element. > $( Node ).length === 1 * execute $ul.find( selector ) twice for the CSS selector case. * check for .length in some places and do an ignorant eq(0) in other cases (thus ignoring the case if there are multiple elements). Tests still pass :-) Change-Id: Ibc86c2dc33a8a3ba378138525c2523ba69bca8f1 --- diff --git a/resources/mediawiki/mediawiki.util.js b/resources/mediawiki/mediawiki.util.js index 6f768392c7..071a52be71 100644 --- a/resources/mediawiki/mediawiki.util.js +++ b/resources/mediawiki/mediawiki.util.js @@ -432,29 +432,27 @@ $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 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 ) { - $ul.find( nextnode ).eq( 0 ).before( $item ); - - // If the jQuery selector isn't found within the