mirror of
https://github.com/jspsych/jsPsych.git
synced 2025-05-10 19:20:55 +00:00
moving stimulus creation to a separate public function so that stimuli can be generated for other plugins
This commit is contained in:
parent
eb60da88e1
commit
03f70efbe2
@ -50,63 +50,11 @@
|
|||||||
|
|
||||||
plugin.trial = function(display_element, block, trial, part) {
|
plugin.trial = function(display_element, block, trial, part) {
|
||||||
|
|
||||||
var nrows = trial.stimuli.length;
|
display_element.html(plugin.generate_stimulus(trial.stimuli, trial.image_size));
|
||||||
var ncols = trial.stimuli[0].length;
|
|
||||||
|
|
||||||
// create table
|
setTimeout(function() {
|
||||||
display_element.append($('<table>', {
|
endTrial();
|
||||||
id: 'jspsych-vsl-grid-scene-table',
|
}, trial.timing_duration);
|
||||||
css: {
|
|
||||||
'border-collapse': 'collapse',
|
|
||||||
'margin-left': 'auto',
|
|
||||||
'margin-right': 'auto'
|
|
||||||
}
|
|
||||||
}));
|
|
||||||
|
|
||||||
for (var row = 0; row < nrows; row++) {
|
|
||||||
$("#jspsych-vsl-grid-scene-table").append($('<tr>', {
|
|
||||||
id: 'jspsych-vsl-grid-scene-table-row-' + row,
|
|
||||||
css: {
|
|
||||||
height: trial.image_size[1] + "px"
|
|
||||||
}
|
|
||||||
}));
|
|
||||||
for (var col = 0; col < ncols; col++) {
|
|
||||||
$("#jspsych-vsl-grid-scene-table-row-" + row).append($('<td>', {
|
|
||||||
id: 'jspsych-vsl-grid-scene-table-' + row + '-' + col,
|
|
||||||
css: {
|
|
||||||
padding: trial.image_size[1] / 10 + "px " + trial.image_size[0] / 10 + "px",
|
|
||||||
border: '1px solid #555'
|
|
||||||
}
|
|
||||||
}));
|
|
||||||
$('#jspsych-vsl-grid-scene-table-' + row + '-' + col).append($('<div>', {
|
|
||||||
id: 'jspsych-vsl-grid-scene-table-cell-' + row + '-' + col,
|
|
||||||
css: {
|
|
||||||
width: trial.image_size[0] + "px",
|
|
||||||
height: trial.image_size[1] + "px"
|
|
||||||
}
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function fill_table(pattern) {
|
|
||||||
for (var row = 0; row < nrows; row++) {
|
|
||||||
for (var col = 0; col < ncols; col++) {
|
|
||||||
if (pattern[row][col] !== 0) {
|
|
||||||
$('#jspsych-vsl-grid-scene-table-cell-' + row + '-' + col).append($('<img>', {
|
|
||||||
src: pattern[row][col],
|
|
||||||
css: {
|
|
||||||
width: trial.image_size[0] + "px",
|
|
||||||
height: trial.image_size[1] + "px",
|
|
||||||
}
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fill_table(trial.stimuli);
|
|
||||||
|
|
||||||
setTimeout(function(){ endTrial(); }, trial.timing_duration);
|
|
||||||
|
|
||||||
function endTrial() {
|
function endTrial() {
|
||||||
|
|
||||||
@ -129,6 +77,75 @@
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
plugin.generate_stimulus = function(pattern, image_size) {
|
||||||
|
var nrows = pattern.length;
|
||||||
|
var ncols = pattern[0].length;
|
||||||
|
|
||||||
|
// create blank element to hold code that we generate
|
||||||
|
$('body').append($('<div>', {
|
||||||
|
id: 'jspsych-vsl-grid-scene-dummy',
|
||||||
|
css: {
|
||||||
|
display: 'none'
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
|
||||||
|
// create table
|
||||||
|
$('#jspsych-vsl-grid-scene-dummy').append($('<table>', {
|
||||||
|
id: 'jspsych-vsl-grid-scene-table',
|
||||||
|
css: {
|
||||||
|
'border-collapse': 'collapse',
|
||||||
|
'margin-left': 'auto',
|
||||||
|
'margin-right': 'auto'
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
|
||||||
|
for (var row = 0; row < nrows; row++) {
|
||||||
|
$("#jspsych-vsl-grid-scene-table").append($('<tr>', {
|
||||||
|
id: 'jspsych-vsl-grid-scene-table-row-' + row,
|
||||||
|
css: {
|
||||||
|
height: image_size[1] + "px"
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
for (var col = 0; col < ncols; col++) {
|
||||||
|
$("#jspsych-vsl-grid-scene-table-row-" + row).append($('<td>', {
|
||||||
|
id: 'jspsych-vsl-grid-scene-table-' + row + '-' + col,
|
||||||
|
css: {
|
||||||
|
padding: image_size[1] / 10 + "px " + image_size[0] / 10 + "px",
|
||||||
|
border: '1px solid #555'
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
$('#jspsych-vsl-grid-scene-table-' + row + '-' + col).append($('<div>', {
|
||||||
|
id: 'jspsych-vsl-grid-scene-table-cell-' + row + '-' + col,
|
||||||
|
css: {
|
||||||
|
width: image_size[0] + "px",
|
||||||
|
height: image_size[1] + "px"
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
for (var row = 0; row < nrows; row++) {
|
||||||
|
for (var col = 0; col < ncols; col++) {
|
||||||
|
if (pattern[row][col] !== 0) {
|
||||||
|
$('#jspsych-vsl-grid-scene-table-cell-' + row + '-' + col).append($('<img>', {
|
||||||
|
src: pattern[row][col],
|
||||||
|
css: {
|
||||||
|
width: image_size[0] + "px",
|
||||||
|
height: image_size[1] + "px",
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var html_out = $('#jspsych-vsl-grid-scene-dummy').html();
|
||||||
|
$('#jspsych-vsl-grid-scene-dummy').remove();
|
||||||
|
|
||||||
|
return html_out;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
return plugin;
|
return plugin;
|
||||||
})();
|
})();
|
||||||
})(jQuery);
|
})(jQuery);
|
Loading…
Reference in New Issue
Block a user