From a7cd37a899fe5bc3a278c5d57980ccaf3edd0ca8 Mon Sep 17 00:00:00 2001 From: chrysn Date: Tue, 20 Jun 2017 19:42:59 +0200 Subject: [PATCH 1/2] Allow ui-sortable to work on deep items The sortable container might not be the item's direct parent; this happens eg. in floating setups when the ng-repeated DOM node is a directive that only includes the floating node as a child, so the resulting tree with directives and CSS resolved looks like
I'm unsure on why the .find(opts['ui-model-items']) -> .find(opts['items']) is necessary exactly (or why it doesn't say the latter originally), but it is required in the same situation; were I to (just on a guess) set {ui-model-items:'.tilefloater', items:'.tilefloater'}, there'd be leftover placeholders, and without the change, .find() doesn't catch the actually moved item. --- src/sortable.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/sortable.js b/src/sortable.js index 8bdaaf9..2dc79ee 100644 --- a/src/sortable.js +++ b/src/sortable.js @@ -218,8 +218,10 @@ angular.module('ui.sortable', []) // we can't just do ui.item.index() because there it might have siblings // which are not items function getItemIndex(item) { - return item.parent() - .find(opts['ui-model-items']) + var par = item.parent(); + while (!par.attr('ui-sortable')) par = par.parent(); + return par + .find(opts['items']) .index(item); } From a25a449794515aeda2c404c2e696981e1ed7d5bc Mon Sep 17 00:00:00 2001 From: chrysn Date: Mon, 3 Jul 2017 09:59:27 +0200 Subject: [PATCH 2/2] (Braces fix to make linter happy) --- src/sortable.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/sortable.js b/src/sortable.js index 2dc79ee..2130b43 100644 --- a/src/sortable.js +++ b/src/sortable.js @@ -219,7 +219,9 @@ angular.module('ui.sortable', []) // which are not items function getItemIndex(item) { var par = item.parent(); - while (!par.attr('ui-sortable')) par = par.parent(); + while (!par.attr('ui-sortable')) { + par = par.parent(); + } return par .find(opts['items']) .index(item);