diff options
author | Paul Duncan <pabs@pablotron.org> | 2017-11-10 11:37:04 -0500 |
---|---|---|
committer | Paul Duncan <pabs@pablotron.org> | 2017-11-10 11:37:04 -0500 |
commit | 100cf72b346ad90d4fbfcd718ea19e622881a154 (patch) | |
tree | a83945ae46e6dcff56f0bde3bd8723788da3164e /htdocs | |
parent | 6d7868815ce731b4445b9f87afa09f98be280797 (diff) | |
download | mathy-100cf72b346ad90d4fbfcd718ea19e622881a154.tar.bz2 mathy-100cf72b346ad90d4fbfcd718ea19e622881a154.zip |
handle saves
Diffstat (limited to 'htdocs')
-rw-r--r-- | htdocs/js/mathy.js | 13 |
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; }))); |