X-Git-Url: https://git.heureux-cyclage.org/?p=lhc%2Fweb%2Fwiklou.git;a=blobdiff_plain;f=resources%2Fsrc%2Fmediawiki.page.gallery.slideshow.js;h=a36e409aa56545dcb2c1c59aa4020b3cb71d048f;hp=4ea1999de69450a3de9ae73f6acff563daf8e45d;hb=9e8439e79d67788916d488f645108f79016d9aca;hpb=f79c9e6ca3c02090d6d56eaecb2ab90d4198b2b9 diff --git a/resources/src/mediawiki.page.gallery.slideshow.js b/resources/src/mediawiki.page.gallery.slideshow.js index 4ea1999de6..a36e409aa5 100644 --- a/resources/src/mediawiki.page.gallery.slideshow.js +++ b/resources/src/mediawiki.page.gallery.slideshow.js @@ -24,7 +24,7 @@ this.drawCarousel(); this.setSizeRequirement(); this.toggleThumbnails( !!this.$gallery.attr( 'data-showthumbnails' ) ); - this.showCurrentImage(); + this.showCurrentImage( true ); // Events $( window ).on( @@ -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 ( @@ -229,8 +229,10 @@ /** * Displays the image set as {@link #$currentImage} in the carousel. + * + * @param {boolean} init Image being show during gallery init (i.e. first image) */ - mw.GallerySlideshow.prototype.showCurrentImage = function () { + mw.GallerySlideshow.prototype.showCurrentImage = function ( init ) { var $thumbnail, $imgLink, $imageLi = this.getCurrentImage(), $caption = $imageLi.find( '.gallerytext' ); @@ -279,7 +281,10 @@ if ( this.$thumbnail.attr( 'src' ) === $thumbnail.attr( 'src' ) ) { this.$img.attr( 'src', info.thumburl ); this.setImageSize(); - mw.hook( 'wikipage.content' ).fire( this.$imgContainer ); + // Don't fire hook twice during init + if ( !init ) { + mw.hook( 'wikipage.content' ).fire( this.$imgContainer ); + } // Pre-fetch the next image this.loadImage( this.getNextImage().find( 'img' ) ); @@ -299,9 +304,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 +314,8 @@ img.onerror = function () { d.reject(); }; - } ).fail( function () { - d.reject(); + return d.promise(); } ); - - return d.promise(); }; /**