| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
ve.ui.MobileContext = function VeUiMobileContext() { |
| 18 |
|
| 19 |
ve.ui.MobileContext.super.apply( this, arguments ); |
| 20 |
|
| 21 |
this.openingTimeout = null; |
| 22 |
|
| 23 |
this.closeButton = new OO.ui.ButtonWidget( { |
| 24 |
classes: [ 've-ui-mobileContext-close' ], |
| 25 |
framed: false, |
| 26 |
label: ve.msg( 'visualeditor-contextitemwidget-label-close' ), |
| 27 |
invisibleLabel: true, |
| 28 |
icon: 'close' |
| 29 |
} ); |
| 30 |
|
| 31 |
|
| 32 |
this.closeButton.connect( this, { click: 'onCloseButtonClick' } ); |
| 33 |
this.inspectors.connect( this, { |
| 34 |
setup: [ 'toggle', true ], |
| 35 |
teardown: [ 'toggle', false ] |
| 36 |
} ); |
| 37 |
|
| 38 |
|
| 39 |
this.$element.addClass( 've-ui-mobileContext' ); |
| 40 |
this.$group.addClass( 've-ui-mobileContext-menu' ); |
| 41 |
this.surface.getGlobalOverlay().$element.append( this.inspectors.$element ); |
| 42 |
}; |
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
OO.inheritClass( ve.ui.MobileContext, ve.ui.LinearContext ); |
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
ve.ui.MobileContext.static.isMobile = true; |
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
ve.ui.MobileContext.prototype.onCloseButtonClick = function () { |
| 58 |
this.hide(); |
| 59 |
ve.track( 'activity.mobileContext', { action: 'context-close' } ); |
| 60 |
}; |
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
ve.ui.MobileContext.prototype.setupMenuItems = function () { |
| 66 |
|
| 67 |
ve.ui.MobileContext.super.prototype.setupMenuItems.apply( this, arguments ); |
| 68 |
|
| 69 |
|
| 70 |
this.$group.prepend( this.closeButton.$element ); |
| 71 |
}; |
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
ve.ui.MobileContext.prototype.createInspectorWindowManager = function () { |
| 77 |
return new ve.ui.MobileWindowManager( this.surface, { |
| 78 |
factory: ve.ui.windowFactory, |
| 79 |
overlay: this.surface.getGlobalOverlay() |
| 80 |
} ); |
| 81 |
}; |
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
ve.ui.MobileContext.prototype.onInspectorOpening = function ( win, opening ) { |
| 90 |
const observer = this.surface.getView().surfaceObserver; |
| 91 |
|
| 92 |
this.inspector = win; |
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
observer.pollOnce(); |
| 98 |
observer.stopTimerLoop(); |
| 99 |
|
| 100 |
opening |
| 101 |
.then( ( opened ) => { |
| 102 |
opened.then( ( closed ) => { |
| 103 |
closed.always( () => { |
| 104 |
this.inspector = null; |
| 105 |
|
| 106 |
observer.startTimerLoop(); |
| 107 |
this.afterContextChange(); |
| 108 |
} ); |
| 109 |
} ); |
| 110 |
} ); |
| 111 |
}; |
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
ve.ui.MobileContext.prototype.toggleMenu = function ( show ) { |
| 117 |
show = show === undefined ? !this.choosing : !!show; |
| 118 |
|
| 119 |
if ( show !== this.choosing ) { |
| 120 |
if ( show ) { |
| 121 |
if ( this.hideMenuTimeout ) { |
| 122 |
clearTimeout( this.hideMenuTimeout ); |
| 123 |
|
| 124 |
ve.ui.MobileContext.super.prototype.toggleMenu.call( this, false ); |
| 125 |
} |
| 126 |
|
| 127 |
ve.ui.MobileContext.super.prototype.toggleMenu.call( this, true ); |
| 128 |
} else { |
| 129 |
this.hideMenuTimeout = setTimeout( () => { |
| 130 |
|
| 131 |
ve.ui.MobileContext.super.prototype.toggleMenu.call( this, false ); |
| 132 |
}, 100 ); |
| 133 |
} |
| 134 |
} |
| 135 |
|
| 136 |
return this; |
| 137 |
}; |
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
ve.ui.MobileContext.prototype.toggle = function ( show ) { |
| 143 |
show = show === undefined ? !this.visible : !!show; |
| 144 |
if ( show && !this.visible ) { |
| 145 |
const deferred = ve.createDeferred(); |
| 146 |
|
| 147 |
this.openingTimeout = setTimeout( () => { |
| 148 |
|
| 149 |
ve.ui.MobileContext.super.prototype.toggle.call( this, true ); |
| 150 |
this.emit( 'resize' ); |
| 151 |
deferred.resolve(); |
| 152 |
this.openingTimeout = null; |
| 153 |
}, 250 ); |
| 154 |
return deferred; |
| 155 |
} else { |
| 156 |
if ( this.openingTimeout ) { |
| 157 |
clearTimeout( this.openingTimeout ); |
| 158 |
this.openingTimeout = null; |
| 159 |
} |
| 160 |
setTimeout( () => { |
| 161 |
this.emit( 'resize' ); |
| 162 |
}, 100 ); |
| 163 |
|
| 164 |
return ve.ui.MobileContext.super.prototype.toggle.call( this, show ); |
| 165 |
} |
| 166 |
}; |
| 167 |
|
| 168 |
|
| 169 |
|
| 170 |
|
| 171 |
ve.ui.MobileContext.prototype.isVisible = function () { |
| 172 |
return this.visible || !!this.openingTimeout; |
| 173 |
}; |
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
|
| 178 |
ve.ui.MobileContext.prototype.isInspectable = function () { |
| 179 |
|
| 180 |
return ve.ui.MobileContext.super.prototype.isInspectable.call( this ) && |
| 181 |
|
| 182 |
!this.surface.getView().hasNativeCursorSelection(); |
| 183 |
}; |
| 184 |
|
| 185 |
|
| 186 |
|
| 187 |
|
| 188 |
ve.ui.MobileContext.prototype.getSurfacePadding = function () { |
| 189 |
return { bottom: this.$element[ 0 ].clientHeight }; |
| 190 |
}; |