/* * 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 the user html/wikitext snippets needed to share * and/or embed a media asset. */ class Embed extends UiElement { /** * @param {jQuery} $container */ constructor( $container ) { super( $container ); /** * Formatter converting image data into formats needed for output * * @property {EmbedFileFormatter} */ this.formatter = new EmbedFileFormatter(); Utils.createHeader( mw.msg( 'multimediaviewer-embed-tab' ) ) .appendTo( $container ); const $body = $( '
' ) .addClass( 'cdx-dialog__body mw-mmv-pt-0 mw-mmv-pb-150' ) .appendTo( $container ); this.createSnippetSelectionButtons( $body ); this.createSizePulldownMenus( $body ); this.createSnippetTextAreas( $body ); } /** * Creates text areas for html and wikitext snippets. * * @param {jQuery} $container */ createSnippetTextAreas( $container ) { [ this.$embedTextHtml, this.$embedTextHtmlDiv ] = Utils.createInputWithCopy( mw.msg( 'multimediaviewer-reuse-copy-embed' ), mw.msg( 'multimediaviewer-reuse-loading-placeholder' ) ); this.$embedTextHtml.attr( 'title', mw.msg( 'multimediaviewer-embed-explanation' ) ); [ this.$embedTextWikitext, this.$embedTextWikitextDiv ] = Utils.createInputWithCopy( mw.msg( 'multimediaviewer-reuse-copy-embed' ), mw.msg( 'multimediaviewer-reuse-loading-placeholder' ) ); this.$embedTextWikitext.attr( 'title', mw.msg( 'multimediaviewer-embed-explanation' ) ); $container.append( this.$embedTextHtmlDiv, this.$embedTextWikitextDiv ); } /** * Creates snippet selection buttons. * * @param {jQuery} $container */ createSnippetSelectionButtons( $container ) { const $embedSwitch = $( '
' ).addClass( 'cdx-tabs mw-mmv-mb-75' ).appendTo( $container ); const $embedSwitchHeader = $( '
' ).addClass( 'cdx-tabs__header' ).appendTo( $embedSwitch ); this.$embedSwitchList = $( '
' ).addClass( 'cdx-tabs__list' ).attr( 'role', 'tablist' ).appendTo( $embedSwitchHeader ); [ 'wikitext', 'html' ].forEach( ( name ) => $( '