code
stringlengths
10
343k
docstring
stringlengths
36
21.9k
func_name
stringlengths
1
3.35k
language
stringclasses
1 value
repo
stringlengths
7
58
path
stringlengths
4
131
url
stringlengths
44
195
license
stringclasses
5 values
function getCommitTime(hash) { const envHash = getEnvVarIfSet([ // Manual override 'LHCI_BUILD_CONTEXT__COMMIT_TIME', // GitLab CI 'CI_COMMIT_TIMESTAMP', ]); if (envHash) return envHash; const result = childProcess.spawnSync('git', ['log', '-n1', '--pretty=%cI', hash], { encoding: 'utf8', }); if (result.status !== 0) { throw new Error( 'Unable to retrieve committer timestamp from commit. ' + 'This can be overridden with setting LHCI_BUILD_CONTEXT__COMMIT_TIME env.' ); } return result.stdout.trim(); }
@param {string} hash @return {string}
getCommitTime ( hash )
javascript
GoogleChrome/lighthouse-ci
packages/utils/src/build-context.js
https://github.com/GoogleChrome/lighthouse-ci/blob/master/packages/utils/src/build-context.js
Apache-2.0
function getCurrentBranch() { const branch = getCurrentBranchRaw_(); if (branch === 'HEAD') throw new Error('Unable to determine current branch'); return branch.replace('refs/heads/', '').slice(0, 40); }
Returns the current branch name. Throws if it could not be determined. @return {string}
getCurrentBranch ( )
javascript
GoogleChrome/lighthouse-ci
packages/utils/src/build-context.js
https://github.com/GoogleChrome/lighthouse-ci/blob/master/packages/utils/src/build-context.js
Apache-2.0
function getCurrentBranchSafe() { try { return getCurrentBranch(); } catch (err) { return undefined; } }
Returns the current branch name. Returns `undefined` if it could not be determined. @return {string|undefined}
getCurrentBranchSafe ( )
javascript
GoogleChrome/lighthouse-ci
packages/utils/src/build-context.js
https://github.com/GoogleChrome/lighthouse-ci/blob/master/packages/utils/src/build-context.js
Apache-2.0
function getGravatarUrlFromEmail(email) { // Use default gravatar image, see https://en.gravatar.com/site/implement/images/. const md5 = crypto.createHash('md5'); md5.update(email.trim().toLowerCase()); return `https://www.gravatar.com/avatar/${md5.digest('hex')}.jpg?d=identicon`; }
@param {string} email @return {string}
getGravatarUrlFromEmail ( email )
javascript
GoogleChrome/lighthouse-ci
packages/utils/src/build-context.js
https://github.com/GoogleChrome/lighthouse-ci/blob/master/packages/utils/src/build-context.js
Apache-2.0
function getAncestorHashForBranch(hash, baseBranch) { const result = runCommandsUntilFirstSuccess([ ['git', ['merge-base', hash, `origin/${baseBranch}`]], ['git', ['merge-base', hash, baseBranch]], ]); // Ancestor hash is optional, so do not throw if it can't be computed. // See https://github.com/GoogleChrome/lighthouse-ci/issues/36 if (result.status !== 0) return ''; return result.stdout.trim(); }
@param {string} hash @param {string} baseBranch @return {string}
getAncestorHashForBranch ( hash , baseBranch )
javascript
GoogleChrome/lighthouse-ci
packages/utils/src/build-context.js
https://github.com/GoogleChrome/lighthouse-ci/blob/master/packages/utils/src/build-context.js
Apache-2.0
function getEmailFromAuthor(author) { const emailRegex = new RegExp(/ <(\S+@\S+)>$/); const emailMatch = author.match(emailRegex); if (!emailMatch) return null; return emailMatch[1]; } /** * @param {string} hash * @return {string} */ function getAvatarUrl(hash = 'HEAD') { const envHash = getEnvVarIfSet([ // Manual override 'LHCI_BUILD_CONTEXT__AVATAR_URL', ]); if (envHash) return envHash; // Next try to parse the email from the complete author. const author = getAuthor(hash); const email = getEmailFromAuthor(author); if (email) return getGravatarUrlFromEmail(email); // Finally fallback to git again if we couldn't parse the email out of the author. const result = childProcess.spawnSync('git', ['log', '--format=%aE', '-n', '1', hash], { encoding: 'utf8', }); if (result.status !== 0) { throw new Error( "Unable to determine commit author's avatar URL because `git log --format=%aE -n 1` failed to provide author's email. " + 'This can be overridden with setting LHCI_BUILD_CONTEXT__AVATAR_URL env.' ); } return getGravatarUrlFromEmail(result.stdout); } /** * @param {string} email * @return {string} */ function getGravatarUrlFromEmail(email) { // Use default gravatar image, see https://en.gravatar.com/site/implement/images/. const md5 = crypto.createHash('md5'); md5.update(email.trim().toLowerCase()); return `https://www.gravatar.com/avatar/${md5.digest('hex')}.jpg?d=identicon`; } /** * @param {string} hash * @return {string} */ function getAncestorHashForBase(hash) { const result = childProcess.spawnSync('git', ['rev-parse', `${hash}^`], {encoding: 'utf8'}); // Ancestor hash is optional, so do not throw if it can't be computed. // See https://github.com/GoogleChrome/lighthouse-ci/issues/36 if (result.status !== 0) return ''; return result.stdout.trim(); } /** * @param {string} hash * @param {string} baseBranch * @return {string} */ function getAncestorHashForBranch(hash, baseBranch) { const result = runCommandsUntilFirstSuccess([ ['git', ['merge-base', hash, `origin/${baseBranch}`]], ['git', ['merge-base', hash, baseBranch]], ]); // Ancestor hash is optional, so do not throw if it can't be computed. // See https://github.com/GoogleChrome/lighthouse-ci/issues/36 if (result.status !== 0) return ''; return result.stdout.trim(); } /** * @param {string} hash * @param {string} baseBranch * @return {string} */ function getAncestorHash(hash, baseBranch) { const envHash = getEnvVarIfSet([ // Manual override 'LHCI_BUILD_CONTEXT__ANCESTOR_HASH', // GitLab CI 'CI_COMMIT_BEFORE_SHA', ]); if (envHash && envHash !== '0000000000000000000000000000000000000000') return envHash; return getCurrentBranch() === baseBranch ? getAncestorHashForBase(hash) : getAncestorHashForBranch(hash, baseBranch); } /** @param {string|undefined} apiHost */ function getGitHubRepoSlug(apiHost = undefined) { const envSlug = getEnvVarIfSet([ // Manual override 'LHCI_BUILD_CONTEXT__GITHUB_REPO_SLUG', // Travis CI 'TRAVIS_PULL_REQUEST_SLUG', 'TRAVIS_REPO_SLUG', // GitHub Actions 'GITHUB_REPOSITORY', // Drone CI 'DRONE_REPO', ]); if (envSlug) return envSlug; // Support CircleCI if (process.env.CIRCLE_PROJECT_USERNAME && process.env.CIRCLE_PROJECT_REPONAME) { return `${process.env.CIRCLE_PROJECT_USERNAME}/${process.env.CIRCLE_PROJECT_REPONAME}`; } const remote = getGitRemote(); if (remote && remote.includes('github.com')) { const remoteMatch = remote.match(/github\.com.([^/]+\/[^/]+?)(\.git|$)/); if (remoteMatch) return remoteMatch[1]; } if (remote && apiHost && !apiHost.includes('github.com')) { const hostMatch = apiHost.match(/:\/\/(.*?)(\/|$)/); if (!hostMatch) return undefined; const remoteRegex = new RegExp(`${hostMatch[1]}(:|\\/)([^/]+\\/.+)\\.git`); const remoteMatch = remote.match(remoteRegex); if (remoteMatch) return remoteMatch[2]; } }
@param {string} author @return {string | null}
getEmailFromAuthor ( author )
javascript
GoogleChrome/lighthouse-ci
packages/utils/src/build-context.js
https://github.com/GoogleChrome/lighthouse-ci/blob/master/packages/utils/src/build-context.js
Apache-2.0
function removeAllItems(auditsToFakeSrc) { const output = JSON.parse(JSON.stringify(auditsToFakeSrc)); for (const value of Object.values(output)) { if (!value.items) continue; value.items = []; } return output; }
@param {Record<string, StrictOmit<AuditGenDef, 'auditId'>>} auditsToFakeSrc @return {Record<string, StrictOmit<AuditGenDef, 'auditId'>>}
removeAllItems ( auditsToFakeSrc )
javascript
GoogleChrome/lighthouse-ci
packages/utils/src/seed-data/dataset-generator.js
https://github.com/GoogleChrome/lighthouse-ci/blob/master/packages/utils/src/seed-data/dataset-generator.js
Apache-2.0
function setLighthouseVersion(runs, version) { for (const run of runs) { const lhr = JSON.parse(run.lhr); lhr.lighthouseVersion = version; run.lhr = JSON.stringify(lhr); } return runs; }
@param {Array<LHCI.ServerCommand.Run>} runs @param {string} version
setLighthouseVersion ( runs , version )
javascript
GoogleChrome/lighthouse-ci
packages/utils/src/seed-data/dataset-generator.js
https://github.com/GoogleChrome/lighthouse-ci/blob/master/packages/utils/src/seed-data/dataset-generator.js
Apache-2.0
next() { // Robert Jenkins' 32 bit integer hash function. this.seed = (this.seed + 0x7ed55d16 + (this.seed << 12)) & 0xffffffff; this.seed = (this.seed ^ 0xc761c23c ^ (this.seed >>> 19)) & 0xffffffff; this.seed = (this.seed + 0x165667b1 + (this.seed << 5)) & 0xffffffff; this.seed = ((this.seed + 0xd3a2646c) ^ (this.seed << 9)) & 0xffffffff; this.seed = (this.seed + 0xfd7046c5 + (this.seed << 3)) & 0xffffffff; this.seed = (this.seed ^ 0xb55a4f09 ^ (this.seed >>> 16)) & 0xffffffff; return (this.seed & 0xfffffff) / 0x10000000; }
Generates a psuedo-random but deterministic number. Based on the v8 implementation of Math.random for testing. @see https://github.com/chromium/octane/blob/570ad1ccfe86e3eecba0636c8f932ac08edec517/base.js#L120
next ( )
javascript
GoogleChrome/lighthouse-ci
packages/utils/src/seed-data/prandom.js
https://github.com/GoogleChrome/lighthouse-ci/blob/master/packages/utils/src/seed-data/prandom.js
Apache-2.0
static toAlphanumeric(input) { const valueOutOf36 = Math.round(input * 35); if (valueOutOf36 < 10) return valueOutOf36.toString(); return String.fromCharCode(97 + valueOutOf36 - 10); }
Returns a random character from the character class [a-z0-9]. @param {number} input @return {string}
toAlphanumeric ( input )
javascript
GoogleChrome/lighthouse-ci
packages/utils/src/seed-data/prandom.js
https://github.com/GoogleChrome/lighthouse-ci/blob/master/packages/utils/src/seed-data/prandom.js
Apache-2.0
module.exports = async (browser, context) => { // launch browser for LHCI const page = await browser.newPage(); await page.goto("https://example.com"); // close session for next run await page.close(); };
@param {puppeteer.Browser} browser @param {{url: string, options: LHCI.CollectCommand.Options}} context
module.exports
javascript
GoogleChrome/lighthouse-ci
docs/recipes/puppeteer-example.js
https://github.com/GoogleChrome/lighthouse-ci/blob/master/docs/recipes/puppeteer-example.js
Apache-2.0
module.hardware = function hardware(mess){ //since Chrome extension content-scripts do not share the javascript environment with the page script that loaded jspsych, //we will need to use hacky methods like communicating through DOM events. var jspsychEvt = new CustomEvent('jspsych', {detail: mess}); document.dispatchEvent(jspsychEvt); //And voila! it will be the job of the content script injected by the extension to listen for the event and do the appropriate actions. };
Allows communication with user hardware through our custom Google Chrome extension + native C++ program @param {object} mess The message to be passed to our extension, see its documentation for the expected members of this object. @author Daniel Rivas
hardware ( mess )
javascript
awslabs/datawig
datawig-js/static/jspsych-6.1.0/jspsych.js
https://github.com/awslabs/datawig/blob/master/datawig-js/static/jspsych-6.1.0/jspsych.js
Apache-2.0
jsPsych.plugins['categorize-html'] = (function() { var plugin = {}; plugin.info = { name: 'categorize-html', description: '', parameters: { stimulus: { type: jsPsych.plugins.parameterType.HTML_STRING, pretty_name: 'Stimulus', default: undefined, description: 'The HTML content to be displayed.' }, key_answer: { type: jsPsych.plugins.parameterType.KEYCODE, pretty_name: 'Key answer', default: undefined, description: 'The key to indicate the correct response.' }, choices: { type: jsPsych.plugins.parameterType.KEYCODE, pretty_name: 'Choices', default: jsPsych.ALL_KEYS, array: true, description: 'The keys the subject is allowed to press to respond to the stimulus.' }, text_answer: { type: jsPsych.plugins.parameterType.STRING, pretty_name: 'Text answer', default: null, description: 'Label that is associated with the correct answer.' }, correct_text: { type: jsPsych.plugins.parameterType.STRING, pretty_name: 'Correct text', default: "<p class='feedback'>Correct</p>", description: 'String to show when correct answer is given.' }, incorrect_text: { type: jsPsych.plugins.parameterType.STRING, pretty_name: 'Incorrect text', default: "<p class='feedback'>Incorrect</p>", description: 'String to show when incorrect answer is given.' }, prompt: { type: jsPsych.plugins.parameterType.STRING, pretty_name: 'Prompt', default: null, description: 'Any content here will be displayed below the stimulus.' }, force_correct_button_press: { type: jsPsych.plugins.parameterType.BOOL, pretty_name: 'Force correct button press', default: false, description: 'If set to true, then the subject must press the correct response key after feedback in order to advance to next trial.' }, show_stim_with_feedback: { type: jsPsych.plugins.parameterType.BOOL, default: true, no_function: false, description: '' }, show_feedback_on_timeout: { type: jsPsych.plugins.parameterType.BOOL, pretty_name: 'Show feedback on timeout', default: false, description: 'If true, stimulus will be shown during feedback. If false, only the text feedback will be displayed during feedback.' }, timeout_message: { type: jsPsych.plugins.parameterType.STRING, pretty_name: 'Timeout message', default: "<p>Please respond faster.</p>", description: 'The message displayed on a timeout non-response.' }, stimulus_duration: { type: jsPsych.plugins.parameterType.INT, pretty_name: 'Stimulus duration', default: null, description: 'How long to hide stimulus.' }, trial_duration: { type: jsPsych.plugins.parameterType.INT, pretty_name: 'Trial duration', default: null, description: 'How long to show trial' }, feedback_duration: { type: jsPsych.plugins.parameterType.INT, pretty_name: 'Feedback duration', default: 2000, description: 'How long to show feedback.' } } } plugin.trial = function(display_element, trial) { display_element.innerHTML = '<div id="jspsych-categorize-html-stimulus" class="jspsych-categorize-html-stimulus">'+trial.stimulus+'</div>'; // hide image after time if the timing parameter is set if (trial.stimulus_duration !== null) { jsPsych.pluginAPI.setTimeout(function() { display_element.querySelector('#jspsych-categorize-html-stimulus').style.visibility = 'hidden'; }, trial.stimulus_duration); } // if prompt is set, show prompt if (trial.prompt !== null) { display_element.innerHTML += trial.prompt; } var trial_data = {}; // create response function var after_response = function(info) { // kill any remaining setTimeout handlers jsPsych.pluginAPI.clearAllTimeouts(); // clear keyboard listener jsPsych.pluginAPI.cancelAllKeyboardResponses(); var correct = false; if (trial.key_answer == info.key) { correct = true; } // save data trial_data = { "rt": info.rt, "correct": correct, "stimulus": trial.stimulus, "key_press": info.key }; display_element.innerHTML = ''; var timeout = info.rt == null; doFeedback(correct, timeout); } jsPsych.pluginAPI.getKeyboardResponse({ callback_function: after_response, valid_responses: trial.choices, rt_method: 'performance', persist: false, allow_held_key: false }); if (trial.trial_duration !== null) { jsPsych.pluginAPI.setTimeout(function() { after_response({ key: null, rt: null }); }, trial.trial_duration); } function doFeedback(correct, timeout) { if (timeout && !trial.show_feedback_on_timeout) { display_element.innerHTML += trial.timeout_message; } else { // show image during feedback if flag is set if (trial.show_stim_with_feedback) { display_element.innerHTML = '<div id="jspsych-categorize-html-stimulus" class="jspsych-categorize-html-stimulus">'+trial.stimulus+'</div>'; } // substitute answer in feedback string. var atext = ""; if (correct) { atext = trial.correct_text.replace("%ANS%", trial.text_answer); } else { atext = trial.incorrect_text.replace("%ANS%", trial.text_answer); } // show the feedback display_element.innerHTML += atext; } // check if force correct button press is set if (trial.force_correct_button_press && correct === false && ((timeout && trial.show_feedback_on_timeout) || !timeout)) { var after_forced_response = function(info) { endTrial(); } jsPsych.pluginAPI.getKeyboardResponse({ callback_function: after_forced_response, valid_responses: [trial.key_answer], rt_method: 'performance', persist: false, allow_held_key: false }); } else { jsPsych.pluginAPI.setTimeout(function() { endTrial(); }, trial.feedback_duration); } } function endTrial() { display_element.innerHTML = ''; jsPsych.finishTrial(trial_data); } }; return plugin; })();
jspsych plugin for categorization trials with feedback Josh de Leeuw documentation: docs.jspsych.org *
(anonymous) ( )
javascript
awslabs/datawig
datawig-js/static/jspsych-6.1.0/plugins/jspsych-categorize-html.js
https://github.com/awslabs/datawig/blob/master/datawig-js/static/jspsych-6.1.0/plugins/jspsych-categorize-html.js
Apache-2.0
jsPsych.plugins["audio-button-response"] = (function() { var plugin = {}; jsPsych.pluginAPI.registerPreload('audio-button-response', 'stimulus', 'audio'); plugin.info = { name: 'audio-button-response', description: '', parameters: { stimulus: { type: jsPsych.plugins.parameterType.AUDIO, pretty_name: 'Stimulus', default: undefined, description: 'The audio to be played.' }, choices: { type: jsPsych.plugins.parameterType.STRING, pretty_name: 'Choices', default: undefined, array: true, description: 'The button labels.' }, button_html: { type: jsPsych.plugins.parameterType.HTML_STRING, pretty_name: 'Button HTML', default: '<button class="jspsych-btn">%choice%</button>', array: true, description: 'Custom button. Can make your own style.' }, prompt: { type: jsPsych.plugins.parameterType.STRING, pretty_name: 'Prompt', default: null, description: 'Any content here will be displayed below the stimulus.' }, trial_duration: { type: jsPsych.plugins.parameterType.INT, pretty_name: 'Trial duration', default: null, description: 'The maximum duration to wait for a response.' }, margin_vertical: { type: jsPsych.plugins.parameterType.STRING, pretty_name: 'Margin vertical', default: '0px', description: 'Vertical margin of button.' }, margin_horizontal: { type: jsPsych.plugins.parameterType.STRING, pretty_name: 'Margin horizontal', default: '8px', description: 'Horizontal margin of button.' }, response_ends_trial: { type: jsPsych.plugins.parameterType.BOOL, pretty_name: 'Response ends trial', default: true, description: 'If true, the trial will end when user makes a response.' }, trial_ends_after_audio: { type: jsPsych.plugins.parameterType.BOOL, pretty_name: 'Trial ends after audio', default: false, description: 'If true, then the trial will end as soon as the audio file finishes playing.' }, } } plugin.trial = function(display_element, trial) { // setup stimulus var context = jsPsych.pluginAPI.audioContext(); if(context !== null){ var source = context.createBufferSource(); source.buffer = jsPsych.pluginAPI.getAudioBuffer(trial.stimulus); source.connect(context.destination); } else { var audio = jsPsych.pluginAPI.getAudioBuffer(trial.stimulus); audio.currentTime = 0; } // set up end event if trial needs it if(trial.trial_ends_after_audio){ if(context !== null){ source.onended = function() { end_trial(); } } else { audio.addEventListener('ended', end_trial); } } //display buttons var buttons = []; if (Array.isArray(trial.button_html)) { if (trial.button_html.length == trial.choices.length) { buttons = trial.button_html; } else { console.error('Error in image-button-response plugin. The length of the button_html array does not equal the length of the choices array'); } } else { for (var i = 0; i < trial.choices.length; i++) { buttons.push(trial.button_html); } } var html = '<div id="jspsych-audio-button-response-btngroup">'; for (var i = 0; i < trial.choices.length; i++) { var str = buttons[i].replace(/%choice%/g, trial.choices[i]); html += '<div class="jspsych-audio-button-response-button" style="cursor: pointer; display: inline-block; margin:'+trial.margin_vertical+' '+trial.margin_horizontal+'" id="jspsych-audio-button-response-button-' + i +'" data-choice="'+i+'">'+str+'</div>'; } html += '</div>'; //show prompt if there is one if (trial.prompt !== null) { html += trial.prompt; } display_element.innerHTML = html; for (var i = 0; i < trial.choices.length; i++) { display_element.querySelector('#jspsych-audio-button-response-button-' + i).addEventListener('click', function(e){ var choice = e.currentTarget.getAttribute('data-choice'); // don't use dataset for jsdom compatibility after_response(choice); }); } // store response var response = { rt: null, button: null }; // function to handle responses by the subject function after_response(choice) { // measure rt var end_time = performance.now(); var rt = end_time - start_time; response.button = choice; response.rt = rt; // disable all the buttons after a response var btns = document.querySelectorAll('.jspsych-audio-button-response-button button'); for(var i=0; i<btns.length; i++){ //btns[i].removeEventListener('click'); btns[i].setAttribute('disabled', 'disabled'); } if (trial.response_ends_trial) { end_trial(); } }; // function to end trial when it is time function end_trial() { // stop the audio file if it is playing // remove end event listeners if they exist if(context !== null){ source.stop(); source.onended = function() { } } else { audio.pause(); audio.removeEventListener('ended', end_trial); } // kill any remaining setTimeout handlers jsPsych.pluginAPI.clearAllTimeouts(); // gather the data to store for the trial var trial_data = { "rt": response.rt, "stimulus": trial.stimulus, "button_pressed": response.button }; // clear the display display_element.innerHTML = ''; // move on to the next trial jsPsych.finishTrial(trial_data); }; // start time var start_time = performance.now(); // start audio if(context !== null){ startTime = context.currentTime; source.start(startTime); } else { audio.play(); } // end trial if time limit is set if (trial.trial_duration !== null) { jsPsych.pluginAPI.setTimeout(function() { end_trial(); }, trial.trial_duration); } }; return plugin; })();
jspsych-audio-button-response Kristin Diep plugin for playing an audio file and getting a keyboard response documentation: docs.jspsych.org *
(anonymous) ( )
javascript
awslabs/datawig
datawig-js/static/jspsych-6.1.0/plugins/jspsych-audio-button-response.js
https://github.com/awslabs/datawig/blob/master/datawig-js/static/jspsych-6.1.0/plugins/jspsych-audio-button-response.js
Apache-2.0
jsPsych.plugins['image-slider-response'] = (function() { var plugin = {}; jsPsych.pluginAPI.registerPreload('image-slider-response', 'stimulus', 'image'); plugin.info = { name: 'image-slider-response', description: '', parameters: { stimulus: { type: jsPsych.plugins.parameterType.IMAGE, pretty_name: 'Stimulus', default: undefined, description: 'The image to be displayed' }, stimulus_height: { type: jsPsych.plugins.parameterType.INT, pretty_name: 'Image height', default: null, description: 'Set the image height in pixels' }, stimulus_width: { type: jsPsych.plugins.parameterType.INT, pretty_name: 'Image width', default: null, description: 'Set the image width in pixels' }, maintain_aspect_ratio: { type: jsPsych.plugins.parameterType.BOOL, pretty_name: 'Maintain aspect ratio', default: true, description: 'Maintain the aspect ratio after setting width or height' }, min: { type: jsPsych.plugins.parameterType.INT, pretty_name: 'Min slider', default: 0, description: 'Sets the minimum value of the slider.' }, max: { type: jsPsych.plugins.parameterType.INT, pretty_name: 'Max slider', default: 100, description: 'Sets the maximum value of the slider', }, start: { type: jsPsych.plugins.parameterType.INT, pretty_name: 'Slider starting value', default: 50, description: 'Sets the starting value of the slider', }, step: { type: jsPsych.plugins.parameterType.INT, pretty_name: 'Step', default: 1, description: 'Sets the step of the slider' }, labels: { type: jsPsych.plugins.parameterType.HTML_STRING, pretty_name:'Labels', default: [], array: true, description: 'Labels of the slider.', }, slider_width: { type: jsPsych.plugins.parameterType.INT, pretty_name:'Slider width', default: null, description: 'Width of the slider in pixels.' }, button_label: { type: jsPsych.plugins.parameterType.STRING, pretty_name: 'Button label', default: 'Continue', array: false, description: 'Label of the button to advance.' }, require_movement: { type: jsPsych.plugins.parameterType.BOOL, pretty_name: 'Require movement', default: false, description: 'If true, the participant will have to move the slider before continuing.' }, prompt: { type: jsPsych.plugins.parameterType.STRING, pretty_name: 'Prompt', default: null, description: 'Any content here will be displayed below the slider.' }, stimulus_duration: { type: jsPsych.plugins.parameterType.INT, pretty_name: 'Stimulus duration', default: null, description: 'How long to hide the stimulus.' }, trial_duration: { type: jsPsych.plugins.parameterType.INT, pretty_name: 'Trial duration', default: null, description: 'How long to show the trial.' }, response_ends_trial: { type: jsPsych.plugins.parameterType.BOOL, pretty_name: 'Response ends trial', default: true, description: 'If true, trial will end when user makes a response.' }, } } plugin.trial = function(display_element, trial) { var html = '<div id="jspsych-image-slider-response-wrapper" style="margin: 100px 0px;">'; html += '<div id="jspsych-image-slider-response-stimulus">'; html += '<img src="'+trial.stimulus+'" style="'; if(trial.stimulus_height !== null){ html += 'height:'+trial.stimulus_height+'px; ' if(trial.stimulus_width == null && trial.maintain_aspect_ratio){ html += 'width: auto; '; } } if(trial.stimulus_width !== null){ html += 'width:'+trial.stimulus_width+'px; ' if(trial.stimulus_height == null && trial.maintain_aspect_ratio){ html += 'height: auto; '; } } html += '"></img>'; html += '</div>'; html += '<div class="jspsych-image-slider-response-container" style="position:relative; margin: 0 auto 3em auto; '; if(trial.slider_width !== null){ html += 'width:'+trial.slider_width+'px;'; } html += '">'; html += '<input type="range" value="'+trial.start+'" min="'+trial.min+'" max="'+trial.max+'" step="'+trial.step+'" style="width: 100%;" id="jspsych-image-slider-response-response"></input>'; html += '<div>' for(var j=0; j < trial.labels.length; j++){ var width = 100/(trial.labels.length-1); var left_offset = (j * (100 /(trial.labels.length - 1))) - (width/2); html += '<div style="display: inline-block; position: absolute; left:'+left_offset+'%; text-align: center; width: '+width+'%;">'; html += '<span style="text-align: center; font-size: 80%;">'+trial.labels[j]+'</span>'; html += '</div>' } html += '</div>'; html += '</div>'; html += '</div>'; if (trial.prompt !== null){ html += trial.prompt; } // add submit button html += '<button id="jspsych-image-slider-response-next" class="jspsych-btn" '+ (trial.require_movement ? "disabled" : "") + '>'+trial.button_label+'</button>'; display_element.innerHTML = html; var response = { rt: null, response: null }; if(trial.require_movement){ display_element.querySelector('#jspsych-image-slider-response-response').addEventListener('change', function(){ display_element.querySelector('#jspsych-image-slider-response-next').disabled = false; }) } display_element.querySelector('#jspsych-image-slider-response-next').addEventListener('click', function() { // measure response time var endTime = performance.now(); response.rt = endTime - startTime; response.response = display_element.querySelector('#jspsych-image-slider-response-response').value; if(trial.response_ends_trial){ end_trial(); } else { display_element.querySelector('#jspsych-image-slider-response-next').disabled = true; } }); function end_trial(){ jsPsych.pluginAPI.clearAllTimeouts(); // save data var trialdata = { "rt": response.rt, "response": response.response }; display_element.innerHTML = ''; // next trial jsPsych.finishTrial(trialdata); } if (trial.stimulus_duration !== null) { jsPsych.pluginAPI.setTimeout(function() { display_element.querySelector('#jspsych-image-slider-response-stimulus').style.visibility = 'hidden'; }, trial.stimulus_duration); } // end trial if trial_duration is set if (trial.trial_duration !== null) { jsPsych.pluginAPI.setTimeout(function() { end_trial(); }, trial.trial_duration); } var startTime = performance.now(); }; return plugin; })();
jspsych-image-slider-response a jspsych plugin for free response survey questions Josh de Leeuw documentation: docs.jspsych.org
(anonymous) ( )
javascript
awslabs/datawig
datawig-js/static/jspsych-6.1.0/plugins/jspsych-image-slider-response.js
https://github.com/awslabs/datawig/blob/master/datawig-js/static/jspsych-6.1.0/plugins/jspsych-image-slider-response.js
Apache-2.0
jsPsych.plugins['iat-image'] = (function() { var plugin = {}; jsPsych.pluginAPI.registerPreload('iat-image', 'stimulus', 'image'); plugin.info = { name: 'iat-image', description: '', parameters: { stimulus: { type: jsPsych.plugins.parameterType.IMAGE, pretty_name: 'Stimulus', default: undefined, description: 'The image to be displayed' }, left_category_key: { type: jsPsych.plugins.parameterType.HTML_STRING, pretty_name: 'Left category key', default: 'E', description: 'Key press that is associated with the left category label.' }, right_category_key: { type: jsPsych.plugins.parameterType.STRING, pretty_name: 'Right category key', default: 'I', description: 'Key press that is associated with the right category label.' }, left_category_label: { type: jsPsych.plugins.parameterType.STRING, pretty_name: 'Left category label', array: true, default: ['left'], description: 'The label that is associated with the stimulus. Aligned to the left side of page.' }, right_category_label: { type: jsPsych.plugins.parameterType.STRING, pretty_name: 'Right category label', array: true, default: ['right'], description: 'The label that is associated with the stimulus. Aligned to the right side of the page.' }, key_to_move_forward: { type: jsPsych.plugins.parameterType.KEYCODE, pretty_name: 'Key to move forward', array: true, default: jsPsych.ALL_KEYS, description: 'The keys that allow the user to advance to the next trial if their key press was incorrect.' }, display_feedback: { type: jsPsych.plugins.parameterType.BOOL, pretty_name: 'Display feedback', default: false, description: 'If true, then html when wrong will be displayed when user makes an incorrect key press.' }, html_when_wrong: { type: jsPsych.plugins.parameterType.HTML_STRING, pretty_name: 'HTML when wrong', default: '<span style="color: red; font-size: 80px">X</span>', description: 'The image to display when a user presses the wrong key.' }, bottom_instructions: { type: jsPsych.plugins.parameterType.HTML_STRING, pretty_name: 'Bottom instructions', default: '<p>If you press the wrong key, a red X will appear. Press any key to continue.</p>', description: 'Instructions shown at the bottom of the page.' }, force_correct_key_press: { type: jsPsych.plugins.parameterType.BOOL, pretty_name: 'Force correct key press', default: false, description: 'If true, in order to advance to the next trial after a wrong key press the user will be forced to press the correct key.' }, stim_key_association: { type: jsPsych.plugins.parameterType.HTML_STRING, pretty_name: 'Stimulus key association', options: ['left', 'right'], default: 'undefined', description: 'Stimulus will be associated with eight "left" or "right".' }, response_ends_trial: { type: jsPsych.plugins.parameterType.BOOL, pretty_name: 'Response ends trial', default: true, description: 'If true, trial will end when user makes a response.' }, trial_duration: { type: jsPsych.plugins.parameterType.INT, pretty_name: 'Trial duration', default: null, description: 'How long to show the trial.' }, } } plugin.trial = function(display_element, trial) { var html_str = ""; html_str += "<div style='position: absolute; height: 20%; width: 100%; margin-left: auto; margin-right: auto; top: 42%; left: 0; right: 0'><img src='"+trial.stimulus+"' id='jspsych-iat-stim'></img></div>"; html_str += "<div id='trial_left_align' style='position: absolute; top: 18%; left: 20%'>"; if(trial.left_category_label.length == 1) { html_str += "<p>Press " + trial.left_category_key + " for:<br> " + trial.left_category_label[0].bold() + "</p></div>"; } else { html_str += "<p>Press " + trial.left_category_key + " for:<br> " + trial.left_category_label[0].bold() + "<br>" + "or<br>" + trial.left_category_label[1].bold() + "</p></div>"; } html_str += "<div id='trial_right_align' style='position: absolute; top: 18%; right: 20%'>"; if(trial.right_category_label.length == 1) { html_str += "<p>Press " + trial.right_category_key + " for:<br> " + trial.right_category_label[0].bold() + '</p></div>'; } else { html_str += "<p>Press " + trial.right_category_key + " for:<br> " + trial.right_category_label[0].bold() + "<br>" + "or<br>" + trial.right_category_label[1].bold() + "</p></div>"; } html_str += "<div id='wrongImgID' style='position:relative; top: 300px; margin-left: auto; margin-right: auto; left: 0; right: 0'>"; if(trial.display_feedback === true) { html_str += "<div id='wrongImgContainer' style='visibility: hidden; position: absolute; top: -75px; margin-left: auto; margin-right: auto; left: 0; right: 0'><p>"+trial.html_when_wrong+"</p></div>"; html_str += "<div>"+trial.bottom_instructions+"</div>"; } else { html_str += "<div>"+trial.bottom_instructions+"</div>"; } html_str += "</div>"; display_element.innerHTML = html_str; // store response var response = { rt: null, key: null, correct: false }; // function to end trial when it is time var end_trial = function() { // kill any remaining setTimeout handlers jsPsych.pluginAPI.clearAllTimeouts(); // kill keyboard listeners if (typeof keyboardListener !== 'undefined') { jsPsych.pluginAPI.cancelKeyboardResponse(keyboardListener); } // gather the data to store for the trial var trial_data = { "rt": response.rt, "stimulus": trial.stimulus, "key_press": response.key, "correct": response.correct }; // clears the display display_element.innerHTML = ''; // move on to the next trial jsPsych.finishTrial(trial_data); }; var leftKeyCode = jsPsych.pluginAPI.convertKeyCharacterToKeyCode(trial.left_category_key); var rightKeyCode = jsPsych.pluginAPI.convertKeyCharacterToKeyCode(trial.right_category_key); // function to handle responses by the subject var after_response = function(info) { var wImg = document.getElementById("wrongImgContainer"); // after a valid response, the stimulus will have the CSS class 'responded' // which can be used to provide visual feedback that a response was recorded display_element.querySelector('#jspsych-iat-stim').className += ' responded'; // only record the first response if (response.key == null ) { response = info; } if(trial.stim_key_association == "right") { if(response.rt !== null && response.key == rightKeyCode) { response.correct = true; if (trial.response_ends_trial) { end_trial(); } } else { response.correct = false; if(!trial.response_ends_trial && trial.display_feedback == true) { wImg.style.visibility = "visible"; } if (trial.response_ends_trial && trial.display_feedback == true) { wImg.style.visibility = "visible"; if(trial.force_correct_key_press) { var keyListener = jsPsych.pluginAPI.getKeyboardResponse({ callback_function: end_trial, valid_responses: [trial.right_category_key] }); } else { var keyListener = jsPsych.pluginAPI.getKeyboardResponse({ callback_function: end_trial, valid_responses: trial.key_to_move_forward });} } else if(trial.response_ends_trial && trial.display_feedback != true) { var keyListener = jsPsych.pluginAPI.getKeyboardResponse({ callback_function: end_trial, valid_responses: [jsPsych.ALL_KEYS] }); } else if(!trial.response_ends_trial && trial.display_feedback != true) { } } } else if(trial.stim_key_association == "left") { if(response.rt !== null && response.key == leftKeyCode) { response.correct = true; if (trial.response_ends_trial) { end_trial(); } } else { response.correct = false; if(!trial.response_ends_trial && trial.display_feedback == true) { wImg.style.visibility = "visible"; } if (trial.response_ends_trial && trial.display_feedback == true) { wImg.style.visibility = "visible"; if(trial.force_correct_key_press) { var keyListener = jsPsych.pluginAPI.getKeyboardResponse({ callback_function: end_trial, valid_responses: [trial.left_category_key] }); } else { var keyListener = jsPsych.pluginAPI.getKeyboardResponse({ callback_function: end_trial, valid_responses: trial.key_to_move_forward });} } else if(trial.response_ends_trial && trial.display_feedback != true) { var keyListener = jsPsych.pluginAPI.getKeyboardResponse({ callback_function: end_trial, valid_responses: [jsPsych.ALL_KEYS] }); } else if(!trial.response_ends_trial && trial.display_feedback != true) { } } } }; // start the response listener if (trial.left_category_key != jsPsych.NO_KEYS && trial.right_category_key != jsPsych.NO_KEYS) { var keyboardListener = jsPsych.pluginAPI.getKeyboardResponse({ callback_function: after_response, valid_responses: [trial.left_category_key, trial.right_category_key], rt_method: 'performance', persist: false, allow_held_key: false }); } // end trial if time limit is set if (trial.trial_duration !== null && trial.response_ends_trial != true) { jsPsych.pluginAPI.setTimeout(function() { end_trial(); }, trial.trial_duration); } }; return plugin; })();
jspsych-iat Kristin Diep plugin for displaying a stimulus and getting a keyboard response documentation: docs.jspsych.org *
(anonymous) ( )
javascript
awslabs/datawig
datawig-js/static/jspsych-6.1.0/plugins/jspsych-iat-image.js
https://github.com/awslabs/datawig/blob/master/datawig-js/static/jspsych-6.1.0/plugins/jspsych-iat-image.js
Apache-2.0
jsPsych.plugins["resize"] = (function() { var plugin = {}; plugin.info = { name: 'resize', description: '', parameters: { item_height: { type: jsPsych.plugins.parameterType.INT, pretty_name: 'Item height', default: 1, description: 'The height of the item to be measured.' }, item_width: { type: jsPsych.plugins.parameterType.INT, pretty_name: 'Item width', default: 1, description: 'The width of the item to be measured.' }, prompt: { type: jsPsych.plugins.parameterType.STRING, pretty_name: 'Prompt', default: null, description: 'The content displayed below the resizable box and above the button.' }, pixels_per_unit: { type: jsPsych.plugins.parameterType.INT, pretty_name: 'Pixels per unit', default: 100, description: 'After the scaling factor is applied, this many pixels will equal one unit of measurement.' }, starting_size: { type: jsPsych.plugins.parameterType.INT, pretty_name: 'Starting size', default: 100, description: 'The initial size of the box, in pixels, along the larget dimension.' }, button_label: { type: jsPsych.plugins.parameterType.STRING, pretty_name: 'Button label', default: 'Continue', description: 'Label to display on the button to complete calibration.' }, } } plugin.trial = function(display_element, trial) { var aspect_ratio = trial.item_width / trial.item_height; // variables to determine div size if(trial.item_width >= trial.item_height){ var start_div_width = trial.starting_size; var start_div_height = Math.round(trial.starting_size / aspect_ratio); } else { var start_div_height = trial.starting_size; var start_div_width = Math.round(trial.starting_size * aspect_ratio); } // create html for display var html ='<div id="jspsych-resize-div" style="border: 2px solid steelblue; height: '+start_div_height+'px; width:'+start_div_width+'px; margin: 7px auto; background-color: lightsteelblue; position: relative;">'; html += '<div id="jspsych-resize-handle" style="cursor: nwse-resize; background-color: steelblue; width: 10px; height: 10px; border: 2px solid lightsteelblue; position: absolute; bottom: 0; right: 0;"></div>'; html += '</div>'; if (trial.prompt !== null){ html += trial.prompt; } html += '<a class="jspsych-btn" id="jspsych-resize-btn">'+trial.button_label+'</a>'; // render display_element.innerHTML = html; // listens for the click document.getElementById("jspsych-resize-btn").addEventListener('click', function() { scale(); end_trial(); }); var dragging = false; var origin_x, origin_y; var cx, cy; var mousedownevent = function(e){ e.preventDefault(); dragging = true; origin_x = e.pageX; origin_y = e.pageY; cx = parseInt(scale_div.style.width); cy = parseInt(scale_div.style.height); } display_element.querySelector('#jspsych-resize-handle').addEventListener('mousedown', mousedownevent); var mouseupevent = function(e){ dragging = false; } document.addEventListener('mouseup', mouseupevent); var scale_div = display_element.querySelector('#jspsych-resize-div'); var resizeevent = function(e){ if(dragging){ var dx = (e.pageX - origin_x); var dy = (e.pageY - origin_y); if(Math.abs(dx) >= Math.abs(dy)){ scale_div.style.width = Math.round(Math.max(20, cx+dx*2)) + "px"; scale_div.style.height = Math.round(Math.max(20, cx+dx*2) / aspect_ratio ) + "px"; } else { scale_div.style.height = Math.round(Math.max(20, cy+dy*2)) + "px"; scale_div.style.width = Math.round(aspect_ratio * Math.max(20, cy+dy*2)) + "px"; } } } document.addEventListener('mousemove', resizeevent); // scales the stimulus var scale_factor; var final_height_px, final_width_px; function scale() { final_width_px = scale_div.offsetWidth; //final_height_px = scale_div.offsetHeight; var pixels_unit_screen = final_width_px / trial.item_width; scale_factor = pixels_unit_screen / trial.pixels_per_unit; document.getElementById("jspsych-content").style.transform = "scale(" + scale_factor + ")"; }; // function to end trial function end_trial() { // clear document event listeners document.removeEventListener('mousemove', resizeevent); document.removeEventListener('mouseup', mouseupevent); // clear the screen display_element.innerHTML = ''; // finishes trial var trial_data = { 'final_height_px': final_height_px, 'final_width_px': final_width_px, 'scale_factor': scale_factor } jsPsych.finishTrial(trial_data); } }; return plugin; })();
jspsych-resize Steve Chao plugin for controlling the real world size of the display documentation: docs.jspsych.org *
(anonymous) ( )
javascript
awslabs/datawig
datawig-js/static/jspsych-6.1.0/plugins/jspsych-resize.js
https://github.com/awslabs/datawig/blob/master/datawig-js/static/jspsych-6.1.0/plugins/jspsych-resize.js
Apache-2.0
jsPsych.plugins["audio-keyboard-response"] = (function() { var plugin = {}; jsPsych.pluginAPI.registerPreload('audio-keyboard-response', 'stimulus', 'audio'); plugin.info = { name: 'audio-keyboard-response', description: '', parameters: { stimulus: { type: jsPsych.plugins.parameterType.AUDIO, pretty_name: 'Stimulus', default: undefined, description: 'The audio to be played.' }, choices: { type: jsPsych.plugins.parameterType.KEYCODE, pretty_name: 'Choices', array: true, default: jsPsych.ALL_KEYS, description: 'The keys the subject is allowed to press to respond to the stimulus.' }, prompt: { type: jsPsych.plugins.parameterType.STRING, pretty_name: 'Prompt', default: null, description: 'Any content here will be displayed below the stimulus.' }, trial_duration: { type: jsPsych.plugins.parameterType.INT, pretty_name: 'Trial duration', default: null, description: 'The maximum duration to wait for a response.' }, response_ends_trial: { type: jsPsych.plugins.parameterType.BOOL, pretty_name: 'Response ends trial', default: true, description: 'If true, the trial will end when user makes a response.' }, trial_ends_after_audio: { type: jsPsych.plugins.parameterType.BOOL, pretty_name: 'Trial ends after audio', default: false, description: 'If true, then the trial will end as soon as the audio file finishes playing.' }, } } plugin.trial = function(display_element, trial) { // setup stimulus var context = jsPsych.pluginAPI.audioContext(); if(context !== null){ var source = context.createBufferSource(); source.buffer = jsPsych.pluginAPI.getAudioBuffer(trial.stimulus); source.connect(context.destination); } else { var audio = jsPsych.pluginAPI.getAudioBuffer(trial.stimulus); audio.currentTime = 0; } // set up end event if trial needs it if(trial.trial_ends_after_audio){ if(context !== null){ source.onended = function() { end_trial(); } } else { audio.addEventListener('ended', end_trial); } } // show prompt if there is one if (trial.prompt !== null) { display_element.innerHTML = trial.prompt; } // store response var response = { rt: null, key: null }; // function to end trial when it is time function end_trial() { // kill any remaining setTimeout handlers jsPsych.pluginAPI.clearAllTimeouts(); // stop the audio file if it is playing // remove end event listeners if they exist if(context !== null){ source.stop(); source.onended = function() { } } else { audio.pause(); audio.removeEventListener('ended', end_trial); } // kill keyboard listeners jsPsych.pluginAPI.cancelAllKeyboardResponses(); // gather the data to store for the trial if(context !== null && response.rt !== null){ response.rt = Math.round(response.rt * 1000); } var trial_data = { "rt": response.rt, "stimulus": trial.stimulus, "key_press": response.key }; // clear the display display_element.innerHTML = ''; // move on to the next trial jsPsych.finishTrial(trial_data); }; // function to handle responses by the subject var after_response = function(info) { // only record the first response if (response.key == null) { response = info; } if (trial.response_ends_trial) { end_trial(); } }; // start audio if(context !== null){ startTime = context.currentTime; source.start(startTime); } else { audio.play(); } // start the response listener if(context !== null) { var keyboardListener = jsPsych.pluginAPI.getKeyboardResponse({ callback_function: after_response, valid_responses: trial.choices, rt_method: 'audio', persist: false, allow_held_key: false, audio_context: context, audio_context_start_time: startTime }); } else { var keyboardListener = jsPsych.pluginAPI.getKeyboardResponse({ callback_function: after_response, valid_responses: trial.choices, rt_method: 'performance', persist: false, allow_held_key: false }); } // end trial if time limit is set if (trial.trial_duration !== null) { jsPsych.pluginAPI.setTimeout(function() { end_trial(); }, trial.trial_duration); } }; return plugin; })();
jspsych-audio-keyboard-response Josh de Leeuw plugin for playing an audio file and getting a keyboard response documentation: docs.jspsych.org *
(anonymous) ( )
javascript
awslabs/datawig
datawig-js/static/jspsych-6.1.0/plugins/jspsych-audio-keyboard-response.js
https://github.com/awslabs/datawig/blob/master/datawig-js/static/jspsych-6.1.0/plugins/jspsych-audio-keyboard-response.js
Apache-2.0
jsPsych.plugins['html-slider-response'] = (function() { var plugin = {}; plugin.info = { name: 'html-slider-response', description: '', parameters: { stimulus: { type: jsPsych.plugins.parameterType.HTML_STRING, pretty_name: 'Stimulus', default: undefined, description: 'The HTML string to be displayed' }, min: { type: jsPsych.plugins.parameterType.INT, pretty_name: 'Min slider', default: 0, description: 'Sets the minimum value of the slider.' }, max: { type: jsPsych.plugins.parameterType.INT, pretty_name: 'Max slider', default: 100, description: 'Sets the maximum value of the slider', }, start: { type: jsPsych.plugins.parameterType.INT, pretty_name: 'Slider starting value', default: 50, description: 'Sets the starting value of the slider', }, step: { type: jsPsych.plugins.parameterType.INT, pretty_name: 'Step', default: 1, description: 'Sets the step of the slider' }, labels: { type: jsPsych.plugins.parameterType.HTML_STRING, pretty_name:'Labels', default: [], array: true, description: 'Labels of the slider.', }, slider_width: { type: jsPsych.plugins.parameterType.INT, pretty_name:'Slider width', default: null, description: 'Width of the slider in pixels.' }, button_label: { type: jsPsych.plugins.parameterType.STRING, pretty_name: 'Button label', default: 'Continue', array: false, description: 'Label of the button to advance.' }, require_movement: { type: jsPsych.plugins.parameterType.BOOL, pretty_name: 'Require movement', default: false, description: 'If true, the participant will have to move the slider before continuing.' }, prompt: { type: jsPsych.plugins.parameterType.STRING, pretty_name: 'Prompt', default: null, description: 'Any content here will be displayed below the slider.' }, stimulus_duration: { type: jsPsych.plugins.parameterType.INT, pretty_name: 'Stimulus duration', default: null, description: 'How long to hide the stimulus.' }, trial_duration: { type: jsPsych.plugins.parameterType.INT, pretty_name: 'Trial duration', default: null, description: 'How long to show the trial.' }, response_ends_trial: { type: jsPsych.plugins.parameterType.BOOL, pretty_name: 'Response ends trial', default: true, description: 'If true, trial will end when user makes a response.' }, } } plugin.trial = function(display_element, trial) { var html = '<div id="jspsych-html-slider-response-wrapper" style="margin: 100px 0px;">'; html += '<div id="jspsych-html-slider-response-stimulus">' + trial.stimulus + '</div>'; html += '<div class="jspsych-html-slider-response-container" style="position:relative; margin: 0 auto 3em auto; '; if(trial.slider_width !== null){ html += 'width:'+trial.slider_width+'px;'; } html += '">'; html += '<input type="range" value="'+trial.start+'" min="'+trial.min+'" max="'+trial.max+'" step="'+trial.step+'" style="width: 100%;" id="jspsych-html-slider-response-response"></input>'; html += '<div>' for(var j=0; j < trial.labels.length; j++){ var width = 100/(trial.labels.length-1); var left_offset = (j * (100 /(trial.labels.length - 1))) - (width/2); html += '<div style="display: inline-block; position: absolute; left:'+left_offset+'%; text-align: center; width: '+width+'%;">'; html += '<span style="text-align: center; font-size: 80%;">'+trial.labels[j]+'</span>'; html += '</div>' } html += '</div>'; html += '</div>'; html += '</div>'; if (trial.prompt !== null){ html += trial.prompt; } // add submit button html += '<button id="jspsych-html-slider-response-next" class="jspsych-btn" '+ (trial.require_movement ? "disabled" : "") + '>'+trial.button_label+'</button>'; display_element.innerHTML = html; var response = { rt: null, response: null }; if(trial.require_movement){ display_element.querySelector('#jspsych-html-slider-response-response').addEventListener('change', function(){ display_element.querySelector('#jspsych-html-slider-response-next').disabled = false; }) } display_element.querySelector('#jspsych-html-slider-response-next').addEventListener('click', function() { // measure response time var endTime = performance.now(); response.rt = endTime - startTime; response.response = display_element.querySelector('#jspsych-html-slider-response-response').value; if(trial.response_ends_trial){ end_trial(); } else { display_element.querySelector('#jspsych-html-slider-response-next').disabled = true; } }); function end_trial(){ jsPsych.pluginAPI.clearAllTimeouts(); // save data var trialdata = { "rt": response.rt, "response": response.response, "stimulus": trial.stimulus }; display_element.innerHTML = ''; // next trial jsPsych.finishTrial(trialdata); } if (trial.stimulus_duration !== null) { jsPsych.pluginAPI.setTimeout(function() { display_element.querySelector('#jspsych-html-slider-response-stimulus').style.visibility = 'hidden'; }, trial.stimulus_duration); } // end trial if trial_duration is set if (trial.trial_duration !== null) { jsPsych.pluginAPI.setTimeout(function() { end_trial(); }, trial.trial_duration); } var startTime = performance.now(); }; return plugin; })();
jspsych-html-slider-response a jspsych plugin for free response survey questions Josh de Leeuw documentation: docs.jspsych.org
(anonymous) ( )
javascript
awslabs/datawig
datawig-js/static/jspsych-6.1.0/plugins/jspsych-html-slider-response.js
https://github.com/awslabs/datawig/blob/master/datawig-js/static/jspsych-6.1.0/plugins/jspsych-html-slider-response.js
Apache-2.0
jsPsych.plugins["video-slider-response"] = (function() { var plugin = {}; jsPsych.pluginAPI.registerPreload('video-slider-response', 'stimulus', 'video'); plugin.info = { name: 'video-slider-response', description: '', parameters: { sources: { type: jsPsych.plugins.parameterType.VIDEO, pretty_name: 'Video', default: undefined, description: 'The video file to play.' }, prompt: { type: jsPsych.plugins.parameterType.STRING, pretty_name: 'Prompt', default: null, description: 'Any content here will be displayed below the stimulus.' }, width: { type: jsPsych.plugins.parameterType.INT, pretty_name: 'Width', default: '', description: 'The width of the video in pixels.' }, height: { type: jsPsych.plugins.parameterType.INT, pretty_name: 'Height', default: '', description: 'The height of the video display in pixels.' }, autoplay: { type: jsPsych.plugins.parameterType.BOOL, pretty_name: 'Autoplay', default: true, description: 'If true, the video will begin playing as soon as it has loaded.' }, controls: { type: jsPsych.plugins.parameterType.BOOL, pretty_name: 'Controls', default: false, description: 'If true, the subject will be able to pause the video or move the playback to any point in the video.' }, start: { type: jsPsych.plugins.parameterType.FLOAT, pretty_name: 'Start', default: null, description: 'Time to start the clip.' }, stop: { type: jsPsych.plugins.parameterType.FLOAT, pretty_name: 'Stop', default: null, description: 'Time to stop the clip.' }, rate: { type: jsPsych.plugins.parameterType.FLOAT, pretty_name: 'Rate', default: 1, description: 'The playback rate of the video. 1 is normal, <1 is slower, >1 is faster.' }, min: { type: jsPsych.plugins.parameterType.INT, pretty_name: 'Min slider', default: 0, description: 'Sets the minimum value of the slider.' }, max: { type: jsPsych.plugins.parameterType.INT, pretty_name: 'Max slider', default: 100, description: 'Sets the maximum value of the slider', }, slider_start: { type: jsPsych.plugins.parameterType.INT, pretty_name: 'Slider starting value', default: 50, description: 'Sets the starting value of the slider', }, step: { type: jsPsych.plugins.parameterType.INT, pretty_name: 'Step', default: 1, description: 'Sets the step of the slider' }, labels: { type: jsPsych.plugins.parameterType.HTML_STRING, pretty_name:'Labels', default: [], array: true, description: 'Labels of the slider.', }, slider_width: { type: jsPsych.plugins.parameterType.INT, pretty_name:'Slider width', default: null, description: 'Width of the slider in pixels.' }, button_label: { type: jsPsych.plugins.parameterType.STRING, pretty_name: 'Button label', default: 'Continue', array: false, description: 'Label of the button to advance.' }, require_movement: { type: jsPsych.plugins.parameterType.BOOL, pretty_name: 'Require movement', default: false, description: 'If true, the participant will have to move the slider before continuing.' }, trial_ends_after_video: { type: jsPsych.plugins.parameterType.BOOL, pretty_name: 'End trial after video finishes', default: false, description: 'If true, the trial will end immediately after the video finishes playing.' }, trial_duration: { type: jsPsych.plugins.parameterType.INT, pretty_name: 'Trial duration', default: null, description: 'How long to show trial before it ends.' }, response_ends_trial: { type: jsPsych.plugins.parameterType.BOOL, pretty_name: 'Response ends trial', default: true, description: 'If true, the trial will end when subject makes a response.' } } } plugin.trial = function(display_element, trial) { // setup stimulus var video_html = '<video id="jspsych-video-slider-response-stimulus"'; if(trial.width) { video_html += ' width="'+trial.width+'"'; } if(trial.height) { video_html += ' height="'+trial.height+'"'; } if(trial.autoplay){ video_html += " autoplay "; } if(trial.controls){ video_html +=" controls "; } video_html +=">"; var video_preload_blob = jsPsych.pluginAPI.getVideoBuffer(trial.sources[0]); if(!video_preload_blob) { for(var i=0; i<trial.sources.length; i++){ var file_name = trial.sources[i]; if(file_name.indexOf('?') > -1){ file_name = file_name.substring(0, file_name.indexOf('?')); } var type = file_name.substr(file_name.lastIndexOf('.') + 1); type = type.toLowerCase(); video_html+='<source src="' + file_name + '" type="video/'+type+'">'; } } video_html += "</video>"; var html = '<div id="jspsych-video-slider-response-wrapper" style="margin: 100px 0px;">'; html += '<div id="jspsych-video-slider-response-stimulus">' + video_html + '</div>'; html += '<div class="jspsych-video-slider-response-container" style="position:relative; margin: 0 auto 3em auto; '; if(trial.slider_width !== null){ html += 'width:'+trial.slider_width+'px;'; } html += '">'; html += '<input type="range" value="'+trial.start+'" min="'+trial.min+'" max="'+trial.max+'" step="'+trial.step+'" style="width: 100%;" id="jspsych-video-slider-response-response"></input>'; html += '<div>' for(var j=0; j < trial.labels.length; j++){ var width = 100/(trial.labels.length-1); var left_offset = (j * (100 /(trial.labels.length - 1))) - (width/2); html += '<div style="display: inline-block; position: absolute; left:'+left_offset+'%; text-align: center; width: '+width+'%;">'; html += '<span style="text-align: center; font-size: 80%;">'+trial.labels[j]+'</span>'; html += '</div>' } html += '</div>'; html += '</div>'; html += '</div>'; // add prompt if there is one if (trial.prompt !== null) { html += '<div>'+trial.prompt+'</div>'; } // add submit button html += '<button id="jspsych-video-slider-response-next" class="jspsych-btn" '+ (trial.require_movement ? "disabled" : "") + '>'+trial.button_label+'</button>'; display_element.innerHTML = html; if(video_preload_blob){ display_element.querySelector('#jspsych-video-slider-response-stimulus').src = video_preload_blob; } display_element.querySelector('#jspsych-video-slider-response-stimulus').onended = function(){ if(trial.trial_ends_after_video){ end_trial(); } } if(trial.start !== null){ display_element.querySelector('#jspsych-video-slider-response-stimulus').currentTime = trial.start; } if(trial.stop !== null){ display_element.querySelector('#jspsych-video-slider-response-stimulus').addEventListener('timeupdate', function(e){ var currenttime = display_element.querySelector('#jspsych-video-slider-response-stimulus').currentTime; if(currenttime >= trial.stop){ display_element.querySelector('#jspsych-video-slider-response-stimulus').pause(); } }) } display_element.querySelector('#jspsych-video-slider-response-stimulus').playbackRate = trial.rate; if(trial.require_movement){ display_element.querySelector('#jspsych-video-slider-response-response').addEventListener('change', function(){ display_element.querySelector('#jspsych-video-slider-response-next').disabled = false; }) } var startTime = performance.now(); // store response var response = { rt: null, response: null }; display_element.querySelector('#jspsych-video-slider-response-next').addEventListener('click', function() { // measure response time var endTime = performance.now(); response.rt = endTime - startTime; response.response = display_element.querySelector('#jspsych-video-slider-response-response').value; if(trial.response_ends_trial){ end_trial(); } else { display_element.querySelector('#jspsych-video-slider-response-next').disabled = true; } }); // function to end trial when it is time function end_trial() { // kill any remaining setTimeout handlers jsPsych.pluginAPI.clearAllTimeouts(); // gather the data to store for the trial var trial_data = { "rt": response.rt, "stimulus": trial.stimulus, "response": response.response }; // clear the display display_element.innerHTML = ''; // move on to the next trial jsPsych.finishTrial(trial_data); }; // end trial if time limit is set if (trial.trial_duration !== null) { jsPsych.pluginAPI.setTimeout(function() { end_trial(); }, trial.trial_duration); } }; return plugin; })();
jspsych-video-slider-response Josh de Leeuw plugin for playing a video file and getting a slider response documentation: docs.jspsych.org *
(anonymous) ( )
javascript
awslabs/datawig
datawig-js/static/jspsych-6.1.0/plugins/jspsych-video-slider-response.js
https://github.com/awslabs/datawig/blob/master/datawig-js/static/jspsych-6.1.0/plugins/jspsych-video-slider-response.js
Apache-2.0
jsPsych.plugins["video-keyboard-response"] = (function() { var plugin = {}; jsPsych.pluginAPI.registerPreload('video-keyboard-response', 'stimulus', 'video'); plugin.info = { name: 'video-keyboard-response', description: '', parameters: { sources: { type: jsPsych.plugins.parameterType.VIDEO, pretty_name: 'Video', default: undefined, description: 'The video file to play.' }, choices: { type: jsPsych.plugins.parameterType.KEYCODE, pretty_name: 'Choices', array: true, default: jsPsych.ALL_KEYS, description: 'The keys the subject is allowed to press to respond to the stimulus.' }, prompt: { type: jsPsych.plugins.parameterType.STRING, pretty_name: 'Prompt', default: null, description: 'Any content here will be displayed below the stimulus.' }, width: { type: jsPsych.plugins.parameterType.INT, pretty_name: 'Width', default: '', description: 'The width of the video in pixels.' }, height: { type: jsPsych.plugins.parameterType.INT, pretty_name: 'Height', default: '', description: 'The height of the video display in pixels.' }, autoplay: { type: jsPsych.plugins.parameterType.BOOL, pretty_name: 'Autoplay', default: true, description: 'If true, the video will begin playing as soon as it has loaded.' }, controls: { type: jsPsych.plugins.parameterType.BOOL, pretty_name: 'Controls', default: false, description: 'If true, the subject will be able to pause the video or move the playback to any point in the video.' }, start: { type: jsPsych.plugins.parameterType.FLOAT, pretty_name: 'Start', default: null, description: 'Time to start the clip.' }, stop: { type: jsPsych.plugins.parameterType.FLOAT, pretty_name: 'Stop', default: null, description: 'Time to stop the clip.' }, rate: { type: jsPsych.plugins.parameterType.FLOAT, pretty_name: 'Rate', default: 1, description: 'The playback rate of the video. 1 is normal, <1 is slower, >1 is faster.' }, trial_ends_after_video: { type: jsPsych.plugins.parameterType.BOOL, pretty_name: 'End trial after video finishes', default: false, description: 'If true, the trial will end immediately after the video finishes playing.' }, trial_duration: { type: jsPsych.plugins.parameterType.INT, pretty_name: 'Trial duration', default: null, description: 'How long to show trial before it ends.' }, response_ends_trial: { type: jsPsych.plugins.parameterType.BOOL, pretty_name: 'Response ends trial', default: true, description: 'If true, the trial will end when subject makes a response.' } } } plugin.trial = function(display_element, trial) { // setup stimulus var video_html = '<div>' video_html += '<video id="jspsych-video-keyboard-response-stimulus"'; if(trial.width) { video_html += ' width="'+trial.width+'"'; } if(trial.height) { video_html += ' height="'+trial.height+'"'; } if(trial.autoplay){ video_html += " autoplay "; } if(trial.controls){ video_html +=" controls "; } video_html +=">"; var video_preload_blob = jsPsych.pluginAPI.getVideoBuffer(trial.sources[0]); if(!video_preload_blob) { for(var i=0; i<trial.sources.length; i++){ var file_name = trial.sources[i]; if(file_name.indexOf('?') > -1){ file_name = file_name.substring(0, file_name.indexOf('?')); } var type = file_name.substr(file_name.lastIndexOf('.') + 1); type = type.toLowerCase(); video_html+='<source src="' + file_name + '" type="video/'+type+'">'; } } video_html += "</video>"; video_html += "</div>"; // add prompt if there is one if (trial.prompt !== null) { video_html += trial.prompt; } display_element.innerHTML = video_html; if(video_preload_blob){ display_element.querySelector('#jspsych-video-keyboard-response-stimulus').src = video_preload_blob; } display_element.querySelector('#jspsych-video-keyboard-response-stimulus').onended = function(){ if(trial.trial_ends_after_video){ end_trial(); } } if(trial.start !== null){ display_element.querySelector('#jspsych-video-keyboard-response-stimulus').currentTime = trial.start; } if(trial.stop !== null){ display_element.querySelector('#jspsych-video-keyboard-response-stimulus').addEventListener('timeupdate', function(e){ var currenttime = display_element.querySelector('#jspsych-video-keyboard-response-stimulus').currentTime; if(currenttime >= trial.stop){ display_element.querySelector('#jspsych-video-keyboard-response-stimulus').pause(); } }) } display_element.querySelector('#jspsych-video-keyboard-response-stimulus').playbackRate = trial.rate; // store response var response = { rt: null, key: null }; // function to end trial when it is time function end_trial() { // kill any remaining setTimeout handlers jsPsych.pluginAPI.clearAllTimeouts(); // kill keyboard listeners jsPsych.pluginAPI.cancelAllKeyboardResponses(); // gather the data to store for the trial var trial_data = { "rt": response.rt, "stimulus": trial.stimulus, "key_press": response.key }; // clear the display display_element.innerHTML = ''; // move on to the next trial jsPsych.finishTrial(trial_data); }; // function to handle responses by the subject var after_response = function(info) { // after a valid response, the stimulus will have the CSS class 'responded' // which can be used to provide visual feedback that a response was recorded display_element.querySelector('#jspsych-video-keyboard-response-stimulus').className += ' responded'; // only record the first response if (response.key == null) { response = info; } if (trial.response_ends_trial) { end_trial(); } }; // start the response listener if (trial.choices != jsPsych.NO_KEYS) { var keyboardListener = jsPsych.pluginAPI.getKeyboardResponse({ callback_function: after_response, valid_responses: trial.choices, rt_method: 'performance', persist: false, allow_held_key: false, }); } // end trial if time limit is set if (trial.trial_duration !== null) { jsPsych.pluginAPI.setTimeout(function() { end_trial(); }, trial.trial_duration); } }; return plugin; })();
jspsych-video-keyboard-response Josh de Leeuw plugin for playing a video file and getting a keyboard response documentation: docs.jspsych.org *
(anonymous) ( )
javascript
awslabs/datawig
datawig-js/static/jspsych-6.1.0/plugins/jspsych-video-keyboard-response.js
https://github.com/awslabs/datawig/blob/master/datawig-js/static/jspsych-6.1.0/plugins/jspsych-video-keyboard-response.js
Apache-2.0
jsPsych.plugins['cloze'] = (function () { var plugin = {}; plugin.info = { name: 'cloze', description: '', parameters: { text: { type: jsPsych.plugins.parameterType.STRING, pretty_name: 'Cloze text', default: undefined, description: 'The cloze text to be displayed. Blanks are indicated by %% signs and automatically replaced by input fields. If there is a correct answer you want the system to check against, it must be typed between the two percentage signs (i.e. %solution%).' }, button_text: { type: jsPsych.plugins.parameterType.STRING, pretty_name: 'Button text', default: 'OK', description: 'Text of the button participants have to press for finishing the cloze test.' }, check_answers: { type: jsPsych.plugins.parameterType.BOOL, pretty_name: 'Check answers', default: false, description: 'Boolean value indicating if the answers given by participants should be compared against a correct solution given in the text (between % signs) after the button was clicked.' }, mistake_fn: { type: jsPsych.plugins.parameterType.FUNCTION, pretty_name: 'Mistake function', default: function () {}, description: 'Function called if check_answers is set to TRUE and there is a difference between the participants answers and the correct solution provided in the text.' } } }; plugin.trial = function (display_element, trial) { var html = '<div class="cloze">'; var elements = trial.text.split('%'); var solutions = []; for (i=0; i<elements.length; i++) { if (i%2 === 0) { html += elements[i]; } else { solutions.push(elements[i].trim()); html += '<input type="text" id="input'+(solutions.length-1)+'" value="">'; } } html += '</div>'; display_element.innerHTML = html; var check = function() { var answers = []; var answers_correct = true; for (i=0; i<solutions.length; i++) { var field = document.getElementById('input'+i); answers.push(field.value.trim()); if (trial.check_answers) { if (answers[i] !== solutions[i]) { field.style.color = 'red'; answers_correct = false; } else { field.style.color = 'black'; } } } if (!trial.check_answers || (trial.check_answers && answers_correct)) { var trial_data = { 'answers' : answers }; display_element.innerHTML = ''; jsPsych.finishTrial(trial_data); } else { trial.mistake_fn(); } }; display_element.innerHTML += '<br><button class="jspsych-html-button-response-button" type="button" id="finish_cloze_button">'+trial.button_text+'</button>'; display_element.querySelector('#finish_cloze_button').addEventListener('click', check); }; return plugin; })();
jspsych-cloze Philipp Sprengholz Plugin for displaying a cloze test and checking participants answers against a correct solution. documentation: docs.jspsych.org *
(anonymous) ( )
javascript
awslabs/datawig
datawig-js/static/jspsych-6.1.0/plugins/jspsych-cloze.js
https://github.com/awslabs/datawig/blob/master/datawig-js/static/jspsych-6.1.0/plugins/jspsych-cloze.js
Apache-2.0
jsPsych.plugins['reconstruction'] = (function() { var plugin = {}; plugin.info = { name: 'reconstruction', description: '', parameters: { stim_function: { type: jsPsych.plugins.parameterType.FUNCTION, pretty_name: 'Stimulus function', default: undefined, description: 'A function with a single parameter that returns an HTML-formatted string representing the stimulus.' }, starting_value: { type: jsPsych.plugins.parameterType.FLOAT, pretty_name: 'Starting value', default: 0.5, description: 'The starting value of the stimulus parameter.' }, step_size: { type: jsPsych.plugins.parameterType.FLOAT, pretty_name: 'Step size', default: 0.05, description: 'The change in the stimulus parameter caused by pressing one of the modification keys.' }, key_increase: { type: jsPsych.plugins.parameterType.KEYCODE, pretty_name: 'Key increase', default: 'h', description: 'The key to press for increasing the parameter value.' }, key_decrease: { type: jsPsych.plugins.parameterType.KEYCODE, pretty_name: 'Key decrease', default: 'g', description: 'The key to press for decreasing the parameter value.' }, button_label: { type: jsPsych.plugins.parameterType.STRING, pretty_name: 'Button label', default: 'Continue', description: 'The text that appears on the button to finish the trial.' } } } plugin.trial = function(display_element, trial) { // current param level var param = trial.starting_value; // set-up key listeners var after_response = function(info) { //console.log('fire'); var key_i = (typeof trial.key_increase == 'string') ? jsPsych.pluginAPI.convertKeyCharacterToKeyCode(trial.key_increase) : trial.key_increase; var key_d = (typeof trial.key_decrease == 'string') ? jsPsych.pluginAPI.convertKeyCharacterToKeyCode(trial.key_decrease) : trial.key_decrease; // get new param value if (info.key == key_i) { param = param + trial.step_size; } else if (info.key == key_d) { param = param - trial.step_size; } param = Math.max(Math.min(1, param), 0); // refresh the display draw(param); } // listen for responses var key_listener = jsPsych.pluginAPI.getKeyboardResponse({ callback_function: after_response, valid_responses: [trial.key_increase, trial.key_decrease], rt_method: 'performance', persist: true, allow_held_key: true }); // draw first iteration draw(param); function draw(param) { //console.log(param); display_element.innerHTML = '<div id="jspsych-reconstruction-stim-container">'+trial.stim_function(param)+'</div>'; // add submit button display_element.innerHTML += '<button id="jspsych-reconstruction-next" class="jspsych-btn jspsych-reconstruction">'+trial.button_label+'</button>'; display_element.querySelector('#jspsych-reconstruction-next').addEventListener('click', endTrial); } function endTrial() { // measure response time var endTime =performance.now(); var response_time = endTime - startTime; // clear keyboard response jsPsych.pluginAPI.cancelKeyboardResponse(key_listener); // save data var trial_data = { "rt": response_time, "final_value": param, "start_value": trial.starting_value }; display_element.innerHTML = ''; // next trial jsPsych.finishTrial(trial_data); } var startTime = performance.now(); }; return plugin; })();
jspsych-reconstruction a jspsych plugin for a reconstruction task where the subject recreates a stimulus from memory Josh de Leeuw documentation: docs.jspsych.org
(anonymous) ( )
javascript
awslabs/datawig
datawig-js/static/jspsych-6.1.0/plugins/jspsych-reconstruction.js
https://github.com/awslabs/datawig/blob/master/datawig-js/static/jspsych-6.1.0/plugins/jspsych-reconstruction.js
Apache-2.0
jsPsych.plugins["html-keyboard-response"] = (function() { var plugin = {}; plugin.info = { name: 'html-keyboard-response', description: '', parameters: { stimulus: { type: jsPsych.plugins.parameterType.HTML_STRING, pretty_name: 'Stimulus', default: undefined, description: 'The HTML string to be displayed' }, choices: { type: jsPsych.plugins.parameterType.KEYCODE, array: true, pretty_name: 'Choices', default: jsPsych.ALL_KEYS, description: 'The keys the subject is allowed to press to respond to the stimulus.' }, prompt: { type: jsPsych.plugins.parameterType.STRING, pretty_name: 'Prompt', default: null, description: 'Any content here will be displayed below the stimulus.' }, stimulus_duration: { type: jsPsych.plugins.parameterType.INT, pretty_name: 'Stimulus duration', default: null, description: 'How long to hide the stimulus.' }, trial_duration: { type: jsPsych.plugins.parameterType.INT, pretty_name: 'Trial duration', default: null, description: 'How long to show trial before it ends.' }, response_ends_trial: { type: jsPsych.plugins.parameterType.BOOL, pretty_name: 'Response ends trial', default: true, description: 'If true, trial will end when subject makes a response.' }, } } plugin.trial = function(display_element, trial) { var new_html = '<div id="jspsych-html-keyboard-response-stimulus">'+trial.stimulus+'</div>'; // add prompt if(trial.prompt !== null){ new_html += trial.prompt; } // draw display_element.innerHTML = new_html; // store response var response = { rt: null, key: null }; // function to end trial when it is time var end_trial = function() { // kill any remaining setTimeout handlers jsPsych.pluginAPI.clearAllTimeouts(); // kill keyboard listeners if (typeof keyboardListener !== 'undefined') { jsPsych.pluginAPI.cancelKeyboardResponse(keyboardListener); } // gather the data to store for the trial var trial_data = { "rt": response.rt, "stimulus": trial.stimulus, "key_press": response.key }; // clear the display display_element.innerHTML = ''; // move on to the next trial jsPsych.finishTrial(trial_data); }; // function to handle responses by the subject var after_response = function(info) { // after a valid response, the stimulus will have the CSS class 'responded' // which can be used to provide visual feedback that a response was recorded display_element.querySelector('#jspsych-html-keyboard-response-stimulus').className += ' responded'; // only record the first response if (response.key == null) { response = info; } if (trial.response_ends_trial) { end_trial(); } }; // start the response listener if (trial.choices != jsPsych.NO_KEYS) { var keyboardListener = jsPsych.pluginAPI.getKeyboardResponse({ callback_function: after_response, valid_responses: trial.choices, rt_method: 'performance', persist: false, allow_held_key: false }); } // hide stimulus if stimulus_duration is set if (trial.stimulus_duration !== null) { jsPsych.pluginAPI.setTimeout(function() { display_element.querySelector('#jspsych-html-keyboard-response-stimulus').style.visibility = 'hidden'; }, trial.stimulus_duration); } // end trial if trial_duration is set if (trial.trial_duration !== null) { jsPsych.pluginAPI.setTimeout(function() { end_trial(); }, trial.trial_duration); } }; return plugin; })();
jspsych-html-keyboard-response Josh de Leeuw plugin for displaying a stimulus and getting a keyboard response documentation: docs.jspsych.org *
(anonymous) ( )
javascript
awslabs/datawig
datawig-js/static/jspsych-6.1.0/plugins/jspsych-html-keyboard-response.js
https://github.com/awslabs/datawig/blob/master/datawig-js/static/jspsych-6.1.0/plugins/jspsych-html-keyboard-response.js
Apache-2.0
jsPsych.plugins['call-function'] = (function() { var plugin = {}; plugin.info = { name: 'call-function', description: '', parameters: { func: { type: jsPsych.plugins.parameterType.FUNCTION, pretty_name: 'Function', default: undefined, description: 'Function to call' }, async: { type: jsPsych.plugins.parameterType.BOOL, pretty_name: 'Asynchronous', default: false, description: 'Is the function call asynchronous?' } } } plugin.trial = function(display_element, trial) { trial.post_trial_gap = 0; var return_val; if(trial.async){ var done = function(data){ return_val = data; end_trial(); } trial.func(done); } else { return_val = trial.func(); end_trial(); } function end_trial(){ var trial_data = { value: return_val }; jsPsych.finishTrial(trial_data); } }; return plugin; })();
jspsych-call-function plugin for calling an arbitrary function during a jspsych experiment Josh de Leeuw documentation: docs.jspsych.org *
(anonymous) ( )
javascript
awslabs/datawig
datawig-js/static/jspsych-6.1.0/plugins/jspsych-call-function.js
https://github.com/awslabs/datawig/blob/master/datawig-js/static/jspsych-6.1.0/plugins/jspsych-call-function.js
Apache-2.0
jsPsych.plugins["image-button-response"] = (function() { var plugin = {}; jsPsych.pluginAPI.registerPreload('image-button-response', 'stimulus', 'image'); plugin.info = { name: 'image-button-response', description: '', parameters: { stimulus: { type: jsPsych.plugins.parameterType.IMAGE, pretty_name: 'Stimulus', default: undefined, description: 'The image to be displayed' }, stimulus_height: { type: jsPsych.plugins.parameterType.INT, pretty_name: 'Image height', default: null, description: 'Set the image height in pixels' }, stimulus_width: { type: jsPsych.plugins.parameterType.INT, pretty_name: 'Image width', default: null, description: 'Set the image width in pixels' }, maintain_aspect_ratio: { type: jsPsych.plugins.parameterType.BOOL, pretty_name: 'Maintain aspect ratio', default: true, description: 'Maintain the aspect ratio after setting width or height' }, choices: { type: jsPsych.plugins.parameterType.STRING, pretty_name: 'Choices', default: undefined, array: true, description: 'The labels for the buttons.' }, button_html: { type: jsPsych.plugins.parameterType.STRING, pretty_name: 'Button HTML', default: '<button class="jspsych-btn">%choice%</button>', array: true, description: 'The html of the button. Can create own style.' }, prompt: { type: jsPsych.plugins.parameterType.STRING, pretty_name: 'Prompt', default: null, description: 'Any content here will be displayed under the button.' }, stimulus_duration: { type: jsPsych.plugins.parameterType.INT, pretty_name: 'Stimulus duration', default: null, description: 'How long to hide the stimulus.' }, trial_duration: { type: jsPsych.plugins.parameterType.INT, pretty_name: 'Trial duration', default: null, description: 'How long to show the trial.' }, margin_vertical: { type: jsPsych.plugins.parameterType.STRING, pretty_name: 'Margin vertical', default: '0px', description: 'The vertical margin of the button.' }, margin_horizontal: { type: jsPsych.plugins.parameterType.STRING, pretty_name: 'Margin horizontal', default: '8px', description: 'The horizontal margin of the button.' }, response_ends_trial: { type: jsPsych.plugins.parameterType.BOOL, pretty_name: 'Response ends trial', default: true, description: 'If true, then trial will end when user responds.' }, } } plugin.trial = function(display_element, trial) { // display stimulus var html = '<img src="'+trial.stimulus+'" id="jspsych-image-button-response-stimulus" style="'; if(trial.stimulus_height !== null){ html += 'height:'+trial.stimulus_height+'px; ' if(trial.stimulus_width == null && trial.maintain_aspect_ratio){ html += 'width: auto; '; } } if(trial.stimulus_width !== null){ html += 'width:'+trial.stimulus_width+'px; ' if(trial.stimulus_height == null && trial.maintain_aspect_ratio){ html += 'height: auto; '; } } html +='"></img>'; //display buttons var buttons = []; if (Array.isArray(trial.button_html)) { if (trial.button_html.length == trial.choices.length) { buttons = trial.button_html; } else { console.error('Error in image-button-response plugin. The length of the button_html array does not equal the length of the choices array'); } } else { for (var i = 0; i < trial.choices.length; i++) { buttons.push(trial.button_html); } } html += '<div id="jspsych-image-button-response-btngroup">'; for (var i = 0; i < trial.choices.length; i++) { var str = buttons[i].replace(/%choice%/g, trial.choices[i]); html += '<div class="jspsych-image-button-response-button" style="display: inline-block; margin:'+trial.margin_vertical+' '+trial.margin_horizontal+'" id="jspsych-image-button-response-button-' + i +'" data-choice="'+i+'">'+str+'</div>'; } html += '</div>'; //show prompt if there is one if (trial.prompt !== null) { html += trial.prompt; } display_element.innerHTML = html; // start timing var start_time = performance.now(); for (var i = 0; i < trial.choices.length; i++) { display_element.querySelector('#jspsych-image-button-response-button-' + i).addEventListener('click', function(e){ var choice = e.currentTarget.getAttribute('data-choice'); // don't use dataset for jsdom compatibility after_response(choice); }); } // store response var response = { rt: null, button: null }; // function to handle responses by the subject function after_response(choice) { // measure rt var end_time = performance.now(); var rt = end_time - start_time; response.button = choice; response.rt = rt; // after a valid response, the stimulus will have the CSS class 'responded' // which can be used to provide visual feedback that a response was recorded display_element.querySelector('#jspsych-image-button-response-stimulus').className += ' responded'; // disable all the buttons after a response var btns = document.querySelectorAll('.jspsych-image-button-response-button button'); for(var i=0; i<btns.length; i++){ //btns[i].removeEventListener('click'); btns[i].setAttribute('disabled', 'disabled'); } if (trial.response_ends_trial) { end_trial(); } }; // function to end trial when it is time function end_trial() { // kill any remaining setTimeout handlers jsPsych.pluginAPI.clearAllTimeouts(); // gather the data to store for the trial var trial_data = { "rt": response.rt, "stimulus": trial.stimulus, "button_pressed": response.button }; // clear the display display_element.innerHTML = ''; // move on to the next trial jsPsych.finishTrial(trial_data); }; // hide image if timing is set if (trial.stimulus_duration !== null) { jsPsych.pluginAPI.setTimeout(function() { display_element.querySelector('#jspsych-image-button-response-stimulus').style.visibility = 'hidden'; }, trial.stimulus_duration); } // end trial if time limit is set if (trial.trial_duration !== null) { jsPsych.pluginAPI.setTimeout(function() { end_trial(); }, trial.trial_duration); } }; return plugin; })();
jspsych-image-button-response Josh de Leeuw plugin for displaying a stimulus and getting a keyboard response documentation: docs.jspsych.org *
(anonymous) ( )
javascript
awslabs/datawig
datawig-js/static/jspsych-6.1.0/plugins/jspsych-image-button-response.js
https://github.com/awslabs/datawig/blob/master/datawig-js/static/jspsych-6.1.0/plugins/jspsych-image-button-response.js
Apache-2.0
jsPsych.plugins["video-button-response"] = (function() { var plugin = {}; jsPsych.pluginAPI.registerPreload('video-button-response', 'stimulus', 'video'); plugin.info = { name: 'video-button-response', description: '', parameters: { sources: { type: jsPsych.plugins.parameterType.VIDEO, pretty_name: 'Video', default: undefined, description: 'The video file to play.' }, choices: { type: jsPsych.plugins.parameterType.STRING, pretty_name: 'Choices', default: undefined, array: true, description: 'The labels for the buttons.' }, button_html: { type: jsPsych.plugins.parameterType.STRING, pretty_name: 'Button HTML', default: '<button class="jspsych-btn">%choice%</button>', array: true, description: 'The html of the button. Can create own style.' }, prompt: { type: jsPsych.plugins.parameterType.STRING, pretty_name: 'Prompt', default: null, description: 'Any content here will be displayed below the buttons.' }, width: { type: jsPsych.plugins.parameterType.INT, pretty_name: 'Width', default: '', description: 'The width of the video in pixels.' }, height: { type: jsPsych.plugins.parameterType.INT, pretty_name: 'Height', default: '', description: 'The height of the video display in pixels.' }, autoplay: { type: jsPsych.plugins.parameterType.BOOL, pretty_name: 'Autoplay', default: true, description: 'If true, the video will begin playing as soon as it has loaded.' }, controls: { type: jsPsych.plugins.parameterType.BOOL, pretty_name: 'Controls', default: false, description: 'If true, the subject will be able to pause the video or move the playback to any point in the video.' }, start: { type: jsPsych.plugins.parameterType.FLOAT, pretty_name: 'Start', default: null, description: 'Time to start the clip.' }, stop: { type: jsPsych.plugins.parameterType.FLOAT, pretty_name: 'Stop', default: null, description: 'Time to stop the clip.' }, rate: { type: jsPsych.plugins.parameterType.FLOAT, pretty_name: 'Rate', default: 1, description: 'The playback rate of the video. 1 is normal, <1 is slower, >1 is faster.' }, trial_ends_after_video: { type: jsPsych.plugins.parameterType.BOOL, pretty_name: 'End trial after video finishes', default: false, description: 'If true, the trial will end immediately after the video finishes playing.' }, trial_duration: { type: jsPsych.plugins.parameterType.INT, pretty_name: 'Trial duration', default: null, description: 'How long to show trial before it ends.' }, margin_vertical: { type: jsPsych.plugins.parameterType.STRING, pretty_name: 'Margin vertical', default: '0px', description: 'The vertical margin of the button.' }, margin_horizontal: { type: jsPsych.plugins.parameterType.STRING, pretty_name: 'Margin horizontal', default: '8px', description: 'The horizontal margin of the button.' }, response_ends_trial: { type: jsPsych.plugins.parameterType.BOOL, pretty_name: 'Response ends trial', default: true, description: 'If true, the trial will end when subject makes a response.' } } } plugin.trial = function(display_element, trial) { // setup stimulus var video_html = '<div>' video_html += '<video id="jspsych-video-button-response-stimulus"'; if(trial.width) { video_html += ' width="'+trial.width+'"'; } if(trial.height) { video_html += ' height="'+trial.height+'"'; } if(trial.autoplay){ video_html += " autoplay "; } if(trial.controls){ video_html +=" controls "; } video_html +=">"; var video_preload_blob = jsPsych.pluginAPI.getVideoBuffer(trial.sources[0]); if(!video_preload_blob) { for(var i=0; i<trial.sources.length; i++){ var file_name = trial.sources[i]; if(file_name.indexOf('?') > -1){ file_name = file_name.substring(0, file_name.indexOf('?')); } var type = file_name.substr(file_name.lastIndexOf('.') + 1); type = type.toLowerCase(); video_html+='<source src="' + file_name + '" type="video/'+type+'">'; } } video_html += "</video>"; video_html += "</div>"; //display buttons var buttons = []; if (Array.isArray(trial.button_html)) { if (trial.button_html.length == trial.choices.length) { buttons = trial.button_html; } else { console.error('Error in video-button-response plugin. The length of the button_html array does not equal the length of the choices array'); } } else { for (var i = 0; i < trial.choices.length; i++) { buttons.push(trial.button_html); } } video_html += '<div id="jspsych-video-button-response-btngroup">'; for (var i = 0; i < trial.choices.length; i++) { var str = buttons[i].replace(/%choice%/g, trial.choices[i]); video_html += '<div class="jspsych-video-button-response-button" style="display: inline-block; margin:'+trial.margin_vertical+' '+trial.margin_horizontal+'" id="jspsych-video-button-response-button-' + i +'" data-choice="'+i+'">'+str+'</div>'; } video_html += '</div>'; // add prompt if there is one if (trial.prompt !== null) { video_html += trial.prompt; } display_element.innerHTML = video_html; var start_time = performance.now(); if(video_preload_blob){ display_element.querySelector('#jspsych-video-button-response-stimulus').src = video_preload_blob; } display_element.querySelector('#jspsych-video-button-response-stimulus').onended = function(){ if(trial.trial_ends_after_video){ end_trial(); } } if(trial.start !== null){ display_element.querySelector('#jspsych-video-button-response-stimulus').currentTime = trial.start; } if(trial.stop !== null){ display_element.querySelector('#jspsych-video-button-response-stimulus').addEventListener('timeupdate', function(e){ var currenttime = display_element.querySelector('#jspsych-video-button-response-stimulus').currentTime; if(currenttime >= trial.stop){ display_element.querySelector('#jspsych-video-button-response-stimulus').pause(); } }) } display_element.querySelector('#jspsych-video-button-response-stimulus').playbackRate = trial.rate; // add event listeners to buttons for (var i = 0; i < trial.choices.length; i++) { display_element.querySelector('#jspsych-video-button-response-button-' + i).addEventListener('click', function(e){ var choice = e.currentTarget.getAttribute('data-choice'); // don't use dataset for jsdom compatibility after_response(choice); }); } // store response var response = { rt: null, button: null }; // function to end trial when it is time function end_trial() { // kill any remaining setTimeout handlers jsPsych.pluginAPI.clearAllTimeouts(); // gather the data to store for the trial var trial_data = { "rt": response.rt, "stimulus": trial.stimulus, "button_pressed": response.button }; // clear the display display_element.innerHTML = ''; // move on to the next trial jsPsych.finishTrial(trial_data); }; // function to handle responses by the subject function after_response(choice) { // measure rt var end_time = performance.now(); var rt = end_time - start_time; response.button = choice; response.rt = rt; // after a valid response, the stimulus will have the CSS class 'responded' // which can be used to provide visual feedback that a response was recorded display_element.querySelector('#jspsych-video-button-response-stimulus').className += ' responded'; // disable all the buttons after a response var btns = document.querySelectorAll('.jspsych-video-button-response-button button'); for(var i=0; i<btns.length; i++){ //btns[i].removeEventListener('click'); btns[i].setAttribute('disabled', 'disabled'); } if (trial.response_ends_trial) { end_trial(); } }; // end trial if time limit is set if (trial.trial_duration !== null) { jsPsych.pluginAPI.setTimeout(function() { end_trial(); }, trial.trial_duration); } }; return plugin; })();
jspsych-video-button-response Josh de Leeuw plugin for playing a video file and getting a button response documentation: docs.jspsych.org *
(anonymous) ( )
javascript
awslabs/datawig
datawig-js/static/jspsych-6.1.0/plugins/jspsych-video-button-response.js
https://github.com/awslabs/datawig/blob/master/datawig-js/static/jspsych-6.1.0/plugins/jspsych-video-button-response.js
Apache-2.0
jsPsych.plugins["html-button-response"] = (function() { var plugin = {}; plugin.info = { name: 'html-button-response', description: '', parameters: { stimulus: { type: jsPsych.plugins.parameterType.HTML_STRING, pretty_name: 'Stimulus', default: undefined, description: 'The HTML string to be displayed' }, choices: { type: jsPsych.plugins.parameterType.STRING, pretty_name: 'Choices', default: undefined, array: true, description: 'The labels for the buttons.' }, button_html: { type: jsPsych.plugins.parameterType.STRING, pretty_name: 'Button HTML', default: '<button class="jspsych-btn">%choice%</button>', array: true, description: 'The html of the button. Can create own style.' }, prompt: { type: jsPsych.plugins.parameterType.STRING, pretty_name: 'Prompt', default: null, description: 'Any content here will be displayed under the button.' }, stimulus_duration: { type: jsPsych.plugins.parameterType.INT, pretty_name: 'Stimulus duration', default: null, description: 'How long to hide the stimulus.' }, trial_duration: { type: jsPsych.plugins.parameterType.INT, pretty_name: 'Trial duration', default: null, description: 'How long to show the trial.' }, margin_vertical: { type: jsPsych.plugins.parameterType.STRING, pretty_name: 'Margin vertical', default: '0px', description: 'The vertical margin of the button.' }, margin_horizontal: { type: jsPsych.plugins.parameterType.STRING, pretty_name: 'Margin horizontal', default: '8px', description: 'The horizontal margin of the button.' }, response_ends_trial: { type: jsPsych.plugins.parameterType.BOOL, pretty_name: 'Response ends trial', default: true, description: 'If true, then trial will end when user responds.' }, } } plugin.trial = function(display_element, trial) { // display stimulus var html = '<div id="jspsych-html-button-response-stimulus">'+trial.stimulus+'</div>'; //display buttons var buttons = []; if (Array.isArray(trial.button_html)) { if (trial.button_html.length == trial.choices.length) { buttons = trial.button_html; } else { console.error('Error in html-button-response plugin. The length of the button_html array does not equal the length of the choices array'); } } else { for (var i = 0; i < trial.choices.length; i++) { buttons.push(trial.button_html); } } html += '<div id="jspsych-html-button-response-btngroup">'; for (var i = 0; i < trial.choices.length; i++) { var str = buttons[i].replace(/%choice%/g, trial.choices[i]); html += '<div class="jspsych-html-button-response-button" style="display: inline-block; margin:'+trial.margin_vertical+' '+trial.margin_horizontal+'" id="jspsych-html-button-response-button-' + i +'" data-choice="'+i+'">'+str+'</div>'; } html += '</div>'; //show prompt if there is one if (trial.prompt !== null) { html += trial.prompt; } display_element.innerHTML = html; // start time var start_time = performance.now(); // add event listeners to buttons for (var i = 0; i < trial.choices.length; i++) { display_element.querySelector('#jspsych-html-button-response-button-' + i).addEventListener('click', function(e){ var choice = e.currentTarget.getAttribute('data-choice'); // don't use dataset for jsdom compatibility after_response(choice); }); } // store response var response = { rt: null, button: null }; // function to handle responses by the subject function after_response(choice) { // measure rt var end_time = performance.now(); var rt = end_time - start_time; response.button = choice; response.rt = rt; // after a valid response, the stimulus will have the CSS class 'responded' // which can be used to provide visual feedback that a response was recorded display_element.querySelector('#jspsych-html-button-response-stimulus').className += ' responded'; // disable all the buttons after a response var btns = document.querySelectorAll('.jspsych-html-button-response-button button'); for(var i=0; i<btns.length; i++){ //btns[i].removeEventListener('click'); btns[i].setAttribute('disabled', 'disabled'); } if (trial.response_ends_trial) { end_trial(); } }; // function to end trial when it is time function end_trial() { // kill any remaining setTimeout handlers jsPsych.pluginAPI.clearAllTimeouts(); // gather the data to store for the trial var trial_data = { "rt": response.rt, "stimulus": trial.stimulus, "button_pressed": response.button }; // clear the display display_element.innerHTML = ''; // move on to the next trial jsPsych.finishTrial(trial_data); }; // hide image if timing is set if (trial.stimulus_duration !== null) { jsPsych.pluginAPI.setTimeout(function() { display_element.querySelector('#jspsych-html-button-response-stimulus').style.visibility = 'hidden'; }, trial.stimulus_duration); } // end trial if time limit is set if (trial.trial_duration !== null) { jsPsych.pluginAPI.setTimeout(function() { end_trial(); }, trial.trial_duration); } }; return plugin; })();
jspsych-html-button-response Josh de Leeuw plugin for displaying a stimulus and getting a keyboard response documentation: docs.jspsych.org *
(anonymous) ( )
javascript
awslabs/datawig
datawig-js/static/jspsych-6.1.0/plugins/jspsych-html-button-response.js
https://github.com/awslabs/datawig/blob/master/datawig-js/static/jspsych-6.1.0/plugins/jspsych-html-button-response.js
Apache-2.0
jsPsych.plugins["image-keyboard-response"] = (function() { var plugin = {}; jsPsych.pluginAPI.registerPreload('image-keyboard-response', 'stimulus', 'image'); plugin.info = { name: 'image-keyboard-response', description: '', parameters: { stimulus: { type: jsPsych.plugins.parameterType.IMAGE, pretty_name: 'Stimulus', default: undefined, description: 'The image to be displayed' }, stimulus_height: { type: jsPsych.plugins.parameterType.INT, pretty_name: 'Image height', default: null, description: 'Set the image height in pixels' }, stimulus_width: { type: jsPsych.plugins.parameterType.INT, pretty_name: 'Image width', default: null, description: 'Set the image width in pixels' }, maintain_aspect_ratio: { type: jsPsych.plugins.parameterType.BOOL, pretty_name: 'Maintain aspect ratio', default: true, description: 'Maintain the aspect ratio after setting width or height' }, choices: { type: jsPsych.plugins.parameterType.KEYCODE, array: true, pretty_name: 'Choices', default: jsPsych.ALL_KEYS, description: 'The keys the subject is allowed to press to respond to the stimulus.' }, prompt: { type: jsPsych.plugins.parameterType.STRING, pretty_name: 'Prompt', default: null, description: 'Any content here will be displayed below the stimulus.' }, stimulus_duration: { type: jsPsych.plugins.parameterType.INT, pretty_name: 'Stimulus duration', default: null, description: 'How long to hide the stimulus.' }, trial_duration: { type: jsPsych.plugins.parameterType.INT, pretty_name: 'Trial duration', default: null, description: 'How long to show trial before it ends.' }, response_ends_trial: { type: jsPsych.plugins.parameterType.BOOL, pretty_name: 'Response ends trial', default: true, description: 'If true, trial will end when subject makes a response.' }, } } plugin.trial = function(display_element, trial) { // display stimulus var html = '<img src="'+trial.stimulus+'" id="jspsych-image-keyboard-response-stimulus" style="'; if(trial.stimulus_height !== null){ html += 'height:'+trial.stimulus_height+'px; ' if(trial.stimulus_width == null && trial.maintain_aspect_ratio){ html += 'width: auto; '; } } if(trial.stimulus_width !== null){ html += 'width:'+trial.stimulus_width+'px; ' if(trial.stimulus_height == null && trial.maintain_aspect_ratio){ html += 'height: auto; '; } } html +='"></img>'; // add prompt if (trial.prompt !== null){ html += trial.prompt; } // render display_element.innerHTML = html; // store response var response = { rt: null, key: null }; // function to end trial when it is time var end_trial = function() { // kill any remaining setTimeout handlers jsPsych.pluginAPI.clearAllTimeouts(); // kill keyboard listeners if (typeof keyboardListener !== 'undefined') { jsPsych.pluginAPI.cancelKeyboardResponse(keyboardListener); } // gather the data to store for the trial var trial_data = { "rt": response.rt, "stimulus": trial.stimulus, "key_press": response.key }; // clear the display display_element.innerHTML = ''; // move on to the next trial jsPsych.finishTrial(trial_data); }; // function to handle responses by the subject var after_response = function(info) { // after a valid response, the stimulus will have the CSS class 'responded' // which can be used to provide visual feedback that a response was recorded display_element.querySelector('#jspsych-image-keyboard-response-stimulus').className += ' responded'; // only record the first response if (response.key == null) { response = info; } if (trial.response_ends_trial) { end_trial(); } }; // start the response listener if (trial.choices != jsPsych.NO_KEYS) { var keyboardListener = jsPsych.pluginAPI.getKeyboardResponse({ callback_function: after_response, valid_responses: trial.choices, rt_method: 'performance', persist: false, allow_held_key: false }); } // hide stimulus if stimulus_duration is set if (trial.stimulus_duration !== null) { jsPsych.pluginAPI.setTimeout(function() { display_element.querySelector('#jspsych-image-keyboard-response-stimulus').style.visibility = 'hidden'; }, trial.stimulus_duration); } // end trial if trial_duration is set if (trial.trial_duration !== null) { jsPsych.pluginAPI.setTimeout(function() { end_trial(); }, trial.trial_duration); } }; return plugin; })();
jspsych-image-keyboard-response Josh de Leeuw plugin for displaying a stimulus and getting a keyboard response documentation: docs.jspsych.org *
(anonymous) ( )
javascript
awslabs/datawig
datawig-js/static/jspsych-6.1.0/plugins/jspsych-image-keyboard-response.js
https://github.com/awslabs/datawig/blob/master/datawig-js/static/jspsych-6.1.0/plugins/jspsych-image-keyboard-response.js
Apache-2.0
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e(require("jquery")):"function"==typeof define&&define.amd?define(["jquery"],e):(t=t||self).BootstrapTable=e(t.jQuery)}(this,(function(t){"use strict";t=t&&t.hasOwnProperty("default")?t.default:t;var e="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function i(t,e){return t(e={exports:{}},e.exports),e.exports}var n=function(t){return t&&t.Math==Math&&t},o=n("object"==typeof globalThis&&globalThis)||n("object"==typeof window&&window)||n("object"==typeof self&&self)||n("object"==typeof e&&e)||Function("return this")(),r=function(t){try{return!!t()}catch(t){return!0}},a=!r((function(){return 7!=Object.defineProperty({},"a",{get:function(){return 7}}).a})),s={}.propertyIsEnumerable,l=Object.getOwnPropertyDescriptor,c={f:l&&!s.call({1:2},1)?function(t){var e=l(this,t);return!!e&&e.enumerable}:s},h=function(t,e){return{enumerable:!(1&t),configurable:!(2&t),writable:!(4&t),value:e}},u={}.toString,d=function(t){return u.call(t).slice(8,-1)},f="".split,p=r((function(){return!Object("z").propertyIsEnumerable(0)}))?function(t){return"String"==d(t)?f.call(t,""):Object(t)}:Object,g=function(t){if(null==t)throw TypeError("Can't call method on "+t);return t},v=function(t){return p(g(t))},b=function(t){return"object"==typeof t?null!==t:"function"==typeof t},m=function(t,e){if(!b(t))return t;var i,n;if(e&&"function"==typeof(i=t.toString)&&!b(n=i.call(t)))return n;if("function"==typeof(i=t.valueOf)&&!b(n=i.call(t)))return n;if(!e&&"function"==typeof(i=t.toString)&&!b(n=i.call(t)))return n;throw TypeError("Can't convert object to primitive value")},y={}.hasOwnProperty,w=function(t,e){return y.call(t,e)},S=o.document,x=b(S)&&b(S.createElement),k=function(t){return x?S.createElement(t):{}},O=!a&&!r((function(){return 7!=Object.defineProperty(k("div"),"a",{get:function(){return 7}}).a})),C=Object.getOwnPropertyDescriptor,T={f:a?C:function(t,e){if(t=v(t),e=m(e,!0),O)try{return C(t,e)}catch(t){}if(w(t,e))return h(!c.f.call(t,e),t[e])}},P=function(t){if(!b(t))throw TypeError(String(t)+" is not an object");return t},$=Object.defineProperty,I={f:a?$:function(t,e,i){if(P(t),e=m(e,!0),P(i),O)try{return $(t,e,i)}catch(t){}if("get"in i||"set"in i)throw TypeError("Accessors not supported");return"value"in i&&(t[e]=i.value),t}},A=a?function(t,e,i){return I.f(t,e,h(1,i))}:function(t,e,i){return t[e]=i,t},E=function(t,e){try{A(o,t,e)}catch(i){o[t]=e}return e},R=o["__core-js_shared__"]||E("__core-js_shared__",{}),j=Function.toString;"function"!=typeof R.inspectSource&&(R.inspectSource=function(t){return j.call(t)});var N,F,_,B=R.inspectSource,V=o.WeakMap,L="function"==typeof V&&/native code/.test(B(V)),D=i((function(t){(t.exports=function(t,e){return R[t]||(R[t]=void 0!==e?e:{})})("versions",[]).push({version:"3.6.0",mode:"global",copyright:"© 2019 Denis Pushkarev (zloirock.ru)"})})),H=0,M=Math.random(),U=function(t){return"Symbol("+String(void 0===t?"":t)+")_"+(++H+M).toString(36)},z=D("keys"),q=function(t){return z[t]||(z[t]=U(t))},W={},G=o.WeakMap;if(L){var K=new G,J=K.get,Y=K.has,X=K.set;N=function(t,e){return X.call(K,t,e),e},F=function(t){return J.call(K,t)||{}},_=function(t){return Y.call(K,t)}}else{var Q=q("state");W[Q]=!0,N=function(t,e){return A(t,Q,e),e},F=function(t){return w(t,Q)?t[Q]:{}},_=function(t){return w(t,Q)}}var Z,tt={set:N,get:F,has:_,enforce:function(t){return _(t)?F(t):N(t,{})},getterFor:function(t){return function(e){var i;if(!b(e)||(i=F(e)).type!==t)throw TypeError("Incompatible receiver, "+t+" required");return i}}},et=i((function(t){var e=tt.get,i=tt.enforce,n=String(String).split("String");(t.exports=function(t,e,r,a){var s=!!a&&!!a.unsafe,l=!!a&&!!a.enumerable,c=!!a&&!!a.noTargetGet;"function"==typeof r&&("string"!=typeof e||w(r,"name")||A(r,"name",e),i(r).source=n.join("string"==typeof e?e:"")),t!==o?(s?!c&&t[e]&&(l=!0):delete t[e],l?t[e]=r:A(t,e,r)):l?t[e]=r:E(e,r)})(Function.prototype,"toString",(function(){return"function"==typeof this&&e(this).source||B(this)}))})),it=o,nt=function(t){return"function"==typeof t?t:void 0},ot=function(t,e){return arguments.length<2?nt(it[t])||nt(o[t]):it[t]&&it[t][e]||o[t]&&o[t][e]},rt=Math.ceil,at=Math.floor,st=function(t){return isNaN(t=+t)?0:(t>0?at:rt)(t)},lt=Math.min,ct=function(t){return t>0?lt(st(t),9007199254740991):0},ht=Math.max,ut=Math.min,dt=function(t,e){var i=st(t);return i<0?ht(i+e,0):ut(i,e)},ft=function(t){return function(e,i,n){var o,r=v(e),a=ct(r.length),s=dt(n,a);if(t&&i!=i){for(;a>s;)if((o=r[s++])!=o)return!0}else for(;a>s;s++)if((t||s in r)&&r[s]===i)return t||s||0;return!t&&-1}},pt={includes:ft(!0),indexOf:ft(!1)},gt=pt.indexOf,vt=function(t,e){var i,n=v(t),o=0,r=[];for(i in n)!w(W,i)&&w(n,i)&&r.push(i);for(;e.length>o;)w(n,i=e[o++])&&(~gt(r,i)||r.push(i));return r},bt=["constructor","hasOwnProperty","isPrototypeOf","propertyIsEnumerable","toLocaleString","toString","valueOf"],mt=bt.concat("length","prototype"),yt={f:Object.getOwnPropertyNames||function(t){return vt(t,mt)}},wt={f:Object.getOwnPropertySymbols},St=ot("Reflect","ownKeys")||function(t){var e=yt.f(P(t)),i=wt.f;return i?e.concat(i(t)):e},xt=function(t,e){for(var i=St(e),n=I.f,o=T.f,r=0;r<i.length;r++){var a=i[r];w(t,a)||n(t,a,o(e,a))}},kt=/#|\.prototype\./,Ot=function(t,e){var i=Tt[Ct(t)];return i==$t||i!=Pt&&("function"==typeof e?r(e):!!e)},Ct=Ot.normalize=function(t){return String(t).replace(kt,".").toLowerCase()},Tt=Ot.data={},Pt=Ot.NATIVE="N",$t=Ot.POLYFILL="P",It=Ot,At=T.f,Et=function(t,e){var i,n,r,a,s,l=t.target,c=t.global,h=t.stat;if(i=c?o:h?o[l]||E(l,{}):(o[l]||{}).prototype)for(n in e){if(a=e[n],r=t.noTargetGet?(s=At(i,n))&&s.value:i[n],!It(c?n:l+(h?".":"#")+n,t.forced)&&void 0!==r){if(typeof a==typeof r)continue;xt(a,r)}(t.sham||r&&r.sham)&&A(a,"sham",!0),et(i,n,a,t)}},Rt=!!Object.getOwnPropertySymbols&&!r((function(){return!String(Symbol())})),jt=Rt&&!Symbol.sham&&"symbol"==typeof Symbol(),Nt=Array.isArray||function(t){return"Array"==d(t)},Ft=function(t){return Object(g(t))},_t=Object.keys||function(t){return vt(t,bt)},Bt=a?Object.defineProperties:function(t,e){P(t);for(var i,n=_t(e),o=n.length,r=0;o>r;)I.f(t,i=n[r++],e[i]);return t},Vt=ot("document","documentElement"),Lt=q("IE_PROTO"),Dt=function(){},Ht=function(t){return"<script>"+t+"<\/script>"},Mt=function(){try{Z=document.domain&&new ActiveXObject("htmlfile")}catch(t){}var t,e;Mt=Z?function(t){t.write(Ht("")),t.close();var e=t.parentWindow.Object;return t=null,e}(Z):((e=k("iframe")).style.display="none",Vt.appendChild(e),e.src=String("javascript:"),(t=e.contentWindow.document).open(),t.write(Ht("document.F=Object")),t.close(),t.F);for(var i=bt.length;i--;)delete Mt.prototype[bt[i]];return Mt()};W[Lt]=!0;var Ut=Object.create||function(t,e){var i;return null!==t?(Dt.prototype=P(t),i=new Dt,Dt.prototype=null,i[Lt]=t):i=Mt(),void 0===e?i:Bt(i,e)},zt=yt.f,qt={}.toString,Wt="object"==typeof window&&window&&Object.getOwnPropertyNames?Object.getOwnPropertyNames(window):[],Gt={f:function(t){return Wt&&"[object Window]"==qt.call(t)?function(t){try{return zt(t)}catch(t){return Wt.slice()}}(t):zt(v(t))}},Kt=D("wks"),Jt=o.Symbol,Yt=jt?Jt:U,Xt=function(t){return w(Kt,t)||(Rt&&w(Jt,t)?Kt[t]=Jt[t]:Kt[t]=Yt("Symbol."+t)),Kt[t]},Qt={f:Xt},Zt=I.f,te=function(t){var e=it.Symbol||(it.Symbol={});w(e,t)||Zt(e,t,{value:Qt.f(t)})},ee=I.f,ie=Xt("toStringTag"),ne=function(t,e,i){t&&!w(t=i?t:t.prototype,ie)&&ee(t,ie,{configurable:!0,value:e})},oe=function(t){if("function"!=typeof t)throw TypeError(String(t)+" is not a function");return t},re=Xt("species"),ae=function(t,e){var i;return Nt(t)&&("function"!=typeof(i=t.constructor)||i!==Array&&!Nt(i.prototype)?b(i)&&null===(i=i[re])&&(i=void 0):i=void 0),new(void 0===i?Array:i)(0===e?0:e)},se=[].push,le=function(t){var e=1==t,i=2==t,n=3==t,o=4==t,r=6==t,a=5==t||r;return function(s,l,c,h){for(var u,d,f=Ft(s),g=p(f),v=function(t,e,i){if(oe(t),void 0===e)return t;switch(i){case 0:return function(){return t.call(e)};case 1:return function(i){return t.call(e,i)};case 2:return function(i,n){return t.call(e,i,n)};case 3:return function(i,n,o){return t.call(e,i,n,o)}}return function(){return t.apply(e,arguments)}}(l,c,3),b=ct(g.length),m=0,y=h||ae,w=e?y(s,b):i?y(s,0):void 0;b>m;m++)if((a||m in g)&&(d=v(u=g[m],m,f),t))if(e)w[m]=d;else if(d)switch(t){case 3:return!0;case 5:return u;case 6:return m;case 2:se.call(w,u)}else if(o)return!1;return r?-1:n||o?o:w}},ce={forEach:le(0),map:le(1),filter:le(2),some:le(3),every:le(4),find:le(5),findIndex:le(6)},he=ce.forEach,ue=q("hidden"),de=Xt("toPrimitive"),fe=tt.set,pe=tt.getterFor("Symbol"),ge=Object.prototype,ve=o.Symbol,be=ot("JSON","stringify"),me=T.f,ye=I.f,we=Gt.f,Se=c.f,xe=D("symbols"),ke=D("op-symbols"),Oe=D("string-to-symbol-registry"),Ce=D("symbol-to-string-registry"),Te=D("wks"),Pe=o.QObject,$e=!Pe||!Pe.prototype||!Pe.prototype.findChild,Ie=a&&r((function(){return 7!=Ut(ye({},"a",{get:function(){return ye(this,"a",{value:7}).a}})).a}))?function(t,e,i){var n=me(ge,e);n&&delete ge[e],ye(t,e,i),n&&t!==ge&&ye(ge,e,n)}:ye,Ae=function(t,e){var i=xe[t]=Ut(ve.prototype);return fe(i,{type:"Symbol",tag:t,description:e}),a||(i.description=e),i},Ee=Rt&&"symbol"==typeof ve.iterator?function(t){return"symbol"==typeof t}:function(t){return Object(t)instanceof ve},Re=function(t,e,i){t===ge&&Re(ke,e,i),P(t);var n=m(e,!0);return P(i),w(xe,n)?(i.enumerable?(w(t,ue)&&t[ue][n]&&(t[ue][n]=!1),i=Ut(i,{enumerable:h(0,!1)})):(w(t,ue)||ye(t,ue,h(1,{})),t[ue][n]=!0),Ie(t,n,i)):ye(t,n,i)},je=function(t,e){P(t);var i=v(e),n=_t(i).concat(Be(i));return he(n,(function(e){a&&!Ne.call(i,e)||Re(t,e,i[e])})),t},Ne=function(t){var e=m(t,!0),i=Se.call(this,e);return!(this===ge&&w(xe,e)&&!w(ke,e))&&(!(i||!w(this,e)||!w(xe,e)||w(this,ue)&&this[ue][e])||i)},Fe=function(t,e){var i=v(t),n=m(e,!0);if(i!==ge||!w(xe,n)||w(ke,n)){var o=me(i,n);return!o||!w(xe,n)||w(i,ue)&&i[ue][n]||(o.enumerable=!0),o}},_e=function(t){var e=we(v(t)),i=[];return he(e,(function(t){w(xe,t)||w(W,t)||i.push(t)})),i},Be=function(t){var e=t===ge,i=we(e?ke:v(t)),n=[];return he(i,(function(t){!w(xe,t)||e&&!w(ge,t)||n.push(xe[t])})),n};if(Rt||(et((ve=function(){if(this instanceof ve)throw TypeError("Symbol is not a constructor");var t=arguments.length&&void 0!==arguments[0]?String(arguments[0]):void 0,e=U(t),i=function(t){this===ge&&i.call(ke,t),w(this,ue)&&w(this[ue],e)&&(this[ue][e]=!1),Ie(this,e,h(1,t))};return a&&$e&&Ie(ge,e,{configurable:!0,set:i}),Ae(e,t)}).prototype,"toString",(function(){return pe(this).tag})),c.f=Ne,I.f=Re,T.f=Fe,yt.f=Gt.f=_e,wt.f=Be,a&&(ye(ve.prototype,"description",{configurable:!0,get:function(){return pe(this).description}}),et(ge,"propertyIsEnumerable",Ne,{unsafe:!0}))),jt||(Qt.f=function(t){return Ae(Xt(t),t)}),Et({global:!0,wrap:!0,forced:!Rt,sham:!Rt},{Symbol:ve}),he(_t(Te),(function(t){te(t)})),Et({target:"Symbol",stat:!0,forced:!Rt},{for:function(t){var e=String(t);if(w(Oe,e))return Oe[e];var i=ve(e);return Oe[e]=i,Ce[i]=e,i},keyFor:function(t){if(!Ee(t))throw TypeError(t+" is not a symbol");if(w(Ce,t))return Ce[t]},useSetter:function(){$e=!0},useSimple:function(){$e=!1}}),Et({target:"Object",stat:!0,forced:!Rt,sham:!a},{create:function(t,e){return void 0===e?Ut(t):je(Ut(t),e)},defineProperty:Re,defineProperties:je,getOwnPropertyDescriptor:Fe}),Et({target:"Object",stat:!0,forced:!Rt},{getOwnPropertyNames:_e,getOwnPropertySymbols:Be}),Et({target:"Object",stat:!0,forced:r((function(){wt.f(1)}))},{getOwnPropertySymbols:function(t){return wt.f(Ft(t))}}),be){var Ve=!Rt||r((function(){var t=ve();return"[null]"!=be([t])||"{}"!=be({a:t})||"{}"!=be(Object(t))}));Et({target:"JSON",stat:!0,forced:Ve},{stringify:function(t,e,i){for(var n,o=[t],r=1;arguments.length>r;)o.push(arguments[r++]);if(n=e,(b(e)||void 0!==t)&&!Ee(t))return Nt(e)||(e=function(t,e){if("function"==typeof n&&(e=n.call(this,t,e)),!Ee(e))return e}),o[1]=e,be.apply(null,o)}})}ve.prototype[de]||A(ve.prototype,de,ve.prototype.valueOf),ne(ve,"Symbol"),W[ue]=!0;var Le=I.f,De=o.Symbol;if(a&&"function"==typeof De&&(!("description"in De.prototype)||void 0!==De().description)){var He={},Me=function(){var t=arguments.length<1||void 0===arguments[0]?void 0:String(arguments[0]),e=this instanceof Me?new De(t):void 0===t?De():De(t);return""===t&&(He[e]=!0),e};xt(Me,De);var Ue=Me.prototype=De.prototype;Ue.constructor=Me;var ze=Ue.toString,qe="Symbol(test)"==String(De("test")),We=/^Symbol\((.*)\)[^)]+$/;Le(Ue,"description",{configurable:!0,get:function(){var t=b(this)?this.valueOf():this,e=ze.call(t);if(w(He,t))return"";var i=qe?e.slice(7,-1):e.replace(We,"$1");return""===i?void 0:i}}),Et({global:!0,forced:!0},{Symbol:Me})}te("iterator");var Ge,Ke,Je=function(t,e,i){var n=m(e);n in t?I.f(t,n,h(0,i)):t[n]=i},Ye=ot("navigator","userAgent")||"",Xe=o.process,Qe=Xe&&Xe.versions,Ze=Qe&&Qe.v8;Ze?Ke=(Ge=Ze.split("."))[0]+Ge[1]:Ye&&(!(Ge=Ye.match(/Edge\/(\d+)/))||Ge[1]>=74)&&(Ge=Ye.match(/Chrome\/(\d+)/))&&(Ke=Ge[1]);var ti=Ke&&+Ke,ei=Xt("species"),ii=function(t){return ti>=51||!r((function(){var e=[];return(e.constructor={})[ei]=function(){return{foo:1}},1!==e[t](Boolean).foo}))},ni=Xt("isConcatSpreadable"),oi=ti>=51||!r((function(){var t=[];return t[ni]=!1,t.concat()[0]!==t})),ri=ii("concat"),ai=function(t){if(!b(t))return!1;var e=t[ni];return void 0!==e?!!e:Nt(t)};Et({target:"Array",proto:!0,forced:!oi||!ri},{concat:function(t){var e,i,n,o,r,a=Ft(this),s=ae(a,0),l=0;for(e=-1,n=arguments.length;e<n;e++)if(r=-1===e?a:arguments[e],ai(r)){if(l+(o=ct(r.length))>9007199254740991)throw TypeError("Maximum allowed index exceeded");for(i=0;i<o;i++,l++)i in r&&Je(s,l,r[i])}else{if(l>=9007199254740991)throw TypeError("Maximum allowed index exceeded");Je(s,l++,r)}return s.length=l,s}});var si=ce.filter,li=ii("filter"),ci=li&&!r((function(){[].filter.call({length:-1,0:1},(function(t){throw t}))}));Et({target:"Array",proto:!0,forced:!li||!ci},{filter:function(t){return si(this,t,arguments.length>1?arguments[1]:void 0)}});var hi=Xt("unscopables"),ui=Array.prototype;null==ui[hi]&&I.f(ui,hi,{configurable:!0,value:Ut(null)});var di=function(t){ui[hi][t]=!0},fi=ce.find,pi=!0;"find"in[]&&Array(1).find((function(){pi=!1})),Et({target:"Array",proto:!0,forced:pi},{find:function(t){return fi(this,t,arguments.length>1?arguments[1]:void 0)}}),di("find");var gi=ce.findIndex,vi=!0;"findIndex"in[]&&Array(1).findIndex((function(){vi=!1})),Et({target:"Array",proto:!0,forced:vi},{findIndex:function(t){return gi(this,t,arguments.length>1?arguments[1]:void 0)}}),di("findIndex");var bi=pt.includes;Et({target:"Array",proto:!0},{includes:function(t){return bi(this,t,arguments.length>1?arguments[1]:void 0)}}),di("includes");var mi=function(t,e){var i=[][t];return!i||!r((function(){i.call(null,e||function(){throw 1},1)}))},yi=pt.indexOf,wi=[].indexOf,Si=!!wi&&1/[1].indexOf(1,-0)<0,xi=mi("indexOf");Et({target:"Array",proto:!0,forced:Si||xi},{indexOf:function(t){return Si?wi.apply(this,arguments)||0:yi(this,t,arguments.length>1?arguments[1]:void 0)}});var ki,Oi,Ci,Ti=!r((function(){function t(){}return t.prototype.constructor=null,Object.getPrototypeOf(new t)!==t.prototype})),Pi=q("IE_PROTO"),$i=Object.prototype,Ii=Ti?Object.getPrototypeOf:function(t){return t=Ft(t),w(t,Pi)?t[Pi]:"function"==typeof t.constructor&&t instanceof t.constructor?t.constructor.prototype:t instanceof Object?$i:null},Ai=Xt("iterator"),Ei=!1;[].keys&&("next"in(Ci=[].keys())?(Oi=Ii(Ii(Ci)))!==Object.prototype&&(ki=Oi):Ei=!0),null==ki&&(ki={}),w(ki,Ai)||A(ki,Ai,(function(){return this}));var Ri={IteratorPrototype:ki,BUGGY_SAFARI_ITERATORS:Ei},ji=Ri.IteratorPrototype,Ni=Object.setPrototypeOf||("__proto__"in{}?function(){var t,e=!1,i={};try{(t=Object.getOwnPropertyDescriptor(Object.prototype,"__proto__").set).call(i,[]),e=i instanceof Array}catch(t){}return function(i,n){return P(i),function(t){if(!b(t)&&null!==t)throw TypeError("Can't set "+String(t)+" as a prototype")}(n),e?t.call(i,n):i.__proto__=n,i}}():void 0),Fi=Ri.IteratorPrototype,_i=Ri.BUGGY_SAFARI_ITERATORS,Bi=Xt("iterator"),Vi=function(){return this},Li=function(t,e,i,n,o,r,a){!function(t,e,i){var n=e+" Iterator";t.prototype=Ut(ji,{next:h(1,i)}),ne(t,n,!1)}(i,e,n);var s,l,c,u=function(t){if(t===o&&v)return v;if(!_i&&t in p)return p[t];switch(t){case"keys":case"values":case"entries":return function(){return new i(this,t)}}return function(){return new i(this)}},d=e+" Iterator",f=!1,p=t.prototype,g=p[Bi]||p["@@iterator"]||o&&p[o],v=!_i&&g||u(o),b="Array"==e&&p.entries||g;if(b&&(s=Ii(b.call(new t)),Fi!==Object.prototype&&s.next&&(Ii(s)!==Fi&&(Ni?Ni(s,Fi):"function"!=typeof s[Bi]&&A(s,Bi,Vi)),ne(s,d,!0))),"values"==o&&g&&"values"!==g.name&&(f=!0,v=function(){return g.call(this)}),p[Bi]!==v&&A(p,Bi,v),o)if(l={values:u("values"),keys:r?v:u("keys"),entries:u("entries")},a)for(c in l)!_i&&!f&&c in p||et(p,c,l[c]);else Et({target:e,proto:!0,forced:_i||f},l);return l},Di=tt.set,Hi=tt.getterFor("Array Iterator"),Mi=Li(Array,"Array",(function(t,e){Di(this,{type:"Array Iterator",target:v(t),index:0,kind:e})}),(function(){var t=Hi(this),e=t.target,i=t.kind,n=t.index++;return!e||n>=e.length?(t.target=void 0,{value:void 0,done:!0}):"keys"==i?{value:n,done:!1}:"values"==i?{value:e[n],done:!1}:{value:[n,e[n]],done:!1}}),"values");di("keys"),di("values"),di("entries");var Ui=[].join,zi=p!=Object,qi=mi("join",",");Et({target:"Array",proto:!0,forced:zi||qi},{join:function(t){return Ui.call(v(this),void 0===t?",":t)}});var Wi=ce.map,Gi=ii("map"),Ki=Gi&&!r((function(){[].map.call({length:-1,0:1},(function(t){throw t}))}));Et({target:"Array",proto:!0,forced:!Gi||!Ki},{map:function(t){return Wi(this,t,arguments.length>1?arguments[1]:void 0)}});var Ji=[].reverse,Yi=[1,2];Et({target:"Array",proto:!0,forced:String(Yi)===String(Yi.reverse())},{reverse:function(){return Nt(this)&&(this.length=this.length),Ji.call(this)}});var Xi=Xt("species"),Qi=[].slice,Zi=Math.max;Et({target:"Array",proto:!0,forced:!ii("slice")},{slice:function(t,e){var i,n,o,r=v(this),a=ct(r.length),s=dt(t,a),l=dt(void 0===e?a:e,a);if(Nt(r)&&("function"!=typeof(i=r.constructor)||i!==Array&&!Nt(i.prototype)?b(i)&&null===(i=i[Xi])&&(i=void 0):i=void 0,i===Array||void 0===i))return Qi.call(r,s,l);for(n=new(void 0===i?Array:i)(Zi(l-s,0)),o=0;s<l;s++,o++)s in r&&Je(n,o,r[s]);return n.length=o,n}});var tn=[],en=tn.sort,nn=r((function(){tn.sort(void 0)})),on=r((function(){tn.sort(null)})),rn=mi("sort");Et({target:"Array",proto:!0,forced:nn||!on||rn},{sort:function(t){return void 0===t?en.call(Ft(this)):en.call(Ft(this),oe(t))}});var an=Math.max,sn=Math.min;Et({target:"Array",proto:!0,forced:!ii("splice")},{splice:function(t,e){var i,n,o,r,a,s,l=Ft(this),c=ct(l.length),h=dt(t,c),u=arguments.length;if(0===u?i=n=0:1===u?(i=0,n=c-h):(i=u-2,n=sn(an(st(e),0),c-h)),c+i-n>9007199254740991)throw TypeError("Maximum allowed length exceeded");for(o=ae(l,n),r=0;r<n;r++)(a=h+r)in l&&Je(o,r,l[a]);if(o.length=n,i<n){for(r=h;r<c-n;r++)s=r+i,(a=r+n)in l?l[s]=l[a]:delete l[s];for(r=c;r>c-n+i;r--)delete l[r-1]}else if(i>n)for(r=c-n;r>h;r--)s=r+i-1,(a=r+n-1)in l?l[s]=l[a]:delete l[s];for(r=0;r<i;r++)l[r+h]=arguments[r+2];return l.length=c-n+i,o}});var ln=function(t,e,i){var n,o;return Ni&&"function"==typeof(n=e.constructor)&&n!==i&&b(o=n.prototype)&&o!==i.prototype&&Ni(t,o),t},cn="\t\n\v\f\r                 \u2028\u2029\ufeff",hn="["+cn+"]",un=RegExp("^"+hn+hn+"*"),dn=RegExp(hn+hn+"*$"),fn=function(t){return function(e){var i=String(g(e));return 1&t&&(i=i.replace(un,"")),2&t&&(i=i.replace(dn,"")),i}},pn={start:fn(1),end:fn(2),trim:fn(3)},gn=yt.f,vn=T.f,bn=I.f,mn=pn.trim,yn=o.Number,wn=yn.prototype,Sn="Number"==d(Ut(wn)),xn=function(t){var e,i,n,o,r,a,s,l,c=m(t,!1);if("string"==typeof c&&c.length>2)if(43===(e=(c=mn(c)).charCodeAt(0))||45===e){if(88===(i=c.charCodeAt(2))||120===i)return NaN}else if(48===e){switch(c.charCodeAt(1)){case 66:case 98:n=2,o=49;break;case 79:case 111:n=8,o=55;break;default:return+c}for(a=(r=c.slice(2)).length,s=0;s<a;s++)if((l=r.charCodeAt(s))<48||l>o)return NaN;return parseInt(r,n)}return+c};if(It("Number",!yn(" 0o1")||!yn("0b1")||yn("+0x1"))){for(var kn,On=function(t){var e=arguments.length<1?0:t,i=this;return i instanceof On&&(Sn?r((function(){wn.valueOf.call(i)})):"Number"!=d(i))?ln(new yn(xn(e)),i,On):xn(e)},Cn=a?gn(yn):"MAX_VALUE,MIN_VALUE,NaN,NEGATIVE_INFINITY,POSITIVE_INFINITY,EPSILON,isFinite,isInteger,isNaN,isSafeInteger,MAX_SAFE_INTEGER,MIN_SAFE_INTEGER,parseFloat,parseInt,isInteger".split(","),Tn=0;Cn.length>Tn;Tn++)w(yn,kn=Cn[Tn])&&!w(On,kn)&&bn(On,kn,vn(yn,kn));On.prototype=wn,wn.constructor=On,et(o,"Number",On)}var Pn=Object.assign,$n=Object.defineProperty,In=!Pn||r((function(){if(a&&1!==Pn({b:1},Pn($n({},"a",{enumerable:!0,get:function(){$n(this,"b",{value:3,enumerable:!1})}}),{b:2})).b)return!0;var t={},e={},i=Symbol();return t[i]=7,"abcdefghijklmnopqrst".split("").forEach((function(t){e[t]=t})),7!=Pn({},t)[i]||"abcdefghijklmnopqrst"!=_t(Pn({},e)).join("")}))?function(t,e){for(var i=Ft(t),n=arguments.length,o=1,r=wt.f,s=c.f;n>o;)for(var l,h=p(arguments[o++]),u=r?_t(h).concat(r(h)):_t(h),d=u.length,f=0;d>f;)l=u[f++],a&&!s.call(h,l)||(i[l]=h[l]);return i}:Pn;Et({target:"Object",stat:!0,forced:Object.assign!==In},{assign:In});var An=c.f,En=function(t){return function(e){for(var i,n=v(e),o=_t(n),r=o.length,s=0,l=[];r>s;)i=o[s++],a&&!An.call(n,i)||l.push(t?[i,n[i]]:n[i]);return l}},Rn={entries:En(!0),values:En(!1)}.entries;Et({target:"Object",stat:!0},{entries:function(t){return Rn(t)}});var jn={};jn[Xt("toStringTag")]="z";var Nn="[object z]"===String(jn),Fn=Xt("toStringTag"),_n="Arguments"==d(function(){return arguments}()),Bn=Nn?d:function(t){var e,i,n;return void 0===t?"Undefined":null===t?"Null":"string"==typeof(i=function(t,e){try{return t[e]}catch(t){}}(e=Object(t),Fn))?i:_n?d(e):"Object"==(n=d(e))&&"function"==typeof e.callee?"Arguments":n},Vn=Nn?{}.toString:function(){return"[object "+Bn(this)+"]"};Nn||et(Object.prototype,"toString",Vn,{unsafe:!0});var Ln=pn.trim,Dn=o.parseFloat,Hn=1/Dn(cn+"-0")!=-1/0?function(t){var e=Ln(String(t)),i=Dn(e);return 0===i&&"-"==e.charAt(0)?-0:i}:Dn;Et({global:!0,forced:parseFloat!=Hn},{parseFloat:Hn});var Mn=pn.trim,Un=o.parseInt,zn=/^[+-]?0[Xx]/,qn=8!==Un(cn+"08")||22!==Un(cn+"0x16")?function(t,e){var i=Mn(String(t));return Un(i,e>>>0||(zn.test(i)?16:10))}:Un;Et({global:!0,forced:parseInt!=qn},{parseInt:qn});var Wn=function(){var t=P(this),e="";return t.global&&(e+="g"),t.ignoreCase&&(e+="i"),t.multiline&&(e+="m"),t.dotAll&&(e+="s"),t.unicode&&(e+="u"),t.sticky&&(e+="y"),e};function Gn(t,e){return RegExp(t,e)}var Kn,Jn,Yn={UNSUPPORTED_Y:r((function(){var t=Gn("a","y");return t.lastIndex=2,null!=t.exec("abcd")})),BROKEN_CARET:r((function(){var t=Gn("^r","gy");return t.lastIndex=2,null!=t.exec("str")}))},Xn=RegExp.prototype.exec,Qn=String.prototype.replace,Zn=Xn,to=(Kn=/a/,Jn=/b*/g,Xn.call(Kn,"a"),Xn.call(Jn,"a"),0!==Kn.lastIndex||0!==Jn.lastIndex),eo=Yn.UNSUPPORTED_Y||Yn.BROKEN_CARET,io=void 0!==/()??/.exec("")[1];(to||io||eo)&&(Zn=function(t){var e,i,n,o,r=this,a=eo&&r.sticky,s=Wn.call(r),l=r.source,c=0,h=t;return a&&(-1===(s=s.replace("y","")).indexOf("g")&&(s+="g"),h=String(t).slice(r.lastIndex),r.lastIndex>0&&(!r.multiline||r.multiline&&"\n"!==t[r.lastIndex-1])&&(l="(?: "+l+")",h=" "+h,c++),i=new RegExp("^(?:"+l+")",s)),io&&(i=new RegExp("^"+l+"$(?!\\s)",s)),to&&(e=r.lastIndex),n=Xn.call(a?i:r,h),a?n?(n.input=n.input.slice(c),n[0]=n[0].slice(c),n.index=r.lastIndex,r.lastIndex+=n[0].length):r.lastIndex=0:to&&n&&(r.lastIndex=r.global?n.index+n[0].length:e),io&&n&&n.length>1&&Qn.call(n[0],i,(function(){for(o=1;o<arguments.length-2;o++)void 0===arguments[o]&&(n[o]=void 0)})),n});var no=Zn;Et({target:"RegExp",proto:!0,forced:/./.exec!==no},{exec:no});var oo=RegExp.prototype,ro=oo.toString,ao=r((function(){return"/a/b"!=ro.call({source:"a",flags:"b"})})),so="toString"!=ro.name;(ao||so)&&et(RegExp.prototype,"toString",(function(){var t=P(this),e=String(t.source),i=t.flags;return"/"+e+"/"+String(void 0===i&&t instanceof RegExp&&!("flags"in oo)?Wn.call(t):i)}),{unsafe:!0});var lo=Xt("match"),co=function(t){var e;return b(t)&&(void 0!==(e=t[lo])?!!e:"RegExp"==d(t))},ho=function(t){if(co(t))throw TypeError("The method doesn't accept regular expressions");return t},uo=Xt("match");Et({target:"String",proto:!0,forced:!function(t){var e=/./;try{"/./"[t](e)}catch(i){try{return e[uo]=!1,"/./"[t](e)}catch(t){}}return!1}("includes")},{includes:function(t){return!!~String(g(this)).indexOf(ho(t),arguments.length>1?arguments[1]:void 0)}});var fo=function(t){return function(e,i){var n,o,r=String(g(e)),a=st(i),s=r.length;return a<0||a>=s?t?"":void 0:(n=r.charCodeAt(a))<55296||n>56319||a+1===s||(o=r.charCodeAt(a+1))<56320||o>57343?t?r.charAt(a):n:t?r.slice(a,a+2):o-56320+(n-55296<<10)+65536}},po={codeAt:fo(!1),charAt:fo(!0)},go=po.charAt,vo=tt.set,bo=tt.getterFor("String Iterator");Li(String,"String",(function(t){vo(this,{type:"String Iterator",string:String(t),index:0})}),(function(){var t,e=bo(this),i=e.string,n=e.index;return n>=i.length?{value:void 0,done:!0}:(t=go(i,n),e.index+=t.length,{value:t,done:!1})}));var mo=Xt("species"),yo=!r((function(){var t=/./;return t.exec=function(){var t=[];return t.groups={a:"7"},t},"7"!=="".replace(t,"$<a>")})),wo="$0"==="a".replace(/./,"$0"),So=!r((function(){var t=/(?:)/,e=t.exec;t.exec=function(){return e.apply(this,arguments)};var i="ab".split(t);return 2!==i.length||"a"!==i[0]||"b"!==i[1]})),xo=function(t,e,i,n){var o=Xt(t),a=!r((function(){var e={};return e[o]=function(){return 7},7!=""[t](e)})),s=a&&!r((function(){var e=!1,i=/a/;return"split"===t&&((i={}).constructor={},i.constructor[mo]=function(){return i},i.flags="",i[o]=/./[o]),i.exec=function(){return e=!0,null},i[o](""),!e}));if(!a||!s||"replace"===t&&(!yo||!wo)||"split"===t&&!So){var l=/./[o],c=i(o,""[t],(function(t,e,i,n,o){return e.exec===no?a&&!o?{done:!0,value:l.call(e,i,n)}:{done:!0,value:t.call(i,e,n)}:{done:!1}}),{REPLACE_KEEPS_$0:wo}),h=c[0],u=c[1];et(String.prototype,t,h),et(RegExp.prototype,o,2==e?function(t,e){return u.call(t,this,e)}:function(t){return u.call(t,this)})}n&&A(RegExp.prototype[o],"sham",!0)},ko=po.charAt,Oo=function(t,e,i){return e+(i?ko(t,e).length:1)},Co=function(t,e){var i=t.exec;if("function"==typeof i){var n=i.call(t,e);if("object"!=typeof n)throw TypeError("RegExp exec method returned something other than an Object or null");return n}if("RegExp"!==d(t))throw TypeError("RegExp#exec called on incompatible receiver");return no.call(t,e)},To=Math.max,Po=Math.min,$o=Math.floor,Io=/\$([$&'`]|\d\d?|<[^>]*>)/g,Ao=/\$([$&'`]|\d\d?)/g;xo("replace",2,(function(t,e,i,n){return[function(i,n){var o=g(this),r=null==i?void 0:i[t];return void 0!==r?r.call(i,o,n):e.call(String(o),i,n)},function(t,r){if(n.REPLACE_KEEPS_$0||"string"==typeof r&&-1===r.indexOf("$0")){var a=i(e,t,this,r);if(a.done)return a.value}var s=P(t),l=String(this),c="function"==typeof r;c||(r=String(r));var h=s.global;if(h){var u=s.unicode;s.lastIndex=0}for(var d=[];;){var f=Co(s,l);if(null===f)break;if(d.push(f),!h)break;""===String(f[0])&&(s.lastIndex=Oo(l,ct(s.lastIndex),u))}for(var p,g="",v=0,b=0;b<d.length;b++){f=d[b];for(var m=String(f[0]),y=To(Po(st(f.index),l.length),0),w=[],S=1;S<f.length;S++)w.push(void 0===(p=f[S])?p:String(p));var x=f.groups;if(c){var k=[m].concat(w,y,l);void 0!==x&&k.push(x);var O=String(r.apply(void 0,k))}else O=o(m,l,y,w,x,r);y>=v&&(g+=l.slice(v,y)+O,v=y+m.length)}return g+l.slice(v)}];function o(t,i,n,o,r,a){var s=n+t.length,l=o.length,c=Ao;return void 0!==r&&(r=Ft(r),c=Io),e.call(a,c,(function(e,a){var c;switch(a.charAt(0)){case"$":return"$";case"&":return t;case"`":return i.slice(0,n);case"'":return i.slice(s);case"<":c=r[a.slice(1,-1)];break;default:var h=+a;if(0===h)return e;if(h>l){var u=$o(h/10);return 0===u?e:u<=l?void 0===o[u-1]?a.charAt(1):o[u-1]+a.charAt(1):e}c=o[h-1]}return void 0===c?"":c}))}}));var Eo=Object.is||function(t,e){return t===e?0!==t||1/t==1/e:t!=t&&e!=e};xo("search",1,(function(t,e,i){return[function(e){var i=g(this),n=null==e?void 0:e[t];return void 0!==n?n.call(e,i):new RegExp(e)[t](String(i))},function(t){var n=i(e,t,this);if(n.done)return n.value;var o=P(t),r=String(this),a=o.lastIndex;Eo(a,0)||(o.lastIndex=0);var s=Co(o,r);return Eo(o.lastIndex,a)||(o.lastIndex=a),null===s?-1:s.index}]}));var Ro=Xt("species"),jo=[].push,No=Math.min,Fo=!r((function(){return!RegExp(4294967295,"y")}));xo("split",2,(function(t,e,i){var n;return n="c"=="abbc".split(/(b)*/)[1]||4!="test".split(/(?:)/,-1).length||2!="ab".split(/(?:ab)*/).length||4!=".".split(/(.?)(.?)/).length||".".split(/()()/).length>1||"".split(/.?/).length?function(t,i){var n=String(g(this)),o=void 0===i?4294967295:i>>>0;if(0===o)return[];if(void 0===t)return[n];if(!co(t))return e.call(n,t,o);for(var r,a,s,l=[],c=(t.ignoreCase?"i":"")+(t.multiline?"m":"")+(t.unicode?"u":"")+(t.sticky?"y":""),h=0,u=new RegExp(t.source,c+"g");(r=no.call(u,n))&&!((a=u.lastIndex)>h&&(l.push(n.slice(h,r.index)),r.length>1&&r.index<n.length&&jo.apply(l,r.slice(1)),s=r[0].length,h=a,l.length>=o));)u.lastIndex===r.index&&u.lastIndex++;return h===n.length?!s&&u.test("")||l.push(""):l.push(n.slice(h)),l.length>o?l.slice(0,o):l}:"0".split(void 0,0).length?function(t,i){return void 0===t&&0===i?[]:e.call(this,t,i)}:e,[function(e,i){var o=g(this),r=null==e?void 0:e[t];return void 0!==r?r.call(e,o,i):n.call(String(o),e,i)},function(t,o){var r=i(n,t,this,o,n!==e);if(r.done)return r.value;var a=P(t),s=String(this),l=function(t,e){var i,n=P(t).constructor;return void 0===n||null==(i=P(n)[Ro])?e:oe(i)}(a,RegExp),c=a.unicode,h=(a.ignoreCase?"i":"")+(a.multiline?"m":"")+(a.unicode?"u":"")+(Fo?"y":"g"),u=new l(Fo?a:"^(?:"+a.source+")",h),d=void 0===o?4294967295:o>>>0;if(0===d)return[];if(0===s.length)return null===Co(u,s)?[s]:[];for(var f=0,p=0,g=[];p<s.length;){u.lastIndex=Fo?p:0;var v,b=Co(u,Fo?s:s.slice(p));if(null===b||(v=No(ct(u.lastIndex+(Fo?0:p)),s.length))===f)p=Oo(s,p,c);else{if(g.push(s.slice(f,p)),g.length===d)return g;for(var m=1;m<=b.length-1;m++)if(g.push(b[m]),g.length===d)return g;p=f=v}}return g.push(s.slice(f)),g}]}),!Fo);var _o=pn.trim;Et({target:"String",proto:!0,forced:function(t){return r((function(){return!!cn[t]()||"​
bootstrap-table - An extended table to integration with some of the most widely used CSS frameworks. (Supports Bootstrap, Semantic UI, Bulma, Material Design, Foundation) @version v1.16.0 @homepage https://bootstrap-table.com @author wenzhixin <[email protected]> (http://wenzhixin.net.cn/) @license MIT
(anonymous) ( t , e )
javascript
awslabs/datawig
datawig-js/static/js/bootstrap-table.min_1.16.0.js
https://github.com/awslabs/datawig/blob/master/datawig-js/static/js/bootstrap-table.min_1.16.0.js
Apache-2.0
getContent: function() { return null; // see implementation },
Return the decompressed content in an unspecified format. The format will depend on the decompressor. @return {Object} the decompressed content.
getContent ( )
javascript
awslabs/datawig
datawig-js/static/js/xlsx_jszip_0.15.5.js
https://github.com/awslabs/datawig/blob/master/datawig-js/static/js/xlsx_jszip_0.15.5.js
Apache-2.0
getCompressedContent: function() { return null; // see implementation }
Return the compressed content in an unspecified format. The format will depend on the compressed conten source. @return {Object} the compressed content.
getCompressedContent ( )
javascript
awslabs/datawig
datawig-js/static/js/xlsx_jszip_0.15.5.js
https://github.com/awslabs/datawig/blob/master/datawig-js/static/js/xlsx_jszip_0.15.5.js
Apache-2.0
module.exports = function crc32(input, crc) { if (typeof input === "undefined" || !input.length) { return 0; } var isArray = utils.getTypeOf(input) !== "string"; if (typeof(crc) == "undefined") { crc = 0; } var x = 0; var y = 0; var b = 0; crc = crc ^ (-1); for (var i = 0, iTop = input.length; i < iTop; i++) { b = isArray ? input[i] : input.charCodeAt(i); y = (crc ^ b) & 0xFF; x = table[y]; crc = (crc >>> 8) ^ x; } return crc ^ (-1); };
Javascript crc32 http://www.webtoolkit.info/
crc32 ( input , crc )
javascript
awslabs/datawig
datawig-js/static/js/xlsx_jszip_0.15.5.js
https://github.com/awslabs/datawig/blob/master/datawig-js/static/js/xlsx_jszip_0.15.5.js
Apache-2.0
checkOffset: function(offset) { this.checkIndex(this.index + offset); },
Check that the offset will not go too far. @param {string} offset the additional offset to check. @throws {Error} an Error if the offset is out of bounds.
checkOffset ( offset )
javascript
awslabs/datawig
datawig-js/static/js/xlsx_jszip_0.15.5.js
https://github.com/awslabs/datawig/blob/master/datawig-js/static/js/xlsx_jszip_0.15.5.js
Apache-2.0
checkIndex: function(newIndex) { if (this.length < newIndex || newIndex < 0) { throw new Error("End of data reached (data length = " + this.length + ", asked index = " + (newIndex) + "). Corrupted zip ?"); } },
Check that the specifed index will not be too far. @param {string} newIndex the index to check. @throws {Error} an Error if the index is out of bounds.
checkIndex ( newIndex )
javascript
awslabs/datawig
datawig-js/static/js/xlsx_jszip_0.15.5.js
https://github.com/awslabs/datawig/blob/master/datawig-js/static/js/xlsx_jszip_0.15.5.js
Apache-2.0
setIndex: function(newIndex) { this.checkIndex(newIndex); this.index = newIndex; },
Change the index. @param {number} newIndex The new index. @throws {Error} if the new index is out of the data.
setIndex ( newIndex )
javascript
awslabs/datawig
datawig-js/static/js/xlsx_jszip_0.15.5.js
https://github.com/awslabs/datawig/blob/master/datawig-js/static/js/xlsx_jszip_0.15.5.js
Apache-2.0
skip: function(n) { this.setIndex(this.index + n); },
Skip the next n bytes. @param {number} n the number of bytes to skip. @throws {Error} if the new index is out of the data.
skip ( n )
javascript
awslabs/datawig
datawig-js/static/js/xlsx_jszip_0.15.5.js
https://github.com/awslabs/datawig/blob/master/datawig-js/static/js/xlsx_jszip_0.15.5.js
Apache-2.0
byteAt: function(i) { // see implementations },
Get the byte at the specified index. @param {number} i the index to use. @return {number} a byte.
byteAt ( i )
javascript
awslabs/datawig
datawig-js/static/js/xlsx_jszip_0.15.5.js
https://github.com/awslabs/datawig/blob/master/datawig-js/static/js/xlsx_jszip_0.15.5.js
Apache-2.0
readInt: function(size) { var result = 0, i; this.checkOffset(size); for (i = this.index + size - 1; i >= this.index; i--) { result = (result << 8) + this.byteAt(i); } this.index += size; return result; },
Get the next number with a given byte size. @param {number} size the number of bytes to read. @return {number} the corresponding number.
readInt ( size )
javascript
awslabs/datawig
datawig-js/static/js/xlsx_jszip_0.15.5.js
https://github.com/awslabs/datawig/blob/master/datawig-js/static/js/xlsx_jszip_0.15.5.js
Apache-2.0
readString: function(size) { return utils.transformTo("string", this.readData(size)); },
Get the next string with a given byte size. @param {number} size the number of bytes to read. @return {string} the corresponding string.
readString ( size )
javascript
awslabs/datawig
datawig-js/static/js/xlsx_jszip_0.15.5.js
https://github.com/awslabs/datawig/blob/master/datawig-js/static/js/xlsx_jszip_0.15.5.js
Apache-2.0
readData: function(size) { // see implementations },
Get raw data without conversion, <size> bytes. @param {number} size the number of bytes to read. @return {Object} the raw data, implementation specific.
readData ( size )
javascript
awslabs/datawig
datawig-js/static/js/xlsx_jszip_0.15.5.js
https://github.com/awslabs/datawig/blob/master/datawig-js/static/js/xlsx_jszip_0.15.5.js
Apache-2.0
lastIndexOfSignature: function(sig) { // see implementations },
Find the last occurence of a zip signature (4 bytes). @param {string} sig the signature to find. @return {number} the index of the last occurence, -1 if not found.
lastIndexOfSignature ( sig )
javascript
awslabs/datawig
datawig-js/static/js/xlsx_jszip_0.15.5.js
https://github.com/awslabs/datawig/blob/master/datawig-js/static/js/xlsx_jszip_0.15.5.js
Apache-2.0
readDate: function() { var dostime = this.readInt(4); return new Date( ((dostime >> 25) & 0x7f) + 1980, // year ((dostime >> 21) & 0x0f) - 1, // month (dostime >> 16) & 0x1f, // day (dostime >> 11) & 0x1f, // hour (dostime >> 5) & 0x3f, // minute (dostime & 0x1f) << 1); // second }
Get the next date. @return {Date} the date.
readDate ( )
javascript
awslabs/datawig
datawig-js/static/js/xlsx_jszip_0.15.5.js
https://github.com/awslabs/datawig/blob/master/datawig-js/static/js/xlsx_jszip_0.15.5.js
Apache-2.0
exports.string2binary = function(str) { return utils.string2binary(str); };
@deprecated This function will be removed in a future version without replacement.
exports.string2binary ( str )
javascript
awslabs/datawig
datawig-js/static/js/xlsx_jszip_0.15.5.js
https://github.com/awslabs/datawig/blob/master/datawig-js/static/js/xlsx_jszip_0.15.5.js
Apache-2.0
function JSZipSync(data, options) { // if this constructor is used without `new`, it adds `new` before itself: if(!(this instanceof JSZipSync)) return new JSZipSync(data, options); // object containing the files : // { // "folder/" : {...}, // "folder/data.txt" : {...} // } this.files = {}; this.comment = null; // Where we are in the hierarchy this.root = ""; if (data) { this.load(data, options); } this.clone = function() { var newObj = new JSZipSync(); for (var i in this) { if (typeof this[i] !== "function") { newObj[i] = this[i]; } } return newObj; }; }
Representation a of zip file in js @constructor @param {String=|ArrayBuffer=|Uint8Array=} data the data to load, if any (optional). @param {Object=} options the options for creating this objects (optional).
JSZipSync ( data , options )
javascript
awslabs/datawig
datawig-js/static/js/xlsx_jszip_0.15.5.js
https://github.com/awslabs/datawig/blob/master/datawig-js/static/js/xlsx_jszip_0.15.5.js
Apache-2.0
encode : function(input) { return base64.encode(input); },
@deprecated This method will be removed in a future version without replacement.
encode ( input )
javascript
awslabs/datawig
datawig-js/static/js/xlsx_jszip_0.15.5.js
https://github.com/awslabs/datawig/blob/master/datawig-js/static/js/xlsx_jszip_0.15.5.js
Apache-2.0
var getRawData = function(file) { if (file._data instanceof CompressedObject) { file._data = file._data.getContent(); file.options.binary = true; file.options.base64 = false; if (utils.getTypeOf(file._data) === "uint8array") { var copy = file._data; // when reading an arraybuffer, the CompressedObject mechanism will keep it and subarray() a Uint8Array. // if we request a file in the same format, we might get the same Uint8Array or its ArrayBuffer (the original zip file). file._data = new Uint8Array(copy.length); // with an empty Uint8Array, Opera fails with a "Offset larger than array size" if (copy.length !== 0) { file._data.set(copy, 0); } } } return file._data; };
Returns the raw data of a ZipObject, decompress the content if necessary. @param {ZipObject} file the file to use. @return {String|ArrayBuffer|Uint8Array|Buffer} the data.
getRawData ( file )
javascript
awslabs/datawig
datawig-js/static/js/xlsx_jszip_0.15.5.js
https://github.com/awslabs/datawig/blob/master/datawig-js/static/js/xlsx_jszip_0.15.5.js
Apache-2.0
var getBinaryData = function(file) { var result = getRawData(file), type = utils.getTypeOf(result); if (type === "string") { if (!file.options.binary) { // unicode text ! // unicode string => binary string is a painful process, check if we can avoid it. if (support.nodebuffer) { return nodeBuffer(result, "utf-8"); } } return file.asBinary(); } return result; };
Returns the data of a ZipObject in a binary form. If the content is an unicode string, encode it. @param {ZipObject} file the file to use. @return {String|ArrayBuffer|Uint8Array|Buffer} the data.
getBinaryData ( file )
javascript
awslabs/datawig
datawig-js/static/js/xlsx_jszip_0.15.5.js
https://github.com/awslabs/datawig/blob/master/datawig-js/static/js/xlsx_jszip_0.15.5.js
Apache-2.0
var dataToString = function(asUTF8) { var result = getRawData(this); if (result === null || typeof result === "undefined") { return ""; } // if the data is a base64 string, we decode it before checking the encoding ! if (this.options.base64) { result = base64.decode(result); } if (asUTF8 && this.options.binary) { // JSZip.prototype.utf8decode supports arrays as input // skip to array => string step, utf8decode will do it. result = out.utf8decode(result); } else { // no utf8 transformation, do the array => string step. result = utils.transformTo("string", result); } if (!asUTF8 && !this.options.binary) { result = utils.transformTo("string", out.utf8encode(result)); } return result; };
Transform this._data into a string. @param {function} filter a function String -> String, applied if not null on the result. @return {String} the string representing this._data.
dataToString ( asUTF8 )
javascript
awslabs/datawig
datawig-js/static/js/xlsx_jszip_0.15.5.js
https://github.com/awslabs/datawig/blob/master/datawig-js/static/js/xlsx_jszip_0.15.5.js
Apache-2.0
var ZipObject = function(name, data, options) { this.name = name; this.dir = options.dir; this.date = options.date; this.comment = options.comment; this._data = data; this.options = options; /* * This object contains initial values for dir and date. * With them, we can check if the user changed the deprecated metadata in * `ZipObject#options` or not. */ this._initialMetadata = { dir : options.dir, date : options.date }; };
A simple object representing a file in the zip file. @constructor @param {string} name the name of the file @param {String|ArrayBuffer|Uint8Array|Buffer} data the data @param {Object} options the options of the file
ZipObject ( name , data , options )
javascript
awslabs/datawig
datawig-js/static/js/xlsx_jszip_0.15.5.js
https://github.com/awslabs/datawig/blob/master/datawig-js/static/js/xlsx_jszip_0.15.5.js
Apache-2.0
asText: function() { return dataToString.call(this, true); },
Return the content as UTF8 string. @return {string} the UTF8 string.
asText ( )
javascript
awslabs/datawig
datawig-js/static/js/xlsx_jszip_0.15.5.js
https://github.com/awslabs/datawig/blob/master/datawig-js/static/js/xlsx_jszip_0.15.5.js
Apache-2.0
asBinary: function() { return dataToString.call(this, false); },
Returns the binary content. @return {string} the content as binary.
asBinary ( )
javascript
awslabs/datawig
datawig-js/static/js/xlsx_jszip_0.15.5.js
https://github.com/awslabs/datawig/blob/master/datawig-js/static/js/xlsx_jszip_0.15.5.js
Apache-2.0
asNodeBuffer: function() { var result = getBinaryData(this); return utils.transformTo("nodebuffer", result); },
Returns the content as a nodejs Buffer. @return {Buffer} the content as a Buffer.
asNodeBuffer ( )
javascript
awslabs/datawig
datawig-js/static/js/xlsx_jszip_0.15.5.js
https://github.com/awslabs/datawig/blob/master/datawig-js/static/js/xlsx_jszip_0.15.5.js
Apache-2.0
asUint8Array: function() { var result = getBinaryData(this); return utils.transformTo("uint8array", result); },
Returns the content as an Uint8Array. @return {Uint8Array} the content as an Uint8Array.
asUint8Array ( )
javascript
awslabs/datawig
datawig-js/static/js/xlsx_jszip_0.15.5.js
https://github.com/awslabs/datawig/blob/master/datawig-js/static/js/xlsx_jszip_0.15.5.js
Apache-2.0
asArrayBuffer: function() { return this.asUint8Array().buffer; }
Returns the content as an ArrayBuffer. @return {ArrayBuffer} the content as an ArrayBufer.
asArrayBuffer ( )
javascript
awslabs/datawig
datawig-js/static/js/xlsx_jszip_0.15.5.js
https://github.com/awslabs/datawig/blob/master/datawig-js/static/js/xlsx_jszip_0.15.5.js
Apache-2.0
var decToHex = function(dec, bytes) { var hex = "", i; for (i = 0; i < bytes; i++) { hex += String.fromCharCode(dec & 0xff); dec = dec >>> 8; } return hex; };
Transform an integer into a string in hexadecimal. @private @param {number} dec the number to convert. @param {number} bytes the number of bytes to generate. @returns {string} the result.
decToHex ( dec , bytes )
javascript
awslabs/datawig
datawig-js/static/js/xlsx_jszip_0.15.5.js
https://github.com/awslabs/datawig/blob/master/datawig-js/static/js/xlsx_jszip_0.15.5.js
Apache-2.0
var extend = function() { var result = {}, i, attr; for (i = 0; i < arguments.length; i++) { // arguments is not enumerable in some browsers for (attr in arguments[i]) { if (arguments[i].hasOwnProperty(attr) && typeof result[attr] === "undefined") { result[attr] = arguments[i][attr]; } } } return result; };
Merge the objects passed as parameters into a new one. @private @param {...Object} var_args All objects to merge. @return {Object} a new object with the data of the others.
extend ( )
javascript
awslabs/datawig
datawig-js/static/js/xlsx_jszip_0.15.5.js
https://github.com/awslabs/datawig/blob/master/datawig-js/static/js/xlsx_jszip_0.15.5.js
Apache-2.0
var prepareFileAttrs = function(o) { o = o || {}; if (o.base64 === true && (o.binary === null || o.binary === undefined)) { o.binary = true; } o = extend(o, defaults); o.date = o.date || new Date(); if (o.compression !== null) o.compression = o.compression.toUpperCase(); return o; };
Transforms the (incomplete) options from the user into the complete set of options to create a file. @private @param {Object} o the options from the user. @return {Object} the complete set of options.
prepareFileAttrs ( o )
javascript
awslabs/datawig
datawig-js/static/js/xlsx_jszip_0.15.5.js
https://github.com/awslabs/datawig/blob/master/datawig-js/static/js/xlsx_jszip_0.15.5.js
Apache-2.0
var fileAdd = function(name, data, o) { // be sure sub folders exist var dataType = utils.getTypeOf(data), parent; o = prepareFileAttrs(o); if (o.createFolders && (parent = parentFolder(name))) { folderAdd.call(this, parent, true); } if (o.dir || data === null || typeof data === "undefined") { o.base64 = false; o.binary = false; data = null; } else if (dataType === "string") { if (o.binary && !o.base64) { // optimizedBinaryString == true means that the file has already been filtered with a 0xFF mask if (o.optimizedBinaryString !== true) { // this is a string, not in a base64 format. // Be sure that this is a correct "binary string" data = utils.string2binary(data); } } } else { // arraybuffer, uint8array, ... o.base64 = false; o.binary = true; if (!dataType && !(data instanceof CompressedObject)) { throw new Error("The data of '" + name + "' is in an unsupported format !"); } // special case : it's way easier to work with Uint8Array than with ArrayBuffer if (dataType === "arraybuffer") { data = utils.transformTo("uint8array", data); } } var object = new ZipObject(name, data, o); this.files[name] = object; return object; };
Add a file in the current folder. @private @param {string} name the name of the file @param {String|ArrayBuffer|Uint8Array|Buffer} data the data of the file @param {Object} o the options of the file @return {Object} the new file.
fileAdd ( name , data , o )
javascript
awslabs/datawig
datawig-js/static/js/xlsx_jszip_0.15.5.js
https://github.com/awslabs/datawig/blob/master/datawig-js/static/js/xlsx_jszip_0.15.5.js
Apache-2.0
var parentFolder = function (path) { if (path.slice(-1) == '/') { path = path.substring(0, path.length - 1); } var lastSlash = path.lastIndexOf('/'); return (lastSlash > 0) ? path.substring(0, lastSlash) : ""; };
Find the parent folder of the path. @private @param {string} path the path to use @return {string} the parent folder, or ""
parentFolder ( path )
javascript
awslabs/datawig
datawig-js/static/js/xlsx_jszip_0.15.5.js
https://github.com/awslabs/datawig/blob/master/datawig-js/static/js/xlsx_jszip_0.15.5.js
Apache-2.0
var folderAdd = function(name, createFolders) { // Check the name ends with a / if (name.slice(-1) != "/") { name += "/"; // IE doesn't like substr(-1) } createFolders = (typeof createFolders !== 'undefined') ? createFolders : false; // Does this folder already exist? if (!this.files[name]) { fileAdd.call(this, name, null, { dir: true, createFolders: createFolders }); } return this.files[name]; };
Add a (sub) folder in the current folder. @private @param {string} name the folder's name @param {boolean=} [createFolders] If true, automatically create sub folders. Defaults to false. @return {Object} the new folder.
folderAdd ( name , createFolders )
javascript
awslabs/datawig
datawig-js/static/js/xlsx_jszip_0.15.5.js
https://github.com/awslabs/datawig/blob/master/datawig-js/static/js/xlsx_jszip_0.15.5.js
Apache-2.0
var generateCompressedObjectFrom = function(file, compression) { var result = new CompressedObject(), content; // the data has not been decompressed, we might reuse things ! if (file._data instanceof CompressedObject) { result.uncompressedSize = file._data.uncompressedSize; result.crc32 = file._data.crc32; if (result.uncompressedSize === 0 || file.dir) { compression = compressions['STORE']; result.compressedContent = ""; result.crc32 = 0; } else if (file._data.compressionMethod === compression.magic) { result.compressedContent = file._data.getCompressedContent(); } else { content = file._data.getContent(); // need to decompress / recompress result.compressedContent = compression.compress(utils.transformTo(compression.compressInputType, content)); } } else { // have uncompressed data content = getBinaryData(file); if (!content || content.length === 0 || file.dir) { compression = compressions['STORE']; content = ""; } result.uncompressedSize = content.length; result.crc32 = crc32(content); result.compressedContent = compression.compress(utils.transformTo(compression.compressInputType, content)); } result.compressedSize = result.compressedContent.length; result.compressionMethod = compression.magic; return result; };
Generate a JSZip.CompressedObject for a given zipOject. @param {ZipObject} file the object to read. @param {JSZip.compression} compression the compression to use. @return {JSZip.CompressedObject} the compressed result.
generateCompressedObjectFrom ( file , compression )
javascript
awslabs/datawig
datawig-js/static/js/xlsx_jszip_0.15.5.js
https://github.com/awslabs/datawig/blob/master/datawig-js/static/js/xlsx_jszip_0.15.5.js
Apache-2.0
load: function(stream, options) { throw new Error("Load method is not defined. Is the file jszip-load.js included ?"); },
Read an existing zip and merge the data in the current JSZip object. The implementation is in jszip-load.js, don't forget to include it. @param {String|ArrayBuffer|Uint8Array|Buffer} stream The stream to load @param {Object} options Options for loading the stream. options.base64 : is the stream in base64 ? default : false @return {JSZip} the current JSZip object
load ( stream , options )
javascript
awslabs/datawig
datawig-js/static/js/xlsx_jszip_0.15.5.js
https://github.com/awslabs/datawig/blob/master/datawig-js/static/js/xlsx_jszip_0.15.5.js
Apache-2.0
filter: function(search) { var result = [], filename, relativePath, file, fileClone; for (filename in this.files) { if (!this.files.hasOwnProperty(filename)) { continue; } file = this.files[filename]; // return a new object, don't let the user mess with our internal objects :) fileClone = new ZipObject(file.name, file._data, extend(file.options)); relativePath = filename.slice(this.root.length, filename.length); if (filename.slice(0, this.root.length) === this.root && // the file is in the current root search(relativePath, fileClone)) { // and the file matches the function result.push(fileClone); } } return result; },
Filter nested files/folders with the specified function. @param {Function} search the predicate to use : function (relativePath, file) {...} It takes 2 arguments : the relative path and the file. @return {Array} An array of matching elements.
filter ( search )
javascript
awslabs/datawig
datawig-js/static/js/xlsx_jszip_0.15.5.js
https://github.com/awslabs/datawig/blob/master/datawig-js/static/js/xlsx_jszip_0.15.5.js
Apache-2.0
file: function(name, data, o) { if (arguments.length === 1) { if (utils.isRegExp(name)) { var regexp = name; return this.filter(function(relativePath, file) { return !file.dir && regexp.test(relativePath); }); } else { // text return this.filter(function(relativePath, file) { return !file.dir && relativePath === name; })[0] || null; } } else { // more than one argument : we have data ! name = this.root + name; fileAdd.call(this, name, data, o); } return this; },
Add a file to the zip file, or search a file. @param {string|RegExp} name The name of the file to add (if data is defined), the name of the file to find (if no data) or a regex to match files. @param {String|ArrayBuffer|Uint8Array|Buffer} data The file data, either raw or base64 encoded @param {Object} o File options @return {JSZip|Object|Array} this JSZip object (when adding a file), a file (when searching by string) or an array of files (when searching by regex).
file ( name , data , o )
javascript
awslabs/datawig
datawig-js/static/js/xlsx_jszip_0.15.5.js
https://github.com/awslabs/datawig/blob/master/datawig-js/static/js/xlsx_jszip_0.15.5.js
Apache-2.0
folder: function(arg) { if (!arg) { return this; } if (utils.isRegExp(arg)) { return this.filter(function(relativePath, file) { return file.dir && arg.test(relativePath); }); } // else, name is a new folder var name = this.root + arg; var newFolder = folderAdd.call(this, name); // Allow chaining by returning a new object with this folder as the root var ret = this.clone(); ret.root = newFolder.name; return ret; },
Add a directory to the zip file, or search. @param {String|RegExp} arg The name of the directory to add, or a regex to search folders. @return {JSZip} an object with the new directory as the root, or an array containing matching folders.
folder ( arg )
javascript
awslabs/datawig
datawig-js/static/js/xlsx_jszip_0.15.5.js
https://github.com/awslabs/datawig/blob/master/datawig-js/static/js/xlsx_jszip_0.15.5.js
Apache-2.0
remove: function(name) { name = this.root + name; var file = this.files[name]; if (!file) { // Look for any folders if (name.slice(-1) != "/") { name += "/"; } file = this.files[name]; } if (file && !file.dir) { // file delete this.files[name]; } else { // maybe a folder, delete recursively var kids = this.filter(function(relativePath, file) { return file.name.slice(0, name.length) === name; }); for (var i = 0; i < kids.length; i++) { delete this.files[kids[i].name]; } } return this; },
Delete a file, or a directory and all sub-files, from the zip @param {string} name the name of the file to delete @return {JSZip} this JSZip object
remove ( name )
javascript
awslabs/datawig
datawig-js/static/js/xlsx_jszip_0.15.5.js
https://github.com/awslabs/datawig/blob/master/datawig-js/static/js/xlsx_jszip_0.15.5.js
Apache-2.0
generate: function(options) { options = extend(options || {}, { base64: true, compression: "STORE", type: "base64", comment: null }); utils.checkSupport(options.type); var zipData = [], localDirLength = 0, centralDirLength = 0, writer, i, utfEncodedComment = utils.transformTo("string", this.utf8encode(options.comment || this.comment || "")); // first, generate all the zip parts. for (var name in this.files) { if (!this.files.hasOwnProperty(name)) { continue; } var file = this.files[name]; var compressionName = file.options.compression || options.compression.toUpperCase(); var compression = compressions[compressionName]; if (!compression) { throw new Error(compressionName + " is not a valid compression method !"); } var compressedObject = generateCompressedObjectFrom.call(this, file, compression); var zipPart = generateZipParts.call(this, name, file, compressedObject, localDirLength); localDirLength += zipPart.fileRecord.length + compressedObject.compressedSize; centralDirLength += zipPart.dirRecord.length; zipData.push(zipPart); } var dirEnd = ""; // end of central dir signature dirEnd = signature.CENTRAL_DIRECTORY_END + // number of this disk "\x00\x00" + // number of the disk with the start of the central directory "\x00\x00" + // total number of entries in the central directory on this disk decToHex(zipData.length, 2) + // total number of entries in the central directory decToHex(zipData.length, 2) + // size of the central directory 4 bytes decToHex(centralDirLength, 4) + // offset of start of central directory with respect to the starting disk number decToHex(localDirLength, 4) + // .ZIP file comment length decToHex(utfEncodedComment.length, 2) + // .ZIP file comment utfEncodedComment; // we have all the parts (and the total length) // time to create a writer ! var typeName = options.type.toLowerCase(); if(typeName==="uint8array"||typeName==="arraybuffer"||typeName==="blob"||typeName==="nodebuffer") { writer = new Uint8ArrayWriter(localDirLength + centralDirLength + dirEnd.length); }else{ writer = new StringWriter(localDirLength + centralDirLength + dirEnd.length); } for (i = 0; i < zipData.length; i++) { writer.append(zipData[i].fileRecord); writer.append(zipData[i].compressedObject.compressedContent); } for (i = 0; i < zipData.length; i++) { writer.append(zipData[i].dirRecord); } writer.append(dirEnd); var zip = writer.finalize(); switch(options.type.toLowerCase()) { // case "zip is an Uint8Array" case "uint8array" : case "arraybuffer" : case "nodebuffer" : return utils.transformTo(options.type.toLowerCase(), zip); case "blob" : return utils.arrayBuffer2Blob(utils.transformTo("arraybuffer", zip)); // case "zip is a string" case "base64" : return (options.base64) ? base64.encode(zip) : zip; default : // case "string" : return zip; } },
Generate the complete zip file @param {Object} options the options to generate the zip file : - base64, (deprecated, use type instead) true to generate base64. - compression, "STORE" by default. - type, "base64" by default. Values are : string, base64, uint8array, arraybuffer, blob. @return {String|Uint8Array|ArrayBuffer|Buffer|Blob} the zip file
generate ( options )
javascript
awslabs/datawig
datawig-js/static/js/xlsx_jszip_0.15.5.js
https://github.com/awslabs/datawig/blob/master/datawig-js/static/js/xlsx_jszip_0.15.5.js
Apache-2.0
var generateZipParts = function(name, file, compressedObject, offset) { var data = compressedObject.compressedContent, utfEncodedFileName = utils.transformTo("string", utf8.utf8encode(file.name)), comment = file.comment || "", utfEncodedComment = utils.transformTo("string", utf8.utf8encode(comment)), useUTF8ForFileName = utfEncodedFileName.length !== file.name.length, useUTF8ForComment = utfEncodedComment.length !== comment.length, o = file.options, dosTime, dosDate, extraFields = "", unicodePathExtraField = "", unicodeCommentExtraField = "", dir, date; // handle the deprecated options.dir if (file._initialMetadata.dir !== file.dir) { dir = file.dir; } else { dir = o.dir; } // handle the deprecated options.date if(file._initialMetadata.date !== file.date) { date = file.date; } else { date = o.date; } dosTime = date.getHours(); dosTime = dosTime << 6; dosTime = dosTime | date.getMinutes(); dosTime = dosTime << 5; dosTime = dosTime | date.getSeconds() / 2; dosDate = date.getFullYear() - 1980; dosDate = dosDate << 4; dosDate = dosDate | (date.getMonth() + 1); dosDate = dosDate << 5; dosDate = dosDate | date.getDate(); if (useUTF8ForFileName) { // set the unicode path extra field. unzip needs at least one extra // field to correctly handle unicode path, so using the path is as good // as any other information. This could improve the situation with // other archive managers too. // This field is usually used without the utf8 flag, with a non // unicode path in the header (winrar, winzip). This helps (a bit) // with the messy Windows' default compressed folders feature but // breaks on p7zip which doesn't seek the unicode path extra field. // So for now, UTF-8 everywhere ! unicodePathExtraField = // Version decToHex(1, 1) + // NameCRC32 decToHex(crc32(utfEncodedFileName), 4) + // UnicodeName utfEncodedFileName; extraFields += // Info-ZIP Unicode Path Extra Field "\x75\x70" + // size decToHex(unicodePathExtraField.length, 2) + // content unicodePathExtraField; } if(useUTF8ForComment) { unicodeCommentExtraField = // Version decToHex(1, 1) + // CommentCRC32 decToHex(this.crc32(utfEncodedComment), 4) + // UnicodeName utfEncodedComment; extraFields += // Info-ZIP Unicode Path Extra Field "\x75\x63" + // size decToHex(unicodeCommentExtraField.length, 2) + // content unicodeCommentExtraField; } var header = ""; // version needed to extract header += "\x0A\x00"; // general purpose bit flag // set bit 11 if utf8 header += (useUTF8ForFileName || useUTF8ForComment) ? "\x00\x08" : "\x00\x00"; // compression method header += compressedObject.compressionMethod; // last mod file time header += decToHex(dosTime, 2); // last mod file date header += decToHex(dosDate, 2); // crc-32 header += decToHex(compressedObject.crc32, 4); // compressed size header += decToHex(compressedObject.compressedSize, 4); // uncompressed size header += decToHex(compressedObject.uncompressedSize, 4); // file name length header += decToHex(utfEncodedFileName.length, 2); // extra field length header += decToHex(extraFields.length, 2); var fileRecord = signature.LOCAL_FILE_HEADER + header + utfEncodedFileName + extraFields; var dirRecord = signature.CENTRAL_FILE_HEADER + // version made by (00: DOS) "\x14\x00" + // file header (common to file and central directory) header + // file comment length decToHex(utfEncodedComment.length, 2) + // disk number start "\x00\x00" + // internal file attributes TODO "\x00\x00" + // external file attributes (dir === true ? "\x10\x00\x00\x00" : "\x00\x00\x00\x00") + // relative offset of local header decToHex(offset, 4) + // file name utfEncodedFileName + // extra field extraFields + // file comment utfEncodedComment; return { fileRecord: fileRecord, dirRecord: dirRecord, compressedObject: compressedObject }; }; // return the actual prototype of JSZip var out = { /** * Read an existing zip and merge the data in the current JSZip object. * The implementation is in jszip-load.js, don't forget to include it. * @param {String|ArrayBuffer|Uint8Array|Buffer} stream The stream to load * @param {Object} options Options for loading the stream. * options.base64 : is the stream in base64 ? default : false * @return {JSZip} the current JSZip object */ load: function(stream, options) { throw new Error("Load method is not defined. Is the file jszip-load.js included ?"); }, /** * Filter nested files/folders with the specified function. * @param {Function} search the predicate to use : * function (relativePath, file) {...} * It takes 2 arguments : the relative path and the file. * @return {Array} An array of matching elements. */ filter: function(search) { var result = [], filename, relativePath, file, fileClone; for (filename in this.files) { if (!this.files.hasOwnProperty(filename)) { continue; } file = this.files[filename]; // return a new object, don't let the user mess with our internal objects :) fileClone = new ZipObject(file.name, file._data, extend(file.options)); relativePath = filename.slice(this.root.length, filename.length); if (filename.slice(0, this.root.length) === this.root && // the file is in the current root search(relativePath, fileClone)) { // and the file matches the function result.push(fileClone); } } return result; }, /** * Add a file to the zip file, or search a file. * @param {string|RegExp} name The name of the file to add (if data is defined), * the name of the file to find (if no data) or a regex to match files. * @param {String|ArrayBuffer|Uint8Array|Buffer} data The file data, either raw or base64 encoded * @param {Object} o File options * @return {JSZip|Object|Array} this JSZip object (when adding a file), * a file (when searching by string) or an array of files (when searching by regex). */ file: function(name, data, o) { if (arguments.length === 1) { if (utils.isRegExp(name)) { var regexp = name; return this.filter(function(relativePath, file) { return !file.dir && regexp.test(relativePath); }); } else { // text return this.filter(function(relativePath, file) { return !file.dir && relativePath === name; })[0] || null; } } else { // more than one argument : we have data ! name = this.root + name; fileAdd.call(this, name, data, o); } return this; }, /** * Add a directory to the zip file, or search. * @param {String|RegExp} arg The name of the directory to add, or a regex to search folders. * @return {JSZip} an object with the new directory as the root, or an array containing matching folders. */ folder: function(arg) { if (!arg) { return this; } if (utils.isRegExp(arg)) { return this.filter(function(relativePath, file) { return file.dir && arg.test(relativePath); }); } // else, name is a new folder var name = this.root + arg; var newFolder = folderAdd.call(this, name); // Allow chaining by returning a new object with this folder as the root var ret = this.clone(); ret.root = newFolder.name; return ret; }, /** * Delete a file, or a directory and all sub-files, from the zip * @param {string} name the name of the file to delete * @return {JSZip} this JSZip object */ remove: function(name) { name = this.root + name; var file = this.files[name]; if (!file) { // Look for any folders if (name.slice(-1) != "/") { name += "/"; } file = this.files[name]; } if (file && !file.dir) { // file delete this.files[name]; } else { // maybe a folder, delete recursively var kids = this.filter(function(relativePath, file) { return file.name.slice(0, name.length) === name; }); for (var i = 0; i < kids.length; i++) { delete this.files[kids[i].name]; } } return this; }, /** * Generate the complete zip file * @param {Object} options the options to generate the zip file : * - base64, (deprecated, use type instead) true to generate base64. * - compression, "STORE" by default. * - type, "base64" by default. Values are : string, base64, uint8array, arraybuffer, blob. * @return {String|Uint8Array|ArrayBuffer|Buffer|Blob} the zip file */ generate: function(options) { options = extend(options || {}, { base64: true, compression: "STORE", type: "base64", comment: null }); utils.checkSupport(options.type); var zipData = [], localDirLength = 0, centralDirLength = 0, writer, i, utfEncodedComment = utils.transformTo("string", this.utf8encode(options.comment || this.comment || "")); // first, generate all the zip parts. for (var name in this.files) { if (!this.files.hasOwnProperty(name)) { continue; } var file = this.files[name]; var compressionName = file.options.compression || options.compression.toUpperCase(); var compression = compressions[compressionName]; if (!compression) { throw new Error(compressionName + " is not a valid compression method !"); } var compressedObject = generateCompressedObjectFrom.call(this, file, compression); var zipPart = generateZipParts.call(this, name, file, compressedObject, localDirLength); localDirLength += zipPart.fileRecord.length + compressedObject.compressedSize; centralDirLength += zipPart.dirRecord.length; zipData.push(zipPart); } var dirEnd = ""; // end of central dir signature dirEnd = signature.CENTRAL_DIRECTORY_END + // number of this disk "\x00\x00" + // number of the disk with the start of the central directory "\x00\x00" + // total number of entries in the central directory on this disk decToHex(zipData.length, 2) + // total number of entries in the central directory decToHex(zipData.length, 2) + // size of the central directory 4 bytes decToHex(centralDirLength, 4) + // offset of start of central directory with respect to the starting disk number decToHex(localDirLength, 4) + // .ZIP file comment length decToHex(utfEncodedComment.length, 2) + // .ZIP file comment utfEncodedComment; // we have all the parts (and the total length) // time to create a writer ! var typeName = options.type.toLowerCase(); if(typeName==="uint8array"||typeName==="arraybuffer"||typeName==="blob"||typeName==="nodebuffer") { writer = new Uint8ArrayWriter(localDirLength + centralDirLength + dirEnd.length); }else{ writer = new StringWriter(localDirLength + centralDirLength + dirEnd.length); } for (i = 0; i < zipData.length; i++) { writer.append(zipData[i].fileRecord); writer.append(zipData[i].compressedObject.compressedContent); } for (i = 0; i < zipData.length; i++) { writer.append(zipData[i].dirRecord); } writer.append(dirEnd); var zip = writer.finalize(); switch(options.type.toLowerCase()) { // case "zip is an Uint8Array" case "uint8array" : case "arraybuffer" : case "nodebuffer" : return utils.transformTo(options.type.toLowerCase(), zip); case "blob" : return utils.arrayBuffer2Blob(utils.transformTo("arraybuffer", zip)); // case "zip is a string" case "base64" : return (options.base64) ? base64.encode(zip) : zip; default : // case "string" : return zip; } }, /** * @deprecated * This method will be removed in a future version without replacement. */ crc32: function (input, crc) { return crc32(input, crc); }, /** * @deprecated * This method will be removed in a future version without replacement. */ utf8encode: function (string) { return utils.transformTo("string", utf8.utf8encode(string)); }, /** * @deprecated * This method will be removed in a future version without replacement. */ utf8decode: function (input) { return utf8.utf8decode(input); } }; module.exports = out; },{"./base64":1,"./compressedObject":2,"./compressions":3,"./crc32":4,"./defaults":6,"./nodeBuffer":11,"./signature":14,"./stringWriter":16,"./support":17,"./uint8ArrayWriter":19,"./utf8":20,"./utils":21}],14:[function(_dereq_,module,exports){
Generate the various parts used in the construction of the final zip file. @param {string} name the file name. @param {ZipObject} file the file content. @param {JSZip.CompressedObject} compressedObject the compressed object. @param {number} offset the current offset from the start of the zip file. @return {object} the zip parts.
generateZipParts ( name , file , compressedObject , offset )
javascript
awslabs/datawig
datawig-js/static/js/xlsx_jszip_0.15.5.js
https://github.com/awslabs/datawig/blob/master/datawig-js/static/js/xlsx_jszip_0.15.5.js
Apache-2.0
StringReader.prototype.lastIndexOfSignature = function(sig) { return this.data.lastIndexOf(sig); };
@see DataReader.lastIndexOfSignature
StringReader.prototype.lastIndexOfSignature ( sig )
javascript
awslabs/datawig
datawig-js/static/js/xlsx_jszip_0.15.5.js
https://github.com/awslabs/datawig/blob/master/datawig-js/static/js/xlsx_jszip_0.15.5.js
Apache-2.0
var StringWriter = function() { this.data = []; };
An object to write any content to a string. @constructor
StringWriter ( )
javascript
awslabs/datawig
datawig-js/static/js/xlsx_jszip_0.15.5.js
https://github.com/awslabs/datawig/blob/master/datawig-js/static/js/xlsx_jszip_0.15.5.js
Apache-2.0
append: function(input) { input = utils.transformTo("string", input); this.data.push(input); },
Append any content to the current string. @param {Object} input the content to add.
append ( input )
javascript
awslabs/datawig
datawig-js/static/js/xlsx_jszip_0.15.5.js
https://github.com/awslabs/datawig/blob/master/datawig-js/static/js/xlsx_jszip_0.15.5.js
Apache-2.0
finalize: function() { return this.data.join(""); }
Finalize the construction an return the result. @return {string} the generated string.
finalize ( )
javascript
awslabs/datawig
datawig-js/static/js/xlsx_jszip_0.15.5.js
https://github.com/awslabs/datawig/blob/master/datawig-js/static/js/xlsx_jszip_0.15.5.js
Apache-2.0
var Uint8ArrayWriter = function(length) { this.data = new Uint8Array(length); this.index = 0; };
An object to write any content to an Uint8Array. @constructor @param {number} length The length of the array.
Uint8ArrayWriter ( length )
javascript
awslabs/datawig
datawig-js/static/js/xlsx_jszip_0.15.5.js
https://github.com/awslabs/datawig/blob/master/datawig-js/static/js/xlsx_jszip_0.15.5.js
Apache-2.0
append: function(input) { if (input.length !== 0) { // with an empty Uint8Array, Opera fails with a "Offset larger than array size" input = utils.transformTo("uint8array", input); this.data.set(input, this.index); this.index += input.length; } },
Append any content to the current array. @param {Object} input the content to add.
append ( input )
javascript
awslabs/datawig
datawig-js/static/js/xlsx_jszip_0.15.5.js
https://github.com/awslabs/datawig/blob/master/datawig-js/static/js/xlsx_jszip_0.15.5.js
Apache-2.0
finalize: function() { return this.data; }
Finalize the construction an return the result. @return {Uint8Array} the generated array.
finalize ( )
javascript
awslabs/datawig
datawig-js/static/js/xlsx_jszip_0.15.5.js
https://github.com/awslabs/datawig/blob/master/datawig-js/static/js/xlsx_jszip_0.15.5.js
Apache-2.0
exports.utf8encode = function utf8encode(str) { if (support.nodebuffer) { return nodeBuffer(str, "utf-8"); } return string2buf(str); };
Transform a javascript string into an array (typed if possible) of bytes, UTF-8 encoded. @param {String} str the string to encode @return {Array|Uint8Array|Buffer} the UTF-8 encoded string.
utf8encode ( str )
javascript
awslabs/datawig
datawig-js/static/js/xlsx_jszip_0.15.5.js
https://github.com/awslabs/datawig/blob/master/datawig-js/static/js/xlsx_jszip_0.15.5.js
Apache-2.0
exports.utf8decode = function utf8decode(buf) { if (support.nodebuffer) { return utils.transformTo("nodebuffer", buf).toString("utf-8"); } buf = utils.transformTo(support.uint8array ? "uint8array" : "array", buf); // return buf2string(buf); // Chrome prefers to work with "small" chunks of data // for the method buf2string. // Firefox and Chrome has their own shortcut, IE doesn't seem to really care. var result = [], k = 0, len = buf.length, chunk = 65536; while (k < len) { var nextBoundary = utf8border(buf, Math.min(k + chunk, len)); if (support.uint8array) { result.push(buf2string(buf.subarray(k, nextBoundary))); } else { result.push(buf2string(buf.slice(k, nextBoundary))); } k = nextBoundary; } return result.join(""); }; // vim: set shiftwidth=4 softtabstop=4: },{"./nodeBuffer":11,"./support":17,"./utils":21}],21:[function(_dereq_,module,exports){
Transform a bytes array (or a representation) representing an UTF-8 encoded string into a javascript string. @param {Array|Uint8Array|Buffer} buf the data de decode @return {String} the decoded string.
utf8decode ( buf )
javascript
awslabs/datawig
datawig-js/static/js/xlsx_jszip_0.15.5.js
https://github.com/awslabs/datawig/blob/master/datawig-js/static/js/xlsx_jszip_0.15.5.js
Apache-2.0
exports.string2binary = function(str) { var result = ""; for (var i = 0; i < str.length; i++) { result += String.fromCharCode(str.charCodeAt(i) & 0xff); } return result; };
Convert a string to a "binary string" : a string containing only char codes between 0 and 255. @param {string} str the string to transform. @return {String} the binary string.
exports.string2binary ( str )
javascript
awslabs/datawig
datawig-js/static/js/xlsx_jszip_0.15.5.js
https://github.com/awslabs/datawig/blob/master/datawig-js/static/js/xlsx_jszip_0.15.5.js
Apache-2.0
function identity(input) { return input; }
The identity function. @param {Object} input the input. @return {Object} the same input.
identity ( input )
javascript
awslabs/datawig
datawig-js/static/js/xlsx_jszip_0.15.5.js
https://github.com/awslabs/datawig/blob/master/datawig-js/static/js/xlsx_jszip_0.15.5.js
Apache-2.0
function stringToArrayLike(str, array) { for (var i = 0; i < str.length; ++i) { array[i] = str.charCodeAt(i) & 0xFF; } return array; }
Fill in an array with a string. @param {String} str the string to use. @param {Array|ArrayBuffer|Uint8Array|Buffer} array the array to fill in (will be mutated). @return {Array|ArrayBuffer|Uint8Array|Buffer} the updated array.
stringToArrayLike ( str , array )
javascript
awslabs/datawig
datawig-js/static/js/xlsx_jszip_0.15.5.js
https://github.com/awslabs/datawig/blob/master/datawig-js/static/js/xlsx_jszip_0.15.5.js
Apache-2.0
function arrayLikeToString(array) { // Performances notes : // -------------------- // String.fromCharCode.apply(null, array) is the fastest, see // see http://jsperf.com/converting-a-uint8array-to-a-string/2 // but the stack is limited (and we can get huge arrays !). // // result += String.fromCharCode(array[i]); generate too many strings ! // // This code is inspired by http://jsperf.com/arraybuffer-to-string-apply-performance/2 var chunk = 65536; var result = [], len = array.length, type = exports.getTypeOf(array), k = 0, canUseApply = true; try { switch(type) { case "uint8array": String.fromCharCode.apply(null, new Uint8Array(0)); break; case "nodebuffer": String.fromCharCode.apply(null, nodeBuffer(0)); break; } } catch(e) { canUseApply = false; } // no apply : slow and painful algorithm // default browser on android 4.* if (!canUseApply) { var resultStr = ""; for(var i = 0; i < array.length;i++) { resultStr += String.fromCharCode(array[i]); } return resultStr; } while (k < len && chunk > 1) { try { if (type === "array" || type === "nodebuffer") { result.push(String.fromCharCode.apply(null, array.slice(k, Math.min(k + chunk, len)))); } else { result.push(String.fromCharCode.apply(null, array.subarray(k, Math.min(k + chunk, len)))); } k += chunk; } catch (e) { chunk = Math.floor(chunk / 2); } } return result.join(""); }
Transform an array-like object to a string. @param {Array|ArrayBuffer|Uint8Array|Buffer} array the array to transform. @return {String} the result.
arrayLikeToString ( array )
javascript
awslabs/datawig
datawig-js/static/js/xlsx_jszip_0.15.5.js
https://github.com/awslabs/datawig/blob/master/datawig-js/static/js/xlsx_jszip_0.15.5.js
Apache-2.0
function arrayLikeToArrayLike(arrayFrom, arrayTo) { for (var i = 0; i < arrayFrom.length; i++) { arrayTo[i] = arrayFrom[i]; } return arrayTo; }
Copy the data from an array-like to an other array-like. @param {Array|ArrayBuffer|Uint8Array|Buffer} arrayFrom the origin array. @param {Array|ArrayBuffer|Uint8Array|Buffer} arrayTo the destination array which will be mutated. @return {Array|ArrayBuffer|Uint8Array|Buffer} the updated destination array.
arrayLikeToArrayLike ( arrayFrom , arrayTo )
javascript
awslabs/datawig
datawig-js/static/js/xlsx_jszip_0.15.5.js
https://github.com/awslabs/datawig/blob/master/datawig-js/static/js/xlsx_jszip_0.15.5.js
Apache-2.0
exports.transformTo = function(outputType, input) { if (!input) { // undefined, null, etc // an empty string won't harm. input = ""; } if (!outputType) { return input; } exports.checkSupport(outputType); var inputType = exports.getTypeOf(input); var result = transform[inputType][outputType](input); return result; };
Transform an input into any type. The supported output type are : string, array, uint8array, arraybuffer, nodebuffer. If no output type is specified, the unmodified input will be returned. @param {String} outputType the output type. @param {String|Array|ArrayBuffer|Uint8Array|Buffer} input the input to convert. @throws {Error} an Error if the browser doesn't support the requested output type.
exports.transformTo ( outputType , input )
javascript
awslabs/datawig
datawig-js/static/js/xlsx_jszip_0.15.5.js
https://github.com/awslabs/datawig/blob/master/datawig-js/static/js/xlsx_jszip_0.15.5.js
Apache-2.0
exports.getTypeOf = function(input) { if (typeof input === "string") { return "string"; } if (Object.prototype.toString.call(input) === "[object Array]") { return "array"; } if (support.nodebuffer && nodeBuffer.test(input)) { return "nodebuffer"; } if (support.uint8array && input instanceof Uint8Array) { return "uint8array"; } if (support.arraybuffer && input instanceof ArrayBuffer) { return "arraybuffer"; } };
Return the type of the input. The type will be in a format valid for JSZip.utils.transformTo : string, array, uint8array, arraybuffer. @param {Object} input the input to identify. @return {String} the (lowercase) type of the input.
exports.getTypeOf ( input )
javascript
awslabs/datawig
datawig-js/static/js/xlsx_jszip_0.15.5.js
https://github.com/awslabs/datawig/blob/master/datawig-js/static/js/xlsx_jszip_0.15.5.js
Apache-2.0
exports.checkSupport = function(type) { var supported = support[type.toLowerCase()]; if (!supported) { throw new Error(type + " is not supported by this browser"); } };
Throw an exception if the type is not supported. @param {String} type the type to check. @throws {Error} an Error if the browser doesn't support the requested type.
exports.checkSupport ( type )
javascript
awslabs/datawig
datawig-js/static/js/xlsx_jszip_0.15.5.js
https://github.com/awslabs/datawig/blob/master/datawig-js/static/js/xlsx_jszip_0.15.5.js
Apache-2.0
exports.findCompression = function(compressionMethod) { for (var method in compressions) { if (!compressions.hasOwnProperty(method)) { continue; } if (compressions[method].magic === compressionMethod) { return compressions[method]; } } return null; };
Find a compression registered in JSZip. @param {string} compressionMethod the method magic to find. @return {Object|null} the JSZip compression object, null if none found.
exports.findCompression ( compressionMethod )
javascript
awslabs/datawig
datawig-js/static/js/xlsx_jszip_0.15.5.js
https://github.com/awslabs/datawig/blob/master/datawig-js/static/js/xlsx_jszip_0.15.5.js
Apache-2.0
exports.isRegExp = function (object) { return Object.prototype.toString.call(object) === "[object RegExp]"; };
Cross-window, cross-Node-context regular expression detection @param {Object} object Anything @return {Boolean} true if the object is a regular expression, false otherwise
exports.isRegExp ( object )
javascript
awslabs/datawig
datawig-js/static/js/xlsx_jszip_0.15.5.js
https://github.com/awslabs/datawig/blob/master/datawig-js/static/js/xlsx_jszip_0.15.5.js
Apache-2.0
exports.pretty = function(str) { var res = '', code, i; for (i = 0; i < (str || "").length; i++) { code = str.charCodeAt(i); res += '\\x' + (code < 16 ? "0" : "") + code.toString(16).toUpperCase(); } return res; }; /** * Find a compression registered in JSZip. * @param {string} compressionMethod the method magic to find. * @return {Object|null} the JSZip compression object, null if none found. */ exports.findCompression = function(compressionMethod) { for (var method in compressions) { if (!compressions.hasOwnProperty(method)) { continue; } if (compressions[method].magic === compressionMethod) { return compressions[method]; } } return null; }; /** * Cross-window, cross-Node-context regular expression detection * @param {Object} object Anything * @return {Boolean} true if the object is a regular expression, * false otherwise */ exports.isRegExp = function (object) { return Object.prototype.toString.call(object) === "[object RegExp]"; }; },{"./compressions":3,"./nodeBuffer":11,"./support":17}],22:[function(_dereq_,module,exports){
Prettify a string read as binary. @param {string} str the string to prettify. @return {string} a pretty string.
exports.pretty ( str )
javascript
awslabs/datawig
datawig-js/static/js/xlsx_jszip_0.15.5.js
https://github.com/awslabs/datawig/blob/master/datawig-js/static/js/xlsx_jszip_0.15.5.js
Apache-2.0
function ZipEntries(data, loadOptions) { this.files = []; this.loadOptions = loadOptions; if (data) { this.load(data); } }
All the entries in the zip file. @constructor @param {String|ArrayBuffer|Uint8Array} data the binary stream to load. @param {Object} loadOptions Options for loading the stream.
ZipEntries ( data , loadOptions )
javascript
awslabs/datawig
datawig-js/static/js/xlsx_jszip_0.15.5.js
https://github.com/awslabs/datawig/blob/master/datawig-js/static/js/xlsx_jszip_0.15.5.js
Apache-2.0
checkSignature: function(expectedSignature) { var signature = this.reader.readString(4); if (signature !== expectedSignature) { throw new Error("Corrupted zip or bug : unexpected signature " + "(" + utils.pretty(signature) + ", expected " + utils.pretty(expectedSignature) + ")"); } },
Check that the reader is on the speficied signature. @param {string} expectedSignature the expected signature. @throws {Error} if it is an other signature.
checkSignature ( expectedSignature )
javascript
awslabs/datawig
datawig-js/static/js/xlsx_jszip_0.15.5.js
https://github.com/awslabs/datawig/blob/master/datawig-js/static/js/xlsx_jszip_0.15.5.js
Apache-2.0
readBlockEndOfCentral: function() { this.diskNumber = this.reader.readInt(2); this.diskWithCentralDirStart = this.reader.readInt(2); this.centralDirRecordsOnThisDisk = this.reader.readInt(2); this.centralDirRecords = this.reader.readInt(2); this.centralDirSize = this.reader.readInt(4); this.centralDirOffset = this.reader.readInt(4); this.zipCommentLength = this.reader.readInt(2); // warning : the encoding depends of the system locale // On a linux machine with LANG=en_US.utf8, this field is utf8 encoded. // On a windows machine, this field is encoded with the localized windows code page. this.zipComment = this.reader.readString(this.zipCommentLength); // To get consistent behavior with the generation part, we will assume that // this is utf8 encoded. this.zipComment = jszipProto.utf8decode(this.zipComment); },
Read the end of the central directory.
readBlockEndOfCentral ( )
javascript
awslabs/datawig
datawig-js/static/js/xlsx_jszip_0.15.5.js
https://github.com/awslabs/datawig/blob/master/datawig-js/static/js/xlsx_jszip_0.15.5.js
Apache-2.0
readBlockZip64EndOfCentral: function() { this.zip64EndOfCentralSize = this.reader.readInt(8); this.versionMadeBy = this.reader.readString(2); this.versionNeeded = this.reader.readInt(2); this.diskNumber = this.reader.readInt(4); this.diskWithCentralDirStart = this.reader.readInt(4); this.centralDirRecordsOnThisDisk = this.reader.readInt(8); this.centralDirRecords = this.reader.readInt(8); this.centralDirSize = this.reader.readInt(8); this.centralDirOffset = this.reader.readInt(8); this.zip64ExtensibleData = {}; var extraDataSize = this.zip64EndOfCentralSize - 44, index = 0, extraFieldId, extraFieldLength, extraFieldValue; while (index < extraDataSize) { extraFieldId = this.reader.readInt(2); extraFieldLength = this.reader.readInt(4); extraFieldValue = this.reader.readString(extraFieldLength); this.zip64ExtensibleData[extraFieldId] = { id: extraFieldId, length: extraFieldLength, value: extraFieldValue }; } },
Read the end of the Zip 64 central directory. Not merged with the method readEndOfCentral : The end of central can coexist with its Zip64 brother, I don't want to read the wrong number of bytes !
readBlockZip64EndOfCentral ( )
javascript
awslabs/datawig
datawig-js/static/js/xlsx_jszip_0.15.5.js
https://github.com/awslabs/datawig/blob/master/datawig-js/static/js/xlsx_jszip_0.15.5.js
Apache-2.0
readBlockZip64EndOfCentralLocator: function() { this.diskWithZip64CentralDirStart = this.reader.readInt(4); this.relativeOffsetEndOfZip64CentralDir = this.reader.readInt(8); this.disksCount = this.reader.readInt(4); if (this.disksCount > 1) { throw new Error("Multi-volumes zip are not supported"); } },
Read the end of the Zip 64 central directory locator.
readBlockZip64EndOfCentralLocator ( )
javascript
awslabs/datawig
datawig-js/static/js/xlsx_jszip_0.15.5.js
https://github.com/awslabs/datawig/blob/master/datawig-js/static/js/xlsx_jszip_0.15.5.js
Apache-2.0
readLocalFiles: function() { var i, file; for (i = 0; i < this.files.length; i++) { file = this.files[i]; this.reader.setIndex(file.localHeaderOffset); this.checkSignature(sig.LOCAL_FILE_HEADER); file.readLocalPart(this.reader); file.handleUTF8(); } },
Read the local files, based on the offset read in the central part.
readLocalFiles ( )
javascript
awslabs/datawig
datawig-js/static/js/xlsx_jszip_0.15.5.js
https://github.com/awslabs/datawig/blob/master/datawig-js/static/js/xlsx_jszip_0.15.5.js
Apache-2.0
load: function(data) { this.prepareReader(data); this.readEndOfCentral(); this.readCentralDir(); this.readLocalFiles(); }
Read a zip file and create ZipEntries. @param {String|ArrayBuffer|Uint8Array|Buffer} data the binary string representing a zip file.
load ( data )
javascript
awslabs/datawig
datawig-js/static/js/xlsx_jszip_0.15.5.js
https://github.com/awslabs/datawig/blob/master/datawig-js/static/js/xlsx_jszip_0.15.5.js
Apache-2.0
function ZipEntry(options, loadOptions) { this.options = options; this.loadOptions = loadOptions; }
An entry in the zip file. @constructor @param {Object} options Options of the current file. @param {Object} loadOptions Options for loading the stream.
ZipEntry ( options , loadOptions )
javascript
awslabs/datawig
datawig-js/static/js/xlsx_jszip_0.15.5.js
https://github.com/awslabs/datawig/blob/master/datawig-js/static/js/xlsx_jszip_0.15.5.js
Apache-2.0
isEncrypted: function() { // bit 1 is set return (this.bitFlag & 0x0001) === 0x0001; },
say if the file is encrypted. @return {boolean} true if the file is encrypted, false otherwise.
isEncrypted ( )
javascript
awslabs/datawig
datawig-js/static/js/xlsx_jszip_0.15.5.js
https://github.com/awslabs/datawig/blob/master/datawig-js/static/js/xlsx_jszip_0.15.5.js
Apache-2.0
useUTF8: function() { // bit 11 is set return (this.bitFlag & 0x0800) === 0x0800; },
say if the file has utf-8 filename/comment. @return {boolean} true if the filename/comment is in utf-8, false otherwise.
useUTF8 ( )
javascript
awslabs/datawig
datawig-js/static/js/xlsx_jszip_0.15.5.js
https://github.com/awslabs/datawig/blob/master/datawig-js/static/js/xlsx_jszip_0.15.5.js
Apache-2.0
prepareCompressedContent: function(reader, from, length) { return function() { var previousIndex = reader.index; reader.setIndex(from); var compressedFileData = reader.readData(length); reader.setIndex(previousIndex); return compressedFileData; }; },
Prepare the function used to generate the compressed content from this ZipFile. @param {DataReader} reader the reader to use. @param {number} from the offset from where we should read the data. @param {number} length the length of the data to read. @return {Function} the callback to get the compressed content (the type depends of the DataReader class).
prepareCompressedContent ( reader , from , length )
javascript
awslabs/datawig
datawig-js/static/js/xlsx_jszip_0.15.5.js
https://github.com/awslabs/datawig/blob/master/datawig-js/static/js/xlsx_jszip_0.15.5.js
Apache-2.0