| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
ve.init.Target = function VeInitTarget( config ) { |
| 25 |
config = config || {}; |
| 26 |
|
| 27 |
|
| 28 |
ve.init.Target.super.call( this, config ); |
| 29 |
|
| 30 |
|
| 31 |
OO.EventEmitter.call( this ); |
| 32 |
|
| 33 |
|
| 34 |
if ( config.register !== false ) { |
| 35 |
ve.init.target = this; |
| 36 |
} |
| 37 |
|
| 38 |
|
| 39 |
this.surfaces = []; |
| 40 |
this.surface = null; |
| 41 |
this.toolbar = null; |
| 42 |
this.toolbarConfig = config.toolbarConfig || {}; |
| 43 |
this.toolbarGroups = config.toolbarGroups || this.constructor.static.toolbarGroups; |
| 44 |
this.actionGroups = config.actionGroups || this.constructor.static.actionGroups; |
| 45 |
this.$scrollContainer = this.getScrollContainer(); |
| 46 |
this.$scrollListener = this.$scrollContainer.is( 'html, body' ) ? |
| 47 |
$( OO.ui.Element.static.getWindow( this.$scrollContainer[ 0 ] ) ) : |
| 48 |
this.$scrollContainer; |
| 49 |
|
| 50 |
this.toolbarScrollOffset = 0; |
| 51 |
this.activeToolbars = 0; |
| 52 |
this.wasSurfaceActive = null; |
| 53 |
this.teardownPromise = null; |
| 54 |
|
| 55 |
this.modes = config.modes || this.constructor.static.modes; |
| 56 |
this.setDefaultMode( config.defaultMode ); |
| 57 |
|
| 58 |
this.setupTriggerListeners(); |
| 59 |
|
| 60 |
|
| 61 |
this.$element.addClass( 've-init-target' ); |
| 62 |
|
| 63 |
if ( ve.init.platform.constructor.static.isIos() ) { |
| 64 |
this.$element.addClass( 've-init-target-ios' ); |
| 65 |
} |
| 66 |
|
| 67 |
|
| 68 |
this.onDocumentKeyDownHandler = this.onDocumentKeyDown.bind( this ); |
| 69 |
this.onDocumentKeyUpHandler = this.onDocumentKeyUp.bind( this ); |
| 70 |
this.onDocumentVisibilityChangeHandler = this.onDocumentVisibilityChange.bind( this ); |
| 71 |
this.onTargetKeyDownHandler = this.onTargetKeyDown.bind( this ); |
| 72 |
this.onContainerScrollHandler = this.onContainerScroll.bind( this ); |
| 73 |
this.bindHandlers(); |
| 74 |
}; |
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
OO.inheritClass( ve.init.Target, OO.ui.Element ); |
| 79 |
|
| 80 |
OO.mixinClass( ve.init.Target, OO.EventEmitter ); |
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
ve.init.Target.static.modes = [ 'visual' ]; |
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
ve.init.Target.static.toolbarGroups = [ |
| 111 |
{ |
| 112 |
name: 'history', |
| 113 |
include: [ { group: 'history' } ] |
| 114 |
}, |
| 115 |
{ |
| 116 |
name: 'format', |
| 117 |
header: OO.ui.deferMsg( 'visualeditor-toolbar-paragraph-format' ), |
| 118 |
title: OO.ui.deferMsg( 'visualeditor-toolbar-format-tooltip' ), |
| 119 |
type: 'menu', |
| 120 |
include: [ { group: 'format' } ], |
| 121 |
promote: [ 'paragraph' ], |
| 122 |
demote: [ 'preformatted', 'blockquote' ] |
| 123 |
}, |
| 124 |
{ |
| 125 |
name: 'style', |
| 126 |
include: [ 'bold', 'italic', 'moreTextStyle' ] |
| 127 |
}, |
| 128 |
{ |
| 129 |
name: 'link', |
| 130 |
include: [ 'link' ] |
| 131 |
}, |
| 132 |
{ |
| 133 |
name: 'structure', |
| 134 |
header: OO.ui.deferMsg( 'visualeditor-toolbar-structure' ), |
| 135 |
title: OO.ui.deferMsg( 'visualeditor-toolbar-structure' ), |
| 136 |
label: OO.ui.deferMsg( 'visualeditor-toolbar-structure' ), |
| 137 |
invisibleLabel: true, |
| 138 |
type: 'list', |
| 139 |
icon: 'listBullet', |
| 140 |
include: [ { group: 'structure' } ], |
| 141 |
demote: [ 'outdent', 'indent' ] |
| 142 |
}, |
| 143 |
{ |
| 144 |
name: 'insert', |
| 145 |
header: OO.ui.deferMsg( 'visualeditor-toolbar-insert' ), |
| 146 |
title: OO.ui.deferMsg( 'visualeditor-toolbar-insert' ), |
| 147 |
label: OO.ui.deferMsg( 'visualeditor-toolbar-insert' ), |
| 148 |
invisibleLabel: true, |
| 149 |
type: 'list', |
| 150 |
icon: 'add', |
| 151 |
include: '*' |
| 152 |
}, |
| 153 |
{ |
| 154 |
name: 'specialCharacter', |
| 155 |
include: [ 'specialCharacter' ] |
| 156 |
}, |
| 157 |
{ |
| 158 |
name: 'pageMenu', |
| 159 |
type: 'list', |
| 160 |
align: 'after', |
| 161 |
icon: 'menu', |
| 162 |
indicator: null, |
| 163 |
header: OO.ui.deferMsg( 'visualeditor-pagemenu-tooltip' ), |
| 164 |
title: OO.ui.deferMsg( 'visualeditor-pagemenu-tooltip' ), |
| 165 |
label: OO.ui.deferMsg( 'visualeditor-pagemenu-tooltip' ), |
| 166 |
invisibleLabel: true, |
| 167 |
include: [ { group: 'utility' }, { group: 'help' } ] |
| 168 |
} |
| 169 |
|
| 170 |
|
| 171 |
|
| 172 |
]; |
| 173 |
|
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
|
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
ve.init.Target.static.actionGroups = []; |
| 183 |
|
| 184 |
|
| 185 |
|
| 186 |
|
| 187 |
|
| 188 |
|
| 189 |
ve.init.Target.static.documentCommands = []; |
| 190 |
|
| 191 |
|
| 192 |
|
| 193 |
|
| 194 |
|
| 195 |
|
| 196 |
ve.init.Target.static.targetCommands = [ 'commandHelp', 'findAndReplace', 'findNext', 'findPrevious' ]; |
| 197 |
|
| 198 |
|
| 199 |
|
| 200 |
|
| 201 |
|
| 202 |
|
| 203 |
|
| 204 |
|
| 205 |
ve.init.Target.static.includeCommands = null; |
| 206 |
|
| 207 |
|
| 208 |
|
| 209 |
|
| 210 |
|
| 211 |
|
| 212 |
ve.init.Target.static.excludeCommands = []; |
| 213 |
|
| 214 |
|
| 215 |
|
| 216 |
|
| 217 |
|
| 218 |
|
| 219 |
|
| 220 |
|
| 221 |
|
| 222 |
|
| 223 |
|
| 224 |
ve.init.Target.static.importRules = { |
| 225 |
external: { |
| 226 |
blacklist: { |
| 227 |
|
| 228 |
|
| 229 |
|
| 230 |
'textStyle/span': true, |
| 231 |
'textStyle/font': true, |
| 232 |
|
| 233 |
alienInline: true, |
| 234 |
alienBlock: true, |
| 235 |
alienTableCell: true, |
| 236 |
comment: true, |
| 237 |
div: true |
| 238 |
}, |
| 239 |
|
| 240 |
htmlBlacklist: { |
| 241 |
|
| 242 |
unwrap: { |
| 243 |
fieldset: true, |
| 244 |
legend: true, |
| 245 |
|
| 246 |
main: true, |
| 247 |
nav: true, |
| 248 |
aside: true, |
| 249 |
|
| 250 |
|
| 251 |
'h1 b, h2 b, h3 b, h4 b, h5 b, h6 b': true, |
| 252 |
'h1 strong, h2 strong, h3 strong, h4 strong, h5 strong, h6 strong': true |
| 253 |
} |
| 254 |
}, |
| 255 |
nodeSanitization: true |
| 256 |
}, |
| 257 |
all: null |
| 258 |
}; |
| 259 |
|
| 260 |
|
| 261 |
|
| 262 |
|
| 263 |
|
| 264 |
|
| 265 |
|
| 266 |
|
| 267 |
|
| 268 |
|
| 269 |
|
| 270 |
ve.init.Target.static.createModelFromDom = function ( doc, mode, options ) { |
| 271 |
if ( mode === 'source' ) { |
| 272 |
return ve.dm.sourceConverter.getModelFromSourceText( doc, options ); |
| 273 |
} else { |
| 274 |
return ve.dm.converter.getModelFromDom( doc, options ); |
| 275 |
} |
| 276 |
}; |
| 277 |
|
| 278 |
|
| 279 |
|
| 280 |
|
| 281 |
|
| 282 |
|
| 283 |
|
| 284 |
|
| 285 |
|
| 286 |
ve.init.Target.static.parseDocument = function ( documentString, mode ) { |
| 287 |
if ( mode === 'source' ) { |
| 288 |
return documentString; |
| 289 |
} |
| 290 |
return ve.createDocumentFromHtml( documentString ); |
| 291 |
}; |
| 292 |
|
| 293 |
|
| 294 |
ve.init.Target.prototype.parseDocument = function () { |
| 295 |
return this.constructor.static.parseDocument.apply( this.constructor.static, arguments ); |
| 296 |
}; |
| 297 |
|
| 298 |
|
| 299 |
|
| 300 |
|
| 301 |
|
| 302 |
|
| 303 |
|
| 304 |
|
| 305 |
ve.init.Target.prototype.setDefaultMode = function ( defaultMode ) { |
| 306 |
|
| 307 |
if ( !this.isModeAvailable( defaultMode ) ) { |
| 308 |
if ( !this.defaultMode ) { |
| 309 |
|
| 310 |
defaultMode = this.modes[ 0 ]; |
| 311 |
} else { |
| 312 |
|
| 313 |
return; |
| 314 |
} |
| 315 |
} |
| 316 |
if ( defaultMode !== this.defaultMode ) { |
| 317 |
if ( this.defaultMode ) { |
| 318 |
|
| 319 |
|
| 320 |
this.$element.removeClass( 've-init-target-' + this.defaultMode ); |
| 321 |
} |
| 322 |
|
| 323 |
|
| 324 |
|
| 325 |
this.$element.addClass( 've-init-target-' + defaultMode ); |
| 326 |
this.defaultMode = defaultMode; |
| 327 |
} |
| 328 |
}; |
| 329 |
|
| 330 |
|
| 331 |
|
| 332 |
|
| 333 |
|
| 334 |
|
| 335 |
ve.init.Target.prototype.getDefaultMode = function () { |
| 336 |
return this.defaultMode; |
| 337 |
}; |
| 338 |
|
| 339 |
|
| 340 |
|
| 341 |
|
| 342 |
|
| 343 |
|
| 344 |
|
| 345 |
ve.init.Target.prototype.isModeAvailable = function ( mode ) { |
| 346 |
return this.modes.indexOf( mode ) !== -1; |
| 347 |
}; |
| 348 |
|
| 349 |
|
| 350 |
|
| 351 |
|
| 352 |
ve.init.Target.prototype.bindHandlers = function () { |
| 353 |
$( this.getElementDocument() ).on( { |
| 354 |
keydown: this.onDocumentKeyDownHandler, |
| 355 |
keyup: this.onDocumentKeyUpHandler, |
| 356 |
visibilitychange: this.onDocumentVisibilityChangeHandler |
| 357 |
} ); |
| 358 |
this.$element.on( 'keydown', this.onTargetKeyDownHandler ); |
| 359 |
this.$scrollListener[ 0 ].addEventListener( 'scroll', this.onContainerScrollHandler, { passive: true } ); |
| 360 |
}; |
| 361 |
|
| 362 |
|
| 363 |
|
| 364 |
|
| 365 |
ve.init.Target.prototype.unbindHandlers = function () { |
| 366 |
$( this.getElementDocument() ).off( { |
| 367 |
keydown: this.onDocumentKeyDownHandler, |
| 368 |
keyup: this.onDocumentKeyUpHandler, |
| 369 |
visibilitychange: this.onDocumentVisibilityChangeHandler |
| 370 |
} ); |
| 371 |
this.$element.off( 'keydown', this.onTargetKeyDownHandler ); |
| 372 |
this.$scrollListener[ 0 ].removeEventListener( 'scroll', this.onContainerScrollHandler ); |
| 373 |
}; |
| 374 |
|
| 375 |
|
| 376 |
|
| 377 |
|
| 378 |
|
| 379 |
|
| 380 |
ve.init.Target.prototype.teardown = function () { |
| 381 |
if ( !this.teardownPromise ) { |
| 382 |
this.unbindHandlers(); |
| 383 |
|
| 384 |
|
| 385 |
this.teardownPromise = this.teardownToolbar().then( this.clearSurfaces.bind( this ) ); |
| 386 |
} |
| 387 |
return this.teardownPromise; |
| 388 |
}; |
| 389 |
|
| 390 |
|
| 391 |
|
| 392 |
|
| 393 |
|
| 394 |
|
| 395 |
ve.init.Target.prototype.destroy = function () { |
| 396 |
return this.teardown().then( () => { |
| 397 |
this.$element.remove(); |
| 398 |
if ( ve.init.target === this ) { |
| 399 |
ve.init.target = null; |
| 400 |
} |
| 401 |
} ); |
| 402 |
}; |
| 403 |
|
| 404 |
|
| 405 |
|
| 406 |
|
| 407 |
ve.init.Target.prototype.setupTriggerListeners = function () { |
| 408 |
const surfaceOrSurfaceConfig = this.getSurface() || this.getSurfaceConfig(); |
| 409 |
this.documentTriggerListener = new ve.TriggerListener( this.constructor.static.documentCommands, surfaceOrSurfaceConfig.commandRegistry ); |
| 410 |
this.targetTriggerListener = new ve.TriggerListener( this.constructor.static.targetCommands, surfaceOrSurfaceConfig.commandRegistry ); |
| 411 |
}; |
| 412 |
|
| 413 |
|
| 414 |
|
| 415 |
|
| 416 |
|
| 417 |
|
| 418 |
ve.init.Target.prototype.getScrollContainer = function () { |
| 419 |
return $( OO.ui.Element.static.getClosestScrollableContainer( document.body ) ); |
| 420 |
}; |
| 421 |
|
| 422 |
|
| 423 |
|
| 424 |
|
| 425 |
ve.init.Target.prototype.onContainerScroll = function () { |
| 426 |
|
| 427 |
const toolbar = this.toolbar; |
| 428 |
|
| 429 |
if ( toolbar && toolbar.isFloatable() ) { |
| 430 |
const wasFloating = toolbar.isFloating(); |
| 431 |
const scrollTop = this.$scrollContainer.scrollTop(); |
| 432 |
|
| 433 |
if ( scrollTop + this.toolbarScrollOffset > toolbar.getElementOffset().top ) { |
| 434 |
toolbar.float(); |
| 435 |
} else { |
| 436 |
toolbar.unfloat(); |
| 437 |
} |
| 438 |
|
| 439 |
if ( toolbar.isFloating() !== wasFloating ) { |
| 440 |
|
| 441 |
|
| 442 |
toolbar.getItems().forEach( ( toolgroup ) => { |
| 443 |
if ( toolgroup instanceof OO.ui.PopupToolGroup && toolgroup.isActive() ) { |
| 444 |
toolgroup.position(); |
| 445 |
} |
| 446 |
} ); |
| 447 |
} |
| 448 |
} |
| 449 |
}; |
| 450 |
|
| 451 |
|
| 452 |
|
| 453 |
|
| 454 |
|
| 455 |
|
| 456 |
ve.init.Target.prototype.onDocumentKeyDown = function ( e ) { |
| 457 |
const trigger = new ve.ui.Trigger( e ); |
| 458 |
if ( trigger.isComplete() ) { |
| 459 |
const command = this.documentTriggerListener.getCommandByTrigger( trigger.toString() ); |
| 460 |
const surface = this.getSurface(); |
| 461 |
if ( surface && command && command.execute( surface, undefined, 'trigger' ) ) { |
| 462 |
e.preventDefault(); |
| 463 |
} |
| 464 |
} |
| 465 |
|
| 466 |
this.$element.toggleClass( 've-init-target-ctrl-meta-down', e.ctrlKey || e.metaKey ); |
| 467 |
}; |
| 468 |
|
| 469 |
|
| 470 |
|
| 471 |
|
| 472 |
|
| 473 |
|
| 474 |
ve.init.Target.prototype.onDocumentKeyUp = function ( e ) { |
| 475 |
this.$element.toggleClass( 've-init-target-ctrl-meta-down', e.ctrlKey || e.metaKey ); |
| 476 |
}; |
| 477 |
|
| 478 |
|
| 479 |
|
| 480 |
|
| 481 |
|
| 482 |
|
| 483 |
ve.init.Target.prototype.onDocumentVisibilityChange = function () { |
| 484 |
|
| 485 |
this.$element.removeClass( 've-init-target-ctrl-meta-down' ); |
| 486 |
}; |
| 487 |
|
| 488 |
|
| 489 |
|
| 490 |
|
| 491 |
|
| 492 |
|
| 493 |
ve.init.Target.prototype.onTargetKeyDown = function ( e ) { |
| 494 |
const trigger = new ve.ui.Trigger( e ); |
| 495 |
if ( trigger.isComplete() ) { |
| 496 |
const command = this.targetTriggerListener.getCommandByTrigger( trigger.toString() ); |
| 497 |
const surface = this.getSurface(); |
| 498 |
if ( surface && command && command.execute( surface, undefined, 'trigger' ) ) { |
| 499 |
e.preventDefault(); |
| 500 |
} |
| 501 |
} |
| 502 |
}; |
| 503 |
|
| 504 |
|
| 505 |
|
| 506 |
|
| 507 |
ve.init.Target.prototype.onToolbarResize = function () { |
| 508 |
if ( !this.getSurface() ) { |
| 509 |
return; |
| 510 |
} |
| 511 |
this.getSurface().setPadding( { |
| 512 |
top: this.getToolbar().getHeight() + this.toolbarScrollOffset |
| 513 |
} ); |
| 514 |
}; |
| 515 |
|
| 516 |
|
| 517 |
|
| 518 |
|
| 519 |
|
| 520 |
|
| 521 |
|
| 522 |
ve.init.Target.prototype.createTargetWidget = function ( config ) { |
| 523 |
return new ve.ui.TargetWidget( ve.extendObject( { |
| 524 |
toolbarGroups: this.toolbarGroups |
| 525 |
}, config ) ); |
| 526 |
}; |
| 527 |
|
| 528 |
|
| 529 |
|
| 530 |
|
| 531 |
|
| 532 |
|
| 533 |
|
| 534 |
|
| 535 |
ve.init.Target.prototype.createSurface = function ( dmDocOrSurface, config ) { |
| 536 |
return new ve.ui.Surface( this, dmDocOrSurface, this.getSurfaceConfig( config ) ); |
| 537 |
}; |
| 538 |
|
| 539 |
|
| 540 |
|
| 541 |
|
| 542 |
|
| 543 |
|
| 544 |
|
| 545 |
ve.init.Target.prototype.getSurfaceConfig = function ( config ) { |
| 546 |
return ve.extendObject( { |
| 547 |
$scrollContainer: this.$scrollContainer, |
| 548 |
$scrollListener: this.$scrollListener, |
| 549 |
commandRegistry: ve.ui.commandRegistry, |
| 550 |
sequenceRegistry: ve.ui.sequenceRegistry, |
| 551 |
dataTransferHandlerFactory: ve.ui.dataTransferHandlerFactory, |
| 552 |
includeCommands: this.constructor.static.includeCommands, |
| 553 |
excludeCommands: OO.simpleArrayUnion( |
| 554 |
this.constructor.static.excludeCommands, |
| 555 |
this.constructor.static.documentCommands, |
| 556 |
this.constructor.static.targetCommands |
| 557 |
), |
| 558 |
importRules: this.constructor.static.importRules |
| 559 |
}, config ); |
| 560 |
}; |
| 561 |
|
| 562 |
|
| 563 |
|
| 564 |
|
| 565 |
|
| 566 |
|
| 567 |
|
| 568 |
|
| 569 |
ve.init.Target.prototype.addSurface = function ( dmDocOrSurface, config ) { |
| 570 |
const surface = this.createSurface( dmDocOrSurface, ve.extendObject( { mode: this.getDefaultMode() }, config ) ); |
| 571 |
this.surfaces.push( surface ); |
| 572 |
surface.getView().connect( this, { |
| 573 |
focus: this.onSurfaceViewFocus.bind( this, surface ) |
| 574 |
} ); |
| 575 |
|
| 576 |
return surface; |
| 577 |
}; |
| 578 |
|
| 579 |
|
| 580 |
|
| 581 |
|
| 582 |
ve.init.Target.prototype.clearSurfaces = function () { |
| 583 |
|
| 584 |
|
| 585 |
this.surface = null; |
| 586 |
while ( this.surfaces.length ) { |
| 587 |
this.surfaces.pop().destroy(); |
| 588 |
} |
| 589 |
}; |
| 590 |
|
| 591 |
|
| 592 |
|
| 593 |
|
| 594 |
|
| 595 |
|
| 596 |
ve.init.Target.prototype.onSurfaceViewFocus = function ( surface ) { |
| 597 |
this.setSurface( surface ); |
| 598 |
}; |
| 599 |
|
| 600 |
|
| 601 |
|
| 602 |
|
| 603 |
|
| 604 |
|
| 605 |
ve.init.Target.prototype.setSurface = function ( surface ) { |
| 606 |
if ( OO.ui.isMobile() ) { |
| 607 |
|
| 608 |
|
| 609 |
this.toolbarConfig.$overlay = surface.getGlobalOverlay().$element; |
| 610 |
|
| 611 |
|
| 612 |
if ( this.toolbar ) { |
| 613 |
this.toolbar.$overlay = this.toolbarConfig.$overlay; |
| 614 |
this.toolbar.$overlay.append( this.toolbar.$popups ); |
| 615 |
} |
| 616 |
} |
| 617 |
|
| 618 |
if ( this.surfaces.indexOf( surface ) === -1 ) { |
| 619 |
throw new Error( 'Active surface must have been added first' ); |
| 620 |
} |
| 621 |
if ( surface !== this.surface ) { |
| 622 |
this.surface = surface; |
| 623 |
this.setupToolbar( surface ); |
| 624 |
} |
| 625 |
}; |
| 626 |
|
| 627 |
|
| 628 |
|
| 629 |
|
| 630 |
|
| 631 |
|
| 632 |
ve.init.Target.prototype.getSurface = function () { |
| 633 |
return this.surface; |
| 634 |
}; |
| 635 |
|
| 636 |
|
| 637 |
|
| 638 |
|
| 639 |
|
| 640 |
|
| 641 |
ve.init.Target.prototype.getToolbar = function () { |
| 642 |
if ( !this.toolbar ) { |
| 643 |
this.toolbar = new ve.ui.PositionedTargetToolbar( this, this.toolbarConfig ); |
| 644 |
} |
| 645 |
return this.toolbar; |
| 646 |
}; |
| 647 |
|
| 648 |
|
| 649 |
|
| 650 |
|
| 651 |
|
| 652 |
|
| 653 |
|
| 654 |
ve.init.Target.prototype.getActions = function () { |
| 655 |
OO.ui.warnDeprecation( 'Target#getActions: Use #getToolbar instead ' + |
| 656 |
'(actions toolbar has been merged into the normal toolbar)' ); |
| 657 |
if ( !this.actionsToolbar ) { |
| 658 |
this.actionsToolbar = this.getToolbar(); |
| 659 |
} |
| 660 |
return this.actionsToolbar; |
| 661 |
}; |
| 662 |
|
| 663 |
|
| 664 |
|
| 665 |
|
| 666 |
|
| 667 |
|
| 668 |
ve.init.Target.prototype.setupToolbar = function ( surface ) { |
| 669 |
const toolbar = this.getToolbar(); |
| 670 |
if ( this.actionGroups.length ) { |
| 671 |
|
| 672 |
if ( !this.actionsToolbar ) { |
| 673 |
this.actionsToolbar = this.getToolbar(); |
| 674 |
} |
| 675 |
} |
| 676 |
|
| 677 |
toolbar.connect( this, { |
| 678 |
resize: 'onToolbarResize', |
| 679 |
active: 'onToolbarActive' |
| 680 |
} ); |
| 681 |
|
| 682 |
if ( surface.nullSelectionOnBlur ) { |
| 683 |
toolbar.$element |
| 684 |
.on( 'focusin', () => { |
| 685 |
|
| 686 |
|
| 687 |
surface.getView().deactivate( true ); |
| 688 |
} ) |
| 689 |
.on( 'focusout', ( e ) => { |
| 690 |
const newFocusedElement = e.relatedTarget; |
| 691 |
if ( !OO.ui.contains( [ toolbar.$element[ 0 ], toolbar.$overlay[ 0 ] ], newFocusedElement, true ) ) { |
| 692 |
|
| 693 |
if ( OO.ui.contains( surface.getView().$element[ 0 ], newFocusedElement, true ) ) { |
| 694 |
|
| 695 |
|
| 696 |
const previousSelection = surface.getModel().getSelection(); |
| 697 |
surface.getView().activate(); |
| 698 |
if ( !previousSelection.isNull() ) { |
| 699 |
surface.getModel().setSelection( previousSelection ); |
| 700 |
} |
| 701 |
} else { |
| 702 |
|
| 703 |
|
| 704 |
|
| 705 |
surface.getView().blur(); |
| 706 |
} |
| 707 |
} |
| 708 |
} ); |
| 709 |
} |
| 710 |
|
| 711 |
this.actionGroups.forEach( ( group ) => { |
| 712 |
group.align = 'after'; |
| 713 |
} ); |
| 714 |
const groups = [ ...this.toolbarGroups, ...this.actionGroups ]; |
| 715 |
|
| 716 |
toolbar.setup( groups, surface ); |
| 717 |
this.attachToolbar(); |
| 718 |
requestAnimationFrame( this.onContainerScrollHandler ); |
| 719 |
}; |
| 720 |
|
| 721 |
|
| 722 |
|
| 723 |
|
| 724 |
|
| 725 |
|
| 726 |
ve.init.Target.prototype.deactivateSurfaceForToolbar = function () { |
| 727 |
const view = this.getSurface().getView(); |
| 728 |
|
| 729 |
this.wasSurfaceActive = !view.deactivated; |
| 730 |
if ( this.wasSurfaceActive ) { |
| 731 |
view.deactivate(); |
| 732 |
} |
| 733 |
}; |
| 734 |
|
| 735 |
|
| 736 |
|
| 737 |
|
| 738 |
|
| 739 |
|
| 740 |
ve.init.Target.prototype.activateSurfaceForToolbar = function () { |
| 741 |
const view = this.getSurface().getView(); |
| 742 |
|
| 743 |
if ( this.wasSurfaceActive && !( OO.ui.isMobile() && !view.getModel().getSelection().isCollapsed() ) ) { |
| 744 |
view.activate(); |
| 745 |
} |
| 746 |
}; |
| 747 |
|
| 748 |
|
| 749 |
|
| 750 |
|
| 751 |
|
| 752 |
|
| 753 |
ve.init.Target.prototype.onToolbarActive = function ( active ) { |
| 754 |
|
| 755 |
if ( active ) { |
| 756 |
this.activeToolbars++; |
| 757 |
if ( this.activeToolbars === 1 ) { |
| 758 |
this.deactivateSurfaceForToolbar(); |
| 759 |
} |
| 760 |
} else { |
| 761 |
this.activeToolbars--; |
| 762 |
if ( !this.activeToolbars ) { |
| 763 |
this.activateSurfaceForToolbar(); |
| 764 |
} |
| 765 |
} |
| 766 |
}; |
| 767 |
|
| 768 |
|
| 769 |
|
| 770 |
|
| 771 |
|
| 772 |
|
| 773 |
ve.init.Target.prototype.teardownToolbar = function () { |
| 774 |
if ( this.toolbar ) { |
| 775 |
this.toolbar.destroy(); |
| 776 |
this.toolbar = null; |
| 777 |
} |
| 778 |
if ( this.actionsToolbar ) { |
| 779 |
this.actionsToolbar = null; |
| 780 |
} |
| 781 |
return ve.createDeferred().resolve().promise(); |
| 782 |
}; |
| 783 |
|
| 784 |
|
| 785 |
|
| 786 |
|
| 787 |
ve.init.Target.prototype.attachToolbar = function () { |
| 788 |
const toolbar = this.getToolbar(); |
| 789 |
toolbar.$element.insertBefore( toolbar.getSurface().$element ); |
| 790 |
toolbar.initialize(); |
| 791 |
}; |