mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/MultimediaViewer
synced 2024-11-27 17:40:06 +00:00
Merge "Add a very simple resize test"
This commit is contained in:
commit
68c14b7ef4
|
@ -227,14 +227,19 @@
|
||||||
this.loadImage( thisImage, initial );
|
this.loadImage( thisImage, initial );
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handles resize events in viewer.
|
||||||
|
*
|
||||||
|
* @protected
|
||||||
|
*
|
||||||
|
* @param {mw.LightboxInterface} ui lightbox that got resized
|
||||||
|
*/
|
||||||
MMVP.resize = function ( ui ) {
|
MMVP.resize = function ( ui ) {
|
||||||
// TODO: Reuse the api member, fix everywhere.
|
var viewer = this,
|
||||||
var api = new mw.Api(),
|
|
||||||
viewer = this,
|
|
||||||
density = $.devicePixelRatio(),
|
density = $.devicePixelRatio(),
|
||||||
filename = ui.currentImageFilename;
|
filename = ui.currentImageFilename;
|
||||||
|
|
||||||
api.get( {
|
this.api.get( {
|
||||||
action: 'query',
|
action: 'query',
|
||||||
format: 'json',
|
format: 'json',
|
||||||
titles: filename,
|
titles: filename,
|
||||||
|
@ -243,6 +248,21 @@
|
||||||
iiurlwidth: Math.floor( density * ui.$imageWrapper.width() ),
|
iiurlwidth: Math.floor( density * ui.$imageWrapper.width() ),
|
||||||
iiurlheight: Math.floor( density * ui.$imageWrapper.height() )
|
iiurlheight: Math.floor( density * ui.$imageWrapper.height() )
|
||||||
} ).done( function ( data ) {
|
} ).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,
|
var imageInfo, innerInfo,
|
||||||
image = new Image();
|
image = new Image();
|
||||||
|
|
||||||
|
@ -255,11 +275,11 @@
|
||||||
|
|
||||||
image.onload = function () {
|
image.onload = function () {
|
||||||
ui.replaceImageWith( image );
|
ui.replaceImageWith( image );
|
||||||
viewer.updateControls();
|
this.updateControls();
|
||||||
};
|
};
|
||||||
|
|
||||||
image.src = innerInfo.thumburl || innerInfo.url;
|
image.src = innerInfo.thumburl || innerInfo.url;
|
||||||
} );
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
MMVP.updateControls = function () {
|
MMVP.updateControls = function () {
|
||||||
|
@ -494,6 +514,7 @@
|
||||||
username = innerInfo.user;
|
username = innerInfo.user;
|
||||||
|
|
||||||
if ( username ) {
|
if ( username ) {
|
||||||
|
// TODO: Reuse the api member, fix everywhere.
|
||||||
// Fetch the gender from the uploader's home wiki
|
// Fetch the gender from the uploader's home wiki
|
||||||
// TODO this is ugly as hell, let's fix this in core.
|
// TODO this is ugly as hell, let's fix this in core.
|
||||||
new mw.Api( {
|
new mw.Api( {
|
||||||
|
|
|
@ -107,4 +107,17 @@
|
||||||
link.trigger( rightClick );
|
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 ) );
|
}( mediaWiki, jQuery ) );
|
||||||
|
|
Loading…
Reference in a new issue