From a1a059e3fba180be4993385ff42cd5919e6cd760 Mon Sep 17 00:00:00 2001 From: Neil Brommer Date: Tue, 2 Jan 2018 20:30:10 -0800 Subject: [PATCH] Make deleteGroup compatible with IE/Edge --- js/editBookmarks.js | 38 +++++++++++++++++++++----------------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/js/editBookmarks.js b/js/editBookmarks.js index 5689712..db0af89 100644 --- a/js/editBookmarks.js +++ b/js/editBookmarks.js @@ -184,29 +184,33 @@ function deleteGroup() { var db = openEvt.target.result; var groupsStore = db.transaction("Groups", "readwrite").objectStore("Groups"); - groupsStore.getAll().onsuccess = function (getAllEvt) { - var groups = getAllEvt.target.result; + var lastIndex = -1; + groupsStore.openCursor().onsuccess = function (cursorEvt) { + var cursor = cursorEvt.target.result; + if (cursor) { + var item = cursor.value; + var cardContainer = $("#group-" + item.groupIndex); + + if (item.groupIndex > lastIndex) + lastIndex = item.groupIndex; + + if (item.groupIndex == groupIndex) { + cardContainer.hide(300, "swing", function () { cardContainer.remove(); }); + } - for (let item of groups) { if (item.groupIndex > groupIndex) { item.groupIndex--; groupsStore.put(item); + + $(cardContainer.children()[0]).attr("data-group-index", item.groupIndex); + cardContainer.attr("id", "group-" + item.groupIndex); } + + cursor.continue(); + } else { + groupsStore.delete(lastIndex); + db.close(); } - - groupsStore.delete(groups.length - 1); - db.close(); - - $("#cardList").children().each(function (index, item) { - item = $(item); - if (index == groupIndex) { - item.hide(300, "swing", e => item.remove()); - } else if (index > groupIndex) { - // modify id and data to reflect new index - $(item.children()[0]).attr("data-group-index", index - 1); - item.attr("id", "group-" + (index - 1)); - } - }); } }