Skip to content

Commit 61e8abb

Browse files
committed
Adapted to work on IE8 with text output
1 parent 8daad48 commit 61e8abb

8 files changed

Lines changed: 72 additions & 22 deletions

File tree

Canvas.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ Canvas.prototype = {
364364
aTextBufferRow = aTextBuffer[y];
365365
if (aTextBufferRow) {
366366
for (x = 0; x < aTextBufferRow.length; x += 1) {
367-
sOut += this.sCpc2Unicode[aTextBufferRow[x] || 32];
367+
sOut += this.sCpc2Unicode.charAt(aTextBufferRow[x] || 32); // works also on IE8, (not: this.sCpc2Unicode[...])
368368
}
369369
}
370370
sOut += "\n";
@@ -441,7 +441,7 @@ Canvas.prototype = {
441441

442442
setFocusOnCanvas: function () {
443443
this.cpcAreaBox.style.background = "#463c3c";
444-
if (this.canvas) {
444+
if (this.canvas && this.canvas.focus) {
445445
this.canvas.focus();
446446
}
447447
this.bHasFocus = true;
@@ -501,7 +501,11 @@ Canvas.prototype = {
501501
} else {
502502
this.canvasClickAction2(event);
503503
}
504-
event.stopPropagation();
504+
if (event.stopPropagation) {
505+
event.stopPropagation();
506+
} else {
507+
// window.event.stopPropagation(); // howto on IE8?
508+
}
505509
},
506510

507511
onWindowClick: function () {

Controller.js

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1761,7 +1761,11 @@ Controller.prototype = {
17611761
},
17621762

17631763
startScreenshot: function () {
1764-
var image = this.oCanvas.canvas.toDataURL("image/png").replace("image/png", "image/octet-stream"); // here is the most important part because if you do not replace you will get a DOM 18 exception.
1764+
var image = "";
1765+
1766+
if (this.oCanvas.canvas.toDataURL) {
1767+
image = this.oCanvas.canvas.toDataURL("image/png").replace("image/png", "image/octet-stream"); // here is the most important part because if you do not replace you will get a DOM 18 exception.
1768+
}
17651769

17661770
return image;
17671771
},
@@ -2075,15 +2079,23 @@ Controller.prototype = {
20752079
},
20762080

20772081
initDropZone: function () {
2078-
var dropZone = document.getElementById("dropZone");
2082+
var dropZone = document.getElementById("dropZone"),
2083+
canvas = this.oCanvas.canvas,
2084+
fileInput = document.getElementById("fileInput");
20792085

2080-
dropZone.addEventListener("dragover", this.fnHandleDragOver.bind(this), false);
2081-
dropZone.addEventListener("drop", this.fnHandleFileSelect.bind(this), false);
2086+
if (dropZone.addEventListener) {
2087+
dropZone.addEventListener("dragover", this.fnHandleDragOver.bind(this), false);
2088+
dropZone.addEventListener("drop", this.fnHandleFileSelect.bind(this), false);
2089+
}
20822090

2083-
this.oCanvas.canvas.addEventListener("dragover", this.fnHandleDragOver.bind(this), false);
2084-
this.oCanvas.canvas.addEventListener("drop", this.fnHandleFileSelect.bind(this), false);
2091+
if (canvas.addEventListener) {
2092+
canvas.addEventListener("dragover", this.fnHandleDragOver.bind(this), false);
2093+
canvas.addEventListener("drop", this.fnHandleFileSelect.bind(this), false);
2094+
}
20852095

2086-
document.getElementById("fileInput").addEventListener("change", this.fnHandleFileSelect.bind(this), false);
2096+
if (fileInput.addEventListener) {
2097+
fileInput.addEventListener("change", this.fnHandleFileSelect.bind(this), false);
2098+
}
20872099
},
20882100

20892101
fnUpdateUndoRedoButtons: function () {

Keyboard.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,8 +209,13 @@ Keyboard.prototype = {
209209
this.bCodeStringsRemoved = false;
210210

211211
cpcArea = document.getElementById("cpcArea");
212-
cpcArea.addEventListener("keydown", this.onCpcAreaKeydown.bind(this), false);
213-
cpcArea.addEventListener("keyup", this.oncpcAreaKeyup.bind(this), false);
212+
if (cpcArea.addEventListener) {
213+
cpcArea.addEventListener("keydown", this.onCpcAreaKeydown.bind(this), false);
214+
cpcArea.addEventListener("keyup", this.oncpcAreaKeyup.bind(this), false);
215+
} else { // IE8?
216+
cpcArea.attachEvent("onkeydown", this.onCpcAreaKeydown.bind(this));
217+
cpcArea.attachEvent("onkeyup", this.oncpcAreaKeyup.bind(this));
218+
}
214219
},
215220

216221
reset: function () {

Polyfills.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,14 +104,19 @@ if (window.Element) {
104104
}
105105

106106
if (window.Event) {
107+
// https://stackoverflow.com/questions/17102300/prototype-event-stoppropagation-for-ie-8
107108
if (!Event.prototype.preventDefault) { // IE8
108109
Utils.console.debug("Polyfill: Event.prototype.preventDefault");
109-
Event.prototype.preventDefault = function () { }; // eslint-disable-line no-empty-function
110+
Event.prototype.preventDefault = function () {
111+
this.returnValue = false;
112+
};
110113
}
111114

112115
if (!Event.prototype.stopPropagation) { // IE8
113116
Utils.console.debug("Polyfill: Event.prototype.stopPropagation");
114-
Event.prototype.stopPropagation = function () { }; // eslint-disable-line no-empty-function
117+
Event.prototype.stopPropagation = function () {
118+
this.cancelBubble = true;
119+
};
115120
}
116121
}
117122

View.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,11 @@ View.prototype = {
9191
option.value = oItem.value;
9292
option.text = oItem.text;
9393
option.title = oItem.title;
94-
select.add(option, null); // null needed for old FF 3.x
94+
try {
95+
select.add(option, null); // null needed for old FF 3.x
96+
} catch (e) {
97+
select.add(option); // null must not be used for IE8
98+
}
9599
} else {
96100
option = select.options[i];
97101
if (option.value !== oItem.value) {

VirtualKeyboard.js

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -618,6 +618,12 @@ VirtualKeyboard.prototype = {
618618
Utils.console.log("fnAttachPointerEvents: Using", oEventNames.type, "events");
619619
}
620620

621+
if (!area.addEventListener) { // IE8
622+
area.addEventListener = function (type, listener) {
623+
area.attachEvent("on" + type, listener);
624+
};
625+
}
626+
621627
if (fnDown) {
622628
area.addEventListener(oEventNames.down, fnDown, false); // +clicked for pointer, touch?
623629
}
@@ -816,9 +822,15 @@ VirtualKeyboard.prototype = {
816822
}
817823

818824
if (this.sPointerOutEvent) {
819-
node.addEventListener(this.sPointerOutEvent, this.fnVirtualKeyout, false);
825+
if (node.addEventListener) {
826+
node.addEventListener(this.sPointerOutEvent, this.fnVirtualKeyout, false);
827+
} else { // IE8
828+
node.attachEvent("on" + this.sPointerOutEvent, this.fnVirtualKeyout);
829+
}
830+
}
831+
if (event.preventDefault) {
832+
event.preventDefault();
820833
}
821-
event.preventDefault();
822834
return false;
823835
},
824836

@@ -857,9 +869,15 @@ VirtualKeyboard.prototype = {
857869
this.fnVirtualKeyboardKeyupOrKeyout(event);
858870

859871
if (this.sPointerOutEvent && this.fnVirtualKeyout) {
860-
node.removeEventListener(this.sPointerOutEvent, this.fnVirtualKeyout); // do not need out event any more
872+
if (node.removeEventListener) {
873+
node.removeEventListener(this.sPointerOutEvent, this.fnVirtualKeyout); // do not need out event any more
874+
} else { // IE8
875+
node.detachEvent("on" + this.sPointerOutEvent, this.fnVirtualKeyout);
876+
}
877+
}
878+
if (event.preventDefault) {
879+
event.preventDefault();
861880
}
862-
event.preventDefault();
863881
return false;
864882
},
865883

@@ -873,7 +891,9 @@ VirtualKeyboard.prototype = {
873891
if (this.sPointerOutEvent && this.fnVirtualKeyout) {
874892
node.removeEventListener(this.sPointerOutEvent, this.fnVirtualKeyout);
875893
}
876-
event.preventDefault();
894+
if (event.preventDefault) {
895+
event.preventDefault();
896+
}
877897
return false;
878898
},
879899

index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
55
<meta name="viewport" content="width=device-width, initial-scale=1.0">
66
<link rel="stylesheet" href="cpcbasic.css" />
7-
<title id="title">CPC Basic v0.10.10</title>
7+
<title id="title">CPC Basic v0.10.11</title>
88
</head>
99

1010
<body id="pageBody">

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "cpcbasic",
3-
"version": "0.10.10",
3+
"version": "0.10.11",
44
"description": "# CPCBasic - Run CPC BASIC in a Browser",
55
"main": "cpcbasic.js",
66
"directories": {

0 commit comments

Comments
 (0)