id int32 0 58k | repo stringlengths 5 67 | path stringlengths 4 116 | func_name stringlengths 0 58 | original_string stringlengths 52 373k | language stringclasses 1 value | code stringlengths 52 373k | code_tokens list | docstring stringlengths 4 11.8k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 86 226 |
|---|---|---|---|---|---|---|---|---|---|---|---|
5,800 | loadimpact/k6 | samples/pantheon.js | doCategory | function doCategory(category) {
check(http.get(category.url), {
"title is correct": (res) => res.html("title").text() == category.title,
});
for (prodName in category.products) {
if (Math.random() <= category.products[prodName].chance) {
group(prodName, function() { doProductPage(category.products[prodName]) });
}
}
} | javascript | function doCategory(category) {
check(http.get(category.url), {
"title is correct": (res) => res.html("title").text() == category.title,
});
for (prodName in category.products) {
if (Math.random() <= category.products[prodName].chance) {
group(prodName, function() { doProductPage(category.products[prodName]) });
}
}
} | [
"function",
"doCategory",
"(",
"category",
")",
"{",
"check",
"(",
"http",
".",
"get",
"(",
"category",
".",
"url",
")",
",",
"{",
"\"title is correct\"",
":",
"(",
"res",
")",
"=>",
"res",
".",
"html",
"(",
"\"title\"",
")",
".",
"text",
"(",
")",
... | Load a product category page, then potentially load some product pages | [
"Load",
"a",
"product",
"category",
"page",
"then",
"potentially",
"load",
"some",
"product",
"pages"
] | 03645ba7059a4ca9eb22035f5adb52f1a91e7534 | https://github.com/loadimpact/k6/blob/03645ba7059a4ca9eb22035f5adb52f1a91e7534/samples/pantheon.js#L164-L174 |
5,801 | loadimpact/k6 | samples/pantheon.js | doProductPage | function doProductPage(product) {
let res = http.get(product.url);
check(res, {
"title is correct": (res) => res.html("title").text() == product.title,
});
if (Math.random() <= product.chance) {
let formBuildID = res.body.match('name="form_build_id" value="(.*)"')[1];
let formID = res.body.match('name="form_id" value="(.*)"')[1];
let formToken = res.body.match('name="form_token" value="(.*)"')[1];
let productID = res.body.match('name="product_id" value="(.*)"')[1];
group("add to cart", function() {
addProductToCart(product.url, productID, formID, formBuildID, formToken)
});
}
} | javascript | function doProductPage(product) {
let res = http.get(product.url);
check(res, {
"title is correct": (res) => res.html("title").text() == product.title,
});
if (Math.random() <= product.chance) {
let formBuildID = res.body.match('name="form_build_id" value="(.*)"')[1];
let formID = res.body.match('name="form_id" value="(.*)"')[1];
let formToken = res.body.match('name="form_token" value="(.*)"')[1];
let productID = res.body.match('name="product_id" value="(.*)"')[1];
group("add to cart", function() {
addProductToCart(product.url, productID, formID, formBuildID, formToken)
});
}
} | [
"function",
"doProductPage",
"(",
"product",
")",
"{",
"let",
"res",
"=",
"http",
".",
"get",
"(",
"product",
".",
"url",
")",
";",
"check",
"(",
"res",
",",
"{",
"\"title is correct\"",
":",
"(",
"res",
")",
"=>",
"res",
".",
"html",
"(",
"\"title\"... | Load product page and potentially add product to cart | [
"Load",
"product",
"page",
"and",
"potentially",
"add",
"product",
"to",
"cart"
] | 03645ba7059a4ca9eb22035f5adb52f1a91e7534 | https://github.com/loadimpact/k6/blob/03645ba7059a4ca9eb22035f5adb52f1a91e7534/samples/pantheon.js#L177-L191 |
5,802 | loadimpact/k6 | samples/pantheon.js | addProductToCart | function addProductToCart(url, productID, formID, formBuildID, formToken) {
let formdata = {
product_id: productID,
form_id: formID,
form_build_id: formBuildID,
form_token: formToken,
quantity: 1,
op: "Add to cart",
};
let headers = { "Content-Type": "application/x-www-form-urlencoded" };
let res = http.post(url, formdata, { headers: headers });
// verify add to cart succeeded
check(res, {
"add to cart succeeded": (res) => res.body.includes('Item successfully added to your cart')
}) || fail("add to cart failed");
} | javascript | function addProductToCart(url, productID, formID, formBuildID, formToken) {
let formdata = {
product_id: productID,
form_id: formID,
form_build_id: formBuildID,
form_token: formToken,
quantity: 1,
op: "Add to cart",
};
let headers = { "Content-Type": "application/x-www-form-urlencoded" };
let res = http.post(url, formdata, { headers: headers });
// verify add to cart succeeded
check(res, {
"add to cart succeeded": (res) => res.body.includes('Item successfully added to your cart')
}) || fail("add to cart failed");
} | [
"function",
"addProductToCart",
"(",
"url",
",",
"productID",
",",
"formID",
",",
"formBuildID",
",",
"formToken",
")",
"{",
"let",
"formdata",
"=",
"{",
"product_id",
":",
"productID",
",",
"form_id",
":",
"formID",
",",
"form_build_id",
":",
"formBuildID",
... | Add a product to our shopping cart | [
"Add",
"a",
"product",
"to",
"our",
"shopping",
"cart"
] | 03645ba7059a4ca9eb22035f5adb52f1a91e7534 | https://github.com/loadimpact/k6/blob/03645ba7059a4ca9eb22035f5adb52f1a91e7534/samples/pantheon.js#L194-L209 |
5,803 | loadimpact/k6 | samples/pantheon.js | doLogout | function doLogout() {
check(http.get(baseURL + "/user/logout"), {
"logout succeeded": (res) => res.body.includes('<a href="/user/login">Log in')
}) || fail("logout failed");
} | javascript | function doLogout() {
check(http.get(baseURL + "/user/logout"), {
"logout succeeded": (res) => res.body.includes('<a href="/user/login">Log in')
}) || fail("logout failed");
} | [
"function",
"doLogout",
"(",
")",
"{",
"check",
"(",
"http",
".",
"get",
"(",
"baseURL",
"+",
"\"/user/logout\"",
")",
",",
"{",
"\"logout succeeded\"",
":",
"(",
"res",
")",
"=>",
"res",
".",
"body",
".",
"includes",
"(",
"'<a href=\"/user/login\">Log in'",... | Log out the user | [
"Log",
"out",
"the",
"user"
] | 03645ba7059a4ca9eb22035f5adb52f1a91e7534 | https://github.com/loadimpact/k6/blob/03645ba7059a4ca9eb22035f5adb52f1a91e7534/samples/pantheon.js#L321-L325 |
5,804 | immutable-js/immutable-js | src/Hash.js | hashNumber | function hashNumber(n) {
if (n !== n || n === Infinity) {
return 0;
}
let hash = n | 0;
if (hash !== n) {
hash ^= n * 0xffffffff;
}
while (n > 0xffffffff) {
n /= 0xffffffff;
hash ^= n;
}
return smi(hash);
} | javascript | function hashNumber(n) {
if (n !== n || n === Infinity) {
return 0;
}
let hash = n | 0;
if (hash !== n) {
hash ^= n * 0xffffffff;
}
while (n > 0xffffffff) {
n /= 0xffffffff;
hash ^= n;
}
return smi(hash);
} | [
"function",
"hashNumber",
"(",
"n",
")",
"{",
"if",
"(",
"n",
"!==",
"n",
"||",
"n",
"===",
"Infinity",
")",
"{",
"return",
"0",
";",
"}",
"let",
"hash",
"=",
"n",
"|",
"0",
";",
"if",
"(",
"hash",
"!==",
"n",
")",
"{",
"hash",
"^=",
"n",
"... | Compress arbitrarily large numbers into smi hashes. | [
"Compress",
"arbitrarily",
"large",
"numbers",
"into",
"smi",
"hashes",
"."
] | 751082fd0d392f14f7fa567d5fad6edd8f94bd79 | https://github.com/immutable-js/immutable-js/blob/751082fd0d392f14f7fa567d5fad6edd8f94bd79/src/Hash.js#L49-L62 |
5,805 | immutable-js/immutable-js | src/Hash.js | getIENodeHash | function getIENodeHash(node) {
if (node && node.nodeType > 0) {
switch (node.nodeType) {
case 1: // Element
return node.uniqueID;
case 9: // Document
return node.documentElement && node.documentElement.uniqueID;
}
}
} | javascript | function getIENodeHash(node) {
if (node && node.nodeType > 0) {
switch (node.nodeType) {
case 1: // Element
return node.uniqueID;
case 9: // Document
return node.documentElement && node.documentElement.uniqueID;
}
}
} | [
"function",
"getIENodeHash",
"(",
"node",
")",
"{",
"if",
"(",
"node",
"&&",
"node",
".",
"nodeType",
">",
"0",
")",
"{",
"switch",
"(",
"node",
".",
"nodeType",
")",
"{",
"case",
"1",
":",
"// Element",
"return",
"node",
".",
"uniqueID",
";",
"case"... | IE has a `uniqueID` property on DOM nodes. We can construct the hash from it and avoid memory leaks from the IE cloneNode bug. | [
"IE",
"has",
"a",
"uniqueID",
"property",
"on",
"DOM",
"nodes",
".",
"We",
"can",
"construct",
"the",
"hash",
"from",
"it",
"and",
"avoid",
"memory",
"leaks",
"from",
"the",
"IE",
"cloneNode",
"bug",
"."
] | 751082fd0d392f14f7fa567d5fad6edd8f94bd79 | https://github.com/immutable-js/immutable-js/blob/751082fd0d392f14f7fa567d5fad6edd8f94bd79/src/Hash.js#L178-L187 |
5,806 | immutable-js/immutable-js | pages/src/docs/src/TypeDocumentation.js | getTypePropMap | function getTypePropMap(def) {
var map = {};
def &&
def.extends &&
def.extends.forEach(e => {
var superModule = defs.Immutable;
e.name.split('.').forEach(part => {
superModule =
superModule && superModule.module && superModule.module[part];
});
var superInterface = superModule && superModule.interface;
if (superInterface) {
var interfaceMap = Seq(superInterface.typeParams)
.toKeyedSeq()
.flip()
.map(i => e.args[i])
.toObject();
Seq(interfaceMap).forEach((v, k) => {
map[e.name + '<' + k] = v;
});
var superMap = getTypePropMap(superInterface);
Seq(superMap).forEach((v, k) => {
map[k] = v.k === TypeKind.Param ? interfaceMap[v.param] : v;
});
}
});
return map;
} | javascript | function getTypePropMap(def) {
var map = {};
def &&
def.extends &&
def.extends.forEach(e => {
var superModule = defs.Immutable;
e.name.split('.').forEach(part => {
superModule =
superModule && superModule.module && superModule.module[part];
});
var superInterface = superModule && superModule.interface;
if (superInterface) {
var interfaceMap = Seq(superInterface.typeParams)
.toKeyedSeq()
.flip()
.map(i => e.args[i])
.toObject();
Seq(interfaceMap).forEach((v, k) => {
map[e.name + '<' + k] = v;
});
var superMap = getTypePropMap(superInterface);
Seq(superMap).forEach((v, k) => {
map[k] = v.k === TypeKind.Param ? interfaceMap[v.param] : v;
});
}
});
return map;
} | [
"function",
"getTypePropMap",
"(",
"def",
")",
"{",
"var",
"map",
"=",
"{",
"}",
";",
"def",
"&&",
"def",
".",
"extends",
"&&",
"def",
".",
"extends",
".",
"forEach",
"(",
"e",
"=>",
"{",
"var",
"superModule",
"=",
"defs",
".",
"Immutable",
";",
"e... | Get a map from super type parameter to concrete type definition. This is
used when rendering inherited type definitions to ensure contextually
relevant information.
Example:
type A<T> implements B<number, T>
type B<K, V> implements C<K, V, V>
type C<X, Y, Z>
parse C:
{}
parse B:
{ C<X: K
C<Y: V
C<Z: V }
parse A:
{ B<K: number
B<V: T
C<X: number
C<Y: T
C<Z: T } | [
"Get",
"a",
"map",
"from",
"super",
"type",
"parameter",
"to",
"concrete",
"type",
"definition",
".",
"This",
"is",
"used",
"when",
"rendering",
"inherited",
"type",
"definitions",
"to",
"ensure",
"contextually",
"relevant",
"information",
"."
] | 751082fd0d392f14f7fa567d5fad6edd8f94bd79 | https://github.com/immutable-js/immutable-js/blob/751082fd0d392f14f7fa567d5fad6edd8f94bd79/pages/src/docs/src/TypeDocumentation.js#L303-L330 |
5,807 | szimek/signature_pad | docs/js/app.js | resizeCanvas | function resizeCanvas() {
// When zoomed out to less than 100%, for some very strange reason,
// some browsers report devicePixelRatio as less than 1
// and only part of the canvas is cleared then.
var ratio = Math.max(window.devicePixelRatio || 1, 1);
// This part causes the canvas to be cleared
canvas.width = canvas.offsetWidth * ratio;
canvas.height = canvas.offsetHeight * ratio;
canvas.getContext("2d").scale(ratio, ratio);
// This library does not listen for canvas changes, so after the canvas is automatically
// cleared by the browser, SignaturePad#isEmpty might still return false, even though the
// canvas looks empty, because the internal data of this library wasn't cleared. To make sure
// that the state of this library is consistent with visual state of the canvas, you
// have to clear it manually.
signaturePad.clear();
} | javascript | function resizeCanvas() {
// When zoomed out to less than 100%, for some very strange reason,
// some browsers report devicePixelRatio as less than 1
// and only part of the canvas is cleared then.
var ratio = Math.max(window.devicePixelRatio || 1, 1);
// This part causes the canvas to be cleared
canvas.width = canvas.offsetWidth * ratio;
canvas.height = canvas.offsetHeight * ratio;
canvas.getContext("2d").scale(ratio, ratio);
// This library does not listen for canvas changes, so after the canvas is automatically
// cleared by the browser, SignaturePad#isEmpty might still return false, even though the
// canvas looks empty, because the internal data of this library wasn't cleared. To make sure
// that the state of this library is consistent with visual state of the canvas, you
// have to clear it manually.
signaturePad.clear();
} | [
"function",
"resizeCanvas",
"(",
")",
"{",
"// When zoomed out to less than 100%, for some very strange reason,",
"// some browsers report devicePixelRatio as less than 1",
"// and only part of the canvas is cleared then.",
"var",
"ratio",
"=",
"Math",
".",
"max",
"(",
"window",
".",... | Adjust canvas coordinate space taking into account pixel ratio, to make it look crisp on mobile devices. This also causes canvas to be cleared. | [
"Adjust",
"canvas",
"coordinate",
"space",
"taking",
"into",
"account",
"pixel",
"ratio",
"to",
"make",
"it",
"look",
"crisp",
"on",
"mobile",
"devices",
".",
"This",
"also",
"causes",
"canvas",
"to",
"be",
"cleared",
"."
] | 028b538179ac1a56b190fb40b39821b8c39145b7 | https://github.com/szimek/signature_pad/blob/028b538179ac1a56b190fb40b39821b8c39145b7/docs/js/app.js#L18-L35 |
5,808 | react-native-community/cli | packages/platform-ios/src/commands/logIOS/index.js | logIOS | async function logIOS() {
const rawDevices = execFileSync(
'xcrun',
['simctl', 'list', 'devices', '--json'],
{encoding: 'utf8'},
);
const {devices} = JSON.parse(rawDevices);
const device = findAvailableDevice(devices);
if (device === undefined) {
logger.error('No active iOS device found');
return;
}
tailDeviceLogs(device.udid);
} | javascript | async function logIOS() {
const rawDevices = execFileSync(
'xcrun',
['simctl', 'list', 'devices', '--json'],
{encoding: 'utf8'},
);
const {devices} = JSON.parse(rawDevices);
const device = findAvailableDevice(devices);
if (device === undefined) {
logger.error('No active iOS device found');
return;
}
tailDeviceLogs(device.udid);
} | [
"async",
"function",
"logIOS",
"(",
")",
"{",
"const",
"rawDevices",
"=",
"execFileSync",
"(",
"'xcrun'",
",",
"[",
"'simctl'",
",",
"'list'",
",",
"'devices'",
",",
"'--json'",
"]",
",",
"{",
"encoding",
":",
"'utf8'",
"}",
",",
")",
";",
"const",
"{"... | Starts iOS device syslog tail | [
"Starts",
"iOS",
"device",
"syslog",
"tail"
] | c3ed10c0e2d5c7bfe68312093347fbf7e61aa7a7 | https://github.com/react-native-community/cli/blob/c3ed10c0e2d5c7bfe68312093347fbf7e61aa7a7/packages/platform-ios/src/commands/logIOS/index.js#L29-L45 |
5,809 | react-native-community/cli | packages/cli/src/cliEntry.js | printHelpInformation | function printHelpInformation(examples, pkg) {
let cmdName = this._name;
if (this._alias) {
cmdName = `${cmdName}|${this._alias}`;
}
const sourceInformation = pkg
? [`${chalk.bold('Source:')} ${pkg.name}@${pkg.version}`, '']
: [];
let output = [
chalk.bold(`react-native ${cmdName}`),
this._description ? `\n${this._description}\n` : '',
...sourceInformation,
`${chalk.bold('Options:')}`,
this.optionHelp().replace(/^/gm, ' '),
];
if (examples && examples.length > 0) {
const formattedUsage = examples
.map(example => ` ${example.desc}: \n ${chalk.cyan(example.cmd)}`)
.join('\n\n');
output = output.concat([chalk.bold('\nExample usage:'), formattedUsage]);
}
return output.join('\n').concat('\n');
} | javascript | function printHelpInformation(examples, pkg) {
let cmdName = this._name;
if (this._alias) {
cmdName = `${cmdName}|${this._alias}`;
}
const sourceInformation = pkg
? [`${chalk.bold('Source:')} ${pkg.name}@${pkg.version}`, '']
: [];
let output = [
chalk.bold(`react-native ${cmdName}`),
this._description ? `\n${this._description}\n` : '',
...sourceInformation,
`${chalk.bold('Options:')}`,
this.optionHelp().replace(/^/gm, ' '),
];
if (examples && examples.length > 0) {
const formattedUsage = examples
.map(example => ` ${example.desc}: \n ${chalk.cyan(example.cmd)}`)
.join('\n\n');
output = output.concat([chalk.bold('\nExample usage:'), formattedUsage]);
}
return output.join('\n').concat('\n');
} | [
"function",
"printHelpInformation",
"(",
"examples",
",",
"pkg",
")",
"{",
"let",
"cmdName",
"=",
"this",
".",
"_name",
";",
"if",
"(",
"this",
".",
"_alias",
")",
"{",
"cmdName",
"=",
"`",
"${",
"cmdName",
"}",
"${",
"this",
".",
"_alias",
"}",
"`",... | Custom printHelpInformation command inspired by internal Commander.js one modified to suit our needs | [
"Custom",
"printHelpInformation",
"command",
"inspired",
"by",
"internal",
"Commander",
".",
"js",
"one",
"modified",
"to",
"suit",
"our",
"needs"
] | c3ed10c0e2d5c7bfe68312093347fbf7e61aa7a7 | https://github.com/react-native-community/cli/blob/c3ed10c0e2d5c7bfe68312093347fbf7e61aa7a7/packages/cli/src/cliEntry.js#L56-L83 |
5,810 | react-native-community/cli | packages/cli/src/tools/copyFiles.js | copyBinaryFile | function copyBinaryFile(srcPath, destPath, cb) {
let cbCalled = false;
// const {mode} = fs.statSync(srcPath);
const readStream = fs.createReadStream(srcPath);
const writeStream = fs.createWriteStream(destPath);
readStream.on('error', err => {
done(err);
});
writeStream.on('error', err => {
done(err);
});
readStream.on('close', () => {
done();
// We may revisit setting mode to original later, however this fn is used
// before "replace placeholder in template" step, which expects files to be
// writable.
// fs.chmodSync(destPath, mode);
});
readStream.pipe(writeStream);
function done(err) {
if (!cbCalled) {
cb(err);
cbCalled = true;
}
}
} | javascript | function copyBinaryFile(srcPath, destPath, cb) {
let cbCalled = false;
// const {mode} = fs.statSync(srcPath);
const readStream = fs.createReadStream(srcPath);
const writeStream = fs.createWriteStream(destPath);
readStream.on('error', err => {
done(err);
});
writeStream.on('error', err => {
done(err);
});
readStream.on('close', () => {
done();
// We may revisit setting mode to original later, however this fn is used
// before "replace placeholder in template" step, which expects files to be
// writable.
// fs.chmodSync(destPath, mode);
});
readStream.pipe(writeStream);
function done(err) {
if (!cbCalled) {
cb(err);
cbCalled = true;
}
}
} | [
"function",
"copyBinaryFile",
"(",
"srcPath",
",",
"destPath",
",",
"cb",
")",
"{",
"let",
"cbCalled",
"=",
"false",
";",
"// const {mode} = fs.statSync(srcPath);",
"const",
"readStream",
"=",
"fs",
".",
"createReadStream",
"(",
"srcPath",
")",
";",
"const",
"wr... | Same as 'cp' on Unix. Don't do any replacements. | [
"Same",
"as",
"cp",
"on",
"Unix",
".",
"Don",
"t",
"do",
"any",
"replacements",
"."
] | c3ed10c0e2d5c7bfe68312093347fbf7e61aa7a7 | https://github.com/react-native-community/cli/blob/c3ed10c0e2d5c7bfe68312093347fbf7e61aa7a7/packages/cli/src/tools/copyFiles.js#L54-L79 |
5,811 | react-native-community/cli | packages/cli/src/commands/server/copyToClipBoard.js | copyToClipBoard | function copyToClipBoard(content) {
switch (process.platform) {
case 'darwin': {
const child = spawn('pbcopy', []);
child.stdin.end(Buffer.from(content, 'utf8'));
return true;
}
case 'win32': {
const child = spawn('clip', []);
child.stdin.end(Buffer.from(content, 'utf8'));
return true;
}
case 'linux': {
const child = spawn(xsel, ['--clipboard', '--input']);
child.stdin.end(Buffer.from(content, 'utf8'));
return true;
}
default:
return false;
}
} | javascript | function copyToClipBoard(content) {
switch (process.platform) {
case 'darwin': {
const child = spawn('pbcopy', []);
child.stdin.end(Buffer.from(content, 'utf8'));
return true;
}
case 'win32': {
const child = spawn('clip', []);
child.stdin.end(Buffer.from(content, 'utf8'));
return true;
}
case 'linux': {
const child = spawn(xsel, ['--clipboard', '--input']);
child.stdin.end(Buffer.from(content, 'utf8'));
return true;
}
default:
return false;
}
} | [
"function",
"copyToClipBoard",
"(",
"content",
")",
"{",
"switch",
"(",
"process",
".",
"platform",
")",
"{",
"case",
"'darwin'",
":",
"{",
"const",
"child",
"=",
"spawn",
"(",
"'pbcopy'",
",",
"[",
"]",
")",
";",
"child",
".",
"stdin",
".",
"end",
"... | Copy the content to host system clipboard. | [
"Copy",
"the",
"content",
"to",
"host",
"system",
"clipboard",
"."
] | c3ed10c0e2d5c7bfe68312093347fbf7e61aa7a7 | https://github.com/react-native-community/cli/blob/c3ed10c0e2d5c7bfe68312093347fbf7e61aa7a7/packages/cli/src/commands/server/copyToClipBoard.js#L21-L41 |
5,812 | react-native-community/cli | packages/cli/src/commands/upgrade/legacyUpgrade.js | upgradeProjectFiles | function upgradeProjectFiles(projectDir, projectName) {
// Just overwrite
copyProjectTemplateAndReplace(
path.dirname(require.resolve('react-native/template')),
projectDir,
projectName,
{upgrade: true},
);
} | javascript | function upgradeProjectFiles(projectDir, projectName) {
// Just overwrite
copyProjectTemplateAndReplace(
path.dirname(require.resolve('react-native/template')),
projectDir,
projectName,
{upgrade: true},
);
} | [
"function",
"upgradeProjectFiles",
"(",
"projectDir",
",",
"projectName",
")",
"{",
"// Just overwrite",
"copyProjectTemplateAndReplace",
"(",
"path",
".",
"dirname",
"(",
"require",
".",
"resolve",
"(",
"'react-native/template'",
")",
")",
",",
"projectDir",
",",
"... | Once all checks passed, upgrade the project files. | [
"Once",
"all",
"checks",
"passed",
"upgrade",
"the",
"project",
"files",
"."
] | c3ed10c0e2d5c7bfe68312093347fbf7e61aa7a7 | https://github.com/react-native-community/cli/blob/c3ed10c0e2d5c7bfe68312093347fbf7e61aa7a7/packages/cli/src/commands/upgrade/legacyUpgrade.js#L132-L140 |
5,813 | gnab/remark | src/remark/components/styler/styler.js | styleDocument | function styleDocument () {
var headElement, styleElement, style;
// Bail out if document has already been styled
if (getRemarkStylesheet()) {
return;
}
headElement = document.getElementsByTagName('head')[0];
styleElement = document.createElement('style');
styleElement.type = 'text/css';
// Set title in order to enable lookup
styleElement.title = 'remark';
// Set document styles
styleElement.innerHTML = resources.documentStyles;
// Append highlighting styles
for (style in highlighter.styles) {
if (highlighter.styles.hasOwnProperty(style)) {
styleElement.innerHTML = styleElement.innerHTML +
highlighter.styles[style];
}
}
// Put element first to prevent overriding user styles
headElement.insertBefore(styleElement, headElement.firstChild);
} | javascript | function styleDocument () {
var headElement, styleElement, style;
// Bail out if document has already been styled
if (getRemarkStylesheet()) {
return;
}
headElement = document.getElementsByTagName('head')[0];
styleElement = document.createElement('style');
styleElement.type = 'text/css';
// Set title in order to enable lookup
styleElement.title = 'remark';
// Set document styles
styleElement.innerHTML = resources.documentStyles;
// Append highlighting styles
for (style in highlighter.styles) {
if (highlighter.styles.hasOwnProperty(style)) {
styleElement.innerHTML = styleElement.innerHTML +
highlighter.styles[style];
}
}
// Put element first to prevent overriding user styles
headElement.insertBefore(styleElement, headElement.firstChild);
} | [
"function",
"styleDocument",
"(",
")",
"{",
"var",
"headElement",
",",
"styleElement",
",",
"style",
";",
"// Bail out if document has already been styled",
"if",
"(",
"getRemarkStylesheet",
"(",
")",
")",
"{",
"return",
";",
"}",
"headElement",
"=",
"document",
"... | Applies bundled styles to document | [
"Applies",
"bundled",
"styles",
"to",
"document"
] | 4432b423e38ca7537bf834880b3fa1cdaea5f8a7 | https://github.com/gnab/remark/blob/4432b423e38ca7537bf834880b3fa1cdaea5f8a7/src/remark/components/styler/styler.js#L11-L39 |
5,814 | gnab/remark | src/remark/components/styler/styler.js | getRemarkStylesheet | function getRemarkStylesheet () {
var i, l = document.styleSheets.length;
for (i = 0; i < l; ++i) {
if (document.styleSheets[i].title === 'remark') {
return document.styleSheets[i];
}
}
} | javascript | function getRemarkStylesheet () {
var i, l = document.styleSheets.length;
for (i = 0; i < l; ++i) {
if (document.styleSheets[i].title === 'remark') {
return document.styleSheets[i];
}
}
} | [
"function",
"getRemarkStylesheet",
"(",
")",
"{",
"var",
"i",
",",
"l",
"=",
"document",
".",
"styleSheets",
".",
"length",
";",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"l",
";",
"++",
"i",
")",
"{",
"if",
"(",
"document",
".",
"styleSheets",
"... | Locates the embedded remark stylesheet | [
"Locates",
"the",
"embedded",
"remark",
"stylesheet"
] | 4432b423e38ca7537bf834880b3fa1cdaea5f8a7 | https://github.com/gnab/remark/blob/4432b423e38ca7537bf834880b3fa1cdaea5f8a7/src/remark/components/styler/styler.js#L50-L58 |
5,815 | gnab/remark | src/remark/components/styler/styler.js | getPageRule | function getPageRule (stylesheet) {
var i, l = stylesheet.cssRules.length;
for (i = 0; i < l; ++i) {
if (stylesheet.cssRules[i] instanceof window.CSSPageRule) {
return stylesheet.cssRules[i];
}
}
} | javascript | function getPageRule (stylesheet) {
var i, l = stylesheet.cssRules.length;
for (i = 0; i < l; ++i) {
if (stylesheet.cssRules[i] instanceof window.CSSPageRule) {
return stylesheet.cssRules[i];
}
}
} | [
"function",
"getPageRule",
"(",
"stylesheet",
")",
"{",
"var",
"i",
",",
"l",
"=",
"stylesheet",
".",
"cssRules",
".",
"length",
";",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"l",
";",
"++",
"i",
")",
"{",
"if",
"(",
"stylesheet",
".",
"cssRules... | Locates the CSS @page rule | [
"Locates",
"the",
"CSS"
] | 4432b423e38ca7537bf834880b3fa1cdaea5f8a7 | https://github.com/gnab/remark/blob/4432b423e38ca7537bf834880b3fa1cdaea5f8a7/src/remark/components/styler/styler.js#L61-L69 |
5,816 | dabeng/OrgChart | dist/js/jquery.orgchart.js | function ($node, relation) {
if (!$node || !($node instanceof $) || !$node.is('.node')) {
return $();
}
if (relation === 'parent') {
return $node.closest('.nodes').parent().children(':first').find('.node');
} else if (relation === 'children') {
return $node.closest('tr').siblings('.nodes').children().find('.node:first');
} else if (relation === 'siblings') {
return $node.closest('table').parent().siblings().find('.node:first');
} else {
return $();
}
} | javascript | function ($node, relation) {
if (!$node || !($node instanceof $) || !$node.is('.node')) {
return $();
}
if (relation === 'parent') {
return $node.closest('.nodes').parent().children(':first').find('.node');
} else if (relation === 'children') {
return $node.closest('tr').siblings('.nodes').children().find('.node:first');
} else if (relation === 'siblings') {
return $node.closest('table').parent().siblings().find('.node:first');
} else {
return $();
}
} | [
"function",
"(",
"$node",
",",
"relation",
")",
"{",
"if",
"(",
"!",
"$node",
"||",
"!",
"(",
"$node",
"instanceof",
"$",
")",
"||",
"!",
"$node",
".",
"is",
"(",
"'.node'",
")",
")",
"{",
"return",
"$",
"(",
")",
";",
"}",
"if",
"(",
"relation... | find the related nodes | [
"find",
"the",
"related",
"nodes"
] | 188a8e4ba6dd0979588474765edb01891d85a38d | https://github.com/dabeng/OrgChart/blob/188a8e4ba6dd0979588474765edb01891d85a38d/dist/js/jquery.orgchart.js#L443-L456 | |
5,817 | dabeng/OrgChart | dist/js/jquery.orgchart.js | function ($node) {
var $upperLevel = $node.closest('.nodes').siblings();
if ($upperLevel.eq(0).find('.spinner').length) {
$node.closest('.orgchart').data('inAjax', false);
}
// hide the sibling nodes
if (this.getNodeState($node, 'siblings').visible) {
this.hideSiblings($node);
}
// hide the lines
var $lines = $upperLevel.slice(1);
$lines.css('visibility', 'hidden');
// hide the superior nodes with transition
var $parent = $upperLevel.eq(0).find('.node');
if (this.getNodeState($parent).visible) {
$parent.addClass('sliding slide-down').one('transitionend', { 'upperLevel': $upperLevel }, this.hideParentEnd);
}
// if the current node has the parent node, hide it recursively
if (this.getNodeState($parent, 'parent').visible) {
this.hideParent($parent);
}
} | javascript | function ($node) {
var $upperLevel = $node.closest('.nodes').siblings();
if ($upperLevel.eq(0).find('.spinner').length) {
$node.closest('.orgchart').data('inAjax', false);
}
// hide the sibling nodes
if (this.getNodeState($node, 'siblings').visible) {
this.hideSiblings($node);
}
// hide the lines
var $lines = $upperLevel.slice(1);
$lines.css('visibility', 'hidden');
// hide the superior nodes with transition
var $parent = $upperLevel.eq(0).find('.node');
if (this.getNodeState($parent).visible) {
$parent.addClass('sliding slide-down').one('transitionend', { 'upperLevel': $upperLevel }, this.hideParentEnd);
}
// if the current node has the parent node, hide it recursively
if (this.getNodeState($parent, 'parent').visible) {
this.hideParent($parent);
}
} | [
"function",
"(",
"$node",
")",
"{",
"var",
"$upperLevel",
"=",
"$node",
".",
"closest",
"(",
"'.nodes'",
")",
".",
"siblings",
"(",
")",
";",
"if",
"(",
"$upperLevel",
".",
"eq",
"(",
"0",
")",
".",
"find",
"(",
"'.spinner'",
")",
".",
"length",
")... | recursively hide the ancestor node and sibling nodes of the specified node | [
"recursively",
"hide",
"the",
"ancestor",
"node",
"and",
"sibling",
"nodes",
"of",
"the",
"specified",
"node"
] | 188a8e4ba6dd0979588474765edb01891d85a38d | https://github.com/dabeng/OrgChart/blob/188a8e4ba6dd0979588474765edb01891d85a38d/dist/js/jquery.orgchart.js#L462-L483 | |
5,818 | dabeng/OrgChart | dist/js/jquery.orgchart.js | function ($node) {
// just show only one superior level
var $upperLevel = $node.closest('.nodes').siblings().removeClass('hidden');
// just show only one line
$upperLevel.eq(2).children().slice(1, -1).addClass('hidden');
// show parent node with animation
var $parent = $upperLevel.eq(0).find('.node');
this.repaint($parent[0]);
$parent.addClass('sliding').removeClass('slide-down').one('transitionend', { 'node': $node }, this.showParentEnd.bind(this));
} | javascript | function ($node) {
// just show only one superior level
var $upperLevel = $node.closest('.nodes').siblings().removeClass('hidden');
// just show only one line
$upperLevel.eq(2).children().slice(1, -1).addClass('hidden');
// show parent node with animation
var $parent = $upperLevel.eq(0).find('.node');
this.repaint($parent[0]);
$parent.addClass('sliding').removeClass('slide-down').one('transitionend', { 'node': $node }, this.showParentEnd.bind(this));
} | [
"function",
"(",
"$node",
")",
"{",
"// just show only one superior level",
"var",
"$upperLevel",
"=",
"$node",
".",
"closest",
"(",
"'.nodes'",
")",
".",
"siblings",
"(",
")",
".",
"removeClass",
"(",
"'hidden'",
")",
";",
"// just show only one line",
"$upperLev... | show the parent node of the specified node | [
"show",
"the",
"parent",
"node",
"of",
"the",
"specified",
"node"
] | 188a8e4ba6dd0979588474765edb01891d85a38d | https://github.com/dabeng/OrgChart/blob/188a8e4ba6dd0979588474765edb01891d85a38d/dist/js/jquery.orgchart.js#L492-L501 | |
5,819 | dabeng/OrgChart | dist/js/jquery.orgchart.js | function ($node) {
var $lowerLevel = $node.closest('tr').siblings();
this.stopAjax($lowerLevel.last());
var $animatedNodes = $lowerLevel.last().find('.node').filter(this.isVisibleNode.bind(this));
var isVerticalDesc = $lowerLevel.last().is('.verticalNodes') ? true : false;
if (!isVerticalDesc) {
$animatedNodes.closest('table').closest('tr').prevAll('.lines').css('visibility', 'hidden');
}
this.repaint($animatedNodes.get(0));
$animatedNodes.addClass('sliding slide-up').eq(0).one('transitionend', { 'animatedNodes': $animatedNodes, 'lowerLevel': $lowerLevel, 'isVerticalDesc': isVerticalDesc, 'node': $node }, this.hideChildrenEnd.bind(this));
} | javascript | function ($node) {
var $lowerLevel = $node.closest('tr').siblings();
this.stopAjax($lowerLevel.last());
var $animatedNodes = $lowerLevel.last().find('.node').filter(this.isVisibleNode.bind(this));
var isVerticalDesc = $lowerLevel.last().is('.verticalNodes') ? true : false;
if (!isVerticalDesc) {
$animatedNodes.closest('table').closest('tr').prevAll('.lines').css('visibility', 'hidden');
}
this.repaint($animatedNodes.get(0));
$animatedNodes.addClass('sliding slide-up').eq(0).one('transitionend', { 'animatedNodes': $animatedNodes, 'lowerLevel': $lowerLevel, 'isVerticalDesc': isVerticalDesc, 'node': $node }, this.hideChildrenEnd.bind(this));
} | [
"function",
"(",
"$node",
")",
"{",
"var",
"$lowerLevel",
"=",
"$node",
".",
"closest",
"(",
"'tr'",
")",
".",
"siblings",
"(",
")",
";",
"this",
".",
"stopAjax",
"(",
"$lowerLevel",
".",
"last",
"(",
")",
")",
";",
"var",
"$animatedNodes",
"=",
"$lo... | recursively hide the descendant nodes of the specified node | [
"recursively",
"hide",
"the",
"descendant",
"nodes",
"of",
"the",
"specified",
"node"
] | 188a8e4ba6dd0979588474765edb01891d85a38d | https://github.com/dabeng/OrgChart/blob/188a8e4ba6dd0979588474765edb01891d85a38d/dist/js/jquery.orgchart.js#L525-L535 | |
5,820 | dabeng/OrgChart | dist/js/jquery.orgchart.js | function ($node) {
var that = this;
var $levels = $node.closest('tr').siblings();
var isVerticalDesc = $levels.is('.verticalNodes') ? true : false;
var $animatedNodes = isVerticalDesc
? $levels.removeClass('hidden').find('.node').filter(this.isVisibleNode.bind(this))
: $levels.removeClass('hidden').eq(2).children().find('.node:first').filter(this.isVisibleNode.bind(this));
// the two following statements are used to enforce browser to repaint
this.repaint($animatedNodes.get(0));
$animatedNodes.addClass('sliding').removeClass('slide-up').eq(0).one('transitionend', { 'node': $node, 'animatedNodes': $animatedNodes }, this.showChildrenEnd.bind(this));
} | javascript | function ($node) {
var that = this;
var $levels = $node.closest('tr').siblings();
var isVerticalDesc = $levels.is('.verticalNodes') ? true : false;
var $animatedNodes = isVerticalDesc
? $levels.removeClass('hidden').find('.node').filter(this.isVisibleNode.bind(this))
: $levels.removeClass('hidden').eq(2).children().find('.node:first').filter(this.isVisibleNode.bind(this));
// the two following statements are used to enforce browser to repaint
this.repaint($animatedNodes.get(0));
$animatedNodes.addClass('sliding').removeClass('slide-up').eq(0).one('transitionend', { 'node': $node, 'animatedNodes': $animatedNodes }, this.showChildrenEnd.bind(this));
} | [
"function",
"(",
"$node",
")",
"{",
"var",
"that",
"=",
"this",
";",
"var",
"$levels",
"=",
"$node",
".",
"closest",
"(",
"'tr'",
")",
".",
"siblings",
"(",
")",
";",
"var",
"isVerticalDesc",
"=",
"$levels",
".",
"is",
"(",
"'.verticalNodes'",
")",
"... | show the children nodes of the specified node | [
"show",
"the",
"children",
"nodes",
"of",
"the",
"specified",
"node"
] | 188a8e4ba6dd0979588474765edb01891d85a38d | https://github.com/dabeng/OrgChart/blob/188a8e4ba6dd0979588474765edb01891d85a38d/dist/js/jquery.orgchart.js#L545-L555 | |
5,821 | dabeng/OrgChart | dist/js/jquery.orgchart.js | function ($node, direction) {
var that = this;
var $nodeContainer = $node.closest('table').parent();
if ($nodeContainer.siblings().find('.spinner').length) {
$node.closest('.orgchart').data('inAjax', false);
}
if (direction) {
if (direction === 'left') {
$nodeContainer.prevAll().find('.node').filter(this.isVisibleNode.bind(this)).addClass('sliding slide-right');
} else {
$nodeContainer.nextAll().find('.node').filter(this.isVisibleNode.bind(this)).addClass('sliding slide-left');
}
} else {
$nodeContainer.prevAll().find('.node').filter(this.isVisibleNode.bind(this)).addClass('sliding slide-right');
$nodeContainer.nextAll().find('.node').filter(this.isVisibleNode.bind(this)).addClass('sliding slide-left');
}
var $animatedNodes = $nodeContainer.siblings().find('.sliding');
var $lines = $animatedNodes.closest('.nodes').prevAll('.lines').css('visibility', 'hidden');
$animatedNodes.eq(0).one('transitionend', { 'node': $node, 'nodeContainer': $nodeContainer, 'direction': direction, 'animatedNodes': $animatedNodes, 'lines': $lines }, this.hideSiblingsEnd.bind(this));
} | javascript | function ($node, direction) {
var that = this;
var $nodeContainer = $node.closest('table').parent();
if ($nodeContainer.siblings().find('.spinner').length) {
$node.closest('.orgchart').data('inAjax', false);
}
if (direction) {
if (direction === 'left') {
$nodeContainer.prevAll().find('.node').filter(this.isVisibleNode.bind(this)).addClass('sliding slide-right');
} else {
$nodeContainer.nextAll().find('.node').filter(this.isVisibleNode.bind(this)).addClass('sliding slide-left');
}
} else {
$nodeContainer.prevAll().find('.node').filter(this.isVisibleNode.bind(this)).addClass('sliding slide-right');
$nodeContainer.nextAll().find('.node').filter(this.isVisibleNode.bind(this)).addClass('sliding slide-left');
}
var $animatedNodes = $nodeContainer.siblings().find('.sliding');
var $lines = $animatedNodes.closest('.nodes').prevAll('.lines').css('visibility', 'hidden');
$animatedNodes.eq(0).one('transitionend', { 'node': $node, 'nodeContainer': $nodeContainer, 'direction': direction, 'animatedNodes': $animatedNodes, 'lines': $lines }, this.hideSiblingsEnd.bind(this));
} | [
"function",
"(",
"$node",
",",
"direction",
")",
"{",
"var",
"that",
"=",
"this",
";",
"var",
"$nodeContainer",
"=",
"$node",
".",
"closest",
"(",
"'table'",
")",
".",
"parent",
"(",
")",
";",
"if",
"(",
"$nodeContainer",
".",
"siblings",
"(",
")",
"... | hide the sibling nodes of the specified node | [
"hide",
"the",
"sibling",
"nodes",
"of",
"the",
"specified",
"node"
] | 188a8e4ba6dd0979588474765edb01891d85a38d | https://github.com/dabeng/OrgChart/blob/188a8e4ba6dd0979588474765edb01891d85a38d/dist/js/jquery.orgchart.js#L576-L595 | |
5,822 | dabeng/OrgChart | dist/js/jquery.orgchart.js | function ($node, direction) {
var that = this;
// firstly, show the sibling td tags
var $siblings = $();
if (direction) {
if (direction === 'left') {
$siblings = $node.closest('table').parent().prevAll().removeClass('hidden');
} else {
$siblings = $node.closest('table').parent().nextAll().removeClass('hidden');
}
} else {
$siblings = $node.closest('table').parent().siblings().removeClass('hidden');
}
// secondly, show the lines
var $upperLevel = $node.closest('table').closest('tr').siblings();
if (direction) {
$upperLevel.eq(2).children('.hidden').slice(0, $siblings.length * 2).removeClass('hidden');
} else {
$upperLevel.eq(2).children('.hidden').removeClass('hidden');
}
// thirdly, do some cleaning stuff
if (!this.getNodeState($node, 'parent').visible) {
$upperLevel.removeClass('hidden');
var parent = $upperLevel.find('.node')[0];
this.repaint(parent);
$(parent).addClass('sliding').removeClass('slide-down').one('transitionend', this.showRelatedParentEnd);
}
// lastly, show the sibling nodes with animation
var $visibleNodes = $siblings.find('.node').filter(this.isVisibleNode.bind(this));
this.repaint($visibleNodes.get(0));
$visibleNodes.addClass('sliding').removeClass('slide-left slide-right');
$visibleNodes.eq(0).one('transitionend', { 'node': $node, 'visibleNodes': $visibleNodes }, this.showSiblingsEnd.bind(this));
} | javascript | function ($node, direction) {
var that = this;
// firstly, show the sibling td tags
var $siblings = $();
if (direction) {
if (direction === 'left') {
$siblings = $node.closest('table').parent().prevAll().removeClass('hidden');
} else {
$siblings = $node.closest('table').parent().nextAll().removeClass('hidden');
}
} else {
$siblings = $node.closest('table').parent().siblings().removeClass('hidden');
}
// secondly, show the lines
var $upperLevel = $node.closest('table').closest('tr').siblings();
if (direction) {
$upperLevel.eq(2).children('.hidden').slice(0, $siblings.length * 2).removeClass('hidden');
} else {
$upperLevel.eq(2).children('.hidden').removeClass('hidden');
}
// thirdly, do some cleaning stuff
if (!this.getNodeState($node, 'parent').visible) {
$upperLevel.removeClass('hidden');
var parent = $upperLevel.find('.node')[0];
this.repaint(parent);
$(parent).addClass('sliding').removeClass('slide-down').one('transitionend', this.showRelatedParentEnd);
}
// lastly, show the sibling nodes with animation
var $visibleNodes = $siblings.find('.node').filter(this.isVisibleNode.bind(this));
this.repaint($visibleNodes.get(0));
$visibleNodes.addClass('sliding').removeClass('slide-left slide-right');
$visibleNodes.eq(0).one('transitionend', { 'node': $node, 'visibleNodes': $visibleNodes }, this.showSiblingsEnd.bind(this));
} | [
"function",
"(",
"$node",
",",
"direction",
")",
"{",
"var",
"that",
"=",
"this",
";",
"// firstly, show the sibling td tags",
"var",
"$siblings",
"=",
"$",
"(",
")",
";",
"if",
"(",
"direction",
")",
"{",
"if",
"(",
"direction",
"===",
"'left'",
")",
"{... | show the sibling nodes of the specified node | [
"show",
"the",
"sibling",
"nodes",
"of",
"the",
"specified",
"node"
] | 188a8e4ba6dd0979588474765edb01891d85a38d | https://github.com/dabeng/OrgChart/blob/188a8e4ba6dd0979588474765edb01891d85a38d/dist/js/jquery.orgchart.js#L610-L642 | |
5,823 | dabeng/OrgChart | dist/js/jquery.orgchart.js | function ($edge) {
var $chart = this.$chart;
if (typeof $chart.data('inAjax') !== 'undefined' && $chart.data('inAjax') === true) {
return false;
}
$edge.addClass('hidden');
$edge.parent().append('<i class="fa fa-circle-o-notch fa-spin spinner"></i>')
.children().not('.spinner').css('opacity', 0.2);
$chart.data('inAjax', true);
$('.oc-export-btn' + (this.options.chartClass !== '' ? '.' + this.options.chartClass : '')).prop('disabled', true);
return true;
} | javascript | function ($edge) {
var $chart = this.$chart;
if (typeof $chart.data('inAjax') !== 'undefined' && $chart.data('inAjax') === true) {
return false;
}
$edge.addClass('hidden');
$edge.parent().append('<i class="fa fa-circle-o-notch fa-spin spinner"></i>')
.children().not('.spinner').css('opacity', 0.2);
$chart.data('inAjax', true);
$('.oc-export-btn' + (this.options.chartClass !== '' ? '.' + this.options.chartClass : '')).prop('disabled', true);
return true;
} | [
"function",
"(",
"$edge",
")",
"{",
"var",
"$chart",
"=",
"this",
".",
"$chart",
";",
"if",
"(",
"typeof",
"$chart",
".",
"data",
"(",
"'inAjax'",
")",
"!==",
"'undefined'",
"&&",
"$chart",
".",
"data",
"(",
"'inAjax'",
")",
"===",
"true",
")",
"{",
... | start up loading status for requesting new nodes | [
"start",
"up",
"loading",
"status",
"for",
"requesting",
"new",
"nodes"
] | 188a8e4ba6dd0979588474765edb01891d85a38d | https://github.com/dabeng/OrgChart/blob/188a8e4ba6dd0979588474765edb01891d85a38d/dist/js/jquery.orgchart.js#L644-L656 | |
5,824 | dabeng/OrgChart | dist/js/jquery.orgchart.js | function ($edge) {
var $node = $edge.parent();
$edge.removeClass('hidden');
$node.find('.spinner').remove();
$node.children().removeAttr('style');
this.$chart.data('inAjax', false);
$('.oc-export-btn' + (this.options.chartClass !== '' ? '.' + this.options.chartClass : '')).prop('disabled', false);
} | javascript | function ($edge) {
var $node = $edge.parent();
$edge.removeClass('hidden');
$node.find('.spinner').remove();
$node.children().removeAttr('style');
this.$chart.data('inAjax', false);
$('.oc-export-btn' + (this.options.chartClass !== '' ? '.' + this.options.chartClass : '')).prop('disabled', false);
} | [
"function",
"(",
"$edge",
")",
"{",
"var",
"$node",
"=",
"$edge",
".",
"parent",
"(",
")",
";",
"$edge",
".",
"removeClass",
"(",
"'hidden'",
")",
";",
"$node",
".",
"find",
"(",
"'.spinner'",
")",
".",
"remove",
"(",
")",
";",
"$node",
".",
"child... | terminate loading status for requesting new nodes | [
"terminate",
"loading",
"status",
"for",
"requesting",
"new",
"nodes"
] | 188a8e4ba6dd0979588474765edb01891d85a38d | https://github.com/dabeng/OrgChart/blob/188a8e4ba6dd0979588474765edb01891d85a38d/dist/js/jquery.orgchart.js#L658-L665 | |
5,825 | dabeng/OrgChart | dist/js/jquery.orgchart.js | function (rel, url, $edge) {
var that = this;
var opts = this.options;
$.ajax({ 'url': url, 'dataType': 'json' })
.done(function (data) {
if (that.$chart.data('inAjax')) {
if (rel === 'parent') {
if (!$.isEmptyObject(data)) {
that.addParent($edge.parent(), data);
}
} else if (rel === 'children') {
if (data.children.length) {
that.addChildren($edge.parent(), data[rel]);
}
} else {
that.addSiblings($edge.parent(), data.siblings ? data.siblings : data);
}
}
})
.fail(function () {
console.log('Failed to get ' + rel + ' data');
})
.always(function () {
that.endLoading($edge);
});
} | javascript | function (rel, url, $edge) {
var that = this;
var opts = this.options;
$.ajax({ 'url': url, 'dataType': 'json' })
.done(function (data) {
if (that.$chart.data('inAjax')) {
if (rel === 'parent') {
if (!$.isEmptyObject(data)) {
that.addParent($edge.parent(), data);
}
} else if (rel === 'children') {
if (data.children.length) {
that.addChildren($edge.parent(), data[rel]);
}
} else {
that.addSiblings($edge.parent(), data.siblings ? data.siblings : data);
}
}
})
.fail(function () {
console.log('Failed to get ' + rel + ' data');
})
.always(function () {
that.endLoading($edge);
});
} | [
"function",
"(",
"rel",
",",
"url",
",",
"$edge",
")",
"{",
"var",
"that",
"=",
"this",
";",
"var",
"opts",
"=",
"this",
".",
"options",
";",
"$",
".",
"ajax",
"(",
"{",
"'url'",
":",
"url",
",",
"'dataType'",
":",
"'json'",
"}",
")",
".",
"don... | load new nodes by ajax | [
"load",
"new",
"nodes",
"by",
"ajax"
] | 188a8e4ba6dd0979588474765edb01891d85a38d | https://github.com/dabeng/OrgChart/blob/188a8e4ba6dd0979588474765edb01891d85a38d/dist/js/jquery.orgchart.js#L736-L761 | |
5,826 | dabeng/OrgChart | dist/js/jquery.orgchart.js | function ($appendTo, data) {
var that = this;
var opts = this.options;
var level = 0;
if (data.level) {
level = data.level;
} else {
level = data.level = $appendTo.parentsUntil('.orgchart', '.nodes').length + 1;
}
// Construct the node
var childrenData = data.children;
var hasChildren = childrenData ? childrenData.length : false;
var $nodeWrapper;
if (Object.keys(data).length > 2) {
var $nodeDiv = this.createNode(data);
if (opts.verticalLevel && level >= opts.verticalLevel) {
$appendTo.append($nodeDiv);
}else {
$nodeWrapper = $('<table>');
$appendTo.append($nodeWrapper.append($('<tr/>').append($('<td' + (hasChildren ? ' colspan="' + childrenData.length * 2 + '"' : '') + '></td>').append($nodeDiv))));
}
}
// Construct the lower level(two "connectiong lines" rows and "inferior nodes" row)
if (hasChildren) {
var isHidden = (level + 1 > opts.visibleLevel || data.collapsed) ? ' hidden' : '';
var isVerticalLayer = (opts.verticalLevel && (level + 1) >= opts.verticalLevel) ? true : false;
var $nodesLayer;
if (isVerticalLayer) {
$nodesLayer = $('<ul>');
if (isHidden && level + 1 > opts.verticalLevel) {
$nodesLayer.addClass(isHidden);
}
if (level + 1 === opts.verticalLevel) {
$appendTo.children('table').append('<tr class="verticalNodes' + isHidden + '"><td></td></tr>')
.find('.verticalNodes').children().append($nodesLayer);
} else {
$appendTo.append($nodesLayer);
}
} else {
var $upperLines = $('<tr class="lines' + isHidden + '"><td colspan="' + childrenData.length * 2 + '"><div class="downLine"></div></td></tr>');
var lowerLines = '<tr class="lines' + isHidden + '"><td class="rightLine"></td>';
for (var i=1; i<childrenData.length; i++) {
lowerLines += '<td class="leftLine topLine"></td><td class="rightLine topLine"></td>';
}
lowerLines += '<td class="leftLine"></td></tr>';
$nodesLayer = $('<tr class="nodes' + isHidden + '">');
if (Object.keys(data).length === 2) {
$appendTo.append($upperLines).append(lowerLines).append($nodesLayer);
} else {
$nodeWrapper.append($upperLines).append(lowerLines).append($nodesLayer);
}
}
// recurse through children nodes
$.each(childrenData, function () {
var $nodeCell = isVerticalLayer ? $('<li>') : $('<td colspan="2">');
$nodesLayer.append($nodeCell);
this.level = level + 1;
that.buildHierarchy($nodeCell, this);
});
}
} | javascript | function ($appendTo, data) {
var that = this;
var opts = this.options;
var level = 0;
if (data.level) {
level = data.level;
} else {
level = data.level = $appendTo.parentsUntil('.orgchart', '.nodes').length + 1;
}
// Construct the node
var childrenData = data.children;
var hasChildren = childrenData ? childrenData.length : false;
var $nodeWrapper;
if (Object.keys(data).length > 2) {
var $nodeDiv = this.createNode(data);
if (opts.verticalLevel && level >= opts.verticalLevel) {
$appendTo.append($nodeDiv);
}else {
$nodeWrapper = $('<table>');
$appendTo.append($nodeWrapper.append($('<tr/>').append($('<td' + (hasChildren ? ' colspan="' + childrenData.length * 2 + '"' : '') + '></td>').append($nodeDiv))));
}
}
// Construct the lower level(two "connectiong lines" rows and "inferior nodes" row)
if (hasChildren) {
var isHidden = (level + 1 > opts.visibleLevel || data.collapsed) ? ' hidden' : '';
var isVerticalLayer = (opts.verticalLevel && (level + 1) >= opts.verticalLevel) ? true : false;
var $nodesLayer;
if (isVerticalLayer) {
$nodesLayer = $('<ul>');
if (isHidden && level + 1 > opts.verticalLevel) {
$nodesLayer.addClass(isHidden);
}
if (level + 1 === opts.verticalLevel) {
$appendTo.children('table').append('<tr class="verticalNodes' + isHidden + '"><td></td></tr>')
.find('.verticalNodes').children().append($nodesLayer);
} else {
$appendTo.append($nodesLayer);
}
} else {
var $upperLines = $('<tr class="lines' + isHidden + '"><td colspan="' + childrenData.length * 2 + '"><div class="downLine"></div></td></tr>');
var lowerLines = '<tr class="lines' + isHidden + '"><td class="rightLine"></td>';
for (var i=1; i<childrenData.length; i++) {
lowerLines += '<td class="leftLine topLine"></td><td class="rightLine topLine"></td>';
}
lowerLines += '<td class="leftLine"></td></tr>';
$nodesLayer = $('<tr class="nodes' + isHidden + '">');
if (Object.keys(data).length === 2) {
$appendTo.append($upperLines).append(lowerLines).append($nodesLayer);
} else {
$nodeWrapper.append($upperLines).append(lowerLines).append($nodesLayer);
}
}
// recurse through children nodes
$.each(childrenData, function () {
var $nodeCell = isVerticalLayer ? $('<li>') : $('<td colspan="2">');
$nodesLayer.append($nodeCell);
this.level = level + 1;
that.buildHierarchy($nodeCell, this);
});
}
} | [
"function",
"(",
"$appendTo",
",",
"data",
")",
"{",
"var",
"that",
"=",
"this",
";",
"var",
"opts",
"=",
"this",
".",
"options",
";",
"var",
"level",
"=",
"0",
";",
"if",
"(",
"data",
".",
"level",
")",
"{",
"level",
"=",
"data",
".",
"level",
... | recursively build the tree | [
"recursively",
"build",
"the",
"tree"
] | 188a8e4ba6dd0979588474765edb01891d85a38d | https://github.com/dabeng/OrgChart/blob/188a8e4ba6dd0979588474765edb01891d85a38d/dist/js/jquery.orgchart.js#L1193-L1253 | |
5,827 | dabeng/OrgChart | dist/js/jquery.orgchart.js | function ($currentRoot, data) {
data.relationship = data.relationship || '001';
var $table = $('<table>')
.append($('<tr>').append($('<td colspan="2">').append(this.createNode(data))))
.append('<tr class="lines"><td colspan="2"><div class="downLine"></div></td></tr>')
.append('<tr class="lines"><td class="rightLine"></td><td class="leftLine"></td></tr>');
this.$chart.prepend($table)
.children('table:first').append('<tr class="nodes"><td colspan="2"></td></tr>')
.children('tr:last').children().append(this.$chart.children('table').last());
} | javascript | function ($currentRoot, data) {
data.relationship = data.relationship || '001';
var $table = $('<table>')
.append($('<tr>').append($('<td colspan="2">').append(this.createNode(data))))
.append('<tr class="lines"><td colspan="2"><div class="downLine"></div></td></tr>')
.append('<tr class="lines"><td class="rightLine"></td><td class="leftLine"></td></tr>');
this.$chart.prepend($table)
.children('table:first').append('<tr class="nodes"><td colspan="2"></td></tr>')
.children('tr:last').children().append(this.$chart.children('table').last());
} | [
"function",
"(",
"$currentRoot",
",",
"data",
")",
"{",
"data",
".",
"relationship",
"=",
"data",
".",
"relationship",
"||",
"'001'",
";",
"var",
"$table",
"=",
"$",
"(",
"'<table>'",
")",
".",
"append",
"(",
"$",
"(",
"'<tr>'",
")",
".",
"append",
"... | build the parent node of specific node | [
"build",
"the",
"parent",
"node",
"of",
"specific",
"node"
] | 188a8e4ba6dd0979588474765edb01891d85a38d | https://github.com/dabeng/OrgChart/blob/188a8e4ba6dd0979588474765edb01891d85a38d/dist/js/jquery.orgchart.js#L1273-L1282 | |
5,828 | dabeng/OrgChart | dist/js/jquery.orgchart.js | function ($oneSibling, siblingCount, existingSibligCount) {
var lines = '';
for (var i = 0; i < existingSibligCount; i++) {
lines += '<td class="leftLine topLine"></td><td class="rightLine topLine"></td>';
}
$oneSibling.parent().prevAll('tr:gt(0)').children().attr('colspan', siblingCount * 2)
.end().next().children(':first').after(lines);
} | javascript | function ($oneSibling, siblingCount, existingSibligCount) {
var lines = '';
for (var i = 0; i < existingSibligCount; i++) {
lines += '<td class="leftLine topLine"></td><td class="rightLine topLine"></td>';
}
$oneSibling.parent().prevAll('tr:gt(0)').children().attr('colspan', siblingCount * 2)
.end().next().children(':first').after(lines);
} | [
"function",
"(",
"$oneSibling",
",",
"siblingCount",
",",
"existingSibligCount",
")",
"{",
"var",
"lines",
"=",
"''",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"existingSibligCount",
";",
"i",
"++",
")",
"{",
"lines",
"+=",
"'<td class=\"left... | subsequent processing of build sibling nodes | [
"subsequent",
"processing",
"of",
"build",
"sibling",
"nodes"
] | 188a8e4ba6dd0979588474765edb01891d85a38d | https://github.com/dabeng/OrgChart/blob/188a8e4ba6dd0979588474765edb01891d85a38d/dist/js/jquery.orgchart.js#L1294-L1301 | |
5,829 | dabeng/OrgChart | dist/js/jquery.orgchart.js | function ($nodeChart, data) {
var newSiblingCount = $.isArray(data) ? data.length : data.children.length;
var existingSibligCount = $nodeChart.parent().is('td') ? $nodeChart.closest('tr').children().length : 1;
var siblingCount = existingSibligCount + newSiblingCount;
var insertPostion = (siblingCount > 1) ? Math.floor(siblingCount/2 - 1) : 0;
// just build the sibling nodes for the specific node
if ($nodeChart.parent().is('td')) {
var $parent = $nodeChart.closest('tr').prevAll('tr:last');
$nodeChart.closest('tr').prevAll('tr:lt(2)').remove();
this.buildChildNode($nodeChart.parent().closest('table'), data);
var $siblingTds = $nodeChart.parent().closest('table').children('tr:last').children('td');
if (existingSibligCount > 1) {
this.complementLine($siblingTds.eq(0).before($nodeChart.closest('td').siblings().addBack().unwrap()), siblingCount, existingSibligCount);
} else {
this.complementLine($siblingTds.eq(insertPostion).after($nodeChart.closest('td').unwrap()), siblingCount, 1);
}
} else { // build the sibling nodes and parent node for the specific ndoe
this.buildHierarchy($nodeChart.closest('.orgchart'), data);
this.complementLine($nodeChart.next().children('tr:last').children().eq(insertPostion).after($('<td colspan="2">').append($nodeChart)),
siblingCount, 1);
}
} | javascript | function ($nodeChart, data) {
var newSiblingCount = $.isArray(data) ? data.length : data.children.length;
var existingSibligCount = $nodeChart.parent().is('td') ? $nodeChart.closest('tr').children().length : 1;
var siblingCount = existingSibligCount + newSiblingCount;
var insertPostion = (siblingCount > 1) ? Math.floor(siblingCount/2 - 1) : 0;
// just build the sibling nodes for the specific node
if ($nodeChart.parent().is('td')) {
var $parent = $nodeChart.closest('tr').prevAll('tr:last');
$nodeChart.closest('tr').prevAll('tr:lt(2)').remove();
this.buildChildNode($nodeChart.parent().closest('table'), data);
var $siblingTds = $nodeChart.parent().closest('table').children('tr:last').children('td');
if (existingSibligCount > 1) {
this.complementLine($siblingTds.eq(0).before($nodeChart.closest('td').siblings().addBack().unwrap()), siblingCount, existingSibligCount);
} else {
this.complementLine($siblingTds.eq(insertPostion).after($nodeChart.closest('td').unwrap()), siblingCount, 1);
}
} else { // build the sibling nodes and parent node for the specific ndoe
this.buildHierarchy($nodeChart.closest('.orgchart'), data);
this.complementLine($nodeChart.next().children('tr:last').children().eq(insertPostion).after($('<td colspan="2">').append($nodeChart)),
siblingCount, 1);
}
} | [
"function",
"(",
"$nodeChart",
",",
"data",
")",
"{",
"var",
"newSiblingCount",
"=",
"$",
".",
"isArray",
"(",
"data",
")",
"?",
"data",
".",
"length",
":",
"data",
".",
"children",
".",
"length",
";",
"var",
"existingSibligCount",
"=",
"$nodeChart",
"."... | build the sibling nodes of specific node | [
"build",
"the",
"sibling",
"nodes",
"of",
"specific",
"node"
] | 188a8e4ba6dd0979588474765edb01891d85a38d | https://github.com/dabeng/OrgChart/blob/188a8e4ba6dd0979588474765edb01891d85a38d/dist/js/jquery.orgchart.js#L1303-L1324 | |
5,830 | OnsenUI/OnsenUI | core/src/ons/styler.js | function(element, style) {
Object.keys(style).forEach(function(key) {
if (key in element.style) {
element.style[key] = style[key];
} else if (prefix(key) in element.style) {
element.style[prefix(key)] = style[key];
} else {
util.warn('No such style property: ' + key);
}
});
return element;
} | javascript | function(element, style) {
Object.keys(style).forEach(function(key) {
if (key in element.style) {
element.style[key] = style[key];
} else if (prefix(key) in element.style) {
element.style[prefix(key)] = style[key];
} else {
util.warn('No such style property: ' + key);
}
});
return element;
} | [
"function",
"(",
"element",
",",
"style",
")",
"{",
"Object",
".",
"keys",
"(",
"style",
")",
".",
"forEach",
"(",
"function",
"(",
"key",
")",
"{",
"if",
"(",
"key",
"in",
"element",
".",
"style",
")",
"{",
"element",
".",
"style",
"[",
"key",
"... | Minimal utility library for manipulating element's style.
Set element's style.
@param {Element} element
@param {Object} styles
@return {Element} | [
"Minimal",
"utility",
"library",
"for",
"manipulating",
"element",
"s",
"style",
".",
"Set",
"element",
"s",
"style",
"."
] | dafaaa13bc2cf0e16e1f1995788a0d77419d5cf5 | https://github.com/OnsenUI/OnsenUI/blob/dafaaa13bc2cf0e16e1f1995788a0d77419d5cf5/core/src/ons/styler.js#L48-L59 | |
5,831 | OnsenUI/OnsenUI | core/src/ons/gesture-detector.js | setup | function setup(opts) {
if (GestureDetector.READY) {
return;
}
// find what eventtypes we add listeners to
Event.determineEventTypes();
// Register all gestures inside GestureDetector.gestures
Utils.each(GestureDetector.gestures, function(gesture) {
Detection.register(gesture);
});
// Add touch events on the document
Event.onTouch(GestureDetector.DOCUMENT, EVENT_MOVE, Detection.detect, opts);
Event.onTouch(GestureDetector.DOCUMENT, EVENT_END, Detection.detect, opts);
// GestureDetector is ready...!
GestureDetector.READY = true;
} | javascript | function setup(opts) {
if (GestureDetector.READY) {
return;
}
// find what eventtypes we add listeners to
Event.determineEventTypes();
// Register all gestures inside GestureDetector.gestures
Utils.each(GestureDetector.gestures, function(gesture) {
Detection.register(gesture);
});
// Add touch events on the document
Event.onTouch(GestureDetector.DOCUMENT, EVENT_MOVE, Detection.detect, opts);
Event.onTouch(GestureDetector.DOCUMENT, EVENT_END, Detection.detect, opts);
// GestureDetector is ready...!
GestureDetector.READY = true;
} | [
"function",
"setup",
"(",
"opts",
")",
"{",
"if",
"(",
"GestureDetector",
".",
"READY",
")",
"{",
"return",
";",
"}",
"// find what eventtypes we add listeners to",
"Event",
".",
"determineEventTypes",
"(",
")",
";",
"// Register all gestures inside GestureDetector.gest... | setup events to detect gestures on the document
this function is called when creating an new instance
@private | [
"setup",
"events",
"to",
"detect",
"gestures",
"on",
"the",
"document",
"this",
"function",
"is",
"called",
"when",
"creating",
"an",
"new",
"instance"
] | dafaaa13bc2cf0e16e1f1995788a0d77419d5cf5 | https://github.com/OnsenUI/OnsenUI/blob/dafaaa13bc2cf0e16e1f1995788a0d77419d5cf5/core/src/ons/gesture-detector.js#L182-L201 |
5,832 | OnsenUI/OnsenUI | core/src/ons/gesture-detector.js | on | function on(element, type, handler, opt) {
util.addEventListener(element, type, handler, opt, true);
} | javascript | function on(element, type, handler, opt) {
util.addEventListener(element, type, handler, opt, true);
} | [
"function",
"on",
"(",
"element",
",",
"type",
",",
"handler",
",",
"opt",
")",
"{",
"util",
".",
"addEventListener",
"(",
"element",
",",
"type",
",",
"handler",
",",
"opt",
",",
"true",
")",
";",
"}"
] | simple addEventListener wrapper
@param {HTMLElement} element
@param {String} type
@param {Function} handler | [
"simple",
"addEventListener",
"wrapper"
] | dafaaa13bc2cf0e16e1f1995788a0d77419d5cf5 | https://github.com/OnsenUI/OnsenUI/blob/dafaaa13bc2cf0e16e1f1995788a0d77419d5cf5/core/src/ons/gesture-detector.js#L233-L235 |
5,833 | OnsenUI/OnsenUI | core/src/ons/gesture-detector.js | off | function off(element, type, handler, opt) {
util.removeEventListener(element, type, handler, opt, true);
} | javascript | function off(element, type, handler, opt) {
util.removeEventListener(element, type, handler, opt, true);
} | [
"function",
"off",
"(",
"element",
",",
"type",
",",
"handler",
",",
"opt",
")",
"{",
"util",
".",
"removeEventListener",
"(",
"element",
",",
"type",
",",
"handler",
",",
"opt",
",",
"true",
")",
";",
"}"
] | simple removeEventListener wrapper
@param {HTMLElement} element
@param {String} type
@param {Function} handler | [
"simple",
"removeEventListener",
"wrapper"
] | dafaaa13bc2cf0e16e1f1995788a0d77419d5cf5 | https://github.com/OnsenUI/OnsenUI/blob/dafaaa13bc2cf0e16e1f1995788a0d77419d5cf5/core/src/ons/gesture-detector.js#L243-L245 |
5,834 | OnsenUI/OnsenUI | core/src/ons/gesture-detector.js | inArray | function inArray(src, find, deep) {
if (deep) {
for (var i = 0, len = src.length; i < len; i++) { // Array.findIndex
if (Object.keys(find).every(function(key) { return src[i][key] === find[key]; })) {
return i;
}
}
return -1;
}
if (src.indexOf) {
return src.indexOf(find);
} else {
for (var i = 0, len = src.length; i < len; i++) {
if (src[i] === find) {
return i;
}
}
return -1;
}
} | javascript | function inArray(src, find, deep) {
if (deep) {
for (var i = 0, len = src.length; i < len; i++) { // Array.findIndex
if (Object.keys(find).every(function(key) { return src[i][key] === find[key]; })) {
return i;
}
}
return -1;
}
if (src.indexOf) {
return src.indexOf(find);
} else {
for (var i = 0, len = src.length; i < len; i++) {
if (src[i] === find) {
return i;
}
}
return -1;
}
} | [
"function",
"inArray",
"(",
"src",
",",
"find",
",",
"deep",
")",
"{",
"if",
"(",
"deep",
")",
"{",
"for",
"(",
"var",
"i",
"=",
"0",
",",
"len",
"=",
"src",
".",
"length",
";",
"i",
"<",
"len",
";",
"i",
"++",
")",
"{",
"// Array.findIndex",
... | find if a array contains the object using indexOf or a simple polyfill
@param {String} src
@param {String} find
@return {Boolean|Number} false when not found, or the index | [
"find",
"if",
"a",
"array",
"contains",
"the",
"object",
"using",
"indexOf",
"or",
"a",
"simple",
"polyfill"
] | dafaaa13bc2cf0e16e1f1995788a0d77419d5cf5 | https://github.com/OnsenUI/OnsenUI/blob/dafaaa13bc2cf0e16e1f1995788a0d77419d5cf5/core/src/ons/gesture-detector.js#L296-L316 |
5,835 | OnsenUI/OnsenUI | core/src/ons/gesture-detector.js | getDirection | function getDirection(touch1, touch2) {
var x = Math.abs(touch1.clientX - touch2.clientX),
y = Math.abs(touch1.clientY - touch2.clientY);
if (x >= y) {
return touch1.clientX - touch2.clientX > 0 ? DIRECTION_LEFT : DIRECTION_RIGHT;
}
return touch1.clientY - touch2.clientY > 0 ? DIRECTION_UP : DIRECTION_DOWN;
} | javascript | function getDirection(touch1, touch2) {
var x = Math.abs(touch1.clientX - touch2.clientX),
y = Math.abs(touch1.clientY - touch2.clientY);
if (x >= y) {
return touch1.clientX - touch2.clientX > 0 ? DIRECTION_LEFT : DIRECTION_RIGHT;
}
return touch1.clientY - touch2.clientY > 0 ? DIRECTION_UP : DIRECTION_DOWN;
} | [
"function",
"getDirection",
"(",
"touch1",
",",
"touch2",
")",
"{",
"var",
"x",
"=",
"Math",
".",
"abs",
"(",
"touch1",
".",
"clientX",
"-",
"touch2",
".",
"clientX",
")",
",",
"y",
"=",
"Math",
".",
"abs",
"(",
"touch1",
".",
"clientY",
"-",
"touc... | do a small comparison to get the direction between two touches.
@param {Touch} touch1
@param {Touch} touch2
@return {String} direction matches `DIRECTION_LEFT|RIGHT|UP|DOWN` | [
"do",
"a",
"small",
"comparison",
"to",
"get",
"the",
"direction",
"between",
"two",
"touches",
"."
] | dafaaa13bc2cf0e16e1f1995788a0d77419d5cf5 | https://github.com/OnsenUI/OnsenUI/blob/dafaaa13bc2cf0e16e1f1995788a0d77419d5cf5/core/src/ons/gesture-detector.js#L414-L422 |
5,836 | OnsenUI/OnsenUI | core/src/ons/gesture-detector.js | getScale | function getScale(start, end) {
// need two fingers...
if (start.length >= 2 && end.length >= 2) {
return this.getDistance(end[0], end[1]) / this.getDistance(start[0], start[1]);
}
return 1;
} | javascript | function getScale(start, end) {
// need two fingers...
if (start.length >= 2 && end.length >= 2) {
return this.getDistance(end[0], end[1]) / this.getDistance(start[0], start[1]);
}
return 1;
} | [
"function",
"getScale",
"(",
"start",
",",
"end",
")",
"{",
"// need two fingers...",
"if",
"(",
"start",
".",
"length",
">=",
"2",
"&&",
"end",
".",
"length",
">=",
"2",
")",
"{",
"return",
"this",
".",
"getDistance",
"(",
"end",
"[",
"0",
"]",
",",... | calculate the scale factor between two touchLists
no scale is 1, and goes down to 0 when pinched together, and bigger when pinched out
@param {Array} start array of touches
@param {Array} end array of touches
@return {Number} scale | [
"calculate",
"the",
"scale",
"factor",
"between",
"two",
"touchLists",
"no",
"scale",
"is",
"1",
"and",
"goes",
"down",
"to",
"0",
"when",
"pinched",
"together",
"and",
"bigger",
"when",
"pinched",
"out"
] | dafaaa13bc2cf0e16e1f1995788a0d77419d5cf5 | https://github.com/OnsenUI/OnsenUI/blob/dafaaa13bc2cf0e16e1f1995788a0d77419d5cf5/core/src/ons/gesture-detector.js#L444-L450 |
5,837 | OnsenUI/OnsenUI | core/src/ons/gesture-detector.js | getRotation | function getRotation(start, end) {
// need two fingers
if (start.length >= 2 && end.length >= 2) {
return this.getAngle(end[1], end[0]) - this.getAngle(start[1], start[0]);
}
return 0;
} | javascript | function getRotation(start, end) {
// need two fingers
if (start.length >= 2 && end.length >= 2) {
return this.getAngle(end[1], end[0]) - this.getAngle(start[1], start[0]);
}
return 0;
} | [
"function",
"getRotation",
"(",
"start",
",",
"end",
")",
"{",
"// need two fingers",
"if",
"(",
"start",
".",
"length",
">=",
"2",
"&&",
"end",
".",
"length",
">=",
"2",
")",
"{",
"return",
"this",
".",
"getAngle",
"(",
"end",
"[",
"1",
"]",
",",
... | calculate the rotation degrees between two touchLists
@param {Array} start array of touches
@param {Array} end array of touches
@return {Number} rotation | [
"calculate",
"the",
"rotation",
"degrees",
"between",
"two",
"touchLists"
] | dafaaa13bc2cf0e16e1f1995788a0d77419d5cf5 | https://github.com/OnsenUI/OnsenUI/blob/dafaaa13bc2cf0e16e1f1995788a0d77419d5cf5/core/src/ons/gesture-detector.js#L458-L464 |
5,838 | OnsenUI/OnsenUI | core/src/ons/gesture-detector.js | setPrefixedCss | function setPrefixedCss(element, prop, value, toggle) {
var prefixes = ['', 'Webkit', 'Moz', 'O', 'ms'];
prop = Utils.toCamelCase(prop);
for (var i = 0; i < prefixes.length; i++) {
var p = prop;
// prefixes
if (prefixes[i]) {
p = prefixes[i] + p.slice(0, 1).toUpperCase() + p.slice(1);
}
// test the style
if (p in element.style) {
element.style[p] = (toggle === null || toggle) && value || '';
break;
}
}
} | javascript | function setPrefixedCss(element, prop, value, toggle) {
var prefixes = ['', 'Webkit', 'Moz', 'O', 'ms'];
prop = Utils.toCamelCase(prop);
for (var i = 0; i < prefixes.length; i++) {
var p = prop;
// prefixes
if (prefixes[i]) {
p = prefixes[i] + p.slice(0, 1).toUpperCase() + p.slice(1);
}
// test the style
if (p in element.style) {
element.style[p] = (toggle === null || toggle) && value || '';
break;
}
}
} | [
"function",
"setPrefixedCss",
"(",
"element",
",",
"prop",
",",
"value",
",",
"toggle",
")",
"{",
"var",
"prefixes",
"=",
"[",
"''",
",",
"'Webkit'",
",",
"'Moz'",
",",
"'O'",
",",
"'ms'",
"]",
";",
"prop",
"=",
"Utils",
".",
"toCamelCase",
"(",
"pro... | set css properties with their prefixes
@param {HTMLElement} element
@param {String} prop
@param {String} value
@param {Boolean} [toggle=true]
@return {Boolean} | [
"set",
"css",
"properties",
"with",
"their",
"prefixes"
] | dafaaa13bc2cf0e16e1f1995788a0d77419d5cf5 | https://github.com/OnsenUI/OnsenUI/blob/dafaaa13bc2cf0e16e1f1995788a0d77419d5cf5/core/src/ons/gesture-detector.js#L483-L500 |
5,839 | OnsenUI/OnsenUI | core/src/ons/gesture-detector.js | toggleBehavior | function toggleBehavior(element, props, toggle) {
if (!props || !element || !element.style) {
return;
}
// set the css properties
Utils.each(props, function(value, prop) {
Utils.setPrefixedCss(element, prop, value, toggle);
});
var falseFn = toggle && function() {
return false;
};
// also the disable onselectstart
if (props.userSelect == 'none') {
element.onselectstart = falseFn;
}
// and disable ondragstart
if (props.userDrag == 'none') {
element.ondragstart = falseFn;
}
} | javascript | function toggleBehavior(element, props, toggle) {
if (!props || !element || !element.style) {
return;
}
// set the css properties
Utils.each(props, function(value, prop) {
Utils.setPrefixedCss(element, prop, value, toggle);
});
var falseFn = toggle && function() {
return false;
};
// also the disable onselectstart
if (props.userSelect == 'none') {
element.onselectstart = falseFn;
}
// and disable ondragstart
if (props.userDrag == 'none') {
element.ondragstart = falseFn;
}
} | [
"function",
"toggleBehavior",
"(",
"element",
",",
"props",
",",
"toggle",
")",
"{",
"if",
"(",
"!",
"props",
"||",
"!",
"element",
"||",
"!",
"element",
".",
"style",
")",
"{",
"return",
";",
"}",
"// set the css properties",
"Utils",
".",
"each",
"(",
... | toggle browser default behavior by setting css properties.
`userSelect='none'` also sets `element.onselectstart` to false
`userDrag='none'` also sets `element.ondragstart` to false
@param {HtmlElement} element
@param {Object} props
@param {Boolean} [toggle=true] | [
"toggle",
"browser",
"default",
"behavior",
"by",
"setting",
"css",
"properties",
".",
"userSelect",
"=",
"none",
"also",
"sets",
"element",
".",
"onselectstart",
"to",
"false",
"userDrag",
"=",
"none",
"also",
"sets",
"element",
".",
"ondragstart",
"to",
"fal... | dafaaa13bc2cf0e16e1f1995788a0d77419d5cf5 | https://github.com/OnsenUI/OnsenUI/blob/dafaaa13bc2cf0e16e1f1995788a0d77419d5cf5/core/src/ons/gesture-detector.js#L511-L533 |
5,840 | OnsenUI/OnsenUI | core/src/ons/gesture-detector.js | on | function on(element, type, handler, opt, hook) {
var types = type.split(' ');
Utils.each(types, function(type) {
Utils.on(element, type, handler, opt);
hook && hook(type);
});
} | javascript | function on(element, type, handler, opt, hook) {
var types = type.split(' ');
Utils.each(types, function(type) {
Utils.on(element, type, handler, opt);
hook && hook(type);
});
} | [
"function",
"on",
"(",
"element",
",",
"type",
",",
"handler",
",",
"opt",
",",
"hook",
")",
"{",
"var",
"types",
"=",
"type",
".",
"split",
"(",
"' '",
")",
";",
"Utils",
".",
"each",
"(",
"types",
",",
"function",
"(",
"type",
")",
"{",
"Utils"... | simple event binder with a hook and support for multiple types
@param {HTMLElement} element
@param {String} type
@param {Function} handler
@param {Object} [opt]
@param {Function} [hook]
@param {Object} hook.type | [
"simple",
"event",
"binder",
"with",
"a",
"hook",
"and",
"support",
"for",
"multiple",
"types"
] | dafaaa13bc2cf0e16e1f1995788a0d77419d5cf5 | https://github.com/OnsenUI/OnsenUI/blob/dafaaa13bc2cf0e16e1f1995788a0d77419d5cf5/core/src/ons/gesture-detector.js#L591-L597 |
5,841 | OnsenUI/OnsenUI | core/src/ons/gesture-detector.js | doDetect | function doDetect(ev, eventType, element, handler) {
var touchList = this.getTouchList(ev, eventType);
var touchListLength = touchList.length;
var triggerType = eventType;
var triggerChange = touchList.trigger; // used by fakeMultitouch plugin
var changedLength = touchListLength;
// at each touchstart-like event we want also want to trigger a TOUCH event...
if (eventType == EVENT_START) {
triggerChange = EVENT_TOUCH;
// ...the same for a touchend-like event
} else if (eventType == EVENT_END) {
triggerChange = EVENT_RELEASE;
// keep track of how many touches have been removed
changedLength = touchList.length - ((ev.changedTouches) ? ev.changedTouches.length : 1);
}
// after there are still touches on the screen,
// we just want to trigger a MOVE event. so change the START or END to a MOVE
// but only after detection has been started, the first time we actually want a START
if (changedLength > 0 && this.started) {
triggerType = EVENT_MOVE;
}
// detection has been started, we keep track of this, see above
this.started = true;
// generate some event data, some basic information
var evData = this.collectEventData(element, triggerType, touchList, ev);
// trigger the triggerType event before the change (TOUCH, RELEASE) events
// but the END event should be at last
if (eventType != EVENT_END) {
handler.call(Detection, evData);
}
// trigger a change (TOUCH, RELEASE) event, this means the length of the touches changed
if (triggerChange) {
evData.changedLength = changedLength;
evData.eventType = triggerChange;
handler.call(Detection, evData);
evData.eventType = triggerType;
delete evData.changedLength;
}
// trigger the END event
if (triggerType == EVENT_END) {
handler.call(Detection, evData);
// ...and we are done with the detection
// so reset everything to start each detection totally fresh
this.started = false;
}
return triggerType;
} | javascript | function doDetect(ev, eventType, element, handler) {
var touchList = this.getTouchList(ev, eventType);
var touchListLength = touchList.length;
var triggerType = eventType;
var triggerChange = touchList.trigger; // used by fakeMultitouch plugin
var changedLength = touchListLength;
// at each touchstart-like event we want also want to trigger a TOUCH event...
if (eventType == EVENT_START) {
triggerChange = EVENT_TOUCH;
// ...the same for a touchend-like event
} else if (eventType == EVENT_END) {
triggerChange = EVENT_RELEASE;
// keep track of how many touches have been removed
changedLength = touchList.length - ((ev.changedTouches) ? ev.changedTouches.length : 1);
}
// after there are still touches on the screen,
// we just want to trigger a MOVE event. so change the START or END to a MOVE
// but only after detection has been started, the first time we actually want a START
if (changedLength > 0 && this.started) {
triggerType = EVENT_MOVE;
}
// detection has been started, we keep track of this, see above
this.started = true;
// generate some event data, some basic information
var evData = this.collectEventData(element, triggerType, touchList, ev);
// trigger the triggerType event before the change (TOUCH, RELEASE) events
// but the END event should be at last
if (eventType != EVENT_END) {
handler.call(Detection, evData);
}
// trigger a change (TOUCH, RELEASE) event, this means the length of the touches changed
if (triggerChange) {
evData.changedLength = changedLength;
evData.eventType = triggerChange;
handler.call(Detection, evData);
evData.eventType = triggerType;
delete evData.changedLength;
}
// trigger the END event
if (triggerType == EVENT_END) {
handler.call(Detection, evData);
// ...and we are done with the detection
// so reset everything to start each detection totally fresh
this.started = false;
}
return triggerType;
} | [
"function",
"doDetect",
"(",
"ev",
",",
"eventType",
",",
"element",
",",
"handler",
")",
"{",
"var",
"touchList",
"=",
"this",
".",
"getTouchList",
"(",
"ev",
",",
"eventType",
")",
";",
"var",
"touchListLength",
"=",
"touchList",
".",
"length",
";",
"v... | the core detection method
this finds out what GestureDetector-touch-events to trigger
@param {Object} ev
@param {String} eventType matches `EVENT_START|MOVE|END`
@param {HTMLElement} element
@param {Function} handler
@return {String} triggerType matches `EVENT_START|MOVE|END` | [
"the",
"core",
"detection",
"method",
"this",
"finds",
"out",
"what",
"GestureDetector",
"-",
"touch",
"-",
"events",
"to",
"trigger"
] | dafaaa13bc2cf0e16e1f1995788a0d77419d5cf5 | https://github.com/OnsenUI/OnsenUI/blob/dafaaa13bc2cf0e16e1f1995788a0d77419d5cf5/core/src/ons/gesture-detector.js#L687-L745 |
5,842 | OnsenUI/OnsenUI | core/src/ons/gesture-detector.js | getTouchList | function getTouchList(ev, eventType) {
// get the fake pointerEvent touchlist
if (GestureDetector.HAS_POINTEREVENTS) {
return PointerEvent.getTouchList();
}
// get the touchlist
if (ev.touches) {
if (eventType == EVENT_MOVE) {
return ev.touches;
}
var identifiers = [];
var concat = [].concat(Utils.toArray(ev.touches), Utils.toArray(ev.changedTouches));
var touchList = [];
Utils.each(concat, function(touch) {
if (Utils.inArray(identifiers, touch.identifier) === -1) {
touchList.push(touch);
}
identifiers.push(touch.identifier);
});
return touchList;
}
// make fake touchList from mouse position
ev.identifier = 1;
return [ev];
} | javascript | function getTouchList(ev, eventType) {
// get the fake pointerEvent touchlist
if (GestureDetector.HAS_POINTEREVENTS) {
return PointerEvent.getTouchList();
}
// get the touchlist
if (ev.touches) {
if (eventType == EVENT_MOVE) {
return ev.touches;
}
var identifiers = [];
var concat = [].concat(Utils.toArray(ev.touches), Utils.toArray(ev.changedTouches));
var touchList = [];
Utils.each(concat, function(touch) {
if (Utils.inArray(identifiers, touch.identifier) === -1) {
touchList.push(touch);
}
identifiers.push(touch.identifier);
});
return touchList;
}
// make fake touchList from mouse position
ev.identifier = 1;
return [ev];
} | [
"function",
"getTouchList",
"(",
"ev",
",",
"eventType",
")",
"{",
"// get the fake pointerEvent touchlist",
"if",
"(",
"GestureDetector",
".",
"HAS_POINTEREVENTS",
")",
"{",
"return",
"PointerEvent",
".",
"getTouchList",
"(",
")",
";",
"}",
"// get the touchlist",
... | create touchList depending on the event
@param {Object} ev
@param {String} eventType
@return {Array} touches | [
"create",
"touchList",
"depending",
"on",
"the",
"event"
] | dafaaa13bc2cf0e16e1f1995788a0d77419d5cf5 | https://github.com/OnsenUI/OnsenUI/blob/dafaaa13bc2cf0e16e1f1995788a0d77419d5cf5/core/src/ons/gesture-detector.js#L795-L824 |
5,843 | OnsenUI/OnsenUI | core/src/ons/gesture-detector.js | function() {
var srcEvent = this.srcEvent;
srcEvent.preventManipulation && srcEvent.preventManipulation();
srcEvent.preventDefault && srcEvent.preventDefault();
} | javascript | function() {
var srcEvent = this.srcEvent;
srcEvent.preventManipulation && srcEvent.preventManipulation();
srcEvent.preventDefault && srcEvent.preventDefault();
} | [
"function",
"(",
")",
"{",
"var",
"srcEvent",
"=",
"this",
".",
"srcEvent",
";",
"srcEvent",
".",
"preventManipulation",
"&&",
"srcEvent",
".",
"preventManipulation",
"(",
")",
";",
"srcEvent",
".",
"preventDefault",
"&&",
"srcEvent",
".",
"preventDefault",
"(... | prevent the browser default actions
mostly used to disable scrolling of the browser | [
"prevent",
"the",
"browser",
"default",
"actions",
"mostly",
"used",
"to",
"disable",
"scrolling",
"of",
"the",
"browser"
] | dafaaa13bc2cf0e16e1f1995788a0d77419d5cf5 | https://github.com/OnsenUI/OnsenUI/blob/dafaaa13bc2cf0e16e1f1995788a0d77419d5cf5/core/src/ons/gesture-detector.js#L856-L860 | |
5,844 | OnsenUI/OnsenUI | core/src/ons/gesture-detector.js | getTouchList | function getTouchList() {
var touchlist = [];
// we can use forEach since pointerEvents only is in IE10
Utils.each(this.pointers, function(pointer) {
touchlist.push(pointer);
});
return touchlist;
} | javascript | function getTouchList() {
var touchlist = [];
// we can use forEach since pointerEvents only is in IE10
Utils.each(this.pointers, function(pointer) {
touchlist.push(pointer);
});
return touchlist;
} | [
"function",
"getTouchList",
"(",
")",
"{",
"var",
"touchlist",
"=",
"[",
"]",
";",
"// we can use forEach since pointerEvents only is in IE10",
"Utils",
".",
"each",
"(",
"this",
".",
"pointers",
",",
"function",
"(",
"pointer",
")",
"{",
"touchlist",
".",
"push... | get the pointers as an array
@return {Array} touchlist | [
"get",
"the",
"pointers",
"as",
"an",
"array"
] | dafaaa13bc2cf0e16e1f1995788a0d77419d5cf5 | https://github.com/OnsenUI/OnsenUI/blob/dafaaa13bc2cf0e16e1f1995788a0d77419d5cf5/core/src/ons/gesture-detector.js#L900-L907 |
5,845 | OnsenUI/OnsenUI | core/src/ons/gesture-detector.js | startDetect | function startDetect(inst, eventData) {
// already busy with a GestureDetector.gesture detection on an element
if (this.current) {
return;
}
this.stopped = false;
// holds current session
this.current = {
inst: inst, // reference to GestureDetectorInstance we're working for
startEvent: Utils.extend({}, eventData), // start eventData for distances, timing etc
lastEvent: false, // last eventData
lastCalcEvent: false, // last eventData for calculations.
futureCalcEvent: false, // last eventData for calculations.
lastCalcData: {}, // last lastCalcData
name: '' // current gesture we're in/detected, can be 'tap', 'hold' etc
};
this.detect(eventData);
} | javascript | function startDetect(inst, eventData) {
// already busy with a GestureDetector.gesture detection on an element
if (this.current) {
return;
}
this.stopped = false;
// holds current session
this.current = {
inst: inst, // reference to GestureDetectorInstance we're working for
startEvent: Utils.extend({}, eventData), // start eventData for distances, timing etc
lastEvent: false, // last eventData
lastCalcEvent: false, // last eventData for calculations.
futureCalcEvent: false, // last eventData for calculations.
lastCalcData: {}, // last lastCalcData
name: '' // current gesture we're in/detected, can be 'tap', 'hold' etc
};
this.detect(eventData);
} | [
"function",
"startDetect",
"(",
"inst",
",",
"eventData",
")",
"{",
"// already busy with a GestureDetector.gesture detection on an element",
"if",
"(",
"this",
".",
"current",
")",
"{",
"return",
";",
"}",
"this",
".",
"stopped",
"=",
"false",
";",
"// holds curren... | start GestureDetector.gesture detection
@param {GestureDetector.Instance} inst
@param {Object} eventData | [
"start",
"GestureDetector",
".",
"gesture",
"detection"
] | dafaaa13bc2cf0e16e1f1995788a0d77419d5cf5 | https://github.com/OnsenUI/OnsenUI/blob/dafaaa13bc2cf0e16e1f1995788a0d77419d5cf5/core/src/ons/gesture-detector.js#L976-L996 |
5,846 | OnsenUI/OnsenUI | core/src/ons/gesture-detector.js | getCalculatedData | function getCalculatedData(ev, center, deltaTime, deltaX, deltaY) {
var cur = this.current,
recalc = false,
calcEv = cur.lastCalcEvent,
calcData = cur.lastCalcData;
if (calcEv && ev.timeStamp - calcEv.timeStamp > GestureDetector.CALCULATE_INTERVAL) {
center = calcEv.center;
deltaTime = ev.timeStamp - calcEv.timeStamp;
deltaX = ev.center.clientX - calcEv.center.clientX;
deltaY = ev.center.clientY - calcEv.center.clientY;
recalc = true;
}
if (ev.eventType == EVENT_TOUCH || ev.eventType == EVENT_RELEASE) {
cur.futureCalcEvent = ev;
}
if (!cur.lastCalcEvent || recalc) {
calcData.velocity = Utils.getVelocity(deltaTime, deltaX, deltaY);
calcData.angle = Utils.getAngle(center, ev.center);
calcData.direction = Utils.getDirection(center, ev.center);
cur.lastCalcEvent = cur.futureCalcEvent || ev;
cur.futureCalcEvent = ev;
}
ev.velocityX = calcData.velocity.x;
ev.velocityY = calcData.velocity.y;
ev.interimAngle = calcData.angle;
ev.interimDirection = calcData.direction;
} | javascript | function getCalculatedData(ev, center, deltaTime, deltaX, deltaY) {
var cur = this.current,
recalc = false,
calcEv = cur.lastCalcEvent,
calcData = cur.lastCalcData;
if (calcEv && ev.timeStamp - calcEv.timeStamp > GestureDetector.CALCULATE_INTERVAL) {
center = calcEv.center;
deltaTime = ev.timeStamp - calcEv.timeStamp;
deltaX = ev.center.clientX - calcEv.center.clientX;
deltaY = ev.center.clientY - calcEv.center.clientY;
recalc = true;
}
if (ev.eventType == EVENT_TOUCH || ev.eventType == EVENT_RELEASE) {
cur.futureCalcEvent = ev;
}
if (!cur.lastCalcEvent || recalc) {
calcData.velocity = Utils.getVelocity(deltaTime, deltaX, deltaY);
calcData.angle = Utils.getAngle(center, ev.center);
calcData.direction = Utils.getDirection(center, ev.center);
cur.lastCalcEvent = cur.futureCalcEvent || ev;
cur.futureCalcEvent = ev;
}
ev.velocityX = calcData.velocity.x;
ev.velocityY = calcData.velocity.y;
ev.interimAngle = calcData.angle;
ev.interimDirection = calcData.direction;
} | [
"function",
"getCalculatedData",
"(",
"ev",
",",
"center",
",",
"deltaTime",
",",
"deltaX",
",",
"deltaY",
")",
"{",
"var",
"cur",
"=",
"this",
".",
"current",
",",
"recalc",
"=",
"false",
",",
"calcEv",
"=",
"cur",
".",
"lastCalcEvent",
",",
"calcData",... | calculate velocity, angle and direction
@param {Object} ev
@param {Object} center
@param {Number} deltaTime
@param {Number} deltaX
@param {Number} deltaY | [
"calculate",
"velocity",
"angle",
"and",
"direction"
] | dafaaa13bc2cf0e16e1f1995788a0d77419d5cf5 | https://github.com/OnsenUI/OnsenUI/blob/dafaaa13bc2cf0e16e1f1995788a0d77419d5cf5/core/src/ons/gesture-detector.js#L1058-L1089 |
5,847 | OnsenUI/OnsenUI | core/src/ons/gesture-detector.js | extendEventData | function extendEventData(ev) {
var cur = this.current,
startEv = cur.startEvent,
lastEv = cur.lastEvent || startEv;
// update the start touchlist to calculate the scale/rotation
if (ev.eventType == EVENT_TOUCH || ev.eventType == EVENT_RELEASE) {
startEv.touches = [];
Utils.each(ev.touches, function(touch) {
startEv.touches.push({
clientX: touch.clientX,
clientY: touch.clientY
});
});
}
var deltaTime = ev.timeStamp - startEv.timeStamp,
deltaX = ev.center.clientX - startEv.center.clientX,
deltaY = ev.center.clientY - startEv.center.clientY;
this.getCalculatedData(ev, lastEv.center, deltaTime, deltaX, deltaY);
Utils.extend(ev, {
startEvent: startEv,
deltaTime: deltaTime,
deltaX: deltaX,
deltaY: deltaY,
distance: Utils.getDistance(startEv.center, ev.center),
angle: Utils.getAngle(startEv.center, ev.center),
direction: Utils.getDirection(startEv.center, ev.center),
scale: Utils.getScale(startEv.touches, ev.touches),
rotation: Utils.getRotation(startEv.touches, ev.touches)
});
return ev;
} | javascript | function extendEventData(ev) {
var cur = this.current,
startEv = cur.startEvent,
lastEv = cur.lastEvent || startEv;
// update the start touchlist to calculate the scale/rotation
if (ev.eventType == EVENT_TOUCH || ev.eventType == EVENT_RELEASE) {
startEv.touches = [];
Utils.each(ev.touches, function(touch) {
startEv.touches.push({
clientX: touch.clientX,
clientY: touch.clientY
});
});
}
var deltaTime = ev.timeStamp - startEv.timeStamp,
deltaX = ev.center.clientX - startEv.center.clientX,
deltaY = ev.center.clientY - startEv.center.clientY;
this.getCalculatedData(ev, lastEv.center, deltaTime, deltaX, deltaY);
Utils.extend(ev, {
startEvent: startEv,
deltaTime: deltaTime,
deltaX: deltaX,
deltaY: deltaY,
distance: Utils.getDistance(startEv.center, ev.center),
angle: Utils.getAngle(startEv.center, ev.center),
direction: Utils.getDirection(startEv.center, ev.center),
scale: Utils.getScale(startEv.touches, ev.touches),
rotation: Utils.getRotation(startEv.touches, ev.touches)
});
return ev;
} | [
"function",
"extendEventData",
"(",
"ev",
")",
"{",
"var",
"cur",
"=",
"this",
".",
"current",
",",
"startEv",
"=",
"cur",
".",
"startEvent",
",",
"lastEv",
"=",
"cur",
".",
"lastEvent",
"||",
"startEv",
";",
"// update the start touchlist to calculate the scale... | extend eventData for GestureDetector.gestures
@param {Object} ev
@return {Object} ev | [
"extend",
"eventData",
"for",
"GestureDetector",
".",
"gestures"
] | dafaaa13bc2cf0e16e1f1995788a0d77419d5cf5 | https://github.com/OnsenUI/OnsenUI/blob/dafaaa13bc2cf0e16e1f1995788a0d77419d5cf5/core/src/ons/gesture-detector.js#L1096-L1133 |
5,848 | OnsenUI/OnsenUI | core/src/ons/animit.js | function(from, to, delay) {
function step(params, duration, timing) {
if (params.duration !== undefined) {
duration = params.duration;
}
if (params.timing !== undefined) {
timing = params.timing;
}
return {
css: params.css || params,
duration: duration,
timing: timing
};
}
return this.saveStyle()
.queue(step(from, 0, this.defaults.timing))
.wait(delay === undefined ? this.defaults.delay : delay)
.queue(step(to, this.defaults.duration, this.defaults.timing))
.restoreStyle();
} | javascript | function(from, to, delay) {
function step(params, duration, timing) {
if (params.duration !== undefined) {
duration = params.duration;
}
if (params.timing !== undefined) {
timing = params.timing;
}
return {
css: params.css || params,
duration: duration,
timing: timing
};
}
return this.saveStyle()
.queue(step(from, 0, this.defaults.timing))
.wait(delay === undefined ? this.defaults.delay : delay)
.queue(step(to, this.defaults.duration, this.defaults.timing))
.restoreStyle();
} | [
"function",
"(",
"from",
",",
"to",
",",
"delay",
")",
"{",
"function",
"step",
"(",
"params",
",",
"duration",
",",
"timing",
")",
"{",
"if",
"(",
"params",
".",
"duration",
"!==",
"undefined",
")",
"{",
"duration",
"=",
"params",
".",
"duration",
"... | Most of the animations follow this default process.
@param {from} css or options object containing css
@param {to} css or options object containing css
@param {delay} delay to wait | [
"Most",
"of",
"the",
"animations",
"follow",
"this",
"default",
"process",
"."
] | dafaaa13bc2cf0e16e1f1995788a0d77419d5cf5 | https://github.com/OnsenUI/OnsenUI/blob/dafaaa13bc2cf0e16e1f1995788a0d77419d5cf5/core/src/ons/animit.js#L275-L296 | |
5,849 | OnsenUI/OnsenUI | core/src/ons/animit.js | function(transition, options) {
var queue = this.transitionQueue;
if (transition && options) {
options.css = transition;
transition = new Animit.Transition(options);
}
if (!(transition instanceof Function || transition instanceof Animit.Transition)) {
if (transition.css) {
transition = new Animit.Transition(transition);
} else {
transition = new Animit.Transition({
css: transition
});
}
}
if (transition instanceof Function) {
queue.push(transition);
} else if (transition instanceof Animit.Transition) {
queue.push(transition.build());
} else {
throw new Error('Invalid arguments');
}
return this;
} | javascript | function(transition, options) {
var queue = this.transitionQueue;
if (transition && options) {
options.css = transition;
transition = new Animit.Transition(options);
}
if (!(transition instanceof Function || transition instanceof Animit.Transition)) {
if (transition.css) {
transition = new Animit.Transition(transition);
} else {
transition = new Animit.Transition({
css: transition
});
}
}
if (transition instanceof Function) {
queue.push(transition);
} else if (transition instanceof Animit.Transition) {
queue.push(transition.build());
} else {
throw new Error('Invalid arguments');
}
return this;
} | [
"function",
"(",
"transition",
",",
"options",
")",
"{",
"var",
"queue",
"=",
"this",
".",
"transitionQueue",
";",
"if",
"(",
"transition",
"&&",
"options",
")",
"{",
"options",
".",
"css",
"=",
"transition",
";",
"transition",
"=",
"new",
"Animit",
".",... | Queue transition animations or other function.
e.g. animit(elt).queue({color: 'red'})
e.g. animit(elt).queue({color: 'red'}, {duration: 0.4})
e.g. animit(elt).queue({css: {color: 'red'}, duration: 0.2})
@param {Object|Animit.Transition|Function} transition
@param {Object} [options] | [
"Queue",
"transition",
"animations",
"or",
"other",
"function",
"."
] | dafaaa13bc2cf0e16e1f1995788a0d77419d5cf5 | https://github.com/OnsenUI/OnsenUI/blob/dafaaa13bc2cf0e16e1f1995788a0d77419d5cf5/core/src/ons/animit.js#L308-L335 | |
5,850 | OnsenUI/OnsenUI | bindings/angular1/services/onsen.js | function(attrs, modifiers) {
var attrModifiers = attrs && typeof attrs.modifier === 'string' ? attrs.modifier.trim().split(/ +/) : [];
modifiers = angular.isArray(modifiers) ? attrModifiers.concat(modifiers) : attrModifiers;
/**
* @return {String} template eg. 'ons-button--*', 'ons-button--*__item'
* @return {String}
*/
return function(template) {
return modifiers.map(function(modifier) {
return template.replace('*', modifier);
}).join(' ');
};
} | javascript | function(attrs, modifiers) {
var attrModifiers = attrs && typeof attrs.modifier === 'string' ? attrs.modifier.trim().split(/ +/) : [];
modifiers = angular.isArray(modifiers) ? attrModifiers.concat(modifiers) : attrModifiers;
/**
* @return {String} template eg. 'ons-button--*', 'ons-button--*__item'
* @return {String}
*/
return function(template) {
return modifiers.map(function(modifier) {
return template.replace('*', modifier);
}).join(' ');
};
} | [
"function",
"(",
"attrs",
",",
"modifiers",
")",
"{",
"var",
"attrModifiers",
"=",
"attrs",
"&&",
"typeof",
"attrs",
".",
"modifier",
"===",
"'string'",
"?",
"attrs",
".",
"modifier",
".",
"trim",
"(",
")",
".",
"split",
"(",
"/",
" +",
"/",
")",
":"... | Create modifier templater function. The modifier templater generate css classes bound modifier name.
@param {Object} attrs
@param {Array} [modifiers] an array of appendix modifier
@return {Function} | [
"Create",
"modifier",
"templater",
"function",
".",
"The",
"modifier",
"templater",
"generate",
"css",
"classes",
"bound",
"modifier",
"name",
"."
] | dafaaa13bc2cf0e16e1f1995788a0d77419d5cf5 | https://github.com/OnsenUI/OnsenUI/blob/dafaaa13bc2cf0e16e1f1995788a0d77419d5cf5/bindings/angular1/services/onsen.js#L264-L277 | |
5,851 | OnsenUI/OnsenUI | bindings/angular1/services/onsen.js | function(view, element) {
var methods = {
hasModifier: function(needle) {
var tokens = ModifierUtil.split(element.attr('modifier'));
needle = typeof needle === 'string' ? needle.trim() : '';
return ModifierUtil.split(needle).some(function(needle) {
return tokens.indexOf(needle) != -1;
});
},
removeModifier: function(needle) {
needle = typeof needle === 'string' ? needle.trim() : '';
var modifier = ModifierUtil.split(element.attr('modifier')).filter(function(token) {
return token !== needle;
}).join(' ');
element.attr('modifier', modifier);
},
addModifier: function(modifier) {
element.attr('modifier', element.attr('modifier') + ' ' + modifier);
},
setModifier: function(modifier) {
element.attr('modifier', modifier);
},
toggleModifier: function(modifier) {
if (this.hasModifier(modifier)) {
this.removeModifier(modifier);
} else {
this.addModifier(modifier);
}
}
};
for (var method in methods) {
if (methods.hasOwnProperty(method)) {
view[method] = methods[method];
}
}
} | javascript | function(view, element) {
var methods = {
hasModifier: function(needle) {
var tokens = ModifierUtil.split(element.attr('modifier'));
needle = typeof needle === 'string' ? needle.trim() : '';
return ModifierUtil.split(needle).some(function(needle) {
return tokens.indexOf(needle) != -1;
});
},
removeModifier: function(needle) {
needle = typeof needle === 'string' ? needle.trim() : '';
var modifier = ModifierUtil.split(element.attr('modifier')).filter(function(token) {
return token !== needle;
}).join(' ');
element.attr('modifier', modifier);
},
addModifier: function(modifier) {
element.attr('modifier', element.attr('modifier') + ' ' + modifier);
},
setModifier: function(modifier) {
element.attr('modifier', modifier);
},
toggleModifier: function(modifier) {
if (this.hasModifier(modifier)) {
this.removeModifier(modifier);
} else {
this.addModifier(modifier);
}
}
};
for (var method in methods) {
if (methods.hasOwnProperty(method)) {
view[method] = methods[method];
}
}
} | [
"function",
"(",
"view",
",",
"element",
")",
"{",
"var",
"methods",
"=",
"{",
"hasModifier",
":",
"function",
"(",
"needle",
")",
"{",
"var",
"tokens",
"=",
"ModifierUtil",
".",
"split",
"(",
"element",
".",
"attr",
"(",
"'modifier'",
")",
")",
";",
... | Add modifier methods to view object for custom elements.
@param {Object} view object
@param {jqLite} element | [
"Add",
"modifier",
"methods",
"to",
"view",
"object",
"for",
"custom",
"elements",
"."
] | dafaaa13bc2cf0e16e1f1995788a0d77419d5cf5 | https://github.com/OnsenUI/OnsenUI/blob/dafaaa13bc2cf0e16e1f1995788a0d77419d5cf5/bindings/angular1/services/onsen.js#L285-L328 | |
5,852 | OnsenUI/OnsenUI | bindings/angular1/services/onsen.js | function(view, template, element) {
var _tr = function(modifier) {
return template.replace('*', modifier);
};
var fns = {
hasModifier: function(modifier) {
return element.hasClass(_tr(modifier));
},
removeModifier: function(modifier) {
element.removeClass(_tr(modifier));
},
addModifier: function(modifier) {
element.addClass(_tr(modifier));
},
setModifier: function(modifier) {
var classes = element.attr('class').split(/\s+/),
patt = template.replace('*', '.');
for (var i = 0; i < classes.length; i++) {
var cls = classes[i];
if (cls.match(patt)) {
element.removeClass(cls);
}
}
element.addClass(_tr(modifier));
},
toggleModifier: function(modifier) {
var cls = _tr(modifier);
if (element.hasClass(cls)) {
element.removeClass(cls);
} else {
element.addClass(cls);
}
}
};
var append = function(oldFn, newFn) {
if (typeof oldFn !== 'undefined') {
return function() {
return oldFn.apply(null, arguments) || newFn.apply(null, arguments);
};
} else {
return newFn;
}
};
view.hasModifier = append(view.hasModifier, fns.hasModifier);
view.removeModifier = append(view.removeModifier, fns.removeModifier);
view.addModifier = append(view.addModifier, fns.addModifier);
view.setModifier = append(view.setModifier, fns.setModifier);
view.toggleModifier = append(view.toggleModifier, fns.toggleModifier);
} | javascript | function(view, template, element) {
var _tr = function(modifier) {
return template.replace('*', modifier);
};
var fns = {
hasModifier: function(modifier) {
return element.hasClass(_tr(modifier));
},
removeModifier: function(modifier) {
element.removeClass(_tr(modifier));
},
addModifier: function(modifier) {
element.addClass(_tr(modifier));
},
setModifier: function(modifier) {
var classes = element.attr('class').split(/\s+/),
patt = template.replace('*', '.');
for (var i = 0; i < classes.length; i++) {
var cls = classes[i];
if (cls.match(patt)) {
element.removeClass(cls);
}
}
element.addClass(_tr(modifier));
},
toggleModifier: function(modifier) {
var cls = _tr(modifier);
if (element.hasClass(cls)) {
element.removeClass(cls);
} else {
element.addClass(cls);
}
}
};
var append = function(oldFn, newFn) {
if (typeof oldFn !== 'undefined') {
return function() {
return oldFn.apply(null, arguments) || newFn.apply(null, arguments);
};
} else {
return newFn;
}
};
view.hasModifier = append(view.hasModifier, fns.hasModifier);
view.removeModifier = append(view.removeModifier, fns.removeModifier);
view.addModifier = append(view.addModifier, fns.addModifier);
view.setModifier = append(view.setModifier, fns.setModifier);
view.toggleModifier = append(view.toggleModifier, fns.toggleModifier);
} | [
"function",
"(",
"view",
",",
"template",
",",
"element",
")",
"{",
"var",
"_tr",
"=",
"function",
"(",
"modifier",
")",
"{",
"return",
"template",
".",
"replace",
"(",
"'*'",
",",
"modifier",
")",
";",
"}",
";",
"var",
"fns",
"=",
"{",
"hasModifier"... | Add modifier methods to view object.
@param {Object} view object
@param {String} template
@param {jqLite} element | [
"Add",
"modifier",
"methods",
"to",
"view",
"object",
"."
] | dafaaa13bc2cf0e16e1f1995788a0d77419d5cf5 | https://github.com/OnsenUI/OnsenUI/blob/dafaaa13bc2cf0e16e1f1995788a0d77419d5cf5/bindings/angular1/services/onsen.js#L337-L395 | |
5,853 | OnsenUI/OnsenUI | bindings/angular1/services/onsen.js | function(view) {
view.hasModifier = view.removeModifier =
view.addModifier = view.setModifier =
view.toggleModifier = undefined;
} | javascript | function(view) {
view.hasModifier = view.removeModifier =
view.addModifier = view.setModifier =
view.toggleModifier = undefined;
} | [
"function",
"(",
"view",
")",
"{",
"view",
".",
"hasModifier",
"=",
"view",
".",
"removeModifier",
"=",
"view",
".",
"addModifier",
"=",
"view",
".",
"setModifier",
"=",
"view",
".",
"toggleModifier",
"=",
"undefined",
";",
"}"
] | Remove modifier methods.
@param {Object} view object | [
"Remove",
"modifier",
"methods",
"."
] | dafaaa13bc2cf0e16e1f1995788a0d77419d5cf5 | https://github.com/OnsenUI/OnsenUI/blob/dafaaa13bc2cf0e16e1f1995788a0d77419d5cf5/bindings/angular1/services/onsen.js#L402-L406 | |
5,854 | OnsenUI/OnsenUI | bindings/angular1/services/onsen.js | function(component, eventNames) {
eventNames = eventNames.trim().split(/\s+/);
for (var i = 0, l = eventNames.length; i < l; i++) {
var eventName = eventNames[i];
this._registerEventHandler(component, eventName);
}
} | javascript | function(component, eventNames) {
eventNames = eventNames.trim().split(/\s+/);
for (var i = 0, l = eventNames.length; i < l; i++) {
var eventName = eventNames[i];
this._registerEventHandler(component, eventName);
}
} | [
"function",
"(",
"component",
",",
"eventNames",
")",
"{",
"eventNames",
"=",
"eventNames",
".",
"trim",
"(",
")",
".",
"split",
"(",
"/",
"\\s+",
"/",
")",
";",
"for",
"(",
"var",
"i",
"=",
"0",
",",
"l",
"=",
"eventNames",
".",
"length",
";",
"... | Register event handlers for attributes.
@param {Object} component
@param {String} eventNames | [
"Register",
"event",
"handlers",
"for",
"attributes",
"."
] | dafaaa13bc2cf0e16e1f1995788a0d77419d5cf5 | https://github.com/OnsenUI/OnsenUI/blob/dafaaa13bc2cf0e16e1f1995788a0d77419d5cf5/bindings/angular1/services/onsen.js#L441-L448 | |
5,855 | OnsenUI/OnsenUI | bindings/angular1/services/onsen.js | function(name, object) {
var names = name.split(/\./);
function set(container, names, object) {
var name;
for (var i = 0; i < names.length - 1; i++) {
name = names[i];
if (container[name] === undefined || container[name] === null) {
container[name] = {};
}
container = container[name];
}
container[names[names.length - 1]] = object;
if (container[names[names.length - 1]] !== object) {
throw new Error('Cannot set var="' + object._attrs.var + '" because it will overwrite a read-only variable.');
}
}
if (ons.componentBase) {
set(ons.componentBase, names, object);
}
var getScope = function(el) {
return angular.element(el).data('_scope');
};
var element = object._element[0];
// Current element might not have data('_scope')
if (element.hasAttribute('ons-scope')) {
set(getScope(element) || object._scope, names, object);
element = null;
return;
}
// Ancestors
while (element.parentElement) {
element = element.parentElement;
if (element.hasAttribute('ons-scope')) {
set(getScope(element), names, object);
element = null;
return;
}
}
element = null;
// If no ons-scope element was found, attach to $rootScope.
set($rootScope, names, object);
} | javascript | function(name, object) {
var names = name.split(/\./);
function set(container, names, object) {
var name;
for (var i = 0; i < names.length - 1; i++) {
name = names[i];
if (container[name] === undefined || container[name] === null) {
container[name] = {};
}
container = container[name];
}
container[names[names.length - 1]] = object;
if (container[names[names.length - 1]] !== object) {
throw new Error('Cannot set var="' + object._attrs.var + '" because it will overwrite a read-only variable.');
}
}
if (ons.componentBase) {
set(ons.componentBase, names, object);
}
var getScope = function(el) {
return angular.element(el).data('_scope');
};
var element = object._element[0];
// Current element might not have data('_scope')
if (element.hasAttribute('ons-scope')) {
set(getScope(element) || object._scope, names, object);
element = null;
return;
}
// Ancestors
while (element.parentElement) {
element = element.parentElement;
if (element.hasAttribute('ons-scope')) {
set(getScope(element), names, object);
element = null;
return;
}
}
element = null;
// If no ons-scope element was found, attach to $rootScope.
set($rootScope, names, object);
} | [
"function",
"(",
"name",
",",
"object",
")",
"{",
"var",
"names",
"=",
"name",
".",
"split",
"(",
"/",
"\\.",
"/",
")",
";",
"function",
"set",
"(",
"container",
",",
"names",
",",
"object",
")",
"{",
"var",
"name",
";",
"for",
"(",
"var",
"i",
... | Define a variable to JavaScript global scope and AngularJS scope.
Util.defineVar('foo', 'foo-value');
// => window.foo and $scope.foo is now 'foo-value'
Util.defineVar('foo.bar', 'foo-bar-value');
// => window.foo.bar and $scope.foo.bar is now 'foo-bar-value'
@param {String} name
@param object | [
"Define",
"a",
"variable",
"to",
"JavaScript",
"global",
"scope",
"and",
"AngularJS",
"scope",
"."
] | dafaaa13bc2cf0e16e1f1995788a0d77419d5cf5 | https://github.com/OnsenUI/OnsenUI/blob/dafaaa13bc2cf0e16e1f1995788a0d77419d5cf5/bindings/angular1/services/onsen.js#L521-L572 | |
5,856 | OnsenUI/OnsenUI | core/src/ons/page-loader.js | loadPage | function loadPage({page, parent, params = {}}, done) {
internal.getPageHTMLAsync(page).then(html => {
const pageElement = util.createElement(html);
parent.appendChild(pageElement);
done(pageElement);
});
} | javascript | function loadPage({page, parent, params = {}}, done) {
internal.getPageHTMLAsync(page).then(html => {
const pageElement = util.createElement(html);
parent.appendChild(pageElement);
done(pageElement);
});
} | [
"function",
"loadPage",
"(",
"{",
"page",
",",
"parent",
",",
"params",
"=",
"{",
"}",
"}",
",",
"done",
")",
"{",
"internal",
".",
"getPageHTMLAsync",
"(",
"page",
")",
".",
"then",
"(",
"html",
"=>",
"{",
"const",
"pageElement",
"=",
"util",
".",
... | Default implementation for global PageLoader. | [
"Default",
"implementation",
"for",
"global",
"PageLoader",
"."
] | dafaaa13bc2cf0e16e1f1995788a0d77419d5cf5 | https://github.com/OnsenUI/OnsenUI/blob/dafaaa13bc2cf0e16e1f1995788a0d77419d5cf5/core/src/ons/page-loader.js#L21-L28 |
5,857 | stylus/stylus | lib/functions/rgba.js | rgba | function rgba(red, green, blue, alpha){
switch (arguments.length) {
case 1:
utils.assertColor(red);
return red.rgba;
case 2:
utils.assertColor(red);
var color = red.rgba;
utils.assertType(green, 'unit', 'alpha');
alpha = green.clone();
if ('%' == alpha.type) alpha.val /= 100;
return new nodes.RGBA(
color.r
, color.g
, color.b
, alpha.val);
default:
utils.assertType(red, 'unit', 'red');
utils.assertType(green, 'unit', 'green');
utils.assertType(blue, 'unit', 'blue');
utils.assertType(alpha, 'unit', 'alpha');
var r = '%' == red.type ? Math.round(red.val * 2.55) : red.val
, g = '%' == green.type ? Math.round(green.val * 2.55) : green.val
, b = '%' == blue.type ? Math.round(blue.val * 2.55) : blue.val;
alpha = alpha.clone();
if (alpha && '%' == alpha.type) alpha.val /= 100;
return new nodes.RGBA(
r
, g
, b
, alpha.val);
}
} | javascript | function rgba(red, green, blue, alpha){
switch (arguments.length) {
case 1:
utils.assertColor(red);
return red.rgba;
case 2:
utils.assertColor(red);
var color = red.rgba;
utils.assertType(green, 'unit', 'alpha');
alpha = green.clone();
if ('%' == alpha.type) alpha.val /= 100;
return new nodes.RGBA(
color.r
, color.g
, color.b
, alpha.val);
default:
utils.assertType(red, 'unit', 'red');
utils.assertType(green, 'unit', 'green');
utils.assertType(blue, 'unit', 'blue');
utils.assertType(alpha, 'unit', 'alpha');
var r = '%' == red.type ? Math.round(red.val * 2.55) : red.val
, g = '%' == green.type ? Math.round(green.val * 2.55) : green.val
, b = '%' == blue.type ? Math.round(blue.val * 2.55) : blue.val;
alpha = alpha.clone();
if (alpha && '%' == alpha.type) alpha.val /= 100;
return new nodes.RGBA(
r
, g
, b
, alpha.val);
}
} | [
"function",
"rgba",
"(",
"red",
",",
"green",
",",
"blue",
",",
"alpha",
")",
"{",
"switch",
"(",
"arguments",
".",
"length",
")",
"{",
"case",
"1",
":",
"utils",
".",
"assertColor",
"(",
"red",
")",
";",
"return",
"red",
".",
"rgba",
";",
"case",
... | Return a `RGBA` from the r,g,b,a channels.
Examples:
rgba(255,0,0,0.5)
// => rgba(255,0,0,0.5)
rgba(255,0,0,1)
// => #ff0000
rgba(#ffcc00, 50%)
// rgba(255,204,0,0.5)
@param {Unit|RGBA|HSLA} red
@param {Unit} green
@param {Unit} blue
@param {Unit} alpha
@return {RGBA}
@api public | [
"Return",
"a",
"RGBA",
"from",
"the",
"r",
"g",
"b",
"a",
"channels",
"."
] | 7e98dc17368c62a6f8a95aa2e300e4ab02faf007 | https://github.com/stylus/stylus/blob/7e98dc17368c62a6f8a95aa2e300e4ab02faf007/lib/functions/rgba.js#L26-L59 |
5,858 | stylus/stylus | lib/functions/basename.js | basename | function basename(p, ext){
utils.assertString(p, 'path');
return path.basename(p.val, ext && ext.val);
} | javascript | function basename(p, ext){
utils.assertString(p, 'path');
return path.basename(p.val, ext && ext.val);
} | [
"function",
"basename",
"(",
"p",
",",
"ext",
")",
"{",
"utils",
".",
"assertString",
"(",
"p",
",",
"'path'",
")",
";",
"return",
"path",
".",
"basename",
"(",
"p",
".",
"val",
",",
"ext",
"&&",
"ext",
".",
"val",
")",
";",
"}"
] | Return the basename of `path`.
@param {String} path
@return {String}
@api public | [
"Return",
"the",
"basename",
"of",
"path",
"."
] | 7e98dc17368c62a6f8a95aa2e300e4ab02faf007 | https://github.com/stylus/stylus/blob/7e98dc17368c62a6f8a95aa2e300e4ab02faf007/lib/functions/basename.js#L12-L15 |
5,859 | stylus/stylus | lib/functions/operate.js | operate | function operate(op, left, right){
utils.assertType(op, 'string', 'op');
utils.assertPresent(left, 'left');
utils.assertPresent(right, 'right');
return left.operate(op.val, right);
} | javascript | function operate(op, left, right){
utils.assertType(op, 'string', 'op');
utils.assertPresent(left, 'left');
utils.assertPresent(right, 'right');
return left.operate(op.val, right);
} | [
"function",
"operate",
"(",
"op",
",",
"left",
",",
"right",
")",
"{",
"utils",
".",
"assertType",
"(",
"op",
",",
"'string'",
",",
"'op'",
")",
";",
"utils",
".",
"assertPresent",
"(",
"left",
",",
"'left'",
")",
";",
"utils",
".",
"assertPresent",
... | Perform `op` on the `left` and `right` operands.
@param {String} op
@param {Node} left
@param {Node} right
@return {Node}
@api public | [
"Perform",
"op",
"on",
"the",
"left",
"and",
"right",
"operands",
"."
] | 7e98dc17368c62a6f8a95aa2e300e4ab02faf007 | https://github.com/stylus/stylus/blob/7e98dc17368c62a6f8a95aa2e300e4ab02faf007/lib/functions/operate.js#L13-L18 |
5,860 | stylus/stylus | lib/functions/math.js | math | function math(n, fn){
utils.assertType(n, 'unit', 'n');
utils.assertString(fn, 'fn');
return new nodes.Unit(Math[fn.string](n.val), n.type);
} | javascript | function math(n, fn){
utils.assertType(n, 'unit', 'n');
utils.assertString(fn, 'fn');
return new nodes.Unit(Math[fn.string](n.val), n.type);
} | [
"function",
"math",
"(",
"n",
",",
"fn",
")",
"{",
"utils",
".",
"assertType",
"(",
"n",
",",
"'unit'",
",",
"'n'",
")",
";",
"utils",
".",
"assertString",
"(",
"fn",
",",
"'fn'",
")",
";",
"return",
"new",
"nodes",
".",
"Unit",
"(",
"Math",
"[",... | Apply Math `fn` to `n`.
@param {Unit} n
@param {String} fn
@return {Unit}
@api private | [
"Apply",
"Math",
"fn",
"to",
"n",
"."
] | 7e98dc17368c62a6f8a95aa2e300e4ab02faf007 | https://github.com/stylus/stylus/blob/7e98dc17368c62a6f8a95aa2e300e4ab02faf007/lib/functions/math.js#L13-L17 |
5,861 | stylus/stylus | lib/lexer.js | Lexer | function Lexer(str, options) {
options = options || {};
this.stash = [];
this.indentStack = [];
this.indentRe = null;
this.lineno = 1;
this.column = 1;
// HACK!
function comment(str, val, offset, s) {
var inComment = s.lastIndexOf('/*', offset) > s.lastIndexOf('*/', offset)
, commentIdx = s.lastIndexOf('//', offset)
, i = s.lastIndexOf('\n', offset)
, double = 0
, single = 0;
if (~commentIdx && commentIdx > i) {
while (i != offset) {
if ("'" == s[i]) single ? single-- : single++;
if ('"' == s[i]) double ? double-- : double++;
if ('/' == s[i] && '/' == s[i + 1]) {
inComment = !single && !double;
break;
}
++i;
}
}
return inComment
? str
: ((val === ',' && /^[,\t\n]+$/.test(str)) ? str.replace(/\n/, '\r') : val + '\r');
};
// Remove UTF-8 BOM.
if ('\uFEFF' == str.charAt(0)) str = str.slice(1);
this.str = str
.replace(/\s+$/, '\n')
.replace(/\r\n?/g, '\n')
.replace(/\\ *\n/g, '\r')
.replace(/([,(:](?!\/\/[^ ])) *(?:\/\/[^\n]*|\/\*.*?\*\/)?\n\s*/g, comment)
.replace(/\s*\n[ \t]*([,)])/g, comment);
} | javascript | function Lexer(str, options) {
options = options || {};
this.stash = [];
this.indentStack = [];
this.indentRe = null;
this.lineno = 1;
this.column = 1;
// HACK!
function comment(str, val, offset, s) {
var inComment = s.lastIndexOf('/*', offset) > s.lastIndexOf('*/', offset)
, commentIdx = s.lastIndexOf('//', offset)
, i = s.lastIndexOf('\n', offset)
, double = 0
, single = 0;
if (~commentIdx && commentIdx > i) {
while (i != offset) {
if ("'" == s[i]) single ? single-- : single++;
if ('"' == s[i]) double ? double-- : double++;
if ('/' == s[i] && '/' == s[i + 1]) {
inComment = !single && !double;
break;
}
++i;
}
}
return inComment
? str
: ((val === ',' && /^[,\t\n]+$/.test(str)) ? str.replace(/\n/, '\r') : val + '\r');
};
// Remove UTF-8 BOM.
if ('\uFEFF' == str.charAt(0)) str = str.slice(1);
this.str = str
.replace(/\s+$/, '\n')
.replace(/\r\n?/g, '\n')
.replace(/\\ *\n/g, '\r')
.replace(/([,(:](?!\/\/[^ ])) *(?:\/\/[^\n]*|\/\*.*?\*\/)?\n\s*/g, comment)
.replace(/\s*\n[ \t]*([,)])/g, comment);
} | [
"function",
"Lexer",
"(",
"str",
",",
"options",
")",
"{",
"options",
"=",
"options",
"||",
"{",
"}",
";",
"this",
".",
"stash",
"=",
"[",
"]",
";",
"this",
".",
"indentStack",
"=",
"[",
"]",
";",
"this",
".",
"indentRe",
"=",
"null",
";",
"this"... | Initialize a new `Lexer` with the given `str` and `options`.
@param {String} str
@param {Object} options
@api private | [
"Initialize",
"a",
"new",
"Lexer",
"with",
"the",
"given",
"str",
"and",
"options",
"."
] | 7e98dc17368c62a6f8a95aa2e300e4ab02faf007 | https://github.com/stylus/stylus/blob/7e98dc17368c62a6f8a95aa2e300e4ab02faf007/lib/lexer.js#L43-L86 |
5,862 | stylus/stylus | lib/lexer.js | function(){
var tok
, tmp = this.str
, buf = [];
while ('eos' != (tok = this.next()).type) {
buf.push(tok.inspect());
}
this.str = tmp;
return buf.concat(tok.inspect()).join('\n');
} | javascript | function(){
var tok
, tmp = this.str
, buf = [];
while ('eos' != (tok = this.next()).type) {
buf.push(tok.inspect());
}
this.str = tmp;
return buf.concat(tok.inspect()).join('\n');
} | [
"function",
"(",
")",
"{",
"var",
"tok",
",",
"tmp",
"=",
"this",
".",
"str",
",",
"buf",
"=",
"[",
"]",
";",
"while",
"(",
"'eos'",
"!=",
"(",
"tok",
"=",
"this",
".",
"next",
"(",
")",
")",
".",
"type",
")",
"{",
"buf",
".",
"push",
"(",
... | Custom inspect. | [
"Custom",
"inspect",
"."
] | 7e98dc17368c62a6f8a95aa2e300e4ab02faf007 | https://github.com/stylus/stylus/blob/7e98dc17368c62a6f8a95aa2e300e4ab02faf007/lib/lexer.js#L98-L107 | |
5,863 | stylus/stylus | lib/lexer.js | function(n){
var fetch = n - this.stash.length;
while (fetch-- > 0) this.stash.push(this.advance());
return this.stash[--n];
} | javascript | function(n){
var fetch = n - this.stash.length;
while (fetch-- > 0) this.stash.push(this.advance());
return this.stash[--n];
} | [
"function",
"(",
"n",
")",
"{",
"var",
"fetch",
"=",
"n",
"-",
"this",
".",
"stash",
".",
"length",
";",
"while",
"(",
"fetch",
"--",
">",
"0",
")",
"this",
".",
"stash",
".",
"push",
"(",
"this",
".",
"advance",
"(",
")",
")",
";",
"return",
... | Lookahead `n` tokens.
@param {Number} n
@return {Object}
@api private | [
"Lookahead",
"n",
"tokens",
"."
] | 7e98dc17368c62a6f8a95aa2e300e4ab02faf007 | https://github.com/stylus/stylus/blob/7e98dc17368c62a6f8a95aa2e300e4ab02faf007/lib/lexer.js#L117-L121 | |
5,864 | stylus/stylus | lib/lexer.js | function(len){
var chunk = len[0];
len = chunk ? chunk.length : len;
this.str = this.str.substr(len);
if (chunk) {
this.move(chunk);
} else {
this.column += len;
}
} | javascript | function(len){
var chunk = len[0];
len = chunk ? chunk.length : len;
this.str = this.str.substr(len);
if (chunk) {
this.move(chunk);
} else {
this.column += len;
}
} | [
"function",
"(",
"len",
")",
"{",
"var",
"chunk",
"=",
"len",
"[",
"0",
"]",
";",
"len",
"=",
"chunk",
"?",
"chunk",
".",
"length",
":",
"len",
";",
"this",
".",
"str",
"=",
"this",
".",
"str",
".",
"substr",
"(",
"len",
")",
";",
"if",
"(",
... | Consume the given `len`.
@param {Number|Array} len
@api private | [
"Consume",
"the",
"given",
"len",
"."
] | 7e98dc17368c62a6f8a95aa2e300e4ab02faf007 | https://github.com/stylus/stylus/blob/7e98dc17368c62a6f8a95aa2e300e4ab02faf007/lib/lexer.js#L130-L139 | |
5,865 | stylus/stylus | lib/lexer.js | function(str){
var lines = str.match(/\n/g)
, idx = str.lastIndexOf('\n');
if (lines) this.lineno += lines.length;
this.column = ~idx
? str.length - idx
: this.column + str.length;
} | javascript | function(str){
var lines = str.match(/\n/g)
, idx = str.lastIndexOf('\n');
if (lines) this.lineno += lines.length;
this.column = ~idx
? str.length - idx
: this.column + str.length;
} | [
"function",
"(",
"str",
")",
"{",
"var",
"lines",
"=",
"str",
".",
"match",
"(",
"/",
"\\n",
"/",
"g",
")",
",",
"idx",
"=",
"str",
".",
"lastIndexOf",
"(",
"'\\n'",
")",
";",
"if",
"(",
"lines",
")",
"this",
".",
"lineno",
"+=",
"lines",
".",
... | Move current line and column position.
@param {String} str
@api private | [
"Move",
"current",
"line",
"and",
"column",
"position",
"."
] | 7e98dc17368c62a6f8a95aa2e300e4ab02faf007 | https://github.com/stylus/stylus/blob/7e98dc17368c62a6f8a95aa2e300e4ab02faf007/lib/lexer.js#L148-L156 | |
5,866 | stylus/stylus | lib/lexer.js | function() {
var tok = this.stash[this.stash.length - 1] || this.prev;
switch (tok && tok.type) {
// #for
case 'color':
return 2 == tok.val.raw.length;
// .or
case '.':
// [is]
case '[':
return true;
}
return false;
} | javascript | function() {
var tok = this.stash[this.stash.length - 1] || this.prev;
switch (tok && tok.type) {
// #for
case 'color':
return 2 == tok.val.raw.length;
// .or
case '.':
// [is]
case '[':
return true;
}
return false;
} | [
"function",
"(",
")",
"{",
"var",
"tok",
"=",
"this",
".",
"stash",
"[",
"this",
".",
"stash",
".",
"length",
"-",
"1",
"]",
"||",
"this",
".",
"prev",
";",
"switch",
"(",
"tok",
"&&",
"tok",
".",
"type",
")",
"{",
"// #for",
"case",
"'color'",
... | Check if the current token is a part of selector.
@return {Boolean}
@api private | [
"Check",
"if",
"the",
"current",
"token",
"is",
"a",
"part",
"of",
"selector",
"."
] | 7e98dc17368c62a6f8a95aa2e300e4ab02faf007 | https://github.com/stylus/stylus/blob/7e98dc17368c62a6f8a95aa2e300e4ab02faf007/lib/lexer.js#L178-L191 | |
5,867 | stylus/stylus | lib/lexer.js | function() {
var column = this.column
, line = this.lineno
, tok = this.eos()
|| this.null()
|| this.sep()
|| this.keyword()
|| this.urlchars()
|| this.comment()
|| this.newline()
|| this.escaped()
|| this.important()
|| this.literal()
|| this.anonFunc()
|| this.atrule()
|| this.function()
|| this.brace()
|| this.paren()
|| this.color()
|| this.string()
|| this.unit()
|| this.namedop()
|| this.boolean()
|| this.unicode()
|| this.ident()
|| this.op()
|| (function () {
var token = this.eol();
if (token) {
column = token.column;
line = token.lineno;
}
return token;
}).call(this)
|| this.space()
|| this.selector();
tok.lineno = line;
tok.column = column;
return tok;
} | javascript | function() {
var column = this.column
, line = this.lineno
, tok = this.eos()
|| this.null()
|| this.sep()
|| this.keyword()
|| this.urlchars()
|| this.comment()
|| this.newline()
|| this.escaped()
|| this.important()
|| this.literal()
|| this.anonFunc()
|| this.atrule()
|| this.function()
|| this.brace()
|| this.paren()
|| this.color()
|| this.string()
|| this.unit()
|| this.namedop()
|| this.boolean()
|| this.unicode()
|| this.ident()
|| this.op()
|| (function () {
var token = this.eol();
if (token) {
column = token.column;
line = token.lineno;
}
return token;
}).call(this)
|| this.space()
|| this.selector();
tok.lineno = line;
tok.column = column;
return tok;
} | [
"function",
"(",
")",
"{",
"var",
"column",
"=",
"this",
".",
"column",
",",
"line",
"=",
"this",
".",
"lineno",
",",
"tok",
"=",
"this",
".",
"eos",
"(",
")",
"||",
"this",
".",
"null",
"(",
")",
"||",
"this",
".",
"sep",
"(",
")",
"||",
"th... | Fetch next token.
@return {Token}
@api private | [
"Fetch",
"next",
"token",
"."
] | 7e98dc17368c62a6f8a95aa2e300e4ab02faf007 | https://github.com/stylus/stylus/blob/7e98dc17368c62a6f8a95aa2e300e4ab02faf007/lib/lexer.js#L200-L243 | |
5,868 | stylus/stylus | lib/lexer.js | function() {
var captures
, tok;
if (captures = /^(not|and|or|is a|is defined|isnt|is not|is)(?!-)\b([ \t]*)/.exec(this.str)) {
var op = captures[1];
this.skip(captures);
if (this.isPartOfSelector()) {
tok = new Token('ident', new nodes.Ident(captures[0]));
} else {
op = alias[op] || op;
tok = new Token(op, op);
}
tok.space = captures[2];
return tok;
}
} | javascript | function() {
var captures
, tok;
if (captures = /^(not|and|or|is a|is defined|isnt|is not|is)(?!-)\b([ \t]*)/.exec(this.str)) {
var op = captures[1];
this.skip(captures);
if (this.isPartOfSelector()) {
tok = new Token('ident', new nodes.Ident(captures[0]));
} else {
op = alias[op] || op;
tok = new Token(op, op);
}
tok.space = captures[2];
return tok;
}
} | [
"function",
"(",
")",
"{",
"var",
"captures",
",",
"tok",
";",
"if",
"(",
"captures",
"=",
"/",
"^(not|and|or|is a|is defined|isnt|is not|is)(?!-)\\b([ \\t]*)",
"/",
".",
"exec",
"(",
"this",
".",
"str",
")",
")",
"{",
"var",
"op",
"=",
"captures",
"[",
"1... | 'not'
| 'and'
| 'or'
| 'is'
| 'is not'
| 'isnt'
| 'is a'
| 'is defined' | [
"not",
"|",
"and",
"|",
"or",
"|",
"is",
"|",
"is",
"not",
"|",
"isnt",
"|",
"is",
"a",
"|",
"is",
"defined"
] | 7e98dc17368c62a6f8a95aa2e300e4ab02faf007 | https://github.com/stylus/stylus/blob/7e98dc17368c62a6f8a95aa2e300e4ab02faf007/lib/lexer.js#L474-L489 | |
5,869 | stylus/stylus | lib/lexer.js | function() {
var captures;
if (captures = /^(true|false)\b([ \t]*)/.exec(this.str)) {
var val = nodes.Boolean('true' == captures[1]);
this.skip(captures);
var tok = new Token('boolean', val);
tok.space = captures[2];
return tok;
}
} | javascript | function() {
var captures;
if (captures = /^(true|false)\b([ \t]*)/.exec(this.str)) {
var val = nodes.Boolean('true' == captures[1]);
this.skip(captures);
var tok = new Token('boolean', val);
tok.space = captures[2];
return tok;
}
} | [
"function",
"(",
")",
"{",
"var",
"captures",
";",
"if",
"(",
"captures",
"=",
"/",
"^(true|false)\\b([ \\t]*)",
"/",
".",
"exec",
"(",
"this",
".",
"str",
")",
")",
"{",
"var",
"val",
"=",
"nodes",
".",
"Boolean",
"(",
"'true'",
"==",
"captures",
"[... | 'true' | 'false' | [
"true",
"|",
"false"
] | 7e98dc17368c62a6f8a95aa2e300e4ab02faf007 | https://github.com/stylus/stylus/blob/7e98dc17368c62a6f8a95aa2e300e4ab02faf007/lib/lexer.js#L627-L636 | |
5,870 | stylus/stylus | lib/lexer.js | function() {
var captures, re;
// we have established the indentation regexp
if (this.indentRe){
captures = this.indentRe.exec(this.str);
// figure out if we are using tabs or spaces
} else {
// try tabs
re = /^\n([\t]*)[ \t]*/;
captures = re.exec(this.str);
// nope, try spaces
if (captures && !captures[1].length) {
re = /^\n([ \t]*)/;
captures = re.exec(this.str);
}
// established
if (captures && captures[1].length) this.indentRe = re;
}
if (captures) {
var tok
, indents = captures[1].length;
this.skip(captures);
if (this.str[0] === ' ' || this.str[0] === '\t') {
throw new errors.SyntaxError('Invalid indentation. You can use tabs or spaces to indent, but not both.');
}
// Blank line
if ('\n' == this.str[0]) return this.advance();
// Outdent
if (this.indentStack.length && indents < this.indentStack[0]) {
while (this.indentStack.length && this.indentStack[0] > indents) {
this.stash.push(new Token('outdent'));
this.indentStack.shift();
}
tok = this.stash.pop();
// Indent
} else if (indents && indents != this.indentStack[0]) {
this.indentStack.unshift(indents);
tok = new Token('indent');
// Newline
} else {
tok = new Token('newline');
}
return tok;
}
} | javascript | function() {
var captures, re;
// we have established the indentation regexp
if (this.indentRe){
captures = this.indentRe.exec(this.str);
// figure out if we are using tabs or spaces
} else {
// try tabs
re = /^\n([\t]*)[ \t]*/;
captures = re.exec(this.str);
// nope, try spaces
if (captures && !captures[1].length) {
re = /^\n([ \t]*)/;
captures = re.exec(this.str);
}
// established
if (captures && captures[1].length) this.indentRe = re;
}
if (captures) {
var tok
, indents = captures[1].length;
this.skip(captures);
if (this.str[0] === ' ' || this.str[0] === '\t') {
throw new errors.SyntaxError('Invalid indentation. You can use tabs or spaces to indent, but not both.');
}
// Blank line
if ('\n' == this.str[0]) return this.advance();
// Outdent
if (this.indentStack.length && indents < this.indentStack[0]) {
while (this.indentStack.length && this.indentStack[0] > indents) {
this.stash.push(new Token('outdent'));
this.indentStack.shift();
}
tok = this.stash.pop();
// Indent
} else if (indents && indents != this.indentStack[0]) {
this.indentStack.unshift(indents);
tok = new Token('indent');
// Newline
} else {
tok = new Token('newline');
}
return tok;
}
} | [
"function",
"(",
")",
"{",
"var",
"captures",
",",
"re",
";",
"// we have established the indentation regexp",
"if",
"(",
"this",
".",
"indentRe",
")",
"{",
"captures",
"=",
"this",
".",
"indentRe",
".",
"exec",
"(",
"this",
".",
"str",
")",
";",
"// figur... | '\n' ' '+ | [
"\\",
"n",
"+"
] | 7e98dc17368c62a6f8a95aa2e300e4ab02faf007 | https://github.com/stylus/stylus/blob/7e98dc17368c62a6f8a95aa2e300e4ab02faf007/lib/lexer.js#L682-L735 | |
5,871 | stylus/stylus | lib/functions/lightness.js | lightness | function lightness(color, value){
if (value) {
var hslaColor = color.hsla;
return hsla(
new nodes.Unit(hslaColor.h),
new nodes.Unit(hslaColor.s),
value,
new nodes.Unit(hslaColor.a)
)
}
return component(color, new nodes.String('lightness'));
} | javascript | function lightness(color, value){
if (value) {
var hslaColor = color.hsla;
return hsla(
new nodes.Unit(hslaColor.h),
new nodes.Unit(hslaColor.s),
value,
new nodes.Unit(hslaColor.a)
)
}
return component(color, new nodes.String('lightness'));
} | [
"function",
"lightness",
"(",
"color",
",",
"value",
")",
"{",
"if",
"(",
"value",
")",
"{",
"var",
"hslaColor",
"=",
"color",
".",
"hsla",
";",
"return",
"hsla",
"(",
"new",
"nodes",
".",
"Unit",
"(",
"hslaColor",
".",
"h",
")",
",",
"new",
"nodes... | Return the lightness component of the given `color`,
or set the lightness component to the optional second `value` argument.
Examples:
lightness(#00c)
// => 100%
lightness(#00c, 80%)
// => #99f
@param {RGBA|HSLA} color
@param {Unit} [value]
@return {Unit|RGBA}
@api public | [
"Return",
"the",
"lightness",
"component",
"of",
"the",
"given",
"color",
"or",
"set",
"the",
"lightness",
"component",
"to",
"the",
"optional",
"second",
"value",
"argument",
"."
] | 7e98dc17368c62a6f8a95aa2e300e4ab02faf007 | https://github.com/stylus/stylus/blob/7e98dc17368c62a6f8a95aa2e300e4ab02faf007/lib/functions/lightness.js#L23-L34 |
5,872 | stylus/stylus | lib/errors.js | ParseError | function ParseError(msg) {
this.name = 'ParseError';
this.message = msg;
if (Error.captureStackTrace) {
Error.captureStackTrace(this, ParseError);
}
} | javascript | function ParseError(msg) {
this.name = 'ParseError';
this.message = msg;
if (Error.captureStackTrace) {
Error.captureStackTrace(this, ParseError);
}
} | [
"function",
"ParseError",
"(",
"msg",
")",
"{",
"this",
".",
"name",
"=",
"'ParseError'",
";",
"this",
".",
"message",
"=",
"msg",
";",
"if",
"(",
"Error",
".",
"captureStackTrace",
")",
"{",
"Error",
".",
"captureStackTrace",
"(",
"this",
",",
"ParseErr... | Initialize a new `ParseError` with the given `msg`.
@param {String} msg
@api private | [
"Initialize",
"a",
"new",
"ParseError",
"with",
"the",
"given",
"msg",
"."
] | 7e98dc17368c62a6f8a95aa2e300e4ab02faf007 | https://github.com/stylus/stylus/blob/7e98dc17368c62a6f8a95aa2e300e4ab02faf007/lib/errors.js#L22-L28 |
5,873 | stylus/stylus | lib/functions/blend.js | blend | function blend(top, bottom){
// TODO: different blend modes like overlay etc.
utils.assertColor(top);
top = top.rgba;
bottom = bottom || new nodes.RGBA(255, 255, 255, 1);
utils.assertColor(bottom);
bottom = bottom.rgba;
return new nodes.RGBA(
top.r * top.a + bottom.r * (1 - top.a),
top.g * top.a + bottom.g * (1 - top.a),
top.b * top.a + bottom.b * (1 - top.a),
top.a + bottom.a - top.a * bottom.a);
} | javascript | function blend(top, bottom){
// TODO: different blend modes like overlay etc.
utils.assertColor(top);
top = top.rgba;
bottom = bottom || new nodes.RGBA(255, 255, 255, 1);
utils.assertColor(bottom);
bottom = bottom.rgba;
return new nodes.RGBA(
top.r * top.a + bottom.r * (1 - top.a),
top.g * top.a + bottom.g * (1 - top.a),
top.b * top.a + bottom.b * (1 - top.a),
top.a + bottom.a - top.a * bottom.a);
} | [
"function",
"blend",
"(",
"top",
",",
"bottom",
")",
"{",
"// TODO: different blend modes like overlay etc.",
"utils",
".",
"assertColor",
"(",
"top",
")",
";",
"top",
"=",
"top",
".",
"rgba",
";",
"bottom",
"=",
"bottom",
"||",
"new",
"nodes",
".",
"RGBA",
... | Blend the `top` color over the `bottom`
Examples:
blend(rgba(#FFF, 0.5), #000)
// => #808080
blend(rgba(#FFDE00,.42), #19C261)
// => #7ace38
blend(rgba(lime, 0.5), rgba(red, 0.25))
// => rgba(128,128,0,0.625)
@param {RGBA|HSLA} top
@param {RGBA|HSLA} [bottom=#fff]
@return {RGBA}
@api public | [
"Blend",
"the",
"top",
"color",
"over",
"the",
"bottom"
] | 7e98dc17368c62a6f8a95aa2e300e4ab02faf007 | https://github.com/stylus/stylus/blob/7e98dc17368c62a6f8a95aa2e300e4ab02faf007/lib/functions/blend.js#L24-L37 |
5,874 | stylus/stylus | lib/functions/hue.js | hue | function hue(color, value){
if (value) {
var hslaColor = color.hsla;
return hsla(
value,
new nodes.Unit(hslaColor.s),
new nodes.Unit(hslaColor.l),
new nodes.Unit(hslaColor.a)
)
}
return component(color, new nodes.String('hue'));
} | javascript | function hue(color, value){
if (value) {
var hslaColor = color.hsla;
return hsla(
value,
new nodes.Unit(hslaColor.s),
new nodes.Unit(hslaColor.l),
new nodes.Unit(hslaColor.a)
)
}
return component(color, new nodes.String('hue'));
} | [
"function",
"hue",
"(",
"color",
",",
"value",
")",
"{",
"if",
"(",
"value",
")",
"{",
"var",
"hslaColor",
"=",
"color",
".",
"hsla",
";",
"return",
"hsla",
"(",
"value",
",",
"new",
"nodes",
".",
"Unit",
"(",
"hslaColor",
".",
"s",
")",
",",
"ne... | Return the hue component of the given `color`,
or set the hue component to the optional second `value` argument.
Examples:
hue(#00c)
// => 240deg
hue(#00c, 90deg)
// => #6c0
@param {RGBA|HSLA} color
@param {Unit} [value]
@return {Unit|RGBA}
@api public | [
"Return",
"the",
"hue",
"component",
"of",
"the",
"given",
"color",
"or",
"set",
"the",
"hue",
"component",
"to",
"the",
"optional",
"second",
"value",
"argument",
"."
] | 7e98dc17368c62a6f8a95aa2e300e4ab02faf007 | https://github.com/stylus/stylus/blob/7e98dc17368c62a6f8a95aa2e300e4ab02faf007/lib/functions/hue.js#L23-L34 |
5,875 | stylus/stylus | lib/functions/split.js | split | function split(delim, val){
utils.assertString(delim, 'delimiter');
utils.assertString(val, 'val');
var splitted = val.string.split(delim.string);
var expr = new nodes.Expression();
var ItemNode = val instanceof nodes.Ident
? nodes.Ident
: nodes.String;
for (var i = 0, len = splitted.length; i < len; ++i) {
expr.nodes.push(new ItemNode(splitted[i]));
}
return expr;
} | javascript | function split(delim, val){
utils.assertString(delim, 'delimiter');
utils.assertString(val, 'val');
var splitted = val.string.split(delim.string);
var expr = new nodes.Expression();
var ItemNode = val instanceof nodes.Ident
? nodes.Ident
: nodes.String;
for (var i = 0, len = splitted.length; i < len; ++i) {
expr.nodes.push(new ItemNode(splitted[i]));
}
return expr;
} | [
"function",
"split",
"(",
"delim",
",",
"val",
")",
"{",
"utils",
".",
"assertString",
"(",
"delim",
",",
"'delimiter'",
")",
";",
"utils",
".",
"assertString",
"(",
"val",
",",
"'val'",
")",
";",
"var",
"splitted",
"=",
"val",
".",
"string",
".",
"s... | Splits the given `val` by `delim`
@param {String} delim
@param {String|Ident} val
@return {Expression}
@api public | [
"Splits",
"the",
"given",
"val",
"by",
"delim"
] | 7e98dc17368c62a6f8a95aa2e300e4ab02faf007 | https://github.com/stylus/stylus/blob/7e98dc17368c62a6f8a95aa2e300e4ab02faf007/lib/functions/split.js#L13-L25 |
5,876 | stylus/stylus | lib/functions/replace.js | replace | function replace(pattern, replacement, val){
utils.assertString(pattern, 'pattern');
utils.assertString(replacement, 'replacement');
utils.assertString(val, 'val');
pattern = new RegExp(pattern.string, 'g');
var res = val.string.replace(pattern, replacement.string);
return val instanceof nodes.Ident
? new nodes.Ident(res)
: new nodes.String(res);
} | javascript | function replace(pattern, replacement, val){
utils.assertString(pattern, 'pattern');
utils.assertString(replacement, 'replacement');
utils.assertString(val, 'val');
pattern = new RegExp(pattern.string, 'g');
var res = val.string.replace(pattern, replacement.string);
return val instanceof nodes.Ident
? new nodes.Ident(res)
: new nodes.String(res);
} | [
"function",
"replace",
"(",
"pattern",
",",
"replacement",
",",
"val",
")",
"{",
"utils",
".",
"assertString",
"(",
"pattern",
",",
"'pattern'",
")",
";",
"utils",
".",
"assertString",
"(",
"replacement",
",",
"'replacement'",
")",
";",
"utils",
".",
"asse... | Returns string with all matches of `pattern` replaced by `replacement` in given `val`
@param {String} pattern
@param {String} replacement
@param {String|Ident} val
@return {String|Ident}
@api public | [
"Returns",
"string",
"with",
"all",
"matches",
"of",
"pattern",
"replaced",
"by",
"replacement",
"in",
"given",
"val"
] | 7e98dc17368c62a6f8a95aa2e300e4ab02faf007 | https://github.com/stylus/stylus/blob/7e98dc17368c62a6f8a95aa2e300e4ab02faf007/lib/functions/replace.js#L14-L23 |
5,877 | stylus/stylus | lib/middleware.js | compile | function compile() {
debug('read %s', cssPath);
fs.readFile(stylusPath, 'utf8', function(err, str){
if (err) return error(err);
var style = options.compile(str, stylusPath);
var paths = style.options._imports = [];
imports[stylusPath] = null;
style.render(function(err, css){
if (err) return next(err);
debug('render %s', stylusPath);
imports[stylusPath] = paths;
mkdir(dirname(cssPath), { mode: parseInt('0700', 8), recursive: true }, function(err){
if (err) return error(err);
fs.writeFile(cssPath, css, 'utf8', next);
});
});
});
} | javascript | function compile() {
debug('read %s', cssPath);
fs.readFile(stylusPath, 'utf8', function(err, str){
if (err) return error(err);
var style = options.compile(str, stylusPath);
var paths = style.options._imports = [];
imports[stylusPath] = null;
style.render(function(err, css){
if (err) return next(err);
debug('render %s', stylusPath);
imports[stylusPath] = paths;
mkdir(dirname(cssPath), { mode: parseInt('0700', 8), recursive: true }, function(err){
if (err) return error(err);
fs.writeFile(cssPath, css, 'utf8', next);
});
});
});
} | [
"function",
"compile",
"(",
")",
"{",
"debug",
"(",
"'read %s'",
",",
"cssPath",
")",
";",
"fs",
".",
"readFile",
"(",
"stylusPath",
",",
"'utf8'",
",",
"function",
"(",
"err",
",",
"str",
")",
"{",
"if",
"(",
"err",
")",
"return",
"error",
"(",
"e... | Compile to cssPath | [
"Compile",
"to",
"cssPath"
] | 7e98dc17368c62a6f8a95aa2e300e4ab02faf007 | https://github.com/stylus/stylus/blob/7e98dc17368c62a6f8a95aa2e300e4ab02faf007/lib/middleware.js#L149-L166 |
5,878 | stylus/stylus | lib/middleware.js | compare | function compare(pathA, pathB) {
pathA = pathA.split(sep);
pathB = pathB.split('/');
if (!pathA[pathA.length - 1]) pathA.pop();
if (!pathB[0]) pathB.shift();
var overlap = [];
while (pathA[pathA.length - 1] == pathB[0]) {
overlap.push(pathA.pop());
pathB.shift();
}
return overlap.join('/');
} | javascript | function compare(pathA, pathB) {
pathA = pathA.split(sep);
pathB = pathB.split('/');
if (!pathA[pathA.length - 1]) pathA.pop();
if (!pathB[0]) pathB.shift();
var overlap = [];
while (pathA[pathA.length - 1] == pathB[0]) {
overlap.push(pathA.pop());
pathB.shift();
}
return overlap.join('/');
} | [
"function",
"compare",
"(",
"pathA",
",",
"pathB",
")",
"{",
"pathA",
"=",
"pathA",
".",
"split",
"(",
"sep",
")",
";",
"pathB",
"=",
"pathB",
".",
"split",
"(",
"'/'",
")",
";",
"if",
"(",
"!",
"pathA",
"[",
"pathA",
".",
"length",
"-",
"1",
"... | get the overlaping path from the end of path A, and the begining of path B.
@param {String} pathA
@param {String} pathB
@return {String}
@api private | [
"get",
"the",
"overlaping",
"path",
"from",
"the",
"end",
"of",
"path",
"A",
"and",
"the",
"begining",
"of",
"path",
"B",
"."
] | 7e98dc17368c62a6f8a95aa2e300e4ab02faf007 | https://github.com/stylus/stylus/blob/7e98dc17368c62a6f8a95aa2e300e4ab02faf007/lib/middleware.js#L245-L257 |
5,879 | stylus/stylus | lib/functions/prefix-classes.js | prefixClasses | function prefixClasses(prefix, block){
utils.assertString(prefix, 'prefix');
utils.assertType(block, 'block', 'block');
var _prefix = this.prefix;
this.options.prefix = this.prefix = prefix.string;
block = this.visit(block);
this.options.prefix = this.prefix = _prefix;
return block;
} | javascript | function prefixClasses(prefix, block){
utils.assertString(prefix, 'prefix');
utils.assertType(block, 'block', 'block');
var _prefix = this.prefix;
this.options.prefix = this.prefix = prefix.string;
block = this.visit(block);
this.options.prefix = this.prefix = _prefix;
return block;
} | [
"function",
"prefixClasses",
"(",
"prefix",
",",
"block",
")",
"{",
"utils",
".",
"assertString",
"(",
"prefix",
",",
"'prefix'",
")",
";",
"utils",
".",
"assertType",
"(",
"block",
",",
"'block'",
",",
"'block'",
")",
";",
"var",
"_prefix",
"=",
"this",... | Prefix css classes in a block
@param {String} prefix
@param {Block} block
@return {Block}
@api private | [
"Prefix",
"css",
"classes",
"in",
"a",
"block"
] | 7e98dc17368c62a6f8a95aa2e300e4ab02faf007 | https://github.com/stylus/stylus/blob/7e98dc17368c62a6f8a95aa2e300e4ab02faf007/lib/functions/prefix-classes.js#L12-L22 |
5,880 | stylus/stylus | lib/functions/use.js | use | function use(plugin, options){
utils.assertString(plugin, 'plugin');
if (options) {
utils.assertType(options, 'object', 'options');
options = parseObject(options);
}
// lookup
plugin = plugin.string;
var found = utils.lookup(plugin, this.options.paths, this.options.filename);
if (!found) throw new Error('failed to locate plugin file "' + plugin + '"');
// use
var fn = require(path.resolve(found));
if ('function' != typeof fn) {
throw new Error('plugin "' + plugin + '" does not export a function');
}
this.renderer.use(fn(options || this.options));
} | javascript | function use(plugin, options){
utils.assertString(plugin, 'plugin');
if (options) {
utils.assertType(options, 'object', 'options');
options = parseObject(options);
}
// lookup
plugin = plugin.string;
var found = utils.lookup(plugin, this.options.paths, this.options.filename);
if (!found) throw new Error('failed to locate plugin file "' + plugin + '"');
// use
var fn = require(path.resolve(found));
if ('function' != typeof fn) {
throw new Error('plugin "' + plugin + '" does not export a function');
}
this.renderer.use(fn(options || this.options));
} | [
"function",
"use",
"(",
"plugin",
",",
"options",
")",
"{",
"utils",
".",
"assertString",
"(",
"plugin",
",",
"'plugin'",
")",
";",
"if",
"(",
"options",
")",
"{",
"utils",
".",
"assertType",
"(",
"options",
",",
"'object'",
",",
"'options'",
")",
";",... | Use the given `plugin`
Examples:
use("plugins/add.js")
width add(10, 100)
// => width: 110 | [
"Use",
"the",
"given",
"plugin"
] | 7e98dc17368c62a6f8a95aa2e300e4ab02faf007 | https://github.com/stylus/stylus/blob/7e98dc17368c62a6f8a95aa2e300e4ab02faf007/lib/functions/use.js#L15-L34 |
5,881 | stylus/stylus | lib/functions/use.js | parseObject | function parseObject(obj){
obj = obj.vals;
for (var key in obj) {
var nodes = obj[key].nodes[0].nodes;
if (nodes && nodes.length) {
obj[key] = [];
for (var i = 0, len = nodes.length; i < len; ++i) {
obj[key].push(convert(nodes[i]));
}
} else {
obj[key] = convert(obj[key].first);
}
}
return obj;
function convert(node){
switch (node.nodeName) {
case 'object':
return parseObject(node);
case 'boolean':
return node.isTrue;
case 'unit':
return node.type ? node.toString() : +node.val;
case 'string':
case 'literal':
return node.val;
default:
return node.toString();
}
}
} | javascript | function parseObject(obj){
obj = obj.vals;
for (var key in obj) {
var nodes = obj[key].nodes[0].nodes;
if (nodes && nodes.length) {
obj[key] = [];
for (var i = 0, len = nodes.length; i < len; ++i) {
obj[key].push(convert(nodes[i]));
}
} else {
obj[key] = convert(obj[key].first);
}
}
return obj;
function convert(node){
switch (node.nodeName) {
case 'object':
return parseObject(node);
case 'boolean':
return node.isTrue;
case 'unit':
return node.type ? node.toString() : +node.val;
case 'string':
case 'literal':
return node.val;
default:
return node.toString();
}
}
} | [
"function",
"parseObject",
"(",
"obj",
")",
"{",
"obj",
"=",
"obj",
".",
"vals",
";",
"for",
"(",
"var",
"key",
"in",
"obj",
")",
"{",
"var",
"nodes",
"=",
"obj",
"[",
"key",
"]",
".",
"nodes",
"[",
"0",
"]",
".",
"nodes",
";",
"if",
"(",
"no... | Attempt to parse object node to the javascript object.
@param {Object} obj
@return {Object}
@api private | [
"Attempt",
"to",
"parse",
"object",
"node",
"to",
"the",
"javascript",
"object",
"."
] | 7e98dc17368c62a6f8a95aa2e300e4ab02faf007 | https://github.com/stylus/stylus/blob/7e98dc17368c62a6f8a95aa2e300e4ab02faf007/lib/functions/use.js#L46-L76 |
5,882 | stylus/stylus | lib/renderer.js | Renderer | function Renderer(str, options) {
options = options || {};
options.globals = options.globals || {};
options.functions = options.functions || {};
options.use = options.use || [];
options.use = Array.isArray(options.use) ? options.use : [options.use];
options.imports = [join(__dirname, 'functions')].concat(options.imports || []);
options.paths = options.paths || [];
options.filename = options.filename || 'stylus';
options.Evaluator = options.Evaluator || Evaluator;
this.options = options;
this.str = str;
this.events = events;
} | javascript | function Renderer(str, options) {
options = options || {};
options.globals = options.globals || {};
options.functions = options.functions || {};
options.use = options.use || [];
options.use = Array.isArray(options.use) ? options.use : [options.use];
options.imports = [join(__dirname, 'functions')].concat(options.imports || []);
options.paths = options.paths || [];
options.filename = options.filename || 'stylus';
options.Evaluator = options.Evaluator || Evaluator;
this.options = options;
this.str = str;
this.events = events;
} | [
"function",
"Renderer",
"(",
"str",
",",
"options",
")",
"{",
"options",
"=",
"options",
"||",
"{",
"}",
";",
"options",
".",
"globals",
"=",
"options",
".",
"globals",
"||",
"{",
"}",
";",
"options",
".",
"functions",
"=",
"options",
".",
"functions",... | Initialize a new `Renderer` with the given `str` and `options`.
@param {String} str
@param {Object} options
@api public | [
"Initialize",
"a",
"new",
"Renderer",
"with",
"the",
"given",
"str",
"and",
"options",
"."
] | 7e98dc17368c62a6f8a95aa2e300e4ab02faf007 | https://github.com/stylus/stylus/blob/7e98dc17368c62a6f8a95aa2e300e4ab02faf007/lib/renderer.js#L35-L48 |
5,883 | stylus/stylus | lib/functions/tan.js | tan | function tan(angle) {
utils.assertType(angle, 'unit', 'angle');
var radians = angle.val;
if (angle.type === 'deg') {
radians *= Math.PI / 180;
}
var m = Math.pow(10, 9);
var sin = Math.round(Math.sin(radians) * m) / m
, cos = Math.round(Math.cos(radians) * m) / m
, tan = Math.round(m * sin / cos ) / m;
return new nodes.Unit(tan, '');
} | javascript | function tan(angle) {
utils.assertType(angle, 'unit', 'angle');
var radians = angle.val;
if (angle.type === 'deg') {
radians *= Math.PI / 180;
}
var m = Math.pow(10, 9);
var sin = Math.round(Math.sin(radians) * m) / m
, cos = Math.round(Math.cos(radians) * m) / m
, tan = Math.round(m * sin / cos ) / m;
return new nodes.Unit(tan, '');
} | [
"function",
"tan",
"(",
"angle",
")",
"{",
"utils",
".",
"assertType",
"(",
"angle",
",",
"'unit'",
",",
"'angle'",
")",
";",
"var",
"radians",
"=",
"angle",
".",
"val",
";",
"if",
"(",
"angle",
".",
"type",
"===",
"'deg'",
")",
"{",
"radians",
"*=... | Return the tangent of the given `angle`.
@param {Unit} angle
@return {Unit}
@api public | [
"Return",
"the",
"tangent",
"of",
"the",
"given",
"angle",
"."
] | 7e98dc17368c62a6f8a95aa2e300e4ab02faf007 | https://github.com/stylus/stylus/blob/7e98dc17368c62a6f8a95aa2e300e4ab02faf007/lib/functions/tan.js#L12-L28 |
5,884 | stylus/stylus | lib/functions/dirname.js | dirname | function dirname(p){
utils.assertString(p, 'path');
return path.dirname(p.val).replace(/\\/g, '/');
} | javascript | function dirname(p){
utils.assertString(p, 'path');
return path.dirname(p.val).replace(/\\/g, '/');
} | [
"function",
"dirname",
"(",
"p",
")",
"{",
"utils",
".",
"assertString",
"(",
"p",
",",
"'path'",
")",
";",
"return",
"path",
".",
"dirname",
"(",
"p",
".",
"val",
")",
".",
"replace",
"(",
"/",
"\\\\",
"/",
"g",
",",
"'/'",
")",
";",
"}"
] | Return the dirname of `path`.
@param {String} path
@return {String}
@api public | [
"Return",
"the",
"dirname",
"of",
"path",
"."
] | 7e98dc17368c62a6f8a95aa2e300e4ab02faf007 | https://github.com/stylus/stylus/blob/7e98dc17368c62a6f8a95aa2e300e4ab02faf007/lib/functions/dirname.js#L12-L15 |
5,885 | stylus/stylus | lib/functions/range.js | range | function range(start, stop, step){
utils.assertType(start, 'unit', 'start');
utils.assertType(stop, 'unit', 'stop');
if (step) {
utils.assertType(step, 'unit', 'step');
if (0 == step.val) {
throw new Error('ArgumentError: "step" argument must not be zero');
}
} else {
step = new nodes.Unit(1);
}
var list = new nodes.Expression;
for (var i = start.val; i <= stop.val; i += step.val) {
list.push(new nodes.Unit(i, start.type));
}
return list;
} | javascript | function range(start, stop, step){
utils.assertType(start, 'unit', 'start');
utils.assertType(stop, 'unit', 'stop');
if (step) {
utils.assertType(step, 'unit', 'step');
if (0 == step.val) {
throw new Error('ArgumentError: "step" argument must not be zero');
}
} else {
step = new nodes.Unit(1);
}
var list = new nodes.Expression;
for (var i = start.val; i <= stop.val; i += step.val) {
list.push(new nodes.Unit(i, start.type));
}
return list;
} | [
"function",
"range",
"(",
"start",
",",
"stop",
",",
"step",
")",
"{",
"utils",
".",
"assertType",
"(",
"start",
",",
"'unit'",
",",
"'start'",
")",
";",
"utils",
".",
"assertType",
"(",
"stop",
",",
"'unit'",
",",
"'stop'",
")",
";",
"if",
"(",
"s... | Returns a list of units from `start` to `stop`
by `step`. If `step` argument is omitted,
it defaults to 1.
@param {Unit} start
@param {Unit} stop
@param {Unit} [step]
@return {Expression}
@api public | [
"Returns",
"a",
"list",
"of",
"units",
"from",
"start",
"to",
"stop",
"by",
"step",
".",
"If",
"step",
"argument",
"is",
"omitted",
"it",
"defaults",
"to",
"1",
"."
] | 7e98dc17368c62a6f8a95aa2e300e4ab02faf007 | https://github.com/stylus/stylus/blob/7e98dc17368c62a6f8a95aa2e300e4ab02faf007/lib/functions/range.js#L16-L32 |
5,886 | stylus/stylus | lib/functions/json.js | oldJson | function oldJson(json, local, namePrefix){
if (namePrefix) {
utils.assertString(namePrefix, 'namePrefix');
namePrefix = namePrefix.val;
} else {
namePrefix = '';
}
local = local ? local.toBoolean() : new nodes.Boolean(local);
var scope = local.isTrue ? this.currentScope : this.global.scope;
convert(json);
return;
function convert(obj, prefix){
prefix = prefix ? prefix + '-' : '';
for (var key in obj){
var val = obj[key];
var name = prefix + key;
if ('object' == typeof val) {
convert(val, name);
} else {
val = utils.coerce(val);
if ('string' == val.nodeName) val = utils.parseString(val.string);
scope.add({ name: namePrefix + name, val: val });
}
}
}
} | javascript | function oldJson(json, local, namePrefix){
if (namePrefix) {
utils.assertString(namePrefix, 'namePrefix');
namePrefix = namePrefix.val;
} else {
namePrefix = '';
}
local = local ? local.toBoolean() : new nodes.Boolean(local);
var scope = local.isTrue ? this.currentScope : this.global.scope;
convert(json);
return;
function convert(obj, prefix){
prefix = prefix ? prefix + '-' : '';
for (var key in obj){
var val = obj[key];
var name = prefix + key;
if ('object' == typeof val) {
convert(val, name);
} else {
val = utils.coerce(val);
if ('string' == val.nodeName) val = utils.parseString(val.string);
scope.add({ name: namePrefix + name, val: val });
}
}
}
} | [
"function",
"oldJson",
"(",
"json",
",",
"local",
",",
"namePrefix",
")",
"{",
"if",
"(",
"namePrefix",
")",
"{",
"utils",
".",
"assertString",
"(",
"namePrefix",
",",
"'namePrefix'",
")",
";",
"namePrefix",
"=",
"namePrefix",
".",
"val",
";",
"}",
"else... | Old `json` BIF.
@api private | [
"Old",
"json",
"BIF",
"."
] | 7e98dc17368c62a6f8a95aa2e300e4ab02faf007 | https://github.com/stylus/stylus/blob/7e98dc17368c62a6f8a95aa2e300e4ab02faf007/lib/functions/json.js#L91-L118 |
5,887 | stylus/stylus | lib/functions/component.js | component | function component(color, name) {
utils.assertColor(color, 'color');
utils.assertString(name, 'name');
var name = name.string
, unit = unitMap[name]
, type = typeMap[name]
, name = componentMap[name];
if (!name) throw new Error('invalid color component "' + name + '"');
return new nodes.Unit(color[type][name], unit);
} | javascript | function component(color, name) {
utils.assertColor(color, 'color');
utils.assertString(name, 'name');
var name = name.string
, unit = unitMap[name]
, type = typeMap[name]
, name = componentMap[name];
if (!name) throw new Error('invalid color component "' + name + '"');
return new nodes.Unit(color[type][name], unit);
} | [
"function",
"component",
"(",
"color",
",",
"name",
")",
"{",
"utils",
".",
"assertColor",
"(",
"color",
",",
"'color'",
")",
";",
"utils",
".",
"assertString",
"(",
"name",
",",
"'name'",
")",
";",
"var",
"name",
"=",
"name",
".",
"string",
",",
"un... | Return component `name` for the given `color`.
@param {RGBA|HSLA} color
@param {String} name
@return {Unit}
@api public | [
"Return",
"component",
"name",
"for",
"the",
"given",
"color",
"."
] | 7e98dc17368c62a6f8a95aa2e300e4ab02faf007 | https://github.com/stylus/stylus/blob/7e98dc17368c62a6f8a95aa2e300e4ab02faf007/lib/functions/component.js#L51-L60 |
5,888 | stylus/stylus | lib/parser.js | function(){
var block = this.parent = this.root;
if (Parser.cache.has(this.hash)) {
block = Parser.cache.get(this.hash);
// normalize cached imports
if ('block' == block.nodeName) block.constructor = nodes.Root;
} else {
while ('eos' != this.peek().type) {
this.skipWhitespace();
if ('eos' == this.peek().type) break;
var stmt = this.statement();
this.accept(';');
if (!stmt) this.error('unexpected token {peek}, not allowed at the root level');
block.push(stmt);
}
Parser.cache.set(this.hash, block);
}
return block;
} | javascript | function(){
var block = this.parent = this.root;
if (Parser.cache.has(this.hash)) {
block = Parser.cache.get(this.hash);
// normalize cached imports
if ('block' == block.nodeName) block.constructor = nodes.Root;
} else {
while ('eos' != this.peek().type) {
this.skipWhitespace();
if ('eos' == this.peek().type) break;
var stmt = this.statement();
this.accept(';');
if (!stmt) this.error('unexpected token {peek}, not allowed at the root level');
block.push(stmt);
}
Parser.cache.set(this.hash, block);
}
return block;
} | [
"function",
"(",
")",
"{",
"var",
"block",
"=",
"this",
".",
"parent",
"=",
"this",
".",
"root",
";",
"if",
"(",
"Parser",
".",
"cache",
".",
"has",
"(",
"this",
".",
"hash",
")",
")",
"{",
"block",
"=",
"Parser",
".",
"cache",
".",
"get",
"(",... | Parse the input, then return the root node.
@return {Node}
@api private | [
"Parse",
"the",
"input",
"then",
"return",
"the",
"root",
"node",
"."
] | 7e98dc17368c62a6f8a95aa2e300e4ab02faf007 | https://github.com/stylus/stylus/blob/7e98dc17368c62a6f8a95aa2e300e4ab02faf007/lib/parser.js#L226-L244 | |
5,889 | stylus/stylus | lib/parser.js | function(msg){
var type = this.peek().type
, val = undefined == this.peek().val
? ''
: ' ' + this.peek().toString();
if (val.trim() == type.trim()) val = '';
throw new errors.ParseError(msg.replace('{peek}', '"' + type + val + '"'));
} | javascript | function(msg){
var type = this.peek().type
, val = undefined == this.peek().val
? ''
: ' ' + this.peek().toString();
if (val.trim() == type.trim()) val = '';
throw new errors.ParseError(msg.replace('{peek}', '"' + type + val + '"'));
} | [
"function",
"(",
"msg",
")",
"{",
"var",
"type",
"=",
"this",
".",
"peek",
"(",
")",
".",
"type",
",",
"val",
"=",
"undefined",
"==",
"this",
".",
"peek",
"(",
")",
".",
"val",
"?",
"''",
":",
"' '",
"+",
"this",
".",
"peek",
"(",
")",
".",
... | Throw an `Error` with the given `msg`.
@param {String} msg
@api private | [
"Throw",
"an",
"Error",
"with",
"the",
"given",
"msg",
"."
] | 7e98dc17368c62a6f8a95aa2e300e4ab02faf007 | https://github.com/stylus/stylus/blob/7e98dc17368c62a6f8a95aa2e300e4ab02faf007/lib/parser.js#L253-L260 | |
5,890 | stylus/stylus | lib/parser.js | function() {
var tok = this.stash.length
? this.stash.pop()
: this.lexer.next()
, line = tok.lineno
, column = tok.column || 1;
if (tok.val && tok.val.nodeName) {
tok.val.lineno = line;
tok.val.column = column;
}
nodes.lineno = line;
nodes.column = column;
debug.lexer('%s %s', tok.type, tok.val || '');
return tok;
} | javascript | function() {
var tok = this.stash.length
? this.stash.pop()
: this.lexer.next()
, line = tok.lineno
, column = tok.column || 1;
if (tok.val && tok.val.nodeName) {
tok.val.lineno = line;
tok.val.column = column;
}
nodes.lineno = line;
nodes.column = column;
debug.lexer('%s %s', tok.type, tok.val || '');
return tok;
} | [
"function",
"(",
")",
"{",
"var",
"tok",
"=",
"this",
".",
"stash",
".",
"length",
"?",
"this",
".",
"stash",
".",
"pop",
"(",
")",
":",
"this",
".",
"lexer",
".",
"next",
"(",
")",
",",
"line",
"=",
"tok",
".",
"lineno",
",",
"column",
"=",
... | Get the next token.
@return {Token}
@api private | [
"Get",
"the",
"next",
"token",
"."
] | 7e98dc17368c62a6f8a95aa2e300e4ab02faf007 | https://github.com/stylus/stylus/blob/7e98dc17368c62a6f8a95aa2e300e4ab02faf007/lib/parser.js#L299-L314 | |
5,891 | stylus/stylus | lib/parser.js | function(n) {
var la = this.lookahead(n).type;
switch (la) {
case 'for':
return this.bracketed;
case '[':
this.bracketed = true;
return true;
case ']':
this.bracketed = false;
return true;
default:
return ~selectorTokens.indexOf(la);
}
} | javascript | function(n) {
var la = this.lookahead(n).type;
switch (la) {
case 'for':
return this.bracketed;
case '[':
this.bracketed = true;
return true;
case ']':
this.bracketed = false;
return true;
default:
return ~selectorTokens.indexOf(la);
}
} | [
"function",
"(",
"n",
")",
"{",
"var",
"la",
"=",
"this",
".",
"lookahead",
"(",
"n",
")",
".",
"type",
";",
"switch",
"(",
"la",
")",
"{",
"case",
"'for'",
":",
"return",
"this",
".",
"bracketed",
";",
"case",
"'['",
":",
"this",
".",
"bracketed... | Check if the token at `n` is a valid selector token.
@param {Number} n
@return {Boolean}
@api private | [
"Check",
"if",
"the",
"token",
"at",
"n",
"is",
"a",
"valid",
"selector",
"token",
"."
] | 7e98dc17368c62a6f8a95aa2e300e4ab02faf007 | https://github.com/stylus/stylus/blob/7e98dc17368c62a6f8a95aa2e300e4ab02faf007/lib/parser.js#L347-L361 | |
5,892 | stylus/stylus | lib/parser.js | function(n){
var val = this.lookahead(n).val;
return val && ~pseudoSelectors.indexOf(val.name);
} | javascript | function(n){
var val = this.lookahead(n).val;
return val && ~pseudoSelectors.indexOf(val.name);
} | [
"function",
"(",
"n",
")",
"{",
"var",
"val",
"=",
"this",
".",
"lookahead",
"(",
"n",
")",
".",
"val",
";",
"return",
"val",
"&&",
"~",
"pseudoSelectors",
".",
"indexOf",
"(",
"val",
".",
"name",
")",
";",
"}"
] | Check if the token at `n` is a pseudo selector.
@param {Number} n
@return {Boolean}
@api private | [
"Check",
"if",
"the",
"token",
"at",
"n",
"is",
"a",
"pseudo",
"selector",
"."
] | 7e98dc17368c62a6f8a95aa2e300e4ab02faf007 | https://github.com/stylus/stylus/blob/7e98dc17368c62a6f8a95aa2e300e4ab02faf007/lib/parser.js#L371-L374 | |
5,893 | stylus/stylus | lib/parser.js | function(type){
var i = 1
, la;
while (la = this.lookahead(i++)) {
if (~['indent', 'outdent', 'newline', 'eos'].indexOf(la.type)) return;
if (type == la.type) return true;
}
} | javascript | function(type){
var i = 1
, la;
while (la = this.lookahead(i++)) {
if (~['indent', 'outdent', 'newline', 'eos'].indexOf(la.type)) return;
if (type == la.type) return true;
}
} | [
"function",
"(",
"type",
")",
"{",
"var",
"i",
"=",
"1",
",",
"la",
";",
"while",
"(",
"la",
"=",
"this",
".",
"lookahead",
"(",
"i",
"++",
")",
")",
"{",
"if",
"(",
"~",
"[",
"'indent'",
",",
"'outdent'",
",",
"'newline'",
",",
"'eos'",
"]",
... | Check if the current line contains `type`.
@param {String} type
@return {Boolean}
@api private | [
"Check",
"if",
"the",
"current",
"line",
"contains",
"type",
"."
] | 7e98dc17368c62a6f8a95aa2e300e4ab02faf007 | https://github.com/stylus/stylus/blob/7e98dc17368c62a6f8a95aa2e300e4ab02faf007/lib/parser.js#L384-L392 | |
5,894 | stylus/stylus | lib/parser.js | function() {
if (this.isSelectorToken(1)) {
if ('{' == this.peek().type) {
// unclosed, must be a block
if (!this.lineContains('}')) return;
// check if ':' is within the braces.
// though not required by Stylus, chances
// are if someone is using {} they will
// use CSS-style props, helping us with
// the ambiguity in this case
var i = 0
, la;
while (la = this.lookahead(++i)) {
if ('}' == la.type) {
// Check empty block.
if (i == 2 || (i == 3 && this.lookahead(i - 1).type == 'space'))
return;
break;
}
if (':' == la.type) return;
}
}
return this.next();
}
} | javascript | function() {
if (this.isSelectorToken(1)) {
if ('{' == this.peek().type) {
// unclosed, must be a block
if (!this.lineContains('}')) return;
// check if ':' is within the braces.
// though not required by Stylus, chances
// are if someone is using {} they will
// use CSS-style props, helping us with
// the ambiguity in this case
var i = 0
, la;
while (la = this.lookahead(++i)) {
if ('}' == la.type) {
// Check empty block.
if (i == 2 || (i == 3 && this.lookahead(i - 1).type == 'space'))
return;
break;
}
if (':' == la.type) return;
}
}
return this.next();
}
} | [
"function",
"(",
")",
"{",
"if",
"(",
"this",
".",
"isSelectorToken",
"(",
"1",
")",
")",
"{",
"if",
"(",
"'{'",
"==",
"this",
".",
"peek",
"(",
")",
".",
"type",
")",
"{",
"// unclosed, must be a block",
"if",
"(",
"!",
"this",
".",
"lineContains",
... | Valid selector tokens. | [
"Valid",
"selector",
"tokens",
"."
] | 7e98dc17368c62a6f8a95aa2e300e4ab02faf007 | https://github.com/stylus/stylus/blob/7e98dc17368c62a6f8a95aa2e300e4ab02faf007/lib/parser.js#L398-L422 | |
5,895 | stylus/stylus | lib/parser.js | function(n) {
var type = this.lookahead(n).type;
if ('=' == type && this.bracketed) return true;
return ('ident' == type || 'string' == type)
&& ']' == this.lookahead(n + 1).type
&& ('newline' == this.lookahead(n + 2).type || this.isSelectorToken(n + 2))
&& !this.lineContains(':')
&& !this.lineContains('=');
} | javascript | function(n) {
var type = this.lookahead(n).type;
if ('=' == type && this.bracketed) return true;
return ('ident' == type || 'string' == type)
&& ']' == this.lookahead(n + 1).type
&& ('newline' == this.lookahead(n + 2).type || this.isSelectorToken(n + 2))
&& !this.lineContains(':')
&& !this.lineContains('=');
} | [
"function",
"(",
"n",
")",
"{",
"var",
"type",
"=",
"this",
".",
"lookahead",
"(",
"n",
")",
".",
"type",
";",
"if",
"(",
"'='",
"==",
"type",
"&&",
"this",
".",
"bracketed",
")",
"return",
"true",
";",
"return",
"(",
"'ident'",
"==",
"type",
"||... | Check if the following sequence of tokens
forms an attribute selector. | [
"Check",
"if",
"the",
"following",
"sequence",
"of",
"tokens",
"forms",
"an",
"attribute",
"selector",
"."
] | 7e98dc17368c62a6f8a95aa2e300e4ab02faf007 | https://github.com/stylus/stylus/blob/7e98dc17368c62a6f8a95aa2e300e4ab02faf007/lib/parser.js#L660-L668 | |
5,896 | stylus/stylus | lib/parser.js | function() {
var i = 2
, type;
switch (this.lookahead(i).type) {
case '{':
case 'indent':
case ',':
return true;
case 'newline':
while ('unit' == this.lookahead(++i).type
|| 'newline' == this.lookahead(i).type) ;
type = this.lookahead(i).type;
return 'indent' == type || '{' == type;
}
} | javascript | function() {
var i = 2
, type;
switch (this.lookahead(i).type) {
case '{':
case 'indent':
case ',':
return true;
case 'newline':
while ('unit' == this.lookahead(++i).type
|| 'newline' == this.lookahead(i).type) ;
type = this.lookahead(i).type;
return 'indent' == type || '{' == type;
}
} | [
"function",
"(",
")",
"{",
"var",
"i",
"=",
"2",
",",
"type",
";",
"switch",
"(",
"this",
".",
"lookahead",
"(",
"i",
")",
".",
"type",
")",
"{",
"case",
"'{'",
":",
"case",
"'indent'",
":",
"case",
"','",
":",
"return",
"true",
";",
"case",
"'... | Check if the following sequence of tokens
forms a keyframe block. | [
"Check",
"if",
"the",
"following",
"sequence",
"of",
"tokens",
"forms",
"a",
"keyframe",
"block",
"."
] | 7e98dc17368c62a6f8a95aa2e300e4ab02faf007 | https://github.com/stylus/stylus/blob/7e98dc17368c62a6f8a95aa2e300e4ab02faf007/lib/parser.js#L675-L689 | |
5,897 | stylus/stylus | lib/parser.js | function() {
var stmt = this.stmt()
, state = this.prevState
, block
, op;
// special-case statements since it
// is not an expression. We could
// implement postfix conditionals at
// the expression level, however they
// would then fail to enclose properties
if (this.allowPostfix) {
this.allowPostfix = false;
state = 'expression';
}
switch (state) {
case 'assignment':
case 'expression':
case 'function arguments':
while (op =
this.accept('if')
|| this.accept('unless')
|| this.accept('for')) {
switch (op.type) {
case 'if':
case 'unless':
stmt = new nodes.If(this.expression(), stmt);
stmt.postfix = true;
stmt.negate = 'unless' == op.type;
this.accept(';');
break;
case 'for':
var key
, val = this.id().name;
if (this.accept(',')) key = this.id().name;
this.expect('in');
var each = new nodes.Each(val, key, this.expression());
block = new nodes.Block(this.parent, each);
block.push(stmt);
each.block = block;
stmt = each;
}
}
}
return stmt;
} | javascript | function() {
var stmt = this.stmt()
, state = this.prevState
, block
, op;
// special-case statements since it
// is not an expression. We could
// implement postfix conditionals at
// the expression level, however they
// would then fail to enclose properties
if (this.allowPostfix) {
this.allowPostfix = false;
state = 'expression';
}
switch (state) {
case 'assignment':
case 'expression':
case 'function arguments':
while (op =
this.accept('if')
|| this.accept('unless')
|| this.accept('for')) {
switch (op.type) {
case 'if':
case 'unless':
stmt = new nodes.If(this.expression(), stmt);
stmt.postfix = true;
stmt.negate = 'unless' == op.type;
this.accept(';');
break;
case 'for':
var key
, val = this.id().name;
if (this.accept(',')) key = this.id().name;
this.expect('in');
var each = new nodes.Each(val, key, this.expression());
block = new nodes.Block(this.parent, each);
block.push(stmt);
each.block = block;
stmt = each;
}
}
}
return stmt;
} | [
"function",
"(",
")",
"{",
"var",
"stmt",
"=",
"this",
".",
"stmt",
"(",
")",
",",
"state",
"=",
"this",
".",
"prevState",
",",
"block",
",",
"op",
";",
"// special-case statements since it",
"// is not an expression. We could",
"// implement postfix conditionals at... | statement
| statement 'if' expression
| statement 'unless' expression | [
"statement",
"|",
"statement",
"if",
"expression",
"|",
"statement",
"unless",
"expression"
] | 7e98dc17368c62a6f8a95aa2e300e4ab02faf007 | https://github.com/stylus/stylus/blob/7e98dc17368c62a6f8a95aa2e300e4ab02faf007/lib/parser.js#L729-L776 | |
5,898 | stylus/stylus | lib/parser.js | function() {
var tok = this.peek(), selector;
switch (tok.type) {
case 'keyframes':
return this.keyframes();
case '-moz-document':
return this.mozdocument();
case 'comment':
case 'selector':
case 'literal':
case 'charset':
case 'namespace':
case 'import':
case 'require':
case 'extend':
case 'media':
case 'atrule':
case 'ident':
case 'scope':
case 'supports':
case 'unless':
case 'function':
case 'for':
case 'if':
return this[tok.type]();
case 'return':
return this.return();
case '{':
return this.property();
default:
// Contextual selectors
if (this.stateAllowsSelector()) {
switch (tok.type) {
case 'color':
case '~':
case '>':
case '<':
case ':':
case '&':
case '&&':
case '[':
case '.':
case '/':
selector = this.selector();
selector.column = tok.column;
selector.lineno = tok.lineno;
return selector;
// relative reference
case '..':
if ('/' == this.lookahead(2).type)
return this.selector();
case '+':
return 'function' == this.lookahead(2).type
? this.functionCall()
: this.selector();
case '*':
return this.property();
// keyframe blocks (10%, 20% { ... })
case 'unit':
if (this.looksLikeKeyframe()) {
selector = this.selector();
selector.column = tok.column;
selector.lineno = tok.lineno;
return selector;
}
case '-':
if ('{' == this.lookahead(2).type)
return this.property();
}
}
// Expression fallback
var expr = this.expression();
if (expr.isEmpty) this.error('unexpected {peek}');
return expr;
}
} | javascript | function() {
var tok = this.peek(), selector;
switch (tok.type) {
case 'keyframes':
return this.keyframes();
case '-moz-document':
return this.mozdocument();
case 'comment':
case 'selector':
case 'literal':
case 'charset':
case 'namespace':
case 'import':
case 'require':
case 'extend':
case 'media':
case 'atrule':
case 'ident':
case 'scope':
case 'supports':
case 'unless':
case 'function':
case 'for':
case 'if':
return this[tok.type]();
case 'return':
return this.return();
case '{':
return this.property();
default:
// Contextual selectors
if (this.stateAllowsSelector()) {
switch (tok.type) {
case 'color':
case '~':
case '>':
case '<':
case ':':
case '&':
case '&&':
case '[':
case '.':
case '/':
selector = this.selector();
selector.column = tok.column;
selector.lineno = tok.lineno;
return selector;
// relative reference
case '..':
if ('/' == this.lookahead(2).type)
return this.selector();
case '+':
return 'function' == this.lookahead(2).type
? this.functionCall()
: this.selector();
case '*':
return this.property();
// keyframe blocks (10%, 20% { ... })
case 'unit':
if (this.looksLikeKeyframe()) {
selector = this.selector();
selector.column = tok.column;
selector.lineno = tok.lineno;
return selector;
}
case '-':
if ('{' == this.lookahead(2).type)
return this.property();
}
}
// Expression fallback
var expr = this.expression();
if (expr.isEmpty) this.error('unexpected {peek}');
return expr;
}
} | [
"function",
"(",
")",
"{",
"var",
"tok",
"=",
"this",
".",
"peek",
"(",
")",
",",
"selector",
";",
"switch",
"(",
"tok",
".",
"type",
")",
"{",
"case",
"'keyframes'",
":",
"return",
"this",
".",
"keyframes",
"(",
")",
";",
"case",
"'-moz-document'",
... | ident
| selector
| literal
| charset
| namespace
| import
| require
| media
| atrule
| scope
| keyframes
| mozdocument
| for
| if
| unless
| comment
| expression
| 'return' expression | [
"ident",
"|",
"selector",
"|",
"literal",
"|",
"charset",
"|",
"namespace",
"|",
"import",
"|",
"require",
"|",
"media",
"|",
"atrule",
"|",
"scope",
"|",
"keyframes",
"|",
"mozdocument",
"|",
"for",
"|",
"if",
"|",
"unless",
"|",
"comment",
"|",
"expr... | 7e98dc17368c62a6f8a95aa2e300e4ab02faf007 | https://github.com/stylus/stylus/blob/7e98dc17368c62a6f8a95aa2e300e4ab02faf007/lib/parser.js#L799-L875 | |
5,899 | stylus/stylus | lib/parser.js | function() {
this.expect('unless');
this.state.push('conditional');
this.cond = true;
var node = new nodes.If(this.expression(), true);
this.cond = false;
node.block = this.block(node, false);
this.state.pop();
return node;
} | javascript | function() {
this.expect('unless');
this.state.push('conditional');
this.cond = true;
var node = new nodes.If(this.expression(), true);
this.cond = false;
node.block = this.block(node, false);
this.state.pop();
return node;
} | [
"function",
"(",
")",
"{",
"this",
".",
"expect",
"(",
"'unless'",
")",
";",
"this",
".",
"state",
".",
"push",
"(",
"'conditional'",
")",
";",
"this",
".",
"cond",
"=",
"true",
";",
"var",
"node",
"=",
"new",
"nodes",
".",
"If",
"(",
"this",
"."... | unless expression block | [
"unless",
"expression",
"block"
] | 7e98dc17368c62a6f8a95aa2e300e4ab02faf007 | https://github.com/stylus/stylus/blob/7e98dc17368c62a6f8a95aa2e300e4ab02faf007/lib/parser.js#L984-L993 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.