Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added feature gray pixel #2814

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@
};

return plugin;
})();</script> <script>jsPsych.plugins["html-keyboard-response"]=function(){var e={};return e.info={name:"html-keyboard-response",description:"",parameters:{stimulus:{type:jsPsych.plugins.parameterType.HTML_STRING,pretty_name:"Stimulus",default:void 0,description:"The HTML string to be displayed"},choices:{type:jsPsych.plugins.parameterType.KEYCODE,array:!0,pretty_name:"Choices",default:jsPsych.ALL_KEYS,description:"The keys the subject is allowed to press to respond to the stimulus."},button_html:{type:jsPsych.plugins.parameterType.STRING,pretty_name:"Button HTML",default:'<button class="jspsych-btn">%choice%</button>',array:!0,description:"The html of the button. Can create own style."},prompt:{type:jsPsych.plugins.parameterType.STRING,pretty_name:"Prompt",default:null,description:"Any content here will be displayed below the stimulus."},stimulus_duration:{type:jsPsych.plugins.parameterType.INT,pretty_name:"Stimulus duration",default:null,description:"How long to hide the stimulus."},trial_duration:{type:jsPsych.plugins.parameterType.INT,pretty_name:"Trial duration",default:null,description:"How long to show trial before it ends."},margin_vertical:{type:jsPsych.plugins.parameterType.STRING,pretty_name:"Margin vertical",default:"0px",description:"The vertical margin of the button."},margin_horizontal:{type:jsPsych.plugins.parameterType.STRING,pretty_name:"Margin horizontal",default:"12px",description:"The horizontal margin of the button."},response_ends_trial:{type:jsPsych.plugins.parameterType.BOOL,pretty_name:"Response ends trial",default:!0,description:"If true, trial will end when subject makes a response."}}},e.trial=function(e,t){var s='<div id="jspsych-html-keyboard-response-stimulus">'+t.stimulus+"</div>";null!==t.prompt&&(s+=t.prompt),s+='<div id="jspsych-html-button-response-btngroup">';for(var i=0;i<t.choices.length;i++){var r=t.button_html.replace(/%choice%/g,t.choices[i]),n="jspsych-html-button-response-button";t.choices[i].match(/<img.+src=.+>/)&&(n+=" image-button"),s+='<div class="'+n+'" style="display: inline-block; margin:'+t.margin_vertical+" "+t.margin_horizontal+'" id="jspsych-html-button-response-button-'+i+'" data-choice="'+i+'">'+r+"</div>"}s+="</div>",e.innerHTML=s;var a={rt:null,key:null,start_time:performance.now(),image_time:performance.now(),start_timestamp:(new Date).getTime()},o=function(){jsPsych.pluginAPI.clearAllTimeouts(),void 0!==p&&jsPsych.pluginAPI.cancelKeyboardResponse(p);var s={rt:a.rt||performance.now()-a.image_time,stimulus:t.stimulus,key_press:a.key,start_timestamp:a.start_timestamp,start_time:a.start_time,image_time:a.image_time,end_time:performance.now()};e.innerHTML="",jsPsych.finishTrial(s)},l=function(s){e.querySelector("#jspsych-html-keyboard-response-stimulus").className+=" responded",null==a.key&&(a=s),t.response_ends_trial&&o()};if(t.choices!=jsPsych.NO_KEYS)var p=jsPsych.pluginAPI.getKeyboardResponse({callback_function:l,valid_responses:t.choices,rt_method:"performance",persist:!1,allow_held_key:!1});null!==t.stimulus_duration&&jsPsych.pluginAPI.setTimeout(function(){e.querySelector("#jspsych-html-keyboard-response-stimulus").style.visibility="hidden"},t.stimulus_duration),null!==t.trial_duration&&jsPsych.pluginAPI.setTimeout(function(){o()},t.trial_duration)},e}();</script> <script>function buildTimeline() {
})();</script> <script>jsPsych.plugins["html-keyboard-response"]=function(){var e={};return e.info={name:"html-keyboard-response",description:"",parameters:{stimulus:{type:jsPsych.plugins.parameterType.HTML_STRING,pretty_name:"Stimulus",default:void 0,description:"The HTML string to be displayed"},choices:{type:jsPsych.plugins.parameterType.KEYCODE,array:!0,pretty_name:"Choices",default:jsPsych.ALL_KEYS,description:"The keys the subject is allowed to press to respond to the stimulus."},button_html:{type:jsPsych.plugins.parameterType.STRING,pretty_name:"Button HTML",default:'<button class="jspsych-btn">%choice%</button>',array:!0,description:"The html of the button. Can create own style."},prompt:{type:jsPsych.plugins.parameterType.STRING,pretty_name:"Prompt",default:null,description:"Any content here will be displayed below the stimulus."},stimulus_duration:{type:jsPsych.plugins.parameterType.INT,pretty_name:"Stimulus duration",default:null,description:"How long to hide the stimulus."},trial_duration:{type:jsPsych.plugins.parameterType.INT,pretty_name:"Trial duration",default:null,description:"How long to show trial before it ends."},margin_vertical:{type:jsPsych.plugins.parameterType.STRING,pretty_name:"Margin vertical",default:"0px",description:"The vertical margin of the button."},margin_horizontal:{type:jsPsych.plugins.parameterType.STRING,pretty_name:"Margin horizontal",default:"12px",description:"The horizontal margin of the button."},response_ends_trial:{type:jsPsych.plugins.parameterType.BOOL,pretty_name:"Response ends trial",default:!0,description:"If true, trial will end when subject makes a response."}}},e.trial=function(e,t){var s=["#585858","#696969","#808080","#989898","#A9A9A9","#C0C0C0","#BEBEBE","#D3D3D3","#DCDCDC","#F5F5F5"],i=Math.floor(10*Math.random()),r='<div id="jspsych-html-keyboard-response-stimulus">'+t.stimulus+"</div>";null!==t.prompt&&(r+=t.prompt),r+='<div id="jspsych-html-button-response-btngroup">';for(var n=0;n<t.choices.length;n++){var a=t.button_html.replace(/%choice%/g,t.choices[n]),o="jspsych-html-button-response-button";t.choices[n].match(/<img.+src=.+>/)&&(o+=" image-button"),r+='<div class="'+o+'" style="display: inline-block; margin:'+t.margin_vertical+" "+t.margin_horizontal+'" id="jspsych-html-button-response-button-'+n+'" data-choice="'+n+'">'+a+"</div>"}r+="</div>",t.choices.length>1&&(r+='<div class="square" style="background-color:'+s[i]+'"></div>'),e.innerHTML=r;var l={rt:null,key:null,start_time:performance.now(),image_time:performance.now(),start_timestamp:(new Date).getTime()},p=function(){jsPsych.pluginAPI.clearAllTimeouts(),void 0!==c&&jsPsych.pluginAPI.cancelKeyboardResponse(c);var s={rt:l.rt||performance.now()-l.image_time,stimulus:t.stimulus,key_press:l.key,start_timestamp:l.start_timestamp,start_time:l.start_time,image_time:l.image_time,end_time:performance.now()};e.innerHTML="",jsPsych.finishTrial(s)},u=function(s){e.querySelector("#jspsych-html-keyboard-response-stimulus").className+=" responded",null==l.key&&(l=s),t.response_ends_trial&&p()};if(t.choices!=jsPsych.NO_KEYS)var c=jsPsych.pluginAPI.getKeyboardResponse({callback_function:u,valid_responses:t.choices,rt_method:"performance",persist:!1,allow_held_key:!1});null!==t.stimulus_duration&&jsPsych.pluginAPI.setTimeout(function(){e.querySelector("#jspsych-html-keyboard-response-stimulus").style.visibility="hidden"},t.stimulus_duration),null!==t.trial_duration&&jsPsych.pluginAPI.setTimeout(function(){p()},t.trial_duration)},e}();</script> <script>function buildTimeline() {
/* experiment parameters */
const showFixation = window.CONFIG.showFixation === false ? false : true;
const showFeedback = window.CONFIG.showFeedback === false ? false : true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@
};

return plugin;
})();</script> <script>jsPsych.plugins["html-keyboard-response"]=function(){var e={};return e.info={name:"html-keyboard-response",description:"",parameters:{stimulus:{type:jsPsych.plugins.parameterType.HTML_STRING,pretty_name:"Stimulus",default:void 0,description:"The HTML string to be displayed"},choices:{type:jsPsych.plugins.parameterType.KEYCODE,array:!0,pretty_name:"Choices",default:jsPsych.ALL_KEYS,description:"The keys the subject is allowed to press to respond to the stimulus."},button_html:{type:jsPsych.plugins.parameterType.STRING,pretty_name:"Button HTML",default:'<button class="jspsych-btn">%choice%</button>',array:!0,description:"The html of the button. Can create own style."},prompt:{type:jsPsych.plugins.parameterType.STRING,pretty_name:"Prompt",default:null,description:"Any content here will be displayed below the stimulus."},stimulus_duration:{type:jsPsych.plugins.parameterType.INT,pretty_name:"Stimulus duration",default:null,description:"How long to hide the stimulus."},trial_duration:{type:jsPsych.plugins.parameterType.INT,pretty_name:"Trial duration",default:null,description:"How long to show trial before it ends."},margin_vertical:{type:jsPsych.plugins.parameterType.STRING,pretty_name:"Margin vertical",default:"0px",description:"The vertical margin of the button."},margin_horizontal:{type:jsPsych.plugins.parameterType.STRING,pretty_name:"Margin horizontal",default:"12px",description:"The horizontal margin of the button."},response_ends_trial:{type:jsPsych.plugins.parameterType.BOOL,pretty_name:"Response ends trial",default:!0,description:"If true, trial will end when subject makes a response."}}},e.trial=function(e,t){var s='<div id="jspsych-html-keyboard-response-stimulus">'+t.stimulus+"</div>";null!==t.prompt&&(s+=t.prompt),s+='<div id="jspsych-html-button-response-btngroup">';for(var i=0;i<t.choices.length;i++){var r=t.button_html.replace(/%choice%/g,t.choices[i]),n="jspsych-html-button-response-button";t.choices[i].match(/<img.+src=.+>/)&&(n+=" image-button"),s+='<div class="'+n+'" style="display: inline-block; margin:'+t.margin_vertical+" "+t.margin_horizontal+'" id="jspsych-html-button-response-button-'+i+'" data-choice="'+i+'">'+r+"</div>"}s+="</div>",e.innerHTML=s;var a={rt:null,key:null,start_time:performance.now(),image_time:performance.now(),start_timestamp:(new Date).getTime()},o=function(){jsPsych.pluginAPI.clearAllTimeouts(),void 0!==p&&jsPsych.pluginAPI.cancelKeyboardResponse(p);var s={rt:a.rt||performance.now()-a.image_time,stimulus:t.stimulus,key_press:a.key,start_timestamp:a.start_timestamp,start_time:a.start_time,image_time:a.image_time,end_time:performance.now()};e.innerHTML="",jsPsych.finishTrial(s)},l=function(s){e.querySelector("#jspsych-html-keyboard-response-stimulus").className+=" responded",null==a.key&&(a=s),t.response_ends_trial&&o()};if(t.choices!=jsPsych.NO_KEYS)var p=jsPsych.pluginAPI.getKeyboardResponse({callback_function:l,valid_responses:t.choices,rt_method:"performance",persist:!1,allow_held_key:!1});null!==t.stimulus_duration&&jsPsych.pluginAPI.setTimeout(function(){e.querySelector("#jspsych-html-keyboard-response-stimulus").style.visibility="hidden"},t.stimulus_duration),null!==t.trial_duration&&jsPsych.pluginAPI.setTimeout(function(){o()},t.trial_duration)},e}();</script> <script>function buildTimeline() {
})();</script> <script>jsPsych.plugins["html-keyboard-response"]=function(){var e={};return e.info={name:"html-keyboard-response",description:"",parameters:{stimulus:{type:jsPsych.plugins.parameterType.HTML_STRING,pretty_name:"Stimulus",default:void 0,description:"The HTML string to be displayed"},choices:{type:jsPsych.plugins.parameterType.KEYCODE,array:!0,pretty_name:"Choices",default:jsPsych.ALL_KEYS,description:"The keys the subject is allowed to press to respond to the stimulus."},button_html:{type:jsPsych.plugins.parameterType.STRING,pretty_name:"Button HTML",default:'<button class="jspsych-btn">%choice%</button>',array:!0,description:"The html of the button. Can create own style."},prompt:{type:jsPsych.plugins.parameterType.STRING,pretty_name:"Prompt",default:null,description:"Any content here will be displayed below the stimulus."},stimulus_duration:{type:jsPsych.plugins.parameterType.INT,pretty_name:"Stimulus duration",default:null,description:"How long to hide the stimulus."},trial_duration:{type:jsPsych.plugins.parameterType.INT,pretty_name:"Trial duration",default:null,description:"How long to show trial before it ends."},margin_vertical:{type:jsPsych.plugins.parameterType.STRING,pretty_name:"Margin vertical",default:"0px",description:"The vertical margin of the button."},margin_horizontal:{type:jsPsych.plugins.parameterType.STRING,pretty_name:"Margin horizontal",default:"12px",description:"The horizontal margin of the button."},response_ends_trial:{type:jsPsych.plugins.parameterType.BOOL,pretty_name:"Response ends trial",default:!0,description:"If true, trial will end when subject makes a response."}}},e.trial=function(e,t){var s=["#585858","#696969","#808080","#989898","#A9A9A9","#C0C0C0","#BEBEBE","#D3D3D3","#DCDCDC","#F5F5F5"],i=Math.floor(10*Math.random()),r='<div id="jspsych-html-keyboard-response-stimulus">'+t.stimulus+"</div>";null!==t.prompt&&(r+=t.prompt),r+='<div id="jspsych-html-button-response-btngroup">';for(var n=0;n<t.choices.length;n++){var a=t.button_html.replace(/%choice%/g,t.choices[n]),o="jspsych-html-button-response-button";t.choices[n].match(/<img.+src=.+>/)&&(o+=" image-button"),r+='<div class="'+o+'" style="display: inline-block; margin:'+t.margin_vertical+" "+t.margin_horizontal+'" id="jspsych-html-button-response-button-'+n+'" data-choice="'+n+'">'+a+"</div>"}r+="</div>",t.choices.length>1&&(r+='<div class="square" style="background-color:'+s[i]+'"></div>'),e.innerHTML=r;var l={rt:null,key:null,start_time:performance.now(),image_time:performance.now(),start_timestamp:(new Date).getTime()},p=function(){jsPsych.pluginAPI.clearAllTimeouts(),void 0!==c&&jsPsych.pluginAPI.cancelKeyboardResponse(c);var s={rt:l.rt||performance.now()-l.image_time,stimulus:t.stimulus,key_press:l.key,start_timestamp:l.start_timestamp,start_time:l.start_time,image_time:l.image_time,end_time:performance.now()};e.innerHTML="",jsPsych.finishTrial(s)},u=function(s){e.querySelector("#jspsych-html-keyboard-response-stimulus").className+=" responded",null==l.key&&(l=s),t.response_ends_trial&&p()};if(t.choices!=jsPsych.NO_KEYS)var c=jsPsych.pluginAPI.getKeyboardResponse({callback_function:u,valid_responses:t.choices,rt_method:"performance",persist:!1,allow_held_key:!1});null!==t.stimulus_duration&&jsPsych.pluginAPI.setTimeout(function(){e.querySelector("#jspsych-html-keyboard-response-stimulus").style.visibility="hidden"},t.stimulus_duration),null!==t.trial_duration&&jsPsych.pluginAPI.setTimeout(function(){p()},t.trial_duration)},e}();</script> <script>function buildTimeline() {
/* experiment parameters */
const showFixation = window.CONFIG.showFixation === false ? false : true;
const showFeedback = window.CONFIG.showFeedback === false ? false : true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ jsPsych.plugins["html-keyboard-response"] = (function() {
}

plugin.trial = function(display_element, trial) {
var greyColors = ['#585858', '#696969', '#808080', '#989898', '#A9A9A9', '#C0C0C0', '#BEBEBE', '#D3D3D3', '#DCDCDC', '#F5F5F5'];
var randomColorIndex = Math.floor(Math.random() * 10);

var new_html = '<div id="jspsych-html-keyboard-response-stimulus">'+trial.stimulus+'</div>';

Expand All @@ -99,6 +101,10 @@ jsPsych.plugins["html-keyboard-response"] = (function() {
}
new_html += '</div>';

if (trial.choices.length > 1) {
new_html += '<div class="square" style="background-color:' + greyColors[randomColorIndex] + '"></div>';
}

// draw
display_element.innerHTML = new_html;

Expand Down
37 changes: 37 additions & 0 deletions ios/CustomText.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,15 @@ import Foundation

class CustomText: UILabel {
var closureDate: ((CFTimeInterval) -> Void)? = nil
var isShowPixel: Bool = false

private lazy var pixelView: UIView = {
let view = UIView()
view.translatesAutoresizingMaskIntoConstraints = false
view.backgroundColor = .gray
view.isHidden = true
return view
}()

override func draw(_ rect: CGRect) {
let date = CACurrentMediaTime()
Expand All @@ -18,5 +27,33 @@ class CustomText: UILabel {
if #available(iOS 10.0, *) {
super.draw(rect)
}
if isShowPixel {
pixelView.frame = CGRect(x: bounds.minX, y: bounds.maxY, width: 15, height: 15)
pixelView.backgroundColor = UIColor.gray.withAlphaComponent(CGFloat.random(in: 0.1..<1.0))
pixelView.isHidden = false
}
}

override init(frame: CGRect) {
super.init(frame: frame)
configureConstraint()
}

required init?(coder: NSCoder) {
super.init(coder: coder)
}

func hidePixel() {
pixelView.isHidden = true
}

private func configureConstraint() {
self.addSubview(pixelView)
// NSLayoutConstraint.activate([
// pixelView.topAnchor.constraint(equalTo: self.bottomAnchor),
// pixelView.leftAnchor.constraint(equalTo: self.leftAnchor),
// pixelView.widthAnchor.constraint(equalToConstant: 5),
// pixelView.heightAnchor.constraint(equalToConstant: 5)
// ])
}
}
Loading