Added save dialog

This commit is contained in:
Rubén de Celis Hernández 2016-06-03 19:32:21 +02:00
parent f084180730
commit 9bf3e37153
1 changed files with 14 additions and 1 deletions

View File

@ -52,8 +52,21 @@
// Save a JSON document
document.getElementById('saveDocument').onclick = function () {
// Save Dialog
fname = window.prompt("Save as...");
// Check json extension in file name
if(fname.indexOf(".")==-1){
fname = fname + ".json";
}else{
if(fname.split('.').pop().toLowerCase() == "json"){
// Nothing to do
}else{
fname = fname.split('.')[0] + ".json";
}
}
var blob = new Blob([editor.getText()], {type: 'application/json;charset=utf-8'});
saveAs(blob, 'document.json');
saveAs(blob, fname);
};
</script>
</body>