/* * 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 () { // 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 (.mw-mmv-post-image). * @param {jQuery} $aboveFold The brighter headline of the metadata panel (.mw-mmv-above-fold). * Called "aboveFold" for historical reasons, but actually a part of the next sibling of the element * is also above the fold (bottom of the screen). * @param {mw.SafeStorage} localStorage the localStorage object, for dependency injection * @param {mw.mmv.Config} config A configuration object. */ function MetadataPanel( $container, $aboveFold, localStorage, config ) { mw.mmv.ui.Element.call( this, $container ); this.$aboveFold = $aboveFold; /** @property {mw.mmv.Config} config - */ this.config = config; /** @property {mw.mmv.HtmlUtils} htmlUtils - */ this.htmlUtils = new mw.mmv.HtmlUtils(); this.initializeHeader( localStorage ); this.initializeImageMetadata(); this.initializeAboutLinks(); } OO.inheritClass( MetadataPanel, mw.mmv.ui.Element ); MPP = MetadataPanel.prototype; /** * Maximum number of restriction icons before default icon is used * * @property {number} MAX_RESTRICT * @static */ MetadataPanel.MAX_RESTRICT = 4; /** * FIXME this should be in the jquery.fullscreen plugin. * * @return {boolean} */ MPP.isFullscreened = function () { return $( this.$container ).closest( '.jq-fullscreened' ).length > 0; }; MPP.attach = function () { var panel = this; this.scroller.attach(); this.buttons.attach(); this.title.attach(); this.creditField.attach(); this.$title .add( this.$authorAndSource ) .add( this.title.$ellipsis ) .add( this.creditField.$ellipsis ) .each( function () { $( this ).tipsy( 'enable' ); } ) .on( 'click.mmv-mp', function ( e ) { var clickTargetIsLink = $( e.target ).is( 'a' ), clickTargetIsTruncated = !!$( e.target ).closest( '.mw-mmv-ttf-truncated' ).length, someTextIsExpanded = !!$( e.target ).closest( '.mw-mmv-untruncated' ).length; if ( !clickTargetIsLink && // don't interfere with clicks on links in the text clickTargetIsTruncated && // don't expand when non-truncated text is clicked !someTextIsExpanded // ignore clicks if text is already expanded ) { if ( panel.isFullscreened() ) { panel.revealTruncatedText(); } else { panel.scroller.toggle( 'up' ); } } } ); $( this.$container ).on( 'mmv-metadata-open.mmv-mp mmv-metadata-reveal-truncated-text.mmv-mp', function () { panel.revealTruncatedText(); } ).on( 'mmv-metadata-close.mmv-mp', function () { panel.hideTruncatedText(); } ).on( 'mouseleave.mmv-mp', function () { var duration; if ( panel.isFullscreened() ) { duration = parseFloat( panel.$container.css( 'transition-duration' ) ) * 1000 || 0; panel.panelShrinkTimeout = setTimeout( function () { panel.hideTruncatedText(); }, duration ); } } ).on( 'mouseenter.mmv-mp', function () { clearTimeout( panel.panelShrinkTimeout ); } ).on( 'mmv-permission-grow.mmv-mp', function () { panel.$permissionLink .text( mw.message( 'multimediaviewer-permission-link-hide' ).text() ); } ).on( 'mmv-permission-shrink.mmv-mp', function () { panel.$permissionLink .text( mw.message( 'multimediaviewer-permission-link' ).text() ); } ); this.handleEvent( 'jq-fullscreen-change.lip', function () { panel.hideTruncatedText(); } ); }; MPP.unattach = function () { this.scroller.freezeHeight(); this.$title .add( this.title.$ellipsis ) .add( this.$authorAndSource ) .add( this.creditField.$ellipsis ) .each( function () { $( this ).tipsy( 'hide' ).tipsy( 'disable' ); } ) .off( 'click.mmv-mp' ); $( this.$container ).off( '.mmv-mp' ); this.scroller.unattach(); this.buttons.unattach(); this.clearEvents(); }; MPP.empty = function () { this.scroller.freezeHeight(); this.scroller.empty(); this.buttons.empty(); this.description.empty(); this.permission.empty(); this.$title.removeClass( 'error' ); this.title.empty(); this.creditField.empty(); this.$license.empty().prop( 'href', '#' ); this.$licenseLi.addClass( 'empty' ); this.$permissionLink.hide(); this.$restrictions.children().hide(); this.$filename.empty(); this.$filenamePrefix.empty(); this.$filenameLi.addClass( 'empty' ); this.$datetime.empty(); this.$datetimeLi.addClass( 'empty' ); this.$location.empty(); this.$locationLi.addClass( 'empty' ); this.progressBar.empty(); this.$container.removeClass( 'mw-mmv-untruncated' ); }; /* Initialization methods */ /** * Initializes the header, which contains the title, credit, and license elements. * * @param {mw.SafeStorage} localStorage the localStorage object, for dependency injection */ MPP.initializeHeader = function ( localStorage ) { this.progressBar = new mw.mmv.ui.ProgressBar( this.$aboveFold ); this.scroller = new mw.mmv.ui.MetadataPanelScroller( this.$container, this.$aboveFold, localStorage ); this.$titleDiv = $( '
' ) .addClass( 'mw-mmv-title-contain' ) .appendTo( this.$aboveFold ); this.$container.append( this.$aboveFold ); this.initializeButtons(); // float, needs to be on top this.initializeTitle(); }; /** * Initializes the title elements. */ MPP.initializeTitle = function () { this.$titlePara = $( '

' ) .addClass( 'mw-mmv-title-para' ) .appendTo( this.$aboveFold ); this.$title = $( '' ) .addClass( 'mw-mmv-title' ); this.title = new mw.mmv.ui.TruncatableTextField( this.$titlePara, this.$title, { styles: [ 'mw-mmv-title-small', 'mw-mmv-title-smaller' ] } ); this.title.setTitle( mw.message( 'multimediaviewer-title-popup-text' ), mw.message( 'multimediaviewer-title-popup-text-more' ) ); this.$title.add( this.title.$ellipsis ).tipsy( { delayIn: mw.config.get( 'wgMultimediaViewer' ).tooltipDelay, gravity: this.correctEW( 'sw' ) } ); }; MPP.initializeButtons = function () { this.buttons = new mw.mmv.ui.StripeButtons( this.$titleDiv ); }; /** * Initializes the main body of metadata elements. */ MPP.initializeImageMetadata = function () { this.$container.addClass( 'mw-mmv-ttf-ellipsis-container' ); 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.initializeCredit(); this.description = new mw.mmv.ui.Description( this.$imageMetadataLeft ); this.permission = new mw.mmv.ui.Permission( this.$imageMetadataLeft, this.scroller ); this.initializeImageLinks(); }; /** * Initializes the credit elements. */ MPP.initializeCredit = function () { this.$credit = $( '

' ) .addClass( 'mw-mmv-credit empty' ) .appendTo( this.$imageMetadataLeft ) .on( 'click.mmv-mp', '.mw-mmv-credit-fallback', function () { mw.mmv.actionLogger.log( 'author-page' ); } ); // we need an inline container for tipsy, otherwise it would be centered weirdly this.$authorAndSource = $( '' ) .addClass( 'mw-mmv-source-author' ) .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' ); } ); this.creditField = new mw.mmv.ui.TruncatableTextField( this.$credit, this.$authorAndSource, { styles: [] } ); this.creditField.setTitle( mw.message( 'multimediaviewer-credit-popup-text' ), mw.message( 'multimediaviewer-credit-popup-text-more' ) ); this.$authorAndSource.add( this.creditField.$ellipsis ).tipsy( { delayIn: mw.config.get( 'wgMultimediaViewer' ).tooltipDelay, gravity: this.correctEW( 'sw' ) } ); }; /** * 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 = $( '