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 @@ ...@@ -361,7 +361,7 @@
* Wrapper for .addEventListener and .attachEvent. * 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') { if ((type.substr(0,2).toLowerCase()) == 'on') {
type = type.substr(2); type = type.substr(2);
} }
...@@ -370,27 +370,56 @@ ...@@ -370,27 +370,56 @@
capture = false; capture = false;
} }
if (el.addEventListener){ if (obj.addEventListener) {
el.addEventListener(type, listener, capture); obj.addEventListener(type, listener, capture);
} else if (el.attachEvent) { } else if (obj.attachEvent) {
/* In IE events always bubble, no capturing possibility. */ obj['__e' + type + listener] = listener;
el.attachEvent('on' + type, listener);
/*
var _type = 'on' + type;
if (el[_type] === null) { obj[type + listener] = function() {
el[_type] = listener; obj['__e' + type + listener](window.event);
} else {
el[_type] = function() {
el[_type](); listener();
}
} }
*/
obj.attachEvent('on' + type, obj[type + listener] );
} else { } else {
; ;
} }
} }
/* 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 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