Debian Codegraph @

extensions/VisualEditor/lib/ve/src/ui/contexts/ve.ui.MobileContext.js

raw symbols SCIP
1 /*!
2 * VisualEditor UserInterface MobileContext class.
3 *
4 * @copyright See AUTHORS.txt
5 */
6
7 /**
8 * UserInterface context that displays inspector full screen.
9 *
10 * @class
11 * @extends ve.ui.LinearContext
12 *
13 * @constructor
14 * @param {ve.ui.Surface} surface
15 * @param {Object} [config] Configuration options
16 */
17 ve.ui.MobileContext = function VeUiMobileContext() {
18 // Parent constructor
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 // Events
32 this.closeButton.connect( this, { click: 'onCloseButtonClick' } );
33 this.inspectors.connect( this, {
34 setup: [ 'toggle', true ],
35 teardown: [ 'toggle', false ]
36 } );
37
38 // Initialization
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 /* Inheritance */
45
46 OO.inheritClass( ve.ui.MobileContext, ve.ui.LinearContext );
47
48 /* Static Properties */
49
50 ve.ui.MobileContext.static.isMobile = true;
51
52 /* Methods */
53
54 /**
55 * Handle click events from the close button
56 */
57 ve.ui.MobileContext.prototype.onCloseButtonClick = function () {
58 this.hide();
59 ve.track( 'activity.mobileContext', { action: 'context-close' } );
60 };
61
62 /**
63 * @inheritdoc
64 */
65 ve.ui.MobileContext.prototype.setupMenuItems = function () {
66 // Parent method
67 ve.ui.MobileContext.super.prototype.setupMenuItems.apply( this, arguments );
68
69 // Ensure close button is at start after $group has been modified.
70 this.$group.prepend( this.closeButton.$element );
71 };
72
73 /**
74 * @inheritdoc
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 * Stripped down version of onInspectorOpening as we don't need to hide/show
85 * the context because the inspector is full screen.
86 *
87 * @inheritdoc
88 */
89 ve.ui.MobileContext.prototype.onInspectorOpening = function ( win, opening ) {
90 const observer = this.surface.getView().surfaceObserver;
91
92 this.inspector = win;
93
94 // Shut down the SurfaceObserver as soon as possible, so it doesn't get confused
95 // by the selection moving around in IE. Will be reenabled when inspector closes.
96 // FIXME this should be done in a nicer way, managed by the Surface classes
97 observer.pollOnce();
98 observer.stopTimerLoop();
99
100 opening
101 .then( ( opened ) => {
102 opened.then( ( closed ) => {
103 closed.always( () => {
104 this.inspector = null;
105 // Reenable observer
106 observer.startTimerLoop();
107 this.afterContextChange();
108 } );
109 } );
110 } );
111 };
112
113 /**
114 * @inheritdoc
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 // Ensure menu is torn down before setting up again.
124 ve.ui.MobileContext.super.prototype.toggleMenu.call( this, false );
125 }
126 // Parent method
127 ve.ui.MobileContext.super.prototype.toggleMenu.call( this, true );
128 } else {
129 this.hideMenuTimeout = setTimeout( () => {
130 // Parent method
131 ve.ui.MobileContext.super.prototype.toggleMenu.call( this, false );
132 }, 100 );
133 }
134 }
135
136 return this;
137 };
138
139 /**
140 * @inheritdoc
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 // Set opening flag immediately
147 this.openingTimeout = setTimeout( () => {
148 // Parent method
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 // Parent method
164 return ve.ui.MobileContext.super.prototype.toggle.call( this, show );
165 }
166 };
167
168 /**
169 * @inheritdoc
170 */
171 ve.ui.MobileContext.prototype.isVisible = function () {
172 return this.visible || !!this.openingTimeout;
173 };
174
175 /**
176 * @inheritdoc
177 */
178 ve.ui.MobileContext.prototype.isInspectable = function () {
179 // Parent method
180 return ve.ui.MobileContext.super.prototype.isInspectable.call( this ) &&
181 // Suppress context when virtual keyboard is visible
182 !this.surface.getView().hasNativeCursorSelection();
183 };
184
185 /**
186 * @inheritdoc
187 */
188 ve.ui.MobileContext.prototype.getSurfacePadding = function () {
189 return { bottom: this.$element[ 0 ].clientHeight };
190 };