UNPKG

@jspsych/plugin-survey-html-form

Version:
3 lines (2 loc) 2.93 kB
var jsPsychSurveyHtmlForm=function(a){"use strict";var p="2.1.0";const c={name:"survey-html-form",version:p,parameters:{html:{type:a.ParameterType.HTML_STRING,default:null},preamble:{type:a.ParameterType.HTML_STRING,default:null},button_label:{type:a.ParameterType.STRING,default:"Continue"},autofocus:{type:a.ParameterType.STRING,default:""},dataAsArray:{type:a.ParameterType.BOOL,default:!1},autocomplete:{type:a.ParameterType.BOOL,default:!1}},data:{response:{type:a.ParameterType.OBJECT},rt:{type:a.ParameterType.INT}},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 i{constructor(l){this.jsPsych=l}trial(l,t){var u="";if(t.preamble!==null&&(u+='<div id="jspsych-survey-html-form-preamble" class="jspsych-survey-html-form-preamble">'+t.preamble+"</div>"),t.autocomplete?u+='<form id="jspsych-survey-html-form">':u+='<form id="jspsych-survey-html-form" autocomplete="off">',u+=t.html,u+='<input type="submit" id="jspsych-survey-html-form-next" class="jspsych-btn jspsych-survey-html-form" value="'+t.button_label+'"></input>',u+="</form>",l.innerHTML=u,t.autofocus!==""){var m=l.querySelectorAll("#"+t.autofocus);m.length===0?console.warn("No element found with id: "+t.autofocus):m.length>1?console.warn('The id "'+t.autofocus+'" is not unique so autofocus will not work.'):m[0].focus()}l.querySelector("#jspsych-survey-html-form").addEventListener("submit",o=>{o.preventDefault();var s=performance.now(),r=Math.round(s-y),e=l.querySelector("#jspsych-survey-html-form"),n=f(e);t.dataAsArray||(n=h(n));var v={rt:r,response:n};this.jsPsych.finishTrial(v)});var y=performance.now();function f(o){for(var s=[],r=0;r<o.elements.length;r++){var e=o.elements[r];if(!(!e.name||e.disabled||e.type==="file"||e.type==="reset"||e.type==="submit"||e.type==="button"))if(e.type==="select-multiple")for(var n=0;n<e.options.length;n++)e.options[n].selected&&s.push({name:e.name,value:e.options[n].value});else(e.type!=="checkbox"&&e.type!=="radio"||e.checked)&&s.push({name:e.name,value:e.value})}return s}function h(o){for(var s={},r=0;r<o.length;r++)s[o[r].name]=o[r].value;return s}}}return i.info=c,i}(jsPsychModule); //# sourceMappingURL=https://unpkg.com/@jspsych/plugin-survey-html-form@2.1.0/dist/index.browser.min.js.map