_id stringlengths 2 6 | title stringlengths 0 58 | partition stringclasses 3
values | text stringlengths 52 373k | language stringclasses 1
value | meta_information dict |
|---|---|---|---|---|---|
q16600 | train | function (length) {
var data = this.data;
var el = this.el;
var endVec3;
// Switch each time vector so line update triggered and to avoid unnecessary vector clone.
endVec3 = this.lineData.end === this.lineEndVec3
? this.otherLineEndVec3
: this.lineEndVec3;
// Treat Infinity as 1000... | javascript | {
"resource": ""
} | |
q16601 | processPropertyDefinition | train | function processPropertyDefinition (propDefinition, componentName) {
var defaultVal = propDefinition.default;
var isCustomType;
var propType;
var typeName = propDefinition.type;
// Type inference.
if (!propDefinition.type) {
if (defaultVal !== undefined &&
(typeof defaultVal === 'boolean' || ty... | javascript | {
"resource": ""
} |
q16602 | parseProperty | train | function parseProperty (value, propDefinition) {
// Use default value if value is falsy.
if (value === undefined || value === null || value === '') {
value = propDefinition.default;
if (Array.isArray(value)) { value = value.slice(); }
}
// Invoke property type parser.
return propDefinition.parse(value... | javascript | {
"resource": ""
} |
q16603 | stringifyProperty | train | function stringifyProperty (value, propDefinition) {
// This function stringifies but it's used in a context where
// there's always second stringification pass. By returning the original
// value when it's not an object we save one unnecessary call
// to JSON.stringify.
if (typeof value !== 'object') { retur... | javascript | {
"resource": ""
} |
q16604 | mediaElementLoaded | train | function mediaElementLoaded (el) {
if (!el.hasAttribute('autoplay') && el.getAttribute('preload') !== 'auto') {
return;
}
// If media specifies autoplay or preload, wait until media is completely buffered.
return new Promise(function (resolve, reject) {
if (el.readyState === 4) { return resolve(); } /... | javascript | {
"resource": ""
} |
q16605 | fixUpMediaElement | train | function fixUpMediaElement (mediaEl) {
// Cross-origin.
var newMediaEl = setCrossOrigin(mediaEl);
// Plays inline for mobile.
if (newMediaEl.tagName && newMediaEl.tagName.toLowerCase() === 'video') {
newMediaEl.setAttribute('playsinline', '');
newMediaEl.setAttribute('webkit-playsinline', '');
}
i... | javascript | {
"resource": ""
} |
q16606 | extractDomain | train | function extractDomain (url) {
// Find and remove protocol (e.g., http, ftp, etc.) to get domain.
var domain = url.indexOf('://') > -1 ? url.split('/')[2] : url.split('/')[0];
// Find and remove port number.
return domain.substring(0, domain.indexOf(':'));
} | javascript | {
"resource": ""
} |
q16607 | train | function (evt) {
// Raycast again for touch.
if (this.data.rayOrigin === 'mouse' && evt.type === 'touchstart') {
this.onMouseMove(evt);
this.el.components.raycaster.checkIntersections();
evt.preventDefault();
}
this.twoWayEmit(EVENTS.MOUSEDOWN);
this.cursorDownEl = this.intersecte... | javascript | {
"resource": ""
} | |
q16608 | train | function (evt) {
var currentIntersection;
var cursorEl = this.el;
var index;
var intersectedEl;
var intersection;
// Select closest object, excluding the cursor.
index = evt.detail.els[0] === cursorEl ? 1 : 0;
intersection = evt.detail.intersections[index];
intersectedEl = evt.detai... | javascript | {
"resource": ""
} | |
q16609 | train | function (data) {
this.attributes = this.initVariables(data, 'attribute');
this.uniforms = this.initVariables(data, 'uniform');
this.material = new (this.raw ? THREE.RawShaderMaterial : THREE.ShaderMaterial)({
// attributes: this.attributes,
uniforms: this.uniforms,
vertexShader: this.vert... | javascript | {
"resource": ""
} | |
q16610 | extend | train | function extend (base, extension) {
if (isUndefined(base)) {
return copy(extension);
}
if (isUndefined(extension)) {
return copy(base);
}
if (isPureObject(base) && isPureObject(extension)) {
return utils.extendDeep(bas... | javascript | {
"resource": ""
} |
q16611 | addComponentMapping | train | function addComponentMapping (componentName, mappings) {
var schema = components[componentName].schema;
Object.keys(schema).map(function (prop) {
// Hyphenate where there is camelCase.
var attrName = prop.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase();
// If there is a mapping collision, prefix with ... | javascript | {
"resource": ""
} |
q16612 | definePrimitive | train | function definePrimitive (tagName, defaultComponents, mappings) {
// If no initial mappings provided, start from empty map.
mappings = mappings || {};
// From the default components, add mapping automagically.
Object.keys(defaultComponents).map(function buildMappings (componentName) {
addComponentMapping(c... | javascript | {
"resource": ""
} |
q16613 | registerPropertyType | train | function registerPropertyType (type, defaultValue, parse, stringify) {
if ('type' in propertyTypes) {
error('Property type ' + type + ' is already registered.');
return;
}
propertyTypes[type] = {
default: defaultValue,
parse: parse || defaultParse,
stringify: stringify || defaultStringify
}... | javascript | {
"resource": ""
} |
q16614 | assetParse | train | function assetParse (value) {
var el;
var parsedUrl;
// If an element was provided (e.g. canvas or video), just return it.
if (typeof value !== 'string') { return value; }
// Wrapped `url()` in case of data URI.
parsedUrl = value.match(urlRegex);
if (parsedUrl) { return parsedUrl[1]; }
// ID.
if (v... | javascript | {
"resource": ""
} |
q16615 | isValidDefaultValue | train | function isValidDefaultValue (type, defaultVal) {
if (type === 'audio' && typeof defaultVal !== 'string') { return false; }
if (type === 'array' && !Array.isArray(defaultVal)) { return false; }
if (type === 'asset' && typeof defaultVal !== 'string') { return false; }
if (type === 'boolean' && typeof defaultVal ... | javascript | {
"resource": ""
} |
q16616 | isValidDefaultCoordinate | train | function isValidDefaultCoordinate (possibleCoordinates, dimensions) {
if (possibleCoordinates === null) { return true; }
if (typeof possibleCoordinates !== 'object') { return false; }
if (Object.keys(possibleCoordinates).length !== dimensions) {
return false;
} else {
var x = possibleCoordinates.x;
... | javascript | {
"resource": ""
} |
q16617 | train | function () {
var controllers = this.controllers;
var gamepad;
var gamepads;
var i;
var prevCount;
gamepads = navigator.getGamepads && navigator.getGamepads();
if (!gamepads) { return; }
prevCount = controllers.length;
controllers.length = 0;
for (i = 0; i < gamepads.length; ++... | javascript | {
"resource": ""
} | |
q16618 | validateSrc | train | function validateSrc (src, isImageCb, isVideoCb) {
checkIsImage(src, function isAnImageUrl (isImage) {
if (isImage) {
isImageCb(src);
return;
}
isVideoCb(src);
});
} | javascript | {
"resource": ""
} |
q16619 | validateCubemapSrc | train | function validateCubemapSrc (src, cb) {
var aCubemap;
var cubemapSrcRegex = '';
var i;
var urls;
var validatedUrls = [];
for (i = 0; i < 5; i++) {
cubemapSrcRegex += '(url\\((?:[^\\)]+)\\),\\s*)';
}
cubemapSrcRegex += '(url\\((?:[^\\)]+)\\)\\s*)';
urls = src.match(new RegExp(cubemapSrcRegex));
... | javascript | {
"resource": ""
} |
q16620 | checkIsImage | train | function checkIsImage (src, onResult) {
var request;
if (src.tagName) {
onResult(src.tagName === 'IMG');
return;
}
request = new XMLHttpRequest();
// Try to send HEAD request to check if image first.
request.open('HEAD', src);
request.addEventListener('load', function (event) {
var contentTy... | javascript | {
"resource": ""
} |
q16621 | validateAndGetQuerySelector | train | function validateAndGetQuerySelector (selector) {
try {
var el = document.querySelector(selector);
if (!el) {
warn('No element was found matching the selector: "%s"', selector);
}
return el;
} catch (e) { // Capture exception if it's not a valid selector.
warn('"%s" is not a valid selecto... | javascript | {
"resource": ""
} |
q16622 | train | function (src, data, cb) {
var self = this;
// Canvas.
if (src.tagName === 'CANVAS') {
this.loadCanvas(src, data, cb);
return;
}
// Video element.
if (src.tagName === 'VIDEO') {
if (!src.src && !src.srcObject && !src.childElementCount) {
warn('Video element was define... | javascript | {
"resource": ""
} | |
q16623 | train | function (data) {
if (data.src.tagName) {
// Since `data.src` can be an element, parse out the string if necessary for the hash.
data = utils.extendDeep({}, data);
data.src = data.src.src;
}
return JSON.stringify(data);
} | javascript | {
"resource": ""
} | |
q16624 | train | function (material) {
delete this.materials[material.uuid];
// If any textures on this material are no longer in use, dispose of them.
var textureCounts = this.textureCounts;
Object.keys(material)
.filter(function (propName) {
return material[propName] && material[propName].isTexture;
... | javascript | {
"resource": ""
} | |
q16625 | train | function (material) {
var materials = this.materials;
Object.keys(materials).forEach(function (uuid) {
materials[uuid].needsUpdate = true;
});
} | javascript | {
"resource": ""
} | |
q16626 | loadImageTexture | train | function loadImageTexture (src, data) {
return new Promise(doLoadImageTexture);
function doLoadImageTexture (resolve, reject) {
var isEl = typeof src !== 'string';
function resolveTexture (texture) {
setTextureProperties(texture, data);
texture.needsUpdate = true;
resolve(texture);
}... | javascript | {
"resource": ""
} |
q16627 | setTextureProperties | train | function setTextureProperties (texture, data) {
var offset = data.offset || {x: 0, y: 0};
var repeat = data.repeat || {x: 1, y: 1};
var npot = data.npot || false;
// To support NPOT textures, wrap must be ClampToEdge (not Repeat),
// and filters must not use mipmaps (i.e. Nearest or Linear).
if (npot) {
... | javascript | {
"resource": ""
} |
q16628 | createVideoEl | train | function createVideoEl (src, width, height) {
var videoEl = document.createElement('video');
videoEl.width = width;
videoEl.height = height;
// Support inline videos for iOS webviews.
videoEl.setAttribute('playsinline', '');
videoEl.setAttribute('webkit-playsinline', '');
videoEl.autoplay = true;
videoE... | javascript | {
"resource": ""
} |
q16629 | fixVideoAttributes | train | function fixVideoAttributes (videoEl) {
videoEl.autoplay = videoEl.hasAttribute('autoplay') && videoEl.getAttribute('autoplay') !== 'false';
videoEl.controls = videoEl.hasAttribute('controls') && videoEl.getAttribute('controls') !== 'false';
if (videoEl.getAttribute('loop') === 'false') {
videoEl.removeAttrib... | javascript | {
"resource": ""
} |
q16630 | train | function (oldEvt) {
var el = this.el;
if (oldEvt) { el.removeEventListener(oldEvt, this.playSoundBound); }
el.addEventListener(this.data.on, this.playSoundBound);
} | javascript | {
"resource": ""
} | |
q16631 | train | function () {
var el = this.el;
var i;
var sceneEl = el.sceneEl;
var self = this;
var sound;
if (this.pool.children.length > 0) {
this.stopSound();
el.removeObject3D('sound');
}
// Only want one AudioListener. Cache it on the scene.
var listener = this.listener = sceneE... | javascript | {
"resource": ""
} | |
q16632 | train | function () {
var i;
var sound;
this.isPlaying = false;
for (i = 0; i < this.pool.children.length; i++) {
sound = this.pool.children[i];
if (!sound.source || !sound.source.buffer || !sound.isPlaying || sound.isPaused) {
continue;
}
sound.isPaused = true;
sound.paus... | javascript | {
"resource": ""
} | |
q16633 | train | function (processSound) {
var found;
var i;
var sound;
if (!this.loaded) {
warn('Sound not loaded yet. It will be played once it finished loading');
this.mustPlay = true;
return;
}
found = false;
this.isPlaying = true;
for (i = 0; i < this.pool.children.length; i++) {... | javascript | {
"resource": ""
} | |
q16634 | train | function () {
var i;
var sound;
this.isPlaying = false;
for (i = 0; i < this.pool.children.length; i++) {
sound = this.pool.children[i];
if (!sound.source || !sound.source.buffer) { return; }
sound.stop();
}
} | javascript | {
"resource": ""
} | |
q16635 | train | function (evt) {
var button = this.mapping.buttons[evt.detail.id];
var buttonMeshes = this.buttonMeshes;
var analogValue;
if (!button) { return; }
if (button === 'trigger') {
analogValue = evt.detail.state.value;
// Update trigger rotation depending on button value.
if (buttonMes... | javascript | {
"resource": ""
} | |
q16636 | wrapANodeMethods | train | function wrapANodeMethods (obj) {
var newObj = {};
var ANodeMethods = [
'attachedCallback',
'attributeChangedCallback',
'createdCallback',
'detachedCallback'
];
wrapMethods(newObj, ANodeMethods, obj, ANode.prototype);
copyProperties(obj, newObj);
return newObj;
} | javascript | {
"resource": ""
} |
q16637 | wrapAEntityMethods | train | function wrapAEntityMethods (obj) {
var newObj = {};
var ANodeMethods = [
'attachedCallback',
'attributeChangedCallback',
'createdCallback',
'detachedCallback'
];
var AEntityMethods = [
'attachedCallback',
'attributeChangedCallback',
'createdCallback',
'detachedCallback'
];
... | javascript | {
"resource": ""
} |
q16638 | wrapMethods | train | function wrapMethods (targetObj, methodList, derivedObj, baseObj) {
methodList.forEach(function (methodName) {
wrapMethod(targetObj, methodName, derivedObj, baseObj);
});
} | javascript | {
"resource": ""
} |
q16639 | wrapMethod | train | function wrapMethod (obj, methodName, derivedObj, baseObj) {
var derivedMethod = derivedObj[methodName];
var baseMethod = baseObj[methodName];
// Derived prototype does not define method, no need to wrap.
if (!derivedMethod || !baseMethod) { return; }
// Derived prototype doesn't override the one in the bas... | javascript | {
"resource": ""
} |
q16640 | copyProperties | train | function copyProperties (source, destination) {
var props = Object.getOwnPropertyNames(source);
props.forEach(function (prop) {
var desc;
if (!destination[prop]) {
desc = Object.getOwnPropertyDescriptor(source, prop);
destination[prop] = {value: source[prop], writable: desc.writable};
}
})... | javascript | {
"resource": ""
} |
q16641 | train | function () {
var cameraEls;
var i;
var sceneEl = this.sceneEl;
var self = this;
// Camera already defined or the one defined it is an spectator one.
if (sceneEl.camera && !sceneEl.camera.el.getAttribute('camera').spectator) {
sceneEl.emit('cameraready', {cameraEl: sceneEl.camera.el});
... | javascript | {
"resource": ""
} | |
q16642 | train | function (newCameraEl) {
var newCamera;
var previousCamera = this.spectatorCameraEl;
var sceneEl = this.sceneEl;
var spectatorCameraEl;
// Same camera.
newCamera = newCameraEl.getObject3D('camera');
if (!newCamera || newCameraEl === this.spectatorCameraEl) { return; }
// Disable curren... | javascript | {
"resource": ""
} | |
q16643 | removeDefaultCamera | train | function removeDefaultCamera (sceneEl) {
var defaultCamera;
var camera = sceneEl.camera;
if (!camera) { return; }
// Remove default camera if present.
defaultCamera = sceneEl.querySelector('[' + DEFAULT_CAMERA_ATTR + ']');
if (!defaultCamera) { return; }
sceneEl.removeChild(defaultCamera);
} | javascript | {
"resource": ""
} |
q16644 | train | function () {
this.mouseDown = false;
this.pitchObject = new THREE.Object3D();
this.yawObject = new THREE.Object3D();
this.yawObject.position.y = 10;
this.yawObject.add(this.pitchObject);
} | javascript | {
"resource": ""
} | |
q16645 | train | function () {
var sceneEl = this.el.sceneEl;
var canvasEl = sceneEl.canvas;
// Wait for canvas to load.
if (!canvasEl) {
sceneEl.addEventListener('render-target-loaded', bind(this.addEventListeners, this));
return;
}
// Mouse events.
canvasEl.addEventListener('mousedown', this.... | javascript | {
"resource": ""
} | |
q16646 | train | function () {
var sceneEl = this.el.sceneEl;
var canvasEl = sceneEl && sceneEl.canvas;
if (!canvasEl) { return; }
// Mouse events.
canvasEl.removeEventListener('mousedown', this.onMouseDown);
window.removeEventListener('mousemove', this.onMouseMove);
window.removeEventListener('mouseup', t... | javascript | {
"resource": ""
} | |
q16647 | train | function (event) {
var direction;
var movementX;
var movementY;
var pitchObject = this.pitchObject;
var previousMouseEvent = this.previousMouseEvent;
var yawObject = this.yawObject;
// Not dragging or not enabled.
if (!this.data.enabled || (!this.mouseDown && !this.pointerLocked)) { ret... | javascript | {
"resource": ""
} | |
q16648 | train | function (evt) {
if (!this.data.enabled) { return; }
// Handle only primary button.
if (evt.button !== 0) { return; }
var sceneEl = this.el.sceneEl;
var canvasEl = sceneEl && sceneEl.canvas;
this.mouseDown = true;
this.previousMouseEvent = evt;
this.showGrabbingCursor();
if (this.... | javascript | {
"resource": ""
} | |
q16649 | train | function (evt) {
if (evt.touches.length !== 1 || !this.data.touchEnabled) { return; }
this.touchStart = {
x: evt.touches[0].pageX,
y: evt.touches[0].pageY
};
this.touchStarted = true;
} | javascript | {
"resource": ""
} | |
q16650 | train | function (evt) {
var direction;
var canvas = this.el.sceneEl.canvas;
var deltaY;
var yawObject = this.yawObject;
if (!this.touchStarted || !this.data.touchEnabled) { return; }
deltaY = 2 * Math.PI * (evt.touches[0].pageX - this.touchStart.x) / canvas.clientWidth;
direction = this.data.rev... | javascript | {
"resource": ""
} | |
q16651 | train | function () {
if (!this.el.sceneEl.checkHeadsetConnected()) { return; }
this.saveCameraPose();
this.el.object3D.position.set(0, 0, 0);
this.el.object3D.updateMatrix();
} | javascript | {
"resource": ""
} | |
q16652 | train | function () {
var el = this.el;
this.savedPose.position.copy(el.object3D.position);
this.savedPose.rotation.copy(el.object3D.rotation);
this.hasSavedPose = true;
} | javascript | {
"resource": ""
} | |
q16653 | train | function () {
var el = this.el;
var savedPose = this.savedPose;
if (!this.hasSavedPose) { return; }
// Reset camera orientation.
el.object3D.position.copy(savedPose.position);
el.object3D.rotation.copy(savedPose.rotation);
this.hasSavedPose = false;
} | javascript | {
"resource": ""
} | |
q16654 | createEnterVRButton | train | function createEnterVRButton (onClick) {
var vrButton;
var wrapper;
// Create elements.
wrapper = document.createElement('div');
wrapper.classList.add(ENTER_VR_CLASS);
wrapper.setAttribute(constants.AFRAME_INJECTED, '');
vrButton = document.createElement('button');
vrButton.className = ENTER_VR_BTN_CLA... | javascript | {
"resource": ""
} |
q16655 | createOrientationModal | train | function createOrientationModal (onClick) {
var modal = document.createElement('div');
modal.className = ORIENTATION_MODAL_CLASS;
modal.classList.add(HIDDEN_CLASS);
modal.setAttribute(constants.AFRAME_INJECTED, '');
var exit = document.createElement('button');
exit.setAttribute(constants.AFRAME_INJECTED, '... | javascript | {
"resource": ""
} |
q16656 | train | function () {
this.geometry.dispose();
this.geometry = null;
this.el.removeObject3D(this.attrName);
this.material.dispose();
this.material = null;
this.texture.dispose();
this.texture = null;
if (this.shaderObject) {
delete this.shaderObject;
}
} | javascript | {
"resource": ""
} | |
q16657 | train | function () {
var data = this.data;
var hasChangedShader;
var material = this.material;
var NewShader;
var shaderData = this.shaderData;
var shaderName;
// Infer shader if using a stock font (or from `-msdf` filename convention).
shaderName = data.shader;
if (MSDF_FONTS.indexOf(data... | javascript | {
"resource": ""
} | |
q16658 | train | function () {
var data = this.data;
var el = this.el;
var fontSrc;
var geometry = this.geometry;
var self = this;
if (!data.font) { warn('No font specified. Using the default font.'); }
// Make invisible during font swap.
this.mesh.visible = false;
// Look up font URL to use, and ... | javascript | {
"resource": ""
} | |
q16659 | train | function () {
var anchor;
var baseline;
var el = this.el;
var data = this.data;
var geometry = this.geometry;
var geometryComponent;
var height;
var layout;
var mesh = this.mesh;
var textRenderWidth;
var textScale;
var width;
var x;
var y;
if (!geometry.layou... | javascript | {
"resource": ""
} | |
q16660 | computeFontWidthFactor | train | function computeFontWidthFactor (font) {
var sum = 0;
var digitsum = 0;
var digits = 0;
font.chars.map(function (ch) {
sum += ch.xadvance;
if (ch.id >= 48 && ch.id <= 57) {
digits++;
digitsum += ch.xadvance;
}
});
return digits ? digitsum / digits : sum / font.chars.length;
} | javascript | {
"resource": ""
} |
q16661 | PromiseCache | train | function PromiseCache () {
var cache = this.cache = {};
this.get = function (key, promiseGenerator) {
if (key in cache) {
return cache[key];
}
cache[key] = promiseGenerator();
return cache[key];
};
} | javascript | {
"resource": ""
} |
q16662 | findMatchingControllerWebVR | train | function findMatchingControllerWebVR (controllers, filterIdExact, filterIdPrefix, filterHand,
filterControllerIndex) {
var controller;
var i;
var matchingControllerOccurence = 0;
var targetControllerMatch = filterControllerIndex || 0;
for (i = 0; i < controllers.length; i++) ... | javascript | {
"resource": ""
} |
q16663 | train | function (controllerPosition) {
// Use controllerPosition and deltaControllerPosition to avoid creating variables.
var controller = this.controller;
var controllerEuler = this.controllerEuler;
var controllerQuaternion = this.controllerQuaternion;
var deltaControllerPosition = this.deltaControllerPos... | javascript | {
"resource": ""
} | |
q16664 | train | function () {
var buttonState;
var controller = this.controller;
var id;
if (!controller) { return; }
// Check every button.
for (id = 0; id < controller.buttons.length; ++id) {
// Initialize button state.
if (!this.buttonStates[id]) {
this.buttonStates[id] = {pressed: fals... | javascript | {
"resource": ""
} | |
q16665 | train | function (id, buttonState) {
var changed;
changed = this.handlePress(id, buttonState) |
this.handleTouch(id, buttonState) |
this.handleValue(id, buttonState);
if (!changed) { return false; }
this.el.emit(EVENTS.BUTTONCHANGED, this.buttonEventDetails[id], false);
return tr... | javascript | {
"resource": ""
} | |
q16666 | train | function (projection) {
var el = this.el;
var size;
var camera;
var cubeCamera;
// Configure camera.
if (projection === 'perspective') {
// Quad is only used in equirectangular mode. Hide it in this case.
this.quad.visible = false;
// Use scene camera.
camera = (this.data... | javascript | {
"resource": ""
} | |
q16667 | train | function (projection) {
var isVREnabled = this.el.renderer.vr.enabled;
var renderer = this.el.renderer;
var params;
// Disable VR.
renderer.vr.enabled = false;
params = this.setCapture(projection);
this.renderCapture(params.camera, params.size, params.projection);
// Trigger file downloa... | javascript | {
"resource": ""
} | |
q16668 | train | function () {
this.canvas.toBlob(function (blob) {
var fileName = 'screenshot-' + document.title.toLowerCase() + '-' + Date.now() + '.png';
var linkEl = document.createElement('a');
var url = URL.createObjectURL(blob);
linkEl.href = url;
linkEl.setAttribute('download', fileName);
... | javascript | {
"resource": ""
} | |
q16669 | styleParse | train | function styleParse (str, obj) {
var chunks;
var i;
var item;
var pos;
var key;
var val;
obj = obj || {};
chunks = getKeyValueChunks(str);
for (i = 0; i < chunks.length; i++) {
item = chunks[i];
if (!item) { continue; }
// Split with `.indexOf` rather than `.split` because the value may ... | javascript | {
"resource": ""
} |
q16670 | styleStringify | train | function styleStringify (obj) {
var key;
var keyCount = 0;
var i = 0;
var str = '';
for (key in obj) { keyCount++; }
for (key in obj) {
str += (key + ': ' + obj[key]);
if (i < keyCount - 1) { str += '; '; }
i++;
}
return str;
} | javascript | {
"resource": ""
} |
q16671 | deindent | train | function deindent(html){
var lines = html.split('\n')
if(lines[0].substring(0, 2) === " "){
for (var i = 0; i < lines.length; i++) {
if (lines[i].substring(0,2) === " ") {
lines[i] = lines[i].slice(2)
}
};
}
return lines.join('\n')
} | javascript | {
"resource": ""
} |
q16672 | init | train | function init() {
// In development, we need to open a socket to listen for changes to data
if (process.env.REACT_STATIC_ENV === 'development') {
const io = require('socket.io-client')
const run = async () => {
try {
const {
data: { port },
} = await axios.get('/__react-stati... | javascript | {
"resource": ""
} |
q16673 | pad | train | function pad(str) {
if (str.length < max) {
return str + ' '.repeat(max - str.length);
}
return str;
} | javascript | {
"resource": ""
} |
q16674 | print | train | function print(type, msg, obj, colors) {
if (typeof type === 'number') {
type = calculateLevel(type);
}
const finalMessage = fillInMsgTemplate(msg, obj, colors);
const subsystems = [
{
in: green('<--'),
out: yellow('-->'),
fs: black('-=-'),
default: blue('---'),
},
{
... | javascript | {
"resource": ""
} |
q16675 | animate | train | function animate(from, to, {duration, easingFunction, horizontal}) {
for (const element of [from, to]) {
element.style.pointerEvents = 'none';
}
if (horizontal) {
const width = from.offsetWidth;
from.style.transform = `translate3d(${width}px, 0, 0)`;
to.style.transform = `translate3d(-${width}px,... | javascript | {
"resource": ""
} |
q16676 | resetElementOnTransitionEnd | train | function resetElementOnTransitionEnd(event) {
event.target.style.transition = '';
event.target.style.pointerEvents = '';
event.target.removeEventListener('transitionend', resetElementOnTransitionEnd);
} | javascript | {
"resource": ""
} |
q16677 | onDroppableReturnedDefaultAnnouncement | train | function onDroppableReturnedDefaultAnnouncement({dragEvent, dropzone}) {
const sourceText = dragEvent.source.textContent.trim() || dragEvent.source.id || 'draggable element';
const dropzoneText = dropzone.textContent.trim() || dropzone.id || 'droppable element';
return `Returned ${sourceText} from ${dropzoneText... | javascript | {
"resource": ""
} |
q16678 | onSortableSortedDefaultAnnouncement | train | function onSortableSortedDefaultAnnouncement({dragEvent}) {
const sourceText = dragEvent.source.textContent.trim() || dragEvent.source.id || 'sortable element';
if (dragEvent.over) {
const overText = dragEvent.over.textContent.trim() || dragEvent.over.id || 'sortable element';
const isFollowing = dragEvent... | javascript | {
"resource": ""
} |
q16679 | hasOverflow | train | function hasOverflow(element) {
const overflowRegex = /(auto|scroll)/;
const computedStyles = getComputedStyle(element, null);
const overflow =
computedStyles.getPropertyValue('overflow') +
computedStyles.getPropertyValue('overflow-y') +
computedStyles.getPropertyValue('overflow-x');
return overfl... | javascript | {
"resource": ""
} |
q16680 | closestScrollableElement | train | function closestScrollableElement(element) {
if (!element) {
return getDocumentScrollingElement();
}
const position = getComputedStyle(element).getPropertyValue('position');
const excludeStaticParents = position === 'absolute';
const scrollableElement = closest(element, (parent) => {
if (excludeStat... | javascript | {
"resource": ""
} |
q16681 | decorateElement | train | function decorateElement(element) {
const hasMissingTabIndex = Boolean(!element.getAttribute('tabindex') && element.tabIndex === -1);
if (hasMissingTabIndex) {
elementsWithMissingTabIndex.push(element);
element.tabIndex = 0;
}
} | javascript | {
"resource": ""
} |
q16682 | stripElement | train | function stripElement(element) {
const tabIndexElementPosition = elementsWithMissingTabIndex.indexOf(element);
if (tabIndexElementPosition !== -1) {
element.tabIndex = -1;
elementsWithMissingTabIndex.splice(tabIndexElementPosition, 1);
}
} | javascript | {
"resource": ""
} |
q16683 | onSwappableSwappedDefaultAnnouncement | train | function onSwappableSwappedDefaultAnnouncement({dragEvent, swappedElement}) {
const sourceText = dragEvent.source.textContent.trim() || dragEvent.source.id || 'swappable element';
const overText = swappedElement.textContent.trim() || swappedElement.id || 'swappable element';
return `Swapped ${sourceText} with ${... | javascript | {
"resource": ""
} |
q16684 | computeMirrorDimensions | train | function computeMirrorDimensions({source, ...args}) {
return withPromise((resolve) => {
const sourceRect = source.getBoundingClientRect();
resolve({source, sourceRect, ...args});
});
} | javascript | {
"resource": ""
} |
q16685 | calculateMirrorOffset | train | function calculateMirrorOffset({sensorEvent, sourceRect, options, ...args}) {
return withPromise((resolve) => {
const top = options.cursorOffsetY === null ? sensorEvent.clientY - sourceRect.top : options.cursorOffsetY;
const left = options.cursorOffsetX === null ? sensorEvent.clientX - sourceRect.left : optio... | javascript | {
"resource": ""
} |
q16686 | resetMirror | train | function resetMirror({mirror, source, options, ...args}) {
return withPromise((resolve) => {
let offsetHeight;
let offsetWidth;
if (options.constrainDimensions) {
const computedSourceStyles = getComputedStyle(source);
offsetHeight = computedSourceStyles.getPropertyValue('height');
offse... | javascript | {
"resource": ""
} |
q16687 | addMirrorClasses | train | function addMirrorClasses({mirror, mirrorClass, ...args}) {
return withPromise((resolve) => {
mirror.classList.add(mirrorClass);
resolve({mirror, mirrorClass, ...args});
});
} | javascript | {
"resource": ""
} |
q16688 | removeMirrorID | train | function removeMirrorID({mirror, ...args}) {
return withPromise((resolve) => {
mirror.removeAttribute('id');
delete mirror.id;
resolve({mirror, ...args});
});
} | javascript | {
"resource": ""
} |
q16689 | positionMirror | train | function positionMirror({withFrame = false, initial = false} = {}) {
return ({mirror, sensorEvent, mirrorOffset, initialY, initialX, scrollOffset, options, ...args}) => {
return withPromise(
(resolve) => {
const result = {
mirror,
sensorEvent,
mirrorOffset,
op... | javascript | {
"resource": ""
} |
q16690 | withPromise | train | function withPromise(callback, {raf = false} = {}) {
return new Promise((resolve, reject) => {
if (raf) {
requestAnimationFrame(() => {
callback(resolve, reject);
});
} else {
callback(resolve, reject);
}
});
} | javascript | {
"resource": ""
} |
q16691 | announce | train | function announce(message, {expire}) {
const element = document.createElement('div');
element.textContent = message;
liveRegion.appendChild(element);
return setTimeout(() => {
liveRegion.removeChild(element);
}, expire);
} | javascript | {
"resource": ""
} |
q16692 | createRegion | train | function createRegion() {
const element = document.createElement('div');
element.setAttribute('id', 'draggable-live-region');
element.setAttribute(ARIA_RELEVANT, 'additions');
element.setAttribute(ARIA_ATOMIC, 'true');
element.setAttribute(ARIA_LIVE, 'assertive');
element.setAttribute(ROLE, 'log');
elem... | javascript | {
"resource": ""
} |
q16693 | train | function () {
var result = new $.Deferred();
var path = this.path;
var createIfMissing = this.createIfMissing;
var recreateIfInvalid = this.recreateIfInvalid;
var self = this;
if (path) {
var prefFile = FileSystem.getFileForPath(pa... | javascript | {
"resource": ""
} | |
q16694 | train | function (newData) {
var result = new $.Deferred();
var path = this.path;
var prefFile = FileSystem.getFileForPath(path);
if (path) {
try {
var text = JSON.stringify(newData, null, 4);
// maintain the original line... | javascript | {
"resource": ""
} | |
q16695 | Scope | train | function Scope(storage) {
this.storage = storage;
storage.on("changed", this.load.bind(this));
this.data = {};
this._dirty = false;
this._layers = [];
this._layerMap = {};
this._exclusions = [];
} | javascript | {
"resource": ""
} |
q16696 | train | function () {
var result = new $.Deferred();
this.storage.load()
.then(function (data) {
var oldKeys = this.getKeys();
this.data = data;
result.resolve();
this.trigger(PREFERENCE_CHANGE, {
... | javascript | {
"resource": ""
} | |
q16697 | train | function () {
var self = this;
if (this._dirty) {
self._dirty = false;
return this.storage.save(this.data);
} else {
return (new $.Deferred()).resolve().promise();
}
} | javascript | {
"resource": ""
} | |
q16698 | train | function (id, value, context, location) {
if (!location) {
location = this.getPreferenceLocation(id, context);
}
if (location && location.layer) {
var layer = this._layerMap[location.layer];
if (layer) {
if (this.dat... | javascript | {
"resource": ""
} | |
q16699 | train | function (id, context) {
var layerCounter,
layers = this._layers,
layer,
data = this.data,
result;
context = context || {};
for (layerCounter = 0; layerCounter < layers.length; layerCounter++) {
layer =... | javascript | {
"resource": ""
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.