From 8624d217770a6d8dda50de8ea97a351e5f6cba83 Mon Sep 17 00:00:00 2001 From: Justin Frei Date: Wed, 13 Jul 2016 10:20:17 -0600 Subject: [PATCH 1/2] Update knockout-sortable.js - Fixes issue with data-bind: sortable element for a non-computed observable array. Dragging an item from a smaller index (eg 0) to a greater index (eg 10) places the element one position after the desired drop position (eg newIndex + 1). --- knockout-sortable.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/knockout-sortable.js b/knockout-sortable.js index fedcff7..3e78780 100644 --- a/knockout-sortable.js +++ b/knockout-sortable.js @@ -138,7 +138,7 @@ // drop an item above the 3rd visible item, but the 2nd visible item // has an actual index of 5. if (e.item.previousElementSibling) { - newIndex = to().indexOf(ko.dataFor(e.item.previousElementSibling)) + 1; + newIndex = to().indexOf(ko.dataFor(e.item.previousElementSibling)) + (newIndex > originalIndex ? 0 : 1); } // Remove sortables "unbound" element From 28c1e0fffa23be3ab1179d4135e3bbea04bedcce Mon Sep 17 00:00:00 2001 From: Justin Frei Date: Thu, 14 Jul 2016 10:42:47 -0600 Subject: [PATCH 2/2] Update knockout-sortable.js Fix issue with newIndex always being 0 --- knockout-sortable.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/knockout-sortable.js b/knockout-sortable.js index 3e78780..628fb6a 100644 --- a/knockout-sortable.js +++ b/knockout-sortable.js @@ -138,7 +138,8 @@ // drop an item above the 3rd visible item, but the 2nd visible item // has an actual index of 5. if (e.item.previousElementSibling) { - newIndex = to().indexOf(ko.dataFor(e.item.previousElementSibling)) + (newIndex > originalIndex ? 0 : 1); + newIndex = to().indexOf(ko.dataFor(e.item.previousElementSibling)); + newIndex += (newIndex > originalIndex ? 0 : 1); } // Remove sortables "unbound" element