diff --git a/docs/developers/extension-development.md b/docs/developers/extension-development.md index f8759cc8..9c945073 100644 --- a/docs/developers/extension-development.md +++ b/docs/developers/extension-development.md @@ -8,7 +8,7 @@ jsPsych.extensions['new-extension'] = (function () { var extension = {}; extension.initialize = function(params){ - // params are passed from the extensions parameter in jsPsych.init + // params are passed from the extensions parameter in initJsPsych } extension.on_start = function(params){ @@ -32,7 +32,7 @@ jsPsych.extensions['new-extension'] = (function () { The four events that an extension must support are shown in the sample code. -`extension.initialize` is called with `jsPsych.init()`. This is where setup code for the extension can happen. This event will happen once per experiment, unlike the other events which occur with each trial. The `params` object can include whatever parameters are necessary to configure the extension. The `params` object is passed from the call to `jsPsych.init()` to the `extension.initialize` method. `extension.initialize` must return a `Promise` that resolves when the extension is finished initializing. +`extension.initialize` is called with `initJsPsych()`. This is where setup code for the extension can happen. This event will happen once per experiment, unlike the other events which occur with each trial. The `params` object can include whatever parameters are necessary to configure the extension. The `params` object is passed from the call to `initJsPsych()` to the `extension.initialize` method. `extension.initialize` must return a `Promise` that resolves when the extension is finished initializing. `extension.on_start` is called at the start of the plugin execution, prior to calling `plugin.trial`. This is where trial-specific initialization can happen, such as creating empty containers to hold data or resetting internal state. The `params` object is passed from the declaration of the extension in the trial object. You can use `params` to customize the behavior of the extension for each trial. diff --git a/docs/extensions/jspsych-ext-webgazer.md b/docs/extensions/jspsych-ext-webgazer.md index 095fae4a..433d027e 100644 --- a/docs/extensions/jspsych-ext-webgazer.md +++ b/docs/extensions/jspsych-ext-webgazer.md @@ -6,10 +6,10 @@ This extension supports eye tracking through the [WebGazer](https://webgazer.cs. ### Initialization Parameters -Initialization parameters can be set when calling `jsPsych.init()` +Initialization parameters can be set when calling `initJsPsych()` ```js -jsPsych.init({ +initJsPsych({ extensions: [ {type: 'webgazer', params: {...}} ] diff --git a/docs/overview/callbacks.md b/docs/overview/callbacks.md index 73248cc2..f4e10756 100644 --- a/docs/overview/callbacks.md +++ b/docs/overview/callbacks.md @@ -6,11 +6,10 @@ jsPsych offers the ability to call arbitrary functions in response to certain ev ## on_close -The `on_close` callback can be declared in the `jsPsych.init` method. The callback triggers when the user leaves the page, but before any content on the page is removed from the browser's memory. This can be used, for example, to save data as the user is leaving the page. +The `on_close` callback can be declared in the `initJsPsych` method. The callback triggers when the user leaves the page, but before any content on the page is removed from the browser's memory. This can be used, for example, to save data as the user is leaving the page. ```javascript -jsPsych.init({ - timeline: exp, +initJsPsych({ on_close: function(){ var data = jsPsych.data.get().json(); save_data_to_server(data); @@ -22,11 +21,10 @@ jsPsych.init({ ## on_data_update -The `on_data_update` callback can be declared in the `jsPsych.init` method. The callback triggers at the end of a data update cycle. This happens after every trial, after the on_finish (trial) and on_trial_finish events execute, allowing you to modify the data in those callbacks, and then use this callback to store the data. The function will be passed a single argument, which contains the data that was written. +The `on_data_update` callback can be declared in the `initJsPsych` method. The callback triggers at the end of a data update cycle. This happens after every trial, after the on_finish (trial) and on_trial_finish events execute, allowing you to modify the data in those callbacks, and then use this callback to store the data. The function will be passed a single argument, which contains the data that was written. ```javascript -jsPsych.init({ - timeline: exp, +initJsPsych({ on_data_update: function(data) { console.log('Just added new data. The contents of the data are: '+JSON.stringify(data)); } @@ -57,11 +55,10 @@ var trial = { ## on_finish (experiment) -The `on_finish` callback can be declared in the `jsPsych.init` method. The callback will trigger once all trials in the experiment have been run. The method will be passed a single argument, containing all of the data generated in the experiment. +The `on_finish` callback can be declared in the `initJsPsych` method. The callback will trigger once all trials in the experiment have been run. The method will be passed a single argument, containing all of the data generated in the experiment. ```javascript -jsPsych.init({ - timeline: exp, +initJsPsych({ on_finish: function(data) { console.log('The experiment is over! Here is all the data: '+JSON.stringify(data)); } @@ -149,11 +146,10 @@ var procedure = { ## on_trial_finish -The `on_trial_finish` callback can be declared in the `jsPsych.init` method. The callback will trigger at the end of every trial in the experiment. If you want a callback to trigger only for the end of certain trials, use the [`on_finish`](#onfinishtrial) callback on the trial object. The callback function will be passed a single argument, containing the data object from the trial. +The `on_trial_finish` callback can be declared in the `initJsPsych` method. The callback will trigger at the end of every trial in the experiment. If you want a callback to trigger only for the end of certain trials, use the [`on_finish`](#onfinishtrial) callback on the trial object. The callback function will be passed a single argument, containing the data object from the trial. ```javascript -jsPsych.init({ - timeline: exp, +initJsPsych({ on_trial_finish: function(data) { console.log('A trial just ended.'); console.log(JSON.stringify(data)); @@ -165,13 +161,12 @@ jsPsych.init({ ## on_trial_start -The `on_trial_start` callback can be declared in the `jsPsych.init` method. The callback will trigger at the start of every trial in the experiment. The function receives a single argument: a modifiable copy of the trial object that will be used to run the next trial. Changes can be made to this object to alter the parameters of the upcoming trial. +The `on_trial_start` callback can be declared in the `initJsPsych` method. The callback will trigger at the start of every trial in the experiment. The function receives a single argument: a modifiable copy of the trial object that will be used to run the next trial. Changes can be made to this object to alter the parameters of the upcoming trial. ```javascript var current_score = 0; // a variable that is updated throughout the experiment to keep track of the current score. -jsPsych.init({ - timeline: exp, +initJsPsych({ on_trial_start: function(trial) { trial.data.score_at_start_of_trial = current_score; console.log('A trial just started.'); diff --git a/docs/overview/data.md b/docs/overview/data.md index 4fa28841..47df079e 100644 --- a/docs/overview/data.md +++ b/docs/overview/data.md @@ -170,8 +170,7 @@ function saveData(name, data){ } // call the saveData function after the experiment is over -jsPsych.init({ - // code to define the experiment structure would go here... +initJsPsych({ on_finish: function(){ saveData(jsPsych.data.get().csv()); } }); ``` diff --git a/docs/overview/exclude-browser.md b/docs/overview/exclude-browser.md index 0a84396a..7526d169 100644 --- a/docs/overview/exclude-browser.md +++ b/docs/overview/exclude-browser.md @@ -1,6 +1,6 @@ # Exclude Participants Based on Browser Features -Online subjects will use many different kinds of browsers. Depending on the experiment, it may be important to specify a minimum feature set of the browser. jsPsych makes this straightforward. Simply specify certain exclusion criteria in the `jsPsych.init` method call. If a subject's browser doesn't meet the criteria the experiment will not start and the subject will see a message explaining the problem. For size restrictions the subject will see a message that displays the current size of their browser window and the minimum size needed to start the experiment, giving the subject an opportunity to enlarge the browser window to continue. +Online subjects will use many different kinds of browsers. Depending on the experiment, it may be important to specify a minimum feature set of the browser. jsPsych makes this straightforward. Simply specify certain exclusion criteria in the `initJsPsych` method call. If a subject's browser doesn't meet the criteria the experiment will not start and the subject will see a message explaining the problem. For size restrictions the subject will see a message that displays the current size of their browser window and the minimum size needed to start the experiment, giving the subject an opportunity to enlarge the browser window to continue. Current exclusion options: * Minimum browser width & height @@ -11,8 +11,7 @@ Current exclusion options: #### Exclude browsers that are not at least 800x600 pixels ```javascript -jsPsych.init({ - timeline: exp, +initJsPsych({ exclusions: { min_width: 800, min_height: 600 @@ -23,8 +22,7 @@ jsPsych.init({ #### Exclude browsers that do not have access to the WebAudio API ```javascript -jsPsych.init({ - timeline: exp, +initJsPsych({ exclusions: { audio: true } diff --git a/docs/overview/experiment-options.md b/docs/overview/experiment-options.md index 468ba7a3..f8b03784 100644 --- a/docs/overview/experiment-options.md +++ b/docs/overview/experiment-options.md @@ -1,12 +1,11 @@ # Experiment-wide settings -There are several options that can be set when calling `jsPsych.init()` to launch the experiment. +There are several options that can be set when calling `initJsPsych()` to initialize the jsPsych experiment. -Options are specified in the object passed to `jsPsych.init`. For example, to specify a default inter-trial interval, a minimum valid response time duration, and a maximum width for all of the experiment's page content, the object would contain: +Options are specified in the object passed to `initJsPsych`. For example, to specify a default inter-trial interval, a minimum valid response time duration, and a maximum width for all of the experiment's page content, the object would contain: ```js -jsPsych.init({ - timeline: [...], +initJsPsych({ default_iti: 250, minimum_valid_rt: 100, experiment_width: 800 @@ -22,13 +21,13 @@ By default, jsPsych will render the experiment in the `
` element of a page ``` @@ -51,28 +50,26 @@ Exclusion criteria can be specified based on features of the user's web browser, ## Display a progress bar -An automatic or manually updated progress bar can be displayed at the top of the screen. By default, the text next to the progress bar is "Completion Progress", but this text can be changed with the `message_progress_bar` parameter in `jsPsych.init`. See the [progress bar page](progress-bar.md) for more details. +An automatic or manually updated progress bar can be displayed at the top of the screen. By default, the text next to the progress bar is "Completion Progress", but this text can be changed with the `message_progress_bar` parameter in `initJsPsych`. See the [progress bar page](progress-bar.md) for more details. ## Choose the method for playing audio files -Specifying the `use_webaudio` parameter in `jsPsych.init()` allows you to choose whether to use the WebAudio API or HTML5 audio for playing audio files during your experiment. By default, jsPsych uses the WebAudio API to play audio files. Among other features, the WebAudio API allows for more precise measurement of response times relative to the onset of the audio. +Specifying the `use_webaudio` parameter in `initJsPsych()` allows you to choose whether to use the WebAudio API or HTML5 audio for playing audio files during your experiment. By default, jsPsych uses the WebAudio API to play audio files. Among other features, the WebAudio API allows for more precise measurement of response times relative to the onset of the audio. However, loading files through the WebAudio API causes errors when running an experiment offline (i.e., by double-clicking on the HTML file, rather than hosting it on a web server). This is due to the [cross-origin security policy](https://security.stackexchange.com/a/190321) implemented by web browsers. For this reason, jsPsych switches to a 'safe mode' when it detects that the webpage is running offline, and automatically uses HTML5 audio to prevent errors, even when `use_webaudio` has been explicitly set to `true`. For more information, see the section [Cross-origin requests (CORS) and safe mode](running-experiments.md#cross-origin-requests-cors-and-safe-mode) on the Running Experiments page. ```js -jsPsych.init({ - timeline: [...], +initJsPsych({ use_webaudio: false }); ``` ## Set the default intertrial interval -By default the next trial in a timeline will begin immediately after the conclusion of the previous trial. An experiment-wide delay can be specified using the `default_iti` parameter to `jsPsych.init()`. +By default the next trial in a timeline will begin immediately after the conclusion of the previous trial. An experiment-wide delay can be specified using the `default_iti` parameter to `initJsPsych()`. ```js -jsPsych.init({ - timeline: [...], +initJsPsych({ default_iti: 500 }); ``` @@ -86,8 +83,7 @@ The experiment will, by default, take up 100% of the display element. Usually th Specifying the `experiment_width` parameter will set a maximum width for the display. The parameter is specified in pixels. ```js -jsPsych.init({ - timeline: [...], +initJsPsych({ experiment_width: 750 }); ``` @@ -98,8 +94,7 @@ By default, jsPsych will treat any keyboard response time as valid. However, it' ```js // ignore any keyboard responses that are less than 100 ms -jsPsych.init({ - timeline: [...], +initJsPsych({ minimum_valid_rt: 100 }); ``` @@ -108,14 +103,13 @@ jsPsych.init({ JavaScript keyboard events make a distinction between uppercase and lowercase key responses (e.g. 'a' and 'A'). Often the researcher just cares about which physical key was pressed, and not whether the key press would result in an uppercase letter (for instance, if CapsLock is on or if the Shift key is held down). For this reason, jsPsych converts all key choice parameters and key responses as lowercase by default. This makes it easier to specify key choices (e.g. `choices: ['a']`, instead of `choices: ['a','A']`), and it makes it easier to check and score a participant's response. -There may be situations when you want key choices and responses to be case-sensitive. You can change this by setting the `case_sensitive_responses` parameter to `true` in `jsPsych.init`. +There may be situations when you want key choices and responses to be case-sensitive. You can change this by setting the `case_sensitive_responses` parameter to `true` in `initJsPsych`. ```js // use case-sensitive key choices and responses, // i.e. uppercase and lower case letters ('a' and 'A') will be treated as different key choices, // and will be recorded this way in the data -jsPsych.init({ - timeline: [...], +initJsPsych({ case_sensitive_responses: true }); ``` @@ -126,22 +120,20 @@ Note that this setting only applies to key choices and responses that use jsPsyc By default, jsPsych switches to a 'safe mode' when it detects that the webpage is running offline (via the `file://` protocol) in order to prevent certain errors. Specifically, in safe mode, HTML5 audio is used to play audio files (even when `use_webaudio` has been explicitly set to `true`) and video preloading is disabled (both automatic and manual preloading). For more information, see the [Cross-origin requests (CORS) and safe mode](running-experiments.md#cross-origin-requests-cors-and-safe-mode) section on the Running Experiments page. -It's possible to override this safe mode feature by setting the `override_safe_mode` parameter to `true` in `jsPsych.init`. This is something you might do if you've disabled certain security settings in your browser for testing purposes. This parameter has no effect when your experiment is running online (on a server), because it will be using the `http://` or `https://` protocol, which does not trigger safe mode. +It's possible to override this safe mode feature by setting the `override_safe_mode` parameter to `true` in `initJsPsych`. This is something you might do if you've disabled certain security settings in your browser for testing purposes. This parameter has no effect when your experiment is running online (on a server), because it will be using the `http://` or `https://` protocol, which does not trigger safe mode. ```js -jsPsych.init({ - timeline: [...], +initJsPsych({ override_safe_mode: true }); ``` ## Add extensions -Extensions are jsPsych modules that can run throughout the experiment and interface with any plugin to extend the functionality of the plugin. One example of an extension is eye tracking, which allows you to gather gaze data during any trial and add it to that trial's data object. If you want to use extensions in your experiment, you must specify this when you initialize the experiment with `jsPsych.init`. The `extensions` parameter in `jsPsych.init` is an array of objects, where each object specifies the extension that you'd like to use in the experiment. Below is an example of adding the webgazer extension. +Extensions are jsPsych modules that can run throughout the experiment and interface with any plugin to extend the functionality of the plugin. One example of an extension is eye tracking, which allows you to gather gaze data during any trial and add it to that trial's data object. If you want to use extensions in your experiment, you must specify this when you initialize the experiment with `initJsPsych`. The `extensions` parameter in `initJsPsych` is an array of objects, where each object specifies the extension that you'd like to use in the experiment. Below is an example of adding the webgazer extension. ```js -jsPsych.init({ - timeline: [...], +initJsPsych({ extensions: [ {type: 'webgazer'} ] diff --git a/docs/overview/extensions.md b/docs/overview/extensions.md index a10e1806..9803e55c 100644 --- a/docs/overview/extensions.md +++ b/docs/overview/extensions.md @@ -4,7 +4,7 @@ Extensions are jsPsych modules that can interface with any plugin to extend the ## Using an Extension -To use an extension in an experiment, you'll load the extension file via a `