From: Timo Tijhof Date: Tue, 6 Aug 2019 13:00:17 +0000 (+0100) Subject: mediawiki.page.gallery.slideshow: Avoid manual Deferred wrapping X-Git-Tag: 1.34.0-rc.0~769^2 X-Git-Url: http://git.cyclocoop.org/%22%20.%20generer_url_ecrire%28%22calendrier%22%2C%22type=semaine%22%29%20.%20%22?a=commitdiff_plain;h=e4166ca60989e7752382e012c1b4f86a12b068a4;p=lhc%2Fweb%2Fwiklou.git mediawiki.page.gallery.slideshow: Avoid manual Deferred wrapping * Use then(), which automatically forwards errors, instead of manually forwarding fail() to d.reject(). This also ensures that any errors in the done() or fail() handler themselves are caught and reject the returned Deferred – instead of an causing the Deferred to indefinely be in the "pending" state. * Use then(), which makes the code consistently asynchronous, instead of sometimes sync and sometimes async. * Use then() for forward-compat with native ES6 Promise. Change-Id: I58fb6ec23fb4056fe2bbb146ff4225dea9d9f379 --- diff --git a/resources/src/mediawiki.page.gallery.slideshow.js b/resources/src/mediawiki.page.gallery.slideshow.js index 4ea1999de6..667c2ba21b 100644 --- a/resources/src/mediawiki.page.gallery.slideshow.js +++ b/resources/src/mediawiki.page.gallery.slideshow.js @@ -212,7 +212,7 @@ // Make the image smaller in case the current image // size is larger than the original file size. - this.getImageInfo( this.$thumbnail ).done( function ( info ) { + this.getImageInfo( this.$thumbnail ).then( function ( info ) { // NOTE: There will be a jump when resizing the window // because the cache is cleared and this a new network request. if ( @@ -299,9 +299,8 @@ * element once the image has loaded. */ mw.GallerySlideshow.prototype.loadImage = function ( $img ) { - var img, d = $.Deferred(); - - this.getImageInfo( $img ).done( function ( info ) { + return this.getImageInfo( $img ).then( function ( info ) { + var img, d = $.Deferred(); img = new Image(); img.src = info.thumburl; img.onload = function () { @@ -310,11 +309,8 @@ img.onerror = function () { d.reject(); }; - } ).fail( function () { - d.reject(); + return d.promise(); } ); - - return d.promise(); }; /**