Made Events work under IE, added some TODO for Events. Other minor adjustments for IE9+ compatability ( <=IE8 needs some fixes)

HEAD
kts 2013-03-17 22:50:32 -07:00
parent 7ad8029abf
commit 73f99487ea
2 changed files with 31 additions and 7 deletions

31
CBDL.js
View File

@ -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) {

View File

@ -1,4 +1,4 @@
<html>
<!DOCTYPE html>
<head>
<script type="text/javascript" src="CBDL.js"></script>
<script type="text/javascript">
@ -86,14 +86,13 @@ myApp2 = function() {
this.Main = function() {
display = new CBDL.Graphics.Display(document.body, new CBDL.Graphics.VideoMode(320, 240, CBDL.Graphics.VM_SCALE), CBDL.Graphics.BACKEND.CANVAS_2D);
console.log("Display Type: "+display.type);
display.Init();
display.Fill(0x00, 0x00, 0x00);
var drawable = new display.Drawable();
console.log(drawable.testFunc);
drawable.testFunc();
events = new CBDL.Event(["keydown", "keyup", "focus", "blur"]);
events = new CBDL.Event(["blur", "focus", "keydown", "keyup"], document.body);
(main_loop = new CBDL.Loop(this, onLoop)).start();
};