| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
ve.ui.MWLanguageVariantInspector = function VeUiMWLanguageVariantInspector() { |
| 17 |
|
| 18 |
ve.ui.MWLanguageVariantInspector.super.apply( this, arguments ); |
| 19 |
}; |
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
OO.inheritClass( ve.ui.MWLanguageVariantInspector, ve.ui.NodeInspector ); |
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
ve.ui.MWLanguageVariantInspector.static.name = 'mwLanguageVariant-disabled'; |
| 28 |
|
| 29 |
ve.ui.MWLanguageVariantInspector.static.title = OO.ui.deferMsg( |
| 30 |
'visualeditor-mwlanguagevariantinspector-title-disabled' |
| 31 |
); |
| 32 |
|
| 33 |
ve.ui.MWLanguageVariantInspector.static.modelClasses = [ |
| 34 |
ve.dm.MWLanguageVariantBlockNode, |
| 35 |
ve.dm.MWLanguageVariantInlineNode, |
| 36 |
ve.dm.MWLanguageVariantHiddenNode |
| 37 |
]; |
| 38 |
|
| 39 |
ve.ui.MWLanguageVariantInspector.static.size = 'large'; |
| 40 |
|
| 41 |
ve.ui.MWLanguageVariantInspector.static.actions = [ |
| 42 |
{ |
| 43 |
action: 'remove', |
| 44 |
label: OO.ui.deferMsg( 'visualeditor-inspector-remove-tooltip' ), |
| 45 |
flags: 'destructive', |
| 46 |
modes: 'edit' |
| 47 |
}, |
| 48 |
...ve.ui.MWLanguageVariantInspector.super.static.actions |
| 49 |
]; |
| 50 |
|
| 51 |
ve.ui.MWLanguageVariantInspector.static.defaultVariantType = |
| 52 |
'mwLanguageVariantInline'; |
| 53 |
|
| 54 |
ve.ui.MWLanguageVariantInspector.static.includeCommands = null; |
| 55 |
|
| 56 |
|
| 57 |
ve.ui.MWLanguageVariantInspector.static.excludeCommands = [ |
| 58 |
|
| 59 |
'paragraph', |
| 60 |
'heading1', |
| 61 |
'heading2', |
| 62 |
'heading3', |
| 63 |
'heading4', |
| 64 |
'heading5', |
| 65 |
'heading6', |
| 66 |
'preformatted', |
| 67 |
'blockquote', |
| 68 |
|
| 69 |
'tableCellHeader', |
| 70 |
'tableCellData', |
| 71 |
|
| 72 |
'bullet', |
| 73 |
'bulletWrapOnce', |
| 74 |
'number', |
| 75 |
'numberWrapOnce', |
| 76 |
'indent', |
| 77 |
'outdent' |
| 78 |
]; |
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
ve.ui.MWLanguageVariantInspector.static.getImportRules = function () { |
| 87 |
return ve.extendObject( |
| 88 |
ve.copy( ve.init.target.constructor.static.importRules ), |
| 89 |
{ |
| 90 |
|
| 91 |
|
| 92 |
} |
| 93 |
); |
| 94 |
}; |
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
ve.ui.MWLanguageVariantInspector.prototype.getDefaultVariantInfo = null; |
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
ve.ui.MWLanguageVariantInspector.prototype.getContentFromInspector = null; |
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
ve.ui.MWLanguageVariantInspector.prototype.createTextTarget = function ( placeholder ) { |
| 130 |
return ve.init.target.createTargetWidget( { |
| 131 |
toolbarGroups: [], |
| 132 |
includeCommands: this.constructor.static.includeCommands, |
| 133 |
excludeCommands: this.constructor.static.excludeCommands, |
| 134 |
importRules: this.constructor.static.getImportRules(), |
| 135 |
inDialog: this.constructor.static.name, |
| 136 |
placeholder: placeholder || null |
| 137 |
} ); |
| 138 |
}; |
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
ve.ui.MWLanguageVariantInspector.prototype.setupTextTargetDoc = function ( textTarget, htmlString ) { |
| 150 |
const doc = this.variantNode.getDocument().newFromHtml( htmlString ); |
| 151 |
textTarget.setDocument( doc ); |
| 152 |
return doc; |
| 153 |
}; |
| 154 |
|
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
ve.ui.MWLanguageVariantInspector.prototype.getHtmlForDoc = function ( doc ) { |
| 168 |
const surface = new ve.dm.Surface( doc ); |
| 169 |
|
| 170 |
|
| 171 |
try { |
| 172 |
surface.change( |
| 173 |
ve.dm.TransactionBuilder.static.newFromWrap( doc, new ve.Range( 0, doc.data.countNonInternalElements() ), [], [], [ { type: 'paragraph' } ], [] ) |
| 174 |
); |
| 175 |
} catch ( e ) { |
| 176 |
|
| 177 |
|
| 178 |
|
| 179 |
} |
| 180 |
|
| 181 |
const targetHtmlDoc = ve.dm.converter.getDomFromModel( doc ); |
| 182 |
return ve.properInnerHtml( targetHtmlDoc.body ); |
| 183 |
}; |
| 184 |
|
| 185 |
|
| 186 |
|
| 187 |
|
| 188 |
|
| 189 |
|
| 190 |
ve.ui.MWLanguageVariantInspector.prototype.initialize = function () { |
| 191 |
|
| 192 |
ve.ui.MWLanguageVariantInspector.super.prototype.initialize.call( this ); |
| 193 |
this.$content.addClass( 've-ui-mwLanguageVariantInspector-content' ); |
| 194 |
}; |
| 195 |
|
| 196 |
|
| 197 |
|
| 198 |
|
| 199 |
ve.ui.MWLanguageVariantInspector.prototype.getActionProcess = function ( action ) { |
| 200 |
if ( action === 'remove' || action === 'insert' ) { |
| 201 |
return new OO.ui.Process( () => { |
| 202 |
this.close( { action: action } ); |
| 203 |
} ); |
| 204 |
} |
| 205 |
return ve.ui.MWLanguageVariantInspector.super.prototype.getActionProcess.call( this, action ); |
| 206 |
}; |
| 207 |
|
| 208 |
|
| 209 |
|
| 210 |
|
| 211 |
|
| 212 |
|
| 213 |
|
| 214 |
ve.ui.MWLanguageVariantInspector.prototype.getSetupProcess = function ( data ) { |
| 215 |
return ve.ui.MWLanguageVariantInspector.super.prototype.getSetupProcess.call( this, data ) |
| 216 |
.next( () => { |
| 217 |
this.getFragment().getSurface().pushStaging(); |
| 218 |
|
| 219 |
this.variantNode = this.getSelectedNode(); |
| 220 |
if ( !this.variantNode ) { |
| 221 |
this.getFragment().insertContent( [ |
| 222 |
{ |
| 223 |
type: this.constructor.static.defaultVariantType, |
| 224 |
attributes: { |
| 225 |
variantInfo: this.getDefaultVariantInfo() |
| 226 |
} |
| 227 |
}, |
| 228 |
{ type: '/' + this.constructor.static.defaultVariantType } |
| 229 |
] ).select(); |
| 230 |
this.variantNode = this.getSelectedNode(); |
| 231 |
} |
| 232 |
} ); |
| 233 |
}; |
| 234 |
|
| 235 |
|
| 236 |
|
| 237 |
|
| 238 |
ve.ui.MWLanguageVariantInspector.prototype.getTeardownProcess = function ( data ) { |
| 239 |
data = data || {}; |
| 240 |
return ve.ui.MWLanguageVariantInspector.super.prototype.getTeardownProcess.call( this, data ) |
| 241 |
.first( () => { |
| 242 |
const surfaceModel = this.getFragment().getSurface(); |
| 243 |
|
| 244 |
if ( data.action === 'remove' ) { |
| 245 |
surfaceModel.popStaging(); |
| 246 |
|
| 247 |
this.getFragment().removeContent(); |
| 248 |
} else if ( data.action === 'done' ) { |
| 249 |
|
| 250 |
const newContent = this.getContentFromInspector( |
| 251 |
ve.copy( this.variantNode.getVariantInfo() ) |
| 252 |
); |
| 253 |
if ( newContent[ 0 ].type === this.variantNode.getType() ) { |
| 254 |
this.getFragment().changeAttributes( { |
| 255 |
variantInfo: newContent[ 0 ].attributes.variantInfo |
| 256 |
} ); |
| 257 |
} else { |
| 258 |
this.getFragment().removeContent(); |
| 259 |
this.getFragment().insertContent( newContent ).select(); |
| 260 |
this.variantNode = this.getSelectedNode(); |
| 261 |
} |
| 262 |
surfaceModel.applyStaging(); |
| 263 |
} else { |
| 264 |
surfaceModel.popStaging(); |
| 265 |
} |
| 266 |
|
| 267 |
} ); |
| 268 |
}; |
| 269 |
|
| 270 |
|
| 271 |
|
| 272 |
|
| 273 |
|
| 274 |
|
| 275 |
|
| 276 |
|
| 277 |
|
| 278 |
|
| 279 |
|
| 280 |
|
| 281 |
ve.ui.MWLanguageVariantDisabledInspector = function VeUiMWLanguageVariantDisabledInspector() { |
| 282 |
ve.ui.MWLanguageVariantDisabledInspector.super.apply( this, arguments ); |
| 283 |
}; |
| 284 |
|
| 285 |
|
| 286 |
|
| 287 |
OO.inheritClass( ve.ui.MWLanguageVariantDisabledInspector, ve.ui.MWLanguageVariantInspector ); |
| 288 |
|
| 289 |
|
| 290 |
|
| 291 |
ve.ui.MWLanguageVariantDisabledInspector.static.name = 'mwLanguageVariant-disabled'; |
| 292 |
|
| 293 |
ve.ui.MWLanguageVariantDisabledInspector.static.title = OO.ui.deferMsg( |
| 294 |
'visualeditor-mwlanguagevariantinspector-title-disabled' |
| 295 |
); |
| 296 |
|
| 297 |
|
| 298 |
|
| 299 |
ve.ui.MWLanguageVariantDisabledInspector.prototype.initialize = function () { |
| 300 |
ve.ui.MWLanguageVariantDisabledInspector.super.prototype.initialize.call( this ); |
| 301 |
this.textTarget = this.createTextTarget( OO.ui.msg( |
| 302 |
'visualeditor-mwlanguagevariantinspector-disabled-placeholder' |
| 303 |
) ); |
| 304 |
this.form.$element.append( this.textTarget.$element ); |
| 305 |
}; |
| 306 |
|
| 307 |
ve.ui.MWLanguageVariantDisabledInspector.prototype.getDefaultVariantInfo = function () { |
| 308 |
return { disabled: { t: '' } }; |
| 309 |
}; |
| 310 |
|
| 311 |
ve.ui.MWLanguageVariantDisabledInspector.prototype.getSetupProcess = function ( data ) { |
| 312 |
return ve.ui.MWLanguageVariantDisabledInspector.super.prototype.getSetupProcess.call( this, data ).next( () => { |
| 313 |
const variantInfo = this.variantNode.getVariantInfo(); |
| 314 |
this.textTargetDoc = this.setupTextTargetDoc( |
| 315 |
this.textTarget, |
| 316 |
variantInfo.disabled.t |
| 317 |
); |
| 318 |
} ); |
| 319 |
}; |
| 320 |
|
| 321 |
ve.ui.MWLanguageVariantDisabledInspector.prototype.getContentFromInspector = function ( variantInfo ) { |
| 322 |
|
| 323 |
|
| 324 |
const type = this.variantNode.getType(); |
| 325 |
variantInfo.disabled.t = this.getHtmlForDoc( this.textTargetDoc ); |
| 326 |
return [ |
| 327 |
{ |
| 328 |
type: type, |
| 329 |
attributes: { variantInfo: variantInfo } |
| 330 |
}, |
| 331 |
{ |
| 332 |
type: '/' + type |
| 333 |
} |
| 334 |
]; |
| 335 |
}; |
| 336 |
|
| 337 |
ve.ui.MWLanguageVariantDisabledInspector.prototype.getReadyProcess = function ( data ) { |
| 338 |
return ve.ui.MWLanguageVariantDisabledInspector.super.prototype.getReadyProcess.call( this, data ) |
| 339 |
.next( () => { |
| 340 |
this.textTarget.focus(); |
| 341 |
} ); |
| 342 |
}; |
| 343 |
|
| 344 |
ve.ui.MWLanguageVariantDisabledInspector.prototype.getTeardownProcess = function ( data ) { |
| 345 |
return ve.ui.MWLanguageVariantDisabledInspector.super.prototype.getTeardownProcess.call( this, data ) |
| 346 |
.next( () => { |
| 347 |
|
| 348 |
this.textTarget.clear(); |
| 349 |
this.textTargetDoc = null; |
| 350 |
} ); |
| 351 |
}; |
| 352 |
|
| 353 |
|
| 354 |
|
| 355 |
|
| 356 |
|
| 357 |
|
| 358 |
|
| 359 |
|
| 360 |
|
| 361 |
|
| 362 |
ve.ui.MWLanguageVariantNameInspector = function VeUiMWLanguageVariantNameInspector() { |
| 363 |
ve.ui.MWLanguageVariantNameInspector.super.apply( this, arguments ); |
| 364 |
}; |
| 365 |
|
| 366 |
|
| 367 |
|
| 368 |
OO.inheritClass( ve.ui.MWLanguageVariantNameInspector, ve.ui.MWLanguageVariantInspector ); |
| 369 |
|
| 370 |
|
| 371 |
|
| 372 |
ve.ui.MWLanguageVariantNameInspector.static.name = 'mwLanguageVariant-name'; |
| 373 |
|
| 374 |
ve.ui.MWLanguageVariantNameInspector.static.title = OO.ui.deferMsg( |
| 375 |
'visualeditor-mwlanguagevariantinspector-title-name' |
| 376 |
); |
| 377 |
|
| 378 |
|
| 379 |
|
| 380 |
ve.ui.MWLanguageVariantNameInspector.prototype.initialize = function () { |
| 381 |
ve.ui.MWLanguageVariantNameInspector.super.prototype.initialize.call( this ); |
| 382 |
this.languageInput = new ve.ui.LanguageInputWidget( { |
| 383 |
dialogManager: this.manager.getSurface().getDialogs(), |
| 384 |
dirInput: 'none' |
| 385 |
} ); |
| 386 |
this.form.$element.append( this.languageInput.$element ); |
| 387 |
}; |
| 388 |
|
| 389 |
ve.ui.MWLanguageVariantNameInspector.prototype.getDefaultVariantInfo = function () { |
| 390 |
return { name: { t: mw.config.get( 'wgUserVariant' ) || 'en' } }; |
| 391 |
}; |
| 392 |
|
| 393 |
ve.ui.MWLanguageVariantNameInspector.prototype.getSetupProcess = function ( data ) { |
| 394 |
return ve.ui.MWLanguageVariantNameInspector.super.prototype.getSetupProcess.call( this, data ) |
| 395 |
.next( () => { |
| 396 |
const variantInfo = this.variantNode.getVariantInfo(); |
| 397 |
this.languageInput.setLangAndDir( |
| 398 |
variantInfo.name.t, |
| 399 |
'auto' |
| 400 |
); |
| 401 |
} ); |
| 402 |
}; |
| 403 |
|
| 404 |
ve.ui.MWLanguageVariantNameInspector.prototype.getContentFromInspector = function ( variantInfo ) { |
| 405 |
const type = this.variantNode.getType(); |
| 406 |
variantInfo.name.t = this.languageInput.getLang(); |
| 407 |
return [ |
| 408 |
{ |
| 409 |
type: type, |
| 410 |
attributes: { variantInfo: variantInfo } |
| 411 |
}, |
| 412 |
{ |
| 413 |
type: '/' + type |
| 414 |
} |
| 415 |
]; |
| 416 |
}; |
| 417 |
|
| 418 |
|
| 419 |
|
| 420 |
|
| 421 |
|
| 422 |
|
| 423 |
|
| 424 |
|
| 425 |
|
| 426 |
|
| 427 |
ve.ui.MWLanguageVariantFilterInspector = function VeUiMWLanguageVariantFilterInspector() { |
| 428 |
ve.ui.MWLanguageVariantFilterInspector.super.apply( this, arguments ); |
| 429 |
}; |
| 430 |
|
| 431 |
|
| 432 |
|
| 433 |
OO.inheritClass( ve.ui.MWLanguageVariantFilterInspector, ve.ui.MWLanguageVariantInspector ); |
| 434 |
|
| 435 |
|
| 436 |
|
| 437 |
ve.ui.MWLanguageVariantFilterInspector.static.name = 'mwLanguageVariant-filter'; |
| 438 |
|
| 439 |
ve.ui.MWLanguageVariantFilterInspector.static.title = OO.ui.deferMsg( |
| 440 |
'visualeditor-mwlanguagevariantinspector-title-filter' |
| 441 |
); |
| 442 |
|
| 443 |
|
| 444 |
|
| 445 |
ve.ui.MWLanguageVariantFilterInspector.prototype.initialize = function () { |
| 446 |
ve.ui.MWLanguageVariantFilterInspector.super.prototype.initialize.call( this ); |
| 447 |
this.textTarget = this.createTextTarget( OO.ui.msg( |
| 448 |
'visualeditor-mwlanguagevariantinspector-filter-text-placeholder' |
| 449 |
) ); |
| 450 |
|
| 451 |
this.langWidget = new OO.ui.TagMultiselectWidget( { |
| 452 |
allowArbitary: false, |
| 453 |
allowDisplayInvalidTags: true, |
| 454 |
allowedValues: ve.init.platform.getLanguageCodes().sort(), |
| 455 |
placeholder: OO.ui.msg( |
| 456 |
'visualeditor-mwlanguagevariantinspector-filter-langs-placeholder' |
| 457 |
), |
| 458 |
icon: 'language' |
| 459 |
} ); |
| 460 |
this.langWidget.createTagItemWidget = function ( data, label ) { |
| 461 |
const name = ve.init.platform.getLanguageName( data.toLowerCase() ); |
| 462 |
label = label || ( name ? ( name + ' (' + data + ')' ) : data ); |
| 463 |
return OO.ui.TagMultiselectWidget.prototype.createTagItemWidget.call( |
| 464 |
this, data, label |
| 465 |
); |
| 466 |
}; |
| 467 |
|
| 468 |
this.form.$element.append( |
| 469 |
new OO.ui.FieldLayout( this.langWidget, { |
| 470 |
align: 'top', |
| 471 |
label: OO.ui.msg( 'visualeditor-mwlanguagevariantinspector-filter-langs-label' ) |
| 472 |
} ).$element |
| 473 |
); |
| 474 |
this.form.$element.append( |
| 475 |
new OO.ui.FieldLayout( this.textTarget, { |
| 476 |
align: 'top', |
| 477 |
label: OO.ui.msg( 'visualeditor-mwlanguagevariantinspector-filter-text-label' ) |
| 478 |
} ).$element |
| 479 |
); |
| 480 |
}; |
| 481 |
|
| 482 |
ve.ui.MWLanguageVariantFilterInspector.prototype.getDefaultVariantInfo = function () { |
| 483 |
return { filter: { l: [ mw.config.get( 'wgUserVariant' ) ], t: '' } }; |
| 484 |
}; |
| 485 |
|
| 486 |
ve.ui.MWLanguageVariantFilterInspector.prototype.getSetupProcess = function ( data ) { |
| 487 |
return ve.ui.MWLanguageVariantFilterInspector.super.prototype.getSetupProcess.call( this, data ).next( () => { |
| 488 |
const variantInfo = this.variantNode.getVariantInfo(); |
| 489 |
this.textTargetDoc = this.setupTextTargetDoc( |
| 490 |
this.textTarget, |
| 491 |
variantInfo.filter.t |
| 492 |
); |
| 493 |
this.langWidget.setValue( variantInfo.filter.l ); |
| 494 |
} ); |
| 495 |
}; |
| 496 |
|
| 497 |
ve.ui.MWLanguageVariantFilterInspector.prototype.getContentFromInspector = function ( variantInfo ) { |
| 498 |
|
| 499 |
|
| 500 |
const type = this.variantNode.getType(); |
| 501 |
variantInfo.filter.t = this.getHtmlForDoc( this.textTargetDoc ); |
| 502 |
variantInfo.filter.l = this.langWidget.getValue(); |
| 503 |
return [ |
| 504 |
{ |
| 505 |
type: type, |
| 506 |
attributes: { variantInfo: variantInfo } |
| 507 |
}, |
| 508 |
{ |
| 509 |
type: '/' + type |
| 510 |
} |
| 511 |
]; |
| 512 |
}; |
| 513 |
|
| 514 |
ve.ui.MWLanguageVariantFilterInspector.prototype.getReadyProcess = function ( data ) { |
| 515 |
return ve.ui.MWLanguageVariantFilterInspector.super.prototype.getReadyProcess.call( this, data ) |
| 516 |
.next( () => { |
| 517 |
this.textTarget.focus(); |
| 518 |
} ); |
| 519 |
}; |
| 520 |
|
| 521 |
ve.ui.MWLanguageVariantFilterInspector.prototype.getTeardownProcess = function ( data ) { |
| 522 |
return ve.ui.MWLanguageVariantFilterInspector.super.prototype.getTeardownProcess.call( this, data ) |
| 523 |
.next( () => { |
| 524 |
|
| 525 |
this.langWidget.clearInput(); |
| 526 |
this.langWidget.clearItems(); |
| 527 |
this.textTarget.clear(); |
| 528 |
this.textTargetDoc = null; |
| 529 |
} ); |
| 530 |
}; |
| 531 |
|
| 532 |
|
| 533 |
|
| 534 |
|
| 535 |
|
| 536 |
|
| 537 |
|
| 538 |
|
| 539 |
|
| 540 |
|
| 541 |
ve.ui.MWLanguageVariantTwoWayInspector = function VeUiMWLanguageVariantTwoWayInspector() { |
| 542 |
ve.ui.MWLanguageVariantTwoWayInspector.super.apply( this, arguments ); |
| 543 |
}; |
| 544 |
|
| 545 |
|
| 546 |
|
| 547 |
OO.inheritClass( ve.ui.MWLanguageVariantTwoWayInspector, ve.ui.MWLanguageVariantInspector ); |
| 548 |
|
| 549 |
|
| 550 |
|
| 551 |
ve.ui.MWLanguageVariantTwoWayInspector.static.name = 'mwLanguageVariant-twoway'; |
| 552 |
|
| 553 |
ve.ui.MWLanguageVariantTwoWayInspector.static.title = OO.ui.deferMsg( |
| 554 |
'visualeditor-mwlanguagevariantinspector-title-twoway' |
| 555 |
); |
| 556 |
|
| 557 |
|
| 558 |
|
| 559 |
ve.ui.MWLanguageVariantTwoWayInspector.prototype.initialize = function () { |
| 560 |
ve.ui.MWLanguageVariantTwoWayInspector.super.prototype.initialize.call( this ); |
| 561 |
this.items = []; |
| 562 |
this.layout = new OO.ui.FieldsetLayout( { } ); |
| 563 |
this.form.$element.append( this.layout.$element ); |
| 564 |
|
| 565 |
this.addButton = new OO.ui.ButtonInputWidget( { |
| 566 |
label: OO.ui.msg( 'visualeditor-mwlanguagevariantinspector-twoway-add-button' ), |
| 567 |
icon: 'add' |
| 568 |
} ); |
| 569 |
this.form.$element.append( this.addButton.$element ); |
| 570 |
|
| 571 |
|
| 572 |
this.addButton.connect( this, { click: 'onAddButtonClick' } ); |
| 573 |
}; |
| 574 |
|
| 575 |
ve.ui.MWLanguageVariantTwoWayInspector.prototype.getDefaultVariantInfo = function () { |
| 576 |
return { twoway: [ { l: mw.config.get( 'wgUserVariant' ), t: '' } ] }; |
| 577 |
}; |
| 578 |
|
| 579 |
ve.ui.MWLanguageVariantTwoWayInspector.prototype.getSetupProcess = function ( data ) { |
| 580 |
return ve.ui.MWLanguageVariantTwoWayInspector.super.prototype.getSetupProcess.call( this, data ).next( () => { |
| 581 |
const variantInfo = this.variantNode.getVariantInfo(); |
| 582 |
this.layout.clearItems(); |
| 583 |
this.items = []; |
| 584 |
variantInfo.twoway.forEach( ( tw, idx ) => { |
| 585 |
this.items[ idx ] = this.createItem( tw.l, tw.t ); |
| 586 |
this.layout.addItems( [ this.items[ idx ].layout ] ); |
| 587 |
} ); |
| 588 |
} ); |
| 589 |
}; |
| 590 |
|
| 591 |
|
| 592 |
|
| 593 |
|
| 594 |
|
| 595 |
|
| 596 |
|
| 597 |
|
| 598 |
|
| 599 |
ve.ui.MWLanguageVariantTwoWayInspector.prototype.createItem = function ( lang, content ) { |
| 600 |
const languageInput = new ve.ui.LanguageInputWidget( { |
| 601 |
dialogManager: this.manager.getSurface().getDialogs(), |
| 602 |
dirInput: 'none' |
| 603 |
} ); |
| 604 |
const textTarget = this.createTextTarget( OO.ui.msg( |
| 605 |
'visualeditor-mwlanguagevariantinspector-twoway-text-placeholder' |
| 606 |
) ); |
| 607 |
const clearButton = new OO.ui.ButtonInputWidget( { |
| 608 |
icon: 'clear', |
| 609 |
title: OO.ui.deferMsg( |
| 610 |
'visualeditor-mwlanguagevariantinspector-twoway-clear-button' |
| 611 |
), |
| 612 |
framed: false |
| 613 |
} ); |
| 614 |
const layout = new OO.ui.FieldLayout( |
| 615 |
new OO.ui.Widget( { |
| 616 |
content: [ |
| 617 |
new OO.ui.ActionFieldLayout( |
| 618 |
languageInput, |
| 619 |
clearButton |
| 620 |
), |
| 621 |
textTarget |
| 622 |
] |
| 623 |
} ), {} |
| 624 |
); |
| 625 |
const item = { |
| 626 |
languageInput: languageInput, |
| 627 |
textTarget: textTarget, |
| 628 |
clearButton: clearButton, |
| 629 |
layout: layout |
| 630 |
}; |
| 631 |
|
| 632 |
|
| 633 |
item.textTargetDoc = this.setupTextTargetDoc( textTarget, content ); |
| 634 |
languageInput.setLangAndDir( lang, 'auto' ); |
| 635 |
clearButton.connect( this, { click: [ 'onClearButtonClick', item ] } ); |
| 636 |
return item; |
| 637 |
}; |
| 638 |
|
| 639 |
ve.ui.MWLanguageVariantTwoWayInspector.prototype.getContentFromInspector = function ( variantInfo ) { |
| 640 |
|
| 641 |
|
| 642 |
const type = this.variantNode.getType(); |
| 643 |
variantInfo.twoway = this.items.map( ( item ) => ( { |
| 644 |
l: item.languageInput.getLang(), |
| 645 |
t: this.getHtmlForDoc( item.textTargetDoc ) |
| 646 |
} ) ); |
| 647 |
return [ |
| 648 |
{ |
| 649 |
type: type, |
| 650 |
attributes: { variantInfo: variantInfo } |
| 651 |
}, |
| 652 |
{ |
| 653 |
type: '/' + type |
| 654 |
} |
| 655 |
]; |
| 656 |
}; |
| 657 |
|
| 658 |
|
| 659 |
|
| 660 |
|
| 661 |
ve.ui.MWLanguageVariantTwoWayInspector.prototype.onAddButtonClick = function () { |
| 662 |
const idx = this.items.length; |
| 663 |
this.items[ idx ] = this.createItem( mw.config.get( 'wgUserVariant' ), '' ); |
| 664 |
this.layout.addItems( [ this.items[ idx ].layout ] ); |
| 665 |
}; |
| 666 |
|
| 667 |
|
| 668 |
|
| 669 |
|
| 670 |
|
| 671 |
|
| 672 |
ve.ui.MWLanguageVariantTwoWayInspector.prototype.onClearButtonClick = function ( item ) { |
| 673 |
const idx = this.items.indexOf( item ); |
| 674 |
this.items.splice( idx, 1 ); |
| 675 |
this.layout.removeItems( [ item.layout ] ); |
| 676 |
item.clearButton.disconnect( this ); |
| 677 |
}; |
| 678 |
|
| 679 |
|
| 680 |
|
| 681 |
|
| 682 |
|
| 683 |
|
| 684 |
|
| 685 |
|
| 686 |
|
| 687 |
|
| 688 |
ve.ui.MWLanguageVariantOneWayInspector = function VeUiMWLanguageVariantOneWayInspector() { |
| 689 |
ve.ui.MWLanguageVariantOneWayInspector.super.apply( this, arguments ); |
| 690 |
}; |
| 691 |
|
| 692 |
|
| 693 |
|
| 694 |
OO.inheritClass( ve.ui.MWLanguageVariantOneWayInspector, ve.ui.MWLanguageVariantInspector ); |
| 695 |
|
| 696 |
|
| 697 |
|
| 698 |
ve.ui.MWLanguageVariantOneWayInspector.static.name = 'mwLanguageVariant-oneway'; |
| 699 |
|
| 700 |
ve.ui.MWLanguageVariantOneWayInspector.static.title = OO.ui.deferMsg( |
| 701 |
'visualeditor-mwlanguagevariantinspector-title-oneway' |
| 702 |
); |
| 703 |
|
| 704 |
|
| 705 |
|
| 706 |
ve.ui.MWLanguageVariantOneWayInspector.prototype.initialize = function () { |
| 707 |
ve.ui.MWLanguageVariantOneWayInspector.super.prototype.initialize.call( this ); |
| 708 |
this.items = []; |
| 709 |
this.layout = new OO.ui.FieldsetLayout( { } ); |
| 710 |
this.form.$element.append( this.layout.$element ); |
| 711 |
|
| 712 |
this.addButton = new OO.ui.ButtonInputWidget( { |
| 713 |
label: OO.ui.msg( 'visualeditor-mwlanguagevariantinspector-oneway-add-button' ), |
| 714 |
icon: 'add' |
| 715 |
} ); |
| 716 |
this.form.$element.append( this.addButton.$element ); |
| 717 |
|
| 718 |
|
| 719 |
this.addButton.connect( this, { click: 'onAddButtonClick' } ); |
| 720 |
}; |
| 721 |
|
| 722 |
ve.ui.MWLanguageVariantOneWayInspector.prototype.getDefaultVariantInfo = function () { |
| 723 |
return { oneway: [ { f: '', l: mw.config.get( 'wgUserVariant' ), t: '' } ] }; |
| 724 |
}; |
| 725 |
|
| 726 |
ve.ui.MWLanguageVariantOneWayInspector.prototype.getSetupProcess = function ( data ) { |
| 727 |
return ve.ui.MWLanguageVariantOneWayInspector.super.prototype.getSetupProcess.call( this, data ).next( () => { |
| 728 |
const variantInfo = this.variantNode.getVariantInfo(); |
| 729 |
this.layout.clearItems(); |
| 730 |
this.items = []; |
| 731 |
variantInfo.oneway.forEach( ( ow, idx ) => { |
| 732 |
this.items[ idx ] = this.createItem( ow.f, ow.l, ow.t ); |
| 733 |
this.layout.addItems( [ this.items[ idx ].layout ] ); |
| 734 |
} ); |
| 735 |
} ); |
| 736 |
}; |
| 737 |
|
| 738 |
|
| 739 |
|
| 740 |
|
| 741 |
|
| 742 |
|
| 743 |
|
| 744 |
|
| 745 |
|
| 746 |
|
| 747 |
ve.ui.MWLanguageVariantOneWayInspector.prototype.createItem = function ( from, lang, to ) { |
| 748 |
const fromTextTarget = this.createTextTarget( OO.ui.msg( |
| 749 |
'visualeditor-mwlanguagevariantinspector-oneway-from-text-placeholder' |
| 750 |
) ); |
| 751 |
const languageInput = new ve.ui.LanguageInputWidget( { |
| 752 |
dialogManager: this.manager.getSurface().getDialogs(), |
| 753 |
dirInput: 'none' |
| 754 |
} ); |
| 755 |
const toTextTarget = this.createTextTarget( OO.ui.msg( |
| 756 |
'visualeditor-mwlanguagevariantinspector-oneway-to-text-placeholder' |
| 757 |
) ); |
| 758 |
const clearButton = new OO.ui.ButtonInputWidget( { |
| 759 |
icon: 'clear', |
| 760 |
title: OO.ui.deferMsg( |
| 761 |
'visualeditor-mwlanguagevariantinspector-oneway-clear-button' |
| 762 |
), |
| 763 |
framed: false |
| 764 |
} ); |
| 765 |
const layout = new OO.ui.FieldLayout( |
| 766 |
new OO.ui.Widget( { |
| 767 |
content: [ |
| 768 |
new OO.ui.ActionFieldLayout( |
| 769 |
fromTextTarget, |
| 770 |
clearButton |
| 771 |
), |
| 772 |
languageInput, |
| 773 |
toTextTarget |
| 774 |
] |
| 775 |
} ), {} |
| 776 |
); |
| 777 |
const item = { |
| 778 |
fromTextTarget: fromTextTarget, |
| 779 |
languageInput: languageInput, |
| 780 |
toTextTarget: toTextTarget, |
| 781 |
clearButton: clearButton, |
| 782 |
layout: layout |
| 783 |
}; |
| 784 |
|
| 785 |
|
| 786 |
item.fromTextTargetDoc = this.setupTextTargetDoc( fromTextTarget, from ); |
| 787 |
item.toTextTargetDoc = this.setupTextTargetDoc( toTextTarget, to ); |
| 788 |
languageInput.setLangAndDir( lang, 'auto' ); |
| 789 |
clearButton.connect( this, { click: [ 'onClearButtonClick', item ] } ); |
| 790 |
return item; |
| 791 |
}; |
| 792 |
|
| 793 |
ve.ui.MWLanguageVariantOneWayInspector.prototype.getContentFromInspector = function ( variantInfo ) { |
| 794 |
|
| 795 |
|
| 796 |
const type = this.variantNode.getType(); |
| 797 |
variantInfo.oneway = this.items.map( ( item ) => ( { |
| 798 |
f: this.getHtmlForDoc( item.fromTextTargetDoc ), |
| 799 |
l: item.languageInput.getLang(), |
| 800 |
t: this.getHtmlForDoc( item.toTextTargetDoc ) |
| 801 |
} ) ); |
| 802 |
return [ |
| 803 |
{ |
| 804 |
type: type, |
| 805 |
attributes: { variantInfo: variantInfo } |
| 806 |
}, |
| 807 |
{ |
| 808 |
type: '/' + type |
| 809 |
} |
| 810 |
]; |
| 811 |
}; |
| 812 |
|
| 813 |
|
| 814 |
|
| 815 |
|
| 816 |
ve.ui.MWLanguageVariantOneWayInspector.prototype.onAddButtonClick = function () { |
| 817 |
const idx = this.items.length; |
| 818 |
this.items[ idx ] = this.createItem( '', mw.config.get( 'wgUserVariant' ), '' ); |
| 819 |
this.layout.addItems( [ this.items[ idx ].layout ] ); |
| 820 |
}; |
| 821 |
|
| 822 |
|
| 823 |
|
| 824 |
|
| 825 |
|
| 826 |
|
| 827 |
ve.ui.MWLanguageVariantOneWayInspector.prototype.onClearButtonClick = function ( item ) { |
| 828 |
const idx = this.items.indexOf( item ); |
| 829 |
this.items.splice( idx, 1 ); |
| 830 |
this.layout.removeItems( [ item.layout ] ); |
| 831 |
item.clearButton.disconnect( this ); |
| 832 |
}; |
| 833 |
|
| 834 |
|
| 835 |
|
| 836 |
ve.ui.windowFactory.register( ve.ui.MWLanguageVariantDisabledInspector ); |
| 837 |
ve.ui.windowFactory.register( ve.ui.MWLanguageVariantNameInspector ); |
| 838 |
ve.ui.windowFactory.register( ve.ui.MWLanguageVariantFilterInspector ); |
| 839 |
ve.ui.windowFactory.register( ve.ui.MWLanguageVariantTwoWayInspector ); |
| 840 |
ve.ui.windowFactory.register( ve.ui.MWLanguageVariantOneWayInspector ); |