-
Notifications
You must be signed in to change notification settings - Fork 0
/
Util.js
62 lines (54 loc) · 1.55 KB
/
Util.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
var Util = {
event : {
on : function(element, type, handler) {
if (element.addEventListener) {
element.addEventListener(type, handler, false);
} else if (element.attachEvent) {
element.attachEvent("on" + type, handler);
} else {
element['on' + type] = handler;
}
},
off : function(element, type, handler){
if (element.removeEventListener){
element.removeEventListener(type, handler, false);
} else if (element.detachEvent){
element.detachEvent('on' + type, handler);
} else {
element['on' + type] = null;
}
},
getEvent : function (e) {
return e || window.event;
},
getPageAxis: function(event) {
if(event.pageX || event.pageY){
return {
x : event.pageX,
y : event.pageY
}
}
var doc = document.documentElement;
var body = document.body;
return {
x : event.clientX +
( doc && doc.scrollLeft || body && body.scrollLeft || 0 ) -
( doc && doc.clientLeft || body && body.clientLeft || 0 ),
y : event.clientY +
( doc && doc.scrollTop || body && body.scrollTop || 0 ) -
( doc && doc.clientTop || body && body.clientTop || 0 )
}
}
},
extend : function () {
var result = {}
for(var i = 0, j = arguments.length; i < j; i++){
for (var p in arguments[i]) {
if (arguments[i].hasOwnProperty(p)) {
result[p] = arguments[i][p];
}
}
}
return result;
}
}