Make moving groups compatible with IE/Edge

This commit is contained in:
Neil Brommer 2018-01-05 15:32:22 -08:00
parent a1a059e3fb
commit c54b962d20

View file

@ -21,13 +21,36 @@ function groupMoved(dropEvt) {
openDBRequest.onsuccess = function (openEvt) {
var db = openEvt.target.result;
var groupsStore = db.transaction("Groups", "readwrite").objectStore("Groups");
groupsStore.getAll().onsuccess = function (getAllEvt) {
var groups = getAllEvt.target.result;
// build an array of all groups
var groups = [];
groupsStore.openCursor().onsuccess = function (cursorEvt) {
var cursor = cursorEvt.target.result;
if (cursor) {
groups.push(cursor.value);
cursor.continue();
} else {
rearrangeGroups(groupsStore, groups, newIndex, oldIndex);
db.close();
}
}
}
openDBRequest.onerror = function (err) {
console.log(err);
window.alert("Error moving group");
}
}
}
function rearrangeGroups(groupsStore, groups, newIndex, oldIndex) {
var movedGroup = $("#group-" + oldIndex);
if (newIndex > oldIndex) {
for (let g of groups) {
for (var i = 0; i < groups.length; i++) {
var g = groups[i];
if (g.groupIndex > oldIndex && g.groupIndex <= newIndex) {
g.groupIndex--;
groupsStore.put(g);
@ -36,22 +59,24 @@ function groupMoved(dropEvt) {
var cardContainer = $("#group-" + (g.groupIndex + 1))
.attr("id", "group" + g.groupIndex);
var card = $(cardContainer.children()[0])
$(cardContainer.children()[0]) // the card
.attr("data-group-index", g.groupIndex);
}
}
} else { // oldIndex > newIndex
for (let g of groups) {
for (var i = 0; i < groups.length; i++) {
var g = groups[i];
if (g.groupIndex < oldIndex && g.groupIndex >= newIndex) {
g.groupIndex++;
groupsStore.put(g);
// modify the group's card
var cardContainer = $("#group-" + (g.groupIndex - 1));
cardContainer.attr("id", "group" + g.groupIndex);
var cardContainer = $("#group-" + (g.groupIndex - 1))
.attr("id", "group" + g.groupIndex);
var card = $(cardContainer.children()[0]);
card.attr("data-group-index", g.groupIndex);
$(cardContainer.children()[0]) // the card
.attr("data-group-index", g.groupIndex);
}
}
}
@ -62,18 +87,8 @@ function groupMoved(dropEvt) {
groupsStore.put(movedGroupData);
// update the group's card
$(dropEvt.item).attr("id", "group" + newIndex);
movedCard.attr("data-group-index", newIndex);
db.close();
}
}
openDBRequest.onerror = function (err) {
console.log(err);
window.alert("Error moving group");
}
}
movedGroup.attr("id", "group" + newIndex);
$(movedGroup.children()[0]).attr("data-group-index", newIndex);
}
function bookmarkMoved(dropEvt) {