generated from CodeYourFuture/tv-show-dom-project
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMovieCounter.js
46 lines (37 loc) · 1.4 KB
/
MovieCounter.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
function MovieCounter(_element = null) {
_element = document.createElement("div");
_element.setAttribute("id", "ep-count");
_element.textContent = "0 Shows";
document.getElementById("root").addEventListener("all-episodes", (event) => {
let count = event.detail;
_element.textContent = `${count} Episode${count == 1 ? "" : "s"}`;
});
document.getElementById("root").addEventListener("one-episode", (event) => {
_element.textContent = "1 Episode";
});
document.getElementById("root").addEventListener("recv-episodes", (event) => {
let count = event.detail.length;
_element.textContent = `${count} Episode${count == 1 ? "" : "s"}`;
});
document
.getElementById("root")
.addEventListener("shows-counter", function (event) {
let count = event.detail;
_element.textContent = `${count} Show${count == 1 ? "" : "s"}`;
});
document
.getElementById("root")
.addEventListener("search-counter", function (event) {
let count = event.detail.count;
let type = event.detail.type;
_element.textContent = `${count} ${type}${count == 1 ? "" : "s"}`;
});
const counterReady = new Event("counter-ready");
document.getElementById("root").dispatchEvent(counterReady);
this.setCount = function (count, type) {
_element.textContent = `${count} ${type}${count == 1 ? "" : "s"}`;
};
this.getElement = function () {
return _element;
};
}