diff options
Diffstat (limited to 'scripts/buttons.js')
| -rw-r--r-- | scripts/buttons.js | 48 |
1 files changed, 35 insertions, 13 deletions
diff --git a/scripts/buttons.js b/scripts/buttons.js index 346e576b..69f0a6c7 100644 --- a/scripts/buttons.js +++ b/scripts/buttons.js @@ -17,24 +17,46 @@ $('.saveToFile').click(function() { location.href = 'data:text/json;base64,' + window.btoa(json); }); -$('.load').click(function(){ - var acceptLoad=true; - - if (nodes.length>0){ - acceptLoad = confirm('All unsaved changes will be deleted, are you sure?'); +var really_load = function() { + if (nodes.length > 0){ + return confirm('All unsaved changes will be deleted, are you sure?'); } + return true; +} - if(acceptLoad){ - links=[]; // TODO - not global - nodes=[]; // TODO - not global - var json_blob = localStorage.getItem(key) - graph.load_from_json(json_blob); - } +$('.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"); }); -$('.deliverabletest').click(function(){ - deliverableTest(); +$('.local-storage-load').click(function(){ + if (!really_load()) { + return; + } + links=[]; // TODO - not global + nodes=[]; // TODO - not global + var json_blob = localStorage.getItem(key) + graph.load_from_json(json_blob); }); $('.set-user').click(function() { |
