forked from nashby/jose-vs-oss
-
Notifications
You must be signed in to change notification settings - Fork 0
/
options.js
108 lines (100 loc) · 2.83 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
// Generated by CoffeeScript 1.6.1
(function() {
var add_button, add_empty_button, load_buttons, load_options, message, save_options,
_this = this;
load_options = function() {
_this.main_div = document.getElementById('options-form');
return chrome.storage.sync.get("jose.buttons", function(data) {
var buttons;
buttons = data["jose.buttons"];
return load_buttons(buttons);
});
};
load_buttons = function(buttons) {
var button, _i, _len, _results;
if (buttons == null) {
buttons = [];
}
_results = [];
for (_i = 0, _len = buttons.length; _i < _len; _i++) {
button = buttons[_i];
_results.push(add_button(button['title'], button['text'], button['closable']));
}
return _results;
};
add_button = function(title, text, closable) {
var div, el;
if (title == null) {
title = "";
}
if (text == null) {
text = "";
}
if (closable == null) {
closable = false;
}
div = document.createElement('div');
div.setAttribute("class", "button");
el = document.createElement('label');
el.innerHTML = "Title:";
div.appendChild(el);
el = document.createElement('input');
el.setAttribute("class", "title");
el.value = title;
div.appendChild(el);
el = document.createElement('textarea');
el.setAttribute("class", "text");
el.value = text;
div.appendChild(el);
el = document.createElement('input');
el.setAttribute("class", "closable");
el.type = 'checkbox';
el.checked = closable;
div.appendChild(el);
el = document.createElement('a');
el.setAttribute("class", "delete_button");
el.setAttribute('href', '#');
el.innerHTML = 'remove';
div.appendChild(el);
return _this.main_div.appendChild(div);
};
add_empty_button = function() {
return add_button();
};
save_options = function() {
var b, buttons, closable, node, nodes, text, title, _i, _len;
buttons = [];
nodes = $('.button');
for (_i = 0, _len = nodes.length; _i < _len; _i++) {
node = nodes[_i];
title = $(node).find(".title").val();
text = $(node).find(".text").val();
closable = $(node).find(".closable").prop('checked');
b = {
title: title,
text: text,
closable: closable
};
buttons.push(b);
}
return chrome.storage.sync.set({
"jose.buttons": buttons
}, message("Settings saved"));
};
message = function(msg) {
return console.log("options.js - " + msg);
};
$(function() {
load_options();
$("#add_button").click(function() {
return add_empty_button();
});
$("#save_options").click(function() {
return save_options();
});
return $(document).on('click', '.delete_button', function() {
$(this).parent().remove();
return false;
});
});
}).call(this);