mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/MultimediaViewer
synced 2024-11-24 08:13:38 +00:00
Refactor animation, plus test
Change-Id: I688c573b7fbd136782177f0b690d3aab994c6d10
This commit is contained in:
parent
29b1efe9b8
commit
9b28edb1be
|
@ -608,9 +608,7 @@
|
|||
imageEle = new Image(),
|
||||
targetWidth = size;
|
||||
|
||||
if ( !viewer.hasAnimatedMetadata ) {
|
||||
viewer.animateMetadataDiv();
|
||||
}
|
||||
viewer.animateMetadataDivOnce();
|
||||
|
||||
imageEle.onload = function () {
|
||||
if ( imageEle.width > targetWidth ) {
|
||||
|
@ -639,10 +637,12 @@
|
|||
comingFromPopstate = false;
|
||||
};
|
||||
|
||||
MMVP.animateMetadataDiv = function () {
|
||||
$.scrollTo( 40, 400, { onAfter: function() { $.scrollTo( 0, 400 ); } } );
|
||||
MMVP.animateMetadataDivOnce = function () {
|
||||
if ( !this.hasAnimatedMetadata ) {
|
||||
$.scrollTo( 40, 400, { onAfter: function() { $.scrollTo( 0, 400 ); } } );
|
||||
|
||||
this.hasAnimatedMetadata = true;
|
||||
this.hasAnimatedMetadata = true;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
@ -255,4 +255,26 @@
|
|||
assert.strictEqual( viewer.findNextHighestImageSize( 3000 ), 2880, 'The image bucketing also works on REALLY big screens' );
|
||||
} );
|
||||
|
||||
QUnit.test( 'Metadata div is only animated once', 4, function ( assert ) {
|
||||
var viewer = new mw.MultimediaViewer(),
|
||||
backupAnimation = $.fn.animate,
|
||||
animationRan = false;
|
||||
|
||||
$.fn.animate = function () {
|
||||
animationRan = true;
|
||||
return this;
|
||||
};
|
||||
|
||||
viewer.animateMetadataDivOnce();
|
||||
assert.strictEqual( viewer.hasAnimatedMetadata, true, 'The first call to animateMetadataDivOnce set hasAnimatedMetadata to true' );
|
||||
assert.strictEqual( animationRan, true, 'The first call to animateMetadataDivOnce led to an animation' );
|
||||
|
||||
animationRan = false;
|
||||
viewer.animateMetadataDivOnce();
|
||||
assert.strictEqual( viewer.hasAnimatedMetadata, true, 'The second call to animateMetadataDivOnce did not change the value of hasAnimatedMetadata' );
|
||||
assert.strictEqual( animationRan, false, 'The second call to animateMetadataDivOnce did not lead to an animation' );
|
||||
|
||||
$.fn.animate = backupAnimation;
|
||||
} );
|
||||
|
||||
}( mediaWiki, jQuery ) );
|
||||
|
|
Loading…
Reference in a new issue