From 73b61f80ebf7db14f443cfe751405f67e2b9ca68 Mon Sep 17 00:00:00 2001 From: Sergey Aksyonov Date: Mon, 22 Dec 2014 14:40:22 +0200 Subject: [PATCH 01/19] Fixed angular directive for complex ng-repeat expressions --- ng-sortable.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/ng-sortable.js b/ng-sortable.js index 12b9388..873e4e8 100644 --- a/ng-sortable.js +++ b/ng-sortable.js @@ -17,9 +17,10 @@ angular.module('ng-sortable', []) (node.nodeValue.indexOf('ngRepeat:') !== -1) ); })[0]; - ngRepeat = ngRepeat.nodeValue.match(/ngRepeat:\s*([^\s]+)\s+in\s+([^\s|]+)/); + ngRepeat = ngRepeat.nodeValue.match(/ngRepeat:\s*([\s\S]+?)\s+in\s+([\s\S]+?)(?:\s)/); - var itemExpr = $parse(ngRepeat[1]); + var lhs = ngRepeat[1].match(/^(?:([\$\w]+)|\(([\$\w]+)\s*,\s*([\$\w]+)\))$/); + var itemExpr = $parse(lhs[3] || lhs[1]); var itemsExpr = $parse(ngRepeat[2]); return { From 3ab736b570bd3e09e548e5c079315a698122e807 Mon Sep 17 00:00:00 2001 From: Sergey Aksyonov Date: Mon, 22 Dec 2014 16:45:50 +0200 Subject: [PATCH 02/19] Fixed expression regex --- ng-sortable.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/ng-sortable.js b/ng-sortable.js index 873e4e8..a1d572e 100644 --- a/ng-sortable.js +++ b/ng-sortable.js @@ -17,10 +17,9 @@ angular.module('ng-sortable', []) (node.nodeValue.indexOf('ngRepeat:') !== -1) ); })[0]; - ngRepeat = ngRepeat.nodeValue.match(/ngRepeat:\s*([\s\S]+?)\s+in\s+([\s\S]+?)(?:\s)/); + ngRepeat = ngRepeat.nodeValue.match(/ngRepeat:\s*(?:\(.*?,\s*)?([^\s)]+)[\s)]+in\s+([^\s|]+)/); - var lhs = ngRepeat[1].match(/^(?:([\$\w]+)|\(([\$\w]+)\s*,\s*([\$\w]+)\))$/); - var itemExpr = $parse(lhs[3] || lhs[1]); + var itemExpr = $parse(ngRepeat[1]); var itemsExpr = $parse(ngRepeat[2]); return { From 8b26ca27c9d4c5de5dbe8eabd703e63c552048f6 Mon Sep 17 00:00:00 2001 From: Lebedev Konstantin Date: Mon, 22 Dec 2014 18:40:50 +0300 Subject: [PATCH 03/19] Update ng-sortable.js --- ng-sortable.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/ng-sortable.js b/ng-sortable.js index a1d572e..f6ec09b 100644 --- a/ng-sortable.js +++ b/ng-sortable.js @@ -3,7 +3,7 @@ * @licence MIT */ angular.module('ng-sortable', []) - .constant('$version', '0.3.2') + .constant('$version', '0.3.3') .directive('ngSortable', ['$parse', function ($parse) { 'use strict'; @@ -17,6 +17,8 @@ angular.module('ng-sortable', []) (node.nodeValue.indexOf('ngRepeat:') !== -1) ); })[0]; + + // 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]); From 91089fc38179690a02277d70a9b2a7c87eecb3d0 Mon Sep 17 00:00:00 2001 From: afc163 Date: Wed, 24 Dec 2014 23:53:05 +0800 Subject: [PATCH 04/19] Add spm support --- package.json | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index cade1db..5b50d73 100644 --- a/package.json +++ b/package.json @@ -25,5 +25,12 @@ "drag" ], "author": "Konstantin Lebedev ", - "license": "MIT" + "license": "MIT", + "spm": { + "main": "Sortable.js", + "ignore": [ + "meteor", + "st" + ] + } } From b1daa70a2a067bb3c9a577dff7b1f0986e3cf057 Mon Sep 17 00:00:00 2001 From: raphj Date: Sun, 28 Dec 2014 10:26:28 +0100 Subject: [PATCH 05/19] Make Sotable compatible xhtml comparisons of node names (via the nodeName property) are done in upper case. However, nodeName is lower case in xhtml. Let's do everything in upper case. --- Sortable.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sortable.js b/Sortable.js index 5d10475..4b82eec 100644 --- a/Sortable.js +++ b/Sortable.js @@ -809,7 +809,7 @@ do { if ( (tag === '>*' && el.parentNode === ctx) || ( - (tag === '' || el.nodeName == tag) && + (tag === '' || el.nodeName.toUpperCase() == tag) && (!selector.length || ((' ' + el.className + ' ').match(re) || []).length == selector.length) ) ) { @@ -937,7 +937,7 @@ */ function _index(/**HTMLElement*/el) { var index = 0; - while (el && (el = el.previousElementSibling) && (el.nodeName !== 'TEMPLATE')) { + while (el && (el = el.previousElementSibling) && (el.nodeName.toUpperCase() !== 'TEMPLATE')) { index++; } return index; From 75d95c4439c5131f0023ef32ae590abbe1a446f4 Mon Sep 17 00:00:00 2001 From: David Burles Date: Thu, 8 Jan 2015 16:33:04 +1100 Subject: [PATCH 06/19] fixes conflict with collection-helpers package update mongo-collection-instances to 0.2.6 --- meteor/package.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/meteor/package.js b/meteor/package.js index 823a0ac..148561a 100644 --- a/meteor/package.js +++ b/meteor/package.js @@ -16,7 +16,7 @@ Package.describe({ Package.onUse(function (api) { api.versionsFrom(['METEOR@0.9.0', 'METEOR@1.0']); api.use('templating', 'client'); - api.use('dburles:mongo-collection-instances@0.2.5'); // to watch collections getting created + api.use('dburles:mongo-collection-instances@0.2.6'); // to watch collections getting created api.export('Sortable'); api.addFiles([ 'Sortable.js', From 842856263cb29ec62fbb1dec5a9f639d13895477 Mon Sep 17 00:00:00 2001 From: Willson Mock Date: Sun, 11 Jan 2015 21:53:10 -0500 Subject: [PATCH 07/19] Update README with updated info --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index c84cfc5..b67881a 100644 --- a/README.md +++ b/README.md @@ -430,7 +430,7 @@ Link to the active instance. ## MIT LICENSE -Copyright 2013-2014 Lebedev Konstantin +Copyright 2013-2015 Lebedev Konstantin http://rubaxa.github.io/Sortable/ Permission is hereby granted, free of charge, to any person obtaining From 34bbbcb5a19b1ae762de80a271e1b256abd82429 Mon Sep 17 00:00:00 2001 From: Lebedev Konstantin Date: Sun, 18 Jan 2015 21:34:37 +0300 Subject: [PATCH 08/19] #229: * ghostClass example --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index b67881a..2d202b8 100644 --- a/README.md +++ b/README.md @@ -202,7 +202,7 @@ Sortable.create(list, { #### `ghostClass` option Class name for the drop placeholder. -Demo: http://jsbin.com/boqugumiqi/1/edit?css,js,output +Demo: http://jsbin.com/hunifu/1/edit?css,js,output ```css .ghost { From e08f065adaec1f47e056f0228da53cb986974637 Mon Sep 17 00:00:00 2001 From: RubaXa Date: Sun, 18 Jan 2015 21:55:53 +0300 Subject: [PATCH 09/19] #209: * drag-handle --- st/app.css | 1 + 1 file changed, 1 insertion(+) diff --git a/st/app.css b/st/app.css index 4dbbb8b..2059294 100644 --- a/st/app.css +++ b/st/app.css @@ -220,6 +220,7 @@ img { margin-right: 10px; font: bold 20px Sans-Serif; color: #5F9EDF; + display: inline-block; cursor: move; cursor: -webkit-grabbing; /* overrides 'move' */ } From 3dc8cae4fc0831f717e3c721df89794e3a30b485 Mon Sep 17 00:00:00 2001 From: RubaXa Date: Tue, 20 Jan 2015 00:18:39 +0300 Subject: [PATCH 10/19] #231: save order --- ng-sortable.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ng-sortable.js b/ng-sortable.js index f7f3c8d..827acdc 100644 --- a/ng-sortable.js +++ b/ng-sortable.js @@ -15,7 +15,7 @@ 'use strict'; angular.module('ng-sortable', []) - .constant('$version', '0.3.2') + .constant('$version', '0.3.3') .directive('ngSortable', ['$parse', function ($parse) { var removed; @@ -76,7 +76,7 @@ if (evt.clone) { newIndex = Sortable.utils.index(evt.clone); - prevItems.splice(newIndex, 0, removed); + prevItems.splice(oldIndex, 0, removed); evt.from.removeChild(evt.clone); } From d823817419dbab417a64027ee8f7d177af4b7808 Mon Sep 17 00:00:00 2001 From: RubaXa Date: Tue, 20 Jan 2015 00:30:42 +0300 Subject: [PATCH 11/19] #231: correct 'clone' workaround --- ng-sortable.js | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/ng-sortable.js b/ng-sortable.js index 827acdc..263ec34 100644 --- a/ng-sortable.js +++ b/ng-sortable.js @@ -17,7 +17,8 @@ angular.module('ng-sortable', []) .constant('$version', '0.3.3') .directive('ngSortable', ['$parse', function ($parse) { - var removed; + var removed, + nextSibling; function getSource(el) { var scope = angular.element(el).scope(); @@ -70,19 +71,20 @@ prevItems = prevSource.items(); oldIndex = prevItems.indexOf(prevSource.item(evt.item)); - removed = prevItems.splice(oldIndex, 1)[0]; - - items.splice(newIndex, 0, removed); + removed = prevItems[oldIndex]; if (evt.clone) { - newIndex = Sortable.utils.index(evt.clone); - prevItems.splice(oldIndex, 0, removed); - evt.from.removeChild(evt.clone); } + else { + prevItems.splice(oldIndex, 1); + } - evt.from.appendChild(evt.item); // revert element - } else { + items.splice(newIndex, 0, removed); + + evt.from.insertBefore(evt.item, nextSibling); // revert element + } + else { items.splice(newIndex, 0, items.splice(oldIndex, 1)[0]); } @@ -94,17 +96,18 @@ opts[name] = opts[name] || options[name]; return opts; }, { - onStart: function () { + onStart: function (/**Event*/) { + nextSibling = evt.item.nextSibling; options.onStart(source.items()); }, onEnd: function () { options.onEnd(source.items()); }, - onAdd: function (evt) { + onAdd: function (/**Event*/evt) { _sync(evt); options.onAdd(source.items(), removed); }, - onUpdate: function (evt) { + onUpdate: function (/**Event*/evt) { _sync(evt); options.onUpdate(source.items(), source.item(evt.item)); }, @@ -119,6 +122,7 @@ $el.on('$destroy', function () { sortable.destroy(); sortable = null; + nextSibling = null; }); if (ngSortable && !/{|}/.test(ngSortable)) { // todo: ugly From e370723822e2114e2acd6cb2f1c9d1bc614de08a Mon Sep 17 00:00:00 2001 From: RubaXa Date: Tue, 20 Jan 2015 00:32:37 +0300 Subject: [PATCH 12/19] * evt --- ng-sortable.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ng-sortable.js b/ng-sortable.js index 263ec34..3e7c24f 100644 --- a/ng-sortable.js +++ b/ng-sortable.js @@ -96,7 +96,7 @@ opts[name] = opts[name] || options[name]; return opts; }, { - onStart: function (/**Event*/) { + onStart: function (/**Event*/evt) { nextSibling = evt.item.nextSibling; options.onStart(source.items()); }, From 8f2aa5eb68f5f31fc1cd0db7a5a3d76c06878803 Mon Sep 17 00:00:00 2001 From: RubaXa Date: Mon, 26 Jan 2015 16:02:31 +0300 Subject: [PATCH 13/19] + create 'cloneEl' on dragStart --- Sortable.js | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/Sortable.js b/Sortable.js index 31386d3..38dbb77 100644 --- a/Sortable.js +++ b/Sortable.js @@ -276,13 +276,6 @@ } } catch (err) { } - - - if (activeGroup.pull == 'clone') { - cloneEl = dragEl.cloneNode(true); - _css(cloneEl, 'display', 'none'); - rootEl.insertBefore(cloneEl, dragEl); - } } }, @@ -347,6 +340,12 @@ this._offUpEvents(); + if (activeGroup.pull == 'clone') { + cloneEl = dragEl.cloneNode(true); + _css(cloneEl, 'display', 'none'); + rootEl.insertBefore(cloneEl, dragEl); + } + if (isTouch) { var rect = dragEl.getBoundingClientRect(), css = _css(dragEl), From 5325c8a84224f231578f092ca56382480652cc91 Mon Sep 17 00:00:00 2001 From: Markus Ast Date: Tue, 27 Jan 2015 16:41:11 +0100 Subject: [PATCH 14/19] fix index calculation to skip templates --- Sortable.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Sortable.js b/Sortable.js index 60cd0bd..153cf1b 100644 --- a/Sortable.js +++ b/Sortable.js @@ -949,8 +949,10 @@ */ function _index(/**HTMLElement*/el) { var index = 0; - while (el && (el = el.previousElementSibling) && (el.nodeName.toUpperCase() !== 'TEMPLATE')) { - index++; + while (el && (el = el.previousElementSibling)) { + if (el.nodeName.toUpperCase() !== 'TEMPLATE') { + index++; + } } return index; } From f500b679f22b5aadf794a522751d5bb13ba881a0 Mon Sep 17 00:00:00 2001 From: RubaXa Date: Tue, 27 Jan 2015 23:47:16 +0300 Subject: [PATCH 15/19] #238: * disabled --- Sortable.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sortable.js b/Sortable.js index 60cd0bd..6395215 100644 --- a/Sortable.js +++ b/Sortable.js @@ -469,7 +469,7 @@ !options.dragoverBubble && evt.stopPropagation(); } - if (!_silent && activeGroup && + if (!_silent && activeGroup && !options.disabled && (isOwner ? canSort || (revert = !rootEl.contains(dragEl)) : activeGroup.pull && groupPut && ( From 705b3ed1aef454a897c433468e046d1ddd9f0cfb Mon Sep 17 00:00:00 2001 From: RubaXa Date: Tue, 27 Jan 2015 23:47:48 +0300 Subject: [PATCH 16/19] #238: * scope after event --- ng-sortable.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/ng-sortable.js b/ng-sortable.js index 8d310c4..ecbf23b 100644 --- a/ng-sortable.js +++ b/ng-sortable.js @@ -15,7 +15,7 @@ 'use strict'; angular.module('ng-sortable', []) - .constant('$version', '0.3.4') + .constant('$version', '0.3.5') .directive('ngSortable', ['$parse', function ($parse) { var removed, nextSibling; @@ -101,13 +101,16 @@ onStart: function (/**Event*/evt) { nextSibling = evt.item.nextSibling; options.onStart(source.items()); + scope.$apply(); }, onEnd: function () { options.onEnd(source.items()); + scope.$apply(); }, onAdd: function (/**Event*/evt) { _sync(evt); options.onAdd(source.items(), removed); + scope.$apply(); }, onUpdate: function (/**Event*/evt) { _sync(evt); From 778ee0b202f7d2396f945420896b312c01219725 Mon Sep 17 00:00:00 2001 From: "E.T.Cook" Date: Wed, 28 Jan 2015 00:06:55 -0600 Subject: [PATCH 17/19] Deep copy object to avoid unwanted referencing In relation to https://github.com/RubaXa/Sortable/issues/237 --- ng-sortable.js | 1 + 1 file changed, 1 insertion(+) diff --git a/ng-sortable.js b/ng-sortable.js index 8d310c4..3a2162f 100644 --- a/ng-sortable.js +++ b/ng-sortable.js @@ -77,6 +77,7 @@ if (evt.clone) { evt.from.removeChild(evt.clone); + removed = angular.copy(removed); } else { prevItems.splice(oldIndex, 1); From 2843550ac8c57c306edfe9ff6856727cf1a324e3 Mon Sep 17 00:00:00 2001 From: RubaXa Date: Wed, 28 Jan 2015 12:58:53 +0300 Subject: [PATCH 18/19] - comments --- .jshintrc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.jshintrc b/.jshintrc index e870dcc..3f67a09 100644 --- a/.jshintrc +++ b/.jshintrc @@ -1,9 +1,9 @@ { "strict": true, - "newcap": false, // "Tolerate uncapitalized constructors" + "newcap": false, "node": true, - "expr": true, // - true && call() "Expected an assignment or function call and instead saw an expression." - "supernew": true, // - "Missing '()' invoking a constructor." + "expr": true, + "supernew": true, "laxbreak": true, "white": true, "globals": { From 7bff4352d60cc1991f245777bfa858e663a8faaa Mon Sep 17 00:00:00 2001 From: RubaXa Date: Fri, 6 Feb 2015 12:24:01 +0300 Subject: [PATCH 19/19] #250: + additional check --- Sortable.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/Sortable.js b/Sortable.js index 3176f3a..bcc6b13 100644 --- a/Sortable.js +++ b/Sortable.js @@ -171,13 +171,15 @@ _dragStarted: function () { - // Apply effect - _toggleClass(dragEl, this.options.ghostClass, true); + if (rootEl && dragEl) { + // Apply effect + _toggleClass(dragEl, this.options.ghostClass, true); - Sortable.active = this; + Sortable.active = this; - // Drag start event - _dispatchEvent(rootEl, 'start', dragEl, rootEl, oldIndex); + // Drag start event + _dispatchEvent(rootEl, 'start', dragEl, rootEl, oldIndex); + } },