Skip to content

Commit

Permalink
#267: + support without ng-repeat
Browse files Browse the repository at this point in the history
  • Loading branch information
RubaXa committed Feb 9, 2015
1 parent 85292d9 commit 55ae445
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions ng-sortable.js
Original file line number Diff line number Diff line change
Expand Up @@ -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|]+)/);

Expand Down Expand Up @@ -74,14 +79,19 @@
/* jshint expr:true */
options[name] && options[name]({
model: item,
models: source.items(),
models: source && source.items(),
oldIndex: evt.oldIndex,
newIndex: evt.newIndex
});
}


function _sync(/**Event*/evt) {
if (!source) {
// Without ng-repeat
return;
}

var oldIndex = evt.oldIndex,
newIndex = evt.newIndex,
items = source.items();
Expand Down Expand Up @@ -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));
}
}));

Expand Down

0 comments on commit 55ae445

Please sign in to comment.