| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
ve.ui.Surface = function VeUiSurface( target, dataOrDocOrSurface, config ) { |
| 38 |
config = config || {}; |
| 39 |
|
| 40 |
|
| 41 |
ve.ui.Surface.super.call( this, config ); |
| 42 |
|
| 43 |
|
| 44 |
this.target = target; |
| 45 |
this.$scrollContainer = config.$scrollContainer || $( this.getClosestScrollableElementContainer() ); |
| 46 |
this.$scrollListener = config.$scrollListener || $( this.getElementWindow() ); |
| 47 |
this.inDialog = config.inDialog || ''; |
| 48 |
this.inTargetWidget = !!config.inTargetWidget; |
| 49 |
this.mode = config.mode; |
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
this.globalOverlay = new ve.ui.Overlay( { classes: [ 've-ui-overlay-global', 've-ui-overlay-global-' + ( OO.ui.isMobile() ? 'mobile' : 'desktop' ) ] } ); |
| 55 |
this.localOverlay = new ve.ui.Overlay( { classes: [ 've-ui-overlay-local' ] } ); |
| 56 |
this.$selections = $( '<div>' ).addClass( 've-ui-surface-selections' ); |
| 57 |
this.$blockers = $( '<div>' ); |
| 58 |
this.$controls = $( '<div>' ); |
| 59 |
this.$menus = $( '<div>' ); |
| 60 |
this.$placeholder = $( '<div>' ).addClass( 've-ui-surface-placeholder' ); |
| 61 |
this.commandRegistry = config.commandRegistry || ve.ui.commandRegistry; |
| 62 |
this.sequenceRegistry = config.sequenceRegistry || ve.ui.sequenceRegistry; |
| 63 |
this.dataTransferHandlerFactory = config.dataTransferHandlerFactory || ve.ui.dataTransferHandlerFactory; |
| 64 |
this.commands = OO.simpleArrayDifference( |
| 65 |
config.includeCommands || this.commandRegistry.getNames(), config.excludeCommands || [] |
| 66 |
); |
| 67 |
this.triggerListener = new ve.TriggerListener( this.commands, this.commandRegistry ); |
| 68 |
if ( dataOrDocOrSurface instanceof ve.dm.Surface ) { |
| 69 |
this.model = dataOrDocOrSurface; |
| 70 |
} else { |
| 71 |
let documentModel; |
| 72 |
if ( dataOrDocOrSurface instanceof ve.dm.Document ) { |
| 73 |
|
| 74 |
documentModel = dataOrDocOrSurface; |
| 75 |
} else if ( dataOrDocOrSurface instanceof ve.dm.ElementLinearData || Array.isArray( dataOrDocOrSurface ) ) { |
| 76 |
|
| 77 |
documentModel = new ve.dm.Document( dataOrDocOrSurface ); |
| 78 |
} else { |
| 79 |
|
| 80 |
documentModel = ve.dm.converter.getModelFromDom( dataOrDocOrSurface ); |
| 81 |
} |
| 82 |
this.model = this.createModel( documentModel, config.attachedRoot ); |
| 83 |
} |
| 84 |
this.view = this.createView( this.model ); |
| 85 |
this.dialogs = this.createDialogWindowManager(); |
| 86 |
this.importRules = config.importRules || {}; |
| 87 |
this.multiline = config.multiline !== false; |
| 88 |
this.context = this.createContext( { |
| 89 |
$popupContainer: config.$overlayContainer, |
| 90 |
popupPadding: config.overlayPadding |
| 91 |
} ); |
| 92 |
this.progresses = []; |
| 93 |
this.showProgressDebounced = ve.debounce( this.showProgress.bind( this ) ); |
| 94 |
this.scrollSelectionIntoViewDebounced = ve.debounce( this.scrollSelectionIntoView.bind( this ), 500 ); |
| 95 |
this.debugBar = null; |
| 96 |
this.placeholder = null; |
| 97 |
this.placeholderVisible = false; |
| 98 |
this.setPlaceholder( config.placeholder ); |
| 99 |
this.setReadOnly( !!config.readOnly ); |
| 100 |
this.nullSelectionOnBlur = config.nullSelectionOnBlur !== false; |
| 101 |
this.completion = new ve.ui.CompletionWidget( this ); |
| 102 |
|
| 103 |
|
| 104 |
this.toolbarHeight = 0; |
| 105 |
this.padding = { |
| 106 |
top: 0, |
| 107 |
right: 0, |
| 108 |
bottom: 0, |
| 109 |
left: 0 |
| 110 |
}; |
| 111 |
|
| 112 |
this.toolbarDialogs = {}; |
| 113 |
|
| 114 |
|
| 115 |
this.getModel().connect( this, { |
| 116 |
select: 'onModelSelect', |
| 117 |
blur: 'onModelBlur', |
| 118 |
focus: 'onModelFocus' |
| 119 |
} ); |
| 120 |
this.getModel().getDocument().connect( this, { transact: 'onDocumentTransact' } ); |
| 121 |
this.getView().connect( this, { |
| 122 |
position: 'onViewPosition', |
| 123 |
activation: 'onViewActivation' |
| 124 |
} ); |
| 125 |
this.getContext().connect( this, { resize: ve.debounce( this.onContextResize.bind( this ) ) } ); |
| 126 |
|
| 127 |
|
| 128 |
if ( OO.ui.isMobile() ) { |
| 129 |
|
| 130 |
this.globalOverlay.$element.append( this.context.$element ); |
| 131 |
} else { |
| 132 |
this.$menus.append( this.context.$element ); |
| 133 |
} |
| 134 |
this.$menus.append( this.completion.$element ); |
| 135 |
this.$element |
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
.addClass( 've-ui-surface ve-ui-surface-' + this.mode ) |
| 140 |
.append( this.view.$element ); |
| 141 |
if ( this.mode === 'source' ) { |
| 142 |
|
| 143 |
this.getView().$element.add( this.$placeholder ) |
| 144 |
.addClass( 've-ui-surface-source-font' ); |
| 145 |
} |
| 146 |
this.view.$element.after( this.localOverlay.$element ); |
| 147 |
this.localOverlay.$element.append( this.$selections, this.$blockers, this.$controls, this.$menus ); |
| 148 |
this.globalOverlay.$element.append( this.dialogs.$element ); |
| 149 |
}; |
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
OO.inheritClass( ve.ui.Surface, OO.ui.Widget ); |
| 154 |
|
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
|
| 168 |
|
| 169 |
|
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
|
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
|
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
|
| 186 |
|
| 187 |
|
| 188 |
|
| 189 |
|
| 190 |
|
| 191 |
|
| 192 |
|
| 193 |
|
| 194 |
|
| 195 |
|
| 196 |
|
| 197 |
|
| 198 |
|
| 199 |
|
| 200 |
|
| 201 |
|
| 202 |
|
| 203 |
|
| 204 |
ve.ui.Surface.prototype.destroy = function () { |
| 205 |
|
| 206 |
this.context.destroy(); |
| 207 |
this.dialogs.destroy(); |
| 208 |
for ( const side in this.toolbarDialogs ) { |
| 209 |
this.toolbarDialogs[ side ].destroy(); |
| 210 |
} |
| 211 |
this.view.destroy(); |
| 212 |
if ( this.debugBar ) { |
| 213 |
this.debugBar.destroy(); |
| 214 |
} |
| 215 |
|
| 216 |
|
| 217 |
this.dialogs.disconnect( this ); |
| 218 |
this.context.getInspectors().disconnect( this ); |
| 219 |
|
| 220 |
|
| 221 |
this.$element.remove(); |
| 222 |
this.globalOverlay.$element.remove(); |
| 223 |
|
| 224 |
|
| 225 |
this.emit( 'destroy' ); |
| 226 |
|
| 227 |
return this; |
| 228 |
}; |
| 229 |
|
| 230 |
|
| 231 |
|
| 232 |
|
| 233 |
|
| 234 |
|
| 235 |
|
| 236 |
|
| 237 |
|
| 238 |
|
| 239 |
ve.ui.Surface.prototype.initialize = function () { |
| 240 |
$( OO.ui.getTeleportTarget() ).append( this.globalOverlay.$element ); |
| 241 |
|
| 242 |
if ( ve.debug ) { |
| 243 |
this.setupDebugBar(); |
| 244 |
} |
| 245 |
|
| 246 |
|
| 247 |
|
| 248 |
|
| 249 |
this.$element.addClass( 've-ui-surface-dir-' + this.getDir() ); |
| 250 |
|
| 251 |
this.getView().initialize(); |
| 252 |
this.getModel().initialize(); |
| 253 |
|
| 254 |
this.emit( 'ready' ); |
| 255 |
return this; |
| 256 |
}; |
| 257 |
|
| 258 |
|
| 259 |
|
| 260 |
|
| 261 |
|
| 262 |
|
| 263 |
ve.ui.Surface.prototype.getTarget = function () { |
| 264 |
return this.target; |
| 265 |
}; |
| 266 |
|
| 267 |
|
| 268 |
|
| 269 |
|
| 270 |
|
| 271 |
|
| 272 |
ve.ui.Surface.prototype.getDom = function () { |
| 273 |
return this.getModel().getDom(); |
| 274 |
}; |
| 275 |
|
| 276 |
|
| 277 |
|
| 278 |
|
| 279 |
|
| 280 |
|
| 281 |
ve.ui.Surface.prototype.getHtml = function () { |
| 282 |
return this.getModel().getHtml(); |
| 283 |
}; |
| 284 |
|
| 285 |
|
| 286 |
|
| 287 |
|
| 288 |
|
| 289 |
|
| 290 |
ve.ui.Surface.prototype.getMode = function () { |
| 291 |
return this.mode; |
| 292 |
}; |
| 293 |
|
| 294 |
|
| 295 |
|
| 296 |
|
| 297 |
|
| 298 |
|
| 299 |
|
| 300 |
ve.ui.Surface.prototype.createContext = function ( config ) { |
| 301 |
return OO.ui.isMobile() ? new ve.ui.MobileContext( this, config ) : new ve.ui.DesktopContext( this, config ); |
| 302 |
}; |
| 303 |
|
| 304 |
|
| 305 |
|
| 306 |
|
| 307 |
|
| 308 |
|
| 309 |
ve.ui.Surface.prototype.createDialogWindowManager = function () { |
| 310 |
return OO.ui.isMobile() ? |
| 311 |
new ve.ui.MobileWindowManager( this, { |
| 312 |
factory: ve.ui.windowFactory, |
| 313 |
overlay: this.globalOverlay |
| 314 |
} ) : |
| 315 |
new ve.ui.SurfaceWindowManager( this, { factory: ve.ui.windowFactory } ); |
| 316 |
}; |
| 317 |
|
| 318 |
|
| 319 |
|
| 320 |
|
| 321 |
|
| 322 |
|
| 323 |
|
| 324 |
|
| 325 |
ve.ui.Surface.prototype.createModel = function ( doc, attachedRoot ) { |
| 326 |
return new ve.dm.Surface( doc, attachedRoot, { sourceMode: this.getMode() === 'source' } ); |
| 327 |
}; |
| 328 |
|
| 329 |
|
| 330 |
|
| 331 |
|
| 332 |
|
| 333 |
|
| 334 |
|
| 335 |
ve.ui.Surface.prototype.createView = function ( model ) { |
| 336 |
return new ve.ce.Surface( model, this ); |
| 337 |
}; |
| 338 |
|
| 339 |
|
| 340 |
|
| 341 |
|
| 342 |
ve.ui.Surface.prototype.setupDebugBar = function () { |
| 343 |
this.debugBar = new ve.ui.DebugBar( this ); |
| 344 |
this.$element.append( this.debugBar.$element ); |
| 345 |
}; |
| 346 |
|
| 347 |
|
| 348 |
|
| 349 |
|
| 350 |
|
| 351 |
|
| 352 |
|
| 353 |
ve.ui.Surface.prototype.getBoundingClientRect = function () { |
| 354 |
|
| 355 |
|
| 356 |
return this.$element[ 0 ].getClientRects()[ 0 ] || null; |
| 357 |
}; |
| 358 |
|
| 359 |
|
| 360 |
|
| 361 |
|
| 362 |
|
| 363 |
|
| 364 |
ve.ui.Surface.prototype.getViewportDimensions = function () { |
| 365 |
const rect = this.getBoundingClientRect(); |
| 366 |
|
| 367 |
if ( !rect ) { |
| 368 |
return null; |
| 369 |
} |
| 370 |
|
| 371 |
const top = Math.max( this.getPadding().top - rect.top, 0 ); |
| 372 |
const bottom = $( this.getElementWindow() ).height() - rect.top; |
| 373 |
|
| 374 |
return { |
| 375 |
top: top, |
| 376 |
left: rect.left, |
| 377 |
bottom: bottom, |
| 378 |
height: bottom - top |
| 379 |
}; |
| 380 |
}; |
| 381 |
|
| 382 |
|
| 383 |
|
| 384 |
|
| 385 |
|
| 386 |
|
| 387 |
ve.ui.Surface.prototype.getModel = function () { |
| 388 |
return this.model; |
| 389 |
}; |
| 390 |
|
| 391 |
|
| 392 |
|
| 393 |
|
| 394 |
|
| 395 |
|
| 396 |
ve.ui.Surface.prototype.getView = function () { |
| 397 |
return this.view; |
| 398 |
}; |
| 399 |
|
| 400 |
|
| 401 |
|
| 402 |
|
| 403 |
|
| 404 |
|
| 405 |
ve.ui.Surface.prototype.getContext = function () { |
| 406 |
return this.context; |
| 407 |
}; |
| 408 |
|
| 409 |
|
| 410 |
|
| 411 |
|
| 412 |
|
| 413 |
|
| 414 |
ve.ui.Surface.prototype.getDialogs = function () { |
| 415 |
return this.dialogs; |
| 416 |
}; |
| 417 |
|
| 418 |
|
| 419 |
|
| 420 |
|
| 421 |
|
| 422 |
|
| 423 |
|
| 424 |
ve.ui.Surface.prototype.getToolbarDialogs = function ( position ) { |
| 425 |
position = position || 'side'; |
| 426 |
this.toolbarDialogs[ position ] = this.toolbarDialogs[ position ] || |
| 427 |
new ve.ui.ToolbarDialogWindowManager( this, { |
| 428 |
factory: ve.ui.windowFactory, |
| 429 |
modal: false |
| 430 |
} ); |
| 431 |
return this.toolbarDialogs[ position ]; |
| 432 |
}; |
| 433 |
|
| 434 |
|
| 435 |
|
| 436 |
|
| 437 |
|
| 438 |
|
| 439 |
|
| 440 |
|
| 441 |
ve.ui.Surface.prototype.getLocalOverlay = function () { |
| 442 |
return this.localOverlay; |
| 443 |
}; |
| 444 |
|
| 445 |
|
| 446 |
|
| 447 |
|
| 448 |
|
| 449 |
|
| 450 |
|
| 451 |
|
| 452 |
ve.ui.Surface.prototype.getGlobalOverlay = function () { |
| 453 |
return this.globalOverlay; |
| 454 |
}; |
| 455 |
|
| 456 |
|
| 457 |
|
| 458 |
|
| 459 |
ve.ui.Surface.prototype.setDisabled = function ( disabled ) { |
| 460 |
if ( disabled ) { |
| 461 |
OO.ui.warnDeprecation( 'Surfaces can\'t be disabled, only set to readOnly' ); |
| 462 |
} |
| 463 |
}; |
| 464 |
|
| 465 |
|
| 466 |
|
| 467 |
|
| 468 |
|
| 469 |
|
| 470 |
|
| 471 |
ve.ui.Surface.prototype.setReadOnly = function ( readOnly ) { |
| 472 |
this.readOnly = !!readOnly; |
| 473 |
this.model.setReadOnly( readOnly ); |
| 474 |
this.view.setReadOnly( readOnly ); |
| 475 |
this.emit( 'readOnly', readOnly ); |
| 476 |
}; |
| 477 |
|
| 478 |
|
| 479 |
|
| 480 |
|
| 481 |
|
| 482 |
|
| 483 |
ve.ui.Surface.prototype.isReadOnly = function () { |
| 484 |
return this.readOnly; |
| 485 |
}; |
| 486 |
|
| 487 |
|
| 488 |
|
| 489 |
|
| 490 |
ve.ui.Surface.prototype.focus = function () { |
| 491 |
this.getView().focus(); |
| 492 |
}; |
| 493 |
|
| 494 |
|
| 495 |
|
| 496 |
|
| 497 |
|
| 498 |
|
| 499 |
ve.ui.Surface.prototype.onDocumentTransact = function () { |
| 500 |
if ( this.placeholder ) { |
| 501 |
this.updatePlaceholder(); |
| 502 |
} |
| 503 |
}; |
| 504 |
|
| 505 |
|
| 506 |
|
| 507 |
|
| 508 |
ve.ui.Surface.prototype.onModelSelect = function () { |
| 509 |
|
| 510 |
if ( this.getView().dragging ^ OO.ui.isMobile() ) { |
| 511 |
|
| 512 |
|
| 513 |
|
| 514 |
|
| 515 |
|
| 516 |
|
| 517 |
|
| 518 |
|
| 519 |
|
| 520 |
return; |
| 521 |
} |
| 522 |
const synchronizer = this.getModel().synchronizer; |
| 523 |
|
| 524 |
if ( !( synchronizer && synchronizer.applying ) ) { |
| 525 |
this.scrollSelectionIntoViewDebounced(); |
| 526 |
} |
| 527 |
}; |
| 528 |
|
| 529 |
|
| 530 |
|
| 531 |
|
| 532 |
|
| 533 |
|
| 534 |
|
| 535 |
|
| 536 |
|
| 537 |
|
| 538 |
|
| 539 |
|
| 540 |
|
| 541 |
ve.ui.Surface.prototype.scrollSelectionIntoView = function ( selectionModel, scrollConfig ) { |
| 542 |
selectionModel = selectionModel || this.getModel().getSelection(); |
| 543 |
|
| 544 |
const view = this.getView(), |
| 545 |
selectionView = view.getSelection( selectionModel ), |
| 546 |
isNative = selectionView.isNativeCursor(); |
| 547 |
|
| 548 |
|
| 549 |
|
| 550 |
let clientRect = selectionView.getSelectionFocusRect(); |
| 551 |
const surfaceRect = this.getBoundingClientRect(); |
| 552 |
if ( !clientRect || !surfaceRect ) { |
| 553 |
return; |
| 554 |
} |
| 555 |
|
| 556 |
|
| 557 |
clientRect = ve.translateRect( clientRect, surfaceRect.left, surfaceRect.top ); |
| 558 |
|
| 559 |
const padding = ve.copy( this.getPadding() ); |
| 560 |
|
| 561 |
let animate = true; |
| 562 |
if ( isNative ) { |
| 563 |
animate = false; |
| 564 |
if ( |
| 565 |
OO.ui.isMobile() && |
| 566 |
!selectionModel.isCollapsed() |
| 567 |
) { |
| 568 |
const profile = $.client.profile(); |
| 569 |
|
| 570 |
|
| 571 |
|
| 572 |
|
| 573 |
|
| 574 |
|
| 575 |
|
| 576 |
|
| 577 |
|
| 578 |
if ( profile.name === 'android' && profile.versionNumber >= 6 ) { |
| 579 |
padding.top += 60; |
| 580 |
} |
| 581 |
|
| 582 |
if ( profile.name === 'android' || profile.name === 'firefox' ) { |
| 583 |
padding.bottom += 30; |
| 584 |
} |
| 585 |
} |
| 586 |
} else { |
| 587 |
|
| 588 |
|
| 589 |
const viewportDimensions = this.getViewportDimensions(); |
| 590 |
if ( clientRect.height > viewportDimensions.height ) { |
| 591 |
return; |
| 592 |
} |
| 593 |
} |
| 594 |
|
| 595 |
|
| 596 |
padding.top += 5; |
| 597 |
padding.bottom += 5; |
| 598 |
padding.left += 5; |
| 599 |
padding.right += 5; |
| 600 |
|
| 601 |
ve.scrollIntoView( clientRect, ve.extendObject( { |
| 602 |
animate: animate, |
| 603 |
scrollContainer: this.$scrollContainer[ 0 ], |
| 604 |
padding: padding |
| 605 |
}, scrollConfig ) ).then( () => { |
| 606 |
if ( isNative ) { |
| 607 |
|
| 608 |
|
| 609 |
this.emit( 'scroll' ); |
| 610 |
} |
| 611 |
} ); |
| 612 |
}; |
| 613 |
|
| 614 |
|
| 615 |
ve.ui.Surface.prototype.scrollCursorIntoView = ve.ui.Surface.prototype.scrollSelectionIntoView; |
| 616 |
|
| 617 |
|
| 618 |
|
| 619 |
|
| 620 |
|
| 621 |
|
| 622 |
ve.ui.Surface.prototype.setPlaceholder = function ( placeholder ) { |
| 623 |
this.placeholder = placeholder; |
| 624 |
if ( this.placeholder ) { |
| 625 |
this.$placeholder.prependTo( this.$element ); |
| 626 |
this.updatePlaceholder(); |
| 627 |
const documentView = this.getView().getDocument(); |
| 628 |
this.$placeholder.prop( { |
| 629 |
dir: documentView.getDir(), |
| 630 |
lang: documentView.getLang() |
| 631 |
} ); |
| 632 |
} else { |
| 633 |
this.$placeholder.detach(); |
| 634 |
this.placeholderVisible = false; |
| 635 |
this.getView().$element.css( 'min-height', '' ); |
| 636 |
} |
| 637 |
this.getView().attachedRoot.$element.attr( 'aria-label', this.placeholder || null ); |
| 638 |
}; |
| 639 |
|
| 640 |
|
| 641 |
|
| 642 |
|
| 643 |
ve.ui.Surface.prototype.updatePlaceholder = function () { |
| 644 |
const hasContent = this.getModel().getDocument().data.hasContent(); |
| 645 |
|
| 646 |
this.$placeholder.toggleClass( 'oo-ui-element-hidden', hasContent ); |
| 647 |
this.placeholderVisible = !hasContent; |
| 648 |
if ( !hasContent ) { |
| 649 |
|
| 650 |
|
| 651 |
const firstNode = this.getView().attachedRoot.children[ 0 ]; |
| 652 |
let $wrapper; |
| 653 |
if ( firstNode ) { |
| 654 |
$wrapper = firstNode.$element.clone(); |
| 655 |
if ( ve.debug ) { |
| 656 |
|
| 657 |
$wrapper.removeAttr( 'style' ); |
| 658 |
} |
| 659 |
} else { |
| 660 |
$wrapper = $( '<p>' ); |
| 661 |
} |
| 662 |
this.$placeholder.empty().append( $wrapper.text( this.placeholder ) ); |
| 663 |
} else { |
| 664 |
this.getView().$element.css( 'min-height', '' ); |
| 665 |
} |
| 666 |
}; |
| 667 |
|
| 668 |
|
| 669 |
|
| 670 |
|
| 671 |
|
| 672 |
|
| 673 |
ve.ui.Surface.prototype.onViewPosition = function ( wasSynchronizing ) { |
| 674 |
const padding = {}; |
| 675 |
for ( const side in this.toolbarDialogs ) { |
| 676 |
ve.extendObject( padding, this.toolbarDialogs[ side ].getSurfacePadding() ); |
| 677 |
} |
| 678 |
if ( Object.keys( padding ).length ) { |
| 679 |
this.setPadding( padding ); |
| 680 |
this.adjustVisiblePadding(); |
| 681 |
|
| 682 |
if ( !wasSynchronizing ) { |
| 683 |
this.scrollSelectionIntoView(); |
| 684 |
} |
| 685 |
} |
| 686 |
if ( this.placeholderVisible ) { |
| 687 |
this.getView().$element.css( 'min-height', this.$placeholder.outerHeight() ); |
| 688 |
} |
| 689 |
}; |
| 690 |
|
| 691 |
|
| 692 |
|
| 693 |
|
| 694 |
|
| 695 |
|
| 696 |
ve.ui.Surface.prototype.getCommands = function () { |
| 697 |
return this.commands; |
| 698 |
}; |
| 699 |
|
| 700 |
|
| 701 |
|
| 702 |
|
| 703 |
|
| 704 |
|
| 705 |
|
| 706 |
|
| 707 |
|
| 708 |
|
| 709 |
|
| 710 |
ve.ui.Surface.prototype.execute = function ( triggerOrAction, method, ...args ) { |
| 711 |
return this.executeWithSource( triggerOrAction, method, false, ...args ); |
| 712 |
}; |
| 713 |
|
| 714 |
|
| 715 |
|
| 716 |
|
| 717 |
|
| 718 |
|
| 719 |
|
| 720 |
|
| 721 |
|
| 722 |
|
| 723 |
ve.ui.Surface.prototype.executeWithSource = function ( triggerOrAction, method, source, ...args ) { |
| 724 |
if ( triggerOrAction instanceof ve.ui.Trigger ) { |
| 725 |
const command = this.triggerListener.getCommandByTrigger( triggerOrAction.toString() ); |
| 726 |
if ( command ) { |
| 727 |
|
| 728 |
return command.execute( this, false, source ); |
| 729 |
} |
| 730 |
} else if ( typeof triggerOrAction === 'string' && typeof method === 'string' ) { |
| 731 |
|
| 732 |
if ( ve.ui.actionFactory.doesActionSupportMethod( triggerOrAction, method ) ) { |
| 733 |
|
| 734 |
const obj = ve.ui.actionFactory.create( triggerOrAction, this, source ); |
| 735 |
const ret = obj[ method ]( ...args ); |
| 736 |
return ret === undefined || !!ret; |
| 737 |
} |
| 738 |
} |
| 739 |
return false; |
| 740 |
}; |
| 741 |
|
| 742 |
|
| 743 |
|
| 744 |
|
| 745 |
|
| 746 |
|
| 747 |
|
| 748 |
ve.ui.Surface.prototype.executeCommand = function ( commandName ) { |
| 749 |
const command = this.commandRegistry.lookup( commandName ); |
| 750 |
if ( command ) { |
| 751 |
return command.execute( this ); |
| 752 |
} |
| 753 |
return false; |
| 754 |
}; |
| 755 |
|
| 756 |
|
| 757 |
ve.ui.Surface.prototype.setToolbarHeight = function ( toolbarHeight ) { |
| 758 |
this.setPadding( { top: toolbarHeight } ); |
| 759 |
}; |
| 760 |
|
| 761 |
|
| 762 |
|
| 763 |
|
| 764 |
|
| 765 |
|
| 766 |
|
| 767 |
|
| 768 |
|
| 769 |
|
| 770 |
|
| 771 |
|
| 772 |
|
| 773 |
|
| 774 |
|
| 775 |
|
| 776 |
|
| 777 |
|
| 778 |
|
| 779 |
ve.ui.Surface.prototype.setPadding = function ( padding ) { |
| 780 |
ve.extendObject( this.padding, padding ); |
| 781 |
|
| 782 |
this.toolbarHeight = this.padding.top; |
| 783 |
}; |
| 784 |
|
| 785 |
|
| 786 |
|
| 787 |
|
| 788 |
|
| 789 |
|
| 790 |
|
| 791 |
|
| 792 |
|
| 793 |
|
| 794 |
|
| 795 |
|
| 796 |
|
| 797 |
|
| 798 |
ve.ui.Surface.prototype.getPadding = function () { |
| 799 |
return this.padding; |
| 800 |
}; |
| 801 |
|
| 802 |
|
| 803 |
|
| 804 |
|
| 805 |
ve.ui.Surface.prototype.onContextResize = function () { |
| 806 |
const padding = this.context.getSurfacePadding(); |
| 807 |
if ( padding ) { |
| 808 |
this.setPadding( padding ); |
| 809 |
this.adjustVisiblePadding(); |
| 810 |
this.scrollSelectionIntoView(); |
| 811 |
} |
| 812 |
}; |
| 813 |
|
| 814 |
|
| 815 |
|
| 816 |
|
| 817 |
ve.ui.Surface.prototype.onModelBlur = function () { |
| 818 |
this.adjustVisiblePadding(); |
| 819 |
}; |
| 820 |
|
| 821 |
|
| 822 |
|
| 823 |
|
| 824 |
ve.ui.Surface.prototype.onModelFocus = function () { |
| 825 |
this.adjustVisiblePadding(); |
| 826 |
}; |
| 827 |
|
| 828 |
|
| 829 |
|
| 830 |
|
| 831 |
ve.ui.Surface.prototype.onViewActivation = function () { |
| 832 |
this.adjustVisiblePadding(); |
| 833 |
}; |
| 834 |
|
| 835 |
|
| 836 |
|
| 837 |
|
| 838 |
|
| 839 |
ve.ui.Surface.prototype.adjustVisiblePadding = function () { |
| 840 |
if ( OO.ui.isMobile() && !this.inTargetWidget ) { |
| 841 |
const keyboardShown = this.getView().hasNativeCursorSelection(); |
| 842 |
let bottom; |
| 843 |
if ( ve.init.platform.constructor.static.isIos() && keyboardShown ) { |
| 844 |
|
| 845 |
|
| 846 |
|
| 847 |
bottom = $( window ).height() - this.getPadding().top; |
| 848 |
} else { |
| 849 |
|
| 850 |
bottom = this.getPadding().bottom; |
| 851 |
} |
| 852 |
this.getView().$attachedRootNode.css( 'padding-bottom', bottom ); |
| 853 |
this.scrollSelectionIntoView(); |
| 854 |
} |
| 855 |
}; |
| 856 |
|
| 857 |
|
| 858 |
|
| 859 |
|
| 860 |
|
| 861 |
|
| 862 |
|
| 863 |
|
| 864 |
|
| 865 |
ve.ui.Surface.prototype.createProgress = function ( progressCompletePromise, label, nonCancellable ) { |
| 866 |
const progressBarDeferred = ve.createDeferred(); |
| 867 |
|
| 868 |
this.progresses.push( { |
| 869 |
label: label, |
| 870 |
cancellable: !nonCancellable, |
| 871 |
progressCompletePromise: progressCompletePromise, |
| 872 |
progressBarDeferred: progressBarDeferred |
| 873 |
} ); |
| 874 |
|
| 875 |
this.showProgressDebounced(); |
| 876 |
|
| 877 |
return progressBarDeferred.promise(); |
| 878 |
}; |
| 879 |
|
| 880 |
ve.ui.Surface.prototype.showProgress = function () { |
| 881 |
const progresses = this.progresses; |
| 882 |
|
| 883 |
this.dialogs.openWindow( 'progress', { progresses: progresses, $returnFocusTo: null } ); |
| 884 |
this.progresses = []; |
| 885 |
}; |
| 886 |
|
| 887 |
|
| 888 |
|
| 889 |
|
| 890 |
|
| 891 |
|
| 892 |
ve.ui.Surface.prototype.getImportRules = function () { |
| 893 |
return this.importRules; |
| 894 |
}; |
| 895 |
|
| 896 |
|
| 897 |
|
| 898 |
|
| 899 |
|
| 900 |
|
| 901 |
ve.ui.Surface.prototype.isMultiline = function () { |
| 902 |
return this.multiline; |
| 903 |
}; |
| 904 |
|
| 905 |
|
| 906 |
|
| 907 |
|
| 908 |
|
| 909 |
|
| 910 |
ve.ui.Surface.prototype.getDir = function () { |
| 911 |
return this.$element.css( 'direction' ); |
| 912 |
}; |
| 913 |
|
| 914 |
|
| 915 |
|
| 916 |
|
| 917 |
|
| 918 |
|
| 919 |
ve.ui.Surface.prototype.getInDialog = function () { |
| 920 |
return this.inDialog; |
| 921 |
}; |