Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added way to give entries paths.

  • Loading branch information...
commit 28c01a9dc73e2a5ee2dc00937cc677ec816c7c1c 1 parent c248b1c
@mcantelon authored
Showing with 27 additions and 13 deletions.
  1. +10 −7 index.html
  2. +17 −6 lib/backbone-file-editor.js
View
17 index.html
@@ -26,14 +26,17 @@
<script>
$(document).ready(function() {
- var dir = new Directory({name: 'main'});
+ var dir = new Directory({
+ name: 'main',
+ parent: 'test'
+ });
- dir.addChildDir({name: 'stuff'})
- .addChildDir({name: 'goat'})
- .addChildDir({name: 'rob'});
+ dir.addDir({name: 'stuff'})
+ .addDir({name: 'goat'})
+ .addDir({name: 'rob'});
- dir.addChildDir({name: 'bing'});
- dir.addChild({name: 'file.png'});
+ dir.addDir({name: 'bing'});
+ dir.addFile({name: 'file.png'});
new FileExplorer({
el: $('#explorer'),
@@ -49,7 +52,7 @@
</script>
<script type="text/template" id='template-dir-entry'>
- <div><%= name %></div>
+ <div><span class="template_dir_entry_name"><%= name %></span></div>
</script>
</html>
View
23 lib/backbone-file-editor.js
@@ -6,16 +6,27 @@ var Directory = Backbone.Model.extend({
this.cssClass = 'directory';
},
- addChild: function(name) {
- var child = new File(name);
+ addChild: function(options, Type) {
+ var child = new Type(options)
+ , parent = this.get('parent');
+
+ if (parent != undefined) {
+ parent += '/' + this.get('name');
+ } else {
+ parent = this.get('name');
+ }
+ child.set({parent: parent});
+
this.children.push(child);
return child;
},
- addChildDir: function(name) {
- var child = new Directory(name);
- this.children.push(child);
- return child;
+ addFile: function(options) {
+ return this.addChild(options, File);
+ },
+
+ addDir: function(options) {
+ return this.addChild(options, Directory);
}
});
Please sign in to comment.
Something went wrong with that request. Please try again.