mirror of
https://github.com/jspsych/jsPsych.git
synced 2025-05-11 16:18:11 +00:00
first draft of #832
This commit is contained in:
parent
42962039af
commit
f6ac098b4c
10
jspsych.js
10
jspsych.js
@ -262,6 +262,11 @@ window.jsPsych = (function() {
|
||||
if(current_trial_finished){ return; }
|
||||
current_trial_finished = true;
|
||||
|
||||
// remove any CSS classes that were added to the DOM via css_classes parameter
|
||||
if(typeof current_trial.css_classes !== 'undefined' && Array.isArray(current_trial.css_classes)){
|
||||
DOM_target.classList.remove(...current_trial.css_classes);
|
||||
}
|
||||
|
||||
// write the data from the trial
|
||||
data = typeof data == 'undefined' ? {} : data;
|
||||
jsPsych.data.write(data);
|
||||
@ -885,6 +890,11 @@ window.jsPsych = (function() {
|
||||
// reset the scroll on the DOM target
|
||||
DOM_target.scrollTop = 0;
|
||||
|
||||
// add CSS classes to the DOM_target if they exist in trial.css_classes
|
||||
if(typeof trial.css_classes !== 'undefined' && Array.isArray(trial.css_classes)){
|
||||
DOM_target.classList.add(...trial.css_classes)
|
||||
}
|
||||
|
||||
// execute trial method
|
||||
jsPsych.plugins[trial.type].trial(DOM_target, trial);
|
||||
|
||||
|
38
tests/jsPsych/css-classes-parameter.test.js
Normal file
38
tests/jsPsych/css-classes-parameter.test.js
Normal file
@ -0,0 +1,38 @@
|
||||
const root = '../../';
|
||||
const utils = require('../testing-utils.js');
|
||||
|
||||
beforeEach(function(){
|
||||
require(root + 'jspsych.js');
|
||||
require(root + 'plugins/jspsych-html-keyboard-response.js');
|
||||
});
|
||||
|
||||
describe('The css_classes parameter for trials', function(){
|
||||
|
||||
test('Adds a single CSS class to the root jsPsych element', function(){
|
||||
var trial = {
|
||||
type: 'html-keyboard-response',
|
||||
stimulus: '<p>foo</p>',
|
||||
css_classes: ['foo']
|
||||
}
|
||||
|
||||
jsPsych.init({timeline:[trial]});
|
||||
|
||||
expect(jsPsych.getDisplayElement().classList.contains('foo')).toBe(true);
|
||||
utils.pressKey(32);
|
||||
})
|
||||
|
||||
test('Removes the added classes at the end of the trial', function(){
|
||||
var trial = {
|
||||
type: 'html-keyboard-response',
|
||||
stimulus: '<p>foo</p>',
|
||||
css_classes: ['foo']
|
||||
}
|
||||
|
||||
jsPsych.init({timeline:[trial]});
|
||||
|
||||
expect(jsPsych.getDisplayElement().classList.contains('foo')).toBe(true);
|
||||
utils.pressKey(32);
|
||||
expect(jsPsych.getDisplayElement().classList.contains('foo')).toBe(false);
|
||||
|
||||
})
|
||||
})
|
Loading…
Reference in New Issue
Block a user