Free javascript Hosting


plugin-iat-image.js

Uploaded on May 17 2022 00:52 by gegtwetg

var jsPsychIatImage=function(e){"use strict";const t={name:"iat-image",parameters:{stimulus:{type:e.ParameterType.IMAGE,pretty_name:"Stimulus",default:void 0},left_category_key:{type:e.ParameterType.KEY,pretty_name:"Left category key",default:"e"},right_category_key:{type:e.ParameterType.KEY,pretty_name:"Right category key",default:"i"},left_category_label:{type:e.ParameterType.STRING,pretty_name:"Left category label",array:!0,default:["left"]},right_category_label:{type:e.ParameterType.STRING,pretty_name:"Right category label",array:!0,default:["right"]},key_to_move_forward:{type:e.ParameterType.KEYS,pretty_name:"Key to move forward",default:"ALL_KEYS"},display_feedback:{type:e.ParameterType.BOOL,pretty_name:"Display feedback",default:!1},html_when_wrong:{type:e.ParameterType.HTML_STRING,pretty_name:"HTML when wrong",default:'<span style="color: red; font-size: 80px">X</span>'},bottom_instructions:{type:e.ParameterType.HTML_STRING,pretty_name:"Bottom instructions",default:"<p>If you press the wrong key, a red X will appear. Press any key to continue.</p>"},force_correct_key_press:{type:e.ParameterType.BOOL,pretty_name:"Force correct key press",default:!1},stim_key_association:{type:e.ParameterType.SELECT,pretty_name:"Stimulus key association",options:["left","right"],default:void 0},response_ends_trial:{type:e.ParameterType.BOOL,pretty_name:"Response ends trial",default:!0},trial_duration:{type:e.ParameterType.INT,pretty_name:"Trial duration",default:null}}};class s{constructor(e){this.jsPsych=e}trial(e,t){var s="";s+="<div style='position: absolute; height: 20%; width: 100%; margin-left: auto; margin-right: auto; top: 42%; left: 0; right: 0'><img src='"+t.stimulus+"' id='jspsych-iat-stim'></img></div>",s+="<div id='trial_left_align' style='position: absolute; top: 10%; left: 10%'>",1==t.left_category_label.length?s+="<p>Press "+t.left_category_key+" for:<br> "+t.left_category_label[0].bold()+"</p></div>":s+="<p>Press "+t.left_category_key+" for:<br> "+t.left_category_label[0].bold()+"<br>or<br>"+t.left_category_label[1].bold()+"</p></div>",s+="<div id='trial_right_align' style='position: absolute; top: 10%; right: 10%'>",1==t.right_category_label.length?s+="<p>Press "+t.right_category_key+" for:<br> "+t.right_category_label[0].bold()+"</p></div>":s+="<p>Press "+t.right_category_key+" for:<br> "+t.right_category_label[0].bold()+"<br>or<br>"+t.right_category_label[1].bold()+"</p></div>",s+="<div id='wrongImgID' style='position:relative; top: 300px; margin-left: auto; margin-right: auto; left: 0; right: 0'>",!0===t.display_feedback?(s+="<div id='wrongImgContainer' style='visibility: hidden; position: absolute; top: -75px; margin-left: auto; margin-right: auto; left: 0; right: 0'><p>"+t.html_when_wrong+"</p></div>",s+="<div>"+t.bottom_instructions+"</div>"):s+="<div>"+t.bottom_instructions+"</div>",s+="</div>",e.innerHTML=s;var r={rt:null,key:null,correct:!1};const a=()=>{this.jsPsych.pluginAPI.clearAllTimeouts(),void 0!==y&&this.jsPsych.pluginAPI.cancelKeyboardResponse(y);var s={rt:r.rt,stimulus:t.stimulus,responser.key,correct:r.correct};e.innerHTML="",this.jsPsych.finishTrial(s)};var i=t.left_category_key,l=t.right_category_key;const o=s=>{var o=document.getElementById("wrongImgContainer");e.querySelector("#jspsych-iat-stim").className+=" responded",null==r.key&&(r.key=s.key,r.rt=s.rt),"right"==t.stim_key_association?null!==r.rt&&this.jsPsych.pluginAPI.compareKeys(r.key,l)?(r.correct=!0,t.response_ends_trial&&a()):(r.correct=!1,t.response_ends_trial||1!=t.display_feedback||(o.style.visibility="visible"),t.response_ends_trial&&1==t.display_feedback?(o.style.visibility="visible",t.force_correct_key_press?this.jsPsych.pluginAPI.getKeyboardResponse({callback_function:a,valid_responses:[t.right_category_key]}):this.jsPsych.pluginAPI.getKeyboardResponse({callback_function:a,valid_responses:t.key_to_move_forward})):t.response_ends_trial&&1!=t.display_feedback?a():!t.response_ends_trial&&t.display_feedback):"left"==t.stim_key_association&&(null!==r.rt&&this.jsPsych.pluginAPI.compareKeys(r.key,i)?(r.correct=!0,t.response_ends_trial&&a()):(r.correct=!1,t.response_ends_trial||1!=t.display_feedback||(o.style.visibility="visible"),t.response_ends_trial&&1==t.display_feedback?(o.style.visibility="visible",t.force_correct_key_press?this.jsPsych.pluginAPI.getKeyboardResponse({callback_function:a,valid_responses:[t.left_category_key]}):this.jsPsych.pluginAPI.getKeyboardResponse({callback_function:a,valid_responses:t.key_to_move_forward})):t.response_ends_trial&&1!=t.display_feedback?a():!t.response_ends_trial&&t.display_feedback))};if("NO_KEYS"!=t.left_category_key&&"NO_KEYS"!=t.right_category_key)var y=this.jsPsych.pluginAPI.getKeyboardResponse({callback_function:o,valid_responses:[t.left_category_key,t.right_category_key],rt_method:"performance",persist:!1,allow_held_key:!1});null!==t.trial_duration&&1!=t.response_ends_trial&&this.jsPsych.pluginAPI.setTimeout((()=>{a()}),t.trial_duration)}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=this.jsPsych.pluginAPI.getValidKey([e.left_category_key,e.right_category_key]),r="left"==e.stim_key_association?s==e.left_category_key:s==e.right_category_key,a={stimulus:e.stimulus,response:s,rt:this.jsPsych.randomization.sampleExGaussian(500,50,1/150,!0),correct:r},i=this.jsPsych.pluginAPI.mergeSimulationData(a,t);return this.jsPsych.pluginAPI.ensureSimulationDataConsistency(e,i),i}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),a=this.jsPsych.getDisplayElement();this.trial(a,e),s(),null!==r.response&&this.jsPsych.pluginAPI.pressKey(r.response,r.rt);const i=null==r.rt?e.trial_duration:r.rt;e.force_correct_key_press?r.correct||this.jsPsych.pluginAPI.pressKey("left"==e.stim_key_association?e.left_category_key:e.right_category_key,i+this.jsPsych.randomization.sampleExGaussian(500,50,1/150,!0)):this.jsPsych.pluginAPI.pressKey(this.jsPsych.pluginAPI.getValidKey(e.key_to_move_forward),i+this.jsPsych.randomization.sampleExGaussian(500,50,1/150,!0))}}return s.info=t,s}(jsPsychModule);

Back to list