2013-08-07 08:59:08 +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-02-17 15:09:23 +00:00
|
|
|
var MMVP,
|
2014-02-24 09:29:14 +00:00
|
|
|
comingFromHashChange = false;
|
2013-08-07 08:59:08 +00:00
|
|
|
|
2013-11-27 21:57:45 +00:00
|
|
|
/**
|
2014-01-11 00:11:37 +00:00
|
|
|
* Analyses the page, looks for image content and sets up the hooks
|
2013-11-27 21:57:45 +00:00
|
|
|
* to manage the viewing experience of such content.
|
2016-07-18 13:49:27 +00:00
|
|
|
*
|
2014-02-25 02:28:49 +00:00
|
|
|
* @class mw.mmv.MultimediaViewer
|
2013-11-27 21:57:45 +00:00
|
|
|
* @constructor
|
2016-04-03 09:18:26 +00:00
|
|
|
* @param {mw.mmv.Config} config mw.mmv.Config object
|
2013-11-27 21:57:45 +00:00
|
|
|
*/
|
2016-04-03 09:18:26 +00:00
|
|
|
function MultimediaViewer( config ) {
|
2016-07-18 13:49:27 +00:00
|
|
|
var apiCacheMaxAge = 86400, // one day (24 hours * 60 min * 60 sec)
|
|
|
|
apiCacheFiveMinutes = 300; // 5 min * 60 sec
|
2014-04-19 01:59:17 +00:00
|
|
|
|
2014-11-20 23:39:29 +00:00
|
|
|
/**
|
2016-04-03 09:18:26 +00:00
|
|
|
* @property {mw.mmv.Config}
|
2014-11-20 23:39:29 +00:00
|
|
|
* @private
|
|
|
|
*/
|
2016-04-03 09:18:26 +00:00
|
|
|
this.config = config;
|
2014-11-20 23:39:29 +00:00
|
|
|
|
2013-11-27 21:57:45 +00:00
|
|
|
/**
|
2014-02-13 09:52:40 +00:00
|
|
|
* @property {mw.mmv.provider.Image}
|
2013-11-27 21:57:45 +00:00
|
|
|
* @private
|
|
|
|
*/
|
2016-04-03 09:18:26 +00:00
|
|
|
this.imageProvider = new mw.mmv.provider.Image( this.config.imageQueryParameter() );
|
2013-11-27 21:57:45 +00:00
|
|
|
|
2014-02-03 20:42:17 +00:00
|
|
|
/**
|
|
|
|
* @property {mw.mmv.provider.ImageInfo}
|
|
|
|
* @private
|
|
|
|
*/
|
2016-01-06 04:05:59 +00:00
|
|
|
this.imageInfoProvider = new mw.mmv.provider.ImageInfo( new mw.mmv.logging.Api( 'imageinfo' ), {
|
2016-04-03 09:18:26 +00:00
|
|
|
language: this.config.language(),
|
2016-01-06 04:05:59 +00:00
|
|
|
maxage: apiCacheFiveMinutes
|
2016-07-18 13:49:27 +00:00
|
|
|
} );
|
2014-02-03 20:42:17 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @property {mw.mmv.provider.FileRepoInfo}
|
|
|
|
* @private
|
|
|
|
*/
|
2014-09-04 23:00:55 +00:00
|
|
|
this.fileRepoInfoProvider = new mw.mmv.provider.FileRepoInfo( new mw.mmv.logging.Api( 'filerepoinfo' ),
|
2014-04-19 01:59:17 +00:00
|
|
|
{ maxage: apiCacheMaxAge } );
|
2014-02-03 20:42:17 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @property {mw.mmv.provider.ThumbnailInfo}
|
|
|
|
* @private
|
|
|
|
*/
|
2014-09-04 23:00:55 +00:00
|
|
|
this.thumbnailInfoProvider = new mw.mmv.provider.ThumbnailInfo( new mw.mmv.logging.Api( 'thumbnailinfo' ),
|
2014-04-19 01:59:17 +00:00
|
|
|
{ maxage: apiCacheMaxAge } );
|
2014-02-03 20:42:17 +00:00
|
|
|
|
2014-04-10 01:08:36 +00:00
|
|
|
/**
|
|
|
|
* @property {mw.mmv.provider.ThumbnailInfo}
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
this.guessedThumbnailInfoProvider = new mw.mmv.provider.GuessedThumbnailInfo();
|
|
|
|
|
2014-03-05 02:24:18 +00:00
|
|
|
/**
|
|
|
|
* Image index on page.
|
2014-04-14 23:22:28 +00:00
|
|
|
* @property {number}
|
2014-03-05 02:24:18 +00:00
|
|
|
*/
|
|
|
|
this.currentIndex = 0;
|
|
|
|
|
2014-04-14 23:22:28 +00:00
|
|
|
/**
|
|
|
|
* @property {mw.mmv.routing.Router} router -
|
|
|
|
*/
|
|
|
|
this.router = new mw.mmv.routing.Router();
|
|
|
|
|
2014-03-05 02:24:18 +00:00
|
|
|
/**
|
|
|
|
* UI object used to display the pictures in the page.
|
|
|
|
* @property {mw.mmv.LightboxInterface}
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
this.ui = new mw.mmv.LightboxInterface();
|
2014-04-28 16:11:55 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* How many sharp images have been displayed in Media Viewer since the pageload
|
|
|
|
* @property {number}
|
|
|
|
*/
|
|
|
|
this.imageDisplayedCount = 0;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* How many data-filled metadata panels have been displayed in Media Viewer since the pageload
|
|
|
|
* @property {number}
|
|
|
|
*/
|
|
|
|
this.metadataDisplayedCount = 0;
|
2014-07-01 22:22:06 +00:00
|
|
|
|
|
|
|
/** @property {string} documentTitle base document title, MediaViewer will expand this */
|
|
|
|
this.documentTitle = document.title;
|
2014-11-15 15:32:04 +00:00
|
|
|
|
|
|
|
/**
|
2014-11-20 23:39:29 +00:00
|
|
|
* @property {mw.mmv.logging.ViewLogger} view -
|
2014-11-15 15:32:04 +00:00
|
|
|
*/
|
2016-04-03 09:18:26 +00:00
|
|
|
this.viewLogger = new mw.mmv.logging.ViewLogger( this.config, window, mw.mmv.actionLogger );
|
2018-06-06 18:23:25 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Stores whether the real image was loaded and displayed already.
|
|
|
|
* This is reset when paging, so it is not necessarily accurate.
|
|
|
|
* @property {boolean}
|
|
|
|
*/
|
|
|
|
this.realThumbnailShown = false;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Stores whether the a blurred placeholder is being displayed in place of the real image.
|
|
|
|
* When a placeholder is displayed, but it is not blurred, this is false.
|
|
|
|
* This is reset when paging, so it is not necessarily accurate.
|
|
|
|
* @property {boolean}
|
|
|
|
*/
|
|
|
|
this.blurredThumbnailShown = false;
|
2014-02-17 15:09:23 +00:00
|
|
|
}
|
2013-08-07 08:59:08 +00:00
|
|
|
|
2014-02-17 15:09:23 +00:00
|
|
|
MMVP = MultimediaViewer.prototype;
|
2013-08-07 08:59:08 +00:00
|
|
|
|
2014-02-19 02:27:30 +00:00
|
|
|
/**
|
|
|
|
* Initialize the lightbox interface given an array of thumbnail
|
|
|
|
* objects.
|
2016-07-18 13:49:27 +00:00
|
|
|
*
|
2014-02-19 02:27:30 +00:00
|
|
|
* @param {Object[]} thumbs Complex structure...TODO, document this better.
|
|
|
|
*/
|
2014-02-17 15:09:23 +00:00
|
|
|
MMVP.initWithThumbs = function ( thumbs ) {
|
|
|
|
var i, thumb;
|
2013-08-07 08:59:08 +00:00
|
|
|
|
2014-02-17 15:09:23 +00:00
|
|
|
this.thumbs = thumbs;
|
2013-10-29 20:26:07 +00:00
|
|
|
|
2014-02-17 15:09:23 +00:00
|
|
|
for ( i = 0; i < this.thumbs.length; i++ ) {
|
|
|
|
thumb = this.thumbs[ i ];
|
|
|
|
// Create a LightboxImage object for each legit image
|
2014-03-04 11:53:53 +00:00
|
|
|
thumb.image = this.createNewImage(
|
|
|
|
thumb.$thumb.prop( 'src' ),
|
2014-02-17 15:09:23 +00:00
|
|
|
thumb.link,
|
|
|
|
thumb.title,
|
|
|
|
i,
|
|
|
|
thumb.thumb,
|
2014-12-30 05:10:27 +00:00
|
|
|
thumb.caption,
|
|
|
|
thumb.alt
|
2014-03-04 11:53:53 +00:00
|
|
|
);
|
2014-12-02 10:05:12 +00:00
|
|
|
|
|
|
|
thumb.extraStatsDeferred = $.Deferred();
|
2014-02-17 15:09:23 +00:00
|
|
|
}
|
|
|
|
};
|
2013-12-10 19:54:07 +00:00
|
|
|
|
2013-12-02 19:46:52 +00:00
|
|
|
/**
|
|
|
|
* Create an image object for the lightbox to use.
|
2016-07-18 13:49:27 +00:00
|
|
|
*
|
2013-12-02 19:46:52 +00:00
|
|
|
* @protected
|
|
|
|
* @param {string} fileLink Link to the file - generally a thumb URL
|
|
|
|
* @param {string} filePageLink Link to the File: page
|
|
|
|
* @param {mw.Title} fileTitle Represents the File: page
|
|
|
|
* @param {number} index Which number file this is
|
2013-11-13 21:16:49 +00:00
|
|
|
* @param {HTMLImageElement} thumb The thumbnail that represents this image on the page
|
2013-12-10 19:54:07 +00:00
|
|
|
* @param {string} [caption] The caption, if any.
|
2014-12-30 05:10:27 +00:00
|
|
|
* @param {string} [alt] The alt text of the image
|
2016-07-18 13:49:27 +00:00
|
|
|
* @return {mw.mmv.LightboxImage}
|
2013-12-02 19:46:52 +00:00
|
|
|
*/
|
2014-12-30 05:10:27 +00:00
|
|
|
MMVP.createNewImage = function ( fileLink, filePageLink, fileTitle, index, thumb, caption, alt ) {
|
|
|
|
var thisImage = new mw.mmv.LightboxImage( fileLink, filePageLink, fileTitle, index, thumb, caption, alt ),
|
2014-04-09 23:59:49 +00:00
|
|
|
$thumb = $( thumb );
|
|
|
|
|
2013-12-02 19:46:52 +00:00
|
|
|
thisImage.filePageLink = filePageLink;
|
|
|
|
thisImage.filePageTitle = fileTitle;
|
|
|
|
thisImage.index = index;
|
2013-11-13 21:16:49 +00:00
|
|
|
thisImage.thumbnail = thumb;
|
2014-04-09 23:59:49 +00:00
|
|
|
thisImage.originalWidth = parseInt( $thumb.data( 'file-width' ), 10 );
|
|
|
|
thisImage.originalHeight = parseInt( $thumb.data( 'file-height' ), 10 );
|
2013-12-02 19:46:52 +00:00
|
|
|
|
|
|
|
return thisImage;
|
|
|
|
};
|
|
|
|
|
2013-12-03 01:58:09 +00:00
|
|
|
/**
|
|
|
|
* Handles resize events in viewer.
|
2016-07-18 13:49:27 +00:00
|
|
|
*
|
2013-12-03 01:58:09 +00:00
|
|
|
* @protected
|
2014-02-25 02:28:49 +00:00
|
|
|
* @param {mw.mmv.LightboxInterface} ui lightbox that got resized
|
2013-12-03 01:58:09 +00:00
|
|
|
*/
|
2013-11-26 03:37:01 +00:00
|
|
|
MMVP.resize = function ( ui ) {
|
2014-09-26 18:37:53 +00:00
|
|
|
var imageWidths, canvasDimensions,
|
|
|
|
viewer = this,
|
2017-01-22 00:50:05 +00:00
|
|
|
image = this.thumbs[ this.currentIndex ].image,
|
2017-01-24 23:20:09 +00:00
|
|
|
ext = this.thumbs[ this.currentIndex ].title.ext.toLowerCase();
|
2013-11-13 21:16:49 +00:00
|
|
|
|
2014-02-13 09:52:40 +00:00
|
|
|
this.preloadThumbnails();
|
|
|
|
|
2014-04-09 23:59:49 +00:00
|
|
|
if ( image ) {
|
2014-02-26 20:09:37 +00:00
|
|
|
imageWidths = ui.canvas.getCurrentImageWidths();
|
2014-09-26 18:37:53 +00:00
|
|
|
canvasDimensions = ui.canvas.getDimensions();
|
|
|
|
|
|
|
|
mw.mmv.dimensionLogger.logDimensions( imageWidths, canvasDimensions, 'resize' );
|
|
|
|
|
2014-04-09 23:59:49 +00:00
|
|
|
this.fetchThumbnailForLightboxImage(
|
|
|
|
image, imageWidths.real
|
2015-01-23 12:48:27 +00:00
|
|
|
).then( function ( thumbnail, image ) {
|
2017-01-22 00:50:05 +00:00
|
|
|
image.className = ext;
|
2014-02-13 09:52:40 +00:00
|
|
|
viewer.setImage( ui, thumbnail, image, imageWidths );
|
2014-03-01 01:10:51 +00:00
|
|
|
}, function ( error ) {
|
|
|
|
viewer.ui.canvas.showError( error );
|
2014-01-30 07:22:26 +00:00
|
|
|
} );
|
|
|
|
}
|
2014-01-06 21:53:42 +00:00
|
|
|
|
|
|
|
this.updateControls();
|
2013-12-03 01:58:09 +00:00
|
|
|
};
|
|
|
|
|
2014-02-19 02:27:30 +00:00
|
|
|
/**
|
|
|
|
* Updates positioning of controls, usually after a resize event.
|
|
|
|
*/
|
2013-11-13 00:43:46 +00:00
|
|
|
MMVP.updateControls = function () {
|
2014-02-17 15:09:23 +00:00
|
|
|
var numImages = this.thumbs ? this.thumbs.length : 0,
|
2015-01-23 12:48:27 +00:00
|
|
|
showNextButton = this.currentIndex < ( numImages - 1 ),
|
2014-03-05 02:24:18 +00:00
|
|
|
showPreviousButton = this.currentIndex > 0;
|
2013-11-13 00:43:46 +00:00
|
|
|
|
2014-02-03 11:23:31 +00:00
|
|
|
this.ui.updateControls( showNextButton, showPreviousButton );
|
2013-11-13 00:43:46 +00:00
|
|
|
};
|
2013-11-06 00:36:06 +00:00
|
|
|
|
2014-01-28 23:57:05 +00:00
|
|
|
/**
|
2014-02-13 09:52:40 +00:00
|
|
|
* Loads and sets the specified image. It also updates the controls.
|
2016-07-18 13:49:27 +00:00
|
|
|
*
|
2014-02-25 02:28:49 +00:00
|
|
|
* @param {mw.mmv.LightboxInterface} ui image container
|
2014-02-13 09:52:40 +00:00
|
|
|
* @param {mw.mmv.model.Thumbnail} thumbnail thumbnail information
|
Refactor progressbar & blur handling
This tries to fix a number of related issues:
* the blurred thumbnail was visible for a split-second sometimes
when switching back to an already-loaded image. (Presumably when
JS was sluggish enough to take more than 10 ms to execute.) We
now check whether the promise is pending before showing a placeholder.
(More generally, a lot of unnecessary logic was executed when paging
through already loaded images, like displaying the placeholder, so
this might make the UI a bit more responsive.)
* the blur could get stuck sometimes - I have seen this a few times,
but have never been able to reproduce it, so I'm only guessing, but
maybe the timing was really unfortunate, and we switched back less
than 10 ms before loading finished. We now remove the blur on every
branch, just to be sure.
* adding a progress handler to a promise might not have any immediate
effect, so when switching to an image which was loading, the progress
bar reacted too late. We now store the progress state per thumbnail
so it is always available immediately.
* the progress would animate from 0 to its actual state whenever we
navigated to the image. The change on paging is now instant; the
progress bar only animates when we are looking at it.
* switching quickly back and forthe between a loaded and a loading
image resulted in the loading image becoming unblurred. This seems
fixed now, I'm not sure why. Maybe the "skip on non-pending promise"
logic affects it somehow.
Also removes some unused things / renames some things which were
confusing, and makes an unrelated fix in the image provider, which kept
amassing fail handlers.
Change-Id: I580becff246f197ec1bc65e82acd422620e35578
Mingle: https://wikimedia.mingle.thoughtworks.com/projects/multimedia/cards/489
2014-04-25 22:26:34 +00:00
|
|
|
* @param {HTMLImageElement} imageElement
|
2014-02-06 23:18:47 +00:00
|
|
|
* @param {mw.mmv.model.ThumbnailWidth} imageWidths
|
2014-01-28 23:57:05 +00:00
|
|
|
*/
|
Refactor progressbar & blur handling
This tries to fix a number of related issues:
* the blurred thumbnail was visible for a split-second sometimes
when switching back to an already-loaded image. (Presumably when
JS was sluggish enough to take more than 10 ms to execute.) We
now check whether the promise is pending before showing a placeholder.
(More generally, a lot of unnecessary logic was executed when paging
through already loaded images, like displaying the placeholder, so
this might make the UI a bit more responsive.)
* the blur could get stuck sometimes - I have seen this a few times,
but have never been able to reproduce it, so I'm only guessing, but
maybe the timing was really unfortunate, and we switched back less
than 10 ms before loading finished. We now remove the blur on every
branch, just to be sure.
* adding a progress handler to a promise might not have any immediate
effect, so when switching to an image which was loading, the progress
bar reacted too late. We now store the progress state per thumbnail
so it is always available immediately.
* the progress would animate from 0 to its actual state whenever we
navigated to the image. The change on paging is now instant; the
progress bar only animates when we are looking at it.
* switching quickly back and forthe between a loaded and a loading
image resulted in the loading image becoming unblurred. This seems
fixed now, I'm not sure why. Maybe the "skip on non-pending promise"
logic affects it somehow.
Also removes some unused things / renames some things which were
confusing, and makes an unrelated fix in the image provider, which kept
amassing fail handlers.
Change-Id: I580becff246f197ec1bc65e82acd422620e35578
Mingle: https://wikimedia.mingle.thoughtworks.com/projects/multimedia/cards/489
2014-04-25 22:26:34 +00:00
|
|
|
MMVP.setImage = function ( ui, thumbnail, imageElement, imageWidths ) {
|
|
|
|
ui.canvas.setImageAndMaxDimensions( thumbnail, imageElement, imageWidths );
|
2014-02-13 09:52:40 +00:00
|
|
|
this.updateControls();
|
2014-01-28 23:57:05 +00:00
|
|
|
};
|
|
|
|
|
2013-12-10 19:54:07 +00:00
|
|
|
/**
|
|
|
|
* Loads a specified image.
|
2016-07-18 13:49:27 +00:00
|
|
|
*
|
2014-02-25 02:28:49 +00:00
|
|
|
* @param {mw.mmv.LightboxImage} image
|
2014-02-13 09:52:40 +00:00
|
|
|
* @param {HTMLImageElement} initialImage A thumbnail to use as placeholder while the image loads
|
2013-12-10 19:54:07 +00:00
|
|
|
*/
|
2014-02-13 09:52:40 +00:00
|
|
|
MMVP.loadImage = function ( image, initialImage ) {
|
2014-02-06 23:18:47 +00:00
|
|
|
var imageWidths,
|
2014-09-26 18:37:53 +00:00
|
|
|
canvasDimensions,
|
2014-02-13 09:52:40 +00:00
|
|
|
imagePromise,
|
2014-02-25 13:43:22 +00:00
|
|
|
metadataPromise,
|
2016-04-03 09:18:26 +00:00
|
|
|
pluginsPromise,
|
2014-02-25 13:43:22 +00:00
|
|
|
start,
|
2014-03-28 10:06:17 +00:00
|
|
|
viewer = this,
|
2014-12-02 10:05:12 +00:00
|
|
|
$initialImage = $( initialImage ),
|
|
|
|
extraStatsDeferred = $.Deferred();
|
2014-02-13 09:52:40 +00:00
|
|
|
|
2017-01-24 23:20:09 +00:00
|
|
|
pluginsPromise = this.loadExtensionPlugins( image.filePageTitle.ext.toLowerCase() );
|
2016-04-03 09:18:26 +00:00
|
|
|
|
2014-03-05 02:24:18 +00:00
|
|
|
this.currentIndex = image.index;
|
2013-11-25 23:51:40 +00:00
|
|
|
|
2014-01-06 20:02:39 +00:00
|
|
|
this.currentImageFileTitle = image.filePageTitle;
|
2014-01-06 21:53:42 +00:00
|
|
|
|
|
|
|
if ( !this.isOpen ) {
|
2014-03-05 02:24:18 +00:00
|
|
|
this.ui.open();
|
2014-01-06 21:53:42 +00:00
|
|
|
this.isOpen = true;
|
|
|
|
} else {
|
2014-03-05 02:24:18 +00:00
|
|
|
this.ui.empty();
|
2014-01-06 21:53:42 +00:00
|
|
|
}
|
2014-03-04 12:52:08 +00:00
|
|
|
this.setHash();
|
2014-02-25 13:43:22 +00:00
|
|
|
|
|
|
|
// At this point we can't show the thumbnail because we don't
|
|
|
|
// know what size it should be. We still assign it to allow for
|
|
|
|
// size calculations in getCurrentImageWidths, which needs to know
|
|
|
|
// the aspect ratio
|
2019-05-18 16:52:00 +00:00
|
|
|
$initialImage.hide()
|
|
|
|
.removeAttr( 'style' )
|
|
|
|
.removeClass()
|
|
|
|
.addClass( 'mw-mmv-placeholder-image ' + image.filePageTitle.ext.toLowerCase() );
|
2016-04-03 09:18:26 +00:00
|
|
|
|
2014-03-05 02:24:18 +00:00
|
|
|
this.ui.canvas.set( image, $initialImage );
|
2014-02-13 09:52:40 +00:00
|
|
|
|
|
|
|
this.preloadImagesMetadata();
|
|
|
|
this.preloadThumbnails();
|
2014-04-19 15:53:28 +00:00
|
|
|
// this.preloadFullscreenThumbnail( image ); // disabled - #474
|
2014-01-06 21:53:42 +00:00
|
|
|
|
2014-02-26 20:09:37 +00:00
|
|
|
imageWidths = this.ui.canvas.getCurrentImageWidths();
|
2014-09-26 18:37:53 +00:00
|
|
|
canvasDimensions = this.ui.canvas.getDimensions();
|
2014-02-25 13:43:22 +00:00
|
|
|
|
2019-02-05 23:59:52 +00:00
|
|
|
start = ( new Date() ).getTime();
|
2014-02-25 13:43:22 +00:00
|
|
|
|
2014-09-26 18:37:53 +00:00
|
|
|
mw.mmv.dimensionLogger.logDimensions( imageWidths, canvasDimensions, 'show' );
|
2014-12-02 10:05:12 +00:00
|
|
|
|
|
|
|
imagePromise = this.fetchThumbnailForLightboxImage( image, imageWidths.real, extraStatsDeferred );
|
2014-02-27 00:40:39 +00:00
|
|
|
|
Refactor progressbar & blur handling
This tries to fix a number of related issues:
* the blurred thumbnail was visible for a split-second sometimes
when switching back to an already-loaded image. (Presumably when
JS was sluggish enough to take more than 10 ms to execute.) We
now check whether the promise is pending before showing a placeholder.
(More generally, a lot of unnecessary logic was executed when paging
through already loaded images, like displaying the placeholder, so
this might make the UI a bit more responsive.)
* the blur could get stuck sometimes - I have seen this a few times,
but have never been able to reproduce it, so I'm only guessing, but
maybe the timing was really unfortunate, and we switched back less
than 10 ms before loading finished. We now remove the blur on every
branch, just to be sure.
* adding a progress handler to a promise might not have any immediate
effect, so when switching to an image which was loading, the progress
bar reacted too late. We now store the progress state per thumbnail
so it is always available immediately.
* the progress would animate from 0 to its actual state whenever we
navigated to the image. The change on paging is now instant; the
progress bar only animates when we are looking at it.
* switching quickly back and forthe between a loaded and a loading
image resulted in the loading image becoming unblurred. This seems
fixed now, I'm not sure why. Maybe the "skip on non-pending promise"
logic affects it somehow.
Also removes some unused things / renames some things which were
confusing, and makes an unrelated fix in the image provider, which kept
amassing fail handlers.
Change-Id: I580becff246f197ec1bc65e82acd422620e35578
Mingle: https://wikimedia.mingle.thoughtworks.com/projects/multimedia/cards/489
2014-04-25 22:26:34 +00:00
|
|
|
this.resetBlurredThumbnailStates();
|
|
|
|
if ( imagePromise.state() === 'pending' ) {
|
|
|
|
this.displayPlaceholderThumbnail( image, $initialImage, imageWidths );
|
|
|
|
}
|
2014-02-27 00:40:39 +00:00
|
|
|
|
Refactor progressbar & blur handling
This tries to fix a number of related issues:
* the blurred thumbnail was visible for a split-second sometimes
when switching back to an already-loaded image. (Presumably when
JS was sluggish enough to take more than 10 ms to execute.) We
now check whether the promise is pending before showing a placeholder.
(More generally, a lot of unnecessary logic was executed when paging
through already loaded images, like displaying the placeholder, so
this might make the UI a bit more responsive.)
* the blur could get stuck sometimes - I have seen this a few times,
but have never been able to reproduce it, so I'm only guessing, but
maybe the timing was really unfortunate, and we switched back less
than 10 ms before loading finished. We now remove the blur on every
branch, just to be sure.
* adding a progress handler to a promise might not have any immediate
effect, so when switching to an image which was loading, the progress
bar reacted too late. We now store the progress state per thumbnail
so it is always available immediately.
* the progress would animate from 0 to its actual state whenever we
navigated to the image. The change on paging is now instant; the
progress bar only animates when we are looking at it.
* switching quickly back and forthe between a loaded and a loading
image resulted in the loading image becoming unblurred. This seems
fixed now, I'm not sure why. Maybe the "skip on non-pending promise"
logic affects it somehow.
Also removes some unused things / renames some things which were
confusing, and makes an unrelated fix in the image provider, which kept
amassing fail handlers.
Change-Id: I580becff246f197ec1bc65e82acd422620e35578
Mingle: https://wikimedia.mingle.thoughtworks.com/projects/multimedia/cards/489
2014-04-25 22:26:34 +00:00
|
|
|
this.setupProgressBar( image, imagePromise, imageWidths.real );
|
2014-04-01 07:56:18 +00:00
|
|
|
|
2014-11-05 10:40:31 +00:00
|
|
|
metadataPromise = this.fetchSizeIndependentLightboxInfo( image.filePageTitle );
|
|
|
|
|
2017-05-11 15:03:52 +00:00
|
|
|
imagePromise.then(
|
|
|
|
// done
|
|
|
|
function ( thumbnail, imageElement ) {
|
|
|
|
if ( viewer.currentIndex !== image.index ) {
|
|
|
|
return;
|
|
|
|
}
|
2014-02-27 00:40:39 +00:00
|
|
|
|
2017-05-11 15:03:52 +00:00
|
|
|
if ( viewer.imageDisplayedCount++ === 0 ) {
|
|
|
|
mw.mmv.durationLogger.stop( 'click-to-first-image' );
|
2014-11-05 10:40:31 +00:00
|
|
|
|
2017-05-11 15:03:52 +00:00
|
|
|
metadataPromise.then( function ( imageInfo, repoInfo ) {
|
|
|
|
if ( imageInfo && imageInfo.anonymizedUploadDateTime ) {
|
|
|
|
mw.mmv.durationLogger.record( 'click-to-first-image', {
|
|
|
|
uploadTimestamp: imageInfo.anonymizedUploadDateTime
|
|
|
|
} );
|
|
|
|
}
|
2014-11-05 10:40:31 +00:00
|
|
|
|
2017-05-11 15:03:52 +00:00
|
|
|
return $.Deferred().resolve( imageInfo, repoInfo );
|
2014-11-05 10:40:31 +00:00
|
|
|
} );
|
2017-05-11 15:03:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
imageElement.className = 'mw-mmv-final-image ' + image.filePageTitle.ext.toLowerCase();
|
|
|
|
imageElement.alt = image.alt;
|
|
|
|
|
|
|
|
$.when( metadataPromise, pluginsPromise ).then( function ( metadata ) {
|
|
|
|
$( document ).trigger( $.Event( 'mmv-metadata', { viewer: viewer, image: image, imageInfo: metadata[ 0 ] } ) );
|
2014-11-05 10:40:31 +00:00
|
|
|
} );
|
2014-12-30 05:10:27 +00:00
|
|
|
|
2019-02-05 23:59:52 +00:00
|
|
|
viewer.displayRealThumbnail( thumbnail, imageElement, imageWidths, ( new Date() ).getTime() - start );
|
2016-04-03 09:18:26 +00:00
|
|
|
|
2017-05-11 15:03:52 +00:00
|
|
|
return $.Deferred().resolve( thumbnail, imageElement );
|
|
|
|
},
|
|
|
|
// fail
|
|
|
|
function ( error ) {
|
|
|
|
viewer.ui.canvas.showError( error );
|
|
|
|
return $.Deferred().reject( error );
|
|
|
|
}
|
|
|
|
);
|
2016-04-03 09:18:26 +00:00
|
|
|
|
2017-05-11 15:03:52 +00:00
|
|
|
metadataPromise.then(
|
|
|
|
// done
|
|
|
|
function ( imageInfo, repoInfo ) {
|
|
|
|
extraStatsDeferred.resolve( { uploadTimestamp: imageInfo.anonymizedUploadDateTime } );
|
2014-02-25 13:43:22 +00:00
|
|
|
|
2017-05-11 15:03:52 +00:00
|
|
|
if ( viewer.currentIndex !== image.index ) {
|
|
|
|
return;
|
|
|
|
}
|
2014-12-02 10:05:12 +00:00
|
|
|
|
2017-05-11 15:03:52 +00:00
|
|
|
if ( viewer.metadataDisplayedCount++ === 0 ) {
|
|
|
|
mw.mmv.durationLogger.stop( 'click-to-first-metadata' ).record( 'click-to-first-metadata' );
|
|
|
|
}
|
2014-02-27 00:40:39 +00:00
|
|
|
|
2017-05-11 15:03:52 +00:00
|
|
|
viewer.ui.panel.setImageInfo( image, imageInfo, repoInfo );
|
2014-11-05 10:40:31 +00:00
|
|
|
|
2017-05-11 15:03:52 +00:00
|
|
|
// File reuse steals a bunch of information from the DOM, so do it last
|
|
|
|
viewer.ui.setFileReuseData( imageInfo, repoInfo, image.caption, image.alt );
|
2014-09-12 18:05:13 +00:00
|
|
|
|
2017-05-11 15:03:52 +00:00
|
|
|
return $.Deferred().resolve( imageInfo, repoInfo );
|
|
|
|
},
|
|
|
|
// fail
|
|
|
|
function ( error ) {
|
|
|
|
extraStatsDeferred.reject();
|
2014-12-02 10:05:12 +00:00
|
|
|
|
2017-05-11 15:03:52 +00:00
|
|
|
if ( viewer.currentIndex === image.index ) {
|
|
|
|
// Set title to caption or file name if caption is not available;
|
|
|
|
// see setTitle() in mmv.ui.metadataPanel for extended caption fallback
|
|
|
|
viewer.ui.panel.showError( image.caption || image.filePageTitle.getNameText(), error );
|
|
|
|
}
|
2014-03-01 01:10:51 +00:00
|
|
|
|
2017-05-11 15:03:52 +00:00
|
|
|
return $.Deferred().reject( error );
|
|
|
|
}
|
|
|
|
);
|
2014-01-28 23:57:05 +00:00
|
|
|
|
2015-01-23 12:48:27 +00:00
|
|
|
$.when( imagePromise, metadataPromise ).then( function () {
|
2014-03-05 02:24:18 +00:00
|
|
|
if ( viewer.currentIndex !== image.index ) {
|
2014-02-27 00:40:39 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-05-05 21:44:27 +00:00
|
|
|
viewer.ui.panel.scroller.animateMetadataOnce();
|
2014-04-11 14:05:58 +00:00
|
|
|
viewer.preloadDependencies();
|
2014-02-13 09:52:40 +00:00
|
|
|
} );
|
2013-11-25 23:51:40 +00:00
|
|
|
|
2014-02-24 09:29:14 +00:00
|
|
|
this.comingFromHashChange = false;
|
2014-02-17 15:09:23 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Loads an image by its title
|
2016-07-18 13:49:27 +00:00
|
|
|
*
|
2014-04-14 23:22:28 +00:00
|
|
|
* @param {mw.Title} title
|
2014-02-17 15:09:23 +00:00
|
|
|
* @param {boolean} updateHash Viewer should update the location hash when true
|
|
|
|
*/
|
|
|
|
MMVP.loadImageByTitle = function ( title, updateHash ) {
|
2018-09-13 20:09:43 +00:00
|
|
|
var i, thumb;
|
2014-02-17 15:09:23 +00:00
|
|
|
|
|
|
|
if ( !this.thumbs || !this.thumbs.length ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-02-24 09:29:14 +00:00
|
|
|
this.comingFromHashChange = !updateHash;
|
2014-02-17 15:09:23 +00:00
|
|
|
|
2018-09-13 20:09:43 +00:00
|
|
|
for ( i = 0; i < this.thumbs.length; i++ ) {
|
|
|
|
thumb = this.thumbs[ i ];
|
2014-04-14 23:22:28 +00:00
|
|
|
if ( thumb.title.getPrefixedText() === title.getPrefixedText() ) {
|
2018-09-13 20:09:43 +00:00
|
|
|
this.loadImage( thumb.image, thumb.$thumb.clone()[ 0 ], true );
|
|
|
|
return;
|
2014-02-17 15:09:23 +00:00
|
|
|
}
|
2018-09-13 20:09:43 +00:00
|
|
|
}
|
2014-02-13 09:52:40 +00:00
|
|
|
};
|
2013-12-10 21:04:45 +00:00
|
|
|
|
2014-02-25 13:43:22 +00:00
|
|
|
/**
|
Refactor progressbar & blur handling
This tries to fix a number of related issues:
* the blurred thumbnail was visible for a split-second sometimes
when switching back to an already-loaded image. (Presumably when
JS was sluggish enough to take more than 10 ms to execute.) We
now check whether the promise is pending before showing a placeholder.
(More generally, a lot of unnecessary logic was executed when paging
through already loaded images, like displaying the placeholder, so
this might make the UI a bit more responsive.)
* the blur could get stuck sometimes - I have seen this a few times,
but have never been able to reproduce it, so I'm only guessing, but
maybe the timing was really unfortunate, and we switched back less
than 10 ms before loading finished. We now remove the blur on every
branch, just to be sure.
* adding a progress handler to a promise might not have any immediate
effect, so when switching to an image which was loading, the progress
bar reacted too late. We now store the progress state per thumbnail
so it is always available immediately.
* the progress would animate from 0 to its actual state whenever we
navigated to the image. The change on paging is now instant; the
progress bar only animates when we are looking at it.
* switching quickly back and forthe between a loaded and a loading
image resulted in the loading image becoming unblurred. This seems
fixed now, I'm not sure why. Maybe the "skip on non-pending promise"
logic affects it somehow.
Also removes some unused things / renames some things which were
confusing, and makes an unrelated fix in the image provider, which kept
amassing fail handlers.
Change-Id: I580becff246f197ec1bc65e82acd422620e35578
Mingle: https://wikimedia.mingle.thoughtworks.com/projects/multimedia/cards/489
2014-04-25 22:26:34 +00:00
|
|
|
* Image loading progress. Keyed by image (database) name + '|' + thumbnail width in pixels,
|
|
|
|
* value is undefined, 'blurred' or 'real' (meaning respectively that no thumbnail is shown
|
|
|
|
* yet / the thumbnail that existed on the page is shown, enlarged and blurred / the real,
|
|
|
|
* correct-size thumbnail is shown).
|
2016-07-18 13:49:27 +00:00
|
|
|
*
|
|
|
|
* @private
|
Refactor progressbar & blur handling
This tries to fix a number of related issues:
* the blurred thumbnail was visible for a split-second sometimes
when switching back to an already-loaded image. (Presumably when
JS was sluggish enough to take more than 10 ms to execute.) We
now check whether the promise is pending before showing a placeholder.
(More generally, a lot of unnecessary logic was executed when paging
through already loaded images, like displaying the placeholder, so
this might make the UI a bit more responsive.)
* the blur could get stuck sometimes - I have seen this a few times,
but have never been able to reproduce it, so I'm only guessing, but
maybe the timing was really unfortunate, and we switched back less
than 10 ms before loading finished. We now remove the blur on every
branch, just to be sure.
* adding a progress handler to a promise might not have any immediate
effect, so when switching to an image which was loading, the progress
bar reacted too late. We now store the progress state per thumbnail
so it is always available immediately.
* the progress would animate from 0 to its actual state whenever we
navigated to the image. The change on paging is now instant; the
progress bar only animates when we are looking at it.
* switching quickly back and forthe between a loaded and a loading
image resulted in the loading image becoming unblurred. This seems
fixed now, I'm not sure why. Maybe the "skip on non-pending promise"
logic affects it somehow.
Also removes some unused things / renames some things which were
confusing, and makes an unrelated fix in the image provider, which kept
amassing fail handlers.
Change-Id: I580becff246f197ec1bc65e82acd422620e35578
Mingle: https://wikimedia.mingle.thoughtworks.com/projects/multimedia/cards/489
2014-04-25 22:26:34 +00:00
|
|
|
* @property {Object.<string, string>}
|
|
|
|
*/
|
|
|
|
MMVP.thumbnailStateCache = {};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Resets the cross-request states needed to handle the blurred thumbnail logic.
|
2014-02-25 13:43:22 +00:00
|
|
|
*/
|
|
|
|
MMVP.resetBlurredThumbnailStates = function () {
|
|
|
|
this.realThumbnailShown = false;
|
|
|
|
this.blurredThumbnailShown = false;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Display the real, full-resolution, thumbnail that was fetched with fetchThumbnail
|
2016-07-18 13:49:27 +00:00
|
|
|
*
|
2014-02-25 13:43:22 +00:00
|
|
|
* @param {mw.mmv.model.Thumbnail} thumbnail
|
Refactor progressbar & blur handling
This tries to fix a number of related issues:
* the blurred thumbnail was visible for a split-second sometimes
when switching back to an already-loaded image. (Presumably when
JS was sluggish enough to take more than 10 ms to execute.) We
now check whether the promise is pending before showing a placeholder.
(More generally, a lot of unnecessary logic was executed when paging
through already loaded images, like displaying the placeholder, so
this might make the UI a bit more responsive.)
* the blur could get stuck sometimes - I have seen this a few times,
but have never been able to reproduce it, so I'm only guessing, but
maybe the timing was really unfortunate, and we switched back less
than 10 ms before loading finished. We now remove the blur on every
branch, just to be sure.
* adding a progress handler to a promise might not have any immediate
effect, so when switching to an image which was loading, the progress
bar reacted too late. We now store the progress state per thumbnail
so it is always available immediately.
* the progress would animate from 0 to its actual state whenever we
navigated to the image. The change on paging is now instant; the
progress bar only animates when we are looking at it.
* switching quickly back and forthe between a loaded and a loading
image resulted in the loading image becoming unblurred. This seems
fixed now, I'm not sure why. Maybe the "skip on non-pending promise"
logic affects it somehow.
Also removes some unused things / renames some things which were
confusing, and makes an unrelated fix in the image provider, which kept
amassing fail handlers.
Change-Id: I580becff246f197ec1bc65e82acd422620e35578
Mingle: https://wikimedia.mingle.thoughtworks.com/projects/multimedia/cards/489
2014-04-25 22:26:34 +00:00
|
|
|
* @param {HTMLImageElement} imageElement
|
2014-02-25 13:43:22 +00:00
|
|
|
* @param {mw.mmv.model.ThumbnailWidth} imageWidths
|
|
|
|
* @param {number} loadTime Time it took to load the thumbnail
|
|
|
|
*/
|
Refactor progressbar & blur handling
This tries to fix a number of related issues:
* the blurred thumbnail was visible for a split-second sometimes
when switching back to an already-loaded image. (Presumably when
JS was sluggish enough to take more than 10 ms to execute.) We
now check whether the promise is pending before showing a placeholder.
(More generally, a lot of unnecessary logic was executed when paging
through already loaded images, like displaying the placeholder, so
this might make the UI a bit more responsive.)
* the blur could get stuck sometimes - I have seen this a few times,
but have never been able to reproduce it, so I'm only guessing, but
maybe the timing was really unfortunate, and we switched back less
than 10 ms before loading finished. We now remove the blur on every
branch, just to be sure.
* adding a progress handler to a promise might not have any immediate
effect, so when switching to an image which was loading, the progress
bar reacted too late. We now store the progress state per thumbnail
so it is always available immediately.
* the progress would animate from 0 to its actual state whenever we
navigated to the image. The change on paging is now instant; the
progress bar only animates when we are looking at it.
* switching quickly back and forthe between a loaded and a loading
image resulted in the loading image becoming unblurred. This seems
fixed now, I'm not sure why. Maybe the "skip on non-pending promise"
logic affects it somehow.
Also removes some unused things / renames some things which were
confusing, and makes an unrelated fix in the image provider, which kept
amassing fail handlers.
Change-Id: I580becff246f197ec1bc65e82acd422620e35578
Mingle: https://wikimedia.mingle.thoughtworks.com/projects/multimedia/cards/489
2014-04-25 22:26:34 +00:00
|
|
|
MMVP.displayRealThumbnail = function ( thumbnail, imageElement, imageWidths, loadTime ) {
|
2014-11-15 15:32:04 +00:00
|
|
|
var viewer = this;
|
|
|
|
|
2014-02-25 13:43:22 +00:00
|
|
|
this.realThumbnailShown = true;
|
|
|
|
|
Refactor progressbar & blur handling
This tries to fix a number of related issues:
* the blurred thumbnail was visible for a split-second sometimes
when switching back to an already-loaded image. (Presumably when
JS was sluggish enough to take more than 10 ms to execute.) We
now check whether the promise is pending before showing a placeholder.
(More generally, a lot of unnecessary logic was executed when paging
through already loaded images, like displaying the placeholder, so
this might make the UI a bit more responsive.)
* the blur could get stuck sometimes - I have seen this a few times,
but have never been able to reproduce it, so I'm only guessing, but
maybe the timing was really unfortunate, and we switched back less
than 10 ms before loading finished. We now remove the blur on every
branch, just to be sure.
* adding a progress handler to a promise might not have any immediate
effect, so when switching to an image which was loading, the progress
bar reacted too late. We now store the progress state per thumbnail
so it is always available immediately.
* the progress would animate from 0 to its actual state whenever we
navigated to the image. The change on paging is now instant; the
progress bar only animates when we are looking at it.
* switching quickly back and forthe between a loaded and a loading
image resulted in the loading image becoming unblurred. This seems
fixed now, I'm not sure why. Maybe the "skip on non-pending promise"
logic affects it somehow.
Also removes some unused things / renames some things which were
confusing, and makes an unrelated fix in the image provider, which kept
amassing fail handlers.
Change-Id: I580becff246f197ec1bc65e82acd422620e35578
Mingle: https://wikimedia.mingle.thoughtworks.com/projects/multimedia/cards/489
2014-04-25 22:26:34 +00:00
|
|
|
this.setImage( this.ui, thumbnail, imageElement, imageWidths );
|
2014-02-25 13:43:22 +00:00
|
|
|
|
Refactor progressbar & blur handling
This tries to fix a number of related issues:
* the blurred thumbnail was visible for a split-second sometimes
when switching back to an already-loaded image. (Presumably when
JS was sluggish enough to take more than 10 ms to execute.) We
now check whether the promise is pending before showing a placeholder.
(More generally, a lot of unnecessary logic was executed when paging
through already loaded images, like displaying the placeholder, so
this might make the UI a bit more responsive.)
* the blur could get stuck sometimes - I have seen this a few times,
but have never been able to reproduce it, so I'm only guessing, but
maybe the timing was really unfortunate, and we switched back less
than 10 ms before loading finished. We now remove the blur on every
branch, just to be sure.
* adding a progress handler to a promise might not have any immediate
effect, so when switching to an image which was loading, the progress
bar reacted too late. We now store the progress state per thumbnail
so it is always available immediately.
* the progress would animate from 0 to its actual state whenever we
navigated to the image. The change on paging is now instant; the
progress bar only animates when we are looking at it.
* switching quickly back and forthe between a loaded and a loading
image resulted in the loading image becoming unblurred. This seems
fixed now, I'm not sure why. Maybe the "skip on non-pending promise"
logic affects it somehow.
Also removes some unused things / renames some things which were
confusing, and makes an unrelated fix in the image provider, which kept
amassing fail handlers.
Change-Id: I580becff246f197ec1bc65e82acd422620e35578
Mingle: https://wikimedia.mingle.thoughtworks.com/projects/multimedia/cards/489
2014-04-25 22:26:34 +00:00
|
|
|
// We only animate unblurWithAnimation if the image wasn't loaded from the cache
|
2014-02-25 13:43:22 +00:00
|
|
|
// A load in < 10ms is considered to be a browser cache hit
|
|
|
|
if ( this.blurredThumbnailShown && loadTime > 10 ) {
|
Refactor progressbar & blur handling
This tries to fix a number of related issues:
* the blurred thumbnail was visible for a split-second sometimes
when switching back to an already-loaded image. (Presumably when
JS was sluggish enough to take more than 10 ms to execute.) We
now check whether the promise is pending before showing a placeholder.
(More generally, a lot of unnecessary logic was executed when paging
through already loaded images, like displaying the placeholder, so
this might make the UI a bit more responsive.)
* the blur could get stuck sometimes - I have seen this a few times,
but have never been able to reproduce it, so I'm only guessing, but
maybe the timing was really unfortunate, and we switched back less
than 10 ms before loading finished. We now remove the blur on every
branch, just to be sure.
* adding a progress handler to a promise might not have any immediate
effect, so when switching to an image which was loading, the progress
bar reacted too late. We now store the progress state per thumbnail
so it is always available immediately.
* the progress would animate from 0 to its actual state whenever we
navigated to the image. The change on paging is now instant; the
progress bar only animates when we are looking at it.
* switching quickly back and forthe between a loaded and a loading
image resulted in the loading image becoming unblurred. This seems
fixed now, I'm not sure why. Maybe the "skip on non-pending promise"
logic affects it somehow.
Also removes some unused things / renames some things which were
confusing, and makes an unrelated fix in the image provider, which kept
amassing fail handlers.
Change-Id: I580becff246f197ec1bc65e82acd422620e35578
Mingle: https://wikimedia.mingle.thoughtworks.com/projects/multimedia/cards/489
2014-04-25 22:26:34 +00:00
|
|
|
this.ui.canvas.unblurWithAnimation();
|
|
|
|
} else {
|
2014-03-05 02:24:18 +00:00
|
|
|
this.ui.canvas.unblur();
|
2014-02-25 13:43:22 +00:00
|
|
|
}
|
2014-02-28 10:44:26 +00:00
|
|
|
|
2014-11-20 23:39:29 +00:00
|
|
|
this.viewLogger.attach( thumbnail.url );
|
2014-11-15 15:32:04 +00:00
|
|
|
|
2014-11-20 23:39:29 +00:00
|
|
|
mw.mmv.actionLogger.log( 'image-view' ).then( function ( wasEventLogged ) {
|
|
|
|
viewer.viewLogger.setLastViewLogged( wasEventLogged );
|
2014-11-15 15:32:04 +00:00
|
|
|
} );
|
2014-02-25 13:43:22 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Display the blurred thumbnail from the page
|
2016-07-18 13:49:27 +00:00
|
|
|
*
|
2014-04-24 01:03:24 +00:00
|
|
|
* @param {mw.mmv.LightboxImage} image
|
2014-02-25 13:43:22 +00:00
|
|
|
* @param {jQuery} $initialImage The thumbnail from the page
|
|
|
|
* @param {mw.mmv.model.ThumbnailWidth} imageWidths
|
Refactor progressbar & blur handling
This tries to fix a number of related issues:
* the blurred thumbnail was visible for a split-second sometimes
when switching back to an already-loaded image. (Presumably when
JS was sluggish enough to take more than 10 ms to execute.) We
now check whether the promise is pending before showing a placeholder.
(More generally, a lot of unnecessary logic was executed when paging
through already loaded images, like displaying the placeholder, so
this might make the UI a bit more responsive.)
* the blur could get stuck sometimes - I have seen this a few times,
but have never been able to reproduce it, so I'm only guessing, but
maybe the timing was really unfortunate, and we switched back less
than 10 ms before loading finished. We now remove the blur on every
branch, just to be sure.
* adding a progress handler to a promise might not have any immediate
effect, so when switching to an image which was loading, the progress
bar reacted too late. We now store the progress state per thumbnail
so it is always available immediately.
* the progress would animate from 0 to its actual state whenever we
navigated to the image. The change on paging is now instant; the
progress bar only animates when we are looking at it.
* switching quickly back and forthe between a loaded and a loading
image resulted in the loading image becoming unblurred. This seems
fixed now, I'm not sure why. Maybe the "skip on non-pending promise"
logic affects it somehow.
Also removes some unused things / renames some things which were
confusing, and makes an unrelated fix in the image provider, which kept
amassing fail handlers.
Change-Id: I580becff246f197ec1bc65e82acd422620e35578
Mingle: https://wikimedia.mingle.thoughtworks.com/projects/multimedia/cards/489
2014-04-25 22:26:34 +00:00
|
|
|
* @param {boolean} [recursion=false] for internal use, never set this when calling from outside
|
2014-02-25 13:43:22 +00:00
|
|
|
*/
|
2014-04-24 01:03:24 +00:00
|
|
|
MMVP.displayPlaceholderThumbnail = function ( image, $initialImage, imageWidths, recursion ) {
|
|
|
|
var viewer = this,
|
2016-07-18 13:49:27 +00:00
|
|
|
size = { width: image.originalWidth, height: image.originalHeight };
|
2014-04-24 01:03:24 +00:00
|
|
|
|
Refactor progressbar & blur handling
This tries to fix a number of related issues:
* the blurred thumbnail was visible for a split-second sometimes
when switching back to an already-loaded image. (Presumably when
JS was sluggish enough to take more than 10 ms to execute.) We
now check whether the promise is pending before showing a placeholder.
(More generally, a lot of unnecessary logic was executed when paging
through already loaded images, like displaying the placeholder, so
this might make the UI a bit more responsive.)
* the blur could get stuck sometimes - I have seen this a few times,
but have never been able to reproduce it, so I'm only guessing, but
maybe the timing was really unfortunate, and we switched back less
than 10 ms before loading finished. We now remove the blur on every
branch, just to be sure.
* adding a progress handler to a promise might not have any immediate
effect, so when switching to an image which was loading, the progress
bar reacted too late. We now store the progress state per thumbnail
so it is always available immediately.
* the progress would animate from 0 to its actual state whenever we
navigated to the image. The change on paging is now instant; the
progress bar only animates when we are looking at it.
* switching quickly back and forthe between a loaded and a loading
image resulted in the loading image becoming unblurred. This seems
fixed now, I'm not sure why. Maybe the "skip on non-pending promise"
logic affects it somehow.
Also removes some unused things / renames some things which were
confusing, and makes an unrelated fix in the image provider, which kept
amassing fail handlers.
Change-Id: I580becff246f197ec1bc65e82acd422620e35578
Mingle: https://wikimedia.mingle.thoughtworks.com/projects/multimedia/cards/489
2014-04-25 22:26:34 +00:00
|
|
|
// If the actual image has already been displayed, there's no point showing the blurry one.
|
|
|
|
// This can happen if the API request to get the original image size needed to show the
|
|
|
|
// placeholder thumbnail takes longer then loading the actual thumbnail.
|
2014-02-25 13:43:22 +00:00
|
|
|
if ( this.realThumbnailShown ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-04-24 01:03:24 +00:00
|
|
|
// Width/height of the original image are added to the HTML by MediaViewer via a PHP hook,
|
|
|
|
// and can be missing in exotic circumstances, e. g. when the extension has only been
|
|
|
|
// enabled recently and the HTML cache has not cleared yet. If that is the case, we need
|
|
|
|
// to fetch the size from the API first.
|
|
|
|
if ( !size.width || !size.height ) {
|
|
|
|
if ( recursion ) {
|
|
|
|
// this should not be possible, but an infinite recursion is nasty
|
|
|
|
// business, so we make a sanity check
|
2017-05-03 09:15:05 +00:00
|
|
|
throw new Error( 'MediaViewer internal error: displayPlaceholderThumbnail recursion' );
|
2014-04-24 01:03:24 +00:00
|
|
|
}
|
|
|
|
this.imageInfoProvider.get( image.filePageTitle ).done( function ( imageInfo ) {
|
|
|
|
// Make sure the user has not navigated away while we were waiting for the size
|
|
|
|
if ( viewer.currentIndex === image.index ) {
|
|
|
|
image.originalWidth = imageInfo.width;
|
|
|
|
image.originalHeight = imageInfo.height;
|
|
|
|
viewer.displayPlaceholderThumbnail( image, $initialImage, imageWidths, true );
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
} else {
|
|
|
|
this.blurredThumbnailShown = this.ui.canvas.maybeDisplayPlaceholder(
|
|
|
|
size, $initialImage, imageWidths );
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
Refactor progressbar & blur handling
This tries to fix a number of related issues:
* the blurred thumbnail was visible for a split-second sometimes
when switching back to an already-loaded image. (Presumably when
JS was sluggish enough to take more than 10 ms to execute.) We
now check whether the promise is pending before showing a placeholder.
(More generally, a lot of unnecessary logic was executed when paging
through already loaded images, like displaying the placeholder, so
this might make the UI a bit more responsive.)
* the blur could get stuck sometimes - I have seen this a few times,
but have never been able to reproduce it, so I'm only guessing, but
maybe the timing was really unfortunate, and we switched back less
than 10 ms before loading finished. We now remove the blur on every
branch, just to be sure.
* adding a progress handler to a promise might not have any immediate
effect, so when switching to an image which was loading, the progress
bar reacted too late. We now store the progress state per thumbnail
so it is always available immediately.
* the progress would animate from 0 to its actual state whenever we
navigated to the image. The change on paging is now instant; the
progress bar only animates when we are looking at it.
* switching quickly back and forthe between a loaded and a loading
image resulted in the loading image becoming unblurred. This seems
fixed now, I'm not sure why. Maybe the "skip on non-pending promise"
logic affects it somehow.
Also removes some unused things / renames some things which were
confusing, and makes an unrelated fix in the image provider, which kept
amassing fail handlers.
Change-Id: I580becff246f197ec1bc65e82acd422620e35578
Mingle: https://wikimedia.mingle.thoughtworks.com/projects/multimedia/cards/489
2014-04-25 22:26:34 +00:00
|
|
|
/**
|
|
|
|
* Image loading progress. Keyed by image (database) name + '|' + thumbnail width in pixels,
|
|
|
|
* value is a number between 0-100.
|
2016-07-18 13:49:27 +00:00
|
|
|
*
|
|
|
|
* @private
|
Refactor progressbar & blur handling
This tries to fix a number of related issues:
* the blurred thumbnail was visible for a split-second sometimes
when switching back to an already-loaded image. (Presumably when
JS was sluggish enough to take more than 10 ms to execute.) We
now check whether the promise is pending before showing a placeholder.
(More generally, a lot of unnecessary logic was executed when paging
through already loaded images, like displaying the placeholder, so
this might make the UI a bit more responsive.)
* the blur could get stuck sometimes - I have seen this a few times,
but have never been able to reproduce it, so I'm only guessing, but
maybe the timing was really unfortunate, and we switched back less
than 10 ms before loading finished. We now remove the blur on every
branch, just to be sure.
* adding a progress handler to a promise might not have any immediate
effect, so when switching to an image which was loading, the progress
bar reacted too late. We now store the progress state per thumbnail
so it is always available immediately.
* the progress would animate from 0 to its actual state whenever we
navigated to the image. The change on paging is now instant; the
progress bar only animates when we are looking at it.
* switching quickly back and forthe between a loaded and a loading
image resulted in the loading image becoming unblurred. This seems
fixed now, I'm not sure why. Maybe the "skip on non-pending promise"
logic affects it somehow.
Also removes some unused things / renames some things which were
confusing, and makes an unrelated fix in the image provider, which kept
amassing fail handlers.
Change-Id: I580becff246f197ec1bc65e82acd422620e35578
Mingle: https://wikimedia.mingle.thoughtworks.com/projects/multimedia/cards/489
2014-04-25 22:26:34 +00:00
|
|
|
* @property {Object.<string, number>}
|
|
|
|
*/
|
|
|
|
MMVP.progressCache = {};
|
|
|
|
|
2014-04-24 01:03:24 +00:00
|
|
|
/**
|
|
|
|
* Displays a progress bar for the image loading, if necessary, and sets up handling of
|
|
|
|
* all the related callbacks.
|
2016-07-18 13:49:27 +00:00
|
|
|
*
|
2014-04-24 01:03:24 +00:00
|
|
|
* @param {mw.mmv.LightboxImage} image
|
|
|
|
* @param {jQuery.Promise.<mw.mmv.model.Thumbnail, HTMLImageElement>} imagePromise
|
Refactor progressbar & blur handling
This tries to fix a number of related issues:
* the blurred thumbnail was visible for a split-second sometimes
when switching back to an already-loaded image. (Presumably when
JS was sluggish enough to take more than 10 ms to execute.) We
now check whether the promise is pending before showing a placeholder.
(More generally, a lot of unnecessary logic was executed when paging
through already loaded images, like displaying the placeholder, so
this might make the UI a bit more responsive.)
* the blur could get stuck sometimes - I have seen this a few times,
but have never been able to reproduce it, so I'm only guessing, but
maybe the timing was really unfortunate, and we switched back less
than 10 ms before loading finished. We now remove the blur on every
branch, just to be sure.
* adding a progress handler to a promise might not have any immediate
effect, so when switching to an image which was loading, the progress
bar reacted too late. We now store the progress state per thumbnail
so it is always available immediately.
* the progress would animate from 0 to its actual state whenever we
navigated to the image. The change on paging is now instant; the
progress bar only animates when we are looking at it.
* switching quickly back and forthe between a loaded and a loading
image resulted in the loading image becoming unblurred. This seems
fixed now, I'm not sure why. Maybe the "skip on non-pending promise"
logic affects it somehow.
Also removes some unused things / renames some things which were
confusing, and makes an unrelated fix in the image provider, which kept
amassing fail handlers.
Change-Id: I580becff246f197ec1bc65e82acd422620e35578
Mingle: https://wikimedia.mingle.thoughtworks.com/projects/multimedia/cards/489
2014-04-25 22:26:34 +00:00
|
|
|
* @param {number} imageWidth needed for caching progress (FIXME)
|
2014-04-24 01:03:24 +00:00
|
|
|
*/
|
Refactor progressbar & blur handling
This tries to fix a number of related issues:
* the blurred thumbnail was visible for a split-second sometimes
when switching back to an already-loaded image. (Presumably when
JS was sluggish enough to take more than 10 ms to execute.) We
now check whether the promise is pending before showing a placeholder.
(More generally, a lot of unnecessary logic was executed when paging
through already loaded images, like displaying the placeholder, so
this might make the UI a bit more responsive.)
* the blur could get stuck sometimes - I have seen this a few times,
but have never been able to reproduce it, so I'm only guessing, but
maybe the timing was really unfortunate, and we switched back less
than 10 ms before loading finished. We now remove the blur on every
branch, just to be sure.
* adding a progress handler to a promise might not have any immediate
effect, so when switching to an image which was loading, the progress
bar reacted too late. We now store the progress state per thumbnail
so it is always available immediately.
* the progress would animate from 0 to its actual state whenever we
navigated to the image. The change on paging is now instant; the
progress bar only animates when we are looking at it.
* switching quickly back and forthe between a loaded and a loading
image resulted in the loading image becoming unblurred. This seems
fixed now, I'm not sure why. Maybe the "skip on non-pending promise"
logic affects it somehow.
Also removes some unused things / renames some things which were
confusing, and makes an unrelated fix in the image provider, which kept
amassing fail handlers.
Change-Id: I580becff246f197ec1bc65e82acd422620e35578
Mingle: https://wikimedia.mingle.thoughtworks.com/projects/multimedia/cards/489
2014-04-25 22:26:34 +00:00
|
|
|
MMVP.setupProgressBar = function ( image, imagePromise, imageWidth ) {
|
|
|
|
var viewer = this,
|
|
|
|
progressBar = viewer.ui.panel.progressBar,
|
|
|
|
key = image.filePageTitle.getPrefixedDb() + '|' + imageWidth;
|
2014-04-24 01:03:24 +00:00
|
|
|
|
2016-07-18 13:49:27 +00:00
|
|
|
if ( !this.progressCache[ key ] ) {
|
Refactor progressbar & blur handling
This tries to fix a number of related issues:
* the blurred thumbnail was visible for a split-second sometimes
when switching back to an already-loaded image. (Presumably when
JS was sluggish enough to take more than 10 ms to execute.) We
now check whether the promise is pending before showing a placeholder.
(More generally, a lot of unnecessary logic was executed when paging
through already loaded images, like displaying the placeholder, so
this might make the UI a bit more responsive.)
* the blur could get stuck sometimes - I have seen this a few times,
but have never been able to reproduce it, so I'm only guessing, but
maybe the timing was really unfortunate, and we switched back less
than 10 ms before loading finished. We now remove the blur on every
branch, just to be sure.
* adding a progress handler to a promise might not have any immediate
effect, so when switching to an image which was loading, the progress
bar reacted too late. We now store the progress state per thumbnail
so it is always available immediately.
* the progress would animate from 0 to its actual state whenever we
navigated to the image. The change on paging is now instant; the
progress bar only animates when we are looking at it.
* switching quickly back and forthe between a loaded and a loading
image resulted in the loading image becoming unblurred. This seems
fixed now, I'm not sure why. Maybe the "skip on non-pending promise"
logic affects it somehow.
Also removes some unused things / renames some things which were
confusing, and makes an unrelated fix in the image provider, which kept
amassing fail handlers.
Change-Id: I580becff246f197ec1bc65e82acd422620e35578
Mingle: https://wikimedia.mingle.thoughtworks.com/projects/multimedia/cards/489
2014-04-25 22:26:34 +00:00
|
|
|
// Animate progress bar to 5 to give a sense that something is happening, and make sure
|
|
|
|
// the progress bar is noticeable, even if we're sitting at 0% stuck waiting for
|
|
|
|
// server-side processing, such as thumbnail (re)generation
|
|
|
|
progressBar.jumpTo( 0 );
|
|
|
|
progressBar.animateTo( 5 );
|
2016-07-18 13:49:27 +00:00
|
|
|
viewer.progressCache[ key ] = 5;
|
Refactor progressbar & blur handling
This tries to fix a number of related issues:
* the blurred thumbnail was visible for a split-second sometimes
when switching back to an already-loaded image. (Presumably when
JS was sluggish enough to take more than 10 ms to execute.) We
now check whether the promise is pending before showing a placeholder.
(More generally, a lot of unnecessary logic was executed when paging
through already loaded images, like displaying the placeholder, so
this might make the UI a bit more responsive.)
* the blur could get stuck sometimes - I have seen this a few times,
but have never been able to reproduce it, so I'm only guessing, but
maybe the timing was really unfortunate, and we switched back less
than 10 ms before loading finished. We now remove the blur on every
branch, just to be sure.
* adding a progress handler to a promise might not have any immediate
effect, so when switching to an image which was loading, the progress
bar reacted too late. We now store the progress state per thumbnail
so it is always available immediately.
* the progress would animate from 0 to its actual state whenever we
navigated to the image. The change on paging is now instant; the
progress bar only animates when we are looking at it.
* switching quickly back and forthe between a loaded and a loading
image resulted in the loading image becoming unblurred. This seems
fixed now, I'm not sure why. Maybe the "skip on non-pending promise"
logic affects it somehow.
Also removes some unused things / renames some things which were
confusing, and makes an unrelated fix in the image provider, which kept
amassing fail handlers.
Change-Id: I580becff246f197ec1bc65e82acd422620e35578
Mingle: https://wikimedia.mingle.thoughtworks.com/projects/multimedia/cards/489
2014-04-25 22:26:34 +00:00
|
|
|
} else {
|
2016-07-18 13:49:27 +00:00
|
|
|
progressBar.jumpTo( this.progressCache[ key ] );
|
Refactor progressbar & blur handling
This tries to fix a number of related issues:
* the blurred thumbnail was visible for a split-second sometimes
when switching back to an already-loaded image. (Presumably when
JS was sluggish enough to take more than 10 ms to execute.) We
now check whether the promise is pending before showing a placeholder.
(More generally, a lot of unnecessary logic was executed when paging
through already loaded images, like displaying the placeholder, so
this might make the UI a bit more responsive.)
* the blur could get stuck sometimes - I have seen this a few times,
but have never been able to reproduce it, so I'm only guessing, but
maybe the timing was really unfortunate, and we switched back less
than 10 ms before loading finished. We now remove the blur on every
branch, just to be sure.
* adding a progress handler to a promise might not have any immediate
effect, so when switching to an image which was loading, the progress
bar reacted too late. We now store the progress state per thumbnail
so it is always available immediately.
* the progress would animate from 0 to its actual state whenever we
navigated to the image. The change on paging is now instant; the
progress bar only animates when we are looking at it.
* switching quickly back and forthe between a loaded and a loading
image resulted in the loading image becoming unblurred. This seems
fixed now, I'm not sure why. Maybe the "skip on non-pending promise"
logic affects it somehow.
Also removes some unused things / renames some things which were
confusing, and makes an unrelated fix in the image provider, which kept
amassing fail handlers.
Change-Id: I580becff246f197ec1bc65e82acd422620e35578
Mingle: https://wikimedia.mingle.thoughtworks.com/projects/multimedia/cards/489
2014-04-25 22:26:34 +00:00
|
|
|
}
|
2014-04-24 01:03:24 +00:00
|
|
|
|
Refactor progressbar & blur handling
This tries to fix a number of related issues:
* the blurred thumbnail was visible for a split-second sometimes
when switching back to an already-loaded image. (Presumably when
JS was sluggish enough to take more than 10 ms to execute.) We
now check whether the promise is pending before showing a placeholder.
(More generally, a lot of unnecessary logic was executed when paging
through already loaded images, like displaying the placeholder, so
this might make the UI a bit more responsive.)
* the blur could get stuck sometimes - I have seen this a few times,
but have never been able to reproduce it, so I'm only guessing, but
maybe the timing was really unfortunate, and we switched back less
than 10 ms before loading finished. We now remove the blur on every
branch, just to be sure.
* adding a progress handler to a promise might not have any immediate
effect, so when switching to an image which was loading, the progress
bar reacted too late. We now store the progress state per thumbnail
so it is always available immediately.
* the progress would animate from 0 to its actual state whenever we
navigated to the image. The change on paging is now instant; the
progress bar only animates when we are looking at it.
* switching quickly back and forthe between a loaded and a loading
image resulted in the loading image becoming unblurred. This seems
fixed now, I'm not sure why. Maybe the "skip on non-pending promise"
logic affects it somehow.
Also removes some unused things / renames some things which were
confusing, and makes an unrelated fix in the image provider, which kept
amassing fail handlers.
Change-Id: I580becff246f197ec1bc65e82acd422620e35578
Mingle: https://wikimedia.mingle.thoughtworks.com/projects/multimedia/cards/489
2014-04-25 22:26:34 +00:00
|
|
|
// FIXME would be nice to have a "filtered" promise which does not fire when the image is not visible
|
2017-05-11 15:03:52 +00:00
|
|
|
imagePromise.then(
|
|
|
|
// done
|
|
|
|
function ( thumbnail, imageElement ) {
|
|
|
|
viewer.progressCache[ key ] = 100;
|
|
|
|
if ( viewer.currentIndex === image.index ) {
|
|
|
|
// Fallback in case the browser doesn't have fancy progress updates
|
|
|
|
progressBar.animateTo( 100 );
|
2014-04-24 01:03:24 +00:00
|
|
|
|
2017-05-11 15:03:52 +00:00
|
|
|
// Hide progress bar, we're done
|
|
|
|
progressBar.hide();
|
|
|
|
}
|
Refactor progressbar & blur handling
This tries to fix a number of related issues:
* the blurred thumbnail was visible for a split-second sometimes
when switching back to an already-loaded image. (Presumably when
JS was sluggish enough to take more than 10 ms to execute.) We
now check whether the promise is pending before showing a placeholder.
(More generally, a lot of unnecessary logic was executed when paging
through already loaded images, like displaying the placeholder, so
this might make the UI a bit more responsive.)
* the blur could get stuck sometimes - I have seen this a few times,
but have never been able to reproduce it, so I'm only guessing, but
maybe the timing was really unfortunate, and we switched back less
than 10 ms before loading finished. We now remove the blur on every
branch, just to be sure.
* adding a progress handler to a promise might not have any immediate
effect, so when switching to an image which was loading, the progress
bar reacted too late. We now store the progress state per thumbnail
so it is always available immediately.
* the progress would animate from 0 to its actual state whenever we
navigated to the image. The change on paging is now instant; the
progress bar only animates when we are looking at it.
* switching quickly back and forthe between a loaded and a loading
image resulted in the loading image becoming unblurred. This seems
fixed now, I'm not sure why. Maybe the "skip on non-pending promise"
logic affects it somehow.
Also removes some unused things / renames some things which were
confusing, and makes an unrelated fix in the image provider, which kept
amassing fail handlers.
Change-Id: I580becff246f197ec1bc65e82acd422620e35578
Mingle: https://wikimedia.mingle.thoughtworks.com/projects/multimedia/cards/489
2014-04-25 22:26:34 +00:00
|
|
|
|
2017-05-11 15:03:52 +00:00
|
|
|
return $.Deferred().resolve( thumbnail, imageElement );
|
|
|
|
},
|
|
|
|
// fail
|
|
|
|
function ( error ) {
|
|
|
|
viewer.progressCache[ key ] = 100;
|
2014-04-24 01:03:24 +00:00
|
|
|
|
2017-05-11 15:03:52 +00:00
|
|
|
if ( viewer.currentIndex === image.index ) {
|
|
|
|
// Hide progress bar on error
|
|
|
|
progressBar.hide();
|
|
|
|
}
|
Refactor progressbar & blur handling
This tries to fix a number of related issues:
* the blurred thumbnail was visible for a split-second sometimes
when switching back to an already-loaded image. (Presumably when
JS was sluggish enough to take more than 10 ms to execute.) We
now check whether the promise is pending before showing a placeholder.
(More generally, a lot of unnecessary logic was executed when paging
through already loaded images, like displaying the placeholder, so
this might make the UI a bit more responsive.)
* the blur could get stuck sometimes - I have seen this a few times,
but have never been able to reproduce it, so I'm only guessing, but
maybe the timing was really unfortunate, and we switched back less
than 10 ms before loading finished. We now remove the blur on every
branch, just to be sure.
* adding a progress handler to a promise might not have any immediate
effect, so when switching to an image which was loading, the progress
bar reacted too late. We now store the progress state per thumbnail
so it is always available immediately.
* the progress would animate from 0 to its actual state whenever we
navigated to the image. The change on paging is now instant; the
progress bar only animates when we are looking at it.
* switching quickly back and forthe between a loaded and a loading
image resulted in the loading image becoming unblurred. This seems
fixed now, I'm not sure why. Maybe the "skip on non-pending promise"
logic affects it somehow.
Also removes some unused things / renames some things which were
confusing, and makes an unrelated fix in the image provider, which kept
amassing fail handlers.
Change-Id: I580becff246f197ec1bc65e82acd422620e35578
Mingle: https://wikimedia.mingle.thoughtworks.com/projects/multimedia/cards/489
2014-04-25 22:26:34 +00:00
|
|
|
|
2017-05-11 15:03:52 +00:00
|
|
|
return $.Deferred().reject( error );
|
|
|
|
},
|
|
|
|
// progress
|
|
|
|
function ( progress ) {
|
|
|
|
// We pretend progress is always at least 5%, so progress events below 5% should be ignored
|
|
|
|
// 100 will be handled by the done handler, do not mix two animations
|
|
|
|
if ( progress >= 5 && progress < 100 ) {
|
|
|
|
viewer.progressCache[ key ] = progress;
|
|
|
|
|
|
|
|
// Touch the UI only if the user is looking at this image
|
|
|
|
if ( viewer.currentIndex === image.index ) {
|
|
|
|
progressBar.animateTo( progress );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return progress;
|
2014-04-24 01:03:24 +00:00
|
|
|
}
|
2017-05-11 15:03:52 +00:00
|
|
|
);
|
2014-02-25 13:43:22 +00:00
|
|
|
};
|
|
|
|
|
2014-02-13 09:52:40 +00:00
|
|
|
/**
|
|
|
|
* Preload this many prev/next images to speed up navigation.
|
|
|
|
* (E.g. preloadDistance = 3 means that the previous 3 and the next 3 images will be loaded.)
|
|
|
|
* Preloading only happens when the viewer is open.
|
|
|
|
* @property {number}
|
|
|
|
*/
|
|
|
|
MMVP.preloadDistance = 1;
|
2014-02-07 14:47:00 +00:00
|
|
|
|
2014-02-13 09:52:40 +00:00
|
|
|
/**
|
|
|
|
* Stores image metadata preloads, so they can be cancelled.
|
2014-02-19 02:27:30 +00:00
|
|
|
* @property {mw.mmv.model.TaskQueue}
|
2014-02-13 09:52:40 +00:00
|
|
|
*/
|
|
|
|
MMVP.metadataPreloadQueue = null;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Stores image thumbnail preloads, so they can be cancelled.
|
2014-02-19 02:27:30 +00:00
|
|
|
* @property {mw.mmv.model.TaskQueue}
|
2014-02-13 09:52:40 +00:00
|
|
|
*/
|
|
|
|
MMVP.thumbnailPreloadQueue = null;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Orders lightboximage indexes for preloading. Works similar to $.each, except it only takes
|
|
|
|
* the callback argument. Calls the callback with each lightboximage index in some sequence
|
|
|
|
* that is ideal for preloading.
|
2016-07-18 13:49:27 +00:00
|
|
|
*
|
2014-02-13 09:52:40 +00:00
|
|
|
* @private
|
2014-02-25 02:28:49 +00:00
|
|
|
* @param {function(number, mw.mmv.LightboxImage)} callback
|
2014-02-13 09:52:40 +00:00
|
|
|
*/
|
2015-01-23 12:48:27 +00:00
|
|
|
MMVP.eachPrealoadableLightboxIndex = function ( callback ) {
|
2016-07-18 13:49:27 +00:00
|
|
|
var i;
|
|
|
|
for ( i = 0; i <= this.preloadDistance; i++ ) {
|
2014-03-05 02:24:18 +00:00
|
|
|
if ( this.currentIndex + i < this.thumbs.length ) {
|
2014-02-13 09:52:40 +00:00
|
|
|
callback(
|
2014-03-05 02:24:18 +00:00
|
|
|
this.currentIndex + i,
|
2014-12-02 10:05:12 +00:00
|
|
|
this.thumbs[ this.currentIndex + i ].image,
|
|
|
|
this.thumbs[ this.currentIndex + i ].extraStatsDeferred
|
2014-02-13 09:52:40 +00:00
|
|
|
);
|
2014-02-07 14:47:00 +00:00
|
|
|
}
|
2014-03-05 02:24:18 +00:00
|
|
|
if ( i && this.currentIndex - i >= 0 ) { // skip duplicate for i==0
|
2014-02-13 09:52:40 +00:00
|
|
|
callback(
|
2014-03-05 02:24:18 +00:00
|
|
|
this.currentIndex - i,
|
2014-12-02 10:05:12 +00:00
|
|
|
this.thumbs[ this.currentIndex - i ].image,
|
|
|
|
this.thumbs[ this.currentIndex - i ].extraStatsDeferred
|
2014-02-13 09:52:40 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A helper function to fill up the preload queues.
|
|
|
|
* taskFactory(lightboxImage) should return a preload task for the given lightboximage.
|
2016-07-18 13:49:27 +00:00
|
|
|
*
|
2014-02-13 09:52:40 +00:00
|
|
|
* @private
|
2014-02-25 02:28:49 +00:00
|
|
|
* @param {function(mw.mmv.LightboxImage): function()} taskFactory
|
2014-02-13 09:52:40 +00:00
|
|
|
* @return {mw.mmv.model.TaskQueue}
|
|
|
|
*/
|
2015-01-23 12:48:27 +00:00
|
|
|
MMVP.pushLightboxImagesIntoQueue = function ( taskFactory ) {
|
2014-02-13 09:52:40 +00:00
|
|
|
var queue = new mw.mmv.model.TaskQueue();
|
|
|
|
|
2015-01-23 12:48:27 +00:00
|
|
|
this.eachPrealoadableLightboxIndex( function ( i, lightboxImage, extraStatsDeferred ) {
|
2014-12-02 10:05:12 +00:00
|
|
|
queue.push( taskFactory( lightboxImage, extraStatsDeferred ) );
|
2013-11-25 23:51:40 +00:00
|
|
|
} );
|
|
|
|
|
2014-02-13 09:52:40 +00:00
|
|
|
return queue;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Cancels in-progress image metadata preloading.
|
|
|
|
*/
|
2015-01-23 12:48:27 +00:00
|
|
|
MMVP.cancelImageMetadataPreloading = function () {
|
2014-02-13 09:52:40 +00:00
|
|
|
if ( this.metadataPreloadQueue ) {
|
|
|
|
this.metadataPreloadQueue.cancel();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Cancels in-progress image thumbnail preloading.
|
|
|
|
*/
|
2015-01-23 12:48:27 +00:00
|
|
|
MMVP.cancelThumbnailsPreloading = function () {
|
2014-02-13 09:52:40 +00:00
|
|
|
if ( this.thumbnailPreloadQueue ) {
|
|
|
|
this.thumbnailPreloadQueue.cancel();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Preload metadata for next and prev N image (N = MMVP.preloadDistance).
|
|
|
|
* Two images will be loaded at a time (one forward, one backward), with closer images
|
|
|
|
* being loaded sooner.
|
|
|
|
*/
|
2015-01-23 12:48:27 +00:00
|
|
|
MMVP.preloadImagesMetadata = function () {
|
2014-02-13 09:52:40 +00:00
|
|
|
var viewer = this;
|
|
|
|
|
|
|
|
this.cancelImageMetadataPreloading();
|
|
|
|
|
2015-01-23 12:48:27 +00:00
|
|
|
this.metadataPreloadQueue = this.pushLightboxImagesIntoQueue( function ( lightboxImage, extraStatsDeferred ) {
|
|
|
|
return function () {
|
2014-12-02 10:05:12 +00:00
|
|
|
var metadatapromise = viewer.fetchSizeIndependentLightboxInfo( lightboxImage.filePageTitle );
|
|
|
|
metadatapromise.done( function ( imageInfo ) {
|
|
|
|
extraStatsDeferred.resolve( { uploadTimestamp: imageInfo.anonymizedUploadDateTime } );
|
|
|
|
} ).fail( function () {
|
|
|
|
extraStatsDeferred.reject();
|
|
|
|
} );
|
|
|
|
return metadatapromise;
|
2014-02-13 09:52:40 +00:00
|
|
|
};
|
|
|
|
} );
|
|
|
|
|
|
|
|
this.metadataPreloadQueue.execute();
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Preload thumbnails for next and prev N image (N = MMVP.preloadDistance).
|
|
|
|
* Two images will be loaded at a time (one forward, one backward), with closer images
|
|
|
|
* being loaded sooner.
|
|
|
|
*/
|
2015-01-23 12:48:27 +00:00
|
|
|
MMVP.preloadThumbnails = function () {
|
2014-03-05 02:24:18 +00:00
|
|
|
var viewer = this;
|
2014-02-13 09:52:40 +00:00
|
|
|
|
|
|
|
this.cancelThumbnailsPreloading();
|
|
|
|
|
2015-01-23 12:48:27 +00:00
|
|
|
this.thumbnailPreloadQueue = this.pushLightboxImagesIntoQueue( function ( lightboxImage, extraStatsDeferred ) {
|
|
|
|
return function () {
|
2014-09-26 18:37:53 +00:00
|
|
|
var imageWidths, canvasDimensions;
|
|
|
|
|
2014-04-16 11:58:18 +00:00
|
|
|
// viewer.ui.canvas.getLightboxImageWidths needs the viewer to be open
|
|
|
|
// because it needs to read the size of visible elements
|
|
|
|
if ( !viewer.isOpen ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-09-26 18:37:53 +00:00
|
|
|
imageWidths = viewer.ui.canvas.getLightboxImageWidths( lightboxImage );
|
|
|
|
canvasDimensions = viewer.ui.canvas.getDimensions();
|
|
|
|
|
|
|
|
mw.mmv.dimensionLogger.logDimensions( imageWidths, canvasDimensions, 'preload' );
|
|
|
|
|
2014-12-02 10:05:12 +00:00
|
|
|
return viewer.fetchThumbnailForLightboxImage( lightboxImage, imageWidths.real, extraStatsDeferred );
|
2014-02-13 09:52:40 +00:00
|
|
|
};
|
|
|
|
} );
|
|
|
|
|
|
|
|
this.thumbnailPreloadQueue.execute();
|
2013-11-25 23:51:40 +00:00
|
|
|
};
|
|
|
|
|
2014-02-20 08:43:10 +00:00
|
|
|
/**
|
|
|
|
* Preload the fullscreen size of the current image.
|
2016-12-14 13:09:10 +00:00
|
|
|
*
|
|
|
|
* @param {mw.mmv.LightboxImage} image
|
2014-02-20 08:43:10 +00:00
|
|
|
*/
|
2015-01-23 12:48:27 +00:00
|
|
|
MMVP.preloadFullscreenThumbnail = function ( image ) {
|
2016-07-18 13:49:27 +00:00
|
|
|
var imageWidths = this.ui.canvas.getLightboxImageWidthsForFullscreen( image ),
|
2014-09-26 18:37:53 +00:00
|
|
|
canvasDimensions = this.ui.canvas.getDimensions( true );
|
|
|
|
|
|
|
|
mw.mmv.dimensionLogger.logDimensions( imageWidths, canvasDimensions, 'preload' );
|
|
|
|
this.fetchThumbnailForLightboxImage( image, imageWidths.real );
|
2014-02-20 08:43:10 +00:00
|
|
|
};
|
|
|
|
|
2014-01-06 20:02:39 +00:00
|
|
|
/**
|
2014-02-13 09:52:40 +00:00
|
|
|
* Loads all the size-independent information needed by the lightbox (image metadata, repo
|
2015-12-24 15:01:56 +00:00
|
|
|
* information).
|
2016-07-18 13:49:27 +00:00
|
|
|
*
|
2014-02-13 09:52:40 +00:00
|
|
|
* @param {mw.Title} fileTitle Title of the file page for the image.
|
2016-07-18 13:49:27 +00:00
|
|
|
* @return {jQuery.Promise.<mw.mmv.model.Image, mw.mmv.model.Repo>}
|
2014-01-06 20:02:39 +00:00
|
|
|
*/
|
2014-02-13 09:52:40 +00:00
|
|
|
MMVP.fetchSizeIndependentLightboxInfo = function ( fileTitle ) {
|
2015-12-24 15:01:56 +00:00
|
|
|
var imageInfoPromise = this.imageInfoProvider.get( fileTitle ),
|
|
|
|
repoInfoPromise = this.fileRepoInfoProvider.get( fileTitle );
|
2014-02-13 09:52:40 +00:00
|
|
|
|
2015-12-24 15:01:56 +00:00
|
|
|
return $.when(
|
2014-02-13 09:52:40 +00:00
|
|
|
imageInfoPromise, repoInfoPromise
|
2015-01-23 12:48:27 +00:00
|
|
|
).then( function ( imageInfo, repoInfoHash ) {
|
2016-07-18 13:49:27 +00:00
|
|
|
return $.Deferred().resolve( imageInfo, repoInfoHash[ imageInfo.repo ] );
|
2014-02-03 20:42:17 +00:00
|
|
|
} );
|
2013-09-26 01:47:59 +00:00
|
|
|
};
|
|
|
|
|
2014-04-09 23:59:49 +00:00
|
|
|
/**
|
|
|
|
* Loads size-dependent components of a lightbox - the thumbnail model and the image itself.
|
2016-07-18 13:49:27 +00:00
|
|
|
*
|
2014-04-09 23:59:49 +00:00
|
|
|
* @param {mw.mmv.LightboxImage} image
|
|
|
|
* @param {number} width the width of the requested thumbnail
|
2014-12-02 10:05:12 +00:00
|
|
|
* @param {jQuery.Deferred.<string>} [extraStatsDeferred] Promise that resolves to the image's upload timestamp when the metadata is loaded
|
2016-07-18 13:49:27 +00:00
|
|
|
* @return {jQuery.Promise.<mw.mmv.model.Thumbnail, HTMLImageElement>}
|
2014-04-09 23:59:49 +00:00
|
|
|
*/
|
2014-12-02 10:05:12 +00:00
|
|
|
MMVP.fetchThumbnailForLightboxImage = function ( image, width, extraStatsDeferred ) {
|
2014-04-09 23:59:49 +00:00
|
|
|
return this.fetchThumbnail(
|
|
|
|
image.filePageTitle,
|
|
|
|
width,
|
2014-04-10 01:08:36 +00:00
|
|
|
image.src,
|
2014-04-09 23:59:49 +00:00
|
|
|
image.originalWidth,
|
2014-12-02 10:05:12 +00:00
|
|
|
image.originalHeight,
|
|
|
|
extraStatsDeferred
|
2014-04-09 23:59:49 +00:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2014-01-30 11:28:43 +00:00
|
|
|
/**
|
2014-02-13 09:52:40 +00:00
|
|
|
* Loads size-dependent components of a lightbox - the thumbnail model and the image itself.
|
2016-07-18 13:49:27 +00:00
|
|
|
*
|
2014-02-13 09:52:40 +00:00
|
|
|
* @param {mw.Title} fileTitle
|
2014-04-09 23:59:49 +00:00
|
|
|
* @param {number} width the width of the requested thumbnail
|
2014-04-10 01:08:36 +00:00
|
|
|
* @param {string} [sampleUrl] a thumbnail URL for the same file (but with different size) (might be missing)
|
2014-04-09 23:59:49 +00:00
|
|
|
* @param {number} [originalWidth] the width of the original, full-sized file (might be missing)
|
|
|
|
* @param {number} [originalHeight] the height of the original, full-sized file (might be missing)
|
2014-12-02 10:05:12 +00:00
|
|
|
* @param {jQuery.Deferred.<string>} [extraStatsDeferred] Promise that resolves to the image's upload timestamp when the metadata is loaded
|
2016-07-18 13:49:27 +00:00
|
|
|
* @return {jQuery.Promise.<mw.mmv.model.Thumbnail, HTMLImageElement>} A promise resolving to
|
Refactor progressbar & blur handling
This tries to fix a number of related issues:
* the blurred thumbnail was visible for a split-second sometimes
when switching back to an already-loaded image. (Presumably when
JS was sluggish enough to take more than 10 ms to execute.) We
now check whether the promise is pending before showing a placeholder.
(More generally, a lot of unnecessary logic was executed when paging
through already loaded images, like displaying the placeholder, so
this might make the UI a bit more responsive.)
* the blur could get stuck sometimes - I have seen this a few times,
but have never been able to reproduce it, so I'm only guessing, but
maybe the timing was really unfortunate, and we switched back less
than 10 ms before loading finished. We now remove the blur on every
branch, just to be sure.
* adding a progress handler to a promise might not have any immediate
effect, so when switching to an image which was loading, the progress
bar reacted too late. We now store the progress state per thumbnail
so it is always available immediately.
* the progress would animate from 0 to its actual state whenever we
navigated to the image. The change on paging is now instant; the
progress bar only animates when we are looking at it.
* switching quickly back and forthe between a loaded and a loading
image resulted in the loading image becoming unblurred. This seems
fixed now, I'm not sure why. Maybe the "skip on non-pending promise"
logic affects it somehow.
Also removes some unused things / renames some things which were
confusing, and makes an unrelated fix in the image provider, which kept
amassing fail handlers.
Change-Id: I580becff246f197ec1bc65e82acd422620e35578
Mingle: https://wikimedia.mingle.thoughtworks.com/projects/multimedia/cards/489
2014-04-25 22:26:34 +00:00
|
|
|
* a thumbnail model and an <img> element. It might or might not have progress events which
|
|
|
|
* return a single number.
|
2014-01-30 11:28:43 +00:00
|
|
|
*/
|
2014-12-02 10:05:12 +00:00
|
|
|
MMVP.fetchThumbnail = function ( fileTitle, width, sampleUrl, originalWidth, originalHeight, extraStatsDeferred ) {
|
2014-05-15 20:24:40 +00:00
|
|
|
var viewer = this,
|
2014-04-10 01:08:36 +00:00
|
|
|
guessing = false,
|
2017-05-11 15:03:52 +00:00
|
|
|
combinedDeferred = $.Deferred(),
|
2014-05-15 20:24:40 +00:00
|
|
|
thumbnailPromise,
|
|
|
|
imagePromise;
|
2014-02-13 09:52:40 +00:00
|
|
|
|
2018-11-22 15:17:40 +00:00
|
|
|
if ( fileTitle.ext.toLowerCase() !== 'svg' && originalWidth && width > originalWidth ) {
|
2014-04-15 00:01:03 +00:00
|
|
|
// Do not request images larger than the original image
|
|
|
|
width = originalWidth;
|
|
|
|
}
|
|
|
|
|
2014-04-10 01:08:36 +00:00
|
|
|
if (
|
|
|
|
sampleUrl && originalWidth && originalHeight &&
|
2016-04-03 09:18:26 +00:00
|
|
|
this.config.useThumbnailGuessing()
|
2014-04-10 01:08:36 +00:00
|
|
|
) {
|
|
|
|
guessing = true;
|
|
|
|
thumbnailPromise = this.guessedThumbnailInfoProvider.get(
|
|
|
|
fileTitle, sampleUrl, width, originalWidth, originalHeight
|
|
|
|
).then( null, function () { // catch rejection, use fallback
|
2014-09-26 18:37:53 +00:00
|
|
|
return viewer.thumbnailInfoProvider.get( fileTitle, width );
|
2014-04-10 01:08:36 +00:00
|
|
|
} );
|
|
|
|
} else {
|
|
|
|
thumbnailPromise = this.thumbnailInfoProvider.get( fileTitle, width );
|
|
|
|
}
|
2014-02-25 13:43:22 +00:00
|
|
|
|
2015-01-21 00:56:45 +00:00
|
|
|
// Add thumbnail width to the extra stats passed to the performance log
|
|
|
|
extraStatsDeferred = $.when( extraStatsDeferred || {} ).then( function ( extraStats ) {
|
|
|
|
extraStats.imageWidth = width;
|
|
|
|
return extraStats;
|
|
|
|
} );
|
|
|
|
|
2014-04-15 00:01:03 +00:00
|
|
|
imagePromise = thumbnailPromise.then( function ( thumbnail ) {
|
2014-12-02 10:05:12 +00:00
|
|
|
return viewer.imageProvider.get( thumbnail.url, extraStatsDeferred );
|
2014-01-30 11:28:43 +00:00
|
|
|
} );
|
2014-02-13 09:52:40 +00:00
|
|
|
|
2014-04-10 01:08:36 +00:00
|
|
|
if ( guessing ) {
|
|
|
|
// If we guessed wrong, need to retry with real URL on failure.
|
|
|
|
// As a side effect this introduces an extra (harmless) retry of a failed thumbnailInfoProvider.get call
|
|
|
|
// because thumbnailInfoProvider.get is already called above when guessedThumbnailInfoProvider.get fails.
|
|
|
|
imagePromise = imagePromise.then( null, function () {
|
|
|
|
return viewer.thumbnailInfoProvider.get( fileTitle, width ).then( function ( thumbnail ) {
|
2014-12-02 10:05:12 +00:00
|
|
|
return viewer.imageProvider.get( thumbnail.url, extraStatsDeferred );
|
2014-04-10 01:08:36 +00:00
|
|
|
} );
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
|
2017-05-11 15:03:52 +00:00
|
|
|
// In jQuery<3, $.when used to also relay notify, but that is no longer
|
|
|
|
// the case - but we still want to pass it along...
|
|
|
|
$.when( thumbnailPromise, imagePromise ).then( combinedDeferred.resolve, combinedDeferred.reject );
|
|
|
|
imagePromise.then( null, null, function ( arg, progress ) {
|
|
|
|
combinedDeferred.notify( progress );
|
Refactor progressbar & blur handling
This tries to fix a number of related issues:
* the blurred thumbnail was visible for a split-second sometimes
when switching back to an already-loaded image. (Presumably when
JS was sluggish enough to take more than 10 ms to execute.) We
now check whether the promise is pending before showing a placeholder.
(More generally, a lot of unnecessary logic was executed when paging
through already loaded images, like displaying the placeholder, so
this might make the UI a bit more responsive.)
* the blur could get stuck sometimes - I have seen this a few times,
but have never been able to reproduce it, so I'm only guessing, but
maybe the timing was really unfortunate, and we switched back less
than 10 ms before loading finished. We now remove the blur on every
branch, just to be sure.
* adding a progress handler to a promise might not have any immediate
effect, so when switching to an image which was loading, the progress
bar reacted too late. We now store the progress state per thumbnail
so it is always available immediately.
* the progress would animate from 0 to its actual state whenever we
navigated to the image. The change on paging is now instant; the
progress bar only animates when we are looking at it.
* switching quickly back and forthe between a loaded and a loading
image resulted in the loading image becoming unblurred. This seems
fixed now, I'm not sure why. Maybe the "skip on non-pending promise"
logic affects it somehow.
Also removes some unused things / renames some things which were
confusing, and makes an unrelated fix in the image provider, which kept
amassing fail handlers.
Change-Id: I580becff246f197ec1bc65e82acd422620e35578
Mingle: https://wikimedia.mingle.thoughtworks.com/projects/multimedia/cards/489
2014-04-25 22:26:34 +00:00
|
|
|
} );
|
2017-05-11 15:03:52 +00:00
|
|
|
return combinedDeferred;
|
2014-01-30 11:28:43 +00:00
|
|
|
};
|
|
|
|
|
2014-02-19 02:27:30 +00:00
|
|
|
/**
|
|
|
|
* Loads an image at a specified index in the viewer's thumbnail array.
|
2016-07-18 13:49:27 +00:00
|
|
|
*
|
2014-02-19 02:27:30 +00:00
|
|
|
* @param {number} index
|
|
|
|
*/
|
2013-11-26 03:37:01 +00:00
|
|
|
MMVP.loadIndex = function ( index ) {
|
2014-02-17 15:09:23 +00:00
|
|
|
var thumb;
|
|
|
|
|
|
|
|
if ( index < this.thumbs.length && index >= 0 ) {
|
2014-11-20 23:39:29 +00:00
|
|
|
this.viewLogger.recordViewDuration();
|
|
|
|
|
2014-02-17 15:09:23 +00:00
|
|
|
thumb = this.thumbs[ index ];
|
2016-07-18 13:49:27 +00:00
|
|
|
this.loadImage( thumb.image, thumb.$thumb.clone()[ 0 ] );
|
2013-11-26 03:37:01 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-02-11 13:25:39 +00:00
|
|
|
/**
|
|
|
|
* Opens the next image
|
|
|
|
*/
|
2013-11-26 03:37:01 +00:00
|
|
|
MMVP.nextImage = function () {
|
2014-05-19 09:24:54 +00:00
|
|
|
mw.mmv.actionLogger.log( 'next-image' );
|
2014-03-05 02:24:18 +00:00
|
|
|
this.loadIndex( this.currentIndex + 1 );
|
2013-11-26 03:37:01 +00:00
|
|
|
};
|
|
|
|
|
2014-02-11 13:25:39 +00:00
|
|
|
/**
|
|
|
|
* Opens the previous image
|
|
|
|
*/
|
2013-11-26 03:37:01 +00:00
|
|
|
MMVP.prevImage = function () {
|
2014-05-19 09:24:54 +00:00
|
|
|
mw.mmv.actionLogger.log( 'prev-image' );
|
2014-03-05 02:24:18 +00:00
|
|
|
this.loadIndex( this.currentIndex - 1 );
|
2013-11-26 03:37:01 +00:00
|
|
|
};
|
|
|
|
|
2014-02-11 13:25:39 +00:00
|
|
|
/**
|
|
|
|
* Handles close event coming from the lightbox
|
|
|
|
*/
|
|
|
|
MMVP.close = function () {
|
2014-11-15 15:32:04 +00:00
|
|
|
var windowTitle;
|
|
|
|
|
2014-11-20 23:39:29 +00:00
|
|
|
this.viewLogger.recordViewDuration();
|
|
|
|
this.viewLogger.unattach();
|
2014-11-15 15:32:04 +00:00
|
|
|
|
|
|
|
windowTitle = this.createDocumentTitle( null );
|
2014-07-01 22:22:06 +00:00
|
|
|
|
2014-02-24 09:29:14 +00:00
|
|
|
if ( comingFromHashChange === false ) {
|
2016-07-18 13:49:27 +00:00
|
|
|
$( document ).trigger( $.Event( 'mmv-hash', { hash: '#', title: windowTitle } ) );
|
2014-02-11 13:25:39 +00:00
|
|
|
} else {
|
2014-02-24 09:29:14 +00:00
|
|
|
comingFromHashChange = false;
|
2014-02-11 13:25:39 +00:00
|
|
|
}
|
|
|
|
|
2014-04-11 09:31:38 +00:00
|
|
|
// This has to happen after the hash reset, because setting the hash to # will reset the page scroll
|
|
|
|
$( document ).trigger( $.Event( 'mmv-cleanup-overlay' ) );
|
|
|
|
|
2014-02-11 13:25:39 +00:00
|
|
|
this.isOpen = false;
|
|
|
|
};
|
|
|
|
|
2014-02-17 15:09:23 +00:00
|
|
|
/**
|
2014-02-21 11:16:30 +00:00
|
|
|
* Handles a hash change coming from the browser
|
2014-02-17 15:09:23 +00:00
|
|
|
*/
|
2014-02-21 11:16:30 +00:00
|
|
|
MMVP.hash = function () {
|
2014-04-14 23:22:28 +00:00
|
|
|
var route = this.router.parseLocation( window.location );
|
2014-02-21 11:16:30 +00:00
|
|
|
|
2014-04-14 23:22:28 +00:00
|
|
|
if ( route instanceof mw.mmv.routing.ThumbnailRoute ) {
|
2014-07-01 22:22:06 +00:00
|
|
|
document.title = this.createDocumentTitle( route.fileTitle );
|
2014-04-14 23:22:28 +00:00
|
|
|
this.loadImageByTitle( route.fileTitle );
|
2014-02-21 11:16:30 +00:00
|
|
|
} else if ( this.isOpen ) {
|
2014-04-11 09:31:38 +00:00
|
|
|
// This allows us to avoid the mmv-hash event that normally happens on close
|
2014-02-24 09:29:14 +00:00
|
|
|
comingFromHashChange = true;
|
2014-02-21 11:16:30 +00:00
|
|
|
|
2014-07-01 22:22:06 +00:00
|
|
|
document.title = this.createDocumentTitle( null );
|
2014-03-05 02:24:18 +00:00
|
|
|
if ( this.ui ) {
|
|
|
|
// FIXME triggers mmv-close event, which calls viewer.close()
|
|
|
|
this.ui.unattach();
|
2014-02-21 11:16:30 +00:00
|
|
|
} else {
|
|
|
|
this.close();
|
|
|
|
}
|
2014-02-17 15:09:23 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-01-23 12:48:27 +00:00
|
|
|
MMVP.setHash = function () {
|
2014-07-01 22:22:06 +00:00
|
|
|
var route, windowTitle, hashFragment;
|
2014-03-04 12:52:08 +00:00
|
|
|
if ( !this.comingFromHashChange ) {
|
2014-04-14 23:22:28 +00:00
|
|
|
route = new mw.mmv.routing.ThumbnailRoute( this.currentImageFileTitle );
|
|
|
|
hashFragment = '#' + this.router.createHash( route );
|
2014-07-01 22:22:06 +00:00
|
|
|
windowTitle = this.createDocumentTitle( this.currentImageFileTitle );
|
2016-07-18 13:49:27 +00:00
|
|
|
$( document ).trigger( $.Event( 'mmv-hash', { hash: hashFragment, title: windowTitle } ) );
|
2014-07-01 22:22:06 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a string which can be shown as document title (the text at the top of the browser window).
|
2016-07-18 13:49:27 +00:00
|
|
|
*
|
2014-07-01 22:22:06 +00:00
|
|
|
* @param {mw.Title|null} imageTitle the title object for the image which is displayed; null when the
|
|
|
|
* viewer is being closed
|
|
|
|
* @return {string}
|
|
|
|
*/
|
|
|
|
MMVP.createDocumentTitle = function ( imageTitle ) {
|
|
|
|
if ( imageTitle ) {
|
|
|
|
return imageTitle.getNameText() + ' - ' + this.documentTitle;
|
|
|
|
} else {
|
|
|
|
return this.documentTitle;
|
2014-03-04 12:52:08 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-04-08 09:54:30 +00:00
|
|
|
/**
|
|
|
|
* @event mmv-close
|
2014-04-11 09:31:38 +00:00
|
|
|
* Fired when the viewer is closed. This is used by the ligthbox to notify the main app.
|
2014-04-08 09:54:30 +00:00
|
|
|
*/
|
|
|
|
/**
|
|
|
|
* @event mmv-next
|
|
|
|
* Fired when the user requests the next image.
|
|
|
|
*/
|
|
|
|
/**
|
|
|
|
* @event mmv-prev
|
|
|
|
* Fired when the user requests the previous image.
|
|
|
|
*/
|
|
|
|
/**
|
2014-09-30 14:16:08 +00:00
|
|
|
* @event mmv-resize-end
|
|
|
|
* Fired when the screen size changes. Debounced to avoid continous triggering while resizing with a mouse.
|
2014-04-08 09:54:30 +00:00
|
|
|
*/
|
|
|
|
/**
|
|
|
|
* @event mmv-request-thumbnail
|
|
|
|
* Used by components to request a thumbnail URL for the current thumbnail, with a given size.
|
|
|
|
* @param {number} size
|
|
|
|
*/
|
2014-02-19 02:27:30 +00:00
|
|
|
/**
|
2014-02-21 11:16:30 +00:00
|
|
|
* Registers all event handlers
|
2014-02-19 02:27:30 +00:00
|
|
|
*/
|
2014-02-11 13:25:39 +00:00
|
|
|
MMVP.setupEventHandlers = function () {
|
2014-02-11 01:12:31 +00:00
|
|
|
var viewer = this;
|
|
|
|
|
2015-09-25 19:55:00 +00:00
|
|
|
this.ui.connect( this, {
|
2016-07-18 13:49:27 +00:00
|
|
|
next: 'nextImage',
|
|
|
|
prev: 'prevImage'
|
2015-09-25 19:55:00 +00:00
|
|
|
} );
|
|
|
|
|
2014-02-21 11:16:30 +00:00
|
|
|
$( document ).on( 'mmv-close.mmvp', function () {
|
2014-02-11 13:25:39 +00:00
|
|
|
viewer.close();
|
2014-09-30 14:16:08 +00:00
|
|
|
} ).on( 'mmv-resize-end.mmvp', function () {
|
2014-03-05 02:24:18 +00:00
|
|
|
viewer.resize( viewer.ui );
|
2014-03-19 03:05:36 +00:00
|
|
|
} ).on( 'mmv-request-thumbnail.mmvp', function ( e, size ) {
|
|
|
|
if ( viewer.currentImageFileTitle ) {
|
|
|
|
return viewer.thumbnailInfoProvider.get( viewer.currentImageFileTitle, size );
|
|
|
|
} else {
|
|
|
|
return $.Deferred().reject();
|
|
|
|
}
|
2014-06-10 20:39:10 +00:00
|
|
|
} ).on( 'mmv-viewfile.mmvp', function () {
|
|
|
|
viewer.imageInfoProvider.get( viewer.currentImageFileTitle ).done( function ( imageInfo ) {
|
|
|
|
document.location = imageInfo.url;
|
|
|
|
} );
|
2014-03-17 08:07:53 +00:00
|
|
|
} );
|
2014-02-11 01:12:31 +00:00
|
|
|
};
|
|
|
|
|
2014-03-04 11:53:53 +00:00
|
|
|
/**
|
|
|
|
* Unregisters all event handlers. Currently only used in tests.
|
|
|
|
*/
|
2014-04-11 14:05:58 +00:00
|
|
|
MMVP.cleanupEventHandlers = function () {
|
2015-09-25 19:55:00 +00:00
|
|
|
$( document ).off( 'mmv-close.mmvp mmv-resize-end.mmvp' );
|
|
|
|
|
|
|
|
this.ui.disconnect( this );
|
2014-03-04 11:53:53 +00:00
|
|
|
};
|
|
|
|
|
2014-04-11 14:05:58 +00:00
|
|
|
/**
|
|
|
|
* Preloads JS and CSS dependencies that aren't needed to display the first image, but could be needed later
|
|
|
|
*/
|
|
|
|
MMVP.preloadDependencies = function () {
|
2015-06-24 18:54:22 +00:00
|
|
|
mw.loader.load( [ 'mmv.ui.reuse.shareembed', 'moment' ] );
|
2014-04-11 14:05:58 +00:00
|
|
|
};
|
|
|
|
|
2016-04-03 09:18:26 +00:00
|
|
|
/**
|
|
|
|
* Loads the RL module defined for a given file extension, if any
|
2016-07-18 13:49:27 +00:00
|
|
|
*
|
2016-04-03 09:18:26 +00:00
|
|
|
* @param {string} extension File extension
|
2016-07-18 13:49:27 +00:00
|
|
|
* @return {jQuery.Promise}
|
2016-04-03 09:18:26 +00:00
|
|
|
*/
|
|
|
|
MMVP.loadExtensionPlugins = function ( extension ) {
|
|
|
|
var deferred = $.Deferred(),
|
|
|
|
config = this.config.extensions();
|
|
|
|
|
|
|
|
if ( !( extension in config ) || config[ extension ] === 'default' ) {
|
|
|
|
return deferred.resolve();
|
|
|
|
}
|
|
|
|
|
2016-07-18 13:49:27 +00:00
|
|
|
mw.loader.using( config[ extension ], function () {
|
2016-04-03 09:18:26 +00:00
|
|
|
deferred.resolve();
|
|
|
|
} );
|
|
|
|
|
|
|
|
return deferred;
|
|
|
|
};
|
|
|
|
|
2014-02-25 02:28:49 +00:00
|
|
|
mw.mmv.MultimediaViewer = MultimediaViewer;
|
2018-11-12 16:33:24 +00:00
|
|
|
}() );
|