mediawiki-extensions-Visual.../modules/ve-mw/ui/contextitems/ve.ui.MWWikitextPasteContextItem.js
thiemowmde c57e86d325 Mark config parameter as optional where it is
This goes along with I3f239e0 in Cite.

Change-Id: Ife88431ef810f978f5c4466ee82405fd4c791032
2023-02-02 10:47:32 +01:00

74 lines
1.9 KiB
JavaScript

/*!
* VisualEditor MWWikitextPasteContextItem class.
*
* @copyright 2011-2019 VisualEditor Team and others; see http://ve.mit-license.org
*/
/**
* Context item shown after a rich text paste.
*
* @class
* @extends ve.ui.LinearContextItem
*
* @constructor
* @param {ve.ui.Context} context Context item is in
* @param {ve.dm.Model} model Model item is related to
* @param {Object} [config]
*/
ve.ui.MWWikitextPasteContextItem = function VeUiMWWikitextPasteContextItem() {
// Parent constructor
ve.ui.MWWikitextPasteContextItem.super.apply( this, arguments );
// Initialization
this.$element.addClass( 've-ui-mwWikitextPasteContextItem' );
};
/* Inheritance */
OO.inheritClass( ve.ui.MWWikitextPasteContextItem, ve.ui.LinearContextItem );
/* Static Properties */
ve.ui.MWWikitextPasteContextItem.static.name = 'wikitextPaste';
ve.ui.MWWikitextPasteContextItem.static.icon = 'wikiText';
ve.ui.MWWikitextPasteContextItem.static.label = OO.ui.deferMsg( 'visualeditor-wikitextconvert-title' );
ve.ui.MWWikitextPasteContextItem.static.editable = false;
/* Methods */
/**
* @inheritdoc
*/
ve.ui.MWWikitextPasteContextItem.prototype.renderBody = function () {
var fragment = this.model.fragment,
doc = this.model.doc,
contextRange = this.model.contextRange;
var convertButton = new OO.ui.ButtonWidget( {
label: ve.msg( 'visualeditor-wikitextconvert-convert' ),
flags: [ 'progressive' ]
} ).on( 'click', function () {
fragment.insertDocument( doc, contextRange ).getPending().then( function () {
fragment.collapseToEnd().select();
} );
// TODO: Show something if the promise (conversion) fails?
} );
this.$body.append(
$( '<p>' ).text( ve.msg( 'visualeditor-wikitextconvert-message' ) )
);
if ( this.$foot ) {
this.$foot.prepend( convertButton.$element );
} else {
this.$body.append( convertButton.$element );
}
};
/* Registration */
ve.ui.contextItemFactory.register( ve.ui.MWWikitextPasteContextItem );