Completed
Push — master ( e88c19...17669b )
by Rain
03:00
created

Knoin.js ➔ ... ➔ ???   B

Complexity

Conditions 6
Paths 13

Size

Total Lines 28

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
cc 6
c 1
b 1
f 0
nc 13
nop 1
dl 0
loc 28
rs 8.439
1
2
import _ from '_';
3
import $ from '$';
4
import ko from 'ko';
5
import hasher from 'hasher';
6
import crossroads from 'crossroads';
7
8
import {runHook} from 'Common/Plugins';
9
import {$html, aViewModels as VIEW_MODELS, popupVisibilityNames} from 'Common/Globals';
10
11
import {
12
	isArray, isUnd, pString, log,
0 ignored issues
show
Unused Code introduced by
The variable log seems to be never used. Consider removing it.
Loading history...
Unused Code introduced by
The variable pString seems to be never used. Consider removing it.
Loading history...
Unused Code introduced by
The variable isUnd seems to be never used. Consider removing it.
Loading history...
13
	createCommand, delegateRun, isNonEmptyArray
0 ignored issues
show
Unused Code introduced by
The variable delegateRun seems to be never used. Consider removing it.
Loading history...
Unused Code introduced by
The variable isNonEmptyArray seems to be never used. Consider removing it.
Loading history...
Unused Code introduced by
The variable createCommand seems to be never used. Consider removing it.
Loading history...
14
} from 'Common/Utils';
15
16
let
17
	currentScreen = null,
0 ignored issues
show
Unused Code introduced by
The variable currentScreen seems to be never used. Consider removing it.
Loading history...
18
	defaultScreenName = '';
0 ignored issues
show
Unused Code introduced by
The variable defaultScreenName seems to be never used. Consider removing it.
Loading history...
19
20
const SCREENS = {};
0 ignored issues
show
Unused Code introduced by
The constant SCREENS seems to be never used. Consider removing it.
Loading history...
21
22
export const ViewType = {
0 ignored issues
show
Unused Code introduced by
The constant ViewType seems to be never used. Consider removing it.
Loading history...
23
	Popup: 'Popups',
24
	Left: 'Left',
25
	Right: 'Right',
26
	Center: 'Center'
27
};
28
29
/**
30
 * @returns {void}
31
 */
32
export function hideLoading()
33
{
34
	$('#rl-content').addClass('rl-content-show');
35
	$('#rl-loading').hide().remove();
36
}
37
38
/**
39
 * @param {Function} SettingsViewModelClass
40
 * @param {string} template
41
 * @param {string} labelName
42
 * @param {string} route
43
 * @param {boolean=} isDefault = false
44
 * @returns {void}
45
 */
46
export function addSettingsViewModel(SettingsViewModelClass, template, labelName, route, isDefault = false)
0 ignored issues
show
Unused Code introduced by
The parameter route is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
Unused Code introduced by
The parameter isDefault is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
Unused Code introduced by
The parameter template is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
Unused Code introduced by
The parameter SettingsViewModelClass is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
Unused Code introduced by
The parameter labelName is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
47
{
48
	SettingsViewModelClass.__rlSettingsData = {
49
		Label: labelName,
50
		Template: template,
51
		Route: route,
52
		IsDefault: !!isDefault
53
	};
54
55
	VIEW_MODELS.settings.push(SettingsViewModelClass);
56
}
57
58
/**
59
 * @param {Function} SettingsViewModelClass
60
 * @returns {void}
61
 */
62
export function removeSettingsViewModel(SettingsViewModelClass)
0 ignored issues
show
Unused Code introduced by
The parameter SettingsViewModelClass is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
63
{
64
	VIEW_MODELS['settings-removed'].push(SettingsViewModelClass);
65
}
66
67
/**
68
 * @param {Function} SettingsViewModelClass
69
 * @returns {void}
70
 */
71
export function disableSettingsViewModel(SettingsViewModelClass)
0 ignored issues
show
Unused Code introduced by
The parameter SettingsViewModelClass is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
72
{
73
	VIEW_MODELS['settings-disabled'].push(SettingsViewModelClass);
74
}
75
76
/**
77
 * @returns {void}
78
 */
79
export function routeOff()
80
{
81
	hasher.changed.active = false;
82
}
83
84
/**
85
 * @returns {void}
86
 */
87
export function routeOn()
88
{
89
	hasher.changed.active = true;
90
}
91
92
/**
93
 * @param {string} screenName
94
 * @returns {?Object}
95
 */
96
export function screen(screenName)
0 ignored issues
show
Unused Code introduced by
The parameter screenName is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
97
{
98
	return ('' !== screenName && !isUnd(SCREENS[screenName])) ? SCREENS[screenName] : null;
99
}
100
101
/**
102
 * @param {Function} ViewModelClassToHide
103
 * @returns {void}
104
 */
105
export function hideScreenPopup(ViewModelClassToHide)
0 ignored issues
show
Unused Code introduced by
The parameter ViewModelClassToHide is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
106
{
107
	if (ViewModelClassToHide && ViewModelClassToHide.__vm && ViewModelClassToHide.__dom)
0 ignored issues
show
Best Practice introduced by
If you intend to check if the variable ViewModelClassToHide is declared in the current environment, consider using typeof ViewModelClassToHide === "undefined" instead. This is safe if the variable is not actually declared.
Loading history...
108
	{
109
		ViewModelClassToHide.__vm.modalVisibility(false);
110
	}
111
}
112
113
/**
114
 * @param {string} hookName
115
 * @param {Function} ViewModelClass
116
 * @param {mixed=} params = null
117
 */
118
export function vmRunHook(hookName, ViewModelClass, params = null)
0 ignored issues
show
Unused Code introduced by
The parameter ViewModelClass is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
Unused Code introduced by
The parameter params is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
Unused Code introduced by
The parameter hookName is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
119
{
120
	_.each(ViewModelClass.__names, (name) => {
121
		runHook(hookName, [name, ViewModelClass.__vm, params]);
122
	});
123
}
124
125
/**
126
 * @param {Function} ViewModelClass
127
 * @param {Object=} vmScreen
128
 * @returns {*}
129
 */
130
export function buildViewModel(ViewModelClass, vmScreen)
0 ignored issues
show
Unused Code introduced by
The parameter ViewModelClass is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
Unused Code introduced by
The parameter vmScreen is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
131
{
132
	if (ViewModelClass && !ViewModelClass.__builded)
0 ignored issues
show
Best Practice introduced by
If you intend to check if the variable ViewModelClass is declared in the current environment, consider using typeof ViewModelClass === "undefined" instead. This is safe if the variable is not actually declared.
Loading history...
133
	{
134
		let vmDom = null;
0 ignored issues
show
Bug introduced by
The variable vmDom seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.vmDom.
Loading history...
135
		const
136
			vm = new ViewModelClass(vmScreen),
0 ignored issues
show
Bug introduced by
The variable vm seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.vm.
Loading history...
137
			position = ViewModelClass.__type || '',
0 ignored issues
show
Bug introduced by
The variable position seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.position.
Loading history...
138
			vmPlace = position ? $('#rl-content #rl-' + position.toLowerCase()) : null;
0 ignored issues
show
Bug introduced by
The variable vmPlace seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.vmPlace.
Loading history...
Best Practice introduced by
If you intend to check if the variable position is declared in the current environment, consider using typeof position === "undefined" instead. This is safe if the variable is not actually declared.
Loading history...
139
140
		ViewModelClass.__builded = true;
141
		ViewModelClass.__vm = vm;
142
143
		vm.onShowTrigger = ko.observable(false);
144
		vm.onHideTrigger = ko.observable(false);
145
146
		vm.viewModelName = ViewModelClass.__name;
147
		vm.viewModelNames = ViewModelClass.__names;
148
		vm.viewModelTemplateID = ViewModelClass.__templateID;
149
		vm.viewModelPosition = ViewModelClass.__type;
150
151
		if (vmPlace && 1 === vmPlace.length)
0 ignored issues
show
Best Practice introduced by
If you intend to check if the variable vmPlace is declared in the current environment, consider using typeof vmPlace === "undefined" instead. This is safe if the variable is not actually declared.
Loading history...
152
		{
153
			vmDom = $('<div></div>').addClass('rl-view-model').addClass('RL-' + vm.viewModelTemplateID).hide();
154
			vmDom.appendTo(vmPlace);
155
156
			vm.viewModelDom = vmDom;
157
			ViewModelClass.__dom = vmDom;
158
159
			if (ViewType.Popup === position)
160
			{
161
				vm.cancelCommand = vm.closeCommand = createCommand(() => {
162
					hideScreenPopup(ViewModelClass);
163
				});
164
165
				vm.modalVisibility.subscribe((value) => {
166
					if (value)
167
					{
168
						vm.viewModelDom.show();
169
						vm.storeAndSetKeyScope();
170
171
						popupVisibilityNames.push(vm.viewModelName);
172
						vm.viewModelDom.css('z-index', 3000 + popupVisibilityNames().length + 10);
173
174
						if (vm.onShowTrigger)
175
						{
176
							vm.onShowTrigger(!vm.onShowTrigger());
177
						}
178
179
						delegateRun(vm, 'onShowWithDelay', [], 500);
180
					}
181
					else
182
					{
183
						delegateRun(vm, 'onHide');
184
						delegateRun(vm, 'onHideWithDelay', [], 500);
185
186
						if (vm.onHideTrigger)
187
						{
188
							vm.onHideTrigger(!vm.onHideTrigger());
189
						}
190
191
						vm.restoreKeyScope();
192
193
						vmRunHook('view-model-on-hide', ViewModelClass);
194
195
						popupVisibilityNames.remove(vm.viewModelName);
196
						vm.viewModelDom.css('z-index', 2000);
197
198
						_.delay(() => vm.viewModelDom.hide(), 300);
199
					}
200
				});
201
			}
202
203
			vmRunHook('view-model-pre-build', ViewModelClass, vmDom);
204
205
			ko.applyBindingAccessorsToNode(vmDom[0], {
206
				translatorInit: true,
207
				template: () => ({name: vm.viewModelTemplateID})
208
			}, vm);
209
210
			delegateRun(vm, 'onBuild', [vmDom]);
211
			if (vm && ViewType.Popup === position)
0 ignored issues
show
Best Practice introduced by
If you intend to check if the variable vm is declared in the current environment, consider using typeof vm === "undefined" instead. This is safe if the variable is not actually declared.
Loading history...
212
			{
213
				vm.registerPopupKeyDown();
214
			}
215
216
			vmRunHook('view-model-post-build', ViewModelClass, vmDom);
217
		}
218
		else
219
		{
220
			log('Cannot find view model position: ' + position);
221
		}
222
	}
223
224
	return ViewModelClass ? ViewModelClass.__vm : null;
0 ignored issues
show
Best Practice introduced by
If you intend to check if the variable ViewModelClass is declared in the current environment, consider using typeof ViewModelClass === "undefined" instead. This is safe if the variable is not actually declared.
Loading history...
225
}
226
227
/**
228
 * @param {Function} ViewModelClassToShow
229
 * @param {Array=} params
230
 * @returns {void}
231
 */
232
export function showScreenPopup(ViewModelClassToShow, params = [])
0 ignored issues
show
Unused Code introduced by
The parameter params is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
Unused Code introduced by
The parameter ViewModelClassToShow is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
233
{
234
	if (ViewModelClassToShow)
0 ignored issues
show
Best Practice introduced by
If you intend to check if the variable ViewModelClassToShow is declared in the current environment, consider using typeof ViewModelClassToShow === "undefined" instead. This is safe if the variable is not actually declared.
Loading history...
235
	{
236
		buildViewModel(ViewModelClassToShow);
237
238
		if (ViewModelClassToShow.__vm && ViewModelClassToShow.__dom)
239
		{
240
			delegateRun(ViewModelClassToShow.__vm, 'onBeforeShow', params || []);
0 ignored issues
show
Best Practice introduced by
If you intend to check if the variable params is declared in the current environment, consider using typeof params === "undefined" instead. This is safe if the variable is not actually declared.
Loading history...
241
242
			ViewModelClassToShow.__vm.modalVisibility(true);
243
244
			delegateRun(ViewModelClassToShow.__vm, 'onShow', params || []);
245
246
			vmRunHook('view-model-on-show', ViewModelClassToShow, params || []);
247
		}
248
	}
249
}
250
251
/**
252
 * @param {Function} ViewModelClassToShow
253
 * @returns {void}
254
 */
255
export function warmUpScreenPopup(ViewModelClassToShow)
0 ignored issues
show
Unused Code introduced by
The parameter ViewModelClassToShow is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
256
{
257
	if (ViewModelClassToShow)
0 ignored issues
show
Best Practice introduced by
If you intend to check if the variable ViewModelClassToShow is declared in the current environment, consider using typeof ViewModelClassToShow === "undefined" instead. This is safe if the variable is not actually declared.
Loading history...
258
	{
259
		buildViewModel(ViewModelClassToShow);
260
261
		if (ViewModelClassToShow.__vm && ViewModelClassToShow.__dom)
262
		{
263
			delegateRun(ViewModelClassToShow.__vm, 'onWarmUp');
264
		}
265
	}
266
}
267
268
/**
269
 * @param {Function} ViewModelClassToShow
270
 * @returns {boolean}
271
 */
272
export function isPopupVisible(ViewModelClassToShow)
0 ignored issues
show
Unused Code introduced by
The parameter ViewModelClassToShow is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
273
{
274
	return ViewModelClassToShow && ViewModelClassToShow.__vm ? ViewModelClassToShow.__vm.modalVisibility() : false;
0 ignored issues
show
Best Practice introduced by
If you intend to check if the variable ViewModelClassToShow is declared in the current environment, consider using typeof ViewModelClassToShow === "undefined" instead. This is safe if the variable is not actually declared.
Loading history...
275
}
276
277
/**
278
 * @param {string} screenName
279
 * @param {string} subPart
280
 * @returns {void}
281
 */
282
export function screenOnRoute(screenName, subPart)
0 ignored issues
show
Unused Code introduced by
The parameter subPart is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
Unused Code introduced by
The parameter screenName is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
283
{
284
	let
285
		vmScreen = null,
0 ignored issues
show
Bug introduced by
The variable vmScreen seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.vmScreen.
Loading history...
286
		isSameScreen = false,
0 ignored issues
show
Bug introduced by
The variable isSameScreen seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.isSameScreen.
Loading history...
287
		cross = null;
0 ignored issues
show
Bug introduced by
The variable cross seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.cross.
Loading history...
288
289
	if ('' === pString(screenName))
290
	{
291
		screenName = defaultScreenName;
0 ignored issues
show
Bug introduced by
The variable screenName seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.screenName.
Loading history...
292
	}
293
294
	if ('' !== screenName)
295
	{
296
		vmScreen = screen(screenName);
297
		if (!vmScreen)
0 ignored issues
show
Best Practice introduced by
If you intend to check if the variable vmScreen is declared in the current environment, consider using typeof vmScreen === "undefined" instead. This is safe if the variable is not actually declared.
Loading history...
298
		{
299
			vmScreen = screen(defaultScreenName);
300
			if (vmScreen)
301
			{
302
				subPart = screenName + '/' + subPart;
0 ignored issues
show
Bug introduced by
The variable subPart seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.subPart.
Loading history...
303
				screenName = defaultScreenName;
304
			}
305
		}
306
307
		if (vmScreen && vmScreen.__started)
308
		{
309
			isSameScreen = currentScreen && vmScreen === currentScreen;
0 ignored issues
show
Best Practice introduced by
If you intend to check if the variable currentScreen is declared in the current environment, consider using typeof currentScreen === "undefined" instead. This is safe if the variable is not actually declared.
Loading history...
310
311
			if (!vmScreen.__builded)
312
			{
313
				vmScreen.__builded = true;
314
315
				if (isNonEmptyArray(vmScreen.viewModels()))
316
				{
317
					_.each(vmScreen.viewModels(), (ViewModelClass) => {
318
						buildViewModel(ViewModelClass, vmScreen);
319
					});
320
				}
321
322
				delegateRun(vmScreen, 'onBuild');
323
			}
324
325
			_.defer(() => {
326
				// hide screen
327
				if (currentScreen && !isSameScreen)
0 ignored issues
show
Best Practice introduced by
If you intend to check if the variable isSameScreen is declared in the current environment, consider using typeof isSameScreen === "undefined" instead. This is safe if the variable is not actually declared.
Loading history...
Best Practice introduced by
If you intend to check if the variable currentScreen is declared in the current environment, consider using typeof currentScreen === "undefined" instead. This is safe if the variable is not actually declared.
Loading history...
328
				{
329
					delegateRun(currentScreen, 'onHide');
330
					delegateRun(currentScreen, 'onHideWithDelay', [], 500);
331
332
					if (currentScreen.onHideTrigger)
333
					{
334
						currentScreen.onHideTrigger(!currentScreen.onHideTrigger());
335
					}
336
337
					if (isNonEmptyArray(currentScreen.viewModels()))
338
					{
339
						_.each(currentScreen.viewModels(), (ViewModelClass) => {
340
							if (ViewModelClass.__vm && ViewModelClass.__dom && ViewType.Popup !== ViewModelClass.__vm.viewModelPosition)
341
							{
342
								ViewModelClass.__dom.hide();
343
								ViewModelClass.__vm.viewModelVisibility(false);
344
345
								delegateRun(ViewModelClass.__vm, 'onHide');
346
								delegateRun(ViewModelClass.__vm, 'onHideWithDelay', [], 500);
347
348
								if (ViewModelClass.__vm.onHideTrigger)
349
								{
350
									ViewModelClass.__vm.onHideTrigger(!ViewModelClass.__vm.onHideTrigger());
351
								}
352
							}
353
						});
354
					}
355
				}
356
				// --
357
358
				currentScreen = vmScreen;
0 ignored issues
show
Bug introduced by
The variable currentScreen seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.currentScreen.
Loading history...
359
360
				// show screen
361
				if (currentScreen && !isSameScreen)
0 ignored issues
show
Best Practice introduced by
If you intend to check if the variable isSameScreen is declared in the current environment, consider using typeof isSameScreen === "undefined" instead. This is safe if the variable is not actually declared.
Loading history...
362
				{
363
					delegateRun(currentScreen, 'onShow');
364
					if (currentScreen.onShowTrigger)
365
					{
366
						currentScreen.onShowTrigger(!currentScreen.onShowTrigger());
367
					}
368
369
					runHook('screen-on-show', [currentScreen.screenName(), currentScreen]);
370
371
					if (isNonEmptyArray(currentScreen.viewModels()))
372
					{
373
						_.each(currentScreen.viewModels(), (ViewModelClass) => {
374
375
							if (ViewModelClass.__vm && ViewModelClass.__dom && ViewType.Popup !== ViewModelClass.__vm.viewModelPosition)
376
							{
377
								delegateRun(ViewModelClass.__vm, 'onBeforeShow');
378
379
								ViewModelClass.__dom.show();
380
								ViewModelClass.__vm.viewModelVisibility(true);
381
382
								delegateRun(ViewModelClass.__vm, 'onShow');
383
								if (ViewModelClass.__vm.onShowTrigger)
384
								{
385
									ViewModelClass.__vm.onShowTrigger(!ViewModelClass.__vm.onShowTrigger());
386
								}
387
388
								delegateRun(ViewModelClass.__vm, 'onShowWithDelay', [], 200);
389
								vmRunHook('view-model-on-show', ViewModelClass);
390
							}
391
392
						});
393
					}
394
				}
395
				// --
396
397
				cross = vmScreen.__cross ? vmScreen.__cross() : null;
0 ignored issues
show
Bug introduced by
The variable cross seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.cross.
Loading history...
398
				if (cross)
399
				{
400
					cross.parse(subPart);
401
				}
402
			});
403
		}
404
	}
405
}
406
407
/**
408
 * @param {Array} screensClasses
409
 * @returns {void}
410
 */
411
export function startScreens(screensClasses)
0 ignored issues
show
Unused Code introduced by
The parameter screensClasses is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
412
{
413
	_.each(screensClasses, (CScreen) => {
414
		if (CScreen)
415
		{
416
			const
417
				vmScreen = new CScreen(),
418
				screenName = vmScreen ? vmScreen.screenName() : '';
419
420
			if (vmScreen && '' !== screenName)
421
			{
422
				if ('' === defaultScreenName)
423
				{
424
					defaultScreenName = screenName;
0 ignored issues
show
Bug introduced by
The variable defaultScreenName seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.defaultScreenName.
Loading history...
425
				}
426
427
				SCREENS[screenName] = vmScreen;
428
			}
429
		}
430
	});
431
432
	_.each(SCREENS, (vmScreen) => {
433
		if (vmScreen && !vmScreen.__started && vmScreen.__start)
434
		{
435
			vmScreen.__started = true;
436
			vmScreen.__start();
437
438
			runHook('screen-pre-start', [vmScreen.screenName(), vmScreen]);
439
			delegateRun(vmScreen, 'onStart');
440
			runHook('screen-post-start', [vmScreen.screenName(), vmScreen]);
441
		}
442
	});
443
444
	const cross = crossroads.create();
0 ignored issues
show
Bug introduced by
The variable cross seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.cross.
Loading history...
445
	cross.addRoute(/^([a-zA-Z0-9\-]*)\/?(.*)$/, screenOnRoute);
446
447
	hasher.initialized.add(cross.parse, cross);
448
	hasher.changed.add(cross.parse, cross);
449
	hasher.init();
450
451
	_.delay(() => $html.removeClass('rl-started-trigger').addClass('rl-started'), 100);
452
	_.delay(() => $html.addClass('rl-started-delay'), 200);
453
}
454
455
/**
456
 * @param {string} sHash
0 ignored issues
show
Documentation introduced by
The parameter sHash does not exist. Did you maybe forget to remove this comment?
Loading history...
457
 * @param {boolean=} silence = false
458
 * @param {boolean=} replace = false
459
 * @returns {void}
460
 */
461
export function setHash(hash, silence = false, replace = false)
0 ignored issues
show
Unused Code introduced by
The parameter silence is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
Unused Code introduced by
The parameter replace is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
Unused Code introduced by
The parameter hash is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
462
{
463
	hash = '#' === hash.substr(0, 1) ? hash.substr(1) : hash;
0 ignored issues
show
Bug introduced by
The variable hash seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.hash.
Loading history...
464
	hash = '/' === hash.substr(0, 1) ? hash.substr(1) : hash;
465
466
	const cmd = replace ? 'replaceHash' : 'setHash';
0 ignored issues
show
Bug introduced by
The variable cmd seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.cmd.
Loading history...
Best Practice introduced by
If you intend to check if the variable replace is declared in the current environment, consider using typeof replace === "undefined" instead. This is safe if the variable is not actually declared.
Loading history...
467
468
	if (silence)
0 ignored issues
show
Best Practice introduced by
If you intend to check if the variable silence is declared in the current environment, consider using typeof silence === "undefined" instead. This is safe if the variable is not actually declared.
Loading history...
469
	{
470
		hasher.changed.active = false;
471
		hasher[cmd](hash);
472
		hasher.changed.active = true;
473
	}
474
	else
475
	{
476
		hasher.changed.active = true;
477
		hasher[cmd](hash);
478
		hasher.setHash(hash);
479
	}
480
}
481
482
/**
483
 * @param {Object} params
0 ignored issues
show
Documentation introduced by
The parameter params does not exist. Did you maybe forget to remove this comment?
Loading history...
484
 * @returns {void}
485
 */
486
function viewDecorator({name, type, templateID})
487
{
488
	return (target) => {
489
		if (target)
490
		{
491
			if (name)
492
			{
493
				if (isArray(name))
494
				{
495
					target.__names = name;
496
				}
497
				else
498
				{
499
					target.__names = [name];
500
				}
501
502
				target.__name = target.__names[0];
503
			}
504
505
			if (type)
506
			{
507
				target.__type = type;
508
			}
509
510
			if (templateID)
511
			{
512
				target.__templateID = templateID;
513
			}
514
		}
515
	};
516
}
517
518
export {viewDecorator, viewDecorator as view, viewDecorator as viewModel};
519