-
Notifications
You must be signed in to change notification settings - Fork 6
/
options.js
35 lines (31 loc) · 1.3 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
// Saves options to localStorage.
function save_options() {
var options = ["urlDial","urlHangup","urlDisplay","displayRefresh","phoneAddress","phoneUsername","phonePassword","prefixLongDistance","prefixInternational"];
var len = options.length;
for(var i = 0; i < len; i++) {
if (document.getElementById(options[i]).value) {
localStorage[options[i]] = document.getElementById(options[i]).value;
} else {
localStorage[options[i]] = "";
}
}
var status = document.getElementById("status");
status.innerHTML = "Options Saved.";
setTimeout(function() {
status.innerHTML = "";
}, 750);
}
// Restores select box state to saved value from localStorage.
function restore_options() {
var options = ["urlDial","urlHangup","urlDisplay","displayRefresh","phoneAddress","phoneUsername","phonePassword","prefixLongDistance","prefixInternational"];
var len = options.length;
for(var i = 0; i < len; i++) {
if (localStorage[options[i]]) {
document.getElementById(options[i]).value = localStorage[options[i]];
} else {
document.getElementById(options[i]).value = "";
}
}
}
document.addEventListener('DOMContentLoaded', restore_options);
document.querySelector('#save').addEventListener('click', save_options);