-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJSFW.js
196 lines (183 loc) · 4.9 KB
/
JSFW.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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
/*! Copyright © 2016 Mayank Mathur
see license at - https://raw.githubusercontent.com/Mynk-9/Javascript-Web-Framework/master/LICENSE
*/
(
function () {
var ___ = function (args) {
return new lib(args);
};
var lib = function (args) {
var selector = [];
if (typeof args === 'object') {
selector.push(args);
} else if (typeof args === 'string') {
selector = document.querySelectorAll(args);
}
this.length = selector.length;
if (typeof this.length === 'undefined') {this.length = 1;}
this.version = '2.0.0';
var i = 0;
for (i = 0; i < this.length; i++) {
this[i] = selector[i];
}
return this;
};
___.func = lib.prototype = {
/* general */
hide: function() {
var len = this.length;
while(len--) {
this[len].style.display = 'none';
}
return this;
},
show: function() {
var len = this.length;
while(len--) {
this[len].style.display = 'inherit';
}
return this;
},
coordinates: function() {
var pos = [];
if (this.length === 1) {
pos = {x: this[0].offsetLeft, y: this[0].offsetTop};
} else {
for (len = 0; len < this.length; len++) {
pos[len] = {x: this[len].offsetLeft, y: this[len].offsetTop};
}
}
return pos;
},
scrolled: function() {
var pos = [];
if (this.length === 1) {
pos = {x: this[0].scrollLeft, y: this[0].scrollTop};
} else {
for (len = 0; len < this.length; len++) {
pos[len] = {x: this[len].scrollLeft, y: this[len].scrollTop};
}
}
return pos;
},
animate: function(posFrom, posTo, func, time) {
if (typeof(func) != 'string' || typeof(posFrom) != 'object' || typeof(posTo) != 'object' || typeof(time) != 'number') {
console.log('error in animate function -> invalid arguments');
return 0;
}
//console.log(((posTo[1] - posFrom[1]) || (posTo.y - posFrom.y) || (posTo.y - posFrom[1]) || (posTo[1] - posFrom.y)));
var len = this.length;
console.log(this[0]);
var anims = [len];
while (len--) {
var diff_X = ((posTo[0] - posFrom[0]) || (posTo.x - posFrom.x) || (posTo.x - posFrom[0]) || (posTo[0] - posFrom.x));
var diff_Y = ((posTo[1] - posFrom[1]) || (posTo.y - posFrom.y) || (posTo.y - posFrom[1]) || (posTo[1] - posFrom.y));
var speed_X = diff_X / time;
var speed_Y = diff_Y / time;
var net_X, net_Y, fps;
net_X = (posFrom[0] || posFrom.x);
net_Y = (posFrom[1] || posFrom.y);
fps = 20;
var cont = 0;
var obj = this[len];
var itr = len;
anims[len] = setInterval(function() {
if (net_X < diff_X && net_Y < diff_Y) {
net_X += (speed_X / fps);
net_Y += (speed_Y / fps);
obj.style.left = net_X + 'px';
obj.style.top = net_Y + 'px';
} else {
clearInterval(anims[itr]);
}
}, time/fps*1000);
}
},
/* class, id etc. */
toggleClass: function(oldC, newC) {
var len = this.length;
while(len--) {
this[len].className = this[len].className.replace(oldC, newC);
}
return this;
},
getClass: function() {
var len = this.length;
if (len === 1) {
return this[0].className;
} else {
var classes = [];
while(len--) {
classes.push(this[len].className);
}
return classes;
}
},
getId: function() {
var len = this.length;
if (len === 1) {
return this[0].getAttribute('id');
} else {
var ids = [];
while(len--) {
ids.push(this[len].getAttribute('id'));
}
return ids;
}
},
addClass: function(_class) {
var len = this.length;
while(len--) {
if (this[len].className !== '') {
this[len].className += (' ' + _class);
} else {
this[len].className += _class;
}
}
return this;
},
removeClass: function(_class) {
var len = this.length;
while (len--) {
this[len].className = this[len].className.replace(_class, '');
}
return this;
},
/* events */
onEvent: function(evnt, fun) {
var len = this.length;
while(len--) {
this[len].addEventListener(evnt, fun);
}
return this;
},
/* external */
loadScriptFile: function(url) {
var x = document.createElement('script');
x.setAttribute('src', url);
document.head.appendChild(x);
return this;
},
loadCSSFile: function(url) {
var x = document.createElement('link');
x.setAttribute('rel', 'stylesheet');
x.setAttribute('href', url);
document.head.appendChild(x);
return this;
}
/* how to add new method
methodName: function(eventArgs) {
// all the code here
//
//
return this;
// or
return returnVar;
}
*/
};
if(!window.___) {
window.___ = ___;
}
}
)();