From 6ff85e49270667415a39db41c1bb6ca31c9d1066 Mon Sep 17 00:00:00 2001 From: KaiSD Date: Wed, 4 Sep 2019 21:48:58 +0200 Subject: [PATCH] =?UTF-8?q?=D0=98=D0=B7=D0=BC=D0=B5=D0=BD=D0=B8=D1=82?= =?UTF-8?q?=D1=8C=20'ace/index.html'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ace/index.html | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/ace/index.html b/ace/index.html index cf53ea1..8c82f58 100644 --- a/ace/index.html +++ b/ace/index.html @@ -100,7 +100,8 @@ }); function save() { - alert("not yet implemented"); + var file = prompt("Name the file:", "text.txt"); + download(file, editor.getSession().getValue()); } editor.commands.addCommand({ @@ -139,6 +140,19 @@ } } + function download(filename, text) { + var element = document.createElement('a'); + element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(text)); + element.setAttribute('download', filename); + + element.style.display = 'none'; + document.body.appendChild(element); + + element.click(); + + document.body.removeChild(element); + } + window.editor = editor;