Merge "Fix bug that would cause the image to stay small"

This commit is contained in:
jenkins-bot 2014-01-27 18:44:58 +00:00 committed by Gerrit Code Review
commit 567039c14e
3 changed files with 26 additions and 9 deletions

View file

@ -27,18 +27,21 @@
*/ */
LIP.initialSrc = null; LIP.initialSrc = null;
LIP.getImageElement = function ( loadcb ) { LIP.getImageElement = function () {
var ele; var ele,
$deferred = $.Deferred(),
image = this;
lightboxHooks.callAll( 'beforeFetchImage', this ); lightboxHooks.callAll( 'beforeFetchImage', this );
ele = new Image(); ele = new Image();
ele.addEventListener( 'load', loadcb ); ele.addEventListener( 'error', $deferred.reject );
ele.addEventListener( 'load', function() { $deferred.resolve( image, ele ); } );
ele.src = this.src || this.initialSrc; ele.src = this.src || this.initialSrc;
lightboxHooks.callAll( 'modifyImageElement', ele ); lightboxHooks.callAll( 'modifyImageElement', ele );
return ele; return $deferred;
}; };
// Assumes that the parent element's size is the maximum size. // Assumes that the parent element's size is the maximum size.

View file

@ -165,12 +165,13 @@
* @param {LightboxImage} image * @param {LightboxImage} image
*/ */
LIP.load = function ( image ) { LIP.load = function ( image ) {
var iface = this, var iface = this;
ele = image.getImageElement( function () {
iface.loadCallback( image, ele );
} );
this.currentImage = image; this.currentImage = image;
image.getImageElement().done( function( image, ele ) {
iface.loadCallback.call( iface, image, ele );
} );
}; };
LIP.autoResizeImage = function () { LIP.autoResizeImage = function () {

View file

@ -10,7 +10,20 @@
QUnit.start(); QUnit.start();
} }
lightboxImage.getImageElement( loadCallback ); lightboxImage.getImageElement()
.done( loadCallback );
} );
QUnit.asyncTest( 'Image failing', 1, function ( assert ) {
var lightboxImage = new window.LightboxImage( 'http://thisdoesntexist/fail.jpg' );
function errorCallback() {
assert.ok( true, 'Image failed !' );
QUnit.start();
}
lightboxImage.getImageElement()
.fail( errorCallback );
} ); } );
}( mediaWiki, jQuery ) ); }( mediaWiki, jQuery ) );