From 41754d7225fed52d114ac5efd509ba4fac1659cd Mon Sep 17 00:00:00 2001
From: olbender <olbender@users.noreply.github.com>
Date: Mon, 18 Jun 2018 12:40:36 +0200
Subject: [PATCH] Save feature

---
 server/http/indexr.html                   | 6 ++----
 server/http/opendlv-ui-editor-js-0.0.1.js | 5 +++++
 2 files changed, 7 insertions(+), 4 deletions(-)

diff --git a/server/http/indexr.html b/server/http/indexr.html
index 8a6b857..edfbc84 100644
--- a/server/http/indexr.html
+++ b/server/http/indexr.html
@@ -85,11 +85,9 @@
           <div id="simulate-program-dropdown" class="dropdown-menu" aria-labelledby="navbarDropdownMenuLink">
           </div>
         </li>
-	<!--
         <li class="nav-item">
-          <a class="nav-link" href="#">Save code</a>
-	</li>
-	-->
+          <a class="nav-link" onclick="downloadCode();" href="">Spara kod till fil</a>
+        </li>
       </ul>
     </nav>
 
diff --git a/server/http/opendlv-ui-editor-js-0.0.1.js b/server/http/opendlv-ui-editor-js-0.0.1.js
index 078f888..b97fb65 100644
--- a/server/http/opendlv-ui-editor-js-0.0.1.js
+++ b/server/http/opendlv-ui-editor-js-0.0.1.js
@@ -137,6 +137,11 @@ function toggleDiv(id) {
   div.style.display = div.style.display == "none" ? "block" : "none";
 }
 
+function downloadCode() {
+  const txt = editor.getValue();
+  this.href = 'data:text/plain;charset=utf-8,' + encodeURIComponent(txt);
+}
+
 function loadExampleCode(index) {
   var code;
   switch (index) {
-- 
GitLab