-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcheckdialog.js
75 lines (62 loc) · 2.31 KB
/
checkdialog.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
const OVERLAY_STYLE = 'display:none;position:fixed;width:500px;height:300px; \
margin:0 auto;margin-top:40vh;background:white;color:black;\
border:1px solid black;border-radius:2px;padding:10px;';
function sel(s) {
return document.querySelector(s);
}
var CheckDialog = function(id, options, callback) {
this.id = id;
this.options = options;
this.overlay = null;
this.callback = callback;
this.overlay = document.createElement('div');
this.overlay.setAttribute('id', this.id);
this.overlay.setAttribute('style', OVERLAY_STYLE);
var checkbuttons = document.createElement('form');
for (var i = 0; i < options.length; i++) {
checkbuttons.innerHTML += '<label><input type="checkbox"' +
' value="' +
options[i].toString() + '"/>'
+ options[i].toString();
+ '</label><br>';
}
var submit = document.createElement('button');
submit.setAttribute('type','button');
submit.style.marginTop = '10px';
submit.innerHTML = 'OK';
var readInput = this.readInput;
submit.onclick = function() { readInput(callback); };
checkbuttons.appendChild(submit);
var closebutton = document.createElement('button');
closebutton.innerHTML = 'Close';
closebutton.style.marginTop = '10px';
closebutton.checkDialogBox = this;
closebutton.onclick = function() {
this.checkDialogBox.close();
}
this.overlay.appendChild(checkbuttons);
this.overlay.appendChild(closebutton);
document.body.appendChild(this.overlay);
};
CheckDialog.prototype.readInput = function(callback) {
var form = sel('form');
console.log(form.childNodes);
var inputs = form.childNodes;
var result = [];
for (var i = 0; i < inputs.length; i++) {
var box = inputs[i].childNodes[0];
console.log(box);
if (box.checked !== undefined)
result.push(box.checked);
}
callback(result);
}
CheckDialog.prototype.open = function() {
this.overlay.style.display = 'inline-block';
}
CheckDialog.prototype.close = function() {
this.overlay.style.display = 'none';
}
CheckDialog.prototype.remove = function() {
document.body.removeChild(this.overlay);
}