/* * This file is part of the MediaWiki extension MultimediaViewer. * * MultimediaViewer is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 2 of the License, or * (at your option) any later version. * * MultimediaViewer is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with MultimediaViewer. If not, see . */ ( function () { // Shortcut for prototype later var DP; /** * UI component that provides functionality to download the media asset displayed. * * @class mw.mmv.ui.download.Pane * @extends mw.mmv.ui.Element * @constructor * @param {jQuery} $container */ function Pane( $container ) { mw.mmv.ui.Element.call( this, $container ); /** @property {mw.mmv.ui.Utils} utils - */ this.utils = new mw.mmv.ui.Utils(); this.$pane = $( '
' ) .addClass( 'mw-mmv-download-pane' ) .appendTo( this.$container ); this.$downloadArea = $( '
' ) .addClass( 'mw-mmv-download-area' ) .appendTo( this.$pane ); this.createDownloadButton( this.$downloadArea ); this.createSizePulldownMenu( this.$downloadArea ); this.createPreviewLink( this.$downloadArea ); this.formatter = new mw.mmv.EmbedFileFormatter(); this.currentAttrView = 'plain'; this.createAttributionButton( this.$pane ); /** * Default item for the size menu. * @property {OO.ui.MenuOptionWidget} */ this.defaultItem = this.downloadSizeMenu.getMenu().findSelectedItem(); /** @property {mw.mmv.model.Image|null} Image the download button currently points to. */ this.image = null; } OO.inheritClass( Pane, mw.mmv.ui.Element ); DP = Pane.prototype; /** * @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. */ /** * 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 ) { // TODO: Use OOUI progressive button widget instead this.$downloadButton = $( '' ) .attr( 'target', '_blank' ) .attr( 'download', '' ) .addClass( 'mw-ui-button mw-ui-progressive mw-mmv-download-go-button' ) .on( 'click', function () { mw.mmv.actionLogger.log( 'download' ); } ); this.$selectionArrow = $( '' ) .addClass( 'mw-ui-button mw-ui-progressive mw-mmv-download-select-menu' ) .append( $( '' ) .addClass( 'mw-mmv-download-image-size-name' ) .html( ' ' ) ) .append( $( '' ) .addClass( 'mw-mmv-download-image-size' ) .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( [ 'original', 'small', 'medium', 'large' ], [ 'mw-mmv-download-size' ], 'original' ); this.downloadSizeMenu.getMenu().on( 'select', function ( item ) { mw.mmv.actionLogger.log( 'download-select-menu-' + item.data.name ); } ); $container.append( this.downloadSizeMenu.$element ); }; /** * Creates preview link. * * @param {jQuery} $container */ DP.createPreviewLink = function ( $container ) { this.$previewLink = $( '' ) .attr( 'target', '_blank' ) .addClass( 'mw-mmv-download-preview-link' ) .text( mw.message( 'multimediaviewer-download-preview-link-title' ).text() ) .appendTo( $container ) .on( 'click', function () { mw.mmv.actionLogger.log( 'download-view-in-browser' ); } ); }; DP.createAttributionButton = function ( $container ) { var dl = this, attributionInput = new OO.ui.TextInputWidget( { classes: [ 'mw-mmv-download-attr-input' ], readOnly: true } ), attributionSwitch = new OO.ui.ButtonSelectWidget( { classes: [ 'mw-mmv-download-attr-select' ] } ), plainOption = new OO.ui.ButtonOptionWidget( { data: 'plain', label: mw.message( 'multimediaviewer-attr-plain' ).text() } ), htmlOption = new OO.ui.ButtonOptionWidget( { data: 'html', label: mw.message( 'multimediaviewer-attr-html' ).text() } ); attributionSwitch.addItems( [ plainOption, htmlOption ] ); attributionSwitch.selectItem( plainOption ); attributionSwitch.on( 'select', function ( selection ) { dl.selectAttribution( selection.getData() ); dl.attributionInput.$element.find( 'input' ).trigger( 'focus' ); } ); this.$attributionSection = $( '
' ) .addClass( 'mw-mmv-download-attribution mw-mmv-download-attribution-collapsed' ) .appendTo( $container ) .on( 'click', function () { if ( dl.$attributionSection.hasClass( 'mw-mmv-download-attribution-collapsed' ) ) { dl.$container.trigger( 'mmv-download-cta-open' ); dl.$attributionSection.removeClass( 'mw-mmv-download-attribution-collapsed' ); dl.attributionInput.$element.find( 'input' ).trigger( 'focus' ); } } ); this.$attributionCtaHeader = $( '

' ) .addClass( 'mw-mmv-download-attribution-cta-header' ) .text( mw.message( 'multimediaviewer-download-attribution-cta-header' ).text() ); this.$attributionCta = $( '

' ) .addClass( 'mw-mmv-download-attribution-cta' ) .append( this.$attributionCtaHeader, $( '

' ) .addClass( 'mw-mmv-download-attribution-cta-invite' ) .text( mw.message( 'multimediaviewer-download-attribution-cta' ).text() ) ) .appendTo( this.$attributionSection ); this.attributionInput = attributionInput; this.$attributionCopy = this.$copyButton = $( '