/* * 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' ]; 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 ) { e.preventDefault(); viewer.lightbox.currentIndex = index; // Open with a basic thumbnail and no information - fill in async viewer.lightbox.images[index].src = this.src; viewer.lightbox.open(); viewer.fetchImageInfo( fileTitle, function ( imageInfo ) { var repoInfo, articlePath, ui = viewer.lightbox.iface, innerInfo = imageInfo.imageinfo[0] || {}; viewer.lightbox.images[index].src = innerInfo.url; viewer.lightbox.open(); ui.$title.text( fileTitle.getNameText() ); if ( viewer.repoInfo ) { repoInfo = viewer.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' ); } ui.$repo .prop( 'href', articlePath.replace( '$1', fileTitle.getPrefixedText() ) ); } ui.$repoLi.toggleClass( 'empty', !Boolean( repoInfo ) ); } ); return false; } ); } ); if ( $thumbs.length > 0 ) { this.lightbox = new MultiLightbox( urls ); } 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 () { this.$imageDesc = $( '

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

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