@jspsych/plugin-survey-multi-select
Advanced tools
Comparing version 1.1.0 to 1.1.1
@@ -1,2 +0,2 @@ | ||
var jsPsychSurveyMultiSelect=function(e){"use strict";const t={name:"survey-multi-select",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},horizontal:{type:e.ParameterType.BOOL,pretty_name:"Horizontal",default:!1},required:{type:e.ParameterType.BOOL,pretty_name:"Required",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"},required_message:{type:e.ParameterType.STRING,pretty_name:"Required message",default:"You must choose at least one response for this question"},autocomplete:{type:e.ParameterType.BOOL,pretty_name:"Allow autocomplete",default:!1}}};class s{constructor(e){this.jsPsych=e}trial(e,t){var s="jspsych-survey-multi-select";const r=(...e)=>e.join("-");e.innerHTML="<style id=\"jspsych-survey-multi-select-css\">.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;}</style>";var i=r(s,"form");e.innerHTML+='<form id="'+i+'"></form>';var n=e.querySelector("#"+i);t.autocomplete||n.setAttribute("autocomplete","off");var a=r(s,"preamble");null!==t.preamble&&(n.innerHTML+='<div id="'+a+'" class="'+a+'">'+t.preamble+"</div>");for(var o=[],l=0;l<t.questions.length;l++)o.push(l);t.randomize_question_order&&(o=this.jsPsych.randomization.shuffle(o));for(l=0;l<t.questions.length;l++){var u=t.questions[o[l]],c=o[l],m=[r(s,"question")];u.horizontal&&m.push(r(s,"horizontal")),n.innerHTML+='<div id="'+r(s,c)+'" data-name="'+u.name+'" class="'+m.join(" ")+'"></div>';var y=r("#jspsych-survey-multi-select",c);e.querySelector(y).innerHTML+='<p id="survey-question" class="'+s+'-text survey-multi-select">'+u.prompt+"</p>";for(var p=0;p<u.options.length;p++){var h=r(s,"option",c,p);e.querySelector(y).innerHTML+='<div id="'+h+'" class="'+r(s,"option")+'"></div>';var d=document.getElementById(h),v=r(s,"response",c),f=r(s,"response",c,p),q=document.createElement("label");q.setAttribute("class",s+"-text"),q.innerHTML=u.options[p],q.setAttribute("for",f);var j=document.createElement("input");j.setAttribute("type","checkbox"),j.setAttribute("name",v),j.setAttribute("id",f),j.setAttribute("value",u.options[p]),d.appendChild(q),q.insertBefore(j,q.firstChild)}}n.innerHTML+='<div class="fail-message"></div>',n.innerHTML+='<button id="'+s+'-next" class="'+s+' jspsych-btn">'+t.button_label+"</button>",e.querySelector("#jspsych-survey-multi-select-next").addEventListener("click",(()=>{for(var s=0;s<t.questions.length;s++)t.questions[s].required&&(null==e.querySelector("#jspsych-survey-multi-select-"+s+" input:checked")?e.querySelector("#jspsych-survey-multi-select-"+s+" input").setCustomValidity(t.required_message):e.querySelector("#jspsych-survey-multi-select-"+s+" input").setCustomValidity(""));n.reportValidity()})),n.addEventListener("submit",(s=>{s.preventDefault();for(var r=performance.now(),i=Math.round(r-g),n={},a=0;a<t.questions.length;a++){for(var l=e.querySelector("#jspsych-survey-multi-select-"+a),u=[],c=l.querySelectorAll("input[type=checkbox]:checked"),m=0;m<c.length;m++){var y=c[m];u.push(y.value)}var p={},h="Q"+a;""!==l.attributes["data-name"].value&&(h=l.attributes["data-name"].value),p[h]=u,Object.assign(n,p),u.length}var d={rt:i,response:n,question_order:o};e.innerHTML="",this.jsPsych.finishTrial(d)}));var g=performance.now()}simulate(e,t,s,r){"data-only"==t&&(r(),this.simulate_data_only(e,s)),"visual"==t&&this.simulate_visual(e,s,r)}create_simulation_data(e,t){const s={};let r=1e3;for(const t of e.questions){let i;i=t.required?this.jsPsych.randomization.randomInt(1,t.options.length):this.jsPsych.randomization.randomInt(0,t.options.length);const n=t.name?t.name:`Q${e.questions.indexOf(t)}`,a=this.jsPsych.randomization.sampleWithoutReplacement(t.options,i);s[n]=a,r+=this.jsPsych.randomization.sampleExGaussian(1500,400,.005,!0)}const i={response:s,rt:r,question_order:e.randomize_question_order?this.jsPsych.randomization.shuffle([...Array(e.questions.length).keys()]):[...Array(e.questions.length).keys()]},n=this.jsPsych.pluginAPI.mergeSimulationData(i,t);return this.jsPsych.pluginAPI.ensureSimulationDataConsistency(e,n),n}simulate_data_only(e,t){const s=this.create_simulation_data(e,t);this.jsPsych.finishTrial(s)}simulate_visual(e,t,s){const r=this.create_simulation_data(e,t),i=this.jsPsych.getDisplayElement();this.trial(i,e),s();const n=Object.entries(r.response);for(let t=0;t<n.length;t++)for(const s of n[t][1])this.jsPsych.pluginAPI.clickTarget(i.querySelector(`#jspsych-survey-multi-select-response-${t}-${e.questions[t].options.indexOf(s)}`),(r.rt-1e3)/n.length*(t+1));this.jsPsych.pluginAPI.clickTarget(i.querySelector("#jspsych-survey-multi-select-next"),r.rt)}}return s.info=t,s}(jsPsychModule); | ||
var jsPsychSurveyMultiSelect=function(e){"use strict";function t(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}function r(e){return function(e){if(Array.isArray(e))return a(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||n(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 n(e,t){if(e){if("string"==typeof e)return a(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)?a(e,t):void 0}}function a(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r<t;r++)n[r]=e[r];return n}function i(e,t){var r="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!r){if(Array.isArray(e)||(r=n(e))||t&&e&&"number"==typeof e.length){r&&(e=r);var a=0,i=function(){};return{s:i,n:function(){return a>=e.length?{done:!0}:{done:!1,value:e[a++]}},e:function(e){throw e},f:i}}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 s,o=!0,l=!1;return{s:function(){r=r.call(e)},n:function(){var e=r.next();return o=e.done,e},e:function(e){l=!0,s=e},f:function(){try{o||null==r.return||r.return()}finally{if(l)throw s}}}}var s={name:"survey-multi-select",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},horizontal:{type:e.ParameterType.BOOL,pretty_name:"Horizontal",default:!1},required:{type:e.ParameterType.BOOL,pretty_name:"Required",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"},required_message:{type:e.ParameterType.STRING,pretty_name:"Required message",default:"You must choose at least one response for this question"},autocomplete:{type:e.ParameterType.BOOL,pretty_name:"Allow autocomplete",default:!1}}},o=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,a,s;return n=e,a=[{key:"trial",value:function(e,t){var r=this,n="jspsych-survey-multi-select",a=function(){for(var e=arguments.length,t=new Array(e),r=0;r<e;r++)t[r]=arguments[r];return t.join("-")};e.innerHTML="<style id=\"jspsych-survey-multi-select-css\">.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;}</style>";var i=a(n,"form");e.innerHTML+='<form id="'+i+'"></form>';var s=e.querySelector("#"+i);t.autocomplete||s.setAttribute("autocomplete","off");var o=a(n,"preamble");null!==t.preamble&&(s.innerHTML+='<div id="'+o+'" class="'+o+'">'+t.preamble+"</div>");for(var l=[],u=0;u<t.questions.length;u++)l.push(u);for(t.randomize_question_order&&(l=this.jsPsych.randomization.shuffle(l)),u=0;u<t.questions.length;u++){var c=t.questions[l[u]],y=l[u],m=[a(n,"question")];c.horizontal&&m.push(a(n,"horizontal")),s.innerHTML+='<div id="'+a(n,y)+'" data-name="'+c.name+'" class="'+m.join(" ")+'"></div>';var p=a("#jspsych-survey-multi-select",y);e.querySelector(p).innerHTML+='<p id="survey-question" class="'+n+'-text survey-multi-select">'+c.prompt+"</p>";for(var h=0;h<c.options.length;h++){var d=a(n,"option",y,h);e.querySelector(p).innerHTML+='<div id="'+d+'" class="'+a(n,"option")+'"></div>';var f=document.getElementById(d),v=a(n,"response",y),b=a(n,"response",y,h),g=document.createElement("label");g.setAttribute("class",n+"-text"),g.innerHTML=c.options[h],g.setAttribute("for",b);var j=document.createElement("input");j.setAttribute("type","checkbox"),j.setAttribute("name",v),j.setAttribute("id",b),j.setAttribute("value",c.options[h]),f.appendChild(g),g.insertBefore(j,g.firstChild)}}s.innerHTML+='<div class="fail-message"></div>',s.innerHTML+='<button id="'+n+'-next" class="'+n+' jspsych-btn">'+t.button_label+"</button>",e.querySelector("#jspsych-survey-multi-select-next").addEventListener("click",(function(){for(var r=0;r<t.questions.length;r++)t.questions[r].required&&(null==e.querySelector("#jspsych-survey-multi-select-"+r+" input:checked")?e.querySelector("#jspsych-survey-multi-select-"+r+" input").setCustomValidity(t.required_message):e.querySelector("#jspsych-survey-multi-select-"+r+" input").setCustomValidity(""));s.reportValidity()})),s.addEventListener("submit",(function(n){n.preventDefault();for(var a=performance.now(),i=Math.round(a-q),s={},o=0;o<t.questions.length;o++){for(var u=e.querySelector("#jspsych-survey-multi-select-"+o),c=[],y=u.querySelectorAll("input[type=checkbox]:checked"),m=0;m<y.length;m++){var p=y[m];c.push(p.value)}var h={},d="Q"+o;""!==u.attributes["data-name"].value&&(d=u.attributes["data-name"].value),h[d]=c,Object.assign(s,h),c.length}var f={rt:i,response:s,question_order:l};e.innerHTML="",r.jsPsych.finishTrial(f)}));var q=performance.now()}},{key:"simulate",value:function(e,t,r,n){"data-only"==t&&(n(),this.simulate_data_only(e,r)),"visual"==t&&this.simulate_visual(e,r,n)}},{key:"create_simulation_data",value:function(e,t){var n,a={},s=1e3,o=i(e.questions);try{for(o.s();!(n=o.n()).done;){var l=n.value,u=void 0;u=l.required?this.jsPsych.randomization.randomInt(1,l.options.length):this.jsPsych.randomization.randomInt(0,l.options.length);var c=l.name?l.name:"Q".concat(e.questions.indexOf(l)),y=this.jsPsych.randomization.sampleWithoutReplacement(l.options,u);a[c]=y,s+=this.jsPsych.randomization.sampleExGaussian(1500,400,.005,!0)}}catch(e){o.e(e)}finally{o.f()}var m={response:a,rt:s,question_order:e.randomize_question_order?this.jsPsych.randomization.shuffle(r(Array(e.questions.length).keys())):r(Array(e.questions.length).keys())},p=this.jsPsych.pluginAPI.mergeSimulationData(m,t);return this.jsPsych.pluginAPI.ensureSimulationDataConsistency(e,p),p}},{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 n=this.create_simulation_data(e,t),a=this.jsPsych.getDisplayElement();this.trial(a,e),r();for(var s=Object.entries(n.response),o=0;o<s.length;o++){var l,u=i(s[o][1]);try{for(u.s();!(l=u.n()).done;){var c=l.value;this.jsPsych.pluginAPI.clickTarget(a.querySelector("#jspsych-survey-multi-select-response-".concat(o,"-").concat(e.questions[o].options.indexOf(c))),(n.rt-1e3)/s.length*(o+1))}}catch(e){u.e(e)}finally{u.f()}}this.jsPsych.pluginAPI.clickTarget(a.querySelector("#jspsych-survey-multi-select-next"),n.rt)}}],a&&t(n.prototype,a),s&&t(n,s),Object.defineProperty(n,"prototype",{writable:!1}),e}();return o.info=s,o}(jsPsychModule); | ||
//# sourceMappingURL=index.browser.min.js.map |
{ | ||
"name": "@jspsych/plugin-survey-multi-select", | ||
"version": "1.1.0", | ||
"version": "1.1.1", | ||
"description": "a jspsych plugin for multiple choice survey questions", | ||
@@ -40,5 +40,5 @@ "type": "module", | ||
"devDependencies": { | ||
"@jspsych/config": "^1.1.0", | ||
"@jspsych/config": "^1.3.0", | ||
"@jspsych/test-utils": "^1.1.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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
166358
1540