rspectacles 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,51 @@
1
+ /*global define: true */
2
+ define(['jquery'], function ($) {
3
+ 'use strict';
4
+
5
+ function createNodes(path, data, node) {
6
+ var nextNode
7
+ ;
8
+
9
+ node.children = node.children || [];
10
+
11
+ if (path.length === 0) {
12
+ nextNode = $.extend({
13
+ size: data.duration
14
+ , name: data.full_description
15
+ }, data);
16
+
17
+ node.children.push(nextNode);
18
+ return;
19
+ }
20
+
21
+ nextNode = node.children.filter(function (child) {
22
+ return child.name === path[0];
23
+ })[0];
24
+
25
+ if (!nextNode) {
26
+ nextNode = { name: path[0] };
27
+ node.children.push(nextNode);
28
+ }
29
+
30
+ path.shift();
31
+ createNodes(path, data, nextNode);
32
+ }
33
+
34
+ function PathTree(data) {
35
+ this.nodes = {};
36
+ data && this.add(data);
37
+ }
38
+
39
+ PathTree.prototype.add = function (data) {
40
+ var that = this;
41
+ !$.isArray(data) && (data = [data]);
42
+
43
+ data.forEach(function (node) {
44
+ var path = node.file_path.split('/');
45
+ path.shift();
46
+ createNodes(path, node, that.nodes);
47
+ });
48
+ };
49
+
50
+ return PathTree;
51
+ });