From 3e3c130b3eede854db602259215866a409618967 Mon Sep 17 00:00:00 2001 From: Alon Levy Date: Mon, 29 Sep 2014 20:46:19 +0300 Subject: buttons/index: add file load button --- scripts/buttons.js | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'scripts') diff --git a/scripts/buttons.js b/scripts/buttons.js index 6ae25d1f..69f0a6c7 100644 --- a/scripts/buttons.js +++ b/scripts/buttons.js @@ -24,6 +24,31 @@ var really_load = function() { return true; } +$('.file-load').on('change', function(event) { + var file = event.target.files[0]; + var reader; + + if (!really_load()) { + return; + } + if (file === undefined) { + return; + } + console.log(file); + reader = new FileReader(); + reader.onload = (function(theFile) { + return function(e) { + var result = e.target.result; + if (e.target.readyState === FileReader.DONE) { + console.log('done reading ' + theFile.name); + console.log('got #' + result.length + ' bytes in ' + typeof(result)); + graph.load_from_json(result); + } + } + })(file); + reader.readAsText(file, "text/javascript"); +}); + $('.local-storage-load').click(function(){ if (!really_load()) { return; -- cgit v1.3.1