bind function el type fn normal block var test _fn if normal block _fn

 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
bind: function(el, type, fn, normal, block) {
var test, _fn;
if (normal || block) {
_fn = function(e) {
try {
e = e || win.event;
if (normal) {
e.target || (e.target = e.srcElement || doc);
e.which || (e.which = e.charCode || e.keyCode);
if (e.pageX == null && e.clientX != null) {
var body = document.body, doc = doc.documentElement;
e.pageX = e.clientX + (doc && doc.scrollLeft || body && body.scrollLeft || 0) - (doc.clientLeft || 0);
e.pageY = e.clientY + (doc && doc.scrollTop || body && body.scrollTop || 0) - (doc.clientTop || 0);
}
e.x = e.pageX || e.clientX;
e.y = e.pageY || e.clientY;
if (e.type === 'keypress')
e.charCode = e.charCode || e.keyCode;
while (e.target && e.target.nodeType == 3) {
e.target = e.target.parentNode;
}
}
if (block) {
e.preventDefault ||
(e.preventDefault = function() {
e.returnValue = false;
});
e.stopPropagation ||
(e.stopPropagation = function() {
e.cancelBubble = true;
});
}
} catch (f) {
}
if (fn.call(el, e) === false || block) {
return false;
}
}
//test = [type + fn, _fn];
} else {
//test = [type + fn, fn];
_fn = fn;
}
if (!el.events)
el.events = {};
if (!el.events[type])
el.events[type] = [];
var evts = el.events[type];
evts[evts.length] = _fn;//test[1];
return this.add(el, type, _fn);
}