2015-07-14 19:23:35 +02:00
|
|
|
$("#btn_validate").click( function () {
|
|
|
|
$("#warnings").html("");
|
|
|
|
$("#errors").html("");
|
|
|
|
$("#results").html("");
|
|
|
|
|
2020-04-29 16:09:29 +02:00
|
|
|
validate(editor.getValue(), function (feedback) {
|
2015-07-14 19:23:35 +02:00
|
|
|
$.each(feedback.warnings, function (index, warning) {
|
2016-11-29 10:55:57 +01:00
|
|
|
$("#warnings").append($('<li id="warning' + index + '">').text(warning));
|
2015-07-14 19:23:35 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
$.each(feedback.errors, function (index, error) {
|
2016-11-29 10:55:57 +01:00
|
|
|
$("#errors").append($('<li id="error' + index + '">').text(error));
|
2015-07-14 19:23:35 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
if (feedback.errors.length === 0 && feedback.warnings.length === 0) {
|
2016-11-29 10:55:57 +01:00
|
|
|
$("#results").append("Congrats! Your syntax is correct.");
|
2015-07-14 19:23:35 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
2020-04-29 15:43:06 +02:00
|
|
|
|
|
|
|
var editor = CodeMirror.fromTextArea(document.getElementById("ta_turtle"), {
|
|
|
|
lineNumbers: true,
|
|
|
|
mode: 'turtle',
|
2020-04-29 17:18:49 +02:00
|
|
|
viewportMargin: Infinity,
|
2020-04-29 15:43:06 +02:00
|
|
|
theme: 'default'
|
|
|
|
});
|
2020-04-29 16:22:45 +02:00
|
|
|
|
|
|
|
var example =
|
|
|
|
['@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .',
|
|
|
|
'@prefix dc: <http://purl.org/dc/elements/1.1/> .',
|
|
|
|
'@prefix ex: <http://example.org/stuff/1.0/> .',
|
|
|
|
'<http://www.w3.org/TR/rdf-syntax-grammar>',
|
|
|
|
' dc:title "RDF/XML Syntax Specification (Revised)" ;',
|
|
|
|
' ex:editor [',
|
|
|
|
' ex:fullname "Dave Beckett";',
|
|
|
|
' ex:homePage <http://purl.org/net/dajobe/>',
|
|
|
|
' ] .'
|
|
|
|
].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);
|
|
|
|
}
|