Gergő Tisza has uploaded a new change for review. https://gerrit.wikimedia.org/r/115335
Change subject: Namespace MMV properly ...................................................................... Namespace MMV properly Everything is under mw.mmv now. (Also, I cut down on the number of direct global instance references a bit.) Change-Id: I88bb3b62b82ce54126dd069b0aab4412d9404719 --- M MultimediaViewer.php M resources/mmv/mmv.bootstrap.js M resources/mmv/mmv.js M resources/mmv/mmv.lightboximage.js M resources/mmv/mmv.lightboxinterface.js M resources/mmv/mmv.multilightbox.js M resources/mmv/ui/mmv.ui.metadataPanel.js M tests/qunit/mmv/mmv.bootstrap.test.js M tests/qunit/mmv/mmv.lightboximage.test.js M tests/qunit/mmv/mmv.lightboxinterface.test.js M tests/qunit/mmv/mmv.multilightbox.test.js M tests/qunit/mmv/mmv.test.js M tests/qunit/mmv/mmv.testhelpers.js 13 files changed, 118 insertions(+), 107 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/MultimediaViewer refs/changes/35/115335/1 diff --git a/MultimediaViewer.php b/MultimediaViewer.php index 1319a59..2515417 100644 --- a/MultimediaViewer.php +++ b/MultimediaViewer.php @@ -39,13 +39,16 @@ return array( 'localBasePath' => __DIR__ . "/resources/$path", 'remoteExtPath' => "MultimediaViewer/resources/$path", - ); }; $wgResourceModules['mmv.lightboximage'] = array_merge( array( 'scripts' => array( 'mmv.lightboximage.js', + ), + + 'dependencies' => array( + 'mmv.base', ), ), $moduleInfo( 'mmv' ) ); @@ -55,6 +58,7 @@ ), 'dependencies' => array( + 'mmv.base', 'mmv.ui.buttons', 'mmv.ui.categories', 'mmv.ui.description', @@ -99,6 +103,7 @@ ), 'dependencies' => array( + 'mmv.base', 'mmv.lightboxinterface', ), ), $moduleInfo( 'mmv' ) ); diff --git a/resources/mmv/mmv.bootstrap.js b/resources/mmv/mmv.bootstrap.js index bc45b10..dfe7a8d 100755 --- a/resources/mmv/mmv.bootstrap.js +++ b/resources/mmv/mmv.bootstrap.js @@ -70,10 +70,10 @@ deferred.reject( error.message ); } ); - return $.when( deferred ).then( function () { + return deferred.done( function ( viewer ) { if ( !bs.viewerInitialized ) { if ( bs.thumbs.length ) { - mw.mediaViewer.initWithThumbs( bs.thumbs ); + viewer.initWithThumbs( bs.thumbs ); } bs.viewerInitialized = true; @@ -84,7 +84,7 @@ /** * Checks if the mmv CSS has been correctly added to the page * This is a workaround for core bug 61852 - * @param {jQuery.Promise} deferred + * @param {jQuery.Promise.<mw.mmv.MultimediaViewer>} deferred */ MMVB.isCSSReady = function ( deferred ) { var $dummy = $( '<div class="' + this.readinessCSSClass + '">' ) @@ -94,7 +94,7 @@ if ( $dummy.css( 'display' ) === 'inline' ) { // Let's be clean and remove the test item before resolving the deferred $dummy.remove(); - deferred.resolve(); + deferred.resolve( mw.mmv.mediaViewer ); } else { $dummy.remove(); setTimeout( function () { bs.isCSSReady( deferred ); }, this.readinessWaitDuration ); @@ -179,8 +179,8 @@ mw.mmv.logger.log( 'enlarge-link-click' ); } - this.loadViewer().then( function () { - mw.mediaViewer.loadImageByTitle( title.getPrefixedText(), true ); + this.loadViewer().then( function ( viewer ) { + viewer.loadImageByTitle( title.getPrefixedText(), true ); } ); e.preventDefault(); @@ -203,8 +203,8 @@ return; } - this.loadViewer().then( function () { - mw.mediaViewer.hash(); + this.loadViewer().then( function ( viewer ) { + viewer.hash(); } ); }; diff --git a/resources/mmv/mmv.js b/resources/mmv/mmv.js index 880a2a8..5dc9cff 100755 --- a/resources/mmv/mmv.js +++ b/resources/mmv/mmv.js @@ -22,13 +22,13 @@ /** * Analyses the page, looks for image content and sets up the hooks * to manage the viewing experience of such content. - * @class mw.MultimediaViewer + * @class mw.mmv.MultimediaViewer * @constructor */ function MultimediaViewer() { /** * MultiLightbox object used to display the pictures in the page. - * @property {mw.MultiLightbox} + * @property {mw.mmv.MultiLightbox} * @private */ this.lightbox = null; @@ -107,14 +107,14 @@ var i, thumb; // Only if we find legit images, create a MultiLightbox object - this.lightbox = new mw.MultiLightbox( 0, mw.LightboxInterface, this ); + this.lightbox = new mw.mmv.MultiLightbox( 0, mw.mmv.LightboxInterface, this ); this.thumbs = thumbs; for ( i = 0; i < this.thumbs.length; i++ ) { thumb = this.thumbs[ i ]; // Create a LightboxImage object for each legit image - thumb.image = mw.mediaViewer.createNewImage( thumb.$thumb.prop( 'src' ), + thumb.image = mw.mmv.mediaViewer.createNewImage( thumb.$thumb.prop( 'src' ), thumb.link, thumb.title, i, @@ -132,10 +132,10 @@ * @param {number} index Which number file this is * @param {HTMLImageElement} thumb The thumbnail that represents this image on the page * @param {string} [caption] The caption, if any. - * @returns {mw.LightboxImage} + * @returns {mw.mmv.LightboxImage} */ MMVP.createNewImage = function ( fileLink, filePageLink, fileTitle, index, thumb, caption ) { - var thisImage = new mw.LightboxImage( fileLink, filePageLink, fileTitle, index, thumb, caption ); + var thisImage = new mw.mmv.LightboxImage( fileLink, filePageLink, fileTitle, index, thumb, caption ); thisImage.filePageLink = filePageLink; thisImage.filePageTitle = fileTitle; thisImage.index = index; @@ -147,7 +147,7 @@ /** * Handles resize events in viewer. * @protected - * @param {mw.LightboxInterface} ui lightbox that got resized + * @param {mw.mmv.LightboxInterface} ui lightbox that got resized */ MMVP.resize = function ( ui ) { var viewer = this, @@ -181,7 +181,7 @@ /** * Loads and sets the specified image. It also updates the controls. - * @param {mw.LightboxInterface} ui image container + * @param {mw.mmv.LightboxInterface} ui image container * @param {mw.mmv.model.Thumbnail} thumbnail thumbnail information * @param {HTMLImageElement} image * @param {mw.mmv.model.ThumbnailWidth} imageWidths @@ -198,7 +198,7 @@ /** * Loads a specified image. - * @param {mw.LightboxImage} image + * @param {mw.mmv.LightboxImage} image * @param {HTMLImageElement} initialImage A thumbnail to use as placeholder while the image loads */ MMVP.loadImage = function ( image, initialImage ) { @@ -303,7 +303,7 @@ * the callback argument. Calls the callback with each lightboximage index in some sequence * that is ideal for preloading. * @private - * @param {function(number, mw.LightboxImage)} callback + * @param {function(number, mw.mmv.LightboxImage)} callback */ MMVP.eachPrealoadableLightboxIndex = function( callback ) { for ( var i = 0; i <= this.preloadDistance; i++ ) { @@ -326,7 +326,7 @@ * A helper function to fill up the preload queues. * taskFactory(lightboxImage) should return a preload task for the given lightboximage. * @private - * @param {function(mw.LightboxImage): function()} taskFactory + * @param {function(mw.mmv.LightboxImage): function()} taskFactory * @return {mw.mmv.model.TaskQueue} */ MMVP.pushLightboxImagesIntoQueue = function( taskFactory ) { @@ -588,6 +588,6 @@ }); }; - mw.MultimediaViewer = MultimediaViewer; - mw.mediaViewer = new mw.MultimediaViewer(); + mw.mmv.MultimediaViewer = MultimediaViewer; + mw.mmv.mediaViewer = new MultimediaViewer(); }( mediaWiki, jQuery ) ); diff --git a/resources/mmv/mmv.lightboximage.js b/resources/mmv/mmv.lightboximage.js index 3742068..512c02f 100644 --- a/resources/mmv/mmv.lightboximage.js +++ b/resources/mmv/mmv.lightboximage.js @@ -19,7 +19,7 @@ /** * Represents an image on the page. - * @class mw.LightboxImage + * @class mw.mmv.LightboxImage * @constructor * @param {string} fileLink Link to the file - generally a thumb URL * @param {string} filePageLink Link to the File: page @@ -61,7 +61,7 @@ * The URL of a placeholder while the image loads. Typically a smaller version of the image, which is already * loaded in the browser. * @type {String} - * @return {jQuery.Promise.<mw.LightboxImage, HTMLImageElement>} + * @return {jQuery.Promise.<mw.mmv.LightboxImage, HTMLImageElement>} * @protected */ LIP.initialSrc = null; @@ -158,5 +158,5 @@ $img.width( imgWidth ).height( imgHeight ); }; - mw.LightboxImage = LightboxImage; + mw.mmv.LightboxImage = LightboxImage; }( mediaWiki, jQuery ) ); diff --git a/resources/mmv/mmv.lightboxinterface.js b/resources/mmv/mmv.lightboxinterface.js index 78bd3ad..430b372 100644 --- a/resources/mmv/mmv.lightboxinterface.js +++ b/resources/mmv/mmv.lightboxinterface.js @@ -20,7 +20,7 @@ /** * Represents the main interface of the lightbox - * @class mw.LightboxInterface + * @class mw.mmv.LightboxInterface * @constructor */ function LightboxInterface( viewer ) { @@ -41,7 +41,7 @@ /** * The currently selected LightboxImage. - * @type {mw.LightboxImage} + * @type {mw.mmv.LightboxImage} * @protected */ LIP.currentImage = null; @@ -265,7 +265,7 @@ /** * Displays an already loaded image. * This is an alternative to load() when we have an image element with the image already loaded. - * @param {mw.LightboxImage} image + * @param {mw.mmv.LightboxImage} image * @param {HTMLImageElement } imageElement */ LIP.showImage = function( image, imageElement ) { @@ -289,7 +289,7 @@ /** * Loads the image, then calls the load callback of the interface. - * @param {mw.LightboxImage} image + * @param {mw.mmv.LightboxImage} image */ LIP.load = function ( image ) { var iface = this; @@ -528,7 +528,7 @@ /** * @method * Gets the widths for a given lightbox image. - * @param {mw.LightboxImage} image + * @param {mw.mmv.LightboxImage} image * @returns {mw.mmv.model.ThumbnailWidth} */ LIP.getLightboxImageWidths = function ( image ) { @@ -542,7 +542,7 @@ * Gets the fullscreen widths for a given lightbox image. * Intended for use before the viewer is in fullscreen mode * (in fullscreen mode getLightboxImageWidths() works fine). - * @param {mw.LightboxImage} image + * @param {mw.mmv.LightboxImage} image * @returns {mw.mmv.model.ThumbnailWidth} */ LIP.getLightboxImageWidthsForFullscreen = function ( image ) { @@ -592,5 +592,5 @@ this.buttons.toggle( showPrevButton, showNextButton ); }; - mw.LightboxInterface = LightboxInterface; + mw.mmv.LightboxInterface = LightboxInterface; }( mediaWiki, jQuery ) ); diff --git a/resources/mmv/mmv.multilightbox.js b/resources/mmv/mmv.multilightbox.js index 4f9fc87..7215f9f 100644 --- a/resources/mmv/mmv.multilightbox.js +++ b/resources/mmv/mmv.multilightbox.js @@ -21,11 +21,11 @@ /** * Some interface functions for MMV. * FIXME merge with Lightboxinterface, figure out better separation of responsibilities - * @class mw.MultiLightbox + * @class mw.mmv.MultiLightbox * @constructor * @param {number} initial * @param {Function} InterfaceClass type of interface to use - * @param {mw.MultimediaViewer} viewer + * @param {mw.mmv.MultimediaViewer} viewer */ function MultiLightbox( initial, InterfaceClass, viewer ) { this.currentIndex = initial || 0; @@ -71,5 +71,5 @@ this.iface.attach(); }; - mw.MultiLightbox = MultiLightbox; + mw.mmv.MultiLightbox = MultiLightbox; }( mediaWiki ) ); diff --git a/resources/mmv/ui/mmv.ui.metadataPanel.js b/resources/mmv/ui/mmv.ui.metadataPanel.js index cf4d715..cdcab52 100644 --- a/resources/mmv/ui/mmv.ui.metadataPanel.js +++ b/resources/mmv/ui/mmv.ui.metadataPanel.js @@ -578,7 +578,7 @@ /** * Set all the image information in the panel - * @param {mw.LightboxImage} image + * @param {mw.mmv.LightboxImage} image * @param {mw.mmv.model.Image} imageData * @param {mw.mmv.model.Repo} repoData * @param {mw.mmv.model.FileUsage} localUsage diff --git a/tests/qunit/mmv/mmv.bootstrap.test.js b/tests/qunit/mmv/mmv.bootstrap.test.js index e5204af..cf48757 100644 --- a/tests/qunit/mmv/mmv.bootstrap.test.js +++ b/tests/qunit/mmv/mmv.bootstrap.test.js @@ -44,7 +44,8 @@ QUnit.test( 'Check viewer invoked when clicking on legit image links', 2, function ( assert ) { // TODO: Is <div class="gallery"><span class="image"><img/></span></div> valid ??? var div, link, link2, link3, bootstrap, - oldLoadImageByTitle = mw.mediaViewer.loadImageByTitle; + viewer = mw.mmv.mediaViewer, + oldLoadImageByTitle = viewer.loadImageByTitle; // Create gallery with legit link image div = createGallery(); @@ -61,7 +62,7 @@ // Create a new bootstrap object to trigger the DOM scan, etc. bootstrap = new mw.mmv.MultimediaViewerBootstrap(); - mw.mediaViewer.loadImageByTitle = function() { + viewer.loadImageByTitle = function() { assert.ok( true, 'Image loaded' ); }; @@ -71,20 +72,21 @@ // Click on legit link link2.trigger( { type : 'click', which : 1 } ); - mw.mediaViewer.loadImageByTitle = function() { + viewer.loadImageByTitle = function() { assert.ok( false, 'Image should not be loaded' ); }; // Click on non-legit link link3.trigger( { type : 'click', which : 1 } ); - mw.mediaViewer.loadImageByTitle = oldLoadImageByTitle; + viewer.loadImageByTitle = oldLoadImageByTitle; bootstrap.hash = $.noop; } ); QUnit.test( 'Skip images with invalid extensions', 0, function ( assert ) { var div, link, bootstrap, - oldLoadImageByTitle = mw.mediaViewer.loadImageByTitle; + viewer = mw.mmv.mediaViewer, + oldLoadImageByTitle = viewer.loadImageByTitle; // Create gallery with image that has invalid name extension div = createGallery( 'thumb.badext' ); @@ -93,20 +95,21 @@ // Create a new bootstrap object to trigger the DOM scan, etc. bootstrap = new mw.mmv.MultimediaViewerBootstrap(); - mw.mediaViewer.loadImageByTitle = function() { + viewer.loadImageByTitle = function() { assert.ok( false, 'Image should not be loaded' ); }; // Click on legit link with wrong image extension link.trigger( { type : 'click', which : 1 } ); - mw.mediaViewer.loadImageByTitle = oldLoadImageByTitle; + viewer.loadImageByTitle = oldLoadImageByTitle; bootstrap.hash = $.noop; } ); QUnit.test( 'Accept only left clicks without modifier keys, skip the rest', 1, function ( assert ) { var $div, $link, bootstrap, - oldLoadImageByTitle = mw.mediaViewer.loadImageByTitle; + viewer = mw.mmv.mediaViewer, + oldLoadImageByTitle = viewer.loadImageByTitle; // Create gallery with image that has invalid name extension $div = createGallery(); @@ -116,14 +119,14 @@ $link = $div.find( 'a.image' ); - mw.mediaViewer.loadImageByTitle = function() { + viewer.loadImageByTitle = function() { assert.ok( true, 'Image loaded' ); }; // Handle valid left click, it should try to load the image $link.trigger( { type : 'click', which : 1 } ); - mw.mediaViewer.loadImageByTitle = function() { + viewer.loadImageByTitle = function() { assert.ok( false, 'Image should not be loaded' ); }; @@ -133,19 +136,20 @@ // Skip invalid right click, no image is loaded $link.trigger( { type : 'click', which : 2 } ); - mw.mediaViewer.loadImageByTitle = oldLoadImageByTitle; + viewer.loadImageByTitle = oldLoadImageByTitle; bootstrap.hash = $.noop; } ); QUnit.test( 'Ensure that the correct title is loaded when clicking', 1, function ( assert ) { var bootstrap, oldByTitle, + viewer = mw.mmv.mediaViewer, $div = createGallery( 'foo.jpg' ), $link = $div.find( 'a.image' ); - oldByTitle = mw.mediaViewer.loadImageByTitle; + oldByTitle = viewer.loadImageByTitle; - mw.mediaViewer.loadImageByTitle = function ( loadedTitle ) { + viewer.loadImageByTitle = function ( loadedTitle ) { assert.strictEqual( loadedTitle, 'File:Foo.jpg', 'Titles are identical' ); }; @@ -154,7 +158,7 @@ $link.trigger( { type : 'click', which : 1 } ); - mw.mediaViewer.loadImageByTitle = oldByTitle; + viewer.loadImageByTitle = oldByTitle; bootstrap.hash = $.noop; } ); @@ -162,8 +166,9 @@ var bootstrap, $div, $link, - oldNewImage = mw.mediaViewer.createNewImage, - oldLoadImage = mw.mediaViewer.loadImage, + viewer = mw.mmv.mediaViewer, + oldNewImage = viewer.createNewImage, + oldLoadImage = viewer.loadImage, fname = 'valid', imgSrc = '/' + fname + '.jpg/300px-' + fname + '.jpg', imgRegex = new RegExp( imgSrc + '$' ); @@ -171,9 +176,9 @@ $div = createThumb( imgSrc, 'Blah blah' ); $link = $div.find( 'a.image' ); - mw.mediaViewer.loadImage = $.noop; + viewer.loadImage = $.noop; - mw.mediaViewer.createNewImage = function ( fileLink, filePageLink, fileTitle, index, thumb, caption ) { + viewer.createNewImage = function ( fileLink, filePageLink, fileTitle, index, thumb, caption ) { assert.ok( fileLink.match( imgRegex ), 'Thumbnail URL used in creating new image object' ); assert.strictEqual( filePageLink, '', 'File page link is sane when creating new image object' ); assert.strictEqual( fileTitle.title, fname, 'Filename is correct when passed into new image constructor' ); @@ -187,8 +192,8 @@ $link.trigger( { type : 'click', which : 1 } ); - mw.mediaViewer.createNewImage = oldNewImage; - mw.mediaViewer.loadImage = oldLoadImage; + viewer.createNewImage = oldNewImage; + viewer.loadImage = oldLoadImage; bootstrap.hash = $.noop; } ); diff --git a/tests/qunit/mmv/mmv.lightboximage.test.js b/tests/qunit/mmv/mmv.lightboximage.test.js index da12e83..97ff32c 100644 --- a/tests/qunit/mmv/mmv.lightboximage.test.js +++ b/tests/qunit/mmv/mmv.lightboximage.test.js @@ -2,7 +2,7 @@ QUnit.module( 'mmv.lightboximage', QUnit.newMwEnvironment() ); QUnit.asyncTest( 'Sanity test, object creation and image loading', 1, function ( assert ) { - var lightboxImage = new mw.LightboxImage( 'http://en.wikipedia.org/w/skins/vector/images/search-ltr.png' ); + var lightboxImage = new mw.mmv.LightboxImage( 'http://en.wikipedia.org/w/skins/vector/images/search-ltr.png' ); // Function to be called if loading is successful function loadCallback() { @@ -15,7 +15,7 @@ } ); QUnit.asyncTest( 'Image failing', 1, function ( assert ) { - var lightboxImage = new mw.LightboxImage( 'fail' ); + var lightboxImage = new mw.mmv.LightboxImage( 'fail' ); function errorCallback() { assert.ok( true, 'Image failed !' ); diff --git a/tests/qunit/mmv/mmv.lightboxinterface.test.js b/tests/qunit/mmv/mmv.lightboxinterface.test.js index ebbf633..b5c70f7 100644 --- a/tests/qunit/mmv/mmv.lightboxinterface.test.js +++ b/tests/qunit/mmv/mmv.lightboxinterface.test.js @@ -2,7 +2,7 @@ QUnit.module( 'mmv.lightboxInterface', QUnit.newMwEnvironment() ); QUnit.test( 'Sanity test, object creation and ui construction', 23, function ( assert ) { - var lightbox = new mw.LightboxInterface( mw.mediaViewer ); + var lightbox = new mw.mmv.LightboxInterface( mw.mmv.mediaViewer ); function checkIfUIAreasAttachedToDocument( inDocument ) { var msg = inDocument === 1 ? ' ' : ' not '; @@ -36,7 +36,7 @@ } ); QUnit.test( 'Handler registration and clearance work OK', 2, function ( assert ) { - var lightbox = new mw.LightboxInterface( mw.mediaViewer ), + var lightbox = new mw.mmv.LightboxInterface( mw.mmv.mediaViewer ), handlerCalls = 0; function handleEvent() { @@ -52,8 +52,8 @@ } ); QUnit.asyncTest( 'Check we are saving the resize listener', 2, function ( assert ) { - var img = new mw.LightboxImage('http://en.wikipedia.org/w/skins/vector/images/search-ltr.png'), - lightbox = new mw.LightboxInterface( mw.mediaViewer ); + var img = new mw.mmv.LightboxImage('http://en.wikipedia.org/w/skins/vector/images/search-ltr.png'), + lightbox = new mw.mmv.LightboxInterface( mw.mmv.mediaViewer ); // resizeListener not saved yet assert.strictEqual( this.resizeListener, undefined, 'Listener is not saved yet' ); @@ -75,7 +75,7 @@ } ); QUnit.test( 'Fullscreen mode', 8, function ( assert ) { - var lightbox = new mw.LightboxInterface( mw.mediaViewer ), + var lightbox = new mw.mmv.LightboxInterface( mw.mmv.mediaViewer ), oldFnEnterFullscreen = $.fn.enterFullscreen, oldFnExitFullscreen = $.fn.exitFullscreen, oldSupportFullscreen = $.support.fullscreen; @@ -83,8 +83,8 @@ // Since we don't want these tests to really open fullscreen // which is subject to user security confirmation, // we use a mock that pretends regular jquery.fullscreen behavior happened - $.fn.enterFullscreen = mw.mmvTestHelpers.enterFullscreenMock; - $.fn.exitFullscreen = mw.mmvTestHelpers.exitFullscreenMock; + $.fn.enterFullscreen = mw.mmv.testHelpers.enterFullscreenMock; + $.fn.exitFullscreen = mw.mmv.testHelpers.exitFullscreenMock; // Attach lightbox to testing fixture to avoid interference with other tests. lightbox.attach( '#qunit-fixture' ); @@ -139,21 +139,21 @@ } ); QUnit.test( 'Fullscreen mode', 8, function ( assert ) { - var lightbox = new mw.LightboxInterface( mw.mediaViewer ), + var lightbox = new mw.mmv.LightboxInterface( mw.mmv.mediaViewer ), oldFnEnterFullscreen = $.fn.enterFullscreen, oldFnExitFullscreen = $.fn.exitFullscreen, oldRevealButtonsAndFadeIfNeeded, - oldPreloadDistance = mw.mediaViewer.preloadDistance, + oldPreloadDistance = mw.mmv.mediaViewer.preloadDistance, buttonOffset; // ugly hack to avoid preloading which would require lightbox list being set up - mw.mediaViewer.preloadDistance = -1; + mw.mmv.mediaViewer.preloadDistance = -1; // Since we don't want these tests to really open fullscreen // which is subject to user security confirmation, // we use a mock that pretends regular jquery.fullscreen behavior happened - $.fn.enterFullscreen = mw.mmvTestHelpers.enterFullscreenMock; - $.fn.exitFullscreen = mw.mmvTestHelpers.exitFullscreenMock; + $.fn.enterFullscreen = mw.mmv.testHelpers.enterFullscreenMock; + $.fn.exitFullscreen = mw.mmv.testHelpers.exitFullscreenMock; // Attach lightbox to testing fixture to avoid interference with other tests. lightbox.attach( '#qunit-fixture' ); @@ -203,11 +203,11 @@ $.fn.enterFullscreen = oldFnEnterFullscreen; $.fn.exitFullscreen = oldFnExitFullscreen; - mw.mediaViewer.preloadDistance = oldPreloadDistance; + mw.mmv.mediaViewer.preloadDistance = oldPreloadDistance; } ); QUnit.test( 'isAnyActiveButtonHovered', 20, function ( assert ) { - var lightbox = new mw.LightboxInterface( mw.mediaViewer ); + var lightbox = new mw.mmv.LightboxInterface( mw.mmv.mediaViewer ); // Attach lightbox to testing fixture to avoid interference with other tests. lightbox.attach( '#qunit-fixture' ); @@ -242,18 +242,18 @@ } ); QUnit.test( 'Metadata scrolling', 15, function ( assert ) { - var lightbox = new mw.LightboxInterface( mw.mediaViewer ), + var lightbox = new mw.mmv.LightboxInterface( mw.mmv.mediaViewer ), keydown = $.Event( 'keydown' ), $document = $( document ), scrollTopBeforeOpeningLightbox, originalJQueryScrollTop = $.fn.scrollTop, memorizedScrollToScroll = 0, originalJQueryScrollTo = $.scrollTo, - oldMWLightbox = mw.mediaViewer.lightbox, - oldMWUI = mw.mediaViewer.ui; + oldMWLightbox = mw.mmv.mediaViewer.lightbox, + oldMWUI = mw.mmv.mediaViewer.ui; // Pretend that we have things hooked up - mw.mediaViewer.ui = lightbox; + mw.mmv.mediaViewer.ui = lightbox; // We need to set up a proxy on the jQuery scrollTop function // that will let us pretend that the document really scrolled @@ -284,7 +284,7 @@ if ( scrollTo !== undefined ) { // Trigger event manually - mw.mediaViewer.scroll(); + mw.mmv.mediaViewer.scroll(); } return $element; @@ -292,14 +292,14 @@ // First phase of the test: up and down arrows - mw.mediaViewer.hasAnimatedMetadata = false; + mw.mmv.mediaViewer.hasAnimatedMetadata = false; localStorage.removeItem( 'mmv.hasOpenedMetadata' ); // Attach lightbox to testing fixture to avoid interference with other tests. lightbox.attach( '#qunit-fixture' ); // Pretend that we have things hooked up - mw.mediaViewer.lightbox = { currentIndex: 0 }; + mw.mmv.mediaViewer.lightbox = { currentIndex: 0 }; // This lets us avoid pushing a state to the history, which might interfere with other tests lightbox.comingFromHashChange = true; @@ -382,7 +382,7 @@ // Let's restore all originals, to make sure this test is free of side-effect $.fn.scrollTop = originalJQueryScrollTop; $.scrollTo = originalJQueryScrollTo; - mw.mediaViewer.lightbox = oldMWLightbox; - mw.mediaViewer.ui = oldMWUI; + mw.mmv.mediaViewer.lightbox = oldMWLightbox; + mw.mmv.mediaViewer.ui = oldMWUI; } ); }( mediaWiki, jQuery ) ); diff --git a/tests/qunit/mmv/mmv.multilightbox.test.js b/tests/qunit/mmv/mmv.multilightbox.test.js index 04f9174..69cb6d4 100644 --- a/tests/qunit/mmv/mmv.multilightbox.test.js +++ b/tests/qunit/mmv/mmv.multilightbox.test.js @@ -3,7 +3,7 @@ QUnit.test( 'Smoke test', 2, function ( assert ) { function DummyClass() {} - var multiLightbox = new mw.MultiLightbox( 0, DummyClass ); + var multiLightbox = new mw.mmv.MultiLightbox( 0, DummyClass ); assert.strictEqual( multiLightbox.currentIndex, 0, 'currentIndex initialized correctly.' ); assert.ok( multiLightbox.iface instanceof DummyClass, 'interface initialized correctly.' ); diff --git a/tests/qunit/mmv/mmv.test.js b/tests/qunit/mmv/mmv.test.js index 44bd701..38235ce 100644 --- a/tests/qunit/mmv/mmv.test.js +++ b/tests/qunit/mmv/mmv.test.js @@ -7,7 +7,7 @@ var viewer, backupAnimation = $.fn.animate, animationRan = false, - oldSetupEventHandlers = mw.MultimediaViewer.prototype.setupEventHandlers; + oldSetupEventHandlers = mw.mmv.MultimediaViewer.prototype.setupEventHandlers; $.fn.animate = function () { animationRan = true; @@ -15,8 +15,8 @@ }; // Because we don't want that throwaway instance to listen to events, could interfere with other tests - mw.MultimediaViewer.prototype.setupEventHandlers = $.noop; - viewer = new mw.MultimediaViewer(); + mw.mmv.MultimediaViewer.prototype.setupEventHandlers = $.noop; + viewer = new mw.mmv.MultimediaViewer(); viewer.animateMetadataDivOnce(); assert.strictEqual( viewer.hasAnimatedMetadata, true, 'The first call to animateMetadataDivOnce set hasAnimatedMetadata to true' ); @@ -29,11 +29,11 @@ $.fn.animate = backupAnimation; - mw.MultimediaViewer.prototype.setupEventHandlers = oldSetupEventHandlers; + mw.mmv.MultimediaViewer.prototype.setupEventHandlers = oldSetupEventHandlers; } ); QUnit.test( 'eachPrealoadableLightboxIndex()', 11, function ( assert ) { - var viewer = mw.mediaViewer, + var viewer = mw.mmv.mediaViewer, oldLightbox, oldPreloadDistance, oldPosition, @@ -80,10 +80,11 @@ QUnit.test( 'Hash handling', 7, function ( assert ) { var oldUnattach, - multiLightbox = new mw.MultiLightbox( 0, mw.LightboxInterface ), - lightbox = new mw.LightboxInterface( mw.mediaViewer ), - oldLoadImage = mw.mediaViewer.loadImageByTitle, - oldLightbox = mw.mediaViewer.lightbox, + viewer = mw.mmv.mediaViewer, + multiLightbox = new mw.mmv.MultiLightbox( 0, mw.mmv.LightboxInterface ), + lightbox = new mw.mmv.LightboxInterface( viewer ), + oldLoadImage = viewer.loadImageByTitle, + oldLightbox = viewer.lightbox, imageSrc = 'Foo bar.jpg', image = { filePageTitle: new mw.Title( 'File:' + imageSrc ) }; @@ -96,21 +97,21 @@ oldUnattach.call( this ); }; - mw.mediaViewer.lightbox = multiLightbox; - mw.mediaViewer.lightbox.iface = lightbox; - mw.mediaViewer.close(); + viewer.lightbox = multiLightbox; + viewer.lightbox.iface = lightbox; + viewer.close(); - assert.ok( !mw.mediaViewer.isOpen, 'Viewer is closed' ); + assert.ok( !viewer.isOpen, 'Viewer is closed' ); - mw.mediaViewer.isOpen = true; + viewer.isOpen = true; // Verify that passing an invalid mmv hash when the mmv is open triggers unattach() window.location.hash = 'Foo'; - mw.mediaViewer.hash(); + viewer.hash(); // Verify that mmv doesn't reset a foreign hash assert.strictEqual( window.location.hash, '#Foo', 'Foreign hash remains intact' ); - assert.ok( !mw.mediaViewer.isOpen, 'Viewer is closed' ); + assert.ok( !viewer.isOpen, 'Viewer is closed' ); lightbox.unattach = function () { assert.ok( false, 'Lightbox was not unattached' ); @@ -119,35 +120,35 @@ // Verify that passing an invalid mmv hash when the mmv is closed doesn't trigger unattach() window.location.hash = 'Bar'; - mw.mediaViewer.hash(); + viewer.hash(); // Verify that mmv doesn't reset a foreign hash assert.strictEqual( window.location.hash, '#Bar', 'Foreign hash remains intact' ); - mw.mediaViewer.lightbox = { images: [ image ] }; + viewer.lightbox = { images: [ image ] }; $( '#qunit-fixture' ).append( '<a class="image"><img src="' + imageSrc + '"></a>' ); - mw.mediaViewer.loadImageByTitle = function( title ) { + viewer.loadImageByTitle = function( title ) { assert.strictEqual( title, 'File:' + imageSrc, 'The title matches' ); }; // Open a valid mmv hash link and check that the right image is requested. // imageSrc contains a space without any encoding on purpose window.location.hash = 'mediaviewer/File:' + imageSrc; - mw.mediaViewer.hash(); + viewer.hash(); // Reset the hash, because for some browsers switching from the non-URI-encoded to // the non-URI-encoded version of the same text with a space will not trigger a hash change window.location.hash = ''; - mw.mediaViewer.hash(); + viewer.hash(); // Try again with an URI-encoded imageSrc containing a space window.location.hash = 'mediaviewer/File:' + encodeURIComponent( imageSrc ); - mw.mediaViewer.hash(); + viewer.hash(); - mw.mediaViewer.lightbox = oldLightbox; - mw.mediaViewer.loadImageByTitle = oldLoadImage; + viewer.lightbox = oldLightbox; + viewer.loadImageByTitle = oldLoadImage; window.location.hash = ''; } ); diff --git a/tests/qunit/mmv/mmv.testhelpers.js b/tests/qunit/mmv/mmv.testhelpers.js index 4d77710..0c77d9f 100644 --- a/tests/qunit/mmv/mmv.testhelpers.js +++ b/tests/qunit/mmv/mmv.testhelpers.js @@ -13,5 +13,5 @@ $( document ).trigger( $.Event( 'jq-fullscreen-change', { element: this, fullscreen: false } ) ); }; - mw.mmvTestHelpers = MTH; + mw.mmv.testHelpers = MTH; } )( mediaWiki, jQuery ); \ No newline at end of file -- To view, visit https://gerrit.wikimedia.org/r/115335 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I88bb3b62b82ce54126dd069b0aab4412d9404719 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/MultimediaViewer Gerrit-Branch: master Gerrit-Owner: Gergő Tisza <gti...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits