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
|
|---|---|---|---|---|---|---|---|---|---|---|---|
12,200
|
que-etc/resize-observer-polyfill
|
src/utils/geometry.js
|
getHTMLElementContentRect
|
function getHTMLElementContentRect(target) {
// Client width & height properties can't be
// used exclusively as they provide rounded values.
const {clientWidth, clientHeight} = target;
// By this condition we can catch all non-replaced inline, hidden and
// detached elements. Though elements with width & height properties less
// than 0.5 will be discarded as well.
//
// Without it we would need to implement separate methods for each of
// those cases and it's not possible to perform a precise and performance
// effective test for hidden elements. E.g. even jQuery's ':visible' filter
// gives wrong results for elements with width & height less than 0.5.
if (!clientWidth && !clientHeight) {
return emptyRect;
}
const styles = getWindowOf(target).getComputedStyle(target);
const paddings = getPaddings(styles);
const horizPad = paddings.left + paddings.right;
const vertPad = paddings.top + paddings.bottom;
// Computed styles of width & height are being used because they are the
// only dimensions available to JS that contain non-rounded values. It could
// be possible to utilize the getBoundingClientRect if only it's data wasn't
// affected by CSS transformations let alone paddings, borders and scroll bars.
let width = toFloat(styles.width),
height = toFloat(styles.height);
// Width & height include paddings and borders when the 'border-box' box
// model is applied (except for IE).
if (styles.boxSizing === 'border-box') {
// Following conditions are required to handle Internet Explorer which
// doesn't include paddings and borders to computed CSS dimensions.
//
// We can say that if CSS dimensions + paddings are equal to the "client"
// properties then it's either IE, and thus we don't need to subtract
// anything, or an element merely doesn't have paddings/borders styles.
if (Math.round(width + horizPad) !== clientWidth) {
width -= getBordersSize(styles, 'left', 'right') + horizPad;
}
if (Math.round(height + vertPad) !== clientHeight) {
height -= getBordersSize(styles, 'top', 'bottom') + vertPad;
}
}
// Following steps can't be applied to the document's root element as its
// client[Width/Height] properties represent viewport area of the window.
// Besides, it's as well not necessary as the <html> itself neither has
// rendered scroll bars nor it can be clipped.
if (!isDocumentElement(target)) {
// In some browsers (only in Firefox, actually) CSS width & height
// include scroll bars size which can be removed at this step as scroll
// bars are the only difference between rounded dimensions + paddings
// and "client" properties, though that is not always true in Chrome.
const vertScrollbar = Math.round(width + horizPad) - clientWidth;
const horizScrollbar = Math.round(height + vertPad) - clientHeight;
// Chrome has a rather weird rounding of "client" properties.
// E.g. for an element with content width of 314.2px it sometimes gives
// the client width of 315px and for the width of 314.7px it may give
// 314px. And it doesn't happen all the time. So just ignore this delta
// as a non-relevant.
if (Math.abs(vertScrollbar) !== 1) {
width -= vertScrollbar;
}
if (Math.abs(horizScrollbar) !== 1) {
height -= horizScrollbar;
}
}
return createRectInit(paddings.left, paddings.top, width, height);
}
|
javascript
|
function getHTMLElementContentRect(target) {
// Client width & height properties can't be
// used exclusively as they provide rounded values.
const {clientWidth, clientHeight} = target;
// By this condition we can catch all non-replaced inline, hidden and
// detached elements. Though elements with width & height properties less
// than 0.5 will be discarded as well.
//
// Without it we would need to implement separate methods for each of
// those cases and it's not possible to perform a precise and performance
// effective test for hidden elements. E.g. even jQuery's ':visible' filter
// gives wrong results for elements with width & height less than 0.5.
if (!clientWidth && !clientHeight) {
return emptyRect;
}
const styles = getWindowOf(target).getComputedStyle(target);
const paddings = getPaddings(styles);
const horizPad = paddings.left + paddings.right;
const vertPad = paddings.top + paddings.bottom;
// Computed styles of width & height are being used because they are the
// only dimensions available to JS that contain non-rounded values. It could
// be possible to utilize the getBoundingClientRect if only it's data wasn't
// affected by CSS transformations let alone paddings, borders and scroll bars.
let width = toFloat(styles.width),
height = toFloat(styles.height);
// Width & height include paddings and borders when the 'border-box' box
// model is applied (except for IE).
if (styles.boxSizing === 'border-box') {
// Following conditions are required to handle Internet Explorer which
// doesn't include paddings and borders to computed CSS dimensions.
//
// We can say that if CSS dimensions + paddings are equal to the "client"
// properties then it's either IE, and thus we don't need to subtract
// anything, or an element merely doesn't have paddings/borders styles.
if (Math.round(width + horizPad) !== clientWidth) {
width -= getBordersSize(styles, 'left', 'right') + horizPad;
}
if (Math.round(height + vertPad) !== clientHeight) {
height -= getBordersSize(styles, 'top', 'bottom') + vertPad;
}
}
// Following steps can't be applied to the document's root element as its
// client[Width/Height] properties represent viewport area of the window.
// Besides, it's as well not necessary as the <html> itself neither has
// rendered scroll bars nor it can be clipped.
if (!isDocumentElement(target)) {
// In some browsers (only in Firefox, actually) CSS width & height
// include scroll bars size which can be removed at this step as scroll
// bars are the only difference between rounded dimensions + paddings
// and "client" properties, though that is not always true in Chrome.
const vertScrollbar = Math.round(width + horizPad) - clientWidth;
const horizScrollbar = Math.round(height + vertPad) - clientHeight;
// Chrome has a rather weird rounding of "client" properties.
// E.g. for an element with content width of 314.2px it sometimes gives
// the client width of 315px and for the width of 314.7px it may give
// 314px. And it doesn't happen all the time. So just ignore this delta
// as a non-relevant.
if (Math.abs(vertScrollbar) !== 1) {
width -= vertScrollbar;
}
if (Math.abs(horizScrollbar) !== 1) {
height -= horizScrollbar;
}
}
return createRectInit(paddings.left, paddings.top, width, height);
}
|
[
"function",
"getHTMLElementContentRect",
"(",
"target",
")",
"{",
"// Client width & height properties can't be",
"// used exclusively as they provide rounded values.",
"const",
"{",
"clientWidth",
",",
"clientHeight",
"}",
"=",
"target",
";",
"// By this condition we can catch all non-replaced inline, hidden and",
"// detached elements. Though elements with width & height properties less",
"// than 0.5 will be discarded as well.",
"//",
"// Without it we would need to implement separate methods for each of",
"// those cases and it's not possible to perform a precise and performance",
"// effective test for hidden elements. E.g. even jQuery's ':visible' filter",
"// gives wrong results for elements with width & height less than 0.5.",
"if",
"(",
"!",
"clientWidth",
"&&",
"!",
"clientHeight",
")",
"{",
"return",
"emptyRect",
";",
"}",
"const",
"styles",
"=",
"getWindowOf",
"(",
"target",
")",
".",
"getComputedStyle",
"(",
"target",
")",
";",
"const",
"paddings",
"=",
"getPaddings",
"(",
"styles",
")",
";",
"const",
"horizPad",
"=",
"paddings",
".",
"left",
"+",
"paddings",
".",
"right",
";",
"const",
"vertPad",
"=",
"paddings",
".",
"top",
"+",
"paddings",
".",
"bottom",
";",
"// Computed styles of width & height are being used because they are the",
"// only dimensions available to JS that contain non-rounded values. It could",
"// be possible to utilize the getBoundingClientRect if only it's data wasn't",
"// affected by CSS transformations let alone paddings, borders and scroll bars.",
"let",
"width",
"=",
"toFloat",
"(",
"styles",
".",
"width",
")",
",",
"height",
"=",
"toFloat",
"(",
"styles",
".",
"height",
")",
";",
"// Width & height include paddings and borders when the 'border-box' box",
"// model is applied (except for IE).",
"if",
"(",
"styles",
".",
"boxSizing",
"===",
"'border-box'",
")",
"{",
"// Following conditions are required to handle Internet Explorer which",
"// doesn't include paddings and borders to computed CSS dimensions.",
"//",
"// We can say that if CSS dimensions + paddings are equal to the \"client\"",
"// properties then it's either IE, and thus we don't need to subtract",
"// anything, or an element merely doesn't have paddings/borders styles.",
"if",
"(",
"Math",
".",
"round",
"(",
"width",
"+",
"horizPad",
")",
"!==",
"clientWidth",
")",
"{",
"width",
"-=",
"getBordersSize",
"(",
"styles",
",",
"'left'",
",",
"'right'",
")",
"+",
"horizPad",
";",
"}",
"if",
"(",
"Math",
".",
"round",
"(",
"height",
"+",
"vertPad",
")",
"!==",
"clientHeight",
")",
"{",
"height",
"-=",
"getBordersSize",
"(",
"styles",
",",
"'top'",
",",
"'bottom'",
")",
"+",
"vertPad",
";",
"}",
"}",
"// Following steps can't be applied to the document's root element as its",
"// client[Width/Height] properties represent viewport area of the window.",
"// Besides, it's as well not necessary as the <html> itself neither has",
"// rendered scroll bars nor it can be clipped.",
"if",
"(",
"!",
"isDocumentElement",
"(",
"target",
")",
")",
"{",
"// In some browsers (only in Firefox, actually) CSS width & height",
"// include scroll bars size which can be removed at this step as scroll",
"// bars are the only difference between rounded dimensions + paddings",
"// and \"client\" properties, though that is not always true in Chrome.",
"const",
"vertScrollbar",
"=",
"Math",
".",
"round",
"(",
"width",
"+",
"horizPad",
")",
"-",
"clientWidth",
";",
"const",
"horizScrollbar",
"=",
"Math",
".",
"round",
"(",
"height",
"+",
"vertPad",
")",
"-",
"clientHeight",
";",
"// Chrome has a rather weird rounding of \"client\" properties.",
"// E.g. for an element with content width of 314.2px it sometimes gives",
"// the client width of 315px and for the width of 314.7px it may give",
"// 314px. And it doesn't happen all the time. So just ignore this delta",
"// as a non-relevant.",
"if",
"(",
"Math",
".",
"abs",
"(",
"vertScrollbar",
")",
"!==",
"1",
")",
"{",
"width",
"-=",
"vertScrollbar",
";",
"}",
"if",
"(",
"Math",
".",
"abs",
"(",
"horizScrollbar",
")",
"!==",
"1",
")",
"{",
"height",
"-=",
"horizScrollbar",
";",
"}",
"}",
"return",
"createRectInit",
"(",
"paddings",
".",
"left",
",",
"paddings",
".",
"top",
",",
"width",
",",
"height",
")",
";",
"}"
] |
Calculates content rectangle of provided HTMLElement.
@param {HTMLElement} target - Element for which to calculate the content rectangle.
@returns {DOMRectInit}
|
[
"Calculates",
"content",
"rectangle",
"of",
"provided",
"HTMLElement",
"."
] |
4a148452494a155656e4d04b9732b5914896b2e0
|
https://github.com/que-etc/resize-observer-polyfill/blob/4a148452494a155656e4d04b9732b5914896b2e0/src/utils/geometry.js#L71-L145
|
12,201
|
jhipster/prettier-java
|
packages/java-parser/scripts/unicode.js
|
pushInUnicode
|
function pushInUnicode(cat, elt) {
if (!unicode.hasOwnProperty(cat)) {
unicode[cat] = {
unicode: [],
ranges: []
};
}
if (Array.isArray(elt)) {
unicode[cat].ranges.push(elt);
} else {
unicode[cat].unicode.push(elt);
}
}
|
javascript
|
function pushInUnicode(cat, elt) {
if (!unicode.hasOwnProperty(cat)) {
unicode[cat] = {
unicode: [],
ranges: []
};
}
if (Array.isArray(elt)) {
unicode[cat].ranges.push(elt);
} else {
unicode[cat].unicode.push(elt);
}
}
|
[
"function",
"pushInUnicode",
"(",
"cat",
",",
"elt",
")",
"{",
"if",
"(",
"!",
"unicode",
".",
"hasOwnProperty",
"(",
"cat",
")",
")",
"{",
"unicode",
"[",
"cat",
"]",
"=",
"{",
"unicode",
":",
"[",
"]",
",",
"ranges",
":",
"[",
"]",
"}",
";",
"}",
"if",
"(",
"Array",
".",
"isArray",
"(",
"elt",
")",
")",
"{",
"unicode",
"[",
"cat",
"]",
".",
"ranges",
".",
"push",
"(",
"elt",
")",
";",
"}",
"else",
"{",
"unicode",
"[",
"cat",
"]",
".",
"unicode",
".",
"push",
"(",
"elt",
")",
";",
"}",
"}"
] |
Function that pushes in an object an attribute to store the characters
|
[
"Function",
"that",
"pushes",
"in",
"an",
"object",
"an",
"attribute",
"to",
"store",
"the",
"characters"
] |
3555a0c6e53697f0026bf8bf56403bb6b7719b17
|
https://github.com/jhipster/prettier-java/blob/3555a0c6e53697f0026bf8bf56403bb6b7719b17/packages/java-parser/scripts/unicode.js#L35-L48
|
12,202
|
jhipster/prettier-java
|
packages/java-parser/scripts/unicode.js
|
generateFile
|
function generateFile() {
let data = `
/*File generated with ../scripts/unicode.js using ../resources/Unicode/UnicodeData.txt.
* As Java Identifiers may contains unicodes letters, this file defines two sets of unicode
* characters, firstIdentChar used to help to determine if a character can be the first letter
* of a JavaIdentifier and the other one (restIdentChar) to determine if it can be part of a
* JavaIdentifier other than the first character.
* Java uses the same file UnicodeData.txt as the unicode.js script to define the unicodes.
* For more:
* https://github.com/jhipster/prettier-java/issues/116
* https://github.com/jhipster/prettier-java/pull/155
*/
"use strict"
const addRanges = (set, rangesArr) => {
for (let i = 0; i < rangesArr.length; i++) {
const range = rangesArr[i];
const start = range[0];
const end = range[1];
for (let codePoint = start; codePoint <= end; codePoint++) {
set.add(codePoint)
}
}
};
const fic = new Set([`;
firstIdentCharCategories.forEach(el => {
unicode[el].unicode.forEach(value => {
data += `${value},`;
});
});
data += `]);
`;
data += `const fic_a = [`;
firstIdentCharCategories.forEach(el => {
unicode[el].ranges.forEach(array => {
data += `[${array}],`;
});
});
data += `];
addRanges(fic, fic_a);
`;
data += `const ricd = new Set([`;
restIdentCharCategories.forEach(el => {
unicode[el].unicode.forEach(value => {
data += `${value},`;
});
});
manuallyAddedCharacters.unicode.forEach(v => (data += `${v},`));
data += `]);
`;
data += `const ricd_a = [`;
restIdentCharCategories.forEach(el => {
unicode[el].ranges.forEach(array => {
data += `[${array}],`;
});
});
data += `];
addRanges(ricd, ricd_a);
`;
data += `const mac_a = [`;
manuallyAddedCharacters.ranges.forEach(array => {
data += `[${array}],`;
});
data += `];
addRanges(ricd, mac_a);
`;
data += `const ric = new Set(function*() { yield* fic; yield* ricd; }());`;
data += `module.exports = {
firstIdentChar: fic,
restIdentChar: ric
}`;
fs.writeFileSync(
path.resolve(__dirname, "../src/unicodesets.js"),
data,
err => {
if (err) {
throw err;
}
}
);
}
|
javascript
|
function generateFile() {
let data = `
/*File generated with ../scripts/unicode.js using ../resources/Unicode/UnicodeData.txt.
* As Java Identifiers may contains unicodes letters, this file defines two sets of unicode
* characters, firstIdentChar used to help to determine if a character can be the first letter
* of a JavaIdentifier and the other one (restIdentChar) to determine if it can be part of a
* JavaIdentifier other than the first character.
* Java uses the same file UnicodeData.txt as the unicode.js script to define the unicodes.
* For more:
* https://github.com/jhipster/prettier-java/issues/116
* https://github.com/jhipster/prettier-java/pull/155
*/
"use strict"
const addRanges = (set, rangesArr) => {
for (let i = 0; i < rangesArr.length; i++) {
const range = rangesArr[i];
const start = range[0];
const end = range[1];
for (let codePoint = start; codePoint <= end; codePoint++) {
set.add(codePoint)
}
}
};
const fic = new Set([`;
firstIdentCharCategories.forEach(el => {
unicode[el].unicode.forEach(value => {
data += `${value},`;
});
});
data += `]);
`;
data += `const fic_a = [`;
firstIdentCharCategories.forEach(el => {
unicode[el].ranges.forEach(array => {
data += `[${array}],`;
});
});
data += `];
addRanges(fic, fic_a);
`;
data += `const ricd = new Set([`;
restIdentCharCategories.forEach(el => {
unicode[el].unicode.forEach(value => {
data += `${value},`;
});
});
manuallyAddedCharacters.unicode.forEach(v => (data += `${v},`));
data += `]);
`;
data += `const ricd_a = [`;
restIdentCharCategories.forEach(el => {
unicode[el].ranges.forEach(array => {
data += `[${array}],`;
});
});
data += `];
addRanges(ricd, ricd_a);
`;
data += `const mac_a = [`;
manuallyAddedCharacters.ranges.forEach(array => {
data += `[${array}],`;
});
data += `];
addRanges(ricd, mac_a);
`;
data += `const ric = new Set(function*() { yield* fic; yield* ricd; }());`;
data += `module.exports = {
firstIdentChar: fic,
restIdentChar: ric
}`;
fs.writeFileSync(
path.resolve(__dirname, "../src/unicodesets.js"),
data,
err => {
if (err) {
throw err;
}
}
);
}
|
[
"function",
"generateFile",
"(",
")",
"{",
"let",
"data",
"=",
"`",
"`",
";",
"firstIdentCharCategories",
".",
"forEach",
"(",
"el",
"=>",
"{",
"unicode",
"[",
"el",
"]",
".",
"unicode",
".",
"forEach",
"(",
"value",
"=>",
"{",
"data",
"+=",
"`",
"${",
"value",
"}",
"`",
";",
"}",
")",
";",
"}",
")",
";",
"data",
"+=",
"`",
"`",
";",
"data",
"+=",
"`",
"`",
";",
"firstIdentCharCategories",
".",
"forEach",
"(",
"el",
"=>",
"{",
"unicode",
"[",
"el",
"]",
".",
"ranges",
".",
"forEach",
"(",
"array",
"=>",
"{",
"data",
"+=",
"`",
"${",
"array",
"}",
"`",
";",
"}",
")",
";",
"}",
")",
";",
"data",
"+=",
"`",
"`",
";",
"data",
"+=",
"`",
"`",
";",
"restIdentCharCategories",
".",
"forEach",
"(",
"el",
"=>",
"{",
"unicode",
"[",
"el",
"]",
".",
"unicode",
".",
"forEach",
"(",
"value",
"=>",
"{",
"data",
"+=",
"`",
"${",
"value",
"}",
"`",
";",
"}",
")",
";",
"}",
")",
";",
"manuallyAddedCharacters",
".",
"unicode",
".",
"forEach",
"(",
"v",
"=>",
"(",
"data",
"+=",
"`",
"${",
"v",
"}",
"`",
")",
")",
";",
"data",
"+=",
"`",
"`",
";",
"data",
"+=",
"`",
"`",
";",
"restIdentCharCategories",
".",
"forEach",
"(",
"el",
"=>",
"{",
"unicode",
"[",
"el",
"]",
".",
"ranges",
".",
"forEach",
"(",
"array",
"=>",
"{",
"data",
"+=",
"`",
"${",
"array",
"}",
"`",
";",
"}",
")",
";",
"}",
")",
";",
"data",
"+=",
"`",
"`",
";",
"data",
"+=",
"`",
"`",
";",
"manuallyAddedCharacters",
".",
"ranges",
".",
"forEach",
"(",
"array",
"=>",
"{",
"data",
"+=",
"`",
"${",
"array",
"}",
"`",
";",
"}",
")",
";",
"data",
"+=",
"`",
"`",
";",
"data",
"+=",
"`",
"`",
";",
"data",
"+=",
"`",
"`",
";",
"fs",
".",
"writeFileSync",
"(",
"path",
".",
"resolve",
"(",
"__dirname",
",",
"\"../src/unicodesets.js\"",
")",
",",
"data",
",",
"err",
"=>",
"{",
"if",
"(",
"err",
")",
"{",
"throw",
"err",
";",
"}",
"}",
")",
";",
"}"
] |
Generating a unicodesets.js file so that we don't have to reparse the file each time the parser is called.
|
[
"Generating",
"a",
"unicodesets",
".",
"js",
"file",
"so",
"that",
"we",
"don",
"t",
"have",
"to",
"reparse",
"the",
"file",
"each",
"time",
"the",
"parser",
"is",
"called",
"."
] |
3555a0c6e53697f0026bf8bf56403bb6b7719b17
|
https://github.com/jhipster/prettier-java/blob/3555a0c6e53697f0026bf8bf56403bb6b7719b17/packages/java-parser/scripts/unicode.js#L151-L237
|
12,203
|
stampit-org/stampit
|
src/stampit.js
|
standardiseDescriptor
|
function standardiseDescriptor(descr) {
var4 = {};
var4[_methods] = descr[_methods] || _undefined;
var1 = descr[_properties];
var2 = descr.props;
var4[_properties] = isObject(var1 || var2) ? assign({}, var2, var1) : _undefined;
var4[_initializers] = extractUniqueFunctions(descr.init, descr[_initializers]);
var4[_composers] = extractUniqueFunctions(descr[_composers]);
var1 = descr[_deepProperties];
var2 = descr[_deepProps];
var4[_deepProperties] = isObject(var1 || var2) ? merge({}, var2, var1) : _undefined;
var4[_propertyDescriptors] = descr[_propertyDescriptors];
var1 = descr[_staticProperties];
var2 = descr.statics;
var4[_staticProperties] = isObject(var1 || var2) ? assign({}, var2, var1) : _undefined;
var1 = descr[_staticDeepProperties];
var2 = descr[_deepStatics];
var4[_staticDeepProperties] = isObject(var1 || var2) ? merge({}, var2, var1) : _undefined;
var1 = descr[_staticPropertyDescriptors];
var2 = descr.name && {name: {value: descr.name}};
var4[_staticPropertyDescriptors] = isObject(var2 || var1) ? assign({}, var1, var2) : _undefined;
var1 = descr[_configuration];
var2 = descr.conf;
var4[_configuration] = isObject(var1 || var2) ? assign({}, var2, var1) : _undefined;
var1 = descr[_deepConfiguration];
var2 = descr[_deepConf];
var4[_deepConfiguration] = isObject(var1 || var2) ? merge({}, var2, var1) : _undefined;
return var4;
}
|
javascript
|
function standardiseDescriptor(descr) {
var4 = {};
var4[_methods] = descr[_methods] || _undefined;
var1 = descr[_properties];
var2 = descr.props;
var4[_properties] = isObject(var1 || var2) ? assign({}, var2, var1) : _undefined;
var4[_initializers] = extractUniqueFunctions(descr.init, descr[_initializers]);
var4[_composers] = extractUniqueFunctions(descr[_composers]);
var1 = descr[_deepProperties];
var2 = descr[_deepProps];
var4[_deepProperties] = isObject(var1 || var2) ? merge({}, var2, var1) : _undefined;
var4[_propertyDescriptors] = descr[_propertyDescriptors];
var1 = descr[_staticProperties];
var2 = descr.statics;
var4[_staticProperties] = isObject(var1 || var2) ? assign({}, var2, var1) : _undefined;
var1 = descr[_staticDeepProperties];
var2 = descr[_deepStatics];
var4[_staticDeepProperties] = isObject(var1 || var2) ? merge({}, var2, var1) : _undefined;
var1 = descr[_staticPropertyDescriptors];
var2 = descr.name && {name: {value: descr.name}};
var4[_staticPropertyDescriptors] = isObject(var2 || var1) ? assign({}, var1, var2) : _undefined;
var1 = descr[_configuration];
var2 = descr.conf;
var4[_configuration] = isObject(var1 || var2) ? assign({}, var2, var1) : _undefined;
var1 = descr[_deepConfiguration];
var2 = descr[_deepConf];
var4[_deepConfiguration] = isObject(var1 || var2) ? merge({}, var2, var1) : _undefined;
return var4;
}
|
[
"function",
"standardiseDescriptor",
"(",
"descr",
")",
"{",
"var4",
"=",
"{",
"}",
";",
"var4",
"[",
"_methods",
"]",
"=",
"descr",
"[",
"_methods",
"]",
"||",
"_undefined",
";",
"var1",
"=",
"descr",
"[",
"_properties",
"]",
";",
"var2",
"=",
"descr",
".",
"props",
";",
"var4",
"[",
"_properties",
"]",
"=",
"isObject",
"(",
"var1",
"||",
"var2",
")",
"?",
"assign",
"(",
"{",
"}",
",",
"var2",
",",
"var1",
")",
":",
"_undefined",
";",
"var4",
"[",
"_initializers",
"]",
"=",
"extractUniqueFunctions",
"(",
"descr",
".",
"init",
",",
"descr",
"[",
"_initializers",
"]",
")",
";",
"var4",
"[",
"_composers",
"]",
"=",
"extractUniqueFunctions",
"(",
"descr",
"[",
"_composers",
"]",
")",
";",
"var1",
"=",
"descr",
"[",
"_deepProperties",
"]",
";",
"var2",
"=",
"descr",
"[",
"_deepProps",
"]",
";",
"var4",
"[",
"_deepProperties",
"]",
"=",
"isObject",
"(",
"var1",
"||",
"var2",
")",
"?",
"merge",
"(",
"{",
"}",
",",
"var2",
",",
"var1",
")",
":",
"_undefined",
";",
"var4",
"[",
"_propertyDescriptors",
"]",
"=",
"descr",
"[",
"_propertyDescriptors",
"]",
";",
"var1",
"=",
"descr",
"[",
"_staticProperties",
"]",
";",
"var2",
"=",
"descr",
".",
"statics",
";",
"var4",
"[",
"_staticProperties",
"]",
"=",
"isObject",
"(",
"var1",
"||",
"var2",
")",
"?",
"assign",
"(",
"{",
"}",
",",
"var2",
",",
"var1",
")",
":",
"_undefined",
";",
"var1",
"=",
"descr",
"[",
"_staticDeepProperties",
"]",
";",
"var2",
"=",
"descr",
"[",
"_deepStatics",
"]",
";",
"var4",
"[",
"_staticDeepProperties",
"]",
"=",
"isObject",
"(",
"var1",
"||",
"var2",
")",
"?",
"merge",
"(",
"{",
"}",
",",
"var2",
",",
"var1",
")",
":",
"_undefined",
";",
"var1",
"=",
"descr",
"[",
"_staticPropertyDescriptors",
"]",
";",
"var2",
"=",
"descr",
".",
"name",
"&&",
"{",
"name",
":",
"{",
"value",
":",
"descr",
".",
"name",
"}",
"}",
";",
"var4",
"[",
"_staticPropertyDescriptors",
"]",
"=",
"isObject",
"(",
"var2",
"||",
"var1",
")",
"?",
"assign",
"(",
"{",
"}",
",",
"var1",
",",
"var2",
")",
":",
"_undefined",
";",
"var1",
"=",
"descr",
"[",
"_configuration",
"]",
";",
"var2",
"=",
"descr",
".",
"conf",
";",
"var4",
"[",
"_configuration",
"]",
"=",
"isObject",
"(",
"var1",
"||",
"var2",
")",
"?",
"assign",
"(",
"{",
"}",
",",
"var2",
",",
"var1",
")",
":",
"_undefined",
";",
"var1",
"=",
"descr",
"[",
"_deepConfiguration",
"]",
";",
"var2",
"=",
"descr",
"[",
"_deepConf",
"]",
";",
"var4",
"[",
"_deepConfiguration",
"]",
"=",
"isObject",
"(",
"var1",
"||",
"var2",
")",
"?",
"merge",
"(",
"{",
"}",
",",
"var2",
",",
"var1",
")",
":",
"_undefined",
";",
"return",
"var4",
";",
"}"
] |
Converts stampit extended descriptor to a standard one.
@param {Object|*} descr
methods
properties
props
initializers
init
deepProperties
deepProps
propertyDescriptors
staticProperties
statics
staticDeepProperties
deepStatics
staticPropertyDescriptors
configuration
conf
deepConfiguration
deepConf
composers
@returns {Descriptor} Standardised descriptor
|
[
"Converts",
"stampit",
"extended",
"descriptor",
"to",
"a",
"standard",
"one",
"."
] |
11b1aaad02e5942450366b97f1881346b1171685
|
https://github.com/stampit-org/stampit/blob/11b1aaad02e5942450366b97f1881346b1171685/src/stampit.js#L133-L173
|
12,204
|
ionic-team/ionic-app-scripts
|
bin/ion-dev.js
|
function(msg) {
var status = 'success';
if (msg.type === 'started') {
status = 'active';
this.buildingNotification(true);
} else {
if (msg.data.reloadApp) {
this.reloadApp();
return;
}
status = msg.data.diagnosticsHtml ? 'error' : 'success';
this.buildingNotification(false);
var diagnosticsEle = document.getElementById('ion-diagnostics');
// If we have an element but no html created yet
if (diagnosticsEle && !msg.data.diagnosticsHtml) {
diagnosticsEle.classList.add('ion-diagnostics-fade-out');
this.diagnosticsTimerId = setTimeout(function() {
var diagnosticsEle = document.getElementById('ion-diagnostics');
if (diagnosticsEle) {
diagnosticsEle.parentElement.removeChild(diagnosticsEle);
}
}, 100);
} else if (msg.data.diagnosticsHtml) {
// We don't have an element but we have diagnostics HTML, so create the error
if (!diagnosticsEle) {
diagnosticsEle = document.createElement('div');
diagnosticsEle.id = 'ion-diagnostics';
diagnosticsEle.className = 'ion-diagnostics-fade-out';
document.body.insertBefore(diagnosticsEle, document.body.firstChild);
}
// Show the last error
clearTimeout(this.diagnosticsTimerId);
this.diagnosticsTimerId = setTimeout(function() {
var diagnosticsEle = document.getElementById('ion-diagnostics');
if (diagnosticsEle) {
diagnosticsEle.classList.remove('ion-diagnostics-fade-out');
}
}, 24);
diagnosticsEle.innerHTML = msg.data.diagnosticsHtml
}
}
this.buildStatus(status);
}
|
javascript
|
function(msg) {
var status = 'success';
if (msg.type === 'started') {
status = 'active';
this.buildingNotification(true);
} else {
if (msg.data.reloadApp) {
this.reloadApp();
return;
}
status = msg.data.diagnosticsHtml ? 'error' : 'success';
this.buildingNotification(false);
var diagnosticsEle = document.getElementById('ion-diagnostics');
// If we have an element but no html created yet
if (diagnosticsEle && !msg.data.diagnosticsHtml) {
diagnosticsEle.classList.add('ion-diagnostics-fade-out');
this.diagnosticsTimerId = setTimeout(function() {
var diagnosticsEle = document.getElementById('ion-diagnostics');
if (diagnosticsEle) {
diagnosticsEle.parentElement.removeChild(diagnosticsEle);
}
}, 100);
} else if (msg.data.diagnosticsHtml) {
// We don't have an element but we have diagnostics HTML, so create the error
if (!diagnosticsEle) {
diagnosticsEle = document.createElement('div');
diagnosticsEle.id = 'ion-diagnostics';
diagnosticsEle.className = 'ion-diagnostics-fade-out';
document.body.insertBefore(diagnosticsEle, document.body.firstChild);
}
// Show the last error
clearTimeout(this.diagnosticsTimerId);
this.diagnosticsTimerId = setTimeout(function() {
var diagnosticsEle = document.getElementById('ion-diagnostics');
if (diagnosticsEle) {
diagnosticsEle.classList.remove('ion-diagnostics-fade-out');
}
}, 24);
diagnosticsEle.innerHTML = msg.data.diagnosticsHtml
}
}
this.buildStatus(status);
}
|
[
"function",
"(",
"msg",
")",
"{",
"var",
"status",
"=",
"'success'",
";",
"if",
"(",
"msg",
".",
"type",
"===",
"'started'",
")",
"{",
"status",
"=",
"'active'",
";",
"this",
".",
"buildingNotification",
"(",
"true",
")",
";",
"}",
"else",
"{",
"if",
"(",
"msg",
".",
"data",
".",
"reloadApp",
")",
"{",
"this",
".",
"reloadApp",
"(",
")",
";",
"return",
";",
"}",
"status",
"=",
"msg",
".",
"data",
".",
"diagnosticsHtml",
"?",
"'error'",
":",
"'success'",
";",
"this",
".",
"buildingNotification",
"(",
"false",
")",
";",
"var",
"diagnosticsEle",
"=",
"document",
".",
"getElementById",
"(",
"'ion-diagnostics'",
")",
";",
"// If we have an element but no html created yet",
"if",
"(",
"diagnosticsEle",
"&&",
"!",
"msg",
".",
"data",
".",
"diagnosticsHtml",
")",
"{",
"diagnosticsEle",
".",
"classList",
".",
"add",
"(",
"'ion-diagnostics-fade-out'",
")",
";",
"this",
".",
"diagnosticsTimerId",
"=",
"setTimeout",
"(",
"function",
"(",
")",
"{",
"var",
"diagnosticsEle",
"=",
"document",
".",
"getElementById",
"(",
"'ion-diagnostics'",
")",
";",
"if",
"(",
"diagnosticsEle",
")",
"{",
"diagnosticsEle",
".",
"parentElement",
".",
"removeChild",
"(",
"diagnosticsEle",
")",
";",
"}",
"}",
",",
"100",
")",
";",
"}",
"else",
"if",
"(",
"msg",
".",
"data",
".",
"diagnosticsHtml",
")",
"{",
"// We don't have an element but we have diagnostics HTML, so create the error",
"if",
"(",
"!",
"diagnosticsEle",
")",
"{",
"diagnosticsEle",
"=",
"document",
".",
"createElement",
"(",
"'div'",
")",
";",
"diagnosticsEle",
".",
"id",
"=",
"'ion-diagnostics'",
";",
"diagnosticsEle",
".",
"className",
"=",
"'ion-diagnostics-fade-out'",
";",
"document",
".",
"body",
".",
"insertBefore",
"(",
"diagnosticsEle",
",",
"document",
".",
"body",
".",
"firstChild",
")",
";",
"}",
"// Show the last error",
"clearTimeout",
"(",
"this",
".",
"diagnosticsTimerId",
")",
";",
"this",
".",
"diagnosticsTimerId",
"=",
"setTimeout",
"(",
"function",
"(",
")",
"{",
"var",
"diagnosticsEle",
"=",
"document",
".",
"getElementById",
"(",
"'ion-diagnostics'",
")",
";",
"if",
"(",
"diagnosticsEle",
")",
"{",
"diagnosticsEle",
".",
"classList",
".",
"remove",
"(",
"'ion-diagnostics-fade-out'",
")",
";",
"}",
"}",
",",
"24",
")",
";",
"diagnosticsEle",
".",
"innerHTML",
"=",
"msg",
".",
"data",
".",
"diagnosticsHtml",
"}",
"}",
"this",
".",
"buildStatus",
"(",
"status",
")",
";",
"}"
] |
Process a build update message and display something to the friendly user.
|
[
"Process",
"a",
"build",
"update",
"message",
"and",
"display",
"something",
"to",
"the",
"friendly",
"user",
"."
] |
5d7ca3825e1aada6a9457a98572d4e86d5e4b0e6
|
https://github.com/ionic-team/ionic-app-scripts/blob/5d7ca3825e1aada6a9457a98572d4e86d5e4b0e6/bin/ion-dev.js#L183-L239
|
|
12,205
|
ionic-team/ionic-app-scripts
|
lab/static/js/lab.js
|
bindToggles
|
function bindToggles() {
// Watch for changes on the checkboxes in the device dropdown
var iphone = $('#device-iphone');
var android = $('#device-android');
var windows = $('#device-windows');
var devices = [iphone, android, windows];
for(var i in devices) {
devices[i].addEventListener('change', function(e) {
var device = this.name;
console.log('Device changed', device, this.checked);
showDevice(device, this.checked);
saveLastDevices(device, this.checked);
});
}
}
|
javascript
|
function bindToggles() {
// Watch for changes on the checkboxes in the device dropdown
var iphone = $('#device-iphone');
var android = $('#device-android');
var windows = $('#device-windows');
var devices = [iphone, android, windows];
for(var i in devices) {
devices[i].addEventListener('change', function(e) {
var device = this.name;
console.log('Device changed', device, this.checked);
showDevice(device, this.checked);
saveLastDevices(device, this.checked);
});
}
}
|
[
"function",
"bindToggles",
"(",
")",
"{",
"// Watch for changes on the checkboxes in the device dropdown",
"var",
"iphone",
"=",
"$",
"(",
"'#device-iphone'",
")",
";",
"var",
"android",
"=",
"$",
"(",
"'#device-android'",
")",
";",
"var",
"windows",
"=",
"$",
"(",
"'#device-windows'",
")",
";",
"var",
"devices",
"=",
"[",
"iphone",
",",
"android",
",",
"windows",
"]",
";",
"for",
"(",
"var",
"i",
"in",
"devices",
")",
"{",
"devices",
"[",
"i",
"]",
".",
"addEventListener",
"(",
"'change'",
",",
"function",
"(",
"e",
")",
"{",
"var",
"device",
"=",
"this",
".",
"name",
";",
"console",
".",
"log",
"(",
"'Device changed'",
",",
"device",
",",
"this",
".",
"checked",
")",
";",
"showDevice",
"(",
"device",
",",
"this",
".",
"checked",
")",
";",
"saveLastDevices",
"(",
"device",
",",
"this",
".",
"checked",
")",
";",
"}",
")",
";",
"}",
"}"
] |
Bind the dropdown platform toggles
|
[
"Bind",
"the",
"dropdown",
"platform",
"toggles"
] |
5d7ca3825e1aada6a9457a98572d4e86d5e4b0e6
|
https://github.com/ionic-team/ionic-app-scripts/blob/5d7ca3825e1aada6a9457a98572d4e86d5e4b0e6/lab/static/js/lab.js#L96-L112
|
12,206
|
ionic-team/ionic-app-scripts
|
lab/static/js/lab.js
|
showDevice
|
function showDevice(device, isShowing) {
$('#device-' + device).checked = isShowing;
var rendered = $('#' + device);
if(!rendered) {
var template = $('#' + device + '-frame-template');
var clone = document.importNode(template, true);
$('preview').appendChild(clone.content);
//check for extra params in location.url to pass on to iframes
var params = document.location.href.split('?');
if (params) {
var newparams = params[params.length - 1];
var oldsrc = $('preview .frame').getAttribute('src');
$('preview .frame').setAttribute('src', oldsrc + '&' + newparams);
}
} else {
rendered.style.display = isShowing ? '' : 'none';
}
}
|
javascript
|
function showDevice(device, isShowing) {
$('#device-' + device).checked = isShowing;
var rendered = $('#' + device);
if(!rendered) {
var template = $('#' + device + '-frame-template');
var clone = document.importNode(template, true);
$('preview').appendChild(clone.content);
//check for extra params in location.url to pass on to iframes
var params = document.location.href.split('?');
if (params) {
var newparams = params[params.length - 1];
var oldsrc = $('preview .frame').getAttribute('src');
$('preview .frame').setAttribute('src', oldsrc + '&' + newparams);
}
} else {
rendered.style.display = isShowing ? '' : 'none';
}
}
|
[
"function",
"showDevice",
"(",
"device",
",",
"isShowing",
")",
"{",
"$",
"(",
"'#device-'",
"+",
"device",
")",
".",
"checked",
"=",
"isShowing",
";",
"var",
"rendered",
"=",
"$",
"(",
"'#'",
"+",
"device",
")",
";",
"if",
"(",
"!",
"rendered",
")",
"{",
"var",
"template",
"=",
"$",
"(",
"'#'",
"+",
"device",
"+",
"'-frame-template'",
")",
";",
"var",
"clone",
"=",
"document",
".",
"importNode",
"(",
"template",
",",
"true",
")",
";",
"$",
"(",
"'preview'",
")",
".",
"appendChild",
"(",
"clone",
".",
"content",
")",
";",
"//check for extra params in location.url to pass on to iframes",
"var",
"params",
"=",
"document",
".",
"location",
".",
"href",
".",
"split",
"(",
"'?'",
")",
";",
"if",
"(",
"params",
")",
"{",
"var",
"newparams",
"=",
"params",
"[",
"params",
".",
"length",
"-",
"1",
"]",
";",
"var",
"oldsrc",
"=",
"$",
"(",
"'preview .frame'",
")",
".",
"getAttribute",
"(",
"'src'",
")",
";",
"$",
"(",
"'preview .frame'",
")",
".",
"setAttribute",
"(",
"'src'",
",",
"oldsrc",
"+",
"'&'",
"+",
"newparams",
")",
";",
"}",
"}",
"else",
"{",
"rendered",
".",
"style",
".",
"display",
"=",
"isShowing",
"?",
"''",
":",
"'none'",
";",
"}",
"}"
] |
Show one of the devices
|
[
"Show",
"one",
"of",
"the",
"devices"
] |
5d7ca3825e1aada6a9457a98572d4e86d5e4b0e6
|
https://github.com/ionic-team/ionic-app-scripts/blob/5d7ca3825e1aada6a9457a98572d4e86d5e4b0e6/lab/static/js/lab.js#L115-L133
|
12,207
|
angular-slider/angularjs-slider
|
demo/lib/ui-bootstrap-tpls.js
|
toggleTopWindowClass
|
function toggleTopWindowClass(toggleSwitch) {
var modalWindow;
if (openedWindows.length() > 0) {
modalWindow = openedWindows.top().value;
modalWindow.modalDomEl.toggleClass(modalWindow.windowTopClass || '', toggleSwitch);
}
}
|
javascript
|
function toggleTopWindowClass(toggleSwitch) {
var modalWindow;
if (openedWindows.length() > 0) {
modalWindow = openedWindows.top().value;
modalWindow.modalDomEl.toggleClass(modalWindow.windowTopClass || '', toggleSwitch);
}
}
|
[
"function",
"toggleTopWindowClass",
"(",
"toggleSwitch",
")",
"{",
"var",
"modalWindow",
";",
"if",
"(",
"openedWindows",
".",
"length",
"(",
")",
">",
"0",
")",
"{",
"modalWindow",
"=",
"openedWindows",
".",
"top",
"(",
")",
".",
"value",
";",
"modalWindow",
".",
"modalDomEl",
".",
"toggleClass",
"(",
"modalWindow",
".",
"windowTopClass",
"||",
"''",
",",
"toggleSwitch",
")",
";",
"}",
"}"
] |
Add or remove "windowTopClass" from the top window in the stack
|
[
"Add",
"or",
"remove",
"windowTopClass",
"from",
"the",
"top",
"window",
"in",
"the",
"stack"
] |
28bf4e71c5c8e87bce4517974d2c65e6d8a5c295
|
https://github.com/angular-slider/angularjs-slider/blob/28bf4e71c5c8e87bce4517974d2c65e6d8a5c295/demo/lib/ui-bootstrap-tpls.js#L3786-L3793
|
12,208
|
angular-slider/angularjs-slider
|
demo/lib/ui-bootstrap-tpls.js
|
prepareTooltip
|
function prepareTooltip() {
ttScope.title = attrs[prefix + 'Title'];
if (contentParse) {
ttScope.content = contentParse(scope);
} else {
ttScope.content = attrs[ttType];
}
ttScope.popupClass = attrs[prefix + 'Class'];
ttScope.placement = angular.isDefined(attrs[prefix + 'Placement']) ? attrs[prefix + 'Placement'] : options.placement;
var delay = parseInt(attrs[prefix + 'PopupDelay'], 10);
var closeDelay = parseInt(attrs[prefix + 'PopupCloseDelay'], 10);
ttScope.popupDelay = !isNaN(delay) ? delay : options.popupDelay;
ttScope.popupCloseDelay = !isNaN(closeDelay) ? closeDelay : options.popupCloseDelay;
}
|
javascript
|
function prepareTooltip() {
ttScope.title = attrs[prefix + 'Title'];
if (contentParse) {
ttScope.content = contentParse(scope);
} else {
ttScope.content = attrs[ttType];
}
ttScope.popupClass = attrs[prefix + 'Class'];
ttScope.placement = angular.isDefined(attrs[prefix + 'Placement']) ? attrs[prefix + 'Placement'] : options.placement;
var delay = parseInt(attrs[prefix + 'PopupDelay'], 10);
var closeDelay = parseInt(attrs[prefix + 'PopupCloseDelay'], 10);
ttScope.popupDelay = !isNaN(delay) ? delay : options.popupDelay;
ttScope.popupCloseDelay = !isNaN(closeDelay) ? closeDelay : options.popupCloseDelay;
}
|
[
"function",
"prepareTooltip",
"(",
")",
"{",
"ttScope",
".",
"title",
"=",
"attrs",
"[",
"prefix",
"+",
"'Title'",
"]",
";",
"if",
"(",
"contentParse",
")",
"{",
"ttScope",
".",
"content",
"=",
"contentParse",
"(",
"scope",
")",
";",
"}",
"else",
"{",
"ttScope",
".",
"content",
"=",
"attrs",
"[",
"ttType",
"]",
";",
"}",
"ttScope",
".",
"popupClass",
"=",
"attrs",
"[",
"prefix",
"+",
"'Class'",
"]",
";",
"ttScope",
".",
"placement",
"=",
"angular",
".",
"isDefined",
"(",
"attrs",
"[",
"prefix",
"+",
"'Placement'",
"]",
")",
"?",
"attrs",
"[",
"prefix",
"+",
"'Placement'",
"]",
":",
"options",
".",
"placement",
";",
"var",
"delay",
"=",
"parseInt",
"(",
"attrs",
"[",
"prefix",
"+",
"'PopupDelay'",
"]",
",",
"10",
")",
";",
"var",
"closeDelay",
"=",
"parseInt",
"(",
"attrs",
"[",
"prefix",
"+",
"'PopupCloseDelay'",
"]",
",",
"10",
")",
";",
"ttScope",
".",
"popupDelay",
"=",
"!",
"isNaN",
"(",
"delay",
")",
"?",
"delay",
":",
"options",
".",
"popupDelay",
";",
"ttScope",
".",
"popupCloseDelay",
"=",
"!",
"isNaN",
"(",
"closeDelay",
")",
"?",
"closeDelay",
":",
"options",
".",
"popupCloseDelay",
";",
"}"
] |
Set the inital scope values. Once
the tooltip is created, the observers
will be added to keep things in synch.
|
[
"Set",
"the",
"inital",
"scope",
"values",
".",
"Once",
"the",
"tooltip",
"is",
"created",
"the",
"observers",
"will",
"be",
"added",
"to",
"keep",
"things",
"in",
"synch",
"."
] |
28bf4e71c5c8e87bce4517974d2c65e6d8a5c295
|
https://github.com/angular-slider/angularjs-slider/blob/28bf4e71c5c8e87bce4517974d2c65e6d8a5c295/demo/lib/ui-bootstrap-tpls.js#L5204-L5219
|
12,209
|
angular-slider/angularjs-slider
|
demo/lib/ui-bootstrap-tpls.js
|
recalculatePosition
|
function recalculatePosition() {
scope.position = appendToBody ? $position.offset(element) : $position.position(element);
scope.position.top += element.prop('offsetHeight');
}
|
javascript
|
function recalculatePosition() {
scope.position = appendToBody ? $position.offset(element) : $position.position(element);
scope.position.top += element.prop('offsetHeight');
}
|
[
"function",
"recalculatePosition",
"(",
")",
"{",
"scope",
".",
"position",
"=",
"appendToBody",
"?",
"$position",
".",
"offset",
"(",
"element",
")",
":",
"$position",
".",
"position",
"(",
"element",
")",
";",
"scope",
".",
"position",
".",
"top",
"+=",
"element",
".",
"prop",
"(",
"'offsetHeight'",
")",
";",
"}"
] |
recalculate actual position and set new values to scope after digest loop is popup in right position
|
[
"recalculate",
"actual",
"position",
"and",
"set",
"new",
"values",
"to",
"scope",
"after",
"digest",
"loop",
"is",
"popup",
"in",
"right",
"position"
] |
28bf4e71c5c8e87bce4517974d2c65e6d8a5c295
|
https://github.com/angular-slider/angularjs-slider/blob/28bf4e71c5c8e87bce4517974d2c65e6d8a5c295/demo/lib/ui-bootstrap-tpls.js#L7312-L7315
|
12,210
|
angular-slider/angularjs-slider
|
demo/lib/ui-bootstrap-tpls.js
|
function(evt) {
// Issue #3973
// Firefox treats right click as a click on document
if (element[0] !== evt.target && evt.which !== 3 && scope.matches.length !== 0) {
resetMatches();
if (!$rootScope.$$phase) {
scope.$digest();
}
}
}
|
javascript
|
function(evt) {
// Issue #3973
// Firefox treats right click as a click on document
if (element[0] !== evt.target && evt.which !== 3 && scope.matches.length !== 0) {
resetMatches();
if (!$rootScope.$$phase) {
scope.$digest();
}
}
}
|
[
"function",
"(",
"evt",
")",
"{",
"// Issue #3973",
"// Firefox treats right click as a click on document",
"if",
"(",
"element",
"[",
"0",
"]",
"!==",
"evt",
".",
"target",
"&&",
"evt",
".",
"which",
"!==",
"3",
"&&",
"scope",
".",
"matches",
".",
"length",
"!==",
"0",
")",
"{",
"resetMatches",
"(",
")",
";",
"if",
"(",
"!",
"$rootScope",
".",
"$$phase",
")",
"{",
"scope",
".",
"$digest",
"(",
")",
";",
"}",
"}",
"}"
] |
Keep reference to click handler to unbind it.
|
[
"Keep",
"reference",
"to",
"click",
"handler",
"to",
"unbind",
"it",
"."
] |
28bf4e71c5c8e87bce4517974d2c65e6d8a5c295
|
https://github.com/angular-slider/angularjs-slider/blob/28bf4e71c5c8e87bce4517974d2c65e6d8a5c295/demo/lib/ui-bootstrap-tpls.js#L7410-L7419
|
|
12,211
|
icebob/fastest-validator
|
lib/validator.js
|
Validator
|
function Validator(opts) {
this.opts = {
messages: deepExtend({}, defaultMessages)
};
if (opts)
deepExtend(this.opts, opts);
this.messages = this.opts.messages;
this.messageKeys = Object.keys(this.messages);
// Load rules
this.rules = loadRules();
this.cache = new Map();
}
|
javascript
|
function Validator(opts) {
this.opts = {
messages: deepExtend({}, defaultMessages)
};
if (opts)
deepExtend(this.opts, opts);
this.messages = this.opts.messages;
this.messageKeys = Object.keys(this.messages);
// Load rules
this.rules = loadRules();
this.cache = new Map();
}
|
[
"function",
"Validator",
"(",
"opts",
")",
"{",
"this",
".",
"opts",
"=",
"{",
"messages",
":",
"deepExtend",
"(",
"{",
"}",
",",
"defaultMessages",
")",
"}",
";",
"if",
"(",
"opts",
")",
"deepExtend",
"(",
"this",
".",
"opts",
",",
"opts",
")",
";",
"this",
".",
"messages",
"=",
"this",
".",
"opts",
".",
"messages",
";",
"this",
".",
"messageKeys",
"=",
"Object",
".",
"keys",
"(",
"this",
".",
"messages",
")",
";",
"// Load rules",
"this",
".",
"rules",
"=",
"loadRules",
"(",
")",
";",
"this",
".",
"cache",
"=",
"new",
"Map",
"(",
")",
";",
"}"
] |
Validator class constructor
@param {Object} opts
|
[
"Validator",
"class",
"constructor"
] |
a5f2b056bd9d92037b90dd214d0aa2a43073bd6b
|
https://github.com/icebob/fastest-validator/blob/a5f2b056bd9d92037b90dd214d0aa2a43073bd6b/lib/validator.js#L59-L73
|
12,212
|
icebob/fastest-validator
|
lib/helpers/flatten.js
|
flatten
|
function flatten(array, target) {
const result = target || [];
for (let i = 0; i < array.length; ++i) {
if (Array.isArray(array[i])) {
flatten(array[i], result);
}
else {
result.push(array[i]);
}
}
return result;
}
|
javascript
|
function flatten(array, target) {
const result = target || [];
for (let i = 0; i < array.length; ++i) {
if (Array.isArray(array[i])) {
flatten(array[i], result);
}
else {
result.push(array[i]);
}
}
return result;
}
|
[
"function",
"flatten",
"(",
"array",
",",
"target",
")",
"{",
"const",
"result",
"=",
"target",
"||",
"[",
"]",
";",
"for",
"(",
"let",
"i",
"=",
"0",
";",
"i",
"<",
"array",
".",
"length",
";",
"++",
"i",
")",
"{",
"if",
"(",
"Array",
".",
"isArray",
"(",
"array",
"[",
"i",
"]",
")",
")",
"{",
"flatten",
"(",
"array",
"[",
"i",
"]",
",",
"result",
")",
";",
"}",
"else",
"{",
"result",
".",
"push",
"(",
"array",
"[",
"i",
"]",
")",
";",
"}",
"}",
"return",
"result",
";",
"}"
] |
Flatten an array
@param {Array} array
@param {Array} target
@returns Array flattened array
|
[
"Flatten",
"an",
"array"
] |
a5f2b056bd9d92037b90dd214d0aa2a43073bd6b
|
https://github.com/icebob/fastest-validator/blob/a5f2b056bd9d92037b90dd214d0aa2a43073bd6b/lib/helpers/flatten.js#L9-L22
|
12,213
|
maxazan/jquery-treegrid
|
js/jquery.treegrid.js
|
function() {
var $this = $(this);
//Save state on change
$this.on("change", function() {
var $this = $(this);
if (typeof($this.treegrid('getSetting', 'onChange')) === "function") {
$this.treegrid('getSetting', 'onChange').apply($this);
}
});
//Default behavior on collapse
$this.on("collapse", function() {
var $this = $(this);
if (typeof($this.treegrid('getSetting', 'onCollapse')) === "function") {
$this.treegrid('getSetting', 'onCollapse').apply($this);
}
});
//Default behavior on expand
$this.on("expand", function() {
var $this = $(this);
if (typeof($this.treegrid('getSetting', 'onExpand')) === "function") {
$this.treegrid('getSetting', 'onExpand').apply($this);
}
});
return $this;
}
|
javascript
|
function() {
var $this = $(this);
//Save state on change
$this.on("change", function() {
var $this = $(this);
if (typeof($this.treegrid('getSetting', 'onChange')) === "function") {
$this.treegrid('getSetting', 'onChange').apply($this);
}
});
//Default behavior on collapse
$this.on("collapse", function() {
var $this = $(this);
if (typeof($this.treegrid('getSetting', 'onCollapse')) === "function") {
$this.treegrid('getSetting', 'onCollapse').apply($this);
}
});
//Default behavior on expand
$this.on("expand", function() {
var $this = $(this);
if (typeof($this.treegrid('getSetting', 'onExpand')) === "function") {
$this.treegrid('getSetting', 'onExpand').apply($this);
}
});
return $this;
}
|
[
"function",
"(",
")",
"{",
"var",
"$this",
"=",
"$",
"(",
"this",
")",
";",
"//Save state on change\r",
"$this",
".",
"on",
"(",
"\"change\"",
",",
"function",
"(",
")",
"{",
"var",
"$this",
"=",
"$",
"(",
"this",
")",
";",
"if",
"(",
"typeof",
"(",
"$this",
".",
"treegrid",
"(",
"'getSetting'",
",",
"'onChange'",
")",
")",
"===",
"\"function\"",
")",
"{",
"$this",
".",
"treegrid",
"(",
"'getSetting'",
",",
"'onChange'",
")",
".",
"apply",
"(",
"$this",
")",
";",
"}",
"}",
")",
";",
"//Default behavior on collapse\r",
"$this",
".",
"on",
"(",
"\"collapse\"",
",",
"function",
"(",
")",
"{",
"var",
"$this",
"=",
"$",
"(",
"this",
")",
";",
"if",
"(",
"typeof",
"(",
"$this",
".",
"treegrid",
"(",
"'getSetting'",
",",
"'onCollapse'",
")",
")",
"===",
"\"function\"",
")",
"{",
"$this",
".",
"treegrid",
"(",
"'getSetting'",
",",
"'onCollapse'",
")",
".",
"apply",
"(",
"$this",
")",
";",
"}",
"}",
")",
";",
"//Default behavior on expand\r",
"$this",
".",
"on",
"(",
"\"expand\"",
",",
"function",
"(",
")",
"{",
"var",
"$this",
"=",
"$",
"(",
"this",
")",
";",
"if",
"(",
"typeof",
"(",
"$this",
".",
"treegrid",
"(",
"'getSetting'",
",",
"'onExpand'",
")",
")",
"===",
"\"function\"",
")",
"{",
"$this",
".",
"treegrid",
"(",
"'getSetting'",
",",
"'onExpand'",
")",
".",
"apply",
"(",
"$this",
")",
";",
"}",
"}",
")",
";",
"return",
"$this",
";",
"}"
] |
Initialize events from settings
@returns {Node}
|
[
"Initialize",
"events",
"from",
"settings"
] |
447d66237275cd52ff4c50624920a221caa41ec7
|
https://github.com/maxazan/jquery-treegrid/blob/447d66237275cd52ff4c50624920a221caa41ec7/js/jquery.treegrid.js#L80-L106
|
|
12,214
|
maxazan/jquery-treegrid
|
js/jquery.treegrid.js
|
function() {
var $this = $(this);
var cell = $this.find('td').get($this.treegrid('getSetting', 'treeColumn'));
var tpl = $this.treegrid('getSetting', 'expanderTemplate');
var expander = $this.treegrid('getSetting', 'getExpander').apply(this);
if (expander) {
expander.remove();
}
$(tpl).prependTo(cell).click(function() {
$($(this).closest('tr')).treegrid('toggle');
});
return $this;
}
|
javascript
|
function() {
var $this = $(this);
var cell = $this.find('td').get($this.treegrid('getSetting', 'treeColumn'));
var tpl = $this.treegrid('getSetting', 'expanderTemplate');
var expander = $this.treegrid('getSetting', 'getExpander').apply(this);
if (expander) {
expander.remove();
}
$(tpl).prependTo(cell).click(function() {
$($(this).closest('tr')).treegrid('toggle');
});
return $this;
}
|
[
"function",
"(",
")",
"{",
"var",
"$this",
"=",
"$",
"(",
"this",
")",
";",
"var",
"cell",
"=",
"$this",
".",
"find",
"(",
"'td'",
")",
".",
"get",
"(",
"$this",
".",
"treegrid",
"(",
"'getSetting'",
",",
"'treeColumn'",
")",
")",
";",
"var",
"tpl",
"=",
"$this",
".",
"treegrid",
"(",
"'getSetting'",
",",
"'expanderTemplate'",
")",
";",
"var",
"expander",
"=",
"$this",
".",
"treegrid",
"(",
"'getSetting'",
",",
"'getExpander'",
")",
".",
"apply",
"(",
"this",
")",
";",
"if",
"(",
"expander",
")",
"{",
"expander",
".",
"remove",
"(",
")",
";",
"}",
"$",
"(",
"tpl",
")",
".",
"prependTo",
"(",
"cell",
")",
".",
"click",
"(",
"function",
"(",
")",
"{",
"$",
"(",
"$",
"(",
"this",
")",
".",
"closest",
"(",
"'tr'",
")",
")",
".",
"treegrid",
"(",
"'toggle'",
")",
";",
"}",
")",
";",
"return",
"$this",
";",
"}"
] |
Initialize expander for node
@returns {Node}
|
[
"Initialize",
"expander",
"for",
"node"
] |
447d66237275cd52ff4c50624920a221caa41ec7
|
https://github.com/maxazan/jquery-treegrid/blob/447d66237275cd52ff4c50624920a221caa41ec7/js/jquery.treegrid.js#L112-L124
|
|
12,215
|
maxazan/jquery-treegrid
|
js/jquery.treegrid.js
|
function() {
var $this = $(this);
$this.find('.treegrid-indent').remove();
var tpl = $this.treegrid('getSetting', 'indentTemplate');
var expander = $this.find('.treegrid-expander');
var depth = $this.treegrid('getDepth');
for (var i = 0; i < depth; i++) {
$(tpl).insertBefore(expander);
}
return $this;
}
|
javascript
|
function() {
var $this = $(this);
$this.find('.treegrid-indent').remove();
var tpl = $this.treegrid('getSetting', 'indentTemplate');
var expander = $this.find('.treegrid-expander');
var depth = $this.treegrid('getDepth');
for (var i = 0; i < depth; i++) {
$(tpl).insertBefore(expander);
}
return $this;
}
|
[
"function",
"(",
")",
"{",
"var",
"$this",
"=",
"$",
"(",
"this",
")",
";",
"$this",
".",
"find",
"(",
"'.treegrid-indent'",
")",
".",
"remove",
"(",
")",
";",
"var",
"tpl",
"=",
"$this",
".",
"treegrid",
"(",
"'getSetting'",
",",
"'indentTemplate'",
")",
";",
"var",
"expander",
"=",
"$this",
".",
"find",
"(",
"'.treegrid-expander'",
")",
";",
"var",
"depth",
"=",
"$this",
".",
"treegrid",
"(",
"'getDepth'",
")",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"depth",
";",
"i",
"++",
")",
"{",
"$",
"(",
"tpl",
")",
".",
"insertBefore",
"(",
"expander",
")",
";",
"}",
"return",
"$this",
";",
"}"
] |
Initialize indent for node
@returns {Node}
|
[
"Initialize",
"indent",
"for",
"node"
] |
447d66237275cd52ff4c50624920a221caa41ec7
|
https://github.com/maxazan/jquery-treegrid/blob/447d66237275cd52ff4c50624920a221caa41ec7/js/jquery.treegrid.js#L130-L140
|
|
12,216
|
maxazan/jquery-treegrid
|
js/jquery.treegrid.js
|
function() {
var tree = $(this).treegrid('getTreeContainer');
if (tree.data('first_init') === undefined) {
tree.data('first_init', $.cookie(tree.treegrid('getSetting', 'saveStateName')) === undefined);
}
return tree.data('first_init');
}
|
javascript
|
function() {
var tree = $(this).treegrid('getTreeContainer');
if (tree.data('first_init') === undefined) {
tree.data('first_init', $.cookie(tree.treegrid('getSetting', 'saveStateName')) === undefined);
}
return tree.data('first_init');
}
|
[
"function",
"(",
")",
"{",
"var",
"tree",
"=",
"$",
"(",
"this",
")",
".",
"treegrid",
"(",
"'getTreeContainer'",
")",
";",
"if",
"(",
"tree",
".",
"data",
"(",
"'first_init'",
")",
"===",
"undefined",
")",
"{",
"tree",
".",
"data",
"(",
"'first_init'",
",",
"$",
".",
"cookie",
"(",
"tree",
".",
"treegrid",
"(",
"'getSetting'",
",",
"'saveStateName'",
")",
")",
"===",
"undefined",
")",
";",
"}",
"return",
"tree",
".",
"data",
"(",
"'first_init'",
")",
";",
"}"
] |
Return true if this tree was never been initialised
@returns {Boolean}
|
[
"Return",
"true",
"if",
"this",
"tree",
"was",
"never",
"been",
"initialised"
] |
447d66237275cd52ff4c50624920a221caa41ec7
|
https://github.com/maxazan/jquery-treegrid/blob/447d66237275cd52ff4c50624920a221caa41ec7/js/jquery.treegrid.js#L164-L170
|
|
12,217
|
maxazan/jquery-treegrid
|
js/jquery.treegrid.js
|
function() {
var $this = $(this);
if ($this.treegrid('getSetting', 'saveStateMethod') === 'cookie') {
var stateArrayString = $.cookie($this.treegrid('getSetting', 'saveStateName')) || '';
var stateArray = (stateArrayString === '' ? [] : stateArrayString.split(','));
var nodeId = $this.treegrid('getNodeId');
if ($this.treegrid('isExpanded')) {
if ($.inArray(nodeId, stateArray) === -1) {
stateArray.push(nodeId);
}
} else if ($this.treegrid('isCollapsed')) {
if ($.inArray(nodeId, stateArray) !== -1) {
stateArray.splice($.inArray(nodeId, stateArray), 1);
}
}
$.cookie($this.treegrid('getSetting', 'saveStateName'), stateArray.join(','));
}
return $this;
}
|
javascript
|
function() {
var $this = $(this);
if ($this.treegrid('getSetting', 'saveStateMethod') === 'cookie') {
var stateArrayString = $.cookie($this.treegrid('getSetting', 'saveStateName')) || '';
var stateArray = (stateArrayString === '' ? [] : stateArrayString.split(','));
var nodeId = $this.treegrid('getNodeId');
if ($this.treegrid('isExpanded')) {
if ($.inArray(nodeId, stateArray) === -1) {
stateArray.push(nodeId);
}
} else if ($this.treegrid('isCollapsed')) {
if ($.inArray(nodeId, stateArray) !== -1) {
stateArray.splice($.inArray(nodeId, stateArray), 1);
}
}
$.cookie($this.treegrid('getSetting', 'saveStateName'), stateArray.join(','));
}
return $this;
}
|
[
"function",
"(",
")",
"{",
"var",
"$this",
"=",
"$",
"(",
"this",
")",
";",
"if",
"(",
"$this",
".",
"treegrid",
"(",
"'getSetting'",
",",
"'saveStateMethod'",
")",
"===",
"'cookie'",
")",
"{",
"var",
"stateArrayString",
"=",
"$",
".",
"cookie",
"(",
"$this",
".",
"treegrid",
"(",
"'getSetting'",
",",
"'saveStateName'",
")",
")",
"||",
"''",
";",
"var",
"stateArray",
"=",
"(",
"stateArrayString",
"===",
"''",
"?",
"[",
"]",
":",
"stateArrayString",
".",
"split",
"(",
"','",
")",
")",
";",
"var",
"nodeId",
"=",
"$this",
".",
"treegrid",
"(",
"'getNodeId'",
")",
";",
"if",
"(",
"$this",
".",
"treegrid",
"(",
"'isExpanded'",
")",
")",
"{",
"if",
"(",
"$",
".",
"inArray",
"(",
"nodeId",
",",
"stateArray",
")",
"===",
"-",
"1",
")",
"{",
"stateArray",
".",
"push",
"(",
"nodeId",
")",
";",
"}",
"}",
"else",
"if",
"(",
"$this",
".",
"treegrid",
"(",
"'isCollapsed'",
")",
")",
"{",
"if",
"(",
"$",
".",
"inArray",
"(",
"nodeId",
",",
"stateArray",
")",
"!==",
"-",
"1",
")",
"{",
"stateArray",
".",
"splice",
"(",
"$",
".",
"inArray",
"(",
"nodeId",
",",
"stateArray",
")",
",",
"1",
")",
";",
"}",
"}",
"$",
".",
"cookie",
"(",
"$this",
".",
"treegrid",
"(",
"'getSetting'",
",",
"'saveStateName'",
")",
",",
"stateArray",
".",
"join",
"(",
"','",
")",
")",
";",
"}",
"return",
"$this",
";",
"}"
] |
Save state of current node
@returns {Node}
|
[
"Save",
"state",
"of",
"current",
"node"
] |
447d66237275cd52ff4c50624920a221caa41ec7
|
https://github.com/maxazan/jquery-treegrid/blob/447d66237275cd52ff4c50624920a221caa41ec7/js/jquery.treegrid.js#L176-L196
|
|
12,218
|
maxazan/jquery-treegrid
|
js/jquery.treegrid.js
|
function() {
var $this = $(this);
if ($this.treegrid('getSetting', 'saveStateMethod') === 'cookie') {
var stateArray = $.cookie($this.treegrid('getSetting', 'saveStateName')).split(',');
if ($.inArray($this.treegrid('getNodeId'), stateArray) !== -1) {
$this.treegrid('expand');
} else {
$this.treegrid('collapse');
}
}
return $this;
}
|
javascript
|
function() {
var $this = $(this);
if ($this.treegrid('getSetting', 'saveStateMethod') === 'cookie') {
var stateArray = $.cookie($this.treegrid('getSetting', 'saveStateName')).split(',');
if ($.inArray($this.treegrid('getNodeId'), stateArray) !== -1) {
$this.treegrid('expand');
} else {
$this.treegrid('collapse');
}
}
return $this;
}
|
[
"function",
"(",
")",
"{",
"var",
"$this",
"=",
"$",
"(",
"this",
")",
";",
"if",
"(",
"$this",
".",
"treegrid",
"(",
"'getSetting'",
",",
"'saveStateMethod'",
")",
"===",
"'cookie'",
")",
"{",
"var",
"stateArray",
"=",
"$",
".",
"cookie",
"(",
"$this",
".",
"treegrid",
"(",
"'getSetting'",
",",
"'saveStateName'",
")",
")",
".",
"split",
"(",
"','",
")",
";",
"if",
"(",
"$",
".",
"inArray",
"(",
"$this",
".",
"treegrid",
"(",
"'getNodeId'",
")",
",",
"stateArray",
")",
"!==",
"-",
"1",
")",
"{",
"$this",
".",
"treegrid",
"(",
"'expand'",
")",
";",
"}",
"else",
"{",
"$this",
".",
"treegrid",
"(",
"'collapse'",
")",
";",
"}",
"}",
"return",
"$this",
";",
"}"
] |
Restore state of current node.
@returns {Node}
|
[
"Restore",
"state",
"of",
"current",
"node",
"."
] |
447d66237275cd52ff4c50624920a221caa41ec7
|
https://github.com/maxazan/jquery-treegrid/blob/447d66237275cd52ff4c50624920a221caa41ec7/js/jquery.treegrid.js#L202-L214
|
|
12,219
|
maxazan/jquery-treegrid
|
js/jquery.treegrid.js
|
function() {
if ($(this).treegrid('isNode')) {
var parentNode = $(this).treegrid('getParentNode');
if (parentNode === null) {
if ($(this).treegrid('getNodeId') === $(this).treegrid('getRootNodes').last().treegrid('getNodeId')) {
return true;
}
} else {
if ($(this).treegrid('getNodeId') === parentNode.treegrid('getChildNodes').last().treegrid('getNodeId')) {
return true;
}
}
}
return false;
}
|
javascript
|
function() {
if ($(this).treegrid('isNode')) {
var parentNode = $(this).treegrid('getParentNode');
if (parentNode === null) {
if ($(this).treegrid('getNodeId') === $(this).treegrid('getRootNodes').last().treegrid('getNodeId')) {
return true;
}
} else {
if ($(this).treegrid('getNodeId') === parentNode.treegrid('getChildNodes').last().treegrid('getNodeId')) {
return true;
}
}
}
return false;
}
|
[
"function",
"(",
")",
"{",
"if",
"(",
"$",
"(",
"this",
")",
".",
"treegrid",
"(",
"'isNode'",
")",
")",
"{",
"var",
"parentNode",
"=",
"$",
"(",
"this",
")",
".",
"treegrid",
"(",
"'getParentNode'",
")",
";",
"if",
"(",
"parentNode",
"===",
"null",
")",
"{",
"if",
"(",
"$",
"(",
"this",
")",
".",
"treegrid",
"(",
"'getNodeId'",
")",
"===",
"$",
"(",
"this",
")",
".",
"treegrid",
"(",
"'getRootNodes'",
")",
".",
"last",
"(",
")",
".",
"treegrid",
"(",
"'getNodeId'",
")",
")",
"{",
"return",
"true",
";",
"}",
"}",
"else",
"{",
"if",
"(",
"$",
"(",
"this",
")",
".",
"treegrid",
"(",
"'getNodeId'",
")",
"===",
"parentNode",
".",
"treegrid",
"(",
"'getChildNodes'",
")",
".",
"last",
"(",
")",
".",
"treegrid",
"(",
"'getNodeId'",
")",
")",
"{",
"return",
"true",
";",
"}",
"}",
"}",
"return",
"false",
";",
"}"
] |
Method return true if node last in branch
@returns {Boolean}
|
[
"Method",
"return",
"true",
"if",
"node",
"last",
"in",
"branch"
] |
447d66237275cd52ff4c50624920a221caa41ec7
|
https://github.com/maxazan/jquery-treegrid/blob/447d66237275cd52ff4c50624920a221caa41ec7/js/jquery.treegrid.js#L351-L365
|
|
12,220
|
maxazan/jquery-treegrid
|
js/jquery.treegrid.js
|
function() {
if ($(this).treegrid('isNode')) {
var parentNode = $(this).treegrid('getParentNode');
if (parentNode === null) {
if ($(this).treegrid('getNodeId') === $(this).treegrid('getRootNodes').first().treegrid('getNodeId')) {
return true;
}
} else {
if ($(this).treegrid('getNodeId') === parentNode.treegrid('getChildNodes').first().treegrid('getNodeId')) {
return true;
}
}
}
return false;
}
|
javascript
|
function() {
if ($(this).treegrid('isNode')) {
var parentNode = $(this).treegrid('getParentNode');
if (parentNode === null) {
if ($(this).treegrid('getNodeId') === $(this).treegrid('getRootNodes').first().treegrid('getNodeId')) {
return true;
}
} else {
if ($(this).treegrid('getNodeId') === parentNode.treegrid('getChildNodes').first().treegrid('getNodeId')) {
return true;
}
}
}
return false;
}
|
[
"function",
"(",
")",
"{",
"if",
"(",
"$",
"(",
"this",
")",
".",
"treegrid",
"(",
"'isNode'",
")",
")",
"{",
"var",
"parentNode",
"=",
"$",
"(",
"this",
")",
".",
"treegrid",
"(",
"'getParentNode'",
")",
";",
"if",
"(",
"parentNode",
"===",
"null",
")",
"{",
"if",
"(",
"$",
"(",
"this",
")",
".",
"treegrid",
"(",
"'getNodeId'",
")",
"===",
"$",
"(",
"this",
")",
".",
"treegrid",
"(",
"'getRootNodes'",
")",
".",
"first",
"(",
")",
".",
"treegrid",
"(",
"'getNodeId'",
")",
")",
"{",
"return",
"true",
";",
"}",
"}",
"else",
"{",
"if",
"(",
"$",
"(",
"this",
")",
".",
"treegrid",
"(",
"'getNodeId'",
")",
"===",
"parentNode",
".",
"treegrid",
"(",
"'getChildNodes'",
")",
".",
"first",
"(",
")",
".",
"treegrid",
"(",
"'getNodeId'",
")",
")",
"{",
"return",
"true",
";",
"}",
"}",
"}",
"return",
"false",
";",
"}"
] |
Method return true if node first in branch
@returns {Boolean}
|
[
"Method",
"return",
"true",
"if",
"node",
"first",
"in",
"branch"
] |
447d66237275cd52ff4c50624920a221caa41ec7
|
https://github.com/maxazan/jquery-treegrid/blob/447d66237275cd52ff4c50624920a221caa41ec7/js/jquery.treegrid.js#L371-L385
|
|
12,221
|
maxazan/jquery-treegrid
|
js/jquery.treegrid.js
|
function() {
return $(this).each(function() {
var $this = $(this);
var expander = $this.treegrid('getSetting', 'getExpander').apply(this);
if (expander) {
if (!$this.treegrid('isCollapsed')) {
expander.removeClass($this.treegrid('getSetting', 'expanderCollapsedClass'));
expander.addClass($this.treegrid('getSetting', 'expanderExpandedClass'));
} else {
expander.removeClass($this.treegrid('getSetting', 'expanderExpandedClass'));
expander.addClass($this.treegrid('getSetting', 'expanderCollapsedClass'));
}
} else {
$this.treegrid('initExpander');
$this.treegrid('renderExpander');
}
});
}
|
javascript
|
function() {
return $(this).each(function() {
var $this = $(this);
var expander = $this.treegrid('getSetting', 'getExpander').apply(this);
if (expander) {
if (!$this.treegrid('isCollapsed')) {
expander.removeClass($this.treegrid('getSetting', 'expanderCollapsedClass'));
expander.addClass($this.treegrid('getSetting', 'expanderExpandedClass'));
} else {
expander.removeClass($this.treegrid('getSetting', 'expanderExpandedClass'));
expander.addClass($this.treegrid('getSetting', 'expanderCollapsedClass'));
}
} else {
$this.treegrid('initExpander');
$this.treegrid('renderExpander');
}
});
}
|
[
"function",
"(",
")",
"{",
"return",
"$",
"(",
"this",
")",
".",
"each",
"(",
"function",
"(",
")",
"{",
"var",
"$this",
"=",
"$",
"(",
"this",
")",
";",
"var",
"expander",
"=",
"$this",
".",
"treegrid",
"(",
"'getSetting'",
",",
"'getExpander'",
")",
".",
"apply",
"(",
"this",
")",
";",
"if",
"(",
"expander",
")",
"{",
"if",
"(",
"!",
"$this",
".",
"treegrid",
"(",
"'isCollapsed'",
")",
")",
"{",
"expander",
".",
"removeClass",
"(",
"$this",
".",
"treegrid",
"(",
"'getSetting'",
",",
"'expanderCollapsedClass'",
")",
")",
";",
"expander",
".",
"addClass",
"(",
"$this",
".",
"treegrid",
"(",
"'getSetting'",
",",
"'expanderExpandedClass'",
")",
")",
";",
"}",
"else",
"{",
"expander",
".",
"removeClass",
"(",
"$this",
".",
"treegrid",
"(",
"'getSetting'",
",",
"'expanderExpandedClass'",
")",
")",
";",
"expander",
".",
"addClass",
"(",
"$this",
".",
"treegrid",
"(",
"'getSetting'",
",",
"'expanderCollapsedClass'",
")",
")",
";",
"}",
"}",
"else",
"{",
"$this",
".",
"treegrid",
"(",
"'initExpander'",
")",
";",
"$this",
".",
"treegrid",
"(",
"'renderExpander'",
")",
";",
"}",
"}",
")",
";",
"}"
] |
Rendering expander depends on node state
@returns {Node}
|
[
"Rendering",
"expander",
"depends",
"on",
"node",
"state"
] |
447d66237275cd52ff4c50624920a221caa41ec7
|
https://github.com/maxazan/jquery-treegrid/blob/447d66237275cd52ff4c50624920a221caa41ec7/js/jquery.treegrid.js#L533-L551
|
|
12,222
|
slackapi/node-slack-interactive-messages
|
src/adapter.js
|
formatMatchingConstraints
|
function formatMatchingConstraints(matchingConstraints) {
let ret = {};
if (typeof matchingConstraints === 'undefined' || matchingConstraints === null) {
throw new TypeError('Constraints cannot be undefined or null');
}
if (!isPlainObject(matchingConstraints)) {
ret.callbackId = matchingConstraints;
} else {
ret = Object.assign({}, matchingConstraints);
}
return ret;
}
|
javascript
|
function formatMatchingConstraints(matchingConstraints) {
let ret = {};
if (typeof matchingConstraints === 'undefined' || matchingConstraints === null) {
throw new TypeError('Constraints cannot be undefined or null');
}
if (!isPlainObject(matchingConstraints)) {
ret.callbackId = matchingConstraints;
} else {
ret = Object.assign({}, matchingConstraints);
}
return ret;
}
|
[
"function",
"formatMatchingConstraints",
"(",
"matchingConstraints",
")",
"{",
"let",
"ret",
"=",
"{",
"}",
";",
"if",
"(",
"typeof",
"matchingConstraints",
"===",
"'undefined'",
"||",
"matchingConstraints",
"===",
"null",
")",
"{",
"throw",
"new",
"TypeError",
"(",
"'Constraints cannot be undefined or null'",
")",
";",
"}",
"if",
"(",
"!",
"isPlainObject",
"(",
"matchingConstraints",
")",
")",
"{",
"ret",
".",
"callbackId",
"=",
"matchingConstraints",
";",
"}",
"else",
"{",
"ret",
"=",
"Object",
".",
"assign",
"(",
"{",
"}",
",",
"matchingConstraints",
")",
";",
"}",
"return",
"ret",
";",
"}"
] |
Transforms various forms of matching constraints to a single standard object shape
@param {string|RegExp|Object} matchingConstraints - the various forms of matching constraints
accepted
@returns {Object} - an object where each matching constraint is a property
@private
|
[
"Transforms",
"various",
"forms",
"of",
"matching",
"constraints",
"to",
"a",
"single",
"standard",
"object",
"shape"
] |
0982098e1cd5356f7fde9f5b82a4c7eb9980f39f
|
https://github.com/slackapi/node-slack-interactive-messages/blob/0982098e1cd5356f7fde9f5b82a4c7eb9980f39f/src/adapter.js#L28-L39
|
12,223
|
slackapi/node-slack-interactive-messages
|
src/adapter.js
|
validateConstraints
|
function validateConstraints(matchingConstraints) {
if (matchingConstraints.callbackId &&
!(isString(matchingConstraints.callbackId) || isRegExp(matchingConstraints.callbackId))) {
return new TypeError('Callback ID must be a string or RegExp');
}
if (matchingConstraints.blockId &&
!(isString(matchingConstraints.blockId) || isRegExp(matchingConstraints.blockId))) {
return new TypeError('Block ID must be a string or RegExp');
}
if (matchingConstraints.actionId &&
!(isString(matchingConstraints.actionId) || isRegExp(matchingConstraints.actionId))) {
return new TypeError('Action ID must be a string or RegExp');
}
return false;
}
|
javascript
|
function validateConstraints(matchingConstraints) {
if (matchingConstraints.callbackId &&
!(isString(matchingConstraints.callbackId) || isRegExp(matchingConstraints.callbackId))) {
return new TypeError('Callback ID must be a string or RegExp');
}
if (matchingConstraints.blockId &&
!(isString(matchingConstraints.blockId) || isRegExp(matchingConstraints.blockId))) {
return new TypeError('Block ID must be a string or RegExp');
}
if (matchingConstraints.actionId &&
!(isString(matchingConstraints.actionId) || isRegExp(matchingConstraints.actionId))) {
return new TypeError('Action ID must be a string or RegExp');
}
return false;
}
|
[
"function",
"validateConstraints",
"(",
"matchingConstraints",
")",
"{",
"if",
"(",
"matchingConstraints",
".",
"callbackId",
"&&",
"!",
"(",
"isString",
"(",
"matchingConstraints",
".",
"callbackId",
")",
"||",
"isRegExp",
"(",
"matchingConstraints",
".",
"callbackId",
")",
")",
")",
"{",
"return",
"new",
"TypeError",
"(",
"'Callback ID must be a string or RegExp'",
")",
";",
"}",
"if",
"(",
"matchingConstraints",
".",
"blockId",
"&&",
"!",
"(",
"isString",
"(",
"matchingConstraints",
".",
"blockId",
")",
"||",
"isRegExp",
"(",
"matchingConstraints",
".",
"blockId",
")",
")",
")",
"{",
"return",
"new",
"TypeError",
"(",
"'Block ID must be a string or RegExp'",
")",
";",
"}",
"if",
"(",
"matchingConstraints",
".",
"actionId",
"&&",
"!",
"(",
"isString",
"(",
"matchingConstraints",
".",
"actionId",
")",
"||",
"isRegExp",
"(",
"matchingConstraints",
".",
"actionId",
")",
")",
")",
"{",
"return",
"new",
"TypeError",
"(",
"'Action ID must be a string or RegExp'",
")",
";",
"}",
"return",
"false",
";",
"}"
] |
Validates general properties of a matching constraints object
@param {Object} matchingConstraints - object describing the constraints on a callback
@returns {Error|false} - a false value represents successful validation, otherwise an error to
describe why validation failed.
@private
|
[
"Validates",
"general",
"properties",
"of",
"a",
"matching",
"constraints",
"object"
] |
0982098e1cd5356f7fde9f5b82a4c7eb9980f39f
|
https://github.com/slackapi/node-slack-interactive-messages/blob/0982098e1cd5356f7fde9f5b82a4c7eb9980f39f/src/adapter.js#L48-L65
|
12,224
|
slackapi/node-slack-interactive-messages
|
src/adapter.js
|
validateOptionsConstraints
|
function validateOptionsConstraints(optionsConstraints) {
if (optionsConstraints.within &&
!(optionsConstraints.within === 'interactive_message' ||
optionsConstraints.within === 'block_actions' ||
optionsConstraints.within === 'dialog')
) {
return new TypeError('Within must be \'block_actions\', \'interactive_message\' or \'dialog\'');
}
// We don't need to validate unfurl, we'll just cooerce it to a boolean
return false;
}
|
javascript
|
function validateOptionsConstraints(optionsConstraints) {
if (optionsConstraints.within &&
!(optionsConstraints.within === 'interactive_message' ||
optionsConstraints.within === 'block_actions' ||
optionsConstraints.within === 'dialog')
) {
return new TypeError('Within must be \'block_actions\', \'interactive_message\' or \'dialog\'');
}
// We don't need to validate unfurl, we'll just cooerce it to a boolean
return false;
}
|
[
"function",
"validateOptionsConstraints",
"(",
"optionsConstraints",
")",
"{",
"if",
"(",
"optionsConstraints",
".",
"within",
"&&",
"!",
"(",
"optionsConstraints",
".",
"within",
"===",
"'interactive_message'",
"||",
"optionsConstraints",
".",
"within",
"===",
"'block_actions'",
"||",
"optionsConstraints",
".",
"within",
"===",
"'dialog'",
")",
")",
"{",
"return",
"new",
"TypeError",
"(",
"'Within must be \\'block_actions\\', \\'interactive_message\\' or \\'dialog\\''",
")",
";",
"}",
"// We don't need to validate unfurl, we'll just cooerce it to a boolean",
"return",
"false",
";",
"}"
] |
Validates properties of a matching constraints object specific to registering an options request
@param {Object} matchingConstraints - object describing the constraints on a callback
@returns {Error|false} - a false value represents successful validation, otherwise an error to
describe why validation failed.
@private
|
[
"Validates",
"properties",
"of",
"a",
"matching",
"constraints",
"object",
"specific",
"to",
"registering",
"an",
"options",
"request"
] |
0982098e1cd5356f7fde9f5b82a4c7eb9980f39f
|
https://github.com/slackapi/node-slack-interactive-messages/blob/0982098e1cd5356f7fde9f5b82a4c7eb9980f39f/src/adapter.js#L74-L85
|
12,225
|
slackapi/node-slack-interactive-messages
|
examples/express-all-interactions/server.js
|
slackSlashCommand
|
function slackSlashCommand(req, res, next) {
if (req.body.command === '/interactive-example') {
const type = req.body.text.split(' ')[0];
if (type === 'button') {
res.json(interactiveButtons);
} else if (type === 'menu') {
res.json(interactiveMenu);
} else if (type === 'dialog') {
res.send();
web.dialog.open({
trigger_id: req.body.trigger_id,
dialog,
}).catch((error) => {
return axios.post(req.body.response_url, {
text: `An error occurred while opening the dialog: ${error.message}`,
});
}).catch(console.error);
} else {
res.send('Use this command followed by `button`, `menu`, or `dialog`.');
}
} else {
next();
}
}
|
javascript
|
function slackSlashCommand(req, res, next) {
if (req.body.command === '/interactive-example') {
const type = req.body.text.split(' ')[0];
if (type === 'button') {
res.json(interactiveButtons);
} else if (type === 'menu') {
res.json(interactiveMenu);
} else if (type === 'dialog') {
res.send();
web.dialog.open({
trigger_id: req.body.trigger_id,
dialog,
}).catch((error) => {
return axios.post(req.body.response_url, {
text: `An error occurred while opening the dialog: ${error.message}`,
});
}).catch(console.error);
} else {
res.send('Use this command followed by `button`, `menu`, or `dialog`.');
}
} else {
next();
}
}
|
[
"function",
"slackSlashCommand",
"(",
"req",
",",
"res",
",",
"next",
")",
"{",
"if",
"(",
"req",
".",
"body",
".",
"command",
"===",
"'/interactive-example'",
")",
"{",
"const",
"type",
"=",
"req",
".",
"body",
".",
"text",
".",
"split",
"(",
"' '",
")",
"[",
"0",
"]",
";",
"if",
"(",
"type",
"===",
"'button'",
")",
"{",
"res",
".",
"json",
"(",
"interactiveButtons",
")",
";",
"}",
"else",
"if",
"(",
"type",
"===",
"'menu'",
")",
"{",
"res",
".",
"json",
"(",
"interactiveMenu",
")",
";",
"}",
"else",
"if",
"(",
"type",
"===",
"'dialog'",
")",
"{",
"res",
".",
"send",
"(",
")",
";",
"web",
".",
"dialog",
".",
"open",
"(",
"{",
"trigger_id",
":",
"req",
".",
"body",
".",
"trigger_id",
",",
"dialog",
",",
"}",
")",
".",
"catch",
"(",
"(",
"error",
")",
"=>",
"{",
"return",
"axios",
".",
"post",
"(",
"req",
".",
"body",
".",
"response_url",
",",
"{",
"text",
":",
"`",
"${",
"error",
".",
"message",
"}",
"`",
",",
"}",
")",
";",
"}",
")",
".",
"catch",
"(",
"console",
".",
"error",
")",
";",
"}",
"else",
"{",
"res",
".",
"send",
"(",
"'Use this command followed by `button`, `menu`, or `dialog`.'",
")",
";",
"}",
"}",
"else",
"{",
"next",
"(",
")",
";",
"}",
"}"
] |
Slack slash command handler
|
[
"Slack",
"slash",
"command",
"handler"
] |
0982098e1cd5356f7fde9f5b82a4c7eb9980f39f
|
https://github.com/slackapi/node-slack-interactive-messages/blob/0982098e1cd5356f7fde9f5b82a4c7eb9980f39f/examples/express-all-interactions/server.js#L217-L240
|
12,226
|
TalAter/UpUp
|
src/upup.js
|
function(settings) {
this.addSettings(settings);
// register the service worker
_serviceWorker.register(_settings['service-worker-url'], _settings['registration-options']).then(function(registration) {
// Registration was successful
if (_debugState) {
console.log('Service worker registration successful with scope: %c'+registration.scope, _debugStyle);
}
// Send the settings to the service worker
var messenger = registration.installing || _serviceWorker.controller || registration.active;
messenger.postMessage({'action': 'set-settings', 'settings': _settings});
}).catch(function(err) {
// registration failed :(
if (_debugState) {
console.log('Service worker registration failed: %c'+err, _debugStyle);
}
});
}
|
javascript
|
function(settings) {
this.addSettings(settings);
// register the service worker
_serviceWorker.register(_settings['service-worker-url'], _settings['registration-options']).then(function(registration) {
// Registration was successful
if (_debugState) {
console.log('Service worker registration successful with scope: %c'+registration.scope, _debugStyle);
}
// Send the settings to the service worker
var messenger = registration.installing || _serviceWorker.controller || registration.active;
messenger.postMessage({'action': 'set-settings', 'settings': _settings});
}).catch(function(err) {
// registration failed :(
if (_debugState) {
console.log('Service worker registration failed: %c'+err, _debugStyle);
}
});
}
|
[
"function",
"(",
"settings",
")",
"{",
"this",
".",
"addSettings",
"(",
"settings",
")",
";",
"// register the service worker",
"_serviceWorker",
".",
"register",
"(",
"_settings",
"[",
"'service-worker-url'",
"]",
",",
"_settings",
"[",
"'registration-options'",
"]",
")",
".",
"then",
"(",
"function",
"(",
"registration",
")",
"{",
"// Registration was successful",
"if",
"(",
"_debugState",
")",
"{",
"console",
".",
"log",
"(",
"'Service worker registration successful with scope: %c'",
"+",
"registration",
".",
"scope",
",",
"_debugStyle",
")",
";",
"}",
"// Send the settings to the service worker",
"var",
"messenger",
"=",
"registration",
".",
"installing",
"||",
"_serviceWorker",
".",
"controller",
"||",
"registration",
".",
"active",
";",
"messenger",
".",
"postMessage",
"(",
"{",
"'action'",
":",
"'set-settings'",
",",
"'settings'",
":",
"_settings",
"}",
")",
";",
"}",
")",
".",
"catch",
"(",
"function",
"(",
"err",
")",
"{",
"// registration failed :(",
"if",
"(",
"_debugState",
")",
"{",
"console",
".",
"log",
"(",
"'Service worker registration failed: %c'",
"+",
"err",
",",
"_debugStyle",
")",
";",
"}",
"}",
")",
";",
"}"
] |
Make this site available offline
Can receive a settings object directly, or be configured by running addSettings() first.
See Settings section of docs for details.
#### Examples:
````javascript
// Set up offline mode with a basic message
UpUp.start({ content: 'Cannot reach site. Please check your internet connection.' });
// Set up offline mode with the settings defined previously via addSettings()
UpUp.start();
````
@param {Object} [settings] - Settings for offline mode
@method start
|
[
"Make",
"this",
"site",
"available",
"offline"
] |
6bf4bab00bc6bece9567c07d478d3bae0ed71fc4
|
https://github.com/TalAter/UpUp/blob/6bf4bab00bc6bece9567c07d478d3bae0ed71fc4/src/upup.js#L161-L181
|
|
12,227
|
TalAter/UpUp
|
src/upup.js
|
function(settings) {
settings = settings || {};
// if we got a string, instead of a settings object, use that string as the content
if (typeof settings === 'string') {
settings = { content: settings };
}
// add new settings to our settings object
[
'content',
'content-url',
'assets',
'service-worker-url',
'cache-version',
].forEach(function(settingName) {
if (settings[settingName] !== undefined) {
_settings[settingName] = settings[settingName];
}
});
// Add scope setting
if (settings['scope'] !== undefined) {
_settings['registration-options']['scope'] = settings['scope'];
}
}
|
javascript
|
function(settings) {
settings = settings || {};
// if we got a string, instead of a settings object, use that string as the content
if (typeof settings === 'string') {
settings = { content: settings };
}
// add new settings to our settings object
[
'content',
'content-url',
'assets',
'service-worker-url',
'cache-version',
].forEach(function(settingName) {
if (settings[settingName] !== undefined) {
_settings[settingName] = settings[settingName];
}
});
// Add scope setting
if (settings['scope'] !== undefined) {
_settings['registration-options']['scope'] = settings['scope'];
}
}
|
[
"function",
"(",
"settings",
")",
"{",
"settings",
"=",
"settings",
"||",
"{",
"}",
";",
"// if we got a string, instead of a settings object, use that string as the content",
"if",
"(",
"typeof",
"settings",
"===",
"'string'",
")",
"{",
"settings",
"=",
"{",
"content",
":",
"settings",
"}",
";",
"}",
"// add new settings to our settings object",
"[",
"'content'",
",",
"'content-url'",
",",
"'assets'",
",",
"'service-worker-url'",
",",
"'cache-version'",
",",
"]",
".",
"forEach",
"(",
"function",
"(",
"settingName",
")",
"{",
"if",
"(",
"settings",
"[",
"settingName",
"]",
"!==",
"undefined",
")",
"{",
"_settings",
"[",
"settingName",
"]",
"=",
"settings",
"[",
"settingName",
"]",
";",
"}",
"}",
")",
";",
"// Add scope setting",
"if",
"(",
"settings",
"[",
"'scope'",
"]",
"!==",
"undefined",
")",
"{",
"_settings",
"[",
"'registration-options'",
"]",
"[",
"'scope'",
"]",
"=",
"settings",
"[",
"'scope'",
"]",
";",
"}",
"}"
] |
Adds settings to configure how UpUp behaves.
Call this before running start, or just pass the settings object when calling the start method.
Receives a mandatory settings object. See Settings section of docs for details.
#### Examples:
````javascript
// Set up offline mode with a basic message
UpUp.addSettings({ content: 'Cannot reach site. Please check your internet connection.' });
UpUp.start();
// The same thing can be achieved like this
UpUp.start({ content: 'Cannot reach site. Please check your internet connection.' });
````
@param {Object} [settings] - Settings for offline mode
@method addSettings
@see [Settings](#settings)
|
[
"Adds",
"settings",
"to",
"configure",
"how",
"UpUp",
"behaves",
".",
"Call",
"this",
"before",
"running",
"start",
"or",
"just",
"pass",
"the",
"settings",
"object",
"when",
"calling",
"the",
"start",
"method",
"."
] |
6bf4bab00bc6bece9567c07d478d3bae0ed71fc4
|
https://github.com/TalAter/UpUp/blob/6bf4bab00bc6bece9567c07d478d3bae0ed71fc4/src/upup.js#L203-L228
|
|
12,228
|
TalAter/UpUp
|
src/upup.sw.js
|
function(input) {
input = input.toString();
var hash = 0, i, chr, len = input.length;
if (len === 0) {
return hash;
}
for (i = 0; i < len; i++) {
chr = input.charCodeAt(i);
hash = (hash << 5) - hash + chr;
hash |= 0;
}
return hash;
}
|
javascript
|
function(input) {
input = input.toString();
var hash = 0, i, chr, len = input.length;
if (len === 0) {
return hash;
}
for (i = 0; i < len; i++) {
chr = input.charCodeAt(i);
hash = (hash << 5) - hash + chr;
hash |= 0;
}
return hash;
}
|
[
"function",
"(",
"input",
")",
"{",
"input",
"=",
"input",
".",
"toString",
"(",
")",
";",
"var",
"hash",
"=",
"0",
",",
"i",
",",
"chr",
",",
"len",
"=",
"input",
".",
"length",
";",
"if",
"(",
"len",
"===",
"0",
")",
"{",
"return",
"hash",
";",
"}",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"len",
";",
"i",
"++",
")",
"{",
"chr",
"=",
"input",
".",
"charCodeAt",
"(",
"i",
")",
";",
"hash",
"=",
"(",
"hash",
"<<",
"5",
")",
"-",
"hash",
"+",
"chr",
";",
"hash",
"|=",
"0",
";",
"}",
"return",
"hash",
";",
"}"
] |
Receives an input and calculates a hash for it
|
[
"Receives",
"an",
"input",
"and",
"calculates",
"a",
"hash",
"for",
"it"
] |
6bf4bab00bc6bece9567c07d478d3bae0ed71fc4
|
https://github.com/TalAter/UpUp/blob/6bf4bab00bc6bece9567c07d478d3bae0ed71fc4/src/upup.sw.js#L11-L23
|
|
12,229
|
craftyjs/Crafty
|
src/graphics/layers.js
|
function(useCached) {
var rect = this._cachedViewportRect;
if (useCached) return rect;
// total transform is viewport transform combined with this layer's transform
var viewport = Crafty.viewport;
var options = this.options;
var scale = Math.pow(viewport._scale, options.scaleResponse);
rect._scale = scale;
rect._w = viewport._width / scale;
rect._h = viewport._height / scale;
// This particular transformation is designed such that,
// if a combination pan/scale keeps the center of the screen fixed for a layer with x/y response of 1,
// then it will also be fixed for layers with other values for x/y response
// (note that the second term vanishes when either the response or scale are 1)
rect._x =
options.xResponse * -viewport._x -
0.5 *
(options.xResponse - 1) *
(1 - 1 / scale) *
viewport._width;
rect._y =
options.yResponse * -viewport._y -
0.5 *
(options.yResponse - 1) *
(1 - 1 / scale) *
viewport._height;
return rect;
}
|
javascript
|
function(useCached) {
var rect = this._cachedViewportRect;
if (useCached) return rect;
// total transform is viewport transform combined with this layer's transform
var viewport = Crafty.viewport;
var options = this.options;
var scale = Math.pow(viewport._scale, options.scaleResponse);
rect._scale = scale;
rect._w = viewport._width / scale;
rect._h = viewport._height / scale;
// This particular transformation is designed such that,
// if a combination pan/scale keeps the center of the screen fixed for a layer with x/y response of 1,
// then it will also be fixed for layers with other values for x/y response
// (note that the second term vanishes when either the response or scale are 1)
rect._x =
options.xResponse * -viewport._x -
0.5 *
(options.xResponse - 1) *
(1 - 1 / scale) *
viewport._width;
rect._y =
options.yResponse * -viewport._y -
0.5 *
(options.yResponse - 1) *
(1 - 1 / scale) *
viewport._height;
return rect;
}
|
[
"function",
"(",
"useCached",
")",
"{",
"var",
"rect",
"=",
"this",
".",
"_cachedViewportRect",
";",
"if",
"(",
"useCached",
")",
"return",
"rect",
";",
"// total transform is viewport transform combined with this layer's transform",
"var",
"viewport",
"=",
"Crafty",
".",
"viewport",
";",
"var",
"options",
"=",
"this",
".",
"options",
";",
"var",
"scale",
"=",
"Math",
".",
"pow",
"(",
"viewport",
".",
"_scale",
",",
"options",
".",
"scaleResponse",
")",
";",
"rect",
".",
"_scale",
"=",
"scale",
";",
"rect",
".",
"_w",
"=",
"viewport",
".",
"_width",
"/",
"scale",
";",
"rect",
".",
"_h",
"=",
"viewport",
".",
"_height",
"/",
"scale",
";",
"// This particular transformation is designed such that,",
"// if a combination pan/scale keeps the center of the screen fixed for a layer with x/y response of 1,",
"// then it will also be fixed for layers with other values for x/y response",
"// (note that the second term vanishes when either the response or scale are 1)",
"rect",
".",
"_x",
"=",
"options",
".",
"xResponse",
"*",
"-",
"viewport",
".",
"_x",
"-",
"0.5",
"*",
"(",
"options",
".",
"xResponse",
"-",
"1",
")",
"*",
"(",
"1",
"-",
"1",
"/",
"scale",
")",
"*",
"viewport",
".",
"_width",
";",
"rect",
".",
"_y",
"=",
"options",
".",
"yResponse",
"*",
"-",
"viewport",
".",
"_y",
"-",
"0.5",
"*",
"(",
"options",
".",
"yResponse",
"-",
"1",
")",
"*",
"(",
"1",
"-",
"1",
"/",
"scale",
")",
"*",
"viewport",
".",
"_height",
";",
"return",
"rect",
";",
"}"
] |
Based on the camera options, find the Crafty coordinates corresponding to the layer's position in the viewport
|
[
"Based",
"on",
"the",
"camera",
"options",
"find",
"the",
"Crafty",
"coordinates",
"corresponding",
"to",
"the",
"layer",
"s",
"position",
"in",
"the",
"viewport"
] |
f3982baa51af24d4e8a14a3194fd3f0e92a2dcba
|
https://github.com/craftyjs/Crafty/blob/f3982baa51af24d4e8a14a3194fd3f0e92a2dcba/src/graphics/layers.js#L83-L114
|
|
12,230
|
craftyjs/Crafty
|
src/graphics/layers.js
|
function(rect, outRect, useCached) {
var view = this._viewportRect(useCached),
scale = view._scale;
outRect = outRect || {};
outRect._x = rect._x * scale + Math.round(-view._x * scale);
outRect._y = rect._y * scale + Math.round(-view._y * scale);
outRect._w = rect._w * scale;
outRect._h = rect._h * scale;
return outRect;
}
|
javascript
|
function(rect, outRect, useCached) {
var view = this._viewportRect(useCached),
scale = view._scale;
outRect = outRect || {};
outRect._x = rect._x * scale + Math.round(-view._x * scale);
outRect._y = rect._y * scale + Math.round(-view._y * scale);
outRect._w = rect._w * scale;
outRect._h = rect._h * scale;
return outRect;
}
|
[
"function",
"(",
"rect",
",",
"outRect",
",",
"useCached",
")",
"{",
"var",
"view",
"=",
"this",
".",
"_viewportRect",
"(",
"useCached",
")",
",",
"scale",
"=",
"view",
".",
"_scale",
";",
"outRect",
"=",
"outRect",
"||",
"{",
"}",
";",
"outRect",
".",
"_x",
"=",
"rect",
".",
"_x",
"*",
"scale",
"+",
"Math",
".",
"round",
"(",
"-",
"view",
".",
"_x",
"*",
"scale",
")",
";",
"outRect",
".",
"_y",
"=",
"rect",
".",
"_y",
"*",
"scale",
"+",
"Math",
".",
"round",
"(",
"-",
"view",
".",
"_y",
"*",
"scale",
")",
";",
"outRect",
".",
"_w",
"=",
"rect",
".",
"_w",
"*",
"scale",
";",
"outRect",
".",
"_h",
"=",
"rect",
".",
"_h",
"*",
"scale",
";",
"return",
"outRect",
";",
"}"
] |
transform a given rect to view space, depending on this layers' total transform
|
[
"transform",
"a",
"given",
"rect",
"to",
"view",
"space",
"depending",
"on",
"this",
"layers",
"total",
"transform"
] |
f3982baa51af24d4e8a14a3194fd3f0e92a2dcba
|
https://github.com/craftyjs/Crafty/blob/f3982baa51af24d4e8a14a3194fd3f0e92a2dcba/src/graphics/layers.js#L117-L128
|
|
12,231
|
craftyjs/Crafty
|
src/spatial/2d.js
|
function(drad) {
var cos = Math.cos(drad);
cos = -1e-10 < cos && cos < 1e-10 ? 0 : cos;
return cos;
}
|
javascript
|
function(drad) {
var cos = Math.cos(drad);
cos = -1e-10 < cos && cos < 1e-10 ? 0 : cos;
return cos;
}
|
[
"function",
"(",
"drad",
")",
"{",
"var",
"cos",
"=",
"Math",
".",
"cos",
"(",
"drad",
")",
";",
"cos",
"=",
"-",
"1e-10",
"<",
"cos",
"&&",
"cos",
"<",
"1e-10",
"?",
"0",
":",
"cos",
";",
"return",
"cos",
";",
"}"
] |
These versions of cos and sin ensure that rotations very close to 0 return 0. This avoids some problems where entities are not quite aligned with the grid.
|
[
"These",
"versions",
"of",
"cos",
"and",
"sin",
"ensure",
"that",
"rotations",
"very",
"close",
"to",
"0",
"return",
"0",
".",
"This",
"avoids",
"some",
"problems",
"where",
"entities",
"are",
"not",
"quite",
"aligned",
"with",
"the",
"grid",
"."
] |
f3982baa51af24d4e8a14a3194fd3f0e92a2dcba
|
https://github.com/craftyjs/Crafty/blob/f3982baa51af24d4e8a14a3194fd3f0e92a2dcba/src/spatial/2d.js#L11-L15
|
|
12,232
|
craftyjs/Crafty
|
src/spatial/2d.js
|
function(v) {
//var theta = -1 * (v % 360); //angle always between 0 and 359
var difference = this._rotation - v;
// skip if there's no rotation!
if (difference === 0) return;
else this._rotation = v;
this._calculateMBR();
this.trigger("Rotate", difference);
}
|
javascript
|
function(v) {
//var theta = -1 * (v % 360); //angle always between 0 and 359
var difference = this._rotation - v;
// skip if there's no rotation!
if (difference === 0) return;
else this._rotation = v;
this._calculateMBR();
this.trigger("Rotate", difference);
}
|
[
"function",
"(",
"v",
")",
"{",
"//var theta = -1 * (v % 360); //angle always between 0 and 359",
"var",
"difference",
"=",
"this",
".",
"_rotation",
"-",
"v",
";",
"// skip if there's no rotation!",
"if",
"(",
"difference",
"===",
"0",
")",
"return",
";",
"else",
"this",
".",
"_rotation",
"=",
"v",
";",
"this",
".",
"_calculateMBR",
"(",
")",
";",
"this",
".",
"trigger",
"(",
"\"Rotate\"",
",",
"difference",
")",
";",
"}"
] |
Handle changes that need to happen on a rotation
|
[
"Handle",
"changes",
"that",
"need",
"to",
"happen",
"on",
"a",
"rotation"
] |
f3982baa51af24d4e8a14a3194fd3f0e92a2dcba
|
https://github.com/craftyjs/Crafty/blob/f3982baa51af24d4e8a14a3194fd3f0e92a2dcba/src/spatial/2d.js#L434-L444
|
|
12,233
|
craftyjs/Crafty
|
src/spatial/2d.js
|
function(x, y) {
if (x === this._x && y === this._y) return;
var old = Crafty.rectManager._pool.copy(this);
var mbr = this._mbr;
if (mbr) {
mbr._x -= this._x - x;
mbr._y -= this._y - y;
// cbr is a non-minimal bounding rectangle that contains both hitbox and mbr
// It will exist only when the collision hitbox sits outside the entity
if (this._cbr) {
this._cbr._x -= this._x - x;
this._cbr._y -= this._y - y;
}
}
this._x = x;
this._y = y;
this.trigger("Move", old);
this.trigger("Invalidate");
Crafty.rectManager._pool.recycle(old);
}
|
javascript
|
function(x, y) {
if (x === this._x && y === this._y) return;
var old = Crafty.rectManager._pool.copy(this);
var mbr = this._mbr;
if (mbr) {
mbr._x -= this._x - x;
mbr._y -= this._y - y;
// cbr is a non-minimal bounding rectangle that contains both hitbox and mbr
// It will exist only when the collision hitbox sits outside the entity
if (this._cbr) {
this._cbr._x -= this._x - x;
this._cbr._y -= this._y - y;
}
}
this._x = x;
this._y = y;
this.trigger("Move", old);
this.trigger("Invalidate");
Crafty.rectManager._pool.recycle(old);
}
|
[
"function",
"(",
"x",
",",
"y",
")",
"{",
"if",
"(",
"x",
"===",
"this",
".",
"_x",
"&&",
"y",
"===",
"this",
".",
"_y",
")",
"return",
";",
"var",
"old",
"=",
"Crafty",
".",
"rectManager",
".",
"_pool",
".",
"copy",
"(",
"this",
")",
";",
"var",
"mbr",
"=",
"this",
".",
"_mbr",
";",
"if",
"(",
"mbr",
")",
"{",
"mbr",
".",
"_x",
"-=",
"this",
".",
"_x",
"-",
"x",
";",
"mbr",
".",
"_y",
"-=",
"this",
".",
"_y",
"-",
"y",
";",
"// cbr is a non-minimal bounding rectangle that contains both hitbox and mbr",
"// It will exist only when the collision hitbox sits outside the entity",
"if",
"(",
"this",
".",
"_cbr",
")",
"{",
"this",
".",
"_cbr",
".",
"_x",
"-=",
"this",
".",
"_x",
"-",
"x",
";",
"this",
".",
"_cbr",
".",
"_y",
"-=",
"this",
".",
"_y",
"-",
"y",
";",
"}",
"}",
"this",
".",
"_x",
"=",
"x",
";",
"this",
".",
"_y",
"=",
"y",
";",
"this",
".",
"trigger",
"(",
"\"Move\"",
",",
"old",
")",
";",
"this",
".",
"trigger",
"(",
"\"Invalidate\"",
")",
";",
"Crafty",
".",
"rectManager",
".",
"_pool",
".",
"recycle",
"(",
"old",
")",
";",
"}"
] |
A separate setter for the common case of moving an entity along both axes
|
[
"A",
"separate",
"setter",
"for",
"the",
"common",
"case",
"of",
"moving",
"an",
"entity",
"along",
"both",
"axes"
] |
f3982baa51af24d4e8a14a3194fd3f0e92a2dcba
|
https://github.com/craftyjs/Crafty/blob/f3982baa51af24d4e8a14a3194fd3f0e92a2dcba/src/spatial/2d.js#L956-L975
|
|
12,234
|
craftyjs/Crafty
|
src/spatial/2d.js
|
function(name, value) {
// Return if there is no change
if (this[name] === value) {
return;
}
//keep a reference of the old positions
var old = Crafty.rectManager._pool.copy(this);
var mbr;
//if rotation, use the rotate method
if (name === "_rotation") {
this._rotate(value); // _rotate triggers "Rotate"
//set the global Z and trigger reorder just in case
} else if (name === "_x" || name === "_y") {
// mbr is the minimal bounding rectangle of the entity
mbr = this._mbr;
if (mbr) {
mbr[name] -= this[name] - value;
// cbr is a non-minimal bounding rectangle that contains both hitbox and mbr
// It will exist only when the collision hitbox sits outside the entity
if (this._cbr) {
this._cbr[name] -= this[name] - value;
}
}
this[name] = value;
this.trigger("Move", old);
} else if (name === "_h" || name === "_w") {
mbr = this._mbr;
var oldValue = this[name];
this[name] = value;
if (mbr) {
this._calculateMBR();
}
if (name === "_w") {
this.trigger("Resize", {
axis: "w",
amount: value - oldValue
});
} else if (name === "_h") {
this.trigger("Resize", {
axis: "h",
amount: value - oldValue
});
}
this.trigger("Move", old);
} else if (name === "_z") {
var intValue = value << 0;
value = value === intValue ? intValue : intValue + 1;
this._globalZ = value * 100000 + this[0]; //magic number 10^5 is the max num of entities
this[name] = value;
this.trigger("Reorder");
}
//everything will assume the value
this[name] = value;
// flag for redraw
this.trigger("Invalidate");
Crafty.rectManager._pool.recycle(old);
}
|
javascript
|
function(name, value) {
// Return if there is no change
if (this[name] === value) {
return;
}
//keep a reference of the old positions
var old = Crafty.rectManager._pool.copy(this);
var mbr;
//if rotation, use the rotate method
if (name === "_rotation") {
this._rotate(value); // _rotate triggers "Rotate"
//set the global Z and trigger reorder just in case
} else if (name === "_x" || name === "_y") {
// mbr is the minimal bounding rectangle of the entity
mbr = this._mbr;
if (mbr) {
mbr[name] -= this[name] - value;
// cbr is a non-minimal bounding rectangle that contains both hitbox and mbr
// It will exist only when the collision hitbox sits outside the entity
if (this._cbr) {
this._cbr[name] -= this[name] - value;
}
}
this[name] = value;
this.trigger("Move", old);
} else if (name === "_h" || name === "_w") {
mbr = this._mbr;
var oldValue = this[name];
this[name] = value;
if (mbr) {
this._calculateMBR();
}
if (name === "_w") {
this.trigger("Resize", {
axis: "w",
amount: value - oldValue
});
} else if (name === "_h") {
this.trigger("Resize", {
axis: "h",
amount: value - oldValue
});
}
this.trigger("Move", old);
} else if (name === "_z") {
var intValue = value << 0;
value = value === intValue ? intValue : intValue + 1;
this._globalZ = value * 100000 + this[0]; //magic number 10^5 is the max num of entities
this[name] = value;
this.trigger("Reorder");
}
//everything will assume the value
this[name] = value;
// flag for redraw
this.trigger("Invalidate");
Crafty.rectManager._pool.recycle(old);
}
|
[
"function",
"(",
"name",
",",
"value",
")",
"{",
"// Return if there is no change",
"if",
"(",
"this",
"[",
"name",
"]",
"===",
"value",
")",
"{",
"return",
";",
"}",
"//keep a reference of the old positions",
"var",
"old",
"=",
"Crafty",
".",
"rectManager",
".",
"_pool",
".",
"copy",
"(",
"this",
")",
";",
"var",
"mbr",
";",
"//if rotation, use the rotate method",
"if",
"(",
"name",
"===",
"\"_rotation\"",
")",
"{",
"this",
".",
"_rotate",
"(",
"value",
")",
";",
"// _rotate triggers \"Rotate\"",
"//set the global Z and trigger reorder just in case",
"}",
"else",
"if",
"(",
"name",
"===",
"\"_x\"",
"||",
"name",
"===",
"\"_y\"",
")",
"{",
"// mbr is the minimal bounding rectangle of the entity",
"mbr",
"=",
"this",
".",
"_mbr",
";",
"if",
"(",
"mbr",
")",
"{",
"mbr",
"[",
"name",
"]",
"-=",
"this",
"[",
"name",
"]",
"-",
"value",
";",
"// cbr is a non-minimal bounding rectangle that contains both hitbox and mbr",
"// It will exist only when the collision hitbox sits outside the entity",
"if",
"(",
"this",
".",
"_cbr",
")",
"{",
"this",
".",
"_cbr",
"[",
"name",
"]",
"-=",
"this",
"[",
"name",
"]",
"-",
"value",
";",
"}",
"}",
"this",
"[",
"name",
"]",
"=",
"value",
";",
"this",
".",
"trigger",
"(",
"\"Move\"",
",",
"old",
")",
";",
"}",
"else",
"if",
"(",
"name",
"===",
"\"_h\"",
"||",
"name",
"===",
"\"_w\"",
")",
"{",
"mbr",
"=",
"this",
".",
"_mbr",
";",
"var",
"oldValue",
"=",
"this",
"[",
"name",
"]",
";",
"this",
"[",
"name",
"]",
"=",
"value",
";",
"if",
"(",
"mbr",
")",
"{",
"this",
".",
"_calculateMBR",
"(",
")",
";",
"}",
"if",
"(",
"name",
"===",
"\"_w\"",
")",
"{",
"this",
".",
"trigger",
"(",
"\"Resize\"",
",",
"{",
"axis",
":",
"\"w\"",
",",
"amount",
":",
"value",
"-",
"oldValue",
"}",
")",
";",
"}",
"else",
"if",
"(",
"name",
"===",
"\"_h\"",
")",
"{",
"this",
".",
"trigger",
"(",
"\"Resize\"",
",",
"{",
"axis",
":",
"\"h\"",
",",
"amount",
":",
"value",
"-",
"oldValue",
"}",
")",
";",
"}",
"this",
".",
"trigger",
"(",
"\"Move\"",
",",
"old",
")",
";",
"}",
"else",
"if",
"(",
"name",
"===",
"\"_z\"",
")",
"{",
"var",
"intValue",
"=",
"value",
"<<",
"0",
";",
"value",
"=",
"value",
"===",
"intValue",
"?",
"intValue",
":",
"intValue",
"+",
"1",
";",
"this",
".",
"_globalZ",
"=",
"value",
"*",
"100000",
"+",
"this",
"[",
"0",
"]",
";",
"//magic number 10^5 is the max num of entities",
"this",
"[",
"name",
"]",
"=",
"value",
";",
"this",
".",
"trigger",
"(",
"\"Reorder\"",
")",
";",
"}",
"//everything will assume the value",
"this",
"[",
"name",
"]",
"=",
"value",
";",
"// flag for redraw",
"this",
".",
"trigger",
"(",
"\"Invalidate\"",
")",
";",
"Crafty",
".",
"rectManager",
".",
"_pool",
".",
"recycle",
"(",
"old",
")",
";",
"}"
] |
This is a setter method for all 2D properties including x, y, w, h, and rotation.
|
[
"This",
"is",
"a",
"setter",
"method",
"for",
"all",
"2D",
"properties",
"including",
"x",
"y",
"w",
"h",
"and",
"rotation",
"."
] |
f3982baa51af24d4e8a14a3194fd3f0e92a2dcba
|
https://github.com/craftyjs/Crafty/blob/f3982baa51af24d4e8a14a3194fd3f0e92a2dcba/src/spatial/2d.js#L979-L1041
|
|
12,235
|
craftyjs/Crafty
|
src/inputs/mouse.js
|
function(eventName, e) {
// trigger event on MouseSystem itself
this.trigger(eventName, e);
// special case: MouseOver & MouseOut
var over = this.over,
closest = e.target;
if (eventName === "MouseMove" && over !== closest) {
// MouseOver target changed
// if old MouseOver target wasn't null, send MouseOut
if (over) {
e.eventName = "MouseOut";
e.target = over;
over.trigger("MouseOut", e);
e.eventName = "MouseMove";
e.target = closest;
}
// save new over entity
this.over = closest;
// if new MouseOver target isn't null, send MouseOver
if (closest) {
e.eventName = "MouseOver";
closest.trigger("MouseOver", e);
e.eventName = "MouseMove";
}
}
// TODO: move routing of events in future to controls system, make it similar to KeyboardSystem
// try to find closest element that will also receive mouse event, whatever the event is
if (closest) {
closest.trigger(eventName, e);
}
}
|
javascript
|
function(eventName, e) {
// trigger event on MouseSystem itself
this.trigger(eventName, e);
// special case: MouseOver & MouseOut
var over = this.over,
closest = e.target;
if (eventName === "MouseMove" && over !== closest) {
// MouseOver target changed
// if old MouseOver target wasn't null, send MouseOut
if (over) {
e.eventName = "MouseOut";
e.target = over;
over.trigger("MouseOut", e);
e.eventName = "MouseMove";
e.target = closest;
}
// save new over entity
this.over = closest;
// if new MouseOver target isn't null, send MouseOver
if (closest) {
e.eventName = "MouseOver";
closest.trigger("MouseOver", e);
e.eventName = "MouseMove";
}
}
// TODO: move routing of events in future to controls system, make it similar to KeyboardSystem
// try to find closest element that will also receive mouse event, whatever the event is
if (closest) {
closest.trigger(eventName, e);
}
}
|
[
"function",
"(",
"eventName",
",",
"e",
")",
"{",
"// trigger event on MouseSystem itself",
"this",
".",
"trigger",
"(",
"eventName",
",",
"e",
")",
";",
"// special case: MouseOver & MouseOut",
"var",
"over",
"=",
"this",
".",
"over",
",",
"closest",
"=",
"e",
".",
"target",
";",
"if",
"(",
"eventName",
"===",
"\"MouseMove\"",
"&&",
"over",
"!==",
"closest",
")",
"{",
"// MouseOver target changed",
"// if old MouseOver target wasn't null, send MouseOut",
"if",
"(",
"over",
")",
"{",
"e",
".",
"eventName",
"=",
"\"MouseOut\"",
";",
"e",
".",
"target",
"=",
"over",
";",
"over",
".",
"trigger",
"(",
"\"MouseOut\"",
",",
"e",
")",
";",
"e",
".",
"eventName",
"=",
"\"MouseMove\"",
";",
"e",
".",
"target",
"=",
"closest",
";",
"}",
"// save new over entity",
"this",
".",
"over",
"=",
"closest",
";",
"// if new MouseOver target isn't null, send MouseOver",
"if",
"(",
"closest",
")",
"{",
"e",
".",
"eventName",
"=",
"\"MouseOver\"",
";",
"closest",
".",
"trigger",
"(",
"\"MouseOver\"",
",",
"e",
")",
";",
"e",
".",
"eventName",
"=",
"\"MouseMove\"",
";",
"}",
"}",
"// TODO: move routing of events in future to controls system, make it similar to KeyboardSystem",
"// try to find closest element that will also receive mouse event, whatever the event is",
"if",
"(",
"closest",
")",
"{",
"closest",
".",
"trigger",
"(",
"eventName",
",",
"e",
")",
";",
"}",
"}"
] |
this method will be called by MouseState iff triggerMouse event was valid
|
[
"this",
"method",
"will",
"be",
"called",
"by",
"MouseState",
"iff",
"triggerMouse",
"event",
"was",
"valid"
] |
f3982baa51af24d4e8a14a3194fd3f0e92a2dcba
|
https://github.com/craftyjs/Crafty/blob/f3982baa51af24d4e8a14a3194fd3f0e92a2dcba/src/inputs/mouse.js#L274-L308
|
|
12,236
|
craftyjs/Crafty
|
src/core/core.js
|
function(key, context) {
var first, keys, subkey;
if (typeof context === "undefined" || context === null) {
context = this;
}
if (key.indexOf(".") > -1) {
keys = key.split(".");
first = keys.shift();
subkey = keys.join(".");
return this._attr_get(keys.join("."), context[first]);
} else {
return context[key];
}
}
|
javascript
|
function(key, context) {
var first, keys, subkey;
if (typeof context === "undefined" || context === null) {
context = this;
}
if (key.indexOf(".") > -1) {
keys = key.split(".");
first = keys.shift();
subkey = keys.join(".");
return this._attr_get(keys.join("."), context[first]);
} else {
return context[key];
}
}
|
[
"function",
"(",
"key",
",",
"context",
")",
"{",
"var",
"first",
",",
"keys",
",",
"subkey",
";",
"if",
"(",
"typeof",
"context",
"===",
"\"undefined\"",
"||",
"context",
"===",
"null",
")",
"{",
"context",
"=",
"this",
";",
"}",
"if",
"(",
"key",
".",
"indexOf",
"(",
"\".\"",
")",
">",
"-",
"1",
")",
"{",
"keys",
"=",
"key",
".",
"split",
"(",
"\".\"",
")",
";",
"first",
"=",
"keys",
".",
"shift",
"(",
")",
";",
"subkey",
"=",
"keys",
".",
"join",
"(",
"\".\"",
")",
";",
"return",
"this",
".",
"_attr_get",
"(",
"keys",
".",
"join",
"(",
"\".\"",
")",
",",
"context",
"[",
"first",
"]",
")",
";",
"}",
"else",
"{",
"return",
"context",
"[",
"key",
"]",
";",
"}",
"}"
] |
Internal getter method for data on the entity. Called by `.attr`.
example
~~~
person._attr_get('name'); // Foxxy
person._attr_get('contact'); // {email: 'fox_at_example.com'}
person._attr_get('contact.email'); // fox_at_example.com
~~~
|
[
"Internal",
"getter",
"method",
"for",
"data",
"on",
"the",
"entity",
".",
"Called",
"by",
".",
"attr",
"."
] |
f3982baa51af24d4e8a14a3194fd3f0e92a2dcba
|
https://github.com/craftyjs/Crafty/blob/f3982baa51af24d4e8a14a3194fd3f0e92a2dcba/src/core/core.js#L617-L630
|
|
12,237
|
craftyjs/Crafty
|
src/core/core.js
|
function() {
var data, silent, recursive;
if (typeof arguments[0] === "string") {
data = this._set_create_object(arguments[0], arguments[1]);
silent = !!arguments[2];
recursive = arguments[3] || arguments[0].indexOf(".") > -1;
} else {
data = arguments[0];
silent = !!arguments[1];
recursive = !!arguments[2];
}
if (!silent) {
this.trigger("Change", data);
}
if (recursive) {
this._recursive_extend(data, this);
} else {
this.extend.call(this, data);
}
return this;
}
|
javascript
|
function() {
var data, silent, recursive;
if (typeof arguments[0] === "string") {
data = this._set_create_object(arguments[0], arguments[1]);
silent = !!arguments[2];
recursive = arguments[3] || arguments[0].indexOf(".") > -1;
} else {
data = arguments[0];
silent = !!arguments[1];
recursive = !!arguments[2];
}
if (!silent) {
this.trigger("Change", data);
}
if (recursive) {
this._recursive_extend(data, this);
} else {
this.extend.call(this, data);
}
return this;
}
|
[
"function",
"(",
")",
"{",
"var",
"data",
",",
"silent",
",",
"recursive",
";",
"if",
"(",
"typeof",
"arguments",
"[",
"0",
"]",
"===",
"\"string\"",
")",
"{",
"data",
"=",
"this",
".",
"_set_create_object",
"(",
"arguments",
"[",
"0",
"]",
",",
"arguments",
"[",
"1",
"]",
")",
";",
"silent",
"=",
"!",
"!",
"arguments",
"[",
"2",
"]",
";",
"recursive",
"=",
"arguments",
"[",
"3",
"]",
"||",
"arguments",
"[",
"0",
"]",
".",
"indexOf",
"(",
"\".\"",
")",
">",
"-",
"1",
";",
"}",
"else",
"{",
"data",
"=",
"arguments",
"[",
"0",
"]",
";",
"silent",
"=",
"!",
"!",
"arguments",
"[",
"1",
"]",
";",
"recursive",
"=",
"!",
"!",
"arguments",
"[",
"2",
"]",
";",
"}",
"if",
"(",
"!",
"silent",
")",
"{",
"this",
".",
"trigger",
"(",
"\"Change\"",
",",
"data",
")",
";",
"}",
"if",
"(",
"recursive",
")",
"{",
"this",
".",
"_recursive_extend",
"(",
"data",
",",
"this",
")",
";",
"}",
"else",
"{",
"this",
".",
"extend",
".",
"call",
"(",
"this",
",",
"data",
")",
";",
"}",
"return",
"this",
";",
"}"
] |
Internal setter method for attributes on the component. Called by `.attr`.
Options:
`silent`: If you want to prevent it from firing events.
`recursive`: If you pass in an object you could overwrite
sibling keys, this recursively merges instead of just
merging it. This is `false` by default, unless you are
using dot notation `name.first`.
example
~~~
person._attr_set('name', 'Foxxy', true);
person._attr_set('name', 'Foxxy');
person._attr_set({name: 'Foxxy'}, true);
person._attr_set({name: 'Foxxy'});
person._attr_set('name.first', 'Foxxy');
~~~
|
[
"Internal",
"setter",
"method",
"for",
"attributes",
"on",
"the",
"component",
".",
"Called",
"by",
".",
"attr",
"."
] |
f3982baa51af24d4e8a14a3194fd3f0e92a2dcba
|
https://github.com/craftyjs/Crafty/blob/f3982baa51af24d4e8a14a3194fd3f0e92a2dcba/src/core/core.js#L653-L675
|
|
12,238
|
craftyjs/Crafty
|
src/core/core.js
|
function(key, value) {
var data = {},
keys,
first,
subkey;
if (key.indexOf(".") > -1) {
keys = key.split(".");
first = keys.shift();
subkey = keys.join(".");
data[first] = this._set_create_object(subkey, value);
} else {
data[key] = value;
}
return data;
}
|
javascript
|
function(key, value) {
var data = {},
keys,
first,
subkey;
if (key.indexOf(".") > -1) {
keys = key.split(".");
first = keys.shift();
subkey = keys.join(".");
data[first] = this._set_create_object(subkey, value);
} else {
data[key] = value;
}
return data;
}
|
[
"function",
"(",
"key",
",",
"value",
")",
"{",
"var",
"data",
"=",
"{",
"}",
",",
"keys",
",",
"first",
",",
"subkey",
";",
"if",
"(",
"key",
".",
"indexOf",
"(",
"\".\"",
")",
">",
"-",
"1",
")",
"{",
"keys",
"=",
"key",
".",
"split",
"(",
"\".\"",
")",
";",
"first",
"=",
"keys",
".",
"shift",
"(",
")",
";",
"subkey",
"=",
"keys",
".",
"join",
"(",
"\".\"",
")",
";",
"data",
"[",
"first",
"]",
"=",
"this",
".",
"_set_create_object",
"(",
"subkey",
",",
"value",
")",
";",
"}",
"else",
"{",
"data",
"[",
"key",
"]",
"=",
"value",
";",
"}",
"return",
"data",
";",
"}"
] |
If you are setting a key of 'foo.bar' or 'bar', this creates
the appropriate object for you to recursively merge with the
current attributes.
|
[
"If",
"you",
"are",
"setting",
"a",
"key",
"of",
"foo",
".",
"bar",
"or",
"bar",
"this",
"creates",
"the",
"appropriate",
"object",
"for",
"you",
"to",
"recursively",
"merge",
"with",
"the",
"current",
"attributes",
"."
] |
f3982baa51af24d4e8a14a3194fd3f0e92a2dcba
|
https://github.com/craftyjs/Crafty/blob/f3982baa51af24d4e8a14a3194fd3f0e92a2dcba/src/core/core.js#L682-L696
|
|
12,239
|
craftyjs/Crafty
|
src/core/core.js
|
function(new_data, original_data) {
var key;
for (key in new_data) {
if (new_data[key].constructor === Object) {
original_data[key] = this._recursive_extend(
new_data[key],
original_data[key]
);
} else {
original_data[key] = new_data[key];
}
}
return original_data;
}
|
javascript
|
function(new_data, original_data) {
var key;
for (key in new_data) {
if (new_data[key].constructor === Object) {
original_data[key] = this._recursive_extend(
new_data[key],
original_data[key]
);
} else {
original_data[key] = new_data[key];
}
}
return original_data;
}
|
[
"function",
"(",
"new_data",
",",
"original_data",
")",
"{",
"var",
"key",
";",
"for",
"(",
"key",
"in",
"new_data",
")",
"{",
"if",
"(",
"new_data",
"[",
"key",
"]",
".",
"constructor",
"===",
"Object",
")",
"{",
"original_data",
"[",
"key",
"]",
"=",
"this",
".",
"_recursive_extend",
"(",
"new_data",
"[",
"key",
"]",
",",
"original_data",
"[",
"key",
"]",
")",
";",
"}",
"else",
"{",
"original_data",
"[",
"key",
"]",
"=",
"new_data",
"[",
"key",
"]",
";",
"}",
"}",
"return",
"original_data",
";",
"}"
] |
Recursively puts `new_data` into `original_data`.
|
[
"Recursively",
"puts",
"new_data",
"into",
"original_data",
"."
] |
f3982baa51af24d4e8a14a3194fd3f0e92a2dcba
|
https://github.com/craftyjs/Crafty/blob/f3982baa51af24d4e8a14a3194fd3f0e92a2dcba/src/core/core.js#L701-L714
|
|
12,240
|
craftyjs/Crafty
|
src/core/core.js
|
function(event, fn) {
// Get handle to event, creating it if necessary
var callbacks = this._callbacks[event];
if (!callbacks) {
callbacks = this._callbacks[event] = (handlers[event] ||
(handlers[event] = {}))[this[0]] = [];
callbacks.context = this;
callbacks.depth = 0;
}
// Push to callback array
callbacks.push(fn);
}
|
javascript
|
function(event, fn) {
// Get handle to event, creating it if necessary
var callbacks = this._callbacks[event];
if (!callbacks) {
callbacks = this._callbacks[event] = (handlers[event] ||
(handlers[event] = {}))[this[0]] = [];
callbacks.context = this;
callbacks.depth = 0;
}
// Push to callback array
callbacks.push(fn);
}
|
[
"function",
"(",
"event",
",",
"fn",
")",
"{",
"// Get handle to event, creating it if necessary",
"var",
"callbacks",
"=",
"this",
".",
"_callbacks",
"[",
"event",
"]",
";",
"if",
"(",
"!",
"callbacks",
")",
"{",
"callbacks",
"=",
"this",
".",
"_callbacks",
"[",
"event",
"]",
"=",
"(",
"handlers",
"[",
"event",
"]",
"||",
"(",
"handlers",
"[",
"event",
"]",
"=",
"{",
"}",
")",
")",
"[",
"this",
"[",
"0",
"]",
"]",
"=",
"[",
"]",
";",
"callbacks",
".",
"context",
"=",
"this",
";",
"callbacks",
".",
"depth",
"=",
"0",
";",
"}",
"// Push to callback array",
"callbacks",
".",
"push",
"(",
"fn",
")",
";",
"}"
] |
Add a function to the list of callbacks for an event
|
[
"Add",
"a",
"function",
"to",
"the",
"list",
"of",
"callbacks",
"for",
"an",
"event"
] |
f3982baa51af24d4e8a14a3194fd3f0e92a2dcba
|
https://github.com/craftyjs/Crafty/blob/f3982baa51af24d4e8a14a3194fd3f0e92a2dcba/src/core/core.js#L1276-L1287
|
|
12,241
|
craftyjs/Crafty
|
src/core/core.js
|
function(event, data) {
if (!this._callbacks[event] || this.__callbacksFrozen) {
return;
}
var callbacks = this._callbacks[event];
// Callback loop; deletes dead callbacks, but only when it is safe to do so
var i,
l = callbacks.length;
// callbacks.depth tracks whether this function was invoked in the middle of a previous iteration through the same callback array
callbacks.depth++;
for (i = 0; i < l; i++) {
if (typeof callbacks[i] === "undefined") {
if (callbacks.depth <= 1) {
callbacks.splice(i, 1);
i--;
l--;
// Delete callbacks object if there are no remaining bound events
if (callbacks.length === 0) {
delete this._callbacks[event];
delete handlers[event][this[0]];
}
}
} else {
callbacks[i].call(this, data);
}
}
callbacks.depth--;
}
|
javascript
|
function(event, data) {
if (!this._callbacks[event] || this.__callbacksFrozen) {
return;
}
var callbacks = this._callbacks[event];
// Callback loop; deletes dead callbacks, but only when it is safe to do so
var i,
l = callbacks.length;
// callbacks.depth tracks whether this function was invoked in the middle of a previous iteration through the same callback array
callbacks.depth++;
for (i = 0; i < l; i++) {
if (typeof callbacks[i] === "undefined") {
if (callbacks.depth <= 1) {
callbacks.splice(i, 1);
i--;
l--;
// Delete callbacks object if there are no remaining bound events
if (callbacks.length === 0) {
delete this._callbacks[event];
delete handlers[event][this[0]];
}
}
} else {
callbacks[i].call(this, data);
}
}
callbacks.depth--;
}
|
[
"function",
"(",
"event",
",",
"data",
")",
"{",
"if",
"(",
"!",
"this",
".",
"_callbacks",
"[",
"event",
"]",
"||",
"this",
".",
"__callbacksFrozen",
")",
"{",
"return",
";",
"}",
"var",
"callbacks",
"=",
"this",
".",
"_callbacks",
"[",
"event",
"]",
";",
"// Callback loop; deletes dead callbacks, but only when it is safe to do so",
"var",
"i",
",",
"l",
"=",
"callbacks",
".",
"length",
";",
"// callbacks.depth tracks whether this function was invoked in the middle of a previous iteration through the same callback array",
"callbacks",
".",
"depth",
"++",
";",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"l",
";",
"i",
"++",
")",
"{",
"if",
"(",
"typeof",
"callbacks",
"[",
"i",
"]",
"===",
"\"undefined\"",
")",
"{",
"if",
"(",
"callbacks",
".",
"depth",
"<=",
"1",
")",
"{",
"callbacks",
".",
"splice",
"(",
"i",
",",
"1",
")",
";",
"i",
"--",
";",
"l",
"--",
";",
"// Delete callbacks object if there are no remaining bound events",
"if",
"(",
"callbacks",
".",
"length",
"===",
"0",
")",
"{",
"delete",
"this",
".",
"_callbacks",
"[",
"event",
"]",
";",
"delete",
"handlers",
"[",
"event",
"]",
"[",
"this",
"[",
"0",
"]",
"]",
";",
"}",
"}",
"}",
"else",
"{",
"callbacks",
"[",
"i",
"]",
".",
"call",
"(",
"this",
",",
"data",
")",
";",
"}",
"}",
"callbacks",
".",
"depth",
"--",
";",
"}"
] |
Process for running all callbacks for the given event
|
[
"Process",
"for",
"running",
"all",
"callbacks",
"for",
"the",
"given",
"event"
] |
f3982baa51af24d4e8a14a3194fd3f0e92a2dcba
|
https://github.com/craftyjs/Crafty/blob/f3982baa51af24d4e8a14a3194fd3f0e92a2dcba/src/core/core.js#L1290-L1318
|
|
12,242
|
craftyjs/Crafty
|
src/core/core.js
|
function(event, fn) {
if (!this._callbacks[event]) {
return;
}
var callbacks = this._callbacks[event];
// Iterate through and delete the callback functions that match
// They are spliced out when _runCallbacks is invoked, not here
// (This function might be called in the middle of a callback, which complicates the logic)
for (var i = 0; i < callbacks.length; i++) {
if (!fn || callbacks[i] === fn) {
delete callbacks[i];
}
}
}
|
javascript
|
function(event, fn) {
if (!this._callbacks[event]) {
return;
}
var callbacks = this._callbacks[event];
// Iterate through and delete the callback functions that match
// They are spliced out when _runCallbacks is invoked, not here
// (This function might be called in the middle of a callback, which complicates the logic)
for (var i = 0; i < callbacks.length; i++) {
if (!fn || callbacks[i] === fn) {
delete callbacks[i];
}
}
}
|
[
"function",
"(",
"event",
",",
"fn",
")",
"{",
"if",
"(",
"!",
"this",
".",
"_callbacks",
"[",
"event",
"]",
")",
"{",
"return",
";",
"}",
"var",
"callbacks",
"=",
"this",
".",
"_callbacks",
"[",
"event",
"]",
";",
"// Iterate through and delete the callback functions that match",
"// They are spliced out when _runCallbacks is invoked, not here",
"// (This function might be called in the middle of a callback, which complicates the logic)",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"callbacks",
".",
"length",
";",
"i",
"++",
")",
"{",
"if",
"(",
"!",
"fn",
"||",
"callbacks",
"[",
"i",
"]",
"===",
"fn",
")",
"{",
"delete",
"callbacks",
"[",
"i",
"]",
";",
"}",
"}",
"}"
] |
Unbind callbacks for the given event If fn is specified, only it will be removed; otherwise all callbacks will be
|
[
"Unbind",
"callbacks",
"for",
"the",
"given",
"event",
"If",
"fn",
"is",
"specified",
"only",
"it",
"will",
"be",
"removed",
";",
"otherwise",
"all",
"callbacks",
"will",
"be"
] |
f3982baa51af24d4e8a14a3194fd3f0e92a2dcba
|
https://github.com/craftyjs/Crafty/blob/f3982baa51af24d4e8a14a3194fd3f0e92a2dcba/src/core/core.js#L1322-L1335
|
|
12,243
|
craftyjs/Crafty
|
src/core/core.js
|
function() {
if (!this._callbacks) return;
this.__callbacksFrozen = false;
for (var event in this._callbacks) {
if (this._callbacks[event]) {
// Remove the normal way, in case we've got a nested loop
this._unbindCallbacks(event);
// Also completely delete the registered callback from handlers
delete handlers[event][this[0]];
}
}
}
|
javascript
|
function() {
if (!this._callbacks) return;
this.__callbacksFrozen = false;
for (var event in this._callbacks) {
if (this._callbacks[event]) {
// Remove the normal way, in case we've got a nested loop
this._unbindCallbacks(event);
// Also completely delete the registered callback from handlers
delete handlers[event][this[0]];
}
}
}
|
[
"function",
"(",
")",
"{",
"if",
"(",
"!",
"this",
".",
"_callbacks",
")",
"return",
";",
"this",
".",
"__callbacksFrozen",
"=",
"false",
";",
"for",
"(",
"var",
"event",
"in",
"this",
".",
"_callbacks",
")",
"{",
"if",
"(",
"this",
".",
"_callbacks",
"[",
"event",
"]",
")",
"{",
"// Remove the normal way, in case we've got a nested loop",
"this",
".",
"_unbindCallbacks",
"(",
"event",
")",
";",
"// Also completely delete the registered callback from handlers",
"delete",
"handlers",
"[",
"event",
"]",
"[",
"this",
"[",
"0",
"]",
"]",
";",
"}",
"}",
"}"
] |
Completely all callbacks for every event, such as on object destruction
|
[
"Completely",
"all",
"callbacks",
"for",
"every",
"event",
"such",
"as",
"on",
"object",
"destruction"
] |
f3982baa51af24d4e8a14a3194fd3f0e92a2dcba
|
https://github.com/craftyjs/Crafty/blob/f3982baa51af24d4e8a14a3194fd3f0e92a2dcba/src/core/core.js#L1338-L1349
|
|
12,244
|
craftyjs/Crafty
|
src/graphics/dom-layer.js
|
function(enabled) {
var style = this._div.style;
var camelize = Crafty.domHelper.camelize;
if (enabled) {
style[camelize("image-rendering")] = "optimizeSpeed"; /* legacy */
style[camelize("image-rendering")] =
"-moz-crisp-edges"; /* Firefox */
style[camelize("image-rendering")] = "-o-crisp-edges"; /* Opera */
style[camelize("image-rendering")] =
"-webkit-optimize-contrast"; /* Webkit (Chrome & Safari) */
style[camelize("-ms-interpolation-mode")] =
"nearest-neighbor"; /* IE */
style[camelize("image-rendering")] =
"optimize-contrast"; /* CSS3 proposed */
style[camelize("image-rendering")] =
"pixelated"; /* CSS4 proposed */
style[camelize("image-rendering")] =
"crisp-edges"; /* CSS4 proposed */
} else {
style[camelize("image-rendering")] = "optimizeQuality"; /* legacy */
style[camelize("-ms-interpolation-mode")] = "bicubic"; /* IE */
style[camelize("image-rendering")] = "auto"; /* CSS3 */
}
}
|
javascript
|
function(enabled) {
var style = this._div.style;
var camelize = Crafty.domHelper.camelize;
if (enabled) {
style[camelize("image-rendering")] = "optimizeSpeed"; /* legacy */
style[camelize("image-rendering")] =
"-moz-crisp-edges"; /* Firefox */
style[camelize("image-rendering")] = "-o-crisp-edges"; /* Opera */
style[camelize("image-rendering")] =
"-webkit-optimize-contrast"; /* Webkit (Chrome & Safari) */
style[camelize("-ms-interpolation-mode")] =
"nearest-neighbor"; /* IE */
style[camelize("image-rendering")] =
"optimize-contrast"; /* CSS3 proposed */
style[camelize("image-rendering")] =
"pixelated"; /* CSS4 proposed */
style[camelize("image-rendering")] =
"crisp-edges"; /* CSS4 proposed */
} else {
style[camelize("image-rendering")] = "optimizeQuality"; /* legacy */
style[camelize("-ms-interpolation-mode")] = "bicubic"; /* IE */
style[camelize("image-rendering")] = "auto"; /* CSS3 */
}
}
|
[
"function",
"(",
"enabled",
")",
"{",
"var",
"style",
"=",
"this",
".",
"_div",
".",
"style",
";",
"var",
"camelize",
"=",
"Crafty",
".",
"domHelper",
".",
"camelize",
";",
"if",
"(",
"enabled",
")",
"{",
"style",
"[",
"camelize",
"(",
"\"image-rendering\"",
")",
"]",
"=",
"\"optimizeSpeed\"",
";",
"/* legacy */",
"style",
"[",
"camelize",
"(",
"\"image-rendering\"",
")",
"]",
"=",
"\"-moz-crisp-edges\"",
";",
"/* Firefox */",
"style",
"[",
"camelize",
"(",
"\"image-rendering\"",
")",
"]",
"=",
"\"-o-crisp-edges\"",
";",
"/* Opera */",
"style",
"[",
"camelize",
"(",
"\"image-rendering\"",
")",
"]",
"=",
"\"-webkit-optimize-contrast\"",
";",
"/* Webkit (Chrome & Safari) */",
"style",
"[",
"camelize",
"(",
"\"-ms-interpolation-mode\"",
")",
"]",
"=",
"\"nearest-neighbor\"",
";",
"/* IE */",
"style",
"[",
"camelize",
"(",
"\"image-rendering\"",
")",
"]",
"=",
"\"optimize-contrast\"",
";",
"/* CSS3 proposed */",
"style",
"[",
"camelize",
"(",
"\"image-rendering\"",
")",
"]",
"=",
"\"pixelated\"",
";",
"/* CSS4 proposed */",
"style",
"[",
"camelize",
"(",
"\"image-rendering\"",
")",
"]",
"=",
"\"crisp-edges\"",
";",
"/* CSS4 proposed */",
"}",
"else",
"{",
"style",
"[",
"camelize",
"(",
"\"image-rendering\"",
")",
"]",
"=",
"\"optimizeQuality\"",
";",
"/* legacy */",
"style",
"[",
"camelize",
"(",
"\"-ms-interpolation-mode\"",
")",
"]",
"=",
"\"bicubic\"",
";",
"/* IE */",
"style",
"[",
"camelize",
"(",
"\"image-rendering\"",
")",
"]",
"=",
"\"auto\"",
";",
"/* CSS3 */",
"}",
"}"
] |
Handle whether images should be smoothed or not
|
[
"Handle",
"whether",
"images",
"should",
"be",
"smoothed",
"or",
"not"
] |
f3982baa51af24d4e8a14a3194fd3f0e92a2dcba
|
https://github.com/craftyjs/Crafty/blob/f3982baa51af24d4e8a14a3194fd3f0e92a2dcba/src/graphics/dom-layer.js#L58-L81
|
|
12,245
|
craftyjs/Crafty
|
src/graphics/dom-layer.js
|
function() {
var style = this._div.style,
view = this._viewportRect();
var scale = view._scale;
var dx = -view._x * scale;
var dy = -view._y * scale;
style.transform = style[Crafty.support.prefix + "Transform"] =
"scale(" + scale + ", " + scale + ")";
style.left = Math.round(dx) + "px";
style.top = Math.round(dy) + "px";
style.zIndex = this.options.z;
}
|
javascript
|
function() {
var style = this._div.style,
view = this._viewportRect();
var scale = view._scale;
var dx = -view._x * scale;
var dy = -view._y * scale;
style.transform = style[Crafty.support.prefix + "Transform"] =
"scale(" + scale + ", " + scale + ")";
style.left = Math.round(dx) + "px";
style.top = Math.round(dy) + "px";
style.zIndex = this.options.z;
}
|
[
"function",
"(",
")",
"{",
"var",
"style",
"=",
"this",
".",
"_div",
".",
"style",
",",
"view",
"=",
"this",
".",
"_viewportRect",
"(",
")",
";",
"var",
"scale",
"=",
"view",
".",
"_scale",
";",
"var",
"dx",
"=",
"-",
"view",
".",
"_x",
"*",
"scale",
";",
"var",
"dy",
"=",
"-",
"view",
".",
"_y",
"*",
"scale",
";",
"style",
".",
"transform",
"=",
"style",
"[",
"Crafty",
".",
"support",
".",
"prefix",
"+",
"\"Transform\"",
"]",
"=",
"\"scale(\"",
"+",
"scale",
"+",
"\", \"",
"+",
"scale",
"+",
"\")\"",
";",
"style",
".",
"left",
"=",
"Math",
".",
"round",
"(",
"dx",
")",
"+",
"\"px\"",
";",
"style",
".",
"top",
"=",
"Math",
".",
"round",
"(",
"dy",
")",
"+",
"\"px\"",
";",
"style",
".",
"zIndex",
"=",
"this",
".",
"options",
".",
"z",
";",
"}"
] |
Sets the viewport position and scale Called by render when the dirtyViewport flag is set
|
[
"Sets",
"the",
"viewport",
"position",
"and",
"scale",
"Called",
"by",
"render",
"when",
"the",
"dirtyViewport",
"flag",
"is",
"set"
] |
f3982baa51af24d4e8a14a3194fd3f0e92a2dcba
|
https://github.com/craftyjs/Crafty/blob/f3982baa51af24d4e8a14a3194fd3f0e92a2dcba/src/graphics/dom-layer.js#L182-L195
|
|
12,246
|
craftyjs/Crafty
|
src/graphics/gl-textures.js
|
function() {
var t;
for (var i = 0; i < this.bound_textures.length; i++) {
t = this.bound_textures[i];
t.unbind();
}
this.bound_textures = [];
this.active = null;
}
|
javascript
|
function() {
var t;
for (var i = 0; i < this.bound_textures.length; i++) {
t = this.bound_textures[i];
t.unbind();
}
this.bound_textures = [];
this.active = null;
}
|
[
"function",
"(",
")",
"{",
"var",
"t",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"this",
".",
"bound_textures",
".",
"length",
";",
"i",
"++",
")",
"{",
"t",
"=",
"this",
".",
"bound_textures",
"[",
"i",
"]",
";",
"t",
".",
"unbind",
"(",
")",
";",
"}",
"this",
".",
"bound_textures",
"=",
"[",
"]",
";",
"this",
".",
"active",
"=",
"null",
";",
"}"
] |
Clear out the bound textures and other existing state
|
[
"Clear",
"out",
"the",
"bound",
"textures",
"and",
"other",
"existing",
"state"
] |
f3982baa51af24d4e8a14a3194fd3f0e92a2dcba
|
https://github.com/craftyjs/Crafty/blob/f3982baa51af24d4e8a14a3194fd3f0e92a2dcba/src/graphics/gl-textures.js#L22-L30
|
|
12,247
|
craftyjs/Crafty
|
src/graphics/gl-textures.js
|
function(url, image, repeating) {
// gl is the context, webgl is the Crafty object containing prefs/etc
// var gl = this.gl;
var webgl = this.webgl;
// Check whether a texture that matches the one requested already exists
var id = "texture-(r:" + repeating + ")-" + url;
if (typeof this.registered_textures[id] !== "undefined")
return this.registered_textures[id];
// Create a texture, bind it to the next available unit
var t = new TextureWrapper(this, id);
this.registered_textures[id] = t;
this.bindTexture(t);
// Set the properties of the texture
t.setImage(image);
t.setFilter(webgl.texture_filter);
t.setRepeat(repeating);
return t;
}
|
javascript
|
function(url, image, repeating) {
// gl is the context, webgl is the Crafty object containing prefs/etc
// var gl = this.gl;
var webgl = this.webgl;
// Check whether a texture that matches the one requested already exists
var id = "texture-(r:" + repeating + ")-" + url;
if (typeof this.registered_textures[id] !== "undefined")
return this.registered_textures[id];
// Create a texture, bind it to the next available unit
var t = new TextureWrapper(this, id);
this.registered_textures[id] = t;
this.bindTexture(t);
// Set the properties of the texture
t.setImage(image);
t.setFilter(webgl.texture_filter);
t.setRepeat(repeating);
return t;
}
|
[
"function",
"(",
"url",
",",
"image",
",",
"repeating",
")",
"{",
"// gl is the context, webgl is the Crafty object containing prefs/etc",
"// var gl = this.gl;",
"var",
"webgl",
"=",
"this",
".",
"webgl",
";",
"// Check whether a texture that matches the one requested already exists",
"var",
"id",
"=",
"\"texture-(r:\"",
"+",
"repeating",
"+",
"\")-\"",
"+",
"url",
";",
"if",
"(",
"typeof",
"this",
".",
"registered_textures",
"[",
"id",
"]",
"!==",
"\"undefined\"",
")",
"return",
"this",
".",
"registered_textures",
"[",
"id",
"]",
";",
"// Create a texture, bind it to the next available unit",
"var",
"t",
"=",
"new",
"TextureWrapper",
"(",
"this",
",",
"id",
")",
";",
"this",
".",
"registered_textures",
"[",
"id",
"]",
"=",
"t",
";",
"this",
".",
"bindTexture",
"(",
"t",
")",
";",
"// Set the properties of the texture",
"t",
".",
"setImage",
"(",
"image",
")",
";",
"t",
".",
"setFilter",
"(",
"webgl",
".",
"texture_filter",
")",
";",
"t",
".",
"setRepeat",
"(",
"repeating",
")",
";",
"return",
"t",
";",
"}"
] |
creates a texture out of the given image and repeating state The url is just used to generate a unique id for the texture
|
[
"creates",
"a",
"texture",
"out",
"of",
"the",
"given",
"image",
"and",
"repeating",
"state",
"The",
"url",
"is",
"just",
"used",
"to",
"generate",
"a",
"unique",
"id",
"for",
"the",
"texture"
] |
f3982baa51af24d4e8a14a3194fd3f0e92a2dcba
|
https://github.com/craftyjs/Crafty/blob/f3982baa51af24d4e8a14a3194fd3f0e92a2dcba/src/graphics/gl-textures.js#L34-L55
|
|
12,248
|
craftyjs/Crafty
|
src/graphics/gl-textures.js
|
function() {
var min_size = Infinity;
var index = null;
for (var i = 0; i < this.bound_textures.length; i++) {
var t = this.bound_textures[i];
if (t.size < min_size) {
min_size = t.size;
index = i;
}
}
return index;
}
|
javascript
|
function() {
var min_size = Infinity;
var index = null;
for (var i = 0; i < this.bound_textures.length; i++) {
var t = this.bound_textures[i];
if (t.size < min_size) {
min_size = t.size;
index = i;
}
}
return index;
}
|
[
"function",
"(",
")",
"{",
"var",
"min_size",
"=",
"Infinity",
";",
"var",
"index",
"=",
"null",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"this",
".",
"bound_textures",
".",
"length",
";",
"i",
"++",
")",
"{",
"var",
"t",
"=",
"this",
".",
"bound_textures",
"[",
"i",
"]",
";",
"if",
"(",
"t",
".",
"size",
"<",
"min_size",
")",
"{",
"min_size",
"=",
"t",
".",
"size",
";",
"index",
"=",
"i",
";",
"}",
"}",
"return",
"index",
";",
"}"
] |
Returns the bound texture of smallest size If we have more textures than available units, we should preferentially leave the larger textures bound?
|
[
"Returns",
"the",
"bound",
"texture",
"of",
"smallest",
"size",
"If",
"we",
"have",
"more",
"textures",
"than",
"available",
"units",
"we",
"should",
"preferentially",
"leave",
"the",
"larger",
"textures",
"bound?"
] |
f3982baa51af24d4e8a14a3194fd3f0e92a2dcba
|
https://github.com/craftyjs/Crafty/blob/f3982baa51af24d4e8a14a3194fd3f0e92a2dcba/src/graphics/gl-textures.js#L59-L70
|
|
12,249
|
craftyjs/Crafty
|
src/graphics/gl-textures.js
|
function(t) {
// return if the texture is already bound
if (t.unit !== null) return;
var i = this.getAvailableUnit();
if (this.bound_textures[i]) {
this.unbindTexture(this.bound_textures[i]);
}
this.bound_textures[i] = t;
t.bind(i);
}
|
javascript
|
function(t) {
// return if the texture is already bound
if (t.unit !== null) return;
var i = this.getAvailableUnit();
if (this.bound_textures[i]) {
this.unbindTexture(this.bound_textures[i]);
}
this.bound_textures[i] = t;
t.bind(i);
}
|
[
"function",
"(",
"t",
")",
"{",
"// return if the texture is already bound",
"if",
"(",
"t",
".",
"unit",
"!==",
"null",
")",
"return",
";",
"var",
"i",
"=",
"this",
".",
"getAvailableUnit",
"(",
")",
";",
"if",
"(",
"this",
".",
"bound_textures",
"[",
"i",
"]",
")",
"{",
"this",
".",
"unbindTexture",
"(",
"this",
".",
"bound_textures",
"[",
"i",
"]",
")",
";",
"}",
"this",
".",
"bound_textures",
"[",
"i",
"]",
"=",
"t",
";",
"t",
".",
"bind",
"(",
"i",
")",
";",
"}"
] |
takes a texture object and, if it isn't associated with a unit, binds it to one
|
[
"takes",
"a",
"texture",
"object",
"and",
"if",
"it",
"isn",
"t",
"associated",
"with",
"a",
"unit",
"binds",
"it",
"to",
"one"
] |
f3982baa51af24d4e8a14a3194fd3f0e92a2dcba
|
https://github.com/craftyjs/Crafty/blob/f3982baa51af24d4e8a14a3194fd3f0e92a2dcba/src/graphics/gl-textures.js#L82-L91
|
|
12,250
|
craftyjs/Crafty
|
src/graphics/gl-textures.js
|
function(unit) {
var gl = this.gl;
this.unit = unit;
this.name = "TEXTURE" + unit;
this.manager.setActiveTexture(this);
gl.bindTexture(gl.TEXTURE_2D, this.glTexture);
}
|
javascript
|
function(unit) {
var gl = this.gl;
this.unit = unit;
this.name = "TEXTURE" + unit;
this.manager.setActiveTexture(this);
gl.bindTexture(gl.TEXTURE_2D, this.glTexture);
}
|
[
"function",
"(",
"unit",
")",
"{",
"var",
"gl",
"=",
"this",
".",
"gl",
";",
"this",
".",
"unit",
"=",
"unit",
";",
"this",
".",
"name",
"=",
"\"TEXTURE\"",
"+",
"unit",
";",
"this",
".",
"manager",
".",
"setActiveTexture",
"(",
"this",
")",
";",
"gl",
".",
"bindTexture",
"(",
"gl",
".",
"TEXTURE_2D",
",",
"this",
".",
"glTexture",
")",
";",
"}"
] |
Given a number, binds to the corresponding texture unit
|
[
"Given",
"a",
"number",
"binds",
"to",
"the",
"corresponding",
"texture",
"unit"
] |
f3982baa51af24d4e8a14a3194fd3f0e92a2dcba
|
https://github.com/craftyjs/Crafty/blob/f3982baa51af24d4e8a14a3194fd3f0e92a2dcba/src/graphics/gl-textures.js#L121-L127
|
|
12,251
|
craftyjs/Crafty
|
src/graphics/gl-textures.js
|
function(image) {
if (!this.isActive())
throw "Trying to set image of texture that isn't active";
this.width = image.width;
this.height = image.height;
this.size = image.width * image.height;
this.powerOfTwo = !(
Math.log(image.width) / Math.LN2 !==
Math.floor(Math.log(image.width) / Math.LN2) ||
Math.log(image.height) / Math.LN2 !==
Math.floor(Math.log(image.height) / Math.LN2)
);
var gl = this.gl;
gl.texImage2D(
gl.TEXTURE_2D,
0,
gl.RGBA,
gl.RGBA,
gl.UNSIGNED_BYTE,
image
);
}
|
javascript
|
function(image) {
if (!this.isActive())
throw "Trying to set image of texture that isn't active";
this.width = image.width;
this.height = image.height;
this.size = image.width * image.height;
this.powerOfTwo = !(
Math.log(image.width) / Math.LN2 !==
Math.floor(Math.log(image.width) / Math.LN2) ||
Math.log(image.height) / Math.LN2 !==
Math.floor(Math.log(image.height) / Math.LN2)
);
var gl = this.gl;
gl.texImage2D(
gl.TEXTURE_2D,
0,
gl.RGBA,
gl.RGBA,
gl.UNSIGNED_BYTE,
image
);
}
|
[
"function",
"(",
"image",
")",
"{",
"if",
"(",
"!",
"this",
".",
"isActive",
"(",
")",
")",
"throw",
"\"Trying to set image of texture that isn't active\"",
";",
"this",
".",
"width",
"=",
"image",
".",
"width",
";",
"this",
".",
"height",
"=",
"image",
".",
"height",
";",
"this",
".",
"size",
"=",
"image",
".",
"width",
"*",
"image",
".",
"height",
";",
"this",
".",
"powerOfTwo",
"=",
"!",
"(",
"Math",
".",
"log",
"(",
"image",
".",
"width",
")",
"/",
"Math",
".",
"LN2",
"!==",
"Math",
".",
"floor",
"(",
"Math",
".",
"log",
"(",
"image",
".",
"width",
")",
"/",
"Math",
".",
"LN2",
")",
"||",
"Math",
".",
"log",
"(",
"image",
".",
"height",
")",
"/",
"Math",
".",
"LN2",
"!==",
"Math",
".",
"floor",
"(",
"Math",
".",
"log",
"(",
"image",
".",
"height",
")",
"/",
"Math",
".",
"LN2",
")",
")",
";",
"var",
"gl",
"=",
"this",
".",
"gl",
";",
"gl",
".",
"texImage2D",
"(",
"gl",
".",
"TEXTURE_2D",
",",
"0",
",",
"gl",
".",
"RGBA",
",",
"gl",
".",
"RGBA",
",",
"gl",
".",
"UNSIGNED_BYTE",
",",
"image",
")",
";",
"}"
] |
actually loads an image into the texture object; sets the appropriate metadata
|
[
"actually",
"loads",
"an",
"image",
"into",
"the",
"texture",
"object",
";",
"sets",
"the",
"appropriate",
"metadata"
] |
f3982baa51af24d4e8a14a3194fd3f0e92a2dcba
|
https://github.com/craftyjs/Crafty/blob/f3982baa51af24d4e8a14a3194fd3f0e92a2dcba/src/graphics/gl-textures.js#L142-L163
|
|
12,252
|
craftyjs/Crafty
|
src/graphics/gl-textures.js
|
function(repeat) {
if (!this.isActive())
throw "Trying to set repeat property of texture that isn't active";
if (repeat && !this.powerOfTwo) {
throw "Can't create a repeating image whose dimensions aren't a power of 2 in WebGL contexts";
}
var gl = this.gl;
this.repeatMode = repeat ? gl.REPEAT : gl.CLAMP_TO_EDGE;
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, this.repeatMode);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, this.repeatMode);
}
|
javascript
|
function(repeat) {
if (!this.isActive())
throw "Trying to set repeat property of texture that isn't active";
if (repeat && !this.powerOfTwo) {
throw "Can't create a repeating image whose dimensions aren't a power of 2 in WebGL contexts";
}
var gl = this.gl;
this.repeatMode = repeat ? gl.REPEAT : gl.CLAMP_TO_EDGE;
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, this.repeatMode);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, this.repeatMode);
}
|
[
"function",
"(",
"repeat",
")",
"{",
"if",
"(",
"!",
"this",
".",
"isActive",
"(",
")",
")",
"throw",
"\"Trying to set repeat property of texture that isn't active\"",
";",
"if",
"(",
"repeat",
"&&",
"!",
"this",
".",
"powerOfTwo",
")",
"{",
"throw",
"\"Can't create a repeating image whose dimensions aren't a power of 2 in WebGL contexts\"",
";",
"}",
"var",
"gl",
"=",
"this",
".",
"gl",
";",
"this",
".",
"repeatMode",
"=",
"repeat",
"?",
"gl",
".",
"REPEAT",
":",
"gl",
".",
"CLAMP_TO_EDGE",
";",
"gl",
".",
"texParameteri",
"(",
"gl",
".",
"TEXTURE_2D",
",",
"gl",
".",
"TEXTURE_WRAP_S",
",",
"this",
".",
"repeatMode",
")",
";",
"gl",
".",
"texParameteri",
"(",
"gl",
".",
"TEXTURE_2D",
",",
"gl",
".",
"TEXTURE_WRAP_T",
",",
"this",
".",
"repeatMode",
")",
";",
"}"
] |
set image wrapping
|
[
"set",
"image",
"wrapping"
] |
f3982baa51af24d4e8a14a3194fd3f0e92a2dcba
|
https://github.com/craftyjs/Crafty/blob/f3982baa51af24d4e8a14a3194fd3f0e92a2dcba/src/graphics/gl-textures.js#L175-L185
|
|
12,253
|
craftyjs/Crafty
|
src/graphics/gl-textures.js
|
function(shader, sampler_name, dimension_name) {
if (this.unit === null)
throw "Trying to use texture not set to a texture unit.";
var gl = this.gl;
gl.useProgram(shader);
// Set the texture buffer to use
gl.uniform1i(gl.getUniformLocation(shader, sampler_name), this.unit);
// Set the image dimensions
gl.uniform2f(
gl.getUniformLocation(shader, dimension_name),
this.width,
this.height
);
}
|
javascript
|
function(shader, sampler_name, dimension_name) {
if (this.unit === null)
throw "Trying to use texture not set to a texture unit.";
var gl = this.gl;
gl.useProgram(shader);
// Set the texture buffer to use
gl.uniform1i(gl.getUniformLocation(shader, sampler_name), this.unit);
// Set the image dimensions
gl.uniform2f(
gl.getUniformLocation(shader, dimension_name),
this.width,
this.height
);
}
|
[
"function",
"(",
"shader",
",",
"sampler_name",
",",
"dimension_name",
")",
"{",
"if",
"(",
"this",
".",
"unit",
"===",
"null",
")",
"throw",
"\"Trying to use texture not set to a texture unit.\"",
";",
"var",
"gl",
"=",
"this",
".",
"gl",
";",
"gl",
".",
"useProgram",
"(",
"shader",
")",
";",
"// Set the texture buffer to use",
"gl",
".",
"uniform1i",
"(",
"gl",
".",
"getUniformLocation",
"(",
"shader",
",",
"sampler_name",
")",
",",
"this",
".",
"unit",
")",
";",
"// Set the image dimensions",
"gl",
".",
"uniform2f",
"(",
"gl",
".",
"getUniformLocation",
"(",
"shader",
",",
"dimension_name",
")",
",",
"this",
".",
"width",
",",
"this",
".",
"height",
")",
";",
"}"
] |
given a shader and pair of uniform names, sets the sampler and dimensions to be used by this texture
|
[
"given",
"a",
"shader",
"and",
"pair",
"of",
"uniform",
"names",
"sets",
"the",
"sampler",
"and",
"dimensions",
"to",
"be",
"used",
"by",
"this",
"texture"
] |
f3982baa51af24d4e8a14a3194fd3f0e92a2dcba
|
https://github.com/craftyjs/Crafty/blob/f3982baa51af24d4e8a14a3194fd3f0e92a2dcba/src/graphics/gl-textures.js#L188-L201
|
|
12,254
|
craftyjs/Crafty
|
src/controls/controls-system.js
|
function(dpad, normalize) {
var x = 0,
y = 0;
// Sum up all active directions
for (var d in dpad.directions) {
var dir = dpad.directions[d];
if (!dir.active) continue;
x += dir.n.x;
y += dir.n.y;
}
// Mitigate rounding errors when close to zero movement
x = -1e-10 < x && x < 1e-10 ? 0 : x;
y = -1e-10 < y && y < 1e-10 ? 0 : y;
// Normalize
if (normalize) {
var m = Math.sqrt(x * x + y * y);
if (m > 0) {
x /= m;
y /= m;
}
}
dpad.x = x;
dpad.y = y;
}
|
javascript
|
function(dpad, normalize) {
var x = 0,
y = 0;
// Sum up all active directions
for (var d in dpad.directions) {
var dir = dpad.directions[d];
if (!dir.active) continue;
x += dir.n.x;
y += dir.n.y;
}
// Mitigate rounding errors when close to zero movement
x = -1e-10 < x && x < 1e-10 ? 0 : x;
y = -1e-10 < y && y < 1e-10 ? 0 : y;
// Normalize
if (normalize) {
var m = Math.sqrt(x * x + y * y);
if (m > 0) {
x /= m;
y /= m;
}
}
dpad.x = x;
dpad.y = y;
}
|
[
"function",
"(",
"dpad",
",",
"normalize",
")",
"{",
"var",
"x",
"=",
"0",
",",
"y",
"=",
"0",
";",
"// Sum up all active directions",
"for",
"(",
"var",
"d",
"in",
"dpad",
".",
"directions",
")",
"{",
"var",
"dir",
"=",
"dpad",
".",
"directions",
"[",
"d",
"]",
";",
"if",
"(",
"!",
"dir",
".",
"active",
")",
"continue",
";",
"x",
"+=",
"dir",
".",
"n",
".",
"x",
";",
"y",
"+=",
"dir",
".",
"n",
".",
"y",
";",
"}",
"// Mitigate rounding errors when close to zero movement",
"x",
"=",
"-",
"1e-10",
"<",
"x",
"&&",
"x",
"<",
"1e-10",
"?",
"0",
":",
"x",
";",
"y",
"=",
"-",
"1e-10",
"<",
"y",
"&&",
"y",
"<",
"1e-10",
"?",
"0",
":",
"y",
";",
"// Normalize",
"if",
"(",
"normalize",
")",
"{",
"var",
"m",
"=",
"Math",
".",
"sqrt",
"(",
"x",
"*",
"x",
"+",
"y",
"*",
"y",
")",
";",
"if",
"(",
"m",
">",
"0",
")",
"{",
"x",
"/=",
"m",
";",
"y",
"/=",
"m",
";",
"}",
"}",
"dpad",
".",
"x",
"=",
"x",
";",
"dpad",
".",
"y",
"=",
"y",
";",
"}"
] |
dpad definition is a map of directions to keys array and active flag
|
[
"dpad",
"definition",
"is",
"a",
"map",
"of",
"directions",
"to",
"keys",
"array",
"and",
"active",
"flag"
] |
f3982baa51af24d4e8a14a3194fd3f0e92a2dcba
|
https://github.com/craftyjs/Crafty/blob/f3982baa51af24d4e8a14a3194fd3f0e92a2dcba/src/controls/controls-system.js#L327-L354
|
|
12,255
|
craftyjs/Crafty
|
src/graphics/webgl-layer.js
|
RenderProgramWrapper
|
function RenderProgramWrapper(layer, shader) {
this.shader = shader;
this.layer = layer;
this.context = layer.context;
this.draw = function() {};
this.array_size = 16;
this.max_size = 1024;
this._indexArray = new Uint16Array(6 * this.array_size);
this._indexBuffer = layer.context.createBuffer();
}
|
javascript
|
function RenderProgramWrapper(layer, shader) {
this.shader = shader;
this.layer = layer;
this.context = layer.context;
this.draw = function() {};
this.array_size = 16;
this.max_size = 1024;
this._indexArray = new Uint16Array(6 * this.array_size);
this._indexBuffer = layer.context.createBuffer();
}
|
[
"function",
"RenderProgramWrapper",
"(",
"layer",
",",
"shader",
")",
"{",
"this",
".",
"shader",
"=",
"shader",
";",
"this",
".",
"layer",
"=",
"layer",
";",
"this",
".",
"context",
"=",
"layer",
".",
"context",
";",
"this",
".",
"draw",
"=",
"function",
"(",
")",
"{",
"}",
";",
"this",
".",
"array_size",
"=",
"16",
";",
"this",
".",
"max_size",
"=",
"1024",
";",
"this",
".",
"_indexArray",
"=",
"new",
"Uint16Array",
"(",
"6",
"*",
"this",
".",
"array_size",
")",
";",
"this",
".",
"_indexBuffer",
"=",
"layer",
".",
"context",
".",
"createBuffer",
"(",
")",
";",
"}"
] |
Object for abstracting out all the gl calls to handle rendering entities with a particular program
|
[
"Object",
"for",
"abstracting",
"out",
"all",
"the",
"gl",
"calls",
"to",
"handle",
"rendering",
"entities",
"with",
"a",
"particular",
"program"
] |
f3982baa51af24d4e8a14a3194fd3f0e92a2dcba
|
https://github.com/craftyjs/Crafty/blob/f3982baa51af24d4e8a14a3194fd3f0e92a2dcba/src/graphics/webgl-layer.js#L5-L15
|
12,256
|
craftyjs/Crafty
|
src/graphics/webgl-layer.js
|
function(attributes) {
this.attributes = attributes;
this._attribute_table = {};
var offset = 0;
for (var i = 0; i < attributes.length; i++) {
var a = attributes[i];
this._attribute_table[a.name] = a;
a.bytes = a.bytes || Float32Array.BYTES_PER_ELEMENT;
a.type = a.type || this.context.FLOAT;
a.offset = offset;
a.location = this.context.getAttribLocation(this.shader, a.name);
this.context.enableVertexAttribArray(a.location);
offset += a.width;
}
// Stride is the full width including the last set
this.stride = offset;
// Create attribute array of correct size to hold max elements
this._attributeArray = new Float32Array(
this.array_size * 4 * this.stride
);
this._attributeBuffer = this.context.createBuffer();
this._registryHoles = [];
this._registrySize = 0;
}
|
javascript
|
function(attributes) {
this.attributes = attributes;
this._attribute_table = {};
var offset = 0;
for (var i = 0; i < attributes.length; i++) {
var a = attributes[i];
this._attribute_table[a.name] = a;
a.bytes = a.bytes || Float32Array.BYTES_PER_ELEMENT;
a.type = a.type || this.context.FLOAT;
a.offset = offset;
a.location = this.context.getAttribLocation(this.shader, a.name);
this.context.enableVertexAttribArray(a.location);
offset += a.width;
}
// Stride is the full width including the last set
this.stride = offset;
// Create attribute array of correct size to hold max elements
this._attributeArray = new Float32Array(
this.array_size * 4 * this.stride
);
this._attributeBuffer = this.context.createBuffer();
this._registryHoles = [];
this._registrySize = 0;
}
|
[
"function",
"(",
"attributes",
")",
"{",
"this",
".",
"attributes",
"=",
"attributes",
";",
"this",
".",
"_attribute_table",
"=",
"{",
"}",
";",
"var",
"offset",
"=",
"0",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"attributes",
".",
"length",
";",
"i",
"++",
")",
"{",
"var",
"a",
"=",
"attributes",
"[",
"i",
"]",
";",
"this",
".",
"_attribute_table",
"[",
"a",
".",
"name",
"]",
"=",
"a",
";",
"a",
".",
"bytes",
"=",
"a",
".",
"bytes",
"||",
"Float32Array",
".",
"BYTES_PER_ELEMENT",
";",
"a",
".",
"type",
"=",
"a",
".",
"type",
"||",
"this",
".",
"context",
".",
"FLOAT",
";",
"a",
".",
"offset",
"=",
"offset",
";",
"a",
".",
"location",
"=",
"this",
".",
"context",
".",
"getAttribLocation",
"(",
"this",
".",
"shader",
",",
"a",
".",
"name",
")",
";",
"this",
".",
"context",
".",
"enableVertexAttribArray",
"(",
"a",
".",
"location",
")",
";",
"offset",
"+=",
"a",
".",
"width",
";",
"}",
"// Stride is the full width including the last set",
"this",
".",
"stride",
"=",
"offset",
";",
"// Create attribute array of correct size to hold max elements",
"this",
".",
"_attributeArray",
"=",
"new",
"Float32Array",
"(",
"this",
".",
"array_size",
"*",
"4",
"*",
"this",
".",
"stride",
")",
";",
"this",
".",
"_attributeBuffer",
"=",
"this",
".",
"context",
".",
"createBuffer",
"(",
")",
";",
"this",
".",
"_registryHoles",
"=",
"[",
"]",
";",
"this",
".",
"_registrySize",
"=",
"0",
";",
"}"
] |
Takes an array of attributes; see WebGLLayer's getProgramWrapper method
|
[
"Takes",
"an",
"array",
"of",
"attributes",
";",
"see",
"WebGLLayer",
"s",
"getProgramWrapper",
"method"
] |
f3982baa51af24d4e8a14a3194fd3f0e92a2dcba
|
https://github.com/craftyjs/Crafty/blob/f3982baa51af24d4e8a14a3194fd3f0e92a2dcba/src/graphics/webgl-layer.js#L19-L47
|
|
12,257
|
craftyjs/Crafty
|
src/graphics/webgl-layer.js
|
function(size) {
if (this.array_size >= this.max_size) return;
var newsize = Math.min(size, this.max_size);
var newAttributeArray = new Float32Array(newsize * 4 * this.stride);
var newIndexArray = new Uint16Array(6 * newsize);
newAttributeArray.set(this._attributeArray);
newIndexArray.set(this._indexArray);
this._attributeArray = newAttributeArray;
this._indexArray = newIndexArray;
this.array_size = newsize;
}
|
javascript
|
function(size) {
if (this.array_size >= this.max_size) return;
var newsize = Math.min(size, this.max_size);
var newAttributeArray = new Float32Array(newsize * 4 * this.stride);
var newIndexArray = new Uint16Array(6 * newsize);
newAttributeArray.set(this._attributeArray);
newIndexArray.set(this._indexArray);
this._attributeArray = newAttributeArray;
this._indexArray = newIndexArray;
this.array_size = newsize;
}
|
[
"function",
"(",
"size",
")",
"{",
"if",
"(",
"this",
".",
"array_size",
">=",
"this",
".",
"max_size",
")",
"return",
";",
"var",
"newsize",
"=",
"Math",
".",
"min",
"(",
"size",
",",
"this",
".",
"max_size",
")",
";",
"var",
"newAttributeArray",
"=",
"new",
"Float32Array",
"(",
"newsize",
"*",
"4",
"*",
"this",
".",
"stride",
")",
";",
"var",
"newIndexArray",
"=",
"new",
"Uint16Array",
"(",
"6",
"*",
"newsize",
")",
";",
"newAttributeArray",
".",
"set",
"(",
"this",
".",
"_attributeArray",
")",
";",
"newIndexArray",
".",
"set",
"(",
"this",
".",
"_indexArray",
")",
";",
"this",
".",
"_attributeArray",
"=",
"newAttributeArray",
";",
"this",
".",
"_indexArray",
"=",
"newIndexArray",
";",
"this",
".",
"array_size",
"=",
"newsize",
";",
"}"
] |
increase the size of the typed arrays does so by creating a new array of that size and copying the existing one into it
|
[
"increase",
"the",
"size",
"of",
"the",
"typed",
"arrays",
"does",
"so",
"by",
"creating",
"a",
"new",
"array",
"of",
"that",
"size",
"and",
"copying",
"the",
"existing",
"one",
"into",
"it"
] |
f3982baa51af24d4e8a14a3194fd3f0e92a2dcba
|
https://github.com/craftyjs/Crafty/blob/f3982baa51af24d4e8a14a3194fd3f0e92a2dcba/src/graphics/webgl-layer.js#L51-L65
|
|
12,258
|
craftyjs/Crafty
|
src/graphics/webgl-layer.js
|
function(e) {
if (this._registryHoles.length === 0) {
if (this._registrySize >= this.max_size) {
throw "Number of entities exceeds maximum limit.";
} else if (this._registrySize >= this.array_size) {
this.growArrays(2 * this.array_size);
}
e._glBufferIndex = this._registrySize;
this._registrySize++;
} else {
e._glBufferIndex = this._registryHoles.pop();
}
}
|
javascript
|
function(e) {
if (this._registryHoles.length === 0) {
if (this._registrySize >= this.max_size) {
throw "Number of entities exceeds maximum limit.";
} else if (this._registrySize >= this.array_size) {
this.growArrays(2 * this.array_size);
}
e._glBufferIndex = this._registrySize;
this._registrySize++;
} else {
e._glBufferIndex = this._registryHoles.pop();
}
}
|
[
"function",
"(",
"e",
")",
"{",
"if",
"(",
"this",
".",
"_registryHoles",
".",
"length",
"===",
"0",
")",
"{",
"if",
"(",
"this",
".",
"_registrySize",
">=",
"this",
".",
"max_size",
")",
"{",
"throw",
"\"Number of entities exceeds maximum limit.\"",
";",
"}",
"else",
"if",
"(",
"this",
".",
"_registrySize",
">=",
"this",
".",
"array_size",
")",
"{",
"this",
".",
"growArrays",
"(",
"2",
"*",
"this",
".",
"array_size",
")",
";",
"}",
"e",
".",
"_glBufferIndex",
"=",
"this",
".",
"_registrySize",
";",
"this",
".",
"_registrySize",
"++",
";",
"}",
"else",
"{",
"e",
".",
"_glBufferIndex",
"=",
"this",
".",
"_registryHoles",
".",
"pop",
"(",
")",
";",
"}",
"}"
] |
Add an entity that needs to be rendered by this program Needs to be assigned an index in the buffer
|
[
"Add",
"an",
"entity",
"that",
"needs",
"to",
"be",
"rendered",
"by",
"this",
"program",
"Needs",
"to",
"be",
"assigned",
"an",
"index",
"in",
"the",
"buffer"
] |
f3982baa51af24d4e8a14a3194fd3f0e92a2dcba
|
https://github.com/craftyjs/Crafty/blob/f3982baa51af24d4e8a14a3194fd3f0e92a2dcba/src/graphics/webgl-layer.js#L69-L81
|
|
12,259
|
craftyjs/Crafty
|
src/graphics/webgl-layer.js
|
function(e) {
if (typeof e._glBufferIndex === "number")
this._registryHoles.push(e._glBufferIndex);
e._glBufferIndex = null;
}
|
javascript
|
function(e) {
if (typeof e._glBufferIndex === "number")
this._registryHoles.push(e._glBufferIndex);
e._glBufferIndex = null;
}
|
[
"function",
"(",
"e",
")",
"{",
"if",
"(",
"typeof",
"e",
".",
"_glBufferIndex",
"===",
"\"number\"",
")",
"this",
".",
"_registryHoles",
".",
"push",
"(",
"e",
".",
"_glBufferIndex",
")",
";",
"e",
".",
"_glBufferIndex",
"=",
"null",
";",
"}"
] |
remove an entity; allow its buffer index to be reused
|
[
"remove",
"an",
"entity",
";",
"allow",
"its",
"buffer",
"index",
"to",
"be",
"reused"
] |
f3982baa51af24d4e8a14a3194fd3f0e92a2dcba
|
https://github.com/craftyjs/Crafty/blob/f3982baa51af24d4e8a14a3194fd3f0e92a2dcba/src/graphics/webgl-layer.js#L84-L88
|
|
12,260
|
craftyjs/Crafty
|
src/graphics/webgl-layer.js
|
function() {
var gl = this.context;
gl.useProgram(this.shader);
gl.bindBuffer(gl.ARRAY_BUFFER, this._attributeBuffer);
var a,
attributes = this.attributes;
// Process every attribute
for (var i = 0; i < attributes.length; i++) {
a = attributes[i];
gl.vertexAttribPointer(
a.location,
a.width,
a.type,
false,
this.stride * a.bytes,
a.offset * a.bytes
);
}
// For now, special case the need for texture objects
var t = this.texture_obj;
if (t && t.unit === null) {
this.layer.texture_manager.bindTexture(t);
}
this.index_pointer = 0;
}
|
javascript
|
function() {
var gl = this.context;
gl.useProgram(this.shader);
gl.bindBuffer(gl.ARRAY_BUFFER, this._attributeBuffer);
var a,
attributes = this.attributes;
// Process every attribute
for (var i = 0; i < attributes.length; i++) {
a = attributes[i];
gl.vertexAttribPointer(
a.location,
a.width,
a.type,
false,
this.stride * a.bytes,
a.offset * a.bytes
);
}
// For now, special case the need for texture objects
var t = this.texture_obj;
if (t && t.unit === null) {
this.layer.texture_manager.bindTexture(t);
}
this.index_pointer = 0;
}
|
[
"function",
"(",
")",
"{",
"var",
"gl",
"=",
"this",
".",
"context",
";",
"gl",
".",
"useProgram",
"(",
"this",
".",
"shader",
")",
";",
"gl",
".",
"bindBuffer",
"(",
"gl",
".",
"ARRAY_BUFFER",
",",
"this",
".",
"_attributeBuffer",
")",
";",
"var",
"a",
",",
"attributes",
"=",
"this",
".",
"attributes",
";",
"// Process every attribute",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"attributes",
".",
"length",
";",
"i",
"++",
")",
"{",
"a",
"=",
"attributes",
"[",
"i",
"]",
";",
"gl",
".",
"vertexAttribPointer",
"(",
"a",
".",
"location",
",",
"a",
".",
"width",
",",
"a",
".",
"type",
",",
"false",
",",
"this",
".",
"stride",
"*",
"a",
".",
"bytes",
",",
"a",
".",
"offset",
"*",
"a",
".",
"bytes",
")",
";",
"}",
"// For now, special case the need for texture objects",
"var",
"t",
"=",
"this",
".",
"texture_obj",
";",
"if",
"(",
"t",
"&&",
"t",
".",
"unit",
"===",
"null",
")",
"{",
"this",
".",
"layer",
".",
"texture_manager",
".",
"bindTexture",
"(",
"t",
")",
";",
"}",
"this",
".",
"index_pointer",
"=",
"0",
";",
"}"
] |
Called before a batch of entities is prepped for rendering
|
[
"Called",
"before",
"a",
"batch",
"of",
"entities",
"is",
"prepped",
"for",
"rendering"
] |
f3982baa51af24d4e8a14a3194fd3f0e92a2dcba
|
https://github.com/craftyjs/Crafty/blob/f3982baa51af24d4e8a14a3194fd3f0e92a2dcba/src/graphics/webgl-layer.js#L102-L128
|
|
12,261
|
craftyjs/Crafty
|
src/graphics/webgl-layer.js
|
function(offset) {
var index = this._indexArray,
l = this.index_pointer;
index[0 + l] = 0 + offset;
index[1 + l] = 1 + offset;
index[2 + l] = 2 + offset;
index[3 + l] = 1 + offset;
index[4 + l] = 2 + offset;
index[5 + l] = 3 + offset;
this.index_pointer += 6;
}
|
javascript
|
function(offset) {
var index = this._indexArray,
l = this.index_pointer;
index[0 + l] = 0 + offset;
index[1 + l] = 1 + offset;
index[2 + l] = 2 + offset;
index[3 + l] = 1 + offset;
index[4 + l] = 2 + offset;
index[5 + l] = 3 + offset;
this.index_pointer += 6;
}
|
[
"function",
"(",
"offset",
")",
"{",
"var",
"index",
"=",
"this",
".",
"_indexArray",
",",
"l",
"=",
"this",
".",
"index_pointer",
";",
"index",
"[",
"0",
"+",
"l",
"]",
"=",
"0",
"+",
"offset",
";",
"index",
"[",
"1",
"+",
"l",
"]",
"=",
"1",
"+",
"offset",
";",
"index",
"[",
"2",
"+",
"l",
"]",
"=",
"2",
"+",
"offset",
";",
"index",
"[",
"3",
"+",
"l",
"]",
"=",
"1",
"+",
"offset",
";",
"index",
"[",
"4",
"+",
"l",
"]",
"=",
"2",
"+",
"offset",
";",
"index",
"[",
"5",
"+",
"l",
"]",
"=",
"3",
"+",
"offset",
";",
"this",
".",
"index_pointer",
"+=",
"6",
";",
"}"
] |
adds a set of 6 indices to the index array Corresponds to 2 triangles that make up a rectangle
|
[
"adds",
"a",
"set",
"of",
"6",
"indices",
"to",
"the",
"index",
"array",
"Corresponds",
"to",
"2",
"triangles",
"that",
"make",
"up",
"a",
"rectangle"
] |
f3982baa51af24d4e8a14a3194fd3f0e92a2dcba
|
https://github.com/craftyjs/Crafty/blob/f3982baa51af24d4e8a14a3194fd3f0e92a2dcba/src/graphics/webgl-layer.js#L141-L151
|
|
12,262
|
craftyjs/Crafty
|
src/graphics/webgl-layer.js
|
function() {
var gl = this.context;
gl.bindBuffer(gl.ARRAY_BUFFER, this._attributeBuffer);
gl.bufferData(gl.ARRAY_BUFFER, this._attributeArray, gl.STATIC_DRAW);
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, this._indexBuffer);
gl.bufferData(
gl.ELEMENT_ARRAY_BUFFER,
this._indexArray,
gl.STATIC_DRAW
);
gl.drawElements(gl.TRIANGLES, this.index_pointer, gl.UNSIGNED_SHORT, 0);
}
|
javascript
|
function() {
var gl = this.context;
gl.bindBuffer(gl.ARRAY_BUFFER, this._attributeBuffer);
gl.bufferData(gl.ARRAY_BUFFER, this._attributeArray, gl.STATIC_DRAW);
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, this._indexBuffer);
gl.bufferData(
gl.ELEMENT_ARRAY_BUFFER,
this._indexArray,
gl.STATIC_DRAW
);
gl.drawElements(gl.TRIANGLES, this.index_pointer, gl.UNSIGNED_SHORT, 0);
}
|
[
"function",
"(",
")",
"{",
"var",
"gl",
"=",
"this",
".",
"context",
";",
"gl",
".",
"bindBuffer",
"(",
"gl",
".",
"ARRAY_BUFFER",
",",
"this",
".",
"_attributeBuffer",
")",
";",
"gl",
".",
"bufferData",
"(",
"gl",
".",
"ARRAY_BUFFER",
",",
"this",
".",
"_attributeArray",
",",
"gl",
".",
"STATIC_DRAW",
")",
";",
"gl",
".",
"bindBuffer",
"(",
"gl",
".",
"ELEMENT_ARRAY_BUFFER",
",",
"this",
".",
"_indexBuffer",
")",
";",
"gl",
".",
"bufferData",
"(",
"gl",
".",
"ELEMENT_ARRAY_BUFFER",
",",
"this",
".",
"_indexArray",
",",
"gl",
".",
"STATIC_DRAW",
")",
";",
"gl",
".",
"drawElements",
"(",
"gl",
".",
"TRIANGLES",
",",
"this",
".",
"index_pointer",
",",
"gl",
".",
"UNSIGNED_SHORT",
",",
"0",
")",
";",
"}"
] |
Writes data from the attribute and index arrays to the appropriate buffers, and then calls drawElements.
|
[
"Writes",
"data",
"from",
"the",
"attribute",
"and",
"index",
"arrays",
"to",
"the",
"appropriate",
"buffers",
"and",
"then",
"calls",
"drawElements",
"."
] |
f3982baa51af24d4e8a14a3194fd3f0e92a2dcba
|
https://github.com/craftyjs/Crafty/blob/f3982baa51af24d4e8a14a3194fd3f0e92a2dcba/src/graphics/webgl-layer.js#L154-L165
|
|
12,263
|
craftyjs/Crafty
|
src/graphics/webgl-layer.js
|
function(src, type) {
var gl = this.context;
var shader = gl.createShader(type);
gl.shaderSource(shader, src);
gl.compileShader(shader);
if (!gl.getShaderParameter(shader, gl.COMPILE_STATUS)) {
throw gl.getShaderInfoLog(shader);
}
return shader;
}
|
javascript
|
function(src, type) {
var gl = this.context;
var shader = gl.createShader(type);
gl.shaderSource(shader, src);
gl.compileShader(shader);
if (!gl.getShaderParameter(shader, gl.COMPILE_STATUS)) {
throw gl.getShaderInfoLog(shader);
}
return shader;
}
|
[
"function",
"(",
"src",
",",
"type",
")",
"{",
"var",
"gl",
"=",
"this",
".",
"context",
";",
"var",
"shader",
"=",
"gl",
".",
"createShader",
"(",
"type",
")",
";",
"gl",
".",
"shaderSource",
"(",
"shader",
",",
"src",
")",
";",
"gl",
".",
"compileShader",
"(",
"shader",
")",
";",
"if",
"(",
"!",
"gl",
".",
"getShaderParameter",
"(",
"shader",
",",
"gl",
".",
"COMPILE_STATUS",
")",
")",
"{",
"throw",
"gl",
".",
"getShaderInfoLog",
"(",
"shader",
")",
";",
"}",
"return",
"shader",
";",
"}"
] |
Create a vertex or fragment shader, given the source and type
|
[
"Create",
"a",
"vertex",
"or",
"fragment",
"shader",
"given",
"the",
"source",
"and",
"type"
] |
f3982baa51af24d4e8a14a3194fd3f0e92a2dcba
|
https://github.com/craftyjs/Crafty/blob/f3982baa51af24d4e8a14a3194fd3f0e92a2dcba/src/graphics/webgl-layer.js#L218-L227
|
|
12,264
|
craftyjs/Crafty
|
src/graphics/webgl-layer.js
|
function(shader) {
var gl = this.context;
var fragmentShader = this._compileShader(
shader.fragmentCode,
gl.FRAGMENT_SHADER
);
var vertexShader = this._compileShader(
shader.vertexCode,
gl.VERTEX_SHADER
);
var shaderProgram = gl.createProgram();
gl.attachShader(shaderProgram, vertexShader);
gl.attachShader(shaderProgram, fragmentShader);
gl.linkProgram(shaderProgram);
if (!gl.getProgramParameter(shaderProgram, gl.LINK_STATUS)) {
throw "Could not initialise shaders";
}
shaderProgram.viewport = gl.getUniformLocation(
shaderProgram,
"uViewport"
);
return shaderProgram;
}
|
javascript
|
function(shader) {
var gl = this.context;
var fragmentShader = this._compileShader(
shader.fragmentCode,
gl.FRAGMENT_SHADER
);
var vertexShader = this._compileShader(
shader.vertexCode,
gl.VERTEX_SHADER
);
var shaderProgram = gl.createProgram();
gl.attachShader(shaderProgram, vertexShader);
gl.attachShader(shaderProgram, fragmentShader);
gl.linkProgram(shaderProgram);
if (!gl.getProgramParameter(shaderProgram, gl.LINK_STATUS)) {
throw "Could not initialise shaders";
}
shaderProgram.viewport = gl.getUniformLocation(
shaderProgram,
"uViewport"
);
return shaderProgram;
}
|
[
"function",
"(",
"shader",
")",
"{",
"var",
"gl",
"=",
"this",
".",
"context",
";",
"var",
"fragmentShader",
"=",
"this",
".",
"_compileShader",
"(",
"shader",
".",
"fragmentCode",
",",
"gl",
".",
"FRAGMENT_SHADER",
")",
";",
"var",
"vertexShader",
"=",
"this",
".",
"_compileShader",
"(",
"shader",
".",
"vertexCode",
",",
"gl",
".",
"VERTEX_SHADER",
")",
";",
"var",
"shaderProgram",
"=",
"gl",
".",
"createProgram",
"(",
")",
";",
"gl",
".",
"attachShader",
"(",
"shaderProgram",
",",
"vertexShader",
")",
";",
"gl",
".",
"attachShader",
"(",
"shaderProgram",
",",
"fragmentShader",
")",
";",
"gl",
".",
"linkProgram",
"(",
"shaderProgram",
")",
";",
"if",
"(",
"!",
"gl",
".",
"getProgramParameter",
"(",
"shaderProgram",
",",
"gl",
".",
"LINK_STATUS",
")",
")",
"{",
"throw",
"\"Could not initialise shaders\"",
";",
"}",
"shaderProgram",
".",
"viewport",
"=",
"gl",
".",
"getUniformLocation",
"(",
"shaderProgram",
",",
"\"uViewport\"",
")",
";",
"return",
"shaderProgram",
";",
"}"
] |
Create and return a complete, linked shader program, given the source for the fragment and vertex shaders. Will compile the two shaders and then link them together
|
[
"Create",
"and",
"return",
"a",
"complete",
"linked",
"shader",
"program",
"given",
"the",
"source",
"for",
"the",
"fragment",
"and",
"vertex",
"shaders",
".",
"Will",
"compile",
"the",
"two",
"shaders",
"and",
"then",
"link",
"them",
"together"
] |
f3982baa51af24d4e8a14a3194fd3f0e92a2dcba
|
https://github.com/craftyjs/Crafty/blob/f3982baa51af24d4e8a14a3194fd3f0e92a2dcba/src/graphics/webgl-layer.js#L231-L256
|
|
12,265
|
craftyjs/Crafty
|
src/graphics/webgl-layer.js
|
function() {
var c = this._canvas;
c.width = Crafty.viewport.width;
c.height = Crafty.viewport.height;
var gl = this.context;
gl.viewportWidth = c.width;
gl.viewportHeight = c.height;
}
|
javascript
|
function() {
var c = this._canvas;
c.width = Crafty.viewport.width;
c.height = Crafty.viewport.height;
var gl = this.context;
gl.viewportWidth = c.width;
gl.viewportHeight = c.height;
}
|
[
"function",
"(",
")",
"{",
"var",
"c",
"=",
"this",
".",
"_canvas",
";",
"c",
".",
"width",
"=",
"Crafty",
".",
"viewport",
".",
"width",
";",
"c",
".",
"height",
"=",
"Crafty",
".",
"viewport",
".",
"height",
";",
"var",
"gl",
"=",
"this",
".",
"context",
";",
"gl",
".",
"viewportWidth",
"=",
"c",
".",
"width",
";",
"gl",
".",
"viewportHeight",
"=",
"c",
".",
"height",
";",
"}"
] |
Called when the viewport resizes
|
[
"Called",
"when",
"the",
"viewport",
"resizes"
] |
f3982baa51af24d4e8a14a3194fd3f0e92a2dcba
|
https://github.com/craftyjs/Crafty/blob/f3982baa51af24d4e8a14a3194fd3f0e92a2dcba/src/graphics/webgl-layer.js#L365-L373
|
|
12,266
|
craftyjs/Crafty
|
src/graphics/webgl-layer.js
|
function(rect) {
rect = rect || this._viewportRect();
var gl = this.context;
// Set viewport and clear it
gl.viewport(0, 0, gl.viewportWidth, gl.viewportHeight);
gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
//Set the viewport uniform variables used by each registered program
var programs = this.programs;
if (this._dirtyViewport) {
var view = this._viewportRect();
for (var comp in programs) {
programs[comp].setViewportUniforms(view, this.options);
}
this._dirtyViewport = false;
}
// Search for any entities in the given area (viewport unless otherwise specified)
var q = Crafty.map.search(rect),
i = 0,
l = q.length,
current;
//From all potential candidates, build a list of visible entities, then sort by zorder
var visible_gl = this.visible_gl;
visible_gl.length = 0;
for (i = 0; i < l; i++) {
current = q[i];
if (
current._visible &&
current.program &&
current._drawLayer === this
) {
visible_gl.push(current);
}
}
visible_gl.sort(this._sort);
l = visible_gl.length;
// Now iterate through the z-sorted entities to be rendered
// Each entity writes it's data into a typed array
// The entities are rendered in batches, where the entire array is copied to a buffer in one operation
// A batch is rendered whenever the next element needs to use a different type of program
// Therefore, you get better performance by grouping programs by z-order if possible.
// (Each sprite sheet will use a different program, but multiple sprites on the same sheet can be rendered in one batch)
var shaderProgram = null;
for (i = 0; i < l; i++) {
current = visible_gl[i];
if (shaderProgram !== current.program) {
if (shaderProgram !== null) {
shaderProgram.renderBatch();
}
shaderProgram = current.program;
shaderProgram.index_pointer = 0;
shaderProgram.switchTo();
}
current.draw();
current._changed = false;
}
if (shaderProgram !== null) {
shaderProgram.renderBatch();
}
}
|
javascript
|
function(rect) {
rect = rect || this._viewportRect();
var gl = this.context;
// Set viewport and clear it
gl.viewport(0, 0, gl.viewportWidth, gl.viewportHeight);
gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
//Set the viewport uniform variables used by each registered program
var programs = this.programs;
if (this._dirtyViewport) {
var view = this._viewportRect();
for (var comp in programs) {
programs[comp].setViewportUniforms(view, this.options);
}
this._dirtyViewport = false;
}
// Search for any entities in the given area (viewport unless otherwise specified)
var q = Crafty.map.search(rect),
i = 0,
l = q.length,
current;
//From all potential candidates, build a list of visible entities, then sort by zorder
var visible_gl = this.visible_gl;
visible_gl.length = 0;
for (i = 0; i < l; i++) {
current = q[i];
if (
current._visible &&
current.program &&
current._drawLayer === this
) {
visible_gl.push(current);
}
}
visible_gl.sort(this._sort);
l = visible_gl.length;
// Now iterate through the z-sorted entities to be rendered
// Each entity writes it's data into a typed array
// The entities are rendered in batches, where the entire array is copied to a buffer in one operation
// A batch is rendered whenever the next element needs to use a different type of program
// Therefore, you get better performance by grouping programs by z-order if possible.
// (Each sprite sheet will use a different program, but multiple sprites on the same sheet can be rendered in one batch)
var shaderProgram = null;
for (i = 0; i < l; i++) {
current = visible_gl[i];
if (shaderProgram !== current.program) {
if (shaderProgram !== null) {
shaderProgram.renderBatch();
}
shaderProgram = current.program;
shaderProgram.index_pointer = 0;
shaderProgram.switchTo();
}
current.draw();
current._changed = false;
}
if (shaderProgram !== null) {
shaderProgram.renderBatch();
}
}
|
[
"function",
"(",
"rect",
")",
"{",
"rect",
"=",
"rect",
"||",
"this",
".",
"_viewportRect",
"(",
")",
";",
"var",
"gl",
"=",
"this",
".",
"context",
";",
"// Set viewport and clear it",
"gl",
".",
"viewport",
"(",
"0",
",",
"0",
",",
"gl",
".",
"viewportWidth",
",",
"gl",
".",
"viewportHeight",
")",
";",
"gl",
".",
"clear",
"(",
"gl",
".",
"COLOR_BUFFER_BIT",
"|",
"gl",
".",
"DEPTH_BUFFER_BIT",
")",
";",
"//Set the viewport uniform variables used by each registered program",
"var",
"programs",
"=",
"this",
".",
"programs",
";",
"if",
"(",
"this",
".",
"_dirtyViewport",
")",
"{",
"var",
"view",
"=",
"this",
".",
"_viewportRect",
"(",
")",
";",
"for",
"(",
"var",
"comp",
"in",
"programs",
")",
"{",
"programs",
"[",
"comp",
"]",
".",
"setViewportUniforms",
"(",
"view",
",",
"this",
".",
"options",
")",
";",
"}",
"this",
".",
"_dirtyViewport",
"=",
"false",
";",
"}",
"// Search for any entities in the given area (viewport unless otherwise specified)",
"var",
"q",
"=",
"Crafty",
".",
"map",
".",
"search",
"(",
"rect",
")",
",",
"i",
"=",
"0",
",",
"l",
"=",
"q",
".",
"length",
",",
"current",
";",
"//From all potential candidates, build a list of visible entities, then sort by zorder",
"var",
"visible_gl",
"=",
"this",
".",
"visible_gl",
";",
"visible_gl",
".",
"length",
"=",
"0",
";",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"l",
";",
"i",
"++",
")",
"{",
"current",
"=",
"q",
"[",
"i",
"]",
";",
"if",
"(",
"current",
".",
"_visible",
"&&",
"current",
".",
"program",
"&&",
"current",
".",
"_drawLayer",
"===",
"this",
")",
"{",
"visible_gl",
".",
"push",
"(",
"current",
")",
";",
"}",
"}",
"visible_gl",
".",
"sort",
"(",
"this",
".",
"_sort",
")",
";",
"l",
"=",
"visible_gl",
".",
"length",
";",
"// Now iterate through the z-sorted entities to be rendered",
"// Each entity writes it's data into a typed array",
"// The entities are rendered in batches, where the entire array is copied to a buffer in one operation",
"// A batch is rendered whenever the next element needs to use a different type of program",
"// Therefore, you get better performance by grouping programs by z-order if possible.",
"// (Each sprite sheet will use a different program, but multiple sprites on the same sheet can be rendered in one batch)",
"var",
"shaderProgram",
"=",
"null",
";",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"l",
";",
"i",
"++",
")",
"{",
"current",
"=",
"visible_gl",
"[",
"i",
"]",
";",
"if",
"(",
"shaderProgram",
"!==",
"current",
".",
"program",
")",
"{",
"if",
"(",
"shaderProgram",
"!==",
"null",
")",
"{",
"shaderProgram",
".",
"renderBatch",
"(",
")",
";",
"}",
"shaderProgram",
"=",
"current",
".",
"program",
";",
"shaderProgram",
".",
"index_pointer",
"=",
"0",
";",
"shaderProgram",
".",
"switchTo",
"(",
")",
";",
"}",
"current",
".",
"draw",
"(",
")",
";",
"current",
".",
"_changed",
"=",
"false",
";",
"}",
"if",
"(",
"shaderProgram",
"!==",
"null",
")",
"{",
"shaderProgram",
".",
"renderBatch",
"(",
")",
";",
"}",
"}"
] |
Render any entities associated with this context; called in response to a draw event
|
[
"Render",
"any",
"entities",
"associated",
"with",
"this",
"context",
";",
"called",
"in",
"response",
"to",
"a",
"draw",
"event"
] |
f3982baa51af24d4e8a14a3194fd3f0e92a2dcba
|
https://github.com/craftyjs/Crafty/blob/f3982baa51af24d4e8a14a3194fd3f0e92a2dcba/src/graphics/webgl-layer.js#L389-L453
|
|
12,267
|
craftyjs/Crafty
|
src/graphics/text.js
|
function(propertyName) {
// could check for DOM component, but this event should only be fired by such an entity!
// Rather than triggering Invalidate on each of these, we rely on css() triggering that event
switch (propertyName) {
case "textAlign":
this._textAlign = this._element.style.textAlign;
break;
case "color":
// Need to set individual color components, so use method
this.textColor(this._element.style.color);
break;
case "fontType":
this._textFont.type = this._element.style.fontType;
break;
case "fontWeight":
this._textFont.weight = this._element.style.fontWeight;
break;
case "fontSize":
this._textFont.size = this._element.style.fontSize;
break;
case "fontFamily":
this._textFont.family = this._element.style.fontFamily;
break;
case "fontVariant":
this._textFont.variant = this._element.style.fontVariant;
break;
case "lineHeight":
this._textFont.lineHeight = this._element.style.lineHeight;
break;
}
}
|
javascript
|
function(propertyName) {
// could check for DOM component, but this event should only be fired by such an entity!
// Rather than triggering Invalidate on each of these, we rely on css() triggering that event
switch (propertyName) {
case "textAlign":
this._textAlign = this._element.style.textAlign;
break;
case "color":
// Need to set individual color components, so use method
this.textColor(this._element.style.color);
break;
case "fontType":
this._textFont.type = this._element.style.fontType;
break;
case "fontWeight":
this._textFont.weight = this._element.style.fontWeight;
break;
case "fontSize":
this._textFont.size = this._element.style.fontSize;
break;
case "fontFamily":
this._textFont.family = this._element.style.fontFamily;
break;
case "fontVariant":
this._textFont.variant = this._element.style.fontVariant;
break;
case "lineHeight":
this._textFont.lineHeight = this._element.style.lineHeight;
break;
}
}
|
[
"function",
"(",
"propertyName",
")",
"{",
"// could check for DOM component, but this event should only be fired by such an entity!",
"// Rather than triggering Invalidate on each of these, we rely on css() triggering that event",
"switch",
"(",
"propertyName",
")",
"{",
"case",
"\"textAlign\"",
":",
"this",
".",
"_textAlign",
"=",
"this",
".",
"_element",
".",
"style",
".",
"textAlign",
";",
"break",
";",
"case",
"\"color\"",
":",
"// Need to set individual color components, so use method",
"this",
".",
"textColor",
"(",
"this",
".",
"_element",
".",
"style",
".",
"color",
")",
";",
"break",
";",
"case",
"\"fontType\"",
":",
"this",
".",
"_textFont",
".",
"type",
"=",
"this",
".",
"_element",
".",
"style",
".",
"fontType",
";",
"break",
";",
"case",
"\"fontWeight\"",
":",
"this",
".",
"_textFont",
".",
"weight",
"=",
"this",
".",
"_element",
".",
"style",
".",
"fontWeight",
";",
"break",
";",
"case",
"\"fontSize\"",
":",
"this",
".",
"_textFont",
".",
"size",
"=",
"this",
".",
"_element",
".",
"style",
".",
"fontSize",
";",
"break",
";",
"case",
"\"fontFamily\"",
":",
"this",
".",
"_textFont",
".",
"family",
"=",
"this",
".",
"_element",
".",
"style",
".",
"fontFamily",
";",
"break",
";",
"case",
"\"fontVariant\"",
":",
"this",
".",
"_textFont",
".",
"variant",
"=",
"this",
".",
"_element",
".",
"style",
".",
"fontVariant",
";",
"break",
";",
"case",
"\"lineHeight\"",
":",
"this",
".",
"_textFont",
".",
"lineHeight",
"=",
"this",
".",
"_element",
".",
"style",
".",
"lineHeight",
";",
"break",
";",
"}",
"}"
] |
type, weight, size, family, lineHeight, and variant. For a few hardcoded css properties, set the internal definitions
|
[
"type",
"weight",
"size",
"family",
"lineHeight",
"and",
"variant",
".",
"For",
"a",
"few",
"hardcoded",
"css",
"properties",
"set",
"the",
"internal",
"definitions"
] |
f3982baa51af24d4e8a14a3194fd3f0e92a2dcba
|
https://github.com/craftyjs/Crafty/blob/f3982baa51af24d4e8a14a3194fd3f0e92a2dcba/src/graphics/text.js#L81-L111
|
|
12,268
|
craftyjs/Crafty
|
src/graphics/text.js
|
function() {
return (
this._textFont.type +
" " +
this._textFont.variant +
" " +
this._textFont.weight +
" " +
this._textFont.size +
" / " +
this._textFont.lineHeight +
" " +
this._textFont.family
);
}
|
javascript
|
function() {
return (
this._textFont.type +
" " +
this._textFont.variant +
" " +
this._textFont.weight +
" " +
this._textFont.size +
" / " +
this._textFont.lineHeight +
" " +
this._textFont.family
);
}
|
[
"function",
"(",
")",
"{",
"return",
"(",
"this",
".",
"_textFont",
".",
"type",
"+",
"\" \"",
"+",
"this",
".",
"_textFont",
".",
"variant",
"+",
"\" \"",
"+",
"this",
".",
"_textFont",
".",
"weight",
"+",
"\" \"",
"+",
"this",
".",
"_textFont",
".",
"size",
"+",
"\" / \"",
"+",
"this",
".",
"_textFont",
".",
"lineHeight",
"+",
"\" \"",
"+",
"this",
".",
"_textFont",
".",
"family",
")",
";",
"}"
] |
Returns the font string to use
|
[
"Returns",
"the",
"font",
"string",
"to",
"use"
] |
f3982baa51af24d4e8a14a3194fd3f0e92a2dcba
|
https://github.com/craftyjs/Crafty/blob/f3982baa51af24d4e8a14a3194fd3f0e92a2dcba/src/graphics/text.js#L259-L273
|
|
12,269
|
craftyjs/Crafty
|
src/graphics/webgl.js
|
function(compName, shader) {
this.program = this._drawLayer.getProgramWrapper(compName, shader);
// Needs to know where in the big array we are!
this.program.registerEntity(this);
// Shader program means ready
this.ready = true;
}
|
javascript
|
function(compName, shader) {
this.program = this._drawLayer.getProgramWrapper(compName, shader);
// Needs to know where in the big array we are!
this.program.registerEntity(this);
// Shader program means ready
this.ready = true;
}
|
[
"function",
"(",
"compName",
",",
"shader",
")",
"{",
"this",
".",
"program",
"=",
"this",
".",
"_drawLayer",
".",
"getProgramWrapper",
"(",
"compName",
",",
"shader",
")",
";",
"// Needs to know where in the big array we are!",
"this",
".",
"program",
".",
"registerEntity",
"(",
"this",
")",
";",
"// Shader program means ready",
"this",
".",
"ready",
"=",
"true",
";",
"}"
] |
v_src is optional, there's a default vertex shader that works for regular rectangular entities
|
[
"v_src",
"is",
"optional",
"there",
"s",
"a",
"default",
"vertex",
"shader",
"that",
"works",
"for",
"regular",
"rectangular",
"entities"
] |
f3982baa51af24d4e8a14a3194fd3f0e92a2dcba
|
https://github.com/craftyjs/Crafty/blob/f3982baa51af24d4e8a14a3194fd3f0e92a2dcba/src/graphics/webgl.js#L282-L289
|
|
12,270
|
craftyjs/Crafty
|
src/sound/sound.js
|
function() {
this.supported = {};
// Without support, no formats are supported
if (!Crafty.support.audio) return;
var audio = this.audioElement(),
canplay;
for (var i in this.codecs) {
canplay = audio.canPlayType(this.codecs[i]);
if (canplay !== "" && canplay !== "no") {
this.supported[i] = true;
} else {
this.supported[i] = false;
}
}
}
|
javascript
|
function() {
this.supported = {};
// Without support, no formats are supported
if (!Crafty.support.audio) return;
var audio = this.audioElement(),
canplay;
for (var i in this.codecs) {
canplay = audio.canPlayType(this.codecs[i]);
if (canplay !== "" && canplay !== "no") {
this.supported[i] = true;
} else {
this.supported[i] = false;
}
}
}
|
[
"function",
"(",
")",
"{",
"this",
".",
"supported",
"=",
"{",
"}",
";",
"// Without support, no formats are supported",
"if",
"(",
"!",
"Crafty",
".",
"support",
".",
"audio",
")",
"return",
";",
"var",
"audio",
"=",
"this",
".",
"audioElement",
"(",
")",
",",
"canplay",
";",
"for",
"(",
"var",
"i",
"in",
"this",
".",
"codecs",
")",
"{",
"canplay",
"=",
"audio",
".",
"canPlayType",
"(",
"this",
".",
"codecs",
"[",
"i",
"]",
")",
";",
"if",
"(",
"canplay",
"!==",
"\"\"",
"&&",
"canplay",
"!==",
"\"no\"",
")",
"{",
"this",
".",
"supported",
"[",
"i",
"]",
"=",
"true",
";",
"}",
"else",
"{",
"this",
".",
"supported",
"[",
"i",
"]",
"=",
"false",
";",
"}",
"}",
"}"
] |
Function to setup supported formats
|
[
"Function",
"to",
"setup",
"supported",
"formats"
] |
f3982baa51af24d4e8a14a3194fd3f0e92a2dcba
|
https://github.com/craftyjs/Crafty/blob/f3982baa51af24d4e8a14a3194fd3f0e92a2dcba/src/sound/sound.js#L36-L50
|
|
12,271
|
craftyjs/Crafty
|
src/sound/sound.js
|
function() {
for (var i = 0; i < this.channels.length; i++) {
var chan = this.channels[i];
/*
* Second test looks for stuff that's out of use,
* but fallen foul of Chromium bug 280417
*/
if (
chan.active === false ||
(chan.obj.ended &&
chan.repeat <= this.sounds[chan.id].played)
) {
chan.active = true;
return chan;
}
}
// If necessary, create a new element, unless we've already reached the max limit
if (i < this.maxChannels) {
var c = {
obj: this.audioElement(),
active: true,
// Checks that the channel is being used to play sound id
_is: function(id) {
return this.id === id && this.active;
}
};
this.channels.push(c);
return c;
}
// In that case, return null
return null;
}
|
javascript
|
function() {
for (var i = 0; i < this.channels.length; i++) {
var chan = this.channels[i];
/*
* Second test looks for stuff that's out of use,
* but fallen foul of Chromium bug 280417
*/
if (
chan.active === false ||
(chan.obj.ended &&
chan.repeat <= this.sounds[chan.id].played)
) {
chan.active = true;
return chan;
}
}
// If necessary, create a new element, unless we've already reached the max limit
if (i < this.maxChannels) {
var c = {
obj: this.audioElement(),
active: true,
// Checks that the channel is being used to play sound id
_is: function(id) {
return this.id === id && this.active;
}
};
this.channels.push(c);
return c;
}
// In that case, return null
return null;
}
|
[
"function",
"(",
")",
"{",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"this",
".",
"channels",
".",
"length",
";",
"i",
"++",
")",
"{",
"var",
"chan",
"=",
"this",
".",
"channels",
"[",
"i",
"]",
";",
"/*\n * Second test looks for stuff that's out of use,\n * but fallen foul of Chromium bug 280417\n */",
"if",
"(",
"chan",
".",
"active",
"===",
"false",
"||",
"(",
"chan",
".",
"obj",
".",
"ended",
"&&",
"chan",
".",
"repeat",
"<=",
"this",
".",
"sounds",
"[",
"chan",
".",
"id",
"]",
".",
"played",
")",
")",
"{",
"chan",
".",
"active",
"=",
"true",
";",
"return",
"chan",
";",
"}",
"}",
"// If necessary, create a new element, unless we've already reached the max limit",
"if",
"(",
"i",
"<",
"this",
".",
"maxChannels",
")",
"{",
"var",
"c",
"=",
"{",
"obj",
":",
"this",
".",
"audioElement",
"(",
")",
",",
"active",
":",
"true",
",",
"// Checks that the channel is being used to play sound id",
"_is",
":",
"function",
"(",
"id",
")",
"{",
"return",
"this",
".",
"id",
"===",
"id",
"&&",
"this",
".",
"active",
";",
"}",
"}",
";",
"this",
".",
"channels",
".",
"push",
"(",
"c",
")",
";",
"return",
"c",
";",
"}",
"// In that case, return null",
"return",
"null",
";",
"}"
] |
Finds an unused audio element, marks it as in use, and return it.
|
[
"Finds",
"an",
"unused",
"audio",
"element",
"marks",
"it",
"as",
"in",
"use",
"and",
"return",
"it",
"."
] |
f3982baa51af24d4e8a14a3194fd3f0e92a2dcba
|
https://github.com/craftyjs/Crafty/blob/f3982baa51af24d4e8a14a3194fd3f0e92a2dcba/src/sound/sound.js#L270-L301
|
|
12,272
|
craftyjs/Crafty
|
src/graphics/image.js
|
function(layer) {
if (!this.img || !layer) return;
if (layer.type === "Canvas") {
this._pattern = this._drawContext.createPattern(
this.img,
this._repeat
);
} else if (layer.type === "WebGL") {
this._establishShader(
"image:" + this.__image,
Crafty.defaultShader("Image")
);
this.program.setTexture(
this._drawLayer.makeTexture(
this.__image,
this.img,
this._repeat !== "no-repeat"
)
);
}
if (this._repeat === "no-repeat") {
this.w = this.w || this.img.width;
this.h = this.h || this.img.height;
}
this.ready = true;
this.trigger("Invalidate");
}
|
javascript
|
function(layer) {
if (!this.img || !layer) return;
if (layer.type === "Canvas") {
this._pattern = this._drawContext.createPattern(
this.img,
this._repeat
);
} else if (layer.type === "WebGL") {
this._establishShader(
"image:" + this.__image,
Crafty.defaultShader("Image")
);
this.program.setTexture(
this._drawLayer.makeTexture(
this.__image,
this.img,
this._repeat !== "no-repeat"
)
);
}
if (this._repeat === "no-repeat") {
this.w = this.w || this.img.width;
this.h = this.h || this.img.height;
}
this.ready = true;
this.trigger("Invalidate");
}
|
[
"function",
"(",
"layer",
")",
"{",
"if",
"(",
"!",
"this",
".",
"img",
"||",
"!",
"layer",
")",
"return",
";",
"if",
"(",
"layer",
".",
"type",
"===",
"\"Canvas\"",
")",
"{",
"this",
".",
"_pattern",
"=",
"this",
".",
"_drawContext",
".",
"createPattern",
"(",
"this",
".",
"img",
",",
"this",
".",
"_repeat",
")",
";",
"}",
"else",
"if",
"(",
"layer",
".",
"type",
"===",
"\"WebGL\"",
")",
"{",
"this",
".",
"_establishShader",
"(",
"\"image:\"",
"+",
"this",
".",
"__image",
",",
"Crafty",
".",
"defaultShader",
"(",
"\"Image\"",
")",
")",
";",
"this",
".",
"program",
".",
"setTexture",
"(",
"this",
".",
"_drawLayer",
".",
"makeTexture",
"(",
"this",
".",
"__image",
",",
"this",
".",
"img",
",",
"this",
".",
"_repeat",
"!==",
"\"no-repeat\"",
")",
")",
";",
"}",
"if",
"(",
"this",
".",
"_repeat",
"===",
"\"no-repeat\"",
")",
"{",
"this",
".",
"w",
"=",
"this",
".",
"w",
"||",
"this",
".",
"img",
".",
"width",
";",
"this",
".",
"h",
"=",
"this",
".",
"h",
"||",
"this",
".",
"img",
".",
"height",
";",
"}",
"this",
".",
"ready",
"=",
"true",
";",
"this",
".",
"trigger",
"(",
"\"Invalidate\"",
")",
";",
"}"
] |
called on image change or layer attachment
|
[
"called",
"on",
"image",
"change",
"or",
"layer",
"attachment"
] |
f3982baa51af24d4e8a14a3194fd3f0e92a2dcba
|
https://github.com/craftyjs/Crafty/blob/f3982baa51af24d4e8a14a3194fd3f0e92a2dcba/src/graphics/image.js#L124-L153
|
|
12,273
|
craftyjs/Crafty
|
src/graphics/dom.js
|
function() {
var comp,
c = this.__c,
str = "";
for (comp in c) {
str += " " + comp;
}
str = str.substr(1);
this._element.className = str;
}
|
javascript
|
function() {
var comp,
c = this.__c,
str = "";
for (comp in c) {
str += " " + comp;
}
str = str.substr(1);
this._element.className = str;
}
|
[
"function",
"(",
")",
"{",
"var",
"comp",
",",
"c",
"=",
"this",
".",
"__c",
",",
"str",
"=",
"\"\"",
";",
"for",
"(",
"comp",
"in",
"c",
")",
"{",
"str",
"+=",
"\" \"",
"+",
"comp",
";",
"}",
"str",
"=",
"str",
".",
"substr",
"(",
"1",
")",
";",
"this",
".",
"_element",
".",
"className",
"=",
"str",
";",
"}"
] |
adds a class on NewComponent events
|
[
"adds",
"a",
"class",
"on",
"NewComponent",
"events"
] |
f3982baa51af24d4e8a14a3194fd3f0e92a2dcba
|
https://github.com/craftyjs/Crafty/blob/f3982baa51af24d4e8a14a3194fd3f0e92a2dcba/src/graphics/dom.js#L90-L99
|
|
12,274
|
craftyjs/Crafty
|
src/debug/logging.js
|
function() {
if (
Crafty.loggingEnabled &&
(typeof window !== "undefined" ? window.console : console) &&
console.log
) {
console.log.apply(console, arguments);
}
}
|
javascript
|
function() {
if (
Crafty.loggingEnabled &&
(typeof window !== "undefined" ? window.console : console) &&
console.log
) {
console.log.apply(console, arguments);
}
}
|
[
"function",
"(",
")",
"{",
"if",
"(",
"Crafty",
".",
"loggingEnabled",
"&&",
"(",
"typeof",
"window",
"!==",
"\"undefined\"",
"?",
"window",
".",
"console",
":",
"console",
")",
"&&",
"console",
".",
"log",
")",
"{",
"console",
".",
"log",
".",
"apply",
"(",
"console",
",",
"arguments",
")",
";",
"}",
"}"
] |
In some cases console.log doesn't exist, so provide a wrapper for it
|
[
"In",
"some",
"cases",
"console",
".",
"log",
"doesn",
"t",
"exist",
"so",
"provide",
"a",
"wrapper",
"for",
"it"
] |
f3982baa51af24d4e8a14a3194fd3f0e92a2dcba
|
https://github.com/craftyjs/Crafty/blob/f3982baa51af24d4e8a14a3194fd3f0e92a2dcba/src/debug/logging.js#L29-L37
|
|
12,275
|
craftyjs/Crafty
|
src/spatial/collision.js
|
function(e) {
var dx,
dy,
rot = this.rotation * DEG_TO_RAD,
points = this.map.points;
// Depending on the change of axis, move the corners of the rectangle appropriately
if (e.axis === "w") {
if (rot) {
dx = e.amount * Math.cos(rot);
dy = e.amount * Math.sin(rot);
} else {
dx = e.amount;
dy = 0;
}
// "top right" point shifts on change of w
points[2] += dx;
points[3] += dy;
} else {
if (rot) {
dy = e.amount * Math.cos(rot);
dx = -e.amount * Math.sin(rot);
} else {
dx = 0;
dy = e.amount;
}
// "bottom left" point shifts on change of h
points[6] += dx;
points[7] += dy;
}
// "bottom right" point shifts on either change
points[4] += dx;
points[5] += dy;
}
|
javascript
|
function(e) {
var dx,
dy,
rot = this.rotation * DEG_TO_RAD,
points = this.map.points;
// Depending on the change of axis, move the corners of the rectangle appropriately
if (e.axis === "w") {
if (rot) {
dx = e.amount * Math.cos(rot);
dy = e.amount * Math.sin(rot);
} else {
dx = e.amount;
dy = 0;
}
// "top right" point shifts on change of w
points[2] += dx;
points[3] += dy;
} else {
if (rot) {
dy = e.amount * Math.cos(rot);
dx = -e.amount * Math.sin(rot);
} else {
dx = 0;
dy = e.amount;
}
// "bottom left" point shifts on change of h
points[6] += dx;
points[7] += dy;
}
// "bottom right" point shifts on either change
points[4] += dx;
points[5] += dy;
}
|
[
"function",
"(",
"e",
")",
"{",
"var",
"dx",
",",
"dy",
",",
"rot",
"=",
"this",
".",
"rotation",
"*",
"DEG_TO_RAD",
",",
"points",
"=",
"this",
".",
"map",
".",
"points",
";",
"// Depending on the change of axis, move the corners of the rectangle appropriately",
"if",
"(",
"e",
".",
"axis",
"===",
"\"w\"",
")",
"{",
"if",
"(",
"rot",
")",
"{",
"dx",
"=",
"e",
".",
"amount",
"*",
"Math",
".",
"cos",
"(",
"rot",
")",
";",
"dy",
"=",
"e",
".",
"amount",
"*",
"Math",
".",
"sin",
"(",
"rot",
")",
";",
"}",
"else",
"{",
"dx",
"=",
"e",
".",
"amount",
";",
"dy",
"=",
"0",
";",
"}",
"// \"top right\" point shifts on change of w",
"points",
"[",
"2",
"]",
"+=",
"dx",
";",
"points",
"[",
"3",
"]",
"+=",
"dy",
";",
"}",
"else",
"{",
"if",
"(",
"rot",
")",
"{",
"dy",
"=",
"e",
".",
"amount",
"*",
"Math",
".",
"cos",
"(",
"rot",
")",
";",
"dx",
"=",
"-",
"e",
".",
"amount",
"*",
"Math",
".",
"sin",
"(",
"rot",
")",
";",
"}",
"else",
"{",
"dx",
"=",
"0",
";",
"dy",
"=",
"e",
".",
"amount",
";",
"}",
"// \"bottom left\" point shifts on change of h",
"points",
"[",
"6",
"]",
"+=",
"dx",
";",
"points",
"[",
"7",
"]",
"+=",
"dy",
";",
"}",
"// \"bottom right\" point shifts on either change",
"points",
"[",
"4",
"]",
"+=",
"dx",
";",
"points",
"[",
"5",
"]",
"+=",
"dy",
";",
"}"
] |
The default behavior is to match the hitbox to the entity. This function will change the hitbox when a "Resize" event triggers.
|
[
"The",
"default",
"behavior",
"is",
"to",
"match",
"the",
"hitbox",
"to",
"the",
"entity",
".",
"This",
"function",
"will",
"change",
"the",
"hitbox",
"when",
"a",
"Resize",
"event",
"triggers",
"."
] |
f3982baa51af24d4e8a14a3194fd3f0e92a2dcba
|
https://github.com/craftyjs/Crafty/blob/f3982baa51af24d4e8a14a3194fd3f0e92a2dcba/src/spatial/collision.js#L410-L446
|
|
12,276
|
craftyjs/Crafty
|
src/spatial/collision.js
|
function(component, collisionData) {
return function() {
var hitData = this.hit(component);
if (collisionData.occurring === true) {
if (hitData !== null) {
// The collision is still in progress
return;
}
collisionData.occurring = false;
this.trigger("HitOff", component);
} else if (hitData !== null) {
collisionData.occurring = true;
this.trigger("HitOn", hitData);
}
};
}
|
javascript
|
function(component, collisionData) {
return function() {
var hitData = this.hit(component);
if (collisionData.occurring === true) {
if (hitData !== null) {
// The collision is still in progress
return;
}
collisionData.occurring = false;
this.trigger("HitOff", component);
} else if (hitData !== null) {
collisionData.occurring = true;
this.trigger("HitOn", hitData);
}
};
}
|
[
"function",
"(",
"component",
",",
"collisionData",
")",
"{",
"return",
"function",
"(",
")",
"{",
"var",
"hitData",
"=",
"this",
".",
"hit",
"(",
"component",
")",
";",
"if",
"(",
"collisionData",
".",
"occurring",
"===",
"true",
")",
"{",
"if",
"(",
"hitData",
"!==",
"null",
")",
"{",
"// The collision is still in progress",
"return",
";",
"}",
"collisionData",
".",
"occurring",
"=",
"false",
";",
"this",
".",
"trigger",
"(",
"\"HitOff\"",
",",
"component",
")",
";",
"}",
"else",
"if",
"(",
"hitData",
"!==",
"null",
")",
"{",
"collisionData",
".",
"occurring",
"=",
"true",
";",
"this",
".",
"trigger",
"(",
"\"HitOn\"",
",",
"hitData",
")",
";",
"}",
"}",
";",
"}"
] |
This is a helper method for creating collisions handlers set up by `checkHits`. Do not call this directly.
@param {String} component - The name of the component for which this handler checks for collisions.
@param {Object} collisionData - Collision data object used to track collisions with the specified component.
@see .checkHits
|
[
"This",
"is",
"a",
"helper",
"method",
"for",
"creating",
"collisions",
"handlers",
"set",
"up",
"by",
"checkHits",
".",
"Do",
"not",
"call",
"this",
"directly",
"."
] |
f3982baa51af24d4e8a14a3194fd3f0e92a2dcba
|
https://github.com/craftyjs/Crafty/blob/f3982baa51af24d4e8a14a3194fd3f0e92a2dcba/src/spatial/collision.js#L646-L663
|
|
12,277
|
craftyjs/Crafty
|
src/graphics/color.js
|
function(e) {
if (!this._color) {
return;
}
if (e.type === "DOM") {
e.style.backgroundColor = this._color;
e.style.lineHeight = 0;
} else if (e.type === "canvas") {
e.ctx.fillStyle = this._color;
e.ctx.fillRect(e.pos._x, e.pos._y, e.pos._w, e.pos._h);
} else if (e.type === "webgl") {
e.program.draw(e, this);
}
}
|
javascript
|
function(e) {
if (!this._color) {
return;
}
if (e.type === "DOM") {
e.style.backgroundColor = this._color;
e.style.lineHeight = 0;
} else if (e.type === "canvas") {
e.ctx.fillStyle = this._color;
e.ctx.fillRect(e.pos._x, e.pos._y, e.pos._w, e.pos._h);
} else if (e.type === "webgl") {
e.program.draw(e, this);
}
}
|
[
"function",
"(",
"e",
")",
"{",
"if",
"(",
"!",
"this",
".",
"_color",
")",
"{",
"return",
";",
"}",
"if",
"(",
"e",
".",
"type",
"===",
"\"DOM\"",
")",
"{",
"e",
".",
"style",
".",
"backgroundColor",
"=",
"this",
".",
"_color",
";",
"e",
".",
"style",
".",
"lineHeight",
"=",
"0",
";",
"}",
"else",
"if",
"(",
"e",
".",
"type",
"===",
"\"canvas\"",
")",
"{",
"e",
".",
"ctx",
".",
"fillStyle",
"=",
"this",
".",
"_color",
";",
"e",
".",
"ctx",
".",
"fillRect",
"(",
"e",
".",
"pos",
".",
"_x",
",",
"e",
".",
"pos",
".",
"_y",
",",
"e",
".",
"pos",
".",
"_w",
",",
"e",
".",
"pos",
".",
"_h",
")",
";",
"}",
"else",
"if",
"(",
"e",
".",
"type",
"===",
"\"webgl\"",
")",
"{",
"e",
".",
"program",
".",
"draw",
"(",
"e",
",",
"this",
")",
";",
"}",
"}"
] |
draw function for "Color"
|
[
"draw",
"function",
"for",
"Color"
] |
f3982baa51af24d4e8a14a3194fd3f0e92a2dcba
|
https://github.com/craftyjs/Crafty/blob/f3982baa51af24d4e8a14a3194fd3f0e92a2dcba/src/graphics/color.js#L230-L243
|
|
12,278
|
craftyjs/Crafty
|
src/inputs/touch.js
|
function(eventName, e) {
// trigger event on TouchSystem itself
this.trigger(eventName, e);
var identifier = e.identifier,
closest = e.target,
over = this.overs[identifier];
if (over) {
// if old TouchOver target wasn't null, send TouchOut
if (
(eventName === "TouchMove" && over !== closest) || // if TouchOver target changed
eventName === "TouchEnd" ||
eventName === "TouchCancel"
) {
// or TouchEnd occurred
e.eventName = "TouchOut";
e.target = over;
e.entity = over; // DEPRECATED: remove this in upcoming release
over.trigger("TouchOut", e);
e.eventName = eventName;
e.target = closest;
e.entity = closest; // DEPRECATED: remove this in upcoming release
// delete old over entity
delete this.overs[identifier];
}
}
// TODO: move routing of events in future to controls system, make it similar to KeyboardSystem
// try to find closest element that will also receive touch event, whatever the event is
if (closest) {
closest.trigger(eventName, e);
}
if (closest) {
// if new TouchOver target isn't null, send TouchOver
if (
eventName === "TouchStart" || // if TouchStart occurred
(eventName === "TouchMove" && over !== closest)
) {
// or TouchOver target changed
e.eventName = "TouchOver";
closest.trigger("TouchOver", e);
e.eventName = eventName;
// save new over entity
this.overs[identifier] = closest;
}
}
}
|
javascript
|
function(eventName, e) {
// trigger event on TouchSystem itself
this.trigger(eventName, e);
var identifier = e.identifier,
closest = e.target,
over = this.overs[identifier];
if (over) {
// if old TouchOver target wasn't null, send TouchOut
if (
(eventName === "TouchMove" && over !== closest) || // if TouchOver target changed
eventName === "TouchEnd" ||
eventName === "TouchCancel"
) {
// or TouchEnd occurred
e.eventName = "TouchOut";
e.target = over;
e.entity = over; // DEPRECATED: remove this in upcoming release
over.trigger("TouchOut", e);
e.eventName = eventName;
e.target = closest;
e.entity = closest; // DEPRECATED: remove this in upcoming release
// delete old over entity
delete this.overs[identifier];
}
}
// TODO: move routing of events in future to controls system, make it similar to KeyboardSystem
// try to find closest element that will also receive touch event, whatever the event is
if (closest) {
closest.trigger(eventName, e);
}
if (closest) {
// if new TouchOver target isn't null, send TouchOver
if (
eventName === "TouchStart" || // if TouchStart occurred
(eventName === "TouchMove" && over !== closest)
) {
// or TouchOver target changed
e.eventName = "TouchOver";
closest.trigger("TouchOver", e);
e.eventName = eventName;
// save new over entity
this.overs[identifier] = closest;
}
}
}
|
[
"function",
"(",
"eventName",
",",
"e",
")",
"{",
"// trigger event on TouchSystem itself",
"this",
".",
"trigger",
"(",
"eventName",
",",
"e",
")",
";",
"var",
"identifier",
"=",
"e",
".",
"identifier",
",",
"closest",
"=",
"e",
".",
"target",
",",
"over",
"=",
"this",
".",
"overs",
"[",
"identifier",
"]",
";",
"if",
"(",
"over",
")",
"{",
"// if old TouchOver target wasn't null, send TouchOut",
"if",
"(",
"(",
"eventName",
"===",
"\"TouchMove\"",
"&&",
"over",
"!==",
"closest",
")",
"||",
"// if TouchOver target changed",
"eventName",
"===",
"\"TouchEnd\"",
"||",
"eventName",
"===",
"\"TouchCancel\"",
")",
"{",
"// or TouchEnd occurred",
"e",
".",
"eventName",
"=",
"\"TouchOut\"",
";",
"e",
".",
"target",
"=",
"over",
";",
"e",
".",
"entity",
"=",
"over",
";",
"// DEPRECATED: remove this in upcoming release",
"over",
".",
"trigger",
"(",
"\"TouchOut\"",
",",
"e",
")",
";",
"e",
".",
"eventName",
"=",
"eventName",
";",
"e",
".",
"target",
"=",
"closest",
";",
"e",
".",
"entity",
"=",
"closest",
";",
"// DEPRECATED: remove this in upcoming release",
"// delete old over entity",
"delete",
"this",
".",
"overs",
"[",
"identifier",
"]",
";",
"}",
"}",
"// TODO: move routing of events in future to controls system, make it similar to KeyboardSystem",
"// try to find closest element that will also receive touch event, whatever the event is",
"if",
"(",
"closest",
")",
"{",
"closest",
".",
"trigger",
"(",
"eventName",
",",
"e",
")",
";",
"}",
"if",
"(",
"closest",
")",
"{",
"// if new TouchOver target isn't null, send TouchOver",
"if",
"(",
"eventName",
"===",
"\"TouchStart\"",
"||",
"// if TouchStart occurred",
"(",
"eventName",
"===",
"\"TouchMove\"",
"&&",
"over",
"!==",
"closest",
")",
")",
"{",
"// or TouchOver target changed",
"e",
".",
"eventName",
"=",
"\"TouchOver\"",
";",
"closest",
".",
"trigger",
"(",
"\"TouchOver\"",
",",
"e",
")",
";",
"e",
".",
"eventName",
"=",
"eventName",
";",
"// save new over entity",
"this",
".",
"overs",
"[",
"identifier",
"]",
"=",
"closest",
";",
"}",
"}",
"}"
] |
this method will be called by TouchState iff triggerTouch event was valid
|
[
"this",
"method",
"will",
"be",
"called",
"by",
"TouchState",
"iff",
"triggerTouch",
"event",
"was",
"valid"
] |
f3982baa51af24d4e8a14a3194fd3f0e92a2dcba
|
https://github.com/craftyjs/Crafty/blob/f3982baa51af24d4e8a14a3194fd3f0e92a2dcba/src/inputs/touch.js#L214-L266
|
|
12,279
|
andywer/webpack-blocks
|
packages/core/lib/env.js
|
env
|
function env(envName, configSetters) {
assertConfigSetters(configSetters)
const currentEnv = process.env.NODE_ENV || 'development'
if (currentEnv !== envName) {
return () => config => config
} else {
return group(configSetters)
}
}
|
javascript
|
function env(envName, configSetters) {
assertConfigSetters(configSetters)
const currentEnv = process.env.NODE_ENV || 'development'
if (currentEnv !== envName) {
return () => config => config
} else {
return group(configSetters)
}
}
|
[
"function",
"env",
"(",
"envName",
",",
"configSetters",
")",
"{",
"assertConfigSetters",
"(",
"configSetters",
")",
"const",
"currentEnv",
"=",
"process",
".",
"env",
".",
"NODE_ENV",
"||",
"'development'",
"if",
"(",
"currentEnv",
"!==",
"envName",
")",
"{",
"return",
"(",
")",
"=>",
"config",
"=>",
"config",
"}",
"else",
"{",
"return",
"group",
"(",
"configSetters",
")",
"}",
"}"
] |
Applies an array of webpack blocks only if `process.env.NODE_ENV` matches the
given `envName`. If no `NODE_ENV` is set, it will be treated as 'development'.
@param {string} envName Environment name like 'development', 'production' or 'testing'.
@param {Function[]} configSetters Array of functions as returned by webpack blocks.
@return {Function}
|
[
"Applies",
"an",
"array",
"of",
"webpack",
"blocks",
"only",
"if",
"process",
".",
"env",
".",
"NODE_ENV",
"matches",
"the",
"given",
"envName",
".",
"If",
"no",
"NODE_ENV",
"is",
"set",
"it",
"will",
"be",
"treated",
"as",
"development",
"."
] |
dca0f219a6551b727494a53e043f87694422a546
|
https://github.com/andywer/webpack-blocks/blob/dca0f219a6551b727494a53e043f87694422a546/packages/core/lib/env.js#L14-L24
|
12,280
|
andywer/webpack-blocks
|
packages/core/lib/when.js
|
when
|
function when(condition, configSetters) {
assertConfigSetters(configSetters)
if (condition) {
return group(configSetters)
} else {
return () => config => config
}
}
|
javascript
|
function when(condition, configSetters) {
assertConfigSetters(configSetters)
if (condition) {
return group(configSetters)
} else {
return () => config => config
}
}
|
[
"function",
"when",
"(",
"condition",
",",
"configSetters",
")",
"{",
"assertConfigSetters",
"(",
"configSetters",
")",
"if",
"(",
"condition",
")",
"{",
"return",
"group",
"(",
"configSetters",
")",
"}",
"else",
"{",
"return",
"(",
")",
"=>",
"config",
"=>",
"config",
"}",
"}"
] |
Applies an array of webpack blocks only if `condition` is true.
@param {boolean} condition Condition to test
@param {Function[]} configSetters Array of functions as returned by webpack blocks.
@return {Function}
|
[
"Applies",
"an",
"array",
"of",
"webpack",
"blocks",
"only",
"if",
"condition",
"is",
"true",
"."
] |
dca0f219a6551b727494a53e043f87694422a546
|
https://github.com/andywer/webpack-blocks/blob/dca0f219a6551b727494a53e043f87694422a546/packages/core/lib/when.js#L13-L21
|
12,281
|
andywer/webpack-blocks
|
packages/webpack/lib/parseVersion.js
|
parseVersion
|
function parseVersion(versionString) {
const [release, prerelease] = versionString.split('-')
const splitRelease = release.split('.').map(number => parseInt(number, 10))
return {
major: splitRelease[0],
minor: splitRelease[1],
patch: splitRelease[2],
prerelease: prerelease || '',
raw: versionString
}
}
|
javascript
|
function parseVersion(versionString) {
const [release, prerelease] = versionString.split('-')
const splitRelease = release.split('.').map(number => parseInt(number, 10))
return {
major: splitRelease[0],
minor: splitRelease[1],
patch: splitRelease[2],
prerelease: prerelease || '',
raw: versionString
}
}
|
[
"function",
"parseVersion",
"(",
"versionString",
")",
"{",
"const",
"[",
"release",
",",
"prerelease",
"]",
"=",
"versionString",
".",
"split",
"(",
"'-'",
")",
"const",
"splitRelease",
"=",
"release",
".",
"split",
"(",
"'.'",
")",
".",
"map",
"(",
"number",
"=>",
"parseInt",
"(",
"number",
",",
"10",
")",
")",
"return",
"{",
"major",
":",
"splitRelease",
"[",
"0",
"]",
",",
"minor",
":",
"splitRelease",
"[",
"1",
"]",
",",
"patch",
":",
"splitRelease",
"[",
"2",
"]",
",",
"prerelease",
":",
"prerelease",
"||",
"''",
",",
"raw",
":",
"versionString",
"}",
"}"
] |
Parse semver-compliant version string.
@param {string} versionString
@return {object} { major: number, minor: number, patch: number, prerelease: string, raw: string }
|
[
"Parse",
"semver",
"-",
"compliant",
"version",
"string",
"."
] |
dca0f219a6551b727494a53e043f87694422a546
|
https://github.com/andywer/webpack-blocks/blob/dca0f219a6551b727494a53e043f87694422a546/packages/webpack/lib/parseVersion.js#L9-L20
|
12,282
|
andywer/webpack-blocks
|
packages/webpack/lib/setEnv.js
|
setEnv
|
function setEnv(constants) {
const setter = context => prevConfig => {
context.setEnv = Object.assign({}, context.setEnv, toObject(constants))
return prevConfig
}
return Object.assign(setter, { post: addEnvironmentPlugin })
}
|
javascript
|
function setEnv(constants) {
const setter = context => prevConfig => {
context.setEnv = Object.assign({}, context.setEnv, toObject(constants))
return prevConfig
}
return Object.assign(setter, { post: addEnvironmentPlugin })
}
|
[
"function",
"setEnv",
"(",
"constants",
")",
"{",
"const",
"setter",
"=",
"context",
"=>",
"prevConfig",
"=>",
"{",
"context",
".",
"setEnv",
"=",
"Object",
".",
"assign",
"(",
"{",
"}",
",",
"context",
".",
"setEnv",
",",
"toObject",
"(",
"constants",
")",
")",
"return",
"prevConfig",
"}",
"return",
"Object",
".",
"assign",
"(",
"setter",
",",
"{",
"post",
":",
"addEnvironmentPlugin",
"}",
")",
"}"
] |
Replaces constants in your source code with values from `process.env`
using the `webpack.EnvironmentPlugin`.
Using `setEnv` multiple times results in a single
EnvironmentPlugin instance configured to do all the replacements.
@param {string[]|object} constants
@return {Function}
|
[
"Replaces",
"constants",
"in",
"your",
"source",
"code",
"with",
"values",
"from",
"process",
".",
"env",
"using",
"the",
"webpack",
".",
"EnvironmentPlugin",
"."
] |
dca0f219a6551b727494a53e043f87694422a546
|
https://github.com/andywer/webpack-blocks/blob/dca0f219a6551b727494a53e043f87694422a546/packages/webpack/lib/setEnv.js#L13-L20
|
12,283
|
andywer/webpack-blocks
|
packages/core/lib/group.js
|
group
|
function group(configSetters) {
assertConfigSetters(configSetters)
const pre = getHooks(configSetters, 'pre')
const post = getHooks(configSetters, 'post')
const groupBlock = context => config => invokeConfigSetters(configSetters, context, config)
return Object.assign(groupBlock, { pre, post })
}
|
javascript
|
function group(configSetters) {
assertConfigSetters(configSetters)
const pre = getHooks(configSetters, 'pre')
const post = getHooks(configSetters, 'post')
const groupBlock = context => config => invokeConfigSetters(configSetters, context, config)
return Object.assign(groupBlock, { pre, post })
}
|
[
"function",
"group",
"(",
"configSetters",
")",
"{",
"assertConfigSetters",
"(",
"configSetters",
")",
"const",
"pre",
"=",
"getHooks",
"(",
"configSetters",
",",
"'pre'",
")",
"const",
"post",
"=",
"getHooks",
"(",
"configSetters",
",",
"'post'",
")",
"const",
"groupBlock",
"=",
"context",
"=>",
"config",
"=>",
"invokeConfigSetters",
"(",
"configSetters",
",",
"context",
",",
"config",
")",
"return",
"Object",
".",
"assign",
"(",
"groupBlock",
",",
"{",
"pre",
",",
"post",
"}",
")",
"}"
] |
Combines an array of blocks to a new joined block. Running this single block
has the same effect as running all source blocks.
@param {Function[]} configSetters Array of functions as returned by webpack blocks.
@return {Function}
|
[
"Combines",
"an",
"array",
"of",
"blocks",
"to",
"a",
"new",
"joined",
"block",
".",
"Running",
"this",
"single",
"block",
"has",
"the",
"same",
"effect",
"as",
"running",
"all",
"source",
"blocks",
"."
] |
dca0f219a6551b727494a53e043f87694422a546
|
https://github.com/andywer/webpack-blocks/blob/dca0f219a6551b727494a53e043f87694422a546/packages/core/lib/group.js#L13-L22
|
12,284
|
andywer/webpack-blocks
|
packages/core/lib/configSetters.js
|
assertConfigSetters
|
function assertConfigSetters(configSetters) {
if (!Array.isArray(configSetters)) {
throw new Error(
`Expected parameter 'configSetters' to be an array of functions. Instead got ${configSetters}.`
)
}
if (!configSetters.every(_.isFunction)) {
const invalidElementIndex = configSetters.findIndex(setter => !_.isFunction(setter))
throw new Error(
`Expected parameter 'configSetters' to be an array of functions. ` +
`Element at index ${invalidElementIndex} is invalid: ${configSetters[invalidElementIndex]}.`
)
}
}
|
javascript
|
function assertConfigSetters(configSetters) {
if (!Array.isArray(configSetters)) {
throw new Error(
`Expected parameter 'configSetters' to be an array of functions. Instead got ${configSetters}.`
)
}
if (!configSetters.every(_.isFunction)) {
const invalidElementIndex = configSetters.findIndex(setter => !_.isFunction(setter))
throw new Error(
`Expected parameter 'configSetters' to be an array of functions. ` +
`Element at index ${invalidElementIndex} is invalid: ${configSetters[invalidElementIndex]}.`
)
}
}
|
[
"function",
"assertConfigSetters",
"(",
"configSetters",
")",
"{",
"if",
"(",
"!",
"Array",
".",
"isArray",
"(",
"configSetters",
")",
")",
"{",
"throw",
"new",
"Error",
"(",
"`",
"${",
"configSetters",
"}",
"`",
")",
"}",
"if",
"(",
"!",
"configSetters",
".",
"every",
"(",
"_",
".",
"isFunction",
")",
")",
"{",
"const",
"invalidElementIndex",
"=",
"configSetters",
".",
"findIndex",
"(",
"setter",
"=>",
"!",
"_",
".",
"isFunction",
"(",
"setter",
")",
")",
"throw",
"new",
"Error",
"(",
"`",
"`",
"+",
"`",
"${",
"invalidElementIndex",
"}",
"${",
"configSetters",
"[",
"invalidElementIndex",
"]",
"}",
"`",
")",
"}",
"}"
] |
Asserts that given param is an array of functions.
@param {Function[]} configSetters Array of functions as returned by webpack blocks.
|
[
"Asserts",
"that",
"given",
"param",
"is",
"an",
"array",
"of",
"functions",
"."
] |
dca0f219a6551b727494a53e043f87694422a546
|
https://github.com/andywer/webpack-blocks/blob/dca0f219a6551b727494a53e043f87694422a546/packages/core/lib/configSetters.js#L14-L27
|
12,285
|
andywer/webpack-blocks
|
packages/core/lib/createConfig.js
|
createConfig
|
function createConfig(initialContext, configSetters) {
if (!initialContext) {
throw new Error(`No initial context passed.`)
}
assertConfigSetters(configSetters)
const baseConfig = {
resolve: {
// Explicitly define default extensions, otherwise blocks will overwrite them instead of extending
extensions: ['.js', '.json']
},
// Less noisy than default settings
stats: {
children: false,
chunks: false,
modules: false,
reasons: false
},
module: {
rules: []
},
plugins: []
}
invokePreHooks(configSetters, initialContext)
const config = invokeConfigSetters(configSetters, initialContext, baseConfig)
const postProcessedConfig = invokePostHooks(configSetters, initialContext, config)
return postProcessedConfig
}
|
javascript
|
function createConfig(initialContext, configSetters) {
if (!initialContext) {
throw new Error(`No initial context passed.`)
}
assertConfigSetters(configSetters)
const baseConfig = {
resolve: {
// Explicitly define default extensions, otherwise blocks will overwrite them instead of extending
extensions: ['.js', '.json']
},
// Less noisy than default settings
stats: {
children: false,
chunks: false,
modules: false,
reasons: false
},
module: {
rules: []
},
plugins: []
}
invokePreHooks(configSetters, initialContext)
const config = invokeConfigSetters(configSetters, initialContext, baseConfig)
const postProcessedConfig = invokePostHooks(configSetters, initialContext, config)
return postProcessedConfig
}
|
[
"function",
"createConfig",
"(",
"initialContext",
",",
"configSetters",
")",
"{",
"if",
"(",
"!",
"initialContext",
")",
"{",
"throw",
"new",
"Error",
"(",
"`",
"`",
")",
"}",
"assertConfigSetters",
"(",
"configSetters",
")",
"const",
"baseConfig",
"=",
"{",
"resolve",
":",
"{",
"// Explicitly define default extensions, otherwise blocks will overwrite them instead of extending",
"extensions",
":",
"[",
"'.js'",
",",
"'.json'",
"]",
"}",
",",
"// Less noisy than default settings",
"stats",
":",
"{",
"children",
":",
"false",
",",
"chunks",
":",
"false",
",",
"modules",
":",
"false",
",",
"reasons",
":",
"false",
"}",
",",
"module",
":",
"{",
"rules",
":",
"[",
"]",
"}",
",",
"plugins",
":",
"[",
"]",
"}",
"invokePreHooks",
"(",
"configSetters",
",",
"initialContext",
")",
"const",
"config",
"=",
"invokeConfigSetters",
"(",
"configSetters",
",",
"initialContext",
",",
"baseConfig",
")",
"const",
"postProcessedConfig",
"=",
"invokePostHooks",
"(",
"configSetters",
",",
"initialContext",
",",
"config",
")",
"return",
"postProcessedConfig",
"}"
] |
Takes an array of webpack blocks and creates a webpack config out of them.
Each webpack block is a callback function which will be invoked to return a
partial webpack config. These partial configs are merged to create the
final, complete webpack config that will be returned.
@param {object} initialContext The blueprint for the initial context object.
@param {object} initialContext.webpack Webpack instance
@param {object} initialContext.webpackVersion Webpack version (`{ major, minor, ... }`)
@param {Function[]} configSetters Array of functions as returned by webpack blocks.
@return {object} Webpack config object.
|
[
"Takes",
"an",
"array",
"of",
"webpack",
"blocks",
"and",
"creates",
"a",
"webpack",
"config",
"out",
"of",
"them",
".",
"Each",
"webpack",
"block",
"is",
"a",
"callback",
"function",
"which",
"will",
"be",
"invoked",
"to",
"return",
"a",
"partial",
"webpack",
"config",
".",
"These",
"partial",
"configs",
"are",
"merged",
"to",
"create",
"the",
"final",
"complete",
"webpack",
"config",
"that",
"will",
"be",
"returned",
"."
] |
dca0f219a6551b727494a53e043f87694422a546
|
https://github.com/andywer/webpack-blocks/blob/dca0f219a6551b727494a53e043f87694422a546/packages/core/lib/createConfig.js#L18-L47
|
12,286
|
cyclosproject/ng-swagger-gen
|
ng-swagger-gen.js
|
ngSwaggerGen
|
function ngSwaggerGen(options) {
if (typeof options.swagger != 'string') {
console.error("Swagger file not specified in the 'swagger' option");
process.exit(1);
}
var globalTunnel = require('global-tunnel-ng');
globalTunnel.initialize();
$RefParser.bundle(options.swagger, { dereference: { circular: false } }).then(
data => {
doGenerate(data, options);
},
err => {
console.error(
`Error reading swagger location ${options.swagger}: ${err}`
);
}
).catch(function (error) {
console.error(`Error: ${error}`);
});
}
|
javascript
|
function ngSwaggerGen(options) {
if (typeof options.swagger != 'string') {
console.error("Swagger file not specified in the 'swagger' option");
process.exit(1);
}
var globalTunnel = require('global-tunnel-ng');
globalTunnel.initialize();
$RefParser.bundle(options.swagger, { dereference: { circular: false } }).then(
data => {
doGenerate(data, options);
},
err => {
console.error(
`Error reading swagger location ${options.swagger}: ${err}`
);
}
).catch(function (error) {
console.error(`Error: ${error}`);
});
}
|
[
"function",
"ngSwaggerGen",
"(",
"options",
")",
"{",
"if",
"(",
"typeof",
"options",
".",
"swagger",
"!=",
"'string'",
")",
"{",
"console",
".",
"error",
"(",
"\"Swagger file not specified in the 'swagger' option\"",
")",
";",
"process",
".",
"exit",
"(",
"1",
")",
";",
"}",
"var",
"globalTunnel",
"=",
"require",
"(",
"'global-tunnel-ng'",
")",
";",
"globalTunnel",
".",
"initialize",
"(",
")",
";",
"$RefParser",
".",
"bundle",
"(",
"options",
".",
"swagger",
",",
"{",
"dereference",
":",
"{",
"circular",
":",
"false",
"}",
"}",
")",
".",
"then",
"(",
"data",
"=>",
"{",
"doGenerate",
"(",
"data",
",",
"options",
")",
";",
"}",
",",
"err",
"=>",
"{",
"console",
".",
"error",
"(",
"`",
"${",
"options",
".",
"swagger",
"}",
"${",
"err",
"}",
"`",
")",
";",
"}",
")",
".",
"catch",
"(",
"function",
"(",
"error",
")",
"{",
"console",
".",
"error",
"(",
"`",
"${",
"error",
"}",
"`",
")",
";",
"}",
")",
";",
"}"
] |
Main generate function
|
[
"Main",
"generate",
"function"
] |
64fa7bab50a6ceb2b7ffd610498c97bc1377c9fb
|
https://github.com/cyclosproject/ng-swagger-gen/blob/64fa7bab50a6ceb2b7ffd610498c97bc1377c9fb/ng-swagger-gen.js#L14-L35
|
12,287
|
cyclosproject/ng-swagger-gen
|
ng-swagger-gen.js
|
function(template, model, file) {
var code = Mustache.render(template, model, templates)
.replace(/[^\S\r\n]+$/gm, '');
fs.writeFileSync(file, code, 'UTF-8');
console.info('Wrote ' + file);
}
|
javascript
|
function(template, model, file) {
var code = Mustache.render(template, model, templates)
.replace(/[^\S\r\n]+$/gm, '');
fs.writeFileSync(file, code, 'UTF-8');
console.info('Wrote ' + file);
}
|
[
"function",
"(",
"template",
",",
"model",
",",
"file",
")",
"{",
"var",
"code",
"=",
"Mustache",
".",
"render",
"(",
"template",
",",
"model",
",",
"templates",
")",
".",
"replace",
"(",
"/",
"[^\\S\\r\\n]+$",
"/",
"gm",
",",
"''",
")",
";",
"fs",
".",
"writeFileSync",
"(",
"file",
",",
"code",
",",
"'UTF-8'",
")",
";",
"console",
".",
"info",
"(",
"'Wrote '",
"+",
"file",
")",
";",
"}"
] |
Utility function to render a template and write it to a file
|
[
"Utility",
"function",
"to",
"render",
"a",
"template",
"and",
"write",
"it",
"to",
"a",
"file"
] |
64fa7bab50a6ceb2b7ffd610498c97bc1377c9fb
|
https://github.com/cyclosproject/ng-swagger-gen/blob/64fa7bab50a6ceb2b7ffd610498c97bc1377c9fb/ng-swagger-gen.js#L93-L98
|
|
12,288
|
cyclosproject/ng-swagger-gen
|
ng-swagger-gen.js
|
applyTagFilter
|
function applyTagFilter(models, services, options) {
var i;
// Normalize the included tag names
const includeTags = options.includeTags;
var included = null;
if (includeTags && includeTags.length > 0) {
included = [];
for (i = 0; i < includeTags.length; i++) {
included.push(tagName(includeTags[i], options));
}
}
// Normalize the excluded tag names
const excludeTags = options.excludeTags;
var excluded = null;
if (excludeTags && excludeTags.length > 0) {
excluded = [];
for (i = 0; i < excludeTags.length; i++) {
excluded.push(tagName(excludeTags[i], options));
}
}
// Filter out the unused models
var ignoreUnusedModels = options.ignoreUnusedModels !== false;
var usedModels = new Set();
const addToUsed = (dep) => usedModels.add(dep);
for (var serviceName in services) {
var include =
(!included || included.indexOf(serviceName) >= 0) &&
(!excluded || excluded.indexOf(serviceName) < 0);
if (!include) {
// This service is skipped - remove it
console.info(
'Ignoring service ' + serviceName + ' because it was not included'
);
delete services[serviceName];
} else if (ignoreUnusedModels) {
// Collect the models used by this service
var service = services[serviceName];
service.serviceDependencies.forEach(addToUsed);
service.serviceErrorDependencies.forEach(addToUsed);
}
}
if (ignoreUnusedModels) {
// Collect the model dependencies of models, so unused can be removed
var allDependencies = new Set();
usedModels.forEach(dep =>
collectDependencies(allDependencies, dep, models)
);
// Remove all models that are unused
for (var modelName in models) {
var model = models[modelName];
if (!allDependencies.has(model.modelClass)) {
// This model is not used - remove it
console.info(
'Ignoring model ' +
modelName +
' because it was not used by any service'
);
delete models[modelName];
}
}
}
}
|
javascript
|
function applyTagFilter(models, services, options) {
var i;
// Normalize the included tag names
const includeTags = options.includeTags;
var included = null;
if (includeTags && includeTags.length > 0) {
included = [];
for (i = 0; i < includeTags.length; i++) {
included.push(tagName(includeTags[i], options));
}
}
// Normalize the excluded tag names
const excludeTags = options.excludeTags;
var excluded = null;
if (excludeTags && excludeTags.length > 0) {
excluded = [];
for (i = 0; i < excludeTags.length; i++) {
excluded.push(tagName(excludeTags[i], options));
}
}
// Filter out the unused models
var ignoreUnusedModels = options.ignoreUnusedModels !== false;
var usedModels = new Set();
const addToUsed = (dep) => usedModels.add(dep);
for (var serviceName in services) {
var include =
(!included || included.indexOf(serviceName) >= 0) &&
(!excluded || excluded.indexOf(serviceName) < 0);
if (!include) {
// This service is skipped - remove it
console.info(
'Ignoring service ' + serviceName + ' because it was not included'
);
delete services[serviceName];
} else if (ignoreUnusedModels) {
// Collect the models used by this service
var service = services[serviceName];
service.serviceDependencies.forEach(addToUsed);
service.serviceErrorDependencies.forEach(addToUsed);
}
}
if (ignoreUnusedModels) {
// Collect the model dependencies of models, so unused can be removed
var allDependencies = new Set();
usedModels.forEach(dep =>
collectDependencies(allDependencies, dep, models)
);
// Remove all models that are unused
for (var modelName in models) {
var model = models[modelName];
if (!allDependencies.has(model.modelClass)) {
// This model is not used - remove it
console.info(
'Ignoring model ' +
modelName +
' because it was not used by any service'
);
delete models[modelName];
}
}
}
}
|
[
"function",
"applyTagFilter",
"(",
"models",
",",
"services",
",",
"options",
")",
"{",
"var",
"i",
";",
"// Normalize the included tag names",
"const",
"includeTags",
"=",
"options",
".",
"includeTags",
";",
"var",
"included",
"=",
"null",
";",
"if",
"(",
"includeTags",
"&&",
"includeTags",
".",
"length",
">",
"0",
")",
"{",
"included",
"=",
"[",
"]",
";",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"includeTags",
".",
"length",
";",
"i",
"++",
")",
"{",
"included",
".",
"push",
"(",
"tagName",
"(",
"includeTags",
"[",
"i",
"]",
",",
"options",
")",
")",
";",
"}",
"}",
"// Normalize the excluded tag names",
"const",
"excludeTags",
"=",
"options",
".",
"excludeTags",
";",
"var",
"excluded",
"=",
"null",
";",
"if",
"(",
"excludeTags",
"&&",
"excludeTags",
".",
"length",
">",
"0",
")",
"{",
"excluded",
"=",
"[",
"]",
";",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"excludeTags",
".",
"length",
";",
"i",
"++",
")",
"{",
"excluded",
".",
"push",
"(",
"tagName",
"(",
"excludeTags",
"[",
"i",
"]",
",",
"options",
")",
")",
";",
"}",
"}",
"// Filter out the unused models",
"var",
"ignoreUnusedModels",
"=",
"options",
".",
"ignoreUnusedModels",
"!==",
"false",
";",
"var",
"usedModels",
"=",
"new",
"Set",
"(",
")",
";",
"const",
"addToUsed",
"=",
"(",
"dep",
")",
"=>",
"usedModels",
".",
"add",
"(",
"dep",
")",
";",
"for",
"(",
"var",
"serviceName",
"in",
"services",
")",
"{",
"var",
"include",
"=",
"(",
"!",
"included",
"||",
"included",
".",
"indexOf",
"(",
"serviceName",
")",
">=",
"0",
")",
"&&",
"(",
"!",
"excluded",
"||",
"excluded",
".",
"indexOf",
"(",
"serviceName",
")",
"<",
"0",
")",
";",
"if",
"(",
"!",
"include",
")",
"{",
"// This service is skipped - remove it",
"console",
".",
"info",
"(",
"'Ignoring service '",
"+",
"serviceName",
"+",
"' because it was not included'",
")",
";",
"delete",
"services",
"[",
"serviceName",
"]",
";",
"}",
"else",
"if",
"(",
"ignoreUnusedModels",
")",
"{",
"// Collect the models used by this service",
"var",
"service",
"=",
"services",
"[",
"serviceName",
"]",
";",
"service",
".",
"serviceDependencies",
".",
"forEach",
"(",
"addToUsed",
")",
";",
"service",
".",
"serviceErrorDependencies",
".",
"forEach",
"(",
"addToUsed",
")",
";",
"}",
"}",
"if",
"(",
"ignoreUnusedModels",
")",
"{",
"// Collect the model dependencies of models, so unused can be removed",
"var",
"allDependencies",
"=",
"new",
"Set",
"(",
")",
";",
"usedModels",
".",
"forEach",
"(",
"dep",
"=>",
"collectDependencies",
"(",
"allDependencies",
",",
"dep",
",",
"models",
")",
")",
";",
"// Remove all models that are unused",
"for",
"(",
"var",
"modelName",
"in",
"models",
")",
"{",
"var",
"model",
"=",
"models",
"[",
"modelName",
"]",
";",
"if",
"(",
"!",
"allDependencies",
".",
"has",
"(",
"model",
".",
"modelClass",
")",
")",
"{",
"// This model is not used - remove it",
"console",
".",
"info",
"(",
"'Ignoring model '",
"+",
"modelName",
"+",
"' because it was not used by any service'",
")",
";",
"delete",
"models",
"[",
"modelName",
"]",
";",
"}",
"}",
"}",
"}"
] |
Applies a filter over the given services, keeping only the specific tags.
Also optionally removes any unused models, even services are filtered.
|
[
"Applies",
"a",
"filter",
"over",
"the",
"given",
"services",
"keeping",
"only",
"the",
"specific",
"tags",
".",
"Also",
"optionally",
"removes",
"any",
"unused",
"models",
"even",
"services",
"are",
"filtered",
"."
] |
64fa7bab50a6ceb2b7ffd610498c97bc1377c9fb
|
https://github.com/cyclosproject/ng-swagger-gen/blob/64fa7bab50a6ceb2b7ffd610498c97bc1377c9fb/ng-swagger-gen.js#L272-L335
|
12,289
|
cyclosproject/ng-swagger-gen
|
ng-swagger-gen.js
|
collectDependencies
|
function collectDependencies(dependencies, model, models) {
if (!model || dependencies.has(model.modelClass)) {
return;
}
dependencies.add(model.modelClass);
if (model.modelDependencies) {
model.modelDependencies.forEach((dep) =>
collectDependencies(dependencies, dep, models)
);
}
}
|
javascript
|
function collectDependencies(dependencies, model, models) {
if (!model || dependencies.has(model.modelClass)) {
return;
}
dependencies.add(model.modelClass);
if (model.modelDependencies) {
model.modelDependencies.forEach((dep) =>
collectDependencies(dependencies, dep, models)
);
}
}
|
[
"function",
"collectDependencies",
"(",
"dependencies",
",",
"model",
",",
"models",
")",
"{",
"if",
"(",
"!",
"model",
"||",
"dependencies",
".",
"has",
"(",
"model",
".",
"modelClass",
")",
")",
"{",
"return",
";",
"}",
"dependencies",
".",
"add",
"(",
"model",
".",
"modelClass",
")",
";",
"if",
"(",
"model",
".",
"modelDependencies",
")",
"{",
"model",
".",
"modelDependencies",
".",
"forEach",
"(",
"(",
"dep",
")",
"=>",
"collectDependencies",
"(",
"dependencies",
",",
"dep",
",",
"models",
")",
")",
";",
"}",
"}"
] |
Collects on the given dependencies set all dependencies of the given model
|
[
"Collects",
"on",
"the",
"given",
"dependencies",
"set",
"all",
"dependencies",
"of",
"the",
"given",
"model"
] |
64fa7bab50a6ceb2b7ffd610498c97bc1377c9fb
|
https://github.com/cyclosproject/ng-swagger-gen/blob/64fa7bab50a6ceb2b7ffd610498c97bc1377c9fb/ng-swagger-gen.js#L340-L350
|
12,290
|
cyclosproject/ng-swagger-gen
|
ng-swagger-gen.js
|
toFileName
|
function toFileName(typeName) {
var result = '';
var wasLower = false;
for (var i = 0; i < typeName.length; i++) {
var c = typeName.charAt(i);
var isLower = /[a-z]/.test(c);
if (!isLower && wasLower) {
result += '-';
}
result += c.toLowerCase();
wasLower = isLower;
}
return result;
}
|
javascript
|
function toFileName(typeName) {
var result = '';
var wasLower = false;
for (var i = 0; i < typeName.length; i++) {
var c = typeName.charAt(i);
var isLower = /[a-z]/.test(c);
if (!isLower && wasLower) {
result += '-';
}
result += c.toLowerCase();
wasLower = isLower;
}
return result;
}
|
[
"function",
"toFileName",
"(",
"typeName",
")",
"{",
"var",
"result",
"=",
"''",
";",
"var",
"wasLower",
"=",
"false",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"typeName",
".",
"length",
";",
"i",
"++",
")",
"{",
"var",
"c",
"=",
"typeName",
".",
"charAt",
"(",
"i",
")",
";",
"var",
"isLower",
"=",
"/",
"[a-z]",
"/",
".",
"test",
"(",
"c",
")",
";",
"if",
"(",
"!",
"isLower",
"&&",
"wasLower",
")",
"{",
"result",
"+=",
"'-'",
";",
"}",
"result",
"+=",
"c",
".",
"toLowerCase",
"(",
")",
";",
"wasLower",
"=",
"isLower",
";",
"}",
"return",
"result",
";",
"}"
] |
Converts a given type name into a TS file name
|
[
"Converts",
"a",
"given",
"type",
"name",
"into",
"a",
"TS",
"file",
"name"
] |
64fa7bab50a6ceb2b7ffd610498c97bc1377c9fb
|
https://github.com/cyclosproject/ng-swagger-gen/blob/64fa7bab50a6ceb2b7ffd610498c97bc1377c9fb/ng-swagger-gen.js#L384-L397
|
12,291
|
cyclosproject/ng-swagger-gen
|
ng-swagger-gen.js
|
toClassName
|
function toClassName(name) {
var result = '';
var upNext = false;
for (var i = 0; i < name.length; i++) {
var c = name.charAt(i);
var valid = /[\w]/.test(c);
if (!valid) {
upNext = true;
} else if (upNext) {
result += c.toUpperCase();
upNext = false;
} else if (result === '') {
result = c.toUpperCase();
} else {
result += c;
}
}
if (/[0-9]/.test(result.charAt(0))) {
result = '_' + result;
}
return result;
}
|
javascript
|
function toClassName(name) {
var result = '';
var upNext = false;
for (var i = 0; i < name.length; i++) {
var c = name.charAt(i);
var valid = /[\w]/.test(c);
if (!valid) {
upNext = true;
} else if (upNext) {
result += c.toUpperCase();
upNext = false;
} else if (result === '') {
result = c.toUpperCase();
} else {
result += c;
}
}
if (/[0-9]/.test(result.charAt(0))) {
result = '_' + result;
}
return result;
}
|
[
"function",
"toClassName",
"(",
"name",
")",
"{",
"var",
"result",
"=",
"''",
";",
"var",
"upNext",
"=",
"false",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"name",
".",
"length",
";",
"i",
"++",
")",
"{",
"var",
"c",
"=",
"name",
".",
"charAt",
"(",
"i",
")",
";",
"var",
"valid",
"=",
"/",
"[\\w]",
"/",
".",
"test",
"(",
"c",
")",
";",
"if",
"(",
"!",
"valid",
")",
"{",
"upNext",
"=",
"true",
";",
"}",
"else",
"if",
"(",
"upNext",
")",
"{",
"result",
"+=",
"c",
".",
"toUpperCase",
"(",
")",
";",
"upNext",
"=",
"false",
";",
"}",
"else",
"if",
"(",
"result",
"===",
"''",
")",
"{",
"result",
"=",
"c",
".",
"toUpperCase",
"(",
")",
";",
"}",
"else",
"{",
"result",
"+=",
"c",
";",
"}",
"}",
"if",
"(",
"/",
"[0-9]",
"/",
".",
"test",
"(",
"result",
".",
"charAt",
"(",
"0",
")",
")",
")",
"{",
"result",
"=",
"'_'",
"+",
"result",
";",
"}",
"return",
"result",
";",
"}"
] |
Converts a given name into a valid class name
|
[
"Converts",
"a",
"given",
"name",
"into",
"a",
"valid",
"class",
"name"
] |
64fa7bab50a6ceb2b7ffd610498c97bc1377c9fb
|
https://github.com/cyclosproject/ng-swagger-gen/blob/64fa7bab50a6ceb2b7ffd610498c97bc1377c9fb/ng-swagger-gen.js#L402-L423
|
12,292
|
cyclosproject/ng-swagger-gen
|
ng-swagger-gen.js
|
simpleRef
|
function simpleRef(ref) {
if (!ref) {
return null;
}
var index = ref.lastIndexOf('/');
if (index >= 0) {
ref = ref.substr(index + 1);
}
return toClassName(ref);
}
|
javascript
|
function simpleRef(ref) {
if (!ref) {
return null;
}
var index = ref.lastIndexOf('/');
if (index >= 0) {
ref = ref.substr(index + 1);
}
return toClassName(ref);
}
|
[
"function",
"simpleRef",
"(",
"ref",
")",
"{",
"if",
"(",
"!",
"ref",
")",
"{",
"return",
"null",
";",
"}",
"var",
"index",
"=",
"ref",
".",
"lastIndexOf",
"(",
"'/'",
")",
";",
"if",
"(",
"index",
">=",
"0",
")",
"{",
"ref",
"=",
"ref",
".",
"substr",
"(",
"index",
"+",
"1",
")",
";",
"}",
"return",
"toClassName",
"(",
"ref",
")",
";",
"}"
] |
Resolves the simple reference name from a qualified reference
|
[
"Resolves",
"the",
"simple",
"reference",
"name",
"from",
"a",
"qualified",
"reference"
] |
64fa7bab50a6ceb2b7ffd610498c97bc1377c9fb
|
https://github.com/cyclosproject/ng-swagger-gen/blob/64fa7bab50a6ceb2b7ffd610498c97bc1377c9fb/ng-swagger-gen.js#L436-L445
|
12,293
|
cyclosproject/ng-swagger-gen
|
ng-swagger-gen.js
|
toEnumName
|
function toEnumName(value) {
var result = '';
var wasLower = false;
for (var i = 0; i < value.length; i++) {
var c = value.charAt(i);
var isLower = /[a-z]/.test(c);
if (!isLower && wasLower) {
result += '_';
}
result += c.toUpperCase();
wasLower = isLower;
}
if (!isNaN(value[0])) {
result = '_' + result;
}
result = result.replace(/[^\w]/g, '_');
result = result.replace(/_+/g, '_');
return result;
}
|
javascript
|
function toEnumName(value) {
var result = '';
var wasLower = false;
for (var i = 0; i < value.length; i++) {
var c = value.charAt(i);
var isLower = /[a-z]/.test(c);
if (!isLower && wasLower) {
result += '_';
}
result += c.toUpperCase();
wasLower = isLower;
}
if (!isNaN(value[0])) {
result = '_' + result;
}
result = result.replace(/[^\w]/g, '_');
result = result.replace(/_+/g, '_');
return result;
}
|
[
"function",
"toEnumName",
"(",
"value",
")",
"{",
"var",
"result",
"=",
"''",
";",
"var",
"wasLower",
"=",
"false",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"value",
".",
"length",
";",
"i",
"++",
")",
"{",
"var",
"c",
"=",
"value",
".",
"charAt",
"(",
"i",
")",
";",
"var",
"isLower",
"=",
"/",
"[a-z]",
"/",
".",
"test",
"(",
"c",
")",
";",
"if",
"(",
"!",
"isLower",
"&&",
"wasLower",
")",
"{",
"result",
"+=",
"'_'",
";",
"}",
"result",
"+=",
"c",
".",
"toUpperCase",
"(",
")",
";",
"wasLower",
"=",
"isLower",
";",
"}",
"if",
"(",
"!",
"isNaN",
"(",
"value",
"[",
"0",
"]",
")",
")",
"{",
"result",
"=",
"'_'",
"+",
"result",
";",
"}",
"result",
"=",
"result",
".",
"replace",
"(",
"/",
"[^\\w]",
"/",
"g",
",",
"'_'",
")",
";",
"result",
"=",
"result",
".",
"replace",
"(",
"/",
"_+",
"/",
"g",
",",
"'_'",
")",
";",
"return",
"result",
";",
"}"
] |
Converts a given enum value into the enum name
|
[
"Converts",
"a",
"given",
"enum",
"value",
"into",
"the",
"enum",
"name"
] |
64fa7bab50a6ceb2b7ffd610498c97bc1377c9fb
|
https://github.com/cyclosproject/ng-swagger-gen/blob/64fa7bab50a6ceb2b7ffd610498c97bc1377c9fb/ng-swagger-gen.js#L450-L468
|
12,294
|
cyclosproject/ng-swagger-gen
|
ng-swagger-gen.js
|
toComments
|
function toComments(text, level) {
var indent = '';
var i;
for (i = 0; i < level; i++) {
indent += ' ';
}
if (text == null || text.length === 0) {
return indent;
}
const lines = text.trim().split('\n');
var result = '\n' + indent + '/**\n';
lines.forEach(line => {
result += indent + ' *' + (line === '' ? '' : ' ' + line) + '\n';
});
result += indent + ' */\n' + indent;
return result;
}
|
javascript
|
function toComments(text, level) {
var indent = '';
var i;
for (i = 0; i < level; i++) {
indent += ' ';
}
if (text == null || text.length === 0) {
return indent;
}
const lines = text.trim().split('\n');
var result = '\n' + indent + '/**\n';
lines.forEach(line => {
result += indent + ' *' + (line === '' ? '' : ' ' + line) + '\n';
});
result += indent + ' */\n' + indent;
return result;
}
|
[
"function",
"toComments",
"(",
"text",
",",
"level",
")",
"{",
"var",
"indent",
"=",
"''",
";",
"var",
"i",
";",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"level",
";",
"i",
"++",
")",
"{",
"indent",
"+=",
"' '",
";",
"}",
"if",
"(",
"text",
"==",
"null",
"||",
"text",
".",
"length",
"===",
"0",
")",
"{",
"return",
"indent",
";",
"}",
"const",
"lines",
"=",
"text",
".",
"trim",
"(",
")",
".",
"split",
"(",
"'\\n'",
")",
";",
"var",
"result",
"=",
"'\\n'",
"+",
"indent",
"+",
"'/**\\n'",
";",
"lines",
".",
"forEach",
"(",
"line",
"=>",
"{",
"result",
"+=",
"indent",
"+",
"' *'",
"+",
"(",
"line",
"===",
"''",
"?",
"''",
":",
"' '",
"+",
"line",
")",
"+",
"'\\n'",
";",
"}",
")",
";",
"result",
"+=",
"indent",
"+",
"' */\\n'",
"+",
"indent",
";",
"return",
"result",
";",
"}"
] |
Returns a multi-line comment for the given text
|
[
"Returns",
"a",
"multi",
"-",
"line",
"comment",
"for",
"the",
"given",
"text"
] |
64fa7bab50a6ceb2b7ffd610498c97bc1377c9fb
|
https://github.com/cyclosproject/ng-swagger-gen/blob/64fa7bab50a6ceb2b7ffd610498c97bc1377c9fb/ng-swagger-gen.js#L473-L489
|
12,295
|
cyclosproject/ng-swagger-gen
|
ng-swagger-gen.js
|
mergeTypes
|
function mergeTypes(...types) {
let allTypes = [];
types.forEach(type => {
(type.allTypes || [type]).forEach(type => {
if (allTypes.indexOf(type) < 0) allTypes.push(type);
});
});
return allTypes;
}
|
javascript
|
function mergeTypes(...types) {
let allTypes = [];
types.forEach(type => {
(type.allTypes || [type]).forEach(type => {
if (allTypes.indexOf(type) < 0) allTypes.push(type);
});
});
return allTypes;
}
|
[
"function",
"mergeTypes",
"(",
"...",
"types",
")",
"{",
"let",
"allTypes",
"=",
"[",
"]",
";",
"types",
".",
"forEach",
"(",
"type",
"=>",
"{",
"(",
"type",
".",
"allTypes",
"||",
"[",
"type",
"]",
")",
".",
"forEach",
"(",
"type",
"=>",
"{",
"if",
"(",
"allTypes",
".",
"indexOf",
"(",
"type",
")",
"<",
"0",
")",
"allTypes",
".",
"push",
"(",
"type",
")",
";",
"}",
")",
";",
"}",
")",
";",
"return",
"allTypes",
";",
"}"
] |
Combine dependencies of multiple types.
@param types
@return {Array}
|
[
"Combine",
"dependencies",
"of",
"multiple",
"types",
"."
] |
64fa7bab50a6ceb2b7ffd610498c97bc1377c9fb
|
https://github.com/cyclosproject/ng-swagger-gen/blob/64fa7bab50a6ceb2b7ffd610498c97bc1377c9fb/ng-swagger-gen.js#L724-L732
|
12,296
|
cyclosproject/ng-swagger-gen
|
ng-swagger-gen.js
|
processProperties
|
function processProperties(swagger, properties, requiredProperties) {
var result = {};
for (var name in properties) {
var property = properties[name];
var descriptor = {
propertyName: name.indexOf('-') === -1 ? name : `"${name}"`,
propertyComments: toComments(property.description, 1),
propertyRequired: requiredProperties.indexOf(name) >= 0,
propertyType: propertyType(property),
};
result[name] = descriptor;
}
return result;
}
|
javascript
|
function processProperties(swagger, properties, requiredProperties) {
var result = {};
for (var name in properties) {
var property = properties[name];
var descriptor = {
propertyName: name.indexOf('-') === -1 ? name : `"${name}"`,
propertyComments: toComments(property.description, 1),
propertyRequired: requiredProperties.indexOf(name) >= 0,
propertyType: propertyType(property),
};
result[name] = descriptor;
}
return result;
}
|
[
"function",
"processProperties",
"(",
"swagger",
",",
"properties",
",",
"requiredProperties",
")",
"{",
"var",
"result",
"=",
"{",
"}",
";",
"for",
"(",
"var",
"name",
"in",
"properties",
")",
"{",
"var",
"property",
"=",
"properties",
"[",
"name",
"]",
";",
"var",
"descriptor",
"=",
"{",
"propertyName",
":",
"name",
".",
"indexOf",
"(",
"'-'",
")",
"===",
"-",
"1",
"?",
"name",
":",
"`",
"${",
"name",
"}",
"`",
",",
"propertyComments",
":",
"toComments",
"(",
"property",
".",
"description",
",",
"1",
")",
",",
"propertyRequired",
":",
"requiredProperties",
".",
"indexOf",
"(",
"name",
")",
">=",
"0",
",",
"propertyType",
":",
"propertyType",
"(",
"property",
")",
",",
"}",
";",
"result",
"[",
"name",
"]",
"=",
"descriptor",
";",
"}",
"return",
"result",
";",
"}"
] |
Process each property for the given properties object, returning an object
keyed by property name with simplified property types
|
[
"Process",
"each",
"property",
"for",
"the",
"given",
"properties",
"object",
"returning",
"an",
"object",
"keyed",
"by",
"property",
"name",
"with",
"simplified",
"property",
"types"
] |
64fa7bab50a6ceb2b7ffd610498c97bc1377c9fb
|
https://github.com/cyclosproject/ng-swagger-gen/blob/64fa7bab50a6ceb2b7ffd610498c97bc1377c9fb/ng-swagger-gen.js#L841-L854
|
12,297
|
cyclosproject/ng-swagger-gen
|
ng-swagger-gen.js
|
resolveRef
|
function resolveRef(swagger, ref) {
if (ref.indexOf('#/') != 0) {
console.error('Resolved references must start with #/. Current: ' + ref);
process.exit(1);
}
var parts = ref.substr(2).split('/');
var result = swagger;
for (var i = 0; i < parts.length; i++) {
var part = parts[i];
result = result[part];
}
return result === swagger ? {} : result;
}
|
javascript
|
function resolveRef(swagger, ref) {
if (ref.indexOf('#/') != 0) {
console.error('Resolved references must start with #/. Current: ' + ref);
process.exit(1);
}
var parts = ref.substr(2).split('/');
var result = swagger;
for (var i = 0; i < parts.length; i++) {
var part = parts[i];
result = result[part];
}
return result === swagger ? {} : result;
}
|
[
"function",
"resolveRef",
"(",
"swagger",
",",
"ref",
")",
"{",
"if",
"(",
"ref",
".",
"indexOf",
"(",
"'#/'",
")",
"!=",
"0",
")",
"{",
"console",
".",
"error",
"(",
"'Resolved references must start with #/. Current: '",
"+",
"ref",
")",
";",
"process",
".",
"exit",
"(",
"1",
")",
";",
"}",
"var",
"parts",
"=",
"ref",
".",
"substr",
"(",
"2",
")",
".",
"split",
"(",
"'/'",
")",
";",
"var",
"result",
"=",
"swagger",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"parts",
".",
"length",
";",
"i",
"++",
")",
"{",
"var",
"part",
"=",
"parts",
"[",
"i",
"]",
";",
"result",
"=",
"result",
"[",
"part",
"]",
";",
"}",
"return",
"result",
"===",
"swagger",
"?",
"{",
"}",
":",
"result",
";",
"}"
] |
Resolves a local reference in the given swagger file
|
[
"Resolves",
"a",
"local",
"reference",
"in",
"the",
"given",
"swagger",
"file"
] |
64fa7bab50a6ceb2b7ffd610498c97bc1377c9fb
|
https://github.com/cyclosproject/ng-swagger-gen/blob/64fa7bab50a6ceb2b7ffd610498c97bc1377c9fb/ng-swagger-gen.js#L859-L871
|
12,298
|
cyclosproject/ng-swagger-gen
|
ng-swagger-gen.js
|
toIdentifier
|
function toIdentifier(string) {
var result = '';
var wasSep = false;
for (var i = 0; i < string.length; i++) {
var c = string.charAt(i);
if (/[a-zA-Z0-9]/.test(c)) {
if (wasSep) {
c = c.toUpperCase();
wasSep = false;
}
result += c;
} else {
wasSep = true;
}
}
return result;
}
|
javascript
|
function toIdentifier(string) {
var result = '';
var wasSep = false;
for (var i = 0; i < string.length; i++) {
var c = string.charAt(i);
if (/[a-zA-Z0-9]/.test(c)) {
if (wasSep) {
c = c.toUpperCase();
wasSep = false;
}
result += c;
} else {
wasSep = true;
}
}
return result;
}
|
[
"function",
"toIdentifier",
"(",
"string",
")",
"{",
"var",
"result",
"=",
"''",
";",
"var",
"wasSep",
"=",
"false",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"string",
".",
"length",
";",
"i",
"++",
")",
"{",
"var",
"c",
"=",
"string",
".",
"charAt",
"(",
"i",
")",
";",
"if",
"(",
"/",
"[a-zA-Z0-9]",
"/",
".",
"test",
"(",
"c",
")",
")",
"{",
"if",
"(",
"wasSep",
")",
"{",
"c",
"=",
"c",
".",
"toUpperCase",
"(",
")",
";",
"wasSep",
"=",
"false",
";",
"}",
"result",
"+=",
"c",
";",
"}",
"else",
"{",
"wasSep",
"=",
"true",
";",
"}",
"}",
"return",
"result",
";",
"}"
] |
Transforms the given string into a valid identifier
|
[
"Transforms",
"the",
"given",
"string",
"into",
"a",
"valid",
"identifier"
] |
64fa7bab50a6ceb2b7ffd610498c97bc1377c9fb
|
https://github.com/cyclosproject/ng-swagger-gen/blob/64fa7bab50a6ceb2b7ffd610498c97bc1377c9fb/ng-swagger-gen.js#L931-L947
|
12,299
|
cyclosproject/ng-swagger-gen
|
ng-swagger-gen.js
|
tagName
|
function tagName(tag, options) {
if (tag == null || tag === '') {
tag = options.defaultTag || 'Api';
}
tag = toIdentifier(tag);
return tag.charAt(0).toUpperCase() + (tag.length == 1 ? '' : tag.substr(1));
}
|
javascript
|
function tagName(tag, options) {
if (tag == null || tag === '') {
tag = options.defaultTag || 'Api';
}
tag = toIdentifier(tag);
return tag.charAt(0).toUpperCase() + (tag.length == 1 ? '' : tag.substr(1));
}
|
[
"function",
"tagName",
"(",
"tag",
",",
"options",
")",
"{",
"if",
"(",
"tag",
"==",
"null",
"||",
"tag",
"===",
"''",
")",
"{",
"tag",
"=",
"options",
".",
"defaultTag",
"||",
"'Api'",
";",
"}",
"tag",
"=",
"toIdentifier",
"(",
"tag",
")",
";",
"return",
"tag",
".",
"charAt",
"(",
"0",
")",
".",
"toUpperCase",
"(",
")",
"+",
"(",
"tag",
".",
"length",
"==",
"1",
"?",
"''",
":",
"tag",
".",
"substr",
"(",
"1",
")",
")",
";",
"}"
] |
Normalizes the tag name. Actually, capitalizes the given name.
If the given tag is null, returns the default from options
|
[
"Normalizes",
"the",
"tag",
"name",
".",
"Actually",
"capitalizes",
"the",
"given",
"name",
".",
"If",
"the",
"given",
"tag",
"is",
"null",
"returns",
"the",
"default",
"from",
"options"
] |
64fa7bab50a6ceb2b7ffd610498c97bc1377c9fb
|
https://github.com/cyclosproject/ng-swagger-gen/blob/64fa7bab50a6ceb2b7ffd610498c97bc1377c9fb/ng-swagger-gen.js#L953-L959
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.