Make moving groups compatible with IE/Edge
This commit is contained in:
parent
a1a059e3fb
commit
c54b962d20
|
@ -21,13 +21,36 @@ function groupMoved(dropEvt) {
|
||||||
|
|
||||||
openDBRequest.onsuccess = function (openEvt) {
|
openDBRequest.onsuccess = function (openEvt) {
|
||||||
var db = openEvt.target.result;
|
var db = openEvt.target.result;
|
||||||
|
|
||||||
var groupsStore = db.transaction("Groups", "readwrite").objectStore("Groups");
|
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) {
|
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) {
|
if (g.groupIndex > oldIndex && g.groupIndex <= newIndex) {
|
||||||
g.groupIndex--;
|
g.groupIndex--;
|
||||||
groupsStore.put(g);
|
groupsStore.put(g);
|
||||||
|
@ -36,22 +59,24 @@ function groupMoved(dropEvt) {
|
||||||
var cardContainer = $("#group-" + (g.groupIndex + 1))
|
var cardContainer = $("#group-" + (g.groupIndex + 1))
|
||||||
.attr("id", "group" + g.groupIndex);
|
.attr("id", "group" + g.groupIndex);
|
||||||
|
|
||||||
var card = $(cardContainer.children()[0])
|
$(cardContainer.children()[0]) // the card
|
||||||
.attr("data-group-index", g.groupIndex);
|
.attr("data-group-index", g.groupIndex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else { // oldIndex > newIndex
|
} 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) {
|
if (g.groupIndex < oldIndex && g.groupIndex >= newIndex) {
|
||||||
g.groupIndex++;
|
g.groupIndex++;
|
||||||
groupsStore.put(g);
|
groupsStore.put(g);
|
||||||
|
|
||||||
// modify the group's card
|
// modify the group's card
|
||||||
var cardContainer = $("#group-" + (g.groupIndex - 1));
|
var cardContainer = $("#group-" + (g.groupIndex - 1))
|
||||||
cardContainer.attr("id", "group" + g.groupIndex);
|
.attr("id", "group" + g.groupIndex);
|
||||||
|
|
||||||
var card = $(cardContainer.children()[0]);
|
$(cardContainer.children()[0]) // the card
|
||||||
card.attr("data-group-index", g.groupIndex);
|
.attr("data-group-index", g.groupIndex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -62,18 +87,8 @@ function groupMoved(dropEvt) {
|
||||||
groupsStore.put(movedGroupData);
|
groupsStore.put(movedGroupData);
|
||||||
|
|
||||||
// update the group's card
|
// update the group's card
|
||||||
$(dropEvt.item).attr("id", "group" + newIndex);
|
movedGroup.attr("id", "group" + newIndex);
|
||||||
movedCard.attr("data-group-index", newIndex);
|
$(movedGroup.children()[0]).attr("data-group-index", newIndex);
|
||||||
|
|
||||||
db.close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
openDBRequest.onerror = function (err) {
|
|
||||||
console.log(err);
|
|
||||||
window.alert("Error moving group");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function bookmarkMoved(dropEvt) {
|
function bookmarkMoved(dropEvt) {
|
||||||
|
|
Loading…
Reference in a new issue