forked from Atrasoftware/chrome-virtual-keyboard-old
-
Notifications
You must be signed in to change notification settings - Fork 0
/
options.js
135 lines (128 loc) · 4.03 KB
/
options.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
function kl_add() {
var o = document.getElementById("al").options;
for (var i=0; i<o.length; i++) {
if (o[i].selected) {
var opt = document.createElement("option");
opt.text = o[i].innerHTML;
opt.value = o[i].value;
var os = document.getElementById("sl").options;
var exists = false;
for (var i2=0; i2<os.length; i2++) {
if (os[i2].value == o[i].value) {
exists = true;
}
}
if (!exists) {
document.getElementById("sl").options.add(opt);
}
}
}
kl_save();
}
function kl_save() {
var a = new Array();
var o = document.getElementById("sl").options;
for (var i=0; i<o.length; i++) {
if (o[i].value != undefined) {
a.push({ value: o[i].value, name: o[i].innerHTML });
}
}
localStorage["keyboardLayoutsList"] = JSON.stringify(a);
localStorage["keyboardLayout1"] = a[0].value;
document.getElementById("changeEffect").className = "show";
}
function kl_load() {
if (localStorage["keyboardLayoutsList"] != undefined) {
var a = JSON.parse(localStorage["keyboardLayoutsList"]);
if (a.length > 0) {
document.getElementById("sl").removeChild(document.getElementById("sl").options[0]);
for (var i=0; i<a.length; i++) {
var opt = document.createElement("option");
opt.text = a[i].name;
opt.value = a[i].value;
if (a[i].value != undefined) {
document.getElementById("sl").options.add(opt);
}
}
}
}
}
function kl_remove() {
var o = document.getElementById("sl").options;
if (o.length > 1) {
for (var i=0; i<o.length; i++) {
if (o[i].selected) {
document.getElementById("sl").removeChild(o[i]);
}
}
}
kl_save();
}
window.addEventListener('load', function() {
document.body.className = "loaded";
kl_load();
document.getElementById("kl_remove").addEventListener("click", kl_remove, false);
document.getElementById("kl_add").addEventListener("click", kl_add, false);
var c = document.getElementsByClassName("setting");
for (var i=0; i<c.length; i++) {
var sk = c[i].getAttribute("_setting");
if (c[i].getAttribute("type") == "checkbox") {
if ((localStorage[sk] == undefined) && (c[i].getAttribute("_default") != undefined)) {
localStorage[sk] = c[i].getAttribute("_default");
}
if (localStorage[sk] == "true") {
c[i].checked = true;
}
} if (c[i].getAttribute("type") == "range") {
if (localStorage[sk] == undefined) {
c[i].value = 0;
} else {
c[i].value = localStorage[sk];
}
} else {
c[i].value = localStorage[sk];
}
c[i].onchange = function() {
var skey = this.getAttribute("_setting");
if (this.getAttribute("type") == "checkbox") {
if ((localStorage[skey] == undefined) && (this.getAttribute("_default") != undefined)) {
localStorage[skey] = this.getAttribute("_default");
}
localStorage[skey] = this.checked ? "true" : "false";
} else {
localStorage[skey] = this.value;
}
document.getElementById("changeEffect").className = "show";
if (this.getAttribute("_changed") != undefined) {
callFunc(this.getAttribute("_changed"));
}
}
if (c[i].getAttribute("_changed") != undefined) {
callFunc(c[i].getAttribute("_changed"));
}
}
}, false);
function callFunc(callback) {
eval(callback)();
}
function slider_zoom() {
var v = document.getElementById("zoomLevel").value;
if (v < 0.3) { v = "Auto"; } else { v = (v*100).toFixed(0)+"%"; }
document.getElementById("zoomLevelValue").innerHTML = v;
}
function checkbox_smallKeyboard() {
var s = document.getElementById("smallKeyboard").checked;
document.getElementById("zoomLevelLabel").style.display = s ? "none" : "block";
}
function checkbox_touchEvents() {
var s = document.getElementById("touchEvents").checked;
document.getElementById("autoTriggerPH").style.display = s ? "none" : "block";
}
function slider_autoTriggerAfter() {
var v = document.getElementById("autoTriggerAfter").value+" sec";
document.getElementById("autoTriggerAfterValue").innerHTML = v;
}
function checkbox_autoTrigger() {
var s = !document.getElementById("autoTrigger").checked;
document.getElementById("autoTriggerOnPH").style.display = s ? "none" : "block";
}