// Generated by CoffeeScript 1.10.0 (function() { var breadcrumb, bttf_cover, cd, cd__, cut_path, cwd, documents, goofy, index, movies, open_folders, photos, pictures, redraw, root, up; goofy = { id: 0, name: 'goofy.png' }; bttf_cover = { id: 1, name: 'Back to the Future (Cover).jpg' }; photos = { id: 10, name: 'Photos', subfolders: [], files: [ { id: 11, name: 'me.jpg' } ] }; pictures = { id: 2, name: 'Pictures', subfolders: [photos], files: [ goofy, { id: 8, name: 'mickey.png' }, { id: 9, name: 'donald.png' }, bttf_cover ] }; movies = { id: 3, name: 'Movies', subfolders: [], files: [ { id: 6, name: 'Back to the Future.mkv' }, bttf_cover ] }; documents = { id: 4, name: 'Documents', subfolders: [photos], files: [goofy] }; root = { id: 5, subfolders: [pictures, movies, documents], files: [ { id: 7, name: 'vmlinuz' } ] }; index = function(node) { if (node.index != null) { return; } node.index = {}; node.subfolders.forEach(function(sf) { return node.index[sf.name] = sf; }); node.files.forEach(function(f) { return node.index[f.name] = f; }); return node.subfolders.forEach(function(sf) { return index(sf); }); }; index(root); open_folders = [root]; cd = function(sf_name) { open_folders.push(open_folders[open_folders.length - 1].index[sf_name]); return redraw(); }; cd__ = function() { if (open_folders.length > 1) { open_folders.pop(); return redraw(); } }; cut_path = function(folder) { if (open_folders.length === 1 || open_folders[open_folders.length - 1].id === folder.id) { redraw(); return; } open_folders.pop(); return cut_path(folder); }; cwd = d3.select('#cwd'); up = d3.select('#up_btn'); breadcrumb = d3.select('#breadcrumb'); up.on('click', function() { return cd__(); }); redraw = function() { var cwd_data, files, path_items, subfolders; cwd_data = open_folders[open_folders.length - 1]; subfolders = cwd.selectAll('.subfolder').data(cwd_data.subfolders, function(d) { return d.id; }); subfolders.enter().append('div').attr({ "class": 'subfolder node' }).html(function(d) { return ' ' + d.name; }).on('click', function(d) { return cd(d.name); }); subfolders.exit().remove(); files = cwd.selectAll('.file').data(cwd_data.files, function(d) { return d.id; }); files.enter().append('div').attr({ "class": 'file node' }).html(function(d) { return ' ' + d.name; }); files.exit().remove(); path_items = breadcrumb.selectAll('.path_item').data(open_folders, function(d) { return d.id; }); path_items.enter().append('div').attr({ "class": 'path_item' }).html(function(d) { return '' + (d.name != null ? d.name : 'Home' + ''); }).on('click', function(d) { return cut_path(d); }); return path_items.exit().remove(); }; redraw(); }).call(this);