From ba026dbe4e540baaab59c24cdf3b7b22cca9c0d5 Mon Sep 17 00:00:00 2001 From: Brendan Hansen Date: Tue, 20 Jul 2021 10:20:17 -0500 Subject: [PATCH] added "save" button --- static/src/index.js | 22 ++++++++++++++++++++++ templates/index.html | 1 + 2 files changed, 23 insertions(+) diff --git a/static/src/index.js b/static/src/index.js index 3b0b91a..b4b786d 100644 --- a/static/src/index.js +++ b/static/src/index.js @@ -143,6 +143,28 @@ function handle_dragover(e) { return false; } +function prompt_download() { + let editor = ace.edit('code-editor'); + let code = editor.getValue(); + + let blob = new Blob([ code ], { + type: 'text/plain' + }); + + let download_link = document.createElement('a'); + download_link.download = `onyx-${Date.now()}.onyx`; + download_link.href = window.URL.createObjectURL(blob); + download_link.onclick = function(e) { + // revokeObjectURL needs a delay to work properly + setTimeout(() => { + window.URL.revokeObjectURL(this.href); + }, 1500); + }; + + download_link.click(); + download_link.remove(); +} + window.onload = () => { let editor = ace.edit('code-editor'); diff --git a/templates/index.html b/templates/index.html index 4191255..b2c6ed0 100644 --- a/templates/index.html +++ b/templates/index.html @@ -31,6 +31,7 @@ + -- 2.25.1