diff --git a/jspsych.js b/jspsych.js
index e9164a6c..5edf4f3b 100755
--- a/jspsych.js
+++ b/jspsych.js
@@ -186,7 +186,6 @@ window.jsPsych = (function() {
};
core.getDisplayElement = function() {
- console.log("yo in getDisplayElement", DOM_target);
return DOM_target;
};
diff --git a/plugins/jspsych-html.js b/plugins/jspsych-html.js
index 5decafce..46b65623 100644
--- a/plugins/jspsych-html.js
+++ b/plugins/jspsych-html.js
@@ -80,7 +80,7 @@ jsPsych.plugins.html = (function() {
var key_listener = function(e) {
if (e.which == trial.cont_key) finish();
};
- display_element.attachEventListener('keydown', key_listener);
+ display_element.addEventListener('keydown', key_listener);
}
});
};
diff --git a/plugins/jspsych-survey-multi-choice.js b/plugins/jspsych-survey-multi-choice.js
index ef14f90e..dd3aafec 100644
--- a/plugins/jspsych-survey-multi-choice.js
+++ b/plugins/jspsych-survey-multi-choice.js
@@ -82,10 +82,8 @@ jsPsych.plugins['survey-multi-choice'] = (function() {
// form element
var trial_form_id = _join(plugin_id_name, "form");
- console.log("trial_form_id", trial_form_id)
display_element.innerHTML += '
';
var trial_form = display_element.querySelector("#" + trial_form_id);
- console.log("trial_form", trial_form)
// show preamble text
var preamble_id_name = _join(plugin_id_name, 'preamble');
trial_form.innerHTML += ''+trial.preamble+'
';
@@ -116,11 +114,12 @@ jsPsych.plugins['survey-multi-choice'] = (function() {
// add label and question text
var option_label = '';
display_element.querySelector(option_id_selector).innerHTML += option_label;
+ console.log("option label", option_label)
// create radio button
var input_id_name = _join(plugin_id_name, 'response', i);
display_element.querySelector(option_id_selector + " label").innerHTML =
- '' +
+ '' +
display_element.querySelector(option_id_selector + " label").innerHTML;
}
@@ -129,7 +128,7 @@ jsPsych.plugins['survey-multi-choice'] = (function() {
display_element.querySelector(question_selector + " p").innerHMTL += "*";
// add required property
- display_element.querySelector(question_selector + " input").required = true;
+ display_element.querySelector(question_selector + " input[type=radio]").required = true;
}
}
// add submit button
@@ -137,8 +136,6 @@ jsPsych.plugins['survey-multi-choice'] = (function() {
trial_form.addEventListener('submit', function(event) {
event.preventDefault();
- var matches = display_element.querySelectorAll("div." + plugin_id_name + "-question");
- console.log("are you getting called")
// measure response time
var endTime = (new Date()).getTime();
var response_time = endTime - startTime;
@@ -146,17 +143,11 @@ jsPsych.plugins['survey-multi-choice'] = (function() {
// create object to hold responses
var question_data = {};
var matches = display_element.querySelectorAll("div." + plugin_id_name + "-question");
- var inputs = document.getElementsByTagName('input');
- var radios = []
- for(var i = 0; i < inputs.length; i++){
- if(inputs[i].checked){
- radios.push(inputs[i].value)
- }
- }
- matches.forEach(function(currentEl ,index){
- var id = "Q" + index;
+ matches.forEach(function(match, index) {
+ var id = 'answer'
+ var val = match.querySelector("input[type=radio]:checked").value;
var obje = {};
- obje[id] = radios[index];
+ obje[id] = val;
Object.assign(question_data, obje);
})
// save data
diff --git a/plugins/jspsych-text.js b/plugins/jspsych-text.js
index a4393d38..edb0e823 100644
--- a/plugins/jspsych-text.js
+++ b/plugins/jspsych-text.js
@@ -74,7 +74,7 @@ jsPsych.plugins.text = (function() {
// check if key is 'mouse'
if (trial.choices == 'mouse') {
- display_element.attachEventListener(mouse_listener);
+ display_element.addEventListener(mouse_listener);
var start_time = (new Date()).getTime();
} else {
jsPsych.pluginAPI.getKeyboardResponse({
diff --git a/plugins/test.js b/plugins/test.js
new file mode 100644
index 00000000..194e4ef2
--- /dev/null
+++ b/plugins/test.js
@@ -0,0 +1,158 @@
+/**
+ * jspsych-test
+ * a jspsych plugin for multiple choice survey questions
+ *
+ * Shane Martin
+ *
+ * documentation: docs.jspsych.org
+ *
+ */
+
+
+jsPsych.plugins['test'] = (function() {
+ var plugin = {};
+
+ plugin.info = {
+ name: 'test',
+ description: '',
+ parameters: {
+ questions: {
+ type: [jsPsych.plugins.parameterType.STRING],
+ array: true,
+ default: undefined,
+ no_function: false,
+ description: ''
+ },
+ options: {
+ type: [jsPsych.plugins.parameterType.STRING],
+ array: true,
+ default: undefined,
+ no_function: false,
+ description: ''
+ },
+ required: {
+ type: [jsPsych.plugins.parameterType.BOOL],
+ array: true,
+ default: false,
+ no_function: false,
+ description: ''
+ },
+ horitzontal: {
+ type: [jsPsych.plugins.parameterType.BOOL],
+ default: false,
+ no_function: false,
+ description: ''
+ },
+ preamble: {
+ type: [jsPsych.plugins.parameterType.STRING],
+ default: '',
+ no_function: false,
+ description: ''
+ }
+ }
+ }
+ plugin.trial = function(display_element, trial) {
+ var plugin_id_name = "jspsych-test";
+ var plugin_id_selector = '#' + plugin_id_name;
+ var _join = function( /*args*/ ) {
+ var arr = Array.prototype.slice.call(arguments, _join.length);
+ return arr.join(separator = '-');
+ }
+
+ // trial defaults
+ trial.preamble = typeof trial.preamble == 'undefined' ? "" : trial.preamble;
+ trial.required = typeof trial.required == 'undefined' ? null : trial.required;
+ trial.horizontal = typeof trial.required == 'undefined' ? false : trial.horizontal;
+
+ // if any trial variables are functions
+ // this evaluates the function and replaces
+ // it with the output of the function
+ trial = jsPsych.pluginAPI.evaluateFunctionParameters(trial);
+
+ // inject CSS for trial
+ var node = display_element.innerHTML += '