2013-08-07 08:59:08 +00:00
|
|
|
/*
|
|
|
|
* This file is part of the MediaWiki extension MultimediaViewer.
|
|
|
|
*
|
|
|
|
* MultimediaViewer is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* MultimediaViewer is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with MultimediaViewer. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2013-10-28 12:44:00 +00:00
|
|
|
( function ( mw, $, moment ) {
|
2013-11-13 23:01:16 +00:00
|
|
|
var MultiLightbox, lightboxHooks, MMVP,
|
2013-11-25 23:51:40 +00:00
|
|
|
|
|
|
|
comingFromPopstate = false,
|
|
|
|
|
|
|
|
imgsSelector = '.gallery .image img, a.image img',
|
|
|
|
|
2013-10-17 23:38:17 +00:00
|
|
|
validExtensions = {
|
|
|
|
'jpg': true,
|
|
|
|
'jpeg': true,
|
|
|
|
'gif': true,
|
|
|
|
'svg': true,
|
|
|
|
'png': true,
|
|
|
|
'tiff': true,
|
|
|
|
'tif': true
|
|
|
|
},
|
|
|
|
|
2013-10-16 00:28:07 +00:00
|
|
|
mmvLogActions = {
|
|
|
|
'thumbnail-link-click': 'User clicked on thumbnail to open lightbox.',
|
|
|
|
'enlarge-link-click': 'User clicked on enlarge link to open lightbox.',
|
|
|
|
'fullscreen-link-click': 'User clicked on fullscreen button in lightbox.',
|
|
|
|
'defullscreen-link-click': 'User clicked on button to return to normal lightbox view.',
|
2013-10-28 22:55:34 +00:00
|
|
|
'close-link-click': 'User clicked on the lightbox close button.',
|
2013-12-06 17:10:39 +00:00
|
|
|
'site-link-click': 'User clicked on the link to the file description page.',
|
|
|
|
|
|
|
|
// Profiling events start messages, $1 replaced with profile ID
|
|
|
|
'profile-image-load-start': 'Profiling image load with ID $1',
|
|
|
|
'profile-image-resize-start': 'Profiling image resize with ID $1',
|
|
|
|
'profile-metadata-fetch-start': 'Profiling image metadata fetch with ID $1',
|
|
|
|
'profile-gender-fetch-start': 'Profiling uploader gender fetch with ID $1',
|
|
|
|
|
|
|
|
// Profiling events end messages, $1 replaced with profile ID, $2 replaced with time it took in ms
|
|
|
|
'profile-image-load-end': 'Finished image load with ID $1 in $2 milliseconds',
|
|
|
|
'profile-image-resize-end': 'Finished image resize with ID $1 in $2 milliseconds',
|
|
|
|
'profile-metadata-fetch-end': 'Finished image metadata fetch with ID $1 in $2 milliseconds',
|
|
|
|
'profile-gender-fetch-end': 'Finished uploader gender fetch with ID $1 in $2 milliseconds'
|
2013-10-16 00:28:07 +00:00
|
|
|
};
|
2013-08-07 08:59:08 +00:00
|
|
|
|
2013-11-27 21:57:45 +00:00
|
|
|
/**
|
2014-01-11 00:11:37 +00:00
|
|
|
* @class mw.MultimediaViewer
|
|
|
|
* Analyses the page, looks for image content and sets up the hooks
|
2013-11-27 21:57:45 +00:00
|
|
|
* to manage the viewing experience of such content.
|
|
|
|
* @constructor
|
|
|
|
*/
|
2013-08-07 08:59:08 +00:00
|
|
|
function MultimediaViewer() {
|
2013-11-27 21:57:45 +00:00
|
|
|
/**
|
|
|
|
* MultiLightbox object used to display the pictures in the page.
|
2014-01-11 00:11:37 +00:00
|
|
|
* @property {mlb.MultiLightbox}
|
2013-11-27 21:57:45 +00:00
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
this.lightbox = null;
|
|
|
|
|
2013-12-31 00:19:20 +00:00
|
|
|
/**
|
|
|
|
* Whether we've fired an animation for the metadata div.
|
|
|
|
* @property {boolean}
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
this.hasAnimatedMetadata = false;
|
|
|
|
|
2013-11-27 21:57:45 +00:00
|
|
|
var $thumbs = $( imgsSelector ),
|
2013-08-07 08:59:08 +00:00
|
|
|
urls = [],
|
|
|
|
viewer = this;
|
|
|
|
|
2013-11-13 21:16:49 +00:00
|
|
|
/**
|
|
|
|
* @property {number[]}
|
|
|
|
* @private
|
|
|
|
* List of acceptable image sizes...used to bucket
|
|
|
|
*/
|
|
|
|
this.imageWidthBuckets = [
|
|
|
|
320,
|
|
|
|
640,
|
|
|
|
800,
|
|
|
|
1024,
|
|
|
|
1280,
|
|
|
|
1920,
|
|
|
|
2560,
|
|
|
|
2880
|
|
|
|
];
|
|
|
|
|
2013-11-27 21:57:45 +00:00
|
|
|
/**
|
|
|
|
* @property {mw.Api}
|
|
|
|
* @private
|
|
|
|
*/
|
2013-09-26 01:47:59 +00:00
|
|
|
this.api = new mw.Api();
|
2013-11-27 21:57:45 +00:00
|
|
|
|
2014-02-03 20:42:17 +00:00
|
|
|
/**
|
|
|
|
* @property {mw.mmv.provider.ImageInfo}
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
this.imageInfoProvider = new mw.mmv.provider.ImageInfo( this.api, {
|
|
|
|
// Short-circuit, don't fallback, to save some tiny amount of time
|
|
|
|
language: mw.config.get( 'wgUserLanguage', false ) || mw.config.get( 'wgContentLanguage', 'en' )
|
|
|
|
} );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @property {mw.mmv.provider.FileRepoInfo}
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
this.fileRepoInfoProvider = new mw.mmv.provider.FileRepoInfo( this.api );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @property {mw.mmv.provider.ThumbnailInfo}
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
this.thumbnailInfoProvider = new mw.mmv.provider.ThumbnailInfo( this.api );
|
|
|
|
|
2014-01-30 11:28:43 +00:00
|
|
|
/**
|
2014-01-31 00:06:33 +00:00
|
|
|
* @property {mw.mmv.provider.ImageUsage}
|
2014-01-30 11:28:43 +00:00
|
|
|
* @private
|
|
|
|
*/
|
2014-02-03 20:42:17 +00:00
|
|
|
this.imageUsageProvider = new mw.mmv.provider.ImageUsage( this.api );
|
2014-01-30 11:28:43 +00:00
|
|
|
|
|
|
|
/**
|
2014-01-31 00:06:33 +00:00
|
|
|
* @property {mw.mmv.provider.GlobalUsage}
|
2014-01-30 11:28:43 +00:00
|
|
|
* @private
|
|
|
|
*/
|
2014-02-03 20:42:17 +00:00
|
|
|
this.globalUsageProvider = new mw.mmv.provider.GlobalUsage( this.api, {
|
2014-01-30 11:28:43 +00:00
|
|
|
doNotUseApi: !mw.config.get( 'wgMultimediaViewer' ).globalUsageAvailable
|
|
|
|
} );
|
|
|
|
// replace with this one to test global usage on a local wiki without going through all the
|
|
|
|
// hassle required for installing the extension:
|
2014-02-03 20:42:17 +00:00
|
|
|
//this.globalUsageProvider = new mw.mmv.provider.GlobalUsage(
|
2014-01-30 11:28:43 +00:00
|
|
|
// new mw.Api( {ajax: { url: 'http://commons.wikimedia.org/w/api.php', dataType: 'jsonp' } } )
|
|
|
|
//);
|
|
|
|
|
2013-11-27 21:57:45 +00:00
|
|
|
// Traverse DOM, looking for potential thumbnails
|
2013-08-07 08:59:08 +00:00
|
|
|
$thumbs.each( function ( i, thumb ) {
|
2013-12-10 19:54:07 +00:00
|
|
|
var thisImage, $thumbCaption, caption,
|
2013-09-26 01:47:59 +00:00
|
|
|
$thumb = $( thumb ),
|
2013-08-07 08:59:08 +00:00
|
|
|
$link = $thumb.closest( 'a.image' ),
|
|
|
|
$thumbContain = $link.closest( '.thumb' ),
|
|
|
|
$enlarge = $thumbContain.find( '.magnify a' ),
|
|
|
|
$links = $link.add( $enlarge ),
|
|
|
|
filePageLink = $link.prop( 'href' ),
|
2013-09-26 01:47:59 +00:00
|
|
|
fileTitle = mw.Title.newFromImg( $thumb ),
|
|
|
|
index = urls.length;
|
2013-08-07 08:59:08 +00:00
|
|
|
|
2013-10-17 23:38:17 +00:00
|
|
|
if ( !validExtensions[fileTitle.getExtension().toLowerCase()] ) {
|
|
|
|
// Not a valid extension, skip this one
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-11-25 23:51:40 +00:00
|
|
|
if ( $thumbContain.length === 0 ) {
|
|
|
|
// This isn't a thumbnail! Just use the link.
|
|
|
|
$thumbContain = $link;
|
|
|
|
} else if ( $thumbContain.is( '.thumb' ) ) {
|
2013-12-10 19:54:07 +00:00
|
|
|
$thumbCaption = $thumbContain.find( '.thumbcaption' ).clone();
|
|
|
|
$thumbCaption.find( '.magnify' ).remove();
|
|
|
|
viewer.whitelistHtml( $thumbCaption );
|
|
|
|
caption = $thumbCaption.html();
|
2013-11-25 23:51:40 +00:00
|
|
|
$thumbContain = $thumbContain.find( '.image' );
|
|
|
|
}
|
|
|
|
|
2013-08-07 08:59:08 +00:00
|
|
|
$links.data( 'filePageLink', filePageLink );
|
2013-11-25 23:51:40 +00:00
|
|
|
|
2013-11-27 21:57:45 +00:00
|
|
|
// Create a LightboxImage object for each legit image
|
2013-12-10 19:54:07 +00:00
|
|
|
thisImage = viewer.createNewImage( $thumb.prop( 'src' ), filePageLink, fileTitle, index, thumb, caption );
|
2013-11-13 21:16:49 +00:00
|
|
|
|
2013-11-25 23:51:40 +00:00
|
|
|
urls.push( thisImage );
|
2013-08-07 08:59:08 +00:00
|
|
|
|
2013-11-27 21:57:45 +00:00
|
|
|
// Register callback that launches modal image viewer if valid click
|
2013-08-07 08:59:08 +00:00
|
|
|
$links.click( function ( e ) {
|
2013-12-16 18:24:17 +00:00
|
|
|
return viewer.clickLinkCallback( e, this, $thumbContain, thisImage );
|
2013-08-07 08:59:08 +00:00
|
|
|
} );
|
|
|
|
} );
|
|
|
|
|
2013-11-27 21:57:45 +00:00
|
|
|
if ( urls.length === 0 ) {
|
|
|
|
// No legit images found, no need to continue
|
|
|
|
return;
|
2013-08-07 08:59:08 +00:00
|
|
|
}
|
|
|
|
|
2013-11-27 21:57:45 +00:00
|
|
|
// Only if we find legit images, create a MultiLightbox object
|
2014-01-06 21:53:42 +00:00
|
|
|
this.lightbox = new mw.MultiLightbox( urls, 0, mw.LightboxInterface, this );
|
2013-11-27 21:57:45 +00:00
|
|
|
|
|
|
|
// Register various event hooks. TODO: Make this a function that's only called once.
|
|
|
|
|
2013-11-13 00:43:46 +00:00
|
|
|
lightboxHooks.register( 'closeInterface', function () {
|
2014-01-27 16:47:23 +00:00
|
|
|
if ( this.$nextButton ) {
|
|
|
|
this.$nextButton.add( this.$prevButton ).css( 'top', '-999px' );
|
|
|
|
}
|
|
|
|
|
2013-11-13 00:43:46 +00:00
|
|
|
$( document.body ).removeClass( 'mw-mlb-lightbox-open' );
|
2013-11-25 23:51:40 +00:00
|
|
|
if ( comingFromPopstate === false ) {
|
|
|
|
history.pushState( {}, '', '#' );
|
|
|
|
} else {
|
|
|
|
comingFromPopstate = false;
|
|
|
|
}
|
2013-12-31 00:19:20 +00:00
|
|
|
|
|
|
|
viewer.hasAnimatedMetadata = false;
|
2014-01-06 21:53:42 +00:00
|
|
|
viewer.isOpen = false;
|
2013-11-13 00:43:46 +00:00
|
|
|
} );
|
|
|
|
|
2013-10-28 22:32:56 +00:00
|
|
|
lightboxHooks.register( 'imageResize', function () {
|
2013-11-26 03:37:01 +00:00
|
|
|
var ui = this;
|
|
|
|
viewer.resize( ui );
|
2013-10-28 22:32:56 +00:00
|
|
|
return false;
|
|
|
|
} );
|
2013-11-06 00:36:06 +00:00
|
|
|
}
|
2013-10-29 20:26:07 +00:00
|
|
|
|
2013-11-06 00:36:06 +00:00
|
|
|
MMVP = MultimediaViewer.prototype;
|
2013-10-29 20:26:07 +00:00
|
|
|
|
2014-01-22 01:21:22 +00:00
|
|
|
// TODO FIXME HACK delete this when other UI elements have been shifted away.
|
|
|
|
MMVP.whitelistHtml = mw.mmv.ui.Element.prototype.whitelistHtml;
|
2013-12-10 19:54:07 +00:00
|
|
|
|
2013-12-02 19:46:52 +00:00
|
|
|
/**
|
|
|
|
* Create an image object for the lightbox to use.
|
|
|
|
* @protected
|
|
|
|
* @param {string} fileLink Link to the file - generally a thumb URL
|
|
|
|
* @param {string} filePageLink Link to the File: page
|
|
|
|
* @param {mw.Title} fileTitle Represents the File: page
|
|
|
|
* @param {number} index Which number file this is
|
2013-11-13 21:16:49 +00:00
|
|
|
* @param {HTMLImageElement} thumb The thumbnail that represents this image on the page
|
2013-12-10 19:54:07 +00:00
|
|
|
* @param {string} [caption] The caption, if any.
|
2013-12-02 19:46:52 +00:00
|
|
|
* @returns {mw.LightboxImage}
|
|
|
|
*/
|
2013-12-10 19:54:07 +00:00
|
|
|
MMVP.createNewImage = function ( fileLink, filePageLink, fileTitle, index, thumb, caption ) {
|
|
|
|
var thisImage = new mw.LightboxImage( fileLink, filePageLink, fileTitle, index, thumb, caption );
|
2013-12-02 19:46:52 +00:00
|
|
|
thisImage.filePageLink = filePageLink;
|
|
|
|
thisImage.filePageTitle = fileTitle;
|
|
|
|
thisImage.index = index;
|
2013-11-13 21:16:49 +00:00
|
|
|
thisImage.thumbnail = thumb;
|
2013-12-02 19:46:52 +00:00
|
|
|
|
|
|
|
return thisImage;
|
|
|
|
};
|
|
|
|
|
2013-11-13 21:16:49 +00:00
|
|
|
/**
|
|
|
|
* Finds the next highest image size given a target size.
|
|
|
|
* Searches the bucketed sizes configured in the class.
|
|
|
|
* @param {number} target
|
|
|
|
* @return {number}
|
|
|
|
*/
|
|
|
|
MMVP.findNextHighestImageSize = function ( target ) {
|
|
|
|
var i, bucket,
|
|
|
|
buckets = this.imageWidthBuckets,
|
|
|
|
len = buckets.length;
|
|
|
|
|
|
|
|
for ( i = 0; i < len; i++ ) {
|
|
|
|
bucket = buckets[i];
|
|
|
|
|
|
|
|
if ( bucket >= target ) {
|
|
|
|
return bucket;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we failed to find a high enough size...good luck
|
|
|
|
return bucket;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the API arguments for various calls to the API to find sized thumbnails.
|
|
|
|
* @param {mw.LightboxInterface} ui
|
2014-01-06 19:43:18 +00:00
|
|
|
* @returns {Object}
|
|
|
|
* @returns {number} return.requested The width that should be requested from the API
|
|
|
|
* @returns {number} return.target The ideal width we would like to have - should be the width of the image element later.
|
2013-11-13 21:16:49 +00:00
|
|
|
*/
|
|
|
|
MMVP.getImageSizeApiArgs = function ( ui ) {
|
|
|
|
var requestedWidth, calculatedMaxWidth,
|
|
|
|
thumb = ui.currentImage.thumbnail,
|
2014-01-24 00:16:13 +00:00
|
|
|
targetWidth = ui.$imageWrapper.width(),
|
|
|
|
targetHeight = ui.$imageWrapper.height();
|
2013-11-13 21:16:49 +00:00
|
|
|
|
|
|
|
if ( ( targetWidth / targetHeight ) > ( thumb.width / thumb.height ) ) {
|
|
|
|
// Need to find width corresponding to highest height we can have.
|
|
|
|
calculatedMaxWidth = ( thumb.width / thumb.height ) * targetHeight;
|
|
|
|
requestedWidth = this.findNextHighestImageSize( calculatedMaxWidth );
|
|
|
|
} else {
|
|
|
|
// Simple case, ratio tells us we're limited by width
|
|
|
|
requestedWidth = this.findNextHighestImageSize( targetWidth );
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
2014-01-28 01:08:00 +00:00
|
|
|
// Factor in pixel ratio so we get as many pixels as the device supports, see b/60388
|
|
|
|
requested: requestedWidth * $.devicePixelRatio(),
|
2013-11-13 21:16:49 +00:00
|
|
|
target: calculatedMaxWidth || targetWidth
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2013-11-27 21:57:45 +00:00
|
|
|
/**
|
|
|
|
* Handles clicks on legit image links.
|
|
|
|
*
|
|
|
|
* @protected
|
|
|
|
*
|
|
|
|
* @param {jQuery.Event} e click event
|
|
|
|
* @param {HTMLElement|jQuery} clickedEle clicked element
|
|
|
|
* @param {jQuery} $thumbContain thumbnail container element
|
|
|
|
* @param {mw.LightboxImage} thisImage lightboximage object
|
|
|
|
*/
|
|
|
|
MMVP.clickLinkCallback = function ( e, clickedEle, $thumbContain, thisImage ) {
|
|
|
|
// Do not interfere with non-left clicks or if modifier keys are pressed.
|
|
|
|
if ( e.which !== 1 || e.altKey || e.ctrlKey || e.shiftKey || e.metaKey ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var $clickedEle = $( clickedEle ),
|
|
|
|
initial = $thumbContain.find( 'img' ).prop( 'src' );
|
|
|
|
|
|
|
|
if ( $clickedEle.is( 'a.image' ) ) {
|
|
|
|
this.log( 'thumbnail-link-click' );
|
|
|
|
} else if ( $clickedEle.is( '.magnify a' ) ) {
|
|
|
|
this.log( 'enlarge-link-click' );
|
|
|
|
}
|
|
|
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
|
|
|
this.loadImage( thisImage, initial );
|
2013-12-16 18:24:17 +00:00
|
|
|
|
|
|
|
return false;
|
2013-11-27 21:57:45 +00:00
|
|
|
};
|
|
|
|
|
2013-12-03 01:58:09 +00:00
|
|
|
/**
|
|
|
|
* Handles resize events in viewer.
|
|
|
|
*
|
|
|
|
* @protected
|
|
|
|
*
|
|
|
|
* @param {mw.LightboxInterface} ui lightbox that got resized
|
|
|
|
*/
|
2013-11-26 03:37:01 +00:00
|
|
|
MMVP.resize = function ( ui ) {
|
2013-12-03 01:58:09 +00:00
|
|
|
var viewer = this,
|
2014-01-06 20:02:39 +00:00
|
|
|
fileTitle = this.currentImageFileTitle;
|
2013-11-13 21:16:49 +00:00
|
|
|
|
2014-01-30 07:22:26 +00:00
|
|
|
if ( fileTitle ) {
|
2014-02-03 20:42:17 +00:00
|
|
|
this.fetchImageInfo( fileTitle ).done( function ( imageData, repoInfo, targetWidth, requestedWidth ) {
|
2014-01-30 07:22:26 +00:00
|
|
|
viewer.loadResizedImage( ui, imageData, targetWidth, requestedWidth );
|
|
|
|
} );
|
|
|
|
}
|
2014-01-06 21:53:42 +00:00
|
|
|
|
|
|
|
this.updateControls();
|
2013-12-03 01:58:09 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Replaces the resized image in the viewer providing we actually got some data.
|
|
|
|
*
|
|
|
|
* @protected
|
|
|
|
*
|
2014-01-11 00:11:37 +00:00
|
|
|
* @param {mw.LightboxInterface} ui lightbox that got resized
|
2014-01-10 21:11:21 +00:00
|
|
|
* @param {mw.mmv.model.Image} imageData information regarding the new resized image
|
2013-11-13 21:16:49 +00:00
|
|
|
* @param {number} targetWidth
|
2014-01-15 05:26:38 +00:00
|
|
|
* @param {number} requestedWidth
|
2013-12-03 01:58:09 +00:00
|
|
|
*/
|
2014-01-10 21:11:21 +00:00
|
|
|
MMVP.loadResizedImage = function ( ui, imageData, targetWidth, requestedWidth ) {
|
2013-12-03 01:58:09 +00:00
|
|
|
// Replace image only if data was returned.
|
2014-01-10 21:11:21 +00:00
|
|
|
if ( imageData ) {
|
2014-01-28 23:57:05 +00:00
|
|
|
this.loadAndSetImage( ui, imageData, targetWidth, requestedWidth, 'image-resize' );
|
2013-12-03 01:58:09 +00:00
|
|
|
}
|
2013-11-26 03:37:01 +00:00
|
|
|
};
|
|
|
|
|
2013-11-13 00:43:46 +00:00
|
|
|
MMVP.updateControls = function () {
|
2014-01-14 15:42:52 +00:00
|
|
|
var ui = this.ui,
|
2013-12-31 21:18:22 +00:00
|
|
|
prevNextTop = ( ( ui.$imageWrapper.height() / 2 ) - 60 ) + 'px';
|
2013-11-13 00:43:46 +00:00
|
|
|
|
|
|
|
ui.$postDiv.css( 'top', ui.$imageWrapper.height() );
|
|
|
|
|
2013-11-26 03:37:01 +00:00
|
|
|
ui.$nextButton.add( ui.$prevButton ).css( {
|
|
|
|
top: prevNextTop
|
|
|
|
} );
|
|
|
|
|
2014-01-30 07:22:26 +00:00
|
|
|
ui.$nextButton.toggleClass( 'disabled', this.lightbox.currentIndex >= ( ( this.lightbox.images ? this.lightbox.images.length : 0 ) - 1 ) );
|
2013-11-26 03:37:01 +00:00
|
|
|
ui.$prevButton.toggleClass( 'disabled', this.lightbox.currentIndex <= 0 );
|
2013-11-13 00:43:46 +00:00
|
|
|
};
|
2013-11-06 00:36:06 +00:00
|
|
|
|
|
|
|
MMVP.registerLogging = function () {
|
|
|
|
var viewer = this;
|
|
|
|
|
|
|
|
this.ui.$closeButton.click( function () {
|
|
|
|
if ( viewer.ui.$dialog ) {
|
|
|
|
viewer.ui.$dialog.dialog( 'close' );
|
|
|
|
}
|
|
|
|
|
|
|
|
viewer.log( 'close-link-click' );
|
2013-10-23 23:51:34 +00:00
|
|
|
} );
|
2013-08-07 08:59:08 +00:00
|
|
|
|
2013-11-06 00:36:06 +00:00
|
|
|
this.ui.$fullscreenButton.click( function () {
|
2014-01-02 22:24:42 +00:00
|
|
|
if ( viewer.ui.isFullscreen ) {
|
2013-11-06 00:36:06 +00:00
|
|
|
viewer.log( 'fullscreen-link-click' );
|
|
|
|
} else {
|
|
|
|
viewer.log( 'defullscreen-link-click' );
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
};
|
|
|
|
|
2014-01-07 20:19:34 +00:00
|
|
|
/**
|
2014-01-10 21:11:21 +00:00
|
|
|
* @method
|
|
|
|
* Get first (hopefully only) member of an object.
|
|
|
|
* @param {Array|Object} things
|
|
|
|
* @returns {Mixed}
|
2014-01-07 20:19:34 +00:00
|
|
|
*/
|
2014-01-10 21:11:21 +00:00
|
|
|
MMVP.getFirst = function ( things ) {
|
|
|
|
var thing;
|
2014-01-07 20:19:34 +00:00
|
|
|
|
2014-01-10 21:11:21 +00:00
|
|
|
if ( things ) {
|
|
|
|
$.each( things, function ( i, thisone ) {
|
|
|
|
thing = thisone;
|
2014-01-07 20:19:34 +00:00
|
|
|
return false;
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
|
2014-01-10 21:11:21 +00:00
|
|
|
return thing;
|
2014-01-07 20:19:34 +00:00
|
|
|
};
|
|
|
|
|
2014-01-10 21:11:21 +00:00
|
|
|
/**
|
|
|
|
* @method
|
|
|
|
* Set the image information in the UI.
|
2013-12-10 19:54:07 +00:00
|
|
|
* @param {mw.LightboxImage} image
|
2014-01-10 21:11:21 +00:00
|
|
|
* @param {mw.mmv.model.Image} imageData
|
|
|
|
* @param {mw.mmv.model.Repo} repoData
|
2014-01-30 11:28:43 +00:00
|
|
|
* @param {mw.mmv.model.FileUsage} localUsage
|
|
|
|
* @param {mw.mmv.model.FileUsage} globalUsage
|
2014-01-10 21:11:21 +00:00
|
|
|
*/
|
2014-01-30 11:28:43 +00:00
|
|
|
MMVP.setImageInfo = function ( image, imageData, repoData, localUsage, globalUsage ) {
|
2014-01-10 21:11:21 +00:00
|
|
|
var gfpid,
|
|
|
|
msgname,
|
2013-12-10 19:54:07 +00:00
|
|
|
fileTitle = image.filePageTitle,
|
|
|
|
caption = image.caption,
|
2013-12-06 17:10:39 +00:00
|
|
|
viewer = this,
|
2014-01-10 21:11:21 +00:00
|
|
|
ui = this.lightbox.iface;
|
2013-10-28 22:32:56 +00:00
|
|
|
|
|
|
|
ui.$title.text( fileTitle.getNameText() );
|
|
|
|
|
2014-01-10 21:11:21 +00:00
|
|
|
ui.initUseFileData( fileTitle, imageData.url, repoData.isLocal );
|
2013-10-29 02:31:23 +00:00
|
|
|
ui.$useFileLi.removeClass( 'empty' );
|
|
|
|
|
2014-01-15 16:18:33 +00:00
|
|
|
ui.setRepoDisplay( repoData.displayName, repoData.favIcon, repoData.isLocal );
|
2014-01-10 21:11:21 +00:00
|
|
|
ui.setFilePageLink( imageData.descriptionUrl );
|
2013-10-28 22:32:56 +00:00
|
|
|
|
2014-01-10 21:11:21 +00:00
|
|
|
ui.$repoLi.removeClass( 'empty' );
|
2013-10-28 22:32:56 +00:00
|
|
|
|
2014-01-10 21:11:21 +00:00
|
|
|
if ( imageData.lastUploader ) {
|
2013-12-06 17:10:39 +00:00
|
|
|
gfpid = this.profileStart( 'gender-fetch' );
|
|
|
|
|
2013-12-03 01:58:09 +00:00
|
|
|
// TODO: Reuse the api member, fix everywhere.
|
2013-10-28 22:32:56 +00:00
|
|
|
// Fetch the gender from the uploader's home wiki
|
|
|
|
// TODO this is ugly as hell, let's fix this in core.
|
|
|
|
new mw.Api( {
|
|
|
|
ajax: {
|
2014-01-13 10:29:59 +00:00
|
|
|
url: repoData.apiUrl || mw.util.wikiScript( 'api' ),
|
|
|
|
dataType: 'jsonp'
|
2013-10-28 22:32:56 +00:00
|
|
|
}
|
|
|
|
} ).get( {
|
|
|
|
action: 'query',
|
|
|
|
list: 'users',
|
2014-01-10 21:11:21 +00:00
|
|
|
ususers: imageData.lastUploader,
|
2013-10-28 22:32:56 +00:00
|
|
|
usprop: 'gender'
|
|
|
|
} ).done( function ( data ) {
|
2014-01-10 21:11:21 +00:00
|
|
|
var gender = 'unknown';
|
2013-12-06 17:10:39 +00:00
|
|
|
|
|
|
|
viewer.profileEnd( gfpid );
|
|
|
|
|
2014-01-10 21:11:21 +00:00
|
|
|
if ( data && data.query && data.query.users &&
|
|
|
|
data.query.users[0] && data.query.users[0].gender ) {
|
|
|
|
gender = data.query.users[0].gender;
|
|
|
|
}
|
|
|
|
|
|
|
|
ui.setUserPageLink( repoData, imageData.lastUploader, gender );
|
2013-10-28 22:32:56 +00:00
|
|
|
} ).fail( function () {
|
2013-12-06 17:10:39 +00:00
|
|
|
mw.log( 'Gender fetch with ID ' + gfpid + ' failed, probably due to cross-domain API request.' );
|
2014-01-10 21:11:21 +00:00
|
|
|
ui.setUserPageLink( repoData, imageData.lastUploader, 'unknown' );
|
2013-10-28 22:32:56 +00:00
|
|
|
} );
|
|
|
|
}
|
|
|
|
|
2014-01-10 21:11:21 +00:00
|
|
|
if ( imageData.creationDateTime ) {
|
|
|
|
ui.$datetime.text(
|
|
|
|
mw.message(
|
|
|
|
'multimediaviewer-datetime-created',
|
|
|
|
this.formatDate( imageData.creationDateTime )
|
|
|
|
).text()
|
|
|
|
);
|
|
|
|
} else if ( imageData.uploadDateTime ) {
|
|
|
|
ui.$datetime.text(
|
|
|
|
mw.message(
|
|
|
|
'multimediaviewer-datetime-uploaded',
|
|
|
|
this.formatDate( imageData.uploadDateTime )
|
|
|
|
).text()
|
|
|
|
);
|
|
|
|
}
|
2013-10-28 22:32:56 +00:00
|
|
|
|
2014-01-10 21:11:21 +00:00
|
|
|
ui.$datetimeLi.toggleClass( 'empty', !imageData.uploadDateTime && !imageData.creationDateTime );
|
2013-10-28 22:32:56 +00:00
|
|
|
|
2014-01-10 21:11:21 +00:00
|
|
|
if ( imageData.source ) {
|
2013-12-10 19:54:07 +00:00
|
|
|
this.whitelistHtml( ui.$source.empty().append( $.parseHTML( imageData.source ) ) );
|
2014-01-10 21:11:21 +00:00
|
|
|
}
|
2013-10-28 22:32:56 +00:00
|
|
|
|
2014-01-10 21:11:21 +00:00
|
|
|
if ( imageData.author ) {
|
2013-12-10 19:54:07 +00:00
|
|
|
this.whitelistHtml( ui.$author.empty().append( $.parseHTML( imageData.author ) ) );
|
2014-01-10 21:11:21 +00:00
|
|
|
}
|
2013-10-28 22:32:56 +00:00
|
|
|
|
2014-01-10 21:11:21 +00:00
|
|
|
if ( imageData.source && imageData.author ) {
|
|
|
|
ui.$credit.html(
|
|
|
|
mw.message(
|
|
|
|
'multimediaviewer-credit',
|
|
|
|
ui.$author.get( 0 ).outerHTML,
|
|
|
|
ui.$source.get( 0 ).outerHTML
|
|
|
|
).plain()
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
// Clobber the contents and only have one of the fields
|
|
|
|
if ( imageData.source ) {
|
|
|
|
ui.$credit.empty().append( ui.$source );
|
|
|
|
} else if ( imageData.author ) {
|
|
|
|
ui.$credit.empty().append( ui.$author );
|
2013-10-28 22:32:56 +00:00
|
|
|
}
|
2013-10-16 23:50:51 +00:00
|
|
|
}
|
|
|
|
|
2014-01-10 21:11:21 +00:00
|
|
|
ui.$credit.toggleClass( 'empty', !imageData.source && !imageData.author );
|
2013-10-16 23:50:51 +00:00
|
|
|
|
2014-01-22 01:21:22 +00:00
|
|
|
ui.description.set( imageData.description, caption );
|
2014-02-03 11:13:37 +00:00
|
|
|
ui.categories.set( repoData.getArticlePath(), imageData.categories );
|
2013-12-10 19:54:07 +00:00
|
|
|
|
2014-01-10 21:11:21 +00:00
|
|
|
msgname = 'multimediaviewer-license-' + ( imageData.license || '' );
|
2013-10-16 23:50:51 +00:00
|
|
|
|
2014-01-10 21:11:21 +00:00
|
|
|
if ( !imageData.license || !mw.messages.exists( msgname ) ) {
|
2013-10-16 23:50:51 +00:00
|
|
|
// Cannot display, fallback or fail
|
|
|
|
msgname = 'multimediaviewer-license-default';
|
2013-12-18 23:20:58 +00:00
|
|
|
} else {
|
|
|
|
// License found, store the license data
|
|
|
|
ui.$license.data( 'license', mw.message( msgname ).text() );
|
2013-10-28 22:32:56 +00:00
|
|
|
}
|
2013-10-16 23:50:51 +00:00
|
|
|
|
2014-01-10 21:11:21 +00:00
|
|
|
ui.$license
|
|
|
|
.text( mw.message( msgname ).text() )
|
|
|
|
.toggleClass( 'cc-license', imageData.isCcLicensed() );
|
2013-10-16 23:50:51 +00:00
|
|
|
|
2014-01-10 21:11:21 +00:00
|
|
|
ui.$license.toggleClass( 'empty', !imageData.license );
|
2014-01-13 21:40:22 +00:00
|
|
|
|
|
|
|
this.setLocationData( imageData );
|
|
|
|
ui.$locationLi.toggleClass( 'empty', !imageData.hasCoords() );
|
2014-01-30 11:28:43 +00:00
|
|
|
|
|
|
|
ui.fileUsage.set( localUsage, globalUsage );
|
2014-01-13 21:40:22 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @method
|
|
|
|
* Sets location data in the interface.
|
|
|
|
* @param {mw.mmv.model.Image} imageData
|
|
|
|
*/
|
|
|
|
MMVP.setLocationData = function ( imageData ) {
|
|
|
|
var latsec, latitude, latmsg, latdeg, latremain, latmin,
|
|
|
|
longsec, longitude, longmsg, longdeg, longremain, longmin;
|
|
|
|
|
|
|
|
if ( !imageData.hasCoords() ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
latitude = imageData.latitude >= 0 ? imageData.latitude : imageData.latitude * -1;
|
|
|
|
latmsg = 'multimediaviewer-geoloc-' + ( imageData.latitude >= 0 ? 'north' : 'south' );
|
|
|
|
latdeg = Math.floor( latitude );
|
|
|
|
latremain = latitude - latdeg;
|
|
|
|
latmin = Math.floor( ( latremain ) * 60 );
|
|
|
|
|
|
|
|
longitude = imageData.longitude >= 0 ? imageData.longitude : imageData.longitude * -1;
|
|
|
|
longmsg = 'multimediaviewer-geoloc-' + ( imageData.longitude >= 0 ? 'east' : 'west' );
|
|
|
|
longdeg = Math.floor( longitude );
|
|
|
|
longremain = longitude - longdeg;
|
|
|
|
longmin = Math.floor( ( longremain ) * 60 );
|
|
|
|
|
|
|
|
longremain -= longmin / 60;
|
|
|
|
latremain -= latmin / 60;
|
|
|
|
latsec = Math.round( latremain * 100 * 60 * 60 ) / 100;
|
|
|
|
longsec = Math.round( longremain * 100 * 60 * 60 ) / 100;
|
|
|
|
|
|
|
|
this.lightbox.iface.setLocationData(
|
|
|
|
latdeg, latmin, latsec, latmsg,
|
|
|
|
longdeg, longmin, longsec, longmsg,
|
|
|
|
imageData.latitude, imageData.longitude,
|
|
|
|
this.getFirst( Object.keys( mw.language.data ) ),
|
|
|
|
imageData.title.getMain()
|
|
|
|
);
|
2013-10-28 22:32:56 +00:00
|
|
|
};
|
|
|
|
|
2014-01-28 23:57:05 +00:00
|
|
|
/**
|
|
|
|
* @method
|
|
|
|
* Loads and sets the image specified in the imageData. It also updates the controls
|
|
|
|
* and collects profiling information.
|
|
|
|
*
|
|
|
|
* @param {mw.LightboxInterface} ui image container
|
|
|
|
* @param {mw.mmv.model.Image} imageData image information
|
|
|
|
* @param {number} targetWidth
|
|
|
|
* @param {number} requestedWidth
|
|
|
|
* @param {string} profileEvent profile event key
|
|
|
|
*/
|
|
|
|
MMVP.loadAndSetImage = function ( ui, imageData, targetWidth, requestedWidth, profileEvent ) {
|
|
|
|
var rpid,
|
|
|
|
maybeThumb,
|
|
|
|
viewer = this,
|
|
|
|
image = new Image();
|
|
|
|
|
|
|
|
image.onload = function () {
|
|
|
|
viewer.profileEnd( rpid );
|
|
|
|
};
|
|
|
|
|
|
|
|
rpid = this.profileStart( profileEvent, {
|
|
|
|
width: imageData.width,
|
|
|
|
height: imageData.height,
|
|
|
|
fileSize: imageData.size
|
|
|
|
}, imageData.mimeType );
|
|
|
|
|
|
|
|
// Use cached image if we have it.
|
|
|
|
maybeThumb = imageData.getThumbUrl( requestedWidth );
|
|
|
|
image.src = maybeThumb || imageData.url;
|
|
|
|
|
|
|
|
if ( maybeThumb && requestedWidth > targetWidth ||
|
|
|
|
!maybeThumb && imageData.width > targetWidth ) {
|
|
|
|
// Image bigger than the current area, resize before loading
|
|
|
|
image.width = targetWidth;
|
|
|
|
}
|
|
|
|
|
|
|
|
ui.replaceImageWith( image );
|
|
|
|
this.updateControls();
|
|
|
|
};
|
|
|
|
|
2013-12-10 19:54:07 +00:00
|
|
|
/**
|
|
|
|
* @method
|
|
|
|
* Loads a specified image.
|
|
|
|
* @param {mw.LightboxImage} image
|
|
|
|
* @param {string} initialSrc The string to set the src attribute to at first.
|
|
|
|
*/
|
2013-11-25 23:51:40 +00:00
|
|
|
MMVP.loadImage = function ( image, initialSrc ) {
|
2013-12-06 17:10:39 +00:00
|
|
|
var mdpid,
|
|
|
|
viewer = this;
|
2013-11-25 23:51:40 +00:00
|
|
|
|
|
|
|
this.lightbox.currentIndex = image.index;
|
|
|
|
|
|
|
|
// Open with the already-loaded thumbnail
|
|
|
|
// Avoids trying to load /wiki/Undefined and doesn't
|
|
|
|
// cost any network time - the library currently needs
|
|
|
|
// some src attribute to work. Will fix.
|
2013-12-10 21:04:45 +00:00
|
|
|
image.initialSrc = initialSrc;
|
2013-11-25 23:51:40 +00:00
|
|
|
this.currentImageFilename = image.filePageTitle.getPrefixedText();
|
2014-01-06 20:02:39 +00:00
|
|
|
this.currentImageFileTitle = image.filePageTitle;
|
2013-11-25 23:51:40 +00:00
|
|
|
this.lightbox.iface.comingFromPopstate = comingFromPopstate;
|
2014-01-06 21:53:42 +00:00
|
|
|
|
|
|
|
if ( !this.isOpen ) {
|
|
|
|
this.lightbox.open();
|
|
|
|
this.isOpen = true;
|
|
|
|
} else {
|
|
|
|
this.lightbox.iface.empty();
|
|
|
|
this.lightbox.iface.load( image );
|
|
|
|
}
|
|
|
|
|
2013-11-25 23:51:40 +00:00
|
|
|
$( document.body ).addClass( 'mw-mlb-lightbox-open' );
|
|
|
|
|
2013-12-06 17:10:39 +00:00
|
|
|
mdpid = this.profileStart( 'metadata-fetch' );
|
|
|
|
|
2014-01-30 11:28:43 +00:00
|
|
|
this.fetchImageInfoAndFileUsageInfo( image.filePageTitle ).then( function ( imageData, repoInfo, targetWidth, requestedWidth, localUsage, globalUsage ) {
|
2014-01-28 23:57:05 +00:00
|
|
|
var repoData = mw.mmv.model.Repo.newFromRepoInfo( repoInfo[imageData.repo] );
|
|
|
|
|
|
|
|
viewer.profileEnd( mdpid );
|
2013-12-06 17:10:39 +00:00
|
|
|
|
2014-01-23 00:38:01 +00:00
|
|
|
viewer.stopListeningToScroll();
|
|
|
|
viewer.animateMetadataDivOnce()
|
|
|
|
// We need to wait until the animation is finished before we listen to scroll
|
|
|
|
.then( function() { viewer.startListeningToScroll(); } );
|
2013-11-25 23:51:40 +00:00
|
|
|
|
2014-01-28 23:57:05 +00:00
|
|
|
viewer.loadAndSetImage( viewer.lightbox.iface, imageData, targetWidth, requestedWidth, 'image-load' );
|
2013-12-10 21:04:45 +00:00
|
|
|
|
|
|
|
viewer.lightbox.iface.$imageDiv.removeClass( 'empty' );
|
2014-01-30 11:28:43 +00:00
|
|
|
viewer.setImageInfo( image, imageData, repoData, localUsage, globalUsage );
|
2013-11-25 23:51:40 +00:00
|
|
|
} );
|
|
|
|
|
|
|
|
comingFromPopstate = false;
|
|
|
|
};
|
|
|
|
|
2014-01-23 00:38:01 +00:00
|
|
|
/**
|
|
|
|
* @method
|
|
|
|
* Animates the metadata area when the viewer is first opened.
|
|
|
|
* @return {jQuery.Promise} an empty promise which resolves when the animation is finished
|
|
|
|
*/
|
2014-01-07 19:58:29 +00:00
|
|
|
MMVP.animateMetadataDivOnce = function () {
|
|
|
|
if ( !this.hasAnimatedMetadata ) {
|
|
|
|
this.hasAnimatedMetadata = true;
|
2014-01-23 00:38:01 +00:00
|
|
|
$.scrollTo( 40, 400 )
|
|
|
|
.scrollTo( 0, 400 );
|
2014-01-07 19:58:29 +00:00
|
|
|
}
|
2014-01-23 00:38:01 +00:00
|
|
|
return $.scrollTo.window().promise();
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @method
|
|
|
|
* Stop listening to the page's scroll events
|
|
|
|
*/
|
|
|
|
MMVP.stopListeningToScroll = function () {
|
|
|
|
$.scrollTo().off( 'scroll.mmvp' );
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @method
|
|
|
|
* Start listening to the page's scroll events
|
|
|
|
* Will call MMVP.scroll(), throttled so it is not triggered on every pixel.
|
|
|
|
*/
|
|
|
|
MMVP.startListeningToScroll = function () {
|
|
|
|
var viewer = this;
|
|
|
|
|
|
|
|
$.scrollTo().on( 'scroll.mmvp', $.throttle( 250, function() { viewer.scroll(); } ) );
|
|
|
|
|
|
|
|
// Trigger a check in case the user scrolled manually during the animation
|
|
|
|
viewer.scroll();
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @method
|
|
|
|
* Receives the window's scroll events and flips the chevron if necessary.
|
|
|
|
*/
|
|
|
|
MMVP.scroll = function () {
|
|
|
|
this.ui.$dragIcon.toggleClass( 'pointing-down', !!$.scrollTo().scrollTop() );
|
2013-12-31 00:19:20 +00:00
|
|
|
};
|
|
|
|
|
2014-01-06 20:02:39 +00:00
|
|
|
/**
|
|
|
|
* @method
|
|
|
|
* Fetches image information from the API.
|
2014-01-07 20:19:34 +00:00
|
|
|
*
|
2014-01-10 21:11:21 +00:00
|
|
|
* Will resolve the promise with two objects (imageData and repoData), the
|
2014-01-07 20:19:34 +00:00
|
|
|
* target width - basically the screen size - that the caller should resize
|
2014-01-10 21:11:21 +00:00
|
|
|
* the image to eventually, and the requested width - that is, what we asked
|
|
|
|
* for from the API - that should be used to fetch the thumbnail URL from
|
|
|
|
* the imageData object.
|
|
|
|
*
|
|
|
|
* The target
|
2014-01-06 20:02:39 +00:00
|
|
|
* @param {mw.Title} fileTitle Title of the file page for the image.
|
2014-01-07 20:19:34 +00:00
|
|
|
* @returns {jQuery.Promise}
|
2014-01-06 20:02:39 +00:00
|
|
|
*/
|
2014-02-03 20:42:17 +00:00
|
|
|
MMVP.fetchImageInfo = function ( fileTitle ) {
|
|
|
|
var widths = this.getImageSizeApiArgs( this.ui ),
|
2013-11-13 21:16:49 +00:00
|
|
|
targetWidth = widths.target,
|
|
|
|
requestedWidth = widths.requested;
|
|
|
|
|
2014-02-03 20:42:17 +00:00
|
|
|
return $.when(
|
|
|
|
this.fileRepoInfoProvider.get(),
|
|
|
|
this.imageInfoProvider.get( fileTitle ),
|
|
|
|
this.thumbnailInfoProvider.get( fileTitle, requestedWidth )
|
|
|
|
).then( function( fileRepoInfoHash, imageInfo, thumbnailData ) {
|
|
|
|
var thumbnailUrl = thumbnailData[0],
|
|
|
|
thumbnailWidth = thumbnailData[1];
|
|
|
|
imageInfo.addThumbUrl( thumbnailWidth, thumbnailUrl );
|
|
|
|
return $.Deferred().resolve( imageInfo, fileRepoInfoHash, targetWidth, requestedWidth );
|
|
|
|
} );
|
2013-09-26 01:47:59 +00:00
|
|
|
};
|
|
|
|
|
2014-01-30 11:28:43 +00:00
|
|
|
/**
|
|
|
|
* Gets file usage info.
|
|
|
|
* @param {mw.Title} fileTitle Title of the file page for the image.
|
|
|
|
* @returns {jQuery.Promise.<mw.mmv.model.FileUsage, mw.mmv.model.FileUsage>} a promise
|
|
|
|
* resolving to a local and a global file usage object
|
|
|
|
* FIXME should be parallel with the other fetches, or even better if it can be integrated
|
|
|
|
* into the same API calls. Lets get it out first though.
|
|
|
|
*/
|
|
|
|
MMVP.fetchFileUsageInfo = function ( fileTitle ) {
|
|
|
|
return $.when(
|
2014-02-03 20:42:17 +00:00
|
|
|
this.imageUsageProvider.get( fileTitle ),
|
|
|
|
this.globalUsageProvider.get( fileTitle )
|
2014-01-30 11:28:43 +00:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets all file-related info.
|
|
|
|
* @param {mw.Title} fileTitle Title of the file page for the image.
|
|
|
|
* @returns {jQuery.Promise.<mw.mmv.model.Image, mw.mmv.model.Repo, Number, Number,
|
|
|
|
* mw.mmv.model.FileUsage, mw.mmv.model.FileUsage>}
|
|
|
|
*/
|
|
|
|
MMVP.fetchImageInfoAndFileUsageInfo = function ( fileTitle ) {
|
|
|
|
return $.when(
|
|
|
|
this.fetchImageInfo( fileTitle ),
|
|
|
|
this.fetchFileUsageInfo( fileTitle )
|
|
|
|
).then( function( first, second ) {
|
|
|
|
var d = $.Deferred();
|
|
|
|
return d.resolve.apply( d, first.concat( second ) );
|
|
|
|
} );
|
|
|
|
};
|
|
|
|
|
2013-11-26 03:37:01 +00:00
|
|
|
MMVP.loadIndex = function ( index ) {
|
2013-12-10 19:54:07 +00:00
|
|
|
var $clicked = $( imgsSelector ).eq( index );
|
2013-11-26 03:37:01 +00:00
|
|
|
if ( index < this.lightbox.images.length && index >= 0 ) {
|
2013-12-10 19:54:07 +00:00
|
|
|
this.loadImage( this.lightbox.images[index], $clicked.prop( 'src' ) );
|
2013-11-26 03:37:01 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
MMVP.nextImage = function () {
|
|
|
|
this.loadIndex( this.lightbox.currentIndex + 1 );
|
|
|
|
};
|
|
|
|
|
|
|
|
MMVP.prevImage = function () {
|
|
|
|
this.loadIndex( this.lightbox.currentIndex - 1 );
|
|
|
|
};
|
|
|
|
|
2013-11-06 00:36:06 +00:00
|
|
|
MMVP.log = function ( action ) {
|
2013-10-16 00:28:07 +00:00
|
|
|
mw.log( mmvLogActions[action] || action );
|
|
|
|
|
|
|
|
if ( mw.eventLog ) {
|
|
|
|
mw.eventLog.logEvent( 'MediaViewer', {
|
2013-12-06 17:10:39 +00:00
|
|
|
version: '1.1',
|
|
|
|
action: action
|
2013-10-16 00:28:07 +00:00
|
|
|
} );
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-12-06 17:10:39 +00:00
|
|
|
( function () {
|
|
|
|
var profiling = {},
|
|
|
|
nonce = 0;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Start profiling an event
|
|
|
|
* @param {string} type Can be image-load, image-resize, metadata-fetch, gender-fetch
|
2014-01-11 00:11:37 +00:00
|
|
|
* @param {Object} [imgSize] Size of image (for image related events)
|
2013-12-06 17:10:39 +00:00
|
|
|
* @param {number} [imgSize.width] In pixels
|
|
|
|
* @param {number} [imgSize.height] In pixels
|
|
|
|
* @param {number} [imgSize.filesize] In bytes
|
|
|
|
* @param {string} [fileType] File type (for image related events)
|
|
|
|
* @param {number} [timeout] Optional timeout for the event.
|
|
|
|
* @returns {number} The id used to finish the profiling
|
|
|
|
*/
|
|
|
|
MMVP.profileStart = function ( type, imgSize, fileType, timeout ) {
|
|
|
|
var thisid = nonce++;
|
|
|
|
|
|
|
|
imgSize = imgSize || {};
|
|
|
|
|
|
|
|
profiling[thisid] = {
|
2014-01-08 17:22:52 +00:00
|
|
|
/* Changelog:
|
|
|
|
* 1.1 fixed the issue with zeros in every message
|
|
|
|
* 1.0 first release
|
|
|
|
*/
|
|
|
|
version: '1.1',
|
2013-12-06 17:10:39 +00:00
|
|
|
action: type,
|
|
|
|
imageWidth: imgSize.width,
|
|
|
|
imageHeight: imgSize.height,
|
|
|
|
fileSize: imgSize.filesize,
|
|
|
|
fileType: fileType,
|
|
|
|
userAgent: navigator.userAgent,
|
|
|
|
start: Date.now()
|
|
|
|
};
|
|
|
|
|
|
|
|
mw.log( mmvLogActions['profile-' + type + '-start'].replace( /\$1/g, thisid ) );
|
|
|
|
|
|
|
|
if ( timeout ) {
|
|
|
|
window.setTimeout( function () {
|
|
|
|
profiling[thisid] = undefined;
|
|
|
|
}, timeout );
|
|
|
|
}
|
|
|
|
|
|
|
|
return thisid;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Signal the end of an event being profiled and send the
|
|
|
|
* eventlogging message.
|
|
|
|
* @param {number} id Should be the value returned from profileStart
|
2014-01-08 00:22:18 +00:00
|
|
|
* @param {boolean} [fakeTime] For testing, whether to fake the time in the message. Time is zero if so.
|
2013-12-06 17:10:39 +00:00
|
|
|
*/
|
2014-01-08 00:22:18 +00:00
|
|
|
MMVP.profileEnd = function ( id, fakeTime ) {
|
2013-12-06 17:10:39 +00:00
|
|
|
var msg;
|
|
|
|
|
|
|
|
if ( profiling[id] ) {
|
|
|
|
msg = profiling[id];
|
2014-01-08 00:22:18 +00:00
|
|
|
msg.milliseconds = Date.now() - msg.start;
|
2013-12-06 17:10:39 +00:00
|
|
|
delete msg.start;
|
|
|
|
|
|
|
|
mw.log(
|
|
|
|
mmvLogActions['profile-' + msg.action + '-end']
|
|
|
|
.replace( /\$1/g, id )
|
2014-01-08 00:22:18 +00:00
|
|
|
.replace( /\$2/g, fakeTime ? 0 : msg.milliseconds )
|
2013-12-06 17:10:39 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
if ( mw.eventLog ) {
|
|
|
|
mw.eventLog.logEvent( 'MediaViewerPerf', msg );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}() );
|
|
|
|
|
2013-10-28 12:44:00 +00:00
|
|
|
/**
|
|
|
|
* Transforms a date string into localized, human-readable format.
|
|
|
|
* Unrecognized strings are returned unchanged.
|
|
|
|
* @param {string} dateString
|
|
|
|
* @return {string}
|
|
|
|
*/
|
2013-11-27 21:57:45 +00:00
|
|
|
MMVP.formatDate = function ( dateString ) {
|
2013-10-28 12:44:00 +00:00
|
|
|
var date = moment( dateString );
|
|
|
|
if ( !date.isValid() ) {
|
|
|
|
return dateString;
|
|
|
|
}
|
|
|
|
return date.format( 'LL' );
|
|
|
|
};
|
|
|
|
|
2014-01-31 09:29:39 +00:00
|
|
|
function handleHash() {
|
|
|
|
var statedIndex,
|
|
|
|
$foundElement,
|
|
|
|
hash = decodeURIComponent( document.location.hash ),
|
|
|
|
linkState = hash.split( '/' );
|
|
|
|
|
2013-11-25 23:51:40 +00:00
|
|
|
comingFromPopstate = true;
|
|
|
|
if ( linkState[0] === '#mediaviewer' ) {
|
|
|
|
statedIndex = mw.mediaViewer.lightbox.images[linkState[2]];
|
2014-01-31 09:29:39 +00:00
|
|
|
|
2013-11-25 23:51:40 +00:00
|
|
|
if ( statedIndex.filePageTitle.getPrefixedText() === linkState[1] ) {
|
2013-12-10 19:54:07 +00:00
|
|
|
$foundElement = $( imgsSelector ).eq( linkState[2] );
|
|
|
|
mw.mediaViewer.loadImage( statedIndex, $foundElement.prop( 'src' ) );
|
2013-11-25 23:51:40 +00:00
|
|
|
}
|
|
|
|
} else {
|
2014-01-31 09:29:39 +00:00
|
|
|
// If the hash is invalid (not a mmv hash) we check if there's any mmv lightbox open and we close it
|
|
|
|
if ( mw.mediaViewer && mw.mediaViewer.lightbox && mw.mediaViewer.lightbox.iface ) {
|
2013-11-27 21:57:45 +00:00
|
|
|
mw.mediaViewer.lightbox.iface.unattach();
|
|
|
|
}
|
2013-11-25 23:51:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-07 08:59:08 +00:00
|
|
|
$( function () {
|
|
|
|
MultiLightbox = window.MultiLightbox;
|
|
|
|
lightboxHooks = window.lightboxHooks;
|
|
|
|
|
|
|
|
var viewer = new MultimediaViewer();
|
2013-11-25 23:51:40 +00:00
|
|
|
|
2013-08-07 08:59:08 +00:00
|
|
|
mw.mediaViewer = viewer;
|
2013-11-25 23:51:40 +00:00
|
|
|
|
2014-01-31 09:29:39 +00:00
|
|
|
handleHash();
|
|
|
|
window.addEventListener( 'popstate', handleHash );
|
2013-08-07 08:59:08 +00:00
|
|
|
} );
|
|
|
|
|
|
|
|
mw.MultimediaViewer = MultimediaViewer;
|
2013-10-28 12:44:00 +00:00
|
|
|
}( mediaWiki, jQuery, moment ) );
|