From 7f1e5e57ef2415593579f326a6e3de26051a2e0b Mon Sep 17 00:00:00 2001 From: Joshua Bell Date: Thu, 2 May 2013 22:53:08 -0400 Subject: [PATCH] Support source queryparam. Fix space. --- index.js | 16 +++++++++++++++- tty.js | 5 +++-- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index 10832a1..0793377 100644 --- a/index.js +++ b/index.js @@ -233,6 +233,15 @@ window.onload = function () { } } + function parseQueryParams() { + var params = {}; + var query = document.location.search.substring(1); + query.split(/&/g).forEach(function(pair) { + pair = pair.replace(/\+/g, " ").split(/=/).map(decodeURIComponent); + params[pair[0]] = pair.length === 1 ? pair[0] : pair[1]; + }); + return params; + } function loadFile(filename, callback) { var req = new XMLHttpRequest(); @@ -250,7 +259,12 @@ window.onload = function () { } // load default - loadFile('samples/sample.default.txt', setSource); + var params = parseQueryParams(); + if ('source' in params) { + setSource(params.source); + } else { + loadFile('samples/sample.default.txt', setSource); + } // Show change history atomToHtml('feed.xml?' + Math.random(), $('#feed')); diff --git a/tty.js b/tty.js index 85c949b..625e642 100644 --- a/tty.js +++ b/tty.js @@ -738,7 +738,7 @@ function TTY(screenElement, keyboardElement, bell) { } // Symbol and Punctuation - case 'Spacebar': return ord(' '); + case 'Space': return ord(' '); case 'Semicolon': return e.shiftKey ? ord(':') : ord(';'); case 'Equal': return e.shiftKey ? ord('+') : ord('='); case 'Comma': return e.shiftKey ? ord('<') : ord(','); @@ -751,7 +751,8 @@ function TTY(screenElement, keyboardElement, bell) { case 'BracketRight': return e.ctrlKey ? 29 : e.shiftKey ? ord('}') : ord(']'); case 'Quote': return e.shiftKey ? ord('"') : ord('\''); - // not present on Apple II keyboard + // Apple IIgs Keyboard + case 'NumpadClear': return 24; case 'NumpadAdd': return ord('+'); case 'NumpadSubtract': return ord('-'); case 'NumpadMultiply': return ord('*');