Commit b8080f63 authored by Julien Cigar's avatar Julien Cigar
Browse files

rewrote the way Evt.bind works + added Evt.unbind

parent c5ff2f1b
......@@ -361,7 +361,7 @@
* Wrapper for .addEventListener and .attachEvent.
*/
Yeti.Evt.bind = function(el, type, listener, capture) {
Yeti.Evt.bind = function(obj, type, listener, capture) {
if ((type.substr(0,2).toLowerCase()) == 'on') {
type = type.substr(2);
}
......@@ -370,28 +370,57 @@
capture = false;
}
if (el.addEventListener){
el.addEventListener(type, listener, capture);
} else if (el.attachEvent) {
/* In IE events always bubble, no capturing possibility. */
el.attachEvent('on' + type, listener);
/*
var _type = 'on' + type;
if (obj.addEventListener) {
obj.addEventListener(type, listener, capture);
} else if (obj.attachEvent) {
obj['__e' + type + listener] = listener;
obj[type + listener] = function() {
obj['__e' + type + listener](window.event);
}
if (el[_type] === null) {
el[_type] = listener;
obj.attachEvent('on' + type, obj[type + listener] );
} else {
el[_type] = function() {
el[_type](); listener();
;
}
}
/* Yeti.Evt.unbind
* Wrapper for .removeEventListener and .detachEvent.
*/
Yeti.Evt.unbind = function(obj, type, listener, capture) {
if ((type.substr(0,2).toLowerCase()) == 'on') {
type = type.substr(2);
}
if (typeof(capture) != 'boolean') {
capture = false;
}
if (obj.removeEventListener) {
obj.removeEventListener(type, listener, capture);
} else if (obj.detachEvent) {
obj.detachEvent('on' + type, obj[type + listener]);
// Prevent a memory leak in IE.
try {
// Check if delete is supported
if (delete({})) {
delete(obj[type + listener]);
delete(obj['__e' + type + listener]);
} else {
throw "delete";
};
} catch(e) {
obj[type + listener] = null;
obj['__e' + type + listener] = null;
}
*/
} else {
;
}
}
/***********************************************************************
DOM
************************************************************************/
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment