X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=resources%2Fsrc%2Fmediawiki.page.gallery.js;h=0ffc867863ddbb9a6ca47360ce24ba7784178796;hb=952c3b0aaa0cfbefac76158d3890af705c232013;hp=892f04416d25ac2ab5fe0d418401eac1b89f038e;hpb=5623d4c64319a98ddd8263c597002d173464ccbf;p=lhc%2Fweb%2Fwiklou.git diff --git a/resources/src/mediawiki.page.gallery.js b/resources/src/mediawiki.page.gallery.js index 892f04416d..0ffc867863 100644 --- a/resources/src/mediawiki.page.gallery.js +++ b/resources/src/mediawiki.page.gallery.js @@ -4,7 +4,7 @@ * - Toggle gallery captions when focused. * - Dynamically resize images to fill horizontal space. */ -( function ( mw, $ ) { +( function () { var $galleries, bound = false, lastWidth = window.innerWidth, @@ -22,20 +22,17 @@ */ function justify() { var lastTop, - $img, - imgWidth, - imgHeight, - captionWidth, rows = [], $gallery = $( this ); $gallery.children( 'li.gallerybox' ).each( function () { - // Math.floor to be paranoid if things are off by 0.00000000001 - var top = Math.floor( $( this ).position().top ), + var $img, imgWidth, imgHeight, outerWidth, captionWidth, + // Math.floor, to be paranoid if things are off by 0.00000000001 + top = Math.floor( $( this ).position().top ), $this = $( this ); if ( top !== lastTop ) { - rows[ rows.length ] = []; + rows.push( [] ); lastTop = top; } @@ -59,20 +56,21 @@ } captionWidth = $this.children().children( 'div.gallerytextwrapper' ).width(); - rows[ rows.length - 1 ][ rows[ rows.length - 1 ].length ] = { + outerWidth = $this.outerWidth(); + rows[ rows.length - 1 ].push( { $elm: $this, - width: $this.outerWidth(), + width: outerWidth, imgWidth: imgWidth, - // XXX: can divide by 0 ever happen? + // FIXME: Deal with devision by 0. aspect: imgWidth / imgHeight, captionWidth: captionWidth, height: imgHeight - }; + } ); // Save all boundaries so we can restore them on window resize $this.data( 'imgWidth', imgWidth ); $this.data( 'imgHeight', imgHeight ); - $this.data( 'width', $this.outerWidth() ); + $this.data( 'width', outerWidth ); $this.data( 'captionWidth', captionWidth ); } ); @@ -173,7 +171,6 @@ $innerDiv = $outerDiv.children( 'div' ).first(); $imageDiv = $innerDiv.children( 'div.thumb' ); $imageElm = $imageDiv.find( 'img' ).first(); - imageElm = $imageElm.length ? $imageElm[ 0 ] : null; $caption = $outerDiv.find( 'div.gallerytextwrapper' ); // Since we are going to re-adjust the height, the vertical @@ -195,8 +192,9 @@ $caption.width( curRow[ j ].captionWidth + ( newWidth - curRow[ j ].imgWidth ) ); } - if ( imageElm ) { - // We don't always have an img, e.g. in the case of an invalid file. + // We don't always have an img, e.g. in the case of an invalid file. + if ( $imageElm[ 0 ] ) { + imageElm = $imageElm[ 0 ]; imageElm.width = newWidth; imageElm.height = preferredHeight; } else { @@ -235,8 +233,8 @@ $( this ).find( 'div.gallerytextwrapper' ).width( captionWidth ); $imageElm = $( this ).find( 'img' ).first(); - imageElm = $imageElm.length ? $imageElm[ 0 ] : null; - if ( imageElm ) { + if ( $imageElm[ 0 ] ) { + imageElm = $imageElm[ 0 ]; imageElm.width = imgWidth; imageElm.height = imgHeight; } else { @@ -283,9 +281,9 @@ if ( !bound ) { bound = true; $( window ) - .resize( $.debounce( 300, true, handleResizeStart ) ) - .resize( $.debounce( 300, handleResizeEnd ) ); + .on( 'resize', $.debounce( 300, true, handleResizeStart ) ) + .on( 'resize', $.debounce( 300, handleResizeEnd ) ); } } ); } ); -}( mediaWiki, jQuery ) ); +}() );