| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
ve.ui.MWLatexInspector = function VeUiMWLatexInspector( config ) { |
| 20 |
|
| 21 |
ve.ui.MWLatexInspector.super.call( this, config ); |
| 22 |
}; |
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
OO.inheritClass( ve.ui.MWLatexInspector, ve.ui.MWLiveExtensionInspector ); |
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
ve.ui.MWLatexInspector.static.dir = 'ltr'; |
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
ve.ui.MWLatexInspector.prototype.initialize = function () { |
| 38 |
|
| 39 |
ve.ui.MWLatexInspector.super.prototype.initialize.call( this ); |
| 40 |
|
| 41 |
this.displaySelect = new OO.ui.ButtonSelectWidget( { |
| 42 |
items: [ |
| 43 |
new OO.ui.ButtonOptionWidget( { |
| 44 |
data: 'default', |
| 45 |
icon: 'mathematicsDisplayDefault', |
| 46 |
label: ve.msg( 'math-visualeditor-mwlatexinspector-display-default' ) |
| 47 |
} ), |
| 48 |
new OO.ui.ButtonOptionWidget( { |
| 49 |
data: 'inline', |
| 50 |
icon: 'mathematicsDisplayInline', |
| 51 |
label: ve.msg( 'math-visualeditor-mwlatexinspector-display-inline' ) |
| 52 |
} ), |
| 53 |
new OO.ui.ButtonOptionWidget( { |
| 54 |
data: 'block', |
| 55 |
icon: 'mathematicsDisplayBlock', |
| 56 |
label: ve.msg( 'math-visualeditor-mwlatexinspector-display-block' ) |
| 57 |
} ) |
| 58 |
] |
| 59 |
} ); |
| 60 |
|
| 61 |
this.idInput = new OO.ui.TextInputWidget(); |
| 62 |
this.qidInput = new mw.widgets.MathWbEntitySelector(); |
| 63 |
|
| 64 |
const inputField = new OO.ui.FieldLayout( this.input, { |
| 65 |
align: 'top', |
| 66 |
label: ve.msg( 'math-visualeditor-mwlatexdialog-card-formula' ) |
| 67 |
} ); |
| 68 |
const displayField = new OO.ui.FieldLayout( this.displaySelect, { |
| 69 |
align: 'top', |
| 70 |
label: ve.msg( 'math-visualeditor-mwlatexinspector-display' ) |
| 71 |
} ); |
| 72 |
const idField = new OO.ui.FieldLayout( this.idInput, { |
| 73 |
align: 'top', |
| 74 |
label: ve.msg( 'math-visualeditor-mwlatexinspector-id' ) |
| 75 |
} ); |
| 76 |
const qidField = new OO.ui.FieldLayout( this.qidInput, { |
| 77 |
align: 'top', |
| 78 |
label: ve.msg( 'math-visualeditor-mwlatexinspector-qid' ) |
| 79 |
} ); |
| 80 |
|
| 81 |
|
| 82 |
this.$content.addClass( 've-ui-mwLatexInspector-content' ); |
| 83 |
this.form.$element.append( |
| 84 |
inputField.$element, |
| 85 |
this.generatedContentsError.$element, |
| 86 |
displayField.$element, |
| 87 |
idField.$element, |
| 88 |
qidField.$element |
| 89 |
); |
| 90 |
}; |
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
ve.ui.MWLatexInspector.prototype.getSetupProcess = function ( data ) { |
| 96 |
return ve.ui.MWLatexInspector.super.prototype.getSetupProcess.call( this, data ) |
| 97 |
.next( () => { |
| 98 |
const display = this.selectedNode.getAttribute( 'mw' ).attrs.display || 'default'; |
| 99 |
const attributes = this.selectedNode && this.selectedNode.getAttribute( 'mw' ).attrs, |
| 100 |
id = attributes && attributes.id || '', |
| 101 |
qid = attributes && attributes.qid || '', |
| 102 |
isReadOnly = this.isReadOnly(); |
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
this.idInput.setValue( id ).setReadOnly( isReadOnly ); |
| 107 |
this.qidInput.setValue( qid ).setReadOnly( isReadOnly ); |
| 108 |
|
| 109 |
|
| 110 |
this.input.on( 'change', this.onChangeHandler ); |
| 111 |
this.displaySelect.on( 'choose', this.onChangeHandler ); |
| 112 |
this.idInput.on( 'change', this.onChangeHandler ); |
| 113 |
this.qidInput.on( 'change', this.onChangeHandler ); |
| 114 |
this.displaySelect.selectItemByData( display ); |
| 115 |
this.displaySelect.on( 'choose', this.onChangeHandler ); |
| 116 |
} ); |
| 117 |
}; |
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
ve.ui.MWLatexInspector.prototype.getTeardownProcess = function ( data ) { |
| 123 |
return ve.ui.MWLatexInspector.super.prototype.getTeardownProcess.call( this, data ) |
| 124 |
.first( () => { |
| 125 |
this.displaySelect.off( 'choose', this.onChangeHandler ); |
| 126 |
} ); |
| 127 |
}; |
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
ve.ui.MWLatexInspector.prototype.updateMwData = function ( mwData ) { |
| 133 |
|
| 134 |
ve.ui.MWLatexInspector.super.prototype.updateMwData.call( this, mwData ); |
| 135 |
|
| 136 |
const display = this.displaySelect.findSelectedItem().getData(); |
| 137 |
const id = this.idInput.getValue(); |
| 138 |
const qid = this.qidInput.getValue(); |
| 139 |
|
| 140 |
mwData.attrs.display = display !== 'default' ? display : undefined; |
| 141 |
mwData.attrs.id = id || undefined; |
| 142 |
mwData.attrs.qid = qid || undefined; |
| 143 |
}; |
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
ve.ui.MWLatexInspector.prototype.formatGeneratedContentsError = function ( $element ) { |
| 149 |
return $element.text().trim(); |
| 150 |
}; |