mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/MultimediaViewer
synced 2024-09-29 13:17:35 +00:00
Merge "Display thumbnail placeholder ASAP"
This commit is contained in:
commit
21ba529db0
|
@ -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';
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 ) {
|
||||
|
|
Loading…
Reference in a new issue