From 5b4737f6288460725ee1f992a744e7e6edecb4b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20G=C3=B3is?= Date: Tue, 21 Jul 2015 14:42:33 +0100 Subject: [PATCH 1/2] Update ng-sortable.js --- ng-sortable.js | 59 +++++++++++++++++++++++++------------------------- 1 file changed, 30 insertions(+), 29 deletions(-) diff --git a/ng-sortable.js b/ng-sortable.js index 4f0b8c5..642340e 100644 --- a/ng-sortable.js +++ b/ng-sortable.js @@ -31,35 +31,6 @@ var removed, nextSibling; - function getSource(el) { - var scope = angular.element(el).scope(); - var ngRepeat = [].filter.call(el.childNodes, function (node) { - return ( - (node.nodeType === 8) && - (node.nodeValue.indexOf('ngRepeat:') !== -1) - ); - })[0]; - - if (!ngRepeat) { - // Without ng-repeat - return null; - } - - // tests: http://jsbin.com/kosubutilo/1/edit?js,output - ngRepeat = ngRepeat.nodeValue.match(/ngRepeat:\s*(?:\(.*?,\s*)?([^\s)]+)[\s)]+in\s+([^\s|]+)/); - - var itemExpr = $parse(ngRepeat[1]); - var itemsExpr = $parse(ngRepeat[2]); - - return { - item: function (el) { - return itemExpr(angular.element(el).scope()); - }, - items: function () { - return itemsExpr(scope); - } - }; - } // Export @@ -67,6 +38,36 @@ restrict: 'AC', scope: { ngSortable: "=?" }, link: function (scope, $el, attrs) { + + function getSource(el) { + var ngRepeat = [].filter.call(el.childNodes, function (node) { + return ( + (node.nodeType === 8) && + (node.nodeValue.indexOf('ngRepeat:') !== -1) + ); + })[0]; + + if (!ngRepeat) { + // Without ng-repeat + return null; + } + + // tests: http://jsbin.com/kosubutilo/1/edit?js,output + ngRepeat = ngRepeat.nodeValue.match(/ngRepeat:\s*(?:\(.*?,\s*)?([^\s)]+)[\s)]+in\s+([^\s|]+)/); + + var itemExpr = $parse(ngRepeat[1]); + var itemsExpr = $parse(ngRepeat[2]); + + return { + item: function (el) { + return itemExpr(angular.element(el).scope()); + }, + items: function () { + return itemsExpr(scope); + } + }; + } + var el = $el[0], options = angular.extend(scope.ngSortable || {}, ngSortableConfig), source = getSource(el), From 9e93358ea538a72c1aca8711e664b8e477e51794 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20G=C3=B3is?= Date: Thu, 13 Aug 2015 12:10:47 +0100 Subject: [PATCH 2/2] Update ng-sortable.js --- ng-sortable.js | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/ng-sortable.js b/ng-sortable.js index 642340e..02f665d 100644 --- a/ng-sortable.js +++ b/ng-sortable.js @@ -30,9 +30,7 @@ .directive('ngSortable', ['$parse', 'ngSortableConfig', function ($parse, ngSortableConfig) { var removed, nextSibling; - - - + // Export return { restrict: 'AC', @@ -59,9 +57,6 @@ var itemsExpr = $parse(ngRepeat[2]); return { - item: function (el) { - return itemExpr(angular.element(el).scope()); - }, items: function () { return itemsExpr(scope); } @@ -81,7 +76,7 @@ /* jshint expr:true */ options[name] && options[name]({ - model: item || source && source.item(evt.item), + model: item || source && source.items()[evt.newIndex], models: source && source.items(), oldIndex: evt.oldIndex, newIndex: evt.newIndex