Skip to content

Commit 338e830

Browse files
committed
1 parent a7bf9ba commit 338e830

File tree

12 files changed

+199
-118
lines changed

12 files changed

+199
-118
lines changed

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "angular-ui-tree",
3-
"version": "2.0.10",
3+
"version": "2.0.11",
44
"homepage": "https://github.com/JimLiu/angular-ui-tree",
55
"authors": [
66
"Jim Liu <https://github.com/JimLiu>",

demo/dist/angular-ui-tree.js

Lines changed: 65 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* @license Angular UI Tree v2.0.10
2+
* @license Angular UI Tree v2.0.11
33
* (c) 2010-2014. https://github.com/JimLiu/angular-ui-tree
44
* License: MIT
55
*/
@@ -40,6 +40,30 @@
4040
function ($document, $window) {
4141
return {
4242

43+
/**
44+
* A hashtable used to storage data of nodes
45+
* @type {Object}
46+
*/
47+
nodesData: {
48+
},
49+
50+
setNodeAttribute: function(scope, attrName, val) {
51+
var data = this.nodesData[scope.$modelValue.$$hashKey];
52+
if (!data) {
53+
data = {};
54+
this.nodesData[scope.$modelValue.$$hashKey] = data;
55+
}
56+
data[attrName] = val;
57+
},
58+
59+
getNodeAttribute: function(scope, attrName) {
60+
var data = this.nodesData[scope.$modelValue.$$hashKey];
61+
if (data) {
62+
return data[attrName];
63+
}
64+
return null;
65+
},
66+
4367
/**
4468
* @ngdoc method
4569
* @methodOf ui.tree.service:$nodrag
@@ -606,29 +630,26 @@
606630
}
607631
}, true);
608632

609-
scope.$watch(function () {
610-
return scope.$eval(attrs.dragEnabled);
611-
}, function (newVal) {
612-
if((typeof newVal) == "boolean") {
613-
scope.dragEnabled = newVal;
633+
attrs.$observe('dragEnabled', function(val) {
634+
var de = scope.$eval(val);
635+
if((typeof de) == "boolean") {
636+
scope.dragEnabled = de;
614637
}
615-
}, true);
638+
});
616639

617-
scope.$watch(function() {
618-
return scope.$eval(attrs.maxDepth);
619-
}, function(newVal) {
620-
if((typeof newVal) == "number") {
621-
scope.maxDepth = newVal;
640+
attrs.$observe('maxDepth', function(val) {
641+
var md = scope.$eval(val);
642+
if((typeof md) == "number") {
643+
scope.maxDepth = md;
622644
}
623-
}, true);
645+
});
624646

625-
scope.$watch(function() {
626-
return scope.$eval(attrs.dragDelay);
627-
}, function(newVal) {
628-
if((typeof newVal) == "number") {
629-
scope.dragDelay = newVal;
647+
attrs.$observe('dragDelay', function(val) {
648+
var dd = scope.$eval(val);
649+
if((typeof dd) == "number") {
650+
scope.dragDelay = dd;
630651
}
631-
}, true);
652+
});
632653

633654
// check if the dest node can accept the dragging node
634655
// by default, we check the 'data-nodrop' attribute in `ui-tree-nodes`
@@ -710,30 +731,24 @@
710731

711732
if (ngModel) {
712733
ngModel.$render = function() {
734+
if (!ngModel.$modelValue || !angular.isArray(ngModel.$modelValue)) {
735+
ngModel.$setViewValue([]);
736+
}
713737
scope.$modelValue = ngModel.$modelValue;
714738
};
715739
}
716-
/*
717-
scope.$watch(attrs.ngModel, function() {
718-
scope.$modelValue = ngModel.$modelValue;
719-
}, true);
720-
*/
721740

722-
scope.$watch(function() {
723-
return scope.$eval(attrs.maxDepth);
724-
}, function(newVal) {
725-
if((typeof newVal) == "number") {
726-
scope.maxDepth = newVal;
741+
attrs.$observe('maxDepth', function(val) {
742+
var md = scope.$eval(val);
743+
if((typeof md) == "number") {
744+
scope.maxDepth = md;
727745
}
728-
}, true);
746+
});
747+
748+
attrs.$observe('nodrop', function(val) {
749+
scope.nodrop = ((typeof val) != "undefined");
750+
});
729751

730-
scope.$watch(function () {
731-
return attrs.nodrop;
732-
}, function (newVal) {
733-
if((typeof newVal) != "undefined") {
734-
scope.nodrop = true;
735-
}
736-
}, true);
737752
}
738753
};
739754
}
@@ -759,6 +774,19 @@
759774
}
760775
scope.init(controllersArr);
761776

777+
scope.collapsed = !!$uiTreeHelper.getNodeAttribute(scope, 'collapsed');
778+
attrs.$observe('collapsed', function(val) {
779+
var collapsed = scope.$eval(val);
780+
if((typeof collapsed) == "boolean") {
781+
scope.collapsed = collapsed;
782+
}
783+
});
784+
785+
scope.$watch('collapsed', function(val) {
786+
$uiTreeHelper.setNodeAttribute(scope, 'collapsed', val);
787+
attrs.$set('collapsed', val);
788+
});
789+
762790
var hasTouch = 'ontouchstart' in window;
763791
var startPos, firstMoving, dragInfo, pos;
764792
var placeElm, hiddenPlaceElm, dragElm;

demo/dist/angular-ui-tree.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

demo/tree.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ <h3>Data binding</h3>
5454
</div>
5555

5656
</div>
57-
57+
5858
<script src="bower_components/angular/angular.min.js"></script>
5959
<script type="text/javascript" src="dist/angular-ui-tree.js"></script>
6060
<script type="text/javascript" src="js/tree.js"></script>

dist/angular-ui-tree.js

Lines changed: 65 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* @license Angular UI Tree v2.0.10
2+
* @license Angular UI Tree v2.0.11
33
* (c) 2010-2014. https://github.com/JimLiu/angular-ui-tree
44
* License: MIT
55
*/
@@ -40,6 +40,30 @@
4040
function ($document, $window) {
4141
return {
4242

43+
/**
44+
* A hashtable used to storage data of nodes
45+
* @type {Object}
46+
*/
47+
nodesData: {
48+
},
49+
50+
setNodeAttribute: function(scope, attrName, val) {
51+
var data = this.nodesData[scope.$modelValue.$$hashKey];
52+
if (!data) {
53+
data = {};
54+
this.nodesData[scope.$modelValue.$$hashKey] = data;
55+
}
56+
data[attrName] = val;
57+
},
58+
59+
getNodeAttribute: function(scope, attrName) {
60+
var data = this.nodesData[scope.$modelValue.$$hashKey];
61+
if (data) {
62+
return data[attrName];
63+
}
64+
return null;
65+
},
66+
4367
/**
4468
* @ngdoc method
4569
* @methodOf ui.tree.service:$nodrag
@@ -606,29 +630,26 @@
606630
}
607631
}, true);
608632

609-
scope.$watch(function () {
610-
return scope.$eval(attrs.dragEnabled);
611-
}, function (newVal) {
612-
if((typeof newVal) == "boolean") {
613-
scope.dragEnabled = newVal;
633+
attrs.$observe('dragEnabled', function(val) {
634+
var de = scope.$eval(val);
635+
if((typeof de) == "boolean") {
636+
scope.dragEnabled = de;
614637
}
615-
}, true);
638+
});
616639

617-
scope.$watch(function() {
618-
return scope.$eval(attrs.maxDepth);
619-
}, function(newVal) {
620-
if((typeof newVal) == "number") {
621-
scope.maxDepth = newVal;
640+
attrs.$observe('maxDepth', function(val) {
641+
var md = scope.$eval(val);
642+
if((typeof md) == "number") {
643+
scope.maxDepth = md;
622644
}
623-
}, true);
645+
});
624646

625-
scope.$watch(function() {
626-
return scope.$eval(attrs.dragDelay);
627-
}, function(newVal) {
628-
if((typeof newVal) == "number") {
629-
scope.dragDelay = newVal;
647+
attrs.$observe('dragDelay', function(val) {
648+
var dd = scope.$eval(val);
649+
if((typeof dd) == "number") {
650+
scope.dragDelay = dd;
630651
}
631-
}, true);
652+
});
632653

633654
// check if the dest node can accept the dragging node
634655
// by default, we check the 'data-nodrop' attribute in `ui-tree-nodes`
@@ -710,30 +731,24 @@
710731

711732
if (ngModel) {
712733
ngModel.$render = function() {
734+
if (!ngModel.$modelValue || !angular.isArray(ngModel.$modelValue)) {
735+
ngModel.$setViewValue([]);
736+
}
713737
scope.$modelValue = ngModel.$modelValue;
714738
};
715739
}
716-
/*
717-
scope.$watch(attrs.ngModel, function() {
718-
scope.$modelValue = ngModel.$modelValue;
719-
}, true);
720-
*/
721740

722-
scope.$watch(function() {
723-
return scope.$eval(attrs.maxDepth);
724-
}, function(newVal) {
725-
if((typeof newVal) == "number") {
726-
scope.maxDepth = newVal;
741+
attrs.$observe('maxDepth', function(val) {
742+
var md = scope.$eval(val);
743+
if((typeof md) == "number") {
744+
scope.maxDepth = md;
727745
}
728-
}, true);
746+
});
747+
748+
attrs.$observe('nodrop', function(val) {
749+
scope.nodrop = ((typeof val) != "undefined");
750+
});
729751

730-
scope.$watch(function () {
731-
return attrs.nodrop;
732-
}, function (newVal) {
733-
if((typeof newVal) != "undefined") {
734-
scope.nodrop = true;
735-
}
736-
}, true);
737752
}
738753
};
739754
}
@@ -759,6 +774,19 @@
759774
}
760775
scope.init(controllersArr);
761776

777+
scope.collapsed = !!$uiTreeHelper.getNodeAttribute(scope, 'collapsed');
778+
attrs.$observe('collapsed', function(val) {
779+
var collapsed = scope.$eval(val);
780+
if((typeof collapsed) == "boolean") {
781+
scope.collapsed = collapsed;
782+
}
783+
});
784+
785+
scope.$watch('collapsed', function(val) {
786+
$uiTreeHelper.setNodeAttribute(scope, 'collapsed', val);
787+
attrs.$set('collapsed', val);
788+
});
789+
762790
var hasTouch = 'ontouchstart' in window;
763791
var startPos, firstMoving, dragInfo, pos;
764792
var placeElm, hiddenPlaceElm, dragElm;

dist/angular-ui-tree.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "Angular-NestedSortable",
3-
"version": "2.0.10",
3+
"version": "2.0.11",
44
"dependencies": {
55
"grunt": "~0.4.2",
66
"grunt-contrib-jshint": "~0.8.0",

source/directives/uiTree.js

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -30,29 +30,26 @@
3030
}
3131
}, true);
3232

33-
scope.$watch(function () {
34-
return scope.$eval(attrs.dragEnabled);
35-
}, function (newVal) {
36-
if((typeof newVal) == "boolean") {
37-
scope.dragEnabled = newVal;
33+
attrs.$observe('dragEnabled', function(val) {
34+
var de = scope.$eval(val);
35+
if((typeof de) == "boolean") {
36+
scope.dragEnabled = de;
3837
}
39-
}, true);
38+
});
4039

41-
scope.$watch(function() {
42-
return scope.$eval(attrs.maxDepth);
43-
}, function(newVal) {
44-
if((typeof newVal) == "number") {
45-
scope.maxDepth = newVal;
40+
attrs.$observe('maxDepth', function(val) {
41+
var md = scope.$eval(val);
42+
if((typeof md) == "number") {
43+
scope.maxDepth = md;
4644
}
47-
}, true);
45+
});
4846

49-
scope.$watch(function() {
50-
return scope.$eval(attrs.dragDelay);
51-
}, function(newVal) {
52-
if((typeof newVal) == "number") {
53-
scope.dragDelay = newVal;
47+
attrs.$observe('dragDelay', function(val) {
48+
var dd = scope.$eval(val);
49+
if((typeof dd) == "number") {
50+
scope.dragDelay = dd;
5451
}
55-
}, true);
52+
});
5653

5754
// check if the dest node can accept the dragging node
5855
// by default, we check the 'data-nodrop' attribute in `ui-tree-nodes`

source/directives/uiTreeNode.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,19 @@
1717
}
1818
scope.init(controllersArr);
1919

20+
scope.collapsed = !!$uiTreeHelper.getNodeAttribute(scope, 'collapsed');
21+
attrs.$observe('collapsed', function(val) {
22+
var collapsed = scope.$eval(val);
23+
if((typeof collapsed) == "boolean") {
24+
scope.collapsed = collapsed;
25+
}
26+
});
27+
28+
scope.$watch('collapsed', function(val) {
29+
$uiTreeHelper.setNodeAttribute(scope, 'collapsed', val);
30+
attrs.$set('collapsed', val);
31+
});
32+
2033
var hasTouch = 'ontouchstart' in window;
2134
var startPos, firstMoving, dragInfo, pos;
2235
var placeElm, hiddenPlaceElm, dragElm;

0 commit comments

Comments
 (0)