diff --git a/resources/mmv/mmv.lightboxinterface.js b/resources/mmv/mmv.lightboxinterface.js index f81f60938..41b800d47 100644 --- a/resources/mmv/mmv.lightboxinterface.js +++ b/resources/mmv/mmv.lightboxinterface.js @@ -338,9 +338,18 @@ delayIn: tooltipDelay, gravity: this.correctEW( 'ne' ) } ) - .click( function () { + .click( function ( e ) { if ( ui.isFullscreen ) { ui.exitFullscreen(); + + // mousemove is throttled and the mouse coordinates only + // register every 250ms, so there is a chance that we moved + // our mouse over one of the buttons but it didn't register, + // and a fadeOut is triggered; when we're coming back from + // fullscreen, we'll want to make sure the mouse data is + // current so that the fadeOut behavior will not trigger + ui.mousePosition = { x: e.pageX, y: e.pageY }; + ui.buttons.revealAndFade( ui.mousePosition ); } else { ui.enterFullscreen(); } diff --git a/resources/mmv/ui/mmv.ui.canvasButtons.js b/resources/mmv/ui/mmv.ui.canvasButtons.js index aeb36ccd9..0bf6c2c6d 100644 --- a/resources/mmv/ui/mmv.ui.canvasButtons.js +++ b/resources/mmv/ui/mmv.ui.canvasButtons.js @@ -175,9 +175,12 @@ offset = $e.offset(); if ( y >= offset.top && - y <= offset.top + $e.height() && + // using css( 'height' ) & css( 'width' ) instead of .height() + // and .width() since those don't include padding, and as a + // result can return a smaller size than is actually the button + y <= offset.top + parseInt( $e.css( 'height' ) ) && x >= offset.left && - x <= offset.left + $e.width() ) { + x <= offset.left + parseInt( $e.css( 'width' ) ) ) { hovered = true; } } ); diff --git a/tests/qunit/mmv/mmv.lightboxinterface.test.js b/tests/qunit/mmv/mmv.lightboxinterface.test.js index 9003c3887..0f7966476 100644 --- a/tests/qunit/mmv/mmv.lightboxinterface.test.js +++ b/tests/qunit/mmv/mmv.lightboxinterface.test.js @@ -144,7 +144,7 @@ restoreScrollTo(); } ); - QUnit.test( 'Fullscreen mode', 8, function ( assert ) { + QUnit.test( 'Fullscreen mode', 9, function ( assert ) { var buttonOffset, panelBottom, oldRevealButtonsAndFadeIfNeeded, lightbox = new mw.mmv.LightboxInterface(), @@ -202,6 +202,12 @@ assert.ok( panelBottom === $( window ).height(), 'Image metadata does not extend beyond the viewport' ); + lightbox.buttons.revealAndFade = function ( position ) { + assert.ok( true, 'Closing fullscreen triggers a reveal + fade' ); + + oldRevealButtonsAndFadeIfNeeded.call( this, position ); + }; + // Exiting fullscreen lightbox.buttons.$fullscreen.click();