mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/MultimediaViewer
synced 2024-12-01 03:06:17 +00:00
fec24e02f7
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
91 lines
2.7 KiB
JavaScript
91 lines
2.7 KiB
JavaScript
/*
|
|
* This file is part of the MediaWiki extension MediaViewer.
|
|
*
|
|
* MediaViewer 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.
|
|
*
|
|
* MediaViewer 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 MediaViewer. If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
( function( mw, $, oo ) {
|
|
var PBP;
|
|
|
|
/**
|
|
* @class mw.mmv.ui.ProgressBar
|
|
* @extends mw.mmv.ui.Element
|
|
* A progress bar for the loading of the image.
|
|
* @constructor
|
|
* @param {jQuery} $container
|
|
*/
|
|
function ProgressBar( $container ) {
|
|
mw.mmv.ui.Element.call( this, $container );
|
|
this.init();
|
|
}
|
|
oo.inheritClass( ProgressBar, mw.mmv.ui.Element );
|
|
PBP = ProgressBar.prototype;
|
|
|
|
/**
|
|
* Initializes the progress display at the top of the panel.
|
|
*/
|
|
PBP.init = function () {
|
|
this.$progress = $( '<div>' )
|
|
.addClass( 'mw-mmv-progress empty' )
|
|
.appendTo( this.$container );
|
|
this.$percent = $( '<div>' )
|
|
.addClass( 'mw-mmv-progress-percent' )
|
|
.appendTo( this.$progress );
|
|
};
|
|
|
|
PBP.empty = function () {
|
|
this.hide();
|
|
};
|
|
|
|
/**
|
|
* Hides the bar, resets it to 0 and stops any animation in progress.
|
|
*/
|
|
PBP.hide = function () {
|
|
this.$progress.addClass( 'empty' );
|
|
this.$percent.stop().css( { width : 0 } );
|
|
};
|
|
|
|
/**
|
|
* Handles the progress display when a percentage of progress is received
|
|
* @param {number} percent a number between 0 and 100
|
|
*/
|
|
PBP.animateTo = function ( percent ) {
|
|
var panel = this;
|
|
|
|
this.$progress.removeClass( 'empty' );
|
|
this.$percent.stop();
|
|
|
|
if ( percent === 100 ) {
|
|
// When a 100% update comes in, we make sure that the bar is visible, we animate
|
|
// fast to 100 and we hide the bar when the animation is done
|
|
this.$percent.animate( { width : percent + '%' }, 50, 'swing', $.proxy( panel.hide, panel ) );
|
|
} else {
|
|
// When any other % update comes in, we make sure the bar is visible
|
|
// and we animate to the right position
|
|
this.$percent.animate( { width : percent + '%' } );
|
|
}
|
|
};
|
|
|
|
/**
|
|
* Goes to the given percent without animation
|
|
* @param {number} percent a number between 0 and 100
|
|
*/
|
|
PBP.jumpTo = function ( percent ) {
|
|
this.$progress.removeClass( 'empty' );
|
|
this.$percent.stop().css( { width : percent + '%' } );
|
|
};
|
|
|
|
mw.mmv.ui.ProgressBar = ProgressBar;
|
|
}( mediaWiki, jQuery, OO ) );
|