@jspsych/plugin-survey-multi-select
Advanced tools
Comparing version 2.0.1 to 2.1.0
var jsPsychSurveyMultiSelect = (function (jspsych) { | ||
'use strict'; | ||
var version = "2.0.1"; | ||
var version = "2.1.0"; | ||
@@ -99,2 +99,7 @@ const info = { | ||
} | ||
}, | ||
// prettier-ignore | ||
citations: { | ||
"apa": "de Leeuw, J. R., Gilbert, R. A., & Luchterhandt, B. (2023). jsPsych: Enabling an Open-Source Collaborative Ecosystem of Behavioral Experiments. Journal of Open Source Software, 8(85), 5351. https://doi.org/10.21105/joss.05351 ", | ||
"bibtex": '@article{Leeuw2023jsPsych, author = {de Leeuw, Joshua R. and Gilbert, Rebecca A. and Luchterhandt, Bj{\\" o}rn}, journal = {Journal of Open Source Software}, doi = {10.21105/joss.05351}, issn = {2475-9066}, number = {85}, year = {2023}, month = {may 11}, pages = {5351}, publisher = {Open Journals}, title = {jsPsych: Enabling an {Open}-{Source} {Collaborative} {Ecosystem} of {Behavioral} {Experiments}}, url = {https://joss.theoj.org/papers/10.21105/joss.05351}, volume = {8}, } ' | ||
} | ||
@@ -272,2 +277,2 @@ }; | ||
})(jsPsychModule); | ||
//# sourceMappingURL=https://unpkg.com/@jspsych/plugin-survey-multi-select@2.0.1/dist/index.browser.js.map | ||
//# sourceMappingURL=https://unpkg.com/@jspsych/plugin-survey-multi-select@2.1.0/dist/index.browser.js.map |
@@ -1,2 +0,2 @@ | ||
var jsPsychSurveyMultiSelect=function(a){"use strict";var A="2.0.1";const k={name:"survey-multi-select",version:A,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},horizontal:{type:a.ParameterType.BOOL,default:!1},required:{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"},required_message:{type:a.ParameterType.STRING,default:"You must choose at least one response for this question"},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 b{constructor(e){this.jsPsych=e}trial(e,r){var t="jspsych-survey-multi-select",o="#"+t;const i=(...l)=>l.join("-");var u=".jspsych-survey-multi-select-question { margin-top: 2em; margin-bottom: 2em; text-align: left; }.jspsych-survey-multi-select-text span.required {color: darkred;}.jspsych-survey-multi-select-horizontal .jspsych-survey-multi-select-text { text-align: center;}.jspsych-survey-multi-select-option { line-height: 2; }.jspsych-survey-multi-select-horizontal .jspsych-survey-multi-select-option { display: inline-block; margin-left: 1em; margin-right: 1em; vertical-align: top;}label.jspsych-survey-multi-select-text input[type='checkbox'] {margin-right: 1em;}";e.innerHTML='<style id="jspsych-survey-multi-select-css">'+u+"</style>";var s=i(t,"form");e.innerHTML+='<form id="'+s+'"></form>';var n=e.querySelector("#"+s);r.autocomplete||n.setAttribute("autocomplete","off");var f=i(t,"preamble");r.preamble!==null&&(n.innerHTML+='<div id="'+f+'" class="'+f+'">'+r.preamble+"</div>");for(var c=[],m=0;m<r.questions.length;m++)c.push(m);r.randomize_question_order&&(c=this.jsPsych.randomization.shuffle(c));for(var m=0;m<r.questions.length;m++){var p=r.questions[c[m]],h=c[m],_=[i(t,"question")];p.horizontal&&_.push(i(t,"horizontal")),n.innerHTML+='<div id="'+i(t,h)+'" data-name="'+p.name+'" class="'+_.join(" ")+'"></div>';var j=i(o,h);e.querySelector(j).innerHTML+='<p id="survey-question" class="'+t+'-text survey-multi-select">'+p.prompt+"</p>";for(var y=0;y<p.options.length;y++){var S=i(t,"option",h,y);e.querySelector(j).innerHTML+='<div id="'+S+'" class="'+i(t,"option")+'"></div>';var H=document.getElementById(S),E=i(t,"response",h),x=i(t,"response",h,y),d=document.createElement("label");d.setAttribute("class",t+"-text"),d.innerHTML=p.options[y],d.setAttribute("for",x);var v=document.createElement("input");v.setAttribute("type","checkbox"),v.setAttribute("name",E),v.setAttribute("id",x),v.setAttribute("value",p.options[y]),H.appendChild(d),d.insertBefore(v,d.firstChild)}}n.innerHTML+='<div class="fail-message"></div>',n.innerHTML+='<button id="'+t+'-next" class="'+t+' jspsych-btn">'+r.button_label+"</button>",e.querySelector("#jspsych-survey-multi-select-next").addEventListener("click",()=>{for(var l=0;l<r.questions.length;l++)r.questions[l].required&&(e.querySelector("#jspsych-survey-multi-select-"+l+" input:checked")==null?e.querySelector("#jspsych-survey-multi-select-"+l+" input").setCustomValidity(r.required_message):e.querySelector("#jspsych-survey-multi-select-"+l+" input").setCustomValidity(""));n.reportValidity()}),n.addEventListener("submit",l=>{l.preventDefault();for(var G=performance.now(),N=Math.round(G-C),L={},z=[],q=0;q<r.questions.length;q++){for(var g=e.querySelector("#jspsych-survey-multi-select-"+q),T=[],I=g.querySelectorAll("input[type=checkbox]:checked"),P=0;P<I.length;P++){var B=I[P];T.push(B.value)}var R="Q"+q,M={},O=R;g.attributes["data-name"].value!==""&&(O=g.attributes["data-name"].value),M[O]=T,Object.assign(L,M),T.length==0?z.push(!1):z.push(!0)}var D={rt:N,response:L,question_order:c};this.jsPsych.finishTrial(D)});var C=performance.now()}simulate(e,r,t,o){r=="data-only"&&(o(),this.simulate_data_only(e,t)),r=="visual"&&this.simulate_visual(e,t,o)}create_simulation_data(e,r){const t={};let o=1e3;for(const s of e.questions){let n;s.required?n=this.jsPsych.randomization.randomInt(1,s.options.length):n=this.jsPsych.randomization.randomInt(0,s.options.length);const f=s.name?s.name:`Q${e.questions.indexOf(s)}`,c=this.jsPsych.randomization.sampleWithoutReplacement(s.options,n);t[f]=c,o+=this.jsPsych.randomization.sampleExGaussian(1500,400,.005,!0)}const i={response:t,rt:o,question_order:e.randomize_question_order?this.jsPsych.randomization.shuffle([...Array(e.questions.length).keys()]):[...Array(e.questions.length).keys()]},u=this.jsPsych.pluginAPI.mergeSimulationData(i,r);return this.jsPsych.pluginAPI.ensureSimulationDataConsistency(e,u),u}simulate_data_only(e,r){const t=this.create_simulation_data(e,r);this.jsPsych.finishTrial(t)}simulate_visual(e,r,t){const o=this.create_simulation_data(e,r),i=this.jsPsych.getDisplayElement();this.trial(i,e),t();const u=Object.entries(o.response);for(let s=0;s<u.length;s++)for(const n of u[s][1])this.jsPsych.pluginAPI.clickTarget(i.querySelector(`#jspsych-survey-multi-select-response-${s}-${e.questions[s].options.indexOf(n)}`),(o.rt-1e3)/u.length*(s+1));this.jsPsych.pluginAPI.clickTarget(i.querySelector("#jspsych-survey-multi-select-next"),o.rt)}}return b.info=k,b}(jsPsychModule); | ||
//# sourceMappingURL=https://unpkg.com/@jspsych/plugin-survey-multi-select@2.0.1/dist/index.browser.min.js.map | ||
var jsPsychSurveyMultiSelect=function(i){"use strict";var I="2.1.0";const M={name:"survey-multi-select",version:I,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},horizontal:{type:i.ParameterType.BOOL,default:!1},required:{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"},required_message:{type:i.ParameterType.STRING,default:"You must choose at least one response for this question"},autocomplete:{type:i.ParameterType.BOOL,default:!1}},data:{response:{type:i.ParameterType.OBJECT},rt:{type:i.ParameterType.INT},question_order:{type:i.ParameterType.INT,array:!0}},citations:{apa:"de Leeuw, J. R., Gilbert, R. A., & Luchterhandt, B. (2023). jsPsych: Enabling an Open-Source Collaborative Ecosystem of Behavioral Experiments. Journal of Open Source Software, 8(85), 5351. https://doi.org/10.21105/joss.05351 ",bibtex:'@article{Leeuw2023jsPsych, author = {de Leeuw, Joshua R. and Gilbert, Rebecca A. and Luchterhandt, Bj{\\" o}rn}, journal = {Journal of Open Source Software}, doi = {10.21105/joss.05351}, issn = {2475-9066}, number = {85}, year = {2023}, month = {may 11}, pages = {5351}, publisher = {Open Journals}, title = {jsPsych: Enabling an {Open}-{Source} {Collaborative} {Ecosystem} of {Behavioral} {Experiments}}, url = {https://joss.theoj.org/papers/10.21105/joss.05351}, volume = {8}, } '}};class T{constructor(e){this.jsPsych=e}trial(e,r){var t="jspsych-survey-multi-select",o="#"+t;const a=(...l)=>l.join("-");var u=".jspsych-survey-multi-select-question { margin-top: 2em; margin-bottom: 2em; text-align: left; }.jspsych-survey-multi-select-text span.required {color: darkred;}.jspsych-survey-multi-select-horizontal .jspsych-survey-multi-select-text { text-align: center;}.jspsych-survey-multi-select-option { line-height: 2; }.jspsych-survey-multi-select-horizontal .jspsych-survey-multi-select-option { display: inline-block; margin-left: 1em; margin-right: 1em; vertical-align: top;}label.jspsych-survey-multi-select-text input[type='checkbox'] {margin-right: 1em;}";e.innerHTML='<style id="jspsych-survey-multi-select-css">'+u+"</style>";var s=a(t,"form");e.innerHTML+='<form id="'+s+'"></form>';var n=e.querySelector("#"+s);r.autocomplete||n.setAttribute("autocomplete","off");var f=a(t,"preamble");r.preamble!==null&&(n.innerHTML+='<div id="'+f+'" class="'+f+'">'+r.preamble+"</div>");for(var c=[],p=0;p<r.questions.length;p++)c.push(p);r.randomize_question_order&&(c=this.jsPsych.randomization.shuffle(c));for(var p=0;p<r.questions.length;p++){var m=r.questions[c[p]],d=c[p],j=[a(t,"question")];m.horizontal&&j.push(a(t,"horizontal")),n.innerHTML+='<div id="'+a(t,d)+'" data-name="'+m.name+'" class="'+j.join(" ")+'"></div>';var S=a(o,d);e.querySelector(S).innerHTML+='<p id="survey-question" class="'+t+'-text survey-multi-select">'+m.prompt+"</p>";for(var y=0;y<m.options.length;y++){var _=a(t,"option",d,y);e.querySelector(S).innerHTML+='<div id="'+_+'" class="'+a(t,"option")+'"></div>';var k=document.getElementById(_),B=a(t,"response",d),L=a(t,"response",d,y),h=document.createElement("label");h.setAttribute("class",t+"-text"),h.innerHTML=m.options[y],h.setAttribute("for",L);var v=document.createElement("input");v.setAttribute("type","checkbox"),v.setAttribute("name",B),v.setAttribute("id",L),v.setAttribute("value",m.options[y]),k.appendChild(h),h.insertBefore(v,h.firstChild)}}n.innerHTML+='<div class="fail-message"></div>',n.innerHTML+='<button id="'+t+'-next" class="'+t+' jspsych-btn">'+r.button_label+"</button>",e.querySelector("#jspsych-survey-multi-select-next").addEventListener("click",()=>{for(var l=0;l<r.questions.length;l++)r.questions[l].required&&(e.querySelector("#jspsych-survey-multi-select-"+l+" input:checked")==null?e.querySelector("#jspsych-survey-multi-select-"+l+" input").setCustomValidity(r.required_message):e.querySelector("#jspsych-survey-multi-select-"+l+" input").setCustomValidity(""));n.reportValidity()}),n.addEventListener("submit",l=>{l.preventDefault();for(var R=performance.now(),C=Math.round(R-H),x={},O=[],b=0;b<r.questions.length;b++){for(var g=e.querySelector("#jspsych-survey-multi-select-"+b),q=[],A=g.querySelectorAll("input[type=checkbox]:checked"),P=0;P<A.length;P++){var G=A[P];q.push(G.value)}var N="Q"+b,z={},E=N;g.attributes["data-name"].value!==""&&(E=g.attributes["data-name"].value),z[E]=q,Object.assign(x,z),q.length==0?O.push(!1):O.push(!0)}var w={rt:C,response:x,question_order:c};this.jsPsych.finishTrial(w)});var H=performance.now()}simulate(e,r,t,o){r=="data-only"&&(o(),this.simulate_data_only(e,t)),r=="visual"&&this.simulate_visual(e,t,o)}create_simulation_data(e,r){const t={};let o=1e3;for(const s of e.questions){let n;s.required?n=this.jsPsych.randomization.randomInt(1,s.options.length):n=this.jsPsych.randomization.randomInt(0,s.options.length);const f=s.name?s.name:`Q${e.questions.indexOf(s)}`,c=this.jsPsych.randomization.sampleWithoutReplacement(s.options,n);t[f]=c,o+=this.jsPsych.randomization.sampleExGaussian(1500,400,.005,!0)}const a={response:t,rt:o,question_order:e.randomize_question_order?this.jsPsych.randomization.shuffle([...Array(e.questions.length).keys()]):[...Array(e.questions.length).keys()]},u=this.jsPsych.pluginAPI.mergeSimulationData(a,r);return this.jsPsych.pluginAPI.ensureSimulationDataConsistency(e,u),u}simulate_data_only(e,r){const t=this.create_simulation_data(e,r);this.jsPsych.finishTrial(t)}simulate_visual(e,r,t){const o=this.create_simulation_data(e,r),a=this.jsPsych.getDisplayElement();this.trial(a,e),t();const u=Object.entries(o.response);for(let s=0;s<u.length;s++)for(const n of u[s][1])this.jsPsych.pluginAPI.clickTarget(a.querySelector(`#jspsych-survey-multi-select-response-${s}-${e.questions[s].options.indexOf(n)}`),(o.rt-1e3)/u.length*(s+1));this.jsPsych.pluginAPI.clickTarget(a.querySelector("#jspsych-survey-multi-select-next"),o.rt)}}return T.info=M,T}(jsPsychModule); | ||
//# sourceMappingURL=https://unpkg.com/@jspsych/plugin-survey-multi-select@2.1.0/dist/index.browser.min.js.map |
@@ -97,2 +97,3 @@ import { JsPsychPlugin, ParameterType, JsPsych, TrialType } from 'jspsych'; | ||
}; | ||
readonly citations: "__CITATIONS__"; | ||
}; | ||
@@ -202,2 +203,3 @@ type Info = typeof info; | ||
}; | ||
readonly citations: "__CITATIONS__"; | ||
}; | ||
@@ -204,0 +206,0 @@ constructor(jsPsych: JsPsych); |
import { ParameterType } from 'jspsych'; | ||
var version = "2.0.1"; | ||
var version = "2.1.0"; | ||
@@ -98,2 +98,7 @@ const info = { | ||
} | ||
}, | ||
// prettier-ignore | ||
citations: { | ||
"apa": "de Leeuw, J. R., Gilbert, R. A., & Luchterhandt, B. (2023). jsPsych: Enabling an Open-Source Collaborative Ecosystem of Behavioral Experiments. Journal of Open Source Software, 8(85), 5351. https://doi.org/10.21105/joss.05351 ", | ||
"bibtex": '@article{Leeuw2023jsPsych, author = {de Leeuw, Joshua R. and Gilbert, Rebecca A. and Luchterhandt, Bj{\\" o}rn}, journal = {Journal of Open Source Software}, doi = {10.21105/joss.05351}, issn = {2475-9066}, number = {85}, year = {2023}, month = {may 11}, pages = {5351}, publisher = {Open Journals}, title = {jsPsych: Enabling an {Open}-{Source} {Collaborative} {Ecosystem} of {Behavioral} {Experiments}}, url = {https://joss.theoj.org/papers/10.21105/joss.05351}, volume = {8}, } ' | ||
} | ||
@@ -100,0 +105,0 @@ }; |
{ | ||
"name": "@jspsych/plugin-survey-multi-select", | ||
"version": "2.0.1", | ||
"version": "2.1.0", | ||
"description": "a jspsych plugin for multiple choice survey questions", | ||
@@ -40,5 +40,5 @@ "type": "module", | ||
"devDependencies": { | ||
"@jspsych/config": "^3.1.1", | ||
"@jspsych/config": "^3.2.0", | ||
"@jspsych/test-utils": "^1.2.0" | ||
} | ||
} |
@@ -100,2 +100,4 @@ import { JsPsych, JsPsychPlugin, ParameterType, TrialType } from "jspsych"; | ||
}, | ||
// prettier-ignore | ||
citations: '__CITATIONS__', | ||
}; | ||
@@ -102,0 +104,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
1527
153186