-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscriptF.js
132 lines (121 loc) · 3.53 KB
/
scriptF.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
//------------------Search Table-------------//
function searchTable(e) {
var t, n, o, r;
for (
id =
3 != e
? document.getElementById("myInput1")
: document.getElementById("myInput"),
t = id.value.toUpperCase(),
n = document.getElementById("myTable").getElementsByTagName("tr"),
r = 0;
r < n.length;
r++
)
(o = n[r].getElementsByTagName("td")[e]) &&
((o.textContent || o.innerText).toUpperCase().indexOf(t) > -1
? (n[r].style.display = "")
: (n[r].style.display = "none"));
}
const getCellValue = (e, t) =>
e.children[t].innerText || e.children[t].textContent,
comparer = (e, t) => (n, o) => {
return (
(r = getCellValue(t ? n : o, e)),
(a = getCellValue(t ? o : n, e)),
"" === r || "" === a || isNaN(r) || isNaN(a)
? r.toString().localeCompare(a)
: r - a
);
var r, a;
};
//------------------------------------------------//
//Sortable Columns
document.querySelectorAll("th").forEach((e) =>
e.addEventListener("click", () => {
const t = e.closest("table").querySelector("tbody");
var n, o;
Array.from(t.querySelectorAll("tr"))
.sort(
((n = Array.from(e.parentNode.children).indexOf(e)),
(o = this.asc = !this.asc),
(e, t) => {
return (
(r = getCellValue(o ? e : t, n)),
(a = getCellValue(o ? t : e, n)),
"" === r || "" === a || isNaN(r) || isNaN(a)
? r.toString().localeCompare(a)
: r - a
);
var r, a;
})
)
.forEach((e) => t.appendChild(e));
})
);
// -----------COuntdown TImer--------------////
var countDownDate = new Date("Oct 25, 2020 08:00:00").getTime(),
x = setInterval(function () {
var e = new Date().getTime(),
t = countDownDate - e,
n = Math.floor(t / 864e5),
o = Math.floor((t % 864e5) / 36e5),
r = Math.floor((t % 36e5) / 6e4),
a = Math.floor((t % 6e4) / 1e3);
(document.getElementById("countdown").innerHTML =
n + "d " + o + "h " + r + "m " + a + "s "),
t < 0 &&
(clearInterval(x),
(document.getElementById("countdown").innerHTML = "EXPIRADO"));
}, 1e3);
//-----------------------------------------------///
//----------Download CSV------//
function download_csv(e, t) {
var n, o;
(n = new Blob([e], { type: "text/csv" })),
((o = document.createElement("a")).download = t),
(o.href = window.URL.createObjectURL(n)),
(o.style.display = "none"),
document.body.appendChild(o),
o.click();
}
function export_table_to_csv(e, t) {
for (
var n = [], o = document.querySelectorAll("table tr"), r = 0;
r < o.length;
r++
) {
for (
var a = [], l = o[r].querySelectorAll("td, th"), c = 0;
c < l.length;
c++
)
a.push(l[c].innerText);
n.push(a.join(","));
}
download_csv(n.join("\n"), t);
}
function downloadCsv() {
export_table_to_csv(
document.querySelector("table").outerHTML,
"candidaturas.csv"
);
}
//-------------------------------///
//Reset Display
function resetDisplay() {
Array.prototype.forEach.call(
document.getElementById("ttbody").getElementsByTagName("tr"),
function (e) {
e.style = "display: ";
}
);
}
//Service Worker
"serviceWorker" in navigator &&
window.addEventListener("load", function () {
navigator.serviceWorker
.register("serviceWorker.js")
.then(res => console.log("service worker registered"))
.catch(err => console.log("service worker not registered", err))
});