|
|
|
@ -35,42 +35,45 @@
|
|
|
|
|
.constant('ngSortableConfig', {}) |
|
|
|
|
.directive('ngSortable', ['$parse', 'ngSortableConfig', function ($parse, ngSortableConfig) { |
|
|
|
|
var removed, |
|
|
|
|
nextSibling, |
|
|
|
|
getSourceFactory = function getSourceFactory(el, scope) { |
|
|
|
|
var ngRepeat = [].filter.call(el.childNodes, function (node) { |
|
|
|
|
nextSibling; |
|
|
|
|
|
|
|
|
|
// Export
|
|
|
|
|
return { |
|
|
|
|
restrict: 'AC', |
|
|
|
|
scope: { ngSortable: "=?" }, |
|
|
|
|
priority: 1001, |
|
|
|
|
compile: function ($element, $attr) { |
|
|
|
|
|
|
|
|
|
var ngRepeat = [].filter.call($element[0].childNodes, function (node) { |
|
|
|
|
return ( |
|
|
|
|
(node.nodeType === 8) && |
|
|
|
|
(node.nodeValue.indexOf('ngRepeat:') !== -1) |
|
|
|
|
(node.nodeType === 1) && |
|
|
|
|
(node.attributes['ng-repeat']) |
|
|
|
|
); |
|
|
|
|
})[0]; |
|
|
|
|
|
|
|
|
|
if (!ngRepeat) { |
|
|
|
|
// Without ng-repeat
|
|
|
|
|
return function () { |
|
|
|
|
return null; |
|
|
|
|
}; |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// tests: http://jsbin.com/kosubutilo/1/edit?js,output
|
|
|
|
|
ngRepeat = ngRepeat.nodeValue.match(/ngRepeat:\s*(?:\(.*?,\s*)?([^\s)]+)[\s)]+in\s+([^\s|]+)/); |
|
|
|
|
var expression = ngRepeat.attributes['ng-repeat'].nodeValue; |
|
|
|
|
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 itemsExpr = $parse(ngRepeat[2]); |
|
|
|
|
if (!match) { |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
var rhs = match[2]; |
|
|
|
|
|
|
|
|
|
return function () { |
|
|
|
|
return function postLink(scope, $el) { |
|
|
|
|
var itemsExpr = $parse(rhs); |
|
|
|
|
var getSource = function getSource() { |
|
|
|
|
return itemsExpr(scope.$parent) || []; |
|
|
|
|
}; |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Export
|
|
|
|
|
return { |
|
|
|
|
restrict: 'AC', |
|
|
|
|
scope: { ngSortable: "=?" }, |
|
|
|
|
link: function (scope, $el) { |
|
|
|
|
var el = $el[0], |
|
|
|
|
options = angular.extend(scope.ngSortable || {}, ngSortableConfig), |
|
|
|
|
watchers = [], |
|
|
|
|
getSource = getSourceFactory(el, scope), |
|
|
|
|
offDestroy, |
|
|
|
|
sortable |
|
|
|
|
; |
|
|
|
@ -198,6 +201,8 @@
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
offDestroy = scope.$on('$destroy', _destroy); |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
}]); |
|
|
|
|