-
Notifications
You must be signed in to change notification settings - Fork 4
/
dialog.js
69 lines (62 loc) · 1.88 KB
/
dialog.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
function Dialog() {
this.dialog = document.getElementById('load-dialog');
}
Dialog.prototype = {
open: function(title) {
var self = this;
focusedInputHandler.push({
handleKeypress: function(ev) {
switch (keyCodeToString(ev.which)) {
case 'escape':
self.close();
break;
default:
return;
}
ev.preventDefault();
}
});
var elem = document.createElement('legend');
elem.id = 'load-dialog-title';
elem.textContent = title;
this.dialog.appendChild(elem);
},
close: function() {
this.dialog.style.display = 'none';
while (this.dialog.childNodes.length > 0)
this.dialog.removeChild(this.dialog.firstChild);
focusedInputHandler.pop();
this.selected = -1;
},
appendDefaultButtons: function(callback) {
var elem = document.createElement('button');
elem.id = 'load-dialog-ok';
elem.textContent = 'Ok';
var self = this;
elem.onclick = function() {
if (callback())
self.close();
};
this.dialog.appendChild(elem);
elem = document.createElement('button');
elem.id = 'load-dialog-cancel';
elem.textContent = 'Cancel';
elem.onclick = function() { self.close(); };
this.dialog.appendChild(elem);
},
appendLabelledInput: function(id, type, text) {
var elem = document.createElement('label');
elem.setAttribute('for', id);
elem.textContent = text;
this.dialog.appendChild(elem);
elem = document.createElement('input');
elem.type = type;
elem.id = id;
this.dialog.appendChild(elem);
},
center: function() {
this.dialog.style.display = 'block';
this.dialog.style.left = (this.dialog.parentNode.offsetWidth - this.dialog.offsetWidth) / 2 + "px";
this.dialog.style.top = (this.dialog.parentNode.parentNode.offsetHeight - this.dialog.offsetHeight) / 2 + "px";
}
};