/* * 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 EP; /** * UI component that provides the user html/wikitext snippets needed to share * and/or embed a media asset. * * @class mw.mmv.ui.reuse.Embed * @extends mw.mmv.ui.reuse.Tab * @constructor * @param {jQuery} $container */ function Embed( $container ) { mw.mmv.ui.reuse.Tab.call( this, $container ); /** * Formatter converting image data into formats needed for output * * @property {mw.mmv.EmbedFileFormatter} */ this.formatter = new mw.mmv.EmbedFileFormatter(); /** @property {mw.mmv.ui.Utils} utils - */ this.utils = new mw.mmv.ui.Utils(); /** * Indicates whether or not the default option has been reset for both size menus. * * @property {boolean} */ this.isSizeMenuDefaultReset = false; this.$pane.addClass( 'mw-mmv-embed-pane' ); this.$pane.appendTo( this.$container ); this.createSnippetTextAreas( this.$pane ); this.$explanation = $( '
' ) .addClass( 'mw-mmv-shareembed-explanation mw-mmv-embed-explanation' ) .text( mw.message( 'multimediaviewer-embed-explanation' ).text() ) .appendTo( this.$pane ); this.createSnippetSelectionButtons( this.$pane ); this.createSizePulldownMenus( this.$pane ); /** * Currently selected embed snippet. * * @property {jQuery} */ this.$currentMainEmbedText = mw.user.isAnon() ? this.embedTextHtml.$element : this.embedTextWikitext.$element; /** * Default item for the html size menu. * * @property {OO.ui.MenuOptionWidget} */ this.defaultHtmlItem = this.embedSizeSwitchHtml.getMenu().findSelectedItem(); /** * Default item for the wikitext size menu. * * @property {OO.ui.MenuOptionWidget} */ this.defaultWikitextItem = this.embedSizeSwitchWikitext.getMenu().findSelectedItem(); /** * Currently selected size menu. * * @property {OO.ui.MenuSelectWidget} */ this.currentSizeMenu = mw.user.isAnon() ? this.embedSizeSwitchHtml.getMenu() : this.embedSizeSwitchWikitext.getMenu(); /** * Current default item. * * @property {OO.ui.MenuOptionWidget} */ this.currentDefaultItem = mw.user.isAnon() ? this.defaultHtmlItem : this.defaultWikitextItem; } OO.inheritClass( Embed, mw.mmv.ui.reuse.Tab ); EP = Embed.prototype; /** @property {number} Width threshold at which an image is to be considered "large" */ EP.LARGE_IMAGE_WIDTH_THRESHOLD = 1200; /** @property {number} Height threshold at which an image is to be considered "large" */ EP.LARGE_IMAGE_HEIGHT_THRESHOLD = 900; /** * Creates text areas for html and wikitext snippets. * * @param {jQuery} $container */ EP.createSnippetTextAreas = function ( $container ) { var wikitextClasses = [ 'mw-mmv-embed-text-wikitext' ], htmlClasses = [ 'mw-mmv-embed-text-html' ]; ( mw.user.isAnon() ? htmlClasses : wikitextClasses ).push( 'active' ); this.embedTextHtml = new OO.ui.MultilineTextInputWidget( { classes: htmlClasses, readOnly: true, autosize: true, maxRows: 5 } ); this.embedTextHtml.$element.find( 'textarea' ) .prop( 'placeholder', mw.message( 'multimediaviewer-reuse-loading-placeholder' ).text() ); this.embedTextHtml.$input.on( 'copy', function () { mw.mmv.actionLogger.log( 'embed-html-copied' ); } ); this.embedTextWikitext = new OO.ui.MultilineTextInputWidget( { classes: wikitextClasses, readOnly: true, autosize: true, maxRows: 5 } ); this.embedTextWikitext.$element.find( 'textarea' ) .prop( 'placeholder', mw.message( 'multimediaviewer-reuse-loading-placeholder' ).text() ); this.embedTextWikitext.$input.on( 'copy', function () { mw.mmv.actionLogger.log( 'embed-wikitext-copied' ); } ); this.$copyButton = $( '