|
@@ -1,11 +1,22 @@
|
1
|
1
|
var d3 = require("d3"),
|
2
|
2
|
$ = require("jquery"),
|
3
|
|
- themes = require("../settings/themes.json"),
|
4
|
3
|
preview = require("./preview.js"),
|
5
|
4
|
video = require("./video.js"),
|
6
|
5
|
audio = require("./audio.js");
|
7
|
6
|
|
8
|
|
-preloadImages();
|
|
7
|
+d3.json("/settings/themes.json", function(err, themes){
|
|
8
|
+
|
|
9
|
+ if (err) {
|
|
10
|
+ throw err;
|
|
11
|
+ }
|
|
12
|
+
|
|
13
|
+ for (var key in themes) {
|
|
14
|
+ themes[key] = $.extend({}, themes.default, themes[key]);
|
|
15
|
+ }
|
|
16
|
+
|
|
17
|
+ preloadImages(themes);
|
|
18
|
+
|
|
19
|
+});
|
9
|
20
|
|
10
|
21
|
function submitted() {
|
11
|
22
|
|
|
@@ -76,6 +87,8 @@ function poll(id) {
|
76
|
87
|
if (result && result.status && result.status === "ready" && result.url) {
|
77
|
88
|
video.update(result.url, preview.theme().name);
|
78
|
89
|
setClass("rendered");
|
|
90
|
+ } else if (result.status === "error") {
|
|
91
|
+ error(result.error);
|
79
|
92
|
} else {
|
80
|
93
|
d3.select("#loading-message").text(statusMessage(result));
|
81
|
94
|
poll(id);
|
|
@@ -97,6 +110,10 @@ function error(msg) {
|
97
|
110
|
msg = JSON.stringify(msg);
|
98
|
111
|
}
|
99
|
112
|
|
|
113
|
+ if (!msg) {
|
|
114
|
+ msg = "Unknown error";
|
|
115
|
+ }
|
|
116
|
+
|
100
|
117
|
d3.select("#loading-message").text("Loading...");
|
101
|
118
|
setClass("error", msg);
|
102
|
119
|
|
|
@@ -192,11 +209,10 @@ function updateCaption() {
|
192
|
209
|
}
|
193
|
210
|
|
194
|
211
|
function updateTheme() {
|
195
|
|
- var extended = $.extend({}, themes.default, d3.select(this.options[this.selectedIndex]).datum());
|
196
|
|
- preview.theme(extended);
|
|
212
|
+ preview.theme(d3.select(this.options[this.selectedIndex]).datum());
|
197
|
213
|
}
|
198
|
214
|
|
199
|
|
-function preloadImages() {
|
|
215
|
+function preloadImages(themes) {
|
200
|
216
|
|
201
|
217
|
// preload images
|
202
|
218
|
var imageQueue = d3.queue();
|
|
@@ -215,22 +231,22 @@ function preloadImages() {
|
215
|
231
|
|
216
|
232
|
imageQueue.awaitAll(initialize);
|
217
|
233
|
|
218
|
|
- function getImage(theme,cb) {
|
|
234
|
+ function getImage(theme, cb) {
|
219
|
235
|
|
220
|
236
|
if (!theme.backgroundImage) {
|
221
|
|
- return cb(null,theme);
|
|
237
|
+ return cb(null, theme);
|
222
|
238
|
}
|
223
|
239
|
|
224
|
240
|
theme.backgroundImageFile = new Image();
|
225
|
241
|
theme.backgroundImageFile.onload = function(){
|
226
|
|
- return cb(null,theme);
|
|
242
|
+ return cb(null, theme);
|
227
|
243
|
};
|
228
|
244
|
theme.backgroundImageFile.onerror = function(e){
|
229
|
245
|
console.warn(e);
|
230
|
|
- return cb(null,theme);
|
|
246
|
+ return cb(null, theme);
|
231
|
247
|
};
|
232
|
248
|
|
233
|
|
- theme.backgroundImageFile.src = "img/" + theme.backgroundImage;
|
|
249
|
+ theme.backgroundImageFile.src = "/settings/backgrounds/" + theme.backgroundImage;
|
234
|
250
|
|
235
|
251
|
}
|
236
|
252
|
|