Changed ExportDictionary to include dictionary's name as exported file name.

This commit is contained in:
Robbie Antenesse 2015-10-26 16:21:13 -06:00
parent 9fb7061f5e
commit 78fa2e88db
1 changed files with 22 additions and 16 deletions

View File

@ -244,7 +244,9 @@ function ShowSettings() {
}
function SaveSettings() {
currentDictionary.name = htmlEntities(document.getElementById("dictionaryNameEdit").value);
if (htmlEntities(document.getElementById("dictionaryNameEdit").value) != "") {
currentDictionary.name = htmlEntities(document.getElementById("dictionaryNameEdit").value);
}
currentDictionary.settings.isComplete = document.getElementById("dictionaryIsComplete").checked;
ShowDictionary();
SaveDictionary();
@ -255,20 +257,6 @@ function HideSettings() {
document.getElementById("wordEntryForm").style.display = (currentDictionary.settings.isComplete) ? "none" : "block";
}
function dynamicSort(property) {
/* Retrieved from http://stackoverflow.com/a/4760279
Usage: theArray.sort(dynamicSort("objectProperty"));*/
var sortOrder = 1;
if (property[0] === "-") {
sortOrder = -1;
property = property.substr(1);
}
return function (a, b) {
var result = (a[property] < b[property]) ? -1 : (a[property] > b[property]) ? 1 : 0;
return result * sortOrder;
}
}
function EmptyWholeDictionary() {
if (confirm("This will delete the entire current dictionary. If you do not have a backed up export, you will lose it forever!\n\nDo you still want to delete?")) {
currentDictionary = JSON.parse(defaultDictionaryJSON);
@ -294,7 +282,11 @@ function LoadDictionary() {
}
function ExportDictionary() {
download("export.dict", localStorage.getItem('dictionary'));
var downloadName = currentDictionary.name.replace(/\W/g, '');
if (downloadName == "") {
downloadName = "export";
}
download(downloadName + ".dict", localStorage.getItem('dictionary'));
}
function ImportDictionary() {
@ -347,6 +339,20 @@ function htmlEntitiesParse(string) {
return String(string).replace(/&amp;/g, '&').replace(/&lt;/g, '<').replace(/&gt;/g, '>').replace(/&quot;/g, '"').replace(/&apos;/g, "'").replace(/<br>/g, '\n');
}
function dynamicSort(property) {
/* Retrieved from http://stackoverflow.com/a/4760279
Usage: theArray.sort(dynamicSort("objectProperty"));*/
var sortOrder = 1;
if (property[0] === "-") {
sortOrder = -1;
property = property.substr(1);
}
return function (a, b) {
var result = (a[property] < b[property]) ? -1 : (a[property] > b[property]) ? 1 : 0;
return result * sortOrder;
}
}
function download(filename, text) {
/* Retrieved from http://stackoverflow.com/a/18197341/3508346
Usage: download('test.txt', 'Hello world!');*/