mirror of
https://github.com/inexorabletash/jsbasic.git
synced 2025-05-14 09:38:16 +00:00
Use newer keyboard polyfill, require IE8+
This commit is contained in:
parent
308c2d0baf
commit
30ff0201d8
20
index.js
20
index.js
@ -86,7 +86,7 @@ window.addEventListener('DOMContentLoaded', function () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var program;
|
var program;
|
||||||
addEvent($('#btn_run'), 'click', function () {
|
$('#btn_run').addEventListener('click', function () {
|
||||||
dos.reset();
|
dos.reset();
|
||||||
tty.reset();
|
tty.reset();
|
||||||
tty.autoScroll = true;
|
tty.autoScroll = true;
|
||||||
@ -117,22 +117,22 @@ window.addEventListener('DOMContentLoaded', function () {
|
|||||||
setTimeout(driver, 0);
|
setTimeout(driver, 0);
|
||||||
});
|
});
|
||||||
|
|
||||||
addEvent($('#btn_stop'), 'click', function () {
|
$('#btn_stop').addEventListener('click', function () {
|
||||||
tty.reset(); // cancel any blocking input
|
tty.reset(); // cancel any blocking input
|
||||||
stopped = true;
|
stopped = true;
|
||||||
updateUI();
|
updateUI();
|
||||||
});
|
});
|
||||||
|
|
||||||
addEvent($('#lb_files'), 'change', function () {
|
$('#lb_files').addEventListener('change', function () {
|
||||||
var sel = $('#lb_files');
|
var sel = $('#lb_files');
|
||||||
loadFile('samples/' + sel.value + ".txt", setSource);
|
loadFile('samples/' + sel.value + ".txt", setSource);
|
||||||
});
|
});
|
||||||
|
|
||||||
addEvent($('#btn_save'), 'click', function () {
|
$('#btn_save').addEventListener('click', function () {
|
||||||
window.localStorage.setItem("save_program", getSource());
|
window.localStorage.setItem("save_program", getSource());
|
||||||
$('#btn_load').disabled = false;
|
$('#btn_load').disabled = false;
|
||||||
});
|
});
|
||||||
addEvent($('#btn_load'), 'click', function () {
|
$('#btn_load').addEventListener('click', function () {
|
||||||
setSource(window.localStorage.getItem("save_program"));
|
setSource(window.localStorage.getItem("save_program"));
|
||||||
});
|
});
|
||||||
$('#btn_load').disabled = (window.localStorage.getItem("save_program") === null);
|
$('#btn_load').disabled = (window.localStorage.getItem("save_program") === null);
|
||||||
@ -140,19 +140,19 @@ window.addEventListener('DOMContentLoaded', function () {
|
|||||||
// Add a "printer" on demand
|
// Add a "printer" on demand
|
||||||
var printer = null;
|
var printer = null;
|
||||||
var paper = $('#paper');
|
var paper = $('#paper');
|
||||||
addEvent($('#show_paper'), 'click', function () {
|
$('#show_paper').addEventListener('click', function () {
|
||||||
window.getClassList(document.body).add('printout');
|
document.body.classList.add('printout');
|
||||||
printer = new Printer(tty, paper);
|
printer = new Printer(tty, paper);
|
||||||
});
|
});
|
||||||
addEvent($('#hide_paper'), 'click', function () {
|
$('#hide_paper').addEventListener('click', function () {
|
||||||
window.getClassList(document.body).remove('printout');
|
document.body.classList.remove('printout');
|
||||||
printer.close();
|
printer.close();
|
||||||
printer = null;
|
printer = null;
|
||||||
});
|
});
|
||||||
|
|
||||||
// Mouse-as-Joystick
|
// Mouse-as-Joystick
|
||||||
var wrapper = $('#screen-wrapper');
|
var wrapper = $('#screen-wrapper');
|
||||||
addEvent(wrapper, 'mousemove', function (e) {
|
wrapper.addEventListener('mousemove', function (e) {
|
||||||
var rect = wrapper.getBoundingClientRect(),
|
var rect = wrapper.getBoundingClientRect(),
|
||||||
x = e.clientX - rect.left, y = e.clientY - rect.top;
|
x = e.clientX - rect.left, y = e.clientY - rect.top;
|
||||||
function clamp(n, min, max) { return n < min ? min : n > max ? max : n; }
|
function clamp(n, min, max) { return n < min ? min : n > max ? max : n; }
|
||||||
|
2
polyfill
2
polyfill
@ -1 +1 @@
|
|||||||
Subproject commit 36bbc210fb65bfd25d075d5eec077822d7b0d5c6
|
Subproject commit 007919d32364e9af78b79a7fc3dbb1e66fc0c875
|
@ -74,7 +74,7 @@
|
|||||||
var pdl = [0, 0, 0, 0];
|
var pdl = [0, 0, 0, 0];
|
||||||
|
|
||||||
// Mouse-as-Joystick
|
// Mouse-as-Joystick
|
||||||
addEvent(wrapper_elem, 'mousemove', function (e) {
|
wrapper_elem.addEventListener('mousemove', function (e) {
|
||||||
var rect = wrapper_elem.getBoundingClientRect(),
|
var rect = wrapper_elem.getBoundingClientRect(),
|
||||||
x = e.clientX - rect.left, y = e.clientY - rect.top;
|
x = e.clientX - rect.left, y = e.clientY - rect.top;
|
||||||
function clamp(n, min, max) { return n < min ? min : n > max ? max : n; }
|
function clamp(n, min, max) { return n < min ? min : n > max ? max : n; }
|
||||||
|
22
tty.js
22
tty.js
@ -167,8 +167,8 @@ function TTY(screenElement, keyboardElement, bell) {
|
|||||||
tbody = document.createElement('tbody');
|
tbody = document.createElement('tbody');
|
||||||
styleElem = tbody;
|
styleElem = tbody;
|
||||||
|
|
||||||
getClassList(styleElem).add(screenWidth === 40 ? 'jsb-40col' : 'jsb-80col');
|
styleElem.classList.add(screenWidth === 40 ? 'jsb-40col' : 'jsb-80col');
|
||||||
if (firmwareActive) { getClassList(styleElem).add('jsb-active'); }
|
if (firmwareActive) { styleElem.classList.add('jsb-active'); }
|
||||||
|
|
||||||
for (y = 0; y < screenHeight; y += 1) {
|
for (y = 0; y < screenHeight; y += 1) {
|
||||||
tr = document.createElement('tr');
|
tr = document.createElement('tr');
|
||||||
@ -732,11 +732,8 @@ function TTY(screenElement, keyboardElement, bell) {
|
|||||||
|
|
||||||
// Internal
|
// Internal
|
||||||
function handleKeyDown(e) {
|
function handleKeyDown(e) {
|
||||||
identifyKey(e);
|
if (!e.code || isBrowserKey(e))
|
||||||
|
|
||||||
if (!e.code || isBrowserKey(e)) {
|
|
||||||
return true;
|
return true;
|
||||||
}
|
|
||||||
|
|
||||||
var handled = false, code;
|
var handled = false, code;
|
||||||
|
|
||||||
@ -780,14 +777,11 @@ function TTY(screenElement, keyboardElement, bell) {
|
|||||||
|
|
||||||
// Internal
|
// Internal
|
||||||
function handleKeyUp(e) {
|
function handleKeyUp(e) {
|
||||||
identifyKey(e);
|
if (!e.code || isBrowserKey(e))
|
||||||
|
|
||||||
if (!e.code || isBrowserKey(e)) {
|
|
||||||
return true;
|
return true;
|
||||||
}
|
|
||||||
|
|
||||||
var handled = false,
|
var handled = false,
|
||||||
code;
|
code;
|
||||||
|
|
||||||
switch (e.code) {
|
switch (e.code) {
|
||||||
|
|
||||||
@ -876,10 +870,10 @@ function TTY(screenElement, keyboardElement, bell) {
|
|||||||
|
|
||||||
init(false, 24, 40);
|
init(false, 24, 40);
|
||||||
|
|
||||||
window.addEvent(keyboardElement, 'keydown', handleKeyDown);
|
keyboardElement.addEventListener('keydown', handleKeyDown);
|
||||||
window.addEvent(keyboardElement, 'keyup', handleKeyUp);
|
keyboardElement.addEventListener('keyup', handleKeyUp);
|
||||||
|
|
||||||
setInterval(function blinkFlash() {
|
setInterval(function blinkFlash() {
|
||||||
window.getClassList(styleElem).toggle('jsb-flash');
|
styleElem.classList.toggle('jsb-flash');
|
||||||
}, 250);
|
}, 250);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user