/* * 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, $, oo ) { // Shortcut for prototype later var MPP; /** * Represents the metadata panel in the viewer * @class mw.mmv.ui.MetadataPanel * @extends mw.mmv.ui.Element * @constructor * @param {jQuery} $container The container for the panel. * @param {jQuery} $controlBar The control bar element. * @param {Object} localStorage the localStorage object, for dependency injection */ function MetadataPanel( $container, $controlBar, localStorage ) { mw.mmv.ui.Element.call( this, $container ); this.$controlBar = $controlBar; /** @property {mw.mmv.Config} config - */ this.config = new mw.mmv.Config( mw.config.get( 'wgMultimediaViewer', {} ), mw.config, mw.user, new mw.Api(), window.localStorage ); /** @property {mw.mmv.HtmlUtils} htmlUtils - */ this.htmlUtils = new mw.mmv.HtmlUtils(); this.initializeHeader( localStorage ); this.initializeImageMetadata(); this.initializeAboutLinks(); this.initializePreferenceLinks(); } oo.inheritClass( MetadataPanel, mw.mmv.ui.Element ); MPP = MetadataPanel.prototype; MPP.attach = function() { this.scroller.attach(); this.buttons.attach(); this.fileReuse.attach(); }; MPP.unattach = function() { this.scroller.unattach(); this.buttons.unattach(); this.fileReuse.unattach(); this.fileReuse.closeDialog(); this.clearEvents(); }; MPP.empty = function () { this.scroller.empty(); this.$license.empty().addClass( 'empty' ); this.$permissionLink.hide(); this.buttons.empty(); this.description.empty(); this.categories.empty(); this.fileUsage.empty(); this.permission.empty(); this.$title.empty().removeClass( 'error' ); this.$credit.empty().addClass( 'empty' ); this.$username.empty(); this.$usernameLi.addClass( 'empty' ); this.$repo.empty(); this.$repoSubtitle.empty(); this.$repoLi.addClass( 'empty' ).removeClass( 'remote local' ); this.$datetime.empty(); this.$datetimeLi.addClass( 'empty' ); this.$location.empty(); this.$locationLi.addClass( 'empty' ); this.progressBar.empty(); this.fileReuse.empty(); }; // ********************************************** // *********** Initialization methods *********** // ********************************************** /** * Initializes the header, which contains the title, credit, and license elements. * @param {Object} localStorage the localStorage object, for dependency injection */ MPP.initializeHeader = function ( localStorage ) { this.progressBar = new mw.mmv.ui.ProgressBar( this.$controlBar ); this.scroller = new mw.mmv.ui.MetadataPanelScroller( this.$container, this.$controlBar, localStorage ); this.$titleDiv = $( '
' ) .addClass( 'mw-mmv-title-contain' ) .appendTo( this.$controlBar ); this.$container.append( this.$controlBar ); this.initializeButtons(); // float, needs to be on top this.initializeTitleAndCredit(); this.initializeLicense(); }; /** * Initializes the title and credit elements. */ MPP.initializeTitleAndCredit = function () { this.$titleAndCredit = $( '
' ) .addClass( 'mw-mmv-title-credit' ) // Since these elements are created dynamically, we listen this way for logging purposes .on( 'click', '.mw-mmv-author a', function () { mw.mmv.actionLogger.log( 'author-page' ); } ) .on( 'click', '.mw-mmv-source a', function () { mw.mmv.actionLogger.log( 'source-page' ); } ) .appendTo( this.$titleDiv ); this.initializeTitle(); this.initializeCredit(); }; /** * Initializes the title elements. */ MPP.initializeTitle = function () { this.$titlePara = $( '

' ) .addClass( 'mw-mmv-title-para' ) .appendTo( this.$titleAndCredit ); this.$title = $( '' ) .prop( 'title', mw.message( 'multimediaviewer-title-popup-text' ) ) .tipsy( { delayIn: mw.config.get( 'wgMultimediaViewer').tooltipDelay, gravity: this.isRTL() ? 'se' : 'sw' } ) .addClass( 'mw-mmv-title' ); this.title = new mw.mmv.ui.TruncatableTextField( this.$titlePara, this.$title ); }; /** * Initializes the credit elements. */ MPP.initializeCredit = function () { this.$credit = $( '

' ) .addClass( 'mw-mmv-credit empty' ); this.creditField = new mw.mmv.ui.TruncatableTextField( this.$titleAndCredit, this.$credit, { max: 200, small: 160 } ); }; /** * Initializes the license elements. */ MPP.initializeLicense = function () { var panel = this; this.$license = $( '' ) .addClass( 'mw-mmv-license empty' ) .prop( 'href', '#' ) .appendTo( this.$titlePara ) .on( 'click', function() { mw.mmv.actionLogger.log( 'license-page' ); } ); this.$permissionLink = $( '' ) .addClass( 'mw-mmv-permission-link mw-mmv-label' ) .text( mw.message( 'multimediaviewer-permission-link' ).text() ) .appendTo( this.$titlePara ) .hide() .on( 'click', function() { panel.permission.grow(); panel.scroller.scrollIntoView( panel.permission.$box, 500 ); } ); }; MPP.initializeButtons = function () { this.buttons = new mw.mmv.ui.StripeButtons( this.$titleDiv, this.localStorage ); }; /** * Initializes the main body of metadata elements. */ MPP.initializeImageMetadata = function () { this.$imageMetadata = $( '

' ) .addClass( 'mw-mmv-image-metadata' ) .appendTo( this.$container ); this.$imageMetadataLeft = $( '
' ) .addClass( 'mw-mmv-image-metadata-column mw-mmv-image-metadata-desc-column' ) .appendTo( this.$imageMetadata ); this.$imageMetadataRight = $( '
' ) .addClass( 'mw-mmv-image-metadata-column mw-mmv-image-metadata-links-column' ) .appendTo( this.$imageMetadata ); this.description = new mw.mmv.ui.Description( this.$imageMetadataLeft ); this.permission = new mw.mmv.ui.Permission( this.$imageMetadataLeft ); this.initializeImageLinks(); }; /** * Initializes the list of image metadata on the right side of the panel. */ MPP.initializeImageLinks = function () { this.$imageLinkDiv = $( '
' ) .addClass( 'mw-mmv-image-links-div' ) .appendTo( this.$imageMetadataRight ); this.$imageLinks = $( '