From ee86bc2bbcc2b3d1c173dda5c942da4d948b869c Mon Sep 17 00:00:00 2001 From: Tim van der Lippe Date: Tue, 3 May 2016 13:40:18 +0200 Subject: [PATCH 1/5] Fix compilation on ES5 for Polymer --- Sortable.html | 102 +++++++++++++++++++++++++------------------------- 1 file changed, 52 insertions(+), 50 deletions(-) diff --git a/Sortable.html b/Sortable.html index 77994ce..4ec31b8 100644 --- a/Sortable.html +++ b/Sortable.html @@ -7,11 +7,12 @@ From 643d9afe85d31e3cae4eb6277868a8efacc02876 Mon Sep 17 00:00:00 2001 From: Tim van der Lippe Date: Tue, 3 May 2016 15:56:37 +0200 Subject: [PATCH 2/5] Fix issue with dragEl undefined when moving with a Polymer element --- Sortable.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Sortable.js b/Sortable.js index 52b2d2d..55e8f2f 100644 --- a/Sortable.js +++ b/Sortable.js @@ -744,8 +744,9 @@ target.parentNode.insertBefore(dragEl, after ? nextSibling : target); } } - - parentEl = dragEl.parentNode; // actualization + if (dragEl) { + parentEl = dragEl.parentNode; // actualization + } this._animate(dragRect, dragEl); this._animate(targetRect, target); From 238216d8c94009947505cef8ffd4d1cf9d7fee10 Mon Sep 17 00:00:00 2001 From: Tim van der Lippe Date: Wed, 22 Jun 2016 17:27:47 +0200 Subject: [PATCH 3/5] Fix feedback --- Sortable.html | 22 +++++++++++----------- Sortable.js | 5 ++--- 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/Sortable.html b/Sortable.html index 4ec31b8..bb7bc22 100644 --- a/Sortable.html +++ b/Sortable.html @@ -64,13 +64,13 @@ options[key] = this[key]; }.bind(this)); - var self = this; + var _this = this; var eventCallbacks = { onUpdate: function (e) { if (template) { template.splice("items", e.newIndex, 0, template.splice("items", e.oldIndex, 1)[0]); } - self.fire("update", e); + _this.fire("update", e); }, onAdd: function(e) { @@ -80,42 +80,42 @@ var item = from.items[e.oldIndex]; template.splice("items", e.newIndex, 0, item); } - self.fire("add", e); + _this.fire("add", e); }, onRemove: function(e) { if (template) { template.splice("items", e.oldIndex, 1)[0]; } - self.fire("remove", e); + _this.fire("remove", e); }, onChoose: function(e) { - self.fire("choose", e); + _this.fire("choose", e); }, onStart: function(e) { - self.fire("start", e); + _this.fire("start", e); }, onEnd: function(e) { - self.fire("end", e); + _this.fire("end", e); }, onSort: function(e) { - self.fire("sort", e); + _this.fire("sort", e); }, onFilter: function(e) { - self.fire("filter", e); + _this.fire("filter", e); }, onMove: function(e) { - self.fire("move", e); + _this.fire("move", e); }, onClone: function(e) { - self.fire("clone", e); + _this.fire("clone", e); } }; diff --git a/Sortable.js b/Sortable.js index 55e8f2f..52b2d2d 100644 --- a/Sortable.js +++ b/Sortable.js @@ -744,9 +744,8 @@ target.parentNode.insertBefore(dragEl, after ? nextSibling : target); } } - if (dragEl) { - parentEl = dragEl.parentNode; // actualization - } + + parentEl = dragEl.parentNode; // actualization this._animate(dragRect, dragEl); this._animate(targetRect, target); From e0f9a114c5ba793b6a978b7aa6429ad26b8597ea Mon Sep 17 00:00:00 2001 From: Stanislav Kiryukhin Date: Thu, 23 Jun 2016 14:17:22 +0300 Subject: [PATCH 4/5] added support for "data-ng-repeat" --- ng-sortable.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ng-sortable.js b/ng-sortable.js index cbe1189..1fbb23c 100644 --- a/ng-sortable.js +++ b/ng-sortable.js @@ -46,16 +46,16 @@ var ngRepeat = [].filter.call($element[0].childNodes, function (node) { return ( - (node.nodeType === 1) && - (node.attributes['ng-repeat']) - ); + node.nodeType === Node.ELEMENT_NODE && + angular.element(node).data('ngRepeat') + ); })[0]; if (!ngRepeat) { return; } - var expression = ngRepeat.attributes['ng-repeat'].nodeValue; + var expression = angular.element(ngRepeat).data('ngRepeat'); var match = expression.match(/^\s*([\s\S]+?)\s+in\s+([\s\S]+?)(?:\s+as\s+([\s\S]+?))?(?:\s+track\s+by\s+([\s\S]+?))?\s*$/); if (!match) { From 995519ac0953f29cafc59aa9d14ceb233c127327 Mon Sep 17 00:00:00 2001 From: Stanislav Kiryukhin Date: Thu, 23 Jun 2016 15:40:46 +0300 Subject: [PATCH 5/5] code improvement --- ng-sortable.js | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/ng-sortable.js b/ng-sortable.js index 1fbb23c..d830675 100644 --- a/ng-sortable.js +++ b/ng-sortable.js @@ -37,6 +37,10 @@ var removed, nextSibling; + function getNgRepeatExpression(node) { + return node.getAttribute('ng-repeat') || node.getAttribute('data-ng-repeat') || node.getAttribute('x-ng-repeat'); + } + // Export return { restrict: 'AC', @@ -45,18 +49,15 @@ compile: function ($element, $attr) { var ngRepeat = [].filter.call($element[0].childNodes, function (node) { - return ( - node.nodeType === Node.ELEMENT_NODE && - angular.element(node).data('ngRepeat') - ); + return node.nodeType === Node.ELEMENT_NODE && getNgRepeatExpression(node); })[0]; if (!ngRepeat) { return; } - var expression = angular.element(ngRepeat).data('ngRepeat'); - var match = expression.match(/^\s*([\s\S]+?)\s+in\s+([\s\S]+?)(?:\s+as\s+([\s\S]+?))?(?:\s+track\s+by\s+([\s\S]+?))?\s*$/); + var match = getNgRepeatExpression(ngRepeat) + .match(/^\s*([\s\S]+?)\s+in\s+([\s\S]+?)(?:\s+as\s+([\s\S]+?))?(?:\s+track\s+by\s+([\s\S]+?))?\s*$/); if (!match) { return;