-
Notifications
You must be signed in to change notification settings - Fork 5
/
options.js
53 lines (46 loc) · 1.49 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
var defaultName = "";
function loadOptions() {
var myName = localStorage["myName"];
var myCals = JSON.parse(localStorage["myCals"]);
if (myName == undefined || myName.length > 20)
myName = defaultName;
var select = document.getElementById("name");
select.value = myName;
for(var i=0; i<myCals.length; i++){
var name = myCals[i].name;
var radioBtn;
if (myCals[i].selected){
radioBtn = $('<input type="radio" name="calendarPicker" checked="true" id="' + i + '" /><label for="' + i + '">' + name + '</label>');
radioBtn.appendTo('#target');
} else {
radioBtn = $('<input type="radio" name="calendarPicker" id="' + i + '" /><label for="' + i + '">' + name + '</label>');
radioBtn.appendTo('#target');
}
}
}
function saveOptions() {
var select = document.getElementById("name").value;
localStorage["myName"] = select;
var cal = $('input[name=calendarPicker]:checked').attr('id');
var myCals = JSON.parse(localStorage["myCals"]);
for (var i = myCals.length - 1; i >= 0; i--) {
myCals[i].selected = false;
};
myCals[cal].selected = true;
localStorage['myCals'] = JSON.stringify(myCals);
}
$(document).ready(function(){
loadOptions();
$('#save').click(function(){
saveOptions();
$('#name').css({"border" : "3px solid green"});
$('#done').css({"display" : "inline"})
setTimeout(function(){
$('#done').fadeOut();
}, 1000);
});
$('#reset').click(function(){
$('#name').css({"border" : "3px solid grey"});
document.getElementById("name").value = "";
});
});