add example and download buttons
This commit is contained in:
parent
9a31ad1016
commit
d1d3f10398
|
@ -19,7 +19,9 @@
|
||||||
<textarea class="area" id="ta_turtle"></textarea>
|
<textarea class="area" id="ta_turtle"></textarea>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
|
<input type="button" id="btn_example" class="btn btn-default" value="Load Example"/>
|
||||||
<input type="button" id="btn_validate" class="btn btn-default" value="Validate!"/>
|
<input type="button" id="btn_validate" class="btn btn-default" value="Validate!"/>
|
||||||
|
<input type="button" id="btn_download" class="btn btn-default" value="Download"/>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
<ul id="errors"></ul>
|
<ul id="errors"></ul>
|
||||||
|
|
36
js/app.js
36
js/app.js
|
@ -23,3 +23,39 @@ var editor = CodeMirror.fromTextArea(document.getElementById("ta_turtle"), {
|
||||||
mode: 'turtle',
|
mode: 'turtle',
|
||||||
theme: 'default'
|
theme: 'default'
|
||||||
});
|
});
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue