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-09-26 01:47:59 +00:00
|
|
|
iiprops = [
|
|
|
|
'timestamp',
|
|
|
|
'user',
|
|
|
|
'userid',
|
|
|
|
'comment',
|
|
|
|
'url',
|
|
|
|
'size',
|
|
|
|
'sha1',
|
|
|
|
'mime',
|
|
|
|
'mediatype',
|
2013-10-10 19:52:02 +00:00
|
|
|
'metadata',
|
|
|
|
'extmetadata'
|
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
|
|
|
/**
|
|
|
|
* Class that analyses the page, looks for image content and sets up the hooks
|
|
|
|
* 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.
|
|
|
|
* @property {mw.MultiLightbox}
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
this.lightbox = null;
|
|
|
|
|
|
|
|
var $thumbs = $( imgsSelector ),
|
2013-08-07 08:59:08 +00:00
|
|
|
urls = [],
|
|
|
|
viewer = this;
|
|
|
|
|
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
|
|
|
|
|
|
|
/**
|
|
|
|
* imageInfo object. TODO: Describe structure and valid states.
|
|
|
|
* @property {Object}
|
|
|
|
* @private
|
|
|
|
*/
|
2013-09-26 01:47:59 +00:00
|
|
|
this.imageInfo = {};
|
|
|
|
|
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-02 19:46:52 +00:00
|
|
|
var thisImage,
|
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' ) ) {
|
|
|
|
$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-02 19:46:52 +00:00
|
|
|
thisImage = viewer.createNewImage( $thumb.prop( 'src' ), filePageLink, fileTitle, index );
|
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-11-27 21:57:45 +00:00
|
|
|
viewer.clickLinkCallback( e, this, $thumbContain, thisImage );
|
2013-09-26 01:47:59 +00:00
|
|
|
|
2013-08-07 08:59:08 +00:00
|
|
|
return false;
|
|
|
|
} );
|
|
|
|
} );
|
|
|
|
|
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
|
|
|
|
this.lightbox = new MultiLightbox( urls );
|
|
|
|
|
|
|
|
// 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 () {
|
|
|
|
this.$mwControls.css( { top: '-999px', left: '-999px' } );
|
2013-11-26 03:37:01 +00:00
|
|
|
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-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
|
|
|
lightboxHooks.register( 'fullscreen', function () {
|
|
|
|
if ( this.$imageMetadata ) {
|
|
|
|
this.$imageMetadata.hide();
|
|
|
|
}
|
|
|
|
} );
|
2013-10-31 22:03:59 +00:00
|
|
|
|
2013-11-06 00:36:06 +00:00
|
|
|
lightboxHooks.register( 'defullscreen', function () {
|
|
|
|
if ( this.$imageMetadata ) {
|
|
|
|
this.$imageMetadata.show();
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
}
|
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
|
|
|
|
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
|
|
|
|
* @returns {mw.LightboxImage}
|
|
|
|
*/
|
|
|
|
MMVP.createNewImage = function ( fileLink, filePageLink, fileTitle, index ) {
|
|
|
|
var thisImage = new mw.LightboxImage( fileLink );
|
|
|
|
thisImage.filePageLink = filePageLink;
|
|
|
|
thisImage.filePageTitle = fileTitle;
|
|
|
|
thisImage.index = index;
|
|
|
|
|
|
|
|
return thisImage;
|
|
|
|
};
|
|
|
|
|
2013-11-27 21:57:45 +00:00
|
|
|
/**
|
|
|
|
* Handles clicks on legit image links.
|
|
|
|
*
|
|
|
|
* @protected
|
|
|
|
* @VisibleForTesting
|
|
|
|
*
|
|
|
|
* @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-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,
|
2013-11-26 03:37:01 +00:00
|
|
|
density = $.devicePixelRatio(),
|
|
|
|
filename = ui.currentImageFilename;
|
|
|
|
|
2013-12-03 01:58:09 +00:00
|
|
|
this.api.get( {
|
2013-11-26 03:37:01 +00:00
|
|
|
action: 'query',
|
|
|
|
format: 'json',
|
|
|
|
titles: filename,
|
|
|
|
prop: 'imageinfo',
|
|
|
|
iiprop: 'url',
|
|
|
|
iiurlwidth: Math.floor( density * ui.$imageWrapper.width() ),
|
|
|
|
iiurlheight: Math.floor( density * ui.$imageWrapper.height() )
|
|
|
|
} ).done( function ( data ) {
|
2013-12-03 01:58:09 +00:00
|
|
|
viewer.loadResizedImage( ui, data );
|
|
|
|
} );
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Replaces the resized image in the viewer providing we actually got some data.
|
|
|
|
*
|
|
|
|
* @protected
|
|
|
|
*
|
|
|
|
* @param {mw.LightboxInterface} ui lightbox that got resized
|
|
|
|
* @param {Object} data information regarding the new resized image
|
|
|
|
*/
|
|
|
|
MMVP.loadResizedImage = function ( ui, data ) {
|
2013-12-06 17:10:39 +00:00
|
|
|
var imageInfo, innerInfo, rpid, viewer, image;
|
|
|
|
|
2013-12-03 01:58:09 +00:00
|
|
|
// Replace image only if data was returned.
|
|
|
|
if ( data && data.query && data.query.pages ) {
|
2013-12-06 17:10:39 +00:00
|
|
|
viewer = this;
|
|
|
|
image = new Image();
|
2013-11-26 03:37:01 +00:00
|
|
|
|
|
|
|
$.each( data.query.pages, function ( i, page ) {
|
|
|
|
imageInfo = page;
|
|
|
|
return false;
|
|
|
|
} );
|
|
|
|
|
|
|
|
innerInfo = imageInfo.imageinfo[0];
|
|
|
|
|
|
|
|
image.onload = function () {
|
2013-12-06 17:10:39 +00:00
|
|
|
viewer.profileEnd( rpid );
|
2013-11-26 03:37:01 +00:00
|
|
|
ui.replaceImageWith( image );
|
2013-12-03 01:58:09 +00:00
|
|
|
this.updateControls();
|
2013-11-26 03:37:01 +00:00
|
|
|
};
|
|
|
|
|
2013-12-06 17:10:39 +00:00
|
|
|
rpid = this.profileStart( 'image-resize', {
|
|
|
|
width: innerInfo.width,
|
|
|
|
height: innerInfo.height,
|
|
|
|
fileSize: innerInfo.size
|
|
|
|
}, innerInfo.mime );
|
|
|
|
|
2013-11-26 03:37:01 +00:00
|
|
|
image.src = innerInfo.thumburl || innerInfo.url;
|
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 () {
|
|
|
|
var isOnButton = false,
|
|
|
|
isOnImage = false,
|
|
|
|
ui = this.ui,
|
2013-11-26 03:37:01 +00:00
|
|
|
pos = ui.$image.offset(),
|
|
|
|
prevNextTop = ( ( ui.$imageWrapper.height() / 2 ) - 32 ) + 'px';
|
2013-11-13 00:43:46 +00:00
|
|
|
|
|
|
|
function fadeIn() {
|
|
|
|
isOnImage = true;
|
|
|
|
ui.$mwControls.fadeIn( 100 );
|
|
|
|
ui.$image.one( 'click', fadeOut );
|
|
|
|
}
|
|
|
|
|
|
|
|
function fadeOut() {
|
|
|
|
ui.$mwControls.fadeOut( 100 );
|
|
|
|
ui.$image.one( 'click', fadeIn );
|
|
|
|
}
|
|
|
|
|
|
|
|
function fadeOutDelayed() {
|
|
|
|
isOnImage = false;
|
|
|
|
setTimeout( function () {
|
|
|
|
if ( !isOnImage && !isOnButton ) {
|
|
|
|
fadeOut();
|
|
|
|
}
|
|
|
|
}, 500 );
|
|
|
|
}
|
|
|
|
|
|
|
|
function detectButton() {
|
|
|
|
isOnButton = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
function detectLeaveButton() {
|
|
|
|
isOnButton = false;
|
|
|
|
setTimeout( function () {
|
|
|
|
if ( !isOnImage && !isOnButton ) {
|
|
|
|
fadeOut();
|
|
|
|
}
|
|
|
|
}, 500 );
|
|
|
|
}
|
|
|
|
|
|
|
|
pos.top = ( ui.$imageWrapper.height() - ui.$image.height() ) / 2;
|
|
|
|
pos.left += ui.$image.width() - ui.$closeButton.width();
|
|
|
|
|
|
|
|
pos.top += 'px';
|
|
|
|
pos.left += 'px';
|
|
|
|
|
|
|
|
ui.$mwControls
|
|
|
|
.css( pos )
|
|
|
|
.appendTo( ui.$main )
|
|
|
|
.fadeIn( 100 )
|
|
|
|
.delay( 500 )
|
|
|
|
.fadeOut( 100 );
|
|
|
|
|
|
|
|
ui.$postDiv.css( 'top', ui.$imageWrapper.height() );
|
|
|
|
|
|
|
|
ui.$image
|
|
|
|
.off( 'mouseenter', fadeIn )
|
|
|
|
.off( 'mouseleave', fadeOutDelayed )
|
|
|
|
.one( 'click', fadeIn )
|
|
|
|
.on( 'mouseenter', fadeIn )
|
|
|
|
.on( 'mouseleave', fadeOutDelayed );
|
|
|
|
|
|
|
|
ui.$closeButton.add( ui.$fullscreenButton )
|
|
|
|
.off( 'mouseenter', detectButton )
|
|
|
|
.off( 'mouseleave', detectLeaveButton )
|
|
|
|
.on( 'mouseenter', detectButton )
|
|
|
|
.on( 'mouseleave', detectLeaveButton );
|
2013-11-26 03:37:01 +00:00
|
|
|
|
|
|
|
ui.$nextButton.add( ui.$prevButton ).css( {
|
|
|
|
top: prevNextTop
|
|
|
|
} );
|
|
|
|
|
|
|
|
ui.$nextButton.toggleClass( 'disabled', this.lightbox.currentIndex >= ( this.lightbox.images.length - 1 ) );
|
|
|
|
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 () {
|
|
|
|
if ( viewer.ui.isFullScreen ) {
|
|
|
|
viewer.log( 'fullscreen-link-click' );
|
|
|
|
} else {
|
|
|
|
viewer.log( 'defullscreen-link-click' );
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
};
|
|
|
|
|
|
|
|
MMVP.fetchRepoInfo = function ( cb ) {
|
2013-09-26 01:47:59 +00:00
|
|
|
var viewer = this;
|
|
|
|
|
|
|
|
if ( this.repoInfo !== undefined ) {
|
|
|
|
cb( this.repoInfo );
|
|
|
|
} else {
|
|
|
|
this.api.get( {
|
|
|
|
action: 'query',
|
|
|
|
format: 'json',
|
|
|
|
meta: 'filerepoinfo'
|
|
|
|
}, function ( data ) {
|
|
|
|
if ( !data || !data.query ) {
|
|
|
|
// Damn, failure. Do it gracefully-ish.
|
|
|
|
cb( {} );
|
2013-10-08 00:54:18 +00:00
|
|
|
return;
|
2013-09-26 01:47:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
viewer.setRepoInfo( data.query.repos );
|
|
|
|
cb( viewer.repoInfo );
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-11-06 00:36:06 +00:00
|
|
|
MMVP.setRepoInfo = function ( repos ) {
|
2013-09-26 01:47:59 +00:00
|
|
|
var i, repo;
|
|
|
|
|
|
|
|
repos = repos || [];
|
|
|
|
|
|
|
|
if ( this.repoInfo === undefined ) {
|
|
|
|
this.repoInfo = {};
|
|
|
|
}
|
|
|
|
|
|
|
|
for ( i = 0; i < repos.length; i++ ) {
|
|
|
|
repo = repos[i];
|
|
|
|
this.repoInfo[repo.name] = repo;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-11-06 00:36:06 +00:00
|
|
|
MMVP.setImageInfo = function ( fileTitle, imageInfo ) {
|
2013-10-30 00:22:27 +00:00
|
|
|
function whitelistHtml( $el ) {
|
|
|
|
var child, $prev, $child = $el.children().first();
|
2013-10-28 22:32:56 +00:00
|
|
|
|
2013-10-30 00:22:27 +00:00
|
|
|
while ( $child && $child.length ) {
|
|
|
|
child = $child.get( 0 );
|
2013-10-28 22:32:56 +00:00
|
|
|
|
2013-10-30 00:22:27 +00:00
|
|
|
if ( child.nodeType !== child.ELEMENT_NODE ) {
|
|
|
|
return;
|
|
|
|
}
|
2013-10-28 22:32:56 +00:00
|
|
|
|
2013-10-30 00:22:27 +00:00
|
|
|
whitelistHtml( $child );
|
2013-10-28 22:32:56 +00:00
|
|
|
|
2013-10-30 00:22:27 +00:00
|
|
|
if ( !$child.is( 'a' ) ) {
|
|
|
|
$prev = $child.prev();
|
|
|
|
$child.replaceWith( $child.contents() );
|
2013-10-28 22:32:56 +00:00
|
|
|
} else {
|
2013-10-30 00:22:27 +00:00
|
|
|
$prev = $child;
|
2013-10-28 22:32:56 +00:00
|
|
|
}
|
|
|
|
|
2013-10-30 00:22:27 +00:00
|
|
|
if ( $prev && $prev.length === 1 ) {
|
|
|
|
$child = $prev.next();
|
|
|
|
} else {
|
|
|
|
$child = $el.children().first();
|
|
|
|
}
|
|
|
|
}
|
2013-10-28 22:32:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function setUserpageLink( username, gender ) {
|
|
|
|
var userpage = 'User:' + username,
|
|
|
|
userTitle = mw.Title.newFromText( userpage );
|
|
|
|
|
|
|
|
ui.$username
|
|
|
|
.text(
|
|
|
|
mw.message( 'multimediaviewer-userpage-link', username, gender ).text()
|
|
|
|
)
|
|
|
|
.prop( 'href', userTitle.getUrl() );
|
|
|
|
|
|
|
|
if ( articlePath ) {
|
|
|
|
ui.$username
|
|
|
|
.prop( 'href', articlePath.replace( '$1', userTitle.getPrefixedText() ) );
|
|
|
|
}
|
|
|
|
|
2013-11-28 21:07:32 +00:00
|
|
|
ui.$usernameLi.toggleClass( 'empty', !username );
|
2013-10-28 22:32:56 +00:00
|
|
|
}
|
|
|
|
|
2013-12-06 17:10:39 +00:00
|
|
|
var extmeta, gfpid,
|
2013-10-29 02:31:23 +00:00
|
|
|
repoInfo, articlePath, linkToRepo,
|
2013-10-28 22:32:56 +00:00
|
|
|
desc,
|
|
|
|
datetime, dtmsg,
|
2013-10-16 23:50:51 +00:00
|
|
|
license, msgname,
|
2013-10-28 22:32:56 +00:00
|
|
|
username,
|
|
|
|
source, author,
|
2013-12-06 17:10:39 +00:00
|
|
|
viewer = this,
|
2013-10-28 22:32:56 +00:00
|
|
|
ui = this.lightbox.iface,
|
|
|
|
innerInfo = imageInfo.imageinfo[0] || {};
|
|
|
|
|
|
|
|
ui.$title.text( fileTitle.getNameText() );
|
|
|
|
|
2013-10-29 02:31:23 +00:00
|
|
|
ui.$useFile.data( 'title', fileTitle );
|
|
|
|
ui.$useFile.data( 'src', innerInfo.url );
|
|
|
|
ui.$useFileLi.removeClass( 'empty' );
|
|
|
|
|
2013-10-28 22:32:56 +00:00
|
|
|
if ( this.repoInfo ) {
|
|
|
|
repoInfo = this.repoInfo[imageInfo.imagerepository];
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( repoInfo ) {
|
|
|
|
if ( repoInfo.displayname ) {
|
|
|
|
ui.$repo.text(
|
|
|
|
mw.message( 'multimediaviewer-repository', repoInfo.displayname ).text()
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
ui.$repo.text(
|
|
|
|
mw.message( 'multimediaviewer-repository', mw.config.get( 'wgSiteName' ) ).text()
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( repoInfo.server && repoInfo.articlepath ) {
|
|
|
|
articlePath = repoInfo.server + repoInfo.articlepath;
|
|
|
|
} else {
|
|
|
|
articlePath = mw.config.get( 'wgArticlePath' );
|
|
|
|
}
|
|
|
|
|
2013-10-29 02:31:23 +00:00
|
|
|
linkToRepo = articlePath.replace( '$1', fileTitle.getPrefixedText() );
|
|
|
|
|
|
|
|
if ( repoInfo.local ) {
|
|
|
|
linkToRepo = mw.config.get( 'wgServer' ) + linkToRepo;
|
2013-11-27 22:58:31 +00:00
|
|
|
ui.$useFile.data( 'isLocal' ,repoInfo.local );
|
2013-10-29 02:31:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ui.$repo.prop( 'href', linkToRepo );
|
|
|
|
ui.$useFile.data( 'link', linkToRepo );
|
2013-10-28 22:32:56 +00:00
|
|
|
}
|
|
|
|
|
2013-11-28 21:07:32 +00:00
|
|
|
ui.$repoLi.toggleClass( 'empty', !repoInfo );
|
2013-10-28 22:32:56 +00:00
|
|
|
|
|
|
|
username = innerInfo.user;
|
|
|
|
|
|
|
|
if ( username ) {
|
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: {
|
|
|
|
url: repoInfo.apiurl || mw.util.wikiScript( 'api' )
|
|
|
|
}
|
|
|
|
} ).get( {
|
|
|
|
action: 'query',
|
|
|
|
list: 'users',
|
|
|
|
ususers: username,
|
|
|
|
usprop: 'gender'
|
|
|
|
} ).done( function ( data ) {
|
|
|
|
var gender = data.query.users[0].gender;
|
2013-12-06 17:10:39 +00:00
|
|
|
|
|
|
|
viewer.profileEnd( gfpid );
|
|
|
|
|
2013-10-28 22:32:56 +00:00
|
|
|
setUserpageLink( username, gender );
|
|
|
|
} ).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.' );
|
2013-10-28 22:32:56 +00:00
|
|
|
setUserpageLink( username, 'unknown' );
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
|
|
|
|
extmeta = innerInfo.extmetadata;
|
|
|
|
|
|
|
|
if ( extmeta ) {
|
|
|
|
desc = extmeta.ImageDescription;
|
|
|
|
|
2013-11-01 19:07:06 +00:00
|
|
|
ui.$imageDescDiv.toggleClass( 'empty', !desc );
|
|
|
|
|
2013-10-28 22:32:56 +00:00
|
|
|
if ( desc ) {
|
|
|
|
desc = desc.value;
|
2013-10-30 00:22:27 +00:00
|
|
|
whitelistHtml( ui.$imageDesc.append( $.parseHTML( desc ) ) );
|
2013-10-28 22:32:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
datetime = extmeta.DateTimeOriginal || extmeta.DateTime;
|
|
|
|
|
|
|
|
if ( datetime ) {
|
|
|
|
// get rid of HTML tags
|
|
|
|
datetime = datetime.value.replace( /<.*?>/g, '' );
|
2013-10-28 12:44:00 +00:00
|
|
|
datetime = this.formatDate( datetime );
|
2013-10-28 22:32:56 +00:00
|
|
|
|
|
|
|
dtmsg = (
|
|
|
|
'multimediaviewer-datetime-' +
|
|
|
|
( extmeta.DateTimeOriginal ? 'created' : 'uploaded' )
|
|
|
|
);
|
|
|
|
|
|
|
|
ui.$datetime.text(
|
|
|
|
mw.message( dtmsg, datetime ).text()
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2013-11-28 21:07:32 +00:00
|
|
|
ui.$datetimeLi.toggleClass( 'empty', !datetime );
|
2013-10-28 22:32:56 +00:00
|
|
|
|
|
|
|
source = extmeta.Credit;
|
|
|
|
author = extmeta.Artist;
|
|
|
|
|
|
|
|
if ( source ) {
|
|
|
|
source = source.value;
|
2013-10-30 00:22:27 +00:00
|
|
|
whitelistHtml( ui.$source.empty().append( $.parseHTML( source ) ) );
|
2013-10-28 22:32:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( author ) {
|
|
|
|
author = author.value;
|
2013-10-30 00:22:27 +00:00
|
|
|
whitelistHtml( ui.$author.empty().append( $.parseHTML( author ) ) );
|
2013-10-28 22:32:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( source && 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 ( source ) {
|
|
|
|
ui.$credit.html( ui.$source );
|
|
|
|
} else if ( author ) {
|
|
|
|
ui.$credit.html( ui.$author );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-28 21:07:32 +00:00
|
|
|
ui.$credit.toggleClass( 'empty', !source && !author );
|
2013-10-16 23:50:51 +00:00
|
|
|
|
|
|
|
license = extmeta.License;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( license ) {
|
|
|
|
license = license.value;
|
|
|
|
}
|
|
|
|
|
|
|
|
msgname = 'multimediaviewer-license-' + ( license || '' );
|
|
|
|
|
|
|
|
if ( !license || !mw.messages.exists( msgname ) ) {
|
|
|
|
// Cannot display, fallback or fail
|
|
|
|
license = 'default';
|
|
|
|
msgname = 'multimediaviewer-license-default';
|
2013-10-28 22:32:56 +00:00
|
|
|
}
|
2013-10-16 23:50:51 +00:00
|
|
|
|
|
|
|
if ( license ) {
|
|
|
|
articlePath = articlePath || mw.config.get( 'wgArticlePath', '' );
|
|
|
|
ui.$license
|
|
|
|
.text( mw.message( msgname ).text() )
|
|
|
|
.prop( 'href', articlePath.replace( '$1', fileTitle.getPrefixedText() ) )
|
|
|
|
.toggleClass( 'cc-license', license.substr( 0, 2 ) === 'cc' );
|
|
|
|
}
|
|
|
|
|
|
|
|
ui.$license.toggleClass( 'empty', !license );
|
2013-10-28 22:32:56 +00:00
|
|
|
};
|
|
|
|
|
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.
|
|
|
|
image.src = initialSrc;
|
|
|
|
this.currentImageFilename = image.filePageTitle.getPrefixedText();
|
|
|
|
this.lightbox.iface.comingFromPopstate = comingFromPopstate;
|
|
|
|
this.lightbox.open();
|
|
|
|
$( document.body ).addClass( 'mw-mlb-lightbox-open' );
|
|
|
|
this.lightbox.iface.$imageDiv.append( $.createSpinner( {
|
|
|
|
id: 'mw-mlb-loading-spinner',
|
|
|
|
size: 'large'
|
|
|
|
} ) );
|
|
|
|
|
2013-12-06 17:10:39 +00:00
|
|
|
mdpid = this.profileStart( 'metadata-fetch' );
|
|
|
|
|
2013-11-25 23:51:40 +00:00
|
|
|
this.fetchImageInfo( image.filePageTitle, function ( imageInfo ) {
|
2013-12-06 17:10:39 +00:00
|
|
|
var pid,
|
|
|
|
innerInfo = imageInfo.imageinfo[0],
|
|
|
|
imageEle = new Image();
|
|
|
|
|
|
|
|
viewer.profileEnd( mdpid );
|
2013-11-25 23:51:40 +00:00
|
|
|
|
|
|
|
imageEle.onload = function () {
|
2013-12-06 17:10:39 +00:00
|
|
|
viewer.profileEnd( pid );
|
2013-11-25 23:51:40 +00:00
|
|
|
viewer.lightbox.iface.replaceImageWith( imageEle );
|
|
|
|
viewer.lightbox.iface.$imageDiv.removeClass( 'empty' );
|
|
|
|
viewer.updateControls();
|
|
|
|
$.removeSpinner( 'mw-mlb-loading-spinner' );
|
|
|
|
viewer.setImageInfo( image.filePageTitle, imageInfo );
|
|
|
|
};
|
|
|
|
|
|
|
|
imageEle.src = imageInfo.imageinfo[0].thumburl || imageInfo.imageinfo[0].url;
|
2013-12-06 17:10:39 +00:00
|
|
|
|
|
|
|
pid = viewer.profileStart( 'image-load', {
|
|
|
|
width: innerInfo.width,
|
|
|
|
height: innerInfo.height,
|
|
|
|
fileSize: innerInfo.size
|
|
|
|
}, innerInfo.mime );
|
2013-11-25 23:51:40 +00:00
|
|
|
} );
|
|
|
|
|
|
|
|
comingFromPopstate = false;
|
|
|
|
};
|
|
|
|
|
2013-11-06 00:36:06 +00:00
|
|
|
MMVP.fetchImageInfo = function ( fileTitle, cb ) {
|
2013-09-26 01:47:59 +00:00
|
|
|
function apiCallback( sitename ) {
|
|
|
|
return function ( data ) {
|
|
|
|
if ( !data || !data.query ) {
|
|
|
|
// No information, oh well
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
viewer.setRepoInfo( data.query.repos );
|
|
|
|
|
2013-09-26 20:53:22 +00:00
|
|
|
if ( data.query.pages ) {
|
|
|
|
$.each( data.query.pages, function ( i, page ) {
|
|
|
|
imageInfo = page;
|
|
|
|
return false;
|
|
|
|
} );
|
2013-09-26 01:47:59 +00:00
|
|
|
|
2013-09-26 20:53:22 +00:00
|
|
|
if ( viewer.imageInfo[filename] === undefined ) {
|
|
|
|
if ( sitename === null ) {
|
|
|
|
viewer.imageInfo[filename] = imageInfo;
|
|
|
|
} else {
|
|
|
|
viewer.imageInfo[filename] = {};
|
|
|
|
}
|
2013-09-26 01:47:59 +00:00
|
|
|
|
2013-09-26 20:53:22 +00:00
|
|
|
viewer.imageInfo[filename].sites = {};
|
2013-09-26 01:47:59 +00:00
|
|
|
|
2013-09-26 20:53:22 +00:00
|
|
|
if ( !viewer.imageInfo[filename].imageinfo ||
|
|
|
|
viewer.imageInfo[filename].imageinfo.length === 0 ) {
|
|
|
|
viewer.imageInfo[filename].imageinfo = [{}];
|
|
|
|
}
|
2013-09-26 01:47:59 +00:00
|
|
|
}
|
|
|
|
|
2013-09-26 20:53:22 +00:00
|
|
|
viewer.imageInfo[filename].sites[sitename] = imageInfo;
|
2013-09-26 01:47:59 +00:00
|
|
|
}
|
|
|
|
|
2013-09-26 20:53:22 +00:00
|
|
|
if ( viewer.imageInfo[filename] ) {
|
|
|
|
// Give back the information we have
|
|
|
|
cb( viewer.imageInfo[filename], viewer.repoInfo );
|
|
|
|
}
|
2013-09-26 01:47:59 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
function fetchImageInfoCallback() {
|
|
|
|
var repoInfo;
|
|
|
|
|
|
|
|
if ( viewer.repoInfo !== undefined ) {
|
|
|
|
repoInfo = viewer.repoInfo;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( repoInfo === undefined ) {
|
|
|
|
apiArgs.meta = 'filerepoinfo';
|
|
|
|
}
|
|
|
|
|
2013-10-08 00:54:18 +00:00
|
|
|
viewer.api.get( apiArgs ).done( apiCallback( null ) );
|
2013-09-26 01:47:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var imageInfo,
|
|
|
|
filename = fileTitle.getPrefixedText(),
|
2013-11-01 15:24:16 +00:00
|
|
|
density = $.devicePixelRatio(),
|
2013-09-26 01:47:59 +00:00
|
|
|
apiArgs = {
|
|
|
|
action: 'query',
|
|
|
|
format: 'json',
|
|
|
|
titles: filename,
|
|
|
|
prop: 'imageinfo',
|
2013-10-11 17:55:10 +00:00
|
|
|
iiprop: iiprops.join( '|' ),
|
2013-11-13 00:43:46 +00:00
|
|
|
iiurlwidth: Math.floor( density * this.lightbox.iface.$imageWrapper.width() ),
|
|
|
|
iiurlheight: Math.floor( density * this.lightbox.iface.$imageWrapper.height() ),
|
2013-10-11 17:55:10 +00:00
|
|
|
// Short-circuit, don't fallback, to save some tiny amount of time
|
|
|
|
iiextmetadatalanguage: mw.config.get( 'wgUserLanguage', false ) || mw.config.get( 'wgContentLanguage', 'en' )
|
2013-09-26 01:47:59 +00:00
|
|
|
},
|
|
|
|
viewer = this;
|
|
|
|
|
|
|
|
if ( this.imageInfo[filename] === undefined ) {
|
|
|
|
// Fetch it in the same API query as the image info
|
|
|
|
fetchImageInfoCallback();
|
|
|
|
} else {
|
|
|
|
this.fetchRepoInfo( function ( res ) {
|
|
|
|
cb( viewer.imageInfo[filename], res );
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-11-26 03:37:01 +00:00
|
|
|
MMVP.loadIndex = function ( index ) {
|
|
|
|
if ( index < this.lightbox.images.length && index >= 0 ) {
|
|
|
|
this.loadImage( this.lightbox.images[index], $( imgsSelector ).eq( index ).prop( 'src' ) );
|
|
|
|
this.resize( this.lightbox.iface );
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
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
|
|
|
|
* @param {object} [imgSize] Size of image (for image related events)
|
|
|
|
* @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] = {
|
|
|
|
version: '1.0',
|
|
|
|
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
|
|
|
|
* @param {boolean} [includeTime] For testing, whether to include the time in the message. Time is zero otherwise.
|
|
|
|
*/
|
|
|
|
MMVP.profileEnd = function ( id, includeTime ) {
|
|
|
|
var msg;
|
|
|
|
|
|
|
|
if ( profiling[id] ) {
|
|
|
|
msg = profiling[id];
|
|
|
|
msg.milliseconds = includeTime ? Date.now() - msg.start : 0;
|
|
|
|
delete msg.start;
|
|
|
|
|
|
|
|
mw.log(
|
|
|
|
mmvLogActions['profile-' + msg.action + '-end']
|
|
|
|
.replace( /\$1/g, id )
|
|
|
|
.replace( /\$2/g, msg.milliseconds )
|
|
|
|
);
|
|
|
|
|
|
|
|
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' );
|
|
|
|
};
|
|
|
|
|
2013-11-25 23:51:40 +00:00
|
|
|
function handleHash( hash ) {
|
|
|
|
var statedIndex, linkState = hash.split( '/' );
|
|
|
|
comingFromPopstate = true;
|
|
|
|
if ( linkState[0] === '#mediaviewer' ) {
|
|
|
|
statedIndex = mw.mediaViewer.lightbox.images[linkState[2]];
|
|
|
|
if ( statedIndex.filePageTitle.getPrefixedText() === linkState[1] ) {
|
|
|
|
mw.mediaViewer.loadImage( statedIndex, $( imgsSelector ).eq( linkState[2] ).prop( 'src' ) );
|
|
|
|
}
|
|
|
|
} else {
|
2013-11-27 21:57:45 +00:00
|
|
|
if ( mw.mediaViewer.lightbox ) {
|
|
|
|
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
|
|
|
|
|
|
|
handleHash( document.location.hash );
|
|
|
|
window.addEventListener( 'popstate', function () { handleHash( document.location.hash ); } );
|
2013-08-07 08:59:08 +00:00
|
|
|
} );
|
|
|
|
|
|
|
|
mw.MultimediaViewer = MultimediaViewer;
|
2013-10-28 12:44:00 +00:00
|
|
|
}( mediaWiki, jQuery, moment ) );
|