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-10-27 16:17:49 +00:00
|
|
|
* @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).
|
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;
|
|
|
|
|
2015-06-20 05:03:28 +00:00
|
|
|
/**
|
|
|
|
* Maximum number of restriction icons before default icon is used
|
|
|
|
* @property MAX_RESTRICT
|
|
|
|
* @static
|
|
|
|
*/
|
|
|
|
MetadataPanel.MAX_RESTRICT = 4;
|
|
|
|
|
2014-11-22 02:46:51 +00:00
|
|
|
/**
|
|
|
|
* FIXME this should be in the jquery.fullscreen plugin.
|
|
|
|
*/
|
2015-01-23 12:48:27 +00:00
|
|
|
MPP.isFullscreened = function () {
|
2014-11-22 02:46:51 +00:00
|
|
|
return $( this.$container ).closest( '.jq-fullscreened' ).length > 0;
|
|
|
|
};
|
|
|
|
|
2015-01-23 12:48:27 +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-10-29 19:50:53 +00:00
|
|
|
this.title.attach();
|
|
|
|
this.creditField.attach();
|
|
|
|
|
|
|
|
this.$title
|
|
|
|
.add( this.$authorAndSource )
|
|
|
|
.add( this.title.$ellipsis )
|
|
|
|
.add( this.creditField.$ellipsis )
|
2014-11-22 00:16:36 +00:00
|
|
|
.each( function () {
|
|
|
|
$( this ).tipsy( 'enable' );
|
|
|
|
} )
|
2014-10-29 19:50:53 +00:00
|
|
|
.on( 'click.mmv-mp', function ( e ) {
|
2014-11-11 15:21:36 +00:00
|
|
|
var clickTargetIsLink = $( e.target ).is( 'a' ),
|
|
|
|
clickTargetIsTruncated = !!$( e.target ).closest( '.mw-mmv-ttf-truncated' ).length,
|
2014-11-22 02:46:51 +00:00
|
|
|
someTextIsExpanded = !!$( e.target ).closest( '.mw-mmv-untruncated' ).length;
|
2014-11-11 15:21:36 +00:00
|
|
|
|
2014-10-29 19:50:53 +00:00
|
|
|
if (
|
2014-11-22 02:46:51 +00:00
|
|
|
!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
|
2014-10-29 19:50:53 +00:00
|
|
|
) {
|
2014-11-22 02:46:51 +00:00
|
|
|
if ( panel.isFullscreened() ) {
|
|
|
|
panel.revealTruncatedText();
|
|
|
|
} else {
|
|
|
|
panel.scroller.toggle( 'up' );
|
|
|
|
}
|
2014-10-29 19:50:53 +00:00
|
|
|
}
|
|
|
|
} );
|
2014-07-16 23:15:38 +00:00
|
|
|
|
2014-11-22 00:16:36 +00:00
|
|
|
$( this.$container ).on( 'mmv-metadata-open.mmv-mp mmv-metadata-reveal-truncated-text.mmv-mp', function () {
|
2014-11-11 15:21:36 +00:00
|
|
|
panel.revealTruncatedText();
|
2014-11-22 00:16:36 +00:00
|
|
|
} ).on( 'mmv-metadata-close.mmv-mp', function () {
|
2014-07-16 23:15:38 +00:00
|
|
|
panel.hideTruncatedText();
|
2014-11-22 02:46:51 +00:00
|
|
|
} ).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 );
|
2015-01-23 12:48:27 +00:00
|
|
|
} ).on( 'mmv-permission-grow.mmv-mp', function () {
|
2014-12-28 21:19:42 +00:00
|
|
|
panel.$permissionLink
|
|
|
|
.text( mw.message( 'multimediaviewer-permission-link-hide' ).text() );
|
2015-01-23 12:48:27 +00:00
|
|
|
} ).on( 'mmv-permission-shrink.mmv-mp', function () {
|
2014-12-28 21:19:42 +00:00
|
|
|
panel.$permissionLink
|
|
|
|
.text( mw.message( 'multimediaviewer-permission-link' ).text() );
|
2014-07-16 23:15:38 +00:00
|
|
|
} );
|
|
|
|
|
2015-01-23 12:48:27 +00:00
|
|
|
this.handleEvent( 'jq-fullscreen-change.lip', function () {
|
2014-07-16 23:15:38 +00:00
|
|
|
panel.hideTruncatedText();
|
|
|
|
} );
|
2014-02-13 20:50:05 +00:00
|
|
|
};
|
|
|
|
|
2015-01-23 12:48:27 +00:00
|
|
|
MPP.unattach = function () {
|
2014-11-13 08:55:12 +00:00
|
|
|
this.scroller.freezeHeight();
|
|
|
|
|
2014-11-19 10:46:39 +00:00
|
|
|
this.$title
|
|
|
|
.add( this.title.$ellipsis )
|
|
|
|
.add( this.$authorAndSource )
|
|
|
|
.add( this.creditField.$ellipsis )
|
|
|
|
.each( function () {
|
|
|
|
$( this ).tipsy( 'hide' ).tipsy( 'disable' );
|
2014-11-22 00:16:36 +00:00
|
|
|
} )
|
|
|
|
.off( 'click.mmv-mp' );
|
|
|
|
|
|
|
|
$( this.$container ).off( '.mmv-mp' );
|
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-02-13 20:50:05 +00:00
|
|
|
this.clearEvents();
|
|
|
|
};
|
|
|
|
|
2014-02-07 14:47:00 +00:00
|
|
|
MPP.empty = function () {
|
2014-11-11 23:44:53 +00:00
|
|
|
this.scroller.freezeHeight();
|
2014-05-05 21:44:27 +00:00
|
|
|
this.scroller.empty();
|
|
|
|
|
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-10-29 19:50:53 +00:00
|
|
|
this.$title.removeClass( 'error' );
|
|
|
|
this.title.empty();
|
|
|
|
this.creditField.empty();
|
2014-02-07 14:47:00 +00:00
|
|
|
|
2014-10-27 14:03:16 +00:00
|
|
|
this.$license.empty().prop( 'href', '#' );
|
|
|
|
this.$licenseLi.addClass( 'empty' );
|
|
|
|
this.$permissionLink.hide();
|
2015-01-15 03:14:20 +00:00
|
|
|
this.$restrictions.children().hide();
|
2014-10-27 14:03:16 +00:00
|
|
|
|
2015-01-13 02:51:46 +00:00
|
|
|
this.$filename.empty();
|
|
|
|
this.$filenamePrefix.empty();
|
|
|
|
this.$filenameLi.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-11-11 15:21:36 +00:00
|
|
|
|
|
|
|
this.$container.removeClass( 'mw-mmv-untruncated' );
|
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.initializeTitle();
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initializes the title elements.
|
|
|
|
*/
|
|
|
|
MPP.initializeTitle = function () {
|
|
|
|
this.$titlePara = $( '<p>' )
|
2014-03-31 21:33:12 +00:00
|
|
|
.addClass( 'mw-mmv-title-para' )
|
2014-10-27 14:03:16 +00:00
|
|
|
.appendTo( this.$aboveFold );
|
2014-02-07 14:47:00 +00:00
|
|
|
|
|
|
|
this.$title = $( '<span>' )
|
2014-03-27 06:05:47 +00:00
|
|
|
.addClass( 'mw-mmv-title' );
|
|
|
|
|
2014-10-29 19:50:53 +00:00
|
|
|
this.title = new mw.mmv.ui.TruncatableTextField( this.$titlePara, this.$title, {
|
|
|
|
styles: ['mw-mmv-title-small', 'mw-mmv-title-smaller']
|
|
|
|
} );
|
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-10-29 19:50:53 +00:00
|
|
|
|
|
|
|
this.$title.add( this.title.$ellipsis ).tipsy( {
|
|
|
|
delayIn: mw.config.get( 'wgMultimediaViewer' ).tooltipDelay,
|
|
|
|
gravity: this.correctEW( 'sw' )
|
|
|
|
} );
|
2014-02-07 14:47:00 +00:00
|
|
|
};
|
|
|
|
|
2014-10-27 14:03:16 +00:00
|
|
|
MPP.initializeButtons = function () {
|
|
|
|
this.buttons = new mw.mmv.ui.StripeButtons( this.$titleDiv );
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initializes the main body of metadata elements.
|
|
|
|
*/
|
|
|
|
MPP.initializeImageMetadata = function () {
|
2014-10-29 19:50:53 +00:00
|
|
|
this.$container.addClass( 'mw-mmv-ttf-ellipsis-container' );
|
|
|
|
|
2014-10-27 14:03:16 +00:00
|
|
|
this.$imageMetadata = $( '<div>' )
|
|
|
|
.addClass( 'mw-mmv-image-metadata' )
|
|
|
|
.appendTo( this.$container );
|
|
|
|
|
|
|
|
this.$imageMetadataLeft = $( '<div>' )
|
|
|
|
.addClass( 'mw-mmv-image-metadata-column mw-mmv-image-metadata-desc-column' )
|
|
|
|
.appendTo( this.$imageMetadata );
|
|
|
|
|
|
|
|
this.$imageMetadataRight = $( '<div>' )
|
|
|
|
.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 );
|
2014-11-13 17:48:14 +00:00
|
|
|
this.permission = new mw.mmv.ui.Permission( this.$imageMetadataLeft, this.scroller );
|
2014-10-27 14:03:16 +00:00
|
|
|
this.initializeImageLinks();
|
|
|
|
};
|
|
|
|
|
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' )
|
2014-10-29 13:36:08 +00:00
|
|
|
.appendTo( this.$imageMetadataLeft )
|
2015-02-15 06:18:55 +00:00
|
|
|
.on( 'click.mmv-mp', '.mw-mmv-credit-fallback', function () {
|
|
|
|
mw.mmv.actionLogger.log( 'author-page' );
|
2014-10-29 13:36:08 +00:00
|
|
|
} );
|
2014-07-03 19:12:59 +00:00
|
|
|
|
|
|
|
// we need an inline container for tipsy, otherwise it would be centered weirdly
|
|
|
|
this.$authorAndSource = $( '<span>' )
|
|
|
|
.addClass( 'mw-mmv-source-author' )
|
2015-02-15 06:18:55 +00:00
|
|
|
.on( 'click', '.mw-mmv-author a', function () {
|
|
|
|
mw.mmv.actionLogger.log( 'author-page' );
|
2014-10-27 14:03:16 +00:00
|
|
|
} )
|
2015-02-15 06:18:55 +00:00
|
|
|
.on( 'click', '.mw-mmv-source a', function () {
|
|
|
|
mw.mmv.actionLogger.log( 'source-page' );
|
2014-07-03 19:12:59 +00:00
|
|
|
} );
|
2014-03-27 06:05:47 +00:00
|
|
|
|
2014-10-27 14:03:16 +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-10-29 19:50:53 +00:00
|
|
|
{ styles: [] }
|
2014-03-27 06:05:47 +00:00
|
|
|
);
|
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-10-29 19:50:53 +00:00
|
|
|
|
2015-01-23 12:48:27 +00:00
|
|
|
this.$authorAndSource.add( this.creditField.$ellipsis ).tipsy( {
|
2014-10-29 19:50:53 +00:00
|
|
|
delayIn: mw.config.get( 'wgMultimediaViewer' ).tooltipDelay,
|
|
|
|
gravity: this.correctEW( 'sw' )
|
|
|
|
} );
|
2014-02-07 14:47:00 +00:00
|
|
|
};
|
|
|
|
|
2014-10-27 14:03:16 +00:00
|
|
|
/**
|
|
|
|
* Initializes the list of image metadata on the right side of the panel.
|
|
|
|
*/
|
|
|
|
MPP.initializeImageLinks = function () {
|
|
|
|
this.$imageLinkDiv = $( '<div>' )
|
|
|
|
.addClass( 'mw-mmv-image-links-div' )
|
|
|
|
.appendTo( this.$imageMetadataRight );
|
|
|
|
|
|
|
|
this.$imageLinks = $( '<ul>' )
|
|
|
|
.addClass( 'mw-mmv-image-links' )
|
|
|
|
.appendTo( this.$imageLinkDiv );
|
|
|
|
|
|
|
|
this.initializeLicense();
|
2015-01-13 02:51:46 +00:00
|
|
|
this.initializeFilename();
|
2014-10-27 14:03:16 +00:00
|
|
|
this.initializeUploader();
|
|
|
|
this.initializeDatetime();
|
|
|
|
this.initializeLocation();
|
|
|
|
};
|
|
|
|
|
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-10-27 14:03:16 +00:00
|
|
|
this.$licenseLi = $( '<li>' )
|
2015-01-23 12:48:27 +00:00
|
|
|
.addClass( 'mw-mmv-license-li empty' )
|
2014-10-27 14:03:16 +00:00
|
|
|
.appendTo( this.$imageLinks );
|
|
|
|
|
2014-02-07 14:47:00 +00:00
|
|
|
this.$license = $( '<a>' )
|
2014-10-27 14:03:16 +00:00
|
|
|
.addClass( 'mw-mmv-license' )
|
2014-02-07 14:47:00 +00:00
|
|
|
.prop( 'href', '#' )
|
2014-10-27 14:03:16 +00:00
|
|
|
.appendTo( this.$licenseLi )
|
2015-02-15 06:18:55 +00:00
|
|
|
.on( 'click', function () {
|
|
|
|
mw.mmv.actionLogger.log( 'license-page' );
|
2014-04-15 16:14:06 +00:00
|
|
|
} );
|
2014-02-14 00:36:10 +00:00
|
|
|
|
2015-01-15 03:14:20 +00:00
|
|
|
this.$restrictions = $( '<span>' )
|
2015-06-20 05:03:28 +00:00
|
|
|
.addClass( 'mw-mmv-restrictions' )
|
2015-01-15 03:14:20 +00:00
|
|
|
.appendTo( this.$licenseLi );
|
|
|
|
|
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() )
|
2014-10-27 14:03:16 +00:00
|
|
|
.appendTo( this.$licenseLi )
|
2014-02-26 01:20:34 +00:00
|
|
|
.hide()
|
2015-01-23 12:48:27 +00:00
|
|
|
.on( 'click', function () {
|
2014-12-28 21:19:42 +00:00
|
|
|
if ( panel.permission.isFullSize() ) {
|
|
|
|
panel.permission.shrink();
|
|
|
|
} else {
|
|
|
|
panel.permission.grow();
|
|
|
|
panel.scroller.toggle( 'up' );
|
|
|
|
}
|
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
|
|
|
};
|
|
|
|
|
2015-01-13 02:51:46 +00:00
|
|
|
/**
|
|
|
|
* Initializes the filename element.
|
|
|
|
*/
|
|
|
|
MPP.initializeFilename = function () {
|
|
|
|
this.$filenameLi = $( '<li>' )
|
|
|
|
.addClass( 'mw-mmv-filename-li empty' )
|
|
|
|
.appendTo( this.$imageLinks );
|
|
|
|
|
|
|
|
this.$filenamePrefix = $( '<span>' )
|
|
|
|
.addClass( 'mw-mmv-filename-prefix' )
|
|
|
|
.appendTo( this.$filenameLi );
|
|
|
|
|
|
|
|
this.$filename = $( '<span>' )
|
|
|
|
.addClass( 'mw-mmv-filename' )
|
|
|
|
.appendTo( this.$filenameLi );
|
|
|
|
};
|
|
|
|
|
2014-02-07 14:47:00 +00:00
|
|
|
/**
|
|
|
|
* 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 () {
|
|
|
|
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 )
|
2015-02-15 06:18:55 +00:00
|
|
|
.click( function () { mw.mmv.actionLogger.log( 'uploader-page' ); } );
|
2014-02-07 14:47:00 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initializes the geolocation element.
|
|
|
|
*/
|
|
|
|
MPP.initializeLocation = function () {
|
|
|
|
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 )
|
2015-02-15 06:18:55 +00:00
|
|
|
.click( function () { mw.mmv.actionLogger.log( 'location-page' ); } );
|
2014-02-07 14:47:00 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initializes two about links at the bottom of the panel.
|
|
|
|
*/
|
|
|
|
MPP.initializeAboutLinks = function () {
|
2015-02-15 06:18:55 +00:00
|
|
|
var separator = ' | ';
|
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' )
|
2015-02-15 06:18:55 +00:00
|
|
|
.click( function () { mw.mmv.actionLogger.log( 'about-page' ); } );
|
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' )
|
2015-02-15 06:18:55 +00:00
|
|
|
.click( function () { mw.mmv.actionLogger.log( 'discuss-page' ); } );
|
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' )
|
2015-02-15 06:18:55 +00:00
|
|
|
.click( function () { mw.mmv.actionLogger.log( 'help-page' ); } );
|
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(),
|
2015-10-22 04:31:47 +00:00
|
|
|
// articlePath is null when the imageinfo API query fails
|
|
|
|
userlink = ( typeof articlePath === 'string' )
|
|
|
|
? articlePath.replace( '$1', userpage ) : undefined;
|
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
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2014-10-29 14:46:30 +00:00
|
|
|
* Sets the image title at the top of the metadata panel.
|
|
|
|
* The title will be the first one available form the options below:
|
|
|
|
* - the image caption
|
|
|
|
* - the description from the filepage
|
|
|
|
* - the filename (without extension)
|
|
|
|
* @param {mw.mmv.LightboxImage} image
|
|
|
|
* @param {mw.mmv.model.Image} imageData
|
2014-02-07 14:47:00 +00:00
|
|
|
*/
|
2014-10-29 14:46:30 +00:00
|
|
|
MPP.setTitle = function ( image, imageData ) {
|
|
|
|
var title;
|
|
|
|
|
|
|
|
if ( image.caption ) {
|
|
|
|
title = image.caption;
|
|
|
|
} else if ( imageData.description ) {
|
|
|
|
title = imageData.description;
|
|
|
|
} else {
|
|
|
|
title = image.filePageTitle.getNameText();
|
|
|
|
}
|
|
|
|
|
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' );
|
|
|
|
};
|
|
|
|
|
2015-01-13 02:51:46 +00:00
|
|
|
/**
|
|
|
|
* Sets the file name in the panel.
|
|
|
|
* @param {string} filename The file name to set, without prefix
|
|
|
|
*/
|
|
|
|
MPP.setFileName = function ( filename ) {
|
|
|
|
this.$filenamePrefix.text( 'File:' );
|
|
|
|
this.$filename.text( filename );
|
|
|
|
|
|
|
|
this.$filenameLi.removeClass( 'empty' );
|
|
|
|
};
|
|
|
|
|
2014-03-27 06:05:47 +00:00
|
|
|
/**
|
2014-10-29 13:36:08 +00:00
|
|
|
* Set source and author.
|
2014-12-28 21:04:22 +00:00
|
|
|
* @param {string} attribution Custom attribution string
|
2014-03-27 06:05:47 +00:00
|
|
|
* @param {string} source With unsafe HTML
|
|
|
|
* @param {string} author With unsafe HTML
|
2014-11-27 07:19:24 +00:00
|
|
|
* @param {number} authorCount
|
2014-10-29 13:36:08 +00:00
|
|
|
* @param {string} filepageUrl URL of the file page (used when other data is not available)
|
2014-03-27 06:05:47 +00:00
|
|
|
*/
|
2014-12-28 21:04:22 +00:00
|
|
|
MPP.setCredit = function ( attribution, source, author, authorCount, filepageUrl ) {
|
2014-10-29 13:36:08 +00:00
|
|
|
// sanitization will be done by TruncatableTextField.set()
|
2014-12-28 21:04:22 +00:00
|
|
|
if ( attribution && ( authorCount <= 1 || !authorCount ) ) {
|
|
|
|
this.creditField.set( this.wrapAttribution( attribution ) );
|
|
|
|
} else if ( author && source ) {
|
2014-03-27 06:05:47 +00:00
|
|
|
this.creditField.set(
|
|
|
|
mw.message(
|
|
|
|
'multimediaviewer-credit',
|
2014-11-27 07:19:24 +00:00
|
|
|
this.wrapAuthor( author, authorCount, filepageUrl ),
|
2014-10-29 13:36:08 +00:00
|
|
|
this.wrapSource( source )
|
2014-03-27 06:05:47 +00:00
|
|
|
).plain()
|
|
|
|
);
|
|
|
|
} else if ( author ) {
|
2014-11-27 07:19:24 +00:00
|
|
|
this.creditField.set( this.wrapAuthor( author, authorCount, filepageUrl ) );
|
2014-03-27 06:05:47 +00:00
|
|
|
} else if ( source ) {
|
2014-10-29 13:36:08 +00:00
|
|
|
this.creditField.set( this.wrapSource( source ) );
|
|
|
|
} else {
|
|
|
|
this.creditField.set(
|
|
|
|
$( '<a>' )
|
|
|
|
.addClass( 'mw-mmv-credit-fallback' )
|
|
|
|
.prop( 'href', filepageUrl )
|
|
|
|
.text( mw.message( 'multimediaviewer-credit-fallback' ).plain() )
|
|
|
|
);
|
2014-03-27 06:05:47 +00:00
|
|
|
}
|
2014-05-31 00:18:12 +00:00
|
|
|
|
2014-10-29 13:36:08 +00:00
|
|
|
this.$credit.removeClass( 'empty' );
|
2014-03-27 06:05:47 +00:00
|
|
|
};
|
|
|
|
|
2014-02-07 14:47:00 +00:00
|
|
|
/**
|
2014-10-29 13:36:08 +00:00
|
|
|
* Wraps a source string it with MediaViewer styles
|
2014-02-07 14:47:00 +00:00
|
|
|
* @param {string} source Warning - unsafe HTML sometimes goes here
|
2014-10-29 13:36:08 +00:00
|
|
|
* @return {string} unsafe HTML
|
2014-02-07 14:47:00 +00:00
|
|
|
*/
|
2014-10-29 13:36:08 +00:00
|
|
|
MPP.wrapSource = function ( source ) {
|
|
|
|
return $( '<span>' )
|
|
|
|
.addClass( 'mw-mmv-source' )
|
|
|
|
.append( $.parseHTML( source ) )
|
|
|
|
.get( 0 ).outerHTML;
|
2014-02-07 14:47:00 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2014-10-29 13:36:08 +00:00
|
|
|
* Wraps an author string with MediaViewer styles
|
2014-02-07 14:47:00 +00:00
|
|
|
* @param {string} author Warning - unsafe HTML sometimes goes here
|
2014-11-27 07:19:24 +00:00
|
|
|
* @param {number} authorCount
|
|
|
|
* @param {string} filepageUrl URL of the file page (used when some author data is not available)
|
2014-10-29 13:36:08 +00:00
|
|
|
* @return {string} unsafe HTML
|
2014-02-07 14:47:00 +00:00
|
|
|
*/
|
2014-11-27 07:19:24 +00:00
|
|
|
MPP.wrapAuthor = function ( author, authorCount, filepageUrl ) {
|
2014-12-02 22:49:29 +00:00
|
|
|
var moreText,
|
|
|
|
$wrapper = $( '<span>' );
|
2014-11-27 07:19:24 +00:00
|
|
|
|
2014-12-02 22:49:29 +00:00
|
|
|
$wrapper.addClass( 'mw-mmv-author' );
|
2014-11-27 07:19:24 +00:00
|
|
|
|
|
|
|
if ( authorCount > 1 ) {
|
2014-12-02 22:49:29 +00:00
|
|
|
moreText = this.htmlUtils.jqueryToHtml(
|
2014-11-27 07:19:24 +00:00
|
|
|
$( '<a>' )
|
|
|
|
.addClass( 'mw-mmv-more-authors' )
|
|
|
|
.text( mw.message( 'multimediaviewer-multiple-authors', authorCount - 1 ).text() )
|
|
|
|
.attr( 'href', filepageUrl )
|
|
|
|
);
|
2014-12-02 22:49:29 +00:00
|
|
|
$wrapper.append( mw.message( 'multimediaviewer-multiple-authors-combine', author, moreText ).text() );
|
|
|
|
} else {
|
|
|
|
$wrapper.append( author );
|
2014-11-27 07:19:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return $wrapper.get( 0 ).outerHTML;
|
2014-02-07 14:47:00 +00:00
|
|
|
};
|
|
|
|
|
2014-12-28 21:04:22 +00:00
|
|
|
/**
|
|
|
|
* Wraps an attribution string with MediaViewer styles
|
|
|
|
* @param {string} attribution Warning - unsafe HTML sometimes goes here
|
|
|
|
* @return {string} unsafe HTML
|
|
|
|
*/
|
|
|
|
MPP.wrapAttribution = function ( attribution ) {
|
|
|
|
return $( '<span>' )
|
|
|
|
.addClass( 'mw-mmv-author' )
|
|
|
|
.addClass( 'mw-mmv-source' )
|
|
|
|
.append( $.parseHTML( attribution ) )
|
|
|
|
.get( 0 ).outerHTML;
|
|
|
|
};
|
|
|
|
|
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-10-29 12:05:29 +00:00
|
|
|
var shortName, url, isCc, isPd;
|
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-10-29 12:05:29 +00:00
|
|
|
isPd = license.isPd();
|
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;
|
2014-10-29 12:05:29 +00:00
|
|
|
isCc = isPd = 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-19 00:29:04 +00:00
|
|
|
.prop( 'href', url )
|
|
|
|
.prop( 'target', license && license.deedUrl ? '_blank' : '' );
|
2014-02-07 14:47:00 +00:00
|
|
|
|
2014-10-27 14:03:16 +00:00
|
|
|
this.$licenseLi
|
|
|
|
.toggleClass( 'cc-license', isCc )
|
2014-10-29 12:05:29 +00:00
|
|
|
.toggleClass( 'pd-license', isPd )
|
2014-10-27 14:03:16 +00:00
|
|
|
.removeClass( 'empty' );
|
2014-02-07 14:47:00 +00:00
|
|
|
};
|
|
|
|
|
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 );
|
|
|
|
};
|
|
|
|
|
2015-01-15 03:14:20 +00:00
|
|
|
/**
|
|
|
|
* Sets any special restrictions that should be displayed.
|
|
|
|
* @param {string[]} restrictions Array of restrictions
|
|
|
|
*/
|
|
|
|
MPP.setRestrictions = function ( restrictions ) {
|
2015-06-20 05:03:28 +00:00
|
|
|
var panel = this; // Access this inside $.each()
|
|
|
|
var restrictionsSet = {};
|
|
|
|
var showDefault = false;
|
|
|
|
var validRestrictions = 0;
|
|
|
|
$.each( restrictions, function( index, value ) {
|
|
|
|
if ( !mw.message( 'multimediaviewer-restriction-' + value ).exists() || value === 'default' || index + 1 > MetadataPanel.MAX_RESTRICT ) {
|
|
|
|
showDefault = true; // If the restriction isn't defined or there are more than MAX_RESTRICT of them, show a generic symbol at the end
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if( restrictionsSet[value] ) {
|
|
|
|
return; // Only show one of each symbol
|
|
|
|
} else {
|
|
|
|
restrictionsSet[value] = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
panel.$restrictions.append( panel.createRestriction( value ) );
|
|
|
|
validRestrictions++; // See how many defined restrictions are added so we know which default i18n msg to use
|
|
|
|
} );
|
|
|
|
|
|
|
|
if ( showDefault ) {
|
|
|
|
if ( validRestrictions ) {
|
|
|
|
panel.$restrictions.append( panel.createRestriction( 'default-and-others' ) );
|
|
|
|
} else {
|
|
|
|
panel.$restrictions.append( panel.createRestriction( 'default' ) );
|
|
|
|
}
|
2015-01-15 03:14:20 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-06-20 05:03:28 +00:00
|
|
|
/**
|
|
|
|
* Helper function that generates restriction labels
|
|
|
|
* @param {string} type Restriction type
|
|
|
|
* @return {jQuery} jQuery object of label
|
|
|
|
*/
|
|
|
|
MPP.createRestriction = function ( type ) {
|
|
|
|
var $label = $( '<span>' )
|
|
|
|
.addClass( 'mw-mmv-label mw-mmv-restriction-label' )
|
|
|
|
.prop( 'title', mw.message( 'multimediaviewer-restriction-' + type ).text() )
|
|
|
|
.tipsy( {
|
|
|
|
delay: mw.config.get( 'wgMultimediaViewer' ).tooltipDelay,
|
|
|
|
gravity: this.correctEW( 'se' )
|
|
|
|
} );
|
|
|
|
|
|
|
|
$( '<span>' )
|
|
|
|
.addClass( 'mw-mmv-restriction-label-inner mw-mmv-restriction-' +
|
|
|
|
( type === 'default-and-others' ? 'default' : type ) )
|
|
|
|
.text( mw.message( 'multimediaviewer-restriction-' + type ).text() )
|
|
|
|
.appendTo( $label );
|
|
|
|
|
|
|
|
return $label;
|
|
|
|
};
|
|
|
|
|
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()
|
|
|
|
);
|
|
|
|
|
2015-01-23 12:48:27 +00:00
|
|
|
$.each( mw.language.data, function ( key, value ) {
|
2014-02-07 14:47:00 +00:00
|
|
|
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-10-29 14:46:30 +00:00
|
|
|
var panel = this;
|
2014-02-07 14:47:00 +00:00
|
|
|
|
2014-09-05 00:45:36 +00:00
|
|
|
mw.mmv.attributionLogger.logAttribution( imageData );
|
|
|
|
|
2014-02-07 14:47:00 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2015-01-13 02:51:46 +00:00
|
|
|
this.setFileName( imageData.title.getMainText() );
|
|
|
|
|
2014-10-29 19:50:53 +00:00
|
|
|
// these handle text truncation and should be called when everything that can push text down
|
|
|
|
// (e.g. floated buttons) has already been laid out
|
|
|
|
this.setTitle( image, imageData );
|
2014-12-28 21:04:22 +00:00
|
|
|
this.setCredit( imageData.attribution, imageData.source, imageData.author, imageData.authorCount, imageData.descriptionUrl );
|
2014-10-29 19:50:53 +00:00
|
|
|
|
2014-02-14 00:36:10 +00:00
|
|
|
if ( imageData.permission ) {
|
|
|
|
this.setPermission( imageData.permission );
|
|
|
|
}
|
|
|
|
|
2015-01-15 03:14:20 +00:00
|
|
|
if ( imageData.restrictions ) {
|
|
|
|
this.setRestrictions( imageData.restrictions );
|
|
|
|
}
|
|
|
|
|
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-11-11 23:44:53 +00:00
|
|
|
|
2014-11-11 15:21:36 +00:00
|
|
|
this.resetTruncatedText();
|
2014-11-22 00:16:36 +00:00
|
|
|
this.scroller.unfreezeHeight();
|
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
|
2015-01-13 21:07:37 +00:00
|
|
|
* @param {string} title image title
|
|
|
|
* @param {string} error error message
|
2014-03-01 01:10:51 +00:00
|
|
|
*/
|
2015-01-13 21:07:37 +00:00
|
|
|
MPP.showError = function ( title, error ) {
|
|
|
|
this.$credit.text( mw.message( 'multimediaviewer-metadata-error', error ).text() );
|
|
|
|
this.$title.html( title );
|
2014-03-01 01:10:51 +00:00
|
|
|
};
|
|
|
|
|
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
|
|
|
/**
|
|
|
|
* Shows truncated text in the title and credit (this also rearranges the layout a bit).
|
|
|
|
*/
|
2014-11-11 15:21:36 +00:00
|
|
|
MPP.revealTruncatedText = function () {
|
2014-07-16 23:15:38 +00:00
|
|
|
if ( this.$container.hasClass( 'mw-mmv-untruncated' ) ) {
|
|
|
|
return;
|
|
|
|
}
|
2014-07-03 19:12:59 +00:00
|
|
|
this.$container.addClass( 'mw-mmv-untruncated' );
|
|
|
|
this.title.grow();
|
|
|
|
this.creditField.grow();
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Undoes changes made by revealTruncatedText().
|
|
|
|
*/
|
|
|
|
MPP.hideTruncatedText = function () {
|
2014-07-16 23:15:38 +00:00
|
|
|
if ( !this.$container.hasClass( 'mw-mmv-untruncated' ) ) {
|
|
|
|
return;
|
|
|
|
}
|
2014-07-03 19:12:59 +00:00
|
|
|
this.title.shrink();
|
|
|
|
this.creditField.shrink();
|
|
|
|
this.$container.removeClass( 'mw-mmv-untruncated' );
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2014-11-11 15:21:36 +00:00
|
|
|
* Hide or reveal truncated text based on whether the panel is open. This is normally handled by
|
|
|
|
* MetadataPanelScroller, but when the panel is reset (e.g. on a prev/next event) sometimes the panel position can change without a panel , such as on a
|
|
|
|
* prev/next event; in such cases this function has to be called.
|
2014-07-03 19:12:59 +00:00
|
|
|
*/
|
2014-11-11 15:21:36 +00:00
|
|
|
MPP.resetTruncatedText = function () {
|
|
|
|
if ( this.scroller.panelIsOpen() ) {
|
|
|
|
this.revealTruncatedText();
|
|
|
|
} else {
|
|
|
|
this.hideTruncatedText();
|
|
|
|
}
|
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 ) );
|