2014-03-31 16:08:02 +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/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
( function ( mw, $, oo ) {
|
|
|
|
// Shortcut for prototype later
|
|
|
|
var DP;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* UI component that provides functionality to download the media asset displayed.
|
|
|
|
*
|
2014-09-16 20:33:05 +00:00
|
|
|
* @class mw.mmv.ui.download.Pane
|
|
|
|
* @extends mw.mmv.ui.Element
|
2014-03-31 16:08:02 +00:00
|
|
|
* @constructor
|
|
|
|
* @param {jQuery} $container
|
|
|
|
*/
|
2014-09-16 20:33:05 +00:00
|
|
|
function Pane( $container ) {
|
|
|
|
mw.mmv.ui.Element.call( this, $container );
|
2014-03-31 16:08:02 +00:00
|
|
|
|
2014-09-16 20:33:05 +00:00
|
|
|
/** @property {mw.mmv.ui.Utils} utils - */
|
|
|
|
this.utils = new mw.mmv.ui.Utils();
|
2014-03-31 16:08:02 +00:00
|
|
|
|
2014-09-16 20:33:05 +00:00
|
|
|
this.$pane = $( '<div>' )
|
|
|
|
.addClass( 'mw-mmv-download-pane' )
|
|
|
|
.appendTo( this.$container );
|
2014-03-31 16:08:02 +00:00
|
|
|
|
2014-09-16 20:33:05 +00:00
|
|
|
this.$downloadArea = $( '<div>' )
|
|
|
|
.addClass( 'mw-mmv-download-area' )
|
|
|
|
.appendTo( this.$pane );
|
|
|
|
|
|
|
|
this.createDownloadButton( this.$downloadArea );
|
|
|
|
this.createSizePulldownMenu( this.$downloadArea );
|
|
|
|
this.createPreviewLink( this.$downloadArea );
|
2014-04-02 02:22:16 +00:00
|
|
|
|
2014-06-12 23:59:06 +00:00
|
|
|
this.formatter = new mw.mmv.EmbedFileFormatter();
|
|
|
|
this.currentAttrView = 'plain';
|
|
|
|
this.createAttributionButton( this.$pane );
|
|
|
|
|
2014-04-02 02:22:16 +00:00
|
|
|
/**
|
|
|
|
* Default item for the size menu.
|
2014-11-17 22:18:23 +00:00
|
|
|
* @property {OO.ui.MenuOptionWidget}
|
2014-04-02 02:22:16 +00:00
|
|
|
*/
|
2014-04-08 23:01:02 +00:00
|
|
|
this.defaultItem = this.downloadSizeMenu.getMenu().getSelectedItem();
|
2014-04-21 17:17:11 +00:00
|
|
|
|
|
|
|
/** @property {mw.mmv.model.Image|null} Image the download button currently points to. */
|
|
|
|
this.image = null;
|
2014-03-31 16:08:02 +00:00
|
|
|
}
|
2014-09-16 20:33:05 +00:00
|
|
|
oo.inheritClass( Pane, mw.mmv.ui.Element );
|
|
|
|
DP = Pane.prototype;
|
2014-03-31 16:08:02 +00:00
|
|
|
|
2014-12-07 08:09:04 +00:00
|
|
|
/**
|
|
|
|
* @event mmv-download-cta-open
|
|
|
|
* Fired when the attribution call to action panel is clicked.
|
|
|
|
*/
|
|
|
|
/**
|
|
|
|
* @event mmv-download-cta-close
|
|
|
|
* Fired when the attribution area is closed.
|
|
|
|
*/
|
|
|
|
|
2014-03-31 16:08:02 +00:00
|
|
|
/**
|
|
|
|
* Creates download split button. It is a link with the "download" property set plus an
|
|
|
|
* arrow that allows the user to select the image size desired. The "download" property
|
|
|
|
* triggers native browser downloading in browsers that support it. The fallback is the
|
|
|
|
* 'download' parameter which instructs the server to send the right headers so the browser
|
|
|
|
* downloads the file instead of just displaying it. If all this fails, the image will appear
|
|
|
|
* in another window/tab.
|
|
|
|
*
|
|
|
|
* @param {jQuery} $container
|
|
|
|
*/
|
|
|
|
DP.createDownloadButton = function ( $container ) {
|
2018-01-17 08:16:54 +00:00
|
|
|
// TODO: Use OOUI progressive button widget instead
|
2014-03-31 16:08:02 +00:00
|
|
|
this.$downloadButton = $( '<a>' )
|
|
|
|
.attr( 'target', '_blank' )
|
2014-04-04 01:34:31 +00:00
|
|
|
.attr( 'download', '' )
|
2016-05-25 18:32:40 +00:00
|
|
|
.addClass( 'mw-ui-button mw-ui-progressive mw-mmv-download-go-button' )
|
2015-02-15 06:18:55 +00:00
|
|
|
.click( function () {
|
|
|
|
mw.mmv.actionLogger.log( 'download' );
|
2014-09-05 12:52:53 +00:00
|
|
|
} );
|
2014-03-31 16:08:02 +00:00
|
|
|
|
|
|
|
this.$selectionArrow = $( '<span>' )
|
2016-05-25 18:32:40 +00:00
|
|
|
.addClass( 'mw-ui-button mw-ui-progressive mw-mmv-download-select-menu' )
|
2014-03-31 16:08:02 +00:00
|
|
|
.append(
|
|
|
|
$( '<span>' )
|
2014-07-01 00:38:44 +00:00
|
|
|
.addClass( 'mw-mmv-download-image-size-name' )
|
2014-03-31 16:08:02 +00:00
|
|
|
.html( ' ' )
|
|
|
|
)
|
|
|
|
.append(
|
|
|
|
$( '<span>' )
|
2014-07-01 00:38:44 +00:00
|
|
|
.addClass( 'mw-mmv-download-image-size' )
|
2014-03-31 16:08:02 +00:00
|
|
|
.html( ' ' )
|
|
|
|
);
|
|
|
|
|
|
|
|
$container
|
|
|
|
.append( this.$downloadButton )
|
|
|
|
.append( this.$selectionArrow );
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates pulldown menu to select image sizes.
|
|
|
|
*
|
|
|
|
* @param {jQuery} $container
|
|
|
|
*/
|
|
|
|
DP.createSizePulldownMenu = function ( $container ) {
|
|
|
|
this.downloadSizeMenu = this.utils.createPulldownMenu(
|
2017-10-31 17:49:29 +00:00
|
|
|
[ 'original', 'small', 'medium', 'large' ],
|
|
|
|
[ 'mw-mmv-download-size' ],
|
|
|
|
'original'
|
|
|
|
);
|
2014-03-31 16:08:02 +00:00
|
|
|
|
2015-01-23 12:48:27 +00:00
|
|
|
this.downloadSizeMenu.getMenu().on( 'select', function ( item ) {
|
2014-09-05 12:52:53 +00:00
|
|
|
mw.mmv.actionLogger.log( 'download-select-menu-' + item.data.name );
|
2014-09-17 20:33:56 +00:00
|
|
|
} );
|
2014-09-05 12:52:53 +00:00
|
|
|
|
2014-03-31 16:08:02 +00:00
|
|
|
$container.append( this.downloadSizeMenu.$element );
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates preview link.
|
|
|
|
*
|
|
|
|
* @param {jQuery} $container
|
|
|
|
*/
|
|
|
|
DP.createPreviewLink = function ( $container ) {
|
|
|
|
this.$previewLink = $( '<a>' )
|
|
|
|
.attr( 'target', '_blank' )
|
2014-07-01 00:38:44 +00:00
|
|
|
.addClass( 'mw-mmv-download-preview-link' )
|
2014-03-31 16:08:02 +00:00
|
|
|
.text( mw.message( 'multimediaviewer-download-preview-link-title' ).text() )
|
2014-09-05 12:52:53 +00:00
|
|
|
.appendTo( $container )
|
2015-02-15 06:18:55 +00:00
|
|
|
.click( function () {
|
|
|
|
mw.mmv.actionLogger.log( 'download-view-in-browser' );
|
2014-09-05 12:52:53 +00:00
|
|
|
} );
|
2014-03-31 16:08:02 +00:00
|
|
|
};
|
|
|
|
|
2014-06-12 23:59:06 +00:00
|
|
|
DP.createAttributionButton = function ( $container ) {
|
|
|
|
var dl = this,
|
|
|
|
attributionInput = new oo.ui.TextInputWidget( {
|
|
|
|
classes: [ 'mw-mmv-download-attr-input' ],
|
2016-07-18 13:49:27 +00:00
|
|
|
readOnly: true
|
2014-06-12 23:59:06 +00:00
|
|
|
} ),
|
|
|
|
attributionSwitch = new oo.ui.ButtonSelectWidget( {
|
|
|
|
classes: [ 'mw-mmv-download-attr-select' ]
|
|
|
|
} ),
|
2014-11-22 00:01:29 +00:00
|
|
|
plainOption = new oo.ui.ButtonOptionWidget( {
|
|
|
|
data: 'plain',
|
2014-06-12 23:59:06 +00:00
|
|
|
label: mw.message( 'multimediaviewer-attr-plain' ).text()
|
|
|
|
} ),
|
2014-11-22 00:01:29 +00:00
|
|
|
htmlOption = new oo.ui.ButtonOptionWidget( {
|
|
|
|
data: 'html',
|
2014-06-12 23:59:06 +00:00
|
|
|
label: mw.message( 'multimediaviewer-attr-html' ).text()
|
|
|
|
} );
|
|
|
|
|
|
|
|
attributionSwitch.addItems( [
|
2014-11-22 00:01:29 +00:00
|
|
|
plainOption,
|
|
|
|
htmlOption
|
|
|
|
] );
|
2014-06-12 23:59:06 +00:00
|
|
|
|
|
|
|
attributionSwitch.selectItem( plainOption );
|
|
|
|
|
|
|
|
attributionSwitch.on( 'select', function ( selection ) {
|
|
|
|
dl.selectAttribution( selection.getData() );
|
|
|
|
|
|
|
|
dl.attributionInput.$element.find( 'input' ).focus();
|
|
|
|
} );
|
|
|
|
|
|
|
|
this.$attributionSection = $( '<div>' )
|
|
|
|
.addClass( 'mw-mmv-download-attribution mw-mmv-download-attribution-collapsed' )
|
2014-10-03 12:55:42 +00:00
|
|
|
.appendTo( $container )
|
|
|
|
.click( function () {
|
|
|
|
if ( dl.$attributionSection.hasClass( 'mw-mmv-download-attribution-collapsed' ) ) {
|
2014-12-07 08:09:04 +00:00
|
|
|
dl.$container.trigger( 'mmv-download-cta-open' );
|
2014-10-03 12:55:42 +00:00
|
|
|
dl.$attributionSection.removeClass( 'mw-mmv-download-attribution-collapsed' );
|
|
|
|
dl.attributionInput.$element.find( 'input' ).focus();
|
|
|
|
}
|
|
|
|
} );
|
2014-06-12 23:59:06 +00:00
|
|
|
|
2014-11-24 22:09:03 +00:00
|
|
|
this.$attributionCtaHeader = $( '<p>' )
|
|
|
|
.addClass( 'mw-mmv-download-attribution-cta-header' )
|
|
|
|
.text( mw.message( 'multimediaviewer-download-attribution-cta-header' ).text() );
|
2014-06-12 23:59:06 +00:00
|
|
|
this.$attributionCta = $( '<div>' )
|
|
|
|
.addClass( 'mw-mmv-download-attribution-cta' )
|
|
|
|
.append(
|
2014-11-24 22:09:03 +00:00
|
|
|
this.$attributionCtaHeader,
|
|
|
|
$( '<p>' )
|
2014-07-01 16:56:15 +00:00
|
|
|
.addClass( 'mw-mmv-download-attribution-cta-invite' )
|
2014-06-12 23:59:06 +00:00
|
|
|
.text( mw.message( 'multimediaviewer-download-attribution-cta' ).text() )
|
2014-11-24 22:09:03 +00:00
|
|
|
)
|
|
|
|
.appendTo( this.$attributionSection );
|
2016-12-28 16:32:28 +00:00
|
|
|
this.attributionInput = attributionInput;
|
|
|
|
this.$attributionCopy = this.$copyButton = $( '<a>' )
|
2017-10-31 17:49:29 +00:00
|
|
|
.addClass( 'mw-mmv-dialog-copy' )
|
|
|
|
.click( function () {
|
|
|
|
// Select the text, and then try to copy the text.
|
|
|
|
// If the copy fails or is not supported, continue as if nothing had happened.
|
|
|
|
dl.attributionInput.select();
|
|
|
|
try {
|
|
|
|
if ( document.queryCommandSupported &&
|
|
|
|
document.queryCommandSupported( 'copy' ) ) {
|
|
|
|
document.execCommand( 'copy' );
|
2016-12-28 16:32:28 +00:00
|
|
|
}
|
2017-10-31 17:49:29 +00:00
|
|
|
} catch ( e ) {
|
|
|
|
// queryCommandSupported in Firefox pre-41 can throw errors when used with
|
|
|
|
// clipboard commands. We catch and ignore these and other copy-command-related
|
|
|
|
// errors here.
|
|
|
|
}
|
|
|
|
} )
|
|
|
|
.prop( 'title', mw.msg( 'multimediaviewer-download-attribution-copy' ) )
|
|
|
|
.tipsy( {
|
|
|
|
delayIn: mw.config.get( 'wgMultimediaViewer' ).tooltipDelay,
|
|
|
|
gravity: this.correctEW( 'se' )
|
|
|
|
} );
|
2014-06-12 23:59:06 +00:00
|
|
|
|
2014-11-24 22:09:03 +00:00
|
|
|
this.$attributionHowHeader = $( '<p>' )
|
|
|
|
.addClass( 'mw-mmv-download-attribution-how-header' )
|
|
|
|
.text( mw.message( 'multimediaviewer-download-attribution-cta-header' ).text() );
|
2014-06-12 23:59:06 +00:00
|
|
|
this.$attributionHow = $( '<div>' )
|
|
|
|
.addClass( 'mw-mmv-download-attribution-how' )
|
|
|
|
.append(
|
2014-11-24 22:09:03 +00:00
|
|
|
this.$attributionHowHeader,
|
2016-12-28 16:32:28 +00:00
|
|
|
this.attributionInput.$element,
|
|
|
|
this.$attributionCopy,
|
2014-11-24 22:09:03 +00:00
|
|
|
attributionSwitch.$element,
|
|
|
|
$( '<p>' )
|
2017-10-31 17:49:29 +00:00
|
|
|
.addClass( 'mw-mmv-download-attribution-close-button' )
|
|
|
|
.click( function ( e ) {
|
|
|
|
dl.$container.trigger( 'mmv-download-cta-close' );
|
|
|
|
dl.$attributionSection.addClass( 'mw-mmv-download-attribution-collapsed' );
|
|
|
|
e.stopPropagation();
|
|
|
|
} )
|
|
|
|
.text( ' ' )
|
2014-11-24 22:09:03 +00:00
|
|
|
)
|
2014-06-12 23:59:06 +00:00
|
|
|
.appendTo( this.$attributionSection );
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Selects the specified attribution type.
|
2016-07-18 13:49:27 +00:00
|
|
|
*
|
|
|
|
* @param {string} [name='plain'] The attribution type to use ('plain' or 'html')
|
2014-06-12 23:59:06 +00:00
|
|
|
*/
|
|
|
|
DP.selectAttribution = function ( name ) {
|
|
|
|
this.currentAttrView = name;
|
|
|
|
|
|
|
|
if ( this.currentAttrView === 'html' ) {
|
|
|
|
this.attributionInput.setValue( this.htmlCredit );
|
|
|
|
} else {
|
|
|
|
this.attributionInput.setValue( this.textCredit );
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-03-31 16:08:02 +00:00
|
|
|
/**
|
|
|
|
* Registers listeners.
|
|
|
|
*/
|
|
|
|
DP.attach = function () {
|
|
|
|
var download = this;
|
|
|
|
|
|
|
|
// Register handlers for switching between file sizes
|
2014-09-16 20:33:05 +00:00
|
|
|
this.downloadSizeMenu.getMenu().on( 'choose', function ( item ) {
|
|
|
|
download.handleSizeSwitch( item );
|
|
|
|
} );
|
2014-03-31 16:08:02 +00:00
|
|
|
this.$selectionArrow.on( 'click', function () {
|
2015-02-13 11:52:45 +00:00
|
|
|
download.downloadSizeMenu.getMenu().toggle();
|
2014-03-31 16:08:02 +00:00
|
|
|
} );
|
2014-06-12 23:59:06 +00:00
|
|
|
|
|
|
|
this.attributionInput.$element.find( 'input' )
|
|
|
|
.on( 'focus', this.selectAllOnEvent )
|
|
|
|
.on( 'mousedown click', this.onlyFocus );
|
2014-03-31 16:08:02 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Clears listeners.
|
|
|
|
*/
|
|
|
|
DP.unattach = function () {
|
2014-09-16 20:33:05 +00:00
|
|
|
mw.mmv.ui.Element.prototype.unattach.call( this );
|
2014-03-31 16:08:02 +00:00
|
|
|
|
2014-04-08 01:14:26 +00:00
|
|
|
this.downloadSizeMenu.getMenu().off( 'choose' );
|
2014-03-31 16:08:02 +00:00
|
|
|
this.$selectionArrow.off( 'click' );
|
2014-06-12 23:59:06 +00:00
|
|
|
|
|
|
|
this.attributionInput.$element.find( 'input' )
|
|
|
|
.off( 'focus mousedown click' );
|
2014-03-31 16:08:02 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handles size menu change events.
|
2014-04-02 02:22:16 +00:00
|
|
|
*
|
2014-11-17 22:18:23 +00:00
|
|
|
* @param {OO.ui.MenuOptionWidget} item
|
2014-03-31 16:08:02 +00:00
|
|
|
*/
|
|
|
|
DP.handleSizeSwitch = function ( item ) {
|
|
|
|
var download = this,
|
2014-04-19 01:28:30 +00:00
|
|
|
value = item.getData();
|
2014-03-31 16:08:02 +00:00
|
|
|
|
2014-04-21 17:17:11 +00:00
|
|
|
if ( value.name === 'original' && this.image !== null ) {
|
|
|
|
this.setDownloadUrl( this.image.url );
|
|
|
|
this.setButtonText( value.name, this.getExtensionFromUrl( this.image.url ),
|
2014-04-19 01:28:30 +00:00
|
|
|
value.width, value.height );
|
2014-04-21 17:17:11 +00:00
|
|
|
} else {
|
|
|
|
// Disable download while we get the image
|
|
|
|
this.$downloadButton.addClass( 'disabledLink' );
|
|
|
|
// Set a temporary message. It will be updated once we have the file type.
|
|
|
|
this.setButtonText( value.name, this.imageExtension, value.width, value.height );
|
|
|
|
|
|
|
|
this.utils.getThumbnailUrlPromise( value.width ).done( function ( thumbnail ) {
|
|
|
|
download.setDownloadUrl( thumbnail.url );
|
|
|
|
download.setButtonText( value.name, download.getExtensionFromUrl( thumbnail.url ),
|
|
|
|
value.width, value.height );
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the URL on the download button.
|
2016-07-18 13:49:27 +00:00
|
|
|
*
|
2014-04-21 17:17:11 +00:00
|
|
|
* @param {string} url
|
|
|
|
*/
|
|
|
|
DP.setDownloadUrl = function ( url ) {
|
|
|
|
this.$downloadButton.attr( 'href', url + '?download' );
|
|
|
|
this.$previewLink.attr( 'href', url );
|
|
|
|
|
|
|
|
// Re-enable download
|
|
|
|
this.$downloadButton.removeClass( 'disabledLink' );
|
2014-03-31 16:08:02 +00:00
|
|
|
};
|
|
|
|
|
2014-04-19 01:28:30 +00:00
|
|
|
/**
|
|
|
|
* Sets the text of the download button.
|
2016-07-18 13:49:27 +00:00
|
|
|
*
|
2014-04-19 01:28:30 +00:00
|
|
|
* @param {string} sizeClass A size class such as 'small'
|
|
|
|
* @param {string} extension file extension
|
|
|
|
* @param {number} width
|
|
|
|
* @param {number} height
|
|
|
|
*/
|
2015-01-23 12:48:27 +00:00
|
|
|
DP.setButtonText = function ( sizeClass, extension, width, height ) {
|
2014-04-19 01:28:30 +00:00
|
|
|
var sizeClasMessage, sizeMessage, dimensionMessage;
|
|
|
|
|
|
|
|
sizeClasMessage = mw.message( 'multimediaviewer-download-' + sizeClass + '-button-name' ).text();
|
|
|
|
dimensionMessage = mw.message( 'multimediaviewer-embed-dimensions', width, height ).text();
|
|
|
|
sizeMessage = mw.message( 'multimediaviewer-embed-dimensions-with-file-format',
|
|
|
|
dimensionMessage, extension ).text();
|
|
|
|
|
|
|
|
// Update button label and size strings to reflect new selected size
|
|
|
|
this.$downloadButton.html(
|
2016-07-18 13:49:27 +00:00
|
|
|
'<span class="mw-mmv-download-image-size-name">' + sizeClasMessage + '</span>' +
|
|
|
|
'<span class="mw-mmv-download-image-size">' + sizeMessage + '</span>'
|
2014-04-19 01:28:30 +00:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2014-06-12 23:59:06 +00:00
|
|
|
/**
|
|
|
|
* Sets the text in the attribution input element.
|
2016-07-18 13:49:27 +00:00
|
|
|
*
|
2014-06-12 23:59:06 +00:00
|
|
|
* @param {mw.mmv.model.EmbedFileInfo} embed
|
|
|
|
*/
|
|
|
|
DP.setAttributionText = function ( embed ) {
|
|
|
|
this.htmlCredit = this.formatter.getCreditHtml( embed );
|
|
|
|
this.textCredit = this.formatter.getCreditText( embed );
|
|
|
|
this.selectAttribution( this.currentAttrView );
|
|
|
|
};
|
|
|
|
|
2014-04-19 01:28:30 +00:00
|
|
|
/**
|
|
|
|
* Chops off the extension part of an URL.
|
2016-07-18 13:49:27 +00:00
|
|
|
*
|
2016-12-14 13:09:10 +00:00
|
|
|
* @param {string} url URL
|
|
|
|
* @return {string} Extension
|
2014-04-19 01:28:30 +00:00
|
|
|
*/
|
2015-01-23 12:48:27 +00:00
|
|
|
DP.getExtensionFromUrl = function ( url ) {
|
2014-04-19 01:28:30 +00:00
|
|
|
var urlParts = url.split( '.' );
|
2016-07-18 13:49:27 +00:00
|
|
|
return urlParts[ urlParts.length - 1 ];
|
2014-04-19 01:28:30 +00:00
|
|
|
};
|
|
|
|
|
2014-03-31 16:08:02 +00:00
|
|
|
/**
|
|
|
|
* Sets the data on the element.
|
|
|
|
*
|
|
|
|
* @param {mw.mmv.model.Image} image
|
2014-06-12 23:59:06 +00:00
|
|
|
* @param {mw.mmv.model.Repo} repo
|
2014-03-31 16:08:02 +00:00
|
|
|
*/
|
2014-06-12 23:59:06 +00:00
|
|
|
DP.set = function ( image, repo ) {
|
2014-11-24 22:09:03 +00:00
|
|
|
var attributionCtaMessage,
|
|
|
|
license = image && image.license,
|
|
|
|
sizeOptions = this.downloadSizeMenu.getMenu().getItems(),
|
2014-03-31 16:08:02 +00:00
|
|
|
sizes = this.utils.getPossibleImageSizesForHtml( image.width, image.height );
|
|
|
|
|
2014-04-21 17:17:11 +00:00
|
|
|
this.image = image;
|
|
|
|
|
2014-03-31 16:08:02 +00:00
|
|
|
this.utils.updateMenuOptions( sizes, sizeOptions );
|
|
|
|
|
|
|
|
this.downloadSizeMenu.$element.addClass( 'active' );
|
|
|
|
|
|
|
|
// Note: This extension will not be the real one for file types other than: png/gif/jpg/jpeg
|
|
|
|
this.imageExtension = image.title.getExtension().toLowerCase();
|
|
|
|
|
2014-04-02 02:22:16 +00:00
|
|
|
// Reset size menu to default item and update download button label now that we have the info
|
2014-04-08 01:14:26 +00:00
|
|
|
this.downloadSizeMenu.getMenu().chooseItem( this.defaultItem );
|
2014-06-12 23:59:06 +00:00
|
|
|
|
|
|
|
if ( image && repo ) {
|
|
|
|
this.setAttributionText( new mw.mmv.model.EmbedFileInfo( image, repo ) );
|
|
|
|
}
|
2014-11-24 22:09:03 +00:00
|
|
|
|
|
|
|
attributionCtaMessage = ( license && license.needsAttribution() ) ?
|
2016-12-14 13:09:10 +00:00
|
|
|
'multimediaviewer-download-attribution-cta-header' :
|
|
|
|
'multimediaviewer-download-optional-attribution-cta-header';
|
2014-11-24 22:09:03 +00:00
|
|
|
this.$attributionCtaHeader.text( mw.message( attributionCtaMessage ).text() );
|
|
|
|
this.$attributionHowHeader.text( mw.message( attributionCtaMessage ).text() );
|
2014-03-31 16:08:02 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
DP.empty = function () {
|
2014-07-15 22:02:05 +00:00
|
|
|
this.downloadSizeMenu.getMenu().toggle( false );
|
2014-03-31 16:08:02 +00:00
|
|
|
this.downloadSizeMenu.$element.removeClass( 'active' );
|
|
|
|
|
|
|
|
this.$downloadButton.attr( 'href', '' );
|
|
|
|
this.$previewLink.attr( 'href', '' );
|
|
|
|
this.imageExtension = undefined;
|
2014-04-21 17:17:11 +00:00
|
|
|
|
|
|
|
this.image = null;
|
2014-03-31 16:08:02 +00:00
|
|
|
};
|
|
|
|
|
2014-09-16 20:33:05 +00:00
|
|
|
mw.mmv.ui.download.Pane = Pane;
|
2014-03-31 16:08:02 +00:00
|
|
|
}( mediaWiki, jQuery, OO ) );
|