Skip to content

Commit

Permalink
fixed #111 #106
Browse files Browse the repository at this point in the history
  • Loading branch information
JimLiu committed Apr 26, 2014
1 parent a7bf9ba commit 338e830
Show file tree
Hide file tree
Showing 12 changed files with 199 additions and 118 deletions.
2 changes: 1 addition & 1 deletion bower.json
@@ -1,6 +1,6 @@
{
"name": "angular-ui-tree",
"version": "2.0.10",
"version": "2.0.11",
"homepage": "https://github.com/JimLiu/angular-ui-tree",
"authors": [
"Jim Liu <https://github.com/JimLiu>",
Expand Down
102 changes: 65 additions & 37 deletions demo/dist/angular-ui-tree.js
@@ -1,5 +1,5 @@
/**
* @license Angular UI Tree v2.0.10
* @license Angular UI Tree v2.0.11
* (c) 2010-2014. https://github.com/JimLiu/angular-ui-tree
* License: MIT
*/
Expand Down Expand Up @@ -40,6 +40,30 @@
function ($document, $window) {
return {

/**
* A hashtable used to storage data of nodes
* @type {Object}
*/
nodesData: {
},

setNodeAttribute: function(scope, attrName, val) {
var data = this.nodesData[scope.$modelValue.$$hashKey];
if (!data) {
data = {};
this.nodesData[scope.$modelValue.$$hashKey] = data;
}
data[attrName] = val;
},

getNodeAttribute: function(scope, attrName) {
var data = this.nodesData[scope.$modelValue.$$hashKey];
if (data) {
return data[attrName];
}
return null;
},

/**
* @ngdoc method
* @methodOf ui.tree.service:$nodrag
Expand Down Expand Up @@ -606,29 +630,26 @@
}
}, true);

scope.$watch(function () {
return scope.$eval(attrs.dragEnabled);
}, function (newVal) {
if((typeof newVal) == "boolean") {
scope.dragEnabled = newVal;
attrs.$observe('dragEnabled', function(val) {
var de = scope.$eval(val);
if((typeof de) == "boolean") {
scope.dragEnabled = de;
}
}, true);
});

scope.$watch(function() {
return scope.$eval(attrs.maxDepth);
}, function(newVal) {
if((typeof newVal) == "number") {
scope.maxDepth = newVal;
attrs.$observe('maxDepth', function(val) {
var md = scope.$eval(val);
if((typeof md) == "number") {
scope.maxDepth = md;
}
}, true);
});

scope.$watch(function() {
return scope.$eval(attrs.dragDelay);
}, function(newVal) {
if((typeof newVal) == "number") {
scope.dragDelay = newVal;
attrs.$observe('dragDelay', function(val) {
var dd = scope.$eval(val);
if((typeof dd) == "number") {
scope.dragDelay = dd;
}
}, true);
});

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

if (ngModel) {
ngModel.$render = function() {
if (!ngModel.$modelValue || !angular.isArray(ngModel.$modelValue)) {
ngModel.$setViewValue([]);
}
scope.$modelValue = ngModel.$modelValue;
};
}
/*
scope.$watch(attrs.ngModel, function() {
scope.$modelValue = ngModel.$modelValue;
}, true);
*/

scope.$watch(function() {
return scope.$eval(attrs.maxDepth);
}, function(newVal) {
if((typeof newVal) == "number") {
scope.maxDepth = newVal;
attrs.$observe('maxDepth', function(val) {
var md = scope.$eval(val);
if((typeof md) == "number") {
scope.maxDepth = md;
}
}, true);
});

attrs.$observe('nodrop', function(val) {
scope.nodrop = ((typeof val) != "undefined");
});

scope.$watch(function () {
return attrs.nodrop;
}, function (newVal) {
if((typeof newVal) != "undefined") {
scope.nodrop = true;
}
}, true);
}
};
}
Expand All @@ -759,6 +774,19 @@
}
scope.init(controllersArr);

scope.collapsed = !!$uiTreeHelper.getNodeAttribute(scope, 'collapsed');
attrs.$observe('collapsed', function(val) {
var collapsed = scope.$eval(val);
if((typeof collapsed) == "boolean") {
scope.collapsed = collapsed;
}
});

scope.$watch('collapsed', function(val) {
$uiTreeHelper.setNodeAttribute(scope, 'collapsed', val);
attrs.$set('collapsed', val);
});

var hasTouch = 'ontouchstart' in window;
var startPos, firstMoving, dragInfo, pos;
var placeElm, hiddenPlaceElm, dragElm;
Expand Down
4 changes: 2 additions & 2 deletions demo/dist/angular-ui-tree.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion demo/tree.html
Expand Up @@ -54,7 +54,7 @@ <h3>Data binding</h3>
</div>

</div>

<script src="bower_components/angular/angular.min.js"></script>
<script type="text/javascript" src="dist/angular-ui-tree.js"></script>
<script type="text/javascript" src="js/tree.js"></script>
Expand Down
102 changes: 65 additions & 37 deletions dist/angular-ui-tree.js
@@ -1,5 +1,5 @@
/**
* @license Angular UI Tree v2.0.10
* @license Angular UI Tree v2.0.11
* (c) 2010-2014. https://github.com/JimLiu/angular-ui-tree
* License: MIT
*/
Expand Down Expand Up @@ -40,6 +40,30 @@
function ($document, $window) {
return {

/**
* A hashtable used to storage data of nodes
* @type {Object}
*/
nodesData: {
},

setNodeAttribute: function(scope, attrName, val) {
var data = this.nodesData[scope.$modelValue.$$hashKey];
if (!data) {
data = {};
this.nodesData[scope.$modelValue.$$hashKey] = data;
}
data[attrName] = val;
},

getNodeAttribute: function(scope, attrName) {
var data = this.nodesData[scope.$modelValue.$$hashKey];
if (data) {
return data[attrName];
}
return null;
},

/**
* @ngdoc method
* @methodOf ui.tree.service:$nodrag
Expand Down Expand Up @@ -606,29 +630,26 @@
}
}, true);

scope.$watch(function () {
return scope.$eval(attrs.dragEnabled);
}, function (newVal) {
if((typeof newVal) == "boolean") {
scope.dragEnabled = newVal;
attrs.$observe('dragEnabled', function(val) {
var de = scope.$eval(val);
if((typeof de) == "boolean") {
scope.dragEnabled = de;
}
}, true);
});

scope.$watch(function() {
return scope.$eval(attrs.maxDepth);
}, function(newVal) {
if((typeof newVal) == "number") {
scope.maxDepth = newVal;
attrs.$observe('maxDepth', function(val) {
var md = scope.$eval(val);
if((typeof md) == "number") {
scope.maxDepth = md;
}
}, true);
});

scope.$watch(function() {
return scope.$eval(attrs.dragDelay);
}, function(newVal) {
if((typeof newVal) == "number") {
scope.dragDelay = newVal;
attrs.$observe('dragDelay', function(val) {
var dd = scope.$eval(val);
if((typeof dd) == "number") {
scope.dragDelay = dd;
}
}, true);
});

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

if (ngModel) {
ngModel.$render = function() {
if (!ngModel.$modelValue || !angular.isArray(ngModel.$modelValue)) {
ngModel.$setViewValue([]);
}
scope.$modelValue = ngModel.$modelValue;
};
}
/*
scope.$watch(attrs.ngModel, function() {
scope.$modelValue = ngModel.$modelValue;
}, true);
*/

scope.$watch(function() {
return scope.$eval(attrs.maxDepth);
}, function(newVal) {
if((typeof newVal) == "number") {
scope.maxDepth = newVal;
attrs.$observe('maxDepth', function(val) {
var md = scope.$eval(val);
if((typeof md) == "number") {
scope.maxDepth = md;
}
}, true);
});

attrs.$observe('nodrop', function(val) {
scope.nodrop = ((typeof val) != "undefined");
});

scope.$watch(function () {
return attrs.nodrop;
}, function (newVal) {
if((typeof newVal) != "undefined") {
scope.nodrop = true;
}
}, true);
}
};
}
Expand All @@ -759,6 +774,19 @@
}
scope.init(controllersArr);

scope.collapsed = !!$uiTreeHelper.getNodeAttribute(scope, 'collapsed');
attrs.$observe('collapsed', function(val) {
var collapsed = scope.$eval(val);
if((typeof collapsed) == "boolean") {
scope.collapsed = collapsed;
}
});

scope.$watch('collapsed', function(val) {
$uiTreeHelper.setNodeAttribute(scope, 'collapsed', val);
attrs.$set('collapsed', val);
});

var hasTouch = 'ontouchstart' in window;
var startPos, firstMoving, dragInfo, pos;
var placeElm, hiddenPlaceElm, dragElm;
Expand Down
4 changes: 2 additions & 2 deletions dist/angular-ui-tree.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "Angular-NestedSortable",
"version": "2.0.10",
"version": "2.0.11",
"dependencies": {
"grunt": "~0.4.2",
"grunt-contrib-jshint": "~0.8.0",
Expand Down
33 changes: 15 additions & 18 deletions source/directives/uiTree.js
Expand Up @@ -30,29 +30,26 @@
}
}, true);

scope.$watch(function () {
return scope.$eval(attrs.dragEnabled);
}, function (newVal) {
if((typeof newVal) == "boolean") {
scope.dragEnabled = newVal;
attrs.$observe('dragEnabled', function(val) {
var de = scope.$eval(val);
if((typeof de) == "boolean") {
scope.dragEnabled = de;
}
}, true);
});

scope.$watch(function() {
return scope.$eval(attrs.maxDepth);
}, function(newVal) {
if((typeof newVal) == "number") {
scope.maxDepth = newVal;
attrs.$observe('maxDepth', function(val) {
var md = scope.$eval(val);
if((typeof md) == "number") {
scope.maxDepth = md;
}
}, true);
});

scope.$watch(function() {
return scope.$eval(attrs.dragDelay);
}, function(newVal) {
if((typeof newVal) == "number") {
scope.dragDelay = newVal;
attrs.$observe('dragDelay', function(val) {
var dd = scope.$eval(val);
if((typeof dd) == "number") {
scope.dragDelay = dd;
}
}, true);
});

// check if the dest node can accept the dragging node
// by default, we check the 'data-nodrop' attribute in `ui-tree-nodes`
Expand Down
13 changes: 13 additions & 0 deletions source/directives/uiTreeNode.js
Expand Up @@ -17,6 +17,19 @@
}
scope.init(controllersArr);

scope.collapsed = !!$uiTreeHelper.getNodeAttribute(scope, 'collapsed');
attrs.$observe('collapsed', function(val) {
var collapsed = scope.$eval(val);
if((typeof collapsed) == "boolean") {
scope.collapsed = collapsed;
}
});

scope.$watch('collapsed', function(val) {
$uiTreeHelper.setNodeAttribute(scope, 'collapsed', val);
attrs.$set('collapsed', val);
});

var hasTouch = 'ontouchstart' in window;
var startPos, firstMoving, dragInfo, pos;
var placeElm, hiddenPlaceElm, dragElm;
Expand Down

0 comments on commit 338e830

Please sign in to comment.