/* * 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 = $( '.gallery .image img, a.image img' ), 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; if ( $thumbContain.length === 0 ) { // This isn't a thumbnail! Just use the link. $thumbContain = $link; } else if ( $thumbContain.is( '.thumb' ) ) { $thumbContain = $thumbContain.find( '.image' ); } // 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. viewer.lightbox.images[index].src = $thumbContain.find( 'img' ).prop( 'src' ); viewer.lightbox.open(); viewer.lightbox.iface.$imageDiv.append( $.createSpinner( { id: 'mw-mlb-loading-spinner', size: 'large' } ) ); viewer.fetchImageInfo( fileTitle, function ( imageInfo ) { var imageEle = new Image(); imageEle.onload = function () { viewer.lightbox.iface.replaceImageWith( imageEle ); viewer.lightbox.iface.$imageDiv.removeClass( 'empty' ); $.removeSpinner( 'mw-mlb-loading-spinner' ); 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, density = $.devicePixelRatio(), filename = viewer.currentImageFilename, ui = this; api.get( { action: 'query', format: 'json', titles: filename, prop: 'imageinfo', iiprop: 'url', iiurlwidth: Math.floor( density * ratio * $( window ).width() * 1.1 ), iiurlheight: Math.floor( density * 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( 'modifyInterface', function () { var ui = this; this.$imageDiv .addClass( 'empty' ); this.$imageDesc = $( '

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

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