$("#btn_validate").click( function () { $("#warnings").html(""); $("#errors").html(""); $("#results").html(""); validate(editor.getValue(), function (feedback) { $.each(feedback.warnings, function (index, warning) { $("#warnings").append($('
  • ').text(warning)); }); $.each(feedback.errors, function (index, error) { $("#errors").append($('
  • ').text(error)); }); if (feedback.errors.length === 0 && feedback.warnings.length === 0) { $("#results").append("Congrats! Your syntax is correct."); } }); }); var editor = CodeMirror.fromTextArea(document.getElementById("ta_turtle"), { lineNumbers: true, 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); }