forked from PeppeL-G/bootstrap-3-modal
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
55 lines (38 loc) · 1.05 KB
/
main.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
const currentModalDep = new Tracker.Dependency();
let currentModal;
// The public API.
Modal = {
get: () => {
currentModalDep.depend();
return currentModal;
},
show: (templateName, data, options = {}) => {
// If there is a shown modal, hide it
if (currentModal) {
Modal.hide();
};
// Show the modal
var parentNode = document.body;
var view = Blaze.renderWithData(Template[templateName], data, parentNode);
var domRange = view._domrange; // TODO: Don't violate against the public API.
var $modal = domRange.$('.modal');
$modal.on('shown.bs.modal', () => {
$modal.find('[autofocus]').focus();
});
$modal.on('hidden.bs.modal', () => {
Blaze.remove(view);
});
$modal.name = templateName;
currentModal = $modal;
currentModalDep.changed();
$modal.modal(options);
},
hide: () => {
if (!currentModal) return;
const { name = '' } = currentModal;
currentModal.modal('hide');
currentModal = null;
currentModalDep.changed();
return name;
},
};