<html>
<head>
<meta name="description" content="CanJS 3.4 - File Navigator - Beginner - START">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
β
</head>
<body>
<!--
<span>root</span>
<ul>
<li class='file'>π <span>cats.png</span></li>
<li class='file'>π <span>dogs.jpg</span></li>
<li class='folder'>π <span>empty folder</span></li>
<li class='folder hasChildren'>π <span>folder with files</span></li>
<li class='folder hasChildren'>
π <span>folder loading files </span>
<div class="loading">Loading</div>
</li>
<li class='folder hasChildren'>
π <span>opened folder</span>
<ul>
<li class='file'>π <span>file1.png</span></li>
<li class='file'>π <span>file2.jpg</span></li>
</ul>
</li>
</ul>-->
β
<script type="text/stache" id="entities-template">
{{<entityChildren}}
<ul>
{{#each this.children}}
<li class="{{this.type}} {{#if this.hasChildren}}hasChildren{{/if}}">
{{#eq type 'file'}}
π <span>{{name}}</span>
{{else}}
π <span on:click="toggleOpen()">{{name}}</span>
{{/eq}}
{{#if isOpen}}
{{>entityChildren}}
{{/if}}
</li>
{{/each}}
</ul>
{{/entityChildren}}
β
<span>{{name}}</span>
{{>entityChildren}}
</script>
β
<script src="//unpkg.com/can/dist/global/can.all.js"></script>
β
<script>
β
var entityId = 1;
β
var makeEntities = function(parentId, depth){
if(depth > 5) {
return [];
}
β
var entitiesCount = can.fixture.rand(6);
β
var entities = [];
β
for(var i = 0 ; i< entitiesCount; i++) {
β
// The id for this entity
var id = ""+(entityId++),
// If the entity is a folder or file
isFolder = Math.random() > 0.3,
// The children for this folder.
children = isFolder ? makeEntities(id, depth+1) : [];
β
var entity = {
id: id,
name: (isFolder ? "Folder" : "File")+" "+id,
parentId: parentId,
type: (isFolder ? "folder" : "file"),
hasChildren: children.length ? true : false
};
entities.push(entity);
if(isFolder) {
entity.children = children;
}
β
}
return entities;
};
β
var rootEntityData = {
id: "0",
name: "ROOT/",
hasChildren: true,
type: "folder",
children: makeEntities("0", 0)
};
</script>
</body>
</html>
β
body {
padding: 10px;
}
β
@import url('https://fonts.googleapis.com/css?family=Roboto+Mono:400,700');
β
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
β
body {
font-family: "Roboto Mono", "Lucida Console", Monaco, monospace;
font-size: 14px;
color: #000;
}
β
ul {
list-style: none;
}
β
li {
padding-left: 20px;
position: relative;
line-height: 2em;
}
β
li:before{
position: absolute;
left: 5px;
top: -2px;
content: '';
display: block;
height: 1em;
border-bottom: 1px solid #bbb;
width: 10px;
}
β
li:after {
position: absolute;
left: 5px;
bottom: 0;
content: '';
display: block;
border-left: 1px solid #bbb;
height: 100%;
}
β
.loading {
color: black;
padding-left: 20px;
padding-top: 10px;
padding-bottom: 10px;
}
β
.loading:after {
content: "...";
}
β
.hasChildren > a-folder > span, .hasChildren > span {
transition: all .1s ease-in-out;
cursor: pointer;
border-bottom: 1px dotted #000;
}
β
.hasChildren > a-folder > span:hover, .hasChildren > span:hover {
opacity: .5;
}
var template = can.stache.from("entities-template");
β
var Entity = can.DefineMap.extend({
id: "string",
name: "string",
hasChildren: "boolean",
type: "string",
children: [{
type: function(rawData){
return new Entity(rawData)
}
}],
isOpen: {type: "boolean", value: false},
toggleOpen: function(){
this.isOpen = !this.isOpen;
}
});
β
var rootEntity = new Entity(rootEntityData);
β
var frag = template(rootEntity);
β
document.body.appendChild(frag);
β
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. |