mirror of
https://github.com/jspsych/jsPsych.git
synced 2025-05-10 11:10:54 +00:00
1.8 KiB
1.8 KiB
@jspsych/plugin-audio-button-response | @jspsych/plugin-canvas-button-response | @jspsych/plugin-html-button-response | @jspsych/plugin-image-button-response | @jspsych/plugin-video-button-response |
---|---|---|---|---|
major | major | major | major | major |
- Make
button_html
a function parameter which, given a choice's text and its index, returns the HTML string of the choice's button. If you were previously passing a string tobutton_html
, like<button>%choice%</button>
, you can now pass the function
Similarly, if you were using the array syntax, likefunction (choice) { return '<button class="jspsych-btn">' + choice + "</button>"; }
an easy way to migrate your trial definition is to pass a function which accesses your array and replaces the['<button class="a">%choice%</button>', '<button class="b">%choice%</button>', '<button class="a">%choice%</button>']
%choice%
placeholder:
From there on, you can further simplify your function. For instance, if the intention of the above example is to have alternating button classes, thefunction (choice, choice_index) { return ['<button class="a">%choice%</button>', '<button class="b">%choice%</button>', '<button class="a">%choice%</button>'][choice_index].replace("%choice%", choice); }
button_html
function might be rewritten asfunction (choice, choice_index) { return '<button class="' + (choice_index % 2 === 0 ? "a" : "b") + '">' + choice + "</button>"; }
- Simplify the button DOM structure and styling: Buttons are no longer wrapped in individual container
div
s for spacing anddata-choice
attributes. Instead, each button is assigned itsdata-choice
attribute and all buttons are direct children of the button group containerdiv
. The containerdiv
, in turn, utilizes a flexbox layout to position the buttons.