-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.js
83 lines (80 loc) · 2.29 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
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
"use strict";
const buttonsContainerEl = document.getElementById("buttons");
buttonsContainerEl.addEventListener("click", changeView);
function changeView(e) {
if (e.target.dataset.action) {
let action = e.target.dataset.action;
viewController[action]();
}
}
const viewController = {
isOn: false,
helloMsg: "Hello! homeworks.done ? X : A",
byeMsg: "Bye...",
msgEl: document.querySelector(".home-msg"),
viewEl: document.getElementById("view"),
viewContentEl: null,
onOff: function () {
this.removeViewContentEl();
if (this.isOn) {
this.msgEl.textContent = this.byeMsg;
buttonsContainerEl.removeEventListener("click", changeView);
setTimeout(() => {
this.viewEl.classList.toggle("off");
this.isOn = !this.isOn;
buttonsContainerEl.addEventListener("click", changeView);
}, 1500);
} else {
this.msgEl.textContent = this.helloMsg;
this.viewEl.classList.toggle("off");
this.isOn = !this.isOn;
}
},
goTv: function () {
const el = createYoutubeIframe("https://www.youtube.com/embed/y-28CssnqEE");
this.addViewContentEl(el);
},
goBack: function () {
console.log("back");
this.removeViewContentEl();
},
goShop: function () {
this.addViewContentEl(createIframe("./shop/index.html"));
},
goGoogle: function () {
this.addViewContentEl(createIframe("https://www.google.com/search?igu=1"));
},
addViewContentEl(el) {
this.viewEl.classList.add("loading");
if (this.viewContentEl) {
this.viewContentEl.replaceWith(el);
this.viewContentEl = el;
} else {
console.log(el);
this.viewEl.prepend(el);
this.viewContentEl = el;
}
},
removeViewContentEl() {
this.viewEl.classList.remove("loading");
if (this.viewContentEl) {
this.viewContentEl.remove();
this.viewContentEl = null;
}
},
};
function createIframe(src) {
const el = document.createElement("iframe");
el.src = src;
el.width = "100%";
el.height = "315";
el.frameborder = "0";
el.setAttribute("allowfullscreen", true);
return el;
}
function createYoutubeIframe(src) {
const el = createIframe(src);
el.title = "Youtube video player";
el.allow = "accelerometer; autoplay;clipboard-write;encrypted-media;gyroscope;picture-in-picture;web-share";
return el;
}