@jspsych/plugin-survey-multi-choice 1.1.3 → 2.0.1
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.
- package/dist/index.browser.js +217 -243
- package/dist/index.browser.js.map +1 -1
- package/dist/index.browser.min.js +2 -2
- package/dist/index.browser.min.js.map +1 -1
- package/dist/index.cjs +216 -242
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +82 -34
- package/dist/index.js +216 -242
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
- package/src/index.spec.ts +1 -1
- package/src/index.ts +42 -18
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var jsPsychSurveyMultiChoice=function(
|
|
2
|
-
//# sourceMappingURL=https://unpkg.com/@jspsych/plugin-survey-multi-choice@
|
|
1
|
+
var jsPsychSurveyMultiChoice=function(a){"use strict";var P="2.0.1";const q={name:"survey-multi-choice",version:P,parameters:{questions:{type:a.ParameterType.COMPLEX,array:!0,nested:{prompt:{type:a.ParameterType.HTML_STRING,default:void 0},options:{type:a.ParameterType.STRING,array:!0,default:void 0},required:{type:a.ParameterType.BOOL,default:!1},horizontal:{type:a.ParameterType.BOOL,default:!1},name:{type:a.ParameterType.STRING,default:""}}},randomize_question_order:{type:a.ParameterType.BOOL,default:!1},preamble:{type:a.ParameterType.HTML_STRING,default:null},button_label:{type:a.ParameterType.STRING,default:"Continue"},autocomplete:{type:a.ParameterType.BOOL,default:!1}},data:{response:{type:a.ParameterType.OBJECT},rt:{type:a.ParameterType.INT},question_order:{type:a.ParameterType.INT,array:!0}}};class h{constructor(t){this.jsPsych=t}trial(t,i){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>",i.preamble!==null&&(e+='<div id="jspsych-survey-multi-choice-preamble" class="jspsych-survey-multi-choice-preamble">'+i.preamble+"</div>"),i.autocomplete?e+='<form id="jspsych-survey-multi-choice-form">':e+='<form id="jspsych-survey-multi-choice-form" autocomplete="off">';for(var u=[],r=0;r<i.questions.length;r++)u.push(r);i.randomize_question_order&&(u=this.jsPsych.randomization.shuffle(u));for(var r=0;r<i.questions.length;r++){var s=i.questions[u[r]],n=u[r],p=["jspsych-survey-multi-choice-question"];s.horizontal&&p.push("jspsych-survey-multi-choice-horizontal"),e+='<div id="jspsych-survey-multi-choice-'+n+'" class="'+p.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 l=0;l<s.options.length;l++){var g="jspsych-survey-multi-choice-option-"+n+"-"+l,T="jspsych-survey-multi-choice-response-"+n,d="jspsych-survey-multi-choice-response-"+n+"-"+l,_=s.required?"required":"";e+='<div id="'+g+'" class="jspsych-survey-multi-choice-option">',e+='<label class="jspsych-survey-multi-choice-text" for="'+d+'">',e+='<input type="radio" name="'+T+'" id="'+d+'" value="'+s.options[l]+'" '+_+"></input>",e+=s.options[l]+"</label>",e+="</div>"}e+="</div>"}e+='<input type="submit" id="'+o+'-next" class="'+o+' jspsych-btn"'+(i.button_label?' value="'+i.button_label+'"':"")+"></input>",e+="</form>",t.innerHTML=e,document.querySelector("form").addEventListener("submit",S=>{S.preventDefault();for(var O=performance.now(),z=Math.round(O-b),v={},c=0;c<i.questions.length;c++){var y=t.querySelector("#jspsych-survey-multi-choice-"+c),x="Q"+c,m;y.querySelector("input[type=radio]:checked")!==null?m=y.querySelector("input[type=radio]:checked").value:m="";var f={},j=x;y.attributes["data-name"].value!==""&&(j=y.attributes["data-name"].value),f[j]=m,Object.assign(v,f)}var I={rt:z,response:v,question_order:u};this.jsPsych.finishTrial(I)});var b=performance.now()}simulate(t,i,o,e){i=="data-only"&&(e(),this.simulate_data_only(t,o)),i=="visual"&&this.simulate_visual(t,o,e)}create_simulation_data(t,i){const o={};let e=1e3;for(const s of t.questions){const n=s.name?s.name:`Q${t.questions.indexOf(s)}`;o[n]=this.jsPsych.randomization.sampleWithoutReplacement(s.options,1)[0],e+=this.jsPsych.randomization.sampleExGaussian(1500,400,.005,!0)}const u={response:o,rt:e,question_order:t.randomize_question_order?this.jsPsych.randomization.shuffle([...Array(t.questions.length).keys()]):[...Array(t.questions.length).keys()]},r=this.jsPsych.pluginAPI.mergeSimulationData(u,i);return this.jsPsych.pluginAPI.ensureSimulationDataConsistency(t,r),r}simulate_data_only(t,i){const o=this.create_simulation_data(t,i);this.jsPsych.finishTrial(o)}simulate_visual(t,i,o){const e=this.create_simulation_data(t,i),u=this.jsPsych.getDisplayElement();this.trial(u,t),o();const r=Object.entries(e.response);for(let s=0;s<r.length;s++)this.jsPsych.pluginAPI.clickTarget(u.querySelector(`#jspsych-survey-multi-choice-response-${s}-${t.questions[s].options.indexOf(r[s][1])}`),(e.rt-1e3)/r.length*(s+1));this.jsPsych.pluginAPI.clickTarget(u.querySelector("#jspsych-survey-multi-choice-next"),e.rt)}}return h.info=q,h}(jsPsychModule);
|
|
2
|
+
//# sourceMappingURL=https://unpkg.com/@jspsych/plugin-survey-multi-choice@2.0.1/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,WAG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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":["../package.json","../src/index.ts"],"sourcesContent":["{\n \"name\": \"@jspsych/plugin-survey-multi-choice\",\n \"version\": \"2.0.1\",\n \"description\": \"a jspsych plugin for multiple choice survey questions\",\n \"type\": \"module\",\n \"main\": \"dist/index.cjs\",\n \"exports\": {\n \"import\": \"./dist/index.js\",\n \"require\": \"./dist/index.cjs\"\n },\n \"typings\": \"dist/index.d.ts\",\n \"unpkg\": \"dist/index.browser.min.js\",\n \"files\": [\n \"src\",\n \"dist\"\n ],\n \"source\": \"src/index.ts\",\n \"scripts\": {\n \"test\": \"jest\",\n \"test:watch\": \"npm test -- --watch\",\n \"tsc\": \"tsc\",\n \"build\": \"rollup --config\",\n \"build:watch\": \"npm run build -- --watch\"\n },\n \"repository\": {\n \"type\": \"git\",\n \"url\": \"git+https://github.com/jspsych/jsPsych.git\",\n \"directory\": \"packages/plugin-survey-multi-choice\"\n },\n \"author\": \"Shane Martin\",\n \"license\": \"MIT\",\n \"bugs\": {\n \"url\": \"https://github.com/jspsych/jsPsych/issues\"\n },\n \"homepage\": \"https://www.jspsych.org/latest/plugins/survey-multi-choice\",\n \"peerDependencies\": {\n \"jspsych\": \">=7.1.0\"\n },\n \"devDependencies\": {\n \"@jspsych/config\": \"^3.1.1\",\n \"@jspsych/test-utils\": \"^1.2.0\"\n }\n}\n","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.OBJECT,\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":["version","info","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":"sDAEEA,IAAAA,EAAW,QCEb,MAAMC,EAAc,CAClB,KAAM,sBACN,QAASD,EACT,WAAY,CAaV,UAAW,CACT,KAAME,EAAAA,cAAc,QACpB,MAAO,GACP,OAAQ,CAEN,OAAQ,CACN,KAAMA,EAAc,cAAA,YACpB,QAAS,MACX,EAEA,QAAS,CACP,KAAMA,EAAAA,cAAc,OACpB,MAAO,GACP,QAAS,MACX,EAEA,SAAU,CACR,KAAMA,gBAAc,KACpB,QAAS,EACX,EAEA,WAAY,CACV,KAAMA,gBAAc,K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QAAQD,EAAK,QAAQ,EAC5C,QAAS1B,EAAI,EAAGA,EAAI2B,EAAQ,OAAQ3B,IAClC,KAAK,QAAQ,UAAU,YACrBL,EAAgB,cACd,yCAAyCK,CAAC,IAAIJ,EAAM,UAAUI,CAAC,EAAE,QAAQ,QACvE2B,EAAQ3B,CAAC,EAAE,CAAC,CACd,CAAC,EACH,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,KAAOF"}
|
package/dist/index.cjs
CHANGED
|
@@ -2,265 +2,239 @@
|
|
|
2
2
|
|
|
3
3
|
var jspsych = require('jspsych');
|
|
4
4
|
|
|
5
|
+
var version = "2.0.1";
|
|
6
|
+
|
|
5
7
|
const info = {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
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
|
-
},
|
|
46
|
-
},
|
|
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,
|
|
8
|
+
name: "survey-multi-choice",
|
|
9
|
+
version,
|
|
10
|
+
parameters: {
|
|
11
|
+
/**
|
|
12
|
+
* An array of objects, each object represents a question that appears on the screen. Each object contains a prompt,
|
|
13
|
+
* options, required, and horizontal parameter that will be applied to the question. See examples below for further
|
|
14
|
+
* clarification.`prompt`: Type string, default value is *undefined*. The string is prompt/question that will be
|
|
15
|
+
* associated with a group of options (radio buttons). All questions will get presented on the same page (trial).
|
|
16
|
+
* `options`: Type array, defualt value is *undefined*. An array of strings. The array contains a set of options to
|
|
17
|
+
* display for an individual question.`required`: Type boolean, default value is null. The boolean value indicates
|
|
18
|
+
* if a question is required('true') or not ('false'), using the HTML5 `required` attribute. If this parameter is
|
|
19
|
+
* undefined, the question will be optional. `horizontal`:Type boolean, default value is false. If true, then the
|
|
20
|
+
* question is centered and the options are displayed horizontally. `name`: Name of the question. Used for storing
|
|
21
|
+
* data. If left undefined then default names (`Q0`, `Q1`, `...`) will be used for the questions.
|
|
22
|
+
*/
|
|
23
|
+
questions: {
|
|
24
|
+
type: jspsych.ParameterType.COMPLEX,
|
|
25
|
+
array: true,
|
|
26
|
+
nested: {
|
|
27
|
+
/** Question prompt. */
|
|
28
|
+
prompt: {
|
|
29
|
+
type: jspsych.ParameterType.HTML_STRING,
|
|
30
|
+
default: void 0
|
|
52
31
|
},
|
|
53
|
-
/**
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
32
|
+
/** Array of multiple choice options for this question. */
|
|
33
|
+
options: {
|
|
34
|
+
type: jspsych.ParameterType.STRING,
|
|
35
|
+
array: true,
|
|
36
|
+
default: void 0
|
|
58
37
|
},
|
|
59
|
-
/**
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
default: "Continue",
|
|
38
|
+
/** Whether or not a response to this question must be given in order to continue. */
|
|
39
|
+
required: {
|
|
40
|
+
type: jspsych.ParameterType.BOOL,
|
|
41
|
+
default: false
|
|
64
42
|
},
|
|
65
|
-
/**
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
default: false,
|
|
43
|
+
/** If true, then the question will be centered and options will be displayed horizontally. */
|
|
44
|
+
horizontal: {
|
|
45
|
+
type: jspsych.ParameterType.BOOL,
|
|
46
|
+
default: false
|
|
70
47
|
},
|
|
48
|
+
/** Name of the question in the trial data. If no name is given, the questions are named Q0, Q1, etc. */
|
|
49
|
+
name: {
|
|
50
|
+
type: jspsych.ParameterType.STRING,
|
|
51
|
+
default: ""
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
},
|
|
55
|
+
/**
|
|
56
|
+
* If true, the display order of `questions` is randomly determined at the start of the trial. In the data object,
|
|
57
|
+
* `Q0` will still refer to the first question in the array, regardless of where it was presented visually.
|
|
58
|
+
*/
|
|
59
|
+
randomize_question_order: {
|
|
60
|
+
type: jspsych.ParameterType.BOOL,
|
|
61
|
+
default: false
|
|
62
|
+
},
|
|
63
|
+
/** HTML formatted string to display at the top of the page above all the questions. */
|
|
64
|
+
preamble: {
|
|
65
|
+
type: jspsych.ParameterType.HTML_STRING,
|
|
66
|
+
default: null
|
|
67
|
+
},
|
|
68
|
+
/** Label of the button. */
|
|
69
|
+
button_label: {
|
|
70
|
+
type: jspsych.ParameterType.STRING,
|
|
71
|
+
default: "Continue"
|
|
71
72
|
},
|
|
73
|
+
/**
|
|
74
|
+
* This determines whether or not all of the input elements on the page should allow autocomplete. Setting
|
|
75
|
+
* this to true will enable autocomplete or auto-fill for the form.
|
|
76
|
+
*/
|
|
77
|
+
autocomplete: {
|
|
78
|
+
type: jspsych.ParameterType.BOOL,
|
|
79
|
+
default: false
|
|
80
|
+
}
|
|
81
|
+
},
|
|
82
|
+
data: {
|
|
83
|
+
/** 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. */
|
|
84
|
+
response: {
|
|
85
|
+
type: jspsych.ParameterType.OBJECT
|
|
86
|
+
},
|
|
87
|
+
/** 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. */
|
|
88
|
+
rt: {
|
|
89
|
+
type: jspsych.ParameterType.INT
|
|
90
|
+
},
|
|
91
|
+
/** 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. */
|
|
92
|
+
question_order: {
|
|
93
|
+
type: jspsych.ParameterType.INT,
|
|
94
|
+
array: true
|
|
95
|
+
}
|
|
96
|
+
}
|
|
72
97
|
};
|
|
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
98
|
class SurveyMultiChoicePlugin {
|
|
82
|
-
|
|
83
|
-
|
|
99
|
+
constructor(jsPsych) {
|
|
100
|
+
this.jsPsych = jsPsych;
|
|
101
|
+
}
|
|
102
|
+
static {
|
|
103
|
+
this.info = info;
|
|
104
|
+
}
|
|
105
|
+
trial(display_element, trial) {
|
|
106
|
+
var plugin_id_name = "jspsych-survey-multi-choice";
|
|
107
|
+
var html = "";
|
|
108
|
+
html += '<style id="jspsych-survey-multi-choice-css">';
|
|
109
|
+
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;}";
|
|
110
|
+
html += "</style>";
|
|
111
|
+
if (trial.preamble !== null) {
|
|
112
|
+
html += '<div id="jspsych-survey-multi-choice-preamble" class="jspsych-survey-multi-choice-preamble">' + trial.preamble + "</div>";
|
|
84
113
|
}
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
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();
|
|
114
|
+
if (trial.autocomplete) {
|
|
115
|
+
html += '<form id="jspsych-survey-multi-choice-form">';
|
|
116
|
+
} else {
|
|
117
|
+
html += '<form id="jspsych-survey-multi-choice-form" autocomplete="off">';
|
|
218
118
|
}
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
119
|
+
var question_order = [];
|
|
120
|
+
for (var i = 0; i < trial.questions.length; i++) {
|
|
121
|
+
question_order.push(i);
|
|
122
|
+
}
|
|
123
|
+
if (trial.randomize_question_order) {
|
|
124
|
+
question_order = this.jsPsych.randomization.shuffle(question_order);
|
|
125
|
+
}
|
|
126
|
+
for (var i = 0; i < trial.questions.length; i++) {
|
|
127
|
+
var question = trial.questions[question_order[i]];
|
|
128
|
+
var question_id = question_order[i];
|
|
129
|
+
var question_classes = ["jspsych-survey-multi-choice-question"];
|
|
130
|
+
if (question.horizontal) {
|
|
131
|
+
question_classes.push("jspsych-survey-multi-choice-horizontal");
|
|
132
|
+
}
|
|
133
|
+
html += '<div id="jspsych-survey-multi-choice-' + question_id + '" class="' + question_classes.join(" ") + '" data-name="' + question.name + '">';
|
|
134
|
+
html += '<p class="jspsych-survey-multi-choice-text survey-multi-choice">' + question.prompt;
|
|
135
|
+
if (question.required) {
|
|
136
|
+
html += "<span class='required'>*</span>";
|
|
137
|
+
}
|
|
138
|
+
html += "</p>";
|
|
139
|
+
for (var j = 0; j < question.options.length; j++) {
|
|
140
|
+
var option_id_name = "jspsych-survey-multi-choice-option-" + question_id + "-" + j;
|
|
141
|
+
var input_name = "jspsych-survey-multi-choice-response-" + question_id;
|
|
142
|
+
var input_id = "jspsych-survey-multi-choice-response-" + question_id + "-" + j;
|
|
143
|
+
var required_attr = question.required ? "required" : "";
|
|
144
|
+
html += '<div id="' + option_id_name + '" class="jspsych-survey-multi-choice-option">';
|
|
145
|
+
html += '<label class="jspsych-survey-multi-choice-text" for="' + input_id + '">';
|
|
146
|
+
html += '<input type="radio" name="' + input_name + '" id="' + input_id + '" value="' + question.options[j] + '" ' + required_attr + "></input>";
|
|
147
|
+
html += question.options[j] + "</label>";
|
|
148
|
+
html += "</div>";
|
|
149
|
+
}
|
|
150
|
+
html += "</div>";
|
|
151
|
+
}
|
|
152
|
+
html += '<input type="submit" id="' + plugin_id_name + '-next" class="' + plugin_id_name + ' jspsych-btn"' + (trial.button_label ? ' value="' + trial.button_label + '"' : "") + "></input>";
|
|
153
|
+
html += "</form>";
|
|
154
|
+
display_element.innerHTML = html;
|
|
155
|
+
document.querySelector("form").addEventListener("submit", (event) => {
|
|
156
|
+
event.preventDefault();
|
|
157
|
+
var endTime = performance.now();
|
|
158
|
+
var response_time = Math.round(endTime - startTime);
|
|
159
|
+
var question_data = {};
|
|
160
|
+
for (var i2 = 0; i2 < trial.questions.length; i2++) {
|
|
161
|
+
var match = display_element.querySelector("#jspsych-survey-multi-choice-" + i2);
|
|
162
|
+
var id = "Q" + i2;
|
|
163
|
+
var val;
|
|
164
|
+
if (match.querySelector("input[type=radio]:checked") !== null) {
|
|
165
|
+
val = match.querySelector("input[type=radio]:checked").value;
|
|
166
|
+
} else {
|
|
167
|
+
val = "";
|
|
223
168
|
}
|
|
224
|
-
|
|
225
|
-
|
|
169
|
+
var obje = {};
|
|
170
|
+
var name = id;
|
|
171
|
+
if (match.attributes["data-name"].value !== "") {
|
|
172
|
+
name = match.attributes["data-name"].value;
|
|
226
173
|
}
|
|
174
|
+
obje[name] = val;
|
|
175
|
+
Object.assign(question_data, obje);
|
|
176
|
+
}
|
|
177
|
+
var trial_data = {
|
|
178
|
+
rt: response_time,
|
|
179
|
+
response: question_data,
|
|
180
|
+
question_order
|
|
181
|
+
};
|
|
182
|
+
this.jsPsych.finishTrial(trial_data);
|
|
183
|
+
});
|
|
184
|
+
var startTime = performance.now();
|
|
185
|
+
}
|
|
186
|
+
simulate(trial, simulation_mode, simulation_options, load_callback) {
|
|
187
|
+
if (simulation_mode == "data-only") {
|
|
188
|
+
load_callback();
|
|
189
|
+
this.simulate_data_only(trial, simulation_options);
|
|
227
190
|
}
|
|
228
|
-
|
|
229
|
-
|
|
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;
|
|
191
|
+
if (simulation_mode == "visual") {
|
|
192
|
+
this.simulate_visual(trial, simulation_options, load_callback);
|
|
246
193
|
}
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
194
|
+
}
|
|
195
|
+
create_simulation_data(trial, simulation_options) {
|
|
196
|
+
const question_data = {};
|
|
197
|
+
let rt = 1e3;
|
|
198
|
+
for (const q of trial.questions) {
|
|
199
|
+
const name = q.name ? q.name : `Q${trial.questions.indexOf(q)}`;
|
|
200
|
+
question_data[name] = this.jsPsych.randomization.sampleWithoutReplacement(q.options, 1)[0];
|
|
201
|
+
rt += this.jsPsych.randomization.sampleExGaussian(1500, 400, 1 / 200, true);
|
|
250
202
|
}
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
203
|
+
const default_data = {
|
|
204
|
+
response: question_data,
|
|
205
|
+
rt,
|
|
206
|
+
question_order: trial.randomize_question_order ? this.jsPsych.randomization.shuffle([...Array(trial.questions.length).keys()]) : [...Array(trial.questions.length).keys()]
|
|
207
|
+
};
|
|
208
|
+
const data = this.jsPsych.pluginAPI.mergeSimulationData(default_data, simulation_options);
|
|
209
|
+
this.jsPsych.pluginAPI.ensureSimulationDataConsistency(trial, data);
|
|
210
|
+
return data;
|
|
211
|
+
}
|
|
212
|
+
simulate_data_only(trial, simulation_options) {
|
|
213
|
+
const data = this.create_simulation_data(trial, simulation_options);
|
|
214
|
+
this.jsPsych.finishTrial(data);
|
|
215
|
+
}
|
|
216
|
+
simulate_visual(trial, simulation_options, load_callback) {
|
|
217
|
+
const data = this.create_simulation_data(trial, simulation_options);
|
|
218
|
+
const display_element = this.jsPsych.getDisplayElement();
|
|
219
|
+
this.trial(display_element, trial);
|
|
220
|
+
load_callback();
|
|
221
|
+
const answers = Object.entries(data.response);
|
|
222
|
+
for (let i = 0; i < answers.length; i++) {
|
|
223
|
+
this.jsPsych.pluginAPI.clickTarget(
|
|
224
|
+
display_element.querySelector(
|
|
225
|
+
`#jspsych-survey-multi-choice-response-${i}-${trial.questions[i].options.indexOf(
|
|
226
|
+
answers[i][1]
|
|
227
|
+
)}`
|
|
228
|
+
),
|
|
229
|
+
(data.rt - 1e3) / answers.length * (i + 1)
|
|
230
|
+
);
|
|
261
231
|
}
|
|
232
|
+
this.jsPsych.pluginAPI.clickTarget(
|
|
233
|
+
display_element.querySelector("#jspsych-survey-multi-choice-next"),
|
|
234
|
+
data.rt
|
|
235
|
+
);
|
|
236
|
+
}
|
|
262
237
|
}
|
|
263
|
-
SurveyMultiChoicePlugin.info = info;
|
|
264
238
|
|
|
265
239
|
module.exports = SurveyMultiChoicePlugin;
|
|
266
240
|
//# sourceMappingURL=index.cjs.map
|