grid-list
Version:
Drag and drop library for a two-dimensional resizable and responsive list of items
22 lines (20 loc) • 465 B
JavaScript
exports.addIndexesToItems = function(items) {
/**
Add indexes to items to match them after being reordered in the positioning
process
*/
for (var i = 0; i < items.length; i++) {
items[i].index = i;
}
};
exports.sortItemsByIndex = function(items) {
items.sort(function(item1, item2) {
if (item1.index < item2.index) {
return -1;
} else if (item1.index > item2.index) {
return 1;
} else {
return 0;
}
});
};