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

Change subject: Position hovercard according to mouse position
......................................................................


Position hovercard according to mouse position

Bug: 63159
Change-Id: I3d038af8915ff586c76f24bd5c2d623de20b09ab
---
M resources/ext.popups.core.js
1 file changed, 21 insertions(+), 10 deletions(-)

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



diff --git a/resources/ext.popups.core.js b/resources/ext.popups.core.js
index aaeef97..bb1e645 100644
--- a/resources/ext.popups.core.js
+++ b/resources/ext.popups.core.js
@@ -38,8 +38,9 @@
                 * @param {String} href
                 * @param {String} title
                 * @param {Object} $el
+                * @param {Object} event
                 */
-               function sendRequest( href, title, $el ) {
+               function sendRequest( href, title, $el, event ) {
 
                        curRequest = api.get( {
                                action: 'query',
@@ -92,7 +93,7 @@
                                        thumbnail: thumbnail,
                                        tall: tall
                                };
-                               createBox( href, $el );
+                               createBox( href, $el, event );
                        } );
 
                        return true;
@@ -202,11 +203,17 @@
                 * for the anchor element to `leaveActive`.
                 * @param {String} href
                 * @param {Object} $el
+                * @param {Object} event
                 */
-               function createBox( href, $el ) {
-                       var bar = cache[ href ],
-                               offsetTop = $el.offset().top + $el.height() + 9,
-                               offsetLeft = $el.offset().left,
+               function createBox( href, $el, event ) {
+                       var
+                               bar = cache[ href ],
+                               offsetTop = ( event.pageY ) ?
+                                       event.pageY + 20 :
+                                       $el.offset().top + $el.height() + 9,
+                               offsetLeft = ( event.pageX ) ?
+                                       event.pageX :
+                                       $el.offset().left,
                                flipped = false;
 
                        elTime = mw.now();
@@ -221,9 +228,13 @@
                        }
 
                        if ( offsetLeft > ( $( window ).width() / 2 ) ) {
-                               offsetLeft = offsetLeft + $el.width();
+                               offsetLeft += ( !event.pageX ) ? $el.width() : 
0;
                                offsetLeft -= ( !bar.tall ) ? 
SIZES.portraitPopupWidth : SIZES.landscapePopupWidth;
                                flipped = true;
+                       }
+
+                       if ( event.pageX ) {
+                               offsetLeft += ( flipped ) ? 20 : -20; // 
compensating the position of the triangle
                        }
 
                        $box
@@ -438,7 +449,7 @@
                                        .attr( 'data-original-title', '' );
                        } );
 
-               $( '#mw-content-text a' ).on( 'mouseenter focus', function () {
+               $( '#mw-content-text a' ).on( 'mouseenter focus', function ( 
event ) {
                        var $this = $( this ),
                                href = $this.attr( 'href' ),
                                title = $this.attr( 'data-original-title' );
@@ -475,11 +486,11 @@
 
                        if ( cache[ href ] ) {
                                openTimer = setTimeout( function () {
-                                       createBox( href, $this );
+                                       createBox( href, $this, event );
                                }, 150 );
                        } else {
                                openTimer = setTimeout( function () {
-                                       sendRequest( href, title, $this );
+                                       sendRequest( href, title, $this, event 
);
                                }, 50 ); // sendRequest sooner so that it 
*hopefully* shows up in 150ms
                        }
                        // Delay to avoid triggering the popup and AJAX 
requests on accidental

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I3d038af8915ff586c76f24bd5c2d623de20b09ab
Gerrit-PatchSet: 3
Gerrit-Project: mediawiki/extensions/Popups
Gerrit-Branch: master
Gerrit-Owner: Prtksxna <[email protected]>
Gerrit-Reviewer: Kipod <[email protected]>
Gerrit-Reviewer: Spage <[email protected]>
Gerrit-Reviewer: Yuvipanda <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

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

Reply via email to