From 5afea90da5ecf71043a196683615c2cdde3daea2 Mon Sep 17 00:00:00 2001 From: atakaragoz Date: Sun, 24 Dec 2023 00:26:28 -0600 Subject: [PATCH 1/5] Initial commit of html-written-recall --- packages/plugin-html-written-recall/README.md | 35 ++++ packages/plugin-html-written-recall/index.js | 149 ++++++++++++++++++ 2 files changed, 184 insertions(+) create mode 100644 packages/plugin-html-written-recall/README.md create mode 100644 packages/plugin-html-written-recall/index.js diff --git a/packages/plugin-html-written-recall/README.md b/packages/plugin-html-written-recall/README.md new file mode 100644 index 00000000..8f0e4b3d --- /dev/null +++ b/packages/plugin-html-written-recall/README.md @@ -0,0 +1,35 @@ +# html-written-recall + +## Overview + +This plugin displays a text box for participants to write a response to a prompt. The response is saved as a string. The trial advances when a certain button is pressed (default is `Spacebar`). The idea is that a general survey-text box allows for editing as well as observing prior responses whereas this input mimics verbal free recall. + +## Loading + +### In browser + +```js + + + + + + + \ No newline at end of file diff --git a/packages/plugin-html-written-recall/index.js b/packages/plugin-html-written-recall/index.js index 6f6f583c..b1d6e2a1 100644 --- a/packages/plugin-html-written-recall/index.js +++ b/packages/plugin-html-written-recall/index.js @@ -27,7 +27,7 @@ var htmlWrittenRecall = (function (jspsych) { next_word_key: { type: jspsych.ParameterType.STRING, pretty_name: "key for next word", - default: "Space", + default: " ", }, button_string: { type: jspsych.ParameterType.HTML_STRING, @@ -44,6 +44,11 @@ var htmlWrittenRecall = (function (jspsych) { pretty_name: "The time the recall block began", default: null, }, + total_block_duration: { + type: jspsych.ParameterType.INT, + pretty_name: "The total duration of the recall block", + default: null, + }, }, }; @@ -88,14 +93,14 @@ var htmlWrittenRecall = (function (jspsych) { end_trial(); }); var buttonDisplayTime; - if (typeof trial.blockTimeStart !== "undefined") { + if (trial.block_time_start !== null) { // Dynamic button delay calculation var currentTime = performance.now(); - var elapsedTime = currentTime - trial.blockTimeStart; - buttonDisplayTime = Math.max(trial.totalBlockDuration - elapsedTime, 0); + var elapsedTime = currentTime - trial.block_time_start; + buttonDisplayTime = Math.max(trial.total_block_duration - elapsedTime, 0); } else { // Static button delay - buttonDisplayTime = trial.buttonDelay; + buttonDisplayTime = trial.button_delay; } this.jsPsych.pluginAPI.setTimeout(() => { button.style.display = "initial"; // Show the button after the delay @@ -117,7 +122,10 @@ var htmlWrittenRecall = (function (jspsych) { this.jsPsych.finishTrial(trial_data); }; - + // if the next_word_key is "Spacebar" convert it to " " for comparison + if (trial.next_word_key.toLowerCase() === "spacebar") { + trial.next_word_key = " "; + } // Function to check for space key press in the textbox const checkForNextWordKey = (event) => { if (textbox.value.trim() !== "" && event.key === trial.next_word_key) { From bed5c68cdb028cdb10fd6177e3f23d1052ed355c Mon Sep 17 00:00:00 2001 From: atakaragoz Date: Fri, 29 Dec 2023 22:40:08 -0600 Subject: [PATCH 3/5] adding examples to docs, thinking about improvement to plugin --- .../docs/jspsych-html-written-recall.md | 58 ++++++++++++++++++- .../examples/example1.html | 23 +++++++- .../examples/example2.html | 43 ++++++++++++++ packages/plugin-html-written-recall/index.js | 2 +- 4 files changed, 121 insertions(+), 5 deletions(-) create mode 100644 packages/plugin-html-written-recall/examples/example2.html diff --git a/packages/plugin-html-written-recall/docs/jspsych-html-written-recall.md b/packages/plugin-html-written-recall/docs/jspsych-html-written-recall.md index 15357bc7..dfaaf243 100644 --- a/packages/plugin-html-written-recall/docs/jspsych-html-written-recall.md +++ b/packages/plugin-html-written-recall/docs/jspsych-html-written-recall.md @@ -4,10 +4,10 @@ This plugin displays a text box for participants to write a response to a prompt Another use case for this plugin is to allow participants to see a set of images and write single word names in response to them or free-associate words. For instance, on a set of trials participants can see a set of images and write the first word that comes to mind. -This code was developed to be used in a loop_function (insert jsPsych `loop_function()` website) such that the participant sets the amount of recalls or until a timer allows them to move onto the next trial. +This code was developed to be used in a `loop_function()` such that the participant sets the amount of recalls or until a timer allows them to move onto the next trial (See example 1). ## Parameters -In addition to the standard jsPsych parameters, html-written-recall takes the following parameters: +In addition to the [parameters available in all plugins](https://www.jspsych.org/overview/plugins#parameters-available-in-all-plugins), this plugin accepts the following parameters. Parameters with a default value of *undefined* must be specified. Parameters can be left unspecified if the default value is acceptable. | Parameter | Type | Default | Description | | --- | --- | --- | --- | @@ -30,3 +30,57 @@ In addition to the [default data collected by all plugins](https://www.jspsych.o | `response` | string | The response given by the participant. | | `button_pressed` | string | A binary indicator of whether or not the button to move onto next portion of experiment is pressed | +## Example + +### Single word association +```javascript +var free_association_trial = { + type: 'html-written-recall', + stimulus: 'Dog', + prompt: 'Write the first word that comes to mind.', + stimulus_duration: 500, // the word disappears after 500 ms + button_string: 'Next task', // Button displayed to finish the block + button_delay: 5000 // button appears after 5 seconds, though this timer resets after each word submitted (so 5 seconds from final submission they can move on) +} + +var free_association_block = { + timeline: [free_association_trial], + loop_function() { + // Loop until 10 trials are completed + if (jsPsych.data.get().last(1).values()[0].button_pressed) { + return false; + } else { + return true; + } + } +} +``` +See `examples/example1.html` for a demo. + +### Free recall with button appearing after 10 seconds +```javascript +var total_block_duration = 10000 // 10 seconds +var free_recall_trial = { + type: 'html-written-recall', + prompt: 'Write down as many words as you can remember from the previous list.', + stimulus_duration: 500, // the word disappears after 500 ms + button_string: 'Next task', // Button displayed to finish the block + block_time_start: begin_block_time, + total_block_duration: total_block_duration // button appears based on global clock +} +var free_recall_block = { + timeline: [free_recall_trial], + on_start: function() { + begin_block_time = performance.now(); + }, // set the initial block time so that participants have 30 seconds before the button appears + loop_function() { + // Loop until 30 seconds have passed + if (jsPsych.data.get().last(1).values()[0].button_pressed) { + return false; + } else { + return true; + } + } +} +``` +See `examples/example2.html` for a demo. diff --git a/packages/plugin-html-written-recall/examples/example1.html b/packages/plugin-html-written-recall/examples/example1.html index dd29c964..f72365bd 100644 --- a/packages/plugin-html-written-recall/examples/example1.html +++ b/packages/plugin-html-written-recall/examples/example1.html @@ -7,15 +7,34 @@ \ No newline at end of file diff --git a/packages/plugin-html-written-recall/examples/example2.html b/packages/plugin-html-written-recall/examples/example2.html new file mode 100644 index 00000000..534c22b7 --- /dev/null +++ b/packages/plugin-html-written-recall/examples/example2.html @@ -0,0 +1,43 @@ + + + + + + + + + + \ No newline at end of file diff --git a/packages/plugin-html-written-recall/index.js b/packages/plugin-html-written-recall/index.js index b1d6e2a1..3c4ceefb 100644 --- a/packages/plugin-html-written-recall/index.js +++ b/packages/plugin-html-written-recall/index.js @@ -17,7 +17,7 @@ var htmlWrittenRecall = (function (jspsych) { stimulus_duration: { type: jspsych.ParameterType.INT, pretty_name: "Stimulus duration", - default: null, + default: null, // might add a stimulus or prompt repeat where it only shows for first word in a block and then disappears }, trial_duration: { type: jspsych.ParameterType.INT, From 88d341e734d155115d245d127eb7c3e55e779d60 Mon Sep 17 00:00:00 2001 From: atakaragoz Date: Fri, 29 Dec 2023 22:50:26 -0600 Subject: [PATCH 4/5] initial way to get stimulus_only_first and prompt_only_first. Need to think about how to do this more easily (or if I even need it) --- packages/plugin-html-written-recall/README.md | 2 +- packages/plugin-html-written-recall/index.js | 36 ++++++++++++++++--- 2 files changed, 32 insertions(+), 6 deletions(-) diff --git a/packages/plugin-html-written-recall/README.md b/packages/plugin-html-written-recall/README.md index 0dbce104..943f347b 100644 --- a/packages/plugin-html-written-recall/README.md +++ b/packages/plugin-html-written-recall/README.md @@ -32,4 +32,4 @@ See [documentation](docs/jspsych-html-written-recall.md) ## Author / Citation -[atakaragoz](https://www.github.com/atakaragoz) \ No newline at end of file +[Ata Karagoz](https://www.github.com/atakaragoz) \ No newline at end of file diff --git a/packages/plugin-html-written-recall/index.js b/packages/plugin-html-written-recall/index.js index 3c4ceefb..ef503316 100644 --- a/packages/plugin-html-written-recall/index.js +++ b/packages/plugin-html-written-recall/index.js @@ -9,15 +9,25 @@ var htmlWrittenRecall = (function (jspsych) { pretty_name: "Stimulus", default: undefined, }, + stimulus_duration: { + type: jspsych.ParameterType.INT, + pretty_name: "Stimulus duration", + default: null, // might add a stimulus or prompt repeat where it only shows for first word in a block and then disappears + }, + stimulus_only_first: { + type: jspsych.ParameterType.BOOL, + pretty_name: "Stimulus only first", + default: false, + }, prompt: { type: jspsych.ParameterType.HTML_STRING, pretty_name: "Prompt", default: null, }, - stimulus_duration: { - type: jspsych.ParameterType.INT, - pretty_name: "Stimulus duration", - default: null, // might add a stimulus or prompt repeat where it only shows for first word in a block and then disappears + prompt_only_first: { + type: jspsych.ParameterType.BOOL, + pretty_name: "Prompt only first", + default: false, }, trial_duration: { type: jspsych.ParameterType.INT, @@ -58,6 +68,16 @@ var htmlWrittenRecall = (function (jspsych) { } trial(display_element, trial) { + + // if the stimulus should only be displayed for the first word, check the block_time_start and if the block has been going for more than 100ms, don't show the stimulus + if (trial.stimulus_only_first && trial.block_time_start !== null) { + var currentTime = performance.now(); + var elapsedTime = currentTime - trial.block_time_start; + if (elapsedTime > 100) { + trial.stimulus = ""; + } + } + var new_html = '
' + trial.stimulus + "
"; @@ -65,8 +85,14 @@ var htmlWrittenRecall = (function (jspsych) { new_html += '
'; // need to make sure autocomplete is off - if (trial.prompt !== null) { + if (trial.prompt !== null && !trial.prompt_only_first) { new_html += trial.prompt; + } else if (trial.prompt !== null && trial.prompt_only_first && trial.block_time_start !== null) { + var currentTime = performance.now(); + var elapsedTime = currentTime - trial.block_time_start; + if (elapsedTime < 100) { + new_html += trial.prompt; + } } if (trial.button_string !== null) { From 6c1114f9a5d545e2e7e387b1b6bb18676b4cb4f6 Mon Sep 17 00:00:00 2001 From: Ata Karagoz Date: Wed, 20 Nov 2024 06:53:35 -0600 Subject: [PATCH 5/5] Create package.json Adding package.json, appears to have been deleted at some point. --- .../plugin-html-written-recall/package.json | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 packages/plugin-html-written-recall/package.json diff --git a/packages/plugin-html-written-recall/package.json b/packages/plugin-html-written-recall/package.json new file mode 100644 index 00000000..dc1bdd4e --- /dev/null +++ b/packages/plugin-html-written-recall/package.json @@ -0,0 +1,32 @@ +{ + "name": "@jspsych-contrib/plugin-html-written-recall", + "version": "0.1.0", + "description": "This plugin displays a text box for participants to write a response to a prompt. The response is saved as a string. The trial advances when a certain keyboard input is pressed (default is `Spacebar`). The idea is that a general survey-text box allows for editing as well as observing prior responses whereas this input mimics verbal free recall. ", + "unpkg": "dist/index.browser.min.js", + "files": [ + "index.js", + "dist" + ], + "scripts": { + "build": "babel index.js --presets @babel/preset-env,minify --source-maps --out-file dist/index.browser.min.js", + "build:watch": "npm run build -- --watch" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/jspsych/jspsych-contrib.git", + "directory": "packages/plugin-html-written-recall" + }, + "author": { + "name": "Ata Karagoz", + "url": "https://github.com/atakaragoz" + }, + "license": "MIT", + "bugs": { + "url": "https://github.com/jspsych/jspsych-contrib/issues" + }, + "homepage": "https://github.com/jspsych/jspsych-contrib/tree/main/packages/plugin-html-written-recall", + "devDependencies": { + "@jspsych/config": "^2.0.0", + "jspsych": "^7.0.0" + } + }