Use newer keyboard polyfill, require IE8+

This commit is contained in:
Joshua Bell 2014-01-22 21:06:31 -08:00
parent 308c2d0baf
commit 30ff0201d8
4 changed files with 20 additions and 26 deletions

View File

@ -86,7 +86,7 @@ window.addEventListener('DOMContentLoaded', function () {
}
var program;
addEvent($('#btn_run'), 'click', function () {
$('#btn_run').addEventListener('click', function () {
dos.reset();
tty.reset();
tty.autoScroll = true;
@ -117,22 +117,22 @@ window.addEventListener('DOMContentLoaded', function () {
setTimeout(driver, 0);
});
addEvent($('#btn_stop'), 'click', function () {
$('#btn_stop').addEventListener('click', function () {
tty.reset(); // cancel any blocking input
stopped = true;
updateUI();
});
addEvent($('#lb_files'), 'change', function () {
$('#lb_files').addEventListener('change', function () {
var sel = $('#lb_files');
loadFile('samples/' + sel.value + ".txt", setSource);
});
addEvent($('#btn_save'), 'click', function () {
$('#btn_save').addEventListener('click', function () {
window.localStorage.setItem("save_program", getSource());
$('#btn_load').disabled = false;
});
addEvent($('#btn_load'), 'click', function () {
$('#btn_load').addEventListener('click', function () {
setSource(window.localStorage.getItem("save_program"));
});
$('#btn_load').disabled = (window.localStorage.getItem("save_program") === null);
@ -140,19 +140,19 @@ window.addEventListener('DOMContentLoaded', function () {
// Add a "printer" on demand
var printer = null;
var paper = $('#paper');
addEvent($('#show_paper'), 'click', function () {
window.getClassList(document.body).add('printout');
$('#show_paper').addEventListener('click', function () {
document.body.classList.add('printout');
printer = new Printer(tty, paper);
});
addEvent($('#hide_paper'), 'click', function () {
window.getClassList(document.body).remove('printout');
$('#hide_paper').addEventListener('click', function () {
document.body.classList.remove('printout');
printer.close();
printer = null;
});
// Mouse-as-Joystick
var wrapper = $('#screen-wrapper');
addEvent(wrapper, 'mousemove', function (e) {
wrapper.addEventListener('mousemove', function (e) {
var rect = wrapper.getBoundingClientRect(),
x = e.clientX - rect.left, y = e.clientY - rect.top;
function clamp(n, min, max) { return n < min ? min : n > max ? max : n; }

@ -1 +1 @@
Subproject commit 36bbc210fb65bfd25d075d5eec077822d7b0d5c6
Subproject commit 007919d32364e9af78b79a7fc3dbb1e66fc0c875

View File

@ -74,7 +74,7 @@
var pdl = [0, 0, 0, 0];
// Mouse-as-Joystick
addEvent(wrapper_elem, 'mousemove', function (e) {
wrapper_elem.addEventListener('mousemove', function (e) {
var rect = wrapper_elem.getBoundingClientRect(),
x = e.clientX - rect.left, y = e.clientY - rect.top;
function clamp(n, min, max) { return n < min ? min : n > max ? max : n; }

22
tty.js
View File

@ -167,8 +167,8 @@ function TTY(screenElement, keyboardElement, bell) {
tbody = document.createElement('tbody');
styleElem = tbody;
getClassList(styleElem).add(screenWidth === 40 ? 'jsb-40col' : 'jsb-80col');
if (firmwareActive) { getClassList(styleElem).add('jsb-active'); }
styleElem.classList.add(screenWidth === 40 ? 'jsb-40col' : 'jsb-80col');
if (firmwareActive) { styleElem.classList.add('jsb-active'); }
for (y = 0; y < screenHeight; y += 1) {
tr = document.createElement('tr');
@ -732,11 +732,8 @@ function TTY(screenElement, keyboardElement, bell) {
// Internal
function handleKeyDown(e) {
identifyKey(e);
if (!e.code || isBrowserKey(e)) {
if (!e.code || isBrowserKey(e))
return true;
}
var handled = false, code;
@ -780,14 +777,11 @@ function TTY(screenElement, keyboardElement, bell) {
// Internal
function handleKeyUp(e) {
identifyKey(e);
if (!e.code || isBrowserKey(e)) {
if (!e.code || isBrowserKey(e))
return true;
}
var handled = false,
code;
code;
switch (e.code) {
@ -876,10 +870,10 @@ function TTY(screenElement, keyboardElement, bell) {
init(false, 24, 40);
window.addEvent(keyboardElement, 'keydown', handleKeyDown);
window.addEvent(keyboardElement, 'keyup', handleKeyUp);
keyboardElement.addEventListener('keydown', handleKeyDown);
keyboardElement.addEventListener('keyup', handleKeyUp);
setInterval(function blinkFlash() {
window.getClassList(styleElem).toggle('jsb-flash');
styleElem.classList.toggle('jsb-flash');
}, 250);
}