Browse Source

Enable the angular directive to work when debugInfo is off

pull/883/head
Rickert Mulder 9 years ago
parent
commit
49d8535399
  1. 45
      ng-sortable.js

45
ng-sortable.js

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

Loading…
Cancel
Save