From d1d3f10398e539dfc4ba7011bee6ecc93e58c573 Mon Sep 17 00:00:00 2001 From: Felix Lohmeier Date: Wed, 29 Apr 2020 16:22:45 +0200 Subject: [PATCH] add example and download buttons --- index.html | 2 ++ js/app.js | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/index.html b/index.html index 1d3ab63..36c5f70 100644 --- a/index.html +++ b/index.html @@ -19,7 +19,9 @@
+ +
diff --git a/js/app.js b/js/app.js index 4a84c18..48d0649 100644 --- a/js/app.js +++ b/js/app.js @@ -23,3 +23,39 @@ var editor = CodeMirror.fromTextArea(document.getElementById("ta_turtle"), { mode: 'turtle', theme: 'default' }); + +var example = + ['@prefix rdf: .', + '@prefix dc: .', + '@prefix ex: .', + '', + ' dc:title "RDF/XML Syntax Specification (Revised)" ;', + ' ex:editor [', + ' ex:fullname "Dave Beckett";', + ' ex:homePage ', + ' ] .' + ].join('\n'); + +$("#btn_example").click( function () { +editor.setValue(example); +}); + +$("#btn_download").click( function () { +var textToWrite = editor.getValue(); +var textToWrite = textToWrite.replace(/\n/g, "\r\n"); +var textFileAsBlob = new Blob([textToWrite], {type:'text/plain'}); +var fileNameToSaveAs = "FILENAME.ttl"; +var downloadLink = document.createElement("a"); +downloadLink.download = fileNameToSaveAs; +downloadLink.innerHTML = "Turtle Web Editor Content"; +window.URL = window.URL || window.webkitURL; +downloadLink.href = window.URL.createObjectURL(textFileAsBlob); +downloadLink.onclick = destroyClickedElement; +downloadLink.style.display = "none"; +document.body.appendChild(downloadLink); +downloadLink.click(); +}); + +function destroyClickedElement(event) { +document.body.removeChild(event.target); +}