fix window reference for server-side use

This commit is contained in:
Josh de Leeuw 2016-04-14 15:35:27 -04:00
parent e011ced826
commit 94e884ca1e
2 changed files with 9 additions and 8 deletions

View File

@ -495,16 +495,16 @@ var jsPsych = (function() {
// get all the trials of a particular type
this.trialsOfType = function(type) {
if (timeline.length == 0) {
if (trial_data.type == type) {
return trial_data;
if (typeof timeline_parameters == 'undefined'){
if (trial_parameters.type == type) {
return trial_parameters;
} else {
return [];
}
} else {
var trials = [];
for (var i = 0; i < timeline.length; i++) {
var t = timeline[i].trialsOfType(type);
for (var i = 0; i < timeline_parameters.timeline.length; i++) {
var t = timeline_parameters.timeline[i].trialsOfType(type);
trials = trials.concat(t);
}
return trials;
@ -1508,12 +1508,12 @@ jsPsych.pluginAPI = (function() {
// audio //
// temporary patch for Safari
if (window.hasOwnProperty('webkitAudioContext') && !window.hasOwnProperty('AudioContext')) {
if (typeof window !== 'undefined' && window.hasOwnProperty('webkitAudioContext') && !window.hasOwnProperty('AudioContext')) {
window.AudioContext = webkitAudioContext;
}
// end patch
var context = (typeof window.AudioContext !== 'undefined') ? new AudioContext() : null;
var context = (typeof window !== 'undefined' && typeof window.AudioContext !== 'undefined') ? new AudioContext() : null;
var audio_buffers = [];
module.getAudioBuffer = function(audioID) {

View File

@ -22,7 +22,8 @@
timeline: [
{stimulus: 'sound/sound.mp3'},
{stimulus: 'sound/hammer.mp3'}
]
],
prompt: 'press any key to advance'
}
jsPsych.init({