/* * 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 . */ ( function ( mw, $ ) { var MultiLightbox, LightboxImage, lightboxHooks, validExtensions = { 'jpg': true, 'jpeg': true, 'gif': true, 'svg': true, 'png': true, 'tiff': true, 'tif': true }, iiprops = [ 'timestamp', 'user', 'userid', 'comment', 'url', 'size', 'sha1', 'mime', 'mediatype', 'metadata', 'extmetadata' ], 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.', 'close-link-click': 'User clicked on the lightbox close button.' }; function MultimediaViewer() { var $thumbs = $( '.thumbimage' ), urls = [], viewer = this; this.api = new mw.Api(); this.imageInfo = {}; $thumbs.each( function ( i, thumb ) { var fileLink, $thumb = $( thumb ), $link = $thumb.closest( 'a.image' ), $thumbContain = $link.closest( '.thumb' ), $enlarge = $thumbContain.find( '.magnify a' ), $links = $link.add( $enlarge ), filePageLink = $link.prop( 'href' ), fileTitle = mw.Title.newFromImg( $thumb ), index = urls.length; if ( !validExtensions[fileTitle.getExtension().toLowerCase()] ) { // Not a valid extension, skip this one return; } $links.data( 'filePageLink', filePageLink ); urls.push( new LightboxImage( fileLink ) ); urls[index].filePageLink = filePageLink; $links.click( function ( e ) { var $this = $( this ); if ( $this.is( 'a.image' ) ) { viewer.log( 'thumbnail-link-click' ); } else if ( $this.is( '.magnify a' ) ) { viewer.log( 'enlarge-link-click' ); } e.preventDefault(); viewer.lightbox.currentIndex = index; // Open with a basic thumbnail and no information - fill in async viewer.lightbox.images[index].src = mw.config.get( 'wgScriptPath', '' ) + '/resources/jquery/images/spinner-large.gif'; viewer.lightbox.open(); viewer.fetchImageInfo( fileTitle, function ( imageInfo ) { var imageEle = new Image(); imageEle.onload = function () { viewer.lightbox.iface.replaceImageWith( imageEle ); viewer.setImageInfo( fileTitle, imageInfo ); }; imageEle.src = imageInfo.imageinfo[0].thumburl || imageInfo.imageinfo[0].url; } ); return false; } ); } ); if ( $thumbs.length > 0 ) { this.lightbox = new MultiLightbox( urls ); } lightboxHooks.register( 'imageResize', function () { var api = new mw.Api(), ratio = this.isFullScreen ? 0.9 : 0.5, filename = viewer.currentImageFilename, ui = this; api.get( { action: 'query', format: 'json', titles: filename, prop: 'imageinfo', iiprop: 'url', iiurlwidth: Math.floor( ratio * $( window ).width() * 1.1 ), iiurlheight: Math.floor( ratio * $( window ).height() * 1.1 ) } ).done( function ( data ) { var imageInfo, innerInfo, image = new Image(); $.each( data.query.pages, function ( i, page ) { imageInfo = page; return false; } ); innerInfo = imageInfo.imageinfo[0]; image.onload = function () { ui.replaceImageWith( image ); }; image.src = innerInfo.thumburl || innerInfo.url; } ); return false; } ); lightboxHooks.register( 'imageLoaded', function () { // Add link wrapper to the image div, put image inside it this.$imageLink = $( '' ) .addClass( 'mw-mlb-image-link' ) .html( this.$image.detach() ); this.$imageDiv.append( this.$imageLink ); } ); lightboxHooks.register( 'modifyInterface', function () { var ui = this; this.$imageDesc = $( '

' ) .addClass( 'mw-mlb-image-desc' ); this.$imageDescDiv = $( '

' ) .addClass( 'mw-mlb-image-desc-div' ) .html( this.$imageDesc ); this.$imageLinks = $( '