aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--htdocs/js/mathy.js13
1 files changed, 9 insertions, 4 deletions
diff --git a/htdocs/js/mathy.js b/htdocs/js/mathy.js
index 7acd7ab..edbb17a 100644
--- a/htdocs/js/mathy.js
+++ b/htdocs/js/mathy.js
@@ -211,7 +211,7 @@ jQuery(function($) {
return false;
// build sortable name
- var sort = name
+ var sortable_name = name
.replace(/\s+/g, ' ')
.replace(/^\s+|\s+$/g, '')
.toLowerCase();
@@ -221,20 +221,25 @@ jQuery(function($) {
saves = saves ? JSON.parse(saves) : [];
if ($.grep(saves, function(row) {
- return row.save == sort;
+ return row.sort == sortable_name;
}).length > 0) {
if (!confirm("Replace existing \"" + name + " \"?"))
return false;
}
+ // exclude duplicates
+ saves = $.grep(saves, function(row) {
+ return row.sort != sortable_name;
+ });
+
// append to results
saves.push({
name: name,
- sort: sort,
+ sort: sortable_name,
text: editor.getValue(),
});
- // write saves
+ // write sorted saves
localStorage.setItem('mathy_saves', JSON.stringify(saves.sort(function(a, b) {
return b.sort < a.sort;
})));