jenkins-bot has submitted this change and it was merged.
Change subject: Move clearInterface things to mw.LightboxInterface
......................................................................
Move clearInterface things to mw.LightboxInterface
Also fixes a bug where we didn't clear our arrow key listeners, and VE
would sometimes see lightbox loads accidentally.
+tests for .empty()
Bug: 58107
Change-Id: Ica8326891b2da1f94966dbe72c28e878934ca64f
---
M resources/ext.multimediaViewer/ext.multimediaViewer.js
M resources/ext.multimediaViewer/ext.multimediaViewer.lightboxinterface.js
M tests/qunit/lightboxinterface.test.js
3 files changed, 76 insertions(+), 29 deletions(-)
Approvals:
MarkTraceur: Looks good to me, approved
Aarcos: Looks good to me, but someone else must approve
jenkins-bot: Verified
diff --git a/resources/ext.multimediaViewer/ext.multimediaViewer.js
b/resources/ext.multimediaViewer/ext.multimediaViewer.js
index f58c1b4..4812cc0 100755
--- a/resources/ext.multimediaViewer/ext.multimediaViewer.js
+++ b/resources/ext.multimediaViewer/ext.multimediaViewer.js
@@ -166,32 +166,6 @@
this.$imageMetadata.show();
}
} );
-
- lightboxHooks.register( 'clearInterface', function () {
- this.$license.empty().addClass( 'empty' );
-
- this.$imageDesc.empty();
- this.$imageDescDiv.addClass( 'empty' );
- this.$title.empty();
- this.$credit.empty().addClass( 'empty' );
-
- this.$username.empty();
- this.$usernameLi.addClass( 'empty' );
-
- this.$repo.empty();
- this.$repoLi.addClass( 'empty' );
-
- this.$datetime.empty();
- this.$datetimeLi.addClass( 'empty' );
-
- this.$useFile.data( 'title', null );
- this.$useFile.data( 'link', null );
- this.$useFile.data( 'src', null );
- this.$useFile.data( 'isLocal', null );
- this.$useFileLi.addClass( 'empty' );
-
- this.$imageDiv.addClass( 'empty' );
- } );
}
MMVP = MultimediaViewer.prototype;
diff --git
a/resources/ext.multimediaViewer/ext.multimediaViewer.lightboxinterface.js
b/resources/ext.multimediaViewer/ext.multimediaViewer.lightboxinterface.js
index 24ccad7..e650e8f 100644
--- a/resources/ext.multimediaViewer/ext.multimediaViewer.lightboxinterface.js
+++ b/resources/ext.multimediaViewer/ext.multimediaViewer.lightboxinterface.js
@@ -34,6 +34,40 @@
LIP = LightboxInterface.prototype;
+ LIP.empty = function () {
+ if ( this.handleKeyDown ) {
+ // Clear events on document
+ $( document ).off( 'keydown', this.handleKeyDown );
+ this.handleKeyDown = undefined;
+ }
+
+ this.$license.empty().addClass( 'empty' );
+
+ this.$imageDesc.empty();
+ this.$imageDescDiv.addClass( 'empty' );
+ this.$title.empty();
+ this.$credit.empty().addClass( 'empty' );
+
+ this.$username.empty();
+ this.$usernameLi.addClass( 'empty' );
+
+ this.$repo.empty();
+ this.$repoLi.addClass( 'empty' );
+
+ this.$datetime.empty();
+ this.$datetimeLi.addClass( 'empty' );
+
+ this.$useFile.data( 'title', null );
+ this.$useFile.data( 'link', null );
+ this.$useFile.data( 'src', null );
+ this.$useFile.data( 'isLocal', null );
+ this.$useFileLi.addClass( 'empty' );
+
+ this.$imageDiv.addClass( 'empty' );
+
+ MLBInterface.prototype.empty.call( this );
+ };
+
LIP.load = function ( image ) {
var hashFragment = '#mediaviewer/' +
mw.mediaViewer.currentImageFilename + '/' +
mw.mediaViewer.lightbox.currentIndex;
@@ -354,7 +388,7 @@
};
LIP.initializeNavigation = function () {
- function handleKeyDown( e ) {
+ this.handleKeyDown = this.handleKeyDown || function ( e ) {
var isRtl = $( document.body ).hasClass( 'rtl' );
switch ( e.keyCode ) {
@@ -375,7 +409,7 @@
}
break;
}
- }
+ };
this.$nextButton = $( '<div>' )
.addClass( 'mw-mlb-next-image disabled' )
@@ -393,7 +427,7 @@
} )
.appendTo( this.$main );
- $( document ).off( 'keydown', handleKeyDown ).on( 'keydown',
handleKeyDown );
+ $( document ).off( 'keydown', this.handleKeyDown ).on(
'keydown', this.handleKeyDown );
};
// We are overwriting what is already set in window.LightboxInterface,
shouldn't it be 'mw.LightboxInterface' ???
diff --git a/tests/qunit/lightboxinterface.test.js
b/tests/qunit/lightboxinterface.test.js
index 0d1f1a0..c1a36e3 100644
--- a/tests/qunit/lightboxinterface.test.js
+++ b/tests/qunit/lightboxinterface.test.js
@@ -1,4 +1,25 @@
( function ( mw, $ ) {
+ var thingsShouldBeEmptied = [
+ '$license',
+ '$imageDesc',
+ '$title',
+ '$credit',
+ '$username',
+ '$repo',
+ '$datetime'
+ ],
+
+ thingsShouldHaveEmptyClass = [
+ '$license',
+ '$imageDescDiv',
+ '$credit',
+ '$usernameLi',
+ '$repoLi',
+ '$datetimeLi',
+ '$useFileLi',
+ '$imageDiv'
+ ];
+
QUnit.module( 'ext.multimediaViewer.lightboxInterface',
QUnit.newMwEnvironment() );
QUnit.test( 'Sanity test, object creation and ui construction', 9,
function ( assert ) {
@@ -50,4 +71,22 @@
lightbox.load(img);
} );
+ QUnit.test( 'The interface is emptied properly when necessary',
thingsShouldBeEmptied.length + thingsShouldHaveEmptyClass.length + 2, function
( assert ) {
+ var i,
+ lightbox = new window.LightboxInterface();
+
+ assert.notStrictEqual( lightbox.handleKeyDown, undefined, 'The
keydown handler is present before empty() gets called' );
+
+ lightbox.empty();
+
+ for ( i = 0; i < thingsShouldBeEmptied.length; i++ ) {
+ assert.strictEqual(
lightbox[thingsShouldBeEmptied[i]].text(), '', 'We successfully emptied the ' +
thingsShouldBeEmptied[i] + ' element' );
+ }
+
+ for ( i = 0; i < thingsShouldHaveEmptyClass.length; i++ ) {
+ assert.strictEqual(
lightbox[thingsShouldHaveEmptyClass[i]].hasClass( 'empty' ), true, 'We
successfully applied the empty class to the ' + thingsShouldHaveEmptyClass[i] +
' element' );
+ }
+
+ assert.strictEqual( lightbox.handleKeyDown, undefined, 'The
keydown handler got removed' );
+ } );
}( mediaWiki, jQuery ) );
--
To view, visit https://gerrit.wikimedia.org/r/99722
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Ica8326891b2da1f94966dbe72c28e878934ca64f
Gerrit-PatchSet: 6
Gerrit-Project: mediawiki/extensions/MultimediaViewer
Gerrit-Branch: master
Gerrit-Owner: MarkTraceur <[email protected]>
Gerrit-Reviewer: Aarcos <[email protected]>
Gerrit-Reviewer: MarkTraceur <[email protected]>
Gerrit-Reviewer: jenkins-bot
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits