diff options
| author | Alon Levy <alon@pobox.com> | 2014-10-19 11:19:19 +0300 |
|---|---|---|
| committer | Alon Levy <alon@pobox.com> | 2014-10-19 11:36:06 +0300 |
| commit | 23547b19674fed733245fc9bec0facb9af855e72 (patch) | |
| tree | 44f550e37aea76d76deb990a741d20afe867933d /scripts/buttons.js | |
| parent | e24c80e030949355d05634a550fb2224953f8a1f (diff) | |
adding proper Save As (with non random filename); MIT licensed
Actually seems that the proper way to save nowadays is the [download]
(https://html.spec.whatwg.org/multipage/semantics.html#attr-hyperlink-download)
attribute of a 'a' element, but that's also supported by the added
[FileSaver.js] (external/scripts/FileSaver.js)
Diffstat (limited to 'scripts/buttons.js')
| -rw-r--r-- | scripts/buttons.js | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/scripts/buttons.js b/scripts/buttons.js index 69f0a6c7..1543b4cc 100644 --- a/scripts/buttons.js +++ b/scripts/buttons.js @@ -13,8 +13,10 @@ $('.save').click(function(){ $('.saveToFile').click(function() { var json = graph.save_to_json(); - console.log(json); - location.href = 'data:text/json;base64,' + window.btoa(json); + var filename = 'graph.json'; + var blob = new Blob([json], {type: 'application/json'}); + console.log('saving ' + json.length + ' bytes to ' + filename); + saveAs(blob, filename); }); var really_load = function() { |
