1 | /** |
||
2 | * [Siteapp] - multi-purpose frontend application |
||
3 | * |
||
4 | * Siteapp ui object |
||
5 | * |
||
6 | * @package [Siteapp] |
||
7 | * @subpackage [Siteapp] UI |
||
8 | * @author Björn Bartels <[email protected]> |
||
9 | * @link https://gitlab.bjoernbartels.earth/groups/themes |
||
10 | * @license http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0 |
||
11 | * @copyright copyright (c) 2016 Björn Bartels <[email protected]> |
||
12 | * |
||
13 | * @namespace Siteapp |
||
14 | * @module Siteapp.Ui |
||
15 | */ |
||
16 | import ModuleManager from '../module/siteapp.moduleManager'; |
||
17 | import AdapterManager from '../sys/siteapp.adapterManager'; |
||
18 | import Paneladapter from './siteapp.paneladapter'; |
||
19 | import Screenlayer from './siteapp.screenlayer'; |
||
20 | |||
21 | |||
22 | const Siteapp_ModuleManager_DEFAULTS = { |
||
0 ignored issues
–
show
Unused Code
introduced
by
![]() |
|||
23 | |||
24 | /* UI modes: 'flow', 'window', false */ |
||
25 | mode : 'flow', |
||
0 ignored issues
–
show
|
|||
26 | |||
27 | /* UI modes: 'flow', 'window', false */ |
||
28 | mode : 'flow', |
||
29 | |||
30 | /* disable UI link redirection, true = same as mode = 'none' */ |
||
31 | disableUiNavigation: false, |
||
32 | |||
33 | /* disable fullscreen mode entirely */ |
||
34 | disableFullscreen: false, |
||
35 | |||
36 | /* enable background modes */ |
||
37 | enableBackground : true, |
||
38 | enableBackgroundAnimation : true, |
||
39 | enableBackgroundNightDay : true, |
||
40 | |||
41 | /* screen adapters */ |
||
42 | screenAdapters: [ |
||
43 | 'default' |
||
44 | ] |
||
45 | |||
46 | }; |
||
47 | |||
48 | const Ui = class Ui extends ModuleManager { |
||
0 ignored issues
–
show
The variable
ModuleManager seems to be never declared. If this is a global, consider adding a /** global: ModuleManager */ comment.
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed. To learn more about declaring variables in Javascript, see the MDN. ![]() |
|||
49 | |||
50 | |||
51 | /** |
||
52 | * Init-wrapper for a layer to connect to UI manager. |
||
53 | * Calls 'initialze' and sets up special 'Ui' references. |
||
54 | * |
||
55 | * For example, in your module's (aka 'layer's) constructor/init, |
||
56 | * instead of... |
||
57 | * ``` |
||
58 | * [Siteapp].initialzeModule(this); |
||
59 | * ``` |
||
60 | * do... |
||
61 | * ``` |
||
62 | * [Siteapp].Ui.connectLayer(this); |
||
63 | * ``` |
||
64 | */ |
||
65 | connectLayer ( layer2connect, name ) { |
||
66 | |||
67 | // set up further 'Ui' references, if any... |
||
68 | this.initialize( layer2connect, name ); |
||
69 | } |
||
70 | |||
71 | disconnectLayer ( layer2disconnect ) { |
||
72 | |||
73 | |||
74 | // remove 'Ui' references, if any... |
||
75 | this.destroy( layer2disconnect ); |
||
76 | |||
77 | } |
||
78 | |||
79 | focusLayer ( layer2focus ) { |
||
80 | if ( (layer2focus instanceof Siteapp.UiManager.Screenlayer) ) { |
||
0 ignored issues
–
show
The variable
Siteapp seems to be never declared. If this is a global, consider adding a /** global: Siteapp */ comment.
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed. To learn more about declaring variables in Javascript, see the MDN. ![]() |
|||
81 | |||
82 | this.unfocusLayers(); |
||
83 | |||
84 | layer2focus.setActive(); |
||
85 | layer2focus.$element.css({zIndex: 1}); |
||
86 | |||
87 | } |
||
88 | } |
||
89 | |||
90 | unfocusLayers ( ) { |
||
91 | this.deactivateLayers(); |
||
92 | |||
93 | this.layers.map((idx, layer) => { |
||
94 | |||
95 | if ( (layer instanceof Siteapp.UiManager.Screenlayer) ) { |
||
0 ignored issues
–
show
The variable
Siteapp seems to be never declared. If this is a global, consider adding a /** global: Siteapp */ comment.
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed. To learn more about declaring variables in Javascript, see the MDN. ![]() |
|||
96 | layer.setInactive(); |
||
97 | layer.$element.css({zIndex: -1}); |
||
98 | } |
||
99 | |||
100 | }); |
||
101 | } |
||
102 | |||
103 | activateLayer ( layer2activate ) { |
||
104 | if ( (layer2activate instanceof Siteapp.UiManager.Screenlayer) ) { |
||
0 ignored issues
–
show
The variable
Siteapp seems to be never declared. If this is a global, consider adding a /** global: Siteapp */ comment.
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed. To learn more about declaring variables in Javascript, see the MDN. ![]() |
|||
105 | |||
106 | layer2activate.setActive(); |
||
107 | |||
108 | } |
||
109 | } |
||
110 | |||
111 | deactivateLayers ( ) { |
||
112 | var layer = this.activeLayer; |
||
113 | |||
114 | if ( (layer instanceof Siteapp.UiManager.Screenlayer) ) { |
||
0 ignored issues
–
show
The variable
Siteapp seems to be never declared. If this is a global, consider adding a /** global: Siteapp */ comment.
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed. To learn more about declaring variables in Javascript, see the MDN. ![]() |
|||
115 | layer.setInactive(); |
||
116 | } |
||
117 | } |
||
118 | |||
119 | /** |
||
120 | * Retrieve screen layer by name. |
||
121 | * |
||
122 | * @param {string} layername |
||
123 | * @returns {Screenlayer} |
||
124 | */ |
||
125 | getLayerByName ( layername ) { |
||
126 | var result = null; |
||
127 | for (var idx in this.layers) { |
||
0 ignored issues
–
show
A for in loop automatically includes the property of any prototype object, consider checking the key using
hasOwnProperty .
When iterating over the keys of an object, this includes not only the keys of the object, but also keys contained in the prototype of that object. It is generally a best practice to check for these keys specifically: var someObject;
for (var key in someObject) {
if ( ! someObject.hasOwnProperty(key)) {
continue; // Skip keys from the prototype.
}
doSomethingWith(key);
}
![]() |
|||
128 | var layer = this.layers[idx]; |
||
129 | if (layer.options.name && (layer.options.name == layername)) { |
||
130 | result = layer; |
||
131 | } |
||
132 | }; |
||
133 | return result; |
||
134 | } |
||
135 | |||
136 | /** |
||
137 | * Retrieve panel adapter by name. |
||
138 | * |
||
139 | * @param {string} adaptername |
||
140 | * @returns {Paneladapter} |
||
141 | */ |
||
142 | getAdapterByName ( adaptername ) { |
||
143 | var result = null; |
||
144 | if (this.Paneladapters.isRegistered(adaptername)) { |
||
145 | for (var idx in this.adapters) { |
||
0 ignored issues
–
show
A for in loop automatically includes the property of any prototype object, consider checking the key using
hasOwnProperty .
When iterating over the keys of an object, this includes not only the keys of the object, but also keys contained in the prototype of that object. It is generally a best practice to check for these keys specifically: var someObject;
for (var key in someObject) {
if ( ! someObject.hasOwnProperty(key)) {
continue; // Skip keys from the prototype.
}
doSomethingWith(key);
}
![]() |
|||
146 | var adapter = this.adapters[idx]; |
||
147 | if (adapter.options.name && (adapter.options.name == adaptername)) { |
||
148 | result = adapter; |
||
149 | } |
||
150 | }; |
||
151 | } |
||
152 | return result; |
||
153 | } |
||
154 | |||
155 | /** |
||
156 | * Retrieve active/focused screen layer. |
||
157 | * |
||
158 | * @var {Screenlayer} activeLayer |
||
159 | */ |
||
160 | get activeLayer () { |
||
161 | for (var idx in this.layers) { |
||
0 ignored issues
–
show
A for in loop automatically includes the property of any prototype object, consider checking the key using
hasOwnProperty .
When iterating over the keys of an object, this includes not only the keys of the object, but also keys contained in the prototype of that object. It is generally a best practice to check for these keys specifically: var someObject;
for (var key in someObject) {
if ( ! someObject.hasOwnProperty(key)) {
continue; // Skip keys from the prototype.
}
doSomethingWith(key);
}
![]() |
|||
162 | if ( this.layers[idx].isActive ) { |
||
163 | return this.layers[idx]; |
||
164 | } |
||
165 | } |
||
166 | return null; |
||
167 | } |
||
168 | |||
169 | /** |
||
170 | * Retrieve registered screen layers. |
||
171 | * |
||
172 | * @var [{Screenlayer}] layers |
||
173 | */ |
||
174 | get layers () { |
||
175 | var $manager = this, |
||
176 | _layers = [], |
||
177 | layerAttrs = [], |
||
178 | namespace = $manager.application.appName |
||
179 | ; |
||
180 | $.each(this._modules, (idx, plugin) => { |
||
181 | var name = Siteapp.sys.hyphenate( Siteapp.sys.functionName(plugin) ); |
||
0 ignored issues
–
show
The variable
Siteapp seems to be never declared. If this is a global, consider adding a /** global: Siteapp */ comment.
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed. To learn more about declaring variables in Javascript, see the MDN. ![]() |
|||
182 | if ($manager.options.namespacedModuleTriggers) { |
||
183 | layerAttrs.push(`[data-${namespace}-${name}]`); |
||
184 | } else { |
||
185 | layerAttrs.push(`[data-${name}]`); |
||
186 | } |
||
187 | }); |
||
188 | $(layerAttrs.join(',')).each((idx, elem) => { |
||
189 | var plugin = $(elem).data(namespace+'Plugin'); |
||
190 | if (plugin instanceof Siteapp.UiManager.Screenlayer) { |
||
0 ignored issues
–
show
The variable
Siteapp seems to be never declared. If this is a global, consider adding a /** global: Siteapp */ comment.
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed. To learn more about declaring variables in Javascript, see the MDN. ![]() |
|||
191 | _layers[plugin.uuid] = plugin; |
||
192 | } |
||
193 | }); |
||
194 | this._screenlayers = _layers; |
||
195 | return this._screenlayers; |
||
196 | } |
||
197 | |||
198 | /** |
||
199 | * Retrieve registered screen layers. |
||
200 | * |
||
201 | * @var [{Screenlayer}] layers |
||
202 | */ |
||
203 | get adapters () { |
||
204 | var $manager = this, |
||
205 | _adapters = [], |
||
206 | adapterAttrs = [], |
||
207 | namespace = $manager.application.appName |
||
208 | ; |
||
209 | $.each(this._modules, (idx, plugin) => { |
||
210 | var name = Siteapp.sys.hyphenate( Siteapp.sys.functionName(plugin) ); |
||
0 ignored issues
–
show
The variable
Siteapp seems to be never declared. If this is a global, consider adding a /** global: Siteapp */ comment.
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed. To learn more about declaring variables in Javascript, see the MDN. ![]() |
|||
211 | if ($manager.options.namespacedModuleTriggers) { |
||
212 | adapterAttrs.push(`[data-${namespace}-${name}]`); |
||
213 | } else { |
||
214 | adapterAttrs.push(`[data-${name}]`); |
||
215 | } |
||
216 | }); |
||
217 | $(adapterAttrs.join(',')).each((idx, elem) => { |
||
218 | var plugin = $(elem).data(namespace+'Plugin'); |
||
219 | if (plugin instanceof Siteapp.UiManager.Paneladapter) { |
||
0 ignored issues
–
show
The variable
Siteapp seems to be never declared. If this is a global, consider adding a /** global: Siteapp */ comment.
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed. To learn more about declaring variables in Javascript, see the MDN. ![]() |
|||
220 | _adapters[plugin.uuid] = plugin; |
||
221 | } |
||
222 | }); |
||
223 | this._paneladapters = _adapters; |
||
224 | return this._paneladapters; |
||
225 | } |
||
226 | |||
227 | /** |
||
228 | * Initializes the UI manager by setting/checking options and attributes, |
||
229 | * adding helper variables, and saving the anchor. |
||
230 | * @function |
||
231 | * @private |
||
232 | */ |
||
233 | _init() { |
||
234 | |||
235 | super._init(); |
||
236 | |||
237 | this._screenlayers = []; |
||
238 | this._paneladapters = []; |
||
239 | |||
240 | this._events(); |
||
241 | |||
242 | this._initPanelAdapterManager(); |
||
243 | |||
244 | } |
||
245 | |||
246 | /** |
||
247 | * Initializes the panel adapter manager |
||
248 | * |
||
249 | * @function |
||
250 | * @private |
||
251 | */ |
||
252 | _initPanelAdapterManager() { |
||
253 | this.Paneladapters = new AdapterManager(); |
||
254 | this.Paneladapters.application = this.application; |
||
255 | |||
256 | // register the generic/default adapter |
||
257 | this.Paneladapters.register(Paneladapter, 'default'); |
||
258 | } |
||
259 | |||
260 | /** |
||
261 | * Adds event listeners to the element, etc... |
||
262 | * @function |
||
263 | * @private |
||
264 | */ |
||
265 | _events() { |
||
266 | this._addKeyHandler(); |
||
267 | this._addClickHandler(); |
||
268 | } |
||
269 | |||
270 | |||
271 | /** |
||
272 | * Adds click event listeners. |
||
273 | * @function |
||
274 | * @private |
||
275 | */ |
||
276 | _addClickHandler () { |
||
277 | } |
||
278 | |||
279 | /** |
||
280 | * Adds keyboard event handlers. |
||
281 | * @private |
||
282 | */ |
||
283 | _addKeyHandler() { |
||
284 | var _this = this; |
||
0 ignored issues
–
show
|
|||
285 | |||
286 | var keyHandlerMap = { |
||
287 | 'ESCAPE' : (e) => { /*console.//log('key event [ESC]:', e, this);*/ } , |
||
0 ignored issues
–
show
|
|||
288 | 'X' : (e) => { /*console.//log('key event [X]:', e, this);*/ } , |
||
0 ignored issues
–
show
|
|||
289 | 'ALT_CTRL_X' : (e) => { /*console.//log('key event [ALT+CTRL+X]:', e, this);*/ }, |
||
0 ignored issues
–
show
|
|||
290 | 'META_A' : (e) => { /*console.//log('key event [CMD+A]:', e, this);*/ } |
||
0 ignored issues
–
show
|
|||
291 | } |
||
292 | Siteapp.Keyboard.addKeyHandlers( keyHandlerMap, 'UiKeys'+this._uuid ); |
||
0 ignored issues
–
show
The variable
Siteapp seems to be never declared. If this is a global, consider adding a /** global: Siteapp */ comment.
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed. To learn more about declaring variables in Javascript, see the MDN. ![]() |
|||
293 | } |
||
294 | |||
295 | /** |
||
296 | * Destroys the layoutbody. |
||
297 | * @function |
||
298 | */ |
||
299 | _destroy() { |
||
300 | Siteapp.Keyboard.unregister( 'UiKeys'+this._uuid ); |
||
0 ignored issues
–
show
The variable
Siteapp seems to be never declared. If this is a global, consider adding a /** global: Siteapp */ comment.
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed. To learn more about declaring variables in Javascript, see the MDN. ![]() |
|||
301 | this.$element.find('*').off('.'+_this.application.appName+''); |
||
0 ignored issues
–
show
The variable
_this seems to be never declared. If this is a global, consider adding a /** global: _this */ comment.
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed. To learn more about declaring variables in Javascript, see the MDN. ![]() |
|||
302 | this.$element.off('.'+_this.application.appName+''); |
||
303 | this.$element.remove(); |
||
304 | } |
||
305 | |||
306 | } |
||
307 | |||
308 | export default Ui; |