-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdialog.js
87 lines (83 loc) · 2.01 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
var Component, div, globalID, if_, list, see, _ref;
see = require('lazy-flow').see;
_ref = require('domcom'), list = _ref.list, if_ = _ref.if_, div = _ref.div, Component = _ref.Component;
globalID = 0;
module.exports = function(options, template) {
var closeCallback, dlg, openCallback, opened;
if (options.showClose) {
template = list(div({
"class": "dcdialog-close",
style: {
position: 'absolute',
"z-index": 10001,
top: 0,
right: '80px'
},
onclick: (function() {
return dlg.close();
})
}), template);
}
if (options.overlay) {
template = list(div({
"class": "dcdialog-overlay",
style: {
"z-index": 10000
}
}), div({
"class": "dcdialog-content",
style: {
position: 'absolute',
"z-index": 10001
}
}, template));
} else {
template = div({
"class": "dcdialog-content",
style: {
"z-index": 10001
}
}, template);
}
opened = see(!options.closed);
dlg = if_(opened, div({
id: 'dcdialog' + (++globalID),
"class": "dcdialog",
style: {
position: 'absolute',
top: '0px',
left: '0px',
"z-index": 9999
}
}, template));
openCallback = options.openCallback;
dlg.open = function() {
openCallback && openCallback();
opened(true);
return dlg.render();
};
closeCallback = options.closeCallback;
dlg.close = function() {
opened(false);
dlg.render();
dc.clean();
return closeCallback && closeCallback();
};
if (options.escClose) {
dlg.on('willMount', function() {
var escHandler;
escHandler = function(event) {
var esc;
esc = 27;
if (event.which === esc || event.keyCode === esc) {
return dlg.close();
}
};
return document.body.addEventListener('keydown', escHandler);
});
dlg.on('willUnmount', function() {
return document.body.removeEventListener('keydown', escHandler);
});
}
return dlg;
};