2014-02-17 15:09:23 +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/>.
|
|
|
|
*/
|
|
|
|
|
2018-11-12 16:33:24 +00:00
|
|
|
( function () {
|
2014-03-04 11:53:53 +00:00
|
|
|
var MMVB;
|
2014-02-17 15:09:23 +00:00
|
|
|
|
|
|
|
/**
|
2014-02-21 11:16:30 +00:00
|
|
|
* Bootstrap code listening to thumb clicks checking the initial location.hash
|
2014-02-17 15:09:23 +00:00
|
|
|
* Loads the mmv and opens it if necessary
|
2016-07-18 13:49:27 +00:00
|
|
|
*
|
2014-02-19 02:27:30 +00:00
|
|
|
* @class mw.mmv.MultimediaViewerBootstrap
|
2014-02-17 15:09:23 +00:00
|
|
|
*/
|
2016-07-18 13:49:27 +00:00
|
|
|
function MultimediaViewerBootstrap() {
|
2014-02-24 17:06:11 +00:00
|
|
|
// Exposed for tests
|
2014-04-24 13:47:59 +00:00
|
|
|
this.hoverWaitDuration = 200;
|
2014-03-26 23:59:04 +00:00
|
|
|
|
2014-06-10 23:29:50 +00:00
|
|
|
// TODO lazy-load config and htmlUtils
|
|
|
|
|
|
|
|
/** @property {mw.mmv.Config} config - */
|
|
|
|
this.config = new mw.mmv.Config(
|
|
|
|
mw.config.get( 'wgMultimediaViewer', {} ),
|
|
|
|
mw.config,
|
|
|
|
mw.user,
|
|
|
|
new mw.Api(),
|
2017-06-02 09:29:41 +00:00
|
|
|
mw.storage
|
2014-06-10 23:29:50 +00:00
|
|
|
);
|
|
|
|
|
2016-04-03 09:18:26 +00:00
|
|
|
this.validExtensions = this.config.extensions();
|
|
|
|
|
2014-03-26 23:59:04 +00:00
|
|
|
/** @property {mw.mmv.HtmlUtils} htmlUtils - */
|
|
|
|
this.htmlUtils = new mw.mmv.HtmlUtils();
|
|
|
|
|
2014-04-29 01:35:07 +00:00
|
|
|
/**
|
|
|
|
* This flag is set to true when we were unable to load the viewer.
|
|
|
|
* @property {boolean}
|
|
|
|
*/
|
|
|
|
this.viewerIsBroken = false;
|
|
|
|
|
2014-03-28 22:39:36 +00:00
|
|
|
this.thumbsReadyDeferred = $.Deferred();
|
2014-03-26 23:59:04 +00:00
|
|
|
this.thumbs = [];
|
2015-08-12 19:02:36 +00:00
|
|
|
this.$thumbs = null; // will be set by processThumbs
|
2014-04-24 13:47:59 +00:00
|
|
|
|
2015-08-12 19:02:36 +00:00
|
|
|
// find and setup all thumbs on this page
|
2015-09-01 02:47:00 +00:00
|
|
|
// this will run initially and then every time the content changes,
|
|
|
|
// e.g. via a VE edit or pagination in a multipage file
|
|
|
|
mw.hook( 'wikipage.content' ).add( $.proxy( this, 'processThumbs' ) );
|
2014-04-11 09:31:38 +00:00
|
|
|
|
2014-02-17 15:09:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
MMVB = MultimediaViewerBootstrap.prototype;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Loads the mmv module asynchronously and passes the thumb data to it
|
2016-07-18 13:49:27 +00:00
|
|
|
*
|
2015-12-03 21:35:30 +00:00
|
|
|
* @param {boolean} [setupOverlay]
|
2016-07-18 13:49:27 +00:00
|
|
|
* @return {jQuery.Promise}
|
2014-02-17 15:09:23 +00:00
|
|
|
*/
|
2015-12-03 21:35:30 +00:00
|
|
|
MMVB.loadViewer = function ( setupOverlay ) {
|
2014-02-17 15:09:23 +00:00
|
|
|
var deferred = $.Deferred(),
|
2015-09-04 08:37:04 +00:00
|
|
|
bs = this,
|
|
|
|
viewer,
|
|
|
|
message;
|
2014-02-17 15:09:23 +00:00
|
|
|
|
2014-03-14 22:19:26 +00:00
|
|
|
// Don't load if someone has specifically stopped us from doing so
|
|
|
|
if ( mw.config.get( 'wgMediaViewer' ) !== true ) {
|
|
|
|
return deferred.reject();
|
|
|
|
}
|
|
|
|
|
2015-12-03 21:35:30 +00:00
|
|
|
// FIXME setupOverlay is a quick hack to avoid setting up and immediately
|
|
|
|
// removing the overlay on a not-MMV -> not-MMV hash change.
|
|
|
|
// loadViewer is called on every click and hash change and setting up
|
|
|
|
// the overlay is not needed on all of those; this logic really should
|
|
|
|
// not be here.
|
|
|
|
if ( setupOverlay ) {
|
|
|
|
bs.setupOverlay();
|
|
|
|
}
|
2014-03-28 08:06:53 +00:00
|
|
|
|
2015-01-23 12:48:27 +00:00
|
|
|
mw.loader.using( 'mmv', function () {
|
2015-09-04 08:37:04 +00:00
|
|
|
try {
|
|
|
|
viewer = bs.getViewer();
|
|
|
|
} catch ( e ) {
|
|
|
|
message = e.message;
|
|
|
|
if ( e.stack ) {
|
|
|
|
message += '\n' + e.stack;
|
|
|
|
}
|
|
|
|
deferred.reject( message );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
deferred.resolve( viewer );
|
2014-02-14 00:36:10 +00:00
|
|
|
}, function ( error ) {
|
|
|
|
deferred.reject( error.message );
|
|
|
|
} );
|
2014-02-24 17:06:11 +00:00
|
|
|
|
2017-05-05 15:53:28 +00:00
|
|
|
return deferred.promise()
|
|
|
|
.then(
|
|
|
|
function ( viewer ) {
|
|
|
|
if ( !bs.viewerInitialized ) {
|
|
|
|
if ( bs.thumbs.length ) {
|
|
|
|
viewer.initWithThumbs( bs.thumbs );
|
|
|
|
}
|
|
|
|
|
|
|
|
bs.viewerInitialized = true;
|
|
|
|
}
|
|
|
|
return viewer;
|
|
|
|
},
|
|
|
|
function ( message ) {
|
|
|
|
mw.log.warn( message );
|
|
|
|
bs.cleanupOverlay();
|
|
|
|
bs.viewerIsBroken = true;
|
|
|
|
mw.notify( 'Error loading MediaViewer: ' + message );
|
|
|
|
return $.Deferred().reject( message );
|
2014-02-17 15:09:23 +00:00
|
|
|
}
|
2017-05-05 15:53:28 +00:00
|
|
|
);
|
2014-02-24 17:06:11 +00:00
|
|
|
};
|
2014-02-17 15:09:23 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Processes all thumbs found on the page
|
2016-12-14 13:09:10 +00:00
|
|
|
*
|
|
|
|
* @param {jQuery} $content Element to search for thumbs
|
2014-02-17 15:09:23 +00:00
|
|
|
*/
|
2016-07-18 10:00:46 +00:00
|
|
|
MMVB.processThumbs = function ( $content ) {
|
2014-02-17 15:09:23 +00:00
|
|
|
var bs = this;
|
|
|
|
|
2016-07-18 10:00:46 +00:00
|
|
|
this.$thumbs = $content.find(
|
2016-07-09 16:49:35 +00:00
|
|
|
'.gallery .image img, ' +
|
|
|
|
'a.image img, ' +
|
|
|
|
'#file a img, ' +
|
2016-07-18 09:45:36 +00:00
|
|
|
'figure[typeof*="mw:Image"] > *:first-child > img, ' +
|
2016-07-09 16:49:35 +00:00
|
|
|
'span[typeof*="mw:Image"] img'
|
|
|
|
);
|
2015-08-12 19:02:36 +00:00
|
|
|
|
2014-04-28 23:20:57 +00:00
|
|
|
try {
|
|
|
|
this.$thumbs.each( function ( i, thumb ) {
|
|
|
|
bs.processThumb( thumb );
|
|
|
|
} );
|
|
|
|
} finally {
|
|
|
|
this.thumbsReadyDeferred.resolve();
|
|
|
|
// now that we have set up our real click handler we can we can remove the temporary
|
|
|
|
// handler added in mmv.head.js which just replays clicks to the real handler
|
|
|
|
$( document ).off( 'click.mmv-head' );
|
|
|
|
}
|
2014-02-17 15:09:23 +00:00
|
|
|
};
|
|
|
|
|
2014-06-11 18:42:29 +00:00
|
|
|
/**
|
|
|
|
* Check if this thumbnail should be handled by MediaViewer
|
2016-07-18 13:49:27 +00:00
|
|
|
*
|
2014-06-11 18:42:29 +00:00
|
|
|
* @param {jQuery} $thumb the thumbnail (an `<img>` element) in question
|
|
|
|
* @return {boolean}
|
|
|
|
*/
|
|
|
|
MMVB.isAllowedThumb = function ( $thumb ) {
|
2017-01-18 08:54:12 +00:00
|
|
|
var selectors = [
|
|
|
|
'.metadata', // this is inside an informational template like {{refimprove}} on enwiki.
|
|
|
|
'.noviewer', // MediaViewer has been specifically disabled for this image
|
|
|
|
'.noarticletext', // we are on an error page for a non-existing article, the image is part of some template
|
|
|
|
'#siteNotice',
|
|
|
|
'ul.mw-gallery-slideshow li.gallerybox' // thumbnails of a slideshow gallery
|
|
|
|
];
|
|
|
|
return $thumb.closest( selectors.join( ', ' ) ).length === 0;
|
2014-06-11 18:42:29 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
2014-02-17 15:09:23 +00:00
|
|
|
/**
|
|
|
|
* Processes a thumb
|
2016-07-18 13:49:27 +00:00
|
|
|
*
|
2014-02-17 15:09:23 +00:00
|
|
|
* @param {Object} thumb
|
|
|
|
*/
|
|
|
|
MMVB.processThumb = function ( thumb ) {
|
2016-06-10 09:30:37 +00:00
|
|
|
var title,
|
|
|
|
bs = this,
|
2014-02-17 15:09:23 +00:00
|
|
|
$thumb = $( thumb ),
|
2016-07-09 16:49:35 +00:00
|
|
|
$link = $thumb.closest( 'a.image, [typeof*="mw:Image"] > a' ),
|
|
|
|
$thumbContain = $link.closest( '.thumb, [typeof*="mw:Image"]' ),
|
2014-02-17 15:09:23 +00:00
|
|
|
$enlarge = $thumbContain.find( '.magnify a' ),
|
2014-12-30 05:10:27 +00:00
|
|
|
link = $link.prop( 'href' ),
|
2016-06-10 09:30:37 +00:00
|
|
|
alt = $thumb.attr( 'alt' ),
|
|
|
|
isFilePageMainThumb = $thumb.closest( '#file' ).length > 0;
|
|
|
|
|
|
|
|
if ( isFilePageMainThumb ) {
|
|
|
|
// main thumbnail (file preview area) of a file page
|
|
|
|
// if this is a PDF filetype thumbnail, it can trick us,
|
|
|
|
// so we short-circuit that logic and use the file page title
|
|
|
|
// instead of the thumbnail logic.
|
|
|
|
title = mw.Title.newFromText( mw.config.get( 'wgTitle' ), mw.config.get( 'wgNamespaceNumber' ) );
|
|
|
|
} else {
|
|
|
|
title = mw.Title.newFromImg( $thumb );
|
|
|
|
}
|
2014-02-17 15:09:23 +00:00
|
|
|
|
2016-07-18 12:34:24 +00:00
|
|
|
if ( !title || !title.getExtension() || !( title.getExtension().toLowerCase() in bs.validExtensions ) ) {
|
2016-06-10 09:30:37 +00:00
|
|
|
// Short-circuit event handler and interface setup, because
|
|
|
|
// we can't do anything for this filetype
|
2014-02-17 15:09:23 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-06-11 18:42:29 +00:00
|
|
|
if ( !bs.isAllowedThumb( $thumb ) ) {
|
2014-03-06 23:26:25 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-07-09 16:49:35 +00:00
|
|
|
if ( $thumbContain.length ) {
|
2014-04-24 13:47:59 +00:00
|
|
|
// If this is a thumb, we preload JS/CSS when the mouse cursor hovers the thumb container (thumb image + caption + border)
|
2018-04-24 14:47:41 +00:00
|
|
|
$thumbContain.on( {
|
|
|
|
mouseenter: function () {
|
|
|
|
// There is no point preloading if clicking the thumb won't open Media Viewer
|
|
|
|
if ( !bs.config.isMediaViewerEnabledOnClick() ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
bs.preloadOnHoverTimer = setTimeout( function () {
|
|
|
|
mw.loader.load( 'mmv' );
|
|
|
|
}, bs.hoverWaitDuration );
|
|
|
|
},
|
|
|
|
mouseleave: function () {
|
|
|
|
if ( bs.preloadOnHoverTimer ) {
|
|
|
|
clearTimeout( bs.preloadOnHoverTimer );
|
|
|
|
}
|
2014-04-24 13:47:59 +00:00
|
|
|
}
|
|
|
|
} );
|
2014-02-17 15:09:23 +00:00
|
|
|
}
|
|
|
|
|
2016-06-10 09:30:37 +00:00
|
|
|
if ( isFilePageMainThumb ) {
|
2014-10-19 19:02:49 +00:00
|
|
|
this.processFilePageThumb( $thumb, title );
|
|
|
|
return;
|
2014-04-08 21:01:07 +00:00
|
|
|
}
|
|
|
|
|
2014-02-17 15:09:23 +00:00
|
|
|
// This is the data that will be passed onto the mmv
|
|
|
|
this.thumbs.push( {
|
2016-07-18 13:49:27 +00:00
|
|
|
thumb: thumb,
|
|
|
|
$thumb: $thumb,
|
|
|
|
title: title,
|
|
|
|
link: link,
|
|
|
|
alt: alt,
|
|
|
|
caption: this.findCaption( $thumbContain, $link ) } );
|
2014-02-17 15:09:23 +00:00
|
|
|
|
2018-04-24 14:47:41 +00:00
|
|
|
$link.add( $enlarge ).on( 'click', function ( e ) {
|
2014-10-19 19:02:49 +00:00
|
|
|
return bs.click( this, e, title );
|
|
|
|
} );
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2015-09-01 02:47:00 +00:00
|
|
|
* Processes the main thumbnail of a file page by adding some buttons
|
|
|
|
* below to open MediaViewer.
|
2016-07-18 13:49:27 +00:00
|
|
|
*
|
2014-10-19 19:02:49 +00:00
|
|
|
* @param {jQuery} $thumb
|
|
|
|
* @param {mw.Title} title
|
|
|
|
*/
|
|
|
|
MMVB.processFilePageThumb = function ( $thumb, title ) {
|
|
|
|
var $link,
|
|
|
|
$configLink,
|
2014-10-03 09:15:28 +00:00
|
|
|
$filepageButtons,
|
2014-10-19 19:02:49 +00:00
|
|
|
bs = this,
|
|
|
|
link = $thumb.closest( 'a' ).prop( 'href' );
|
|
|
|
|
2015-09-01 02:47:00 +00:00
|
|
|
// remove the buttons (and the clearing element) if they are already there
|
|
|
|
// this should not happen (at least until we support paged media) but just in case
|
2019-05-06 23:57:14 +00:00
|
|
|
// eslint-disable-next-line no-jquery/no-global-selector
|
2015-09-01 02:47:00 +00:00
|
|
|
$( '.mw-mmv-filepage-buttons' ).next().addBack().remove();
|
|
|
|
|
2014-10-19 19:02:49 +00:00
|
|
|
$link = $( '<a>' )
|
|
|
|
// It won't matter because we catch the click event anyway, but
|
|
|
|
// give the user some URL to see.
|
|
|
|
.prop( 'href', link )
|
|
|
|
.addClass( 'mw-mmv-view-expanded mw-ui-button mw-ui-icon mw-ui-icon-before' )
|
|
|
|
.text( mw.message( 'multimediaviewer-view-expanded' ).text() );
|
|
|
|
|
|
|
|
$configLink = $( '<a>' )
|
|
|
|
.prop( 'href', $thumb.closest( 'a' ).prop( 'href' ) )
|
|
|
|
.addClass( 'mw-mmv-view-config mw-ui-button mw-ui-icon mw-ui-icon-element' )
|
|
|
|
.text( mw.message( 'multimediaviewer-view-config' ).text() );
|
|
|
|
|
2014-10-03 09:15:28 +00:00
|
|
|
$filepageButtons = $( '<div>' )
|
|
|
|
.addClass( 'mw-ui-button-group mw-mmv-filepage-buttons' )
|
|
|
|
.append( $link, $configLink );
|
2014-10-19 19:02:49 +00:00
|
|
|
|
2019-05-06 23:57:14 +00:00
|
|
|
// eslint-disable-next-line no-jquery/no-global-selector
|
2014-10-19 19:02:49 +00:00
|
|
|
$( '.fullMedia' ).append(
|
2014-10-03 09:15:28 +00:00
|
|
|
$filepageButtons,
|
2014-10-19 19:02:49 +00:00
|
|
|
$( '<div>' )
|
|
|
|
.css( 'clear', 'both' )
|
|
|
|
);
|
|
|
|
|
|
|
|
this.thumbs.push( {
|
2016-07-18 13:49:27 +00:00
|
|
|
thumb: $thumb.get( 0 ),
|
|
|
|
$thumb: $thumb,
|
|
|
|
title: title,
|
|
|
|
link: link
|
2014-10-19 19:02:49 +00:00
|
|
|
} );
|
|
|
|
|
2018-04-24 14:47:41 +00:00
|
|
|
$link.on( 'click', function () {
|
2014-10-03 09:15:28 +00:00
|
|
|
if ( bs.statusInfoDialog ) {
|
|
|
|
bs.statusInfoDialog.close();
|
|
|
|
}
|
2014-10-19 19:02:49 +00:00
|
|
|
bs.openImage( this, title );
|
|
|
|
return false;
|
|
|
|
} );
|
|
|
|
|
2018-04-24 14:47:41 +00:00
|
|
|
$configLink.on( 'click', function () {
|
2014-10-03 09:15:28 +00:00
|
|
|
if ( bs.statusInfoDialog ) {
|
|
|
|
bs.statusInfoDialog.close();
|
|
|
|
}
|
2014-10-19 19:02:49 +00:00
|
|
|
bs.openImage( this, title ).then( function () {
|
|
|
|
$( document ).trigger( 'mmv-options-open' );
|
|
|
|
} );
|
|
|
|
return false;
|
2014-02-17 15:09:23 +00:00
|
|
|
} );
|
2014-10-03 09:15:28 +00:00
|
|
|
|
|
|
|
if ( this.config.shouldShowStatusInfo() ) {
|
|
|
|
this.config.disableStatusInfo();
|
|
|
|
this.showStatusInfo();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Shows a popup notifying the user
|
|
|
|
*/
|
|
|
|
MMVB.showStatusInfo = function () {
|
|
|
|
var bs = this;
|
|
|
|
|
|
|
|
mw.loader.using( 'mmv.ui.tipsyDialog' ).done( function () {
|
|
|
|
/** @property {mw.mmv.ui.TipsyDialog} statusInfoDialog popup on the file page explaining how to re-enable */
|
2019-05-06 23:57:14 +00:00
|
|
|
// eslint-disable-next-line no-jquery/no-global-selector
|
2014-10-03 09:15:28 +00:00
|
|
|
bs.statusInfoDialog = new mw.mmv.ui.TipsyDialog( $( '.mw-mmv-view-expanded' ), { gravity: 'sw' } );
|
|
|
|
bs.statusInfoDialog.setContent(
|
|
|
|
mw.message( 'multimediaviewer-disable-info-title' ).plain(),
|
2015-01-23 12:48:27 +00:00
|
|
|
mw.message( 'multimediaviewer-disable-info' ).escaped()
|
2014-10-03 09:15:28 +00:00
|
|
|
);
|
|
|
|
// tipsy mispositions the tooltip, probably because it does the positioning before the buttons are
|
|
|
|
// displayed and the page is reflown. Adding some delay seems to help.
|
2019-06-10 10:39:24 +00:00
|
|
|
setTimeout( function () {
|
2014-10-03 09:15:28 +00:00
|
|
|
bs.statusInfoDialog.open();
|
|
|
|
}, 1000 );
|
|
|
|
} );
|
2014-02-17 15:09:23 +00:00
|
|
|
};
|
|
|
|
|
2014-04-25 23:16:48 +00:00
|
|
|
/**
|
|
|
|
* Finds the caption for an image.
|
2016-07-18 13:49:27 +00:00
|
|
|
*
|
2014-04-25 23:16:48 +00:00
|
|
|
* @param {jQuery} $thumbContain The container for the thumbnail.
|
|
|
|
* @param {jQuery} $link The link that encompasses the thumbnail.
|
2016-07-18 13:49:27 +00:00
|
|
|
* @return {string|undefined} Unsafe HTML may be present - caution
|
2014-04-25 23:16:48 +00:00
|
|
|
*/
|
|
|
|
MMVB.findCaption = function ( $thumbContain, $link ) {
|
2016-08-01 21:00:59 +00:00
|
|
|
var $thumbCaption, $potentialCaptions;
|
2014-04-25 23:16:48 +00:00
|
|
|
|
2016-08-01 21:00:59 +00:00
|
|
|
if ( !$thumbContain.length ) {
|
|
|
|
return $link.prop( 'title' ) || undefined;
|
|
|
|
}
|
|
|
|
|
|
|
|
$potentialCaptions = $thumbContain.find( '.thumbcaption, figcaption' );
|
|
|
|
if ( $potentialCaptions.length < 2 ) {
|
|
|
|
$thumbCaption = $potentialCaptions.eq( 0 );
|
|
|
|
} else {
|
|
|
|
// Template:Multiple_image or some such; try to find closest caption to the image
|
2019-07-29 14:20:17 +00:00
|
|
|
// eslint-disable-next-line no-jquery/no-sizzle
|
2014-12-30 01:26:17 +00:00
|
|
|
$thumbCaption = $link.closest( ':has(> .thumbcaption)', $thumbContain )
|
2016-08-01 21:00:59 +00:00
|
|
|
.find( '> .thumbcaption' );
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( !$thumbCaption.length ) { // gallery, maybe
|
|
|
|
$thumbCaption = $thumbContain
|
|
|
|
.closest( '.gallerybox' )
|
|
|
|
.not( function () {
|
|
|
|
// do not treat categories as galleries - the autogenerated caption they have is not helpful
|
|
|
|
return $thumbContain.closest( '#mw-category-media' ).length;
|
|
|
|
} )
|
|
|
|
.not( function () {
|
|
|
|
// do not treat special file related pages as galleries
|
|
|
|
var $specialFileRelatedPages = $(
|
|
|
|
'.page-Special_NewFiles, ' +
|
|
|
|
'.page-Special_MostLinkedFiles,' +
|
|
|
|
'.page-Special_MostGloballyLinkedFiles, ' +
|
|
|
|
'.page-Special_UncategorizedFiles, ' +
|
|
|
|
'.page-Special_UnusedFiles'
|
|
|
|
);
|
|
|
|
return $thumbContain.closest( $specialFileRelatedPages ).length;
|
|
|
|
} )
|
|
|
|
.find( '.gallerytext' );
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( $thumbCaption.find( '.magnify' ).length ) {
|
|
|
|
$thumbCaption = $thumbCaption.clone();
|
2014-04-25 23:16:48 +00:00
|
|
|
$thumbCaption.find( '.magnify' ).remove();
|
|
|
|
}
|
2016-08-01 21:00:59 +00:00
|
|
|
|
|
|
|
return this.htmlUtils.htmlToTextWithTags( $thumbCaption.html() || '' );
|
2014-04-25 23:16:48 +00:00
|
|
|
};
|
|
|
|
|
2014-02-17 15:09:23 +00:00
|
|
|
/**
|
2014-10-19 19:02:49 +00:00
|
|
|
* Opens MediaViewer and loads the given thumbnail. Requires processThumb() to be called first.
|
2016-07-18 13:49:27 +00:00
|
|
|
*
|
2014-04-29 01:35:07 +00:00
|
|
|
* @param {HTMLElement} element Clicked element
|
2018-04-24 14:28:02 +00:00
|
|
|
* @param {mw.Title} title File title
|
2016-12-14 13:09:10 +00:00
|
|
|
* @return {jQuery.Promise}
|
2014-02-17 15:09:23 +00:00
|
|
|
*/
|
2014-10-19 19:02:49 +00:00
|
|
|
MMVB.openImage = function ( element, title ) {
|
2014-02-17 15:09:23 +00:00
|
|
|
var $element = $( element );
|
|
|
|
|
2014-05-05 07:52:34 +00:00
|
|
|
mw.mmv.durationLogger.start( [ 'click-to-first-image', 'click-to-first-metadata' ] );
|
2014-04-28 16:11:55 +00:00
|
|
|
|
2016-07-09 16:49:35 +00:00
|
|
|
if ( $element.is( 'a.image, [typeof*="mw:Image"] > a' ) ) {
|
2014-05-19 09:24:54 +00:00
|
|
|
mw.mmv.actionLogger.log( 'thumbnail' );
|
2014-02-17 15:09:23 +00:00
|
|
|
} else if ( $element.is( '.magnify a' ) ) {
|
2014-05-19 09:24:54 +00:00
|
|
|
mw.mmv.actionLogger.log( 'enlarge' );
|
2014-02-17 15:09:23 +00:00
|
|
|
}
|
|
|
|
|
2014-09-12 17:13:42 +00:00
|
|
|
this.ensureEventHandlersAreSetUp();
|
|
|
|
|
2015-12-03 21:35:30 +00:00
|
|
|
return this.loadViewer( true ).then( function ( viewer ) {
|
2019-05-16 13:19:44 +00:00
|
|
|
viewer.loadImageByTitle( title, false );
|
2014-02-17 15:09:23 +00:00
|
|
|
} );
|
2014-10-19 19:02:49 +00:00
|
|
|
};
|
2014-02-17 15:09:23 +00:00
|
|
|
|
2014-10-19 19:02:49 +00:00
|
|
|
/**
|
|
|
|
* Handles a click event on a link
|
2016-07-18 13:49:27 +00:00
|
|
|
*
|
2014-10-19 19:02:49 +00:00
|
|
|
* @param {HTMLElement} element Clicked element
|
|
|
|
* @param {jQuery.Event} e jQuery event object
|
2018-04-24 14:28:02 +00:00
|
|
|
* @param {mw.Title} title File title
|
2016-07-18 13:49:27 +00:00
|
|
|
* @return {boolean} a value suitable for an event handler (ie. true if the click should be handled
|
2014-10-19 19:02:49 +00:00
|
|
|
* by the browser).
|
|
|
|
*/
|
|
|
|
MMVB.click = function ( element, e, title ) {
|
|
|
|
// Do not interfere with non-left clicks or if modifier keys are pressed.
|
|
|
|
if ( ( e.button !== 0 && e.which !== 1 ) || e.altKey || e.ctrlKey || e.shiftKey || e.metaKey ) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Don't load if someone has specifically stopped us from doing so
|
|
|
|
if ( !this.config.isMediaViewerEnabledOnClick() ) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Don't load if we already tried loading and it failed
|
|
|
|
if ( this.viewerIsBroken ) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.openImage( element, title );
|
|
|
|
|
|
|
|
// calling this late so that in case of errors users at least get to the file page
|
2014-02-17 15:09:23 +00:00
|
|
|
e.preventDefault();
|
|
|
|
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
|
2015-12-03 21:35:30 +00:00
|
|
|
/**
|
|
|
|
* Returns true if the hash part of the current URL is one that's owned by MMV.
|
2016-07-18 13:49:27 +00:00
|
|
|
*
|
|
|
|
* @return {boolean}
|
2015-12-03 21:35:30 +00:00
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
MMVB.isViewerHash = function () {
|
2019-05-16 13:19:44 +00:00
|
|
|
var path = OO.Router.prototype.getPath();
|
|
|
|
return path.match( mw.mmv.ROUTE_REGEXP ) || path.match( mw.mmv.LEGACY_ROUTE_REGEXP );
|
2015-12-03 21:35:30 +00:00
|
|
|
};
|
2014-10-19 19:02:49 +00:00
|
|
|
|
2014-02-17 15:09:23 +00:00
|
|
|
/**
|
2014-02-24 09:29:14 +00:00
|
|
|
* Handles the browser location hash on pageload or hash change
|
2016-07-18 13:49:27 +00:00
|
|
|
*
|
|
|
|
* @param {boolean} initialHash Whether this is called for the hash that came with the pageload
|
2014-02-17 15:09:23 +00:00
|
|
|
*/
|
2014-04-15 16:14:06 +00:00
|
|
|
MMVB.hash = function ( initialHash ) {
|
2014-04-09 00:22:18 +00:00
|
|
|
var bootstrap = this;
|
|
|
|
|
2014-02-21 11:16:30 +00:00
|
|
|
// There is no point loading the mmv if it isn't loaded yet for hash changes unrelated to the mmv
|
|
|
|
// Such as anchor links on the page
|
2015-12-03 21:35:30 +00:00
|
|
|
if ( !this.viewerInitialized && !this.isViewerHash() ) {
|
2014-02-21 11:16:30 +00:00
|
|
|
return;
|
2014-02-17 15:09:23 +00:00
|
|
|
}
|
2014-02-21 11:16:30 +00:00
|
|
|
|
2015-12-03 21:35:30 +00:00
|
|
|
this.loadViewer( this.isViewerHash() ).then( function ( viewer ) {
|
2019-05-16 13:19:44 +00:00
|
|
|
viewer.router.checkRoute();
|
2014-04-09 00:22:18 +00:00
|
|
|
// this is an ugly temporary fix to avoid a black screen of death when
|
|
|
|
// the page is loaded with an invalid MMV url
|
|
|
|
if ( !viewer.isOpen ) {
|
|
|
|
bootstrap.cleanupOverlay();
|
2014-04-15 16:14:06 +00:00
|
|
|
} else if ( initialHash ) {
|
2014-05-19 09:24:54 +00:00
|
|
|
mw.mmv.actionLogger.log( 'hash-load' );
|
2014-04-15 16:14:06 +00:00
|
|
|
} else {
|
2014-05-19 09:24:54 +00:00
|
|
|
mw.mmv.actionLogger.log( 'history-navigation' );
|
2014-04-09 00:22:18 +00:00
|
|
|
}
|
2014-02-21 11:16:30 +00:00
|
|
|
} );
|
2014-02-17 15:09:23 +00:00
|
|
|
};
|
|
|
|
|
2014-03-04 11:53:53 +00:00
|
|
|
/**
|
|
|
|
* Instantiates a new viewer if necessary
|
2016-07-18 13:49:27 +00:00
|
|
|
*
|
|
|
|
* @return {mw.mmv.MultimediaViewer}
|
2014-03-04 11:53:53 +00:00
|
|
|
*/
|
|
|
|
MMVB.getViewer = function () {
|
|
|
|
if ( this.viewer === undefined ) {
|
2016-04-03 09:18:26 +00:00
|
|
|
this.viewer = new mw.mmv.MultimediaViewer( this.config );
|
2014-03-04 11:53:53 +00:00
|
|
|
this.viewer.setupEventHandlers();
|
2014-12-30 07:13:22 +00:00
|
|
|
mw.mmv.viewer = this.viewer;
|
2014-03-04 11:53:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return this.viewer;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Listens to events on the window/document
|
|
|
|
*/
|
|
|
|
MMVB.setupEventHandlers = function () {
|
|
|
|
var self = this;
|
2014-02-17 15:09:23 +00:00
|
|
|
|
2014-09-12 17:13:42 +00:00
|
|
|
/** @property {boolean} eventHandlersHaveBeenSetUp tracks domready event handler state */
|
|
|
|
this.eventHandlersHaveBeenSetUp = true;
|
|
|
|
|
2014-04-11 09:31:38 +00:00
|
|
|
// Interpret any hash that might already be in the url
|
2014-04-15 16:14:06 +00:00
|
|
|
self.hash( true );
|
2014-03-04 11:53:53 +00:00
|
|
|
|
2019-05-16 13:19:44 +00:00
|
|
|
$( document ).on( 'mmv-setup-overlay', function () {
|
|
|
|
self.setupOverlay();
|
2014-04-11 09:31:38 +00:00
|
|
|
} ).on( 'mmv-cleanup-overlay', function () {
|
2014-03-28 08:06:53 +00:00
|
|
|
self.cleanupOverlay();
|
2014-03-04 11:53:53 +00:00
|
|
|
} );
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Cleans up event handlers, used for tests
|
|
|
|
*/
|
|
|
|
MMVB.cleanupEventHandlers = function () {
|
2019-05-16 13:19:44 +00:00
|
|
|
$( document ).off( 'mmv-setup-overlay mmv-cleanup-overlay' );
|
2014-09-12 17:13:42 +00:00
|
|
|
this.eventHandlersHaveBeenSetUp = false;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Makes sure event handlers are set up properly via MultimediaViewerBootstrap.setupEventHandlers().
|
|
|
|
* Called before loading the main mmv module. At this point, event handers for MultimediaViewerBootstrap
|
|
|
|
* should have been set up, but due to bug 70756 it cannot be guaranteed.
|
|
|
|
*/
|
|
|
|
MMVB.ensureEventHandlersAreSetUp = function () {
|
|
|
|
if ( !this.eventHandlersHaveBeenSetUp ) {
|
|
|
|
this.setupEventHandlers();
|
|
|
|
}
|
2014-03-04 11:53:53 +00:00
|
|
|
};
|
|
|
|
|
2014-03-28 08:06:53 +00:00
|
|
|
/**
|
|
|
|
* Sets up the overlay while the viewer loads
|
|
|
|
*/
|
|
|
|
MMVB.setupOverlay = function () {
|
2017-09-13 18:04:22 +00:00
|
|
|
var $body = $( document.body );
|
2014-04-11 09:31:38 +00:00
|
|
|
|
|
|
|
// There are situations where we can call setupOverlay while the overlay is already there,
|
|
|
|
// such as inside this.hash(). In that case, do nothing
|
|
|
|
if ( $body.hasClass( 'mw-mmv-lightbox-open' ) ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-04-09 00:22:18 +00:00
|
|
|
if ( !this.$overlay ) {
|
|
|
|
this.$overlay = $( '<div>' )
|
|
|
|
.addClass( 'mw-mmv-overlay' );
|
|
|
|
}
|
2014-03-28 08:06:53 +00:00
|
|
|
|
2017-09-13 18:04:22 +00:00
|
|
|
this.savedScrollTop = $( window ).scrollTop();
|
2014-04-11 09:31:38 +00:00
|
|
|
|
|
|
|
$body.addClass( 'mw-mmv-lightbox-open' )
|
2014-03-28 08:06:53 +00:00
|
|
|
.append( this.$overlay );
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Cleans up the overlay
|
|
|
|
*/
|
|
|
|
MMVB.cleanupOverlay = function () {
|
2014-04-23 00:26:07 +00:00
|
|
|
var bootstrap = this;
|
|
|
|
|
2014-03-31 21:33:12 +00:00
|
|
|
$( document.body ).removeClass( 'mw-mmv-lightbox-open' );
|
2014-03-28 08:06:53 +00:00
|
|
|
|
|
|
|
if ( this.$overlay ) {
|
|
|
|
this.$overlay.remove();
|
|
|
|
}
|
2014-04-11 09:31:38 +00:00
|
|
|
|
2017-09-13 18:04:22 +00:00
|
|
|
if ( this.savedScrollTop !== undefined ) {
|
2014-04-23 00:26:07 +00:00
|
|
|
// setTimeout because otherwise Chrome will scroll back to top after the popstate event handlers run
|
2016-07-18 13:49:27 +00:00
|
|
|
setTimeout( function () {
|
2017-09-13 18:04:22 +00:00
|
|
|
$( window ).scrollTop( bootstrap.savedScrollTop );
|
|
|
|
bootstrap.savedScrollTop = undefined;
|
|
|
|
} );
|
2014-04-11 09:31:38 +00:00
|
|
|
}
|
2014-03-28 08:06:53 +00:00
|
|
|
};
|
|
|
|
|
2014-03-28 22:39:36 +00:00
|
|
|
MMVB.whenThumbsReady = function () {
|
|
|
|
return this.thumbsReadyDeferred.promise();
|
|
|
|
};
|
|
|
|
|
2014-03-04 11:53:53 +00:00
|
|
|
mw.mmv.MultimediaViewerBootstrap = MultimediaViewerBootstrap;
|
2018-11-12 16:33:24 +00:00
|
|
|
}() );
|