");
return text;
};
function unswitchedPageHTMLtext (text) {
if(text.match(/
';
return result;
};
function replaceCoverPage (text) {
if(text.match(/(^|\n)\s*\[\/\/\s*coverpage\s*\]\:\s+\#\s+\"[^\"]+\"/i)) {
text = text.replace(/(^|\n)\s*\[\/\/\s*coverpage\s*\]\:\s+\#\s+\"\s*Start of coverpage\s*\"/ig, '\n
');
text = text.replace(/\n[ \t]*\[\/\/\s*coverpage\s*\]\:\s+\#\s+\"\s*End of coverpage\s*\"/ig, '\n
\n
\n');
text += '\n
\n';
};
return text;
};
function replaceRadioButons (text) {
return text.replace(/\(\(\)\)/g, brackets2radiobuttons)
};
function replaceVASslider (text) {
return text.replace(/\>\>[-]{10,}\<\')
};
// Input text field <<| default text { css style }|>>
function replaceTextInput (text) {
return text.replace(/\<\<\\?[\|\¦]\s*([^\|\¦\{\\]*[^\|\¦\{\s\\])\s*(\{\s*([^\}\\]*[^\}\\\s])\s*\})?\s*\\?[\|\¦]\>\>/g, '
')
};
// Text insertions
function replaceTextItems (text) {
// Fixed text field (iframe) {{{< url >| css style }}}
// First, remove the fixed, iFrame cases
text = text.replace(/\{\{\{\<([^\>\|\¦\\]*[^\>\|\¦\\\s])\s*\>(\s*\\?[\|\¦]([^\}]*))?\}\}\}/g, '
');;
// Parameter fields {{{! parameter ! | css style }}}
text = text.replace(/\{\{\{!\s*([^\|!\¦]*[^\|!\¦\s])\s*!(\s*\\?[\|\¦]([^\}]*))?\}\}\}/g, '
XXXX ');
// StimulusTable references {{{ stimulus | css style }}}
var textNamesRaw = text.match(/\{\{\{([^\}]+)\}\}\}/g);
if(textNamesRaw != null && textNamesRaw.length > 0) {
// Seperate text names from text
textNamesRaw = textNamesRaw.map(x => x.replace(/^\{+\s*([^\}\|\¦\\]*[^\}\|\¦\\\s])(\s*\\?[\|\¦]([^\}]*))?\s*\}+$/g, "$1"))
textNames.push(textNamesRaw);
textNames = textNames.flat();
text = text.replace(/\{\{\{\s*([^\}\|\¦\\]*[^\}\|\¦\\\s])(\s*\\?[\|\¦]\s*([^\}]*))?\s*\}\}\}/g, '
XXXX ');
};
return text;
};
// Image insertions
function replaceImage (text) {
// Fixed image {{§< url >| css style §}}
// First, remove the fixed, iFrame cases
text = text.replace(/\{\{§\<([^\>\|\¦\\]*[^\>\|\¦\\\s])\s*\>(\s*\\?[\|\¦]([^\}§]*))?§\}\}/g, '
');;
// StimulusTable references {{§ stimulus | css style §}}
var imageNamesRaw = text.match(/\{\{§([^§\}]+)§\}\}/g);
if(imageNamesRaw != null && imageNamesRaw.length > 0) {
// Seperate text names from text
imageNamesRaw = imageNamesRaw.map(x => x.replace(/^\{\{§\s*([^§\}\|\¦\\]*[^§\}\|\¦\\\s])(\s*\\?[\|\¦]([^§\}]*))?\s*§\}\}$/g, "$1"))
imageNames.push(imageNamesRaw);
imageNames = imageNames.flat();
text = text.replace(/\{\{§\s*([^\}\|\¦\\]*[^\}\|\¦\\\s])(\s*\\?[\|\¦]\s*([^\}]*))?\s*§\}\}/g, '
');
};
return text;
};
// Audio buttons [[[ label | stimulus {css style} ]]]
function replaceAudio (text) {
var audioNamesRaw = text.match(/\[\[\[([^\]]+)\]\]\]/g);
// Remove direct audio links
audioNamesRaw = audioNamesRaw.filter(function(x){return !x.match(/[\>\<]/)})
// Seperate audio names from text
audioNamesRaw = audioNamesRaw.map(x => x.replace(/^\[+\s*([^\|\¦\{]*[\|\¦])?\s*([^\]\{]*[^\]\{\s])\s*(\{.*)?\]+$/g, "$2"))
audioNames.push(audioNamesRaw);
audioNames = audioNames.flat();
// Fixed links [[[ label |
{css style}]]]
text = text.replace(/\[\[\[\s*([^\]\|\¦\\]*[^\]\|\¦\\\s])\s*\\?[\|\¦]\s*\<([^\>]*)\>\s*(\{\s*([^\}]+)\s*\})?\]\]\]/g, '$1
');
// Stimulus links with label [[[ label | stimulus {css style}]]]
text = text.replace(/\[\[\[\s*([^\]\|\¦\\]*[^\]\|\¦\\\s])\s*\\?[\|\¦]\s*([^\]\{]*[^\]\{\s])\s*(\{\s*([^\}]*[^\}\s])\s*\})?\s*\]\]\]/g, ''+PlayText+' $1
');
// Stimulus links without label [[[ stimulus {css style}]]]
return text.replace(/\[\[\[\s*([^\]\{]*[^\]\{\s])\s*(\{\s*([^\}]*[^\}\s])\s*\})?\s*\]\]\]/g, ''+PlayText+' $1
');
};
// Video buttons [[[ alt-text | stimulus {css style} ]]] (alt-text does not work)
function replaceVideo (text) {
var audioNamesRaw = text.match(/\[\[§([^\]§]+)§\]\]/g);
// Remove direct audio links
audioNamesRaw = audioNamesRaw.filter(function(x){return !x.match(/[\>\<]/)})
// Seperate audio names from text
audioNamesRaw = audioNamesRaw.map(x => x.replace(/^\[\[§\s*([^\|\¦\{]*[\|\¦])?\s*([^§\]\{]*[^§\]\{\s])\s*(\{.*)?§\]\]$/g, "$2"))
audioNames.push(audioNamesRaw);
audioNames = audioNames.flat();
// Fixed links [[[ label | {css style}]]]
text = text.replace(/\[\[§\s*(([^§\]\|\¦\\\<\>]*[^\]\|\¦\\\s\<\>])\s*\\?[\|\¦])?\s*\<([^\>]*)\>\s*(\{\s*([^\}]+)\s*\})?§\]\]/g, ' ');
// Stimulus links with label [[[ label | stimulus {css style}]]]
text = text.replace(/\[\[§\s*([^§\]\|\¦\\]*[^§\]\|\¦\\\s])\s*\\?[\|\¦]\s*([^§\]\{]*[^§\]\{\s])\s*(\{\s*([^\}]*[^\}\s])\s*\})?\s*§\]\]/g, ' ');
// Stimulus links without label [[[ stimulus {css style}]]]
return text.replace(/\[\[§\s*([^§\]\{]*[^§\]\{\s])\s*(\{\s*([^\}]*[^\}\s])\s*\})?\s*§\]\]/g, ' ');
};
function preProcessMD (text) {
var lines = text.split(/\r?\n|\r|\n/g);
var questionNum = 0;
audioNames = [];
textNames = [];
imageNames = [];
for(var i=0; i < lines.length; ++i){
// Stimuli
if(lines[i].match(/\[\[\[[^\]]*\]\]\]/)){
lines[i] = replaceAudio(lines[i]);
};
if(lines[i].match(/\[\[§[^§\]]*§\]\]/)){
lines[i] = replaceVideo(lines[i]);
};
if(lines[i].match(/\{\{\{[^\}]*\}\}\}/)){
lines[i] = replaceTextItems(lines[i]);
};
if(lines[i].match(/\{\{§[^§\}]*§\}\}/)){
lines[i] = replaceImage(lines[i]);
};
// Input
buttonCounter = 0;
if(lines[i].match(/\(\(\)\)/)){
++questionNum;
lines[i] = replaceRadioButons (lines[i]);
lines[i] = lines[i].replace(/XXXX/g, questionNum);
};
if(lines[i].match(/\>\>[-]{10,}\<\)){
++questionNum;
lines[i] = replaceVASslider (lines[i]);
lines[i] = lines[i].replace(/XXXX/g, questionNum);
};
if(lines[i].match(/\<\<[\|\¦]|[\|\¦]\>\>/)){
++questionNum;
lines[i] = replaceTextInput (lines[i]);
lines[i] = lines[i].replace(/XXXX/g, questionNum);
};
};
// Ready number of scales
NumberOfScales = questionNum;
var processedText = lines.join('\n');
// insert Cover page
processedText = replaceCoverPage(processedText);
return processedText;
};
function preProcessPreamble (text) {
var processedPreamble = text.replace(/XXNUMBEROFSCALESXX/g, NumberOfScales);
processedPreamble = processedPreamble.replace(/XXEXPERIMENTNAMEXX/g, ExperimentAcronym);
processedPreamble = processedPreamble.replace(/XXRANDOMIZEABXX/g, RandomizeAB);
processedPreamble = processedPreamble.replace(/XXSHUFFLESTIMULUSLISTXX/g, ShuffleStimuli);
processedPreamble = processedPreamble.replace(/XXaudioBaseURLXX/g, audioBaseURL);
processedPreamble = processedPreamble.replace(/XXPracticeItemsXX/g, PracticeItems);
processedPreamble = processedPreamble.replace(/XXNextTextXX/g, NextText);
processedPreamble = processedPreamble.replace(/XXNextAlertTextXX/g, NextAlertText);
processedPreamble = processedPreamble.replace(/XXReadyTextXX/g, ReadyText);
processedPreamble = processedPreamble.replace(/XXPlayTextXX/g, PlayText);
processedPreamble = processedPreamble.replace(/XXRestartPageTextXX/g, RestartPageText);
processedPreamble = processedPreamble.replace(/XXSaveTextXX/g, SaveText);
processedPreamble = processedPreamble.replace(/XXSaveButtonTextXX/g, SaveButtonText);
processedPreamble = processedPreamble.replace(/XXToolTipNextXX/g, ToolTipNext);
processedPreamble = processedPreamble.replace(/XXToolTipReadyXX/g, ToolTipReady);
processedPreamble = processedPreamble.replace(/XXToolTipRestartXX/g, ToolTipRestart);
processedPreamble = processedPreamble.replace(/XXToolTipSaveXX/g, ToolTipSave);
processedPreamble = processedPreamble.replace(/XXstimulusTableJSONXX/g, stimulusTableJSON);
audioNamesString = (audioNames.length > 0) ? '"' + audioNames.join('", "')+ '"' : "";
textNamesString = (textNames.length > 0) ? '"' + textNames.join('", "') + '"' : "";
imageNamesString = (imageNames.length > 0) ? '"' + imageNames.join('", "') + '"' : "";
processedPreamble = processedPreamble.replace(/var audioNames\s*\=\s*\[\];/, 'var audioNames = ['+ audioNamesString +'];');
processedPreamble = processedPreamble.replace(/var textNames\s*\=\s*\[\];/, 'var textNames = ['+ textNamesString +'];');
processedPreamble = processedPreamble.replace(/var imageNames\s*\=\s*\[\];/, 'var imageNames = ['+ imageNamesString +'];');
processedPreamble = processedPreamble.replace(/var requiredNames\s*\=\s*\[\];/, 'var requiredNames = ["'+requiredNames.join('", "')+'"];');
processedPreamble = processedPreamble.replace(/var addDigest\s*=\s*false;/, 'var addDigest = '+addDigestText.replace(/["']/g, "") +';');
processedPreamble = processedPreamble.replace(//, '');
if(addDigestText != 'true'){
processedPreamble = processedPreamble.replace(/src\s*=\s*["'](\.\/)?sha\.js["']/ig, "src='' ")
processedPreamble = processedPreamble.replace(/src\s*=\s*["']https:\/\/cdn\.jsdelivr\.net\/npm\/jssha\@[\d\.]*\/dist\/sha\.js["']/ig, "src='' ")
};
return processedPreamble;
};
function setUp() {
if(window.location.search.match(/ExperimentAcronym\=/)){
fileName = window.location.search.replace(/^.*ExperimentAcronym\=([^&]+)[&]?.*$/g, "$1");
if(fileName.length > 0){
loadMarkdown('ExpAcronym_examples/'+fileName+'_markdown.js');
if(document.getElementById('ExperimentAcronym').value != fileName) {
loadMarkdown('./'+fileName+'_markdown.js');
};
// Clear body.style
bodyStyleText = "";
};
};
initializeMarkdown();
};
Create an experiment