Noah před 7 roky
rodič
revize
86046d8218
2 změnil soubory, kde provedl 34 přidání a 11 odebrání
  1. 20 9
      client/index.js
  2. 14 2
      server/index.js

+ 20 - 9
client/index.js Zobrazit soubor

1
 var d3 = require("d3"),
1
 var d3 = require("d3"),
2
     $ = require("jquery"),
2
     $ = require("jquery"),
3
-    themes = require("../settings/themes.json"),
4
     preview = require("./preview.js"),
3
     preview = require("./preview.js"),
5
     video = require("./video.js"),
4
     video = require("./video.js"),
6
     audio = require("./audio.js");
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
 function submitted() {
21
 function submitted() {
11
 
22
 
192
 }
203
 }
193
 
204
 
194
 function updateTheme() {
205
 function updateTheme() {
195
-  var extended = $.extend({}, themes.default, d3.select(this.options[this.selectedIndex]).datum());
206
+  var extended = d3.select(this.options[this.selectedIndex]).datum();
196
   preview.theme(extended);
207
   preview.theme(extended);
197
 }
208
 }
198
 
209
 
199
-function preloadImages() {
210
+function preloadImages(themes) {
200
 
211
 
201
   // preload images
212
   // preload images
202
   var imageQueue = d3.queue();
213
   var imageQueue = d3.queue();
215
 
226
 
216
   imageQueue.awaitAll(initialize);
227
   imageQueue.awaitAll(initialize);
217
 
228
 
218
-  function getImage(theme,cb) {
229
+  function getImage(theme, cb) {
219
 
230
 
220
     if (!theme.backgroundImage) {
231
     if (!theme.backgroundImage) {
221
-      return cb(null,theme);
232
+      return cb(null, theme);
222
     }
233
     }
223
 
234
 
224
     theme.backgroundImageFile = new Image();
235
     theme.backgroundImageFile = new Image();
225
     theme.backgroundImageFile.onload = function(){
236
     theme.backgroundImageFile.onload = function(){
226
-      return cb(null,theme);
237
+      return cb(null, theme);
227
     };
238
     };
228
     theme.backgroundImageFile.onerror = function(e){
239
     theme.backgroundImageFile.onerror = function(e){
229
       console.warn(e);
240
       console.warn(e);
230
-      return cb(null,theme);
241
+      return cb(null, theme);
231
     };
242
     };
232
 
243
 
233
-    theme.backgroundImageFile.src = "img/" + theme.backgroundImage;
244
+    theme.backgroundImageFile.src = "/settings/backgrounds/" + theme.backgroundImage;
234
 
245
 
235
   }
246
   }
236
 
247
 

+ 14 - 2
server/index.js Zobrazit soubor

62
 // Check the status of a current video
62
 // Check the status of a current video
63
 app.get("/status/:id/", status);
63
 app.get("/status/:id/", status);
64
 
64
 
65
-// Serve background images and everything else statically
66
-app.use("/img/", express.static(path.join(__dirname, "..", "settings", "backgrounds")));
65
+
66
+// Serve background images and themes JSON statically
67
+app.use("/settings/", function(req, res, next) {
68
+
69
+  // Keep server settings off limits
70
+  if (req.url.match(/\.js$/i)) {
71
+    return res.status(404).send("Cannot GET " + path.join("/settings", req.url));
72
+  }
73
+
74
+  next();
75
+
76
+}, express.static(path.join(__dirname, "..", "settings")));
77
+
78
+// Serve editor files statically
67
 app.use(express.static(path.join(__dirname, "..", "editor")));
79
 app.use(express.static(path.join(__dirname, "..", "editor")));
68
 
80
 
69
 app.use(errorHandlers);
81
 app.use(errorHandlers);