Merge "Display thumbnail placeholder ASAP"

This commit is contained in:
jenkins-bot 2014-03-31 21:05:45 +00:00 committed by Gerrit Code Review
commit 21ba529db0
3 changed files with 45 additions and 10 deletions

View file

@ -719,6 +719,7 @@ call_user_func( function() {
$wgHooks['ResourceLoaderGetConfigVars'][] = 'MultimediaViewerHooks::resourceLoaderGetConfigVars';
$wgHooks['MakeGlobalVariablesScript'][] = 'MultimediaViewerHooks::makeGlobalVariablesScript';
$wgHooks['ResourceLoaderTestModules'][] = 'MultimediaViewerHooks::getTestModules';
$wgHooks['ThumbnailBeforeProduceHTML'][] = 'MultimediaViewerHooks::thumbnailBeforeProduceHTML';
$section = 'other';

View file

@ -223,4 +223,30 @@ class MultimediaViewerHooks {
return true;
}
/**
* Modify thumbnail DOM
* @param ThumbnailImage $thumbnail
* @param array $attribs Attributes of the <img> element
* @param array $linkAttribs Attributes of the wrapping <a> element
*/
public static function thumbnailBeforeProduceHTML( ThumbnailImage $thumbnail, array &$attribs, array &$linkAttribs ) {
$file = $thumbnail->getFile();
if ( $file ) {
// At the moment all classes that extend File have getWidth() and getHeight()
// but since the File class doesn't have these methods defined, this check
// is more future-proof
if ( method_exists( $file, 'getWidth' ) ) {
$attribs['data-file-width'] = $file->getWidth();
}
if ( method_exists( $file, 'getHeight' ) ) {
$attribs['data-file-height'] = $file->getHeight();
}
}
return true;
}
}

View file

@ -195,11 +195,13 @@
*/
MMVP.loadImage = function ( image, initialImage ) {
var imageWidths,
viewer = this,
imagePromise,
metadataPromise,
start,
$initialImage = $( initialImage );
viewer = this,
$initialImage = $( initialImage ),
fileWidth = parseInt( $initialImage.data( 'file-width' ), 10 ),
fileHeight = parseInt( $initialImage.data( 'file-height' ), 10 );
this.currentIndex = image.index;
@ -244,6 +246,20 @@
viewer.ui.panel.percent( 5 );
}
if ( fileWidth > 0 && fileHeight > 0 ) {
viewer.displayPlaceholderThumbnail( { width : fileWidth , height : fileHeight },
$initialImage,
imageWidths );
} else {
this.imageInfoProvider.get( image.filePageTitle ).done( function ( imageInfo ) {
if ( viewer.currentIndex !== image.index ) {
return;
}
viewer.displayPlaceholderThumbnail( imageInfo, $initialImage, imageWidths );
} );
}
imagePromise.progress( function ( thumbnailInfoResponse, imageResponse ) {
if ( viewer.currentIndex !== image.index ) {
return;
@ -265,14 +281,6 @@
viewer.ui.canvas.showError( error );
} );
this.imageInfoProvider.get( image.filePageTitle ).done( function ( imageInfo ) {
if ( viewer.currentIndex !== image.index ) {
return;
}
viewer.displayPlaceholderThumbnail( imageInfo, $initialImage, imageWidths );
} );
metadataPromise = this.fetchSizeIndependentLightboxInfo(
image.filePageTitle
).done( function ( imageInfo, repoInfo, localUsage, globalUsage, userInfo ) {