Bmansurov has uploaded a new change for review.

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

Change subject: Send `dwelledButAbandoned` action for links when popups are 
turned off
......................................................................

Send `dwelledButAbandoned` action for links when popups are turned off

This action correctly gets sent when popups are enabled, but now
it is also being sent when popups are disabled.

Bug: T131315
Change-Id: I426f0a1a735b8fe6b16f3d2695d9099dd0d0469b
---
M resources/ext.popups.schemaPopups.utils.js
M resources/ext.popups.targets/desktopTarget.js
2 files changed, 36 insertions(+), 26 deletions(-)


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

diff --git a/resources/ext.popups.schemaPopups.utils.js 
b/resources/ext.popups.schemaPopups.utils.js
index 11a7796..faf10ed 100644
--- a/resources/ext.popups.schemaPopups.utils.js
+++ b/resources/ext.popups.schemaPopups.utils.js
@@ -13,8 +13,9 @@
                        popupEnabled: mw.popups.getEnabledState(),
                        popupDelay: mw.popups.render.POPUP_DELAY,
                        pageToken: mw.user.generateRandomSessionId() +
-                       Math.floor( mw.now() ).toString() +
-                       mw.user.generateRandomSessionId(),
+                               Math.floor( mw.now() ).toString() +
+                               mw.user.generateRandomSessionId(),
+                       sessionToken: mw.user.sessionId(),
                        // arbitrary name that represents the current UI of the 
popups
                        version: 'legacy',
                        // current API version
@@ -26,8 +27,6 @@
                        defaults.editCountBucket = 
mw.popups.schemaPopups.getEditCountBucket(
                                mw.config.get( 'wgUserEditCount' ) );
                }
-               // Also add the session token
-               defaults.sessionToken = mw.user.sessionId();
 
                return defaults;
        }
diff --git a/resources/ext.popups.targets/desktopTarget.js 
b/resources/ext.popups.targets/desktopTarget.js
index a34e151..f68b17d 100644
--- a/resources/ext.popups.targets/desktopTarget.js
+++ b/resources/ext.popups.targets/desktopTarget.js
@@ -101,32 +101,43 @@
                        mw.popups.removeTooltips( $elements );
                        mw.popups.setupTriggers( $elements );
                } else {
-
-                       $elements.on( mw.popups.triggers, function () {
-                               // cache the hover start time and link 
interaction token for a later use
-                               dwellStartTime = mw.now();
-                               linkInteractionToken = 
mw.popups.getRandomToken();
-                       } );
-
                        // Events are logged even when Hovercards are disabled
                        // See T88166 for details
-                       $elements.on( 'click', function ( event ) {
-                               var $this = $( this ),
-                                       action = mw.popups.getAction( event ),
-                                       href = $this.attr( 'href' );
+                       $elements
+                               .on( mw.popups.triggers, function () {
+                                       // cache the hover start time and link 
interaction token for a later use
+                                       dwellStartTime = mw.now();
+                                       linkInteractionToken = 
mw.popups.getRandomToken();
+                               } )
+                               .on( 'mouseleave blur', function () {
+                                       var $this = $( this );
 
-                               mw.track( 'ext.popups.schemaPopups', {
-                                       pageTitleHover: $this.attr( 'title' ),
-                                       action: action,
-                                       totalInteractionTime: Math.round( 
mw.now() - dwellStartTime ),
-                                       linkInteractionToken: 
linkInteractionToken
+                                       if ( dwellStartTime && 
linkInteractionToken && mw.now() - dwellStartTime >= 250 ) {
+                                               mw.track( 
'ext.popups.schemaPopups', {
+                                                       pageTitleHover: 
$this.attr( 'title' ),
+                                                       action: 
'dwelledButAbandoned',
+                                                       totalInteractionTime: 
Math.round( mw.now() - dwellStartTime ),
+                                                       linkInteractionToken: 
linkInteractionToken
+                                               } );
+                                       }
+                               } )
+                               .on( 'click', function ( event ) {
+                                       var $this = $( this ),
+                                               action = mw.popups.getAction( 
event ),
+                                               href = $this.attr( 'href' );
+
+                                       mw.track( 'ext.popups.schemaPopups', {
+                                               pageTitleHover: $this.attr( 
'title' ),
+                                               action: action,
+                                               totalInteractionTime: 
Math.round( mw.now() - dwellStartTime ),
+                                               linkInteractionToken: 
linkInteractionToken
+                                       } );
+
+                                       if ( action  === 'opened in same tab' ) 
{
+                                               event.preventDefault();
+                                               window.location.href = href;
+                                       }
                                } );
-
-                               if ( action  === 'opened in same tab' ) {
-                                       event.preventDefault();
-                                       window.location.href = href;
-                               }
-                       } );
                }
        } );
 

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I426f0a1a735b8fe6b16f3d2695d9099dd0d0469b
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Popups
Gerrit-Branch: master
Gerrit-Owner: Bmansurov <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to