[MediaWiki-commits] [Gerrit] mediawiki...Popups[master]: Hygiene: Add set and get methods for active link

2016-09-23 Thread jenkins-bot (Code Review)
jenkins-bot has submitted this change and it was merged.

Change subject: Hygiene: Add set and get methods for active link
..


Hygiene: Add set and get methods for active link

Named functions help explain to a reader and reviewer what the code
is actually doing.

Change-Id: I1d059c9270fd2298285fa5e4e52e403a06f35503
---
M resources/ext.popups.renderer/desktopRenderer.js
1 file changed, 38 insertions(+), 18 deletions(-)

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



diff --git a/resources/ext.popups.renderer/desktopRenderer.js 
b/resources/ext.popups.renderer/desktopRenderer.js
index 45ab725..0633122 100644
--- a/resources/ext.popups.renderer/desktopRenderer.js
+++ b/resources/ext.popups.renderer/desktopRenderer.js
@@ -2,7 +2,28 @@
 
 ( function ( $, mw ) {
var closeTimer, openTimer,
+   $activeLink = null,
logData = {};
+
+   /**
+* Sets the link that the currently shown popup relates to
+*
+* @ignore
+* @param {jQuery|null} [$link] if undefined there is no active link
+*/
+   function setActiveLink( $link ) {
+   $activeLink = $link;
+   }
+
+   /**
+* Gets the link that the currently shown popup relates to
+*
+* @ignore
+* @return {jQuery|null} if undefined there is no active link
+*/
+   function getActiveLink() {
+   return $activeLink;
+   }
 
/**
 * Logs the click on link or popup
@@ -65,12 +86,6 @@
mw.popups.render.cache = {};
 
/**
-* The link the currently has a popup
-* @property {jQuery} currentLink
-*/
-   mw.popups.render.currentLink = undefined;
-
-   /**
 * Object to store all renderers
 * @property {Object} renderers
 */
@@ -87,13 +102,14 @@
 * @param {string} linkInteractionToken random token representing the 
current interaction with the link
 */
mw.popups.render.render = function ( $link, event, dwellStartTime, 
linkInteractionToken ) {
-   var linkHref = $link.attr( 'href' );
+   var linkHref = $link.attr( 'href' ),
+   $activeLink = getActiveLink();
 
// This will happen when the mouse goes from the popup box back 
to the
// anchor tag. In such a case, the timer to close the box is 
cleared.
if (
-   mw.popups.render.currentLink &&
-   mw.popups.render.currentLink[ 0 ] === $link[ 0 ]
+   $activeLink &&
+   $activeLink[ 0 ] === $link[ 0 ]
) {
if ( closeTimer ) {
closeTimer.abort();
@@ -103,7 +119,7 @@
 
// If the mouse moves to another link (we already check if its 
the same
// link in the previous condition), then close the popup.
-   if ( mw.popups.render.currentLink ) {
+   if ( $activeLink ) {
mw.popups.render.closePopup();
}
 
@@ -113,7 +129,7 @@
return;
}
 
-   mw.popups.render.currentLink = $link;
+   setActiveLink( $link );
// Set the log data only after the current link is set, 
otherwise, functions like
// closePopup will use the new log data when closing an old 
popup.
logData = {
@@ -224,12 +240,13 @@
 * @param {Object} event
 */
mw.popups.render.clickHandler = function ( event ) {
-   var action = mw.popups.getAction( event );
+   var action = mw.popups.getAction( event ),
+   $activeLink = getActiveLink();
 
logClickAction( event );
 
if ( action === 'opened in same tab' ) {
-   window.location.href = 
mw.popups.render.currentLink.attr( 'href' );
+   window.location.href = $activeLink.attr( 'href' );
}
};
 
@@ -240,13 +257,14 @@
 * @method closePopup
 */
mw.popups.render.closePopup = function () {
-   var fadeInClass, fadeOutClass;
+   var fadeInClass, fadeOutClass,
+   $activeLink = getActiveLink();
 
-   if ( mw.popups.render.currentLink === undefined ) {
+   if ( !$activeLink ) {
return false;
}
 
-   $( mw.popups.render.currentLink ).off( 'mouseleave blur', 
mw.popups.render.leaveActive );
+   $activeLink.off( 'mouseleave blur', 
mw.popups.render.leaveActive );
 
fadeInClass = ( mw.popups.$popup.hasClass( 
'mwe-popups-fade-in-up' ) ) ?
'mwe-popups-fade-in-up' :
@@ -338,6 +356,8 @@
 * @method lea

[MediaWiki-commits] [Gerrit] mediawiki...Popups[master]: Hygiene: Add set and get methods for active link

2016-09-22 Thread Jdlrobson (Code Review)
Jdlrobson has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/312426

Change subject: Hygiene: Add set and get methods for active link
..

Hygiene: Add set and get methods for active link

Named functions help explain to a reader and reviewer what the code
is actually doing.

Change-Id: I1d059c9270fd2298285fa5e4e52e403a06f35503
---
M resources/ext.popups.renderer/desktopRenderer.js
1 file changed, 38 insertions(+), 19 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Popups 
refs/changes/26/312426/1

diff --git a/resources/ext.popups.renderer/desktopRenderer.js 
b/resources/ext.popups.renderer/desktopRenderer.js
index 45ab725..b5ae9f6 100644
--- a/resources/ext.popups.renderer/desktopRenderer.js
+++ b/resources/ext.popups.renderer/desktopRenderer.js
@@ -1,8 +1,28 @@
 /*global popupDelay: true, popupHideDelay: true*/
 
 ( function ( $, mw ) {
-   var closeTimer, openTimer,
+   var closeTimer, openTimer, $activeLink,
logData = {};
+
+   /**
+* Sets the link that the currently shown popup relates to
+*
+* @ignore
+* @param {jQuery} [$link] if undefined there is no active link
+*/
+   function setActiveLink( $link ) {
+   $activeLink = $link;
+   }
+
+   /**
+* Gets the link that the currently shown popup relates to
+*
+* @ignore
+* @return {jQuery|undefined} if undefined there is no active link
+*/
+   function getActiveLink( $link ) {
+   return $activeLink;
+   }
 
/**
 * Logs the click on link or popup
@@ -65,12 +85,6 @@
mw.popups.render.cache = {};
 
/**
-* The link the currently has a popup
-* @property {jQuery} currentLink
-*/
-   mw.popups.render.currentLink = undefined;
-
-   /**
 * Object to store all renderers
 * @property {Object} renderers
 */
@@ -87,13 +101,14 @@
 * @param {string} linkInteractionToken random token representing the 
current interaction with the link
 */
mw.popups.render.render = function ( $link, event, dwellStartTime, 
linkInteractionToken ) {
-   var linkHref = $link.attr( 'href' );
+   var linkHref = $link.attr( 'href' ),
+   $activeLink = getActiveLink();
 
// This will happen when the mouse goes from the popup box back 
to the
// anchor tag. In such a case, the timer to close the box is 
cleared.
if (
-   mw.popups.render.currentLink &&
-   mw.popups.render.currentLink[ 0 ] === $link[ 0 ]
+   $activeLink &&
+   $activeLink[ 0 ] === $link[ 0 ]
) {
if ( closeTimer ) {
closeTimer.abort();
@@ -103,7 +118,7 @@
 
// If the mouse moves to another link (we already check if its 
the same
// link in the previous condition), then close the popup.
-   if ( mw.popups.render.currentLink ) {
+   if ( $activeLink ) {
mw.popups.render.closePopup();
}
 
@@ -113,7 +128,7 @@
return;
}
 
-   mw.popups.render.currentLink = $link;
+   setActiveLink( $link );
// Set the log data only after the current link is set, 
otherwise, functions like
// closePopup will use the new log data when closing an old 
popup.
logData = {
@@ -224,12 +239,13 @@
 * @param {Object} event
 */
mw.popups.render.clickHandler = function ( event ) {
-   var action = mw.popups.getAction( event );
+   var action = mw.popups.getAction( event ),
+   $activeLink = getActiveLink();
 
logClickAction( event );
 
if ( action === 'opened in same tab' ) {
-   window.location.href = 
mw.popups.render.currentLink.attr( 'href' );
+   window.location.href = $activeLink.attr( 'href' );
}
};
 
@@ -240,13 +256,14 @@
 * @method closePopup
 */
mw.popups.render.closePopup = function () {
-   var fadeInClass, fadeOutClass;
+   var fadeInClass, fadeOutClass,
+   $activeLink = getActiveLink();
 
-   if ( mw.popups.render.currentLink === undefined ) {
+   if ( !$activeLink ) {
return false;
}
 
-   $( mw.popups.render.currentLink ).off( 'mouseleave blur', 
mw.popups.render.leaveActive );
+   $activeLink.off( 'mouseleave blur', 
mw.popups.render.leaveActive );
 
fadeInClass = ( mw.popups.$popup.hasClass(