diff options
author | ondrej.zara <none@none> | 2010-01-04 09:59:37 +0000 |
---|---|---|
committer | ondrej.zara <none@none> | 2010-01-04 09:59:37 +0000 |
commit | b238426f9ac5d4e70a200d32789c0ae3de50fa8c (patch) | |
tree | 91872e508b96d1c6b46e6d05cb7af89f0cc7213e | |
parent | 29839b3e81ac6d4dfd6eb40a104e9a6d50e31b0d (diff) | |
download | wwwsqldesigner-b238426f9ac5d4e70a200d32789c0ae3de50fa8c.zip wwwsqldesigner-b238426f9ac5d4e70a200d32789c0ae3de50fa8c.tar.gz wwwsqldesigner-b238426f9ac5d4e70a200d32789c0ae3de50fa8c.tar.bz2 |
faster oz events
--HG--
extra : convert_revision : svn%3Ab267cdba-c1da-11dd-874b-8bacd04a0a74/trunk%4076
-rw-r--r-- | js/oz.js | 42 |
1 files changed, 27 insertions, 15 deletions
@@ -1,4 +1,4 @@ -/* (c) 2007 - now() Ondrej Zara, 1.3 */ +/* (c) 2007 - now() Ondrej Zara, 1.5 */ var OZ = { $:function(x) { return typeof(x) == "string" ? document.getElementById(x) : x; }, opera:!!window.opera, @@ -8,7 +8,8 @@ var OZ = { khtml:!!navigator.userAgent.match(/khtml/i) || !!navigator.userAgent.match(/konqueror/i), Event:{ _id:0, - _cache:{}, + _byName:{}, + _byID:{}, add:function(elm,event,cb) { var id = OZ.Event._id++; var element = OZ.$(elm); @@ -21,12 +22,16 @@ var OZ = { element.attachEvent("on"+event,fnc); } } - OZ.Event._cache[id] = [element,event,fnc]; + if (!(event in OZ.Event._byName)) { OZ.Event._byName[event] = {}; } + var obj = OZ.Event._byName[event]; + obj[id] = [element,event,fnc]; + OZ.Event._byID[id] = obj; return id; }, remove:function(id) { - var e = OZ.Event._cache[id]; - if (!e) { return; } + var obj = OZ.Event._byID[id]; + if (!obj) { return; } + var e = obj[id]; var elm = e[0]; if (elm) { if (elm.removeEventListener) { @@ -35,7 +40,8 @@ var OZ = { elm.detachEvent("on"+e[1],e[2]); } } - delete OZ.Event._cache[id]; + delete OZ.Event._byID[id]; + delete obj[id]; }, stop:function(e) { e.stopPropagation ? e.stopPropagation() : e.cancelBubble = true; }, prevent:function(e) { e.preventDefault ? e.preventDefault() : e.returnValue = false; }, @@ -56,12 +62,7 @@ var OZ = { this.prototype = new tmp(); return this; }; - c.prototype.bind = function(fnc) { - var obj = this; - return function() { - return fnc.apply(obj,arguments); - } - }; + c.prototype.bind = function(fnc) { return fnc.bind(this); }; c.prototype.dispatch = function(type, data) { var obj = { type:type, @@ -70,9 +71,10 @@ var OZ = { data:data } var tocall = []; - for (var p in OZ.Event._cache) { - var item = OZ.Event._cache[p]; - if (item[1] == type && (!item[0] || item[0] == this)) { tocall.push(item[2]); } + var list = OZ.Event._byName[type]; + for (var id in list) { + var item = list[id]; + if (!item[0] || item[0] == this) { tocall.push(item[2]); } } var len = tocall.length; for (var i=0;i<len;i++) { tocall[i](obj); } @@ -218,6 +220,16 @@ var OZ = { } } +if (!Function.prototype.bind) { + Function.prototype.bind = function(thisObj) { + var fn = this; + var args = Array.prototype.slice.call(arguments, 1); + return function() { + return fn.apply(thisObj, args.concat(Array.prototype.slice.call(arguments))); + } + } +}; + if (!Array.prototype.indexOf) { Array.prototype.indexOf = function(item, from) { var len = this.length; |