/* * 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, Utils } = require( 'mmv.ui.ondemandshareddependencies' ); const { UiElement } = require( 'mmv' ); ( function () { /** * 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.message( 'multimediaviewer-embed-tab' ).text() ) .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.message( 'multimediaviewer-reuse-copy-embed' ).text(), mw.message( 'multimediaviewer-reuse-loading-placeholder' ).text() ); this.$embedTextHtml.attr( 'title', mw.message( 'multimediaviewer-embed-explanation' ).text() ); [ this.$embedTextWikitext, this.$embedTextWikitextDiv ] = Utils.createInputWithCopy( mw.message( 'multimediaviewer-reuse-copy-embed' ).text(), mw.message( 'multimediaviewer-reuse-loading-placeholder' ).text() ); this.$embedTextWikitext.attr( 'title', mw.message( 'multimediaviewer-embed-explanation' ).text() ); $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 ) => $( '