@jspsych/plugin-image-keyboard-response
Advanced tools
Comparing version
@@ -1,2 +0,2 @@ | ||
var jsPsychImageKeyboardResponse=function(t){"use strict";const e={name:"image-keyboard-response",parameters:{stimulus:{type:t.ParameterType.IMAGE,pretty_name:"Stimulus",default:void 0},stimulus_height:{type:t.ParameterType.INT,pretty_name:"Image height",default:null},stimulus_width:{type:t.ParameterType.INT,pretty_name:"Image width",default:null},maintain_aspect_ratio:{type:t.ParameterType.BOOL,pretty_name:"Maintain aspect ratio",default:!0},choices:{type:t.ParameterType.KEYS,pretty_name:"Choices",default:"ALL_KEYS"},prompt:{type:t.ParameterType.HTML_STRING,pretty_name:"Prompt",default:null},stimulus_duration:{type:t.ParameterType.INT,pretty_name:"Stimulus duration",default:null},trial_duration:{type:t.ParameterType.INT,pretty_name:"Trial duration",default:null},response_ends_trial:{type:t.ParameterType.BOOL,pretty_name:"Response ends trial",default:!0},render_on_canvas:{type:t.ParameterType.BOOL,pretty_name:"Render on canvas",default:!0}}};class s{constructor(t){this.jsPsych=t}trial(t,e){var s,i;if(e.render_on_canvas){var a=!1;if(t.hasChildNodes())for(;t.firstChild;)t.removeChild(t.firstChild);var l=document.createElement("canvas");l.id="jspsych-image-keyboard-response-stimulus",l.style.margin="0",l.style.padding="0";var r=l.getContext("2d");(u=new Image).onload=()=>{a||(n(),r.drawImage(u,0,0,i,s))},u.src=e.stimulus;const n=()=>{null!==e.stimulus_height?(s=e.stimulus_height,null==e.stimulus_width&&e.maintain_aspect_ratio&&(i=u.naturalWidth*(e.stimulus_height/u.naturalHeight))):s=u.naturalHeight,null!==e.stimulus_width?(i=e.stimulus_width,null==e.stimulus_height&&e.maintain_aspect_ratio&&(s=u.naturalHeight*(e.stimulus_width/u.naturalWidth))):null!==e.stimulus_height&&e.maintain_aspect_ratio||(i=u.naturalWidth),l.height=s,l.width=i};n(),t.insertBefore(l,null),u.complete&&Number.isFinite(i)&&Number.isFinite(s)&&(r.drawImage(u,0,0,i,s),a=!0),null!==e.prompt&&t.insertAdjacentHTML("beforeend",e.prompt)}else{var n='<img src="'+e.stimulus+'" id="jspsych-image-keyboard-response-stimulus">';null!==e.prompt&&(n+=e.prompt),t.innerHTML=n;var u=t.querySelector("#jspsych-image-keyboard-response-stimulus");null!==e.stimulus_height?(s=e.stimulus_height,null==e.stimulus_width&&e.maintain_aspect_ratio&&(i=u.naturalWidth*(e.stimulus_height/u.naturalHeight))):s=u.naturalHeight,null!==e.stimulus_width?(i=e.stimulus_width,null==e.stimulus_height&&e.maintain_aspect_ratio&&(s=u.naturalHeight*(e.stimulus_width/u.naturalWidth))):null!==e.stimulus_height&&e.maintain_aspect_ratio||(i=u.naturalWidth),u.style.height=s.toString()+"px",u.style.width=i.toString()+"px"}var m={rt:null,key:null};const o=()=>{this.jsPsych.pluginAPI.clearAllTimeouts(),void 0!==h&&this.jsPsych.pluginAPI.cancelKeyboardResponse(h);var s={rt:m.rt,stimulus:e.stimulus,response:m.key};t.innerHTML="",this.jsPsych.finishTrial(s)};if("NO_KEYS"!=e.choices)var h=this.jsPsych.pluginAPI.getKeyboardResponse({callback_function:s=>{t.querySelector("#jspsych-image-keyboard-response-stimulus").className+=" responded",null==m.key&&(m=s),e.response_ends_trial&&o()},valid_responses:e.choices,rt_method:"performance",persist:!1,allow_held_key:!1});null!==e.stimulus_duration&&this.jsPsych.pluginAPI.setTimeout((()=>{t.querySelector("#jspsych-image-keyboard-response-stimulus").style.visibility="hidden"}),e.stimulus_duration),null!==e.trial_duration?this.jsPsych.pluginAPI.setTimeout((()=>{o()}),e.trial_duration):!1===e.response_ends_trial&&console.warn("The experiment may be deadlocked. Try setting a trial duration or set response_ends_trial to true.")}simulate(t,e,s,i){"data-only"==e&&(i(),this.simulate_data_only(t,s)),"visual"==e&&this.simulate_visual(t,s,i)}simulate_data_only(t,e){const s=this.create_simulation_data(t,e);this.jsPsych.finishTrial(s)}simulate_visual(t,e,s){const i=this.create_simulation_data(t,e),a=this.jsPsych.getDisplayElement();this.trial(a,t),s(),null!==i.rt&&this.jsPsych.pluginAPI.pressKey(i.response,i.rt)}create_simulation_data(t,e){const s={stimulus:t.stimulus,rt:this.jsPsych.randomization.sampleExGaussian(500,50,1/150,!0),response:this.jsPsych.pluginAPI.getValidKey(t.choices)},i=this.jsPsych.pluginAPI.mergeSimulationData(s,e);return this.jsPsych.pluginAPI.ensureSimulationDataConsistency(t,i),i}}return s.info=e,s}(jsPsychModule); | ||
var jsPsychImageKeyboardResponse=function(t){"use strict";function e(t,e){for(var i=0;i<e.length;i++){var s=e[i];s.enumerable=s.enumerable||!1,s.configurable=!0,"value"in s&&(s.writable=!0),Object.defineProperty(t,s.key,s)}}var i={name:"image-keyboard-response",parameters:{stimulus:{type:t.ParameterType.IMAGE,pretty_name:"Stimulus",default:void 0},stimulus_height:{type:t.ParameterType.INT,pretty_name:"Image height",default:null},stimulus_width:{type:t.ParameterType.INT,pretty_name:"Image width",default:null},maintain_aspect_ratio:{type:t.ParameterType.BOOL,pretty_name:"Maintain aspect ratio",default:!0},choices:{type:t.ParameterType.KEYS,pretty_name:"Choices",default:"ALL_KEYS"},prompt:{type:t.ParameterType.HTML_STRING,pretty_name:"Prompt",default:null},stimulus_duration:{type:t.ParameterType.INT,pretty_name:"Stimulus duration",default:null},trial_duration:{type:t.ParameterType.INT,pretty_name:"Trial duration",default:null},response_ends_trial:{type:t.ParameterType.BOOL,pretty_name:"Response ends trial",default:!0},render_on_canvas:{type:t.ParameterType.BOOL,pretty_name:"Render on canvas",default:!0}}},s=function(){function t(e){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this.jsPsych=e}var i,s,a;return i=t,s=[{key:"trial",value:function(t,e){var i,s,a=this;if(e.render_on_canvas){var n=!1;if(t.hasChildNodes())for(;t.firstChild;)t.removeChild(t.firstChild);var r=document.createElement("canvas");r.id="jspsych-image-keyboard-response-stimulus",r.style.margin="0",r.style.padding="0";var l=r.getContext("2d");(m=new Image).onload=function(){n||(u(),l.drawImage(m,0,0,s,i))},m.src=e.stimulus;var u=function(){null!==e.stimulus_height?(i=e.stimulus_height,null==e.stimulus_width&&e.maintain_aspect_ratio&&(s=m.naturalWidth*(e.stimulus_height/m.naturalHeight))):i=m.naturalHeight,null!==e.stimulus_width?(s=e.stimulus_width,null==e.stimulus_height&&e.maintain_aspect_ratio&&(i=m.naturalHeight*(e.stimulus_width/m.naturalWidth))):null!==e.stimulus_height&&e.maintain_aspect_ratio||(s=m.naturalWidth),r.height=i,r.width=s};u(),t.insertBefore(r,null),m.complete&&Number.isFinite(s)&&Number.isFinite(i)&&(l.drawImage(m,0,0,s,i),n=!0),null!==e.prompt&&t.insertAdjacentHTML("beforeend",e.prompt)}else{var o='<img src="'+e.stimulus+'" id="jspsych-image-keyboard-response-stimulus">';null!==e.prompt&&(o+=e.prompt),t.innerHTML=o;var m=t.querySelector("#jspsych-image-keyboard-response-stimulus");null!==e.stimulus_height?(i=e.stimulus_height,null==e.stimulus_width&&e.maintain_aspect_ratio&&(s=m.naturalWidth*(e.stimulus_height/m.naturalHeight))):i=m.naturalHeight,null!==e.stimulus_width?(s=e.stimulus_width,null==e.stimulus_height&&e.maintain_aspect_ratio&&(i=m.naturalHeight*(e.stimulus_width/m.naturalWidth))):null!==e.stimulus_height&&e.maintain_aspect_ratio||(s=m.naturalWidth),m.style.height=i.toString()+"px",m.style.width=s.toString()+"px"}var h={rt:null,key:null},p=function(){a.jsPsych.pluginAPI.clearAllTimeouts(),void 0!==d&&a.jsPsych.pluginAPI.cancelKeyboardResponse(d);var i={rt:h.rt,stimulus:e.stimulus,response:h.key};t.innerHTML="",a.jsPsych.finishTrial(i)};if("NO_KEYS"!=e.choices)var d=this.jsPsych.pluginAPI.getKeyboardResponse({callback_function:function(i){t.querySelector("#jspsych-image-keyboard-response-stimulus").className+=" responded",null==h.key&&(h=i),e.response_ends_trial&&p()},valid_responses:e.choices,rt_method:"performance",persist:!1,allow_held_key:!1});null!==e.stimulus_duration&&this.jsPsych.pluginAPI.setTimeout((function(){t.querySelector("#jspsych-image-keyboard-response-stimulus").style.visibility="hidden"}),e.stimulus_duration),null!==e.trial_duration?this.jsPsych.pluginAPI.setTimeout((function(){p()}),e.trial_duration):!1===e.response_ends_trial&&console.warn("The experiment may be deadlocked. Try setting a trial duration or set response_ends_trial to true.")}},{key:"simulate",value:function(t,e,i,s){"data-only"==e&&(s(),this.simulate_data_only(t,i)),"visual"==e&&this.simulate_visual(t,i,s)}},{key:"simulate_data_only",value:function(t,e){var i=this.create_simulation_data(t,e);this.jsPsych.finishTrial(i)}},{key:"simulate_visual",value:function(t,e,i){var s=this.create_simulation_data(t,e),a=this.jsPsych.getDisplayElement();this.trial(a,t),i(),null!==s.rt&&this.jsPsych.pluginAPI.pressKey(s.response,s.rt)}},{key:"create_simulation_data",value:function(t,e){var i={stimulus:t.stimulus,rt:this.jsPsych.randomization.sampleExGaussian(500,50,1/150,!0),response:this.jsPsych.pluginAPI.getValidKey(t.choices)},s=this.jsPsych.pluginAPI.mergeSimulationData(i,e);return this.jsPsych.pluginAPI.ensureSimulationDataConsistency(t,s),s}}],s&&e(i.prototype,s),a&&e(i,a),Object.defineProperty(i,"prototype",{writable:!1}),t}();return s.info=i,s}(jsPsychModule); | ||
//# sourceMappingURL=index.browser.min.js.map |
{ | ||
"name": "@jspsych/plugin-image-keyboard-response", | ||
"version": "1.1.0", | ||
"version": "1.1.1", | ||
"description": "jsPsych plugin for displaying a stimulus and getting a keyboard response", | ||
@@ -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
139942
2.43%1416
0.14%