Skip to content

Commit

Permalink
wip styling items
Browse files Browse the repository at this point in the history
  • Loading branch information
fer committed May 20, 2015
1 parent b7db186 commit 1a3717e
Show file tree
Hide file tree
Showing 6 changed files with 111 additions and 66 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Files
.DS_Store

# Directories
.idea
47 changes: 46 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,49 @@

Ionic directive for displaying and manipulating nested list ionic items.

<!-- Here is the DEMO page -->
<!-- Here is the DEMO page -->

## Installation

<!-- bower installation -->


```
<script src="lib/ion-tree-list/ion-tree-list.js"></script>
```

app.js:

```
angular.module('starter', [
'ionic',
'controllers',
'services',
'ion-tree-list'
])
```

controller:

```
$scope.tasks = [
{
name: 'first task 1',
tree: [
{
name: 'first task 1.1'
},
]
},
{
name: 'first task 2'
}
];
```


Template:

```
<ion-tree-list items="tasks"></ion-tree-list>
```
24 changes: 24 additions & 0 deletions bower.json
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"
]
}
41 changes: 25 additions & 16 deletions ion-tree-list.js
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);
}
}
});
}
});
26 changes: 11 additions & 15 deletions ion-tree-list.tmpl.html
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>
34 changes: 0 additions & 34 deletions test.js

This file was deleted.

0 comments on commit 1a3717e

Please sign in to comment.