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
| partition
stringclasses 1
value |
---|---|---|---|---|---|---|---|---|---|---|---|
NetEase/pomelo
|
lib/connectors/siosocket.js
|
function(msgs){
var res = '[', msg;
for(var i=0, l=msgs.length; i<l; i++) {
if(i > 0) {
res += ',';
}
msg = msgs[i];
if(typeof msg === 'string') {
res += msg;
} else {
res += JSON.stringify(msg);
}
}
res += ']';
return res;
}
|
javascript
|
function(msgs){
var res = '[', msg;
for(var i=0, l=msgs.length; i<l; i++) {
if(i > 0) {
res += ',';
}
msg = msgs[i];
if(typeof msg === 'string') {
res += msg;
} else {
res += JSON.stringify(msg);
}
}
res += ']';
return res;
}
|
[
"function",
"(",
"msgs",
")",
"{",
"var",
"res",
"=",
"'['",
",",
"msg",
";",
"for",
"(",
"var",
"i",
"=",
"0",
",",
"l",
"=",
"msgs",
".",
"length",
";",
"i",
"<",
"l",
";",
"i",
"++",
")",
"{",
"if",
"(",
"i",
">",
"0",
")",
"{",
"res",
"+=",
"','",
";",
"}",
"msg",
"=",
"msgs",
"[",
"i",
"]",
";",
"if",
"(",
"typeof",
"msg",
"===",
"'string'",
")",
"{",
"res",
"+=",
"msg",
";",
"}",
"else",
"{",
"res",
"+=",
"JSON",
".",
"stringify",
"(",
"msg",
")",
";",
"}",
"}",
"res",
"+=",
"']'",
";",
"return",
"res",
";",
"}"
] |
Encode batch msg to client
|
[
"Encode",
"batch",
"msg",
"to",
"client"
] |
defcf019631ed399cc4dad932d3b028a04a039a4
|
https://github.com/NetEase/pomelo/blob/defcf019631ed399cc4dad932d3b028a04a039a4/lib/connectors/siosocket.js#L64-L79
|
train
|
|
NetEase/pomelo
|
lib/util/countDownLatch.js
|
function(count, opts, cb) {
this.count = count;
this.cb = cb;
var self = this;
if (opts.timeout) {
this.timerId = setTimeout(function() {
self.cb(true);
}, opts.timeout);
}
}
|
javascript
|
function(count, opts, cb) {
this.count = count;
this.cb = cb;
var self = this;
if (opts.timeout) {
this.timerId = setTimeout(function() {
self.cb(true);
}, opts.timeout);
}
}
|
[
"function",
"(",
"count",
",",
"opts",
",",
"cb",
")",
"{",
"this",
".",
"count",
"=",
"count",
";",
"this",
".",
"cb",
"=",
"cb",
";",
"var",
"self",
"=",
"this",
";",
"if",
"(",
"opts",
".",
"timeout",
")",
"{",
"this",
".",
"timerId",
"=",
"setTimeout",
"(",
"function",
"(",
")",
"{",
"self",
".",
"cb",
"(",
"true",
")",
";",
"}",
",",
"opts",
".",
"timeout",
")",
";",
"}",
"}"
] |
Count down to zero or timeout and invoke cb finally.
|
[
"Count",
"down",
"to",
"zero",
"or",
"timeout",
"and",
"invoke",
"cb",
"finally",
"."
] |
defcf019631ed399cc4dad932d3b028a04a039a4
|
https://github.com/NetEase/pomelo/blob/defcf019631ed399cc4dad932d3b028a04a039a4/lib/util/countDownLatch.js#L6-L15
|
train
|
|
GeekyAnts/vue-native-core
|
packages/vue-server-renderer/build.js
|
cached
|
function cached (fn) {
var cache = Object.create(null);
return (function cachedFn (str) {
var hit = cache[str];
return hit || (cache[str] = fn(str))
})
}
|
javascript
|
function cached (fn) {
var cache = Object.create(null);
return (function cachedFn (str) {
var hit = cache[str];
return hit || (cache[str] = fn(str))
})
}
|
[
"function",
"cached",
"(",
"fn",
")",
"{",
"var",
"cache",
"=",
"Object",
".",
"create",
"(",
"null",
")",
";",
"return",
"(",
"function",
"cachedFn",
"(",
"str",
")",
"{",
"var",
"hit",
"=",
"cache",
"[",
"str",
"]",
";",
"return",
"hit",
"||",
"(",
"cache",
"[",
"str",
"]",
"=",
"fn",
"(",
"str",
")",
")",
"}",
")",
"}"
] |
Create a cached version of a pure function.
|
[
"Create",
"a",
"cached",
"version",
"of",
"a",
"pure",
"function",
"."
] |
a7b4c9e35fe3f01d7576086f41e5e9ec6975b72e
|
https://github.com/GeekyAnts/vue-native-core/blob/a7b4c9e35fe3f01d7576086f41e5e9ec6975b72e/packages/vue-server-renderer/build.js#L104-L110
|
train
|
GeekyAnts/vue-native-core
|
packages/vue-server-renderer/build.js
|
toObject
|
function toObject (arr) {
var res = {};
for (var i = 0; i < arr.length; i++) {
if (arr[i]) {
extend(res, arr[i]);
}
}
return res
}
|
javascript
|
function toObject (arr) {
var res = {};
for (var i = 0; i < arr.length; i++) {
if (arr[i]) {
extend(res, arr[i]);
}
}
return res
}
|
[
"function",
"toObject",
"(",
"arr",
")",
"{",
"var",
"res",
"=",
"{",
"}",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"arr",
".",
"length",
";",
"i",
"++",
")",
"{",
"if",
"(",
"arr",
"[",
"i",
"]",
")",
"{",
"extend",
"(",
"res",
",",
"arr",
"[",
"i",
"]",
")",
";",
"}",
"}",
"return",
"res",
"}"
] |
Merge an Array of Objects into a single Object.
|
[
"Merge",
"an",
"Array",
"of",
"Objects",
"into",
"a",
"single",
"Object",
"."
] |
a7b4c9e35fe3f01d7576086f41e5e9ec6975b72e
|
https://github.com/GeekyAnts/vue-native-core/blob/a7b4c9e35fe3f01d7576086f41e5e9ec6975b72e/packages/vue-server-renderer/build.js#L159-L167
|
train
|
GeekyAnts/vue-native-core
|
packages/vue-server-renderer/build.js
|
genStaticKeys
|
function genStaticKeys (modules) {
return modules.reduce(function (keys, m) {
return keys.concat(m.staticKeys || [])
}, []).join(',')
}
|
javascript
|
function genStaticKeys (modules) {
return modules.reduce(function (keys, m) {
return keys.concat(m.staticKeys || [])
}, []).join(',')
}
|
[
"function",
"genStaticKeys",
"(",
"modules",
")",
"{",
"return",
"modules",
".",
"reduce",
"(",
"function",
"(",
"keys",
",",
"m",
")",
"{",
"return",
"keys",
".",
"concat",
"(",
"m",
".",
"staticKeys",
"||",
"[",
"]",
")",
"}",
",",
"[",
"]",
")",
".",
"join",
"(",
"','",
")",
"}"
] |
Generate a static keys string from compiler modules.
|
[
"Generate",
"a",
"static",
"keys",
"string",
"from",
"compiler",
"modules",
"."
] |
a7b4c9e35fe3f01d7576086f41e5e9ec6975b72e
|
https://github.com/GeekyAnts/vue-native-core/blob/a7b4c9e35fe3f01d7576086f41e5e9ec6975b72e/packages/vue-server-renderer/build.js#L187-L191
|
train
|
GeekyAnts/vue-native-core
|
dist/vue.runtime.common.js
|
looseEqual
|
function looseEqual (a, b) {
var isObjectA = isObject(a);
var isObjectB = isObject(b);
if (isObjectA && isObjectB) {
try {
return JSON.stringify(a) === JSON.stringify(b)
} catch (e) {
// possible circular reference
return a === b
}
} else if (!isObjectA && !isObjectB) {
return String(a) === String(b)
} else {
return false
}
}
|
javascript
|
function looseEqual (a, b) {
var isObjectA = isObject(a);
var isObjectB = isObject(b);
if (isObjectA && isObjectB) {
try {
return JSON.stringify(a) === JSON.stringify(b)
} catch (e) {
// possible circular reference
return a === b
}
} else if (!isObjectA && !isObjectB) {
return String(a) === String(b)
} else {
return false
}
}
|
[
"function",
"looseEqual",
"(",
"a",
",",
"b",
")",
"{",
"var",
"isObjectA",
"=",
"isObject",
"(",
"a",
")",
";",
"var",
"isObjectB",
"=",
"isObject",
"(",
"b",
")",
";",
"if",
"(",
"isObjectA",
"&&",
"isObjectB",
")",
"{",
"try",
"{",
"return",
"JSON",
".",
"stringify",
"(",
"a",
")",
"===",
"JSON",
".",
"stringify",
"(",
"b",
")",
"}",
"catch",
"(",
"e",
")",
"{",
"return",
"a",
"===",
"b",
"}",
"}",
"else",
"if",
"(",
"!",
"isObjectA",
"&&",
"!",
"isObjectB",
")",
"{",
"return",
"String",
"(",
"a",
")",
"===",
"String",
"(",
"b",
")",
"}",
"else",
"{",
"return",
"false",
"}",
"}"
] |
Generate a static keys string from compiler modules.
Check if two values are loosely equal - that is,
if they are plain objects, do they have the same shape?
|
[
"Generate",
"a",
"static",
"keys",
"string",
"from",
"compiler",
"modules",
".",
"Check",
"if",
"two",
"values",
"are",
"loosely",
"equal",
"-",
"that",
"is",
"if",
"they",
"are",
"plain",
"objects",
"do",
"they",
"have",
"the",
"same",
"shape?"
] |
a7b4c9e35fe3f01d7576086f41e5e9ec6975b72e
|
https://github.com/GeekyAnts/vue-native-core/blob/a7b4c9e35fe3f01d7576086f41e5e9ec6975b72e/dist/vue.runtime.common.js#L221-L236
|
train
|
GeekyAnts/vue-native-core
|
dist/vue.runtime.common.js
|
once
|
function once (fn) {
var called = false;
return function () {
if (!called) {
called = true;
fn.apply(this, arguments);
}
}
}
|
javascript
|
function once (fn) {
var called = false;
return function () {
if (!called) {
called = true;
fn.apply(this, arguments);
}
}
}
|
[
"function",
"once",
"(",
"fn",
")",
"{",
"var",
"called",
"=",
"false",
";",
"return",
"function",
"(",
")",
"{",
"if",
"(",
"!",
"called",
")",
"{",
"called",
"=",
"true",
";",
"fn",
".",
"apply",
"(",
"this",
",",
"arguments",
")",
";",
"}",
"}",
"}"
] |
Ensure a function is called only once.
|
[
"Ensure",
"a",
"function",
"is",
"called",
"only",
"once",
"."
] |
a7b4c9e35fe3f01d7576086f41e5e9ec6975b72e
|
https://github.com/GeekyAnts/vue-native-core/blob/a7b4c9e35fe3f01d7576086f41e5e9ec6975b72e/dist/vue.runtime.common.js#L248-L256
|
train
|
GeekyAnts/vue-native-core
|
dist/vue.runtime.common.js
|
simpleNormalizeChildren
|
function simpleNormalizeChildren (children) {
for (var i = 0; i < children.length; i++) {
if (Array.isArray(children[i])) {
return Array.prototype.concat.apply([], children)
}
}
return children
}
|
javascript
|
function simpleNormalizeChildren (children) {
for (var i = 0; i < children.length; i++) {
if (Array.isArray(children[i])) {
return Array.prototype.concat.apply([], children)
}
}
return children
}
|
[
"function",
"simpleNormalizeChildren",
"(",
"children",
")",
"{",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"children",
".",
"length",
";",
"i",
"++",
")",
"{",
"if",
"(",
"Array",
".",
"isArray",
"(",
"children",
"[",
"i",
"]",
")",
")",
"{",
"return",
"Array",
".",
"prototype",
".",
"concat",
".",
"apply",
"(",
"[",
"]",
",",
"children",
")",
"}",
"}",
"return",
"children",
"}"
] |
1. When the children contains components - because a functional component may return an Array instead of a single root. In this case, just a simple normalization is needed - if any child is an Array, we flatten the whole thing with Array.prototype.concat. It is guaranteed to be only 1-level deep because functional components already normalize their own children.
|
[
"1",
".",
"When",
"the",
"children",
"contains",
"components",
"-",
"because",
"a",
"functional",
"component",
"may",
"return",
"an",
"Array",
"instead",
"of",
"a",
"single",
"root",
".",
"In",
"this",
"case",
"just",
"a",
"simple",
"normalization",
"is",
"needed",
"-",
"if",
"any",
"child",
"is",
"an",
"Array",
"we",
"flatten",
"the",
"whole",
"thing",
"with",
"Array",
".",
"prototype",
".",
"concat",
".",
"It",
"is",
"guaranteed",
"to",
"be",
"only",
"1",
"-",
"level",
"deep",
"because",
"functional",
"components",
"already",
"normalize",
"their",
"own",
"children",
"."
] |
a7b4c9e35fe3f01d7576086f41e5e9ec6975b72e
|
https://github.com/GeekyAnts/vue-native-core/blob/a7b4c9e35fe3f01d7576086f41e5e9ec6975b72e/dist/vue.runtime.common.js#L1771-L1778
|
train
|
GeekyAnts/vue-native-core
|
packages/vue-native-helper/build.js
|
_toString
|
function _toString(val) {
return val == null
? ''
: typeof val === 'object'
? JSON.stringify(val, null, 2)
: String(val)
}
|
javascript
|
function _toString(val) {
return val == null
? ''
: typeof val === 'object'
? JSON.stringify(val, null, 2)
: String(val)
}
|
[
"function",
"_toString",
"(",
"val",
")",
"{",
"return",
"val",
"==",
"null",
"?",
"''",
":",
"typeof",
"val",
"===",
"'object'",
"?",
"JSON",
".",
"stringify",
"(",
"val",
",",
"null",
",",
"2",
")",
":",
"String",
"(",
"val",
")",
"}"
] |
Convert a value to a string that is actually rendered.
|
[
"Convert",
"a",
"value",
"to",
"a",
"string",
"that",
"is",
"actually",
"rendered",
"."
] |
a7b4c9e35fe3f01d7576086f41e5e9ec6975b72e
|
https://github.com/GeekyAnts/vue-native-core/blob/a7b4c9e35fe3f01d7576086f41e5e9ec6975b72e/packages/vue-native-helper/build.js#L50-L56
|
train
|
GeekyAnts/vue-native-core
|
src/platforms/weex/runtime/modules/transition.js
|
getEnterTargetState
|
function getEnterTargetState (el, stylesheet, startClass, endClass, activeClass, vm) {
const targetState = {}
const startState = stylesheet[startClass]
const endState = stylesheet[endClass]
const activeState = stylesheet[activeClass]
// 1. fallback to element's default styling
if (startState) {
for (const key in startState) {
targetState[key] = el.style[key]
if (
process.env.NODE_ENV !== 'production' &&
targetState[key] == null &&
(!activeState || activeState[key] == null) &&
(!endState || endState[key] == null)
) {
warn(
`transition property "${key}" is declared in enter starting class (.${startClass}), ` +
`but not declared anywhere in enter ending class (.${endClass}), ` +
`enter active cass (.${activeClass}) or the element's default styling. ` +
`Note in Weex, CSS properties need explicit values to be transitionable.`
)
}
}
}
// 2. if state is mixed in active state, extract them while excluding
// transition properties
if (activeState) {
for (const key in activeState) {
if (key.indexOf('transition') !== 0) {
targetState[key] = activeState[key]
}
}
}
// 3. explicit endState has highest priority
if (endState) {
extend(targetState, endState)
}
return targetState
}
|
javascript
|
function getEnterTargetState (el, stylesheet, startClass, endClass, activeClass, vm) {
const targetState = {}
const startState = stylesheet[startClass]
const endState = stylesheet[endClass]
const activeState = stylesheet[activeClass]
// 1. fallback to element's default styling
if (startState) {
for (const key in startState) {
targetState[key] = el.style[key]
if (
process.env.NODE_ENV !== 'production' &&
targetState[key] == null &&
(!activeState || activeState[key] == null) &&
(!endState || endState[key] == null)
) {
warn(
`transition property "${key}" is declared in enter starting class (.${startClass}), ` +
`but not declared anywhere in enter ending class (.${endClass}), ` +
`enter active cass (.${activeClass}) or the element's default styling. ` +
`Note in Weex, CSS properties need explicit values to be transitionable.`
)
}
}
}
// 2. if state is mixed in active state, extract them while excluding
// transition properties
if (activeState) {
for (const key in activeState) {
if (key.indexOf('transition') !== 0) {
targetState[key] = activeState[key]
}
}
}
// 3. explicit endState has highest priority
if (endState) {
extend(targetState, endState)
}
return targetState
}
|
[
"function",
"getEnterTargetState",
"(",
"el",
",",
"stylesheet",
",",
"startClass",
",",
"endClass",
",",
"activeClass",
",",
"vm",
")",
"{",
"const",
"targetState",
"=",
"{",
"}",
"const",
"startState",
"=",
"stylesheet",
"[",
"startClass",
"]",
"const",
"endState",
"=",
"stylesheet",
"[",
"endClass",
"]",
"const",
"activeState",
"=",
"stylesheet",
"[",
"activeClass",
"]",
"if",
"(",
"startState",
")",
"{",
"for",
"(",
"const",
"key",
"in",
"startState",
")",
"{",
"targetState",
"[",
"key",
"]",
"=",
"el",
".",
"style",
"[",
"key",
"]",
"if",
"(",
"process",
".",
"env",
".",
"NODE_ENV",
"!==",
"'production'",
"&&",
"targetState",
"[",
"key",
"]",
"==",
"null",
"&&",
"(",
"!",
"activeState",
"||",
"activeState",
"[",
"key",
"]",
"==",
"null",
")",
"&&",
"(",
"!",
"endState",
"||",
"endState",
"[",
"key",
"]",
"==",
"null",
")",
")",
"{",
"warn",
"(",
"`",
"${",
"key",
"}",
"${",
"startClass",
"}",
"`",
"+",
"`",
"${",
"endClass",
"}",
"`",
"+",
"`",
"${",
"activeClass",
"}",
"`",
"+",
"`",
"`",
")",
"}",
"}",
"}",
"if",
"(",
"activeState",
")",
"{",
"for",
"(",
"const",
"key",
"in",
"activeState",
")",
"{",
"if",
"(",
"key",
".",
"indexOf",
"(",
"'transition'",
")",
"!==",
"0",
")",
"{",
"targetState",
"[",
"key",
"]",
"=",
"activeState",
"[",
"key",
"]",
"}",
"}",
"}",
"if",
"(",
"endState",
")",
"{",
"extend",
"(",
"targetState",
",",
"endState",
")",
"}",
"return",
"targetState",
"}"
] |
determine the target animation style for an entering transition.
|
[
"determine",
"the",
"target",
"animation",
"style",
"for",
"an",
"entering",
"transition",
"."
] |
a7b4c9e35fe3f01d7576086f41e5e9ec6975b72e
|
https://github.com/GeekyAnts/vue-native-core/blob/a7b4c9e35fe3f01d7576086f41e5e9ec6975b72e/src/platforms/weex/runtime/modules/transition.js#L227-L265
|
train
|
GeekyAnts/vue-native-core
|
examples/svg/svg.js
|
function () {
var total = this.stats.length
return this.stats.map(function (stat, i) {
var point = valueToPoint(stat.value, i, total)
return point.x + ',' + point.y
}).join(' ')
}
|
javascript
|
function () {
var total = this.stats.length
return this.stats.map(function (stat, i) {
var point = valueToPoint(stat.value, i, total)
return point.x + ',' + point.y
}).join(' ')
}
|
[
"function",
"(",
")",
"{",
"var",
"total",
"=",
"this",
".",
"stats",
".",
"length",
"return",
"this",
".",
"stats",
".",
"map",
"(",
"function",
"(",
"stat",
",",
"i",
")",
"{",
"var",
"point",
"=",
"valueToPoint",
"(",
"stat",
".",
"value",
",",
"i",
",",
"total",
")",
"return",
"point",
".",
"x",
"+",
"','",
"+",
"point",
".",
"y",
"}",
")",
".",
"join",
"(",
"' '",
")",
"}"
] |
a computed property for the polygon's points
|
[
"a",
"computed",
"property",
"for",
"the",
"polygon",
"s",
"points"
] |
a7b4c9e35fe3f01d7576086f41e5e9ec6975b72e
|
https://github.com/GeekyAnts/vue-native-core/blob/a7b4c9e35fe3f01d7576086f41e5e9ec6975b72e/examples/svg/svg.js#L17-L23
|
train
|
|
GeekyAnts/vue-native-core
|
examples/svg/svg.js
|
valueToPoint
|
function valueToPoint (value, index, total) {
var x = 0
var y = -value * 0.8
var angle = Math.PI * 2 / total * index
var cos = Math.cos(angle)
var sin = Math.sin(angle)
var tx = x * cos - y * sin + 100
var ty = x * sin + y * cos + 100
return {
x: tx,
y: ty
}
}
|
javascript
|
function valueToPoint (value, index, total) {
var x = 0
var y = -value * 0.8
var angle = Math.PI * 2 / total * index
var cos = Math.cos(angle)
var sin = Math.sin(angle)
var tx = x * cos - y * sin + 100
var ty = x * sin + y * cos + 100
return {
x: tx,
y: ty
}
}
|
[
"function",
"valueToPoint",
"(",
"value",
",",
"index",
",",
"total",
")",
"{",
"var",
"x",
"=",
"0",
"var",
"y",
"=",
"-",
"value",
"*",
"0.8",
"var",
"angle",
"=",
"Math",
".",
"PI",
"*",
"2",
"/",
"total",
"*",
"index",
"var",
"cos",
"=",
"Math",
".",
"cos",
"(",
"angle",
")",
"var",
"sin",
"=",
"Math",
".",
"sin",
"(",
"angle",
")",
"var",
"tx",
"=",
"x",
"*",
"cos",
"-",
"y",
"*",
"sin",
"+",
"100",
"var",
"ty",
"=",
"x",
"*",
"sin",
"+",
"y",
"*",
"cos",
"+",
"100",
"return",
"{",
"x",
":",
"tx",
",",
"y",
":",
"ty",
"}",
"}"
] |
math helper...
|
[
"math",
"helper",
"..."
] |
a7b4c9e35fe3f01d7576086f41e5e9ec6975b72e
|
https://github.com/GeekyAnts/vue-native-core/blob/a7b4c9e35fe3f01d7576086f41e5e9ec6975b72e/examples/svg/svg.js#L48-L60
|
train
|
GeekyAnts/vue-native-core
|
packages/weex-vue-framework/factory.js
|
assertType
|
function assertType (value, type) {
var valid;
var expectedType = getType(type);
if (expectedType === 'String') {
valid = typeof value === (expectedType = 'string');
} else if (expectedType === 'Number') {
valid = typeof value === (expectedType = 'number');
} else if (expectedType === 'Boolean') {
valid = typeof value === (expectedType = 'boolean');
} else if (expectedType === 'Function') {
valid = typeof value === (expectedType = 'function');
} else if (expectedType === 'Object') {
valid = isPlainObject(value);
} else if (expectedType === 'Array') {
valid = Array.isArray(value);
} else {
valid = value instanceof type;
}
return {
valid: valid,
expectedType: expectedType
}
}
|
javascript
|
function assertType (value, type) {
var valid;
var expectedType = getType(type);
if (expectedType === 'String') {
valid = typeof value === (expectedType = 'string');
} else if (expectedType === 'Number') {
valid = typeof value === (expectedType = 'number');
} else if (expectedType === 'Boolean') {
valid = typeof value === (expectedType = 'boolean');
} else if (expectedType === 'Function') {
valid = typeof value === (expectedType = 'function');
} else if (expectedType === 'Object') {
valid = isPlainObject(value);
} else if (expectedType === 'Array') {
valid = Array.isArray(value);
} else {
valid = value instanceof type;
}
return {
valid: valid,
expectedType: expectedType
}
}
|
[
"function",
"assertType",
"(",
"value",
",",
"type",
")",
"{",
"var",
"valid",
";",
"var",
"expectedType",
"=",
"getType",
"(",
"type",
")",
";",
"if",
"(",
"expectedType",
"===",
"'String'",
")",
"{",
"valid",
"=",
"typeof",
"value",
"===",
"(",
"expectedType",
"=",
"'string'",
")",
";",
"}",
"else",
"if",
"(",
"expectedType",
"===",
"'Number'",
")",
"{",
"valid",
"=",
"typeof",
"value",
"===",
"(",
"expectedType",
"=",
"'number'",
")",
";",
"}",
"else",
"if",
"(",
"expectedType",
"===",
"'Boolean'",
")",
"{",
"valid",
"=",
"typeof",
"value",
"===",
"(",
"expectedType",
"=",
"'boolean'",
")",
";",
"}",
"else",
"if",
"(",
"expectedType",
"===",
"'Function'",
")",
"{",
"valid",
"=",
"typeof",
"value",
"===",
"(",
"expectedType",
"=",
"'function'",
")",
";",
"}",
"else",
"if",
"(",
"expectedType",
"===",
"'Object'",
")",
"{",
"valid",
"=",
"isPlainObject",
"(",
"value",
")",
";",
"}",
"else",
"if",
"(",
"expectedType",
"===",
"'Array'",
")",
"{",
"valid",
"=",
"Array",
".",
"isArray",
"(",
"value",
")",
";",
"}",
"else",
"{",
"valid",
"=",
"value",
"instanceof",
"type",
";",
"}",
"return",
"{",
"valid",
":",
"valid",
",",
"expectedType",
":",
"expectedType",
"}",
"}"
] |
Assert the type of a value
|
[
"Assert",
"the",
"type",
"of",
"a",
"value"
] |
a7b4c9e35fe3f01d7576086f41e5e9ec6975b72e
|
https://github.com/GeekyAnts/vue-native-core/blob/a7b4c9e35fe3f01d7576086f41e5e9ec6975b72e/packages/weex-vue-framework/factory.js#L1384-L1406
|
train
|
GeekyAnts/vue-native-core
|
packages/weex-vue-framework/index.js
|
init
|
function init (cfg) {
renderer.Document = cfg.Document;
renderer.Element = cfg.Element;
renderer.Comment = cfg.Comment;
renderer.sendTasks = cfg.sendTasks;
}
|
javascript
|
function init (cfg) {
renderer.Document = cfg.Document;
renderer.Element = cfg.Element;
renderer.Comment = cfg.Comment;
renderer.sendTasks = cfg.sendTasks;
}
|
[
"function",
"init",
"(",
"cfg",
")",
"{",
"renderer",
".",
"Document",
"=",
"cfg",
".",
"Document",
";",
"renderer",
".",
"Element",
"=",
"cfg",
".",
"Element",
";",
"renderer",
".",
"Comment",
"=",
"cfg",
".",
"Comment",
";",
"renderer",
".",
"sendTasks",
"=",
"cfg",
".",
"sendTasks",
";",
"}"
] |
Prepare framework config, basically about the virtual-DOM and JS bridge.
@param {object} cfg
|
[
"Prepare",
"framework",
"config",
"basically",
"about",
"the",
"virtual",
"-",
"DOM",
"and",
"JS",
"bridge",
"."
] |
a7b4c9e35fe3f01d7576086f41e5e9ec6975b72e
|
https://github.com/GeekyAnts/vue-native-core/blob/a7b4c9e35fe3f01d7576086f41e5e9ec6975b72e/packages/weex-vue-framework/index.js#L33-L38
|
train
|
GeekyAnts/vue-native-core
|
packages/weex-vue-framework/index.js
|
genModuleGetter
|
function genModuleGetter (instanceId) {
var instance = instances[instanceId];
return function (name) {
var nativeModule = modules[name] || [];
var output = {};
var loop = function ( methodName ) {
output[methodName] = function () {
var args = [], len = arguments.length;
while ( len-- ) args[ len ] = arguments[ len ];
var finalArgs = args.map(function (value) {
return normalize(value, instance)
});
renderer.sendTasks(instanceId + '', [{ module: name, method: methodName, args: finalArgs }], -1);
};
};
for (var methodName in nativeModule) loop( methodName );
return output
}
}
|
javascript
|
function genModuleGetter (instanceId) {
var instance = instances[instanceId];
return function (name) {
var nativeModule = modules[name] || [];
var output = {};
var loop = function ( methodName ) {
output[methodName] = function () {
var args = [], len = arguments.length;
while ( len-- ) args[ len ] = arguments[ len ];
var finalArgs = args.map(function (value) {
return normalize(value, instance)
});
renderer.sendTasks(instanceId + '', [{ module: name, method: methodName, args: finalArgs }], -1);
};
};
for (var methodName in nativeModule) loop( methodName );
return output
}
}
|
[
"function",
"genModuleGetter",
"(",
"instanceId",
")",
"{",
"var",
"instance",
"=",
"instances",
"[",
"instanceId",
"]",
";",
"return",
"function",
"(",
"name",
")",
"{",
"var",
"nativeModule",
"=",
"modules",
"[",
"name",
"]",
"||",
"[",
"]",
";",
"var",
"output",
"=",
"{",
"}",
";",
"var",
"loop",
"=",
"function",
"(",
"methodName",
")",
"{",
"output",
"[",
"methodName",
"]",
"=",
"function",
"(",
")",
"{",
"var",
"args",
"=",
"[",
"]",
",",
"len",
"=",
"arguments",
".",
"length",
";",
"while",
"(",
"len",
"--",
")",
"args",
"[",
"len",
"]",
"=",
"arguments",
"[",
"len",
"]",
";",
"var",
"finalArgs",
"=",
"args",
".",
"map",
"(",
"function",
"(",
"value",
")",
"{",
"return",
"normalize",
"(",
"value",
",",
"instance",
")",
"}",
")",
";",
"renderer",
".",
"sendTasks",
"(",
"instanceId",
"+",
"''",
",",
"[",
"{",
"module",
":",
"name",
",",
"method",
":",
"methodName",
",",
"args",
":",
"finalArgs",
"}",
"]",
",",
"-",
"1",
")",
";",
"}",
";",
"}",
";",
"for",
"(",
"var",
"methodName",
"in",
"nativeModule",
")",
"loop",
"(",
"methodName",
")",
";",
"return",
"output",
"}",
"}"
] |
Generate native module getter. Each native module has several
methods to call. And all the behaviors is instance-related. So
this getter will return a set of methods which additionally
send current instance id to native when called. Also the args
will be normalized into "safe" value. For example function arg
will be converted into a callback id.
@param {string} instanceId
@return {function}
|
[
"Generate",
"native",
"module",
"getter",
".",
"Each",
"native",
"module",
"has",
"several",
"methods",
"to",
"call",
".",
"And",
"all",
"the",
"behaviors",
"is",
"instance",
"-",
"related",
".",
"So",
"this",
"getter",
"will",
"return",
"a",
"set",
"of",
"methods",
"which",
"additionally",
"send",
"current",
"instance",
"id",
"to",
"native",
"when",
"called",
".",
"Also",
"the",
"args",
"will",
"be",
"normalized",
"into",
"safe",
"value",
".",
"For",
"example",
"function",
"arg",
"will",
"be",
"converted",
"into",
"a",
"callback",
"id",
"."
] |
a7b4c9e35fe3f01d7576086f41e5e9ec6975b72e
|
https://github.com/GeekyAnts/vue-native-core/blob/a7b4c9e35fe3f01d7576086f41e5e9ec6975b72e/packages/weex-vue-framework/index.js#L323-L343
|
train
|
GeekyAnts/vue-native-core
|
src/platforms/weex/framework.js
|
normalize
|
function normalize (v, instance) {
const type = typof(v)
switch (type) {
case 'undefined':
case 'null':
return ''
case 'regexp':
return v.toString()
case 'date':
return v.toISOString()
case 'number':
case 'string':
case 'boolean':
case 'array':
case 'object':
if (v instanceof renderer.Element) {
return v.ref
}
return v
case 'function':
instance.callbacks[++instance.callbackId] = v
return instance.callbackId.toString()
default:
return JSON.stringify(v)
}
}
|
javascript
|
function normalize (v, instance) {
const type = typof(v)
switch (type) {
case 'undefined':
case 'null':
return ''
case 'regexp':
return v.toString()
case 'date':
return v.toISOString()
case 'number':
case 'string':
case 'boolean':
case 'array':
case 'object':
if (v instanceof renderer.Element) {
return v.ref
}
return v
case 'function':
instance.callbacks[++instance.callbackId] = v
return instance.callbackId.toString()
default:
return JSON.stringify(v)
}
}
|
[
"function",
"normalize",
"(",
"v",
",",
"instance",
")",
"{",
"const",
"type",
"=",
"typof",
"(",
"v",
")",
"switch",
"(",
"type",
")",
"{",
"case",
"'undefined'",
":",
"case",
"'null'",
":",
"return",
"''",
"case",
"'regexp'",
":",
"return",
"v",
".",
"toString",
"(",
")",
"case",
"'date'",
":",
"return",
"v",
".",
"toISOString",
"(",
")",
"case",
"'number'",
":",
"case",
"'string'",
":",
"case",
"'boolean'",
":",
"case",
"'array'",
":",
"case",
"'object'",
":",
"if",
"(",
"v",
"instanceof",
"renderer",
".",
"Element",
")",
"{",
"return",
"v",
".",
"ref",
"}",
"return",
"v",
"case",
"'function'",
":",
"instance",
".",
"callbacks",
"[",
"++",
"instance",
".",
"callbackId",
"]",
"=",
"v",
"return",
"instance",
".",
"callbackId",
".",
"toString",
"(",
")",
"default",
":",
"return",
"JSON",
".",
"stringify",
"(",
"v",
")",
"}",
"}"
] |
Convert all type of values into "safe" format to send to native.
1. A `function` will be converted into callback id.
2. An `Element` object will be converted into `ref`.
The `instance` param is used to generate callback id and store
function if necessary.
@param {any} v
@param {object} instance
@return {any}
|
[
"Convert",
"all",
"type",
"of",
"values",
"into",
"safe",
"format",
"to",
"send",
"to",
"native",
".",
"1",
".",
"A",
"function",
"will",
"be",
"converted",
"into",
"callback",
"id",
".",
"2",
".",
"An",
"Element",
"object",
"will",
"be",
"converted",
"into",
"ref",
".",
"The",
"instance",
"param",
"is",
"used",
"to",
"generate",
"callback",
"id",
"and",
"store",
"function",
"if",
"necessary",
"."
] |
a7b4c9e35fe3f01d7576086f41e5e9ec6975b72e
|
https://github.com/GeekyAnts/vue-native-core/blob/a7b4c9e35fe3f01d7576086f41e5e9ec6975b72e/src/platforms/weex/framework.js#L380-L406
|
train
|
muaz-khan/RTCMultiConnection
|
dev/getUserMedia.js
|
setStreamType
|
function setStreamType(constraints, stream) {
if (constraints.mandatory && constraints.mandatory.chromeMediaSource) {
stream.isScreen = true;
} else if (constraints.mozMediaSource || constraints.mediaSource) {
stream.isScreen = true;
} else if (constraints.video) {
stream.isVideo = true;
} else if (constraints.audio) {
stream.isAudio = true;
}
}
|
javascript
|
function setStreamType(constraints, stream) {
if (constraints.mandatory && constraints.mandatory.chromeMediaSource) {
stream.isScreen = true;
} else if (constraints.mozMediaSource || constraints.mediaSource) {
stream.isScreen = true;
} else if (constraints.video) {
stream.isVideo = true;
} else if (constraints.audio) {
stream.isAudio = true;
}
}
|
[
"function",
"setStreamType",
"(",
"constraints",
",",
"stream",
")",
"{",
"if",
"(",
"constraints",
".",
"mandatory",
"&&",
"constraints",
".",
"mandatory",
".",
"chromeMediaSource",
")",
"{",
"stream",
".",
"isScreen",
"=",
"true",
";",
"}",
"else",
"if",
"(",
"constraints",
".",
"mozMediaSource",
"||",
"constraints",
".",
"mediaSource",
")",
"{",
"stream",
".",
"isScreen",
"=",
"true",
";",
"}",
"else",
"if",
"(",
"constraints",
".",
"video",
")",
"{",
"stream",
".",
"isVideo",
"=",
"true",
";",
"}",
"else",
"if",
"(",
"constraints",
".",
"audio",
")",
"{",
"stream",
".",
"isAudio",
"=",
"true",
";",
"}",
"}"
] |
getUserMediaHandler.js
|
[
"getUserMediaHandler",
".",
"js"
] |
2032ce949bde30b43a3d2666e0f1e5afbf337f3d
|
https://github.com/muaz-khan/RTCMultiConnection/blob/2032ce949bde30b43a3d2666e0f1e5afbf337f3d/dev/getUserMedia.js#L3-L13
|
train
|
muaz-khan/RTCMultiConnection
|
dev/XHRConnection.js
|
xhr
|
function xhr(url, callback, data) {
if (!window.XMLHttpRequest || !window.JSON) return;
var request = new XMLHttpRequest();
request.onreadystatechange = function() {
if (callback && request.readyState == 4 && request.status == 200) {
// server MUST return JSON text
callback(JSON.parse(request.responseText));
}
};
request.open('POST', url);
var formData = new FormData();
// you're passing "message" parameter
formData.append('message', data);
request.send(formData);
}
|
javascript
|
function xhr(url, callback, data) {
if (!window.XMLHttpRequest || !window.JSON) return;
var request = new XMLHttpRequest();
request.onreadystatechange = function() {
if (callback && request.readyState == 4 && request.status == 200) {
// server MUST return JSON text
callback(JSON.parse(request.responseText));
}
};
request.open('POST', url);
var formData = new FormData();
// you're passing "message" parameter
formData.append('message', data);
request.send(formData);
}
|
[
"function",
"xhr",
"(",
"url",
",",
"callback",
",",
"data",
")",
"{",
"if",
"(",
"!",
"window",
".",
"XMLHttpRequest",
"||",
"!",
"window",
".",
"JSON",
")",
"return",
";",
"var",
"request",
"=",
"new",
"XMLHttpRequest",
"(",
")",
";",
"request",
".",
"onreadystatechange",
"=",
"function",
"(",
")",
"{",
"if",
"(",
"callback",
"&&",
"request",
".",
"readyState",
"==",
"4",
"&&",
"request",
".",
"status",
"==",
"200",
")",
"{",
"callback",
"(",
"JSON",
".",
"parse",
"(",
"request",
".",
"responseText",
")",
")",
";",
"}",
"}",
";",
"request",
".",
"open",
"(",
"'POST'",
",",
"url",
")",
";",
"var",
"formData",
"=",
"new",
"FormData",
"(",
")",
";",
"formData",
".",
"append",
"(",
"'message'",
",",
"data",
")",
";",
"request",
".",
"send",
"(",
"formData",
")",
";",
"}"
] |
a simple function to make XMLHttpRequests
|
[
"a",
"simple",
"function",
"to",
"make",
"XMLHttpRequests"
] |
2032ce949bde30b43a3d2666e0f1e5afbf337f3d
|
https://github.com/muaz-khan/RTCMultiConnection/blob/2032ce949bde30b43a3d2666e0f1e5afbf337f3d/dev/XHRConnection.js#L16-L34
|
train
|
muaz-khan/RTCMultiConnection
|
dev/TextSenderReceiver.js
|
TextReceiver
|
function TextReceiver(connection) {
var content = {};
function receive(data, userid, extra) {
// uuid is used to uniquely identify sending instance
var uuid = data.uuid;
if (!content[uuid]) {
content[uuid] = [];
}
content[uuid].push(data.message);
if (data.last) {
var message = content[uuid].join('');
if (data.isobject) {
message = JSON.parse(message);
}
// latency detection
var receivingTime = new Date().getTime();
var latency = receivingTime - data.sendingTime;
var e = {
data: message,
userid: userid,
extra: extra,
latency: latency
};
if (connection.autoTranslateText) {
e.original = e.data;
connection.Translator.TranslateText(e.data, function(translatedText) {
e.data = translatedText;
connection.onmessage(e);
});
} else {
connection.onmessage(e);
}
delete content[uuid];
}
}
return {
receive: receive
};
}
|
javascript
|
function TextReceiver(connection) {
var content = {};
function receive(data, userid, extra) {
// uuid is used to uniquely identify sending instance
var uuid = data.uuid;
if (!content[uuid]) {
content[uuid] = [];
}
content[uuid].push(data.message);
if (data.last) {
var message = content[uuid].join('');
if (data.isobject) {
message = JSON.parse(message);
}
// latency detection
var receivingTime = new Date().getTime();
var latency = receivingTime - data.sendingTime;
var e = {
data: message,
userid: userid,
extra: extra,
latency: latency
};
if (connection.autoTranslateText) {
e.original = e.data;
connection.Translator.TranslateText(e.data, function(translatedText) {
e.data = translatedText;
connection.onmessage(e);
});
} else {
connection.onmessage(e);
}
delete content[uuid];
}
}
return {
receive: receive
};
}
|
[
"function",
"TextReceiver",
"(",
"connection",
")",
"{",
"var",
"content",
"=",
"{",
"}",
";",
"function",
"receive",
"(",
"data",
",",
"userid",
",",
"extra",
")",
"{",
"var",
"uuid",
"=",
"data",
".",
"uuid",
";",
"if",
"(",
"!",
"content",
"[",
"uuid",
"]",
")",
"{",
"content",
"[",
"uuid",
"]",
"=",
"[",
"]",
";",
"}",
"content",
"[",
"uuid",
"]",
".",
"push",
"(",
"data",
".",
"message",
")",
";",
"if",
"(",
"data",
".",
"last",
")",
"{",
"var",
"message",
"=",
"content",
"[",
"uuid",
"]",
".",
"join",
"(",
"''",
")",
";",
"if",
"(",
"data",
".",
"isobject",
")",
"{",
"message",
"=",
"JSON",
".",
"parse",
"(",
"message",
")",
";",
"}",
"var",
"receivingTime",
"=",
"new",
"Date",
"(",
")",
".",
"getTime",
"(",
")",
";",
"var",
"latency",
"=",
"receivingTime",
"-",
"data",
".",
"sendingTime",
";",
"var",
"e",
"=",
"{",
"data",
":",
"message",
",",
"userid",
":",
"userid",
",",
"extra",
":",
"extra",
",",
"latency",
":",
"latency",
"}",
";",
"if",
"(",
"connection",
".",
"autoTranslateText",
")",
"{",
"e",
".",
"original",
"=",
"e",
".",
"data",
";",
"connection",
".",
"Translator",
".",
"TranslateText",
"(",
"e",
".",
"data",
",",
"function",
"(",
"translatedText",
")",
"{",
"e",
".",
"data",
"=",
"translatedText",
";",
"connection",
".",
"onmessage",
"(",
"e",
")",
";",
"}",
")",
";",
"}",
"else",
"{",
"connection",
".",
"onmessage",
"(",
"e",
")",
";",
"}",
"delete",
"content",
"[",
"uuid",
"]",
";",
"}",
"}",
"return",
"{",
"receive",
":",
"receive",
"}",
";",
"}"
] |
TextReceiver.js & TextSender.js
|
[
"TextReceiver",
".",
"js",
"&",
"TextSender",
".",
"js"
] |
2032ce949bde30b43a3d2666e0f1e5afbf337f3d
|
https://github.com/muaz-khan/RTCMultiConnection/blob/2032ce949bde30b43a3d2666e0f1e5afbf337f3d/dev/TextSenderReceiver.js#L3-L49
|
train
|
muaz-khan/RTCMultiConnection
|
dev/MediaStreamRecorder.js
|
mergeProps
|
function mergeProps(mergein, mergeto) {
for (var t in mergeto) {
if (typeof mergeto[t] !== 'function') {
mergein[t] = mergeto[t];
}
}
return mergein;
}
|
javascript
|
function mergeProps(mergein, mergeto) {
for (var t in mergeto) {
if (typeof mergeto[t] !== 'function') {
mergein[t] = mergeto[t];
}
}
return mergein;
}
|
[
"function",
"mergeProps",
"(",
"mergein",
",",
"mergeto",
")",
"{",
"for",
"(",
"var",
"t",
"in",
"mergeto",
")",
"{",
"if",
"(",
"typeof",
"mergeto",
"[",
"t",
"]",
"!==",
"'function'",
")",
"{",
"mergein",
"[",
"t",
"]",
"=",
"mergeto",
"[",
"t",
"]",
";",
"}",
"}",
"return",
"mergein",
";",
"}"
] |
Merge all other data-types except "function"
|
[
"Merge",
"all",
"other",
"data",
"-",
"types",
"except",
"function"
] |
2032ce949bde30b43a3d2666e0f1e5afbf337f3d
|
https://github.com/muaz-khan/RTCMultiConnection/blob/2032ce949bde30b43a3d2666e0f1e5afbf337f3d/dev/MediaStreamRecorder.js#L907-L914
|
train
|
muaz-khan/RTCMultiConnection
|
dev/MediaStreamRecorder.js
|
WhammyVideo
|
function WhammyVideo(duration, quality) {
this.frames = [];
if (!duration) {
duration = 1;
}
this.duration = 1000 / duration;
this.quality = quality || 0.8;
}
|
javascript
|
function WhammyVideo(duration, quality) {
this.frames = [];
if (!duration) {
duration = 1;
}
this.duration = 1000 / duration;
this.quality = quality || 0.8;
}
|
[
"function",
"WhammyVideo",
"(",
"duration",
",",
"quality",
")",
"{",
"this",
".",
"frames",
"=",
"[",
"]",
";",
"if",
"(",
"!",
"duration",
")",
"{",
"duration",
"=",
"1",
";",
"}",
"this",
".",
"duration",
"=",
"1000",
"/",
"duration",
";",
"this",
".",
"quality",
"=",
"quality",
"||",
"0.8",
";",
"}"
] |
a more abstract-ish API
|
[
"a",
"more",
"abstract",
"-",
"ish",
"API"
] |
2032ce949bde30b43a3d2666e0f1e5afbf337f3d
|
https://github.com/muaz-khan/RTCMultiConnection/blob/2032ce949bde30b43a3d2666e0f1e5afbf337f3d/dev/MediaStreamRecorder.js#L2228-L2235
|
train
|
muaz-khan/RTCMultiConnection
|
dev/MediaStreamRecorder.js
|
checkFrames
|
function checkFrames(frames) {
if (!frames[0]) {
postMessage({
error: 'Something went wrong. Maybe WebP format is not supported in the current browser.'
});
return;
}
var width = frames[0].width,
height = frames[0].height,
duration = frames[0].duration;
for (var i = 1; i < frames.length; i++) {
duration += frames[i].duration;
}
return {
duration: duration,
width: width,
height: height
};
}
|
javascript
|
function checkFrames(frames) {
if (!frames[0]) {
postMessage({
error: 'Something went wrong. Maybe WebP format is not supported in the current browser.'
});
return;
}
var width = frames[0].width,
height = frames[0].height,
duration = frames[0].duration;
for (var i = 1; i < frames.length; i++) {
duration += frames[i].duration;
}
return {
duration: duration,
width: width,
height: height
};
}
|
[
"function",
"checkFrames",
"(",
"frames",
")",
"{",
"if",
"(",
"!",
"frames",
"[",
"0",
"]",
")",
"{",
"postMessage",
"(",
"{",
"error",
":",
"'Something went wrong. Maybe WebP format is not supported in the current browser.'",
"}",
")",
";",
"return",
";",
"}",
"var",
"width",
"=",
"frames",
"[",
"0",
"]",
".",
"width",
",",
"height",
"=",
"frames",
"[",
"0",
"]",
".",
"height",
",",
"duration",
"=",
"frames",
"[",
"0",
"]",
".",
"duration",
";",
"for",
"(",
"var",
"i",
"=",
"1",
";",
"i",
"<",
"frames",
".",
"length",
";",
"i",
"++",
")",
"{",
"duration",
"+=",
"frames",
"[",
"i",
"]",
".",
"duration",
";",
"}",
"return",
"{",
"duration",
":",
"duration",
",",
"width",
":",
"width",
",",
"height",
":",
"height",
"}",
";",
"}"
] |
sums the lengths of all the frames and gets the duration
|
[
"sums",
"the",
"lengths",
"of",
"all",
"the",
"frames",
"and",
"gets",
"the",
"duration"
] |
2032ce949bde30b43a3d2666e0f1e5afbf337f3d
|
https://github.com/muaz-khan/RTCMultiConnection/blob/2032ce949bde30b43a3d2666e0f1e5afbf337f3d/dev/MediaStreamRecorder.js#L2415-L2435
|
train
|
muaz-khan/RTCMultiConnection
|
dev/ios-hacks.js
|
setCordovaAPIs
|
function setCordovaAPIs() {
// if (DetectRTC.osName !== 'iOS') return;
if (typeof cordova === 'undefined' || typeof cordova.plugins === 'undefined' || typeof cordova.plugins.iosrtc === 'undefined') return;
var iosrtc = cordova.plugins.iosrtc;
window.webkitRTCPeerConnection = iosrtc.RTCPeerConnection;
window.RTCSessionDescription = iosrtc.RTCSessionDescription;
window.RTCIceCandidate = iosrtc.RTCIceCandidate;
window.MediaStream = iosrtc.MediaStream;
window.MediaStreamTrack = iosrtc.MediaStreamTrack;
navigator.getUserMedia = navigator.webkitGetUserMedia = iosrtc.getUserMedia;
iosrtc.debug.enable('iosrtc*');
if (typeof iosrtc.selectAudioOutput == 'function') {
iosrtc.selectAudioOutput(window.iOSDefaultAudioOutputDevice || 'speaker'); // earpiece or speaker
}
iosrtc.registerGlobals();
}
|
javascript
|
function setCordovaAPIs() {
// if (DetectRTC.osName !== 'iOS') return;
if (typeof cordova === 'undefined' || typeof cordova.plugins === 'undefined' || typeof cordova.plugins.iosrtc === 'undefined') return;
var iosrtc = cordova.plugins.iosrtc;
window.webkitRTCPeerConnection = iosrtc.RTCPeerConnection;
window.RTCSessionDescription = iosrtc.RTCSessionDescription;
window.RTCIceCandidate = iosrtc.RTCIceCandidate;
window.MediaStream = iosrtc.MediaStream;
window.MediaStreamTrack = iosrtc.MediaStreamTrack;
navigator.getUserMedia = navigator.webkitGetUserMedia = iosrtc.getUserMedia;
iosrtc.debug.enable('iosrtc*');
if (typeof iosrtc.selectAudioOutput == 'function') {
iosrtc.selectAudioOutput(window.iOSDefaultAudioOutputDevice || 'speaker'); // earpiece or speaker
}
iosrtc.registerGlobals();
}
|
[
"function",
"setCordovaAPIs",
"(",
")",
"{",
"if",
"(",
"typeof",
"cordova",
"===",
"'undefined'",
"||",
"typeof",
"cordova",
".",
"plugins",
"===",
"'undefined'",
"||",
"typeof",
"cordova",
".",
"plugins",
".",
"iosrtc",
"===",
"'undefined'",
")",
"return",
";",
"var",
"iosrtc",
"=",
"cordova",
".",
"plugins",
".",
"iosrtc",
";",
"window",
".",
"webkitRTCPeerConnection",
"=",
"iosrtc",
".",
"RTCPeerConnection",
";",
"window",
".",
"RTCSessionDescription",
"=",
"iosrtc",
".",
"RTCSessionDescription",
";",
"window",
".",
"RTCIceCandidate",
"=",
"iosrtc",
".",
"RTCIceCandidate",
";",
"window",
".",
"MediaStream",
"=",
"iosrtc",
".",
"MediaStream",
";",
"window",
".",
"MediaStreamTrack",
"=",
"iosrtc",
".",
"MediaStreamTrack",
";",
"navigator",
".",
"getUserMedia",
"=",
"navigator",
".",
"webkitGetUserMedia",
"=",
"iosrtc",
".",
"getUserMedia",
";",
"iosrtc",
".",
"debug",
".",
"enable",
"(",
"'iosrtc*'",
")",
";",
"if",
"(",
"typeof",
"iosrtc",
".",
"selectAudioOutput",
"==",
"'function'",
")",
"{",
"iosrtc",
".",
"selectAudioOutput",
"(",
"window",
".",
"iOSDefaultAudioOutputDevice",
"||",
"'speaker'",
")",
";",
"}",
"iosrtc",
".",
"registerGlobals",
"(",
")",
";",
"}"
] |
ios-hacks.js
|
[
"ios",
"-",
"hacks",
".",
"js"
] |
2032ce949bde30b43a3d2666e0f1e5afbf337f3d
|
https://github.com/muaz-khan/RTCMultiConnection/blob/2032ce949bde30b43a3d2666e0f1e5afbf337f3d/dev/ios-hacks.js#L3-L20
|
train
|
getsentry/sentry-javascript
|
packages/raven-js/plugins/ember.js
|
emberPlugin
|
function emberPlugin(Raven, Ember) {
Ember = Ember || window.Ember;
// quit if Ember isn't on the page
if (!Ember) return;
var _oldOnError = Ember.onerror;
Ember.onerror = function EmberOnError(error) {
Raven.captureException(error);
if (typeof _oldOnError === 'function') {
_oldOnError.call(this, error);
}
};
Ember.RSVP.on('error', function(reason) {
if (reason instanceof Error) {
Raven.captureException(reason, {
extra: {context: 'Unhandled Promise error detected'}
});
} else {
Raven.captureMessage('Unhandled Promise error detected', {extra: {reason: reason}});
}
});
}
|
javascript
|
function emberPlugin(Raven, Ember) {
Ember = Ember || window.Ember;
// quit if Ember isn't on the page
if (!Ember) return;
var _oldOnError = Ember.onerror;
Ember.onerror = function EmberOnError(error) {
Raven.captureException(error);
if (typeof _oldOnError === 'function') {
_oldOnError.call(this, error);
}
};
Ember.RSVP.on('error', function(reason) {
if (reason instanceof Error) {
Raven.captureException(reason, {
extra: {context: 'Unhandled Promise error detected'}
});
} else {
Raven.captureMessage('Unhandled Promise error detected', {extra: {reason: reason}});
}
});
}
|
[
"function",
"emberPlugin",
"(",
"Raven",
",",
"Ember",
")",
"{",
"Ember",
"=",
"Ember",
"||",
"window",
".",
"Ember",
";",
"if",
"(",
"!",
"Ember",
")",
"return",
";",
"var",
"_oldOnError",
"=",
"Ember",
".",
"onerror",
";",
"Ember",
".",
"onerror",
"=",
"function",
"EmberOnError",
"(",
"error",
")",
"{",
"Raven",
".",
"captureException",
"(",
"error",
")",
";",
"if",
"(",
"typeof",
"_oldOnError",
"===",
"'function'",
")",
"{",
"_oldOnError",
".",
"call",
"(",
"this",
",",
"error",
")",
";",
"}",
"}",
";",
"Ember",
".",
"RSVP",
".",
"on",
"(",
"'error'",
",",
"function",
"(",
"reason",
")",
"{",
"if",
"(",
"reason",
"instanceof",
"Error",
")",
"{",
"Raven",
".",
"captureException",
"(",
"reason",
",",
"{",
"extra",
":",
"{",
"context",
":",
"'Unhandled Promise error detected'",
"}",
"}",
")",
";",
"}",
"else",
"{",
"Raven",
".",
"captureMessage",
"(",
"'Unhandled Promise error detected'",
",",
"{",
"extra",
":",
"{",
"reason",
":",
"reason",
"}",
"}",
")",
";",
"}",
"}",
")",
";",
"}"
] |
Ember.js plugin
Patches event handler callbacks and ajax callbacks.
|
[
"Ember",
".",
"js",
"plugin"
] |
a872223343fecf7364473b78bede937f1eb57bd0
|
https://github.com/getsentry/sentry-javascript/blob/a872223343fecf7364473b78bede937f1eb57bd0/packages/raven-js/plugins/ember.js#L6-L28
|
train
|
getsentry/sentry-javascript
|
packages/raven-js/Gruntfile.js
|
AddPluginBrowserifyTransformer
|
function AddPluginBrowserifyTransformer() {
var noop = function(chunk, _, cb) {
cb(null, chunk);
};
var append = function(cb) {
cb(null, "\nrequire('../src/singleton').addPlugin(module.exports);");
};
return function(file) {
return through(noop, /plugins/.test(file) ? append : undefined);
};
}
|
javascript
|
function AddPluginBrowserifyTransformer() {
var noop = function(chunk, _, cb) {
cb(null, chunk);
};
var append = function(cb) {
cb(null, "\nrequire('../src/singleton').addPlugin(module.exports);");
};
return function(file) {
return through(noop, /plugins/.test(file) ? append : undefined);
};
}
|
[
"function",
"AddPluginBrowserifyTransformer",
"(",
")",
"{",
"var",
"noop",
"=",
"function",
"(",
"chunk",
",",
"_",
",",
"cb",
")",
"{",
"cb",
"(",
"null",
",",
"chunk",
")",
";",
"}",
";",
"var",
"append",
"=",
"function",
"(",
"cb",
")",
"{",
"cb",
"(",
"null",
",",
"\"\\nrequire('../src/singleton').addPlugin(module.exports);\"",
")",
";",
"}",
";",
"\\n",
"}"
] |
custom browserify transformer to re-write plugins to self-register with Raven via addPlugin
|
[
"custom",
"browserify",
"transformer",
"to",
"re",
"-",
"write",
"plugins",
"to",
"self",
"-",
"register",
"with",
"Raven",
"via",
"addPlugin"
] |
a872223343fecf7364473b78bede937f1eb57bd0
|
https://github.com/getsentry/sentry-javascript/blob/a872223343fecf7364473b78bede937f1eb57bd0/packages/raven-js/Gruntfile.js#L26-L36
|
train
|
getsentry/sentry-javascript
|
packages/raven-js/src/raven.js
|
Raven
|
function Raven() {
this._hasJSON = !!(typeof JSON === 'object' && JSON.stringify);
// Raven can run in contexts where there's no document (react-native)
this._hasDocument = !isUndefined(_document);
this._hasNavigator = !isUndefined(_navigator);
this._lastCapturedException = null;
this._lastData = null;
this._lastEventId = null;
this._globalServer = null;
this._globalKey = null;
this._globalProject = null;
this._globalContext = {};
this._globalOptions = {
// SENTRY_RELEASE can be injected by https://github.com/getsentry/sentry-webpack-plugin
release: _window.SENTRY_RELEASE && _window.SENTRY_RELEASE.id,
logger: 'javascript',
ignoreErrors: [],
ignoreUrls: [],
whitelistUrls: [],
includePaths: [],
headers: null,
collectWindowErrors: true,
captureUnhandledRejections: true,
maxMessageLength: 0,
// By default, truncates URL values to 250 chars
maxUrlLength: 250,
stackTraceLimit: 50,
autoBreadcrumbs: true,
instrument: true,
sampleRate: 1,
sanitizeKeys: []
};
this._fetchDefaults = {
method: 'POST',
// Despite all stars in the sky saying that Edge supports old draft syntax, aka 'never', 'always', 'origin' and 'default
// https://caniuse.com/#feat=referrer-policy
// It doesn't. And it throw exception instead of ignoring this parameter...
// REF: https://github.com/getsentry/raven-js/issues/1233
referrerPolicy: supportsReferrerPolicy() ? 'origin' : ''
};
this._ignoreOnError = 0;
this._isRavenInstalled = false;
this._originalErrorStackTraceLimit = Error.stackTraceLimit;
// capture references to window.console *and* all its methods first
// before the console plugin has a chance to monkey patch
this._originalConsole = _window.console || {};
this._originalConsoleMethods = {};
this._plugins = [];
this._startTime = now();
this._wrappedBuiltIns = [];
this._breadcrumbs = [];
this._lastCapturedEvent = null;
this._keypressTimeout;
this._location = _window.location;
this._lastHref = this._location && this._location.href;
this._resetBackoff();
// eslint-disable-next-line guard-for-in
for (var method in this._originalConsole) {
this._originalConsoleMethods[method] = this._originalConsole[method];
}
}
|
javascript
|
function Raven() {
this._hasJSON = !!(typeof JSON === 'object' && JSON.stringify);
// Raven can run in contexts where there's no document (react-native)
this._hasDocument = !isUndefined(_document);
this._hasNavigator = !isUndefined(_navigator);
this._lastCapturedException = null;
this._lastData = null;
this._lastEventId = null;
this._globalServer = null;
this._globalKey = null;
this._globalProject = null;
this._globalContext = {};
this._globalOptions = {
// SENTRY_RELEASE can be injected by https://github.com/getsentry/sentry-webpack-plugin
release: _window.SENTRY_RELEASE && _window.SENTRY_RELEASE.id,
logger: 'javascript',
ignoreErrors: [],
ignoreUrls: [],
whitelistUrls: [],
includePaths: [],
headers: null,
collectWindowErrors: true,
captureUnhandledRejections: true,
maxMessageLength: 0,
// By default, truncates URL values to 250 chars
maxUrlLength: 250,
stackTraceLimit: 50,
autoBreadcrumbs: true,
instrument: true,
sampleRate: 1,
sanitizeKeys: []
};
this._fetchDefaults = {
method: 'POST',
// Despite all stars in the sky saying that Edge supports old draft syntax, aka 'never', 'always', 'origin' and 'default
// https://caniuse.com/#feat=referrer-policy
// It doesn't. And it throw exception instead of ignoring this parameter...
// REF: https://github.com/getsentry/raven-js/issues/1233
referrerPolicy: supportsReferrerPolicy() ? 'origin' : ''
};
this._ignoreOnError = 0;
this._isRavenInstalled = false;
this._originalErrorStackTraceLimit = Error.stackTraceLimit;
// capture references to window.console *and* all its methods first
// before the console plugin has a chance to monkey patch
this._originalConsole = _window.console || {};
this._originalConsoleMethods = {};
this._plugins = [];
this._startTime = now();
this._wrappedBuiltIns = [];
this._breadcrumbs = [];
this._lastCapturedEvent = null;
this._keypressTimeout;
this._location = _window.location;
this._lastHref = this._location && this._location.href;
this._resetBackoff();
// eslint-disable-next-line guard-for-in
for (var method in this._originalConsole) {
this._originalConsoleMethods[method] = this._originalConsole[method];
}
}
|
[
"function",
"Raven",
"(",
")",
"{",
"this",
".",
"_hasJSON",
"=",
"!",
"!",
"(",
"typeof",
"JSON",
"===",
"'object'",
"&&",
"JSON",
".",
"stringify",
")",
";",
"this",
".",
"_hasDocument",
"=",
"!",
"isUndefined",
"(",
"_document",
")",
";",
"this",
".",
"_hasNavigator",
"=",
"!",
"isUndefined",
"(",
"_navigator",
")",
";",
"this",
".",
"_lastCapturedException",
"=",
"null",
";",
"this",
".",
"_lastData",
"=",
"null",
";",
"this",
".",
"_lastEventId",
"=",
"null",
";",
"this",
".",
"_globalServer",
"=",
"null",
";",
"this",
".",
"_globalKey",
"=",
"null",
";",
"this",
".",
"_globalProject",
"=",
"null",
";",
"this",
".",
"_globalContext",
"=",
"{",
"}",
";",
"this",
".",
"_globalOptions",
"=",
"{",
"release",
":",
"_window",
".",
"SENTRY_RELEASE",
"&&",
"_window",
".",
"SENTRY_RELEASE",
".",
"id",
",",
"logger",
":",
"'javascript'",
",",
"ignoreErrors",
":",
"[",
"]",
",",
"ignoreUrls",
":",
"[",
"]",
",",
"whitelistUrls",
":",
"[",
"]",
",",
"includePaths",
":",
"[",
"]",
",",
"headers",
":",
"null",
",",
"collectWindowErrors",
":",
"true",
",",
"captureUnhandledRejections",
":",
"true",
",",
"maxMessageLength",
":",
"0",
",",
"maxUrlLength",
":",
"250",
",",
"stackTraceLimit",
":",
"50",
",",
"autoBreadcrumbs",
":",
"true",
",",
"instrument",
":",
"true",
",",
"sampleRate",
":",
"1",
",",
"sanitizeKeys",
":",
"[",
"]",
"}",
";",
"this",
".",
"_fetchDefaults",
"=",
"{",
"method",
":",
"'POST'",
",",
"referrerPolicy",
":",
"supportsReferrerPolicy",
"(",
")",
"?",
"'origin'",
":",
"''",
"}",
";",
"this",
".",
"_ignoreOnError",
"=",
"0",
";",
"this",
".",
"_isRavenInstalled",
"=",
"false",
";",
"this",
".",
"_originalErrorStackTraceLimit",
"=",
"Error",
".",
"stackTraceLimit",
";",
"this",
".",
"_originalConsole",
"=",
"_window",
".",
"console",
"||",
"{",
"}",
";",
"this",
".",
"_originalConsoleMethods",
"=",
"{",
"}",
";",
"this",
".",
"_plugins",
"=",
"[",
"]",
";",
"this",
".",
"_startTime",
"=",
"now",
"(",
")",
";",
"this",
".",
"_wrappedBuiltIns",
"=",
"[",
"]",
";",
"this",
".",
"_breadcrumbs",
"=",
"[",
"]",
";",
"this",
".",
"_lastCapturedEvent",
"=",
"null",
";",
"this",
".",
"_keypressTimeout",
";",
"this",
".",
"_location",
"=",
"_window",
".",
"location",
";",
"this",
".",
"_lastHref",
"=",
"this",
".",
"_location",
"&&",
"this",
".",
"_location",
".",
"href",
";",
"this",
".",
"_resetBackoff",
"(",
")",
";",
"for",
"(",
"var",
"method",
"in",
"this",
".",
"_originalConsole",
")",
"{",
"this",
".",
"_originalConsoleMethods",
"[",
"method",
"]",
"=",
"this",
".",
"_originalConsole",
"[",
"method",
"]",
";",
"}",
"}"
] |
First, check for JSON support If there is no JSON, we no-op the core features of Raven since JSON is required to encode the payload
|
[
"First",
"check",
"for",
"JSON",
"support",
"If",
"there",
"is",
"no",
"JSON",
"we",
"no",
"-",
"op",
"the",
"core",
"features",
"of",
"Raven",
"since",
"JSON",
"is",
"required",
"to",
"encode",
"the",
"payload"
] |
a872223343fecf7364473b78bede937f1eb57bd0
|
https://github.com/getsentry/sentry-javascript/blob/a872223343fecf7364473b78bede937f1eb57bd0/packages/raven-js/src/raven.js#L67-L128
|
train
|
getsentry/sentry-javascript
|
packages/raven-js/src/raven.js
|
function() {
TraceKit.report.uninstall();
this._detachPromiseRejectionHandler();
this._unpatchFunctionToString();
this._restoreBuiltIns();
this._restoreConsole();
Error.stackTraceLimit = this._originalErrorStackTraceLimit;
this._isRavenInstalled = false;
return this;
}
|
javascript
|
function() {
TraceKit.report.uninstall();
this._detachPromiseRejectionHandler();
this._unpatchFunctionToString();
this._restoreBuiltIns();
this._restoreConsole();
Error.stackTraceLimit = this._originalErrorStackTraceLimit;
this._isRavenInstalled = false;
return this;
}
|
[
"function",
"(",
")",
"{",
"TraceKit",
".",
"report",
".",
"uninstall",
"(",
")",
";",
"this",
".",
"_detachPromiseRejectionHandler",
"(",
")",
";",
"this",
".",
"_unpatchFunctionToString",
"(",
")",
";",
"this",
".",
"_restoreBuiltIns",
"(",
")",
";",
"this",
".",
"_restoreConsole",
"(",
")",
";",
"Error",
".",
"stackTraceLimit",
"=",
"this",
".",
"_originalErrorStackTraceLimit",
";",
"this",
".",
"_isRavenInstalled",
"=",
"false",
";",
"return",
"this",
";",
"}"
] |
Uninstalls the global error handler.
@return {Raven}
|
[
"Uninstalls",
"the",
"global",
"error",
"handler",
"."
] |
a872223343fecf7364473b78bede937f1eb57bd0
|
https://github.com/getsentry/sentry-javascript/blob/a872223343fecf7364473b78bede937f1eb57bd0/packages/raven-js/src/raven.js#L406-L418
|
train
|
|
getsentry/sentry-javascript
|
packages/raven-js/src/raven.js
|
function(ex, options) {
options = objectMerge({trimHeadFrames: 0}, options ? options : {});
if (isErrorEvent(ex) && ex.error) {
// If it is an ErrorEvent with `error` property, extract it to get actual Error
ex = ex.error;
} else if (isDOMError(ex) || isDOMException(ex)) {
// If it is a DOMError or DOMException (which are legacy APIs, but still supported in some browsers)
// then we just extract the name and message, as they don't provide anything else
// https://developer.mozilla.org/en-US/docs/Web/API/DOMError
// https://developer.mozilla.org/en-US/docs/Web/API/DOMException
var name = ex.name || (isDOMError(ex) ? 'DOMError' : 'DOMException');
var message = ex.message ? name + ': ' + ex.message : name;
return this.captureMessage(
message,
objectMerge(options, {
// neither DOMError or DOMException provide stack trace and we most likely wont get it this way as well
// but it's barely any overhead so we may at least try
stacktrace: true,
trimHeadFrames: options.trimHeadFrames + 1
})
);
} else if (isError(ex)) {
// we have a real Error object
ex = ex;
} else if (isPlainObject(ex)) {
// If it is plain Object, serialize it manually and extract options
// This will allow us to group events based on top-level keys
// which is much better than creating new group when any key/value change
options = this._getCaptureExceptionOptionsFromPlainObject(options, ex);
ex = new Error(options.message);
} else {
// If none of previous checks were valid, then it means that
// it's not a DOMError/DOMException
// it's not a plain Object
// it's not a valid ErrorEvent (one with an error property)
// it's not an Error
// So bail out and capture it as a simple message:
return this.captureMessage(
ex,
objectMerge(options, {
stacktrace: true, // if we fall back to captureMessage, default to attempting a new trace
trimHeadFrames: options.trimHeadFrames + 1
})
);
}
// Store the raw exception object for potential debugging and introspection
this._lastCapturedException = ex;
// TraceKit.report will re-raise any exception passed to it,
// which means you have to wrap it in try/catch. Instead, we
// can wrap it here and only re-raise if TraceKit.report
// raises an exception different from the one we asked to
// report on.
try {
var stack = TraceKit.computeStackTrace(ex);
this._handleStackInfo(stack, options);
} catch (ex1) {
if (ex !== ex1) {
throw ex1;
}
}
return this;
}
|
javascript
|
function(ex, options) {
options = objectMerge({trimHeadFrames: 0}, options ? options : {});
if (isErrorEvent(ex) && ex.error) {
// If it is an ErrorEvent with `error` property, extract it to get actual Error
ex = ex.error;
} else if (isDOMError(ex) || isDOMException(ex)) {
// If it is a DOMError or DOMException (which are legacy APIs, but still supported in some browsers)
// then we just extract the name and message, as they don't provide anything else
// https://developer.mozilla.org/en-US/docs/Web/API/DOMError
// https://developer.mozilla.org/en-US/docs/Web/API/DOMException
var name = ex.name || (isDOMError(ex) ? 'DOMError' : 'DOMException');
var message = ex.message ? name + ': ' + ex.message : name;
return this.captureMessage(
message,
objectMerge(options, {
// neither DOMError or DOMException provide stack trace and we most likely wont get it this way as well
// but it's barely any overhead so we may at least try
stacktrace: true,
trimHeadFrames: options.trimHeadFrames + 1
})
);
} else if (isError(ex)) {
// we have a real Error object
ex = ex;
} else if (isPlainObject(ex)) {
// If it is plain Object, serialize it manually and extract options
// This will allow us to group events based on top-level keys
// which is much better than creating new group when any key/value change
options = this._getCaptureExceptionOptionsFromPlainObject(options, ex);
ex = new Error(options.message);
} else {
// If none of previous checks were valid, then it means that
// it's not a DOMError/DOMException
// it's not a plain Object
// it's not a valid ErrorEvent (one with an error property)
// it's not an Error
// So bail out and capture it as a simple message:
return this.captureMessage(
ex,
objectMerge(options, {
stacktrace: true, // if we fall back to captureMessage, default to attempting a new trace
trimHeadFrames: options.trimHeadFrames + 1
})
);
}
// Store the raw exception object for potential debugging and introspection
this._lastCapturedException = ex;
// TraceKit.report will re-raise any exception passed to it,
// which means you have to wrap it in try/catch. Instead, we
// can wrap it here and only re-raise if TraceKit.report
// raises an exception different from the one we asked to
// report on.
try {
var stack = TraceKit.computeStackTrace(ex);
this._handleStackInfo(stack, options);
} catch (ex1) {
if (ex !== ex1) {
throw ex1;
}
}
return this;
}
|
[
"function",
"(",
"ex",
",",
"options",
")",
"{",
"options",
"=",
"objectMerge",
"(",
"{",
"trimHeadFrames",
":",
"0",
"}",
",",
"options",
"?",
"options",
":",
"{",
"}",
")",
";",
"if",
"(",
"isErrorEvent",
"(",
"ex",
")",
"&&",
"ex",
".",
"error",
")",
"{",
"ex",
"=",
"ex",
".",
"error",
";",
"}",
"else",
"if",
"(",
"isDOMError",
"(",
"ex",
")",
"||",
"isDOMException",
"(",
"ex",
")",
")",
"{",
"var",
"name",
"=",
"ex",
".",
"name",
"||",
"(",
"isDOMError",
"(",
"ex",
")",
"?",
"'DOMError'",
":",
"'DOMException'",
")",
";",
"var",
"message",
"=",
"ex",
".",
"message",
"?",
"name",
"+",
"': '",
"+",
"ex",
".",
"message",
":",
"name",
";",
"return",
"this",
".",
"captureMessage",
"(",
"message",
",",
"objectMerge",
"(",
"options",
",",
"{",
"stacktrace",
":",
"true",
",",
"trimHeadFrames",
":",
"options",
".",
"trimHeadFrames",
"+",
"1",
"}",
")",
")",
";",
"}",
"else",
"if",
"(",
"isError",
"(",
"ex",
")",
")",
"{",
"ex",
"=",
"ex",
";",
"}",
"else",
"if",
"(",
"isPlainObject",
"(",
"ex",
")",
")",
"{",
"options",
"=",
"this",
".",
"_getCaptureExceptionOptionsFromPlainObject",
"(",
"options",
",",
"ex",
")",
";",
"ex",
"=",
"new",
"Error",
"(",
"options",
".",
"message",
")",
";",
"}",
"else",
"{",
"return",
"this",
".",
"captureMessage",
"(",
"ex",
",",
"objectMerge",
"(",
"options",
",",
"{",
"stacktrace",
":",
"true",
",",
"trimHeadFrames",
":",
"options",
".",
"trimHeadFrames",
"+",
"1",
"}",
")",
")",
";",
"}",
"this",
".",
"_lastCapturedException",
"=",
"ex",
";",
"try",
"{",
"var",
"stack",
"=",
"TraceKit",
".",
"computeStackTrace",
"(",
"ex",
")",
";",
"this",
".",
"_handleStackInfo",
"(",
"stack",
",",
"options",
")",
";",
"}",
"catch",
"(",
"ex1",
")",
"{",
"if",
"(",
"ex",
"!==",
"ex1",
")",
"{",
"throw",
"ex1",
";",
"}",
"}",
"return",
"this",
";",
"}"
] |
Manually capture an exception and send it over to Sentry
@param {error} ex An exception to be logged
@param {object} options A specific set of options for this error [optional]
@return {Raven}
|
[
"Manually",
"capture",
"an",
"exception",
"and",
"send",
"it",
"over",
"to",
"Sentry"
] |
a872223343fecf7364473b78bede937f1eb57bd0
|
https://github.com/getsentry/sentry-javascript/blob/a872223343fecf7364473b78bede937f1eb57bd0/packages/raven-js/src/raven.js#L468-L534
|
train
|
|
getsentry/sentry-javascript
|
packages/raven-js/src/raven.js
|
function(current) {
var last = this._lastData;
if (
!last ||
current.message !== last.message || // defined for captureMessage
current.transaction !== last.transaction // defined for captureException/onerror
)
return false;
// Stacktrace interface (i.e. from captureMessage)
if (current.stacktrace || last.stacktrace) {
return isSameStacktrace(current.stacktrace, last.stacktrace);
} else if (current.exception || last.exception) {
// Exception interface (i.e. from captureException/onerror)
return isSameException(current.exception, last.exception);
} else if (current.fingerprint || last.fingerprint) {
return Boolean(current.fingerprint && last.fingerprint) &&
JSON.stringify(current.fingerprint) === JSON.stringify(last.fingerprint)
}
return true;
}
|
javascript
|
function(current) {
var last = this._lastData;
if (
!last ||
current.message !== last.message || // defined for captureMessage
current.transaction !== last.transaction // defined for captureException/onerror
)
return false;
// Stacktrace interface (i.e. from captureMessage)
if (current.stacktrace || last.stacktrace) {
return isSameStacktrace(current.stacktrace, last.stacktrace);
} else if (current.exception || last.exception) {
// Exception interface (i.e. from captureException/onerror)
return isSameException(current.exception, last.exception);
} else if (current.fingerprint || last.fingerprint) {
return Boolean(current.fingerprint && last.fingerprint) &&
JSON.stringify(current.fingerprint) === JSON.stringify(last.fingerprint)
}
return true;
}
|
[
"function",
"(",
"current",
")",
"{",
"var",
"last",
"=",
"this",
".",
"_lastData",
";",
"if",
"(",
"!",
"last",
"||",
"current",
".",
"message",
"!==",
"last",
".",
"message",
"||",
"current",
".",
"transaction",
"!==",
"last",
".",
"transaction",
")",
"return",
"false",
";",
"if",
"(",
"current",
".",
"stacktrace",
"||",
"last",
".",
"stacktrace",
")",
"{",
"return",
"isSameStacktrace",
"(",
"current",
".",
"stacktrace",
",",
"last",
".",
"stacktrace",
")",
";",
"}",
"else",
"if",
"(",
"current",
".",
"exception",
"||",
"last",
".",
"exception",
")",
"{",
"return",
"isSameException",
"(",
"current",
".",
"exception",
",",
"last",
".",
"exception",
")",
";",
"}",
"else",
"if",
"(",
"current",
".",
"fingerprint",
"||",
"last",
".",
"fingerprint",
")",
"{",
"return",
"Boolean",
"(",
"current",
".",
"fingerprint",
"&&",
"last",
".",
"fingerprint",
")",
"&&",
"JSON",
".",
"stringify",
"(",
"current",
".",
"fingerprint",
")",
"===",
"JSON",
".",
"stringify",
"(",
"last",
".",
"fingerprint",
")",
"}",
"return",
"true",
";",
"}"
] |
Returns true if the in-process data payload matches the signature
of the previously-sent data
NOTE: This has to be done at this level because TraceKit can generate
data from window.onerror WITHOUT an exception object (IE8, IE9,
other old browsers). This can take the form of an "exception"
data object with a single frame (derived from the onerror args).
|
[
"Returns",
"true",
"if",
"the",
"in",
"-",
"process",
"data",
"payload",
"matches",
"the",
"signature",
"of",
"the",
"previously",
"-",
"sent",
"data"
] |
a872223343fecf7364473b78bede937f1eb57bd0
|
https://github.com/getsentry/sentry-javascript/blob/a872223343fecf7364473b78bede937f1eb57bd0/packages/raven-js/src/raven.js#L1908-L1930
|
train
|
|
getsentry/sentry-javascript
|
packages/browser/src/loader.js
|
function(content) {
// content.e = error
// content.p = promise rejection
// content.f = function call the Sentry
if (
(content.e ||
content.p ||
(content.f && content.f.indexOf('capture') > -1) ||
(content.f && content.f.indexOf('showReportDialog') > -1)) &&
lazy
) {
// We only want to lazy inject/load the sdk bundle if
// an error or promise rejection occured
// OR someone called `capture...` on the SDK
injectSdk(onLoadCallbacks);
}
queue.data.push(content);
}
|
javascript
|
function(content) {
// content.e = error
// content.p = promise rejection
// content.f = function call the Sentry
if (
(content.e ||
content.p ||
(content.f && content.f.indexOf('capture') > -1) ||
(content.f && content.f.indexOf('showReportDialog') > -1)) &&
lazy
) {
// We only want to lazy inject/load the sdk bundle if
// an error or promise rejection occured
// OR someone called `capture...` on the SDK
injectSdk(onLoadCallbacks);
}
queue.data.push(content);
}
|
[
"function",
"(",
"content",
")",
"{",
"if",
"(",
"(",
"content",
".",
"e",
"||",
"content",
".",
"p",
"||",
"(",
"content",
".",
"f",
"&&",
"content",
".",
"f",
".",
"indexOf",
"(",
"'capture'",
")",
">",
"-",
"1",
")",
"||",
"(",
"content",
".",
"f",
"&&",
"content",
".",
"f",
".",
"indexOf",
"(",
"'showReportDialog'",
")",
">",
"-",
"1",
")",
")",
"&&",
"lazy",
")",
"{",
"injectSdk",
"(",
"onLoadCallbacks",
")",
";",
"}",
"queue",
".",
"data",
".",
"push",
"(",
"content",
")",
";",
"}"
] |
Create a namespace and attach function that will store captured exception Because functions are also objects, we can attach the queue itself straight to it and save some bytes
|
[
"Create",
"a",
"namespace",
"and",
"attach",
"function",
"that",
"will",
"store",
"captured",
"exception",
"Because",
"functions",
"are",
"also",
"objects",
"we",
"can",
"attach",
"the",
"queue",
"itself",
"straight",
"to",
"it",
"and",
"save",
"some",
"bytes"
] |
a872223343fecf7364473b78bede937f1eb57bd0
|
https://github.com/getsentry/sentry-javascript/blob/a872223343fecf7364473b78bede937f1eb57bd0/packages/browser/src/loader.js#L29-L46
|
train
|
|
getsentry/sentry-javascript
|
packages/raven-js/scripts/generate-plugin-combinations.js
|
generate
|
function generate(plugins, dest) {
const pluginNames = plugins.map((plugin) => {
return path.basename(plugin, '.js');
});
const pluginCombinations = combine(pluginNames);
pluginCombinations.forEach((pluginCombination) => {
fs.writeFileSync(
path.resolve(dest, `${pluginCombination.join(',')}.js`),
template(pluginCombination),
);
});
}
|
javascript
|
function generate(plugins, dest) {
const pluginNames = plugins.map((plugin) => {
return path.basename(plugin, '.js');
});
const pluginCombinations = combine(pluginNames);
pluginCombinations.forEach((pluginCombination) => {
fs.writeFileSync(
path.resolve(dest, `${pluginCombination.join(',')}.js`),
template(pluginCombination),
);
});
}
|
[
"function",
"generate",
"(",
"plugins",
",",
"dest",
")",
"{",
"const",
"pluginNames",
"=",
"plugins",
".",
"map",
"(",
"(",
"plugin",
")",
"=>",
"{",
"return",
"path",
".",
"basename",
"(",
"plugin",
",",
"'.js'",
")",
";",
"}",
")",
";",
"const",
"pluginCombinations",
"=",
"combine",
"(",
"pluginNames",
")",
";",
"pluginCombinations",
".",
"forEach",
"(",
"(",
"pluginCombination",
")",
"=>",
"{",
"fs",
".",
"writeFileSync",
"(",
"path",
".",
"resolve",
"(",
"dest",
",",
"`",
"${",
"pluginCombination",
".",
"join",
"(",
"','",
")",
"}",
"`",
")",
",",
"template",
"(",
"pluginCombination",
")",
",",
")",
";",
"}",
")",
";",
"}"
] |
Generate all plugin combinations.
@param {array} plugins
@param {string} dest
|
[
"Generate",
"all",
"plugin",
"combinations",
"."
] |
a872223343fecf7364473b78bede937f1eb57bd0
|
https://github.com/getsentry/sentry-javascript/blob/a872223343fecf7364473b78bede937f1eb57bd0/packages/raven-js/scripts/generate-plugin-combinations.js#L46-L59
|
train
|
getsentry/sentry-javascript
|
packages/raven-node/lib/client.js
|
Client
|
function Client(dsn, options) {
if (dsn instanceof Client) return dsn;
var ravenInstance = new Raven();
return ravenInstance.config.apply(ravenInstance, arguments);
}
|
javascript
|
function Client(dsn, options) {
if (dsn instanceof Client) return dsn;
var ravenInstance = new Raven();
return ravenInstance.config.apply(ravenInstance, arguments);
}
|
[
"function",
"Client",
"(",
"dsn",
",",
"options",
")",
"{",
"if",
"(",
"dsn",
"instanceof",
"Client",
")",
"return",
"dsn",
";",
"var",
"ravenInstance",
"=",
"new",
"Raven",
"(",
")",
";",
"return",
"ravenInstance",
".",
"config",
".",
"apply",
"(",
"ravenInstance",
",",
"arguments",
")",
";",
"}"
] |
Maintain old API compat, need to make sure arguments length is preserved
|
[
"Maintain",
"old",
"API",
"compat",
"need",
"to",
"make",
"sure",
"arguments",
"length",
"is",
"preserved"
] |
a872223343fecf7364473b78bede937f1eb57bd0
|
https://github.com/getsentry/sentry-javascript/blob/a872223343fecf7364473b78bede937f1eb57bd0/packages/raven-node/lib/client.js#L662-L666
|
train
|
getsentry/sentry-javascript
|
packages/raven-js/scripts/build.js
|
build
|
async function build(inputOptions, outputOptions) {
const input = Object.assign(
{
plugins: [
commonjs(), // We can remove this plugin if there are no more CommonJS modules
resolve(), // We need this plugin only to build the test script
babel({
exclude: 'node_modules/**'
})
]
},
inputOptions
);
const output = Object.assign(
{
format: 'umd'
},
outputOptions
);
const bundle = await rollup(input);
await bundle.write(output);
}
|
javascript
|
async function build(inputOptions, outputOptions) {
const input = Object.assign(
{
plugins: [
commonjs(), // We can remove this plugin if there are no more CommonJS modules
resolve(), // We need this plugin only to build the test script
babel({
exclude: 'node_modules/**'
})
]
},
inputOptions
);
const output = Object.assign(
{
format: 'umd'
},
outputOptions
);
const bundle = await rollup(input);
await bundle.write(output);
}
|
[
"async",
"function",
"build",
"(",
"inputOptions",
",",
"outputOptions",
")",
"{",
"const",
"input",
"=",
"Object",
".",
"assign",
"(",
"{",
"plugins",
":",
"[",
"commonjs",
"(",
")",
",",
"resolve",
"(",
")",
",",
"babel",
"(",
"{",
"exclude",
":",
"'node_modules/**'",
"}",
")",
"]",
"}",
",",
"inputOptions",
")",
";",
"const",
"output",
"=",
"Object",
".",
"assign",
"(",
"{",
"format",
":",
"'umd'",
"}",
",",
"outputOptions",
")",
";",
"const",
"bundle",
"=",
"await",
"rollup",
"(",
"input",
")",
";",
"await",
"bundle",
".",
"write",
"(",
"output",
")",
";",
"}"
] |
Only needed for test build
Build using rollup.js
@see https://rollupjs.org/#javascript-api
@param inputOptions
@param outputOptions
@returns Promise
|
[
"Only",
"needed",
"for",
"test",
"build",
"Build",
"using",
"rollup",
".",
"js"
] |
a872223343fecf7364473b78bede937f1eb57bd0
|
https://github.com/getsentry/sentry-javascript/blob/a872223343fecf7364473b78bede937f1eb57bd0/packages/raven-js/scripts/build.js#L15-L38
|
train
|
Project-OSRM/osrm-backend
|
scripts/osrm-runner.js
|
ServerDetails
|
function ServerDetails(x) {
if (!(this instanceof ServerDetails)) return new ServerDetails(x);
const v = x.split(':');
this.hostname = (v[0].length > 0) ? v[0] : '';
this.port = (v.length > 1) ? Number(v[1]) : 80;
}
|
javascript
|
function ServerDetails(x) {
if (!(this instanceof ServerDetails)) return new ServerDetails(x);
const v = x.split(':');
this.hostname = (v[0].length > 0) ? v[0] : '';
this.port = (v.length > 1) ? Number(v[1]) : 80;
}
|
[
"function",
"ServerDetails",
"(",
"x",
")",
"{",
"if",
"(",
"!",
"(",
"this",
"instanceof",
"ServerDetails",
")",
")",
"return",
"new",
"ServerDetails",
"(",
"x",
")",
";",
"const",
"v",
"=",
"x",
".",
"split",
"(",
"':'",
")",
";",
"this",
".",
"hostname",
"=",
"(",
"v",
"[",
"0",
"]",
".",
"length",
">",
"0",
")",
"?",
"v",
"[",
"0",
"]",
":",
"''",
";",
"this",
".",
"port",
"=",
"(",
"v",
".",
"length",
">",
"1",
")",
"?",
"Number",
"(",
"v",
"[",
"1",
"]",
")",
":",
"80",
";",
"}"
] |
Command line arguments
|
[
"Command",
"line",
"arguments"
] |
e86d93760f51304940d55d62c0d47f15094d6712
|
https://github.com/Project-OSRM/osrm-backend/blob/e86d93760f51304940d55d62c0d47f15094d6712/scripts/osrm-runner.js#L86-L91
|
train
|
wix/react-native-ui-lib
|
scripts/utils/propTypesHandler.js
|
propTypesDocsHandler
|
function propTypesDocsHandler(documentation, path) {
const propTypesPath = getMemberValuePath(path, 'propTypes');
const docComment = getDocblock(propTypesPath.parent);
const statementPattern = /@.*\:/;
const info = {};
if (docComment) {
const infoRaw = _.split(docComment, '\n');
_.forEach(infoRaw, (statement) => {
if (statement && statementPattern.test(statement)) {
const key = statement.match(statementPattern)[0].slice(1, -1);
info[key] = statement.split(statementPattern)[1].trim();
}
});
}
documentation.set('propsInfo', info);
}
|
javascript
|
function propTypesDocsHandler(documentation, path) {
const propTypesPath = getMemberValuePath(path, 'propTypes');
const docComment = getDocblock(propTypesPath.parent);
const statementPattern = /@.*\:/;
const info = {};
if (docComment) {
const infoRaw = _.split(docComment, '\n');
_.forEach(infoRaw, (statement) => {
if (statement && statementPattern.test(statement)) {
const key = statement.match(statementPattern)[0].slice(1, -1);
info[key] = statement.split(statementPattern)[1].trim();
}
});
}
documentation.set('propsInfo', info);
}
|
[
"function",
"propTypesDocsHandler",
"(",
"documentation",
",",
"path",
")",
"{",
"const",
"propTypesPath",
"=",
"getMemberValuePath",
"(",
"path",
",",
"'propTypes'",
")",
";",
"const",
"docComment",
"=",
"getDocblock",
"(",
"propTypesPath",
".",
"parent",
")",
";",
"const",
"statementPattern",
"=",
"/",
"@.*\\:",
"/",
";",
"const",
"info",
"=",
"{",
"}",
";",
"if",
"(",
"docComment",
")",
"{",
"const",
"infoRaw",
"=",
"_",
".",
"split",
"(",
"docComment",
",",
"'\\n'",
")",
";",
"\\n",
"}",
"_",
".",
"forEach",
"(",
"infoRaw",
",",
"(",
"statement",
")",
"=>",
"{",
"if",
"(",
"statement",
"&&",
"statementPattern",
".",
"test",
"(",
"statement",
")",
")",
"{",
"const",
"key",
"=",
"statement",
".",
"match",
"(",
"statementPattern",
")",
"[",
"0",
"]",
".",
"slice",
"(",
"1",
",",
"-",
"1",
")",
";",
"info",
"[",
"key",
"]",
"=",
"statement",
".",
"split",
"(",
"statementPattern",
")",
"[",
"1",
"]",
".",
"trim",
"(",
")",
";",
"}",
"}",
")",
";",
"}"
] |
Extract info on the component props
|
[
"Extract",
"info",
"on",
"the",
"component",
"props"
] |
439d36c7932bc3cfe574320e8f214a03f988c5ac
|
https://github.com/wix/react-native-ui-lib/blob/439d36c7932bc3cfe574320e8f214a03f988c5ac/scripts/utils/propTypesHandler.js#L10-L26
|
train
|
wuchangming/spy-debugger
|
buildin_modules/weinre/web/client/inspector.js
|
flushQueue
|
function flushQueue()
{
var queued = WebInspector.log.queued;
if (!queued)
return;
for (var i = 0; i < queued.length; ++i)
logMessage(queued[i]);
delete WebInspector.log.queued;
}
|
javascript
|
function flushQueue()
{
var queued = WebInspector.log.queued;
if (!queued)
return;
for (var i = 0; i < queued.length; ++i)
logMessage(queued[i]);
delete WebInspector.log.queued;
}
|
[
"function",
"flushQueue",
"(",
")",
"{",
"var",
"queued",
"=",
"WebInspector",
".",
"log",
".",
"queued",
";",
"if",
"(",
"!",
"queued",
")",
"return",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"queued",
".",
"length",
";",
"++",
"i",
")",
"logMessage",
"(",
"queued",
"[",
"i",
"]",
")",
";",
"delete",
"WebInspector",
".",
"log",
".",
"queued",
";",
"}"
] |
flush the queue of pending messages
|
[
"flush",
"the",
"queue",
"of",
"pending",
"messages"
] |
55c1dda0dff0c44920673711656ddfd7ff03c307
|
https://github.com/wuchangming/spy-debugger/blob/55c1dda0dff0c44920673711656ddfd7ff03c307/buildin_modules/weinre/web/client/inspector.js#L1213-L1223
|
train
|
wuchangming/spy-debugger
|
buildin_modules/weinre/web/client/inspector.js
|
flushQueueIfAvailable
|
function flushQueueIfAvailable()
{
if (!isLogAvailable())
return;
clearInterval(WebInspector.log.interval);
delete WebInspector.log.interval;
flushQueue();
}
|
javascript
|
function flushQueueIfAvailable()
{
if (!isLogAvailable())
return;
clearInterval(WebInspector.log.interval);
delete WebInspector.log.interval;
flushQueue();
}
|
[
"function",
"flushQueueIfAvailable",
"(",
")",
"{",
"if",
"(",
"!",
"isLogAvailable",
"(",
")",
")",
"return",
";",
"clearInterval",
"(",
"WebInspector",
".",
"log",
".",
"interval",
")",
";",
"delete",
"WebInspector",
".",
"log",
".",
"interval",
";",
"flushQueue",
"(",
")",
";",
"}"
] |
flush the queue if it console is available - this function is run on an interval
|
[
"flush",
"the",
"queue",
"if",
"it",
"console",
"is",
"available",
"-",
"this",
"function",
"is",
"run",
"on",
"an",
"interval"
] |
55c1dda0dff0c44920673711656ddfd7ff03c307
|
https://github.com/wuchangming/spy-debugger/blob/55c1dda0dff0c44920673711656ddfd7ff03c307/buildin_modules/weinre/web/client/inspector.js#L1227-L1236
|
train
|
wuchangming/spy-debugger
|
buildin_modules/weinre/web/client/UglifyJS/process.js
|
fixrefs
|
function fixrefs(scope, i) {
// do children first; order shouldn't matter
for (i = scope.children.length; --i >= 0;)
fixrefs(scope.children[i]);
for (i in scope.refs) if (HOP(scope.refs, i)) {
// find origin scope and propagate the reference to origin
for (var origin = scope.has(i), s = scope; s; s = s.parent) {
s.refs[i] = origin;
if (s === origin) break;
}
}
}
|
javascript
|
function fixrefs(scope, i) {
// do children first; order shouldn't matter
for (i = scope.children.length; --i >= 0;)
fixrefs(scope.children[i]);
for (i in scope.refs) if (HOP(scope.refs, i)) {
// find origin scope and propagate the reference to origin
for (var origin = scope.has(i), s = scope; s; s = s.parent) {
s.refs[i] = origin;
if (s === origin) break;
}
}
}
|
[
"function",
"fixrefs",
"(",
"scope",
",",
"i",
")",
"{",
"for",
"(",
"i",
"=",
"scope",
".",
"children",
".",
"length",
";",
"--",
"i",
">=",
"0",
";",
")",
"fixrefs",
"(",
"scope",
".",
"children",
"[",
"i",
"]",
")",
";",
"for",
"(",
"i",
"in",
"scope",
".",
"refs",
")",
"if",
"(",
"HOP",
"(",
"scope",
".",
"refs",
",",
"i",
")",
")",
"{",
"for",
"(",
"var",
"origin",
"=",
"scope",
".",
"has",
"(",
"i",
")",
",",
"s",
"=",
"scope",
";",
"s",
";",
"s",
"=",
"s",
".",
"parent",
")",
"{",
"s",
".",
"refs",
"[",
"i",
"]",
"=",
"origin",
";",
"if",
"(",
"s",
"===",
"origin",
")",
"break",
";",
"}",
"}",
"}"
] |
for referenced names it might be useful to know their origin scope. current_scope here is the toplevel one.
|
[
"for",
"referenced",
"names",
"it",
"might",
"be",
"useful",
"to",
"know",
"their",
"origin",
"scope",
".",
"current_scope",
"here",
"is",
"the",
"toplevel",
"one",
"."
] |
55c1dda0dff0c44920673711656ddfd7ff03c307
|
https://github.com/wuchangming/spy-debugger/blob/55c1dda0dff0c44920673711656ddfd7ff03c307/buildin_modules/weinre/web/client/UglifyJS/process.js#L439-L450
|
train
|
ai/size-limit
|
index.js
|
getSize
|
async function getSize (files, opts) {
if (typeof files === 'string') files = [files]
if (!opts) opts = { }
if (opts.webpack === false) {
let sizes = await Promise.all(files.map(async file => {
let bytes = await readFile(file, 'utf8')
let result = { parsed: bytes.length }
if (opts.running !== false) result.running = await getRunningTime(file)
if (opts.gzip === false) {
result.loading = getLoadingTime(result.parsed)
} else {
result.gzip = await gzipSize(bytes)
result.loading = getLoadingTime(result.gzip)
}
return result
}))
return sizes.reduce(sumSize)
} else {
let config = getConfig(files, opts)
let output = path.join(
config.output.path || process.cwd(), config.output.filename)
let size, running
try {
let stats = await runWebpack(config)
if (opts.running !== false) running = await getRunningTime(output)
if (stats.hasErrors()) {
throw new Error(stats.toString('errors-only'))
}
if (opts.config && stats.stats) {
size = stats.stats
.map(stat => extractSize(stat.toJson(), opts))
.reduce(sumSize)
} else {
size = extractSize(stats.toJson(), opts)
}
} finally {
if (config.output.path && !opts.output) {
await del(config.output.path, { force: true })
}
}
let result = { parsed: size.parsed - WEBPACK_EMPTY_PROJECT_PARSED }
if (opts.running !== false) result.running = running
if (opts.config || opts.gzip === false) {
result.loading = getLoadingTime(result.parsed)
} else {
result.gzip = size.gzip - WEBPACK_EMPTY_PROJECT_GZIP
result.loading = getLoadingTime(result.gzip)
}
return result
}
}
|
javascript
|
async function getSize (files, opts) {
if (typeof files === 'string') files = [files]
if (!opts) opts = { }
if (opts.webpack === false) {
let sizes = await Promise.all(files.map(async file => {
let bytes = await readFile(file, 'utf8')
let result = { parsed: bytes.length }
if (opts.running !== false) result.running = await getRunningTime(file)
if (opts.gzip === false) {
result.loading = getLoadingTime(result.parsed)
} else {
result.gzip = await gzipSize(bytes)
result.loading = getLoadingTime(result.gzip)
}
return result
}))
return sizes.reduce(sumSize)
} else {
let config = getConfig(files, opts)
let output = path.join(
config.output.path || process.cwd(), config.output.filename)
let size, running
try {
let stats = await runWebpack(config)
if (opts.running !== false) running = await getRunningTime(output)
if (stats.hasErrors()) {
throw new Error(stats.toString('errors-only'))
}
if (opts.config && stats.stats) {
size = stats.stats
.map(stat => extractSize(stat.toJson(), opts))
.reduce(sumSize)
} else {
size = extractSize(stats.toJson(), opts)
}
} finally {
if (config.output.path && !opts.output) {
await del(config.output.path, { force: true })
}
}
let result = { parsed: size.parsed - WEBPACK_EMPTY_PROJECT_PARSED }
if (opts.running !== false) result.running = running
if (opts.config || opts.gzip === false) {
result.loading = getLoadingTime(result.parsed)
} else {
result.gzip = size.gzip - WEBPACK_EMPTY_PROJECT_GZIP
result.loading = getLoadingTime(result.gzip)
}
return result
}
}
|
[
"async",
"function",
"getSize",
"(",
"files",
",",
"opts",
")",
"{",
"if",
"(",
"typeof",
"files",
"===",
"'string'",
")",
"files",
"=",
"[",
"files",
"]",
"if",
"(",
"!",
"opts",
")",
"opts",
"=",
"{",
"}",
"if",
"(",
"opts",
".",
"webpack",
"===",
"false",
")",
"{",
"let",
"sizes",
"=",
"await",
"Promise",
".",
"all",
"(",
"files",
".",
"map",
"(",
"async",
"file",
"=>",
"{",
"let",
"bytes",
"=",
"await",
"readFile",
"(",
"file",
",",
"'utf8'",
")",
"let",
"result",
"=",
"{",
"parsed",
":",
"bytes",
".",
"length",
"}",
"if",
"(",
"opts",
".",
"running",
"!==",
"false",
")",
"result",
".",
"running",
"=",
"await",
"getRunningTime",
"(",
"file",
")",
"if",
"(",
"opts",
".",
"gzip",
"===",
"false",
")",
"{",
"result",
".",
"loading",
"=",
"getLoadingTime",
"(",
"result",
".",
"parsed",
")",
"}",
"else",
"{",
"result",
".",
"gzip",
"=",
"await",
"gzipSize",
"(",
"bytes",
")",
"result",
".",
"loading",
"=",
"getLoadingTime",
"(",
"result",
".",
"gzip",
")",
"}",
"return",
"result",
"}",
")",
")",
"return",
"sizes",
".",
"reduce",
"(",
"sumSize",
")",
"}",
"else",
"{",
"let",
"config",
"=",
"getConfig",
"(",
"files",
",",
"opts",
")",
"let",
"output",
"=",
"path",
".",
"join",
"(",
"config",
".",
"output",
".",
"path",
"||",
"process",
".",
"cwd",
"(",
")",
",",
"config",
".",
"output",
".",
"filename",
")",
"let",
"size",
",",
"running",
"try",
"{",
"let",
"stats",
"=",
"await",
"runWebpack",
"(",
"config",
")",
"if",
"(",
"opts",
".",
"running",
"!==",
"false",
")",
"running",
"=",
"await",
"getRunningTime",
"(",
"output",
")",
"if",
"(",
"stats",
".",
"hasErrors",
"(",
")",
")",
"{",
"throw",
"new",
"Error",
"(",
"stats",
".",
"toString",
"(",
"'errors-only'",
")",
")",
"}",
"if",
"(",
"opts",
".",
"config",
"&&",
"stats",
".",
"stats",
")",
"{",
"size",
"=",
"stats",
".",
"stats",
".",
"map",
"(",
"stat",
"=>",
"extractSize",
"(",
"stat",
".",
"toJson",
"(",
")",
",",
"opts",
")",
")",
".",
"reduce",
"(",
"sumSize",
")",
"}",
"else",
"{",
"size",
"=",
"extractSize",
"(",
"stats",
".",
"toJson",
"(",
")",
",",
"opts",
")",
"}",
"}",
"finally",
"{",
"if",
"(",
"config",
".",
"output",
".",
"path",
"&&",
"!",
"opts",
".",
"output",
")",
"{",
"await",
"del",
"(",
"config",
".",
"output",
".",
"path",
",",
"{",
"force",
":",
"true",
"}",
")",
"}",
"}",
"let",
"result",
"=",
"{",
"parsed",
":",
"size",
".",
"parsed",
"-",
"WEBPACK_EMPTY_PROJECT_PARSED",
"}",
"if",
"(",
"opts",
".",
"running",
"!==",
"false",
")",
"result",
".",
"running",
"=",
"running",
"if",
"(",
"opts",
".",
"config",
"||",
"opts",
".",
"gzip",
"===",
"false",
")",
"{",
"result",
".",
"loading",
"=",
"getLoadingTime",
"(",
"result",
".",
"parsed",
")",
"}",
"else",
"{",
"result",
".",
"gzip",
"=",
"size",
".",
"gzip",
"-",
"WEBPACK_EMPTY_PROJECT_GZIP",
"result",
".",
"loading",
"=",
"getLoadingTime",
"(",
"result",
".",
"gzip",
")",
"}",
"return",
"result",
"}",
"}"
] |
Return size of project files with all dependencies and after UglifyJS
and gzip.
@param {string|string[]} files Files to get size.
@param {object} [opts] Extra options.
@param {"server"|"static"|false} [opts.analyzer=false] Show package
content in browser.
@param {boolean} [opts.webpack=true] Pack files by webpack.
@param {boolean} [opts.running=true] Calculate running time.
@param {boolean} [opts.gzip=true] Compress files by gzip.
@param {string} [opts.config] A path to custom webpack config.
@param {string} [opts.bundle] Bundle name for Analyzer mode.
@param {string} [opts.output] A path for output bundle.
@param {string[]} [opts.ignore] Dependencies to be ignored.
@param {string[]} [opts.entry] Webpack entry whose size will be checked.
@return {Promise} Promise with parsed and gzip size of files
@example
const getSize = require('size-limit')
const index = path.join(__dirname, 'index.js')
const extra = path.join(__dirname, 'extra.js')
getSize([index, extra]).then(size => {
if (size.gzip > 1 * 1024 * 1024) {
console.error('Project become bigger than 1MB')
}
})
|
[
"Return",
"size",
"of",
"project",
"files",
"with",
"all",
"dependencies",
"and",
"after",
"UglifyJS",
"and",
"gzip",
"."
] |
0795111fe22771a7e7b82ab95f8e2e43f08dc2cf
|
https://github.com/ai/size-limit/blob/0795111fe22771a7e7b82ab95f8e2e43f08dc2cf/index.js#L212-L266
|
train
|
zeit/now-cli
|
src/commands/inspect.js
|
getEventMetadata
|
function getEventMetadata({ event, payload }) {
if (event === 'state') {
return chalk.bold(payload.value);
}
if (event === 'instance-start' || event === 'instance-stop') {
if (payload.dc != null) {
return chalk.green(`(${payload.dc})`);
}
}
return '';
}
|
javascript
|
function getEventMetadata({ event, payload }) {
if (event === 'state') {
return chalk.bold(payload.value);
}
if (event === 'instance-start' || event === 'instance-stop') {
if (payload.dc != null) {
return chalk.green(`(${payload.dc})`);
}
}
return '';
}
|
[
"function",
"getEventMetadata",
"(",
"{",
"event",
",",
"payload",
"}",
")",
"{",
"if",
"(",
"event",
"===",
"'state'",
")",
"{",
"return",
"chalk",
".",
"bold",
"(",
"payload",
".",
"value",
")",
";",
"}",
"if",
"(",
"event",
"===",
"'instance-start'",
"||",
"event",
"===",
"'instance-stop'",
")",
"{",
"if",
"(",
"payload",
".",
"dc",
"!=",
"null",
")",
"{",
"return",
"chalk",
".",
"green",
"(",
"`",
"${",
"payload",
".",
"dc",
"}",
"`",
")",
";",
"}",
"}",
"return",
"''",
";",
"}"
] |
gets the metadata that should be printed next to each event
|
[
"gets",
"the",
"metadata",
"that",
"should",
"be",
"printed",
"next",
"to",
"each",
"event"
] |
b53d907b745126113bc3e251ac2451088026a363
|
https://github.com/zeit/now-cli/blob/b53d907b745126113bc3e251ac2451088026a363/src/commands/inspect.js#L286-L298
|
train
|
zeit/now-cli
|
src/commands/inspect.js
|
stateString
|
function stateString(s) {
switch (s) {
case 'INITIALIZING':
return chalk.yellow(s);
case 'ERROR':
return chalk.red(s);
case 'READY':
return s;
default:
return chalk.gray('UNKNOWN');
}
}
|
javascript
|
function stateString(s) {
switch (s) {
case 'INITIALIZING':
return chalk.yellow(s);
case 'ERROR':
return chalk.red(s);
case 'READY':
return s;
default:
return chalk.gray('UNKNOWN');
}
}
|
[
"function",
"stateString",
"(",
"s",
")",
"{",
"switch",
"(",
"s",
")",
"{",
"case",
"'INITIALIZING'",
":",
"return",
"chalk",
".",
"yellow",
"(",
"s",
")",
";",
"case",
"'ERROR'",
":",
"return",
"chalk",
".",
"red",
"(",
"s",
")",
";",
"case",
"'READY'",
":",
"return",
"s",
";",
"default",
":",
"return",
"chalk",
".",
"gray",
"(",
"'UNKNOWN'",
")",
";",
"}",
"}"
] |
renders the state string
|
[
"renders",
"the",
"state",
"string"
] |
b53d907b745126113bc3e251ac2451088026a363
|
https://github.com/zeit/now-cli/blob/b53d907b745126113bc3e251ac2451088026a363/src/commands/inspect.js#L309-L323
|
train
|
zeit/now-cli
|
src/commands/list.js
|
filterUniqueApps
|
function filterUniqueApps() {
const uniqueApps = new Set();
return function uniqueAppFilter([appName]) {
if (uniqueApps.has(appName)) {
return false;
}
uniqueApps.add(appName);
return true;
};
}
|
javascript
|
function filterUniqueApps() {
const uniqueApps = new Set();
return function uniqueAppFilter([appName]) {
if (uniqueApps.has(appName)) {
return false;
}
uniqueApps.add(appName);
return true;
};
}
|
[
"function",
"filterUniqueApps",
"(",
")",
"{",
"const",
"uniqueApps",
"=",
"new",
"Set",
"(",
")",
";",
"return",
"function",
"uniqueAppFilter",
"(",
"[",
"appName",
"]",
")",
"{",
"if",
"(",
"uniqueApps",
".",
"has",
"(",
"appName",
")",
")",
"{",
"return",
"false",
";",
"}",
"uniqueApps",
".",
"add",
"(",
"appName",
")",
";",
"return",
"true",
";",
"}",
";",
"}"
] |
filters only one deployment per app, so that the user doesn't see so many deployments at once. this mode can be bypassed by supplying an app name
|
[
"filters",
"only",
"one",
"deployment",
"per",
"app",
"so",
"that",
"the",
"user",
"doesn",
"t",
"see",
"so",
"many",
"deployments",
"at",
"once",
".",
"this",
"mode",
"can",
"be",
"bypassed",
"by",
"supplying",
"an",
"app",
"name"
] |
b53d907b745126113bc3e251ac2451088026a363
|
https://github.com/zeit/now-cli/blob/b53d907b745126113bc3e251ac2451088026a363/src/commands/list.js#L337-L346
|
train
|
zeit/now-cli
|
src/util/hash.js
|
hashes
|
async function hashes(files) {
const map = new Map();
await Promise.all(
files.map(async name => {
const data = await fs.promises.readFile(name);
const h = hash(data);
const entry = map.get(h);
if (entry) {
entry.names.push(name);
} else {
map.set(hash(data), { names: [name], data });
}
})
);
return map;
}
|
javascript
|
async function hashes(files) {
const map = new Map();
await Promise.all(
files.map(async name => {
const data = await fs.promises.readFile(name);
const h = hash(data);
const entry = map.get(h);
if (entry) {
entry.names.push(name);
} else {
map.set(hash(data), { names: [name], data });
}
})
);
return map;
}
|
[
"async",
"function",
"hashes",
"(",
"files",
")",
"{",
"const",
"map",
"=",
"new",
"Map",
"(",
")",
";",
"await",
"Promise",
".",
"all",
"(",
"files",
".",
"map",
"(",
"async",
"name",
"=>",
"{",
"const",
"data",
"=",
"await",
"fs",
".",
"promises",
".",
"readFile",
"(",
"name",
")",
";",
"const",
"h",
"=",
"hash",
"(",
"data",
")",
";",
"const",
"entry",
"=",
"map",
".",
"get",
"(",
"h",
")",
";",
"if",
"(",
"entry",
")",
"{",
"entry",
".",
"names",
".",
"push",
"(",
"name",
")",
";",
"}",
"else",
"{",
"map",
".",
"set",
"(",
"hash",
"(",
"data",
")",
",",
"{",
"names",
":",
"[",
"name",
"]",
",",
"data",
"}",
")",
";",
"}",
"}",
")",
")",
";",
"return",
"map",
";",
"}"
] |
Computes hashes for the contents of each file given.
@param {Array} of {String} full paths
@return {Map}
|
[
"Computes",
"hashes",
"for",
"the",
"contents",
"of",
"each",
"file",
"given",
"."
] |
b53d907b745126113bc3e251ac2451088026a363
|
https://github.com/zeit/now-cli/blob/b53d907b745126113bc3e251ac2451088026a363/src/util/hash.js#L14-L31
|
train
|
Freeboard/freeboard
|
js/freeboard.thirdparty.js
|
function( element ) {
// if the element is already wrapped, return it
if ( element.parent().is( ".ui-effects-wrapper" )) {
return element.parent();
}
// wrap the element
var props = {
width: element.outerWidth(true),
height: element.outerHeight(true),
"float": element.css( "float" )
},
wrapper = $( "<div></div>" )
.addClass( "ui-effects-wrapper" )
.css({
fontSize: "100%",
background: "transparent",
border: "none",
margin: 0,
padding: 0
}),
// Store the size in case width/height are defined in % - Fixes #5245
size = {
width: element.width(),
height: element.height()
},
active = document.activeElement;
// support: Firefox
// Firefox incorrectly exposes anonymous content
// https://bugzilla.mozilla.org/show_bug.cgi?id=561664
try {
active.id;
} catch( e ) {
active = document.body;
}
element.wrap( wrapper );
// Fixes #7595 - Elements lose focus when wrapped.
if ( element[ 0 ] === active || $.contains( element[ 0 ], active ) ) {
$( active ).focus();
}
wrapper = element.parent(); //Hotfix for jQuery 1.4 since some change in wrap() seems to actually lose the reference to the wrapped element
// transfer positioning properties to the wrapper
if ( element.css( "position" ) === "static" ) {
wrapper.css({ position: "relative" });
element.css({ position: "relative" });
} else {
$.extend( props, {
position: element.css( "position" ),
zIndex: element.css( "z-index" )
});
$.each([ "top", "left", "bottom", "right" ], function(i, pos) {
props[ pos ] = element.css( pos );
if ( isNaN( parseInt( props[ pos ], 10 ) ) ) {
props[ pos ] = "auto";
}
});
element.css({
position: "relative",
top: 0,
left: 0,
right: "auto",
bottom: "auto"
});
}
element.css(size);
return wrapper.css( props ).show();
}
|
javascript
|
function( element ) {
// if the element is already wrapped, return it
if ( element.parent().is( ".ui-effects-wrapper" )) {
return element.parent();
}
// wrap the element
var props = {
width: element.outerWidth(true),
height: element.outerHeight(true),
"float": element.css( "float" )
},
wrapper = $( "<div></div>" )
.addClass( "ui-effects-wrapper" )
.css({
fontSize: "100%",
background: "transparent",
border: "none",
margin: 0,
padding: 0
}),
// Store the size in case width/height are defined in % - Fixes #5245
size = {
width: element.width(),
height: element.height()
},
active = document.activeElement;
// support: Firefox
// Firefox incorrectly exposes anonymous content
// https://bugzilla.mozilla.org/show_bug.cgi?id=561664
try {
active.id;
} catch( e ) {
active = document.body;
}
element.wrap( wrapper );
// Fixes #7595 - Elements lose focus when wrapped.
if ( element[ 0 ] === active || $.contains( element[ 0 ], active ) ) {
$( active ).focus();
}
wrapper = element.parent(); //Hotfix for jQuery 1.4 since some change in wrap() seems to actually lose the reference to the wrapped element
// transfer positioning properties to the wrapper
if ( element.css( "position" ) === "static" ) {
wrapper.css({ position: "relative" });
element.css({ position: "relative" });
} else {
$.extend( props, {
position: element.css( "position" ),
zIndex: element.css( "z-index" )
});
$.each([ "top", "left", "bottom", "right" ], function(i, pos) {
props[ pos ] = element.css( pos );
if ( isNaN( parseInt( props[ pos ], 10 ) ) ) {
props[ pos ] = "auto";
}
});
element.css({
position: "relative",
top: 0,
left: 0,
right: "auto",
bottom: "auto"
});
}
element.css(size);
return wrapper.css( props ).show();
}
|
[
"function",
"(",
"element",
")",
"{",
"if",
"(",
"element",
".",
"parent",
"(",
")",
".",
"is",
"(",
"\".ui-effects-wrapper\"",
")",
")",
"{",
"return",
"element",
".",
"parent",
"(",
")",
";",
"}",
"var",
"props",
"=",
"{",
"width",
":",
"element",
".",
"outerWidth",
"(",
"true",
")",
",",
"height",
":",
"element",
".",
"outerHeight",
"(",
"true",
")",
",",
"\"float\"",
":",
"element",
".",
"css",
"(",
"\"float\"",
")",
"}",
",",
"wrapper",
"=",
"$",
"(",
"\"<div></div>\"",
")",
".",
"addClass",
"(",
"\"ui-effects-wrapper\"",
")",
".",
"css",
"(",
"{",
"fontSize",
":",
"\"100%\"",
",",
"background",
":",
"\"transparent\"",
",",
"border",
":",
"\"none\"",
",",
"margin",
":",
"0",
",",
"padding",
":",
"0",
"}",
")",
",",
"size",
"=",
"{",
"width",
":",
"element",
".",
"width",
"(",
")",
",",
"height",
":",
"element",
".",
"height",
"(",
")",
"}",
",",
"active",
"=",
"document",
".",
"activeElement",
";",
"try",
"{",
"active",
".",
"id",
";",
"}",
"catch",
"(",
"e",
")",
"{",
"active",
"=",
"document",
".",
"body",
";",
"}",
"element",
".",
"wrap",
"(",
"wrapper",
")",
";",
"if",
"(",
"element",
"[",
"0",
"]",
"===",
"active",
"||",
"$",
".",
"contains",
"(",
"element",
"[",
"0",
"]",
",",
"active",
")",
")",
"{",
"$",
"(",
"active",
")",
".",
"focus",
"(",
")",
";",
"}",
"wrapper",
"=",
"element",
".",
"parent",
"(",
")",
";",
"if",
"(",
"element",
".",
"css",
"(",
"\"position\"",
")",
"===",
"\"static\"",
")",
"{",
"wrapper",
".",
"css",
"(",
"{",
"position",
":",
"\"relative\"",
"}",
")",
";",
"element",
".",
"css",
"(",
"{",
"position",
":",
"\"relative\"",
"}",
")",
";",
"}",
"else",
"{",
"$",
".",
"extend",
"(",
"props",
",",
"{",
"position",
":",
"element",
".",
"css",
"(",
"\"position\"",
")",
",",
"zIndex",
":",
"element",
".",
"css",
"(",
"\"z-index\"",
")",
"}",
")",
";",
"$",
".",
"each",
"(",
"[",
"\"top\"",
",",
"\"left\"",
",",
"\"bottom\"",
",",
"\"right\"",
"]",
",",
"function",
"(",
"i",
",",
"pos",
")",
"{",
"props",
"[",
"pos",
"]",
"=",
"element",
".",
"css",
"(",
"pos",
")",
";",
"if",
"(",
"isNaN",
"(",
"parseInt",
"(",
"props",
"[",
"pos",
"]",
",",
"10",
")",
")",
")",
"{",
"props",
"[",
"pos",
"]",
"=",
"\"auto\"",
";",
"}",
"}",
")",
";",
"element",
".",
"css",
"(",
"{",
"position",
":",
"\"relative\"",
",",
"top",
":",
"0",
",",
"left",
":",
"0",
",",
"right",
":",
"\"auto\"",
",",
"bottom",
":",
"\"auto\"",
"}",
")",
";",
"}",
"element",
".",
"css",
"(",
"size",
")",
";",
"return",
"wrapper",
".",
"css",
"(",
"props",
")",
".",
"show",
"(",
")",
";",
"}"
] |
Wraps the element around a wrapper that copies position properties
|
[
"Wraps",
"the",
"element",
"around",
"a",
"wrapper",
"that",
"copies",
"position",
"properties"
] |
38789f6e8bd3d04f7d3b2c3427e509d00f2610fc
|
https://github.com/Freeboard/freeboard/blob/38789f6e8bd3d04f7d3b2c3427e509d00f2610fc/js/freeboard.thirdparty.js#L5734-L5807
|
train
|
|
Freeboard/freeboard
|
js/freeboard.thirdparty.js
|
function( value, allowAny ) {
var parsed;
if ( value !== "" ) {
parsed = this._parse( value );
if ( parsed !== null ) {
if ( !allowAny ) {
parsed = this._adjustValue( parsed );
}
value = this._format( parsed );
}
}
this.element.val( value );
this._refresh();
}
|
javascript
|
function( value, allowAny ) {
var parsed;
if ( value !== "" ) {
parsed = this._parse( value );
if ( parsed !== null ) {
if ( !allowAny ) {
parsed = this._adjustValue( parsed );
}
value = this._format( parsed );
}
}
this.element.val( value );
this._refresh();
}
|
[
"function",
"(",
"value",
",",
"allowAny",
")",
"{",
"var",
"parsed",
";",
"if",
"(",
"value",
"!==",
"\"\"",
")",
"{",
"parsed",
"=",
"this",
".",
"_parse",
"(",
"value",
")",
";",
"if",
"(",
"parsed",
"!==",
"null",
")",
"{",
"if",
"(",
"!",
"allowAny",
")",
"{",
"parsed",
"=",
"this",
".",
"_adjustValue",
"(",
"parsed",
")",
";",
"}",
"value",
"=",
"this",
".",
"_format",
"(",
"parsed",
")",
";",
"}",
"}",
"this",
".",
"element",
".",
"val",
"(",
"value",
")",
";",
"this",
".",
"_refresh",
"(",
")",
";",
"}"
] |
update the value without triggering change
|
[
"update",
"the",
"value",
"without",
"triggering",
"change"
] |
38789f6e8bd3d04f7d3b2c3427e509d00f2610fc
|
https://github.com/Freeboard/freeboard/blob/38789f6e8bd3d04f7d3b2c3427e509d00f2610fc/js/freeboard.thirdparty.js#L13730-L13743
|
train
|
|
testing-library/dom-testing-library
|
src/query-helpers.js
|
makeSingleQuery
|
function makeSingleQuery(allQuery, getMultipleError) {
return (container, ...args) => {
const els = allQuery(container, ...args)
if (els.length > 1) {
throw getMultipleElementsFoundError(
getMultipleError(container, ...args),
container,
)
}
return els[0] || null
}
}
|
javascript
|
function makeSingleQuery(allQuery, getMultipleError) {
return (container, ...args) => {
const els = allQuery(container, ...args)
if (els.length > 1) {
throw getMultipleElementsFoundError(
getMultipleError(container, ...args),
container,
)
}
return els[0] || null
}
}
|
[
"function",
"makeSingleQuery",
"(",
"allQuery",
",",
"getMultipleError",
")",
"{",
"return",
"(",
"container",
",",
"...",
"args",
")",
"=>",
"{",
"const",
"els",
"=",
"allQuery",
"(",
"container",
",",
"...",
"args",
")",
"if",
"(",
"els",
".",
"length",
">",
"1",
")",
"{",
"throw",
"getMultipleElementsFoundError",
"(",
"getMultipleError",
"(",
"container",
",",
"...",
"args",
")",
",",
"container",
",",
")",
"}",
"return",
"els",
"[",
"0",
"]",
"||",
"null",
"}",
"}"
] |
this accepts a query function and returns a function which throws an error if more than one elements is returned, otherwise it returns the first element or null
|
[
"this",
"accepts",
"a",
"query",
"function",
"and",
"returns",
"a",
"function",
"which",
"throws",
"an",
"error",
"if",
"more",
"than",
"one",
"elements",
"is",
"returned",
"otherwise",
"it",
"returns",
"the",
"first",
"element",
"or",
"null"
] |
fcb2cbcffb7aff6ecff3be8731168c86eee82ce1
|
https://github.com/testing-library/dom-testing-library/blob/fcb2cbcffb7aff6ecff3be8731168c86eee82ce1/src/query-helpers.js#L68-L79
|
train
|
testing-library/dom-testing-library
|
src/query-helpers.js
|
makeGetAllQuery
|
function makeGetAllQuery(allQuery, getMissingError) {
return (container, ...args) => {
const els = allQuery(container, ...args)
if (!els.length) {
throw getElementError(getMissingError(container, ...args), container)
}
return els
}
}
|
javascript
|
function makeGetAllQuery(allQuery, getMissingError) {
return (container, ...args) => {
const els = allQuery(container, ...args)
if (!els.length) {
throw getElementError(getMissingError(container, ...args), container)
}
return els
}
}
|
[
"function",
"makeGetAllQuery",
"(",
"allQuery",
",",
"getMissingError",
")",
"{",
"return",
"(",
"container",
",",
"...",
"args",
")",
"=>",
"{",
"const",
"els",
"=",
"allQuery",
"(",
"container",
",",
"...",
"args",
")",
"if",
"(",
"!",
"els",
".",
"length",
")",
"{",
"throw",
"getElementError",
"(",
"getMissingError",
"(",
"container",
",",
"...",
"args",
")",
",",
"container",
")",
"}",
"return",
"els",
"}",
"}"
] |
this accepts a query function and returns a function which throws an error if an empty list of elements is returned
|
[
"this",
"accepts",
"a",
"query",
"function",
"and",
"returns",
"a",
"function",
"which",
"throws",
"an",
"error",
"if",
"an",
"empty",
"list",
"of",
"elements",
"is",
"returned"
] |
fcb2cbcffb7aff6ecff3be8731168c86eee82ce1
|
https://github.com/testing-library/dom-testing-library/blob/fcb2cbcffb7aff6ecff3be8731168c86eee82ce1/src/query-helpers.js#L83-L91
|
train
|
testing-library/dom-testing-library
|
src/query-helpers.js
|
makeFindQuery
|
function makeFindQuery(getter) {
return (container, text, options, waitForElementOptions) =>
waitForElement(
() => getter(container, text, options),
waitForElementOptions,
)
}
|
javascript
|
function makeFindQuery(getter) {
return (container, text, options, waitForElementOptions) =>
waitForElement(
() => getter(container, text, options),
waitForElementOptions,
)
}
|
[
"function",
"makeFindQuery",
"(",
"getter",
")",
"{",
"return",
"(",
"container",
",",
"text",
",",
"options",
",",
"waitForElementOptions",
")",
"=>",
"waitForElement",
"(",
"(",
")",
"=>",
"getter",
"(",
"container",
",",
"text",
",",
"options",
")",
",",
"waitForElementOptions",
",",
")",
"}"
] |
this accepts a getter query function and returns a function which calls waitForElement and passing a function which invokes the getter.
|
[
"this",
"accepts",
"a",
"getter",
"query",
"function",
"and",
"returns",
"a",
"function",
"which",
"calls",
"waitForElement",
"and",
"passing",
"a",
"function",
"which",
"invokes",
"the",
"getter",
"."
] |
fcb2cbcffb7aff6ecff3be8731168c86eee82ce1
|
https://github.com/testing-library/dom-testing-library/blob/fcb2cbcffb7aff6ecff3be8731168c86eee82ce1/src/query-helpers.js#L95-L101
|
train
|
testing-library/dom-testing-library
|
src/matches.js
|
makeNormalizer
|
function makeNormalizer({trim, collapseWhitespace, normalizer}) {
if (normalizer) {
// User has specified a custom normalizer
if (
typeof trim !== 'undefined' ||
typeof collapseWhitespace !== 'undefined'
) {
// They've also specified a value for trim or collapseWhitespace
throw new Error(
'trim and collapseWhitespace are not supported with a normalizer. ' +
'If you want to use the default trim and collapseWhitespace logic in your normalizer, ' +
'use "getDefaultNormalizer({trim, collapseWhitespace})" and compose that into your normalizer',
)
}
return normalizer
} else {
// No custom normalizer specified. Just use default.
return getDefaultNormalizer({trim, collapseWhitespace})
}
}
|
javascript
|
function makeNormalizer({trim, collapseWhitespace, normalizer}) {
if (normalizer) {
// User has specified a custom normalizer
if (
typeof trim !== 'undefined' ||
typeof collapseWhitespace !== 'undefined'
) {
// They've also specified a value for trim or collapseWhitespace
throw new Error(
'trim and collapseWhitespace are not supported with a normalizer. ' +
'If you want to use the default trim and collapseWhitespace logic in your normalizer, ' +
'use "getDefaultNormalizer({trim, collapseWhitespace})" and compose that into your normalizer',
)
}
return normalizer
} else {
// No custom normalizer specified. Just use default.
return getDefaultNormalizer({trim, collapseWhitespace})
}
}
|
[
"function",
"makeNormalizer",
"(",
"{",
"trim",
",",
"collapseWhitespace",
",",
"normalizer",
"}",
")",
"{",
"if",
"(",
"normalizer",
")",
"{",
"if",
"(",
"typeof",
"trim",
"!==",
"'undefined'",
"||",
"typeof",
"collapseWhitespace",
"!==",
"'undefined'",
")",
"{",
"throw",
"new",
"Error",
"(",
"'trim and collapseWhitespace are not supported with a normalizer. '",
"+",
"'If you want to use the default trim and collapseWhitespace logic in your normalizer, '",
"+",
"'use \"getDefaultNormalizer({trim, collapseWhitespace})\" and compose that into your normalizer'",
",",
")",
"}",
"return",
"normalizer",
"}",
"else",
"{",
"return",
"getDefaultNormalizer",
"(",
"{",
"trim",
",",
"collapseWhitespace",
"}",
")",
"}",
"}"
] |
Constructs a normalizer to pass to functions in matches.js
@param {boolean|undefined} trim The user-specified value for `trim`, without
any defaulting having been applied
@param {boolean|undefined} collapseWhitespace The user-specified value for
`collapseWhitespace`, without any defaulting having been applied
@param {Function|undefined} normalizer The user-specified normalizer
@returns {Function} A normalizer
|
[
"Constructs",
"a",
"normalizer",
"to",
"pass",
"to",
"functions",
"in",
"matches",
".",
"js"
] |
fcb2cbcffb7aff6ecff3be8731168c86eee82ce1
|
https://github.com/testing-library/dom-testing-library/blob/fcb2cbcffb7aff6ecff3be8731168c86eee82ce1/src/matches.js#L51-L71
|
train
|
muaz-khan/RecordRTC
|
RecordRTC.js
|
function(arrayOfWebPImages) {
config.advertisement = [];
var length = arrayOfWebPImages.length;
for (var i = 0; i < length; i++) {
config.advertisement.push({
duration: i,
image: arrayOfWebPImages[i]
});
}
}
|
javascript
|
function(arrayOfWebPImages) {
config.advertisement = [];
var length = arrayOfWebPImages.length;
for (var i = 0; i < length; i++) {
config.advertisement.push({
duration: i,
image: arrayOfWebPImages[i]
});
}
}
|
[
"function",
"(",
"arrayOfWebPImages",
")",
"{",
"config",
".",
"advertisement",
"=",
"[",
"]",
";",
"var",
"length",
"=",
"arrayOfWebPImages",
".",
"length",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"length",
";",
"i",
"++",
")",
"{",
"config",
".",
"advertisement",
".",
"push",
"(",
"{",
"duration",
":",
"i",
",",
"image",
":",
"arrayOfWebPImages",
"[",
"i",
"]",
"}",
")",
";",
"}",
"}"
] |
This method appends an array of webp images to the recorded video-blob. It takes an "array" object.
@type {Array.<Array>}
@param {Array} arrayOfWebPImages - Array of webp images.
@method
@memberof RecordRTC
@instance
@todo This method should be deprecated.
@example
var arrayOfWebPImages = [];
arrayOfWebPImages.push({
duration: index,
image: 'data:image/webp;base64,...'
});
recorder.setAdvertisementArray(arrayOfWebPImages);
|
[
"This",
"method",
"appends",
"an",
"array",
"of",
"webp",
"images",
"to",
"the",
"recorded",
"video",
"-",
"blob",
".",
"It",
"takes",
"an",
"array",
"object",
"."
] |
3c6bad427b9da35c1cf617199ed13dda056c38ba
|
https://github.com/muaz-khan/RecordRTC/blob/3c6bad427b9da35c1cf617199ed13dda056c38ba/RecordRTC.js#L606-L616
|
train
|
|
muaz-khan/RecordRTC
|
RecordRTC.js
|
function() {
if (mediaRecorder && typeof mediaRecorder.clearRecordedData === 'function') {
mediaRecorder.clearRecordedData();
}
mediaRecorder = null;
setState('inactive');
self.blob = null;
}
|
javascript
|
function() {
if (mediaRecorder && typeof mediaRecorder.clearRecordedData === 'function') {
mediaRecorder.clearRecordedData();
}
mediaRecorder = null;
setState('inactive');
self.blob = null;
}
|
[
"function",
"(",
")",
"{",
"if",
"(",
"mediaRecorder",
"&&",
"typeof",
"mediaRecorder",
".",
"clearRecordedData",
"===",
"'function'",
")",
"{",
"mediaRecorder",
".",
"clearRecordedData",
"(",
")",
";",
"}",
"mediaRecorder",
"=",
"null",
";",
"setState",
"(",
"'inactive'",
")",
";",
"self",
".",
"blob",
"=",
"null",
";",
"}"
] |
This method resets the recorder. So that you can reuse single recorder instance many times.
@method
@memberof RecordRTC
@instance
@example
recorder.reset();
recorder.startRecording();
|
[
"This",
"method",
"resets",
"the",
"recorder",
".",
"So",
"that",
"you",
"can",
"reuse",
"single",
"recorder",
"instance",
"many",
"times",
"."
] |
3c6bad427b9da35c1cf617199ed13dda056c38ba
|
https://github.com/muaz-khan/RecordRTC/blob/3c6bad427b9da35c1cf617199ed13dda056c38ba/RecordRTC.js#L683-L690
|
train
|
|
muaz-khan/RecordRTC
|
RecordRTC.js
|
function() {
var self = this;
if (typeof indexedDB === 'undefined' || typeof indexedDB.open === 'undefined') {
console.error('IndexedDB API are not available in this browser.');
return;
}
var dbVersion = 1;
var dbName = this.dbName || location.href.replace(/\/|:|#|%|\.|\[|\]/g, ''),
db;
var request = indexedDB.open(dbName, dbVersion);
function createObjectStore(dataBase) {
dataBase.createObjectStore(self.dataStoreName);
}
function putInDB() {
var transaction = db.transaction([self.dataStoreName], 'readwrite');
if (self.videoBlob) {
transaction.objectStore(self.dataStoreName).put(self.videoBlob, 'videoBlob');
}
if (self.gifBlob) {
transaction.objectStore(self.dataStoreName).put(self.gifBlob, 'gifBlob');
}
if (self.audioBlob) {
transaction.objectStore(self.dataStoreName).put(self.audioBlob, 'audioBlob');
}
function getFromStore(portionName) {
transaction.objectStore(self.dataStoreName).get(portionName).onsuccess = function(event) {
if (self.callback) {
self.callback(event.target.result, portionName);
}
};
}
getFromStore('audioBlob');
getFromStore('videoBlob');
getFromStore('gifBlob');
}
request.onerror = self.onError;
request.onsuccess = function() {
db = request.result;
db.onerror = self.onError;
if (db.setVersion) {
if (db.version !== dbVersion) {
var setVersion = db.setVersion(dbVersion);
setVersion.onsuccess = function() {
createObjectStore(db);
putInDB();
};
} else {
putInDB();
}
} else {
putInDB();
}
};
request.onupgradeneeded = function(event) {
createObjectStore(event.target.result);
};
}
|
javascript
|
function() {
var self = this;
if (typeof indexedDB === 'undefined' || typeof indexedDB.open === 'undefined') {
console.error('IndexedDB API are not available in this browser.');
return;
}
var dbVersion = 1;
var dbName = this.dbName || location.href.replace(/\/|:|#|%|\.|\[|\]/g, ''),
db;
var request = indexedDB.open(dbName, dbVersion);
function createObjectStore(dataBase) {
dataBase.createObjectStore(self.dataStoreName);
}
function putInDB() {
var transaction = db.transaction([self.dataStoreName], 'readwrite');
if (self.videoBlob) {
transaction.objectStore(self.dataStoreName).put(self.videoBlob, 'videoBlob');
}
if (self.gifBlob) {
transaction.objectStore(self.dataStoreName).put(self.gifBlob, 'gifBlob');
}
if (self.audioBlob) {
transaction.objectStore(self.dataStoreName).put(self.audioBlob, 'audioBlob');
}
function getFromStore(portionName) {
transaction.objectStore(self.dataStoreName).get(portionName).onsuccess = function(event) {
if (self.callback) {
self.callback(event.target.result, portionName);
}
};
}
getFromStore('audioBlob');
getFromStore('videoBlob');
getFromStore('gifBlob');
}
request.onerror = self.onError;
request.onsuccess = function() {
db = request.result;
db.onerror = self.onError;
if (db.setVersion) {
if (db.version !== dbVersion) {
var setVersion = db.setVersion(dbVersion);
setVersion.onsuccess = function() {
createObjectStore(db);
putInDB();
};
} else {
putInDB();
}
} else {
putInDB();
}
};
request.onupgradeneeded = function(event) {
createObjectStore(event.target.result);
};
}
|
[
"function",
"(",
")",
"{",
"var",
"self",
"=",
"this",
";",
"if",
"(",
"typeof",
"indexedDB",
"===",
"'undefined'",
"||",
"typeof",
"indexedDB",
".",
"open",
"===",
"'undefined'",
")",
"{",
"console",
".",
"error",
"(",
"'IndexedDB API are not available in this browser.'",
")",
";",
"return",
";",
"}",
"var",
"dbVersion",
"=",
"1",
";",
"var",
"dbName",
"=",
"this",
".",
"dbName",
"||",
"location",
".",
"href",
".",
"replace",
"(",
"/",
"\\/|:|#|%|\\.|\\[|\\]",
"/",
"g",
",",
"''",
")",
",",
"db",
";",
"var",
"request",
"=",
"indexedDB",
".",
"open",
"(",
"dbName",
",",
"dbVersion",
")",
";",
"function",
"createObjectStore",
"(",
"dataBase",
")",
"{",
"dataBase",
".",
"createObjectStore",
"(",
"self",
".",
"dataStoreName",
")",
";",
"}",
"function",
"putInDB",
"(",
")",
"{",
"var",
"transaction",
"=",
"db",
".",
"transaction",
"(",
"[",
"self",
".",
"dataStoreName",
"]",
",",
"'readwrite'",
")",
";",
"if",
"(",
"self",
".",
"videoBlob",
")",
"{",
"transaction",
".",
"objectStore",
"(",
"self",
".",
"dataStoreName",
")",
".",
"put",
"(",
"self",
".",
"videoBlob",
",",
"'videoBlob'",
")",
";",
"}",
"if",
"(",
"self",
".",
"gifBlob",
")",
"{",
"transaction",
".",
"objectStore",
"(",
"self",
".",
"dataStoreName",
")",
".",
"put",
"(",
"self",
".",
"gifBlob",
",",
"'gifBlob'",
")",
";",
"}",
"if",
"(",
"self",
".",
"audioBlob",
")",
"{",
"transaction",
".",
"objectStore",
"(",
"self",
".",
"dataStoreName",
")",
".",
"put",
"(",
"self",
".",
"audioBlob",
",",
"'audioBlob'",
")",
";",
"}",
"function",
"getFromStore",
"(",
"portionName",
")",
"{",
"transaction",
".",
"objectStore",
"(",
"self",
".",
"dataStoreName",
")",
".",
"get",
"(",
"portionName",
")",
".",
"onsuccess",
"=",
"function",
"(",
"event",
")",
"{",
"if",
"(",
"self",
".",
"callback",
")",
"{",
"self",
".",
"callback",
"(",
"event",
".",
"target",
".",
"result",
",",
"portionName",
")",
";",
"}",
"}",
";",
"}",
"getFromStore",
"(",
"'audioBlob'",
")",
";",
"getFromStore",
"(",
"'videoBlob'",
")",
";",
"getFromStore",
"(",
"'gifBlob'",
")",
";",
"}",
"request",
".",
"onerror",
"=",
"self",
".",
"onError",
";",
"request",
".",
"onsuccess",
"=",
"function",
"(",
")",
"{",
"db",
"=",
"request",
".",
"result",
";",
"db",
".",
"onerror",
"=",
"self",
".",
"onError",
";",
"if",
"(",
"db",
".",
"setVersion",
")",
"{",
"if",
"(",
"db",
".",
"version",
"!==",
"dbVersion",
")",
"{",
"var",
"setVersion",
"=",
"db",
".",
"setVersion",
"(",
"dbVersion",
")",
";",
"setVersion",
".",
"onsuccess",
"=",
"function",
"(",
")",
"{",
"createObjectStore",
"(",
"db",
")",
";",
"putInDB",
"(",
")",
";",
"}",
";",
"}",
"else",
"{",
"putInDB",
"(",
")",
";",
"}",
"}",
"else",
"{",
"putInDB",
"(",
")",
";",
"}",
"}",
";",
"request",
".",
"onupgradeneeded",
"=",
"function",
"(",
"event",
")",
"{",
"createObjectStore",
"(",
"event",
".",
"target",
".",
"result",
")",
";",
"}",
";",
"}"
] |
This method must be called once to initialize IndexedDB ObjectStore. Though, it is auto-used internally.
@method
@memberof DiskStorage
@internal
@example
DiskStorage.init();
|
[
"This",
"method",
"must",
"be",
"called",
"once",
"to",
"initialize",
"IndexedDB",
"ObjectStore",
".",
"Though",
"it",
"is",
"auto",
"-",
"used",
"internally",
"."
] |
3c6bad427b9da35c1cf617199ed13dda056c38ba
|
https://github.com/muaz-khan/RecordRTC/blob/3c6bad427b9da35c1cf617199ed13dda056c38ba/RecordRTC.js#L4388-L4456
|
train
|
|
muaz-khan/RecordRTC
|
RecordRTC.js
|
function(config) {
this.audioBlob = config.audioBlob;
this.videoBlob = config.videoBlob;
this.gifBlob = config.gifBlob;
this.init();
return this;
}
|
javascript
|
function(config) {
this.audioBlob = config.audioBlob;
this.videoBlob = config.videoBlob;
this.gifBlob = config.gifBlob;
this.init();
return this;
}
|
[
"function",
"(",
"config",
")",
"{",
"this",
".",
"audioBlob",
"=",
"config",
".",
"audioBlob",
";",
"this",
".",
"videoBlob",
"=",
"config",
".",
"videoBlob",
";",
"this",
".",
"gifBlob",
"=",
"config",
".",
"gifBlob",
";",
"this",
".",
"init",
"(",
")",
";",
"return",
"this",
";",
"}"
] |
This method stores blobs in IndexedDB.
@method
@memberof DiskStorage
@internal
@example
DiskStorage.Store({
audioBlob: yourAudioBlob,
videoBlob: yourVideoBlob,
gifBlob : yourGifBlob
});
|
[
"This",
"method",
"stores",
"blobs",
"in",
"IndexedDB",
"."
] |
3c6bad427b9da35c1cf617199ed13dda056c38ba
|
https://github.com/muaz-khan/RecordRTC/blob/3c6bad427b9da35c1cf617199ed13dda056c38ba/RecordRTC.js#L4487-L4495
|
train
|
|
muaz-khan/RecordRTC
|
WebGL-Recording/vendor/glge-compiled.js
|
getLastNumber
|
function getLastNumber(str){
var retval="";
for (var i=str.length-1;i>=0;--i)
if (str[i]>="0"&&str[i]<="9")
retval=str[i]+retval;
if (retval.length==0) return "0";
return retval;
}
|
javascript
|
function getLastNumber(str){
var retval="";
for (var i=str.length-1;i>=0;--i)
if (str[i]>="0"&&str[i]<="9")
retval=str[i]+retval;
if (retval.length==0) return "0";
return retval;
}
|
[
"function",
"getLastNumber",
"(",
"str",
")",
"{",
"var",
"retval",
"=",
"\"\"",
";",
"for",
"(",
"var",
"i",
"=",
"str",
".",
"length",
"-",
"1",
";",
"i",
">=",
"0",
";",
"--",
"i",
")",
"if",
"(",
"str",
"[",
"i",
"]",
">=",
"\"0\"",
"&&",
"str",
"[",
"i",
"]",
"<=",
"\"9\"",
")",
"retval",
"=",
"str",
"[",
"i",
"]",
"+",
"retval",
";",
"if",
"(",
"retval",
".",
"length",
"==",
"0",
")",
"return",
"\"0\"",
";",
"return",
"retval",
";",
"}"
] |
the exporter is buggy eg VCGLab | MeshLab and does not specify input_set
|
[
"the",
"exporter",
"is",
"buggy",
"eg",
"VCGLab",
"|",
"MeshLab",
"and",
"does",
"not",
"specify",
"input_set"
] |
3c6bad427b9da35c1cf617199ed13dda056c38ba
|
https://github.com/muaz-khan/RecordRTC/blob/3c6bad427b9da35c1cf617199ed13dda056c38ba/WebGL-Recording/vendor/glge-compiled.js#L18122-L18129
|
train
|
statsd/statsd
|
lib/mgmt_console.js
|
existing_stats
|
function existing_stats(stats_type, bucket){
matches = [];
//typical case: one-off, fully qualified
if (bucket in stats_type) {
matches.push(bucket);
}
//special case: match a whole 'folder' (and subfolders) of stats
if (bucket.slice(-2) == ".*") {
var folder = bucket.slice(0,-1);
for (var name in stats_type) {
//check if stat is in bucket, ie~ name starts with folder
if (name.substring(0, folder.length) == folder) {
matches.push(name);
}
}
}
return matches;
}
|
javascript
|
function existing_stats(stats_type, bucket){
matches = [];
//typical case: one-off, fully qualified
if (bucket in stats_type) {
matches.push(bucket);
}
//special case: match a whole 'folder' (and subfolders) of stats
if (bucket.slice(-2) == ".*") {
var folder = bucket.slice(0,-1);
for (var name in stats_type) {
//check if stat is in bucket, ie~ name starts with folder
if (name.substring(0, folder.length) == folder) {
matches.push(name);
}
}
}
return matches;
}
|
[
"function",
"existing_stats",
"(",
"stats_type",
",",
"bucket",
")",
"{",
"matches",
"=",
"[",
"]",
";",
"if",
"(",
"bucket",
"in",
"stats_type",
")",
"{",
"matches",
".",
"push",
"(",
"bucket",
")",
";",
"}",
"if",
"(",
"bucket",
".",
"slice",
"(",
"-",
"2",
")",
"==",
"\".*\"",
")",
"{",
"var",
"folder",
"=",
"bucket",
".",
"slice",
"(",
"0",
",",
"-",
"1",
")",
";",
"for",
"(",
"var",
"name",
"in",
"stats_type",
")",
"{",
"if",
"(",
"name",
".",
"substring",
"(",
"0",
",",
"folder",
".",
"length",
")",
"==",
"folder",
")",
"{",
"matches",
".",
"push",
"(",
"name",
")",
";",
"}",
"}",
"}",
"return",
"matches",
";",
"}"
] |
existing_stats - find fully qualified matches for the requested stats bucket
@param stats_type array of all statistics of this type (eg~ timers) to match
@param bucket string to search on, which can be fully qualified,
or end in a .* to search for a folder, like stats.temp.*
@return array of fully qualified stats that match the specified bucket. if
no matches, an empty array is a valid response
|
[
"existing_stats",
"-",
"find",
"fully",
"qualified",
"matches",
"for",
"the",
"requested",
"stats",
"bucket"
] |
ef8e4d76d76c3a0cf771e3724cf79ea22f3c50d9
|
https://github.com/statsd/statsd/blob/ef8e4d76d76c3a0cf771e3724cf79ea22f3c50d9/lib/mgmt_console.js#L46-L67
|
train
|
statsd/statsd
|
backends/graphite.js
|
Metric
|
function Metric(key, value, ts) {
var m = this;
this.key = key;
this.value = value;
this.ts = ts;
// return a string representation of this metric appropriate
// for sending to the graphite collector. does not include
// a trailing newline.
this.toText = function() {
return m.key + " " + m.value + " " + m.ts;
};
this.toPickle = function() {
return MARK + STRING + '\'' + m.key + '\'\n' + MARK + LONG + m.ts + 'L\n' + STRING + '\'' + m.value + '\'\n' + TUPLE + TUPLE + APPEND;
};
}
|
javascript
|
function Metric(key, value, ts) {
var m = this;
this.key = key;
this.value = value;
this.ts = ts;
// return a string representation of this metric appropriate
// for sending to the graphite collector. does not include
// a trailing newline.
this.toText = function() {
return m.key + " " + m.value + " " + m.ts;
};
this.toPickle = function() {
return MARK + STRING + '\'' + m.key + '\'\n' + MARK + LONG + m.ts + 'L\n' + STRING + '\'' + m.value + '\'\n' + TUPLE + TUPLE + APPEND;
};
}
|
[
"function",
"Metric",
"(",
"key",
",",
"value",
",",
"ts",
")",
"{",
"var",
"m",
"=",
"this",
";",
"this",
".",
"key",
"=",
"key",
";",
"this",
".",
"value",
"=",
"value",
";",
"this",
".",
"ts",
"=",
"ts",
";",
"this",
".",
"toText",
"=",
"function",
"(",
")",
"{",
"return",
"m",
".",
"key",
"+",
"\" \"",
"+",
"m",
".",
"value",
"+",
"\" \"",
"+",
"m",
".",
"ts",
";",
"}",
";",
"this",
".",
"toPickle",
"=",
"function",
"(",
")",
"{",
"return",
"MARK",
"+",
"STRING",
"+",
"'\\''",
"+",
"\\'",
"+",
"m",
".",
"key",
"+",
"'\\'\\n'",
"+",
"\\'",
"+",
"\\n",
"+",
"MARK",
"+",
"LONG",
"+",
"m",
".",
"ts",
"+",
"'L\\n'",
"+",
"\\n",
"+",
"STRING",
"+",
"'\\''",
"+",
"\\'",
";",
"}",
";",
"}"
] |
A single measurement for sending to graphite.
|
[
"A",
"single",
"measurement",
"for",
"sending",
"to",
"graphite",
"."
] |
ef8e4d76d76c3a0cf771e3724cf79ea22f3c50d9
|
https://github.com/statsd/statsd/blob/ef8e4d76d76c3a0cf771e3724cf79ea22f3c50d9/backends/graphite.js#L105-L121
|
train
|
statsd/statsd
|
backends/graphite.js
|
Stats
|
function Stats() {
var s = this;
this.metrics = [];
this.add = function(key, value, ts) {
s.metrics.push(new Metric(key, value, ts));
};
this.toText = function() {
return s.metrics.map(function(m) { return m.toText(); }).join('\n') + '\n';
};
this.toPickle = function() {
var body = MARK + LIST + s.metrics.map(function(m) { return m.toPickle(); }).join('') + STOP;
// The first four bytes of the graphite pickle format
// contain the length of the rest of the payload.
// We use Buffer because this is binary data.
var buf = new Buffer(4 + body.length);
buf.writeUInt32BE(body.length,0);
buf.write(body,4);
return buf;
};
}
|
javascript
|
function Stats() {
var s = this;
this.metrics = [];
this.add = function(key, value, ts) {
s.metrics.push(new Metric(key, value, ts));
};
this.toText = function() {
return s.metrics.map(function(m) { return m.toText(); }).join('\n') + '\n';
};
this.toPickle = function() {
var body = MARK + LIST + s.metrics.map(function(m) { return m.toPickle(); }).join('') + STOP;
// The first four bytes of the graphite pickle format
// contain the length of the rest of the payload.
// We use Buffer because this is binary data.
var buf = new Buffer(4 + body.length);
buf.writeUInt32BE(body.length,0);
buf.write(body,4);
return buf;
};
}
|
[
"function",
"Stats",
"(",
")",
"{",
"var",
"s",
"=",
"this",
";",
"this",
".",
"metrics",
"=",
"[",
"]",
";",
"this",
".",
"add",
"=",
"function",
"(",
"key",
",",
"value",
",",
"ts",
")",
"{",
"s",
".",
"metrics",
".",
"push",
"(",
"new",
"Metric",
"(",
"key",
",",
"value",
",",
"ts",
")",
")",
";",
"}",
";",
"this",
".",
"toText",
"=",
"function",
"(",
")",
"{",
"return",
"s",
".",
"metrics",
".",
"map",
"(",
"function",
"(",
"m",
")",
"{",
"return",
"m",
".",
"toText",
"(",
")",
";",
"}",
")",
".",
"join",
"(",
"'\\n'",
")",
"+",
"\\n",
";",
"}",
";",
"'\\n'",
"}"
] |
A collection of measurements for sending to graphite.
|
[
"A",
"collection",
"of",
"measurements",
"for",
"sending",
"to",
"graphite",
"."
] |
ef8e4d76d76c3a0cf771e3724cf79ea22f3c50d9
|
https://github.com/statsd/statsd/blob/ef8e4d76d76c3a0cf771e3724cf79ea22f3c50d9/backends/graphite.js#L124-L148
|
train
|
statsd/statsd
|
backends/graphite.js
|
sk
|
function sk(key) {
if (globalKeySanitize) {
return key;
} else {
return key.replace(/\s+/g, '_')
.replace(/\//g, '-')
.replace(/[^a-zA-Z_\-0-9\.]/g, '');
}
}
|
javascript
|
function sk(key) {
if (globalKeySanitize) {
return key;
} else {
return key.replace(/\s+/g, '_')
.replace(/\//g, '-')
.replace(/[^a-zA-Z_\-0-9\.]/g, '');
}
}
|
[
"function",
"sk",
"(",
"key",
")",
"{",
"if",
"(",
"globalKeySanitize",
")",
"{",
"return",
"key",
";",
"}",
"else",
"{",
"return",
"key",
".",
"replace",
"(",
"/",
"\\s+",
"/",
"g",
",",
"'_'",
")",
".",
"replace",
"(",
"/",
"\\/",
"/",
"g",
",",
"'-'",
")",
".",
"replace",
"(",
"/",
"[^a-zA-Z_\\-0-9\\.]",
"/",
"g",
",",
"''",
")",
";",
"}",
"}"
] |
Sanitize key for graphite if not done globally
|
[
"Sanitize",
"key",
"for",
"graphite",
"if",
"not",
"done",
"globally"
] |
ef8e4d76d76c3a0cf771e3724cf79ea22f3c50d9
|
https://github.com/statsd/statsd/blob/ef8e4d76d76c3a0cf771e3724cf79ea22f3c50d9/backends/graphite.js#L164-L172
|
train
|
statsd/statsd
|
proxy.js
|
healthcheck
|
function healthcheck(node) {
var ended = false;
var node_id = node.host + ':' + node.port;
var client = net.connect(
{port: node.adminport, host: node.host},
function onConnect() {
if (!ended) {
client.write('health\r\n');
}
}
);
client.setTimeout(healthCheckInterval, function() {
client.end();
markNodeAsUnhealthy(node_id);
client.removeAllListeners('data');
ended = true;
});
client.on('data', function(data) {
if (ended) {
return;
}
var health_status = data.toString();
client.end();
ended = true;
if (health_status.indexOf('up') < 0) {
markNodeAsUnhealthy(node_id);
} else {
markNodeAsHealthy(node_id);
}
});
client.on('error', function(e) {
if (ended) {
return;
}
if (e.code !== 'ECONNREFUSED' && e.code !== 'EHOSTUNREACH' && e.code !== 'ECONNRESET') {
log('Error during healthcheck on node ' + node_id + ' with ' + e.code, 'ERROR');
}
markNodeAsUnhealthy(node_id);
});
}
|
javascript
|
function healthcheck(node) {
var ended = false;
var node_id = node.host + ':' + node.port;
var client = net.connect(
{port: node.adminport, host: node.host},
function onConnect() {
if (!ended) {
client.write('health\r\n');
}
}
);
client.setTimeout(healthCheckInterval, function() {
client.end();
markNodeAsUnhealthy(node_id);
client.removeAllListeners('data');
ended = true;
});
client.on('data', function(data) {
if (ended) {
return;
}
var health_status = data.toString();
client.end();
ended = true;
if (health_status.indexOf('up') < 0) {
markNodeAsUnhealthy(node_id);
} else {
markNodeAsHealthy(node_id);
}
});
client.on('error', function(e) {
if (ended) {
return;
}
if (e.code !== 'ECONNREFUSED' && e.code !== 'EHOSTUNREACH' && e.code !== 'ECONNRESET') {
log('Error during healthcheck on node ' + node_id + ' with ' + e.code, 'ERROR');
}
markNodeAsUnhealthy(node_id);
});
}
|
[
"function",
"healthcheck",
"(",
"node",
")",
"{",
"var",
"ended",
"=",
"false",
";",
"var",
"node_id",
"=",
"node",
".",
"host",
"+",
"':'",
"+",
"node",
".",
"port",
";",
"var",
"client",
"=",
"net",
".",
"connect",
"(",
"{",
"port",
":",
"node",
".",
"adminport",
",",
"host",
":",
"node",
".",
"host",
"}",
",",
"function",
"onConnect",
"(",
")",
"{",
"if",
"(",
"!",
"ended",
")",
"{",
"client",
".",
"write",
"(",
"'health\\r\\n'",
")",
";",
"}",
"}",
")",
";",
"\\r",
"\\n",
"client",
".",
"setTimeout",
"(",
"healthCheckInterval",
",",
"function",
"(",
")",
"{",
"client",
".",
"end",
"(",
")",
";",
"markNodeAsUnhealthy",
"(",
"node_id",
")",
";",
"client",
".",
"removeAllListeners",
"(",
"'data'",
")",
";",
"ended",
"=",
"true",
";",
"}",
")",
";",
"}"
] |
Perform health check on node
|
[
"Perform",
"health",
"check",
"on",
"node"
] |
ef8e4d76d76c3a0cf771e3724cf79ea22f3c50d9
|
https://github.com/statsd/statsd/blob/ef8e4d76d76c3a0cf771e3724cf79ea22f3c50d9/proxy.js#L255-L301
|
train
|
SAP/openui5
|
src/sap.ui.documentation/src/sap/ui/documentation/sdk/model/formatter.js
|
function (sLink) {
if (sLink[0] === "#") {
sLink = document.location.href.substring(0,document.location.href.search("demoapps\.html")) + sLink;
}
return sLink;
}
|
javascript
|
function (sLink) {
if (sLink[0] === "#") {
sLink = document.location.href.substring(0,document.location.href.search("demoapps\.html")) + sLink;
}
return sLink;
}
|
[
"function",
"(",
"sLink",
")",
"{",
"if",
"(",
"sLink",
"[",
"0",
"]",
"===",
"\"#\"",
")",
"{",
"sLink",
"=",
"document",
".",
"location",
".",
"href",
".",
"substring",
"(",
"0",
",",
"document",
".",
"location",
".",
"href",
".",
"search",
"(",
"\"demoapps\\.html\"",
")",
")",
"+",
"\\.",
";",
"}",
"sLink",
"}"
] |
Formats a library namespace to link to the API reference if it starts with sap.
@public
@param {string} sNamespace value to be formatted
@returns {string} formatted link
|
[
"Formats",
"a",
"library",
"namespace",
"to",
"link",
"to",
"the",
"API",
"reference",
"if",
"it",
"starts",
"with",
"sap",
"."
] |
8a832fca01cb1cdf8df589788e0c5723e2a33c70
|
https://github.com/SAP/openui5/blob/8a832fca01cb1cdf8df589788e0c5723e2a33c70/src/sap.ui.documentation/src/sap/ui/documentation/sdk/model/formatter.js#L16-L21
|
train
|
|
SAP/openui5
|
src/sap.uxap/src/sap/uxap/ThrottledTaskHelper.js
|
function(oOldOptions, oNewOptions) {
var oMergedOptions = jQuery.extend({}, oOldOptions, oNewOptions);
jQuery.each(oMergedOptions, function(key) {
oMergedOptions[key] = oOldOptions[key] || oNewOptions[key]; // default merge strategy is inclusive OR
});
return oMergedOptions;
}
|
javascript
|
function(oOldOptions, oNewOptions) {
var oMergedOptions = jQuery.extend({}, oOldOptions, oNewOptions);
jQuery.each(oMergedOptions, function(key) {
oMergedOptions[key] = oOldOptions[key] || oNewOptions[key]; // default merge strategy is inclusive OR
});
return oMergedOptions;
}
|
[
"function",
"(",
"oOldOptions",
",",
"oNewOptions",
")",
"{",
"var",
"oMergedOptions",
"=",
"jQuery",
".",
"extend",
"(",
"{",
"}",
",",
"oOldOptions",
",",
"oNewOptions",
")",
";",
"jQuery",
".",
"each",
"(",
"oMergedOptions",
",",
"function",
"(",
"key",
")",
"{",
"oMergedOptions",
"[",
"key",
"]",
"=",
"oOldOptions",
"[",
"key",
"]",
"||",
"oNewOptions",
"[",
"key",
"]",
";",
"}",
")",
";",
"return",
"oMergedOptions",
";",
"}"
] |
Updates the task arguments
Default merge strategy is inclusive OR
@private
|
[
"Updates",
"the",
"task",
"arguments",
"Default",
"merge",
"strategy",
"is",
"inclusive",
"OR"
] |
8a832fca01cb1cdf8df589788e0c5723e2a33c70
|
https://github.com/SAP/openui5/blob/8a832fca01cb1cdf8df589788e0c5723e2a33c70/src/sap.uxap/src/sap/uxap/ThrottledTaskHelper.js#L95-L103
|
train
|
|
SAP/openui5
|
src/sap.ui.dt/src/sap/ui/dt/ElementOverlay.js
|
function(oChild1, oChild2) {
var oGeometry1 = DOMUtil.getGeometry(oChild1);
var oGeometry2 = DOMUtil.getGeometry(oChild2);
var oPosition1 = oGeometry1 && oGeometry1.position;
var oPosition2 = oGeometry2 && oGeometry2.position;
if (oPosition1 && oPosition2) {
var iBottom1 = oPosition1.top + oGeometry1.size.height;
var iBottom2 = oPosition2.top + oGeometry2.size.height;
if (oPosition1.top < oPosition2.top) {
if (iBottom1 >= iBottom2 && oPosition2.left < oPosition1.left) {
/* Example:
+--------------+
+------+ | |
| 2 | | 1 |
+------+ | |
+--------------+
Despites 1st overlay's top is above 2nd element,
the order should be switched, since 2nd element
is shorter and is more to the left
*/
return 1;
} else {
return -1; // do not switch order
}
} else if (oPosition1.top === oPosition2.top) {
if (oPosition1.left === oPosition2.left) {
// Give priority to smaller block by height or width
if (
oGeometry1.size.height < oGeometry2.size.height
|| oGeometry1.size.width < oGeometry2.size.width
) {
return -1;
} else if (
oGeometry1.size.height > oGeometry2.size.height
|| oGeometry1.size.width > oGeometry2.size.width
) {
return 1;
} else {
return 0;
}
} else if (oPosition1.left < oPosition2.left) {
return -1; // order is correct
} else {
return 1; // switch order
}
} else if (iBottom1 <= iBottom2 && oPosition2.left > oPosition1.left) { // if (oPosition1.top > oPosition2.top)
/* see picture above, but switch 1 and 2 - order is correct */
return -1;
} else {
/* Example:
+--------------+
+------+ | 2 |
| 1 | +--------------+
| |
+------+
Since 1st overlay's both top and bottom coordinates are
bellow in dom, then top and bottom of 2nd, they should be switched
*/
return 1;
}
}
return 0;
}
|
javascript
|
function(oChild1, oChild2) {
var oGeometry1 = DOMUtil.getGeometry(oChild1);
var oGeometry2 = DOMUtil.getGeometry(oChild2);
var oPosition1 = oGeometry1 && oGeometry1.position;
var oPosition2 = oGeometry2 && oGeometry2.position;
if (oPosition1 && oPosition2) {
var iBottom1 = oPosition1.top + oGeometry1.size.height;
var iBottom2 = oPosition2.top + oGeometry2.size.height;
if (oPosition1.top < oPosition2.top) {
if (iBottom1 >= iBottom2 && oPosition2.left < oPosition1.left) {
/* Example:
+--------------+
+------+ | |
| 2 | | 1 |
+------+ | |
+--------------+
Despites 1st overlay's top is above 2nd element,
the order should be switched, since 2nd element
is shorter and is more to the left
*/
return 1;
} else {
return -1; // do not switch order
}
} else if (oPosition1.top === oPosition2.top) {
if (oPosition1.left === oPosition2.left) {
// Give priority to smaller block by height or width
if (
oGeometry1.size.height < oGeometry2.size.height
|| oGeometry1.size.width < oGeometry2.size.width
) {
return -1;
} else if (
oGeometry1.size.height > oGeometry2.size.height
|| oGeometry1.size.width > oGeometry2.size.width
) {
return 1;
} else {
return 0;
}
} else if (oPosition1.left < oPosition2.left) {
return -1; // order is correct
} else {
return 1; // switch order
}
} else if (iBottom1 <= iBottom2 && oPosition2.left > oPosition1.left) { // if (oPosition1.top > oPosition2.top)
/* see picture above, but switch 1 and 2 - order is correct */
return -1;
} else {
/* Example:
+--------------+
+------+ | 2 |
| 1 | +--------------+
| |
+------+
Since 1st overlay's both top and bottom coordinates are
bellow in dom, then top and bottom of 2nd, they should be switched
*/
return 1;
}
}
return 0;
}
|
[
"function",
"(",
"oChild1",
",",
"oChild2",
")",
"{",
"var",
"oGeometry1",
"=",
"DOMUtil",
".",
"getGeometry",
"(",
"oChild1",
")",
";",
"var",
"oGeometry2",
"=",
"DOMUtil",
".",
"getGeometry",
"(",
"oChild2",
")",
";",
"var",
"oPosition1",
"=",
"oGeometry1",
"&&",
"oGeometry1",
".",
"position",
";",
"var",
"oPosition2",
"=",
"oGeometry2",
"&&",
"oGeometry2",
".",
"position",
";",
"if",
"(",
"oPosition1",
"&&",
"oPosition2",
")",
"{",
"var",
"iBottom1",
"=",
"oPosition1",
".",
"top",
"+",
"oGeometry1",
".",
"size",
".",
"height",
";",
"var",
"iBottom2",
"=",
"oPosition2",
".",
"top",
"+",
"oGeometry2",
".",
"size",
".",
"height",
";",
"if",
"(",
"oPosition1",
".",
"top",
"<",
"oPosition2",
".",
"top",
")",
"{",
"if",
"(",
"iBottom1",
">=",
"iBottom2",
"&&",
"oPosition2",
".",
"left",
"<",
"oPosition1",
".",
"left",
")",
"{",
"return",
"1",
";",
"}",
"else",
"{",
"return",
"-",
"1",
";",
"}",
"}",
"else",
"if",
"(",
"oPosition1",
".",
"top",
"===",
"oPosition2",
".",
"top",
")",
"{",
"if",
"(",
"oPosition1",
".",
"left",
"===",
"oPosition2",
".",
"left",
")",
"{",
"if",
"(",
"oGeometry1",
".",
"size",
".",
"height",
"<",
"oGeometry2",
".",
"size",
".",
"height",
"||",
"oGeometry1",
".",
"size",
".",
"width",
"<",
"oGeometry2",
".",
"size",
".",
"width",
")",
"{",
"return",
"-",
"1",
";",
"}",
"else",
"if",
"(",
"oGeometry1",
".",
"size",
".",
"height",
">",
"oGeometry2",
".",
"size",
".",
"height",
"||",
"oGeometry1",
".",
"size",
".",
"width",
">",
"oGeometry2",
".",
"size",
".",
"width",
")",
"{",
"return",
"1",
";",
"}",
"else",
"{",
"return",
"0",
";",
"}",
"}",
"else",
"if",
"(",
"oPosition1",
".",
"left",
"<",
"oPosition2",
".",
"left",
")",
"{",
"return",
"-",
"1",
";",
"}",
"else",
"{",
"return",
"1",
";",
"}",
"}",
"else",
"if",
"(",
"iBottom1",
"<=",
"iBottom2",
"&&",
"oPosition2",
".",
"left",
">",
"oPosition1",
".",
"left",
")",
"{",
"return",
"-",
"1",
";",
"}",
"else",
"{",
"return",
"1",
";",
"}",
"}",
"return",
"0",
";",
"}"
] |
compares two DOM Nodes and returns 1, if first child should be bellow in dom order
|
[
"compares",
"two",
"DOM",
"Nodes",
"and",
"returns",
"1",
"if",
"first",
"child",
"should",
"be",
"bellow",
"in",
"dom",
"order"
] |
8a832fca01cb1cdf8df589788e0c5723e2a33c70
|
https://github.com/SAP/openui5/blob/8a832fca01cb1cdf8df589788e0c5723e2a33c70/src/sap.ui.dt/src/sap/ui/dt/ElementOverlay.js#L388-L453
|
train
|
|
SAP/openui5
|
src/sap.ui.documentation/src/sap/ui/documentation/sdk/controller/App.controller.js
|
function() {
var oViewModel = this.getModel("appView"),
bPhoneSize = oViewModel.getProperty("/bPhoneSize");
// Version switch should not be shown on phone sizes or when no versions are found
oViewModel.setProperty("/bShowVersionSwitchInHeader", !bPhoneSize && !!this._aNeoAppVersions);
oViewModel.setProperty("/bShowVersionSwitchInMenu", bPhoneSize && !!this._aNeoAppVersions);
}
|
javascript
|
function() {
var oViewModel = this.getModel("appView"),
bPhoneSize = oViewModel.getProperty("/bPhoneSize");
// Version switch should not be shown on phone sizes or when no versions are found
oViewModel.setProperty("/bShowVersionSwitchInHeader", !bPhoneSize && !!this._aNeoAppVersions);
oViewModel.setProperty("/bShowVersionSwitchInMenu", bPhoneSize && !!this._aNeoAppVersions);
}
|
[
"function",
"(",
")",
"{",
"var",
"oViewModel",
"=",
"this",
".",
"getModel",
"(",
"\"appView\"",
")",
",",
"bPhoneSize",
"=",
"oViewModel",
".",
"getProperty",
"(",
"\"/bPhoneSize\"",
")",
";",
"oViewModel",
".",
"setProperty",
"(",
"\"/bShowVersionSwitchInHeader\"",
",",
"!",
"bPhoneSize",
"&&",
"!",
"!",
"this",
".",
"_aNeoAppVersions",
")",
";",
"oViewModel",
".",
"setProperty",
"(",
"\"/bShowVersionSwitchInMenu\"",
",",
"bPhoneSize",
"&&",
"!",
"!",
"this",
".",
"_aNeoAppVersions",
")",
";",
"}"
] |
Determines whether or not to show the version change button.
@private
|
[
"Determines",
"whether",
"or",
"not",
"to",
"show",
"the",
"version",
"change",
"button",
"."
] |
8a832fca01cb1cdf8df589788e0c5723e2a33c70
|
https://github.com/SAP/openui5/blob/8a832fca01cb1cdf8df589788e0c5723e2a33c70/src/sap.ui.documentation/src/sap/ui/documentation/sdk/controller/App.controller.js#L414-L421
|
train
|
|
SAP/openui5
|
src/sap.ui.documentation/src/sap/ui/documentation/sdk/controller/App.controller.js
|
function () {
var that = this;
if (!this._oFeedbackDialog) {
this._oFeedbackDialog = new sap.ui.xmlfragment("feedbackDialogFragment", "sap.ui.documentation.sdk.view.FeedbackDialog", this);
this._oView.addDependent(this._oFeedbackDialog);
this._oFeedbackDialog.textInput = Fragment.byId("feedbackDialogFragment", "feedbackInput");
this._oFeedbackDialog.contextCheckBox = Fragment.byId("feedbackDialogFragment", "pageContext");
this._oFeedbackDialog.contextData = Fragment.byId("feedbackDialogFragment", "contextData");
this._oFeedbackDialog.ratingStatus = Fragment.byId("feedbackDialogFragment", "ratingStatus");
this._oFeedbackDialog.ratingStatus.value = 0;
this._oFeedbackDialog.sendButton = Fragment.byId("feedbackDialogFragment", "sendButton");
this._oFeedbackDialog.ratingBar = [
{
button : Fragment.byId("feedbackDialogFragment", "excellent"),
status : "Excellent"
},
{
button : Fragment.byId("feedbackDialogFragment", "good"),
status : "Good"
},
{
button : Fragment.byId("feedbackDialogFragment", "average"),
status : "Average"
},
{
button : Fragment.byId("feedbackDialogFragment", "poor"),
status : "Poor"
},
{
button : Fragment.byId("feedbackDialogFragment", "veryPoor"),
status : "Very Poor"
}
];
this._oFeedbackDialog.reset = function () {
this.sendButton.setEnabled(false);
this.textInput.setValue("");
this.contextCheckBox.setSelected(true);
this.ratingStatus.setText("");
this.ratingStatus.setState("None");
this.ratingStatus.value = 0;
this.contextData.setVisible(false);
this.ratingBar.forEach(function(oRatingBarElement){
if (oRatingBarElement.button.getPressed()) {
oRatingBarElement.button.setPressed(false);
}
});
};
this._oFeedbackDialog.updateContextData = function() {
var sVersion = that._getUI5Version(),
sUI5Distribution = that._getUI5Distribution();
if (this.contextCheckBox.getSelected()) {
this.contextData.setValue("Location: " + that._getCurrentPageRelativeURL() + "\n" + sUI5Distribution + " Version: " + sVersion);
} else {
this.contextData.setValue(sUI5Distribution + " Version: " + sVersion);
}
};
this._oFeedbackDialog.updateContextData();
}
this._oFeedbackDialog.updateContextData();
if (!this._oFeedbackDialog.isOpen()) {
syncStyleClass("sapUiSizeCompact", this.getView(), this._oFeedbackDialog);
this._oFeedbackDialog.open();
}
}
|
javascript
|
function () {
var that = this;
if (!this._oFeedbackDialog) {
this._oFeedbackDialog = new sap.ui.xmlfragment("feedbackDialogFragment", "sap.ui.documentation.sdk.view.FeedbackDialog", this);
this._oView.addDependent(this._oFeedbackDialog);
this._oFeedbackDialog.textInput = Fragment.byId("feedbackDialogFragment", "feedbackInput");
this._oFeedbackDialog.contextCheckBox = Fragment.byId("feedbackDialogFragment", "pageContext");
this._oFeedbackDialog.contextData = Fragment.byId("feedbackDialogFragment", "contextData");
this._oFeedbackDialog.ratingStatus = Fragment.byId("feedbackDialogFragment", "ratingStatus");
this._oFeedbackDialog.ratingStatus.value = 0;
this._oFeedbackDialog.sendButton = Fragment.byId("feedbackDialogFragment", "sendButton");
this._oFeedbackDialog.ratingBar = [
{
button : Fragment.byId("feedbackDialogFragment", "excellent"),
status : "Excellent"
},
{
button : Fragment.byId("feedbackDialogFragment", "good"),
status : "Good"
},
{
button : Fragment.byId("feedbackDialogFragment", "average"),
status : "Average"
},
{
button : Fragment.byId("feedbackDialogFragment", "poor"),
status : "Poor"
},
{
button : Fragment.byId("feedbackDialogFragment", "veryPoor"),
status : "Very Poor"
}
];
this._oFeedbackDialog.reset = function () {
this.sendButton.setEnabled(false);
this.textInput.setValue("");
this.contextCheckBox.setSelected(true);
this.ratingStatus.setText("");
this.ratingStatus.setState("None");
this.ratingStatus.value = 0;
this.contextData.setVisible(false);
this.ratingBar.forEach(function(oRatingBarElement){
if (oRatingBarElement.button.getPressed()) {
oRatingBarElement.button.setPressed(false);
}
});
};
this._oFeedbackDialog.updateContextData = function() {
var sVersion = that._getUI5Version(),
sUI5Distribution = that._getUI5Distribution();
if (this.contextCheckBox.getSelected()) {
this.contextData.setValue("Location: " + that._getCurrentPageRelativeURL() + "\n" + sUI5Distribution + " Version: " + sVersion);
} else {
this.contextData.setValue(sUI5Distribution + " Version: " + sVersion);
}
};
this._oFeedbackDialog.updateContextData();
}
this._oFeedbackDialog.updateContextData();
if (!this._oFeedbackDialog.isOpen()) {
syncStyleClass("sapUiSizeCompact", this.getView(), this._oFeedbackDialog);
this._oFeedbackDialog.open();
}
}
|
[
"function",
"(",
")",
"{",
"var",
"that",
"=",
"this",
";",
"if",
"(",
"!",
"this",
".",
"_oFeedbackDialog",
")",
"{",
"this",
".",
"_oFeedbackDialog",
"=",
"new",
"sap",
".",
"ui",
".",
"xmlfragment",
"(",
"\"feedbackDialogFragment\"",
",",
"\"sap.ui.documentation.sdk.view.FeedbackDialog\"",
",",
"this",
")",
";",
"this",
".",
"_oView",
".",
"addDependent",
"(",
"this",
".",
"_oFeedbackDialog",
")",
";",
"this",
".",
"_oFeedbackDialog",
".",
"textInput",
"=",
"Fragment",
".",
"byId",
"(",
"\"feedbackDialogFragment\"",
",",
"\"feedbackInput\"",
")",
";",
"this",
".",
"_oFeedbackDialog",
".",
"contextCheckBox",
"=",
"Fragment",
".",
"byId",
"(",
"\"feedbackDialogFragment\"",
",",
"\"pageContext\"",
")",
";",
"this",
".",
"_oFeedbackDialog",
".",
"contextData",
"=",
"Fragment",
".",
"byId",
"(",
"\"feedbackDialogFragment\"",
",",
"\"contextData\"",
")",
";",
"this",
".",
"_oFeedbackDialog",
".",
"ratingStatus",
"=",
"Fragment",
".",
"byId",
"(",
"\"feedbackDialogFragment\"",
",",
"\"ratingStatus\"",
")",
";",
"this",
".",
"_oFeedbackDialog",
".",
"ratingStatus",
".",
"value",
"=",
"0",
";",
"this",
".",
"_oFeedbackDialog",
".",
"sendButton",
"=",
"Fragment",
".",
"byId",
"(",
"\"feedbackDialogFragment\"",
",",
"\"sendButton\"",
")",
";",
"this",
".",
"_oFeedbackDialog",
".",
"ratingBar",
"=",
"[",
"{",
"button",
":",
"Fragment",
".",
"byId",
"(",
"\"feedbackDialogFragment\"",
",",
"\"excellent\"",
")",
",",
"status",
":",
"\"Excellent\"",
"}",
",",
"{",
"button",
":",
"Fragment",
".",
"byId",
"(",
"\"feedbackDialogFragment\"",
",",
"\"good\"",
")",
",",
"status",
":",
"\"Good\"",
"}",
",",
"{",
"button",
":",
"Fragment",
".",
"byId",
"(",
"\"feedbackDialogFragment\"",
",",
"\"average\"",
")",
",",
"status",
":",
"\"Average\"",
"}",
",",
"{",
"button",
":",
"Fragment",
".",
"byId",
"(",
"\"feedbackDialogFragment\"",
",",
"\"poor\"",
")",
",",
"status",
":",
"\"Poor\"",
"}",
",",
"{",
"button",
":",
"Fragment",
".",
"byId",
"(",
"\"feedbackDialogFragment\"",
",",
"\"veryPoor\"",
")",
",",
"status",
":",
"\"Very Poor\"",
"}",
"]",
";",
"this",
".",
"_oFeedbackDialog",
".",
"reset",
"=",
"function",
"(",
")",
"{",
"this",
".",
"sendButton",
".",
"setEnabled",
"(",
"false",
")",
";",
"this",
".",
"textInput",
".",
"setValue",
"(",
"\"\"",
")",
";",
"this",
".",
"contextCheckBox",
".",
"setSelected",
"(",
"true",
")",
";",
"this",
".",
"ratingStatus",
".",
"setText",
"(",
"\"\"",
")",
";",
"this",
".",
"ratingStatus",
".",
"setState",
"(",
"\"None\"",
")",
";",
"this",
".",
"ratingStatus",
".",
"value",
"=",
"0",
";",
"this",
".",
"contextData",
".",
"setVisible",
"(",
"false",
")",
";",
"this",
".",
"ratingBar",
".",
"forEach",
"(",
"function",
"(",
"oRatingBarElement",
")",
"{",
"if",
"(",
"oRatingBarElement",
".",
"button",
".",
"getPressed",
"(",
")",
")",
"{",
"oRatingBarElement",
".",
"button",
".",
"setPressed",
"(",
"false",
")",
";",
"}",
"}",
")",
";",
"}",
";",
"this",
".",
"_oFeedbackDialog",
".",
"updateContextData",
"=",
"function",
"(",
")",
"{",
"var",
"sVersion",
"=",
"that",
".",
"_getUI5Version",
"(",
")",
",",
"sUI5Distribution",
"=",
"that",
".",
"_getUI5Distribution",
"(",
")",
";",
"if",
"(",
"this",
".",
"contextCheckBox",
".",
"getSelected",
"(",
")",
")",
"{",
"this",
".",
"contextData",
".",
"setValue",
"(",
"\"Location: \"",
"+",
"that",
".",
"_getCurrentPageRelativeURL",
"(",
")",
"+",
"\"\\n\"",
"+",
"\\n",
"+",
"sUI5Distribution",
"+",
"\" Version: \"",
")",
";",
"}",
"else",
"sVersion",
"}",
";",
"{",
"this",
".",
"contextData",
".",
"setValue",
"(",
"sUI5Distribution",
"+",
"\" Version: \"",
"+",
"sVersion",
")",
";",
"}",
"}",
"this",
".",
"_oFeedbackDialog",
".",
"updateContextData",
"(",
")",
";",
"this",
".",
"_oFeedbackDialog",
".",
"updateContextData",
"(",
")",
";",
"}"
] |
Opens a dialog to give feedback on the demo kit
|
[
"Opens",
"a",
"dialog",
"to",
"give",
"feedback",
"on",
"the",
"demo",
"kit"
] |
8a832fca01cb1cdf8df589788e0c5723e2a33c70
|
https://github.com/SAP/openui5/blob/8a832fca01cb1cdf8df589788e0c5723e2a33c70/src/sap.ui.documentation/src/sap/ui/documentation/sdk/controller/App.controller.js#L441-L508
|
train
|
|
SAP/openui5
|
src/sap.ui.documentation/src/sap/ui/documentation/sdk/controller/App.controller.js
|
function() {
var data = {};
if (this._oFeedbackDialog.contextCheckBox.getSelected()) {
data = {
"texts": {
"t1": this._oFeedbackDialog.textInput.getValue()
},
"ratings":{
"r1": {"value" : this._oFeedbackDialog.ratingStatus.value}
},
"context": {"page": this._getCurrentPageRelativeURL(), "attr1": this._getUI5Distribution() + ":" + sap.ui.version}
};
} else {
data = {
"texts": {
"t1": this._oFeedbackDialog.textInput.getValue()
},
"ratings":{
"r1": {"value" : this._oFeedbackDialog.ratingStatus.value}
},
"context": {"attr1": this._getUI5Distribution() + ":" + sap.ui.version}
};
}
// send feedback
this._oFeedbackDialog.setBusyIndicatorDelay(0);
this._oFeedbackDialog.setBusy(true);
jQuery.ajax({
url: this.FEEDBACK_SERVICE_URL,
type: "POST",
contentType: "application/json",
data: JSON.stringify(data)
}).
done(
function () {
MessageBox.success("Your feedback has been sent.", {title: "Thank you!"});
this._oFeedbackDialog.reset();
this._oFeedbackDialog.close();
this._oFeedbackDialog.setBusy(false);
}.bind(this)
).
fail(
function (oRequest, sStatus, sError) {
var sErrorDetails = sError; // + "\n" + oRequest.responseText;
MessageBox.error("An error occurred sending your feedback:\n" + sErrorDetails, {title: "Sorry!"});
this._oFeedbackDialog.setBusy(false);
}.bind(this)
);
}
|
javascript
|
function() {
var data = {};
if (this._oFeedbackDialog.contextCheckBox.getSelected()) {
data = {
"texts": {
"t1": this._oFeedbackDialog.textInput.getValue()
},
"ratings":{
"r1": {"value" : this._oFeedbackDialog.ratingStatus.value}
},
"context": {"page": this._getCurrentPageRelativeURL(), "attr1": this._getUI5Distribution() + ":" + sap.ui.version}
};
} else {
data = {
"texts": {
"t1": this._oFeedbackDialog.textInput.getValue()
},
"ratings":{
"r1": {"value" : this._oFeedbackDialog.ratingStatus.value}
},
"context": {"attr1": this._getUI5Distribution() + ":" + sap.ui.version}
};
}
// send feedback
this._oFeedbackDialog.setBusyIndicatorDelay(0);
this._oFeedbackDialog.setBusy(true);
jQuery.ajax({
url: this.FEEDBACK_SERVICE_URL,
type: "POST",
contentType: "application/json",
data: JSON.stringify(data)
}).
done(
function () {
MessageBox.success("Your feedback has been sent.", {title: "Thank you!"});
this._oFeedbackDialog.reset();
this._oFeedbackDialog.close();
this._oFeedbackDialog.setBusy(false);
}.bind(this)
).
fail(
function (oRequest, sStatus, sError) {
var sErrorDetails = sError; // + "\n" + oRequest.responseText;
MessageBox.error("An error occurred sending your feedback:\n" + sErrorDetails, {title: "Sorry!"});
this._oFeedbackDialog.setBusy(false);
}.bind(this)
);
}
|
[
"function",
"(",
")",
"{",
"var",
"data",
"=",
"{",
"}",
";",
"if",
"(",
"this",
".",
"_oFeedbackDialog",
".",
"contextCheckBox",
".",
"getSelected",
"(",
")",
")",
"{",
"data",
"=",
"{",
"\"texts\"",
":",
"{",
"\"t1\"",
":",
"this",
".",
"_oFeedbackDialog",
".",
"textInput",
".",
"getValue",
"(",
")",
"}",
",",
"\"ratings\"",
":",
"{",
"\"r1\"",
":",
"{",
"\"value\"",
":",
"this",
".",
"_oFeedbackDialog",
".",
"ratingStatus",
".",
"value",
"}",
"}",
",",
"\"context\"",
":",
"{",
"\"page\"",
":",
"this",
".",
"_getCurrentPageRelativeURL",
"(",
")",
",",
"\"attr1\"",
":",
"this",
".",
"_getUI5Distribution",
"(",
")",
"+",
"\":\"",
"+",
"sap",
".",
"ui",
".",
"version",
"}",
"}",
";",
"}",
"else",
"{",
"data",
"=",
"{",
"\"texts\"",
":",
"{",
"\"t1\"",
":",
"this",
".",
"_oFeedbackDialog",
".",
"textInput",
".",
"getValue",
"(",
")",
"}",
",",
"\"ratings\"",
":",
"{",
"\"r1\"",
":",
"{",
"\"value\"",
":",
"this",
".",
"_oFeedbackDialog",
".",
"ratingStatus",
".",
"value",
"}",
"}",
",",
"\"context\"",
":",
"{",
"\"attr1\"",
":",
"this",
".",
"_getUI5Distribution",
"(",
")",
"+",
"\":\"",
"+",
"sap",
".",
"ui",
".",
"version",
"}",
"}",
";",
"}",
"this",
".",
"_oFeedbackDialog",
".",
"setBusyIndicatorDelay",
"(",
"0",
")",
";",
"this",
".",
"_oFeedbackDialog",
".",
"setBusy",
"(",
"true",
")",
";",
"jQuery",
".",
"ajax",
"(",
"{",
"url",
":",
"this",
".",
"FEEDBACK_SERVICE_URL",
",",
"type",
":",
"\"POST\"",
",",
"contentType",
":",
"\"application/json\"",
",",
"data",
":",
"JSON",
".",
"stringify",
"(",
"data",
")",
"}",
")",
".",
"done",
"(",
"function",
"(",
")",
"{",
"MessageBox",
".",
"success",
"(",
"\"Your feedback has been sent.\"",
",",
"{",
"title",
":",
"\"Thank you!\"",
"}",
")",
";",
"this",
".",
"_oFeedbackDialog",
".",
"reset",
"(",
")",
";",
"this",
".",
"_oFeedbackDialog",
".",
"close",
"(",
")",
";",
"this",
".",
"_oFeedbackDialog",
".",
"setBusy",
"(",
"false",
")",
";",
"}",
".",
"bind",
"(",
"this",
")",
")",
".",
"fail",
"(",
"function",
"(",
"oRequest",
",",
"sStatus",
",",
"sError",
")",
"{",
"var",
"sErrorDetails",
"=",
"sError",
";",
"MessageBox",
".",
"error",
"(",
"\"An error occurred sending your feedback:\\n\"",
"+",
"\\n",
",",
"sErrorDetails",
")",
";",
"{",
"title",
":",
"\"Sorry!\"",
"}",
"}",
".",
"this",
".",
"_oFeedbackDialog",
".",
"setBusy",
"(",
"false",
")",
";",
"bind",
")",
";",
"}"
] |
Event handler for the send feedback button
|
[
"Event",
"handler",
"for",
"the",
"send",
"feedback",
"button"
] |
8a832fca01cb1cdf8df589788e0c5723e2a33c70
|
https://github.com/SAP/openui5/blob/8a832fca01cb1cdf8df589788e0c5723e2a33c70/src/sap.ui.documentation/src/sap/ui/documentation/sdk/controller/App.controller.js#L513-L564
|
train
|
|
SAP/openui5
|
src/sap.ui.documentation/src/sap/ui/documentation/sdk/controller/App.controller.js
|
function(oEvent) {
var that = this;
var oPressedButton = oEvent.getSource();
that._oFeedbackDialog.ratingBar.forEach(function(oRatingBarElement) {
if (oPressedButton !== oRatingBarElement.button) {
oRatingBarElement.button.setPressed(false);
} else {
if (!oRatingBarElement.button.getPressed()) {
setRatingStatus("None", "", 0);
} else {
switch (oRatingBarElement.status) {
case "Excellent":
setRatingStatus("Success", oRatingBarElement.status, 5);
break;
case "Good":
setRatingStatus("Success", oRatingBarElement.status, 4);
break;
case "Average":
setRatingStatus("None", oRatingBarElement.status, 3);
break;
case "Poor":
setRatingStatus("Warning", oRatingBarElement.status, 2);
break;
case "Very Poor":
setRatingStatus("Error", oRatingBarElement.status, 1);
}
}
}
});
function setRatingStatus(sState, sText, iValue) {
that._oFeedbackDialog.ratingStatus.setState(sState);
that._oFeedbackDialog.ratingStatus.setText(sText);
that._oFeedbackDialog.ratingStatus.value = iValue;
if (iValue) {
that._oFeedbackDialog.sendButton.setEnabled(true);
} else {
that._oFeedbackDialog.sendButton.setEnabled(false);
}
}
}
|
javascript
|
function(oEvent) {
var that = this;
var oPressedButton = oEvent.getSource();
that._oFeedbackDialog.ratingBar.forEach(function(oRatingBarElement) {
if (oPressedButton !== oRatingBarElement.button) {
oRatingBarElement.button.setPressed(false);
} else {
if (!oRatingBarElement.button.getPressed()) {
setRatingStatus("None", "", 0);
} else {
switch (oRatingBarElement.status) {
case "Excellent":
setRatingStatus("Success", oRatingBarElement.status, 5);
break;
case "Good":
setRatingStatus("Success", oRatingBarElement.status, 4);
break;
case "Average":
setRatingStatus("None", oRatingBarElement.status, 3);
break;
case "Poor":
setRatingStatus("Warning", oRatingBarElement.status, 2);
break;
case "Very Poor":
setRatingStatus("Error", oRatingBarElement.status, 1);
}
}
}
});
function setRatingStatus(sState, sText, iValue) {
that._oFeedbackDialog.ratingStatus.setState(sState);
that._oFeedbackDialog.ratingStatus.setText(sText);
that._oFeedbackDialog.ratingStatus.value = iValue;
if (iValue) {
that._oFeedbackDialog.sendButton.setEnabled(true);
} else {
that._oFeedbackDialog.sendButton.setEnabled(false);
}
}
}
|
[
"function",
"(",
"oEvent",
")",
"{",
"var",
"that",
"=",
"this",
";",
"var",
"oPressedButton",
"=",
"oEvent",
".",
"getSource",
"(",
")",
";",
"that",
".",
"_oFeedbackDialog",
".",
"ratingBar",
".",
"forEach",
"(",
"function",
"(",
"oRatingBarElement",
")",
"{",
"if",
"(",
"oPressedButton",
"!==",
"oRatingBarElement",
".",
"button",
")",
"{",
"oRatingBarElement",
".",
"button",
".",
"setPressed",
"(",
"false",
")",
";",
"}",
"else",
"{",
"if",
"(",
"!",
"oRatingBarElement",
".",
"button",
".",
"getPressed",
"(",
")",
")",
"{",
"setRatingStatus",
"(",
"\"None\"",
",",
"\"\"",
",",
"0",
")",
";",
"}",
"else",
"{",
"switch",
"(",
"oRatingBarElement",
".",
"status",
")",
"{",
"case",
"\"Excellent\"",
":",
"setRatingStatus",
"(",
"\"Success\"",
",",
"oRatingBarElement",
".",
"status",
",",
"5",
")",
";",
"break",
";",
"case",
"\"Good\"",
":",
"setRatingStatus",
"(",
"\"Success\"",
",",
"oRatingBarElement",
".",
"status",
",",
"4",
")",
";",
"break",
";",
"case",
"\"Average\"",
":",
"setRatingStatus",
"(",
"\"None\"",
",",
"oRatingBarElement",
".",
"status",
",",
"3",
")",
";",
"break",
";",
"case",
"\"Poor\"",
":",
"setRatingStatus",
"(",
"\"Warning\"",
",",
"oRatingBarElement",
".",
"status",
",",
"2",
")",
";",
"break",
";",
"case",
"\"Very Poor\"",
":",
"setRatingStatus",
"(",
"\"Error\"",
",",
"oRatingBarElement",
".",
"status",
",",
"1",
")",
";",
"}",
"}",
"}",
"}",
")",
";",
"function",
"setRatingStatus",
"(",
"sState",
",",
"sText",
",",
"iValue",
")",
"{",
"that",
".",
"_oFeedbackDialog",
".",
"ratingStatus",
".",
"setState",
"(",
"sState",
")",
";",
"that",
".",
"_oFeedbackDialog",
".",
"ratingStatus",
".",
"setText",
"(",
"sText",
")",
";",
"that",
".",
"_oFeedbackDialog",
".",
"ratingStatus",
".",
"value",
"=",
"iValue",
";",
"if",
"(",
"iValue",
")",
"{",
"that",
".",
"_oFeedbackDialog",
".",
"sendButton",
".",
"setEnabled",
"(",
"true",
")",
";",
"}",
"else",
"{",
"that",
".",
"_oFeedbackDialog",
".",
"sendButton",
".",
"setEnabled",
"(",
"false",
")",
";",
"}",
"}",
"}"
] |
Event handler for the rating to update the label and the data
@param {sap.ui.base.Event}
|
[
"Event",
"handler",
"for",
"the",
"rating",
"to",
"update",
"the",
"label",
"and",
"the",
"data"
] |
8a832fca01cb1cdf8df589788e0c5723e2a33c70
|
https://github.com/SAP/openui5/blob/8a832fca01cb1cdf8df589788e0c5723e2a33c70/src/sap.ui.documentation/src/sap/ui/documentation/sdk/controller/App.controller.js#L592-L633
|
train
|
|
SAP/openui5
|
src/sap.ui.core/src/sap/ui/thirdparty/hasher.js
|
function(path){
// ##### BEGIN: MODIFIED BY SAP
var dispatchFunction;
// ##### END: MODIFIED BY SAP
path = _makePath.apply(null, arguments);
if(path !== _hash){
// we should store raw value
// ##### BEGIN: MODIFIED BY SAP
dispatchFunction = _registerChange(path);
if (!hasher.raw) {
path = _encodePath(path);
}
window.location.hash = '#' + path;
dispatchFunction && dispatchFunction();
// ##### END: MODIFIED BY SAP
}
}
|
javascript
|
function(path){
// ##### BEGIN: MODIFIED BY SAP
var dispatchFunction;
// ##### END: MODIFIED BY SAP
path = _makePath.apply(null, arguments);
if(path !== _hash){
// we should store raw value
// ##### BEGIN: MODIFIED BY SAP
dispatchFunction = _registerChange(path);
if (!hasher.raw) {
path = _encodePath(path);
}
window.location.hash = '#' + path;
dispatchFunction && dispatchFunction();
// ##### END: MODIFIED BY SAP
}
}
|
[
"function",
"(",
"path",
")",
"{",
"var",
"dispatchFunction",
";",
"path",
"=",
"_makePath",
".",
"apply",
"(",
"null",
",",
"arguments",
")",
";",
"if",
"(",
"path",
"!==",
"_hash",
")",
"{",
"dispatchFunction",
"=",
"_registerChange",
"(",
"path",
")",
";",
"if",
"(",
"!",
"hasher",
".",
"raw",
")",
"{",
"path",
"=",
"_encodePath",
"(",
"path",
")",
";",
"}",
"window",
".",
"location",
".",
"hash",
"=",
"'#'",
"+",
"path",
";",
"dispatchFunction",
"&&",
"dispatchFunction",
"(",
")",
";",
"}",
"}"
] |
Set Hash value, generating a new history record.
@param {...string} path Hash value without '#'. Hasher will join
path segments using `hasher.separator` and prepend/append hash value
with `hasher.appendHash` and `hasher.prependHash`
@example hasher.setHash('lorem', 'ipsum', 'dolor') -> '#/lorem/ipsum/dolor'
|
[
"Set",
"Hash",
"value",
"generating",
"a",
"new",
"history",
"record",
"."
] |
8a832fca01cb1cdf8df589788e0c5723e2a33c70
|
https://github.com/SAP/openui5/blob/8a832fca01cb1cdf8df589788e0c5723e2a33c70/src/sap.ui.core/src/sap/ui/thirdparty/hasher.js#L361-L378
|
train
|
|
SAP/openui5
|
src/sap.ui.demokit/src/sap/ui/demokit/util/jsanalyzer/Doclet.js
|
Doclet
|
function Doclet(comment) {
this.comment = comment = unwrap(comment);
this.tags = [];
var m;
var lastContent = 0;
var lastTag = "description";
while ((m = rtag.exec(comment)) != null) {
this._addTag(lastTag, comment.slice(lastContent, m.index));
lastTag = m[2];
lastContent = rtag.lastIndex;
}
this._addTag(lastTag, comment.slice(lastContent));
}
|
javascript
|
function Doclet(comment) {
this.comment = comment = unwrap(comment);
this.tags = [];
var m;
var lastContent = 0;
var lastTag = "description";
while ((m = rtag.exec(comment)) != null) {
this._addTag(lastTag, comment.slice(lastContent, m.index));
lastTag = m[2];
lastContent = rtag.lastIndex;
}
this._addTag(lastTag, comment.slice(lastContent));
}
|
[
"function",
"Doclet",
"(",
"comment",
")",
"{",
"this",
".",
"comment",
"=",
"comment",
"=",
"unwrap",
"(",
"comment",
")",
";",
"this",
".",
"tags",
"=",
"[",
"]",
";",
"var",
"m",
";",
"var",
"lastContent",
"=",
"0",
";",
"var",
"lastTag",
"=",
"\"description\"",
";",
"while",
"(",
"(",
"m",
"=",
"rtag",
".",
"exec",
"(",
"comment",
")",
")",
"!=",
"null",
")",
"{",
"this",
".",
"_addTag",
"(",
"lastTag",
",",
"comment",
".",
"slice",
"(",
"lastContent",
",",
"m",
".",
"index",
")",
")",
";",
"lastTag",
"=",
"m",
"[",
"2",
"]",
";",
"lastContent",
"=",
"rtag",
".",
"lastIndex",
";",
"}",
"this",
".",
"_addTag",
"(",
"lastTag",
",",
"comment",
".",
"slice",
"(",
"lastContent",
")",
")",
";",
"}"
] |
Creates a Doclet from the given comment string
@param {string} comment Comment string.
@constructor
@private
|
[
"Creates",
"a",
"Doclet",
"from",
"the",
"given",
"comment",
"string"
] |
8a832fca01cb1cdf8df589788e0c5723e2a33c70
|
https://github.com/SAP/openui5/blob/8a832fca01cb1cdf8df589788e0c5723e2a33c70/src/sap.ui.demokit/src/sap/ui/demokit/util/jsanalyzer/Doclet.js#L42-L56
|
train
|
SAP/openui5
|
src/sap.ui.core/src/sap/ui/core/Control.js
|
fnAppendBusyIndicator
|
function fnAppendBusyIndicator() {
// Only append if busy state is still set
if (!this.getBusy()) {
return;
}
var $this = this.$(this._sBusySection);
//If there is a pending delayed call to append the busy indicator, we can clear it now
if (this._busyIndicatorDelayedCallId) {
clearTimeout(this._busyIndicatorDelayedCallId);
delete this._busyIndicatorDelayedCallId;
}
// if no busy section/control jquery instance could be retrieved -> the control is not part of the dom anymore
// this might happen in certain scenarios when e.g. a dialog is closed faster than the busyIndicatorDelay
if (!$this || $this.length === 0) {
Log.warning("BusyIndicator could not be rendered. The outer control instance is not valid anymore.");
return;
}
if (this._sBlockSection === this._sBusySection) {
if (this._oBlockState) {
BusyIndicatorUtils.addHTML(this._oBlockState, this.getBusyIndicatorSize());
BlockLayerUtils.toggleAnimationStyle(this._oBlockState, true);
this._oBusyBlockState = this._oBlockState;
} else {
// BusyIndicator is the first blocking element created (and )
fnAddStandaloneBusyIndicator.call(this);
}
} else {
// Standalone busy indicator
fnAddStandaloneBusyIndicator.call(this);
}
}
|
javascript
|
function fnAppendBusyIndicator() {
// Only append if busy state is still set
if (!this.getBusy()) {
return;
}
var $this = this.$(this._sBusySection);
//If there is a pending delayed call to append the busy indicator, we can clear it now
if (this._busyIndicatorDelayedCallId) {
clearTimeout(this._busyIndicatorDelayedCallId);
delete this._busyIndicatorDelayedCallId;
}
// if no busy section/control jquery instance could be retrieved -> the control is not part of the dom anymore
// this might happen in certain scenarios when e.g. a dialog is closed faster than the busyIndicatorDelay
if (!$this || $this.length === 0) {
Log.warning("BusyIndicator could not be rendered. The outer control instance is not valid anymore.");
return;
}
if (this._sBlockSection === this._sBusySection) {
if (this._oBlockState) {
BusyIndicatorUtils.addHTML(this._oBlockState, this.getBusyIndicatorSize());
BlockLayerUtils.toggleAnimationStyle(this._oBlockState, true);
this._oBusyBlockState = this._oBlockState;
} else {
// BusyIndicator is the first blocking element created (and )
fnAddStandaloneBusyIndicator.call(this);
}
} else {
// Standalone busy indicator
fnAddStandaloneBusyIndicator.call(this);
}
}
|
[
"function",
"fnAppendBusyIndicator",
"(",
")",
"{",
"if",
"(",
"!",
"this",
".",
"getBusy",
"(",
")",
")",
"{",
"return",
";",
"}",
"var",
"$this",
"=",
"this",
".",
"$",
"(",
"this",
".",
"_sBusySection",
")",
";",
"if",
"(",
"this",
".",
"_busyIndicatorDelayedCallId",
")",
"{",
"clearTimeout",
"(",
"this",
".",
"_busyIndicatorDelayedCallId",
")",
";",
"delete",
"this",
".",
"_busyIndicatorDelayedCallId",
";",
"}",
"if",
"(",
"!",
"$this",
"||",
"$this",
".",
"length",
"===",
"0",
")",
"{",
"Log",
".",
"warning",
"(",
"\"BusyIndicator could not be rendered. The outer control instance is not valid anymore.\"",
")",
";",
"return",
";",
"}",
"if",
"(",
"this",
".",
"_sBlockSection",
"===",
"this",
".",
"_sBusySection",
")",
"{",
"if",
"(",
"this",
".",
"_oBlockState",
")",
"{",
"BusyIndicatorUtils",
".",
"addHTML",
"(",
"this",
".",
"_oBlockState",
",",
"this",
".",
"getBusyIndicatorSize",
"(",
")",
")",
";",
"BlockLayerUtils",
".",
"toggleAnimationStyle",
"(",
"this",
".",
"_oBlockState",
",",
"true",
")",
";",
"this",
".",
"_oBusyBlockState",
"=",
"this",
".",
"_oBlockState",
";",
"}",
"else",
"{",
"fnAddStandaloneBusyIndicator",
".",
"call",
"(",
"this",
")",
";",
"}",
"}",
"else",
"{",
"fnAddStandaloneBusyIndicator",
".",
"call",
"(",
"this",
")",
";",
"}",
"}"
] |
Add busy indicator to DOM
@private
|
[
"Add",
"busy",
"indicator",
"to",
"DOM"
] |
8a832fca01cb1cdf8df589788e0c5723e2a33c70
|
https://github.com/SAP/openui5/blob/8a832fca01cb1cdf8df589788e0c5723e2a33c70/src/sap.ui.core/src/sap/ui/core/Control.js#L721-L759
|
train
|
SAP/openui5
|
src/sap.ui.core/src/sap/ui/core/Control.js
|
fnAddStandaloneBlockLayer
|
function fnAddStandaloneBlockLayer () {
this._oBlockState = BlockLayerUtils.block(this, this.getId() + "-blockedLayer", this._sBlockSection);
jQuery(this._oBlockState.$blockLayer.get(0)).addClass("sapUiBlockLayerOnly");
}
|
javascript
|
function fnAddStandaloneBlockLayer () {
this._oBlockState = BlockLayerUtils.block(this, this.getId() + "-blockedLayer", this._sBlockSection);
jQuery(this._oBlockState.$blockLayer.get(0)).addClass("sapUiBlockLayerOnly");
}
|
[
"function",
"fnAddStandaloneBlockLayer",
"(",
")",
"{",
"this",
".",
"_oBlockState",
"=",
"BlockLayerUtils",
".",
"block",
"(",
"this",
",",
"this",
".",
"getId",
"(",
")",
"+",
"\"-blockedLayer\"",
",",
"this",
".",
"_sBlockSection",
")",
";",
"jQuery",
"(",
"this",
".",
"_oBlockState",
".",
"$blockLayer",
".",
"get",
"(",
"0",
")",
")",
".",
"addClass",
"(",
"\"sapUiBlockLayerOnly\"",
")",
";",
"}"
] |
Adds a standalone block-layer. Might be shared with a BusyIndicator later on.
|
[
"Adds",
"a",
"standalone",
"block",
"-",
"layer",
".",
"Might",
"be",
"shared",
"with",
"a",
"BusyIndicator",
"later",
"on",
"."
] |
8a832fca01cb1cdf8df589788e0c5723e2a33c70
|
https://github.com/SAP/openui5/blob/8a832fca01cb1cdf8df589788e0c5723e2a33c70/src/sap.ui.core/src/sap/ui/core/Control.js#L764-L767
|
train
|
SAP/openui5
|
src/sap.ui.core/src/sap/ui/core/Control.js
|
fnAddStandaloneBusyIndicator
|
function fnAddStandaloneBusyIndicator () {
this._oBusyBlockState = BlockLayerUtils.block(this, this.getId() + "-busyIndicator", this._sBusySection);
BusyIndicatorUtils.addHTML(this._oBusyBlockState, this.getBusyIndicatorSize());
}
|
javascript
|
function fnAddStandaloneBusyIndicator () {
this._oBusyBlockState = BlockLayerUtils.block(this, this.getId() + "-busyIndicator", this._sBusySection);
BusyIndicatorUtils.addHTML(this._oBusyBlockState, this.getBusyIndicatorSize());
}
|
[
"function",
"fnAddStandaloneBusyIndicator",
"(",
")",
"{",
"this",
".",
"_oBusyBlockState",
"=",
"BlockLayerUtils",
".",
"block",
"(",
"this",
",",
"this",
".",
"getId",
"(",
")",
"+",
"\"-busyIndicator\"",
",",
"this",
".",
"_sBusySection",
")",
";",
"BusyIndicatorUtils",
".",
"addHTML",
"(",
"this",
".",
"_oBusyBlockState",
",",
"this",
".",
"getBusyIndicatorSize",
"(",
")",
")",
";",
"}"
] |
Adds a standalone BusyIndicator.
The block-layer code is able to recognize that a new block-layer is not needed.
|
[
"Adds",
"a",
"standalone",
"BusyIndicator",
".",
"The",
"block",
"-",
"layer",
"code",
"is",
"able",
"to",
"recognize",
"that",
"a",
"new",
"block",
"-",
"layer",
"is",
"not",
"needed",
"."
] |
8a832fca01cb1cdf8df589788e0c5723e2a33c70
|
https://github.com/SAP/openui5/blob/8a832fca01cb1cdf8df589788e0c5723e2a33c70/src/sap.ui.core/src/sap/ui/core/Control.js#L773-L776
|
train
|
SAP/openui5
|
src/sap.ui.core/src/sap/ui/core/Control.js
|
fnRemoveBusyIndicator
|
function fnRemoveBusyIndicator(bForceRemoval) {
// removing all block layers is done upon rerendering and destroy of the control
if (bForceRemoval) {
fnRemoveAllBlockLayers.call(this);
return;
}
var $this = this.$(this._sBusySection);
$this.removeClass('sapUiLocalBusy');
//Unset the actual DOM Element´s 'aria-busy'
$this.removeAttr('aria-busy');
if (this._sBlockSection === this._sBusySection) {
if (!this.getBlocked() && !this.getBusy()) {
// Remove shared block state & busy block state reference
fnRemoveAllBlockLayers.call(this);
} else if (this.getBlocked()) {
// Hide animation in shared block layer
BlockLayerUtils.toggleAnimationStyle(this._oBlockState || this._oBusyBlockState, false);
this._oBlockState = this._oBusyBlockState;
} else if (this._oBusyBlockState) {
BlockLayerUtils.unblock(this._oBusyBlockState);
delete this._oBusyBlockState;
}
} else if (this._oBusyBlockState) {
// standalone busy block state
BlockLayerUtils.unblock(this._oBusyBlockState);
delete this._oBusyBlockState;
}
}
|
javascript
|
function fnRemoveBusyIndicator(bForceRemoval) {
// removing all block layers is done upon rerendering and destroy of the control
if (bForceRemoval) {
fnRemoveAllBlockLayers.call(this);
return;
}
var $this = this.$(this._sBusySection);
$this.removeClass('sapUiLocalBusy');
//Unset the actual DOM Element´s 'aria-busy'
$this.removeAttr('aria-busy');
if (this._sBlockSection === this._sBusySection) {
if (!this.getBlocked() && !this.getBusy()) {
// Remove shared block state & busy block state reference
fnRemoveAllBlockLayers.call(this);
} else if (this.getBlocked()) {
// Hide animation in shared block layer
BlockLayerUtils.toggleAnimationStyle(this._oBlockState || this._oBusyBlockState, false);
this._oBlockState = this._oBusyBlockState;
} else if (this._oBusyBlockState) {
BlockLayerUtils.unblock(this._oBusyBlockState);
delete this._oBusyBlockState;
}
} else if (this._oBusyBlockState) {
// standalone busy block state
BlockLayerUtils.unblock(this._oBusyBlockState);
delete this._oBusyBlockState;
}
}
|
[
"function",
"fnRemoveBusyIndicator",
"(",
"bForceRemoval",
")",
"{",
"if",
"(",
"bForceRemoval",
")",
"{",
"fnRemoveAllBlockLayers",
".",
"call",
"(",
"this",
")",
";",
"return",
";",
"}",
"var",
"$this",
"=",
"this",
".",
"$",
"(",
"this",
".",
"_sBusySection",
")",
";",
"$this",
".",
"removeClass",
"(",
"'sapUiLocalBusy'",
")",
";",
"$this",
".",
"removeAttr",
"(",
"'aria-busy'",
")",
";",
"if",
"(",
"this",
".",
"_sBlockSection",
"===",
"this",
".",
"_sBusySection",
")",
"{",
"if",
"(",
"!",
"this",
".",
"getBlocked",
"(",
")",
"&&",
"!",
"this",
".",
"getBusy",
"(",
")",
")",
"{",
"fnRemoveAllBlockLayers",
".",
"call",
"(",
"this",
")",
";",
"}",
"else",
"if",
"(",
"this",
".",
"getBlocked",
"(",
")",
")",
"{",
"BlockLayerUtils",
".",
"toggleAnimationStyle",
"(",
"this",
".",
"_oBlockState",
"||",
"this",
".",
"_oBusyBlockState",
",",
"false",
")",
";",
"this",
".",
"_oBlockState",
"=",
"this",
".",
"_oBusyBlockState",
";",
"}",
"else",
"if",
"(",
"this",
".",
"_oBusyBlockState",
")",
"{",
"BlockLayerUtils",
".",
"unblock",
"(",
"this",
".",
"_oBusyBlockState",
")",
";",
"delete",
"this",
".",
"_oBusyBlockState",
";",
"}",
"}",
"else",
"if",
"(",
"this",
".",
"_oBusyBlockState",
")",
"{",
"BlockLayerUtils",
".",
"unblock",
"(",
"this",
".",
"_oBusyBlockState",
")",
";",
"delete",
"this",
".",
"_oBusyBlockState",
";",
"}",
"}"
] |
Remove busy indicator from DOM
@param {boolean} bForceRemoval Forces the removal of all Block layers
@private
|
[
"Remove",
"busy",
"indicator",
"from",
"DOM"
] |
8a832fca01cb1cdf8df589788e0c5723e2a33c70
|
https://github.com/SAP/openui5/blob/8a832fca01cb1cdf8df589788e0c5723e2a33c70/src/sap.ui.core/src/sap/ui/core/Control.js#L796-L831
|
train
|
SAP/openui5
|
src/sap.ui.core/src/sap/ui/model/odata/ODataMessageParser.js
|
filterDuplicates
|
function filterDuplicates(/*ref*/ aMessages){
if (aMessages.length > 1) {
for (var iIndex = 1; iIndex < aMessages.length; iIndex++) {
if (aMessages[0].getCode() == aMessages[iIndex].getCode() && aMessages[0].getMessage() == aMessages[iIndex].getMessage()) {
aMessages.shift(); // Remove outer error, since inner error is more detailed
break;
}
}
}
}
|
javascript
|
function filterDuplicates(/*ref*/ aMessages){
if (aMessages.length > 1) {
for (var iIndex = 1; iIndex < aMessages.length; iIndex++) {
if (aMessages[0].getCode() == aMessages[iIndex].getCode() && aMessages[0].getMessage() == aMessages[iIndex].getMessage()) {
aMessages.shift(); // Remove outer error, since inner error is more detailed
break;
}
}
}
}
|
[
"function",
"filterDuplicates",
"(",
"aMessages",
")",
"{",
"if",
"(",
"aMessages",
".",
"length",
">",
"1",
")",
"{",
"for",
"(",
"var",
"iIndex",
"=",
"1",
";",
"iIndex",
"<",
"aMessages",
".",
"length",
";",
"iIndex",
"++",
")",
"{",
"if",
"(",
"aMessages",
"[",
"0",
"]",
".",
"getCode",
"(",
")",
"==",
"aMessages",
"[",
"iIndex",
"]",
".",
"getCode",
"(",
")",
"&&",
"aMessages",
"[",
"0",
"]",
".",
"getMessage",
"(",
")",
"==",
"aMessages",
"[",
"iIndex",
"]",
".",
"getMessage",
"(",
")",
")",
"{",
"aMessages",
".",
"shift",
"(",
")",
";",
"break",
";",
"}",
"}",
"}",
"}"
] |
The message container returned by the backend could contain duplicate messages in some scenarios.
The outer error could be identical to an inner error. This makes sense when the outer error is only though as error message container
for the inner errors and therefore shouldn't be end up in a seperate UI message.
This function is used to filter out not relevant outer errors.
@example
{
"error": {
"code": "ABC",
"message": {
"value": "Bad things happened."
},
"innererror": {
"errordetails": [
{
"code": "ABC",
"message": "Bad things happened."
},
...
@private
|
[
"The",
"message",
"container",
"returned",
"by",
"the",
"backend",
"could",
"contain",
"duplicate",
"messages",
"in",
"some",
"scenarios",
".",
"The",
"outer",
"error",
"could",
"be",
"identical",
"to",
"an",
"inner",
"error",
".",
"This",
"makes",
"sense",
"when",
"the",
"outer",
"error",
"is",
"only",
"though",
"as",
"error",
"message",
"container",
"for",
"the",
"inner",
"errors",
"and",
"therefore",
"shouldn",
"t",
"be",
"end",
"up",
"in",
"a",
"seperate",
"UI",
"message",
"."
] |
8a832fca01cb1cdf8df589788e0c5723e2a33c70
|
https://github.com/SAP/openui5/blob/8a832fca01cb1cdf8df589788e0c5723e2a33c70/src/sap.ui.core/src/sap/ui/model/odata/ODataMessageParser.js#L892-L901
|
train
|
SAP/openui5
|
src/sap.ui.core/src/sap/ui/core/date/Buddhist.js
|
toBuddhist
|
function toBuddhist(oGregorian) {
var iEraStartYear = UniversalDate.getEraStartDate(CalendarType.Buddhist, 0).year,
iYear = oGregorian.year - iEraStartYear + 1;
// Before 1941 new year started on 1st of April
if (oGregorian.year < 1941 && oGregorian.month < 3) {
iYear -= 1;
}
if (oGregorian.year === null) {
iYear = undefined;
}
return {
year: iYear,
month: oGregorian.month,
day: oGregorian.day
};
}
|
javascript
|
function toBuddhist(oGregorian) {
var iEraStartYear = UniversalDate.getEraStartDate(CalendarType.Buddhist, 0).year,
iYear = oGregorian.year - iEraStartYear + 1;
// Before 1941 new year started on 1st of April
if (oGregorian.year < 1941 && oGregorian.month < 3) {
iYear -= 1;
}
if (oGregorian.year === null) {
iYear = undefined;
}
return {
year: iYear,
month: oGregorian.month,
day: oGregorian.day
};
}
|
[
"function",
"toBuddhist",
"(",
"oGregorian",
")",
"{",
"var",
"iEraStartYear",
"=",
"UniversalDate",
".",
"getEraStartDate",
"(",
"CalendarType",
".",
"Buddhist",
",",
"0",
")",
".",
"year",
",",
"iYear",
"=",
"oGregorian",
".",
"year",
"-",
"iEraStartYear",
"+",
"1",
";",
"if",
"(",
"oGregorian",
".",
"year",
"<",
"1941",
"&&",
"oGregorian",
".",
"month",
"<",
"3",
")",
"{",
"iYear",
"-=",
"1",
";",
"}",
"if",
"(",
"oGregorian",
".",
"year",
"===",
"null",
")",
"{",
"iYear",
"=",
"undefined",
";",
"}",
"return",
"{",
"year",
":",
"iYear",
",",
"month",
":",
"oGregorian",
".",
"month",
",",
"day",
":",
"oGregorian",
".",
"day",
"}",
";",
"}"
] |
Find the matching Buddhist date for the given gregorian date
@param {object} oGregorian
@return {object}
|
[
"Find",
"the",
"matching",
"Buddhist",
"date",
"for",
"the",
"given",
"gregorian",
"date"
] |
8a832fca01cb1cdf8df589788e0c5723e2a33c70
|
https://github.com/SAP/openui5/blob/8a832fca01cb1cdf8df589788e0c5723e2a33c70/src/sap.ui.core/src/sap/ui/core/date/Buddhist.js#L48-L63
|
train
|
SAP/openui5
|
src/sap.ui.core/src/sap/ui/core/date/Buddhist.js
|
toGregorian
|
function toGregorian(oBuddhist) {
var iEraStartYear = UniversalDate.getEraStartDate(CalendarType.Buddhist, 0).year,
iYear = oBuddhist.year + iEraStartYear - 1;
// Before 1941 new year started on 1st of April
if (iYear < 1941 && oBuddhist.month < 3) {
iYear += 1;
}
if (oBuddhist.year === null) {
iYear = undefined;
}
return {
year: iYear,
month: oBuddhist.month,
day: oBuddhist.day
};
}
|
javascript
|
function toGregorian(oBuddhist) {
var iEraStartYear = UniversalDate.getEraStartDate(CalendarType.Buddhist, 0).year,
iYear = oBuddhist.year + iEraStartYear - 1;
// Before 1941 new year started on 1st of April
if (iYear < 1941 && oBuddhist.month < 3) {
iYear += 1;
}
if (oBuddhist.year === null) {
iYear = undefined;
}
return {
year: iYear,
month: oBuddhist.month,
day: oBuddhist.day
};
}
|
[
"function",
"toGregorian",
"(",
"oBuddhist",
")",
"{",
"var",
"iEraStartYear",
"=",
"UniversalDate",
".",
"getEraStartDate",
"(",
"CalendarType",
".",
"Buddhist",
",",
"0",
")",
".",
"year",
",",
"iYear",
"=",
"oBuddhist",
".",
"year",
"+",
"iEraStartYear",
"-",
"1",
";",
"if",
"(",
"iYear",
"<",
"1941",
"&&",
"oBuddhist",
".",
"month",
"<",
"3",
")",
"{",
"iYear",
"+=",
"1",
";",
"}",
"if",
"(",
"oBuddhist",
".",
"year",
"===",
"null",
")",
"{",
"iYear",
"=",
"undefined",
";",
"}",
"return",
"{",
"year",
":",
"iYear",
",",
"month",
":",
"oBuddhist",
".",
"month",
",",
"day",
":",
"oBuddhist",
".",
"day",
"}",
";",
"}"
] |
Calculate gregorian year from Buddhist year and month
@param {object} oBuddhist
@return {int}
|
[
"Calculate",
"gregorian",
"year",
"from",
"Buddhist",
"year",
"and",
"month"
] |
8a832fca01cb1cdf8df589788e0c5723e2a33c70
|
https://github.com/SAP/openui5/blob/8a832fca01cb1cdf8df589788e0c5723e2a33c70/src/sap.ui.core/src/sap/ui/core/date/Buddhist.js#L71-L86
|
train
|
SAP/openui5
|
src/sap.ui.core/src/sap/ui/core/date/Buddhist.js
|
toGregorianArguments
|
function toGregorianArguments(aArgs) {
var oBuddhist, oGregorian;
oBuddhist = {
year: aArgs[0],
month: aArgs[1],
day: aArgs[2] !== undefined ? aArgs[2] : 1
};
oGregorian = toGregorian(oBuddhist);
aArgs[0] = oGregorian.year;
return aArgs;
}
|
javascript
|
function toGregorianArguments(aArgs) {
var oBuddhist, oGregorian;
oBuddhist = {
year: aArgs[0],
month: aArgs[1],
day: aArgs[2] !== undefined ? aArgs[2] : 1
};
oGregorian = toGregorian(oBuddhist);
aArgs[0] = oGregorian.year;
return aArgs;
}
|
[
"function",
"toGregorianArguments",
"(",
"aArgs",
")",
"{",
"var",
"oBuddhist",
",",
"oGregorian",
";",
"oBuddhist",
"=",
"{",
"year",
":",
"aArgs",
"[",
"0",
"]",
",",
"month",
":",
"aArgs",
"[",
"1",
"]",
",",
"day",
":",
"aArgs",
"[",
"2",
"]",
"!==",
"undefined",
"?",
"aArgs",
"[",
"2",
"]",
":",
"1",
"}",
";",
"oGregorian",
"=",
"toGregorian",
"(",
"oBuddhist",
")",
";",
"aArgs",
"[",
"0",
"]",
"=",
"oGregorian",
".",
"year",
";",
"return",
"aArgs",
";",
"}"
] |
Convert arguments array from Buddhist date to gregorian data
@param {object} oBuddhist
@return {int}
|
[
"Convert",
"arguments",
"array",
"from",
"Buddhist",
"date",
"to",
"gregorian",
"data"
] |
8a832fca01cb1cdf8df589788e0c5723e2a33c70
|
https://github.com/SAP/openui5/blob/8a832fca01cb1cdf8df589788e0c5723e2a33c70/src/sap.ui.core/src/sap/ui/core/date/Buddhist.js#L94-L104
|
train
|
SAP/openui5
|
src/sap.ui.support/src/sap/ui/support/supportRules/util/Utils.js
|
function (oVersionInfo) {
var bResult = false,
sFrameworkInfo = "";
try {
sFrameworkInfo = oVersionInfo.gav ? oVersionInfo.gav : oVersionInfo.name;
bResult = sFrameworkInfo.indexOf('openui5') !== -1 ? true : false;
} catch (e) {
return bResult;
}
return bResult;
}
|
javascript
|
function (oVersionInfo) {
var bResult = false,
sFrameworkInfo = "";
try {
sFrameworkInfo = oVersionInfo.gav ? oVersionInfo.gav : oVersionInfo.name;
bResult = sFrameworkInfo.indexOf('openui5') !== -1 ? true : false;
} catch (e) {
return bResult;
}
return bResult;
}
|
[
"function",
"(",
"oVersionInfo",
")",
"{",
"var",
"bResult",
"=",
"false",
",",
"sFrameworkInfo",
"=",
"\"\"",
";",
"try",
"{",
"sFrameworkInfo",
"=",
"oVersionInfo",
".",
"gav",
"?",
"oVersionInfo",
".",
"gav",
":",
"oVersionInfo",
".",
"name",
";",
"bResult",
"=",
"sFrameworkInfo",
".",
"indexOf",
"(",
"'openui5'",
")",
"!==",
"-",
"1",
"?",
"true",
":",
"false",
";",
"}",
"catch",
"(",
"e",
")",
"{",
"return",
"bResult",
";",
"}",
"return",
"bResult",
";",
"}"
] |
Checks the distribution of UI5 that the Application is using
@public
@param {object} oVersionInfo information about the UI5 freawork used by the Application
@returns {boolean} result true if the distribution of application is OPENUI5
|
[
"Checks",
"the",
"distribution",
"of",
"UI5",
"that",
"the",
"Application",
"is",
"using"
] |
8a832fca01cb1cdf8df589788e0c5723e2a33c70
|
https://github.com/SAP/openui5/blob/8a832fca01cb1cdf8df589788e0c5723e2a33c70/src/sap.ui.support/src/sap/ui/support/supportRules/util/Utils.js#L23-L35
|
train
|
|
SAP/openui5
|
src/sap.ui.support/src/sap/ui/support/supportRules/util/Utils.js
|
function () {
var that = this;
var oInternalRulesPromise = new Promise(function (resolve) {
if (that.bCanLoadInternalRules !== null) {
resolve(that.bCanLoadInternalRules);
return;
}
jQuery.ajax({
type: "HEAD",
url: sInternalPingFilePath,
success: function () {
that.bCanLoadInternalRules = true;
resolve(that.bCanLoadInternalRules);
},
error: function() {
that.bCanLoadInternalRules = false;
resolve(that.bCanLoadInternalRules);
}
});
});
return oInternalRulesPromise;
}
|
javascript
|
function () {
var that = this;
var oInternalRulesPromise = new Promise(function (resolve) {
if (that.bCanLoadInternalRules !== null) {
resolve(that.bCanLoadInternalRules);
return;
}
jQuery.ajax({
type: "HEAD",
url: sInternalPingFilePath,
success: function () {
that.bCanLoadInternalRules = true;
resolve(that.bCanLoadInternalRules);
},
error: function() {
that.bCanLoadInternalRules = false;
resolve(that.bCanLoadInternalRules);
}
});
});
return oInternalRulesPromise;
}
|
[
"function",
"(",
")",
"{",
"var",
"that",
"=",
"this",
";",
"var",
"oInternalRulesPromise",
"=",
"new",
"Promise",
"(",
"function",
"(",
"resolve",
")",
"{",
"if",
"(",
"that",
".",
"bCanLoadInternalRules",
"!==",
"null",
")",
"{",
"resolve",
"(",
"that",
".",
"bCanLoadInternalRules",
")",
";",
"return",
";",
"}",
"jQuery",
".",
"ajax",
"(",
"{",
"type",
":",
"\"HEAD\"",
",",
"url",
":",
"sInternalPingFilePath",
",",
"success",
":",
"function",
"(",
")",
"{",
"that",
".",
"bCanLoadInternalRules",
"=",
"true",
";",
"resolve",
"(",
"that",
".",
"bCanLoadInternalRules",
")",
";",
"}",
",",
"error",
":",
"function",
"(",
")",
"{",
"that",
".",
"bCanLoadInternalRules",
"=",
"false",
";",
"resolve",
"(",
"that",
".",
"bCanLoadInternalRules",
")",
";",
"}",
"}",
")",
";",
"}",
")",
";",
"return",
"oInternalRulesPromise",
";",
"}"
] |
Checks if there are internal rules files that has to be loaded
@returns {Promise} The returned promise resolves with an argument showing
whether internal rules can be loaded or not
|
[
"Checks",
"if",
"there",
"are",
"internal",
"rules",
"files",
"that",
"has",
"to",
"be",
"loaded"
] |
8a832fca01cb1cdf8df589788e0c5723e2a33c70
|
https://github.com/SAP/openui5/blob/8a832fca01cb1cdf8df589788e0c5723e2a33c70/src/sap.ui.support/src/sap/ui/support/supportRules/util/Utils.js#L68-L95
|
train
|
|
SAP/openui5
|
src/sap.ui.layout/src/sap/ui/layout/form/ColumnLayout.js
|
function(aRows, iField, oLD, oOptions, iLabelSize) {
var iRemain = 0;
var oRow;
for (i = 0; i < aRows.length; i++) {
if (iField >= aRows[i].first && iField <= aRows[i].last) {
oRow = aRows[i];
break;
}
}
if (!oLD) {
oOptions.Size = Math.floor(oRow.availableCells / oRow.defaultFields);
}
if (iField === oRow.first && iField > 0) {
oOptions.Break = true;
if (iLabelSize > 0 && iLabelSize < iColumns && oOptions.Size <= iColumns - iLabelSize) {
oOptions.Space = iLabelSize;
}
}
if (iField === oRow.firstDefault) {
// add remaining cells to first default field
iRemain = oRow.availableCells - oRow.defaultFields * oOptions.Size;
if (iRemain > 0) {
oOptions.Size = oOptions.Size + iRemain;
}
}
}
|
javascript
|
function(aRows, iField, oLD, oOptions, iLabelSize) {
var iRemain = 0;
var oRow;
for (i = 0; i < aRows.length; i++) {
if (iField >= aRows[i].first && iField <= aRows[i].last) {
oRow = aRows[i];
break;
}
}
if (!oLD) {
oOptions.Size = Math.floor(oRow.availableCells / oRow.defaultFields);
}
if (iField === oRow.first && iField > 0) {
oOptions.Break = true;
if (iLabelSize > 0 && iLabelSize < iColumns && oOptions.Size <= iColumns - iLabelSize) {
oOptions.Space = iLabelSize;
}
}
if (iField === oRow.firstDefault) {
// add remaining cells to first default field
iRemain = oRow.availableCells - oRow.defaultFields * oOptions.Size;
if (iRemain > 0) {
oOptions.Size = oOptions.Size + iRemain;
}
}
}
|
[
"function",
"(",
"aRows",
",",
"iField",
",",
"oLD",
",",
"oOptions",
",",
"iLabelSize",
")",
"{",
"var",
"iRemain",
"=",
"0",
";",
"var",
"oRow",
";",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"aRows",
".",
"length",
";",
"i",
"++",
")",
"{",
"if",
"(",
"iField",
">=",
"aRows",
"[",
"i",
"]",
".",
"first",
"&&",
"iField",
"<=",
"aRows",
"[",
"i",
"]",
".",
"last",
")",
"{",
"oRow",
"=",
"aRows",
"[",
"i",
"]",
";",
"break",
";",
"}",
"}",
"if",
"(",
"!",
"oLD",
")",
"{",
"oOptions",
".",
"Size",
"=",
"Math",
".",
"floor",
"(",
"oRow",
".",
"availableCells",
"/",
"oRow",
".",
"defaultFields",
")",
";",
"}",
"if",
"(",
"iField",
"===",
"oRow",
".",
"first",
"&&",
"iField",
">",
"0",
")",
"{",
"oOptions",
".",
"Break",
"=",
"true",
";",
"if",
"(",
"iLabelSize",
">",
"0",
"&&",
"iLabelSize",
"<",
"iColumns",
"&&",
"oOptions",
".",
"Size",
"<=",
"iColumns",
"-",
"iLabelSize",
")",
"{",
"oOptions",
".",
"Space",
"=",
"iLabelSize",
";",
"}",
"}",
"if",
"(",
"iField",
"===",
"oRow",
".",
"firstDefault",
")",
"{",
"iRemain",
"=",
"oRow",
".",
"availableCells",
"-",
"oRow",
".",
"defaultFields",
"*",
"oOptions",
".",
"Size",
";",
"if",
"(",
"iRemain",
">",
"0",
")",
"{",
"oOptions",
".",
"Size",
"=",
"oOptions",
".",
"Size",
"+",
"iRemain",
";",
"}",
"}",
"}"
] |
determine size of Field
|
[
"determine",
"size",
"of",
"Field"
] |
8a832fca01cb1cdf8df589788e0c5723e2a33c70
|
https://github.com/SAP/openui5/blob/8a832fca01cb1cdf8df589788e0c5723e2a33c70/src/sap.ui.layout/src/sap/ui/layout/form/ColumnLayout.js#L506-L533
|
train
|
|
SAP/openui5
|
src/sap.ui.core/src/sap/ui/thirdparty/caja-html-sanitizer.js
|
sanitizeHistorySensitive
|
function sanitizeHistorySensitive(blockOfProperties) {
var elide = false;
for (var i = 0, n = blockOfProperties.length; i < n-1; ++i) {
var token = blockOfProperties[i];
if (':' === blockOfProperties[i+1]) {
elide = !(cssSchema[token].cssPropBits & CSS_PROP_BIT_ALLOWED_IN_LINK);
}
if (elide) { blockOfProperties[i] = ''; }
if (';' === token) { elide = false; }
}
return blockOfProperties.join('');
}
|
javascript
|
function sanitizeHistorySensitive(blockOfProperties) {
var elide = false;
for (var i = 0, n = blockOfProperties.length; i < n-1; ++i) {
var token = blockOfProperties[i];
if (':' === blockOfProperties[i+1]) {
elide = !(cssSchema[token].cssPropBits & CSS_PROP_BIT_ALLOWED_IN_LINK);
}
if (elide) { blockOfProperties[i] = ''; }
if (';' === token) { elide = false; }
}
return blockOfProperties.join('');
}
|
[
"function",
"sanitizeHistorySensitive",
"(",
"blockOfProperties",
")",
"{",
"var",
"elide",
"=",
"false",
";",
"for",
"(",
"var",
"i",
"=",
"0",
",",
"n",
"=",
"blockOfProperties",
".",
"length",
";",
"i",
"<",
"n",
"-",
"1",
";",
"++",
"i",
")",
"{",
"var",
"token",
"=",
"blockOfProperties",
"[",
"i",
"]",
";",
"if",
"(",
"':'",
"===",
"blockOfProperties",
"[",
"i",
"+",
"1",
"]",
")",
"{",
"elide",
"=",
"!",
"(",
"cssSchema",
"[",
"token",
"]",
".",
"cssPropBits",
"&",
"CSS_PROP_BIT_ALLOWED_IN_LINK",
")",
";",
"}",
"if",
"(",
"elide",
")",
"{",
"blockOfProperties",
"[",
"i",
"]",
"=",
"''",
";",
"}",
"if",
"(",
"';'",
"===",
"token",
")",
"{",
"elide",
"=",
"false",
";",
"}",
"}",
"return",
"blockOfProperties",
".",
"join",
"(",
"''",
")",
";",
"}"
] |
Given a series of sanitized tokens, removes any properties that would
leak user history if allowed to style links differently depending on
whether the linked URL is in the user's browser history.
@param {Array.<string>} blockOfProperties
|
[
"Given",
"a",
"series",
"of",
"sanitized",
"tokens",
"removes",
"any",
"properties",
"that",
"would",
"leak",
"user",
"history",
"if",
"allowed",
"to",
"style",
"links",
"differently",
"depending",
"on",
"whether",
"the",
"linked",
"URL",
"is",
"in",
"the",
"user",
"s",
"browser",
"history",
"."
] |
8a832fca01cb1cdf8df589788e0c5723e2a33c70
|
https://github.com/SAP/openui5/blob/8a832fca01cb1cdf8df589788e0c5723e2a33c70/src/sap.ui.core/src/sap/ui/thirdparty/caja-html-sanitizer.js#L1493-L1504
|
train
|
SAP/openui5
|
src/sap.ui.core/src/sap/ui/thirdparty/caja-html-sanitizer.js
|
escapeAttrib
|
function escapeAttrib(s) {
return ('' + s).replace(ampRe, '&').replace(ltRe, '<')
.replace(gtRe, '>').replace(quotRe, '"');
}
|
javascript
|
function escapeAttrib(s) {
return ('' + s).replace(ampRe, '&').replace(ltRe, '<')
.replace(gtRe, '>').replace(quotRe, '"');
}
|
[
"function",
"escapeAttrib",
"(",
"s",
")",
"{",
"return",
"(",
"''",
"+",
"s",
")",
".",
"replace",
"(",
"ampRe",
",",
"'&'",
")",
".",
"replace",
"(",
"ltRe",
",",
"'<'",
")",
".",
"replace",
"(",
"gtRe",
",",
"'>'",
")",
".",
"replace",
"(",
"quotRe",
",",
"'"'",
")",
";",
"}"
] |
Escapes HTML special characters in attribute values.
{\@updoc
$ escapeAttrib('')
# ''
$ escapeAttrib('"<<&==&>>"') // Do not just escape the first occurrence.
# '"<<&==&>>"'
$ escapeAttrib('Hello <World>!')
# 'Hello <World>!'
}
|
[
"Escapes",
"HTML",
"special",
"characters",
"in",
"attribute",
"values",
"."
] |
8a832fca01cb1cdf8df589788e0c5723e2a33c70
|
https://github.com/SAP/openui5/blob/8a832fca01cb1cdf8df589788e0c5723e2a33c70/src/sap.ui.core/src/sap/ui/thirdparty/caja-html-sanitizer.js#L2842-L2845
|
train
|
SAP/openui5
|
src/sap.ui.core/src/sap/ui/thirdparty/caja-html-sanitizer.js
|
htmlSplit
|
function htmlSplit(str) {
// can't hoist this out of the function because of the re.exec loop.
var re = /(<\/|<\!--|<[!?]|[&<>])/g;
str += '';
if (splitWillCapture) {
return str.split(re);
} else {
var parts = [];
var lastPos = 0;
var m;
while ((m = re.exec(str)) !== null) {
parts.push(str.substring(lastPos, m.index));
parts.push(m[0]);
lastPos = m.index + m[0].length;
}
parts.push(str.substring(lastPos));
return parts;
}
}
|
javascript
|
function htmlSplit(str) {
// can't hoist this out of the function because of the re.exec loop.
var re = /(<\/|<\!--|<[!?]|[&<>])/g;
str += '';
if (splitWillCapture) {
return str.split(re);
} else {
var parts = [];
var lastPos = 0;
var m;
while ((m = re.exec(str)) !== null) {
parts.push(str.substring(lastPos, m.index));
parts.push(m[0]);
lastPos = m.index + m[0].length;
}
parts.push(str.substring(lastPos));
return parts;
}
}
|
[
"function",
"htmlSplit",
"(",
"str",
")",
"{",
"var",
"re",
"=",
"/",
"(<\\/|<\\!--|<[!?]|[&<>])",
"/",
"g",
";",
"str",
"+=",
"''",
";",
"if",
"(",
"splitWillCapture",
")",
"{",
"return",
"str",
".",
"split",
"(",
"re",
")",
";",
"}",
"else",
"{",
"var",
"parts",
"=",
"[",
"]",
";",
"var",
"lastPos",
"=",
"0",
";",
"var",
"m",
";",
"while",
"(",
"(",
"m",
"=",
"re",
".",
"exec",
"(",
"str",
")",
")",
"!==",
"null",
")",
"{",
"parts",
".",
"push",
"(",
"str",
".",
"substring",
"(",
"lastPos",
",",
"m",
".",
"index",
")",
")",
";",
"parts",
".",
"push",
"(",
"m",
"[",
"0",
"]",
")",
";",
"lastPos",
"=",
"m",
".",
"index",
"+",
"m",
"[",
"0",
"]",
".",
"length",
";",
"}",
"parts",
".",
"push",
"(",
"str",
".",
"substring",
"(",
"lastPos",
")",
")",
";",
"return",
"parts",
";",
"}",
"}"
] |
Split str into parts for the html parser.
|
[
"Split",
"str",
"into",
"parts",
"for",
"the",
"html",
"parser",
"."
] |
8a832fca01cb1cdf8df589788e0c5723e2a33c70
|
https://github.com/SAP/openui5/blob/8a832fca01cb1cdf8df589788e0c5723e2a33c70/src/sap.ui.core/src/sap/ui/thirdparty/caja-html-sanitizer.js#L3152-L3170
|
train
|
SAP/openui5
|
src/sap.ui.core/src/sap/ui/thirdparty/caja-html-sanitizer.js
|
sanitize
|
function sanitize(inputHtml, opt_naiveUriRewriter, opt_nmTokenPolicy) {
var tagPolicy = makeTagPolicy(opt_naiveUriRewriter, opt_nmTokenPolicy);
return sanitizeWithPolicy(inputHtml, tagPolicy);
}
|
javascript
|
function sanitize(inputHtml, opt_naiveUriRewriter, opt_nmTokenPolicy) {
var tagPolicy = makeTagPolicy(opt_naiveUriRewriter, opt_nmTokenPolicy);
return sanitizeWithPolicy(inputHtml, tagPolicy);
}
|
[
"function",
"sanitize",
"(",
"inputHtml",
",",
"opt_naiveUriRewriter",
",",
"opt_nmTokenPolicy",
")",
"{",
"var",
"tagPolicy",
"=",
"makeTagPolicy",
"(",
"opt_naiveUriRewriter",
",",
"opt_nmTokenPolicy",
")",
";",
"return",
"sanitizeWithPolicy",
"(",
"inputHtml",
",",
"tagPolicy",
")",
";",
"}"
] |
Strips unsafe tags and attributes from HTML.
@param {string} inputHtml The HTML to sanitize.
@param {?function(?string): ?string} opt_naiveUriRewriter A transform to
apply to URI attributes. If not given, URI attributes are deleted.
@param {function(?string): ?string} opt_nmTokenPolicy A transform to apply
to attributes containing HTML names, element IDs, and space-separated
lists of classes. If not given, such attributes are left unchanged.
|
[
"Strips",
"unsafe",
"tags",
"and",
"attributes",
"from",
"HTML",
"."
] |
8a832fca01cb1cdf8df589788e0c5723e2a33c70
|
https://github.com/SAP/openui5/blob/8a832fca01cb1cdf8df589788e0c5723e2a33c70/src/sap.ui.core/src/sap/ui/thirdparty/caja-html-sanitizer.js#L3552-L3555
|
train
|
SAP/openui5
|
src/sap.ui.core/src/sap/ui/performance/BeaconRequest.js
|
function (option) {
option = option || {};
if (!BeaconRequest.isSupported()) {
throw Error("Beacon API is not supported");
}
if (typeof option.url !== "string") {
throw Error("Beacon url must be valid");
}
this._nMaxBufferLength = option.maxBufferLength || 10;
this._aBuffer = [];
this._sUrl = option.url;
this.attachSendOnUnload();
}
|
javascript
|
function (option) {
option = option || {};
if (!BeaconRequest.isSupported()) {
throw Error("Beacon API is not supported");
}
if (typeof option.url !== "string") {
throw Error("Beacon url must be valid");
}
this._nMaxBufferLength = option.maxBufferLength || 10;
this._aBuffer = [];
this._sUrl = option.url;
this.attachSendOnUnload();
}
|
[
"function",
"(",
"option",
")",
"{",
"option",
"=",
"option",
"||",
"{",
"}",
";",
"if",
"(",
"!",
"BeaconRequest",
".",
"isSupported",
"(",
")",
")",
"{",
"throw",
"Error",
"(",
"\"Beacon API is not supported\"",
")",
";",
"}",
"if",
"(",
"typeof",
"option",
".",
"url",
"!==",
"\"string\"",
")",
"{",
"throw",
"Error",
"(",
"\"Beacon url must be valid\"",
")",
";",
"}",
"this",
".",
"_nMaxBufferLength",
"=",
"option",
".",
"maxBufferLength",
"||",
"10",
";",
"this",
".",
"_aBuffer",
"=",
"[",
"]",
";",
"this",
".",
"_sUrl",
"=",
"option",
".",
"url",
";",
"this",
".",
"attachSendOnUnload",
"(",
")",
";",
"}"
] |
A helper for buffering and sending BeaconRequests to a certain URL
@param {object} option Options for beacon API initialization
@param {string} option.url beacon URL
@param {string} option.maxBufferLength Number of entries in the stack before the beacon is send
@private
@ui5-restricted sap.ui.core
|
[
"A",
"helper",
"for",
"buffering",
"and",
"sending",
"BeaconRequests",
"to",
"a",
"certain",
"URL"
] |
8a832fca01cb1cdf8df589788e0c5723e2a33c70
|
https://github.com/SAP/openui5/blob/8a832fca01cb1cdf8df589788e0c5723e2a33c70/src/sap.ui.core/src/sap/ui/performance/BeaconRequest.js#L18-L33
|
train
|
|
SAP/openui5
|
src/sap.ui.support/src/sap/ui/support/supportRules/ui/controllers/Analysis.controller.js
|
function (sRule, bAsync) {
var sCheckFunction = this.model.getProperty(sRule + "/check");
if (!sCheckFunction) {
return;
}
// Check if a function is found
var oMatch = sCheckFunction.match(/function[^(]*\(([^)]*)\)/);
if (!oMatch) {
return;
}
// Get the parameters of the function found and trim, then split by word.
var aParams = oMatch[1].trim().split(/\W+/);
// Add missing parameters to ensure the resolve function is passed on the correct position.
aParams[0] = aParams[0] || "oIssueManager";
aParams[1] = aParams[1] || "oCoreFacade";
aParams[2] = aParams[2] || "oScope";
// If async add a fnResolve to the template else remove it.
if (bAsync) {
aParams[3] = aParams[3] || "fnResolve";
} else {
aParams = aParams.slice(0, 3);
}
// Replace the current parameters with the new ones.
var sNewCheckFunction = sCheckFunction.replace(/function[^(]*\(([^)]*)\)/, "function (" + aParams.join(", ") + ")");
this.model.setProperty(sRule + "/check", sNewCheckFunction);
}
|
javascript
|
function (sRule, bAsync) {
var sCheckFunction = this.model.getProperty(sRule + "/check");
if (!sCheckFunction) {
return;
}
// Check if a function is found
var oMatch = sCheckFunction.match(/function[^(]*\(([^)]*)\)/);
if (!oMatch) {
return;
}
// Get the parameters of the function found and trim, then split by word.
var aParams = oMatch[1].trim().split(/\W+/);
// Add missing parameters to ensure the resolve function is passed on the correct position.
aParams[0] = aParams[0] || "oIssueManager";
aParams[1] = aParams[1] || "oCoreFacade";
aParams[2] = aParams[2] || "oScope";
// If async add a fnResolve to the template else remove it.
if (bAsync) {
aParams[3] = aParams[3] || "fnResolve";
} else {
aParams = aParams.slice(0, 3);
}
// Replace the current parameters with the new ones.
var sNewCheckFunction = sCheckFunction.replace(/function[^(]*\(([^)]*)\)/, "function (" + aParams.join(", ") + ")");
this.model.setProperty(sRule + "/check", sNewCheckFunction);
}
|
[
"function",
"(",
"sRule",
",",
"bAsync",
")",
"{",
"var",
"sCheckFunction",
"=",
"this",
".",
"model",
".",
"getProperty",
"(",
"sRule",
"+",
"\"/check\"",
")",
";",
"if",
"(",
"!",
"sCheckFunction",
")",
"{",
"return",
";",
"}",
"var",
"oMatch",
"=",
"sCheckFunction",
".",
"match",
"(",
"/",
"function[^(]*\\(([^)]*)\\)",
"/",
")",
";",
"if",
"(",
"!",
"oMatch",
")",
"{",
"return",
";",
"}",
"var",
"aParams",
"=",
"oMatch",
"[",
"1",
"]",
".",
"trim",
"(",
")",
".",
"split",
"(",
"/",
"\\W+",
"/",
")",
";",
"aParams",
"[",
"0",
"]",
"=",
"aParams",
"[",
"0",
"]",
"||",
"\"oIssueManager\"",
";",
"aParams",
"[",
"1",
"]",
"=",
"aParams",
"[",
"1",
"]",
"||",
"\"oCoreFacade\"",
";",
"aParams",
"[",
"2",
"]",
"=",
"aParams",
"[",
"2",
"]",
"||",
"\"oScope\"",
";",
"if",
"(",
"bAsync",
")",
"{",
"aParams",
"[",
"3",
"]",
"=",
"aParams",
"[",
"3",
"]",
"||",
"\"fnResolve\"",
";",
"}",
"else",
"{",
"aParams",
"=",
"aParams",
".",
"slice",
"(",
"0",
",",
"3",
")",
";",
"}",
"var",
"sNewCheckFunction",
"=",
"sCheckFunction",
".",
"replace",
"(",
"/",
"function[^(]*\\(([^)]*)\\)",
"/",
",",
"\"function (\"",
"+",
"aParams",
".",
"join",
"(",
"\", \"",
")",
"+",
"\")\"",
")",
";",
"this",
".",
"model",
".",
"setProperty",
"(",
"sRule",
"+",
"\"/check\"",
",",
"sNewCheckFunction",
")",
";",
"}"
] |
Add fnResolve to the check function when async is set to true otherwise removes it.
@private
@param {string} sRule the model path to edit or new rule
@param {bAsync} bAsync the async property of the rule
|
[
"Add",
"fnResolve",
"to",
"the",
"check",
"function",
"when",
"async",
"is",
"set",
"to",
"true",
"otherwise",
"removes",
"it",
"."
] |
8a832fca01cb1cdf8df589788e0c5723e2a33c70
|
https://github.com/SAP/openui5/blob/8a832fca01cb1cdf8df589788e0c5723e2a33c70/src/sap.ui.support/src/sap/ui/support/supportRules/ui/controllers/Analysis.controller.js#L123-L155
|
train
|
|
SAP/openui5
|
src/sap.ui.support/src/sap/ui/support/supportRules/ui/controllers/Analysis.controller.js
|
function (component, savedComponents) {
for (var index = 0; index < savedComponents.length; index += 1) {
if (savedComponents[index].text == component.text && savedComponents[index].selected) {
return true;
}
}
return false;
}
|
javascript
|
function (component, savedComponents) {
for (var index = 0; index < savedComponents.length; index += 1) {
if (savedComponents[index].text == component.text && savedComponents[index].selected) {
return true;
}
}
return false;
}
|
[
"function",
"(",
"component",
",",
"savedComponents",
")",
"{",
"for",
"(",
"var",
"index",
"=",
"0",
";",
"index",
"<",
"savedComponents",
".",
"length",
";",
"index",
"+=",
"1",
")",
"{",
"if",
"(",
"savedComponents",
"[",
"index",
"]",
".",
"text",
"==",
"component",
".",
"text",
"&&",
"savedComponents",
"[",
"index",
"]",
".",
"selected",
")",
"{",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}"
] |
Checks if given execution scope component is selected comparing against an array of settings
@param {Object} component The current component object to be checked
@param {Array} savedComponents The local storage settings for the checked execution scope components
@returns {boolean} If the component is checked or not
|
[
"Checks",
"if",
"given",
"execution",
"scope",
"component",
"is",
"selected",
"comparing",
"against",
"an",
"array",
"of",
"settings"
] |
8a832fca01cb1cdf8df589788e0c5723e2a33c70
|
https://github.com/SAP/openui5/blob/8a832fca01cb1cdf8df589788e0c5723e2a33c70/src/sap.ui.support/src/sap/ui/support/supportRules/ui/controllers/Analysis.controller.js#L348-L355
|
train
|
|
SAP/openui5
|
src/sap.ui.support/src/sap/ui/support/supportRules/ui/controllers/Analysis.controller.js
|
function (oEvent) {
var bShowRuleProperties = true,
oSelectedRule = this.model.getProperty("/selectedRule"),
bAdditionalRulesetsTab = oEvent.getParameter("selectedKey") === "additionalRulesets";
if (bAdditionalRulesetsTab || !oSelectedRule) {
bShowRuleProperties = false;
}
// Ensure we don't make unnecessary requests. The requests will be made only
// the first time the user clicks AdditionalRulesets tab.
if (!this.bAdditionalRulesetsLoaded && bAdditionalRulesetsTab) {
this.rulesViewContainer.setBusyIndicatorDelay(0);
this.rulesViewContainer.setBusy(true);
CommunicationBus.publish(channelNames.GET_NON_LOADED_RULE_SETS, {
loadedRulesets: this._getLoadedRulesets()
});
}
this.getView().getModel().setProperty("/showRuleProperties", bShowRuleProperties);
}
|
javascript
|
function (oEvent) {
var bShowRuleProperties = true,
oSelectedRule = this.model.getProperty("/selectedRule"),
bAdditionalRulesetsTab = oEvent.getParameter("selectedKey") === "additionalRulesets";
if (bAdditionalRulesetsTab || !oSelectedRule) {
bShowRuleProperties = false;
}
// Ensure we don't make unnecessary requests. The requests will be made only
// the first time the user clicks AdditionalRulesets tab.
if (!this.bAdditionalRulesetsLoaded && bAdditionalRulesetsTab) {
this.rulesViewContainer.setBusyIndicatorDelay(0);
this.rulesViewContainer.setBusy(true);
CommunicationBus.publish(channelNames.GET_NON_LOADED_RULE_SETS, {
loadedRulesets: this._getLoadedRulesets()
});
}
this.getView().getModel().setProperty("/showRuleProperties", bShowRuleProperties);
}
|
[
"function",
"(",
"oEvent",
")",
"{",
"var",
"bShowRuleProperties",
"=",
"true",
",",
"oSelectedRule",
"=",
"this",
".",
"model",
".",
"getProperty",
"(",
"\"/selectedRule\"",
")",
",",
"bAdditionalRulesetsTab",
"=",
"oEvent",
".",
"getParameter",
"(",
"\"selectedKey\"",
")",
"===",
"\"additionalRulesets\"",
";",
"if",
"(",
"bAdditionalRulesetsTab",
"||",
"!",
"oSelectedRule",
")",
"{",
"bShowRuleProperties",
"=",
"false",
";",
"}",
"if",
"(",
"!",
"this",
".",
"bAdditionalRulesetsLoaded",
"&&",
"bAdditionalRulesetsTab",
")",
"{",
"this",
".",
"rulesViewContainer",
".",
"setBusyIndicatorDelay",
"(",
"0",
")",
";",
"this",
".",
"rulesViewContainer",
".",
"setBusy",
"(",
"true",
")",
";",
"CommunicationBus",
".",
"publish",
"(",
"channelNames",
".",
"GET_NON_LOADED_RULE_SETS",
",",
"{",
"loadedRulesets",
":",
"this",
".",
"_getLoadedRulesets",
"(",
")",
"}",
")",
";",
"}",
"this",
".",
"getView",
"(",
")",
".",
"getModel",
"(",
")",
".",
"setProperty",
"(",
"\"/showRuleProperties\"",
",",
"bShowRuleProperties",
")",
";",
"}"
] |
On selecting "Additional RuleSet" tab, start loading Additional RuleSets by brute search.
@param {Event} oEvent TreeTable event
|
[
"On",
"selecting",
"Additional",
"RuleSet",
"tab",
"start",
"loading",
"Additional",
"RuleSets",
"by",
"brute",
"search",
"."
] |
8a832fca01cb1cdf8df589788e0c5723e2a33c70
|
https://github.com/SAP/openui5/blob/8a832fca01cb1cdf8df589788e0c5723e2a33c70/src/sap.ui.support/src/sap/ui/support/supportRules/ui/controllers/Analysis.controller.js#L405-L425
|
train
|
|
SAP/openui5
|
src/sap.ui.support/src/sap/ui/support/supportRules/ui/controllers/Analysis.controller.js
|
function (tempLib, treeTable) {
var library,
rule,
oTempLibCopy,
bSelected,
aRules,
iIndex,
fnFilter = function (oRule) {
return oRule.id === rule.id;
};
for (var i in treeTable) {
library = treeTable[i];
oTempLibCopy = treeTable[i].nodes;
if (library.name !== Constants.TEMP_RULESETS_NAME) {
continue;
}
//reset the model to add the temp rules
treeTable[i].nodes = [];
for (var ruleIndex in tempLib.rules) {
rule = tempLib.rules[ruleIndex];
bSelected = oTempLibCopy[ruleIndex] !== undefined ? oTempLibCopy[ruleIndex].selected : true;
// syncs selection of temporary rules from local storage
if (this.tempRulesFromStorage) {
aRules = this.tempRulesFromStorage.filter(fnFilter);
if (aRules.length > 0) {
bSelected = aRules[0].selected;
iIndex = this.tempRulesFromStorage.indexOf(aRules[0]);
this.tempRulesFromStorage.splice(iIndex, 1);
if (bSelected === false) {
library.selected = false;
}
}
if (this.tempRulesFromStorage.length === 0) {
this.tempRulesFromStorage.length = null;
}
}
library.nodes.push({
name: rule.title,
description: rule.description,
id: rule.id,
audiences: rule.audiences.toString(),
categories: rule.categories.toString(),
minversion: rule.minversion,
resolution: rule.resolution,
title: rule.title,
selected: bSelected,
libName: library.name,
check: rule.check
});
}
this.model.setProperty("/treeModel", treeTable);
return library;
}
}
|
javascript
|
function (tempLib, treeTable) {
var library,
rule,
oTempLibCopy,
bSelected,
aRules,
iIndex,
fnFilter = function (oRule) {
return oRule.id === rule.id;
};
for (var i in treeTable) {
library = treeTable[i];
oTempLibCopy = treeTable[i].nodes;
if (library.name !== Constants.TEMP_RULESETS_NAME) {
continue;
}
//reset the model to add the temp rules
treeTable[i].nodes = [];
for (var ruleIndex in tempLib.rules) {
rule = tempLib.rules[ruleIndex];
bSelected = oTempLibCopy[ruleIndex] !== undefined ? oTempLibCopy[ruleIndex].selected : true;
// syncs selection of temporary rules from local storage
if (this.tempRulesFromStorage) {
aRules = this.tempRulesFromStorage.filter(fnFilter);
if (aRules.length > 0) {
bSelected = aRules[0].selected;
iIndex = this.tempRulesFromStorage.indexOf(aRules[0]);
this.tempRulesFromStorage.splice(iIndex, 1);
if (bSelected === false) {
library.selected = false;
}
}
if (this.tempRulesFromStorage.length === 0) {
this.tempRulesFromStorage.length = null;
}
}
library.nodes.push({
name: rule.title,
description: rule.description,
id: rule.id,
audiences: rule.audiences.toString(),
categories: rule.categories.toString(),
minversion: rule.minversion,
resolution: rule.resolution,
title: rule.title,
selected: bSelected,
libName: library.name,
check: rule.check
});
}
this.model.setProperty("/treeModel", treeTable);
return library;
}
}
|
[
"function",
"(",
"tempLib",
",",
"treeTable",
")",
"{",
"var",
"library",
",",
"rule",
",",
"oTempLibCopy",
",",
"bSelected",
",",
"aRules",
",",
"iIndex",
",",
"fnFilter",
"=",
"function",
"(",
"oRule",
")",
"{",
"return",
"oRule",
".",
"id",
"===",
"rule",
".",
"id",
";",
"}",
";",
"for",
"(",
"var",
"i",
"in",
"treeTable",
")",
"{",
"library",
"=",
"treeTable",
"[",
"i",
"]",
";",
"oTempLibCopy",
"=",
"treeTable",
"[",
"i",
"]",
".",
"nodes",
";",
"if",
"(",
"library",
".",
"name",
"!==",
"Constants",
".",
"TEMP_RULESETS_NAME",
")",
"{",
"continue",
";",
"}",
"treeTable",
"[",
"i",
"]",
".",
"nodes",
"=",
"[",
"]",
";",
"for",
"(",
"var",
"ruleIndex",
"in",
"tempLib",
".",
"rules",
")",
"{",
"rule",
"=",
"tempLib",
".",
"rules",
"[",
"ruleIndex",
"]",
";",
"bSelected",
"=",
"oTempLibCopy",
"[",
"ruleIndex",
"]",
"!==",
"undefined",
"?",
"oTempLibCopy",
"[",
"ruleIndex",
"]",
".",
"selected",
":",
"true",
";",
"if",
"(",
"this",
".",
"tempRulesFromStorage",
")",
"{",
"aRules",
"=",
"this",
".",
"tempRulesFromStorage",
".",
"filter",
"(",
"fnFilter",
")",
";",
"if",
"(",
"aRules",
".",
"length",
">",
"0",
")",
"{",
"bSelected",
"=",
"aRules",
"[",
"0",
"]",
".",
"selected",
";",
"iIndex",
"=",
"this",
".",
"tempRulesFromStorage",
".",
"indexOf",
"(",
"aRules",
"[",
"0",
"]",
")",
";",
"this",
".",
"tempRulesFromStorage",
".",
"splice",
"(",
"iIndex",
",",
"1",
")",
";",
"if",
"(",
"bSelected",
"===",
"false",
")",
"{",
"library",
".",
"selected",
"=",
"false",
";",
"}",
"}",
"if",
"(",
"this",
".",
"tempRulesFromStorage",
".",
"length",
"===",
"0",
")",
"{",
"this",
".",
"tempRulesFromStorage",
".",
"length",
"=",
"null",
";",
"}",
"}",
"library",
".",
"nodes",
".",
"push",
"(",
"{",
"name",
":",
"rule",
".",
"title",
",",
"description",
":",
"rule",
".",
"description",
",",
"id",
":",
"rule",
".",
"id",
",",
"audiences",
":",
"rule",
".",
"audiences",
".",
"toString",
"(",
")",
",",
"categories",
":",
"rule",
".",
"categories",
".",
"toString",
"(",
")",
",",
"minversion",
":",
"rule",
".",
"minversion",
",",
"resolution",
":",
"rule",
".",
"resolution",
",",
"title",
":",
"rule",
".",
"title",
",",
"selected",
":",
"bSelected",
",",
"libName",
":",
"library",
".",
"name",
",",
"check",
":",
"rule",
".",
"check",
"}",
")",
";",
"}",
"this",
".",
"model",
".",
"setProperty",
"(",
"\"/treeModel\"",
",",
"treeTable",
")",
";",
"return",
"library",
";",
"}",
"}"
] |
Keeps in sync the TreeViewModel for temporary library that we use for visualisation of sap.m.TreeTable and the model that we use in the Suppport Assistant
@param {Object} tempLib temporary library model from Support Assistant
@param {Object} treeTable Model for sap.m.TreeTable visualization
@returns {Object} The temp library
|
[
"Keeps",
"in",
"sync",
"the",
"TreeViewModel",
"for",
"temporary",
"library",
"that",
"we",
"use",
"for",
"visualisation",
"of",
"sap",
".",
"m",
".",
"TreeTable",
"and",
"the",
"model",
"that",
"we",
"use",
"in",
"the",
"Suppport",
"Assistant"
] |
8a832fca01cb1cdf8df589788e0c5723e2a33c70
|
https://github.com/SAP/openui5/blob/8a832fca01cb1cdf8df589788e0c5723e2a33c70/src/sap.ui.support/src/sap/ui/support/supportRules/ui/controllers/Analysis.controller.js#L451-L514
|
train
|
|
SAP/openui5
|
src/sap.ui.support/src/sap/ui/support/supportRules/ui/controllers/Analysis.controller.js
|
function (tempRule, treeTable) {
var ruleSource = this.model.getProperty("/editRuleSource");
for (var i in treeTable) {
if (treeTable[i].name === Constants.TEMP_RULESETS_NAME) {
for (var innerIndex in treeTable[i].nodes) {
if (treeTable[i].nodes[innerIndex].id === ruleSource.id) {
treeTable[i].nodes[innerIndex] = {
name: tempRule.title,
description: tempRule.description,
id: tempRule.id,
audiences: tempRule.audiences,
categories: tempRule.categories,
minversion: tempRule.minversion,
resolution: tempRule.resolution,
selected: treeTable[i].nodes[innerIndex].selected,
title: tempRule.title,
libName: treeTable[i].name,
check: tempRule.check
};
}
}
}
}
}
|
javascript
|
function (tempRule, treeTable) {
var ruleSource = this.model.getProperty("/editRuleSource");
for (var i in treeTable) {
if (treeTable[i].name === Constants.TEMP_RULESETS_NAME) {
for (var innerIndex in treeTable[i].nodes) {
if (treeTable[i].nodes[innerIndex].id === ruleSource.id) {
treeTable[i].nodes[innerIndex] = {
name: tempRule.title,
description: tempRule.description,
id: tempRule.id,
audiences: tempRule.audiences,
categories: tempRule.categories,
minversion: tempRule.minversion,
resolution: tempRule.resolution,
selected: treeTable[i].nodes[innerIndex].selected,
title: tempRule.title,
libName: treeTable[i].name,
check: tempRule.check
};
}
}
}
}
}
|
[
"function",
"(",
"tempRule",
",",
"treeTable",
")",
"{",
"var",
"ruleSource",
"=",
"this",
".",
"model",
".",
"getProperty",
"(",
"\"/editRuleSource\"",
")",
";",
"for",
"(",
"var",
"i",
"in",
"treeTable",
")",
"{",
"if",
"(",
"treeTable",
"[",
"i",
"]",
".",
"name",
"===",
"Constants",
".",
"TEMP_RULESETS_NAME",
")",
"{",
"for",
"(",
"var",
"innerIndex",
"in",
"treeTable",
"[",
"i",
"]",
".",
"nodes",
")",
"{",
"if",
"(",
"treeTable",
"[",
"i",
"]",
".",
"nodes",
"[",
"innerIndex",
"]",
".",
"id",
"===",
"ruleSource",
".",
"id",
")",
"{",
"treeTable",
"[",
"i",
"]",
".",
"nodes",
"[",
"innerIndex",
"]",
"=",
"{",
"name",
":",
"tempRule",
".",
"title",
",",
"description",
":",
"tempRule",
".",
"description",
",",
"id",
":",
"tempRule",
".",
"id",
",",
"audiences",
":",
"tempRule",
".",
"audiences",
",",
"categories",
":",
"tempRule",
".",
"categories",
",",
"minversion",
":",
"tempRule",
".",
"minversion",
",",
"resolution",
":",
"tempRule",
".",
"resolution",
",",
"selected",
":",
"treeTable",
"[",
"i",
"]",
".",
"nodes",
"[",
"innerIndex",
"]",
".",
"selected",
",",
"title",
":",
"tempRule",
".",
"title",
",",
"libName",
":",
"treeTable",
"[",
"i",
"]",
".",
"name",
",",
"check",
":",
"tempRule",
".",
"check",
"}",
";",
"}",
"}",
"}",
"}",
"}"
] |
Keeps in sync the TreeViewModel for temporary rules that we use for visualisation of sap.m.TreeTable and the model that we use in the SuppportAssistant
@param {Object} tempRule Temporary rule
@param {Object} treeTable Model for sap.m.TreeTable visualization
|
[
"Keeps",
"in",
"sync",
"the",
"TreeViewModel",
"for",
"temporary",
"rules",
"that",
"we",
"use",
"for",
"visualisation",
"of",
"sap",
".",
"m",
".",
"TreeTable",
"and",
"the",
"model",
"that",
"we",
"use",
"in",
"the",
"SuppportAssistant"
] |
8a832fca01cb1cdf8df589788e0c5723e2a33c70
|
https://github.com/SAP/openui5/blob/8a832fca01cb1cdf8df589788e0c5723e2a33c70/src/sap.ui.support/src/sap/ui/support/supportRules/ui/controllers/Analysis.controller.js#L521-L544
|
train
|
|
SAP/openui5
|
src/sap.ui.support/src/sap/ui/support/supportRules/ui/controllers/Analysis.controller.js
|
function () {
var tempRules = Storage.getRules(),
loadingFromAdditionalRuleSets = this.model.getProperty("/loadingAdditionalRuleSets");
if (tempRules && !loadingFromAdditionalRuleSets && !this.tempRulesLoaded) {
this.tempRulesFromStorage = tempRules;
this.tempRulesLoaded = true;
tempRules.forEach(function (tempRule) {
CommunicationBus.publish(channelNames.VERIFY_CREATE_RULE, RuleSerializer.serialize(tempRule));
});
this.persistedTempRulesCount = tempRules.length;
}
}
|
javascript
|
function () {
var tempRules = Storage.getRules(),
loadingFromAdditionalRuleSets = this.model.getProperty("/loadingAdditionalRuleSets");
if (tempRules && !loadingFromAdditionalRuleSets && !this.tempRulesLoaded) {
this.tempRulesFromStorage = tempRules;
this.tempRulesLoaded = true;
tempRules.forEach(function (tempRule) {
CommunicationBus.publish(channelNames.VERIFY_CREATE_RULE, RuleSerializer.serialize(tempRule));
});
this.persistedTempRulesCount = tempRules.length;
}
}
|
[
"function",
"(",
")",
"{",
"var",
"tempRules",
"=",
"Storage",
".",
"getRules",
"(",
")",
",",
"loadingFromAdditionalRuleSets",
"=",
"this",
".",
"model",
".",
"getProperty",
"(",
"\"/loadingAdditionalRuleSets\"",
")",
";",
"if",
"(",
"tempRules",
"&&",
"!",
"loadingFromAdditionalRuleSets",
"&&",
"!",
"this",
".",
"tempRulesLoaded",
")",
"{",
"this",
".",
"tempRulesFromStorage",
"=",
"tempRules",
";",
"this",
".",
"tempRulesLoaded",
"=",
"true",
";",
"tempRules",
".",
"forEach",
"(",
"function",
"(",
"tempRule",
")",
"{",
"CommunicationBus",
".",
"publish",
"(",
"channelNames",
".",
"VERIFY_CREATE_RULE",
",",
"RuleSerializer",
".",
"serialize",
"(",
"tempRule",
")",
")",
";",
"}",
")",
";",
"this",
".",
"persistedTempRulesCount",
"=",
"tempRules",
".",
"length",
";",
"}",
"}"
] |
Loads temporary rules from the local storage
|
[
"Loads",
"temporary",
"rules",
"from",
"the",
"local",
"storage"
] |
8a832fca01cb1cdf8df589788e0c5723e2a33c70
|
https://github.com/SAP/openui5/blob/8a832fca01cb1cdf8df589788e0c5723e2a33c70/src/sap.ui.support/src/sap/ui/support/supportRules/ui/controllers/Analysis.controller.js#L725-L739
|
train
|
|
SAP/openui5
|
src/sap.ui.support/src/sap/ui/support/supportRules/ui/controllers/Analysis.controller.js
|
function (event) {
var sPath = event.getSource().getBindingContext("treeModel").getPath(),
sourceObject = this.treeTable.getBinding().getModel().getProperty(sPath),
libs = this.model.getProperty("/libraries");
libs.forEach(function (lib, libIndex) {
lib.rules.forEach(function (rule) {
if (rule.id === sourceObject.id) {
sourceObject.check = rule.check;
}
});
});
return sourceObject;
}
|
javascript
|
function (event) {
var sPath = event.getSource().getBindingContext("treeModel").getPath(),
sourceObject = this.treeTable.getBinding().getModel().getProperty(sPath),
libs = this.model.getProperty("/libraries");
libs.forEach(function (lib, libIndex) {
lib.rules.forEach(function (rule) {
if (rule.id === sourceObject.id) {
sourceObject.check = rule.check;
}
});
});
return sourceObject;
}
|
[
"function",
"(",
"event",
")",
"{",
"var",
"sPath",
"=",
"event",
".",
"getSource",
"(",
")",
".",
"getBindingContext",
"(",
"\"treeModel\"",
")",
".",
"getPath",
"(",
")",
",",
"sourceObject",
"=",
"this",
".",
"treeTable",
".",
"getBinding",
"(",
")",
".",
"getModel",
"(",
")",
".",
"getProperty",
"(",
"sPath",
")",
",",
"libs",
"=",
"this",
".",
"model",
".",
"getProperty",
"(",
"\"/libraries\"",
")",
";",
"libs",
".",
"forEach",
"(",
"function",
"(",
"lib",
",",
"libIndex",
")",
"{",
"lib",
".",
"rules",
".",
"forEach",
"(",
"function",
"(",
"rule",
")",
"{",
"if",
"(",
"rule",
".",
"id",
"===",
"sourceObject",
".",
"id",
")",
"{",
"sourceObject",
".",
"check",
"=",
"rule",
".",
"check",
";",
"}",
"}",
")",
";",
"}",
")",
";",
"return",
"sourceObject",
";",
"}"
] |
Gets rule from selected row
@param {Object} event Event
@returns {Object} ISelected rule from row
*
|
[
"Gets",
"rule",
"from",
"selected",
"row"
] |
8a832fca01cb1cdf8df589788e0c5723e2a33c70
|
https://github.com/SAP/openui5/blob/8a832fca01cb1cdf8df589788e0c5723e2a33c70/src/sap.ui.support/src/sap/ui/support/supportRules/ui/controllers/Analysis.controller.js#L966-L979
|
train
|
|
SAP/openui5
|
src/sap.ui.support/src/sap/ui/support/supportRules/ui/controllers/Analysis.controller.js
|
function (aColumnsIds, bVisibilityValue) {
var aColumns = this.treeTable.getColumns();
aColumns.forEach(function(oColumn) {
oColumn.setVisible(!bVisibilityValue);
aColumnsIds.forEach(function(sRuleId) {
if (oColumn.sId.includes(sRuleId)) {
oColumn.setVisible(bVisibilityValue);
}
});
});
}
|
javascript
|
function (aColumnsIds, bVisibilityValue) {
var aColumns = this.treeTable.getColumns();
aColumns.forEach(function(oColumn) {
oColumn.setVisible(!bVisibilityValue);
aColumnsIds.forEach(function(sRuleId) {
if (oColumn.sId.includes(sRuleId)) {
oColumn.setVisible(bVisibilityValue);
}
});
});
}
|
[
"function",
"(",
"aColumnsIds",
",",
"bVisibilityValue",
")",
"{",
"var",
"aColumns",
"=",
"this",
".",
"treeTable",
".",
"getColumns",
"(",
")",
";",
"aColumns",
".",
"forEach",
"(",
"function",
"(",
"oColumn",
")",
"{",
"oColumn",
".",
"setVisible",
"(",
"!",
"bVisibilityValue",
")",
";",
"aColumnsIds",
".",
"forEach",
"(",
"function",
"(",
"sRuleId",
")",
"{",
"if",
"(",
"oColumn",
".",
"sId",
".",
"includes",
"(",
"sRuleId",
")",
")",
"{",
"oColumn",
".",
"setVisible",
"(",
"bVisibilityValue",
")",
";",
"}",
"}",
")",
";",
"}",
")",
";",
"}"
] |
Sets visibility to columns.
@param {Array} aColumnsIds Ids of columns
@param {boolean} bVisibilityValue
|
[
"Sets",
"visibility",
"to",
"columns",
"."
] |
8a832fca01cb1cdf8df589788e0c5723e2a33c70
|
https://github.com/SAP/openui5/blob/8a832fca01cb1cdf8df589788e0c5723e2a33c70/src/sap.ui.support/src/sap/ui/support/supportRules/ui/controllers/Analysis.controller.js#L996-L1007
|
train
|
|
SAP/openui5
|
src/sap.ui.support/src/sap/ui/support/supportRules/ui/controllers/Analysis.controller.js
|
function (oEvent) {
var oColumn = oEvent.getParameter("column"),
bNewVisibilityState = oEvent.getParameter("newVisible");
if (!this.model.getProperty("/persistingSettings")) {
return;
}
oColumn.setVisible(bNewVisibilityState);
this.persistVisibleColumns();
}
|
javascript
|
function (oEvent) {
var oColumn = oEvent.getParameter("column"),
bNewVisibilityState = oEvent.getParameter("newVisible");
if (!this.model.getProperty("/persistingSettings")) {
return;
}
oColumn.setVisible(bNewVisibilityState);
this.persistVisibleColumns();
}
|
[
"function",
"(",
"oEvent",
")",
"{",
"var",
"oColumn",
"=",
"oEvent",
".",
"getParameter",
"(",
"\"column\"",
")",
",",
"bNewVisibilityState",
"=",
"oEvent",
".",
"getParameter",
"(",
"\"newVisible\"",
")",
";",
"if",
"(",
"!",
"this",
".",
"model",
".",
"getProperty",
"(",
"\"/persistingSettings\"",
")",
")",
"{",
"return",
";",
"}",
"oColumn",
".",
"setVisible",
"(",
"bNewVisibilityState",
")",
";",
"this",
".",
"persistVisibleColumns",
"(",
")",
";",
"}"
] |
On column visibility change persist column visibility selection
@param {object} oEvent event
|
[
"On",
"column",
"visibility",
"change",
"persist",
"column",
"visibility",
"selection"
] |
8a832fca01cb1cdf8df589788e0c5723e2a33c70
|
https://github.com/SAP/openui5/blob/8a832fca01cb1cdf8df589788e0c5723e2a33c70/src/sap.ui.support/src/sap/ui/support/supportRules/ui/controllers/Analysis.controller.js#L1013-L1021
|
train
|
|
SAP/openui5
|
src/sap.ui.core/src/sap/ui/model/analytics/odata4analytics.js
|
function(oModelReference, mParameter) {
if (typeof mParameter == "string") {
throw "Deprecated second argument: Adjust your invocation by passing an object with a property sAnnotationJSONDoc as a second argument instead";
}
this._mParameter = mParameter;
var that = this;
/*
* get access to OData model
*/
this._oActivatedWorkarounds = {};
if (oModelReference && oModelReference.aWorkaroundID) {
for (var i = -1, sID; (sID = oModelReference.aWorkaroundID[++i]) !== undefined;) {
this._oActivatedWorkarounds[sID] = true;
}
oModelReference = oModelReference.oModelReference;
}
// check proper usage
if (!oModelReference || (!oModelReference.sServiceURI && !oModelReference.oModel)) {
throw "Usage with oModelReference being an instance of Model.ReferenceByURI or Model.ReferenceByModel";
}
//check if a model is given, or we need to create one from the service URI
if (oModelReference.oModel) {
this._oModel = oModelReference.oModel;
// find out which model version we are running
this._iVersion = AnalyticalVersionInfo.getVersion(this._oModel);
checkForMetadata();
} else if (mParameter && mParameter.modelVersion === AnalyticalVersionInfo.V2) {
// Check if the user wants a V2 model
var V2ODataModel = sap.ui.requireSync("sap/ui/model/odata/v2/ODataModel");
this._oModel = new V2ODataModel(oModelReference.sServiceURI);
this._iVersion = AnalyticalVersionInfo.V2;
checkForMetadata();
} else {
//default is V1 Model
var ODataModel = sap.ui.requireSync("sap/ui/model/odata/ODataModel");
this._oModel = new ODataModel(oModelReference.sServiceURI);
this._iVersion = AnalyticalVersionInfo.V1;
checkForMetadata();
}
if (this._oModel.getServiceMetadata()
&& this._oModel.getServiceMetadata().dataServices == undefined) {
throw "Model could not be loaded";
}
/**
* Check if the metadata is already available, if not defere the interpretation of the Metadata
*/
function checkForMetadata() {
// V2 supports asynchronous loading of metadata
// we have to register for the MetadataLoaded Event in case, the data is not loaded already
if (!that._oModel.getServiceMetadata()) {
that._oModel.attachMetadataLoaded(processMetadata);
} else {
// metadata already loaded
processMetadata();
}
}
/**
* Kickstart the interpretation of the metadata,
* either called directly if metadata is available, or deferred and then
* executed via callback by the model during the metadata loaded event.
*/
function processMetadata () {
//only interprete the metadata if the analytics model was not initialised yet
if (that.bIsInitialized) {
return;
}
//mark analytics model as initialized
that.bIsInitialized = true;
/*
* add extra annotations if provided
*/
if (mParameter && mParameter.sAnnotationJSONDoc) {
that.mergeV2Annotations(mParameter.sAnnotationJSONDoc);
}
that._interpreteMetadata(that._oModel.getServiceMetadata().dataServices);
}
}
|
javascript
|
function(oModelReference, mParameter) {
if (typeof mParameter == "string") {
throw "Deprecated second argument: Adjust your invocation by passing an object with a property sAnnotationJSONDoc as a second argument instead";
}
this._mParameter = mParameter;
var that = this;
/*
* get access to OData model
*/
this._oActivatedWorkarounds = {};
if (oModelReference && oModelReference.aWorkaroundID) {
for (var i = -1, sID; (sID = oModelReference.aWorkaroundID[++i]) !== undefined;) {
this._oActivatedWorkarounds[sID] = true;
}
oModelReference = oModelReference.oModelReference;
}
// check proper usage
if (!oModelReference || (!oModelReference.sServiceURI && !oModelReference.oModel)) {
throw "Usage with oModelReference being an instance of Model.ReferenceByURI or Model.ReferenceByModel";
}
//check if a model is given, or we need to create one from the service URI
if (oModelReference.oModel) {
this._oModel = oModelReference.oModel;
// find out which model version we are running
this._iVersion = AnalyticalVersionInfo.getVersion(this._oModel);
checkForMetadata();
} else if (mParameter && mParameter.modelVersion === AnalyticalVersionInfo.V2) {
// Check if the user wants a V2 model
var V2ODataModel = sap.ui.requireSync("sap/ui/model/odata/v2/ODataModel");
this._oModel = new V2ODataModel(oModelReference.sServiceURI);
this._iVersion = AnalyticalVersionInfo.V2;
checkForMetadata();
} else {
//default is V1 Model
var ODataModel = sap.ui.requireSync("sap/ui/model/odata/ODataModel");
this._oModel = new ODataModel(oModelReference.sServiceURI);
this._iVersion = AnalyticalVersionInfo.V1;
checkForMetadata();
}
if (this._oModel.getServiceMetadata()
&& this._oModel.getServiceMetadata().dataServices == undefined) {
throw "Model could not be loaded";
}
/**
* Check if the metadata is already available, if not defere the interpretation of the Metadata
*/
function checkForMetadata() {
// V2 supports asynchronous loading of metadata
// we have to register for the MetadataLoaded Event in case, the data is not loaded already
if (!that._oModel.getServiceMetadata()) {
that._oModel.attachMetadataLoaded(processMetadata);
} else {
// metadata already loaded
processMetadata();
}
}
/**
* Kickstart the interpretation of the metadata,
* either called directly if metadata is available, or deferred and then
* executed via callback by the model during the metadata loaded event.
*/
function processMetadata () {
//only interprete the metadata if the analytics model was not initialised yet
if (that.bIsInitialized) {
return;
}
//mark analytics model as initialized
that.bIsInitialized = true;
/*
* add extra annotations if provided
*/
if (mParameter && mParameter.sAnnotationJSONDoc) {
that.mergeV2Annotations(mParameter.sAnnotationJSONDoc);
}
that._interpreteMetadata(that._oModel.getServiceMetadata().dataServices);
}
}
|
[
"function",
"(",
"oModelReference",
",",
"mParameter",
")",
"{",
"if",
"(",
"typeof",
"mParameter",
"==",
"\"string\"",
")",
"{",
"throw",
"\"Deprecated second argument: Adjust your invocation by passing an object with a property sAnnotationJSONDoc as a second argument instead\"",
";",
"}",
"this",
".",
"_mParameter",
"=",
"mParameter",
";",
"var",
"that",
"=",
"this",
";",
"this",
".",
"_oActivatedWorkarounds",
"=",
"{",
"}",
";",
"if",
"(",
"oModelReference",
"&&",
"oModelReference",
".",
"aWorkaroundID",
")",
"{",
"for",
"(",
"var",
"i",
"=",
"-",
"1",
",",
"sID",
";",
"(",
"sID",
"=",
"oModelReference",
".",
"aWorkaroundID",
"[",
"++",
"i",
"]",
")",
"!==",
"undefined",
";",
")",
"{",
"this",
".",
"_oActivatedWorkarounds",
"[",
"sID",
"]",
"=",
"true",
";",
"}",
"oModelReference",
"=",
"oModelReference",
".",
"oModelReference",
";",
"}",
"if",
"(",
"!",
"oModelReference",
"||",
"(",
"!",
"oModelReference",
".",
"sServiceURI",
"&&",
"!",
"oModelReference",
".",
"oModel",
")",
")",
"{",
"throw",
"\"Usage with oModelReference being an instance of Model.ReferenceByURI or Model.ReferenceByModel\"",
";",
"}",
"if",
"(",
"oModelReference",
".",
"oModel",
")",
"{",
"this",
".",
"_oModel",
"=",
"oModelReference",
".",
"oModel",
";",
"this",
".",
"_iVersion",
"=",
"AnalyticalVersionInfo",
".",
"getVersion",
"(",
"this",
".",
"_oModel",
")",
";",
"checkForMetadata",
"(",
")",
";",
"}",
"else",
"if",
"(",
"mParameter",
"&&",
"mParameter",
".",
"modelVersion",
"===",
"AnalyticalVersionInfo",
".",
"V2",
")",
"{",
"var",
"V2ODataModel",
"=",
"sap",
".",
"ui",
".",
"requireSync",
"(",
"\"sap/ui/model/odata/v2/ODataModel\"",
")",
";",
"this",
".",
"_oModel",
"=",
"new",
"V2ODataModel",
"(",
"oModelReference",
".",
"sServiceURI",
")",
";",
"this",
".",
"_iVersion",
"=",
"AnalyticalVersionInfo",
".",
"V2",
";",
"checkForMetadata",
"(",
")",
";",
"}",
"else",
"{",
"var",
"ODataModel",
"=",
"sap",
".",
"ui",
".",
"requireSync",
"(",
"\"sap/ui/model/odata/ODataModel\"",
")",
";",
"this",
".",
"_oModel",
"=",
"new",
"ODataModel",
"(",
"oModelReference",
".",
"sServiceURI",
")",
";",
"this",
".",
"_iVersion",
"=",
"AnalyticalVersionInfo",
".",
"V1",
";",
"checkForMetadata",
"(",
")",
";",
"}",
"if",
"(",
"this",
".",
"_oModel",
".",
"getServiceMetadata",
"(",
")",
"&&",
"this",
".",
"_oModel",
".",
"getServiceMetadata",
"(",
")",
".",
"dataServices",
"==",
"undefined",
")",
"{",
"throw",
"\"Model could not be loaded\"",
";",
"}",
"function",
"checkForMetadata",
"(",
")",
"{",
"if",
"(",
"!",
"that",
".",
"_oModel",
".",
"getServiceMetadata",
"(",
")",
")",
"{",
"that",
".",
"_oModel",
".",
"attachMetadataLoaded",
"(",
"processMetadata",
")",
";",
"}",
"else",
"{",
"processMetadata",
"(",
")",
";",
"}",
"}",
"function",
"processMetadata",
"(",
")",
"{",
"if",
"(",
"that",
".",
"bIsInitialized",
")",
"{",
"return",
";",
"}",
"that",
".",
"bIsInitialized",
"=",
"true",
";",
"if",
"(",
"mParameter",
"&&",
"mParameter",
".",
"sAnnotationJSONDoc",
")",
"{",
"that",
".",
"mergeV2Annotations",
"(",
"mParameter",
".",
"sAnnotationJSONDoc",
")",
";",
"}",
"that",
".",
"_interpreteMetadata",
"(",
"that",
".",
"_oModel",
".",
"getServiceMetadata",
"(",
")",
".",
"dataServices",
")",
";",
"}",
"}"
] |
initialize a new object
@private
|
[
"initialize",
"a",
"new",
"object"
] |
8a832fca01cb1cdf8df589788e0c5723e2a33c70
|
https://github.com/SAP/openui5/blob/8a832fca01cb1cdf8df589788e0c5723e2a33c70/src/sap.ui.core/src/sap/ui/model/analytics/odata4analytics.js#L245-L333
|
train
|
|
SAP/openui5
|
src/sap.ui.core/src/sap/ui/model/analytics/odata4analytics.js
|
processMetadata
|
function processMetadata () {
//only interprete the metadata if the analytics model was not initialised yet
if (that.bIsInitialized) {
return;
}
//mark analytics model as initialized
that.bIsInitialized = true;
/*
* add extra annotations if provided
*/
if (mParameter && mParameter.sAnnotationJSONDoc) {
that.mergeV2Annotations(mParameter.sAnnotationJSONDoc);
}
that._interpreteMetadata(that._oModel.getServiceMetadata().dataServices);
}
|
javascript
|
function processMetadata () {
//only interprete the metadata if the analytics model was not initialised yet
if (that.bIsInitialized) {
return;
}
//mark analytics model as initialized
that.bIsInitialized = true;
/*
* add extra annotations if provided
*/
if (mParameter && mParameter.sAnnotationJSONDoc) {
that.mergeV2Annotations(mParameter.sAnnotationJSONDoc);
}
that._interpreteMetadata(that._oModel.getServiceMetadata().dataServices);
}
|
[
"function",
"processMetadata",
"(",
")",
"{",
"if",
"(",
"that",
".",
"bIsInitialized",
")",
"{",
"return",
";",
"}",
"that",
".",
"bIsInitialized",
"=",
"true",
";",
"if",
"(",
"mParameter",
"&&",
"mParameter",
".",
"sAnnotationJSONDoc",
")",
"{",
"that",
".",
"mergeV2Annotations",
"(",
"mParameter",
".",
"sAnnotationJSONDoc",
")",
";",
"}",
"that",
".",
"_interpreteMetadata",
"(",
"that",
".",
"_oModel",
".",
"getServiceMetadata",
"(",
")",
".",
"dataServices",
")",
";",
"}"
] |
Kickstart the interpretation of the metadata,
either called directly if metadata is available, or deferred and then
executed via callback by the model during the metadata loaded event.
|
[
"Kickstart",
"the",
"interpretation",
"of",
"the",
"metadata",
"either",
"called",
"directly",
"if",
"metadata",
"is",
"available",
"or",
"deferred",
"and",
"then",
"executed",
"via",
"callback",
"by",
"the",
"model",
"during",
"the",
"metadata",
"loaded",
"event",
"."
] |
8a832fca01cb1cdf8df589788e0c5723e2a33c70
|
https://github.com/SAP/openui5/blob/8a832fca01cb1cdf8df589788e0c5723e2a33c70/src/sap.ui.core/src/sap/ui/model/analytics/odata4analytics.js#L314-L331
|
train
|
SAP/openui5
|
src/sap.ui.core/src/sap/ui/model/analytics/odata4analytics.js
|
function(sName) {
var oQueryResult = this._oQueryResultSet[sName];
// Everybody should have a second chance:
// If the name was not fully qualified, check if it is in the default
// container
if (!oQueryResult && this._oDefaultEntityContainer) {
var sQName = this._oDefaultEntityContainer.name + "." + sName;
oQueryResult = this._oQueryResultSet[sQName];
}
return oQueryResult;
}
|
javascript
|
function(sName) {
var oQueryResult = this._oQueryResultSet[sName];
// Everybody should have a second chance:
// If the name was not fully qualified, check if it is in the default
// container
if (!oQueryResult && this._oDefaultEntityContainer) {
var sQName = this._oDefaultEntityContainer.name + "." + sName;
oQueryResult = this._oQueryResultSet[sQName];
}
return oQueryResult;
}
|
[
"function",
"(",
"sName",
")",
"{",
"var",
"oQueryResult",
"=",
"this",
".",
"_oQueryResultSet",
"[",
"sName",
"]",
";",
"if",
"(",
"!",
"oQueryResult",
"&&",
"this",
".",
"_oDefaultEntityContainer",
")",
"{",
"var",
"sQName",
"=",
"this",
".",
"_oDefaultEntityContainer",
".",
"name",
"+",
"\".\"",
"+",
"sName",
";",
"oQueryResult",
"=",
"this",
".",
"_oQueryResultSet",
"[",
"sQName",
"]",
";",
"}",
"return",
"oQueryResult",
";",
"}"
] |
Find analytic query result by name
@param {string}
sName Fully qualified name of query result entity set
@returns {sap.ui.model.analytics.odata4analytics.QueryResult} The query result object
with this name or null if it does not exist
@public
@function
@name sap.ui.model.analytics.odata4analytics.Model#findQueryResultByName
|
[
"Find",
"analytic",
"query",
"result",
"by",
"name"
] |
8a832fca01cb1cdf8df589788e0c5723e2a33c70
|
https://github.com/SAP/openui5/blob/8a832fca01cb1cdf8df589788e0c5723e2a33c70/src/sap.ui.core/src/sap/ui/model/analytics/odata4analytics.js#L743-L755
|
train
|
|
SAP/openui5
|
src/sap.ui.core/src/sap/ui/model/analytics/odata4analytics.js
|
function(oSchema, sQTypeName) {
var aEntitySet = [];
for (var i = -1, oEntityContainer; (oEntityContainer = oSchema.entityContainer[++i]) !== undefined;) {
for (var j = -1, oEntitySet; (oEntitySet = oEntityContainer.entitySet[++j]) !== undefined;) {
if (oEntitySet.entityType == sQTypeName) {
aEntitySet.push([ oEntityContainer, oEntitySet ]);
}
}
}
return aEntitySet;
}
|
javascript
|
function(oSchema, sQTypeName) {
var aEntitySet = [];
for (var i = -1, oEntityContainer; (oEntityContainer = oSchema.entityContainer[++i]) !== undefined;) {
for (var j = -1, oEntitySet; (oEntitySet = oEntityContainer.entitySet[++j]) !== undefined;) {
if (oEntitySet.entityType == sQTypeName) {
aEntitySet.push([ oEntityContainer, oEntitySet ]);
}
}
}
return aEntitySet;
}
|
[
"function",
"(",
"oSchema",
",",
"sQTypeName",
")",
"{",
"var",
"aEntitySet",
"=",
"[",
"]",
";",
"for",
"(",
"var",
"i",
"=",
"-",
"1",
",",
"oEntityContainer",
";",
"(",
"oEntityContainer",
"=",
"oSchema",
".",
"entityContainer",
"[",
"++",
"i",
"]",
")",
"!==",
"undefined",
";",
")",
"{",
"for",
"(",
"var",
"j",
"=",
"-",
"1",
",",
"oEntitySet",
";",
"(",
"oEntitySet",
"=",
"oEntityContainer",
".",
"entitySet",
"[",
"++",
"j",
"]",
")",
"!==",
"undefined",
";",
")",
"{",
"if",
"(",
"oEntitySet",
".",
"entityType",
"==",
"sQTypeName",
")",
"{",
"aEntitySet",
".",
"push",
"(",
"[",
"oEntityContainer",
",",
"oEntitySet",
"]",
")",
";",
"}",
"}",
"}",
"return",
"aEntitySet",
";",
"}"
] |
Private methods
Find entity sets of a given type
@private
|
[
"Private",
"methods",
"Find",
"entity",
"sets",
"of",
"a",
"given",
"type"
] |
8a832fca01cb1cdf8df589788e0c5723e2a33c70
|
https://github.com/SAP/openui5/blob/8a832fca01cb1cdf8df589788e0c5723e2a33c70/src/sap.ui.core/src/sap/ui/model/analytics/odata4analytics.js#L815-L827
|
train
|
|
SAP/openui5
|
src/sap.ui.core/src/sap/ui/model/analytics/odata4analytics.js
|
function(oModel, oEntityType, oEntitySet, oParameterization, oAssocFromParamsToResult) {
this._oModel = oModel;
this._oEntityType = oEntityType;
this._oEntitySet = oEntitySet;
this._oParameterization = oParameterization;
this._oDimensionSet = {};
this._oMeasureSet = {};
// parse entity type for analytic semantics described by annotations
var aProperty = oEntityType.getTypeDescription().property;
var oAttributeForPropertySet = {};
for (var i = -1, oProperty; (oProperty = aProperty[++i]) !== undefined;) {
if (oProperty.extensions == undefined) {
continue;
}
for (var j = -1, oExtension; (oExtension = oProperty.extensions[++j]) !== undefined;) {
if (!oExtension.namespace == odata4analytics.constants.SAP_NAMESPACE) {
continue;
}
switch (oExtension.name) {
case "aggregation-role":
switch (oExtension.value) {
case "dimension": {
var oDimension = new odata4analytics.Dimension(this, oProperty);
this._oDimensionSet[oDimension.getName()] = oDimension;
break;
}
case "measure": {
var oMeasure = new odata4analytics.Measure(this, oProperty);
this._oMeasureSet[oMeasure.getName()] = oMeasure;
break;
}
case "totaled-properties-list":
this._oTotaledPropertyListProperty = oProperty;
break;
default:
}
break;
case "attribute-for": {
var oDimensionAttribute = new odata4analytics.DimensionAttribute(this, oProperty);
var oKeyProperty = oDimensionAttribute.getKeyProperty();
oAttributeForPropertySet[oKeyProperty.name] = oDimensionAttribute;
break;
}
default:
}
}
}
// assign dimension attributes to the respective dimension objects
for ( var sDimensionAttributeName in oAttributeForPropertySet) {
var oDimensionAttribute2 = oAttributeForPropertySet[sDimensionAttributeName];
oDimensionAttribute2.getDimension().addAttribute(oDimensionAttribute2);
}
// apply workaround for missing text properties if requested
if (oModel._oActivatedWorkarounds.IdentifyTextPropertiesByName) {
var aMatchedTextPropertyName = [];
for ( var oDimName in this._oDimensionSet) {
var oDimension2 = this._oDimensionSet[oDimName];
if (!oDimension2.getTextProperty()) {
var oTextProperty = null; // order of matching is
// significant!
oTextProperty = oEntityType.findPropertyByName(oDimName + "Name");
if (!oTextProperty) {
oTextProperty = oEntityType.findPropertyByName(oDimName + "Text");
}
if (!oTextProperty) {
oTextProperty = oEntityType.findPropertyByName(oDimName + "Desc");
}
if (!oTextProperty) {
oTextProperty = oEntityType.findPropertyByName(oDimName + "Description");
}
if (oTextProperty) { // any match?
oDimension2.setTextProperty(oTextProperty); // link
// dimension
// with text
// property
aMatchedTextPropertyName.push(oTextProperty.name);
}
}
}
// make sure that any matched text property is not exposed as
// dimension (according to spec)
for (var t = -1, sPropertyName; (sPropertyName = aMatchedTextPropertyName[++t]) !== undefined;) {
delete this._oDimensionSet[sPropertyName];
}
}
}
|
javascript
|
function(oModel, oEntityType, oEntitySet, oParameterization, oAssocFromParamsToResult) {
this._oModel = oModel;
this._oEntityType = oEntityType;
this._oEntitySet = oEntitySet;
this._oParameterization = oParameterization;
this._oDimensionSet = {};
this._oMeasureSet = {};
// parse entity type for analytic semantics described by annotations
var aProperty = oEntityType.getTypeDescription().property;
var oAttributeForPropertySet = {};
for (var i = -1, oProperty; (oProperty = aProperty[++i]) !== undefined;) {
if (oProperty.extensions == undefined) {
continue;
}
for (var j = -1, oExtension; (oExtension = oProperty.extensions[++j]) !== undefined;) {
if (!oExtension.namespace == odata4analytics.constants.SAP_NAMESPACE) {
continue;
}
switch (oExtension.name) {
case "aggregation-role":
switch (oExtension.value) {
case "dimension": {
var oDimension = new odata4analytics.Dimension(this, oProperty);
this._oDimensionSet[oDimension.getName()] = oDimension;
break;
}
case "measure": {
var oMeasure = new odata4analytics.Measure(this, oProperty);
this._oMeasureSet[oMeasure.getName()] = oMeasure;
break;
}
case "totaled-properties-list":
this._oTotaledPropertyListProperty = oProperty;
break;
default:
}
break;
case "attribute-for": {
var oDimensionAttribute = new odata4analytics.DimensionAttribute(this, oProperty);
var oKeyProperty = oDimensionAttribute.getKeyProperty();
oAttributeForPropertySet[oKeyProperty.name] = oDimensionAttribute;
break;
}
default:
}
}
}
// assign dimension attributes to the respective dimension objects
for ( var sDimensionAttributeName in oAttributeForPropertySet) {
var oDimensionAttribute2 = oAttributeForPropertySet[sDimensionAttributeName];
oDimensionAttribute2.getDimension().addAttribute(oDimensionAttribute2);
}
// apply workaround for missing text properties if requested
if (oModel._oActivatedWorkarounds.IdentifyTextPropertiesByName) {
var aMatchedTextPropertyName = [];
for ( var oDimName in this._oDimensionSet) {
var oDimension2 = this._oDimensionSet[oDimName];
if (!oDimension2.getTextProperty()) {
var oTextProperty = null; // order of matching is
// significant!
oTextProperty = oEntityType.findPropertyByName(oDimName + "Name");
if (!oTextProperty) {
oTextProperty = oEntityType.findPropertyByName(oDimName + "Text");
}
if (!oTextProperty) {
oTextProperty = oEntityType.findPropertyByName(oDimName + "Desc");
}
if (!oTextProperty) {
oTextProperty = oEntityType.findPropertyByName(oDimName + "Description");
}
if (oTextProperty) { // any match?
oDimension2.setTextProperty(oTextProperty); // link
// dimension
// with text
// property
aMatchedTextPropertyName.push(oTextProperty.name);
}
}
}
// make sure that any matched text property is not exposed as
// dimension (according to spec)
for (var t = -1, sPropertyName; (sPropertyName = aMatchedTextPropertyName[++t]) !== undefined;) {
delete this._oDimensionSet[sPropertyName];
}
}
}
|
[
"function",
"(",
"oModel",
",",
"oEntityType",
",",
"oEntitySet",
",",
"oParameterization",
",",
"oAssocFromParamsToResult",
")",
"{",
"this",
".",
"_oModel",
"=",
"oModel",
";",
"this",
".",
"_oEntityType",
"=",
"oEntityType",
";",
"this",
".",
"_oEntitySet",
"=",
"oEntitySet",
";",
"this",
".",
"_oParameterization",
"=",
"oParameterization",
";",
"this",
".",
"_oDimensionSet",
"=",
"{",
"}",
";",
"this",
".",
"_oMeasureSet",
"=",
"{",
"}",
";",
"var",
"aProperty",
"=",
"oEntityType",
".",
"getTypeDescription",
"(",
")",
".",
"property",
";",
"var",
"oAttributeForPropertySet",
"=",
"{",
"}",
";",
"for",
"(",
"var",
"i",
"=",
"-",
"1",
",",
"oProperty",
";",
"(",
"oProperty",
"=",
"aProperty",
"[",
"++",
"i",
"]",
")",
"!==",
"undefined",
";",
")",
"{",
"if",
"(",
"oProperty",
".",
"extensions",
"==",
"undefined",
")",
"{",
"continue",
";",
"}",
"for",
"(",
"var",
"j",
"=",
"-",
"1",
",",
"oExtension",
";",
"(",
"oExtension",
"=",
"oProperty",
".",
"extensions",
"[",
"++",
"j",
"]",
")",
"!==",
"undefined",
";",
")",
"{",
"if",
"(",
"!",
"oExtension",
".",
"namespace",
"==",
"odata4analytics",
".",
"constants",
".",
"SAP_NAMESPACE",
")",
"{",
"continue",
";",
"}",
"switch",
"(",
"oExtension",
".",
"name",
")",
"{",
"case",
"\"aggregation-role\"",
":",
"switch",
"(",
"oExtension",
".",
"value",
")",
"{",
"case",
"\"dimension\"",
":",
"{",
"var",
"oDimension",
"=",
"new",
"odata4analytics",
".",
"Dimension",
"(",
"this",
",",
"oProperty",
")",
";",
"this",
".",
"_oDimensionSet",
"[",
"oDimension",
".",
"getName",
"(",
")",
"]",
"=",
"oDimension",
";",
"break",
";",
"}",
"case",
"\"measure\"",
":",
"{",
"var",
"oMeasure",
"=",
"new",
"odata4analytics",
".",
"Measure",
"(",
"this",
",",
"oProperty",
")",
";",
"this",
".",
"_oMeasureSet",
"[",
"oMeasure",
".",
"getName",
"(",
")",
"]",
"=",
"oMeasure",
";",
"break",
";",
"}",
"case",
"\"totaled-properties-list\"",
":",
"this",
".",
"_oTotaledPropertyListProperty",
"=",
"oProperty",
";",
"break",
";",
"default",
":",
"}",
"break",
";",
"case",
"\"attribute-for\"",
":",
"{",
"var",
"oDimensionAttribute",
"=",
"new",
"odata4analytics",
".",
"DimensionAttribute",
"(",
"this",
",",
"oProperty",
")",
";",
"var",
"oKeyProperty",
"=",
"oDimensionAttribute",
".",
"getKeyProperty",
"(",
")",
";",
"oAttributeForPropertySet",
"[",
"oKeyProperty",
".",
"name",
"]",
"=",
"oDimensionAttribute",
";",
"break",
";",
"}",
"default",
":",
"}",
"}",
"}",
"for",
"(",
"var",
"sDimensionAttributeName",
"in",
"oAttributeForPropertySet",
")",
"{",
"var",
"oDimensionAttribute2",
"=",
"oAttributeForPropertySet",
"[",
"sDimensionAttributeName",
"]",
";",
"oDimensionAttribute2",
".",
"getDimension",
"(",
")",
".",
"addAttribute",
"(",
"oDimensionAttribute2",
")",
";",
"}",
"if",
"(",
"oModel",
".",
"_oActivatedWorkarounds",
".",
"IdentifyTextPropertiesByName",
")",
"{",
"var",
"aMatchedTextPropertyName",
"=",
"[",
"]",
";",
"for",
"(",
"var",
"oDimName",
"in",
"this",
".",
"_oDimensionSet",
")",
"{",
"var",
"oDimension2",
"=",
"this",
".",
"_oDimensionSet",
"[",
"oDimName",
"]",
";",
"if",
"(",
"!",
"oDimension2",
".",
"getTextProperty",
"(",
")",
")",
"{",
"var",
"oTextProperty",
"=",
"null",
";",
"oTextProperty",
"=",
"oEntityType",
".",
"findPropertyByName",
"(",
"oDimName",
"+",
"\"Name\"",
")",
";",
"if",
"(",
"!",
"oTextProperty",
")",
"{",
"oTextProperty",
"=",
"oEntityType",
".",
"findPropertyByName",
"(",
"oDimName",
"+",
"\"Text\"",
")",
";",
"}",
"if",
"(",
"!",
"oTextProperty",
")",
"{",
"oTextProperty",
"=",
"oEntityType",
".",
"findPropertyByName",
"(",
"oDimName",
"+",
"\"Desc\"",
")",
";",
"}",
"if",
"(",
"!",
"oTextProperty",
")",
"{",
"oTextProperty",
"=",
"oEntityType",
".",
"findPropertyByName",
"(",
"oDimName",
"+",
"\"Description\"",
")",
";",
"}",
"if",
"(",
"oTextProperty",
")",
"{",
"oDimension2",
".",
"setTextProperty",
"(",
"oTextProperty",
")",
";",
"aMatchedTextPropertyName",
".",
"push",
"(",
"oTextProperty",
".",
"name",
")",
";",
"}",
"}",
"}",
"for",
"(",
"var",
"t",
"=",
"-",
"1",
",",
"sPropertyName",
";",
"(",
"sPropertyName",
"=",
"aMatchedTextPropertyName",
"[",
"++",
"t",
"]",
")",
"!==",
"undefined",
";",
")",
"{",
"delete",
"this",
".",
"_oDimensionSet",
"[",
"sPropertyName",
"]",
";",
"}",
"}",
"}"
] |
initialize new object
@private
|
[
"initialize",
"new",
"object"
] |
8a832fca01cb1cdf8df589788e0c5723e2a33c70
|
https://github.com/SAP/openui5/blob/8a832fca01cb1cdf8df589788e0c5723e2a33c70/src/sap.ui.core/src/sap/ui/model/analytics/odata4analytics.js#L880-L971
|
train
|
|
SAP/openui5
|
src/sap.ui.core/src/sap/ui/model/analytics/odata4analytics.js
|
function() {
if (this._aDimensionNames) {
return this._aDimensionNames;
}
this._aDimensionNames = [];
for ( var sName in this._oDimensionSet) {
this._aDimensionNames.push(this._oDimensionSet[sName].getName());
}
return this._aDimensionNames;
}
|
javascript
|
function() {
if (this._aDimensionNames) {
return this._aDimensionNames;
}
this._aDimensionNames = [];
for ( var sName in this._oDimensionSet) {
this._aDimensionNames.push(this._oDimensionSet[sName].getName());
}
return this._aDimensionNames;
}
|
[
"function",
"(",
")",
"{",
"if",
"(",
"this",
".",
"_aDimensionNames",
")",
"{",
"return",
"this",
".",
"_aDimensionNames",
";",
"}",
"this",
".",
"_aDimensionNames",
"=",
"[",
"]",
";",
"for",
"(",
"var",
"sName",
"in",
"this",
".",
"_oDimensionSet",
")",
"{",
"this",
".",
"_aDimensionNames",
".",
"push",
"(",
"this",
".",
"_oDimensionSet",
"[",
"sName",
"]",
".",
"getName",
"(",
")",
")",
";",
"}",
"return",
"this",
".",
"_aDimensionNames",
";",
"}"
] |
Get the names of all dimensions included in the query result
@returns {string[]} List of all dimension names
@public
@function
@name sap.ui.model.analytics.odata4analytics.QueryResult#getAllDimensionNames
|
[
"Get",
"the",
"names",
"of",
"all",
"dimensions",
"included",
"in",
"the",
"query",
"result"
] |
8a832fca01cb1cdf8df589788e0c5723e2a33c70
|
https://github.com/SAP/openui5/blob/8a832fca01cb1cdf8df589788e0c5723e2a33c70/src/sap.ui.core/src/sap/ui/model/analytics/odata4analytics.js#L1009-L1021
|
train
|
|
SAP/openui5
|
src/sap.ui.core/src/sap/ui/model/analytics/odata4analytics.js
|
function() {
if (this._aMeasureNames) {
return this._aMeasureNames;
}
this._aMeasureNames = [];
for ( var sName in this._oMeasureSet) {
this._aMeasureNames.push(this._oMeasureSet[sName].getName());
}
return this._aMeasureNames;
}
|
javascript
|
function() {
if (this._aMeasureNames) {
return this._aMeasureNames;
}
this._aMeasureNames = [];
for ( var sName in this._oMeasureSet) {
this._aMeasureNames.push(this._oMeasureSet[sName].getName());
}
return this._aMeasureNames;
}
|
[
"function",
"(",
")",
"{",
"if",
"(",
"this",
".",
"_aMeasureNames",
")",
"{",
"return",
"this",
".",
"_aMeasureNames",
";",
"}",
"this",
".",
"_aMeasureNames",
"=",
"[",
"]",
";",
"for",
"(",
"var",
"sName",
"in",
"this",
".",
"_oMeasureSet",
")",
"{",
"this",
".",
"_aMeasureNames",
".",
"push",
"(",
"this",
".",
"_oMeasureSet",
"[",
"sName",
"]",
".",
"getName",
"(",
")",
")",
";",
"}",
"return",
"this",
".",
"_aMeasureNames",
";",
"}"
] |
Get the names of all measures included in the query result
@returns {string[]} List of all measure names
@public
@function
@name sap.ui.model.analytics.odata4analytics.QueryResult#getAllMeasureNames
|
[
"Get",
"the",
"names",
"of",
"all",
"measures",
"included",
"in",
"the",
"query",
"result"
] |
8a832fca01cb1cdf8df589788e0c5723e2a33c70
|
https://github.com/SAP/openui5/blob/8a832fca01cb1cdf8df589788e0c5723e2a33c70/src/sap.ui.core/src/sap/ui/model/analytics/odata4analytics.js#L1047-L1059
|
train
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.