<html>
<head>
<link href="http://maxcdn.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
<link rel="stylesheet" href="//rawgit.com/iVantage/angular-ivh-treeview/master/dist/ivh-treeview.css">
<link rel="stylesheet" href="//rawgit.com/iVantage/angular-ivh-treeview/master/dist/ivh-treeview-theme-basic.css">
<meta charset="utf-8">
<title>Angular JS</title>
</head>
<body ng-app="jsbin">
<div class="container">
<div ng-controller="DemoCtrl as demo">
<h1>Hello World!</h1>
<p class="alert alert-info">
The <strong>ivh.treeview</strong> module provides a directive for rendering tree-like collections. It supports checkboxes and deep filtering. By default we use basic (+)/(-) for twisties but that's all configurable.
</p>
<input type="text" ng-model="bagSearch" class="form-control" placeholder="Find stuff in your bag..." style="">
<div ivh-treeview="demo.bag"
ivh-treeview-filter="bagSearch"
ivh-treeview-expand-to-depth="1"></div>
<div class="row">
<div class="col-md-6">
<h4>All Selected Things</h4>
<ul>
<li ng-repeat="item in demo.allSelected">
{{item}}
</li>
</ul>
<p ng-hide="demo.allSelected.length"><em>Nothing selected yet</em></p>
</div>
<div class="col-md-6">
<h4>Top Selected Things</h4>
<ul>
<li ng-repeat="item in demo.topSelected">
{{item}}
</li>
</ul>
<p ng-hide="demo.topSelected.length"><em>Nothing selected yet</em></p>
</div>
</div>
</div>
</div>
<script src="//cdnjs.cloudflare.com/ajax/libs/angular.js/1.2.16/angular.js"></script>
<script src="//rawgit.com/iVantage/angular-ivh-treeview/master/dist/ivh-treeview.min.js"></script>
</body>
</html>
/*jshint laxcomma:true */
console.clear();
var app = angular.module('jsbin', ['ivh.treeview']);
app.controller('DemoCtrl', function($scope, ivhTreeviewBfs) {
var self = this;
var things = [
'Mustachio',
'Cane',
'Monacle',
'Umbrella',
'Headphones',
'Top hat',
'Fedora',
'Flat cap',
'Phone',
'Wallet',
'Squirrel',
'Wizard hat',
'Great sword',
'Playing cards',
'Post-it notes',
'Stickers',
'Tea',
'Patch'
];
var getThing = function() {
return things[Math.floor(Math.random()*100)%things.length];
};
var makeThings = function(numChildren, depth) {
if(depth < 1) { return; }
var c, ret = {
label: getThing(),
children: []
};
for(var ix = numChildren; ix--;) {
c = makeThings(numChildren, depth-1);
if(c) {
ret.children.push(c);
}
}
if(!ret.children.length) {
delete ret.children;
}
return ret;
};
var makeNode = function(label) {
return {
label: label,
children: []
};
};
var makeTree = function(list, arity) {
list = list.slice(0);
var node = makeNode(list.shift())
, nodes = [node]
, tree = [node];
while(list.length && nodes.length) {
node = nodes.shift();
while(list.length && node.children.length < arity) {
node.children.push(makeNode(list.shift()));
}
Array.prototype.push.apply(nodes, node.children);
}
return tree;
};
var bag = self.bag = makeTree(things, 4);
self.gatherAllSelected = function() {
self.allSelected.length = 0;
ivhTreeviewBfs(bag, function(node, parents) {
if(node.selected) {
self.allSelected.push(node.label);
}
});
};
self.gatherTopmostSelected = function() {
self.topSelected.length = 0;
ivhTreeviewBfs(bag, function(node, parents) {
if(node.selected) {
self.topSelected.push(node.label);
return false; // Stops traversal of this branch
}
});
};
self.allSelected = [];
self.topSelected = [];
$scope.$watch(function() {
return bag;
}, function() {
self.gatherAllSelected();
self.gatherTopmostSelected();
}, true);
});
Output
You can jump to the latest bin by adding /latest
to your URL
Keyboard Shortcuts
Shortcut | Action |
---|---|
ctrl + [num] | Toggle nth panel |
ctrl + 0 | Close focused panel |
ctrl + enter | Re-render output. If console visible: run JS in console |
Ctrl + l | Clear the console |
ctrl + / | Toggle comment on selected lines |
ctrl + ] | Indents selected lines |
ctrl + [ | Unindents selected lines |
tab | Code complete & Emmet expand |
ctrl + shift + L | Beautify code in active panel |
ctrl + s | Save & lock current Bin from further changes |
ctrl + shift + s | Open the share options |
ctrl + y | Archive Bin |
Complete list of JS Bin shortcuts |
JS Bin URLs
URL | Action |
---|---|
/ | Show the full rendered output. This content will update in real time as it's updated from the /edit url. |
/edit | Edit the current bin |
/watch | Follow a Code Casting session |
/embed | Create an embeddable version of the bin |
/latest | Load the very latest bin (/latest goes in place of the revision) |
/[username]/last | View the last edited bin for this user |
/[username]/last/edit | Edit the last edited bin for this user |
/[username]/last/watch | Follow the Code Casting session for the latest bin for this user |
/quiet | Remove analytics and edit button from rendered output |
.js | Load only the JavaScript for a bin |
.css | Load only the CSS for a bin |
Except for username prefixed urls, the url may start with http://jsbin.com/abc and the url fragments can be added to the url to view it differently. |