-
Notifications
You must be signed in to change notification settings - Fork 7
/
sidebar.js
214 lines (186 loc) · 4.82 KB
/
sidebar.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
var ajax = require('ajax');
//var modules = require('./dsp-modules');
var about = require('./about');
var emitter = require('emitter');
var utils = require('./utils');
var tree = require('treeview');
var createElement = utils.createElement;
var library = {};
/*
[
'simple-sine',
'on-the-verge',
'on-the-verge-tech-mix',
'polytropon',
'polytropon-astral-mix',
'unexpected-token',
'early-morning',
'morning',
'late-morning',
'icecream',
'got-some-303',
'need-more-303',
'subwah'
]
.forEach(function(name){
library['/projects/' + name.replace(/-/g, ' ')] = require('./library/projects/' + name)
.toString()
.split('\n')
.slice(1, -1)
.join('\n');
});
*/
var sidebar = module.exports = emitter({});
sidebar.create = createSidebar;
function createSidebar(context){
sidebar.el = createElement('sidebar');
sidebar.on('select', function(node){
var path = node.path();
var sublime = context.sublime;
if (!sublime) return;
if (context.hasEdited) {
if (!confirm('You\'ve made some edits!\n\nAre you sure you want to load a new project and lose everything?')) return;
}
context.isNewProject = true;
var session = sublime.editor.getSession();
ajax.get('.' + path, function(code){
session.setValue(code);
});
});
var nodes = [
// ['modules', true],
['projects', true]
];
var contents = {
'/projects': [
['afternoon walk'],
['dubstep dawn'],
['early morning'],
['go to sleep'],
['got some 303'],
['icecream'],
['late morning'],
['mind swift'],
['mind swift seutje mix'],
['morning'],
['need more 303'],
['on the verge'],
['on the verge tech mix'],
['polytropon'],
['polytropon astral mix'],
['rooftop unvisited'],
['simple sine'],
['subwah'],
['unexpected token'],
['yay'],
]
// '/modules': [
// ['effects', true],
// ['oscillators', true],
// ['sequencers', true],
// ['synths', true],
// ['various', true]
// ],
// //'/projects': Object.keys(library).map(function(name){ return [name.split('/').pop()]; }),
// '/modules/effects': [
// ['amp', true],
// ['chorus', true],
// ['delay', true],
// ['dynamics', true],
// ['eq', true],
// ['filter', true],
// ['flanger', true],
// ['modulation', true],
// ['phaser', true],
// ['reverb', true]
// ],
// '/modules/synths': [
// ['ambient', true],
// ['analog', true],
// ['bass', true],
// ['drums', true],
// ['flute', true],
// ['fm', true],
// ['fx', true],
// ['modular', true],
// ['organ', true],
// ['pads', true],
// ['percussion', true],
// ['piano', true],
// ['sample', true],
// ['strings', true]
// ]
};
function fetch(node, fn){
var path = node.path();
var parts = path.split('/');
var dir = parts[1];
var res = contents[path];
if (!res) {
switch (dir) {
case 'projects':
load(path, fn);
break;
default:
about.show()
// fund.show('milestone I');
// fund.modal.once('hiding', fn.bind(this, new Error('no results')));
break;
}
} else {
fn(null, contents[path]);
}
}
function load(path, fn){
ajax.getJSON(path, function(res){
res = res.map(function(name){
return [name];
});
fn(null, res);
});
}
setTimeout(function(){
tree(sidebar, nodes, fetch)[0].click(function(err, nodes){
var path = document.location.pathname;
if (!loadRawGit(document.location.search)) {
nodes.forEach(function(node){
if (~node.path().indexOf('simple sine')) node.click();
});
}
});
}, 0);
function loadRawGit(search){
var sublime = context.sublime;
if (!sublime) return false;
let path = search.slice(1).split('.com').pop()
context.isNewProject = true;
var session = sublime.editor.getSession();
path = 'https://gitcdn.xyz/cdn' + path;
if (!~path.indexOf('/raw/')) return false //path += '/raw/';
ajax({
url: path,
dataType: 'text/plain',
success: success
});
function success(code){
session.setValue(code);
}
return true
}
/*
sidebar.header = createElement('header');
sidebar.header.innerHTML = '<ul><li>modules<li>projects<li>samples<li>visuals</ul>';
sidebar.list = document.createElement('ul');
sidebar.list.className = 'browser';
var keys = Object.keys(modules);
keys.unshift('+ create');
keys.forEach(function(key){
var item;
item = document.createElement('li');
item.innerHTML = key;
sidebar.list.appendChild(item);
});
sidebar.el.appendChild(sidebar.header);
sidebar.el.appendChild(sidebar.list);
*/
}