| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
ve.ui.CommentInspector = function VeUiCommentInspector() { |
| 17 |
|
| 18 |
ve.ui.CommentInspector.super.apply( this, arguments ); |
| 19 |
}; |
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
OO.inheritClass( ve.ui.CommentInspector, ve.ui.NodeInspector ); |
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
ve.ui.CommentInspector.static.name = 'comment'; |
| 28 |
|
| 29 |
ve.ui.CommentInspector.static.title = |
| 30 |
OO.ui.deferMsg( 'visualeditor-commentinspector-title' ); |
| 31 |
|
| 32 |
ve.ui.CommentInspector.static.modelClasses = [ ve.dm.CommentNode ]; |
| 33 |
|
| 34 |
ve.ui.CommentInspector.static.size = 'large'; |
| 35 |
|
| 36 |
ve.ui.CommentInspector.static.actions = [ |
| 37 |
{ |
| 38 |
action: 'remove', |
| 39 |
label: OO.ui.deferMsg( 'visualeditor-inspector-remove-tooltip' ), |
| 40 |
flags: 'destructive', |
| 41 |
modes: 'edit' |
| 42 |
}, |
| 43 |
...ve.ui.CommentInspector.super.static.actions |
| 44 |
]; |
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
ve.ui.CommentInspector.prototype.initialize = function () { |
| 52 |
|
| 53 |
ve.ui.CommentInspector.super.prototype.initialize.call( this ); |
| 54 |
|
| 55 |
this.textWidget = new ve.ui.WhitespacePreservingTextInputWidget( { |
| 56 |
autosize: true |
| 57 |
} ); |
| 58 |
this.textWidget.connect( this, { resize: 'updateSize' } ); |
| 59 |
this.textWidget.$input.attr( 'aria-label', OO.ui.deferMsg( 'visualeditor-commentinspector-title' ) ); |
| 60 |
|
| 61 |
this.$content.addClass( 've-ui-commentInspector-content' ); |
| 62 |
this.form.$element.append( this.textWidget.$element ); |
| 63 |
}; |
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
ve.ui.CommentInspector.prototype.getActionProcess = function ( action ) { |
| 69 |
if ( action === 'remove' || action === 'insert' ) { |
| 70 |
return new OO.ui.Process( () => { |
| 71 |
this.close( { action: action } ); |
| 72 |
} ); |
| 73 |
} |
| 74 |
return ve.ui.CommentInspector.super.prototype.getActionProcess.call( this, action ); |
| 75 |
}; |
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
ve.ui.CommentInspector.prototype.getSetupProcess = function ( data ) { |
| 84 |
return ve.ui.CommentInspector.super.prototype.getSetupProcess.call( this, data ) |
| 85 |
.next( () => { |
| 86 |
this.getFragment().getSurface().pushStaging(); |
| 87 |
|
| 88 |
this.commentNode = this.getSelectedNode(); |
| 89 |
if ( this.commentNode ) { |
| 90 |
this.textWidget.setValueAndWhitespace( this.commentNode.getAttribute( 'text' ) || '' ); |
| 91 |
} else { |
| 92 |
this.textWidget.setWhitespace( [ ' ', ' ' ] ); |
| 93 |
this.getFragment().insertContent( [ |
| 94 |
{ |
| 95 |
type: 'comment', |
| 96 |
attributes: { text: '' } |
| 97 |
}, |
| 98 |
{ type: '/comment' } |
| 99 |
] ).select(); |
| 100 |
this.commentNode = this.getSelectedNode(); |
| 101 |
} |
| 102 |
this.textWidget.setReadOnly( this.isReadOnly() ); |
| 103 |
} ); |
| 104 |
}; |
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
ve.ui.CommentInspector.prototype.getReadyProcess = function ( data ) { |
| 110 |
return ve.ui.CommentInspector.super.prototype.getReadyProcess.call( this, data ) |
| 111 |
.next( () => { |
| 112 |
this.textWidget.focus(); |
| 113 |
} ); |
| 114 |
}; |
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
ve.ui.CommentInspector.prototype.getTeardownProcess = function ( data ) { |
| 120 |
data = data || {}; |
| 121 |
return ve.ui.CommentInspector.super.prototype.getTeardownProcess.call( this, data ) |
| 122 |
.first( () => { |
| 123 |
const surfaceModel = this.getFragment().getSurface(); |
| 124 |
|
| 125 |
|
| 126 |
if ( data.action === 'done' && this.textWidget.getValue() !== '' ) { |
| 127 |
|
| 128 |
this.getFragment().changeAttributes( { text: this.textWidget.getValueAndWhitespace() } ); |
| 129 |
surfaceModel.applyStaging(); |
| 130 |
} else { |
| 131 |
surfaceModel.popStaging(); |
| 132 |
if ( data.action === 'remove' || data.action === 'done' ) { |
| 133 |
this.getFragment().removeContent(); |
| 134 |
} |
| 135 |
} |
| 136 |
|
| 137 |
|
| 138 |
this.textWidget.setValueAndWhitespace( '' ); |
| 139 |
} ); |
| 140 |
}; |
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
ve.ui.windowFactory.register( ve.ui.CommentInspector ); |