mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/MultimediaViewer
synced 2024-11-24 00:03:56 +00:00
Merge "Add a very simple resize test"
This commit is contained in:
commit
68c14b7ef4
|
@ -227,14 +227,19 @@
|
|||
this.loadImage( thisImage, initial );
|
||||
};
|
||||
|
||||
/**
|
||||
* Handles resize events in viewer.
|
||||
*
|
||||
* @protected
|
||||
*
|
||||
* @param {mw.LightboxInterface} ui lightbox that got resized
|
||||
*/
|
||||
MMVP.resize = function ( ui ) {
|
||||
// TODO: Reuse the api member, fix everywhere.
|
||||
var api = new mw.Api(),
|
||||
viewer = this,
|
||||
var viewer = this,
|
||||
density = $.devicePixelRatio(),
|
||||
filename = ui.currentImageFilename;
|
||||
|
||||
api.get( {
|
||||
this.api.get( {
|
||||
action: 'query',
|
||||
format: 'json',
|
||||
titles: filename,
|
||||
|
@ -243,6 +248,21 @@
|
|||
iiurlwidth: Math.floor( density * ui.$imageWrapper.width() ),
|
||||
iiurlheight: Math.floor( density * ui.$imageWrapper.height() )
|
||||
} ).done( function ( data ) {
|
||||
viewer.loadResizedImage( ui, data );
|
||||
} );
|
||||
};
|
||||
|
||||
/**
|
||||
* Replaces the resized image in the viewer providing we actually got some data.
|
||||
*
|
||||
* @protected
|
||||
*
|
||||
* @param {mw.LightboxInterface} ui lightbox that got resized
|
||||
* @param {Object} data information regarding the new resized image
|
||||
*/
|
||||
MMVP.loadResizedImage = function ( ui, data ) {
|
||||
// Replace image only if data was returned.
|
||||
if ( data && data.query && data.query.pages ) {
|
||||
var imageInfo, innerInfo,
|
||||
image = new Image();
|
||||
|
||||
|
@ -255,11 +275,11 @@
|
|||
|
||||
image.onload = function () {
|
||||
ui.replaceImageWith( image );
|
||||
viewer.updateControls();
|
||||
this.updateControls();
|
||||
};
|
||||
|
||||
image.src = innerInfo.thumburl || innerInfo.url;
|
||||
} );
|
||||
}
|
||||
};
|
||||
|
||||
MMVP.updateControls = function () {
|
||||
|
@ -494,6 +514,7 @@
|
|||
username = innerInfo.user;
|
||||
|
||||
if ( username ) {
|
||||
// TODO: Reuse the api member, fix everywhere.
|
||||
// Fetch the gender from the uploader's home wiki
|
||||
// TODO this is ugly as hell, let's fix this in core.
|
||||
new mw.Api( {
|
||||
|
|
|
@ -107,4 +107,17 @@
|
|||
link.trigger( rightClick );
|
||||
} );
|
||||
|
||||
QUnit.test( 'Do not load the resized image if no data returning from the api', 1, function ( assert ) {
|
||||
var ui,
|
||||
data,
|
||||
viewer = new mw.MultimediaViewer();
|
||||
|
||||
// Calling loadResizedImage() with empty/undefined data should not fail.
|
||||
viewer.loadResizedImage( ui, data );
|
||||
viewer.loadResizedImage( ui, {} );
|
||||
viewer.loadResizedImage( ui, { query: {} } );
|
||||
|
||||
assert.ok( true, 'Resized image is not replaced since we have not data.' );
|
||||
} );
|
||||
|
||||
}( mediaWiki, jQuery ) );
|
||||
|
|
Loading…
Reference in a new issue