Mercurial > hg > webaudioevaluationtool
comparison js/core.js @ 2624:a33b66ca3baa
#135: Added user-modifiable interfaces/interfaces.json. Users just need to update this file to add 3rd party interfaces
author | Nicholas Jillings <nicholas.jillings@mail.bcu.ac.uk> |
---|---|
date | Wed, 18 Jan 2017 14:54:12 +0000 |
parents | 74e5d7a978ee |
children | e3cf3c24149e |
comparison
equal
deleted
inserted
replaced
2623:d4707c4a8b98 | 2624:a33b66ca3baa |
---|---|
329 interfaceContext.lightbox.post("Error", errStr); | 329 interfaceContext.lightbox.post("Error", errStr); |
330 return; | 330 return; |
331 } | 331 } |
332 } | 332 } |
333 | 333 |
334 // Detect the interface to use and load the relevant javascripts. | 334 var getInterfaces = new XMLHttpRequest(); |
335 var interfaceJS = document.createElement('script'); | 335 getInterfaces.open("GET", "interfaces/interfaces.json"); |
336 interfaceJS.setAttribute("type", "text/javascript"); | 336 getInterfaces.onerror = function (e) { |
337 switch (specification.interface) { | 337 throw (e); |
338 case "APE": | 338 } |
339 interfaceJS.setAttribute("src", "interfaces/ape.js"); | 339 getInterfaces.onload = function () { |
340 | 340 if (getInterfaces.status !== 200) { |
341 // APE comes with a css file | 341 throw (new Error(getInterfaces.status)); |
342 var css = document.createElement('link'); | 342 } |
343 css.rel = 'stylesheet'; | 343 // Get the current interface |
344 css.type = 'text/css'; | 344 var name = specification.interface, |
345 css.href = 'interfaces/ape.css'; | 345 head = document.getElementsByTagName("head")[0], |
346 | 346 data = JSON.parse(getInterfaces.responseText), |
347 document.getElementsByTagName("head")[0].appendChild(css); | 347 interfaceObject = data.interfaces.find(function (e) { |
348 break; | 348 return e.name == name; |
349 | 349 }); |
350 case "MUSHRA": | 350 if (!interfaceObject) { |
351 interfaceJS.setAttribute("src", "interfaces/mushra.js"); | 351 throw ("Cannot load desired interface"); |
352 | 352 } |
353 // MUSHRA comes with a css file | 353 interfaceObject.scripts.forEach(function (v) { |
354 var css = document.createElement('link'); | 354 var script = document.createElement("script"); |
355 css.rel = 'stylesheet'; | 355 script.setAttribute("type", "text/javascript"); |
356 css.type = 'text/css'; | 356 script.setAttribute("src", v); |
357 css.href = 'interfaces/mushra.css'; | 357 head.appendChild(script); |
358 | 358 }); |
359 document.getElementsByTagName("head")[0].appendChild(css); | 359 interfaceObject.css.forEach(function (v) { |
360 break; | 360 var css = document.createElement("link"); |
361 | 361 css.setAttribute("rel", "stylesheet"); |
362 case "AB": | 362 css.setAttribute("type", "text/css"); |
363 interfaceJS.setAttribute("src", "interfaces/AB.js"); | 363 css.setAttribute("href", v); |
364 | 364 head.appendChild(css); |
365 // AB comes with a css file | 365 }); |
366 var css = document.createElement('link'); | 366 } |
367 css.rel = 'stylesheet'; | 367 getInterfaces.send(); |
368 css.type = 'text/css'; | |
369 css.href = 'interfaces/AB.css'; | |
370 | |
371 document.getElementsByTagName("head")[0].appendChild(css); | |
372 break; | |
373 | |
374 case "ABX": | |
375 interfaceJS.setAttribute("src", "interfaces/ABX.js"); | |
376 | |
377 // AB comes with a css file | |
378 var css = document.createElement('link'); | |
379 css.rel = 'stylesheet'; | |
380 css.type = 'text/css'; | |
381 css.href = 'interfaces/ABX.css'; | |
382 | |
383 document.getElementsByTagName("head")[0].appendChild(css); | |
384 break; | |
385 | |
386 case "Bipolar": | |
387 case "ACR": | |
388 case "DCR": | |
389 case "CCR": | |
390 case "ABC": | |
391 // Above enumerate to horizontal sliders | |
392 interfaceJS.setAttribute("src", "interfaces/horizontal-sliders.js"); | |
393 | |
394 // horizontal-sliders comes with a css file | |
395 var css = document.createElement('link'); | |
396 css.rel = 'stylesheet'; | |
397 css.type = 'text/css'; | |
398 css.href = 'interfaces/horizontal-sliders.css'; | |
399 | |
400 document.getElementsByTagName("head")[0].appendChild(css); | |
401 break; | |
402 case "discrete": | |
403 case "likert": | |
404 // Above enumerate to horizontal discrete radios | |
405 interfaceJS.setAttribute("src", "interfaces/discrete.js"); | |
406 | |
407 // horizontal-sliders comes with a css file | |
408 var css = document.createElement('link'); | |
409 css.rel = 'stylesheet'; | |
410 css.type = 'text/css'; | |
411 css.href = 'interfaces/discrete.css'; | |
412 | |
413 document.getElementsByTagName("head")[0].appendChild(css); | |
414 break; | |
415 case "timeline": | |
416 interfaceJS.setAttribute("src", "interfaces/timeline.js"); | |
417 var css = document.createElement('link'); | |
418 css.rel = 'stylesheet'; | |
419 css.type = 'text/css'; | |
420 css.href = 'interfaces/timeline.css'; | |
421 | |
422 document.getElementsByTagName("head")[0].appendChild(css); | |
423 break; | |
424 } | |
425 document.getElementsByTagName("head")[0].appendChild(interfaceJS); | |
426 | 368 |
427 if (gReturnURL != undefined) { | 369 if (gReturnURL != undefined) { |
428 console.log("returnURL Overide from " + specification.returnURL + " to " + gReturnURL); | 370 console.log("returnURL Overide from " + specification.returnURL + " to " + gReturnURL); |
429 specification.returnURL = gReturnURL; | 371 specification.returnURL = gReturnURL; |
430 } | 372 } |