Reanimate metadata panel when viewer is reopened

Change-Id: I776a27358b2da17a35234aa8cb649a49df4a651d
Mingle: https://wikimedia.mingle.thoughtworks.com/projects/multimedia/cards/548
This commit is contained in:
Gergő Tisza 2014-05-01 01:12:12 +00:00 committed by Gilles Dubuc
parent 5f7af0cede
commit 88f766bfc3
2 changed files with 16 additions and 3 deletions

View file

@ -37,11 +37,11 @@
this.localStorage = localStorage; this.localStorage = localStorage;
/** /**
* Whether we've fired an animation for the metadata div. * Whether we've already fired an animation for the metadata div in this lightbox session.
* @property {boolean} * @property {boolean}
* @private * @private
*/ */
this.hasAnimatedMetadata = !this.localStorage || this.localStorage.getItem( 'mmv.hasOpenedMetadata' ); this.hasAnimatedMetadata = undefined;
/** @property {mw.mmv.HtmlUtils} htmlUtils - */ /** @property {mw.mmv.HtmlUtils} htmlUtils - */
this.htmlUtils = new mw.mmv.HtmlUtils(); this.htmlUtils = new mw.mmv.HtmlUtils();
@ -67,6 +67,9 @@
this.buttons.attach(); this.buttons.attach();
this.fileReuse.attach(); this.fileReuse.attach();
// reset animation flag when the viewer is reopened
this.hasAnimatedMetadata = !this.localStorage || this.localStorage.getItem( 'mmv.hasOpenedMetadata' );
}; };
MPP.unattach = function() { MPP.unattach = function() {

View file

@ -210,7 +210,7 @@
} ); } );
QUnit.test( 'Metadata div is only animated once', 4, function ( assert ) { QUnit.test( 'Metadata div is only animated once', 5, function ( assert ) {
var $qf = $( '#qunit-fixture' ), var $qf = $( '#qunit-fixture' ),
displayCount, displayCount,
panel = new mw.mmv.ui.MetadataPanel( $qf, $( '<div>' ).appendTo( $qf ), { panel = new mw.mmv.ui.MetadataPanel( $qf, $( '<div>' ).appendTo( $qf ), {
@ -219,6 +219,8 @@
setItem: function ( _, val ) { displayCount = val; } setItem: function ( _, val ) { displayCount = val; }
} ); } );
panel.attach();
panel.animateMetadataOnce(); panel.animateMetadataOnce();
assert.ok( panel.hasAnimatedMetadata, assert.ok( panel.hasAnimatedMetadata,
@ -233,6 +235,14 @@
assert.strictEqual( panel.hasAnimatedMetadata, true, 'The second call to animateMetadataOnce did not change the value of hasAnimatedMetadata' ); assert.strictEqual( panel.hasAnimatedMetadata, true, 'The second call to animateMetadataOnce did not change the value of hasAnimatedMetadata' );
assert.ok( !$qf.hasClass( 'invite' ), assert.ok( !$qf.hasClass( 'invite' ),
'The second call to animateMetadataOnce did not lead to an animation' ); 'The second call to animateMetadataOnce did not lead to an animation' );
panel.unattach();
panel.attach();
panel.animateMetadataOnce();
assert.ok( $qf.hasClass( 'invite' ),
'After closing and opening the viewer, the panel is animated again' );
} ); } );
QUnit.test( 'Repo icon', 4, function ( assert ) { QUnit.test( 'Repo icon', 4, function ( assert ) {