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/>.
|
|
|
|
*/
|
|
|
|
|
2023-05-19 20:26:45 +00:00
|
|
|
const Canvas = require( './ui/mmv.ui.canvas.js' );
|
|
|
|
const CanvasButtons = require( './ui/mmv.ui.canvasButtons.js' );
|
|
|
|
const MetadataPanel = require( './ui/mmv.ui.metadataPanel.js' );
|
|
|
|
const OptionsDialog = require( './ui/mmv.ui.viewingOptions.js' );
|
|
|
|
const ThumbnailWidthCalculator = require( './mmv.ThumbnailWidthCalculator.js' );
|
|
|
|
const UiElement = require( './ui/mmv.ui.js' );
|
|
|
|
|
2024-05-23 20:13:50 +00:00
|
|
|
/** Proxy for a Dialog. Initialises and attaches the dialog upon first use. */
|
|
|
|
class DialogProxy extends UiElement {
|
|
|
|
constructor( eventName, initDialog ) {
|
|
|
|
super();
|
|
|
|
this.eventName = eventName;
|
|
|
|
this.initDialog = initDialog;
|
|
|
|
}
|
|
|
|
|
|
|
|
attach() {
|
|
|
|
this.handleEvent( this.eventName, this.handleOpenCloseClick.bind( this ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
set( ...setValues ) {
|
|
|
|
this.setValues = setValues;
|
|
|
|
}
|
|
|
|
|
|
|
|
handleOpenCloseClick() {
|
|
|
|
mw.loader.using( 'mmv.ui.reuse', ( req ) => {
|
|
|
|
this.unattach();
|
|
|
|
const dialog = this.initDialog( req );
|
|
|
|
dialog.attach();
|
|
|
|
dialog.set( ...this.setValues );
|
|
|
|
dialog.handleOpenCloseClick();
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
|
|
|
|
closeDialog() {}
|
|
|
|
}
|
|
|
|
|
2024-05-21 20:12:08 +00:00
|
|
|
/**
|
|
|
|
* Represents the main interface of the lightbox
|
|
|
|
*/
|
|
|
|
class LightboxInterface extends UiElement {
|
2015-06-19 00:16:16 +00:00
|
|
|
|
2024-05-21 20:12:08 +00:00
|
|
|
constructor() {
|
|
|
|
const $wrapper = $( '<div>' )
|
|
|
|
.addClass( 'mw-mmv-wrapper' );
|
|
|
|
super( $wrapper );
|
|
|
|
this.$wrapper = $wrapper;
|
2013-12-06 20:10:51 +00:00
|
|
|
|
2024-06-27 19:03:48 +00:00
|
|
|
// When opening we might override the theme-color, so remember the original value
|
|
|
|
const metaElement = document.querySelector( 'meta[name="theme-color"]' );
|
|
|
|
this.originalThemeColor = metaElement ? metaElement.getAttribute( 'content' ) : null;
|
|
|
|
|
2023-05-20 12:38:59 +00:00
|
|
|
/**
|
2024-05-21 20:12:08 +00:00
|
|
|
* @property {ThumbnailWidthCalculator}
|
|
|
|
* @private
|
2023-05-20 12:38:59 +00:00
|
|
|
*/
|
2024-05-21 20:12:08 +00:00
|
|
|
this.thumbnailWidthCalculator = new ThumbnailWidthCalculator();
|
2014-02-25 01:54:05 +00:00
|
|
|
|
2024-05-21 20:12:08 +00:00
|
|
|
this.$main = $( '<div>' )
|
|
|
|
.addClass( 'mw-mmv-main' );
|
2014-02-25 01:54:05 +00:00
|
|
|
|
2024-05-21 20:12:08 +00:00
|
|
|
// I blame CSS for this
|
|
|
|
this.$innerWrapper = $( '<div>' )
|
|
|
|
.addClass( 'mw-mmv-image-inner-wrapper' );
|
2014-03-04 12:52:08 +00:00
|
|
|
|
2024-05-21 20:12:08 +00:00
|
|
|
this.$imageWrapper = $( '<div>' )
|
|
|
|
.addClass( 'mw-mmv-image-wrapper' )
|
|
|
|
.append( this.$innerWrapper );
|
2014-03-04 12:52:08 +00:00
|
|
|
|
2024-05-21 20:12:08 +00:00
|
|
|
this.$preDiv = $( '<div>' )
|
|
|
|
// The overlay has no-invert, so the interface overlaid
|
|
|
|
// on it must also have no-invert
|
|
|
|
.addClass( 'mw-mmv-pre-image mw-no-invert' );
|
2015-09-25 19:55:00 +00:00
|
|
|
|
2024-05-21 20:12:08 +00:00
|
|
|
this.$postDiv = $( '<div>' )
|
|
|
|
.addClass( 'mw-mmv-post-image' );
|
2014-02-25 01:54:05 +00:00
|
|
|
|
2024-05-21 20:12:08 +00:00
|
|
|
this.$aboveFold = $( '<div>' )
|
|
|
|
.addClass( 'mw-mmv-above-fold' );
|
2014-02-25 01:54:05 +00:00
|
|
|
|
2024-05-21 20:12:08 +00:00
|
|
|
this.$main.append(
|
|
|
|
this.$preDiv,
|
|
|
|
this.$imageWrapper,
|
2024-05-15 18:40:29 +00:00
|
|
|
this.$postDiv
|
2024-05-21 20:12:08 +00:00
|
|
|
);
|
2024-05-20 20:04:59 +00:00
|
|
|
|
2024-05-21 20:12:08 +00:00
|
|
|
this.$wrapper.append(
|
|
|
|
this.$main
|
|
|
|
);
|
2014-02-03 11:23:31 +00:00
|
|
|
|
2024-05-21 20:12:08 +00:00
|
|
|
this.setupCanvasButtons();
|
2014-02-13 20:50:05 +00:00
|
|
|
|
2024-08-11 09:58:39 +00:00
|
|
|
this.panel = new MetadataPanel( this.$postDiv, this.$aboveFold );
|
2024-05-21 20:12:08 +00:00
|
|
|
this.buttons = new CanvasButtons( this.$preDiv, this.$closeButton, this.$fullscreenButton );
|
|
|
|
this.canvas = new Canvas( this.$innerWrapper, this.$imageWrapper, this.$wrapper );
|
2014-02-26 20:09:37 +00:00
|
|
|
|
2024-05-29 08:54:16 +00:00
|
|
|
/** @property {DialogProxy|ReuseDialog} */
|
2024-05-23 20:13:50 +00:00
|
|
|
this.fileReuse = new DialogProxy( 'mmv-reuse-open', ( req ) => {
|
|
|
|
const { ReuseDialog } = req( 'mmv.ui.reuse' );
|
2024-08-11 09:58:39 +00:00
|
|
|
this.fileReuse = new ReuseDialog( this.$preDiv, this.buttons.$download );
|
2024-05-23 20:13:50 +00:00
|
|
|
return this.fileReuse;
|
|
|
|
} );
|
2024-05-29 08:54:16 +00:00
|
|
|
/** @property {DialogProxy|DownloadDialog} */
|
2024-05-23 20:13:50 +00:00
|
|
|
this.downloadDialog = new DialogProxy( 'mmv-download-open', ( req ) => {
|
|
|
|
const { DownloadDialog } = req( 'mmv.ui.reuse' );
|
2024-08-11 09:58:39 +00:00
|
|
|
this.downloadDialog = new DownloadDialog( this.$preDiv, this.buttons.$download );
|
2024-05-23 20:13:50 +00:00
|
|
|
return this.downloadDialog;
|
|
|
|
} );
|
2024-08-11 09:58:39 +00:00
|
|
|
this.optionsDialog = new OptionsDialog( this.$preDiv, this.buttons.$options );
|
2024-05-21 20:12:08 +00:00
|
|
|
}
|
2014-11-22 02:46:51 +00:00
|
|
|
|
2024-05-21 20:12:08 +00:00
|
|
|
/**
|
|
|
|
* Sets up the file reuse data in the DOM
|
|
|
|
*
|
2024-05-29 08:54:16 +00:00
|
|
|
* @param {ImageModel} image
|
2024-05-21 20:12:08 +00:00
|
|
|
* @param {string} caption
|
|
|
|
* @param {string} alt
|
|
|
|
*/
|
2024-05-29 08:54:16 +00:00
|
|
|
setFileReuseData( image, caption, alt ) {
|
2024-05-21 20:12:08 +00:00
|
|
|
this.buttons.set( image );
|
2024-05-29 08:54:16 +00:00
|
|
|
this.fileReuse.set( image, caption, alt );
|
|
|
|
this.downloadDialog.set( image );
|
2024-05-21 20:12:08 +00:00
|
|
|
}
|
2014-09-12 18:05:13 +00:00
|
|
|
|
2024-05-21 20:12:08 +00:00
|
|
|
/**
|
|
|
|
* Empties the interface.
|
|
|
|
*/
|
|
|
|
empty() {
|
|
|
|
this.panel.empty();
|
|
|
|
this.canvas.empty();
|
|
|
|
this.buttons.empty();
|
2014-01-08 15:14:52 +00:00
|
|
|
|
2024-05-21 20:12:08 +00:00
|
|
|
this.$main.addClass( 'metadata-panel-is-closed' )
|
|
|
|
.removeClass( 'metadata-panel-is-open' );
|
|
|
|
}
|
2020-01-07 08:55:09 +00:00
|
|
|
|
2024-05-21 20:12:08 +00:00
|
|
|
/**
|
|
|
|
* Opens the lightbox.
|
|
|
|
*/
|
|
|
|
open() {
|
|
|
|
this.empty();
|
|
|
|
this.attach();
|
|
|
|
}
|
2014-11-13 08:55:12 +00:00
|
|
|
|
2024-05-21 20:12:08 +00:00
|
|
|
/**
|
|
|
|
* Attaches the interface to the DOM.
|
|
|
|
*
|
|
|
|
* @param {string} [parentId] parent id where we want to attach the UI. Defaults to document
|
|
|
|
* element, override is mainly used for testing.
|
|
|
|
*/
|
|
|
|
attach( parentId ) {
|
|
|
|
// Advanced description needs to be below the fold when the lightbox opens
|
|
|
|
// regardless of what the scroll value was prior to opening the lightbox
|
|
|
|
// If the lightbox is already attached, it means we're doing prev/next, and
|
|
|
|
// we should avoid scrolling the panel
|
|
|
|
if ( !this.attached ) {
|
|
|
|
$( window ).scrollTop( 0 );
|
|
|
|
}
|
2014-02-25 01:54:05 +00:00
|
|
|
|
2024-05-21 20:12:08 +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-01-08 15:14:52 +00:00
|
|
|
|
2024-05-21 20:12:08 +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;
|
2023-05-20 12:38:59 +00:00
|
|
|
}
|
2014-06-27 19:45:45 +00:00
|
|
|
|
2024-06-27 19:03:48 +00:00
|
|
|
// Make sure devices set their theming to dark to match the background of the viewer
|
|
|
|
this.setThemeColor( '#000000' );
|
|
|
|
|
2024-05-21 20:12:08 +00:00
|
|
|
this.handleEvent( 'keyup', ( e ) => {
|
|
|
|
if ( e.keyCode === 27 && !( e.altKey || e.ctrlKey || e.shiftKey || e.metaKey ) ) {
|
|
|
|
// Escape button pressed
|
|
|
|
this.unattach();
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
|
|
|
|
this.handleEvent( 'fullscreenchange.lip', () => {
|
|
|
|
this.fullscreenChange();
|
|
|
|
} );
|
|
|
|
|
|
|
|
this.handleEvent( 'keydown', ( e ) => {
|
|
|
|
this.keydown( e );
|
|
|
|
} );
|
|
|
|
|
|
|
|
this.handleEvent( 'touchstart', ( e ) => {
|
|
|
|
this.touchTap( e );
|
|
|
|
} );
|
|
|
|
|
|
|
|
// mousemove generates a ton of events, which is why we throttle it
|
|
|
|
this.handleEvent( 'mousemove.lip', mw.util.throttle( ( e ) => {
|
|
|
|
this.mousemove( e );
|
2024-06-12 22:59:08 +00:00
|
|
|
}, 100, true ) );
|
2024-05-21 20:12:08 +00:00
|
|
|
|
|
|
|
this.buttons.connect( this, {
|
|
|
|
next: [ 'emit', 'next' ],
|
|
|
|
prev: [ 'emit', 'prev' ]
|
|
|
|
} );
|
|
|
|
|
|
|
|
const $parent = $( parentId || document.body );
|
|
|
|
|
|
|
|
// Clean up fullscreen data left attached to the DOM
|
2024-06-12 22:59:08 +00:00
|
|
|
this.$main.removeClass( 'jq-fullscreened' ).removeClass( 'user-inactive' );
|
2024-05-21 20:12:08 +00:00
|
|
|
this.isFullscreen = false;
|
|
|
|
|
|
|
|
$parent
|
|
|
|
.append(
|
|
|
|
this.$wrapper
|
|
|
|
);
|
|
|
|
this.currentlyAttached = true;
|
|
|
|
|
|
|
|
this.panel.attach();
|
|
|
|
|
|
|
|
this.canvas.attach();
|
|
|
|
|
|
|
|
// cross-communication between panel and canvas, sort of
|
|
|
|
this.$postDiv.on( 'mmv-metadata-open.lip', () => {
|
|
|
|
this.$main.addClass( 'metadata-panel-is-open' )
|
|
|
|
.removeClass( 'metadata-panel-is-closed' );
|
|
|
|
} ).on( 'mmv-metadata-close.lip', () => {
|
|
|
|
this.$main.removeClass( 'metadata-panel-is-open' )
|
|
|
|
.addClass( 'metadata-panel-is-closed' );
|
|
|
|
} );
|
|
|
|
this.$wrapper.on( 'mmv-panel-close-area-click.lip', () => {
|
|
|
|
this.panel.scroller.toggle( 'down' );
|
|
|
|
} );
|
|
|
|
|
|
|
|
this.buttons.attach();
|
|
|
|
|
|
|
|
this.fileReuse.attach();
|
|
|
|
this.downloadDialog.attach();
|
|
|
|
this.optionsDialog.attach();
|
|
|
|
|
|
|
|
this.attached = true;
|
|
|
|
}
|
2014-11-22 02:46:51 +00:00
|
|
|
|
2024-05-21 20:12:08 +00:00
|
|
|
/**
|
|
|
|
* Detaches the interface from the DOM.
|
|
|
|
*
|
|
|
|
* @fires MultimediaViewer#mmv-close
|
|
|
|
*/
|
|
|
|
unattach() {
|
|
|
|
// We trigger this event on the document because unattach() can run
|
|
|
|
// when the interface is unattached
|
|
|
|
// We're calling this before cleaning up (below) the DOM, as that
|
|
|
|
// appears to have an impact on automatic scroll restoration (which
|
|
|
|
// might happen as a result of this being closed) in FF
|
|
|
|
$( document ).trigger( $.Event( 'mmv-close' ) )
|
|
|
|
.off( 'fullscreenchange.lip' );
|
2014-02-28 03:20:40 +00:00
|
|
|
|
2024-05-21 20:12:08 +00:00
|
|
|
// Has to happen first so that the scroller can freeze with visible elements
|
|
|
|
this.panel.unattach();
|
2014-09-24 21:05:53 +00:00
|
|
|
|
2024-05-21 20:12:08 +00:00
|
|
|
this.$wrapper.detach();
|
2014-07-23 23:00:37 +00:00
|
|
|
|
2024-05-21 20:12:08 +00:00
|
|
|
this.currentlyAttached = false;
|
2015-01-13 00:06:59 +00:00
|
|
|
|
2024-05-21 20:12:08 +00:00
|
|
|
this.buttons.unattach();
|
2014-04-11 09:31:38 +00:00
|
|
|
|
2024-05-21 20:12:08 +00:00
|
|
|
this.$postDiv.off( '.lip' );
|
|
|
|
this.$wrapper.off( 'mmv-panel-close-area-click.lip' );
|
2016-01-07 20:01:49 +00:00
|
|
|
|
2024-05-21 20:12:08 +00:00
|
|
|
this.fileReuse.unattach();
|
|
|
|
this.fileReuse.closeDialog();
|
2014-01-08 15:14:52 +00:00
|
|
|
|
2024-05-21 20:12:08 +00:00
|
|
|
this.downloadDialog.unattach();
|
|
|
|
this.downloadDialog.closeDialog();
|
2014-02-25 01:54:05 +00:00
|
|
|
|
2024-05-21 20:12:08 +00:00
|
|
|
this.optionsDialog.unattach();
|
|
|
|
this.optionsDialog.closeDialog();
|
2014-02-25 01:54:05 +00:00
|
|
|
|
2024-05-21 20:12:08 +00:00
|
|
|
// Canvas listens for events from dialogs, so should be unattached at the end
|
|
|
|
this.canvas.unattach();
|
2014-02-25 01:54:05 +00:00
|
|
|
|
2024-05-21 20:12:08 +00:00
|
|
|
this.clearEvents();
|
2014-02-25 01:54:05 +00:00
|
|
|
|
2024-05-21 20:12:08 +00:00
|
|
|
this.buttons.disconnect( this, {
|
|
|
|
next: [ 'emit', 'next' ],
|
|
|
|
prev: [ 'emit', 'prev' ]
|
|
|
|
} );
|
2014-02-25 01:54:05 +00:00
|
|
|
|
2024-06-27 19:03:48 +00:00
|
|
|
this.setThemeColor( this.originalThemeColor );
|
|
|
|
|
2024-05-21 20:12:08 +00:00
|
|
|
this.attached = false;
|
|
|
|
}
|
2014-04-15 16:14:06 +00:00
|
|
|
|
2024-05-21 20:12:08 +00:00
|
|
|
/**
|
|
|
|
* Exits fullscreen mode.
|
|
|
|
*/
|
|
|
|
exitFullscreen() {
|
|
|
|
this.fullscreenButtonJustPressed = true;
|
|
|
|
if ( this.$main.get( 0 ) === document.fullscreenElement ) {
|
|
|
|
if ( document.exitFullscreen ) {
|
|
|
|
document.exitFullscreen();
|
2023-09-21 23:24:12 +00:00
|
|
|
}
|
2014-02-25 01:54:05 +00:00
|
|
|
}
|
2024-05-21 20:12:08 +00:00
|
|
|
this.isFullscreen = false;
|
|
|
|
this.$main.removeClass( 'jq-fullscreened' );
|
2024-06-12 22:59:08 +00:00
|
|
|
clearTimeout( this.interactionTimer );
|
|
|
|
this.userActivity();
|
2024-05-21 20:12:08 +00:00
|
|
|
}
|
2014-02-03 11:23:31 +00:00
|
|
|
|
2024-05-21 20:12:08 +00:00
|
|
|
/**
|
|
|
|
* Enters fullscreen mode.
|
|
|
|
*/
|
|
|
|
enterFullscreen() {
|
|
|
|
const el = this.$main.get( 0 );
|
|
|
|
if ( el.requestFullscreen ) {
|
|
|
|
el.requestFullscreen();
|
2014-02-03 11:23:31 +00:00
|
|
|
}
|
2024-05-21 20:12:08 +00:00
|
|
|
this.isFullscreen = true;
|
|
|
|
this.$main.addClass( 'jq-fullscreened' );
|
2024-06-12 22:59:08 +00:00
|
|
|
this.resetInteractionTimer();
|
|
|
|
this.userInactive();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Interrupt and reset the 3sec delay to hide the controls
|
|
|
|
*/
|
|
|
|
resetInteractionTimer() {
|
|
|
|
clearTimeout( this.interactionTimer );
|
|
|
|
this.interactionTimer = setTimeout( () => {
|
|
|
|
this.userInactive();
|
|
|
|
}, 3000 );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* In fullscreen, hide the mouse cursor and the controls
|
|
|
|
* Called from resetInteractionTimer()
|
|
|
|
*/
|
|
|
|
userInactive() {
|
|
|
|
this.$main.addClass( 'user-inactive' );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* In fullscreen, show the mouse cursor and the controls
|
|
|
|
* Call this after any interactivity
|
|
|
|
*/
|
|
|
|
userActivity() {
|
|
|
|
this.$main.removeClass( 'user-inactive' );
|
2024-05-21 20:12:08 +00:00
|
|
|
}
|
2014-01-06 21:53:42 +00:00
|
|
|
|
2024-05-21 20:12:08 +00:00
|
|
|
/**
|
|
|
|
* Setup for canvas navigation buttons
|
|
|
|
*/
|
|
|
|
setupCanvasButtons() {
|
|
|
|
this.$closeButton = $( '<button>' )
|
2024-06-12 22:59:08 +00:00
|
|
|
.addClass( 'cdx-button cdx-button--icon-only mw-mmv-button mw-mmv-close' )
|
2024-05-28 18:04:50 +00:00
|
|
|
.prop( 'title', mw.msg( 'multimediaviewer-close-popup-text' ) )
|
2024-07-11 15:44:51 +00:00
|
|
|
.append( $( '<span>' ).addClass( 'mw-mmv-icon' ) )
|
2024-05-21 20:12:08 +00:00
|
|
|
.on( 'click', () => {
|
2023-05-20 12:38:59 +00:00
|
|
|
this.unattach();
|
2024-05-21 20:12:08 +00:00
|
|
|
} );
|
2014-01-06 21:53:42 +00:00
|
|
|
|
2024-05-21 20:12:08 +00:00
|
|
|
this.$fullscreenButton = $( '<button>' )
|
2024-06-12 22:59:08 +00:00
|
|
|
.addClass( 'cdx-button cdx-button--icon-only mw-mmv-button mw-mmv-fullscreen' )
|
2024-05-28 18:04:50 +00:00
|
|
|
.prop( 'title', mw.msg( 'multimediaviewer-fullscreen-popup-text' ) )
|
2024-07-11 15:44:51 +00:00
|
|
|
.append( $( '<span>' ).addClass( 'mw-mmv-icon' ) )
|
2024-06-12 22:59:08 +00:00
|
|
|
.on( 'click', () => {
|
2024-05-21 20:12:08 +00:00
|
|
|
if ( this.isFullscreen ) {
|
|
|
|
this.exitFullscreen();
|
|
|
|
} else {
|
|
|
|
this.enterFullscreen();
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
}
|
2023-05-20 12:38:59 +00:00
|
|
|
|
2024-05-21 20:12:08 +00:00
|
|
|
/**
|
|
|
|
* Handle a fullscreen change event.
|
|
|
|
*/
|
|
|
|
fullscreenChange() {
|
|
|
|
// eslint-disable-next-line compat/compat
|
|
|
|
this.isFullscreen = !!document.fullscreenElement;
|
|
|
|
if ( this.isFullscreen ) {
|
|
|
|
this.$fullscreenButton
|
2024-05-28 18:04:50 +00:00
|
|
|
.prop( 'title', mw.msg( 'multimediaviewer-defullscreen-popup-text' ) )
|
|
|
|
.attr( 'alt', mw.msg( 'multimediaviewer-defullscreen-popup-text' ) );
|
2024-05-21 20:12:08 +00:00
|
|
|
} else {
|
|
|
|
this.$fullscreenButton
|
2024-05-28 18:04:50 +00:00
|
|
|
.prop( 'title', mw.msg( 'multimediaviewer-fullscreen-popup-text' ) )
|
|
|
|
.attr( 'alt', mw.msg( 'multimediaviewer-fullscreen-popup-text' ) );
|
2024-05-21 20:12:08 +00:00
|
|
|
}
|
2014-01-23 00:38:01 +00:00
|
|
|
|
2024-05-21 20:12:08 +00:00
|
|
|
if ( !this.fullscreenButtonJustPressed && !this.isFullscreen ) {
|
|
|
|
// Close the interface all the way if the user pressed 'esc'
|
|
|
|
this.unattach();
|
|
|
|
} else if ( this.fullscreenButtonJustPressed ) {
|
|
|
|
this.fullscreenButtonJustPressed = false;
|
2014-02-26 17:04:29 +00:00
|
|
|
}
|
|
|
|
|
2024-05-21 20:12:08 +00:00
|
|
|
// Fullscreen change events can happen after unattach(), in which
|
|
|
|
// case we shouldn't do anything UI-related
|
|
|
|
if ( !this.currentlyAttached ) {
|
|
|
|
return;
|
|
|
|
}
|
2014-03-04 12:52:08 +00:00
|
|
|
|
2024-05-21 20:12:08 +00:00
|
|
|
if ( this.isFullscreen ) {
|
2024-06-12 22:59:08 +00:00
|
|
|
this.userInactive();
|
2014-01-23 00:38:01 +00:00
|
|
|
}
|
|
|
|
|
2024-05-21 20:12:08 +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
|
|
|
|
this.$main.trigger( $.Event( 'mmv-resize-end' ) );
|
|
|
|
}
|
2023-05-20 12:38:59 +00:00
|
|
|
|
2024-05-21 20:12:08 +00:00
|
|
|
/**
|
|
|
|
* Handles keydown events on the document
|
|
|
|
*
|
|
|
|
* @param {jQuery.Event} e The jQuery keypress event object
|
|
|
|
*/
|
|
|
|
keydown( e ) {
|
|
|
|
const isRtl = $( document.body ).hasClass( 'rtl' );
|
2014-11-17 20:47:48 +00:00
|
|
|
|
2024-05-21 20:12:08 +00:00
|
|
|
if ( e.altKey || e.shiftKey || e.ctrlKey || e.metaKey ) {
|
|
|
|
return;
|
2014-02-03 11:23:31 +00:00
|
|
|
}
|
2024-05-21 20:12:08 +00:00
|
|
|
if ( e.key === 'ArrowLeft' ) {
|
|
|
|
this.emit( isRtl ? 'next' : 'prev' );
|
|
|
|
e.preventDefault();
|
|
|
|
} else if ( e.key === 'ArrowRight' ) {
|
|
|
|
this.emit( isRtl ? 'prev' : 'next' );
|
|
|
|
e.preventDefault();
|
|
|
|
} else if ( e.key === 'Home' ) {
|
|
|
|
this.emit( 'first' );
|
|
|
|
e.preventDefault();
|
|
|
|
} else if ( e.key === 'End' ) {
|
|
|
|
this.emit( 'last' );
|
|
|
|
e.preventDefault();
|
2024-06-12 22:59:08 +00:00
|
|
|
} else if ( this.isFullscreen ) {
|
|
|
|
// Any other key in fullscreen reveals the controls
|
|
|
|
this.resetInteractionTimer();
|
|
|
|
this.userActivity();
|
2024-05-21 20:12:08 +00:00
|
|
|
}
|
|
|
|
}
|
2014-02-03 11:23:31 +00:00
|
|
|
|
2024-05-21 20:12:08 +00:00
|
|
|
/**
|
|
|
|
* Handles mousemove events on the document
|
|
|
|
*
|
|
|
|
* @param {jQuery.Event} e The mousemove event object
|
|
|
|
*/
|
|
|
|
mousemove( e ) {
|
|
|
|
// T77869 ignore fake mousemove events triggered by Chrome
|
|
|
|
if (
|
|
|
|
e &&
|
|
|
|
e.originalEvent &&
|
|
|
|
e.originalEvent.movementX === 0 &&
|
|
|
|
e.originalEvent.movementY === 0
|
|
|
|
) {
|
|
|
|
return;
|
2014-02-03 11:23:31 +00:00
|
|
|
}
|
|
|
|
|
2024-05-21 20:12:08 +00:00
|
|
|
if ( this.isFullscreen ) {
|
2024-06-12 22:59:08 +00:00
|
|
|
this.resetInteractionTimer();
|
|
|
|
this.userActivity();
|
2024-05-20 20:04:59 +00:00
|
|
|
}
|
2024-05-21 20:12:08 +00:00
|
|
|
}
|
2024-05-20 20:04:59 +00:00
|
|
|
|
2024-05-21 20:12:08 +00:00
|
|
|
touchTap() {
|
|
|
|
if ( this.isFullscreen ) {
|
2024-06-12 22:59:08 +00:00
|
|
|
this.resetInteractionTimer();
|
|
|
|
this.userActivity();
|
2024-05-21 20:12:08 +00:00
|
|
|
}
|
|
|
|
}
|
2014-02-25 01:54:05 +00:00
|
|
|
|
2024-05-21 20:12:08 +00:00
|
|
|
/**
|
|
|
|
* Updates the next and prev buttons
|
|
|
|
*
|
|
|
|
* @param {boolean} showPrevButton Whether the prev button should be revealed or not
|
|
|
|
* @param {boolean} showNextButton Whether the next button should be revealed or not
|
|
|
|
*/
|
|
|
|
updateControls( showPrevButton, showNextButton ) {
|
2024-06-12 22:59:08 +00:00
|
|
|
const prevNextTop = `${ ( this.$imageWrapper.height() - 60 ) / 2 }px`;
|
2024-05-21 20:12:08 +00:00
|
|
|
|
|
|
|
if ( this.isFullscreen ) {
|
|
|
|
this.$postDiv.css( 'top', '' );
|
|
|
|
} else {
|
|
|
|
this.$postDiv.css( 'top', this.$imageWrapper.height() );
|
2014-02-25 01:54:05 +00:00
|
|
|
}
|
2024-05-21 20:12:08 +00:00
|
|
|
|
|
|
|
this.buttons.setOffset( prevNextTop );
|
|
|
|
this.buttons.toggle( showPrevButton, showNextButton );
|
2023-05-20 12:38:59 +00:00
|
|
|
}
|
2024-06-27 19:03:48 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Update the theme-color of the document
|
|
|
|
*
|
|
|
|
* @param {string|null} color to set as theme-color or null to remove the theme-color
|
|
|
|
*/
|
|
|
|
setThemeColor( color ) {
|
|
|
|
let metaElement = document.querySelector( 'meta[name="theme-color"]' );
|
|
|
|
if ( !metaElement ) {
|
|
|
|
metaElement = document.createElement( 'meta' );
|
|
|
|
metaElement.setAttribute( 'name', 'theme-color' );
|
|
|
|
document.head.appendChild( metaElement );
|
|
|
|
}
|
|
|
|
if ( color === null ) {
|
|
|
|
metaElement.remove();
|
|
|
|
} else {
|
|
|
|
this.originalThemeColor = metaElement.getAttribute( 'content' );
|
|
|
|
metaElement.setAttribute( 'content', color );
|
|
|
|
}
|
|
|
|
}
|
2024-05-21 20:12:08 +00:00
|
|
|
}
|
2014-02-25 01:54:05 +00:00
|
|
|
|
2024-05-21 20:12:08 +00:00
|
|
|
module.exports = LightboxInterface;
|