forked from samdark/opera-xdebug
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoptions.html
150 lines (126 loc) · 3.82 KB
/
options.html
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
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<link rel="stylesheet" href="options.css" />
<title id="widget-title">extension title</title>
</head>
<body>
<header>
<img src="xdebug.png" />
<h1 id="widget-name">extension title</h1>
<h2>Made by <span id="widget-author">extension author</span></h2>
</header>
<section>
<h3>IDE key</h3>
<fieldset>
<p>For some IDEs key should match the one set in your IDE settngs:</p>
<p><input type="text" name="idekey" /></p>
</fieldset>
</section>
<footer>
<p>Icon was created by <a href="http://tutsii.deviantart.com/art/Human-O2-Grunge-129720670">Aleksandra Wolska</a>.</p>
<p>Xdebug documentation is available at <a href="http://xdebug.org/">http://xdebug.org/</a>.</p>
<p>Please email bug reports and suggestions to <span id="widget-email"></span>.</p>
</footer>
<script>
addEventListener(
'DOMContentLoaded',
function() {
var storage = widget.preferences;
// glue for multiple values ( checkbox, select-multiple )
var glue = '\n';
// get the FORM elements
var formElements = document.querySelectorAll('input,select');
// list of FORM elements
var skip = hash('hidden,submit,image,reset,button');
var multipleValues = hash('checkbox,select-multiple');
var checkable = hash('checkbox,radio');
// string to hash
function hash(str, glue) {
var obj = {};
var tmp = str.split(glue || ',');
while(tmp.length){
obj[ tmp.pop() ] = true;
}
return obj;
}
function walkElements(callback) {
var obj = [];
for(var i = 0,element = null; element = formElements[i++];){
// skip the element if it has no name or is of a type with no useful value
var type = element.type.toLowerCase();
var name = element.name || '';
if(skip[type] === true || name == '') continue;
var tmp = callback(element, name, type);
if(tmp != null)
obj.push(tmp);
}
return obj;
}
// listener for element changes
function changedElement(e) {
var element = e.currentTarget || e;
var type = element.type.toLowerCase();
var name = element.name || '';
var value = multipleValues[type] !== true ? element.value : walkElements(
function(e, n, t) {
if(n == name && e.options){
var tmp = [];
for(var j = 0,option = null; option = e.options[j++];){
if(option.selected){
tmp.push(option.value);
}
}
return tmp.join(glue);
}
else if(n == name && checkable[t] === true && e.checked){
return e.value;
}
}
).join(glue);
// set value
storage.setItem(name, value);
}
// set the textContent of an element
function setText(id, txt) {
var e = document.getElementById(id);
if(e){
e.innerHTML = txt;
}
}
// fill placeholders
var widgetLabel = widget.name+" "+widget.version;
var authorLabel = '<a href="'+widget.authorHref+'">'+widget.author+'</a>';
var emailLabel = '<a href="mailto:'+widget.authorEmail+'">'+widget.authorEmail+'</a>';
setText('widget-title', widgetLabel);
setText('widget-name', widgetLabel);
setText('widget-author', authorLabel);
setText('widget-email', emailLabel);
// walk and set the elements accordingly to the storage
walkElements(function(element, name, type) {
var value = storage[name] !== undefined ? storage.getItem(name) : element.value;
var valueHash = hash(value, glue);
if(element.selectedOptions){
// 'select' element
for(var j = 0,option = null; option = element.options[j++];){
option.selected = valueHash[option.value] === true;
}
}
else if(checkable[type] === true){
// 'checkable' element
element.checked = valueHash[element.value] === true;
}
else
element.value = value;
if(storage[name] == undefined)
changedElement(element);
// listen to changes
element.addEventListener('change', changedElement, true);
});
},
false
);
</script>
</body>
</html>