Debian Codegraph @

extensions/VisualEditor/modules/ve-mw/ui/contextitems/ve.ui.MWWikitextPasteContextItem.js

raw symbols SCIP
1 /*!
2 * VisualEditor MWWikitextPasteContextItem class.
3 *
4 * @copyright See AUTHORS.txt
5 */
6
7 /**
8 * Context item shown after a rich text paste.
9 *
10 * @class
11 * @extends ve.ui.PersistentContextItem
12 *
13 * @constructor
14 * @param {ve.ui.LinearContext} context Context the item is in
15 * @param {Object} [data] Extra data
16 * @param {Object} [config]
17 */
18 ve.ui.MWWikitextPasteContextItem = function VeUiMWWikitextPasteContextItem() {
19 // Parent constructor
20 ve.ui.MWWikitextPasteContextItem.super.apply( this, arguments );
21
22 // Initialization
23 this.$element.addClass( 've-ui-mwWikitextPasteContextItem' );
24 };
25
26 /* Inheritance */
27
28 OO.inheritClass( ve.ui.MWWikitextPasteContextItem, ve.ui.PersistentContextItem );
29
30 /* Static Properties */
31
32 ve.ui.MWWikitextPasteContextItem.static.name = 'wikitextPaste';
33
34 ve.ui.MWWikitextPasteContextItem.static.icon = 'wikiText';
35
36 ve.ui.MWWikitextPasteContextItem.static.label = OO.ui.deferMsg( 'visualeditor-wikitextconvert-title' );
37
38 /* Methods */
39
40 /**
41 * @inheritdoc
42 */
43 ve.ui.MWWikitextPasteContextItem.prototype.renderBody = function () {
44 const fragment = this.data.fragment,
45 doc = this.data.doc,
46 contextRange = this.data.contextRange;
47
48 const convertButton = new OO.ui.ButtonWidget( {
49 label: ve.msg( 'visualeditor-wikitextconvert-convert' ),
50 flags: [ 'progressive' ]
51 } ).on( 'click', () => {
52 fragment.insertDocument( doc, contextRange ).getPending().then( () => {
53 fragment.collapseToEnd().select();
54 } );
55 // TODO: Show something if the promise (conversion) fails?
56 } );
57
58 this.$body.append(
59 $( '<p>' ).text( ve.msg( 'visualeditor-wikitextconvert-message' ) )
60 );
61
62 if ( this.$foot ) {
63 this.$foot.prepend( convertButton.$element );
64 } else {
65 this.$body.append( convertButton.$element );
66 }
67 };
68
69 /* Registration */
70
71 ve.ui.contextItemFactory.register( ve.ui.MWWikitextPasteContextItem );