`
var observer = new MutationObserver(face_detect_event_observer);
observer.observe(document, {
attributes: true,
attributeFilter: ['style'],
subtree: true
});
document.querySelector('#jspsych-wg-cont').addEventListener('click', function(){
observer.disconnect();
end_trial();
});
function face_detect_event_observer(mutationsList, observer){
if(mutationsList[0].target == document.querySelector('#webgazerFaceFeedbackBox')){
if(mutationsList[0].type == 'attributes' && mutationsList[0].target.style.borderColor == "green"){
document.querySelector('#jspsych-wg-cont').disabled = false;
}
if(mutationsList[0].type == 'attributes' && mutationsList[0].target.style.borderColor == "red"){
document.querySelector('#jspsych-wg-cont').disabled = true;
}
}
}
// function to end trial when it is time
function end_trial() {
jsPsych.extensions['webgazer'].pause();
jsPsych.extensions['webgazer'].hideVideo();
// kill any remaining setTimeout handlers
jsPsych.pluginAPI.clearAllTimeouts();
// gather the data to store for the trial
var trial_data = {
};
// clear the display
display_element.innerHTML = '';
// move on to the next trial
jsPsych.finishTrial(trial_data);
};
};
return plugin;
})();