-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathutils.js
54 lines (43 loc) · 1.2 KB
/
utils.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
//Defines the top level Class
function Class() { }
Class.prototype.construct = function() {};
Class.extend = function(def) {
var classDef = function() {
if (arguments[0] !== Class) { this.construct.apply(this, arguments); }
};
var proto = new this(Class);
var superClass = this.prototype;
for (var n in def) {
var item = def[n];
if (item instanceof Function)
{
item.$ = superClass;
}
proto[n] = item;
}
classDef.prototype = proto;
//Give this new class the same static extend method
classDef.extend = this.extend;
return classDef;
};
_ = function(name)
{
return $(name).get(0);
};
Object.prototype.position = function()
{
var node = this;
var x = 0;
var y = 0;
while (node)
{
if (!isNaN(node.offsetLeft) && !isNaN(node.offsetLeft))
{
x += node.offsetLeft ? node.offsetLeft : 0;
y += node.offsetTop ? node.offsetTop : 0;
console.log(node.offsetLeft + ', ' + node.offsetTop);
}
node = node.parentNode;
}
return { x: x, y: y };
}