From 73f99487ea83b7dc4dc6855e2c3804ba9e564984 Mon Sep 17 00:00:00 2001 From: kts Date: Sun, 17 Mar 2013 22:50:32 -0700 Subject: [PATCH] Made Events work under IE, added some TODO for Events. Other minor adjustments for IE9+ compatability ( <=IE8 needs some fixes) --- CBDL.js | 31 ++++++++++++++++++++++++++++--- cbdl.html | 7 +++---- 2 files changed, 31 insertions(+), 7 deletions(-) diff --git a/CBDL.js b/CBDL.js index ab244c3..b3283a9 100644 --- a/CBDL.js +++ b/CBDL.js @@ -109,6 +109,7 @@ CBDL.Includes = function(app) { var exists = false; // Compare some_library string to every script.src so as to disallow // multiple loading of the same library. + // TODO: implement getElementsByTagName for <=IE8 var script_list = document.head.getElementsByTagName('script'); for(script in script_list) { if (script_list[script].src) { @@ -452,10 +453,34 @@ CBDL.Event = CBDL.Event || function(event_types, context) { context = (typeof context !== 'undefined' ? context : window); this.event_pool = new CBDL.Event.EventPool; for (event_type in event_types) { - console.log(context); CBDL.addEvent(context, event_types[event_type], (function(scope) { return function(event) { - scope.handleEvent(event); + // IE is so broken. After pushing an event to + // an array, and even after checking if the + // event is still a proper event(check its + // .type property) after you PUSH it, + // once you attempt to retrieve it, it somehow + // reverts to a basic MSEventObj object. WTF + // AKA: + // event_list.push(event); + // console.log(event_list[0].type); + // ^-- returns "keydown" + // THEN, elsewhere: + // console.log(event_list[0].type); + // ^-- ERROR, NO SUCH MEMBER + // This problem is bypassed if you first create + // a new Object, copy the event's properties + // to it, then push that new Object to the + // array. It can retrieve the data fine + // afterwards. This must mean that IE destroys + // the Event object, even if you add it to an + // array. :( + // TODO: make an IE-only CBDL.Event. + var _event_ = new Object(); + for (property in event) { + _event_[property] = event[property]; + } + scope.handleEvent(_event_); } })(this)); } @@ -488,7 +513,7 @@ CBDL.Event.EventPool.prototype.getNext = function() { if (this.events.length > 0) { return this.events.shift(); } - return -1; + return false; }; CBDL.Event.EventPool.prototype.push = function(event) { diff --git a/cbdl.html b/cbdl.html index 0e4fdd1..9b2f168 100644 --- a/cbdl.html +++ b/cbdl.html @@ -1,4 +1,4 @@ - +