_id stringlengths 2 6 | title stringlengths 0 58 | partition stringclasses 3
values | text stringlengths 52 373k | language stringclasses 1
value | meta_information dict |
|---|---|---|---|---|---|
q16400 | createProducer | train | function createProducer(tapVersion) {
var producers = {
'12': new TAP12Producer(),
'13': new TAP13Producer()
};
var producer = producers[tapVersion];
if (!producer) {
throw new Error(
'invalid or unsupported TAP version: ' + JSON.stringify(tapVersion)
);
}
return producer;
} | javascript | {
"resource": ""
} |
q16401 | NyanCat | train | function NyanCat(runner, options) {
Base.call(this, runner, options);
var self = this;
var width = (Base.window.width * 0.75) | 0;
var nyanCatWidth = (this.nyanCatWidth = 11);
this.colorIndex = 0;
this.numberOfLines = 4;
this.rainbowColors = self.generateColors();
this.scoreboardWidth = 5;
this.tick... | javascript | {
"resource": ""
} |
q16402 | createInvalidReporterError | train | function createInvalidReporterError(message, reporter) {
var err = new TypeError(message);
err.code = 'ERR_MOCHA_INVALID_REPORTER';
err.reporter = reporter;
return err;
} | javascript | {
"resource": ""
} |
q16403 | createInvalidInterfaceError | train | function createInvalidInterfaceError(message, ui) {
var err = new Error(message);
err.code = 'ERR_MOCHA_INVALID_INTERFACE';
err.interface = ui;
return err;
} | javascript | {
"resource": ""
} |
q16404 | createInvalidArgumentTypeError | train | function createInvalidArgumentTypeError(message, argument, expected) {
var err = new TypeError(message);
err.code = 'ERR_MOCHA_INVALID_ARG_TYPE';
err.argument = argument;
err.expected = expected;
err.actual = typeof argument;
return err;
} | javascript | {
"resource": ""
} |
q16405 | createInvalidArgumentValueError | train | function createInvalidArgumentValueError(message, argument, value, reason) {
var err = new TypeError(message);
err.code = 'ERR_MOCHA_INVALID_ARG_VALUE';
err.argument = argument;
err.value = value;
err.reason = typeof reason !== 'undefined' ? reason : 'is invalid';
return err;
} | javascript | {
"resource": ""
} |
q16406 | createInvalidExceptionError | train | function createInvalidExceptionError(message, value) {
var err = new Error(message);
err.code = 'ERR_MOCHA_INVALID_EXCEPTION';
err.valueType = typeof value;
err.value = value;
return err;
} | javascript | {
"resource": ""
} |
q16407 | highlight | train | function highlight(js) {
return js
.replace(/</g, '<')
.replace(/>/g, '>')
.replace(/\/\/(.*)/gm, '<span class="comment">//$1</span>')
.replace(/('.*?')/gm, '<span class="string">$1</span>')
.replace(/(\d+\.\d+)/gm, '<span class="number">$1</span>')
.replace(/(\d+)/gm, '<span class="numb... | javascript | {
"resource": ""
} |
q16408 | jsonStringify | train | function jsonStringify(object, spaces, depth) {
if (typeof spaces === 'undefined') {
// primitive types
return _stringify(object);
}
depth = depth || 1;
var space = spaces * depth;
var str = Array.isArray(object) ? '[' : '{';
var end = Array.isArray(object) ? ']' : '}';
var length =
typeof ob... | javascript | {
"resource": ""
} |
q16409 | hasMatchingExtname | train | function hasMatchingExtname(pathname, exts) {
var suffix = path.extname(pathname).slice(1);
return exts.some(function(element) {
return suffix === element;
});
} | javascript | {
"resource": ""
} |
q16410 | emitWarning | train | function emitWarning(msg, type) {
if (process.emitWarning) {
process.emitWarning(msg, type);
} else {
process.nextTick(function() {
console.warn(type + ': ' + msg);
});
}
} | javascript | {
"resource": ""
} |
q16411 | Min | train | function Min(runner, options) {
Base.call(this, runner, options);
runner.on(EVENT_RUN_BEGIN, function() {
// clear screen
process.stdout.write('\u001b[2J');
// set cursor position
process.stdout.write('\u001b[1;3H');
});
runner.once(EVENT_RUN_END, this.epilogue.bind(this));
} | javascript | {
"resource": ""
} |
q16412 | Spec | train | function Spec(runner, options) {
Base.call(this, runner, options);
var self = this;
var indents = 0;
var n = 0;
function indent() {
return Array(indents).join(' ');
}
runner.on(EVENT_RUN_BEGIN, function() {
console.log();
});
runner.on(EVENT_SUITE_BEGIN, function(suite) {
++indents;
... | javascript | {
"resource": ""
} |
q16413 | Markdown | train | function Markdown(runner, options) {
Base.call(this, runner, options);
var level = 0;
var buf = '';
function title(str) {
return Array(level).join('#') + ' ' + str;
}
function mapTOC(suite, obj) {
var ret = obj;
var key = SUITE_PREFIX + suite.title;
obj = obj[key] = obj[key] || {suite: s... | javascript | {
"resource": ""
} |
q16414 | Mocha | train | function Mocha(options) {
options = utils.assign({}, mocharc, options || {});
this.files = [];
this.options = options;
// root suite
this.suite = new exports.Suite('', new exports.Context(), true);
if ('useColors' in options) {
utils.deprecate(
'useColors is DEPRECATED and will be removed from a ... | javascript | {
"resource": ""
} |
q16415 | JSONStream | train | function JSONStream(runner, options) {
Base.call(this, runner, options);
var self = this;
var total = runner.total;
runner.once(EVENT_RUN_BEGIN, function() {
writeEvent(['start', {total: total}]);
});
runner.on(EVENT_TEST_PASS, function(test) {
writeEvent(['pass', clean(test)]);
});
runner.o... | javascript | {
"resource": ""
} |
q16416 | clean | train | function clean(test) {
return {
title: test.title,
fullTitle: test.fullTitle(),
duration: test.duration,
currentRetry: test.currentRetry()
};
} | javascript | {
"resource": ""
} |
q16417 | List | train | function List(runner, options) {
Base.call(this, runner, options);
var self = this;
var n = 0;
runner.on(EVENT_RUN_BEGIN, function() {
console.log();
});
runner.on(EVENT_TEST_BEGIN, function(test) {
process.stdout.write(color('pass', ' ' + test.fullTitle() + ': '));
});
runner.on(EVENT_TE... | javascript | {
"resource": ""
} |
q16418 | text | train | function text(el, contents) {
if (el.textContent) {
el.textContent = contents;
} else {
el.innerText = contents;
}
} | javascript | {
"resource": ""
} |
q16419 | Dot | train | function Dot(runner, options) {
Base.call(this, runner, options);
var self = this;
var width = (Base.window.width * 0.75) | 0;
var n = -1;
runner.on(EVENT_RUN_BEGIN, function() {
process.stdout.write('\n');
});
runner.on(EVENT_TEST_PENDING, function() {
if (++n % width === 0) {
process.st... | javascript | {
"resource": ""
} |
q16420 | extraGlobals | train | function extraGlobals() {
if (typeof process === 'object' && typeof process.version === 'string') {
var parts = process.version.split('.');
var nodeVersion = parts.reduce(function(a, v) {
return (a << 8) | v;
});
// 'errno' was renamed to process._errno in v0.9.11.
if (nodeVersion < 0x00090... | javascript | {
"resource": ""
} |
q16421 | train | function(resolution) {
this.width = canvas.width = window.innerWidth;
this.height = canvas.height = window.innerHeight;
this.resolution = resolution;
this.spacing = this.width / resolution;
this.focalLen = this.height / this.width;
this.range = isMobile ? 9 : 18;
this.lightRange = 9;
this.scale = canvas... | javascript | {
"resource": ""
} | |
q16422 | train | function() {
var dir = game.player.dir;
var sky = game.map.skybox;
var ambient = game.map.light;
var width = sky.width * (this.height / sky.height) * 2;
var left = (dir / circle) * -width;
ctx.save();
ctx.drawImage(sky.image, left, 0, width, this.height);
if (left < width - this.width) ... | javascript | {
"resource": ""
} | |
q16423 | train | function() {
var x, angle, ray;
ctx.save();
for (var col=0; col<this.resolution; col++) {
x = col / this.resolution - 0.5;
angle = Math.atan2(x, this.focalLen);
ray = game.map.cast(game.player, game.player.dir + angle, this.range);
this.drawCol(col, ray, angle);
}
ctx.res... | javascript | {
"resource": ""
} | |
q16424 | train | function(col, ray, angle) {
var step, drops, rain, texX, wall;
var tex1 = game.map.wall;
var tex2 = game.map.speaker;
var left = Math.floor(col * this.spacing);
var width = Math.ceil(this.spacing);
var hit = -1;
// Find the next wall hit.
while (++hit < ray.length && ray[hit].height <= ... | javascript | {
"resource": ""
} | |
q16425 | train | function() {
var hand = game.player.hand;
var steps = game.player.steps;
var scaleFactor = this.scale * 6;
// Calculate the position of each hand relative to the steps taken.
var xScale = Math.cos(steps * 2);
var yScale = Math.sin(steps * 4);
var bobX = xScale * scaleFactor;
var bobY = ... | javascript | {
"resource": ""
} | |
q16426 | train | function(height, angle, dist) {
var z = dist * Math.cos(angle);
var wallH = this.height * height / z;
var bottom = this.height / 2 * (1 + 1 / z);
return {
top: bottom - wallH,
height: wallH
};
} | javascript | {
"resource": ""
} | |
q16427 | train | function(options) {
var self = this;
self.sounds = [];
// Setup the options to define this sprite display.
self._width = options.width;
self._left = options.left;
self._spriteMap = options.spriteMap;
self._sprite = options.sprite;
self.setupListeners();
// Create our audio sprite definition.
self... | javascript | {
"resource": ""
} | |
q16428 | train | function() {
var self = this;
var keys = Object.keys(self._spriteMap);
keys.forEach(function(key) {
window[key].addEventListener('click', function() {
self.play(key);
}, false);
});
} | javascript | {
"resource": ""
} | |
q16429 | train | function(key) {
var self = this;
var sprite = self._spriteMap[key];
// Play the sprite sound and capture the ID.
var id = self.sound.play(sprite);
// Create a progress element and begin visually tracking it.
var elm = document.createElement('div');
elm.className = 'progress';
elm.id = ... | javascript | {
"resource": ""
} | |
q16430 | train | function() {
var self = this;
// Calculate the scale of our window from "full" size.
var scale = window.innerWidth / 3600;
// Resize and reposition the sprite overlays.
var keys = Object.keys(self._spriteMap);
for (var i=0; i<keys.length; i++) {
var sprite = window[keys[i]];
sprite... | javascript | {
"resource": ""
} | |
q16431 | train | function() {
var self = this;
// Loop through all active sounds and update their progress bar.
for (var i=0; i<self.sounds.length; i++) {
var id = parseInt(self.sounds[i].id, 10);
var offset = self._sprite[self.sounds[i].dataset.sprite][0];
var seek = (self.sound.seek(id) || 0) - (offset ... | javascript | {
"resource": ""
} | |
q16432 | train | function() {
// Define our control key codes and states.
this.codes = {
// Arrows
37: 'left', 39: 'right', 38: 'front', 40: 'back',
// WASD
65: 'left', 68: 'right', 87: 'front', 83: 'back',
};
this.states = {left: false, right: false, front: false, back: false};
// Setup the DOM listeners.
... | javascript | {
"resource": ""
} | |
q16433 | train | function(pressed, event) {
var state = this.codes[event.keyCode];
if (!state) {
return;
}
this.states[state] = pressed;
event.preventDefault && event.preventDefault();
event.stopPropagation && event.stopPropagation();
} | javascript | {
"resource": ""
} | |
q16434 | train | function(event) {
var touches = event.touches[0];
// Reset the states.
this.touchEnd(event);
// Determine which key to simulate.
if (touches.pageY < window.innerHeight * 0.3) {
this.key(true, {keyCode: 38});
} else if (touches.pageY > window.innerHeight * 0.7) {
this.key(true, {key... | javascript | {
"resource": ""
} | |
q16435 | train | function(event) {
this.states.left = false;
this.states.right = false;
this.states.front = false;
this.states.back = false;
event.preventDefault();
event.stopPropagation();
} | javascript | {
"resource": ""
} | |
q16436 | train | function() {
// Loop through the tiles and setup the audio listeners.
for (var i=0; i<this.grid.length; i++) {
if (this.grid[i] === 2) {
var y = Math.floor(i / this.size);
var x = i % this.size;
game.audio.speaker(x, y);
}
}
} | javascript | {
"resource": ""
} | |
q16437 | train | function(x, y) {
x = Math.floor(x);
y = Math.floor(y);
if (x < 0 || x > this.size - 1 || y < 0 || y > this.size - 1) {
return -1;
}
return this.grid[y * this.size + x];
} | javascript | {
"resource": ""
} | |
q16438 | train | function(sin, cos, range, origin) {
var stepX = this.step(sin, cos, origin.x, origin.y, false);
var stepY = this.step(cos, sin, origin.y, origin.x, true);
var inspectX = [sin, cos, stepX, 1, 0, origin.dist, stepX.y];
var inspectY = [sin, cos, stepY, 0, 1, origin.dist, stepY.x];
var next = this.... | javascript | {
"resource": ""
} | |
q16439 | train | function(rise, run, x, y, inverted) {
if (run === 0) {
return {len2: Infinity};
}
var dx = run > 0 ? Math.floor(x + 1) - x : Math.ceil(x - 1) - x;
var dy = dx * (rise / run);
return {
x: inverted ? y + dy : x + dx,
y: inverted ? x + dx : y + dy,
len2: dx * dx + dy * dy
... | javascript | {
"resource": ""
} | |
q16440 | train | function(sin, cos, step, shiftX, shiftY, dist, offset) {
var dx = (cos < 0) ? shiftX : 0;
var dy = (sin < 0) ? shiftY : 0;
step.type = this.check(step.x - dx, step.y - dy);
step.height = (step.type) > 0 ? 1 : 0;
step.dist = dist + Math.sqrt(step.len2);
if (shiftX) {
step.shading = (cos <... | javascript | {
"resource": ""
} | |
q16441 | train | function(point, angle, range) {
var sin = Math.sin(angle);
var cos = Math.cos(angle);
return this.ray(sin, cos, range, {
x: point.x,
y: point.y,
height: 0,
dist: 0
});
} | javascript | {
"resource": ""
} | |
q16442 | train | function(secs) {
if (this.light > 0) {
this.light = Math.max(this.light - 10 * secs, 0);
} else if (Math.random() * 6 < secs) {
this.light = 2;
// Play the lightning sound.
game.audio.lightning();
}
} | javascript | {
"resource": ""
} | |
q16443 | train | function() {
var self = this || Howler;
// Create a global ID counter.
self._counter = 1000;
// Pool of unlocked HTML5 Audio objects.
self._html5AudioPool = [];
self.html5PoolSize = 10;
// Internal properties.
self._codecs = {};
self._howls = [];
self._mute... | javascript | {
"resource": ""
} | |
q16444 | train | function() {
var self = this || Howler;
for (var i=self._howls.length-1; i>=0; i--) {
self._howls[i].unload();
}
// Create a new AudioContext to make sure it is fully reset.
if (self.usingWebAudio && self.ctx && typeof self.ctx.close !== 'undefined') {
self.ctx.close();
... | javascript | {
"resource": ""
} | |
q16445 | train | function() {
var self = this || Howler;
// Keeps track of the suspend/resume state of the AudioContext.
self.state = self.ctx ? self.ctx.state || 'suspended' : 'suspended';
// Automatically begin the 30-second suspend process
self._autoSuspend();
// Check if audio is available.
... | javascript | {
"resource": ""
} | |
q16446 | train | function() {
var self = this || Howler;
var audioTest = null;
// Must wrap in a try/catch because IE11 in server mode throws an error.
try {
audioTest = (typeof Audio !== 'undefined') ? new Audio() : null;
} catch (err) {
return self;
}
if (!audioTest || typeo... | javascript | {
"resource": ""
} | |
q16447 | train | function() {
var self = this || Howler;
// Return the next object from the pool if one exists.
if (self._html5AudioPool.length) {
return self._html5AudioPool.pop();
}
//.Check if the audio is locked and throw a warning.
var testPlay = new Audio().play();
if (testPlay ... | javascript | {
"resource": ""
} | |
q16448 | train | function(audio) {
var self = this || Howler;
// Don't add audio to the pool if we don't know if it has been unlocked.
if (audio._unlocked) {
self._html5AudioPool.push(audio);
}
return self;
} | javascript | {
"resource": ""
} | |
q16449 | train | function() {
var self = this;
if (!self.ctx || typeof self.ctx.resume === 'undefined' || !Howler.usingWebAudio) {
return;
}
if (self.state === 'running' && self._suspendTimer) {
clearTimeout(self._suspendTimer);
self._suspendTimer = null;
} else if (self.state ===... | javascript | {
"resource": ""
} | |
q16450 | train | function() {
var self = this;
var url = null;
// If no audio is available, quit immediately.
if (Howler.noAudio) {
self._emit('loaderror', null, 'No audio support.');
return;
}
// Make sure our source is in an array.
if (typeof self._src === 'string') {
... | javascript | {
"resource": ""
} | |
q16451 | train | function() {
sound._paused = false;
sound._seek = seek;
sound._start = start;
sound._stop = stop;
sound._loop = loop;
} | javascript | {
"resource": ""
} | |
q16452 | train | function() {
self._playLock = false;
setParams();
self._refreshBuffer(sound);
// Setup the playback params.
var vol = (sound._muted || self._muted) ? 0 : sound._volume;
node.gain.setValueAtTime(vol, Howler.ctx.currentTime);
sound._playStart = Howler... | javascript | {
"resource": ""
} | |
q16453 | train | function() {
node.currentTime = seek;
node.muted = sound._muted || self._muted || Howler._muted || node.muted;
node.volume = sound._volume * Howler.volume();
node.playbackRate = sound._rate;
// Some browsers will throw an error if this is called without user interactio... | javascript | {
"resource": ""
} | |
q16454 | train | function(sound, from, to, len, id, isGroup) {
var self = this;
var vol = from;
var diff = to - from;
var steps = Math.abs(diff / 0.01);
var stepLen = Math.max(4, (steps > 0) ? len / steps : len);
var lastTick = Date.now();
// Store the value being faded to.
sound._fadeTo... | javascript | {
"resource": ""
} | |
q16455 | train | function(id) {
var self = this;
var sound = self._soundById(id);
if (sound && sound._interval) {
if (self._webAudio) {
sound._node.gain.cancelScheduledValues(Howler.ctx.currentTime);
}
clearInterval(sound._interval);
sound._interval = null;
self.volu... | javascript | {
"resource": ""
} | |
q16456 | train | function(id) {
var self = this;
var duration = self._duration;
// If we pass an ID, get the sound and return the sprite length.
var sound = self._soundById(id);
if (sound) {
duration = self._sprite[sound._sprite][1] / 1000;
}
return duration;
} | javascript | {
"resource": ""
} | |
q16457 | train | function(event, fn, id, once) {
var self = this;
var events = self['_on' + event];
if (typeof fn === 'function') {
events.push(once ? {id: id, fn: fn, once: once} : {id: id, fn: fn});
}
return self;
} | javascript | {
"resource": ""
} | |
q16458 | train | function(event, fn, id) {
var self = this;
var events = self['_on' + event];
var i = 0;
// Allow passing just an event and ID.
if (typeof fn === 'number') {
id = fn;
fn = null;
}
if (fn || id) {
// Loop through event store and remove the passed functio... | javascript | {
"resource": ""
} | |
q16459 | train | function(event, fn, id) {
var self = this;
// Setup the event listener.
self.on(event, fn, id, 1);
return self;
} | javascript | {
"resource": ""
} | |
q16460 | train | function(event, id, msg) {
var self = this;
var events = self['_on' + event];
// Loop through event store and fire all functions.
for (var i=events.length-1; i>=0; i--) {
// Only fire the listener if the correct ID is used.
if (!events[i].id || events[i].id === id || event === '... | javascript | {
"resource": ""
} | |
q16461 | train | function(sound) {
var self = this;
var sprite = sound._sprite;
// If we are using IE and there was network latency we may be clipping
// audio before it completes playing. Lets check the node to make sure it
// believes it has completed, before ending the playback.
if (!self._webAud... | javascript | {
"resource": ""
} | |
q16462 | train | function(id) {
var self = this;
if (self._endTimers[id]) {
// Clear the timeout or remove the ended listener.
if (typeof self._endTimers[id] !== 'function') {
clearTimeout(self._endTimers[id]);
} else {
var sound = self._soundById(id);
if (sound && soun... | javascript | {
"resource": ""
} | |
q16463 | train | function(id) {
var self = this;
// Loop through all sounds and find the one with this ID.
for (var i=0; i<self._sounds.length; i++) {
if (id === self._sounds[i]._id) {
return self._sounds[i];
}
}
return null;
} | javascript | {
"resource": ""
} | |
q16464 | train | function() {
var self = this;
self._drain();
// Find the first inactive node to recycle.
for (var i=0; i<self._sounds.length; i++) {
if (self._sounds[i]._ended) {
return self._sounds[i].reset();
}
}
// If no inactive node was found, create a new one.
... | javascript | {
"resource": ""
} | |
q16465 | train | function() {
var self = this;
var limit = self._pool;
var cnt = 0;
var i = 0;
// If there are less sounds than the max pool size, we are done.
if (self._sounds.length < limit) {
return;
}
// Count the number of inactive sounds.
for (i=0; i<self._sounds.len... | javascript | {
"resource": ""
} | |
q16466 | train | function(id) {
var self = this;
if (typeof id === 'undefined') {
var ids = [];
for (var i=0; i<self._sounds.length; i++) {
ids.push(self._sounds[i]._id);
}
return ids;
} else {
return [id];
}
} | javascript | {
"resource": ""
} | |
q16467 | train | function(sound) {
var self = this;
// Setup the buffer source for playback.
sound._node.bufferSource = Howler.ctx.createBufferSource();
sound._node.bufferSource.buffer = cache[self._src];
// Connect to the correct node.
if (sound._panner) {
sound._node.bufferSource.connect(... | javascript | {
"resource": ""
} | |
q16468 | train | function(node) {
var self = this;
var isIOS = Howler._navigator && Howler._navigator.vendor.indexOf('Apple') >= 0;
if (Howler._scratchBuffer && node.bufferSource) {
node.bufferSource.onended = null;
node.bufferSource.disconnect(0);
if (isIOS) {
try { node.bufferSourc... | javascript | {
"resource": ""
} | |
q16469 | train | function() {
var self = this;
var parent = self._parent;
// Setup the default parameters.
self._muted = parent._muted;
self._loop = parent._loop;
self._volume = parent._volume;
self._rate = parent._rate;
self._seek = 0;
self._paused = true;
self._ended = true... | javascript | {
"resource": ""
} | |
q16470 | train | function() {
var self = this;
var parent = self._parent;
var volume = (Howler._muted || self._muted || self._parent._muted) ? 0 : self._volume;
if (parent._webAudio) {
// Create the gain node for controlling volume (the source will connect to this).
self._node = (typeof Howler.c... | javascript | {
"resource": ""
} | |
q16471 | train | function() {
var self = this;
// Fire an error event and pass back the code.
self._parent._emit('loaderror', self._id, self._node.error ? self._node.error.code : 0);
// Clear the event listener.
self._node.removeEventListener('error', self._errorFn, false);
} | javascript | {
"resource": ""
} | |
q16472 | train | function() {
var self = this;
var parent = self._parent;
// Round up the duration to account for the lower precision in HTML5 Audio.
parent._duration = Math.ceil(self._node.duration * 10) / 10;
// Setup a sprite if none is defined.
if (Object.keys(parent._sprite).length === 0) {
... | javascript | {
"resource": ""
} | |
q16473 | train | function(arraybuffer, self) {
// Fire a load error if something broke.
var error = function() {
self._emit('loaderror', null, 'Decoding audio data failed.');
};
// Load the sound on success.
var success = function(buffer) {
if (buffer && self._sounds.length > 0) {
cache[self._sr... | javascript | {
"resource": ""
} | |
q16474 | train | function(buffer) {
if (buffer && self._sounds.length > 0) {
cache[self._src] = buffer;
loadSound(self, buffer);
} else {
error();
}
} | javascript | {
"resource": ""
} | |
q16475 | train | function(self, buffer) {
// Set the duration.
if (buffer && !self._duration) {
self._duration = buffer.duration;
}
// Setup a sprite if none is defined.
if (Object.keys(self._sprite).length === 0) {
self._sprite = {__default: [0, self._duration * 1000]};
}
// Fire the loaded ev... | javascript | {
"resource": ""
} | |
q16476 | train | function() {
// If we have already detected that Web Audio isn't supported, don't run this step again.
if (!Howler.usingWebAudio) {
return;
}
// Check if we are using Web Audio and setup the AudioContext if we are.
try {
if (typeof AudioContext !== 'undefined') {
Howler.ctx = ne... | javascript | {
"resource": ""
} | |
q16477 | train | function(x, y, dir, speed) {
this.x = x;
this.y = y;
this.dir = dir;
this.speed = speed || 3;
this.steps = 0;
this.hand = new Texture('./assets/gun.png', 512, 360);
// Update the position of the audio listener.
Howler.pos(this.x, this.y, -0.5);
// Update the direction and orientation.
this.rotate(... | javascript | {
"resource": ""
} | |
q16478 | train | function(angle) {
this.dir = (this.dir + angle + circle) % circle;
// Calculate the rotation vector and update the orientation of the listener.
var x = Math.cos(this.dir);
var y = 0;
var z = Math.sin(this.dir);
Howler.orientation(x, y, z, 0, 1, 0);
} | javascript | {
"resource": ""
} | |
q16479 | train | function(dist) {
var dx = Math.cos(this.dir) * dist;
var dy = Math.sin(this.dir) * dist;
// Move the player if they can walk here.
this.x += (game.map.check(this.x + dx, this.y) <= 0) ? dx : 0;
this.y += (game.map.check(this.x, this.y + dy) <= 0) ? dy : 0;
this.steps += dist;
// Update th... | javascript | {
"resource": ""
} | |
q16480 | train | function(secs) {
var states = game.controls.states;
if (states.left) this.rotate(-Math.PI * secs);
if (states.right) this.rotate(Math.PI * secs);
if (states.front) this.walk(this.speed * secs);
if (states.back) this.walk(-this.speed * secs);
} | javascript | {
"resource": ""
} | |
q16481 | train | function() {
this.lastTime = 0;
// Setup our different game components.
this.audio = new Sound();
this.player = new Player(10, 26, Math.PI * 1.9, 2.5);
this.controls = new Controls();
this.map = new Map(25);
this.camera = new Camera(isMobile ? 256 : 512);
requestAnimationFrame(this.tick.bind(this));... | javascript | {
"resource": ""
} | |
q16482 | train | function(time) {
var ms = time - this.lastTime;
this.lastTime = time;
// Update the different components of the scene.
this.map.update(ms / 1000);
this.player.update(ms / 1000);
this.camera.render(this.player, this.map);
// Continue the game loop.
requestAnimationFrame(this.tick.bind(t... | javascript | {
"resource": ""
} | |
q16483 | train | function(stations) {
var self = this;
self.stations = stations;
self.index = 0;
// Setup the display for each station.
for (var i=0; i<self.stations.length; i++) {
window['title' + i].innerHTML = '<b>' + self.stations[i].freq + '</b> ' + self.stations[i].title;
window['station' + i].addEventListen... | javascript | {
"resource": ""
} | |
q16484 | train | function(index) {
var self = this;
var sound;
index = typeof index === 'number' ? index : self.index;
var data = self.stations[index];
// If we already loaded this track, use the current one.
// Otherwise, setup and load a new Howl.
if (data.howl) {
sound = data.howl;
} else {
... | javascript | {
"resource": ""
} | |
q16485 | train | function() {
var self = this;
// Get the Howl we want to manipulate.
var sound = self.stations[self.index].howl;
// Toggle the display.
self.toggleStationDisplay(self.index, false);
// Stop the sound.
if (sound) {
sound.unload();
}
} | javascript | {
"resource": ""
} | |
q16486 | train | function(playlist) {
this.playlist = playlist;
this.index = 0;
// Display the title of the first track.
track.innerHTML = '1. ' + playlist[0].title;
// Setup the playlist display.
playlist.forEach(function(song) {
var div = document.createElement('div');
div.className = 'list-song';
div.innerH... | javascript | {
"resource": ""
} | |
q16487 | train | function(index) {
var self = this;
var sound;
index = typeof index === 'number' ? index : self.index;
var data = self.playlist[index];
// If we already loaded this track, use the current one.
// Otherwise, setup and load a new Howl.
if (data.howl) {
sound = data.howl;
} else {
... | javascript | {
"resource": ""
} | |
q16488 | train | function() {
var self = this;
// Get the Howl we want to manipulate.
var sound = self.playlist[self.index].howl;
// Puase the sound.
sound.pause();
// Show the play button.
playBtn.style.display = 'block';
pauseBtn.style.display = 'none';
} | javascript | {
"resource": ""
} | |
q16489 | train | function(direction) {
var self = this;
// Get the next track based on the direction of the track.
var index = 0;
if (direction === 'prev') {
index = self.index - 1;
if (index < 0) {
index = self.playlist.length - 1;
}
} else {
index = self.index + 1;
if (index ... | javascript | {
"resource": ""
} | |
q16490 | train | function(index) {
var self = this;
// Stop the current track.
if (self.playlist[self.index].howl) {
self.playlist[self.index].howl.stop();
}
// Reset progress.
progress.style.width = '0%';
// Play the new track.
self.play(index);
} | javascript | {
"resource": ""
} | |
q16491 | train | function(val) {
var self = this;
// Update the global volume (affecting all Howls).
Howler.volume(val);
// Update the display on the slider.
var barWidth = (val * 90) / 100;
barFull.style.width = (barWidth * 100) + '%';
sliderBtn.style.left = (window.innerWidth * barWidth + window.innerWid... | javascript | {
"resource": ""
} | |
q16492 | train | function(per) {
var self = this;
// Get the Howl we want to manipulate.
var sound = self.playlist[self.index].howl;
// Convert the percent into a seek position.
if (sound.playing()) {
sound.seek(sound.duration() * per);
}
} | javascript | {
"resource": ""
} | |
q16493 | train | function() {
var self = this;
// Get the Howl we want to manipulate.
var sound = self.playlist[self.index].howl;
// Determine our current seek position.
var seek = sound.seek() || 0;
timer.innerHTML = self.formatTime(Math.round(seek));
progress.style.width = (((seek / sound.duration()) * 1... | javascript | {
"resource": ""
} | |
q16494 | train | function() {
var height = window.innerHeight * 0.3;
var width = window.innerWidth;
wave.height = height;
wave.height_2 = height / 2;
wave.MAX = wave.height_2 - 4;
wave.width = width;
wave.width_2 = width / 2;
wave.width_4 = width / 4;
wave.canvas.height = height;
wave.canvas.width = width;
wave.co... | javascript | {
"resource": ""
} | |
q16495 | maketoc | train | function maketoc(element, enableSections)
{
enableSections = (enableSections != null) ? enableSections : true;
var tmp = crawlDom(document.body, 2, 4, [], 30, enableSections);
if (tmp.childNodes.length > 0)
{
element.appendChild(tmp);
}
} | javascript | {
"resource": ""
} |
q16496 | addPoint | train | function addPoint(type, x, y)
{
var rpt = new mxPoint(x, y);
rpt.type = type;
actual.push(rpt);
var curr = (state.routedPoints != null) ? state.routedPoints[actual.length - 1] : null;
return curr == null || curr.type != type || curr.x != x || curr.y != y;
} | javascript | {
"resource": ""
} |
q16497 | short | train | function short(str, max)
{
if (str.length > max)
{
str = str.substring(0, Math.round(max / 2)) + '...' +
str.substring(str.length - Math.round(max / 4));
}
return str;
} | javascript | {
"resource": ""
} |
q16498 | reference | train | function reference(node, clone)
{
clone.originalNode = node;
node = node.firstChild;
var child = clone.firstChild;
while (node != null && child != null)
{
reference(node, child);
node = node.nextSibling;
child = child.nextSibling;
}
return clone;
} | javascript | {
"resource": ""
} |
q16499 | checkNode | train | function checkNode(node, clone)
{
if (node != null)
{
if (clone.originalNode != node)
{
cleanNode(node);
}
else
{
node = node.firstChild;
clone = clone.firstChild;
while (node != null)
{
var nextNode = node.nextSibling;
if (c... | javascript | {
"resource": ""
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.