var evtKonstruktor makeFn function fn normal block return block normal

  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
var evtKonstruktor = {
makeFn: function( fn, normal, block ) {
return !(block || normal) ? 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 d = doc, body = d.body, doc = d.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;
if (e.target && e.target.nodeType == 3) {
e.target = e.target.parentNode;
}
}
e.preventDefault ||
(e.preventDefault = function() {
this.returnValue = false;
});
e.stopPropagation ||
(e.stopPropagation = function() {
this.cancelBubble = true;
});
} catch (f) {
}
if (fn.call(el, e) === false || block) {
e.preventDefault();
e.stopPropagation();
e.cancel = true;
return false;
}
};
},
addHandler: (function() {
if (doc.addEventListener) {
return function(el, type, fn) {
return el.addEventListener(type, fn, false);
}
} else if (doc.attachEvent) {
return function(el, type, fn) {
el['e' + type + fn] = fn;
el[type + fn] = function() {
if (el['e' + type + fn](win.event) === false)
return false;
}
el.attachEvent('on' + type, el[type + fn]);
}
} else {
return function(el, type, fn) {
return el['on' + type] = function(e) {
if (!el || !el.events || !el.events[type])
return;
var evts = el.events[type];
for (var i = 0, len = evts.length; i < len; i++)
evts[i].call(el, e);
};
}
}
})(),
bind: function(el, type, fn, normal, block, quick) {
var test, _fn = this.makeFn( fn, normal, block);
if(quick)
return this.addHandler(el, type, _fn);
if (!el.events)
el.events = {};
if (!el.events[type])
el.events[type] = [];
var evts = el.events[type];
evts[evts.length] = _fn;
return this.addHandler(el, type, _fn);
},
unbind: function(el, type, fn) {
if (fn) {
return this.removeHandler(el, type, fn);
} else {
if (el.events && el.events[type]) {
var evts = el.events[type];
for (var i = 0, len = evts.length; i < len; i++)
this.removeHandler(el, type, evts[i]);
el.events[type] = null;
}
}
},
removeHandler: (function() {
if (doc.removeEventListener) {
return function(el, type, fn) {
el.removeEventListener(type, fn, false);
}
} else if (doc.detachEvent) {
return function(el, type, fn) {
el.detachEvent('on' + type, el[type + fn]);
el[type + fn] = null;
}
} else {
return function(el, type, fn) {
el["on" + type] = null;
}
}
})()
}