This repository has been archived by the owner on Nov 3, 2021. It is now read-only.
/
settings.js
721 lines (652 loc) · 23.8 KB
/
settings.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
/* exported Settings */
/* global _ */
/* global Awesomescreen */
/* global Browser */
/* global BrowserDB */
/* global BrowserDialog */
/* global KeyEvent */
/* global LazyLoader */
/* global SearchUtil */
/* global Toolbar */
/* global UrlHelper */
'use strict';
/**
* Browser app settings panel.
* @namespace Settings
*/
var Settings = {
DEFAULT_HOMEPAGE: 'http://www.mozilla.org',
currentSearchEngine: null,
selectSearchEngine: null,
searchEngineList: null,
focusList: null,
focusPos: 0,
/** Get all DOM elements when inited. */
getAllElements: function settings_getAllElements() {
var toCamelCase = function toCamelCase(str) {
return str.replace(/\-(.)/g, function replacer(str, p1) {
return p1.toUpperCase();
});
};
var elementIDs = [
'settings-list', 'settings-list-area',
'settings-homepage', 'settings-homepage-name',
'settings-search-engine', 'settings-search-engine-name',
'settings-clear-history',
'settings-clear-cookie',
'settings-dialog',
'settings-dialog-homepage',
'settings-dialog-homepage-input',
'settings-dialog-homepage-input-area',
'settings-dialog-homepage-clear',
'settings-dialog-homepage-default',
'settings-dialog-homepage-cancel',
'settings-dialog-homepage-ok',
'settings-dialog-search',
'settings-dialog-search-select',
'settings-dialog-search-select-list',
'settings-dialog-search-cancel',
'settings-dialog-search-ok',
'settings-banner-message'
];
// Loop and add element with camel style name to Modal Dialog attribute.
elementIDs.forEach(function createElementRef(name) {
this[toCamelCase(name)] = document.getElementById(name);
}, this);
},
/**
* Intialise settings panel.
*/
init: function settings_init() {
this.getAllElements();
this.getDefaultHomepage((function(result) {
/* default homepage nothing... */
Browser.debug('default homepage = ' + result);
if(!result) {
console.log('set default homepage...');
this.setDefaultHomepage();
this.setHomepage(this.DEFAULT_HOMEPAGE);
}
}).bind(this));
this.settingsList.addEventListener('mouseup',
this.handleListClick.bind(this));
this.settingsListArea.addEventListener('mouseup',
this.handleListAreaClick.bind(this));
this.settingsDialog.addEventListener('mouseup',
this.handleListAreaClick.bind(this));
this.settingsHomepage.addEventListener('mouseup',
this.handleHomepageClick.bind(this));
this.settingsSearchEngine.addEventListener('mouseup',
this.handleSearchEngineClick.bind(this));
this.settingsClearHistory.addEventListener('mouseup',
this.handleClearHistoryClick.bind(this));
this.settingsClearCookie.addEventListener('mouseup',
this.handleClearCookieClick.bind(this));
this.settingsDialogHomepageInput.addEventListener('submit',
this.handleDialogHomepageInputSubmit.bind(this));
this.settingsDialogHomepageClear.addEventListener('mouseup',
this.handleDialogHomepageClear.bind(this));
this.settingsDialogHomepageDefault.addEventListener('mouseup',
this.handleDialogHomepageDefault.bind(this));
this.settingsDialogHomepageCancel.addEventListener('mouseup',
this.handleDialogHomepageCancel.bind(this));
this.settingsDialogHomepageOk.addEventListener('mouseup',
this.handleDialogHomepageOk.bind(this));
this.settingsDialogSearchCancel.addEventListener('mouseup',
this.handleDialogSearchCancel.bind(this));
this.settingsDialogSearchOk.addEventListener('mouseup',
this.handleDialogSearchOk.bind(this));
this.settingsDialogHomepageInputArea.addEventListener('focus',
this.handleDialogHomepageInputAreaFocus.bind(this));
this.settingsDialogHomepageInputArea.addEventListener('mousedown',
this.handleDialogHomepageInputAreaClick.bind(this));
this.settingsDialogHomepageInputArea.addEventListener('blur',
this.handleDialogHomepageInputBlur.bind(this));
this.settingsDialogHomepageClear.addEventListener('keyup',
this.handleDialogHomepageClear.bind(this));
this.settingsDialogHomepageDefault.addEventListener('keyup',
this.handleDialogHomepageDefault.bind(this));
this.settingsDialogHomepageCancel.addEventListener('keyup',
this.handleDialogHomepageCancel.bind(this));
this.settingsDialogHomepageOk.addEventListener('keyup',
this.handleDialogHomepageOk.bind(this));
this.settingsDialogSearchCancel.addEventListener('keyup',
this.handleDialogSearchCancel.bind(this));
this.settingsDialogSearchOk.addEventListener('keyup',
this.handleDialogSearchOk.bind(this));
//IFDEF_FIREFOX_SYNC
LazyLoader.load('js/sync/settings.js');
//ENDIF_FIREFOX_SYNC
},
getDefaultHomepage: function settings_getDefaultHomepage(cb) {
BrowserDB.db.open((function() {
BrowserDB.getSetting( 'default_homepage', cb );
}).bind(this));
},
setDefaultHomepage: function settings_setDefaultHomepage() {
BrowserDB.db.open((function() {
BrowserDB.updateSetting( this.DEFAULT_HOMEPAGE, 'default_homepage' );
}).bind(this));
},
getHomepage: function settings_getHomepage(cb) {
BrowserDB.db.open((function() {
BrowserDB.getSetting( 'settings_homepage', cb );
}).bind(this));
},
setHomepage: function settings_setHomepage(url) {
BrowserDB.db.open((function() {
BrowserDB.updateSetting( url, 'settings_homepage' );
}).bind(this));
},
/**
* Show settings panel.
*/
show: function settings_show() {
document.body.classList.add('settings-screen');
this.getHomepage((function(result) {
this.settingsHomepageName.textContent = result;
}).bind(this));
this.settingsSearchEngineName.textContent =
SearchUtil.getCurrentEngineName();
this.currentSearchEngine = this.settingsSearchEngineName.textContent;
this.selectSearchEngine = this.currentSearchEngine;
// XXX: Get Firefox Account sign in status and display it
},
/**
* settings list displays a confirmation.
*/
isDisplayed: function settings_isDisplayed() {
return document.body.classList.contains('settings-screen');
},
/**
* Hide settings panel.
*/
hide: function settings_hide() {
// Browser.switchCursorMode( true );
BrowserDialog.cancelDialog();
this.hideDialogHomepage();
this.hideDialogSearch();
document.body.classList.remove('settings-screen');
},
handleListClick: function settings_handleListClick(evt) {
if( evt ) {
evt.stopPropagation();
}
this.hide();
},
handleListAreaClick: function settings_handleListAreaClick(evt) {
if( evt ) {
evt.stopPropagation();
}
},
focusChange: function settings_focusChange(pos) {
var opt = null;
var flg = false;
if( Awesomescreen.pointerImg.style.display == 'none' ) {
Browser.switchCursorMode(true);
Browser.switchCursorMode(false);
flg = true;
}
for( var i = 0 ; i < Settings.focusList.length ; i ++ ) {
if( i == pos ) {
if(Settings.focusList[i].nodeName == 'INPUT') {
if( !Settings.settingsDialogHomepageInput
.classList.contains('exfocus') ) {
Settings.settingsDialogHomepageInput.classList.add('exfocus');
}
} else if(Settings.focusList[i].id == 'settings-dialog-homepage-clear'){
Settings.focusList[i].focus();
if( !Settings.settingsDialogHomepageInput
.classList.contains('exfocus') ) {
Settings.settingsDialogHomepageInput.classList.add('exfocus');
}
if( flg ) {
opt = Awesomescreen.DEFAULT_EXCLEAR;
}
} else {
Settings.focusList[i].focus();
Settings.settingsDialogHomepageInput.classList.remove('exfocus');
}
Awesomescreen.focusImgFunc(Settings.focusList[i], opt);
} else {
Settings.focusList[i].blur();
}
}
},
/**
* Handle homepage click.
*/
handleHomepageClick: function settings_handleHomepageClick() {
if( !this.isDialogHomepageDisplayed() ) {
this.focusList = [];
Browser.switchCursorMode(false);
this.settingsDialog.classList.remove('hidden');
this.settingsDialogHomepage.classList.remove('hidden');
this.settingsDialogHomepageInput.classList.remove('input');
this.settingsDialogHomepageInput.classList.remove('exfocus');
this.settingsDialogHomepageInputArea.value =
this.settingsHomepageName.textContent;
this.settingsDialogHomepageInputArea.tabIndex = '0';
this.settingsDialogHomepageClear.tabIndex = '0';
this.focusList.push(this.settingsDialogHomepageInputArea);
this.focusList.push(this.settingsDialogHomepageClear);
this.focusList.push(this.settingsDialogHomepageDefault);
this.focusList.push(this.settingsDialogHomepageOk);
this.focusList.push(this.settingsDialogHomepageCancel);
this.focusPos = this.focusList.length - 1;
this.focusChange(this.focusPos);
}
},
hideDialogHomepage: function settings_hideDialogHomepage() {
if( this.isDialogHomepageDisplayed() ) {
Awesomescreen.pointerImg.style.display = 'none';
this.settingsDialogHomepageInput.classList.remove('input');
this.settingsDialogHomepageInput.classList.remove('exfocus');
this.settingsDialogHomepage.classList.add('hidden');
this.settingsDialog.classList.add('hidden');
Browser.switchCursorMode(true);
}
},
isDialogHomepageDisplayed: function settings_isDialogHomepageDisplayed() {
return !this.settingsDialogHomepage.classList.contains('hidden');
},
handleDialogHomepageInputSubmit:
function settings_handleDialogHomepageInputSubmit(ev) {
if (ev) {
// Can be canceled
ev.preventDefault();
}
var hasScheme =
UrlHelper.hasScheme(this.settingsDialogHomepageInputArea.value);
// No scheme, prepend basic protocol and return
if (!hasScheme) {
this.settingsDialogHomepageInputArea.value =
'http://' + this.settingsDialogHomepageInputArea.value;
}
this.settingsDialogHomepageInputArea.blur();
},
handleDialogHomepageInputAreaFocus:
function settings_handleDialogHomepageInputAreaFocus(evt) {
if( evt ) {
evt.preventDefault();
}
Settings.settingsDialogHomepageInput.classList.add('input');
Settings.settingsDialogHomepageInput.classList.remove('exfocus');
},
handleDialogHomepageInputAreaClick:
function settings_handleDialogHomepageInputAreaClick(evt) {
Browser.switchCursorMode(true);
Browser.switchCursorMode(false);
Settings.settingsDialogHomepageInput.classList.add('input');
Settings.settingsDialogHomepageInput.classList.remove('exfocus');
Settings.focusPos = 0;
Settings.focusList[Settings.focusPos].focus();
Awesomescreen.pointerImg.style.display = 'none';
},
handleDialogHomepageInputBlur:
function settings_handleDialogHomepageInputBlur(evt) {
if( evt ) {
evt.preventDefault();
}
if( Awesomescreen.pointerImg.style.display == 'none' ) {
Browser.switchCursorMode(true);
Browser.switchCursorMode(false);
}
// Pointer image to the input area(fucusPos=0)
Settings.focusPos = 0;
Settings.settingsDialogHomepageInput.classList.remove('input');
Settings.focusChange(Settings.focusPos);
Awesomescreen.pointerImg.style.display = 'block';
},
handleDialogHomepageClear:
function settings_handleDialogHomepageClear(evt) {
if( evt ) {
evt.preventDefault();
}
if(( evt.type == 'keyup' ) && ( evt.keyCode != KeyEvent.DOM_VK_RETURN )) {
return;
}
if( evt.keyCode != KeyEvent.DOM_VK_RETURN ) {
Awesomescreen.pointerImg.style.display = 'none';
document.activeElement.blur();
document.activeElement.classList.remove('exfocus');
}
document.activeElement.classList.remove('active');
this.settingsDialogHomepageInputArea.value = '';
},
handleDialogHomepageDefault:
function settings_handleDialogHomepageDefault(evt) {
if( evt ) {
evt.preventDefault();
}
if(( evt.type == 'keyup' ) && ( evt.keyCode != KeyEvent.DOM_VK_RETURN )) {
return;
}
if( evt.keyCode != KeyEvent.DOM_VK_RETURN ) {
Awesomescreen.pointerImg.style.display = 'none';
document.activeElement.blur();
document.activeElement.classList.remove('exfocus');
}
document.activeElement.classList.remove('active');
this.getDefaultHomepage((function(result) {
this.settingsDialogHomepageInputArea.value = result;
}).bind(this));
},
handleDialogHomepageCancel:
function settings_handleDialogHomepageCancel(evt) {
if( evt ) {
evt.preventDefault();
}
if(( evt.type == 'keyup' ) && ( evt.keyCode != KeyEvent.DOM_VK_RETURN )) {
return;
}
// animation end event handler
var end_event = (function() {
Settings.settingsDialogHomepageCancel.removeEventListener('transitionend',
end_event, false);
Settings.hideDialogHomepage();
});
// end animantion event
Settings.settingsDialogHomepageCancel.addEventListener('transitionend',
end_event, false);
document.activeElement.classList.remove('active');
},
handleDialogHomepageOk: function settings_handleDialogHomepageOk(evt) {
if( evt ) {
evt.preventDefault();
}
if(( evt.type == 'keyup' ) && ( evt.keyCode != KeyEvent.DOM_VK_RETURN )) {
return;
}
// animation end event handler
var end_event = (function() {
Settings.settingsDialogHomepageOk.removeEventListener('transitionend',
end_event, false);
Settings.hideDialogHomepage();
});
// end animantion event
Settings.settingsDialogHomepageOk.addEventListener('transitionend',
end_event, false);
document.activeElement.classList.remove('active');
this.setHomepage(this.settingsDialogHomepageInputArea.value);
this.settingsHomepageName.textContent =
this.settingsDialogHomepageInputArea.value;
},
/**
* Handle search engine click.
*/
handleSearchEngineClick: function settings_handleSearchEngineClick() {
if( !this.isDialogSearchDisplayed() ) {
this.focusList = [];
Browser.switchCursorMode(false);
this.settingsDialog.classList.remove('hidden');
this.settingsDialogSearch.classList.remove('hidden');
this.selectSearchEngine = this.currentSearchEngine;
this.searchEngineList = SearchUtil.getEngineList();
for(var i in this.searchEngineList) {
var title = document.createElement('div');
title.classList.add('title');
var name = document.createElement('p');
name.classList.add('name');
name.textContent = this.searchEngineList[i].name;
title.appendChild(name);
var check = document.createElement('div');
check.classList.add('check');
var onoff = document.createElement('p');
if( name.textContent == this.currentSearchEngine ) {
name.dataset.display = 'selected';
onoff.classList.add('on');
} else {
name.dataset.display = '';
onoff.classList.add('off');
}
check.appendChild(onoff);
var item = document.createElement('div');
item.classList.add('item');
item.appendChild(title);
item.appendChild(check);
item.tabIndex = '0';
this.settingsDialogSearchSelectList.appendChild(item);
item.addEventListener('mouseup',
this.handleDialogSearchSelected.bind(this));
item.addEventListener('keyup',
this.handleDialogSearchSelected.bind(this));
this.focusList.push(item);
}
this.focusList.push(this.settingsDialogSearchOk);
this.focusList.push(this.settingsDialogSearchCancel);
this.focusPos = this.focusList.length - 1;
this.focusChange(this.focusPos);
}
},
handleClearHistoryClick: function settings_handleClearHistoryClick() {
BrowserDialog.createDialog('clear_history', null);
},
handleClearCookieClick: function settings_handleClearCookieClick() {
BrowserDialog.createDialog('del_cookie', null);
},
clearCookieFailed: function settings_clearCookieFailed() {
// this.settingsBannerMessage.innerHTML =
// 'Failed to clear cookies and stored data';
this.settingsBannerMessage.innerHTML = _('LT_FAILED_');
this.showBannerMessage();
},
showBannerMessage: function settings_showBannerMessage() {
if( this.settingsBannerMessage.dataset.display != 'visible' ) {
this.settingsBannerMessage.dataset.display = 'visible';
}
clearTimeout( this.showBannerMessageTimeoutID );
this.showBannerMessageTimeoutID = setTimeout( function() {
Settings.settingsBannerMessage.dataset.display = '';
}, 3000);
},
hideDialogSearch: function settings_hideDialogSearch() {
if( this.isDialogSearchDisplayed() ) {
Awesomescreen.pointerImg.style.display = 'none';
var childs = this.settingsDialogSearchSelectList.childNodes;
var len = childs.length;
for(var i = 0 ; i < len ; i ++) {
this.settingsDialogSearchSelectList.removeChild(childs[0]);
}
this.settingsDialogSearch.classList.add('hidden');
this.settingsDialog.classList.add('hidden');
Browser.switchCursorMode(true);
}
},
isDialogSearchDisplayed: function settings_isDialogSearchDisplayed() {
return !this.settingsDialogSearch.classList.contains('hidden');
},
handleDialogSearchSelected:
function settings_handleDialogSearchSelected(ev) {
if( ev ) {
ev.preventDefault();
}
if(( ev.type == 'keyup' ) && ( ev.keyCode != KeyEvent.DOM_VK_RETURN )) {
return;
}
this.selectSearchEngine = ev.currentTarget.textContent;
var childs = this.settingsDialogSearchSelectList.childNodes;
var len = childs.length;
for(var i = 0 ; i < len ; i ++) {
if(childs[i].textContent == this.selectSearchEngine) {
childs[i].firstChild.firstChild.dataset.display = 'selected';
childs[i].lastChild.lastChild.classList.remove('off');
childs[i].lastChild.lastChild.classList.add('on');
} else {
childs[i].firstChild.firstChild.dataset.display = '';
childs[i].lastChild.lastChild.classList.remove('on');
childs[i].lastChild.lastChild.classList.add('off');
}
}
},
handleDialogSearchCancel: function settings_handleDialogSearchCancel(ev) {
if( ev ) {
ev.preventDefault();
}
if(( ev.type == 'keyup' ) && ( ev.keyCode != KeyEvent.DOM_VK_RETURN )) {
return;
}
// animation end event handler
var end_event = (function() {
Settings.settingsDialogSearchCancel.removeEventListener('transitionend',
end_event, false);
Settings.hideDialogSearch();
});
// end animantion event
Settings.settingsDialogSearchCancel.addEventListener('transitionend',
end_event, false);
document.activeElement.classList.remove('active');
},
handleDialogSearchOk: function settings_handleDialogSearchOk(ev) {
if( ev ) {
ev.preventDefault();
}
if(( ev.type == 'keyup' ) && ( ev.keyCode != KeyEvent.DOM_VK_RETURN )) {
return;
}
// animation end event handler
var end_event = (function() {
Settings.settingsDialogSearchOk.removeEventListener('transitionend',
end_event, false);
Settings.hideDialogSearch();
});
var setSearchEngine = function () {
this.currentSearchEngine = this.selectSearchEngine;
this.settingsSearchEngineName.textContent =
this.currentSearchEngine;
Toolbar.setSearchEngine();
};
// end animantion event
Settings.settingsDialogSearchOk.addEventListener('transitionend',
end_event, false);
if( this.currentSearchEngine != this.selectSearchEngine ) {
for(var i in this.searchEngineList) {
if( this.selectSearchEngine == this.searchEngineList[i].name ) {
SearchUtil.setSearchEngineId(this.searchEngineList[i].id,
setSearchEngine.bind(this));
break;
}
}
}
document.activeElement.classList.remove('active');
},
/**
* Handle Key Event.
*/
handleKeyEvent: function settings_handleKeyEvent(ev) {
if( !Settings.isDisplayed() ) {
return false;
}
// in the input area focus (= display keyboard)
if(document.activeElement.nodeName == 'INPUT') {
return true;
}
switch( ev.keyCode ) {
case KeyEvent.DOM_VK_LEFT :
ev.preventDefault();
if( Settings.isDialogHomepageDisplayed() ) {
if(( Settings.focusPos == 1 ) || ( Settings.focusPos == 4 )) {
Settings.focusPos --;
Settings.focusChange(Settings.focusPos);
}
return true;
}
if( Settings.isDialogSearchDisplayed() ) {
if( Settings.focusPos == Settings.focusList.length - 1 ) {
Settings.focusPos --;
Settings.focusChange(Settings.focusPos);
}
return true;
}
break;
case KeyEvent.DOM_VK_RIGHT :
ev.preventDefault();
if( Settings.isDialogHomepageDisplayed() ) {
if(( Settings.focusPos === 0 ) || ( Settings.focusPos === 3 )) {
Settings.focusPos ++;
Settings.focusChange(Settings.focusPos);
}
return true;
}
if( Settings.isDialogSearchDisplayed() ) {
if( Settings.focusPos == Settings.focusList.length - 2 ) {
Settings.focusPos ++;
Settings.focusChange(Settings.focusPos);
}
return true;
}
break;
case KeyEvent.DOM_VK_UP :
ev.preventDefault();
if( Settings.isDialogHomepageDisplayed() ) {
if(( Settings.focusPos === 2 ) || ( Settings.focusPos === 4 )) {
Settings.focusPos -= 2;
Settings.focusChange(Settings.focusPos);
} else if( Settings.focusPos === 3 ) {
Settings.focusPos --;
Settings.focusChange(Settings.focusPos);
}
return true;
}
if( Settings.isDialogSearchDisplayed() ) {
if( Settings.focusPos > 0 ) {
if( Settings.focusPos >= Settings.focusList.length - 1 ) {
Settings.focusPos = Settings.focusList.length - 3;
} else {
Settings.focusPos --;
}
Settings.focusChange(Settings.focusPos);
}
return true;
}
break;
case KeyEvent.DOM_VK_DOWN :
ev.preventDefault();
if( Settings.isDialogHomepageDisplayed() ) {
if(( Settings.focusPos == 1 ) || ( Settings.focusPos === 2 )) {
Settings.focusPos ++;
Settings.focusChange(Settings.focusPos);
} else if( Settings.focusPos === 0 ) {
Settings.focusPos += 2;
Settings.focusChange(Settings.focusPos);
}
return true;
}
if( Settings.isDialogSearchDisplayed() ) {
if( Settings.focusPos < Settings.focusList.length - 2 ) {
Settings.focusPos ++;
Settings.focusChange(Settings.focusPos);
}
return true;
}
break;
case KeyEvent.DOM_VK_RETURN :
ev.preventDefault();
if( Settings.focusPos === 0 ) {
Settings.focusList[Settings.focusPos].focus();
if( Settings.isDialogHomepageDisplayed() ) {
Awesomescreen.pointerImg.style.display = 'none';
}
}else{
document.activeElement.classList.remove('active');
document.activeElement.classList.add('active');
}
break;
case KeyEvent.DOM_VK_BACK_SPACE :
case KeyEvent.DOM_VK_ESCAPE:
if( Settings.isDialogHomepageDisplayed() ) {
Settings.hideDialogHomepage();
return true;
}
if( Settings.isDialogSearchDisplayed() ) {
Settings.hideDialogSearch();
return true;
}
Settings.hide();
return true;
default :
return false;
}
return true;
}
};