Update Sorting - sort by name then part of speech.
This commit is contained in:
parent
5acca6f283
commit
0df7281c94
|
@ -374,9 +374,9 @@ function ResetDictionaryToDefault() {
|
||||||
|
|
||||||
function SaveAndUpdateDictionary(keepFormContents) {
|
function SaveAndUpdateDictionary(keepFormContents) {
|
||||||
if (!currentDictionary.settings.sortByEquivalent) {
|
if (!currentDictionary.settings.sortByEquivalent) {
|
||||||
currentDictionary.words.sort(dynamicSort("name"));
|
currentDictionary.words.sort(dynamicSort(['name', 'partOfSpeech']));
|
||||||
} else {
|
} else {
|
||||||
currentDictionary.words.sort(dynamicSort("simpleDefinition"));
|
currentDictionary.words.sort(dynamicSort(['simpleDefinition', 'partOfSpeech']));
|
||||||
}
|
}
|
||||||
SaveDictionary(true, true);
|
SaveDictionary(true, true);
|
||||||
ShowDictionary();
|
ShowDictionary();
|
||||||
|
@ -694,18 +694,25 @@ function regexParseForSearch(string) {
|
||||||
return String(string).replace(/([\[\\\^\$\.\|\?\*\+\(\)\{\}\]])/g, "\\$1");
|
return String(string).replace(/([\[\\\^\$\.\|\?\*\+\(\)\{\}\]])/g, "\\$1");
|
||||||
}
|
}
|
||||||
|
|
||||||
function dynamicSort(property) {
|
function dynamicSort(propertiesArray) {
|
||||||
/* Retrieved from http://stackoverflow.com/a/4760279
|
/* Retrieved from http://stackoverflow.com/a/30446887/3508346
|
||||||
Usage: theArray.sort(dynamicSort("objectProperty"));*/
|
Usage: theArray.sort(dynamicSort(['propertyAscending', '-propertyDescending']));*/
|
||||||
var sortOrder = 1;
|
|
||||||
if (property[0] === "-") {
|
|
||||||
sortOrder = -1;
|
|
||||||
property = property.substr(1);
|
|
||||||
}
|
|
||||||
return function (a, b) {
|
return function (a, b) {
|
||||||
var result = (a[property].toLowerCase() < b[property].toLowerCase()) ? -1 : (a[property].toLowerCase() > b[property].toLowerCase()) ? 1 : 0;
|
return propertiesArray
|
||||||
return result * sortOrder;
|
.map(function (o) {
|
||||||
}
|
var dir = 1;
|
||||||
|
if (o[0] === '-') {
|
||||||
|
dir = -1;
|
||||||
|
o=o.substring(1);
|
||||||
|
}
|
||||||
|
if (removeDiacritics(a[o]) > removeDiacritics(b[o])) return dir;
|
||||||
|
if (removeDiacritics(a[o]) < removeDiacritics(b[o])) return -(dir);
|
||||||
|
return 0;
|
||||||
|
})
|
||||||
|
.reduce(function firstNonZeroValue (p,n) {
|
||||||
|
return p ? p : n;
|
||||||
|
}, 0);
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function download(filename, text) {
|
function download(filename, text) {
|
||||||
|
|
Loading…
Reference in New Issue