-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdynamic-modals-for-bootstrap.js
41 lines (34 loc) · 1.29 KB
/
dynamic-modals-for-bootstrap.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
import {Blaze} from 'meteor/blaze';
export default function dynamicModal (template, context = {}, callbacks = {}) {
const {show, shown = callbacks, hide, hidden} = callbacks || {};
if (typeof template === 'string') {
template = Template[template];
}
if (!template || !(template instanceof Blaze.Template)) {
throw new Error('You must pass blaze template');
}
template.onRendered(function () {
Tracker.afterFlush(() => {
const $modal = $(this.firstNode);
this.modal = $modal.modal.bind($modal);
$modal.on('hidden.bs.modal', () => {
if (typeof hidden === 'function') {
hidden(this);
}
Blaze.remove(this.view);
});
if (typeof hide === 'function') {
$modal.on('hide.bs.modal', () => hide(this));
}
if (typeof shown === 'function') {
$modal.on('shown.bs.modal', () => shown(this));
}
if (typeof show === 'function') {
$modal.on('show.bs.modal', () => show(this));
}
this.hide = () => this.modal('hide');
this.modal('show');
});
});
return Blaze.renderWithData(template, context, document.body);
}