forked from fer/ion-tree-list
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
111 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Files | ||
.DS_Store | ||
|
||
# Directories | ||
.idea |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
{ | ||
"name": "ion-tree-list", | ||
"main": "ion-tree-list.js", | ||
"version": "0.0.1", | ||
"homepage": "https://github.com/fer/ion-tree-list", | ||
"authors": [ | ||
"fer <[email protected]>" | ||
], | ||
"description": "Ionic directive for displaying and manipulating nested list items.", | ||
"keywords": [ | ||
"ionic", | ||
"ion", | ||
"tree", | ||
"list" | ||
], | ||
"license": "MIT", | ||
"ignore": [ | ||
"**/.*", | ||
"node_modules", | ||
"bower_components", | ||
"test", | ||
"tests" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,37 @@ | ||
/** | ||
* returns a tree object with extra attribute 'depth' | ||
* | ||
* @param obj tree object | ||
* @param depth initial depth | ||
* @returns {*} obj with depths | ||
*/ | ||
function addDepthToTree(obj, depth) { | ||
for (key in obj) { | ||
if (typeof(obj[key]) == 'object') { | ||
if (key == 'tree') { | ||
addDepthToTree(obj[key], depth) | ||
} | ||
|
||
obj[key].depth = depth; | ||
addDepthToTree(obj[key], depth + 1) | ||
obj[key].visible = true; | ||
|
||
addDepthToTree(obj[key], (key == 'tree') ? depth + 1 : depth) | ||
} | ||
} | ||
return obj | ||
} | ||
|
||
angular.module('ion-tree-list', []) | ||
.directive('ionTreeList', function () { | ||
return { | ||
restrict: 'EA', | ||
scope: { | ||
items: '=' | ||
}, | ||
templateUrl: 'lib/ion-tree-list/ion-tree-list.tmpl.html', | ||
controller: function($scope){ | ||
$scope.items = addDepthToTree($scope.items, 0); | ||
console.log($scope.items) | ||
.directive('ionTreeList', function () { | ||
return { | ||
restrict: 'E', | ||
transclude: true, | ||
scope: { | ||
items: '=' | ||
}, | ||
templateUrl: 'lib/ion-tree-list/ion-tree-list.tmpl.html', | ||
controller: function($scope){ | ||
$scope.items = addDepthToTree($scope.items, 0); | ||
$scope.collapse = function(item) { | ||
item.visible = false; | ||
console.log(item); | ||
} | ||
} | ||
}); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,28 @@ | ||
<style> | ||
.level-0 { | ||
padding: 10px 10px; | ||
} | ||
.level-1 { | ||
padding: 10px 20px; | ||
padding-left: 45px; | ||
} | ||
.level-2 { | ||
padding: 10px 30px; | ||
padding-left: 65px; | ||
} | ||
.level-3 { | ||
padding: 10px 40px; | ||
padding-left: 85px; | ||
} | ||
.level-4 { | ||
padding: 10px 50px; | ||
padding-left: 105px; | ||
} | ||
</style> | ||
|
||
<script type="text/ng-template" id="items_renderer"> | ||
<ion-item> | ||
<span class="level-{{item.depth}}"> | ||
<i class="ion-arrow-down-b" ng-if="item.tree"></i> | ||
<a class="item level-{{item.depth}}" ng-click="collapse(item)" ng-show="item.visible"> | ||
<span style="padding-right: 10px;"> | ||
<i class="icon ion-arrow-down-b" ng-if="item.tree"></i> | ||
<input type="checkbox" ng-if="!item.tree"/> | ||
{{item.name}} | ||
</span> | ||
</ion-item> | ||
({{item.depth}}) {{item.name}} | ||
</a> | ||
<ion-list ng-model="item.tree" ng-repeat="item in item.tree" ng-include="'items_renderer'"></ion-list> | ||
</script> | ||
|
||
<ion-list ng-model="items" show-reorder="true"> | ||
<div class="list" ng-model="items" show-reorder="true"> | ||
<span ng-repeat="item in items" ng-include="'items_renderer'"></span> | ||
</ion-list> | ||
</div> |