/
uk-modal.js
70 lines (58 loc) · 1.62 KB
/
uk-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
import Component from "@ember/component";
import layout from "../templates/components/uk-modal";
import UIkit from "uikit";
import { scheduleOnce } from "@ember/runloop";
import { getOwner } from "@ember/application";
export default Component.extend({
layout,
btnClose: true,
escClose: true,
bgClose: true,
stack: false,
container: true,
clsPage: "uk-modal-page",
clsPanel: "uk-modal-dialog",
selClose: [
".uk-modal-close",
".uk-modal-close-default",
".uk-modal-close-outside",
".uk-modal-close-full"
].join(", "),
init() {
this._super(...arguments);
const { APP } = getOwner(this).resolveRegistration("config:environment");
this.set("container", document.querySelector(APP.rootElement || "body"));
},
_show() {
this.modal && this.set("visible", true);
},
_hide() {
this.modal && this.set("visible", false);
},
didInsertElement() {
const id = `#modal-${this.elementId}`;
this.set(
"modal",
UIkit.modal(id, {
escClose: this.get("escClose"),
bgClose: this.get("bgClose"),
stack: this.get("stack"),
container: this.get("container"),
clsPage: this.get("clsPage"),
clsPanel: this.get("clsPanel"),
selClose: this.get("selClose")
})
);
UIkit.util.on(id, "show", () => this._show());
UIkit.util.on(id, "hide", () => this._hide());
},
didReceiveAttrs() {
scheduleOnce("afterRender", () => {
this.visible ? this.modal.show() : this.modal.hide();
});
},
willDestroyElement() {
this.modal.$el.parentNode.removeChild(this.modal.$el);
this.set("modal", null);
}
});