2014-02-07 14:47:00 +00:00
|
|
|
/*
|
|
|
|
* 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 <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2014-04-11 14:58:37 +00:00
|
|
|
( function ( mw, $, oo ) {
|
2014-02-07 14:47:00 +00:00
|
|
|
// Shortcut for prototype later
|
|
|
|
var MPP;
|
|
|
|
|
|
|
|
/**
|
2014-02-19 02:27:30 +00:00
|
|
|
* Represents the metadata panel in the viewer
|
|
|
|
* @class mw.mmv.ui.MetadataPanel
|
2014-02-07 14:47:00 +00:00
|
|
|
* @extends mw.mmv.ui.Element
|
|
|
|
* @constructor
|
2014-07-03 19:12:59 +00:00
|
|
|
* @param {jQuery} $container The container for the panel (.mw-mmv-post-image).
|
2014-07-16 23:15:38 +00:00
|
|
|
* @param {jQuery} $aboveFold The always-visible part of the metadata panel (.mw-mmv-above-fold).
|
2014-05-01 10:00:31 +00:00
|
|
|
* @param {Object} localStorage the localStorage object, for dependency injection
|
2014-09-12 18:05:13 +00:00
|
|
|
* @param {mw.mmv.Config} config A configuration object.
|
2014-02-07 14:47:00 +00:00
|
|
|
*/
|
2014-09-12 18:05:13 +00:00
|
|
|
function MetadataPanel( $container, $aboveFold, localStorage, config ) {
|
2014-02-07 14:47:00 +00:00
|
|
|
mw.mmv.ui.Element.call( this, $container );
|
2014-03-17 08:07:53 +00:00
|
|
|
|
2014-07-16 23:15:38 +00:00
|
|
|
this.$aboveFold = $aboveFold;
|
2014-06-11 02:14:59 +00:00
|
|
|
|
|
|
|
/** @property {mw.mmv.Config} config - */
|
2014-09-12 18:05:13 +00:00
|
|
|
this.config = config;
|
2014-06-11 02:14:59 +00:00
|
|
|
|
2014-03-26 23:59:04 +00:00
|
|
|
/** @property {mw.mmv.HtmlUtils} htmlUtils - */
|
|
|
|
this.htmlUtils = new mw.mmv.HtmlUtils();
|
|
|
|
|
2014-05-05 21:44:27 +00:00
|
|
|
this.initializeHeader( localStorage );
|
2014-02-07 14:47:00 +00:00
|
|
|
this.initializeImageMetadata();
|
|
|
|
this.initializeAboutLinks();
|
|
|
|
}
|
|
|
|
oo.inheritClass( MetadataPanel, mw.mmv.ui.Element );
|
|
|
|
MPP = MetadataPanel.prototype;
|
|
|
|
|
2014-02-13 20:50:05 +00:00
|
|
|
MPP.attach = function() {
|
2014-07-03 19:12:59 +00:00
|
|
|
var panel = this;
|
|
|
|
|
2014-05-05 21:44:27 +00:00
|
|
|
this.scroller.attach();
|
2014-04-01 01:41:57 +00:00
|
|
|
this.buttons.attach();
|
2014-07-03 19:12:59 +00:00
|
|
|
|
|
|
|
this.$title.add( this.$authorAndSource ).on( 'click.mmv-mp', function ( e ) {
|
|
|
|
if (
|
|
|
|
$( e.target ).is( 'a' ) // ignore clicks to external links
|
|
|
|
|| !$( e.target ).closest( '.mw-mmv-truncate-toolong' ).length // text is not truncated
|
|
|
|
) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
panel.toggleTruncatedText();
|
|
|
|
} );
|
2014-07-16 23:15:38 +00:00
|
|
|
|
|
|
|
$( this.$container ).on( 'mmv-metadata-open', function () {
|
|
|
|
panel.revealTruncatedText( true );
|
|
|
|
} ).on( 'mmv-metadata-close', function () {
|
|
|
|
panel.hideTruncatedText();
|
|
|
|
} );
|
|
|
|
|
|
|
|
this.handleEvent( 'jq-fullscreen-change.lip', function() {
|
|
|
|
panel.hideTruncatedText();
|
|
|
|
} );
|
2014-02-13 20:50:05 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
MPP.unattach = function() {
|
2014-06-27 19:45:45 +00:00
|
|
|
this.$title.tipsy( 'hide' );
|
2014-07-14 21:51:06 +00:00
|
|
|
|
2014-07-03 19:12:59 +00:00
|
|
|
this.$authorAndSource.tipsy( 'hide' );
|
2014-06-27 19:45:45 +00:00
|
|
|
|
2014-05-05 21:44:27 +00:00
|
|
|
this.scroller.unattach();
|
2014-04-01 01:41:57 +00:00
|
|
|
this.buttons.unattach();
|
2014-07-03 19:12:59 +00:00
|
|
|
|
|
|
|
this.$title.add( this.$authorAndSource ).off( 'click.mmv-mp' );
|
2014-02-13 20:50:05 +00:00
|
|
|
this.clearEvents();
|
|
|
|
};
|
|
|
|
|
2014-02-07 14:47:00 +00:00
|
|
|
MPP.empty = function () {
|
2014-05-05 21:44:27 +00:00
|
|
|
this.scroller.empty();
|
|
|
|
|
2014-02-07 14:47:00 +00:00
|
|
|
this.$license.empty().addClass( 'empty' );
|
2014-02-14 00:36:10 +00:00
|
|
|
this.$permissionLink.hide();
|
2014-02-07 14:47:00 +00:00
|
|
|
|
2014-04-01 01:41:57 +00:00
|
|
|
this.buttons.empty();
|
|
|
|
|
2014-02-07 14:47:00 +00:00
|
|
|
this.description.empty();
|
2014-02-14 00:36:10 +00:00
|
|
|
this.permission.empty();
|
2014-02-07 14:47:00 +00:00
|
|
|
|
2014-07-03 19:12:59 +00:00
|
|
|
this.hideTruncatedText();
|
2014-03-01 01:10:51 +00:00
|
|
|
this.$title.empty().removeClass( 'error' );
|
2014-07-03 19:12:59 +00:00
|
|
|
this.$authorAndSource.empty();
|
|
|
|
this.$credit.addClass( 'empty' );
|
2014-02-07 14:47:00 +00:00
|
|
|
|
|
|
|
this.$username.empty();
|
|
|
|
this.$usernameLi.addClass( 'empty' );
|
|
|
|
|
|
|
|
this.$datetime.empty();
|
|
|
|
this.$datetimeLi.addClass( 'empty' );
|
|
|
|
|
|
|
|
this.$location.empty();
|
|
|
|
this.$locationLi.addClass( 'empty' );
|
|
|
|
|
2014-04-21 21:48:40 +00:00
|
|
|
this.progressBar.empty();
|
2014-02-07 14:47:00 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// **********************************************
|
|
|
|
// *********** Initialization methods ***********
|
|
|
|
// **********************************************
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initializes the header, which contains the title, credit, and license elements.
|
2014-05-05 21:44:27 +00:00
|
|
|
* @param {Object} localStorage the localStorage object, for dependency injection
|
2014-02-07 14:47:00 +00:00
|
|
|
*/
|
2014-05-05 21:44:27 +00:00
|
|
|
MPP.initializeHeader = function ( localStorage ) {
|
2014-07-16 23:15:38 +00:00
|
|
|
this.progressBar = new mw.mmv.ui.ProgressBar( this.$aboveFold );
|
2014-02-25 13:43:22 +00:00
|
|
|
|
2014-07-16 23:15:38 +00:00
|
|
|
this.scroller = new mw.mmv.ui.MetadataPanelScroller( this.$container, this.$aboveFold,
|
2014-05-05 21:44:27 +00:00
|
|
|
localStorage );
|
2014-02-07 14:47:00 +00:00
|
|
|
|
|
|
|
this.$titleDiv = $( '<div>' )
|
2014-03-31 21:33:12 +00:00
|
|
|
.addClass( 'mw-mmv-title-contain' )
|
2014-07-16 23:15:38 +00:00
|
|
|
.appendTo( this.$aboveFold );
|
2014-02-07 14:47:00 +00:00
|
|
|
|
2014-07-16 23:15:38 +00:00
|
|
|
this.$container.append( this.$aboveFold );
|
2014-02-07 14:47:00 +00:00
|
|
|
|
2014-04-01 01:41:57 +00:00
|
|
|
this.initializeButtons(); // float, needs to be on top
|
2014-02-07 14:47:00 +00:00
|
|
|
this.initializeTitleAndCredit();
|
|
|
|
this.initializeLicense();
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initializes the title and credit elements.
|
|
|
|
*/
|
|
|
|
MPP.initializeTitleAndCredit = function () {
|
2014-09-05 12:52:53 +00:00
|
|
|
var self = this;
|
|
|
|
|
2014-02-07 14:47:00 +00:00
|
|
|
this.$titleAndCredit = $( '<div>' )
|
2014-03-31 21:33:12 +00:00
|
|
|
.addClass( 'mw-mmv-title-credit' )
|
2014-04-15 16:14:06 +00:00
|
|
|
// Since these elements are created dynamically, we listen this way for logging purposes
|
2014-09-05 12:52:53 +00:00
|
|
|
.on( 'click', '.mw-mmv-author a', function ( e ) {
|
|
|
|
self.trackLinkClick.call( this, 'author-page', e );
|
2014-04-15 16:14:06 +00:00
|
|
|
} )
|
2014-09-05 12:52:53 +00:00
|
|
|
.on( 'click', '.mw-mmv-source a', function ( e ) {
|
|
|
|
self.trackLinkClick.call( this, 'source-page', e );
|
2014-04-15 16:14:06 +00:00
|
|
|
} )
|
2014-02-07 14:47:00 +00:00
|
|
|
.appendTo( this.$titleDiv );
|
|
|
|
|
|
|
|
this.initializeTitle();
|
|
|
|
this.initializeCredit();
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initializes the title elements.
|
|
|
|
*/
|
|
|
|
MPP.initializeTitle = function () {
|
|
|
|
this.$titlePara = $( '<p>' )
|
2014-03-31 21:33:12 +00:00
|
|
|
.addClass( 'mw-mmv-title-para' )
|
2014-02-07 14:47:00 +00:00
|
|
|
.appendTo( this.$titleAndCredit );
|
|
|
|
|
|
|
|
this.$title = $( '<span>' )
|
2014-05-31 00:18:12 +00:00
|
|
|
.tipsy( {
|
2014-07-03 19:12:59 +00:00
|
|
|
delayIn: mw.config.get( 'wgMultimediaViewer' ).tooltipDelay,
|
2014-10-03 09:15:28 +00:00
|
|
|
gravity: this.correctEW( 'sw' )
|
2014-05-31 00:18:12 +00:00
|
|
|
} )
|
2014-03-27 06:05:47 +00:00
|
|
|
.addClass( 'mw-mmv-title' );
|
|
|
|
|
|
|
|
this.title = new mw.mmv.ui.TruncatableTextField( this.$titlePara, this.$title );
|
2014-07-03 19:12:59 +00:00
|
|
|
this.title.setTitle(
|
|
|
|
mw.message( 'multimediaviewer-title-popup-text' ),
|
|
|
|
mw.message( 'multimediaviewer-title-popup-text-more' )
|
|
|
|
);
|
2014-02-07 14:47:00 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initializes the credit elements.
|
|
|
|
*/
|
|
|
|
MPP.initializeCredit = function () {
|
|
|
|
this.$credit = $( '<p>' )
|
2014-07-03 19:12:59 +00:00
|
|
|
.addClass( 'mw-mmv-credit empty' )
|
|
|
|
.appendTo( this.$titleAndCredit );
|
|
|
|
|
|
|
|
// we need an inline container for tipsy, otherwise it would be centered weirdly
|
|
|
|
this.$authorAndSource = $( '<span>' )
|
|
|
|
.addClass( 'mw-mmv-source-author' )
|
|
|
|
.tipsy( {
|
|
|
|
delayIn: mw.config.get( 'wgMultimediaViewer' ).tooltipDelay,
|
2014-10-03 09:15:28 +00:00
|
|
|
gravity: this.correctEW( 'sw' )
|
2014-07-03 19:12:59 +00:00
|
|
|
} );
|
2014-03-27 06:05:47 +00:00
|
|
|
|
|
|
|
this.creditField = new mw.mmv.ui.TruncatableTextField(
|
|
|
|
this.$credit,
|
2014-07-03 19:12:59 +00:00
|
|
|
this.$authorAndSource,
|
2014-03-27 06:05:47 +00:00
|
|
|
{ max: 200, small: 160 }
|
|
|
|
);
|
2014-07-03 19:12:59 +00:00
|
|
|
|
|
|
|
this.creditField.setTitle(
|
|
|
|
mw.message( 'multimediaviewer-credit-popup-text' ),
|
|
|
|
mw.message( 'multimediaviewer-credit-popup-text-more' )
|
|
|
|
);
|
2014-02-07 14:47:00 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initializes the license elements.
|
|
|
|
*/
|
|
|
|
MPP.initializeLicense = function () {
|
2014-02-14 00:36:10 +00:00
|
|
|
var panel = this;
|
|
|
|
|
2014-02-07 14:47:00 +00:00
|
|
|
this.$license = $( '<a>' )
|
2014-03-31 21:33:12 +00:00
|
|
|
.addClass( 'mw-mmv-license empty' )
|
2014-02-07 14:47:00 +00:00
|
|
|
.prop( 'href', '#' )
|
2014-04-15 16:14:06 +00:00
|
|
|
.appendTo( this.$titlePara )
|
2014-09-05 12:52:53 +00:00
|
|
|
.on( 'click', function( e ) {
|
|
|
|
panel.trackLinkClick.call( this, 'license-page', e );
|
2014-04-15 16:14:06 +00:00
|
|
|
} );
|
2014-02-14 00:36:10 +00:00
|
|
|
|
|
|
|
this.$permissionLink = $( '<span>' )
|
2014-03-31 21:33:12 +00:00
|
|
|
.addClass( 'mw-mmv-permission-link mw-mmv-label' )
|
2014-02-14 00:36:10 +00:00
|
|
|
.text( mw.message( 'multimediaviewer-permission-link' ).text() )
|
|
|
|
.appendTo( this.$titlePara )
|
2014-02-26 01:20:34 +00:00
|
|
|
.hide()
|
2014-02-14 00:36:10 +00:00
|
|
|
.on( 'click', function() {
|
|
|
|
panel.permission.grow();
|
2014-05-05 21:44:27 +00:00
|
|
|
panel.scroller.scrollIntoView( panel.permission.$box, 500 );
|
2014-07-03 19:12:59 +00:00
|
|
|
return false;
|
2014-02-14 00:36:10 +00:00
|
|
|
} );
|
2014-02-07 14:47:00 +00:00
|
|
|
};
|
|
|
|
|
2014-04-01 01:41:57 +00:00
|
|
|
MPP.initializeButtons = function () {
|
2014-05-01 10:00:31 +00:00
|
|
|
this.buttons = new mw.mmv.ui.StripeButtons( this.$titleDiv, this.localStorage );
|
2014-04-01 01:41:57 +00:00
|
|
|
};
|
|
|
|
|
2014-02-07 14:47:00 +00:00
|
|
|
/**
|
|
|
|
* Initializes the main body of metadata elements.
|
|
|
|
*/
|
|
|
|
MPP.initializeImageMetadata = function () {
|
|
|
|
this.$imageMetadata = $( '<div>' )
|
2014-03-31 21:33:12 +00:00
|
|
|
.addClass( 'mw-mmv-image-metadata' )
|
2014-02-07 14:47:00 +00:00
|
|
|
.appendTo( this.$container );
|
|
|
|
|
2014-02-14 00:36:10 +00:00
|
|
|
this.$imageMetadataLeft = $( '<div>' )
|
2014-03-31 21:33:12 +00:00
|
|
|
.addClass( 'mw-mmv-image-metadata-column mw-mmv-image-metadata-desc-column' )
|
2014-02-14 00:36:10 +00:00
|
|
|
.appendTo( this.$imageMetadata );
|
|
|
|
|
|
|
|
this.$imageMetadataRight = $( '<div>' )
|
2014-03-31 21:33:12 +00:00
|
|
|
.addClass( 'mw-mmv-image-metadata-column mw-mmv-image-metadata-links-column' )
|
2014-02-14 00:36:10 +00:00
|
|
|
.appendTo( this.$imageMetadata );
|
|
|
|
|
|
|
|
this.description = new mw.mmv.ui.Description( this.$imageMetadataLeft );
|
|
|
|
this.permission = new mw.mmv.ui.Permission( this.$imageMetadataLeft );
|
2014-02-07 14:47:00 +00:00
|
|
|
this.initializeImageLinks();
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initializes the list of image metadata on the right side of the panel.
|
|
|
|
*/
|
|
|
|
MPP.initializeImageLinks = function () {
|
|
|
|
this.$imageLinkDiv = $( '<div>' )
|
2014-03-31 21:33:12 +00:00
|
|
|
.addClass( 'mw-mmv-image-links-div' )
|
2014-02-14 00:36:10 +00:00
|
|
|
.appendTo( this.$imageMetadataRight );
|
2014-02-07 14:47:00 +00:00
|
|
|
|
|
|
|
this.$imageLinks = $( '<ul>' )
|
2014-03-31 21:33:12 +00:00
|
|
|
.addClass( 'mw-mmv-image-links' )
|
2014-02-07 14:47:00 +00:00
|
|
|
.appendTo( this.$imageLinkDiv );
|
|
|
|
|
|
|
|
this.initializeUploader();
|
2014-02-26 17:19:51 +00:00
|
|
|
this.initializeDatetime();
|
2014-02-07 14:47:00 +00:00
|
|
|
this.initializeLocation();
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initializes the upload date/time element.
|
|
|
|
*/
|
|
|
|
MPP.initializeDatetime = function () {
|
|
|
|
this.$datetimeLi = $( '<li>' )
|
2014-03-31 21:33:12 +00:00
|
|
|
.addClass( 'mw-mmv-datetime-li empty' )
|
2014-02-07 14:47:00 +00:00
|
|
|
.appendTo( this.$imageLinks );
|
|
|
|
|
|
|
|
this.$datetime = $( '<span>' )
|
2014-03-31 21:33:12 +00:00
|
|
|
.addClass( 'mw-mmv-datetime' )
|
2014-02-07 14:47:00 +00:00
|
|
|
.appendTo( this.$datetimeLi );
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initializes the link to the uploader's file page.
|
|
|
|
*/
|
|
|
|
MPP.initializeUploader = function () {
|
2014-09-05 12:52:53 +00:00
|
|
|
var self = this;
|
|
|
|
|
2014-02-07 14:47:00 +00:00
|
|
|
this.$usernameLi = $( '<li>' )
|
2014-03-31 21:33:12 +00:00
|
|
|
.addClass( 'mw-mmv-username-li empty' )
|
2014-02-07 14:47:00 +00:00
|
|
|
.appendTo( this.$imageLinks );
|
|
|
|
|
|
|
|
this.$username = $( '<a>' )
|
2014-03-31 21:33:12 +00:00
|
|
|
.addClass( 'mw-mmv-username' )
|
2014-02-07 14:47:00 +00:00
|
|
|
.prop( 'href', '#' )
|
2014-09-05 12:52:53 +00:00
|
|
|
.appendTo( this.$usernameLi )
|
|
|
|
.click( function( e ) { self.trackLinkClick.call( this, 'uploader-page', e ); } );
|
2014-02-07 14:47:00 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initializes the geolocation element.
|
|
|
|
*/
|
|
|
|
MPP.initializeLocation = function () {
|
2014-09-05 12:52:53 +00:00
|
|
|
var self = this;
|
|
|
|
|
2014-02-07 14:47:00 +00:00
|
|
|
this.$locationLi = $( '<li>' )
|
2014-03-31 21:33:12 +00:00
|
|
|
.addClass( 'mw-mmv-location-li empty' )
|
2014-02-07 14:47:00 +00:00
|
|
|
.appendTo( this.$imageLinks );
|
|
|
|
|
|
|
|
this.$location = $( '<a>' )
|
2014-03-31 21:33:12 +00:00
|
|
|
.addClass( 'mw-mmv-location' )
|
2014-09-05 12:52:53 +00:00
|
|
|
.appendTo( this.$locationLi )
|
|
|
|
.click( function( e ) { self.trackLinkClick.call( this, 'location-page', e ); } );
|
2014-02-07 14:47:00 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initializes two about links at the bottom of the panel.
|
|
|
|
*/
|
|
|
|
MPP.initializeAboutLinks = function () {
|
2014-09-05 12:52:53 +00:00
|
|
|
var separator = ' | ',
|
|
|
|
self = this;
|
2014-03-24 13:35:34 +00:00
|
|
|
|
2014-02-07 14:47:00 +00:00
|
|
|
this.$mmvAboutLink = $( '<a>' )
|
|
|
|
.prop( 'href', mw.config.get( 'wgMultimediaViewer' ).infoLink )
|
|
|
|
.text( mw.message( 'multimediaviewer-about-mmv' ).text() )
|
2014-09-05 12:52:53 +00:00
|
|
|
.addClass( 'mw-mmv-about-link' )
|
|
|
|
.click( function( e ) { self.trackLinkClick.call( this, 'about-page', e ); } );
|
2014-02-07 14:47:00 +00:00
|
|
|
|
|
|
|
this.$mmvDiscussLink = $( '<a>' )
|
|
|
|
.prop( 'href', mw.config.get( 'wgMultimediaViewer' ).discussionLink )
|
|
|
|
.text( mw.message( 'multimediaviewer-discuss-mmv' ).text() )
|
2014-09-05 12:52:53 +00:00
|
|
|
.addClass( 'mw-mmv-discuss-link' )
|
|
|
|
.click( function( e ) { self.trackLinkClick.call( this, 'discuss-page', e ); } );
|
2014-02-07 14:47:00 +00:00
|
|
|
|
2014-03-24 13:35:34 +00:00
|
|
|
this.$mmvHelpLink = $( '<a>' )
|
|
|
|
.prop( 'href', mw.config.get( 'wgMultimediaViewer' ).helpLink )
|
|
|
|
.text( mw.message( 'multimediaviewer-help-mmv' ).text() )
|
2014-09-05 12:52:53 +00:00
|
|
|
.addClass( 'mw-mmv-help-link' )
|
|
|
|
.click( function( e ) { self.trackLinkClick.call( this, 'help-page', e ); } );
|
2014-03-24 13:35:34 +00:00
|
|
|
|
2014-02-07 14:47:00 +00:00
|
|
|
this.$mmvAboutLinks = $( '<div>' )
|
2014-03-31 21:33:12 +00:00
|
|
|
.addClass( 'mw-mmv-about-links' )
|
2014-02-07 14:47:00 +00:00
|
|
|
.append(
|
|
|
|
this.$mmvAboutLink,
|
2014-03-24 13:35:34 +00:00
|
|
|
separator,
|
|
|
|
this.$mmvDiscussLink,
|
|
|
|
separator,
|
|
|
|
this.$mmvHelpLink
|
2014-02-07 14:47:00 +00:00
|
|
|
)
|
|
|
|
.appendTo( this.$imageMetadata );
|
2014-06-11 02:14:59 +00:00
|
|
|
};
|
2014-04-23 20:31:43 +00:00
|
|
|
|
2014-02-07 14:47:00 +00:00
|
|
|
// *********************************
|
|
|
|
// ******** Setting methods ********
|
|
|
|
// *********************************
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the link to the user page where possible
|
|
|
|
* @param {mw.mmv.model.Repo} repoData
|
|
|
|
* @param {string} username
|
|
|
|
* @param {string} gender
|
|
|
|
*/
|
|
|
|
MPP.setUserPageLink = function ( repoData, username, gender ) {
|
2014-02-19 19:12:22 +00:00
|
|
|
var userpage = 'User:' + username,
|
|
|
|
articlePath = repoData.getArticlePath(),
|
|
|
|
userlink = articlePath.replace( '$1', userpage );
|
2014-02-07 14:47:00 +00:00
|
|
|
|
2014-02-19 19:12:22 +00:00
|
|
|
this.$username
|
|
|
|
.text(
|
|
|
|
mw.message( 'multimediaviewer-userpage-link', username, gender ).text()
|
|
|
|
)
|
|
|
|
.prop( 'href', userlink );
|
2014-02-07 14:47:00 +00:00
|
|
|
|
2014-02-19 19:12:22 +00:00
|
|
|
this.$usernameLi.toggleClass( 'empty', !username );
|
2014-02-07 14:47:00 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the file title in the panel
|
|
|
|
* @param {string} title
|
|
|
|
*/
|
|
|
|
MPP.setFileTitle = function ( title ) {
|
2014-03-27 06:05:47 +00:00
|
|
|
this.title.set( title );
|
2014-02-07 14:47:00 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the upload or creation date and time in the panel
|
|
|
|
* @param {string} date The formatted date to set.
|
|
|
|
* @param {boolean} created Whether this is the creation date
|
|
|
|
*/
|
|
|
|
MPP.setDateTime = function ( date, created ) {
|
|
|
|
this.$datetime.text(
|
|
|
|
mw.message(
|
|
|
|
'multimediaviewer-datetime-' + ( created ? 'created' : 'uploaded' ),
|
|
|
|
date
|
|
|
|
).text()
|
|
|
|
);
|
|
|
|
|
|
|
|
this.$datetimeLi.removeClass( 'empty' );
|
|
|
|
};
|
|
|
|
|
2014-03-27 06:05:47 +00:00
|
|
|
/**
|
|
|
|
* Bignasty function for setting source and author. Both #setAuthor and
|
|
|
|
* #setSource use this with some shortcuts.
|
|
|
|
* @param {string} source With unsafe HTML
|
|
|
|
* @param {string} author With unsafe HTML
|
|
|
|
*/
|
|
|
|
MPP.setCredit = function ( source, author ) {
|
2014-04-10 22:58:19 +00:00
|
|
|
this.source = source || null;
|
|
|
|
this.author = author || null;
|
2014-03-27 06:05:47 +00:00
|
|
|
|
|
|
|
if ( author && source ) {
|
|
|
|
this.creditField.set(
|
|
|
|
mw.message(
|
|
|
|
'multimediaviewer-credit',
|
|
|
|
this.author,
|
|
|
|
this.source
|
|
|
|
).plain()
|
|
|
|
);
|
|
|
|
} else if ( author ) {
|
2014-04-10 22:58:19 +00:00
|
|
|
this.creditField.set( this.author );
|
2014-03-27 06:05:47 +00:00
|
|
|
} else if ( source ) {
|
2014-04-10 22:58:19 +00:00
|
|
|
this.creditField.set( this.source );
|
2014-03-27 06:05:47 +00:00
|
|
|
}
|
2014-05-31 00:18:12 +00:00
|
|
|
|
2014-07-03 19:12:59 +00:00
|
|
|
this.$credit.toggleClass( 'empty', !author && !source );
|
2014-03-27 06:05:47 +00:00
|
|
|
};
|
|
|
|
|
2014-02-07 14:47:00 +00:00
|
|
|
/**
|
|
|
|
* Sets the source in the panel
|
|
|
|
* @param {string} source Warning - unsafe HTML sometimes goes here
|
|
|
|
*/
|
|
|
|
MPP.setSource = function ( source ) {
|
2014-04-10 22:58:19 +00:00
|
|
|
if ( source ) {
|
|
|
|
source = $( '<span>' )
|
|
|
|
.addClass( 'mw-mmv-source' )
|
|
|
|
.append( $.parseHTML( source ) )
|
|
|
|
.get( 0 ).outerHTML;
|
|
|
|
}
|
|
|
|
|
2014-03-27 06:05:47 +00:00
|
|
|
this.setCredit( source, this.author );
|
2014-02-07 14:47:00 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the author in the panel
|
|
|
|
* @param {string} author Warning - unsafe HTML sometimes goes here
|
|
|
|
*/
|
|
|
|
MPP.setAuthor = function ( author ) {
|
2014-04-10 22:58:19 +00:00
|
|
|
if ( author ) {
|
|
|
|
author = $( '<span>' )
|
|
|
|
.addClass( 'mw-mmv-author' )
|
|
|
|
.append( $.parseHTML( author ) )
|
|
|
|
.get( 0 ).outerHTML;
|
|
|
|
}
|
|
|
|
|
2014-03-27 06:05:47 +00:00
|
|
|
this.setCredit( this.source, author );
|
2014-02-07 14:47:00 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the license display in the panel
|
2014-04-19 00:25:12 +00:00
|
|
|
* @param {mw.mmv.model.License|null} license license data (could be missing)
|
|
|
|
* @param {string} filePageUrl URL of the file description page
|
2014-02-07 14:47:00 +00:00
|
|
|
*/
|
2014-04-19 00:25:12 +00:00
|
|
|
MPP.setLicense = function ( license, filePageUrl ) {
|
2014-04-19 00:26:55 +00:00
|
|
|
var shortName, url, isCc;
|
2014-04-19 00:25:12 +00:00
|
|
|
|
2014-04-19 00:39:46 +00:00
|
|
|
if ( license ) {
|
2014-04-19 00:26:55 +00:00
|
|
|
shortName = license.getShortName();
|
2014-04-19 00:39:46 +00:00
|
|
|
url = license.deedUrl || filePageUrl;
|
|
|
|
isCc = license.isCc();
|
2014-04-19 00:25:12 +00:00
|
|
|
} else {
|
|
|
|
shortName = mw.message( 'multimediaviewer-license-default' ).text();
|
2014-04-19 00:39:46 +00:00
|
|
|
url = filePageUrl;
|
|
|
|
isCc = false;
|
2014-04-19 00:25:12 +00:00
|
|
|
}
|
|
|
|
|
2014-02-07 14:47:00 +00:00
|
|
|
this.$license
|
2014-04-19 00:25:12 +00:00
|
|
|
.text( shortName )
|
2014-04-18 18:27:00 +00:00
|
|
|
.toggleClass( 'cc-license', isCc )
|
2014-04-19 00:29:04 +00:00
|
|
|
.prop( 'href', url )
|
|
|
|
.prop( 'target', license && license.deedUrl ? '_blank' : '' );
|
2014-02-07 14:47:00 +00:00
|
|
|
|
|
|
|
this.$license.removeClass( 'empty' );
|
|
|
|
};
|
|
|
|
|
2014-02-14 00:36:10 +00:00
|
|
|
/**
|
|
|
|
* Set an extra permission text which should be displayed.
|
|
|
|
* @param {string} permission
|
|
|
|
*/
|
|
|
|
MPP.setPermission = function ( permission ) {
|
|
|
|
this.$permissionLink.show();
|
|
|
|
this.permission.set( permission );
|
|
|
|
};
|
|
|
|
|
2014-02-07 14:47:00 +00:00
|
|
|
/**
|
|
|
|
* Sets location data in the interface.
|
|
|
|
* @param {mw.mmv.model.Image} imageData
|
|
|
|
*/
|
|
|
|
MPP.setLocationData = function ( imageData ) {
|
|
|
|
var latsec, latitude, latmsg, latdeg, latremain, latmin,
|
|
|
|
longsec, longitude, longmsg, longdeg, longremain, longmin,
|
|
|
|
language;
|
|
|
|
|
|
|
|
if ( !imageData.hasCoords() ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
latitude = imageData.latitude >= 0 ? imageData.latitude : imageData.latitude * -1;
|
|
|
|
latmsg = 'multimediaviewer-geoloc-' + ( imageData.latitude >= 0 ? 'north' : 'south' );
|
|
|
|
latdeg = Math.floor( latitude );
|
|
|
|
latremain = latitude - latdeg;
|
|
|
|
latmin = Math.floor( ( latremain ) * 60 );
|
|
|
|
|
|
|
|
longitude = imageData.longitude >= 0 ? imageData.longitude : imageData.longitude * -1;
|
|
|
|
longmsg = 'multimediaviewer-geoloc-' + ( imageData.longitude >= 0 ? 'east' : 'west' );
|
|
|
|
longdeg = Math.floor( longitude );
|
|
|
|
longremain = longitude - longdeg;
|
|
|
|
longmin = Math.floor( ( longremain ) * 60 );
|
|
|
|
|
|
|
|
longremain -= longmin / 60;
|
|
|
|
latremain -= latmin / 60;
|
|
|
|
latsec = Math.round( latremain * 100 * 60 * 60 ) / 100;
|
|
|
|
longsec = Math.round( longremain * 100 * 60 * 60 ) / 100;
|
|
|
|
|
|
|
|
this.$location.text(
|
|
|
|
mw.message( 'multimediaviewer-geolocation',
|
|
|
|
mw.message(
|
|
|
|
'multimediaviewer-geoloc-coords',
|
|
|
|
|
|
|
|
mw.message(
|
|
|
|
'multimediaviewer-geoloc-coord',
|
|
|
|
mw.language.convertNumber( latdeg ),
|
|
|
|
mw.language.convertNumber( latmin ),
|
|
|
|
mw.language.convertNumber( latsec ),
|
|
|
|
mw.message( latmsg ).text()
|
|
|
|
).text(),
|
|
|
|
|
|
|
|
mw.message(
|
|
|
|
'multimediaviewer-geoloc-coord',
|
|
|
|
mw.language.convertNumber( longdeg ),
|
|
|
|
mw.language.convertNumber( longmin ),
|
|
|
|
mw.language.convertNumber( longsec ),
|
|
|
|
mw.message( longmsg ).text()
|
|
|
|
).text()
|
|
|
|
).text()
|
|
|
|
).text()
|
|
|
|
);
|
|
|
|
|
|
|
|
$.each( mw.language.data, function( key, value ) {
|
|
|
|
value = 'go away jshint';
|
|
|
|
language = key;
|
|
|
|
return false;
|
|
|
|
} );
|
|
|
|
|
|
|
|
this.$location.prop( 'href', (
|
|
|
|
'//tools.wmflabs.org/geohack/geohack.php?pagename=' +
|
|
|
|
'File:' + imageData.title.getMain() +
|
|
|
|
'¶ms=' +
|
|
|
|
Math.abs( imageData.latitude ) + ( imageData.latitude >= 0 ? '_N_' : '_S_' ) +
|
|
|
|
Math.abs( imageData.longitude ) + ( imageData.longitude >= 0 ? '_E_' : '_W_' ) +
|
|
|
|
'&language=' + language
|
|
|
|
) );
|
|
|
|
|
|
|
|
this.$locationLi.removeClass( 'empty' );
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set all the image information in the panel
|
2014-02-25 02:28:49 +00:00
|
|
|
* @param {mw.mmv.LightboxImage} image
|
2014-02-07 14:47:00 +00:00
|
|
|
* @param {mw.mmv.model.Image} imageData
|
|
|
|
* @param {mw.mmv.model.Repo} repoData
|
2014-02-13 09:52:40 +00:00
|
|
|
* @param {mw.mmv.model.User} user
|
2014-02-07 14:47:00 +00:00
|
|
|
*/
|
2014-09-05 06:14:52 +00:00
|
|
|
MPP.setImageInfo = function ( image, imageData, repoData, user ) {
|
2014-04-19 00:25:12 +00:00
|
|
|
var panel = this,
|
2014-02-07 14:47:00 +00:00
|
|
|
fileTitle = image.filePageTitle;
|
|
|
|
|
2014-09-05 00:45:36 +00:00
|
|
|
mw.mmv.attributionLogger.logAttribution( imageData );
|
|
|
|
|
2014-02-07 14:47:00 +00:00
|
|
|
this.setFileTitle( fileTitle.getNameText() );
|
|
|
|
|
|
|
|
if ( imageData.creationDateTime ) {
|
2014-04-11 14:58:37 +00:00
|
|
|
// Use the raw date until moment can try to interpret it
|
|
|
|
panel.setDateTime( imageData.creationDateTime );
|
|
|
|
|
|
|
|
this.formatDate( imageData.creationDateTime ).then( function ( formattedDate ) {
|
|
|
|
panel.setDateTime( formattedDate, true );
|
|
|
|
} );
|
2014-02-07 14:47:00 +00:00
|
|
|
} else if ( imageData.uploadDateTime ) {
|
2014-04-11 14:58:37 +00:00
|
|
|
// Use the raw date until moment can try to interpret it
|
|
|
|
panel.setDateTime( imageData.uploadDateTime );
|
|
|
|
|
|
|
|
this.formatDate( imageData.uploadDateTime ).then( function ( formattedDate ) {
|
|
|
|
panel.setDateTime( formattedDate );
|
|
|
|
} );
|
2014-02-07 14:47:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( imageData.source ) {
|
|
|
|
this.setSource( imageData.source );
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( imageData.author ) {
|
|
|
|
this.setAuthor( imageData.author );
|
|
|
|
}
|
|
|
|
|
2014-04-02 00:07:51 +00:00
|
|
|
this.buttons.set( imageData, repoData );
|
2014-02-07 14:47:00 +00:00
|
|
|
this.description.set( imageData.description, image.caption );
|
|
|
|
|
2014-04-19 00:39:46 +00:00
|
|
|
this.setLicense( imageData.license, imageData.descriptionUrl );
|
2014-02-07 14:47:00 +00:00
|
|
|
|
2014-02-14 00:36:10 +00:00
|
|
|
if ( imageData.permission ) {
|
|
|
|
this.setPermission( imageData.permission );
|
|
|
|
}
|
|
|
|
|
2014-02-07 14:47:00 +00:00
|
|
|
this.setLocationData( imageData );
|
|
|
|
|
2014-02-13 09:52:40 +00:00
|
|
|
if ( user ) {
|
|
|
|
this.setUserPageLink( repoData, imageData.lastUploader, user.gender );
|
2014-02-07 14:47:00 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-03-01 01:10:51 +00:00
|
|
|
/**
|
|
|
|
* Show an error message, in case the data could not be loaded
|
|
|
|
* @param {string} error
|
|
|
|
*/
|
|
|
|
MPP.showError = function ( error ) {
|
|
|
|
this.$title.addClass( 'error' )
|
|
|
|
.text( mw.message( 'multimediaviewer-metadata-error', error ).text() );
|
|
|
|
};
|
|
|
|
|
2014-02-07 14:47:00 +00:00
|
|
|
/**
|
|
|
|
* Transforms a date string into localized, human-readable format.
|
|
|
|
* Unrecognized strings are returned unchanged.
|
|
|
|
* @param {string} dateString
|
2014-04-11 14:58:37 +00:00
|
|
|
* @return {jQuery.Deferred}
|
2014-02-07 14:47:00 +00:00
|
|
|
*/
|
|
|
|
MPP.formatDate = function ( dateString ) {
|
2014-04-11 14:58:37 +00:00
|
|
|
var deferred = $.Deferred(),
|
|
|
|
date;
|
|
|
|
|
|
|
|
mw.loader.using( 'moment', function () {
|
|
|
|
date = moment( dateString );
|
|
|
|
|
|
|
|
if ( date.isValid() ) {
|
|
|
|
deferred.resolve( date.format( 'LL' ) );
|
|
|
|
} else {
|
|
|
|
deferred.resolve( dateString );
|
|
|
|
}
|
|
|
|
}, function ( error ) {
|
|
|
|
deferred.reject( error );
|
|
|
|
if ( window.console && window.console.error ) {
|
|
|
|
window.console.error( 'mw.loader.using error when trying to load moment', error );
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
|
|
|
|
return deferred.promise();
|
2014-02-07 14:47:00 +00:00
|
|
|
};
|
|
|
|
|
2014-07-03 19:12:59 +00:00
|
|
|
/**
|
|
|
|
* Calls #revealTruncatedText() or #hideTruncatedText() based on the current state.
|
|
|
|
*/
|
|
|
|
MPP.toggleTruncatedText = function () {
|
|
|
|
if ( this.$container.hasClass( 'mw-mmv-untruncated' ) ) {
|
|
|
|
this.hideTruncatedText();
|
|
|
|
} else {
|
|
|
|
this.revealTruncatedText();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Shows truncated text in the title and credit (this also rearranges the layout a bit).
|
|
|
|
* Opens the panel partially to make sure the revealed text is visible.
|
2014-07-16 23:15:38 +00:00
|
|
|
* @param {boolean} noScroll if set, do not scroll the panel (because the function was triggered from a
|
|
|
|
* scroll event in the first place)
|
2014-07-03 19:12:59 +00:00
|
|
|
*/
|
2014-07-16 23:15:38 +00:00
|
|
|
MPP.revealTruncatedText = function ( noScroll ) {
|
|
|
|
if ( this.$container.hasClass( 'mw-mmv-untruncated' ) ) {
|
|
|
|
// avoid self-triggering via reveal -> scroll -> reveal
|
|
|
|
return;
|
|
|
|
}
|
2014-07-03 19:12:59 +00:00
|
|
|
this.$container.addClass( 'mw-mmv-untruncated' );
|
|
|
|
this.title.grow();
|
|
|
|
this.creditField.grow();
|
2014-07-16 23:15:38 +00:00
|
|
|
if ( this.aboveFoldIsLargerThanNormal() && !noScroll ) {
|
2014-07-03 19:12:59 +00:00
|
|
|
this.scroller.scrollIntoView( this.$datetimeLi, 500 );
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Undoes changes made by revealTruncatedText().
|
|
|
|
*/
|
|
|
|
MPP.hideTruncatedText = function () {
|
2014-07-16 23:15:38 +00:00
|
|
|
if ( !this.$container.hasClass( 'mw-mmv-untruncated' ) ) {
|
|
|
|
// avoid double-triggering
|
|
|
|
return;
|
|
|
|
}
|
2014-07-03 19:12:59 +00:00
|
|
|
this.title.shrink();
|
|
|
|
this.creditField.shrink();
|
|
|
|
this.$container.removeClass( 'mw-mmv-untruncated' );
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns true if the above-fold part of the metadata panel changed size (due to text overflow) after
|
|
|
|
* calling revealTruncatedText().
|
|
|
|
*/
|
|
|
|
MPP.aboveFoldIsLargerThanNormal = function () {
|
2014-07-16 23:15:38 +00:00
|
|
|
return this.$aboveFold.height() > parseInt( this.$aboveFold.css( 'min-height' ), 10 );
|
2014-07-03 19:12:59 +00:00
|
|
|
};
|
|
|
|
|
2014-02-07 14:47:00 +00:00
|
|
|
mw.mmv.ui.MetadataPanel = MetadataPanel;
|
2014-04-11 14:58:37 +00:00
|
|
|
}( mediaWiki, jQuery, OO ) );
|