| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
ve.ui.SpecialCharacterDialog = function VeUiSpecialCharacterDialog() { |
| 17 |
|
| 18 |
ve.ui.SpecialCharacterDialog.super.apply( this, arguments ); |
| 19 |
|
| 20 |
this.characterListLoaded = false; |
| 21 |
|
| 22 |
this.$element.addClass( 've-ui-specialCharacterDialog' ); |
| 23 |
}; |
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
OO.inheritClass( ve.ui.SpecialCharacterDialog, ve.ui.ToolbarDialog ); |
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
ve.ui.SpecialCharacterDialog.static.name = 'specialCharacter'; |
| 32 |
|
| 33 |
|
| 34 |
ve.ui.SpecialCharacterDialog.static.title = |
| 35 |
OO.ui.deferMsg( 'visualeditor-specialcharacter-button-tooltip' ); |
| 36 |
|
| 37 |
ve.ui.SpecialCharacterDialog.static.size = 'full'; |
| 38 |
|
| 39 |
ve.ui.SpecialCharacterDialog.static.padded = false; |
| 40 |
|
| 41 |
ve.ui.SpecialCharacterDialog.static.activeSurface = true; |
| 42 |
|
| 43 |
ve.ui.SpecialCharacterDialog.static.handlesSource = true; |
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
ve.ui.SpecialCharacterDialog.prototype.initialize = function () { |
| 51 |
|
| 52 |
ve.ui.SpecialCharacterDialog.super.prototype.initialize.call( this ); |
| 53 |
|
| 54 |
this.characterListLayout = new ve.ui.SymbolListBookletLayout(); |
| 55 |
this.characterListLayout.connect( this, { |
| 56 |
choose: 'onCharacterListChoose' |
| 57 |
} ); |
| 58 |
|
| 59 |
|
| 60 |
this.$body.append( this.characterListLayout.$element ); |
| 61 |
}; |
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
ve.ui.SpecialCharacterDialog.prototype.getSetupProcess = function ( data ) { |
| 67 |
data = data || {}; |
| 68 |
return ve.ui.SpecialCharacterDialog.super.prototype.getSetupProcess.call( this, data ) |
| 69 |
.next( () => { |
| 70 |
this.surface = data.surface; |
| 71 |
this.surface.getModel().connect( this, { contextChange: 'onContextChange' } ); |
| 72 |
|
| 73 |
this.characterListLayout.$element.toggleClass( 've-ui-specialCharacterDialog-characterList-source', this.surface.getMode() === 'source' ); |
| 74 |
|
| 75 |
if ( !this.characterListLoaded ) { |
| 76 |
this.characterListLoaded = true; |
| 77 |
|
| 78 |
ve.init.platform.fetchSpecialCharList() |
| 79 |
.then( ( symbolData ) => { |
| 80 |
this.characterListLayout.setSymbolData( symbolData ); |
| 81 |
this.updateSize(); |
| 82 |
} ); |
| 83 |
} |
| 84 |
} ); |
| 85 |
}; |
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
ve.ui.SpecialCharacterDialog.prototype.getTeardownProcess = function ( data ) { |
| 91 |
data = data || {}; |
| 92 |
return ve.ui.SpecialCharacterDialog.super.prototype.getTeardownProcess.call( this, data ) |
| 93 |
.first( () => { |
| 94 |
this.surface.getModel().disconnect( this ); |
| 95 |
this.surface = null; |
| 96 |
} ); |
| 97 |
}; |
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
ve.ui.SpecialCharacterDialog.prototype.getReadyProcess = function ( data ) { |
| 103 |
return ve.ui.SpecialCharacterDialog.super.prototype.getReadyProcess.call( this, data ) |
| 104 |
.next( () => { |
| 105 |
const surface = this.surface; |
| 106 |
|
| 107 |
🤦) |
| 108 |
const previousSelection = surface.getModel().getSelection(); |
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
setTimeout( () => { |
| 114 |
surface.getView().focus(); |
| 115 |
if ( !previousSelection.isNull() ) { |
| 116 |
surface.getModel().setSelection( previousSelection ); |
| 117 |
} |
| 118 |
} ); |
| 119 |
} ); |
| 120 |
}; |
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
ve.ui.SpecialCharacterDialog.prototype.getActionProcess = function ( action ) { |
| 126 |
return new OO.ui.Process( () => { |
| 127 |
this.close( { action: action } ); |
| 128 |
} ); |
| 129 |
}; |
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
ve.ui.SpecialCharacterDialog.prototype.onContextChange = function () { |
| 135 |
this.setDisabled( !( this.surface.getModel().getSelection() instanceof ve.dm.LinearSelection ) ); |
| 136 |
}; |
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
ve.ui.SpecialCharacterDialog.prototype.onCharacterListChoose = function ( character ) { |
| 144 |
const fragment = this.surface.getModel().getFragment(), |
| 145 |
mode = this.surface.getMode(); |
| 146 |
|
| 147 |
function encode( text ) { |
| 148 |
if ( mode === 'visual' && character.entities ) { |
| 149 |
return ve.init.platform.decodeEntities( text ); |
| 150 |
} else { |
| 151 |
return text; |
| 152 |
} |
| 153 |
} |
| 154 |
|
| 155 |
if ( character ) { |
| 156 |
if ( typeof character === 'string' || character.string ) { |
| 157 |
fragment.insertContent( encode( character.string || character ), true ).collapseToEnd().select(); |
| 158 |
} else if ( character.action.type === 'replace' ) { |
| 159 |
fragment.insertContent( encode( character.action.options.peri ), true ).collapseToEnd().select(); |
| 160 |
} else if ( character.action.type === 'encapsulate' ) { |
| 161 |
fragment.collapseToStart().insertContent( encode( character.action.options.pre ), true ); |
| 162 |
fragment.collapseToEnd().insertContent( encode( character.action.options.post ), true ).collapseToEnd().select(); |
| 163 |
} |
| 164 |
|
| 165 |
ve.track( |
| 166 |
'activity.' + this.constructor.static.name, |
| 167 |
{ action: 'insert-' + this.characterListLayout.currentPageName } |
| 168 |
); |
| 169 |
} |
| 170 |
}; |
| 171 |
|
| 172 |
ve.ui.SpecialCharacterDialog.prototype.getBodyHeight = function () { |
| 173 |
return 150; |
| 174 |
}; |
| 175 |
|
| 176 |
ve.ui.SpecialCharacterDialog.prototype.getContentHeight = function () { |
| 177 |
|
| 178 |
return this.getBodyHeight(); |
| 179 |
}; |
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
ve.ui.windowFactory.register( ve.ui.SpecialCharacterDialog ); |