-
Notifications
You must be signed in to change notification settings - Fork 0
/
Modal.js
97 lines (82 loc) · 2.47 KB
/
Modal.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
// Generated by CoffeeScript 1.12.7
(function() {
var Modal, m, s, style, u,
bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
m = require('mithril');
s = require('mss-js');
u = require('./utils');
style = require('./style');
Modal = (function() {
function Modal(arg) {
var ref, ref1, ref2;
this.widget = arg.widget, this.clickToHide = (ref = arg.clickToHide) != null ? ref : true, this.escToHide = (ref1 = arg.escToHide) != null ? ref1 : true, this.onHide = (ref2 = arg.onHide) != null ? ref2 : u.noOp;
this.hide = bind(this.hide, this);
this.show = bind(this.show, this);
this.onEscInternal = bind(this.onEscInternal, this);
this.onClickInternal = bind(this.onClickInternal, this);
this.showWidget = false;
}
Modal.prototype.onClickInternal = function(e) {
var t;
t = u.getTarget(e);
if (this.clickToHide && t.className.indexOf && ((u.targetHasClass(t, 'Modal')) || (u.targetHasClass(t, 'HVCenter')))) {
return this.hide();
}
};
Modal.prototype.onEscInternal = function(e) {
if ((e.key === 'Escape' || e.keyCode === 27) && this.escToHide) {
this.showWidget = false;
m.redraw();
return true;
}
};
Modal.prototype.show = function() {
return this.showWidget = true;
};
Modal.prototype.hide = function() {
this.showWidget = false;
return this.onHide();
};
Modal.prototype.view = function() {
var self;
self = this;
if (this.showWidget) {
return m('.Modal', {
onclick: this.onClickInternal,
oncreate: function() {
return window.addEventListener('keyup', self.onEscInternal, true);
},
onremove: function() {
return window.removeEventListener('keyup', self.onEscInternal, true);
}
}, m('.HVCenter', this.widget.view()));
}
};
return Modal;
})();
Modal.mss = {
Modal: {
width: '100%',
height: '100%',
position: 'fixed',
top: 0,
left: 0,
background: style.modalBG,
zIndex: 9999,
$before: {
content: '""',
display: 'inline-block',
height: '100%',
verticalAlign: 'middle'
},
HVCenter: {
display: 'inline-block',
width: '100%',
textAlign: 'center',
opacity: 1,
verticalAlign: 'middle'
}
}
};
module.exports = Modal;
}).call(this);