2019-11-16 15:20:44 +00:00
|
|
|
/*!
|
|
|
|
* VisualEditor MWWikitextPasteContextItem class.
|
|
|
|
*
|
2023-12-01 16:06:11 +00:00
|
|
|
* @copyright See AUTHORS.txt
|
2019-11-16 15:20:44 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Context item shown after a rich text paste.
|
|
|
|
*
|
|
|
|
* @class
|
2023-07-10 14:46:57 +00:00
|
|
|
* @extends ve.ui.PersistentContextItem
|
2019-11-16 15:20:44 +00:00
|
|
|
*
|
|
|
|
* @constructor
|
2023-07-10 13:31:31 +00:00
|
|
|
* @param {ve.ui.LinearContext} context Context the item is in
|
2023-07-10 14:46:57 +00:00
|
|
|
* @param {Object} [data] Extra data
|
2023-02-02 09:47:32 +00:00
|
|
|
* @param {Object} [config]
|
2019-11-16 15:20:44 +00:00
|
|
|
*/
|
|
|
|
ve.ui.MWWikitextPasteContextItem = function VeUiMWWikitextPasteContextItem() {
|
|
|
|
// Parent constructor
|
|
|
|
ve.ui.MWWikitextPasteContextItem.super.apply( this, arguments );
|
|
|
|
|
|
|
|
// Initialization
|
|
|
|
this.$element.addClass( 've-ui-mwWikitextPasteContextItem' );
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Inheritance */
|
|
|
|
|
2023-07-10 14:46:57 +00:00
|
|
|
OO.inheritClass( ve.ui.MWWikitextPasteContextItem, ve.ui.PersistentContextItem );
|
2019-11-16 15:20:44 +00:00
|
|
|
|
|
|
|
/* 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' );
|
|
|
|
|
|
|
|
/* Methods */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
ve.ui.MWWikitextPasteContextItem.prototype.renderBody = function () {
|
2023-07-10 14:46:57 +00:00
|
|
|
var fragment = this.data.fragment,
|
|
|
|
doc = this.data.doc,
|
|
|
|
contextRange = this.data.contextRange;
|
2019-11-16 15:20:44 +00:00
|
|
|
|
2022-02-21 18:07:07 +00:00
|
|
|
var convertButton = new OO.ui.ButtonWidget( {
|
2019-11-16 15:20:44 +00:00
|
|
|
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 );
|