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 () {
|
2024-05-21 14:22:56 +00:00
|
|
|
const fragment = this.data.fragment,
|
2023-07-10 14:46:57 +00:00
|
|
|
doc = this.data.doc,
|
|
|
|
contextRange = this.data.contextRange;
|
2019-11-16 15:20:44 +00:00
|
|
|
|
2024-05-21 14:22:56 +00:00
|
|
|
const convertButton = new OO.ui.ButtonWidget( {
|
2019-11-16 15:20:44 +00:00
|
|
|
label: ve.msg( 'visualeditor-wikitextconvert-convert' ),
|
|
|
|
flags: [ 'progressive' ]
|
2024-04-30 16:44:25 +00:00
|
|
|
} ).on( 'click', () => {
|
|
|
|
fragment.insertDocument( doc, contextRange ).getPending().then( () => {
|
2019-11-16 15:20:44 +00:00
|
|
|
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 );
|