UNPKG

@jspsych/plugin-survey-html-form

Version:
3 lines (2 loc) 3.18 kB
var jsPsychSurveyHtmlForm=function(t){"use strict";var p={name:"@jspsych/plugin-survey-html-form",version:"2.0.0",description:"a jspsych plugin for free html forms",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-html-form"},author:"Jan Simson",license:"MIT",bugs:{url:"https://github.com/jspsych/jsPsych/issues"},homepage:"https://www.jspsych.org/latest/plugins/survey-html-form",peerDependencies:{jspsych:">=7.1.0"},devDependencies:{"@jspsych/config":"^3.0.0","@jspsych/test-utils":"^1.2.0"}};const c={name:"survey-html-form",version:p.version,parameters:{html:{type:t.ParameterType.HTML_STRING,default:null},preamble:{type:t.ParameterType.HTML_STRING,default:null},button_label:{type:t.ParameterType.STRING,default:"Continue"},autofocus:{type:t.ParameterType.STRING,default:""},dataAsArray:{type:t.ParameterType.BOOL,default:!1},autocomplete:{type:t.ParameterType.BOOL,default:!1}},data:{response:{type:t.ParameterType.COMPLEX,nested:{identifier:{type:t.ParameterType.STRING},response:{type:t.ParameterType.STRING|t.ParameterType.INT|t.ParameterType.FLOAT|t.ParameterType.BOOL|t.ParameterType.OBJECT}}},rt:{type:t.ParameterType.INT}}};class m{constructor(l){this.jsPsych=l}trial(l,r){var u="";if(r.preamble!==null&&(u+='<div id="jspsych-survey-html-form-preamble" class="jspsych-survey-html-form-preamble">'+r.preamble+"</div>"),r.autocomplete?u+='<form id="jspsych-survey-html-form">':u+='<form id="jspsych-survey-html-form" autocomplete="off">',u+=r.html,u+='<input type="submit" id="jspsych-survey-html-form-next" class="jspsych-btn jspsych-survey-html-form" value="'+r.button_label+'"></input>',u+="</form>",l.innerHTML=u,r.autofocus!==""){var i=l.querySelectorAll("#"+r.autofocus);i.length===0?console.warn("No element found with id: "+r.autofocus):i.length>1?console.warn('The id "'+r.autofocus+'" is not unique so autofocus will not work.'):i[0].focus()}l.querySelector("#jspsych-survey-html-form").addEventListener("submit",a=>{a.preventDefault();var o=performance.now(),s=Math.round(o-y),e=l.querySelector("#jspsych-survey-html-form"),n=f(e);r.dataAsArray||(n=h(n));var d={rt:s,response:n};this.jsPsych.finishTrial(d)});var y=performance.now();function f(a){for(var o=[],s=0;s<a.elements.length;s++){var e=a.elements[s];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||o.push({name:e.name,value:e.options[n].value});else(e.type!=="checkbox"&&e.type!=="radio"||e.checked)&&o.push({name:e.name,value:e.value})}return o}function h(a){for(var o={},s=0;s<a.length;s++)o[a[s].name]=a[s].value;return o}}}return m.info=c,m}(jsPsychModule); //# sourceMappingURL=https://unpkg.com/@jspsych/plugin-survey-html-form@2.0.0/dist/index.browser.min.js.map