| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
ve.ui.MWPreDialog = function VeUiMWPreDialog() { |
| 18 |
|
| 19 |
ve.ui.MWPreDialog.super.apply( this, arguments ); |
| 20 |
|
| 21 |
this.$element.addClass( 've-ui-mwPreDialog' ); |
| 22 |
}; |
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
OO.inheritClass( ve.ui.MWPreDialog, ve.ui.MWExtensionDialog ); |
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
ve.ui.MWPreDialog.static.name = 'mwPre'; |
| 31 |
|
| 32 |
ve.ui.MWPreDialog.static.size = 'large'; |
| 33 |
|
| 34 |
ve.ui.MWPreDialog.static.title = OO.ui.deferMsg( 'visualeditor-mwpredialog-title' ); |
| 35 |
|
| 36 |
ve.ui.MWPreDialog.static.modelClasses = [ ve.dm.MWPreNode ]; |
| 37 |
|
| 38 |
ve.ui.MWPreDialog.static.actions = [ |
| 39 |
...ve.ui.MWPreDialog.super.static.actions, |
| 40 |
{ |
| 41 |
action: 'convert', |
| 42 |
label: OO.ui.deferMsg( 'visualeditor-mwpredialog-convert' ), |
| 43 |
modes: [ 'edit' ] |
| 44 |
} |
| 45 |
]; |
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
ve.ui.MWPreDialog.prototype.initialize = function () { |
| 53 |
|
| 54 |
ve.ui.MWPreDialog.super.prototype.initialize.call( this ); |
| 55 |
|
| 56 |
|
| 57 |
this.panel = new OO.ui.PanelLayout( { |
| 58 |
padded: true |
| 59 |
} ); |
| 60 |
|
| 61 |
this.input = new ve.ui.MWPreTextInputWidget( { |
| 62 |
|
| 63 |
|
| 64 |
rows: 100, |
| 65 |
classes: [ 've-ui-mwExtensionWindow-input' ] |
| 66 |
} ); |
| 67 |
this.input.connect( this, { resize: 'updateSize' } ); |
| 68 |
|
| 69 |
|
| 70 |
this.$element.addClass( 've-ui-mwPreDialog' ); |
| 71 |
this.panel.$element.append( this.input.$element ); |
| 72 |
this.$body.append( this.panel.$element ); |
| 73 |
}; |
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
ve.ui.MWPreDialog.prototype.getReadyProcess = function ( data ) { |
| 79 |
return ve.ui.MWPreDialog.super.prototype.getReadyProcess.call( this, data ) |
| 80 |
.next( () => { |
| 81 |
this.input.focus(); |
| 82 |
} ); |
| 83 |
}; |
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
ve.ui.MWPreDialog.prototype.getActionProcess = function ( action ) { |
| 89 |
if ( action === 'convert' ) { |
| 90 |
return new OO.ui.Process( () => { |
| 91 |
const |
| 92 |
value = this.input.getValue(), |
| 93 |
nodeRange = this.selectedNode.getOuterRange(), |
| 94 |
surfaceModel = this.getFragment().getSurface(), |
| 95 |
doc = surfaceModel.getDocument(), |
| 96 |
|
| 97 |
content = value.split( '' ), |
| 98 |
|
| 99 |
annotations = doc.data.getAnnotationsFromOffset( nodeRange.start ); |
| 100 |
ve.dm.Document.static.addAnnotationsToData( content, annotations ); |
| 101 |
|
| 102 |
content.unshift( { type: 'mwPreformatted' } ); |
| 103 |
content.push( { type: '/mwPreformatted' } ); |
| 104 |
|
| 105 |
surfaceModel.change( |
| 106 |
ve.dm.TransactionBuilder.static.newFromReplacement( doc, nodeRange, content ) |
| 107 |
); |
| 108 |
this.close(); |
| 109 |
} ); |
| 110 |
} |
| 111 |
|
| 112 |
return ve.ui.MWPreDialog.super.prototype.getActionProcess.call( this, action ); |
| 113 |
}; |
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
ve.ui.MWPreDialog.prototype.getBodyHeight = function () { |
| 119 |
return 500; |
| 120 |
}; |
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
ve.ui.windowFactory.register( ve.ui.MWPreDialog ); |