-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
116 lines (99 loc) · 2.45 KB
/
index.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
EventTarget.prototype.ev = EventTarget.prototype.addEventListener;
EventTarget.prototype.rmev = EventTarget.prototype.removeEventListener;
HTMLElement.prototype.css = function (styles) {
if (styles) {
for (s in styles)
this.style[s] = styles[s];
} else {
return this.style;
}
}
HTMLElement.prototype.load = function (url) {
if(this.classList.contains('loaded')) {
this.rmcls('hidden');
return;
}
request = new XMLHttpRequest();
request.open('GET', url);
request.send();
request.onload = () => {
if (request.status >= 200 && request.status < 400)
this.innerHTML = request.responseText;
this.init();
this.addcls('loaded');
this.rmcls('hidden');
}
}
HTMLElement.prototype.attr = function (attribute) {
return this.getAttribute(attribute);
}
HTMLElement.prototype.setattr = function (attribute, value) {
return this.setAttribute(attribute);
}
HTMLElement.prototype.rmcls = function (clsname) {
this.classList.remove(clsname);
}
HTMLElement.prototype.addcls = function (clsname) {
this.classList.add(clsname);
}
HTMLElement.prototype.up = function () {
return this.parentElement;
}
HTMLElement.prototype.upto = function (levels) {
if(levels) {
var elem = this;
for (var i=0; i<levels; i++) {
if(elem.parentElement) {
elem = elem.parentElement;
} else {
break;
}
}
return elem;
} else {
return this;
}
}
document.ready = (cb) => document.ev("DOMContentLoaded", cb);
w = (selector) => {
elements = document.querySelectorAll(selector);
if (elements.length == 0) return null;
if (elements.length == 1) return elements[0];
/* set methods over whole array */
elements.css = (styles) => {
for (i=0; i<elements.length; i++) {
e = elements[i];
e.css(styles);
}}
elements.ev = (evtype, cb) => {
for (i=0; i<elements.length; i++) {
e = elements[i];
e.ev(evtype, cb);
}}
elements.rmcls = (clsname) => {
for (i=0; i<elements.length; i++) {
var e = elements[i];
e.rmcls(clsname);
}}
elements.addcls = (clsname) => {
for (i=0; i<elements.length; i++) {
var e = elements[i];
e.addcls(clsname);
}}
return elements;
}
wtree = (root, tree) => {
}
time2str = function (time, lz=false) {
var minutes = Math.floor(time/60);
var seconds = time - minutes*60;
minutes = minutes.toString();
if(lz) {
for(var i=minutes.length; i<2; i++)
minutes = '0' + minutes;
}
seconds = seconds.toString();
for(var i=seconds.length; i<2; i++)
seconds = '0' + seconds;
return `${minutes}:${seconds}`;
}