/* * 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 . */ const EmbedFileFormatter = require( './mmv.EmbedFileFormatter.js' ); const Utils = require( './mmv.ui.utils.js' ); const { UiElement } = require( 'mmv' ); /** * UI component that provides functionality to download the media asset displayed. */ class DownloadPane extends UiElement { /** * @param {jQuery} $container */ constructor( $container ) { super( $container ); this.formatter = new EmbedFileFormatter(); this.createDownloadSection( this.$container ); this.createAttributionButton( this.$container ); /** @property {ImageModel|null} Image the download button currently points to. */ this.image = null; } /** * Creates dialog download section. * * @param {jQuery} $container */ createDownloadSection( $container ) { const $header = $( '
' ) .addClass( 'cdx-dialog__header' ) .appendTo( $container ); $( '
' ) .addClass( 'cdx-dialog__header__title' ) .text( mw.msg( 'multimediaviewer-download-link' ) ) .appendTo( $header ); const $body = $( '
' ) .addClass( 'cdx-dialog__body mw-mmv-pt-0' ) .appendTo( $container ); this.$downloadArea = $( '
' ) .addClass( 'mw-mmv-flex mw-mmv-gap-50' ) .appendTo( $body ); this.createSizePulldownMenu( this.$downloadArea ); this.createDownloadButton( this.$downloadArea ); const $p = $( '

' ).addClass( 'mw-mmv-mt-75' ).appendTo( $body ); this.createPreviewLink( $p ); } /** * 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 */ createDownloadButton( $container ) { this.$downloadButton = $( '' ) .attr( 'target', '_blank' ) .attr( 'download', '' ) .addClass( 'cdx-button cdx-button--weight-primary cdx-button--action-progressive cdx-button--fake-button cdx-button--fake-button--enabled' ) .html( '' + mw.msg( 'multimediaviewer-download' ) ) .appendTo( $container ); } /** * Creates pulldown menu to select image sizes. * * @param {jQuery} $container */ createSizePulldownMenu( $container ) { this.$downloadSizeMenu = Utils.createSelectMenu( [ 'original', 'small', 'medium', 'large', 'xl' ], 'original' ).appendTo( $container ); } /** * Creates preview link. * * @param {jQuery} $container */ createPreviewLink( $container ) { this.$previewLink = $( '' ) .attr( 'target', '_blank' ) .addClass( 'cdx-docs-link' ) .html( mw.msg( 'multimediaviewer-download-preview-link-title' ) ) .appendTo( $container ); } createAttributionButton( $container ) { [ this.$attributionInput, this.$attributionInputDiv ] = Utils.createInputWithCopy( mw.msg( 'multimediaviewer-download-attribution-copy' ), '' ); const $header = $( '

' ) .addClass( 'cdx-dialog__header' ) .appendTo( $container ); $( '

' ) .addClass( 'cdx-dialog__header__title' ) .text( mw.msg( 'multimediaviewer-download-attribution' ) ) .appendTo( $header ); this.$attributionHowHeader = $( '

' ) .addClass( 'mw-mmv-mb-75' ) .text( mw.msg( 'multimediaviewer-download-attribution-cta-header' ) ); const $attributionTabs = $( '

' ).addClass( 'cdx-tabs' ); const $attributionTabsHeader = $( '
' ).addClass( 'cdx-tabs__header' ).appendTo( $attributionTabs ); this.$attributionTabsList = $( '
' ).addClass( 'cdx-tabs__list' ).attr( 'role', 'tablist' ).appendTo( $attributionTabsHeader ); [ 'plain', 'html' ].forEach( ( name ) => $( '