From 30ff0201d88b0aa26bbbcf4a727251eaa2457bd2 Mon Sep 17 00:00:00 2001 From: Joshua Bell Date: Wed, 22 Jan 2014 21:06:31 -0800 Subject: [PATCH] Use newer keyboard polyfill, require IE8+ --- index.js | 20 ++++++++++---------- polyfill | 2 +- script.js | 2 +- tty.js | 22 ++++++++-------------- 4 files changed, 20 insertions(+), 26 deletions(-) diff --git a/index.js b/index.js index 2b0ec3a..468382c 100644 --- a/index.js +++ b/index.js @@ -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; } diff --git a/polyfill b/polyfill index 36bbc21..007919d 160000 --- a/polyfill +++ b/polyfill @@ -1 +1 @@ -Subproject commit 36bbc210fb65bfd25d075d5eec077822d7b0d5c6 +Subproject commit 007919d32364e9af78b79a7fc3dbb1e66fc0c875 diff --git a/script.js b/script.js index ac9a813..983b6fc 100644 --- a/script.js +++ b/script.js @@ -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; } diff --git a/tty.js b/tty.js index 95b7f98..e449dd2 100644 --- a/tty.js +++ b/tty.js @@ -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); }