-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmodal.js
61 lines (60 loc) · 2.05 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
// Popup function for small screen warning.
export let smallScreenModal = function(msg, btn) {
// See https://developer.mozilla.org/en-US/docs/Web/HTML/Element/template
// Select elements
const body = document.querySelector("body");
const template = document.querySelector("#modal");
// Clone the template
const clone = template.content.cloneNode(true);
let content = clone.querySelector(".modal-content");
// Modal should fill 80% of screen height
content.style = "min-height: 80vh;";
// Adding <p> tag:
let p = document.createElement("p");
p.textContent = msg;
content.appendChild(p);
// Adding <button>:
let button = document.createElement("button");
button.textContent = btn;
button.onclick = function() {return this.parentNode.parentNode.remove()};
content.appendChild(button);
// Add modal to body
body.appendChild(clone);
};
export let showModal = function(e, [type, value]) {
// See https://developer.mozilla.org/en-US/docs/Web/HTML/Element/template
// Select elements
const body = document.querySelector("body");
const template = document.querySelector("#modal");
// Clone the template
const clone = template.content.cloneNode(true);
let content = clone.querySelector(".modal-content");
// Determine type of modal.
if (type === 'p') {
// Adding <p> tag:
let p = document.createElement("p");
p.textContent = value;
content.appendChild(p)
} else if (type === 'iframe') {
// Adding <iframe> tag with video url:
let iframe = document.createElement("iframe");
// Styling
iframe.allowFullscreen = true;
iframe.width = "100%";
iframe.style = "min-height: 80vh;";
iframe.frameBorder = "0";
// Set url of iframe to value
iframe.src = value;
content.appendChild(iframe);
} else if (type === 'img') {
// Adding <img> tag with img url:
let img = document.createElement("img");
// Styling
img.style = "width: 100%; min-height: 80vh;";
// Set url of img to value
img.src = value;
content.appendChild(img);
}
// Add modal to body
body.appendChild(clone);
};