jenkins-bot has submitted this change and it was merged.

Change subject: Re-use result instead of querying the DOM for selector multiple 
times
......................................................................


Re-use result instead of querying the DOM for selector multiple times

It's a complicated query, we should not repeat it when not necessary.

Change-Id: I71d47de088afa7dab0a6eaed214c61db699fcd0c
---
M resources/ext.popups.core.js
1 file changed, 19 insertions(+), 9 deletions(-)

Approvals:
  Prtksxna: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/resources/ext.popups.core.js b/resources/ext.popups.core.js
index a209cc2..9db8c8c 100644
--- a/resources/ext.popups.core.js
+++ b/resources/ext.popups.core.js
@@ -89,9 +89,8 @@
         *
         * @method removeTooltips
         */
-       mw.popups.removeTooltips = function () {
-               var notSelector = ':not(' + mw.popups.IGNORE_CLASSES.join(', ') 
+ ')';
-               mw.popups.$content.find( 'a' + notSelector + ':not([title=""])' 
)
+       mw.popups.removeTooltips = function ( $elements ) {
+               $elements
                        .on( 'mouseenter focus', function () {
                                $( this )
                                        .data( 'title', $( this ).attr( 'title' 
) )
@@ -123,10 +122,8 @@
         *
         * @method setupTriggers
         */
-       mw.popups.setupTriggers = function () {
-               var notSelector = ':not(' + mw.popups.IGNORE_CLASSES.join(', ') 
+ ')';
-
-               mw.popups.$content.find( 'a' + notSelector + ':not([title=""])' 
).on( 'mouseenter focus', function ( event ) {
+       mw.popups.setupTriggers = function ( $elements ) {
+               $elements.on( 'mouseenter focus', function ( event ) {
                        var
                                $this = $( this ),
                                href = $this.attr( 'href' );
@@ -143,10 +140,23 @@
                } );
        };
 
+       /**
+        * Returns links that can have Popups
+        *
+        * @method selectPopupElements
+        */
+       mw.popups.selectPopupElements = function () {
+               var notSelector = ':not(' + mw.popups.IGNORE_CLASSES.join(', ') 
+ ')';
+
+               return mw.popups.$content.find( 'a' + notSelector + 
':not([title=""])' );
+       };
+
        mw.hook( 'wikipage.content').add( function ( $content ) {
                mw.popups.$content = $content;
-               mw.popups.removeTooltips();
-               mw.popups.setupTriggers();
+
+               var $elements = mw.popups.selectPopupElements();
+               mw.popups.removeTooltips( $elements );
+               mw.popups.setupTriggers( $elements );
        } );
 
        $( function () {

-- 
To view, visit https://gerrit.wikimedia.org/r/134266
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I71d47de088afa7dab0a6eaed214c61db699fcd0c
Gerrit-PatchSet: 9
Gerrit-Project: mediawiki/extensions/Popups
Gerrit-Branch: master
Gerrit-Owner: TheDJ <hartman.w...@gmail.com>
Gerrit-Reviewer: Krinkle <krinklem...@gmail.com>
Gerrit-Reviewer: Prtksxna <psax...@wikimedia.org>
Gerrit-Reviewer: Spage <sp...@wikimedia.org>
Gerrit-Reviewer: TheDJ <hartman.w...@gmail.com>
Gerrit-Reviewer: Yuvipanda <yuvipa...@gmail.com>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to