2013-11-13 23:01:16 +00:00
|
|
|
/*
|
|
|
|
* This file is part of the MediaWiki extension MultimediaViewer.
|
|
|
|
*
|
|
|
|
* MultimediaViewer is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* MultimediaViewer is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with MultimediaViewer. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2014-03-04 12:52:08 +00:00
|
|
|
( function ( mw, $, oo ) {
|
2013-11-25 23:51:40 +00:00
|
|
|
var LIP;
|
|
|
|
|
2014-01-11 00:05:03 +00:00
|
|
|
/**
|
2014-02-25 01:54:05 +00:00
|
|
|
* Represents the main interface of the lightbox
|
2016-07-18 13:49:27 +00:00
|
|
|
*
|
2014-02-25 02:28:49 +00:00
|
|
|
* @class mw.mmv.LightboxInterface
|
2014-03-04 12:52:08 +00:00
|
|
|
* @extends mw.mmv.ui.Element
|
2014-01-11 00:05:03 +00:00
|
|
|
* @constructor
|
|
|
|
*/
|
2014-03-04 12:52:08 +00:00
|
|
|
function LightboxInterface() {
|
2017-06-02 09:29:41 +00:00
|
|
|
this.localStorage = mw.storage;
|
2015-08-14 18:15:57 +00:00
|
|
|
|
2014-09-12 18:05:13 +00:00
|
|
|
/** @property {mw.mmv.Config} config - */
|
|
|
|
this.config = new mw.mmv.Config(
|
|
|
|
mw.config.get( 'wgMultimediaViewer', {} ),
|
|
|
|
mw.config,
|
|
|
|
mw.user,
|
|
|
|
new mw.Api(),
|
2015-08-14 18:15:57 +00:00
|
|
|
this.localStorage
|
2014-09-12 18:05:13 +00:00
|
|
|
);
|
2013-12-12 21:31:14 +00:00
|
|
|
|
2014-02-06 23:18:47 +00:00
|
|
|
/**
|
2014-02-19 02:27:30 +00:00
|
|
|
* @property {mw.mmv.ThumbnailWidthCalculator}
|
2014-02-13 09:52:40 +00:00
|
|
|
* @private
|
2014-02-06 23:18:47 +00:00
|
|
|
*/
|
2014-02-13 09:52:40 +00:00
|
|
|
this.thumbnailWidthCalculator = new mw.mmv.ThumbnailWidthCalculator();
|
|
|
|
|
2014-02-25 01:54:05 +00:00
|
|
|
this.init();
|
2014-03-04 12:52:08 +00:00
|
|
|
mw.mmv.ui.Element.call( this, this.$wrapper );
|
2013-11-13 23:01:16 +00:00
|
|
|
}
|
2014-03-04 12:52:08 +00:00
|
|
|
oo.inheritClass( LightboxInterface, mw.mmv.ui.Element );
|
2013-11-25 23:51:40 +00:00
|
|
|
LIP = LightboxInterface.prototype;
|
|
|
|
|
2014-02-25 01:54:05 +00:00
|
|
|
/**
|
|
|
|
* The currently selected LightboxImage.
|
2016-07-18 13:49:27 +00:00
|
|
|
*
|
2014-02-25 02:28:49 +00:00
|
|
|
* @type {mw.mmv.LightboxImage}
|
2014-02-25 01:54:05 +00:00
|
|
|
* @protected
|
|
|
|
*/
|
|
|
|
LIP.currentImage = null;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initialize the entire interface - helper method.
|
|
|
|
*/
|
|
|
|
LIP.init = function () {
|
2014-02-26 13:15:09 +00:00
|
|
|
// SVG filter, needed to achieve blur in Firefox
|
|
|
|
this.$filter = $( '<svg><filter id="gaussian-blur"><fegaussianblur stdDeviation="3"></filter></svg>' );
|
|
|
|
|
2014-02-25 01:54:05 +00:00
|
|
|
this.$wrapper = $( '<div>' )
|
2014-03-31 21:33:12 +00:00
|
|
|
.addClass( 'mw-mmv-wrapper' );
|
2014-02-25 01:54:05 +00:00
|
|
|
|
|
|
|
this.$main = $( '<div>' )
|
2014-03-31 21:33:12 +00:00
|
|
|
.addClass( 'mw-mmv-main' );
|
2014-02-25 01:54:05 +00:00
|
|
|
|
|
|
|
// I blame CSS for this
|
|
|
|
this.$innerWrapper = $( '<div>' )
|
2014-03-31 21:33:12 +00:00
|
|
|
.addClass( 'mw-mmv-image-inner-wrapper' );
|
2014-02-25 01:54:05 +00:00
|
|
|
|
|
|
|
this.$imageWrapper = $( '<div>' )
|
2014-03-31 21:33:12 +00:00
|
|
|
.addClass( 'mw-mmv-image-wrapper' )
|
2014-02-25 01:54:05 +00:00
|
|
|
.append( this.$innerWrapper );
|
|
|
|
|
|
|
|
this.$preDiv = $( '<div>' )
|
2014-03-31 21:33:12 +00:00
|
|
|
.addClass( 'mw-mmv-pre-image' );
|
2014-02-25 01:54:05 +00:00
|
|
|
|
|
|
|
this.$postDiv = $( '<div>' )
|
2014-03-31 21:33:12 +00:00
|
|
|
.addClass( 'mw-mmv-post-image' );
|
2014-04-04 09:32:30 +00:00
|
|
|
|
2014-07-16 23:15:38 +00:00
|
|
|
this.$aboveFold = $( '<div>' )
|
2014-06-17 22:23:18 +00:00
|
|
|
.addClass( 'mw-mmv-above-fold' );
|
2014-02-25 01:54:05 +00:00
|
|
|
|
|
|
|
this.$main.append(
|
|
|
|
this.$preDiv,
|
|
|
|
this.$imageWrapper,
|
2014-02-26 13:15:09 +00:00
|
|
|
this.$postDiv,
|
|
|
|
this.$filter
|
2014-02-25 01:54:05 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
this.$wrapper.append(
|
|
|
|
this.$main
|
|
|
|
);
|
|
|
|
|
2014-04-04 09:32:30 +00:00
|
|
|
this.setupCanvasButtons();
|
|
|
|
|
2015-08-14 18:15:57 +00:00
|
|
|
this.panel = new mw.mmv.ui.MetadataPanel( this.$postDiv, this.$aboveFold, this.localStorage, this.config );
|
2014-04-04 09:32:30 +00:00
|
|
|
this.buttons = new mw.mmv.ui.CanvasButtons( this.$preDiv, this.$closeButton, this.$fullscreenButton );
|
2014-02-26 20:09:37 +00:00
|
|
|
this.canvas = new mw.mmv.ui.Canvas( this.$innerWrapper, this.$imageWrapper, this.$wrapper );
|
2014-09-12 18:05:13 +00:00
|
|
|
|
|
|
|
this.fileReuse = new mw.mmv.ui.reuse.Dialog( this.$innerWrapper, this.buttons.$reuse, this.config );
|
2014-09-16 20:33:05 +00:00
|
|
|
this.downloadDialog = new mw.mmv.ui.download.Dialog( this.$innerWrapper, this.buttons.$download, this.config );
|
2014-07-23 23:00:37 +00:00
|
|
|
this.optionsDialog = new mw.mmv.ui.OptionsDialog( this.$innerWrapper, this.buttons.$options, this.config );
|
2014-09-12 18:05:13 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets up the file reuse data in the DOM
|
2016-07-18 13:49:27 +00:00
|
|
|
*
|
2014-09-12 18:05:13 +00:00
|
|
|
* @param {mw.mmv.model.Image} image
|
|
|
|
* @param {mw.mmv.model.Repo} repo
|
|
|
|
* @param {string} caption
|
2014-12-30 05:10:27 +00:00
|
|
|
* @param {string} alt
|
2014-09-12 18:05:13 +00:00
|
|
|
*/
|
2014-12-30 05:10:27 +00:00
|
|
|
LIP.setFileReuseData = function ( image, repo, caption, alt ) {
|
|
|
|
this.fileReuse.set( image, repo, caption, alt );
|
2014-09-16 20:33:05 +00:00
|
|
|
this.downloadDialog.set( image, repo );
|
2014-02-25 01:54:05 +00:00
|
|
|
};
|
|
|
|
|
2014-02-19 02:27:30 +00:00
|
|
|
/**
|
|
|
|
* Empties the interface.
|
|
|
|
*/
|
2013-12-06 20:10:51 +00:00
|
|
|
LIP.empty = function () {
|
2014-02-07 14:47:00 +00:00
|
|
|
this.panel.empty();
|
2013-12-06 20:10:51 +00:00
|
|
|
|
2014-02-26 20:09:37 +00:00
|
|
|
this.canvas.empty();
|
2014-09-12 18:05:13 +00:00
|
|
|
|
|
|
|
this.buttons.empty();
|
2015-06-19 00:16:16 +00:00
|
|
|
|
|
|
|
this.$main.addClass( 'metadata-panel-is-closed' )
|
|
|
|
.removeClass( 'metadata-panel-is-open' );
|
2013-12-06 20:10:51 +00:00
|
|
|
};
|
|
|
|
|
2014-03-05 02:24:18 +00:00
|
|
|
/**
|
|
|
|
* Opens the lightbox.
|
|
|
|
*/
|
|
|
|
LIP.open = function () {
|
|
|
|
this.empty();
|
|
|
|
this.attach();
|
|
|
|
};
|
|
|
|
|
2014-02-19 02:27:30 +00:00
|
|
|
/**
|
|
|
|
* Attaches the interface to the DOM.
|
2016-07-18 13:49:27 +00:00
|
|
|
*
|
2014-02-25 01:54:05 +00:00
|
|
|
* @param {string} [parentId] parent id where we want to attach the UI. Defaults to document
|
|
|
|
* element, override is mainly used for testing.
|
2014-02-19 02:27:30 +00:00
|
|
|
*/
|
2014-01-08 15:14:52 +00:00
|
|
|
LIP.attach = function ( parentId ) {
|
2014-03-04 12:52:08 +00:00
|
|
|
var ui = this,
|
2014-02-25 01:54:05 +00:00
|
|
|
$parent;
|
|
|
|
|
2014-01-08 15:14:52 +00:00
|
|
|
// Advanced description needs to be below the fold when the lightbox opens
|
|
|
|
// regardless of what the scroll value was prior to opening the lightbox
|
2014-04-11 09:31:38 +00:00
|
|
|
// If the lightbox is already attached, it means we're doing prev/next, and
|
|
|
|
// we should avoid scrolling the panel
|
|
|
|
if ( !this.attached ) {
|
2017-09-13 18:04:22 +00:00
|
|
|
$( window ).scrollTop( 0 );
|
2014-01-09 16:44:00 +00:00
|
|
|
}
|
2014-01-08 15:14:52 +00:00
|
|
|
|
2014-01-31 10:35:50 +00:00
|
|
|
// Make sure that the metadata is going to be at the bottom when it appears
|
|
|
|
// 83 is the height of the top metadata area. Which can't be measured by
|
|
|
|
// reading the DOM at this point of the execution, unfortunately
|
|
|
|
this.$postDiv.css( 'top', ( $( window ).height() - 83 ) + 'px' );
|
|
|
|
|
2014-02-25 01:54:05 +00:00
|
|
|
// Re-appending the same content can have nasty side-effects
|
|
|
|
// Such as the browser leaving fullscreen mode if the fullscreened element is part of it
|
|
|
|
if ( this.currentlyAttached ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-03-04 12:52:08 +00:00
|
|
|
this.handleEvent( 'keyup', function ( e ) {
|
2015-01-23 12:48:27 +00:00
|
|
|
if ( e.keyCode === 27 && !( e.altKey || e.ctrlKey || e.shiftKey || e.metaKey ) ) {
|
2014-03-04 12:52:08 +00:00
|
|
|
// Escape button pressed
|
|
|
|
ui.unattach();
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
|
2015-01-23 12:48:27 +00:00
|
|
|
this.handleEvent( 'jq-fullscreen-change.lip', function ( e ) {
|
2014-03-04 12:52:08 +00:00
|
|
|
ui.fullscreenChange( e );
|
2014-02-25 01:54:05 +00:00
|
|
|
} );
|
|
|
|
|
2014-03-04 12:52:08 +00:00
|
|
|
this.handleEvent( 'keydown', function ( e ) { ui.keydown( e ); } );
|
|
|
|
|
|
|
|
// mousemove generates a ton of events, which is why we throttle it
|
2015-01-23 12:48:27 +00:00
|
|
|
this.handleEvent( 'mousemove.lip', $.throttle( 250, function ( e ) {
|
2014-03-04 12:52:08 +00:00
|
|
|
ui.mousemove( e );
|
|
|
|
} ) );
|
|
|
|
|
|
|
|
this.handleEvent( 'mmv-faded-out', function ( e ) { ui.fadedOut( e ); } );
|
|
|
|
this.handleEvent( 'mmv-fade-stopped', function ( e ) { ui.fadeStopped( e ); } );
|
|
|
|
|
2015-09-25 19:55:00 +00:00
|
|
|
this.buttons.connect( this, {
|
2016-07-18 13:49:27 +00:00
|
|
|
next: [ 'emit', 'next' ],
|
|
|
|
prev: [ 'emit', 'prev' ]
|
2015-09-25 19:55:00 +00:00
|
|
|
} );
|
|
|
|
|
2014-02-25 01:54:05 +00:00
|
|
|
$parent = $( parentId || document.body );
|
|
|
|
|
|
|
|
// Clean up fullscreen data because hard-existing fullscreen might have left
|
|
|
|
// jquery.fullscreen unable to remove the class and attribute, since $main wasn't
|
|
|
|
// attached to the DOM anymore at the time the jq-fullscreen-change event triggered
|
|
|
|
this.$main.data( 'isFullscreened', false ).removeClass( 'jq-fullscreened' );
|
|
|
|
this.isFullscreen = false;
|
|
|
|
|
|
|
|
$parent
|
|
|
|
.append(
|
2014-03-28 08:06:53 +00:00
|
|
|
this.$wrapper
|
2014-02-25 01:54:05 +00:00
|
|
|
);
|
|
|
|
this.currentlyAttached = true;
|
2014-02-03 11:23:31 +00:00
|
|
|
|
2014-02-13 20:50:05 +00:00
|
|
|
this.panel.attach();
|
|
|
|
|
2014-02-26 20:09:37 +00:00
|
|
|
this.canvas.attach();
|
|
|
|
|
2014-11-22 02:46:51 +00:00
|
|
|
// cross-communication between panel and canvas, sort of
|
|
|
|
this.$postDiv.on( 'mmv-metadata-open.lip', function () {
|
2015-06-19 00:16:16 +00:00
|
|
|
ui.$main.addClass( 'metadata-panel-is-open' )
|
|
|
|
.removeClass( 'metadata-panel-is-closed' );
|
2014-11-22 02:46:51 +00:00
|
|
|
} ).on( 'mmv-metadata-close.lip', function () {
|
2015-06-19 00:16:16 +00:00
|
|
|
ui.$main.removeClass( 'metadata-panel-is-open' )
|
|
|
|
.addClass( 'metadata-panel-is-closed' );
|
2014-11-22 02:46:51 +00:00
|
|
|
} );
|
|
|
|
this.$wrapper.on( 'mmv-panel-close-area-click.lip', function () {
|
|
|
|
ui.panel.scroller.toggle( 'down' );
|
|
|
|
} );
|
|
|
|
|
2014-02-03 11:23:31 +00:00
|
|
|
// Buttons fading might not had been reset properly after a hard fullscreen exit
|
|
|
|
// This needs to happen after the parent attach() because the buttons need to be attached
|
|
|
|
// to the DOM for $.fn.stop() to work
|
2014-02-04 23:44:36 +00:00
|
|
|
this.buttons.stopFade();
|
2014-09-12 18:05:13 +00:00
|
|
|
this.buttons.attach();
|
|
|
|
|
|
|
|
this.fileReuse.attach();
|
2014-09-16 20:33:05 +00:00
|
|
|
this.downloadDialog.attach();
|
2014-07-23 23:00:37 +00:00
|
|
|
this.optionsDialog.attach();
|
2014-03-19 15:01:30 +00:00
|
|
|
|
|
|
|
// Reset the cursor fading
|
|
|
|
this.fadeStopped();
|
2014-04-11 09:31:38 +00:00
|
|
|
|
|
|
|
this.attached = true;
|
2014-01-08 15:14:52 +00:00
|
|
|
};
|
|
|
|
|
2014-02-19 02:27:30 +00:00
|
|
|
/**
|
|
|
|
* Detaches the interface from the DOM.
|
|
|
|
*/
|
2014-01-08 15:14:52 +00:00
|
|
|
LIP.unattach = function () {
|
2014-05-19 09:24:54 +00:00
|
|
|
mw.mmv.actionLogger.log( 'close' );
|
2014-04-15 16:14:06 +00:00
|
|
|
|
2014-11-13 08:55:12 +00:00
|
|
|
// Has to happen first so that the scroller can freeze with visible elements
|
|
|
|
this.panel.unattach();
|
|
|
|
|
2014-02-25 01:54:05 +00:00
|
|
|
this.$wrapper.detach();
|
|
|
|
|
|
|
|
this.currentlyAttached = false;
|
2014-01-08 15:14:52 +00:00
|
|
|
|
2014-06-27 19:45:45 +00:00
|
|
|
this.buttons.unattach();
|
|
|
|
|
2014-11-22 02:46:51 +00:00
|
|
|
this.$postDiv.off( '.lip' );
|
|
|
|
this.$wrapper.off( 'mmv-panel-close-area-click.lip' );
|
|
|
|
|
2014-09-12 18:05:13 +00:00
|
|
|
this.fileReuse.unattach();
|
|
|
|
this.fileReuse.closeDialog();
|
2014-02-28 03:20:40 +00:00
|
|
|
|
2014-09-24 21:05:53 +00:00
|
|
|
this.downloadDialog.unattach();
|
|
|
|
this.downloadDialog.closeDialog();
|
|
|
|
|
2014-07-23 23:00:37 +00:00
|
|
|
this.optionsDialog.unattach();
|
|
|
|
this.optionsDialog.closeDialog();
|
|
|
|
|
2015-01-13 00:06:59 +00:00
|
|
|
// Canvas listens for events from dialogs, so should be unattached at the end
|
|
|
|
this.canvas.unattach();
|
|
|
|
|
2014-02-28 03:20:40 +00:00
|
|
|
this.clearEvents();
|
2014-04-11 09:31:38 +00:00
|
|
|
|
2016-01-07 20:01:49 +00:00
|
|
|
this.buttons.disconnect( this, {
|
2016-07-18 13:49:27 +00:00
|
|
|
next: [ 'emit', 'next' ],
|
|
|
|
prev: [ 'emit', 'prev' ]
|
2016-01-07 20:01:49 +00:00
|
|
|
} );
|
|
|
|
|
2014-04-11 09:31:38 +00:00
|
|
|
// We trigger this event on the document because unattach() can run
|
|
|
|
// when the interface is unattached
|
|
|
|
$( document ).trigger( $.Event( 'mmv-close' ) )
|
|
|
|
.off( 'jq-fullscreen-change.lip' );
|
|
|
|
|
|
|
|
this.attached = false;
|
2014-01-08 15:14:52 +00:00
|
|
|
};
|
|
|
|
|
2014-02-25 01:54:05 +00:00
|
|
|
/**
|
|
|
|
* Exits fullscreen mode.
|
|
|
|
*/
|
|
|
|
LIP.exitFullscreen = function () {
|
|
|
|
this.fullscreenButtonJustPressed = true;
|
|
|
|
this.$main.exitFullscreen();
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Enters fullscreen mode.
|
|
|
|
*/
|
|
|
|
LIP.enterFullscreen = function () {
|
|
|
|
this.$main.enterFullscreen();
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2014-04-04 09:32:30 +00:00
|
|
|
* Setup for canvas navigation buttons
|
2014-02-25 01:54:05 +00:00
|
|
|
*/
|
2014-04-04 09:32:30 +00:00
|
|
|
LIP.setupCanvasButtons = function () {
|
2014-05-31 00:18:12 +00:00
|
|
|
var ui = this,
|
2015-01-23 12:48:27 +00:00
|
|
|
tooltipDelay = mw.config.get( 'wgMultimediaViewer' ).tooltipDelay;
|
2014-02-25 01:54:05 +00:00
|
|
|
|
2017-03-18 06:38:33 +00:00
|
|
|
this.$closeButton = $( '<button>' )
|
2014-02-25 01:54:05 +00:00
|
|
|
.text( ' ' )
|
2014-03-31 21:33:12 +00:00
|
|
|
.addClass( 'mw-mmv-close' )
|
2014-05-31 00:18:12 +00:00
|
|
|
.prop( 'title', mw.message( 'multimediaviewer-close-popup-text' ).text() )
|
|
|
|
.tipsy( {
|
|
|
|
delayIn: tooltipDelay,
|
2014-10-03 09:15:28 +00:00
|
|
|
gravity: this.correctEW( 'ne' )
|
2014-05-31 00:18:12 +00:00
|
|
|
} )
|
2018-04-24 14:47:41 +00:00
|
|
|
.on( 'click', function () {
|
2016-03-02 00:39:18 +00:00
|
|
|
if ( ui.isFullscreen ) {
|
|
|
|
ui.$main.trigger( $.Event( 'jq-fullscreen-change.lip' ) );
|
|
|
|
}
|
2014-03-04 12:52:08 +00:00
|
|
|
ui.unattach();
|
2014-02-25 01:54:05 +00:00
|
|
|
} );
|
|
|
|
|
2017-03-18 06:38:33 +00:00
|
|
|
this.$fullscreenButton = $( '<button>' )
|
2014-02-25 01:54:05 +00:00
|
|
|
.text( ' ' )
|
2014-03-31 21:33:12 +00:00
|
|
|
.addClass( 'mw-mmv-fullscreen' )
|
2014-05-31 00:18:12 +00:00
|
|
|
.prop( 'title', mw.message( 'multimediaviewer-fullscreen-popup-text' ).text() )
|
|
|
|
.tipsy( {
|
|
|
|
delayIn: tooltipDelay,
|
2014-10-03 09:15:28 +00:00
|
|
|
gravity: this.correctEW( 'ne' )
|
2014-05-31 00:18:12 +00:00
|
|
|
} )
|
2018-04-24 14:47:41 +00:00
|
|
|
.on( 'click', function ( e ) {
|
2014-03-04 12:52:08 +00:00
|
|
|
if ( ui.isFullscreen ) {
|
|
|
|
ui.exitFullscreen();
|
2017-06-07 14:52:52 +00:00
|
|
|
|
|
|
|
// 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 );
|
2014-02-25 01:54:05 +00:00
|
|
|
} else {
|
2014-03-04 12:52:08 +00:00
|
|
|
ui.enterFullscreen();
|
2014-02-25 01:54:05 +00:00
|
|
|
}
|
|
|
|
} );
|
|
|
|
|
|
|
|
// If the browser doesn't support fullscreen mode, hide the fullscreen button
|
|
|
|
if ( $.support.fullscreen ) {
|
|
|
|
this.$fullscreenButton.show();
|
|
|
|
} else {
|
|
|
|
this.$fullscreenButton.hide();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-02-19 02:27:30 +00:00
|
|
|
/**
|
|
|
|
* Handle a fullscreen change event.
|
2016-07-18 13:49:27 +00:00
|
|
|
*
|
2014-02-19 02:27:30 +00:00
|
|
|
* @param {jQuery.Event} e The fullscreen change event.
|
|
|
|
*/
|
2014-02-25 01:54:05 +00:00
|
|
|
LIP.fullscreenChange = function ( e ) {
|
|
|
|
this.isFullscreen = e.fullscreen;
|
|
|
|
|
2014-04-15 16:14:06 +00:00
|
|
|
if ( this.isFullscreen ) {
|
2014-05-19 09:24:54 +00:00
|
|
|
mw.mmv.actionLogger.log( 'fullscreen' );
|
2014-05-31 00:18:12 +00:00
|
|
|
|
|
|
|
this.$fullscreenButton
|
2016-12-09 17:02:49 +00:00
|
|
|
.prop( 'title', mw.message( 'multimediaviewer-defullscreen-popup-text' ).text() )
|
|
|
|
.attr( 'alt', mw.message( 'multimediaviewer-defullscreen-popup-text' ).text() );
|
2014-04-15 16:14:06 +00:00
|
|
|
} else {
|
2014-05-19 09:24:54 +00:00
|
|
|
mw.mmv.actionLogger.log( 'defullscreen' );
|
2014-05-31 00:18:12 +00:00
|
|
|
|
|
|
|
this.$fullscreenButton
|
2016-12-09 17:02:49 +00:00
|
|
|
.prop( 'title', mw.message( 'multimediaviewer-fullscreen-popup-text' ).text() )
|
|
|
|
.attr( 'alt', mw.message( 'multimediaviewer-fullscreen-popup-text' ).text() );
|
2014-04-15 16:14:06 +00:00
|
|
|
}
|
|
|
|
|
2014-02-25 01:54:05 +00:00
|
|
|
if ( !this.fullscreenButtonJustPressed && !e.fullscreen ) {
|
|
|
|
// Close the interface all the way if the user pressed 'esc'
|
|
|
|
this.unattach();
|
|
|
|
} else if ( this.fullscreenButtonJustPressed ) {
|
|
|
|
this.fullscreenButtonJustPressed = false;
|
|
|
|
}
|
2014-02-03 11:23:31 +00:00
|
|
|
|
|
|
|
// Fullscreen change events can happen after unattach(), in which
|
|
|
|
// case we shouldn't do anything UI-related
|
|
|
|
if ( !this.currentlyAttached ) {
|
|
|
|
return;
|
|
|
|
}
|
2014-01-06 21:53:42 +00:00
|
|
|
|
2014-02-03 11:23:31 +00:00
|
|
|
if ( this.isFullscreen ) {
|
|
|
|
// When entering fullscreen without a mousemove, the browser
|
|
|
|
// still thinks that the cursor is where it was prior to entering
|
|
|
|
// fullscreen. I.e. on top of the fullscreen button
|
|
|
|
// Thus, we purposefully reset the saved position, so that
|
|
|
|
// the fade out really takes place (otherwise it's cancelled
|
|
|
|
// by updateControls which is called a few times when fullscreen opens)
|
|
|
|
this.mousePosition = { x: 0, y: 0 };
|
2014-02-04 23:44:36 +00:00
|
|
|
this.buttons.fadeOut();
|
2014-02-03 11:23:31 +00:00
|
|
|
}
|
2014-05-07 04:49:15 +00:00
|
|
|
|
|
|
|
// Some browsers only send resize events before toggling fullscreen, but not once the toggling is done
|
|
|
|
// This makes sure that the UI is properly resized after a fullscreen change
|
2014-09-30 14:16:08 +00:00
|
|
|
this.$main.trigger( $.Event( 'mmv-resize-end' ) );
|
2014-01-06 21:53:42 +00:00
|
|
|
};
|
|
|
|
|
2014-01-23 00:38:01 +00:00
|
|
|
/**
|
|
|
|
* Handles keydown events on the document
|
2016-07-18 13:49:27 +00:00
|
|
|
*
|
2014-01-23 00:38:01 +00:00
|
|
|
* @param {jQuery.Event} e The jQuery keypress event object
|
|
|
|
*/
|
|
|
|
LIP.keydown = function ( e ) {
|
2014-03-04 12:52:08 +00:00
|
|
|
var forward,
|
|
|
|
isRtl = $( document.body ).hasClass( 'rtl' );
|
2014-01-23 00:38:01 +00:00
|
|
|
|
2014-02-26 17:04:29 +00:00
|
|
|
if ( e.altKey || e.shiftKey || e.ctrlKey || e.metaKey ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-01-23 00:38:01 +00:00
|
|
|
switch ( e.which ) {
|
2014-03-04 12:52:08 +00:00
|
|
|
case 37: // Left arrow
|
|
|
|
case 39: // Right arrow
|
2014-03-03 11:20:52 +00:00
|
|
|
e.preventDefault();
|
2014-03-04 12:52:08 +00:00
|
|
|
forward = ( e.which === 39 );
|
2014-01-23 00:38:01 +00:00
|
|
|
if ( isRtl ) {
|
2014-03-04 12:52:08 +00:00
|
|
|
forward = !forward;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( forward ) {
|
2015-09-25 19:55:00 +00:00
|
|
|
this.emit( 'next' );
|
2014-01-23 00:38:01 +00:00
|
|
|
} else {
|
2015-09-25 19:55:00 +00:00
|
|
|
this.emit( 'prev' );
|
2014-01-23 00:38:01 +00:00
|
|
|
}
|
2015-09-25 19:55:00 +00:00
|
|
|
|
2014-03-03 11:20:52 +00:00
|
|
|
e.preventDefault();
|
2014-01-23 00:38:01 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-02-03 11:23:31 +00:00
|
|
|
/**
|
|
|
|
* Handles mousemove events on the document
|
2016-07-18 13:49:27 +00:00
|
|
|
*
|
2014-02-19 02:27:30 +00:00
|
|
|
* @param {jQuery.Event} e The mousemove event object
|
2014-02-03 11:23:31 +00:00
|
|
|
*/
|
|
|
|
LIP.mousemove = function ( e ) {
|
2015-07-06 17:44:16 +00:00
|
|
|
// T77869 ignore fake mousemove events triggered by Chrome
|
2014-11-17 20:47:48 +00:00
|
|
|
if (
|
2016-07-18 13:49:27 +00:00
|
|
|
e &&
|
|
|
|
e.originalEvent &&
|
|
|
|
e.originalEvent.movementX === 0 &&
|
|
|
|
e.originalEvent.movementY === 0
|
2014-11-17 20:47:48 +00:00
|
|
|
) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-02-03 11:23:31 +00:00
|
|
|
if ( e ) {
|
|
|
|
// Saving the mouse position is useful whenever we need to
|
|
|
|
// run LIP.mousemove manually, such as when going to the next/prev
|
|
|
|
// element
|
2014-02-04 23:44:36 +00:00
|
|
|
this.mousePosition = { x: e.pageX, y: e.pageY };
|
2014-02-03 11:23:31 +00:00
|
|
|
}
|
|
|
|
|
2014-02-04 23:44:36 +00:00
|
|
|
if ( this.isFullscreen ) {
|
|
|
|
this.buttons.revealAndFade( this.mousePosition );
|
2014-02-03 11:23:31 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-02-18 08:25:48 +00:00
|
|
|
/**
|
|
|
|
* Called when the buttons have completely faded out and disappeared
|
|
|
|
*/
|
|
|
|
LIP.fadedOut = function () {
|
|
|
|
this.$main.addClass( 'cursor-hidden' );
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Called when the buttons have stopped fading and are back into view
|
|
|
|
*/
|
|
|
|
LIP.fadeStopped = function () {
|
|
|
|
this.$main.removeClass( 'cursor-hidden' );
|
|
|
|
};
|
|
|
|
|
2014-02-25 01:54:05 +00:00
|
|
|
/**
|
|
|
|
* Updates the next and prev buttons
|
2016-07-18 13:49:27 +00:00
|
|
|
*
|
2014-02-25 01:54:05 +00:00
|
|
|
* @param {boolean} showPrevButton Whether the prev button should be revealed or not
|
|
|
|
* @param {boolean} showNextButton Whether the next button should be revealed or not
|
|
|
|
*/
|
|
|
|
LIP.updateControls = function ( showPrevButton, showNextButton ) {
|
|
|
|
var prevNextTop = ( ( this.$imageWrapper.height() / 2 ) - 60 ) + 'px';
|
|
|
|
|
|
|
|
if ( this.$main.data( 'isFullscreened' ) ) {
|
|
|
|
this.$postDiv.css( 'top', '' );
|
|
|
|
} else {
|
|
|
|
this.$postDiv.css( 'top', this.$imageWrapper.height() );
|
|
|
|
}
|
|
|
|
|
|
|
|
this.buttons.setOffset( prevNextTop );
|
2014-05-15 20:24:40 +00:00
|
|
|
this.buttons.toggle( showPrevButton, showNextButton );
|
2014-02-25 01:54:05 +00:00
|
|
|
};
|
|
|
|
|
2014-02-25 02:28:49 +00:00
|
|
|
mw.mmv.LightboxInterface = LightboxInterface;
|
2014-03-04 12:52:08 +00:00
|
|
|
}( mediaWiki, jQuery, OO ) );
|