@jspsych/plugin-survey-multi-choice 1.1.3 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,2 +1,2 @@
1
- var jsPsychSurveyMultiChoice=function(e){"use strict";function t(e,t){for(var r=0;r<t.length;r++){var i=t[r];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(e,(n=i.key,o=void 0,"symbol"==typeof(o=function(e,t){if("object"!=typeof e||null===e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var i=r.call(e,t||"default");if("object"!=typeof i)return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(n,"string"))?o:String(o)),i)}var n,o}function r(e){return function(e){if(Array.isArray(e))return n(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||i(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function i(e,t){if(e){if("string"==typeof e)return n(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?n(e,t):void 0}}function n(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,i=new Array(t);r<t;r++)i[r]=e[r];return i}var o={name:"survey-multi-choice",parameters:{questions:{type:e.ParameterType.COMPLEX,array:!0,pretty_name:"Questions",nested:{prompt:{type:e.ParameterType.HTML_STRING,pretty_name:"Prompt",default:void 0},options:{type:e.ParameterType.STRING,pretty_name:"Options",array:!0,default:void 0},required:{type:e.ParameterType.BOOL,pretty_name:"Required",default:!1},horizontal:{type:e.ParameterType.BOOL,pretty_name:"Horizontal",default:!1},name:{type:e.ParameterType.STRING,pretty_name:"Question Name",default:""}}},randomize_question_order:{type:e.ParameterType.BOOL,pretty_name:"Randomize Question Order",default:!1},preamble:{type:e.ParameterType.HTML_STRING,pretty_name:"Preamble",default:null},button_label:{type:e.ParameterType.STRING,pretty_name:"Button label",default:"Continue"},autocomplete:{type:e.ParameterType.BOOL,pretty_name:"Allow autocomplete",default:!1}}},a=function(){function e(t){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.jsPsych=t}var n,o,a;return n=e,(o=[{key:"trial",value:function(e,t){var r=this,i="jspsych-survey-multi-choice",n="";n+='<style id="jspsych-survey-multi-choice-css">',n+=".jspsych-survey-multi-choice-question { margin-top: 2em; margin-bottom: 2em; text-align: left; }.jspsych-survey-multi-choice-text span.required {color: darkred;}.jspsych-survey-multi-choice-horizontal .jspsych-survey-multi-choice-text { text-align: center;}.jspsych-survey-multi-choice-option { line-height: 2; }.jspsych-survey-multi-choice-horizontal .jspsych-survey-multi-choice-option { display: inline-block; margin-left: 1em; margin-right: 1em; vertical-align: top;}label.jspsych-survey-multi-choice-text input[type='radio'] {margin-right: 1em;}",n+="</style>",null!==t.preamble&&(n+='<div id="jspsych-survey-multi-choice-preamble" class="jspsych-survey-multi-choice-preamble">'+t.preamble+"</div>"),t.autocomplete?n+='<form id="jspsych-survey-multi-choice-form">':n+='<form id="jspsych-survey-multi-choice-form" autocomplete="off">';for(var o=[],a=0;a<t.questions.length;a++)o.push(a);for(t.randomize_question_order&&(o=this.jsPsych.randomization.shuffle(o)),a=0;a<t.questions.length;a++){var s=t.questions[o[a]],u=o[a],l=["jspsych-survey-multi-choice-question"];s.horizontal&&l.push("jspsych-survey-multi-choice-horizontal"),n+='<div id="jspsych-survey-multi-choice-'+u+'" class="'+l.join(" ")+'" data-name="'+s.name+'">',n+='<p class="jspsych-survey-multi-choice-text survey-multi-choice">'+s.prompt,s.required&&(n+="<span class='required'>*</span>"),n+="</p>";for(var c=0;c<s.options.length;c++){var y="jspsych-survey-multi-choice-option-"+u+"-"+c,p="jspsych-survey-multi-choice-response-"+u,m="jspsych-survey-multi-choice-response-"+u+"-"+c,h=s.required?"required":"";n+='<div id="'+y+'" class="jspsych-survey-multi-choice-option">',n+='<label class="jspsych-survey-multi-choice-text" for="'+m+'">',n+='<input type="radio" name="'+p+'" id="'+m+'" value="'+s.options[c]+'" '+h+"></input>",n+=s.options[c]+"</label>",n+="</div>"}n+="</div>"}n+='<input type="submit" id="'+i+'-next" class="'+i+' jspsych-btn"'+(t.button_label?' value="'+t.button_label+'"':"")+"></input>",n+="</form>",e.innerHTML=n,document.querySelector("form").addEventListener("submit",(function(i){i.preventDefault();for(var n=performance.now(),a=Math.round(n-f),s={},u=0;u<t.questions.length;u++){var l,c=e.querySelector("#jspsych-survey-multi-choice-"+u),y="Q"+u;l=null!==c.querySelector("input[type=radio]:checked")?c.querySelector("input[type=radio]:checked").value:"";var p={},m=y;""!==c.attributes["data-name"].value&&(m=c.attributes["data-name"].value),p[m]=l,Object.assign(s,p)}var h={rt:a,response:s,question_order:o};e.innerHTML="",r.jsPsych.finishTrial(h)}));var f=performance.now()}},{key:"simulate",value:function(e,t,r,i){"data-only"==t&&(i(),this.simulate_data_only(e,r)),"visual"==t&&this.simulate_visual(e,r,i)}},{key:"create_simulation_data",value:function(e,t){var n,o={},a=1e3,s=function(e,t){var r="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!r){if(Array.isArray(e)||(r=i(e))||t&&e&&"number"==typeof e.length){r&&(e=r);var n=0,o=function(){};return{s:o,n:function(){return n>=e.length?{done:!0}:{done:!1,value:e[n++]}},e:function(e){throw e},f:o}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var a,s=!0,u=!1;return{s:function(){r=r.call(e)},n:function(){var e=r.next();return s=e.done,e},e:function(e){u=!0,a=e},f:function(){try{s||null==r.return||r.return()}finally{if(u)throw a}}}}(e.questions);try{for(s.s();!(n=s.n()).done;){var u=n.value;o[u.name?u.name:"Q".concat(e.questions.indexOf(u))]=this.jsPsych.randomization.sampleWithoutReplacement(u.options,1)[0],a+=this.jsPsych.randomization.sampleExGaussian(1500,400,.005,!0)}}catch(e){s.e(e)}finally{s.f()}var l={response:o,rt:a,question_order:e.randomize_question_order?this.jsPsych.randomization.shuffle(r(Array(e.questions.length).keys())):r(Array(e.questions.length).keys())},c=this.jsPsych.pluginAPI.mergeSimulationData(l,t);return this.jsPsych.pluginAPI.ensureSimulationDataConsistency(e,c),c}},{key:"simulate_data_only",value:function(e,t){var r=this.create_simulation_data(e,t);this.jsPsych.finishTrial(r)}},{key:"simulate_visual",value:function(e,t,r){var i=this.create_simulation_data(e,t),n=this.jsPsych.getDisplayElement();this.trial(n,e),r();for(var o=Object.entries(i.response),a=0;a<o.length;a++)this.jsPsych.pluginAPI.clickTarget(n.querySelector("#jspsych-survey-multi-choice-response-".concat(a,"-").concat(e.questions[a].options.indexOf(o[a][1]))),(i.rt-1e3)/o.length*(a+1));this.jsPsych.pluginAPI.clickTarget(n.querySelector("#jspsych-survey-multi-choice-next"),i.rt)}}])&&t(n.prototype,o),a&&t(n,a),Object.defineProperty(n,"prototype",{writable:!1}),e}();return a.info=o,a}(jsPsychModule);
2
- //# sourceMappingURL=https://unpkg.com/@jspsych/plugin-survey-multi-choice@1.1.3/dist/index.browser.min.js.map
1
+ var jsPsychSurveyMultiChoice=function(i){"use strict";var j={name:"@jspsych/plugin-survey-multi-choice",version:"2.0.0",description:"a jspsych plugin for multiple choice survey questions",type:"module",main:"dist/index.cjs",exports:{import:"./dist/index.js",require:"./dist/index.cjs"},typings:"dist/index.d.ts",unpkg:"dist/index.browser.min.js",files:["src","dist"],source:"src/index.ts",scripts:{test:"jest","test:watch":"npm test -- --watch",tsc:"tsc",build:"rollup --config","build:watch":"npm run build -- --watch"},repository:{type:"git",url:"git+https://github.com/jspsych/jsPsych.git",directory:"packages/plugin-survey-multi-choice"},author:"Shane Martin",license:"MIT",bugs:{url:"https://github.com/jspsych/jsPsych/issues"},homepage:"https://www.jspsych.org/latest/plugins/survey-multi-choice",peerDependencies:{jspsych:">=7.1.0"},devDependencies:{"@jspsych/config":"^3.0.0","@jspsych/test-utils":"^1.2.0"}};const P={name:"survey-multi-choice",version:j.version,parameters:{questions:{type:i.ParameterType.COMPLEX,array:!0,nested:{prompt:{type:i.ParameterType.HTML_STRING,default:void 0},options:{type:i.ParameterType.STRING,array:!0,default:void 0},required:{type:i.ParameterType.BOOL,default:!1},horizontal:{type:i.ParameterType.BOOL,default:!1},name:{type:i.ParameterType.STRING,default:""}}},randomize_question_order:{type:i.ParameterType.BOOL,default:!1},preamble:{type:i.ParameterType.HTML_STRING,default:null},button_label:{type:i.ParameterType.STRING,default:"Continue"},autocomplete:{type:i.ParameterType.BOOL,default:!1}},data:{response:{type:i.ParameterType.COMPLEX,nested:{identifier:{type:i.ParameterType.STRING},response:{type:i.ParameterType.STRING|i.ParameterType.INT|i.ParameterType.FLOAT|i.ParameterType.BOOL|i.ParameterType.OBJECT}}},rt:{type:i.ParameterType.INT},question_order:{type:i.ParameterType.INT,array:!0}}};class m{constructor(t){this.jsPsych=t}trial(t,r){var o="jspsych-survey-multi-choice",e="";e+='<style id="jspsych-survey-multi-choice-css">',e+=".jspsych-survey-multi-choice-question { margin-top: 2em; margin-bottom: 2em; text-align: left; }.jspsych-survey-multi-choice-text span.required {color: darkred;}.jspsych-survey-multi-choice-horizontal .jspsych-survey-multi-choice-text { text-align: center;}.jspsych-survey-multi-choice-option { line-height: 2; }.jspsych-survey-multi-choice-horizontal .jspsych-survey-multi-choice-option { display: inline-block; margin-left: 1em; margin-right: 1em; vertical-align: top;}label.jspsych-survey-multi-choice-text input[type='radio'] {margin-right: 1em;}",e+="</style>",r.preamble!==null&&(e+='<div id="jspsych-survey-multi-choice-preamble" class="jspsych-survey-multi-choice-preamble">'+r.preamble+"</div>"),r.autocomplete?e+='<form id="jspsych-survey-multi-choice-form">':e+='<form id="jspsych-survey-multi-choice-form" autocomplete="off">';for(var n=[],a=0;a<r.questions.length;a++)n.push(a);r.randomize_question_order&&(n=this.jsPsych.randomization.shuffle(n));for(var a=0;a<r.questions.length;a++){var s=r.questions[n[a]],u=n[a],h=["jspsych-survey-multi-choice-question"];s.horizontal&&h.push("jspsych-survey-multi-choice-horizontal"),e+='<div id="jspsych-survey-multi-choice-'+u+'" class="'+h.join(" ")+'" data-name="'+s.name+'">',e+='<p class="jspsych-survey-multi-choice-text survey-multi-choice">'+s.prompt,s.required&&(e+="<span class='required'>*</span>"),e+="</p>";for(var c=0;c<s.options.length;c++){var T="jspsych-survey-multi-choice-option-"+u+"-"+c,q="jspsych-survey-multi-choice-response-"+u,d="jspsych-survey-multi-choice-response-"+u+"-"+c,b=s.required?"required":"";e+='<div id="'+T+'" class="jspsych-survey-multi-choice-option">',e+='<label class="jspsych-survey-multi-choice-text" for="'+d+'">',e+='<input type="radio" name="'+q+'" id="'+d+'" value="'+s.options[c]+'" '+b+"></input>",e+=s.options[c]+"</label>",e+="</div>"}e+="</div>"}e+='<input type="submit" id="'+o+'-next" class="'+o+' jspsych-btn"'+(r.button_label?' value="'+r.button_label+'"':"")+"></input>",e+="</form>",t.innerHTML=e,document.querySelector("form").addEventListener("submit",x=>{x.preventDefault();for(var O=performance.now(),S=Math.round(O-_),v={},l=0;l<r.questions.length;l++){var p=t.querySelector("#jspsych-survey-multi-choice-"+l),I="Q"+l,y;p.querySelector("input[type=radio]:checked")!==null?y=p.querySelector("input[type=radio]:checked").value:y="";var g={},f=I;p.attributes["data-name"].value!==""&&(f=p.attributes["data-name"].value),g[f]=y,Object.assign(v,g)}var z={rt:S,response:v,question_order:n};this.jsPsych.finishTrial(z)});var _=performance.now()}simulate(t,r,o,e){r=="data-only"&&(e(),this.simulate_data_only(t,o)),r=="visual"&&this.simulate_visual(t,o,e)}create_simulation_data(t,r){const o={};let e=1e3;for(const s of t.questions){const u=s.name?s.name:`Q${t.questions.indexOf(s)}`;o[u]=this.jsPsych.randomization.sampleWithoutReplacement(s.options,1)[0],e+=this.jsPsych.randomization.sampleExGaussian(1500,400,.005,!0)}const n={response:o,rt:e,question_order:t.randomize_question_order?this.jsPsych.randomization.shuffle([...Array(t.questions.length).keys()]):[...Array(t.questions.length).keys()]},a=this.jsPsych.pluginAPI.mergeSimulationData(n,r);return this.jsPsych.pluginAPI.ensureSimulationDataConsistency(t,a),a}simulate_data_only(t,r){const o=this.create_simulation_data(t,r);this.jsPsych.finishTrial(o)}simulate_visual(t,r,o){const e=this.create_simulation_data(t,r),n=this.jsPsych.getDisplayElement();this.trial(n,t),o();const a=Object.entries(e.response);for(let s=0;s<a.length;s++)this.jsPsych.pluginAPI.clickTarget(n.querySelector(`#jspsych-survey-multi-choice-response-${s}-${t.questions[s].options.indexOf(a[s][1])}`),(e.rt-1e3)/a.length*(s+1));this.jsPsych.pluginAPI.clickTarget(n.querySelector("#jspsych-survey-multi-choice-next"),e.rt)}}return m.info=P,m}(jsPsychModule);
2
+ //# sourceMappingURL=https://unpkg.com/@jspsych/plugin-survey-multi-choice@2.0.0/dist/index.browser.min.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.browser.min.js","sources":["../src/index.ts"],"sourcesContent":["import { JsPsych, JsPsychPlugin, ParameterType, TrialType } from \"jspsych\";\n\nconst info = <const>{\n name: \"survey-multi-choice\",\n parameters: {\n /** Array containing one or more objects with parameters for the question(s) that should be shown on the page. */\n questions: {\n type: ParameterType.COMPLEX,\n array: true,\n pretty_name: \"Questions\",\n nested: {\n /** Question prompt. */\n prompt: {\n type: ParameterType.HTML_STRING,\n pretty_name: \"Prompt\",\n default: undefined,\n },\n /** Array of multiple choice options for this question. */\n options: {\n type: ParameterType.STRING,\n pretty_name: \"Options\",\n array: true,\n default: undefined,\n },\n /** Whether or not a response to this question must be given in order to continue. */\n required: {\n type: ParameterType.BOOL,\n pretty_name: \"Required\",\n default: false,\n },\n /** If true, then the question will be centered and options will be displayed horizontally. */\n horizontal: {\n type: ParameterType.BOOL,\n pretty_name: \"Horizontal\",\n default: false,\n },\n /** Name of the question in the trial data. If no name is given, the questions are named Q0, Q1, etc. */\n name: {\n type: ParameterType.STRING,\n pretty_name: \"Question Name\",\n default: \"\",\n },\n },\n },\n /** If true, the order of the questions in the 'questions' array will be randomized. */\n randomize_question_order: {\n type: ParameterType.BOOL,\n pretty_name: \"Randomize Question Order\",\n default: false,\n },\n /** HTML-formatted string to display at top of the page above all of the questions. */\n preamble: {\n type: ParameterType.HTML_STRING,\n pretty_name: \"Preamble\",\n default: null,\n },\n /** Label of the button to submit responses. */\n button_label: {\n type: ParameterType.STRING,\n pretty_name: \"Button label\",\n default: \"Continue\",\n },\n /** Setting this to true will enable browser auto-complete or auto-fill for the form. */\n autocomplete: {\n type: ParameterType.BOOL,\n pretty_name: \"Allow autocomplete\",\n default: false,\n },\n },\n};\n\ntype Info = typeof info;\n\n/**\n * **survey-multi-choice**\n *\n * jsPsych plugin for presenting multiple choice survey questions\n *\n * @author Shane Martin\n * @see {@link https://www.jspsych.org/plugins/jspsych-survey-multi-choice/ survey-multi-choice plugin documentation on jspsych.org}\n */\nclass SurveyMultiChoicePlugin implements JsPsychPlugin<Info> {\n static info = info;\n\n constructor(private jsPsych: JsPsych) {}\n\n trial(display_element: HTMLElement, trial: TrialType<Info>) {\n var plugin_id_name = \"jspsych-survey-multi-choice\";\n\n var html = \"\";\n\n // inject CSS for trial\n html += '<style id=\"jspsych-survey-multi-choice-css\">';\n html +=\n \".jspsych-survey-multi-choice-question { margin-top: 2em; margin-bottom: 2em; text-align: left; }\" +\n \".jspsych-survey-multi-choice-text span.required {color: darkred;}\" +\n \".jspsych-survey-multi-choice-horizontal .jspsych-survey-multi-choice-text { text-align: center;}\" +\n \".jspsych-survey-multi-choice-option { line-height: 2; }\" +\n \".jspsych-survey-multi-choice-horizontal .jspsych-survey-multi-choice-option { display: inline-block; margin-left: 1em; margin-right: 1em; vertical-align: top;}\" +\n \"label.jspsych-survey-multi-choice-text input[type='radio'] {margin-right: 1em;}\";\n html += \"</style>\";\n\n // show preamble text\n if (trial.preamble !== null) {\n html +=\n '<div id=\"jspsych-survey-multi-choice-preamble\" class=\"jspsych-survey-multi-choice-preamble\">' +\n trial.preamble +\n \"</div>\";\n }\n\n // form element\n if (trial.autocomplete) {\n html += '<form id=\"jspsych-survey-multi-choice-form\">';\n } else {\n html += '<form id=\"jspsych-survey-multi-choice-form\" autocomplete=\"off\">';\n }\n // generate question order. this is randomized here as opposed to randomizing the order of trial.questions\n // so that the data are always associated with the same question regardless of order\n var question_order = [];\n for (var i = 0; i < trial.questions.length; i++) {\n question_order.push(i);\n }\n if (trial.randomize_question_order) {\n question_order = this.jsPsych.randomization.shuffle(question_order);\n }\n\n // add multiple-choice questions\n for (var i = 0; i < trial.questions.length; i++) {\n // get question based on question_order\n var question = trial.questions[question_order[i]];\n var question_id = question_order[i];\n\n // create question container\n var question_classes = [\"jspsych-survey-multi-choice-question\"];\n if (question.horizontal) {\n question_classes.push(\"jspsych-survey-multi-choice-horizontal\");\n }\n\n html +=\n '<div id=\"jspsych-survey-multi-choice-' +\n question_id +\n '\" class=\"' +\n question_classes.join(\" \") +\n '\" data-name=\"' +\n question.name +\n '\">';\n\n // add question text\n html += '<p class=\"jspsych-survey-multi-choice-text survey-multi-choice\">' + question.prompt;\n if (question.required) {\n html += \"<span class='required'>*</span>\";\n }\n html += \"</p>\";\n\n // create option radio buttons\n for (var j = 0; j < question.options.length; j++) {\n // add label and question text\n var option_id_name = \"jspsych-survey-multi-choice-option-\" + question_id + \"-\" + j;\n var input_name = \"jspsych-survey-multi-choice-response-\" + question_id;\n var input_id = \"jspsych-survey-multi-choice-response-\" + question_id + \"-\" + j;\n\n var required_attr = question.required ? \"required\" : \"\";\n\n // add radio button container\n html += '<div id=\"' + option_id_name + '\" class=\"jspsych-survey-multi-choice-option\">';\n html += '<label class=\"jspsych-survey-multi-choice-text\" for=\"' + input_id + '\">';\n html +=\n '<input type=\"radio\" name=\"' +\n input_name +\n '\" id=\"' +\n input_id +\n '\" value=\"' +\n question.options[j] +\n '\" ' +\n required_attr +\n \"></input>\";\n html += question.options[j] + \"</label>\";\n html += \"</div>\";\n }\n\n html += \"</div>\";\n }\n\n // add submit button\n html +=\n '<input type=\"submit\" id=\"' +\n plugin_id_name +\n '-next\" class=\"' +\n plugin_id_name +\n ' jspsych-btn\"' +\n (trial.button_label ? ' value=\"' + trial.button_label + '\"' : \"\") +\n \"></input>\";\n html += \"</form>\";\n\n // render\n display_element.innerHTML = html;\n\n document.querySelector(\"form\").addEventListener(\"submit\", (event) => {\n event.preventDefault();\n // measure response time\n var endTime = performance.now();\n var response_time = Math.round(endTime - startTime);\n\n // create object to hold responses\n var question_data = {};\n for (var i = 0; i < trial.questions.length; i++) {\n var match = display_element.querySelector(\"#jspsych-survey-multi-choice-\" + i);\n var id = \"Q\" + i;\n var val: String;\n if (match.querySelector(\"input[type=radio]:checked\") !== null) {\n val = match.querySelector<HTMLInputElement>(\"input[type=radio]:checked\").value;\n } else {\n val = \"\";\n }\n var obje = {};\n var name = id;\n if (match.attributes[\"data-name\"].value !== \"\") {\n name = match.attributes[\"data-name\"].value;\n }\n obje[name] = val;\n Object.assign(question_data, obje);\n }\n // save data\n var trial_data = {\n rt: response_time,\n response: question_data,\n question_order: question_order,\n };\n display_element.innerHTML = \"\";\n\n // next trial\n this.jsPsych.finishTrial(trial_data);\n });\n\n var startTime = performance.now();\n }\n\n simulate(\n trial: TrialType<Info>,\n simulation_mode,\n simulation_options: any,\n load_callback: () => void\n ) {\n if (simulation_mode == \"data-only\") {\n load_callback();\n this.simulate_data_only(trial, simulation_options);\n }\n if (simulation_mode == \"visual\") {\n this.simulate_visual(trial, simulation_options, load_callback);\n }\n }\n\n private create_simulation_data(trial: TrialType<Info>, simulation_options) {\n const question_data = {};\n let rt = 1000;\n\n for (const q of trial.questions) {\n const name = q.name ? q.name : `Q${trial.questions.indexOf(q)}`;\n question_data[name] = this.jsPsych.randomization.sampleWithoutReplacement(q.options, 1)[0];\n rt += this.jsPsych.randomization.sampleExGaussian(1500, 400, 1 / 200, true);\n }\n\n const default_data = {\n response: question_data,\n rt: rt,\n question_order: trial.randomize_question_order\n ? this.jsPsych.randomization.shuffle([...Array(trial.questions.length).keys()])\n : [...Array(trial.questions.length).keys()],\n };\n\n const data = this.jsPsych.pluginAPI.mergeSimulationData(default_data, simulation_options);\n\n this.jsPsych.pluginAPI.ensureSimulationDataConsistency(trial, data);\n\n return data;\n }\n\n private simulate_data_only(trial: TrialType<Info>, simulation_options) {\n const data = this.create_simulation_data(trial, simulation_options);\n\n this.jsPsych.finishTrial(data);\n }\n\n private simulate_visual(trial: TrialType<Info>, simulation_options, load_callback: () => void) {\n const data = this.create_simulation_data(trial, simulation_options);\n\n const display_element = this.jsPsych.getDisplayElement();\n\n this.trial(display_element, trial);\n load_callback();\n\n const answers = Object.entries(data.response);\n for (let i = 0; i < answers.length; i++) {\n this.jsPsych.pluginAPI.clickTarget(\n display_element.querySelector(\n `#jspsych-survey-multi-choice-response-${i}-${trial.questions[i].options.indexOf(\n answers[i][1]\n )}`\n ),\n ((data.rt - 1000) / answers.length) * (i + 1)\n );\n }\n\n this.jsPsych.pluginAPI.clickTarget(\n display_element.querySelector(\"#jspsych-survey-multi-choice-next\"),\n data.rt\n );\n }\n}\n\nexport default SurveyMultiChoicePlugin;\n"],"names":["info","name","parameters","questions","type","ParameterType","COMPLEX","array","pretty_name","nested","prompt","HTML_STRING","default","undefined","options","STRING","required","BOOL","horizontal","randomize_question_order","preamble","button_label","autocomplete","SurveyMultiChoicePlugin","jsPsych","_classCallCheck","this","key","value","display_element","trial","_this","plugin_id_name","html","question_order","i","length","push","randomization","shuffle","question","question_id","question_classes","join","j","option_id_name","input_name","input_id","required_attr","innerHTML","document","querySelector","addEventListener","event","preventDefault","endTime","performance","now","response_time","Math","round","startTime","question_data","val","match","id","obje","attributes","Object","assign","trial_data","rt","response","finishTrial","simulation_mode","simulation_options","load_callback","simulate_data_only","simulate_visual","_step","_iterator","_createForOfIteratorHelper","s","n","done","q","concat","indexOf","sampleWithoutReplacement","sampleExGaussian","err","e","f","default_data","_toConsumableArray","Array","keys","data","pluginAPI","mergeSimulationData","ensureSimulationDataConsistency","create_simulation_data","getDisplayElement","answers","entries","clickTarget"],"mappings":"wxCAEA,IAAMA,EAAc,CAClBC,KAAM,sBACNC,WAAY,CAEVC,UAAW,CACTC,KAAMC,EAAaA,cAACC,QACpBC,OAAO,EACPC,YAAa,YACbC,OAAQ,CAENC,OAAQ,CACNN,KAAMC,EAAaA,cAACM,YACpBH,YAAa,SACbI,aAASC,GAGXC,QAAS,CACPV,KAAMC,EAAaA,cAACU,OACpBP,YAAa,UACbD,OAAO,EACPK,aAASC,GAGXG,SAAU,CACRZ,KAAMC,EAAaA,cAACY,KACpBT,YAAa,WACbI,SAAS,GAGXM,WAAY,CACVd,KAAMC,EAAaA,cAACY,KACpBT,YAAa,aACbI,SAAS,GAGXX,KAAM,CACJG,KAAMC,EAAaA,cAACU,OACpBP,YAAa,gBACbI,QAAS,MAKfO,yBAA0B,CACxBf,KAAMC,EAAaA,cAACY,KACpBT,YAAa,2BACbI,SAAS,GAGXQ,SAAU,CACRhB,KAAMC,EAAaA,cAACM,YACpBH,YAAa,WACbI,QAAS,MAGXS,aAAc,CACZjB,KAAMC,EAAaA,cAACU,OACpBP,YAAa,eACbI,QAAS,YAGXU,aAAc,CACZlB,KAAMC,EAAaA,cAACY,KACpBT,YAAa,qBACbI,SAAS,KAeTW,EAAuB,WAG3B,SAAAA,EAAoBC,gGAAgBC,MAAAF,GAAhBG,KAAOF,QAAPA,CAAmB,WA+NtC,SA/NuCD,KAAA,CAAA,CAAAI,IAAA,QAAAC,MAExC,SAAMC,EAA8BC,GAAsB,IAAAC,EAAAL,KACpDM,EAAiB,8BAEjBC,EAAO,GAGXA,GAAQ,+CACRA,GACE,8iBAMFA,GAAQ,WAGe,OAAnBH,EAAMV,WACRa,GACE,+FACAH,EAAMV,SACN,UAIAU,EAAMR,aACRW,GAAQ,+CAERA,GA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AAY,GAAA,CAED,IAAMC,EAAe,CACnBrB,SAAUV,EACVS,GAAIA,EACJrC,eAAgBJ,EAAMX,yBAClBO,KAAKF,QAAQc,cAAcC,QAAOuD,EAAKC,MAAMjE,EAAM3B,UAAUiC,QAAQ4D,SAAQF,EACzEC,MAAMjE,EAAM3B,UAAUiC,QAAQ4D,SAGlCC,EAAOvE,KAAKF,QAAQ0E,UAAUC,oBAAoBN,EAAclB,GAItE,OAFAjD,KAAKF,QAAQ0E,UAAUE,gCAAgCtE,EAAOmE,GAEvDA,CACT,GAAC,CAAAtE,IAAA,qBAAAC,MAEO,SAAmBE,EAAwB6C,GACjD,IAAMsB,EAAOvE,KAAK2E,uBAAuBvE,EAAO6C,GAEhDjD,KAAKF,QAAQiD,YAAYwB,EAC3B,GAAC,CAAAtE,IAAA,kBAAAC,MAEO,SAAgBE,EAAwB6C,EAAoBC,GAClE,IAAMqB,EAAOvE,KAAK2E,uBAAuBvE,EAAO6C,GAE1C9C,EAAkBH,KAAKF,QAAQ8E,oBAErC5E,KAAKI,MAAMD,EAAiBC,GAC5B8C,IAGA,IADA,IAAM2B,EAAUnC,OAAOoC,QAAQP,EAAKzB,UAC3BrC,EAAI,EAAGA,EAAIoE,EAAQnE,OAAQD,IAClCT,KAAKF,QAAQ0E,UAAUO,YACrB5E,EAAgBsB,cAAamC,yCAAAA,OACcnD,EAAC,KAAAmD,OAAIxD,EAAM3B,UAAUgC,GAAGrB,QAAQyE,QACvEgB,EAAQpE,GAAG,OAGb8D,EAAK1B,GAAK,KAAQgC,EAAQnE,QAAWD,EAAI,IAI/CT,KAAKF,QAAQ0E,UAAUO,YACrB5E,EAAgBsB,cAAc,qCAC9B8C,EAAK1B,GAET,oFAAChD,CAAA,CAlO0B,UACpBA,EAAIvB,KAAGA"}
1
+ {"version":3,"file":"index.browser.min.js","sources":["../src/index.ts"],"sourcesContent":["import { JsPsych, JsPsychPlugin, ParameterType, TrialType } from \"jspsych\";\n\nimport { version } from \"../package.json\";\n\nconst info = <const>{\n name: \"survey-multi-choice\",\n version: version,\n parameters: {\n /**\n * An array of objects, each object represents a question that appears on the screen. Each object contains a prompt,\n * options, required, and horizontal parameter that will be applied to the question. See examples below for further\n * clarification.`prompt`: Type string, default value is *undefined*. The string is prompt/question that will be\n * associated with a group of options (radio buttons). All questions will get presented on the same page (trial).\n * `options`: Type array, defualt value is *undefined*. An array of strings. The array contains a set of options to\n * display for an individual question.`required`: Type boolean, default value is null. The boolean value indicates\n * if a question is required('true') or not ('false'), using the HTML5 `required` attribute. If this parameter is\n * undefined, the question will be optional. `horizontal`:Type boolean, default value is false. If true, then the\n * question is centered and the options are displayed horizontally. `name`: Name of the question. Used for storing\n * data. If left undefined then default names (`Q0`, `Q1`, `...`) will be used for the questions.\n */\n questions: {\n type: ParameterType.COMPLEX,\n array: true,\n nested: {\n /** Question prompt. */\n prompt: {\n type: ParameterType.HTML_STRING,\n default: undefined,\n },\n /** Array of multiple choice options for this question. */\n options: {\n type: ParameterType.STRING,\n array: true,\n default: undefined,\n },\n /** Whether or not a response to this question must be given in order to continue. */\n required: {\n type: ParameterType.BOOL,\n default: false,\n },\n /** If true, then the question will be centered and options will be displayed horizontally. */\n horizontal: {\n type: ParameterType.BOOL,\n default: false,\n },\n /** Name of the question in the trial data. If no name is given, the questions are named Q0, Q1, etc. */\n name: {\n type: ParameterType.STRING,\n default: \"\",\n },\n },\n },\n /**\n * If true, the display order of `questions` is randomly determined at the start of the trial. In the data object,\n * `Q0` will still refer to the first question in the array, regardless of where it was presented visually.\n */\n randomize_question_order: {\n type: ParameterType.BOOL,\n default: false,\n },\n /** HTML formatted string to display at the top of the page above all the questions. */\n preamble: {\n type: ParameterType.HTML_STRING,\n default: null,\n },\n /** Label of the button. */\n button_label: {\n type: ParameterType.STRING,\n default: \"Continue\",\n },\n /**\n * This determines whether or not all of the input elements on the page should allow autocomplete. Setting\n * this to true will enable autocomplete or auto-fill for the form.\n */\n autocomplete: {\n type: ParameterType.BOOL,\n default: false,\n },\n },\n data: {\n /** An object containing the response for each question. The object will have a separate key (variable) for each question, with the first question in the trial being recorded in `Q0`, the second in `Q1`, and so on. The responses are recorded as integers, representing the position selected on the likert scale for that question. If the `name` parameter is defined for the question, then the response object will use the value of `name` as the key for each question. This will be encoded as a JSON string when data is saved using the `.json()` or `.csv()` functions. */\n response: {\n type: ParameterType.COMPLEX,\n nested: {\n identifier: {\n type: ParameterType.STRING,\n },\n response: {\n type:\n ParameterType.STRING |\n ParameterType.INT |\n ParameterType.FLOAT |\n ParameterType.BOOL |\n ParameterType.OBJECT,\n },\n },\n },\n /** The response time in milliseconds for the participant to make a response. The time is measured from when the questions first appear on the screen until the participant's response(s) are submitted. */\n rt: {\n type: ParameterType.INT,\n },\n /** An array with the order of questions. For example `[2,0,1]` would indicate that the first question was `trial.questions[2]` (the third item in the `questions` parameter), the second question was `trial.questions[0]`, and the final question was `trial.questions[1]`. This will be encoded as a JSON string when data is saved using the `.json()` or `.csv()` functions. */\n question_order: {\n type: ParameterType.INT,\n array: true,\n },\n },\n};\n\ntype Info = typeof info;\n\n/**\n * **survey-multi-choice**\n *\n * The survey-multi-choice plugin displays a set of questions with multiple choice response fields. The participant selects a single answer.\n *\n * @author Shane Martin\n * @see {@link https://www.jspsych.org/latest/plugins/survey-multi-choice/ survey-multi-choice plugin documentation on jspsych.org}\n */\nclass SurveyMultiChoicePlugin implements JsPsychPlugin<Info> {\n static info = info;\n\n constructor(private jsPsych: JsPsych) {}\n\n trial(display_element: HTMLElement, trial: TrialType<Info>) {\n var plugin_id_name = \"jspsych-survey-multi-choice\";\n\n var html = \"\";\n\n // inject CSS for trial\n html += '<style id=\"jspsych-survey-multi-choice-css\">';\n html +=\n \".jspsych-survey-multi-choice-question { margin-top: 2em; margin-bottom: 2em; text-align: left; }\" +\n \".jspsych-survey-multi-choice-text span.required {color: darkred;}\" +\n \".jspsych-survey-multi-choice-horizontal .jspsych-survey-multi-choice-text { text-align: center;}\" +\n \".jspsych-survey-multi-choice-option { line-height: 2; }\" +\n \".jspsych-survey-multi-choice-horizontal .jspsych-survey-multi-choice-option { display: inline-block; margin-left: 1em; margin-right: 1em; vertical-align: top;}\" +\n \"label.jspsych-survey-multi-choice-text input[type='radio'] {margin-right: 1em;}\";\n html += \"</style>\";\n\n // show preamble text\n if (trial.preamble !== null) {\n html +=\n '<div id=\"jspsych-survey-multi-choice-preamble\" class=\"jspsych-survey-multi-choice-preamble\">' +\n trial.preamble +\n \"</div>\";\n }\n\n // form element\n if (trial.autocomplete) {\n html += '<form id=\"jspsych-survey-multi-choice-form\">';\n } else {\n html += '<form id=\"jspsych-survey-multi-choice-form\" autocomplete=\"off\">';\n }\n // generate question order. this is randomized here as opposed to randomizing the order of trial.questions\n // so that the data are always associated with the same question regardless of order\n var question_order = [];\n for (var i = 0; i < trial.questions.length; i++) {\n question_order.push(i);\n }\n if (trial.randomize_question_order) {\n question_order = this.jsPsych.randomization.shuffle(question_order);\n }\n\n // add multiple-choice questions\n for (var i = 0; i < trial.questions.length; i++) {\n // get question based on question_order\n var question = trial.questions[question_order[i]];\n var question_id = question_order[i];\n\n // create question container\n var question_classes = [\"jspsych-survey-multi-choice-question\"];\n if (question.horizontal) {\n question_classes.push(\"jspsych-survey-multi-choice-horizontal\");\n }\n\n html +=\n '<div id=\"jspsych-survey-multi-choice-' +\n question_id +\n '\" class=\"' +\n question_classes.join(\" \") +\n '\" data-name=\"' +\n question.name +\n '\">';\n\n // add question text\n html += '<p class=\"jspsych-survey-multi-choice-text survey-multi-choice\">' + question.prompt;\n if (question.required) {\n html += \"<span class='required'>*</span>\";\n }\n html += \"</p>\";\n\n // create option radio buttons\n for (var j = 0; j < question.options.length; j++) {\n // add label and question text\n var option_id_name = \"jspsych-survey-multi-choice-option-\" + question_id + \"-\" + j;\n var input_name = \"jspsych-survey-multi-choice-response-\" + question_id;\n var input_id = \"jspsych-survey-multi-choice-response-\" + question_id + \"-\" + j;\n\n var required_attr = question.required ? \"required\" : \"\";\n\n // add radio button container\n html += '<div id=\"' + option_id_name + '\" class=\"jspsych-survey-multi-choice-option\">';\n html += '<label class=\"jspsych-survey-multi-choice-text\" for=\"' + input_id + '\">';\n html +=\n '<input type=\"radio\" name=\"' +\n input_name +\n '\" id=\"' +\n input_id +\n '\" value=\"' +\n question.options[j] +\n '\" ' +\n required_attr +\n \"></input>\";\n html += question.options[j] + \"</label>\";\n html += \"</div>\";\n }\n\n html += \"</div>\";\n }\n\n // add submit button\n html +=\n '<input type=\"submit\" id=\"' +\n plugin_id_name +\n '-next\" class=\"' +\n plugin_id_name +\n ' jspsych-btn\"' +\n (trial.button_label ? ' value=\"' + trial.button_label + '\"' : \"\") +\n \"></input>\";\n html += \"</form>\";\n\n // render\n display_element.innerHTML = html;\n\n document.querySelector(\"form\").addEventListener(\"submit\", (event) => {\n event.preventDefault();\n // measure response time\n var endTime = performance.now();\n var response_time = Math.round(endTime - startTime);\n\n // create object to hold responses\n var question_data = {};\n for (var i = 0; i < trial.questions.length; i++) {\n var match = display_element.querySelector(\"#jspsych-survey-multi-choice-\" + i);\n var id = \"Q\" + i;\n var val: String;\n if (match.querySelector(\"input[type=radio]:checked\") !== null) {\n val = match.querySelector<HTMLInputElement>(\"input[type=radio]:checked\").value;\n } else {\n val = \"\";\n }\n var obje = {};\n var name = id;\n if (match.attributes[\"data-name\"].value !== \"\") {\n name = match.attributes[\"data-name\"].value;\n }\n obje[name] = val;\n Object.assign(question_data, obje);\n }\n // save data\n var trial_data = {\n rt: response_time,\n response: question_data,\n question_order: question_order,\n };\n\n // next trial\n this.jsPsych.finishTrial(trial_data);\n });\n\n var startTime = performance.now();\n }\n\n simulate(\n trial: TrialType<Info>,\n simulation_mode,\n simulation_options: any,\n load_callback: () => void\n ) {\n if (simulation_mode == \"data-only\") {\n load_callback();\n this.simulate_data_only(trial, simulation_options);\n }\n if (simulation_mode == \"visual\") {\n this.simulate_visual(trial, simulation_options, load_callback);\n }\n }\n\n private create_simulation_data(trial: TrialType<Info>, simulation_options) {\n const question_data = {};\n let rt = 1000;\n\n for (const q of trial.questions) {\n const name = q.name ? q.name : `Q${trial.questions.indexOf(q)}`;\n question_data[name] = this.jsPsych.randomization.sampleWithoutReplacement(q.options, 1)[0];\n rt += this.jsPsych.randomization.sampleExGaussian(1500, 400, 1 / 200, true);\n }\n\n const default_data = {\n response: question_data,\n rt: rt,\n question_order: trial.randomize_question_order\n ? this.jsPsych.randomization.shuffle([...Array(trial.questions.length).keys()])\n : [...Array(trial.questions.length).keys()],\n };\n\n const data = this.jsPsych.pluginAPI.mergeSimulationData(default_data, simulation_options);\n\n this.jsPsych.pluginAPI.ensureSimulationDataConsistency(trial, data);\n\n return data;\n }\n\n private simulate_data_only(trial: TrialType<Info>, simulation_options) {\n const data = this.create_simulation_data(trial, simulation_options);\n\n this.jsPsych.finishTrial(data);\n }\n\n private simulate_visual(trial: TrialType<Info>, simulation_options, load_callback: () => void) {\n const data = this.create_simulation_data(trial, simulation_options);\n\n const display_element = this.jsPsych.getDisplayElement();\n\n this.trial(display_element, trial);\n load_callback();\n\n const answers = Object.entries(data.response);\n for (let i = 0; i < answers.length; i++) {\n this.jsPsych.pluginAPI.clickTarget(\n display_element.querySelector(\n `#jspsych-survey-multi-choice-response-${i}-${trial.questions[i].options.indexOf(\n answers[i][1]\n )}`\n ),\n ((data.rt - 1000) / answers.length) * (i + 1)\n );\n }\n\n this.jsPsych.pluginAPI.clickTarget(\n display_element.querySelector(\"#jspsych-survey-multi-choice-next\"),\n data.rt\n );\n }\n}\n\nexport default SurveyMultiChoicePlugin;\n"],"names":["info","version","ParameterType","SurveyMultiChoicePlugin","jsPsych","display_element","trial","plugin_id_name","html","question_order","i","question","question_id","question_classes","j","option_id_name","input_name","input_id","required_attr","event","endTime","response_time","startTime","question_data","match","id","val","obje","name","trial_data","simulation_mode","simulation_options","load_callback","rt","q","default_data","data","answers"],"mappings":"q5BAIA,MAAMA,EAAc,CAClB,KAAM,sBACN,QAASC,UACT,WAAY,CAaV,UAAW,CACT,KAAMC,EAAc,cA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gCzB,EAAO8B,CAAI,EAE3DA,CACT,CAEQ,mBAAmB9B,EAAwByB,EAAoB,CACrE,MAAMK,EAAO,KAAK,uBAAuB9B,EAAOyB,CAAkB,EAElE,KAAK,QAAQ,YAAYK,CAAI,CAC/B,CAEQ,gBAAgB9B,EAAwByB,EAAoBC,EAA2B,CAC7F,MAAMI,EAAO,KAAK,uBAAuB9B,EAAOyB,CAAkB,EAE5D1B,EAAkB,KAAK,QAAQ,kBAErC,EAAA,KAAK,MAAMA,EAAiBC,CAAK,EACjC0B,EAEA,EAAA,MAAMK,EAAU,OAAO,QAAQD,EAAK,QAAQ,EAC5C,QAAS1B,EAAI,EAAGA,EAAI2B,EAAQ,OAAQ3B,IAClC,KAAK,QAAQ,UAAU,YACrBL,EAAgB,cACd,yCAAyCK,KAAKJ,EAAM,UAAUI,GAAG,QAAQ,QACvE2B,EAAQ3B,GAAG,EACb,GACF,GACE0B,EAAK,GAAK,KAAQC,EAAQ,QAAW3B,EAAI,EAC7C,EAGF,KAAK,QAAQ,UAAU,YACrBL,EAAgB,cAAc,mCAAmC,EACjE+B,EAAK,EACP,CACF,CACF,CAlOMjC,OAAAA,EACG,KAAOH"}
package/dist/index.cjs CHANGED
@@ -2,263 +2,255 @@
2
2
 
3
3
  var jspsych = require('jspsych');
4
4
 
5
+ var _package = {
6
+ name: "@jspsych/plugin-survey-multi-choice",
7
+ version: "2.0.0",
8
+ description: "a jspsych plugin for multiple choice survey questions",
9
+ type: "module",
10
+ main: "dist/index.cjs",
11
+ exports: {
12
+ import: "./dist/index.js",
13
+ require: "./dist/index.cjs"
14
+ },
15
+ typings: "dist/index.d.ts",
16
+ unpkg: "dist/index.browser.min.js",
17
+ files: [
18
+ "src",
19
+ "dist"
20
+ ],
21
+ source: "src/index.ts",
22
+ scripts: {
23
+ test: "jest",
24
+ "test:watch": "npm test -- --watch",
25
+ tsc: "tsc",
26
+ build: "rollup --config",
27
+ "build:watch": "npm run build -- --watch"
28
+ },
29
+ repository: {
30
+ type: "git",
31
+ url: "git+https://github.com/jspsych/jsPsych.git",
32
+ directory: "packages/plugin-survey-multi-choice"
33
+ },
34
+ author: "Shane Martin",
35
+ license: "MIT",
36
+ bugs: {
37
+ url: "https://github.com/jspsych/jsPsych/issues"
38
+ },
39
+ homepage: "https://www.jspsych.org/latest/plugins/survey-multi-choice",
40
+ peerDependencies: {
41
+ jspsych: ">=7.1.0"
42
+ },
43
+ devDependencies: {
44
+ "@jspsych/config": "^3.0.0",
45
+ "@jspsych/test-utils": "^1.2.0"
46
+ }
47
+ };
48
+
5
49
  const info = {
6
- name: "survey-multi-choice",
7
- parameters: {
8
- /** Array containing one or more objects with parameters for the question(s) that should be shown on the page. */
9
- questions: {
10
- type: jspsych.ParameterType.COMPLEX,
11
- array: true,
12
- pretty_name: "Questions",
13
- nested: {
14
- /** Question prompt. */
15
- prompt: {
16
- type: jspsych.ParameterType.HTML_STRING,
17
- pretty_name: "Prompt",
18
- default: undefined,
19
- },
20
- /** Array of multiple choice options for this question. */
21
- options: {
22
- type: jspsych.ParameterType.STRING,
23
- pretty_name: "Options",
24
- array: true,
25
- default: undefined,
26
- },
27
- /** Whether or not a response to this question must be given in order to continue. */
28
- required: {
29
- type: jspsych.ParameterType.BOOL,
30
- pretty_name: "Required",
31
- default: false,
32
- },
33
- /** If true, then the question will be centered and options will be displayed horizontally. */
34
- horizontal: {
35
- type: jspsych.ParameterType.BOOL,
36
- pretty_name: "Horizontal",
37
- default: false,
38
- },
39
- /** Name of the question in the trial data. If no name is given, the questions are named Q0, Q1, etc. */
40
- name: {
41
- type: jspsych.ParameterType.STRING,
42
- pretty_name: "Question Name",
43
- default: "",
44
- },
45
- },
50
+ name: "survey-multi-choice",
51
+ version: _package.version,
52
+ parameters: {
53
+ questions: {
54
+ type: jspsych.ParameterType.COMPLEX,
55
+ array: true,
56
+ nested: {
57
+ prompt: {
58
+ type: jspsych.ParameterType.HTML_STRING,
59
+ default: void 0
46
60
  },
47
- /** If true, the order of the questions in the 'questions' array will be randomized. */
48
- randomize_question_order: {
49
- type: jspsych.ParameterType.BOOL,
50
- pretty_name: "Randomize Question Order",
51
- default: false,
61
+ options: {
62
+ type: jspsych.ParameterType.STRING,
63
+ array: true,
64
+ default: void 0
52
65
  },
53
- /** HTML-formatted string to display at top of the page above all of the questions. */
54
- preamble: {
55
- type: jspsych.ParameterType.HTML_STRING,
56
- pretty_name: "Preamble",
57
- default: null,
66
+ required: {
67
+ type: jspsych.ParameterType.BOOL,
68
+ default: false
58
69
  },
59
- /** Label of the button to submit responses. */
60
- button_label: {
61
- type: jspsych.ParameterType.STRING,
62
- pretty_name: "Button label",
63
- default: "Continue",
70
+ horizontal: {
71
+ type: jspsych.ParameterType.BOOL,
72
+ default: false
64
73
  },
65
- /** Setting this to true will enable browser auto-complete or auto-fill for the form. */
66
- autocomplete: {
67
- type: jspsych.ParameterType.BOOL,
68
- pretty_name: "Allow autocomplete",
69
- default: false,
74
+ name: {
75
+ type: jspsych.ParameterType.STRING,
76
+ default: ""
77
+ }
78
+ }
79
+ },
80
+ randomize_question_order: {
81
+ type: jspsych.ParameterType.BOOL,
82
+ default: false
83
+ },
84
+ preamble: {
85
+ type: jspsych.ParameterType.HTML_STRING,
86
+ default: null
87
+ },
88
+ button_label: {
89
+ type: jspsych.ParameterType.STRING,
90
+ default: "Continue"
91
+ },
92
+ autocomplete: {
93
+ type: jspsych.ParameterType.BOOL,
94
+ default: false
95
+ }
96
+ },
97
+ data: {
98
+ response: {
99
+ type: jspsych.ParameterType.COMPLEX,
100
+ nested: {
101
+ identifier: {
102
+ type: jspsych.ParameterType.STRING
70
103
  },
104
+ response: {
105
+ type: jspsych.ParameterType.STRING | jspsych.ParameterType.INT | jspsych.ParameterType.FLOAT | jspsych.ParameterType.BOOL | jspsych.ParameterType.OBJECT
106
+ }
107
+ }
71
108
  },
109
+ rt: {
110
+ type: jspsych.ParameterType.INT
111
+ },
112
+ question_order: {
113
+ type: jspsych.ParameterType.INT,
114
+ array: true
115
+ }
116
+ }
72
117
  };
73
- /**
74
- * **survey-multi-choice**
75
- *
76
- * jsPsych plugin for presenting multiple choice survey questions
77
- *
78
- * @author Shane Martin
79
- * @see {@link https://www.jspsych.org/plugins/jspsych-survey-multi-choice/ survey-multi-choice plugin documentation on jspsych.org}
80
- */
81
118
  class SurveyMultiChoicePlugin {
82
- constructor(jsPsych) {
83
- this.jsPsych = jsPsych;
119
+ constructor(jsPsych) {
120
+ this.jsPsych = jsPsych;
121
+ }
122
+ trial(display_element, trial) {
123
+ var plugin_id_name = "jspsych-survey-multi-choice";
124
+ var html = "";
125
+ html += '<style id="jspsych-survey-multi-choice-css">';
126
+ html += ".jspsych-survey-multi-choice-question { margin-top: 2em; margin-bottom: 2em; text-align: left; }.jspsych-survey-multi-choice-text span.required {color: darkred;}.jspsych-survey-multi-choice-horizontal .jspsych-survey-multi-choice-text { text-align: center;}.jspsych-survey-multi-choice-option { line-height: 2; }.jspsych-survey-multi-choice-horizontal .jspsych-survey-multi-choice-option { display: inline-block; margin-left: 1em; margin-right: 1em; vertical-align: top;}label.jspsych-survey-multi-choice-text input[type='radio'] {margin-right: 1em;}";
127
+ html += "</style>";
128
+ if (trial.preamble !== null) {
129
+ html += '<div id="jspsych-survey-multi-choice-preamble" class="jspsych-survey-multi-choice-preamble">' + trial.preamble + "</div>";
84
130
  }
85
- trial(display_element, trial) {
86
- var plugin_id_name = "jspsych-survey-multi-choice";
87
- var html = "";
88
- // inject CSS for trial
89
- html += '<style id="jspsych-survey-multi-choice-css">';
90
- html +=
91
- ".jspsych-survey-multi-choice-question { margin-top: 2em; margin-bottom: 2em; text-align: left; }" +
92
- ".jspsych-survey-multi-choice-text span.required {color: darkred;}" +
93
- ".jspsych-survey-multi-choice-horizontal .jspsych-survey-multi-choice-text { text-align: center;}" +
94
- ".jspsych-survey-multi-choice-option { line-height: 2; }" +
95
- ".jspsych-survey-multi-choice-horizontal .jspsych-survey-multi-choice-option { display: inline-block; margin-left: 1em; margin-right: 1em; vertical-align: top;}" +
96
- "label.jspsych-survey-multi-choice-text input[type='radio'] {margin-right: 1em;}";
97
- html += "</style>";
98
- // show preamble text
99
- if (trial.preamble !== null) {
100
- html +=
101
- '<div id="jspsych-survey-multi-choice-preamble" class="jspsych-survey-multi-choice-preamble">' +
102
- trial.preamble +
103
- "</div>";
104
- }
105
- // form element
106
- if (trial.autocomplete) {
107
- html += '<form id="jspsych-survey-multi-choice-form">';
108
- }
109
- else {
110
- html += '<form id="jspsych-survey-multi-choice-form" autocomplete="off">';
111
- }
112
- // generate question order. this is randomized here as opposed to randomizing the order of trial.questions
113
- // so that the data are always associated with the same question regardless of order
114
- var question_order = [];
115
- for (var i = 0; i < trial.questions.length; i++) {
116
- question_order.push(i);
117
- }
118
- if (trial.randomize_question_order) {
119
- question_order = this.jsPsych.randomization.shuffle(question_order);
120
- }
121
- // add multiple-choice questions
122
- for (var i = 0; i < trial.questions.length; i++) {
123
- // get question based on question_order
124
- var question = trial.questions[question_order[i]];
125
- var question_id = question_order[i];
126
- // create question container
127
- var question_classes = ["jspsych-survey-multi-choice-question"];
128
- if (question.horizontal) {
129
- question_classes.push("jspsych-survey-multi-choice-horizontal");
130
- }
131
- html +=
132
- '<div id="jspsych-survey-multi-choice-' +
133
- question_id +
134
- '" class="' +
135
- question_classes.join(" ") +
136
- '" data-name="' +
137
- question.name +
138
- '">';
139
- // add question text
140
- html += '<p class="jspsych-survey-multi-choice-text survey-multi-choice">' + question.prompt;
141
- if (question.required) {
142
- html += "<span class='required'>*</span>";
143
- }
144
- html += "</p>";
145
- // create option radio buttons
146
- for (var j = 0; j < question.options.length; j++) {
147
- // add label and question text
148
- var option_id_name = "jspsych-survey-multi-choice-option-" + question_id + "-" + j;
149
- var input_name = "jspsych-survey-multi-choice-response-" + question_id;
150
- var input_id = "jspsych-survey-multi-choice-response-" + question_id + "-" + j;
151
- var required_attr = question.required ? "required" : "";
152
- // add radio button container
153
- html += '<div id="' + option_id_name + '" class="jspsych-survey-multi-choice-option">';
154
- html += '<label class="jspsych-survey-multi-choice-text" for="' + input_id + '">';
155
- html +=
156
- '<input type="radio" name="' +
157
- input_name +
158
- '" id="' +
159
- input_id +
160
- '" value="' +
161
- question.options[j] +
162
- '" ' +
163
- required_attr +
164
- "></input>";
165
- html += question.options[j] + "</label>";
166
- html += "</div>";
167
- }
168
- html += "</div>";
169
- }
170
- // add submit button
171
- html +=
172
- '<input type="submit" id="' +
173
- plugin_id_name +
174
- '-next" class="' +
175
- plugin_id_name +
176
- ' jspsych-btn"' +
177
- (trial.button_label ? ' value="' + trial.button_label + '"' : "") +
178
- "></input>";
179
- html += "</form>";
180
- // render
181
- display_element.innerHTML = html;
182
- document.querySelector("form").addEventListener("submit", (event) => {
183
- event.preventDefault();
184
- // measure response time
185
- var endTime = performance.now();
186
- var response_time = Math.round(endTime - startTime);
187
- // create object to hold responses
188
- var question_data = {};
189
- for (var i = 0; i < trial.questions.length; i++) {
190
- var match = display_element.querySelector("#jspsych-survey-multi-choice-" + i);
191
- var id = "Q" + i;
192
- var val;
193
- if (match.querySelector("input[type=radio]:checked") !== null) {
194
- val = match.querySelector("input[type=radio]:checked").value;
195
- }
196
- else {
197
- val = "";
198
- }
199
- var obje = {};
200
- var name = id;
201
- if (match.attributes["data-name"].value !== "") {
202
- name = match.attributes["data-name"].value;
203
- }
204
- obje[name] = val;
205
- Object.assign(question_data, obje);
206
- }
207
- // save data
208
- var trial_data = {
209
- rt: response_time,
210
- response: question_data,
211
- question_order: question_order,
212
- };
213
- display_element.innerHTML = "";
214
- // next trial
215
- this.jsPsych.finishTrial(trial_data);
216
- });
217
- var startTime = performance.now();
131
+ if (trial.autocomplete) {
132
+ html += '<form id="jspsych-survey-multi-choice-form">';
133
+ } else {
134
+ html += '<form id="jspsych-survey-multi-choice-form" autocomplete="off">';
218
135
  }
219
- simulate(trial, simulation_mode, simulation_options, load_callback) {
220
- if (simulation_mode == "data-only") {
221
- load_callback();
222
- this.simulate_data_only(trial, simulation_options);
136
+ var question_order = [];
137
+ for (var i = 0; i < trial.questions.length; i++) {
138
+ question_order.push(i);
139
+ }
140
+ if (trial.randomize_question_order) {
141
+ question_order = this.jsPsych.randomization.shuffle(question_order);
142
+ }
143
+ for (var i = 0; i < trial.questions.length; i++) {
144
+ var question = trial.questions[question_order[i]];
145
+ var question_id = question_order[i];
146
+ var question_classes = ["jspsych-survey-multi-choice-question"];
147
+ if (question.horizontal) {
148
+ question_classes.push("jspsych-survey-multi-choice-horizontal");
149
+ }
150
+ html += '<div id="jspsych-survey-multi-choice-' + question_id + '" class="' + question_classes.join(" ") + '" data-name="' + question.name + '">';
151
+ html += '<p class="jspsych-survey-multi-choice-text survey-multi-choice">' + question.prompt;
152
+ if (question.required) {
153
+ html += "<span class='required'>*</span>";
154
+ }
155
+ html += "</p>";
156
+ for (var j = 0; j < question.options.length; j++) {
157
+ var option_id_name = "jspsych-survey-multi-choice-option-" + question_id + "-" + j;
158
+ var input_name = "jspsych-survey-multi-choice-response-" + question_id;
159
+ var input_id = "jspsych-survey-multi-choice-response-" + question_id + "-" + j;
160
+ var required_attr = question.required ? "required" : "";
161
+ html += '<div id="' + option_id_name + '" class="jspsych-survey-multi-choice-option">';
162
+ html += '<label class="jspsych-survey-multi-choice-text" for="' + input_id + '">';
163
+ html += '<input type="radio" name="' + input_name + '" id="' + input_id + '" value="' + question.options[j] + '" ' + required_attr + "></input>";
164
+ html += question.options[j] + "</label>";
165
+ html += "</div>";
166
+ }
167
+ html += "</div>";
168
+ }
169
+ html += '<input type="submit" id="' + plugin_id_name + '-next" class="' + plugin_id_name + ' jspsych-btn"' + (trial.button_label ? ' value="' + trial.button_label + '"' : "") + "></input>";
170
+ html += "</form>";
171
+ display_element.innerHTML = html;
172
+ document.querySelector("form").addEventListener("submit", (event) => {
173
+ event.preventDefault();
174
+ var endTime = performance.now();
175
+ var response_time = Math.round(endTime - startTime);
176
+ var question_data = {};
177
+ for (var i2 = 0; i2 < trial.questions.length; i2++) {
178
+ var match = display_element.querySelector("#jspsych-survey-multi-choice-" + i2);
179
+ var id = "Q" + i2;
180
+ var val;
181
+ if (match.querySelector("input[type=radio]:checked") !== null) {
182
+ val = match.querySelector("input[type=radio]:checked").value;
183
+ } else {
184
+ val = "";
223
185
  }
224
- if (simulation_mode == "visual") {
225
- this.simulate_visual(trial, simulation_options, load_callback);
186
+ var obje = {};
187
+ var name = id;
188
+ if (match.attributes["data-name"].value !== "") {
189
+ name = match.attributes["data-name"].value;
226
190
  }
191
+ obje[name] = val;
192
+ Object.assign(question_data, obje);
193
+ }
194
+ var trial_data = {
195
+ rt: response_time,
196
+ response: question_data,
197
+ question_order
198
+ };
199
+ this.jsPsych.finishTrial(trial_data);
200
+ });
201
+ var startTime = performance.now();
202
+ }
203
+ simulate(trial, simulation_mode, simulation_options, load_callback) {
204
+ if (simulation_mode == "data-only") {
205
+ load_callback();
206
+ this.simulate_data_only(trial, simulation_options);
227
207
  }
228
- create_simulation_data(trial, simulation_options) {
229
- const question_data = {};
230
- let rt = 1000;
231
- for (const q of trial.questions) {
232
- const name = q.name ? q.name : `Q${trial.questions.indexOf(q)}`;
233
- question_data[name] = this.jsPsych.randomization.sampleWithoutReplacement(q.options, 1)[0];
234
- rt += this.jsPsych.randomization.sampleExGaussian(1500, 400, 1 / 200, true);
235
- }
236
- const default_data = {
237
- response: question_data,
238
- rt: rt,
239
- question_order: trial.randomize_question_order
240
- ? this.jsPsych.randomization.shuffle([...Array(trial.questions.length).keys()])
241
- : [...Array(trial.questions.length).keys()],
242
- };
243
- const data = this.jsPsych.pluginAPI.mergeSimulationData(default_data, simulation_options);
244
- this.jsPsych.pluginAPI.ensureSimulationDataConsistency(trial, data);
245
- return data;
208
+ if (simulation_mode == "visual") {
209
+ this.simulate_visual(trial, simulation_options, load_callback);
246
210
  }
247
- simulate_data_only(trial, simulation_options) {
248
- const data = this.create_simulation_data(trial, simulation_options);
249
- this.jsPsych.finishTrial(data);
211
+ }
212
+ create_simulation_data(trial, simulation_options) {
213
+ const question_data = {};
214
+ let rt = 1e3;
215
+ for (const q of trial.questions) {
216
+ const name = q.name ? q.name : `Q${trial.questions.indexOf(q)}`;
217
+ question_data[name] = this.jsPsych.randomization.sampleWithoutReplacement(q.options, 1)[0];
218
+ rt += this.jsPsych.randomization.sampleExGaussian(1500, 400, 1 / 200, true);
250
219
  }
251
- simulate_visual(trial, simulation_options, load_callback) {
252
- const data = this.create_simulation_data(trial, simulation_options);
253
- const display_element = this.jsPsych.getDisplayElement();
254
- this.trial(display_element, trial);
255
- load_callback();
256
- const answers = Object.entries(data.response);
257
- for (let i = 0; i < answers.length; i++) {
258
- this.jsPsych.pluginAPI.clickTarget(display_element.querySelector(`#jspsych-survey-multi-choice-response-${i}-${trial.questions[i].options.indexOf(answers[i][1])}`), ((data.rt - 1000) / answers.length) * (i + 1));
259
- }
260
- this.jsPsych.pluginAPI.clickTarget(display_element.querySelector("#jspsych-survey-multi-choice-next"), data.rt);
220
+ const default_data = {
221
+ response: question_data,
222
+ rt,
223
+ question_order: trial.randomize_question_order ? this.jsPsych.randomization.shuffle([...Array(trial.questions.length).keys()]) : [...Array(trial.questions.length).keys()]
224
+ };
225
+ const data = this.jsPsych.pluginAPI.mergeSimulationData(default_data, simulation_options);
226
+ this.jsPsych.pluginAPI.ensureSimulationDataConsistency(trial, data);
227
+ return data;
228
+ }
229
+ simulate_data_only(trial, simulation_options) {
230
+ const data = this.create_simulation_data(trial, simulation_options);
231
+ this.jsPsych.finishTrial(data);
232
+ }
233
+ simulate_visual(trial, simulation_options, load_callback) {
234
+ const data = this.create_simulation_data(trial, simulation_options);
235
+ const display_element = this.jsPsych.getDisplayElement();
236
+ this.trial(display_element, trial);
237
+ load_callback();
238
+ const answers = Object.entries(data.response);
239
+ for (let i = 0; i < answers.length; i++) {
240
+ this.jsPsych.pluginAPI.clickTarget(
241
+ display_element.querySelector(
242
+ `#jspsych-survey-multi-choice-response-${i}-${trial.questions[i].options.indexOf(
243
+ answers[i][1]
244
+ )}`
245
+ ),
246
+ (data.rt - 1e3) / answers.length * (i + 1)
247
+ );
261
248
  }
249
+ this.jsPsych.pluginAPI.clickTarget(
250
+ display_element.querySelector("#jspsych-survey-multi-choice-next"),
251
+ data.rt
252
+ );
253
+ }
262
254
  }
263
255
  SurveyMultiChoicePlugin.info = info;
264
256