| 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.mw.MobileArticleTarget = function VeInitMwMobileArticleTarget( overlay, config ) { |
| 25 |
this.overlay = overlay; |
| 26 |
this.$overlay = overlay.$el; |
| 27 |
this.$overlaySurface = overlay.$el.find( '.surface' ); |
| 28 |
|
| 29 |
config = config || {}; |
| 30 |
config.toolbarConfig = ve.extendObject( { |
| 31 |
actions: false |
| 32 |
}, config.toolbarConfig ); |
| 33 |
|
| 34 |
|
| 35 |
ve.init.mw.MobileArticleTarget.super.call( this, config ); |
| 36 |
|
| 37 |
|
| 38 |
this.$editableContent = $( '#mw-content-text' ); |
| 39 |
|
| 40 |
if ( config.section !== undefined ) { |
| 41 |
this.section = config.section; |
| 42 |
} |
| 43 |
|
| 44 |
|
| 45 |
this.$element.addClass( 've-init-mw-mobileArticleTarget ve-init-mobileTarget' ); |
| 46 |
}; |
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
OO.inheritClass( ve.init.mw.MobileArticleTarget, ve.init.mw.ArticleTarget ); |
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
ve.init.mw.MobileArticleTarget.static.toolbarGroups = [ |
| 55 |
|
| 56 |
{ |
| 57 |
name: 'history', |
| 58 |
include: [ 'undo' ] |
| 59 |
}, |
| 60 |
|
| 61 |
{ |
| 62 |
name: 'style', |
| 63 |
classes: [ 've-test-toolbar-style' ], |
| 64 |
type: 'list', |
| 65 |
icon: 'textStyle', |
| 66 |
title: OO.ui.deferMsg( 'visualeditor-toolbar-style-tooltip' ), |
| 67 |
label: OO.ui.deferMsg( 'visualeditor-toolbar-style-tooltip' ), |
| 68 |
invisibleLabel: true, |
| 69 |
include: [ { group: 'textStyle' }, 'language', 'clear' ], |
| 70 |
forceExpand: [ 'bold', 'italic', 'clear' ], |
| 71 |
promote: [ 'bold', 'italic' ], |
| 72 |
demote: [ 'strikethrough', 'code', 'underline', 'language', 'clear' ] |
| 73 |
}, |
| 74 |
|
| 75 |
{ |
| 76 |
name: 'link', |
| 77 |
include: [ 'link' ] |
| 78 |
}, |
| 79 |
|
| 80 |
{ |
| 81 |
name: 'reference' |
| 82 |
} |
| 83 |
]; |
| 84 |
|
| 85 |
ve.init.mw.MobileArticleTarget.static.trackingName = 'mobile'; |
| 86 |
|
| 87 |
|
| 88 |
ve.init.mw.MobileArticleTarget.static.platformType = 'phone'; |
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
ve.init.mw.MobileArticleTarget.prototype.deactivateSurfaceForToolbar = function () { |
| 96 |
|
| 97 |
ve.init.mw.MobileArticleTarget.super.prototype.deactivateSurfaceForToolbar.call( this ); |
| 98 |
|
| 99 |
if ( this.wasSurfaceActive && ve.init.platform.constructor.static.isIos() ) { |
| 100 |
this.prevScrollPosition = this.$scrollContainer.scrollTop(); |
| 101 |
} |
| 102 |
}; |
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
ve.init.mw.MobileArticleTarget.prototype.activateSurfaceForToolbar = function () { |
| 108 |
|
| 109 |
ve.init.mw.MobileArticleTarget.super.prototype.activateSurfaceForToolbar.call( this ); |
| 110 |
|
| 111 |
if ( this.wasSurfaceActive && ve.init.platform.constructor.static.isIos() ) { |
| 112 |
|
| 113 |
|
| 114 |
this.$scrollContainer.scrollTop( this.prevScrollPosition ); |
| 115 |
} |
| 116 |
}; |
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
ve.init.mw.MobileArticleTarget.prototype.clearSurfaces = function () { |
| 122 |
if ( ve.init.platform.constructor.static.isIos() && this.viewportZoomHandler ) { |
| 123 |
this.viewportZoomHandler.detach(); |
| 124 |
this.viewportZoomHandler = null; |
| 125 |
} |
| 126 |
|
| 127 |
ve.init.mw.MobileArticleTarget.super.prototype.clearSurfaces.call( this ); |
| 128 |
}; |
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
ve.init.mw.MobileArticleTarget.prototype.onContainerScroll = function () { |
| 134 |
|
| 135 |
const surfaceView = this.surface && this.surface.getView(), |
| 136 |
isActiveWithKeyboard = surfaceView && surfaceView.isFocused() && !surfaceView.isDeactivated(); |
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
clearTimeout( this.onContainerScrollTimer ); |
| 149 |
if ( !isActiveWithKeyboard ) { |
| 150 |
return; |
| 151 |
} |
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
|
| 157 |
let animateToolbarIntoView; |
| 158 |
this.onContainerScrollTimer = setTimeout( animateToolbarIntoView = () => { |
| 159 |
if ( this.toolbarAnimating ) { |
| 160 |
|
| 161 |
|
| 162 |
return; |
| 163 |
} |
| 164 |
|
| 165 |
const $header = this.overlay.$el.find( '.overlay-header-container' ); |
| 166 |
|
| 167 |
|
| 168 |
|
| 169 |
|
| 170 |
|
| 171 |
|
| 172 |
const pos = $header[ 0 ].getBoundingClientRect().top; |
| 173 |
if ( pos >= -1 ) { |
| 174 |
return; |
| 175 |
} |
| 176 |
|
| 177 |
|
| 178 |
|
| 179 |
const viewportHeight = 2000; |
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
const scrollY = document.body.scrollTop || document.documentElement.scrollTop; |
| 184 |
const scrollX = document.body.scrollLeft || document.documentElement.scrollLeft; |
| 185 |
|
| 186 |
|
| 187 |
this.toolbarAnimating = true; |
| 188 |
|
| 189 |
const $overlaySurface = this.$overlaySurface; |
| 190 |
|
| 191 |
|
| 192 |
$overlaySurface.css( 'transform', 'translateY( ' + viewportHeight + 'px )' ); |
| 193 |
window.scroll( scrollX, scrollY + viewportHeight ); |
| 194 |
|
| 195 |
|
| 196 |
$header.removeClass( 'toolbar-shown toolbar-shown-done' ); |
| 197 |
const headerHeight = $header[ 0 ].offsetHeight; |
| 198 |
const headerTranslateY = Math.max( -headerHeight, pos ); |
| 199 |
$header.css( 'transform', 'translateY( ' + headerTranslateY + 'px )' ); |
| 200 |
|
| 201 |
|
| 202 |
|
| 203 |
setTimeout( () => { |
| 204 |
|
| 205 |
$overlaySurface.css( 'transform', '' ); |
| 206 |
window.scroll( scrollX, scrollY ); |
| 207 |
|
| 208 |
|
| 209 |
$header.addClass( 'toolbar-shown' ).css( 'transform', '' ); |
| 210 |
setTimeout( () => { |
| 211 |
$header.addClass( 'toolbar-shown-done' ); |
| 212 |
|
| 213 |
this.toolbarAnimating = false; |
| 214 |
|
| 215 |
animateToolbarIntoView(); |
| 216 |
… |
| 217 |
|
| 218 |
}, 300 ); |
| 219 |
|
| 220 |
|
| 221 |
}, 50 ); |
| 222 |
}, 250 ); |
| 223 |
}; |
| 224 |
|
| 225 |
|
| 226 |
|
| 227 |
|
| 228 |
ve.init.mw.MobileArticleTarget.prototype.onSurfaceScroll = function () { |
| 229 |
if ( ve.init.platform.constructor.static.isIos() && this.getSurface() ) { |
| 230 |
|
| 231 |
|
| 232 |
|
| 233 |
const nativeSelection = this.getSurface().getView().nativeSelection; |
| 234 |
if ( nativeSelection.rangeCount && document.activeElement.contentEditable === 'true' ) { |
| 235 |
const range = nativeSelection.getRangeAt( 0 ); |
| 236 |
nativeSelection.removeAllRanges(); |
| 237 |
nativeSelection.addRange( range ); |
| 238 |
} |
| 239 |
} |
| 240 |
}; |
| 241 |
|
| 242 |
|
| 243 |
|
| 244 |
|
| 245 |
ve.init.mw.MobileArticleTarget.prototype.createSurface = function ( dmDoc, config ) { |
| 246 |
if ( this.overlay.isNewPage ) { |
| 247 |
config = ve.extendObject( { |
| 248 |
placeholder: this.overlay.options.placeholder |
| 249 |
}, config ); |
| 250 |
} |
| 251 |
|
| 252 |
|
| 253 |
const surface = ve.init.mw.MobileArticleTarget |
| 254 |
.super.prototype.createSurface.call( this, dmDoc, config ); |
| 255 |
|
| 256 |
surface.connect( this, { scroll: 'onSurfaceScroll' } ); |
| 257 |
|
| 258 |
return surface; |
| 259 |
}; |
| 260 |
|
| 261 |
|
| 262 |
|
| 263 |
|
| 264 |
ve.init.mw.MobileArticleTarget.prototype.getSurfaceClasses = function () { |
| 265 |
const classes = ve.init.mw.MobileArticleTarget.super.prototype.getSurfaceClasses.call( this ); |
| 266 |
return [ ...classes, 'content' ]; |
| 267 |
}; |
| 268 |
|
| 269 |
|
| 270 |
|
| 271 |
|
| 272 |
ve.init.mw.MobileArticleTarget.prototype.setSurface = function ( surface ) { |
| 273 |
const changed = surface !== this.surface; |
| 274 |
|
| 275 |
|
| 276 |
|
| 277 |
ve.init.mw.Target.super.prototype.setSurface.apply( this, arguments ); |
| 278 |
|
| 279 |
if ( changed ) { |
| 280 |
this.$overlaySurface.append( surface.$element ); |
| 281 |
} |
| 282 |
}; |
| 283 |
|
| 284 |
|
| 285 |
|
| 286 |
|
| 287 |
ve.init.mw.MobileArticleTarget.prototype.surfaceReady = function () { |
| 288 |
if ( this.teardownPromise ) { |
| 289 |
|
| 290 |
|
| 291 |
return; |
| 292 |
} |
| 293 |
|
| 294 |
|
| 295 |
|
| 296 |
this.getSurface().getView().deactivate( false ); |
| 297 |
|
| 298 |
|
| 299 |
ve.init.mw.MobileArticleTarget.super.prototype.surfaceReady.apply( this, arguments ); |
| 300 |
|
| 301 |
|
| 302 |
if ( this.getSurface().getModel().getSelection().isNull() ) { |
| 303 |
this.getSurface().getView().selectFirstSelectableContentOffset(); |
| 304 |
} |
| 305 |
|
| 306 |
this.events.trackActivationComplete(); |
| 307 |
|
| 308 |
if ( ve.init.platform.constructor.static.isIos() ) { |
| 309 |
if ( this.viewportZoomHandler ) { |
| 310 |
this.viewportZoomHandler.detach(); |
| 311 |
} |
| 312 |
this.viewportZoomHandler = new ve.init.mw.ViewportZoomHandler(); |
| 313 |
this.viewportZoomHandler.attach( this.getSurface() ); |
| 314 |
} |
| 315 |
}; |
| 316 |
|
| 317 |
|
| 318 |
|
| 319 |
|
| 320 |
ve.init.mw.MobileArticleTarget.prototype.afterSurfaceReady = function () { |
| 321 |
this.adjustContentPadding(); |
| 322 |
|
| 323 |
|
| 324 |
ve.init.mw.MobileArticleTarget.super.prototype.afterSurfaceReady.apply( this, arguments ); |
| 325 |
}; |
| 326 |
|
| 327 |
|
| 328 |
|
| 329 |
|
| 330 |
ve.init.mw.MobileArticleTarget.prototype.adjustContentPadding = function () { |
| 331 |
const surface = this.getSurface(), |
| 332 |
surfaceView = surface.getView(), |
| 333 |
toolbarHeight = this.getToolbar().$element[ 0 ].clientHeight; |
| 334 |
|
| 335 |
surface.setPadding( { |
| 336 |
top: toolbarHeight |
| 337 |
} ); |
| 338 |
surfaceView.$attachedRootNode.css( 'padding-top', toolbarHeight ); |
| 339 |
surface.$placeholder.css( 'padding-top', toolbarHeight ); |
| 340 |
surfaceView.emit( 'position' ); |
| 341 |
surface.scrollSelectionIntoView(); |
| 342 |
}; |
| 343 |
|
| 344 |
|
| 345 |
|
| 346 |
|
| 347 |
ve.init.mw.MobileArticleTarget.prototype.switchToFallbackWikitextEditor = function ( modified ) { |
| 348 |
let dataPromise; |
| 349 |
if ( modified ) { |
| 350 |
dataPromise = this.getWikitextDataPromiseForDoc( modified ).then( ( response ) => { |
| 351 |
const content = ve.getProp( response, 'visualeditoredit', 'content' ); |
| 352 |
return { text: content }; |
| 353 |
} ); |
| 354 |
} |
| 355 |
this.overlay.switchToSourceEditor( dataPromise ); |
| 356 |
return dataPromise; |
| 357 |
}; |
| 358 |
|
| 359 |
|
| 360 |
|
| 361 |
|
| 362 |
ve.init.mw.MobileArticleTarget.prototype.save = function () { |
| 363 |
|
| 364 |
const promise = ve.init.mw.MobileArticleTarget.super.prototype.save.apply( this, arguments ); |
| 365 |
|
| 366 |
this.overlay.log( { |
| 367 |
action: 'saveAttempt' |
| 368 |
} ); |
| 369 |
|
| 370 |
return promise; |
| 371 |
}; |
| 372 |
|
| 373 |
|
| 374 |
|
| 375 |
|
| 376 |
ve.init.mw.MobileArticleTarget.prototype.showSaveDialog = function () { |
| 377 |
|
| 378 |
ve.init.mw.MobileArticleTarget.super.prototype.showSaveDialog.apply( this, arguments ); |
| 379 |
|
| 380 |
this.overlay.log( { |
| 381 |
action: 'saveIntent' |
| 382 |
} ); |
| 383 |
}; |
| 384 |
|
| 385 |
|
| 386 |
|
| 387 |
|
| 388 |
ve.init.mw.MobileArticleTarget.prototype.replacePageContent = function ( |
| 389 |
html, categoriesHtml, displayTitle, lastModified |
| 390 |
) { |
| 391 |
|
| 392 |
ve.init.mw.MobileArticleTarget.super.prototype.replacePageContent.apply( this, arguments ); |
| 393 |
|
| 394 |
if ( lastModified ) { |
| 395 |
|
| 396 |
|
| 397 |
$( '.last-modified-bar' ).remove(); |
| 398 |
} |
| 399 |
}; |
| 400 |
|
| 401 |
|
| 402 |
|
| 403 |
|
| 404 |
ve.init.mw.MobileArticleTarget.prototype.saveComplete = function ( data ) { |
| 405 |
|
| 406 |
|
| 407 |
|
| 408 |
this.overlay.saved = true; |
| 409 |
|
| 410 |
|
| 411 |
ve.init.mw.MobileArticleTarget.super.prototype.saveComplete.apply( this, arguments ); |
| 412 |
|
| 413 |
const fragment = this.getSectionHashFromPage().slice( 1 ); |
| 414 |
|
| 415 |
this.overlay.sectionId = fragment; |
| 416 |
this.overlay.onSaveComplete( data.newrevid, data.tempusercreatedredirect, data.tempusercreated ); |
| 417 |
}; |
| 418 |
|
| 419 |
|
| 420 |
|
| 421 |
|
| 422 |
ve.init.mw.MobileArticleTarget.prototype.saveFail = function ( doc, saveData, code, data ) { |
| 423 |
|
| 424 |
ve.init.mw.MobileArticleTarget.super.prototype.saveFail.apply( this, arguments ); |
| 425 |
|
| 426 |
this.overlay.onSaveFailure( data ); |
| 427 |
}; |
| 428 |
|
| 429 |
|
| 430 |
|
| 431 |
|
| 432 |
ve.init.mw.MobileArticleTarget.prototype.tryTeardown = function () { |
| 433 |
this.overlay.onExitClick( $.Event() ); |
| 434 |
}; |
| 435 |
|
| 436 |
|
| 437 |
|
| 438 |
|
| 439 |
ve.init.mw.MobileArticleTarget.prototype.setupToolbar = function ( surface ) { |
| 440 |
const originalToolbarGroups = this.toolbarGroups; |
| 441 |
|
| 442 |
|
| 443 |
|
| 444 |
|
| 445 |
|
| 446 |
this.toolbarGroups = [ |
| 447 |
|
| 448 |
{ |
| 449 |
name: 'back', |
| 450 |
include: [ 'back' ] |
| 451 |
}, |
| 452 |
...this.toolbarGroups, |
| 453 |
{ |
| 454 |
name: 'editMode', |
| 455 |
type: 'list', |
| 456 |
icon: 'edit', |
| 457 |
title: ve.msg( 'visualeditor-mweditmode-tooltip' ), |
| 458 |
label: ve.msg( 'visualeditor-mweditmode-tooltip' ), |
| 459 |
invisibleLabel: true, |
| 460 |
include: [ { group: 'editMode' } ] |
| 461 |
}, |
| 462 |
{ |
| 463 |
name: 'save', |
| 464 |
type: 'bar', |
| 465 |
include: [ 'showSave' ] |
| 466 |
} |
| 467 |
]; |
| 468 |
|
| 469 |
|
| 470 |
ve.init.mw.MobileArticleTarget.super.prototype.setupToolbar.call( this, surface ); |
| 471 |
|
| 472 |
this.toolbarGroups = originalToolbarGroups; |
| 473 |
|
| 474 |
this.toolbar.$element.addClass( 've-init-mw-mobileArticleTarget-toolbar' ); |
| 475 |
this.toolbar.$popups.addClass( 've-init-mw-mobileArticleTarget-toolbar-popups' ); |
| 476 |
}; |
| 477 |
|
| 478 |
|
| 479 |
|
| 480 |
|
| 481 |
ve.init.mw.MobileArticleTarget.prototype.attachToolbar = function () { |
| 482 |
|
| 483 |
this.overlay.$el.find( '.overlay-header > .toolbar' ).append( this.toolbar.$element ); |
| 484 |
this.toolbar.initialize(); |
| 485 |
}; |
| 486 |
|
| 487 |
|
| 488 |
|
| 489 |
|
| 490 |
ve.init.mw.MobileArticleTarget.prototype.setupToolbarSaveButton = function () { |
| 491 |
this.toolbarSaveButton = this.toolbar.getToolGroupByName( 'save' ).items[ 0 ]; |
| 492 |
}; |
| 493 |
|
| 494 |
|
| 495 |
|
| 496 |
|
| 497 |
ve.init.mw.MobileArticleTarget.prototype.goToHeading = function ( headingNode ) { |
| 498 |
this.scrollToHeading( headingNode ); |
| 499 |
}; |
| 500 |
|
| 501 |
|
| 502 |
|
| 503 |
|
| 504 |
ve.init.mw.MobileArticleTarget.prototype.done = function () { |
| 505 |
this.getSurface().getModel().setNullSelection(); |
| 506 |
this.getSurface().getView().blur(); |
| 507 |
}; |
| 508 |
|
| 509 |
|
| 510 |
|
| 511 |
ve.init.mw.targetFactory.register( ve.init.mw.MobileArticleTarget ); |