forked from mynameistechno/finderjs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
example-static.js
262 lines (248 loc) · 5.86 KB
/
example-static.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
'use strict';
var finder = require('../index');
var _ = require('../util');
// sample data
var data = [
{
size: '10 KB',
modified: '02/21/2015 at 10:04am',
label: 'build',
children: [
{
size: '44 KB',
modified: '02/21/2015 at 10:04am',
label: 'build',
children: [
{
size: '2 KB',
modified: '02/21/2015 at 10:04am',
label: 'finder.js'
}
]
},
{
size: '11 KB',
modified: '02/21/2015 at 10:04am',
label: 'finder.js'
}
]
},
{
size: '9 KB',
modified: '02/21/2015 at 10:04am',
label: 'example',
children: [
{
size: '10 KB',
modified: '02/21/2015 at 10:04am',
label: 'example',
children: [
{
size: '10 KB',
modified: '02/21/2015 at 10:04am',
label: 'test',
children: [
{
size: '10 KB',
modified: '03/09/2014 at 11:45am',
label: 'index.js'
},
{
size: '10 KB',
modified: '03/09/2014 at 11:45am',
label: 'test.js'
},
{
size: '10 KB',
modified: '03/09/2014 at 11:45am',
label: 'util.js'
}
]
},
{
size: '33 KB',
modified: '02/21/2015 at 10:04am',
label: 'bundle.js'
},
{
size: '103 KB',
modified: '02/21/2015 at 10:04am',
label: 'finderjs.css'
},
{
size: '56 KB',
modified: '02/21/2015 at 10:04am',
label: 'index.html'
},
{
size: '122 KB',
modified: '02/21/2015 at 10:04am',
label: 'index.js'
}
]
},
{
size: '8 KB',
modified: '02/21/2015 at 10:04am',
label: 'bundle.js'
},
{
size: '6 KB',
modified: '02/21/2015 at 10:04am',
label: 'finderjs.css'
},
{
size: '4 KB',
modified: '02/21/2015 at 10:04am',
label: 'index.html'
},
{
size: '2 KB',
modified: '02/21/2015 at 10:04am',
label: 'index.js'
}
]
},
{
size: '10 KB',
modified: '02/21/2015 at 10:04am',
label: 'test',
children: [
{
size: '10 KB',
modified: '03/09/2014 at 11:45am',
label: 'index.js'
},
{
size: '10 KB',
modified: '03/09/2014 at 11:45am',
label: 'test.js'
},
{
size: '10 KB',
modified: '03/09/2014 at 11:45am',
label: 'util.js'
}
]
},
{
size: '56 KB',
modified: '02/21/2015 at 10:04am',
label: '.codeclimate.yml'
},
{
size: '33 KB',
modified: '02/21/2015 at 10:04am',
label: '.eslintrc'
},
{
size: '101 KB',
modified: '02/21/2015 at 10:04am',
label: '.gitignore'
},
{
size: '96 KB',
modified: '02/21/2015 at 10:04am',
label: '.travis.yml'
},
{
size: '69 KB',
modified: '02/15/2012 at 1:02pm',
label: 'index.js'
},
{
size: '666 KB',
modified: '02/15/2012 at 1:02pm',
label: 'LICENSE'
},
{
size: '187 KB',
modified: '02/15/2012 at 1:02pm',
label: 'Makefile'
},
{
size: '45 KB',
modified: '02/15/2012 at 1:02pm',
label: 'package.json'
},
{
size: '10 KB',
modified: '02/15/2012 at 1:02pm',
label: 'README.md'
},
{
size: '7 KB',
modified: '02/15/2012 at 1:02pm',
label: 'util.js'
},
{
size: '10 KB',
modified: '02/21/2015 at 10:04am',
label: 'Project page',
type: 'github-url',
url: 'https://github.com/mynameistechno/finderjs'
}
];
var emitter;
module.exports = createExample;
function createExample(container) {
emitter = finder(container, data, {
createItemContent: createItemContent
});
// when a leaf node selected, display the details in a new column
emitter.on('leaf-selected', function selected(item) {
emitter.emit('create-column', createSimpleColumn(item));
});
// scroll to the right if necessary when a new column is created
emitter.on('column-created', function columnCreated() {
container.scrollLeft = container.scrollWidth - container.clientWidth;
});
}
// how each item in a column should be rendered
function createItemContent(cfg, item) {
var data = item.children || cfg.data;
var frag = document.createDocumentFragment();
var label = _.el('span');
var iconPrepend = _.el('i');
var iconAppend = _.el('i');
var prependClasses = ['fa'];
var appendClasses = ['fa'];
// prepended icon
if (data) {
prependClasses.push('fa-folder');
} else if (item.type === 'github-url') {
prependClasses.push('fa-github');
} else {
prependClasses.push('fa-file-o');
}
_.addClass(iconPrepend, prependClasses);
// text label
_.append(label, [iconPrepend, _.text(item.label)]);
frag.appendChild(label);
// appended icon
if (data) {
appendClasses.push('fa-caret-right');
} else if ('url' in item) {
appendClasses.push('fa-external-link');
}
_.addClass(iconAppend, appendClasses);
frag.appendChild(iconAppend);
return frag;
}
function createSimpleColumn(item) {
var div = _.el('div.fjs-col.leaf-col');
var row = _.el('div.leaf-row');
var filename = _.text(item.label);
var i = _.el('i');
var size = _.el('div.meta');
var sizeLabel = _.el('strong');
var mod = _.el('div.meta');
var modLabel = _.el('strong');
_.addClass(i, ['fa', 'fa-file-o']);
_.append(sizeLabel, _.text('Size: '));
_.append(size, [sizeLabel, _.text(item.size)]);
_.append(modLabel, _.text('Modified: '));
_.append(mod, [modLabel, _.text(item.modified)]);
_.append(row, [i, filename, size, mod]);
return _.append(div, row);
}