From: Ed Sanders Date: Fri, 19 Apr 2019 13:08:07 +0000 (+0100) Subject: Gallery slideshow: Improve missing image and error handling X-Git-Tag: 1.34.0-rc.0~1889^2 X-Git-Url: http://git.cyclocoop.org/%7B%24admin_url%7Dcompta/comptes/journal.php?a=commitdiff_plain;h=d830ad1917c3665bc5362cac9703e4de9ae89add;p=lhc%2Fweb%2Fwiklou.git Gallery slideshow: Improve missing image and error handling Change-Id: I6aae5801178aa66fc40d40b9dec239a34b0ee029 --- diff --git a/resources/src/mediawiki.page.gallery.slideshow.js b/resources/src/mediawiki.page.gallery.slideshow.js index dd52767eb2..4ea1999de6 100644 --- a/resources/src/mediawiki.page.gallery.slideshow.js +++ b/resources/src/mediawiki.page.gallery.slideshow.js @@ -242,24 +242,33 @@ .removeClass( 'slideshow-current' ); $imageLi.addClass( 'slideshow-current' ); - // 2. Create and show thumbnail this.$thumbnail = $imageLi.find( 'img' ); - this.$img = $( '' ).attr( { - src: this.$thumbnail.attr( 'src' ), - alt: this.$thumbnail.attr( 'alt' ) - } ); - // 'image' class required for detection by MultimediaViewer - $imgLink = $( '' ).addClass( 'image' ) - .attr( 'href', $imageLi.find( 'a' ).eq( 0 ).attr( 'href' ) ) - .append( this.$img ); + if ( this.$thumbnail.length ) { + // 2. Create and show thumbnail + this.$img = $( '' ).attr( { + src: this.$thumbnail.attr( 'src' ), + alt: this.$thumbnail.attr( 'alt' ) + } ); + // 'image' class required for detection by MultimediaViewer + $imgLink = $( '' ).addClass( 'image' ) + .attr( 'href', $imageLi.find( 'a' ).eq( 0 ).attr( 'href' ) ) + .append( this.$img ); - this.$imgContainer.empty().append( $imgLink ); + this.$imgContainer.empty().append( $imgLink ); + } else { + // 2b. No image found (e.g. file doesn't exist) + this.$imgContainer.text( $imageLi.find( '.thumb' ).text() ); + } // 3. Copy caption this.$imgCaption .empty() .append( $caption.clone() ); + if ( !this.$thumbnail.length ) { + return; + } + // 4. Stretch thumbnail to correct size this.setImageSize(); @@ -275,6 +284,10 @@ // Pre-fetch the next image this.loadImage( this.getNextImage().find( 'img' ) ); } + }.bind( this ) ).fail( function () { + // Image didn't load + var title = mw.Title.newFromImg( this.$img ); + this.$imgContainer.text( title ? title.getMainText() : '' ); }.bind( this ) ); };