Made Events work under IE, added some TODO for Events. Other minor adjustments for IE9+ compatability ( <=IE8 needs some fixes)
parent
7ad8029abf
commit
73f99487ea
31
CBDL.js
31
CBDL.js
|
@ -109,6 +109,7 @@ CBDL.Includes = function(app) {
|
||||||
var exists = false;
|
var exists = false;
|
||||||
// Compare some_library string to every script.src so as to disallow
|
// Compare some_library string to every script.src so as to disallow
|
||||||
// multiple loading of the same library.
|
// multiple loading of the same library.
|
||||||
|
// TODO: implement getElementsByTagName for <=IE8
|
||||||
var script_list = document.head.getElementsByTagName('script');
|
var script_list = document.head.getElementsByTagName('script');
|
||||||
for(script in script_list) {
|
for(script in script_list) {
|
||||||
if (script_list[script].src) {
|
if (script_list[script].src) {
|
||||||
|
@ -452,10 +453,34 @@ CBDL.Event = CBDL.Event || function(event_types, context) {
|
||||||
context = (typeof context !== 'undefined' ? context : window);
|
context = (typeof context !== 'undefined' ? context : window);
|
||||||
this.event_pool = new CBDL.Event.EventPool;
|
this.event_pool = new CBDL.Event.EventPool;
|
||||||
for (event_type in event_types) {
|
for (event_type in event_types) {
|
||||||
console.log(context);
|
|
||||||
CBDL.addEvent(context, event_types[event_type], (function(scope) {
|
CBDL.addEvent(context, event_types[event_type], (function(scope) {
|
||||||
return function(event) {
|
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));
|
})(this));
|
||||||
}
|
}
|
||||||
|
@ -488,7 +513,7 @@ CBDL.Event.EventPool.prototype.getNext = function() {
|
||||||
if (this.events.length > 0) {
|
if (this.events.length > 0) {
|
||||||
return this.events.shift();
|
return this.events.shift();
|
||||||
}
|
}
|
||||||
return -1;
|
return false;
|
||||||
};
|
};
|
||||||
|
|
||||||
CBDL.Event.EventPool.prototype.push = function(event) {
|
CBDL.Event.EventPool.prototype.push = function(event) {
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
<html>
|
<!DOCTYPE html>
|
||||||
<head>
|
<head>
|
||||||
<script type="text/javascript" src="CBDL.js"></script>
|
<script type="text/javascript" src="CBDL.js"></script>
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
|
@ -86,14 +86,13 @@ myApp2 = function() {
|
||||||
|
|
||||||
this.Main = 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);
|
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.Init();
|
||||||
display.Fill(0x00, 0x00, 0x00);
|
display.Fill(0x00, 0x00, 0x00);
|
||||||
|
|
||||||
var drawable = new display.Drawable();
|
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();
|
(main_loop = new CBDL.Loop(this, onLoop)).start();
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue