From 55ae4457ca7bd8de31b0a98d527f8a0cb3204212 Mon Sep 17 00:00:00 2001 From: RubaXa Date: Mon, 9 Feb 2015 18:27:02 +0300 Subject: [PATCH] #267: + support without ng-repeat --- ng-sortable.js | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/ng-sortable.js b/ng-sortable.js index ec4aba6df..bef396c7f 100644 --- a/ng-sortable.js +++ b/ng-sortable.js @@ -39,6 +39,11 @@ ); })[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|]+)/); @@ -74,7 +79,7 @@ /* jshint expr:true */ options[name] && options[name]({ model: item, - models: source.items(), + models: source && source.items(), oldIndex: evt.oldIndex, newIndex: evt.newIndex }); @@ -82,6 +87,11 @@ function _sync(/**Event*/evt) { + if (!source) { + // Without ng-repeat + return; + } + var oldIndex = evt.oldIndex, newIndex = evt.newIndex, items = source.items(); @@ -133,13 +143,13 @@ }, onUpdate: function (/**Event*/evt) { _sync(evt); - _emitEvent(evt, source.item(evt.item)); + _emitEvent(evt, source && source.item(evt.item)); }, onRemove: function (/**Event*/evt) { _emitEvent(evt, removed); }, onSort: function (/**Event*/evt) { - _emitEvent(evt, source.item(evt.item)); + _emitEvent(evt, source && source.item(evt.item)); } }));