From 78fea4c28ccf0523ebc18e523e21d990835f7c08 Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Mon, 11 Mar 2013 22:12:37 +0400 Subject: [PATCH] added save/load actions (c-s/c-o), still not done and need more testing... Signed-off-by: Alex A. Naanou --- index.html | 121 +++++++++++++++++++++++++++++++++++++++++++++++- lib/keyboard.js | 12 ++--- 2 files changed, 125 insertions(+), 8 deletions(-) diff --git a/index.html b/index.html index 938846f..5095095 100755 --- a/index.html +++ b/index.html @@ -84,9 +84,9 @@ - + @@ -143,6 +143,101 @@ function showInfo(){ '')) } + + +// setup download link... +var USE_ZIP = true +var USE_DATA_URL = true +function generateMagazineDownload(){ + var zip = new JSZip() + var json = JSON.stringify(buildJSON(true, true)) + // this is a really odd one, Chrome seems to replace some + // entities with actual chars... + // what is even more odd, this then confuses some unicode + // readers/wwriters... + .replace(/–/g, '–') + if(USE_ZIP){ + zip.file('magazine.json', json) + var content = zip.generate() + } else { + var content = btoa(json) + } + if(USE_DATA_URL){ + $('#data_download') + .attr('href','data:text/octet-stream;base64,'+content) + .css('display', 'inline') + if(USE_ZIP){ + $('#data_download') + .attr('download','magazine.zip') + } else { + $('#data_download') + .attr('download','magazine.json') + } + } else { + location.href="data:application/zip;base64,"+content + } +} + +/* +// util... +// from: http://stackoverflow.com/a/11058858 +function ab2str(buf) { + return String.fromCharCode.apply(null, new Uint16Array(buf)); +} + +function str2ab(str) { + var buf = new ArrayBuffer(str.length*2); // 2 bytes for each char + var bufView = new Uint16Array(buf); + for (var i=0, strLen=str.length; iOpen Issue'+ + '') + }, + }, + 'S': { + // save... + // XXX needs testing... + 'ctrl': function(){ + showInOverlay('

Save Issue

'+ + '

NOTE: this download will not include the actual '+ + 'images. at this point, images should be added manually.

'+ + '

Download

') + + // setup the data... + $(generateMagazineDownload) + }, + }, }, // ignore all keys except Esc here... diff --git a/lib/keyboard.js b/lib/keyboard.js index 3bbc15f..cdf48fa 100755 --- a/lib/keyboard.js +++ b/lib/keyboard.js @@ -14,7 +14,7 @@ // toKeyName() and toKeyCode() for a more uniform access. // // NOTE: these are un-shifted ASCII key names rather than actual key -// code values. +// code translations. // NOTE: ASCII letters (capital) are not present because they actually // match their key codes and are accessible via: // String.fromCharCode() or .charCodeAt(0) @@ -38,16 +38,16 @@ var _SPECIAL_KEYS = { 114: 'F3', 118: 'F7', 122: 'F11', 115: 'F4', 119: 'F8', 123: 'F12', - // number row.. + // Number row.. 49: '1', 50: '2', 51: '3', 52: '4', 53: '5', 54: '6', 55: '7', 56: '8', 57: '9', 48: '0', - // punctuation... + // Punctuation... // top row... - 192: '`', 189: '-', 187: '=', + 192: '`', /* Numbers */ 189: '-', 187: '=', // right side of keyboard... - 219: '[', 221: ']', 220: '\\', - 186: ';', 222: '\'', + 219: '[', 221: ']', 220: '\\', + 186: ';', 222: '\'', 188: ',', 190: '.', 191: '/', }