id
int32 0
58k
| repo
stringlengths 5
67
| path
stringlengths 4
116
| func_name
stringlengths 0
58
| original_string
stringlengths 52
373k
| language
stringclasses 1
value | code
stringlengths 52
373k
| code_tokens
sequence | docstring
stringlengths 4
11.8k
| docstring_tokens
sequence | sha
stringlengths 40
40
| url
stringlengths 86
226
|
---|---|---|---|---|---|---|---|---|---|---|---|
5,500 | stylelint/stylelint | lib/augmentConfig.js | augmentConfigExtended | function augmentConfigExtended(
stylelint /*: stylelint$internalApi*/,
cosmiconfigResultArg /*: ?{
config: stylelint$config,
filepath: string,
}*/
) /*: Promise<?{ config: stylelint$config, filepath: string }>*/ {
const cosmiconfigResult = cosmiconfigResultArg; // Lock in for Flow
if (!cosmiconfigResult) return Promise.resolve(null);
const configDir = path.dirname(cosmiconfigResult.filepath || "");
const cleanedConfig = _.omit(cosmiconfigResult.config, "ignoreFiles");
return augmentConfigBasic(stylelint, cleanedConfig, configDir).then(
augmentedConfig => {
return {
config: augmentedConfig,
filepath: cosmiconfigResult.filepath
};
}
);
} | javascript | function augmentConfigExtended(
stylelint /*: stylelint$internalApi*/,
cosmiconfigResultArg /*: ?{
config: stylelint$config,
filepath: string,
}*/
) /*: Promise<?{ config: stylelint$config, filepath: string }>*/ {
const cosmiconfigResult = cosmiconfigResultArg; // Lock in for Flow
if (!cosmiconfigResult) return Promise.resolve(null);
const configDir = path.dirname(cosmiconfigResult.filepath || "");
const cleanedConfig = _.omit(cosmiconfigResult.config, "ignoreFiles");
return augmentConfigBasic(stylelint, cleanedConfig, configDir).then(
augmentedConfig => {
return {
config: augmentedConfig,
filepath: cosmiconfigResult.filepath
};
}
);
} | [
"function",
"augmentConfigExtended",
"(",
"stylelint",
"/*: stylelint$internalApi*/",
",",
"cosmiconfigResultArg",
"/*: ?{\n config: stylelint$config,\n filepath: string,\n }*/",
")",
"/*: Promise<?{ config: stylelint$config, filepath: string }>*/",
"{",
"const",
"cosmiconfigResult",
"=",
"cosmiconfigResultArg",
";",
"// Lock in for Flow",
"if",
"(",
"!",
"cosmiconfigResult",
")",
"return",
"Promise",
".",
"resolve",
"(",
"null",
")",
";",
"const",
"configDir",
"=",
"path",
".",
"dirname",
"(",
"cosmiconfigResult",
".",
"filepath",
"||",
"\"\"",
")",
";",
"const",
"cleanedConfig",
"=",
"_",
".",
"omit",
"(",
"cosmiconfigResult",
".",
"config",
",",
"\"ignoreFiles\"",
")",
";",
"return",
"augmentConfigBasic",
"(",
"stylelint",
",",
"cleanedConfig",
",",
"configDir",
")",
".",
"then",
"(",
"augmentedConfig",
"=>",
"{",
"return",
"{",
"config",
":",
"augmentedConfig",
",",
"filepath",
":",
"cosmiconfigResult",
".",
"filepath",
"}",
";",
"}",
")",
";",
"}"
] | Extended configs need to be run through augmentConfigBasic but do not need the full treatment. Things like pluginFunctions will be resolved and added by the parent config. | [
"Extended",
"configs",
"need",
"to",
"be",
"run",
"through",
"augmentConfigBasic",
"but",
"do",
"not",
"need",
"the",
"full",
"treatment",
".",
"Things",
"like",
"pluginFunctions",
"will",
"be",
"resolved",
"and",
"added",
"by",
"the",
"parent",
"config",
"."
] | b35c55f6144d0cb03924498f275cc39c39de3816 | https://github.com/stylelint/stylelint/blob/b35c55f6144d0cb03924498f275cc39c39de3816/lib/augmentConfig.js#L39-L61 |
5,501 | stylelint/stylelint | lib/augmentConfig.js | absolutizeProcessors | function absolutizeProcessors(
processors /*: stylelint$configProcessors*/,
configDir /*: string*/
) /*: stylelint$configProcessors*/ {
const normalizedProcessors = Array.isArray(processors)
? processors
: [processors];
return normalizedProcessors.map(item => {
if (typeof item === "string") {
return getModulePath(configDir, item);
}
return [getModulePath(configDir, item[0]), item[1]];
});
} | javascript | function absolutizeProcessors(
processors /*: stylelint$configProcessors*/,
configDir /*: string*/
) /*: stylelint$configProcessors*/ {
const normalizedProcessors = Array.isArray(processors)
? processors
: [processors];
return normalizedProcessors.map(item => {
if (typeof item === "string") {
return getModulePath(configDir, item);
}
return [getModulePath(configDir, item[0]), item[1]];
});
} | [
"function",
"absolutizeProcessors",
"(",
"processors",
"/*: stylelint$configProcessors*/",
",",
"configDir",
"/*: string*/",
")",
"/*: stylelint$configProcessors*/",
"{",
"const",
"normalizedProcessors",
"=",
"Array",
".",
"isArray",
"(",
"processors",
")",
"?",
"processors",
":",
"[",
"processors",
"]",
";",
"return",
"normalizedProcessors",
".",
"map",
"(",
"item",
"=>",
"{",
"if",
"(",
"typeof",
"item",
"===",
"\"string\"",
")",
"{",
"return",
"getModulePath",
"(",
"configDir",
",",
"item",
")",
";",
"}",
"return",
"[",
"getModulePath",
"(",
"configDir",
",",
"item",
"[",
"0",
"]",
")",
",",
"item",
"[",
"1",
"]",
"]",
";",
"}",
")",
";",
"}"
] | Processors are absolutized in their own way because they can be and return a string or an array | [
"Processors",
"are",
"absolutized",
"in",
"their",
"own",
"way",
"because",
"they",
"can",
"be",
"and",
"return",
"a",
"string",
"or",
"an",
"array"
] | b35c55f6144d0cb03924498f275cc39c39de3816 | https://github.com/stylelint/stylelint/blob/b35c55f6144d0cb03924498f275cc39c39de3816/lib/augmentConfig.js#L136-L151 |
5,502 | stylelint/stylelint | lib/utils/addEmptyLineAfter.js | addEmptyLineAfter | function addEmptyLineAfter(
node /*: postcss$node*/,
newline /*: '\n' | '\r\n'*/
) /*: postcss$node*/ {
const after = _.last(node.raws.after.split(";"));
if (!/\r?\n/.test(after)) {
node.raws.after = node.raws.after + _.repeat(newline, 2);
} else {
node.raws.after = node.raws.after.replace(/(\r?\n)/, `${newline}$1`);
}
return node;
} | javascript | function addEmptyLineAfter(
node /*: postcss$node*/,
newline /*: '\n' | '\r\n'*/
) /*: postcss$node*/ {
const after = _.last(node.raws.after.split(";"));
if (!/\r?\n/.test(after)) {
node.raws.after = node.raws.after + _.repeat(newline, 2);
} else {
node.raws.after = node.raws.after.replace(/(\r?\n)/, `${newline}$1`);
}
return node;
} | [
"function",
"addEmptyLineAfter",
"(",
"node",
"/*: postcss$node*/",
",",
"newline",
"/*: '\\n' | '\\r\\n'*/",
")",
"/*: postcss$node*/",
"{",
"const",
"after",
"=",
"_",
".",
"last",
"(",
"node",
".",
"raws",
".",
"after",
".",
"split",
"(",
"\";\"",
")",
")",
";",
"if",
"(",
"!",
"/",
"\\r?\\n",
"/",
".",
"test",
"(",
"after",
")",
")",
"{",
"node",
".",
"raws",
".",
"after",
"=",
"node",
".",
"raws",
".",
"after",
"+",
"_",
".",
"repeat",
"(",
"newline",
",",
"2",
")",
";",
"}",
"else",
"{",
"node",
".",
"raws",
".",
"after",
"=",
"node",
".",
"raws",
".",
"after",
".",
"replace",
"(",
"/",
"(\\r?\\n)",
"/",
",",
"`",
"${",
"newline",
"}",
"`",
")",
";",
"}",
"return",
"node",
";",
"}"
] | Add an empty line after a node. Mutates the node. | [
"Add",
"an",
"empty",
"line",
"after",
"a",
"node",
".",
"Mutates",
"the",
"node",
"."
] | b35c55f6144d0cb03924498f275cc39c39de3816 | https://github.com/stylelint/stylelint/blob/b35c55f6144d0cb03924498f275cc39c39de3816/lib/utils/addEmptyLineAfter.js#L7-L20 |
5,503 | stylelint/stylelint | lib/utils/addEmptyLineBefore.js | addEmptyLineBefore | function addEmptyLineBefore(
node /*: postcss$node*/,
newline /*: '\n' | '\r\n'*/
) /*: postcss$node*/ {
if (!/\r?\n/.test(node.raws.before)) {
node.raws.before = _.repeat(newline, 2) + node.raws.before;
} else {
node.raws.before = node.raws.before.replace(/(\r?\n)/, `${newline}$1`);
}
return node;
} | javascript | function addEmptyLineBefore(
node /*: postcss$node*/,
newline /*: '\n' | '\r\n'*/
) /*: postcss$node*/ {
if (!/\r?\n/.test(node.raws.before)) {
node.raws.before = _.repeat(newline, 2) + node.raws.before;
} else {
node.raws.before = node.raws.before.replace(/(\r?\n)/, `${newline}$1`);
}
return node;
} | [
"function",
"addEmptyLineBefore",
"(",
"node",
"/*: postcss$node*/",
",",
"newline",
"/*: '\\n' | '\\r\\n'*/",
")",
"/*: postcss$node*/",
"{",
"if",
"(",
"!",
"/",
"\\r?\\n",
"/",
".",
"test",
"(",
"node",
".",
"raws",
".",
"before",
")",
")",
"{",
"node",
".",
"raws",
".",
"before",
"=",
"_",
".",
"repeat",
"(",
"newline",
",",
"2",
")",
"+",
"node",
".",
"raws",
".",
"before",
";",
"}",
"else",
"{",
"node",
".",
"raws",
".",
"before",
"=",
"node",
".",
"raws",
".",
"before",
".",
"replace",
"(",
"/",
"(\\r?\\n)",
"/",
",",
"`",
"${",
"newline",
"}",
"`",
")",
";",
"}",
"return",
"node",
";",
"}"
] | Add an empty line before a node. Mutates the node. | [
"Add",
"an",
"empty",
"line",
"before",
"a",
"node",
".",
"Mutates",
"the",
"node",
"."
] | b35c55f6144d0cb03924498f275cc39c39de3816 | https://github.com/stylelint/stylelint/blob/b35c55f6144d0cb03924498f275cc39c39de3816/lib/utils/addEmptyLineBefore.js#L7-L18 |
5,504 | lambci/docker-lambda | nodejs6.10/run/awslambda-mock.js | function(invokeId, errType, resultStr) {
if (!invoked) return
var diffMs = hrTimeMs(process.hrtime(start))
var billedMs = Math.min(100 * (Math.floor(diffMs / 100) + 1), TIMEOUT * 1000)
systemLog('END RequestId: ' + invokeId)
systemLog([
'REPORT RequestId: ' + invokeId,
'Duration: ' + diffMs.toFixed(2) + ' ms',
'Billed Duration: ' + billedMs + ' ms',
'Memory Size: ' + MEM_SIZE + ' MB',
'Max Memory Used: ' + Math.round(process.memoryUsage().rss / (1024 * 1024)) + ' MB',
'',
].join('\t'))
var exitCode = errored || errType ? 1 : 0
if (typeof resultStr === 'string') {
handleResult(resultStr, function() { process.exit(exitCode) })
} else {
process.exit(exitCode)
}
} | javascript | function(invokeId, errType, resultStr) {
if (!invoked) return
var diffMs = hrTimeMs(process.hrtime(start))
var billedMs = Math.min(100 * (Math.floor(diffMs / 100) + 1), TIMEOUT * 1000)
systemLog('END RequestId: ' + invokeId)
systemLog([
'REPORT RequestId: ' + invokeId,
'Duration: ' + diffMs.toFixed(2) + ' ms',
'Billed Duration: ' + billedMs + ' ms',
'Memory Size: ' + MEM_SIZE + ' MB',
'Max Memory Used: ' + Math.round(process.memoryUsage().rss / (1024 * 1024)) + ' MB',
'',
].join('\t'))
var exitCode = errored || errType ? 1 : 0
if (typeof resultStr === 'string') {
handleResult(resultStr, function() { process.exit(exitCode) })
} else {
process.exit(exitCode)
}
} | [
"function",
"(",
"invokeId",
",",
"errType",
",",
"resultStr",
")",
"{",
"if",
"(",
"!",
"invoked",
")",
"return",
"var",
"diffMs",
"=",
"hrTimeMs",
"(",
"process",
".",
"hrtime",
"(",
"start",
")",
")",
"var",
"billedMs",
"=",
"Math",
".",
"min",
"(",
"100",
"*",
"(",
"Math",
".",
"floor",
"(",
"diffMs",
"/",
"100",
")",
"+",
"1",
")",
",",
"TIMEOUT",
"*",
"1000",
")",
"systemLog",
"(",
"'END RequestId: '",
"+",
"invokeId",
")",
"systemLog",
"(",
"[",
"'REPORT RequestId: '",
"+",
"invokeId",
",",
"'Duration: '",
"+",
"diffMs",
".",
"toFixed",
"(",
"2",
")",
"+",
"' ms'",
",",
"'Billed Duration: '",
"+",
"billedMs",
"+",
"' ms'",
",",
"'Memory Size: '",
"+",
"MEM_SIZE",
"+",
"' MB'",
",",
"'Max Memory Used: '",
"+",
"Math",
".",
"round",
"(",
"process",
".",
"memoryUsage",
"(",
")",
".",
"rss",
"/",
"(",
"1024",
"*",
"1024",
")",
")",
"+",
"' MB'",
",",
"''",
",",
"]",
".",
"join",
"(",
"'\\t'",
")",
")",
"var",
"exitCode",
"=",
"errored",
"||",
"errType",
"?",
"1",
":",
"0",
"if",
"(",
"typeof",
"resultStr",
"===",
"'string'",
")",
"{",
"handleResult",
"(",
"resultStr",
",",
"function",
"(",
")",
"{",
"process",
".",
"exit",
"(",
"exitCode",
")",
"}",
")",
"}",
"else",
"{",
"process",
".",
"exit",
"(",
"exitCode",
")",
"}",
"}"
] | eslint-disable-line no-unused-vars | [
"eslint",
"-",
"disable",
"-",
"line",
"no",
"-",
"unused",
"-",
"vars"
] | d5a7c1d5cb8615b98cfab8e802140182c897b23a | https://github.com/lambci/docker-lambda/blob/d5a7c1d5cb8615b98cfab8e802140182c897b23a/nodejs6.10/run/awslambda-mock.js#L88-L108 |
|
5,505 | lambci/docker-lambda | nodejs6.10/run/awslambda-mock.js | uuid | function uuid() {
return crypto.randomBytes(4).toString('hex') + '-' +
crypto.randomBytes(2).toString('hex') + '-' +
crypto.randomBytes(2).toString('hex').replace(/^./, '1') + '-' +
crypto.randomBytes(2).toString('hex') + '-' +
crypto.randomBytes(6).toString('hex')
} | javascript | function uuid() {
return crypto.randomBytes(4).toString('hex') + '-' +
crypto.randomBytes(2).toString('hex') + '-' +
crypto.randomBytes(2).toString('hex').replace(/^./, '1') + '-' +
crypto.randomBytes(2).toString('hex') + '-' +
crypto.randomBytes(6).toString('hex')
} | [
"function",
"uuid",
"(",
")",
"{",
"return",
"crypto",
".",
"randomBytes",
"(",
"4",
")",
".",
"toString",
"(",
"'hex'",
")",
"+",
"'-'",
"+",
"crypto",
".",
"randomBytes",
"(",
"2",
")",
".",
"toString",
"(",
"'hex'",
")",
"+",
"'-'",
"+",
"crypto",
".",
"randomBytes",
"(",
"2",
")",
".",
"toString",
"(",
"'hex'",
")",
".",
"replace",
"(",
"/",
"^.",
"/",
",",
"'1'",
")",
"+",
"'-'",
"+",
"crypto",
".",
"randomBytes",
"(",
"2",
")",
".",
"toString",
"(",
"'hex'",
")",
"+",
"'-'",
"+",
"crypto",
".",
"randomBytes",
"(",
"6",
")",
".",
"toString",
"(",
"'hex'",
")",
"}"
] | Approximates the look of a v1 UUID | [
"Approximates",
"the",
"look",
"of",
"a",
"v1",
"UUID"
] | d5a7c1d5cb8615b98cfab8e802140182c897b23a | https://github.com/lambci/docker-lambda/blob/d5a7c1d5cb8615b98cfab8e802140182c897b23a/nodejs6.10/run/awslambda-mock.js#L143-L149 |
5,506 | priologic/easyrtc | lib/easyrtc_public_obj.js | function(roomName, appRoomObj, callback) {
// Join room. Creates a default connection room object
e.app[appName].connection[easyrtcid].room[roomName] = {
apiField: {},
enteredOn: Date.now(),
gotListOn: Date.now(),
clientList: {},
toRoom: e.app[appName].room[roomName]
};
// Add easyrtcid to room clientList
e.app[appName].room[roomName].clientList[easyrtcid] = {
enteredOn: Date.now(),
modifiedOn: Date.now(),
toConnection: e.app[appName].connection[easyrtcid]
};
// Returns connection room object to callback.
connectionObj.room(roomName, callback);
} | javascript | function(roomName, appRoomObj, callback) {
// Join room. Creates a default connection room object
e.app[appName].connection[easyrtcid].room[roomName] = {
apiField: {},
enteredOn: Date.now(),
gotListOn: Date.now(),
clientList: {},
toRoom: e.app[appName].room[roomName]
};
// Add easyrtcid to room clientList
e.app[appName].room[roomName].clientList[easyrtcid] = {
enteredOn: Date.now(),
modifiedOn: Date.now(),
toConnection: e.app[appName].connection[easyrtcid]
};
// Returns connection room object to callback.
connectionObj.room(roomName, callback);
} | [
"function",
"(",
"roomName",
",",
"appRoomObj",
",",
"callback",
")",
"{",
"// Join room. Creates a default connection room object\r",
"e",
".",
"app",
"[",
"appName",
"]",
".",
"connection",
"[",
"easyrtcid",
"]",
".",
"room",
"[",
"roomName",
"]",
"=",
"{",
"apiField",
":",
"{",
"}",
",",
"enteredOn",
":",
"Date",
".",
"now",
"(",
")",
",",
"gotListOn",
":",
"Date",
".",
"now",
"(",
")",
",",
"clientList",
":",
"{",
"}",
",",
"toRoom",
":",
"e",
".",
"app",
"[",
"appName",
"]",
".",
"room",
"[",
"roomName",
"]",
"}",
";",
"// Add easyrtcid to room clientList\r",
"e",
".",
"app",
"[",
"appName",
"]",
".",
"room",
"[",
"roomName",
"]",
".",
"clientList",
"[",
"easyrtcid",
"]",
"=",
"{",
"enteredOn",
":",
"Date",
".",
"now",
"(",
")",
",",
"modifiedOn",
":",
"Date",
".",
"now",
"(",
")",
",",
"toConnection",
":",
"e",
".",
"app",
"[",
"appName",
"]",
".",
"connection",
"[",
"easyrtcid",
"]",
"}",
";",
"// Returns connection room object to callback.\r",
"connectionObj",
".",
"room",
"(",
"roomName",
",",
"callback",
")",
";",
"}"
] | Local private function to create the default connection-room object in the private variable | [
"Local",
"private",
"function",
"to",
"create",
"the",
"default",
"connection",
"-",
"room",
"object",
"in",
"the",
"private",
"variable"
] | 5ea69776f319fab15a784f94db91a2c1f5154ef5 | https://github.com/priologic/easyrtc/blob/5ea69776f319fab15a784f94db91a2c1f5154ef5/lib/easyrtc_public_obj.js#L2362-L2381 |
|
5,507 | priologic/easyrtc | lib/easyrtc_default_event_listeners.js | function (err) {
if (err) {
try{
pub.util.sendSocketCallbackMsg(easyrtcid, socketCallback, pub.util.getErrorMsg("LOGIN_GEN_FAIL"), appObj);
socket.disconnect();
pub.util.logError("["+easyrtcid+"] General authentication error. Socket disconnected.", err);
}catch(e) {}
} else {
callback(null, connectionObj);
}
} | javascript | function (err) {
if (err) {
try{
pub.util.sendSocketCallbackMsg(easyrtcid, socketCallback, pub.util.getErrorMsg("LOGIN_GEN_FAIL"), appObj);
socket.disconnect();
pub.util.logError("["+easyrtcid+"] General authentication error. Socket disconnected.", err);
}catch(e) {}
} else {
callback(null, connectionObj);
}
} | [
"function",
"(",
"err",
")",
"{",
"if",
"(",
"err",
")",
"{",
"try",
"{",
"pub",
".",
"util",
".",
"sendSocketCallbackMsg",
"(",
"easyrtcid",
",",
"socketCallback",
",",
"pub",
".",
"util",
".",
"getErrorMsg",
"(",
"\"LOGIN_GEN_FAIL\"",
")",
",",
"appObj",
")",
";",
"socket",
".",
"disconnect",
"(",
")",
";",
"pub",
".",
"util",
".",
"logError",
"(",
"\"[\"",
"+",
"easyrtcid",
"+",
"\"] General authentication error. Socket disconnected.\"",
",",
"err",
")",
";",
"}",
"catch",
"(",
"e",
")",
"{",
"}",
"}",
"else",
"{",
"callback",
"(",
"null",
",",
"connectionObj",
")",
";",
"}",
"}"
] | This function is called upon completion of the async waterfall, or upon an error being thrown. | [
"This",
"function",
"is",
"called",
"upon",
"completion",
"of",
"the",
"async",
"waterfall",
"or",
"upon",
"an",
"error",
"being",
"thrown",
"."
] | 5ea69776f319fab15a784f94db91a2c1f5154ef5 | https://github.com/priologic/easyrtc/blob/5ea69776f319fab15a784f94db91a2c1f5154ef5/lib/easyrtc_default_event_listeners.js#L491-L501 |
|
5,508 | priologic/easyrtc | demos/js/demo_ice_filter.js | iceCandidateFilter | function iceCandidateFilter( iceCandidate, fromPeer) {
var sdp = iceCandidate.candidate;
if( sdp.indexOf("typ relay") > 0) { // is turn candidate
if( document.getElementById("allowTurn").checked ) {
return iceCandidate;
}
else {
return null;
}
}
else if( sdp.indexOf("typ srflx") > 0) { // is turn candidate
if( document.getElementById("allowStun").checked ) {
return iceCandidate;
}
else {
return null;
}
}
else if( sdp.indexOf("typ host") > 0) { // is turn candidate
if( document.getElementById("allowLocal").checked ) {
return iceCandidate;
}
else {
return null;
}
}
else {
console.log("Unrecognized type of ice candidate, passing through: " + sdp);
}
} | javascript | function iceCandidateFilter( iceCandidate, fromPeer) {
var sdp = iceCandidate.candidate;
if( sdp.indexOf("typ relay") > 0) { // is turn candidate
if( document.getElementById("allowTurn").checked ) {
return iceCandidate;
}
else {
return null;
}
}
else if( sdp.indexOf("typ srflx") > 0) { // is turn candidate
if( document.getElementById("allowStun").checked ) {
return iceCandidate;
}
else {
return null;
}
}
else if( sdp.indexOf("typ host") > 0) { // is turn candidate
if( document.getElementById("allowLocal").checked ) {
return iceCandidate;
}
else {
return null;
}
}
else {
console.log("Unrecognized type of ice candidate, passing through: " + sdp);
}
} | [
"function",
"iceCandidateFilter",
"(",
"iceCandidate",
",",
"fromPeer",
")",
"{",
"var",
"sdp",
"=",
"iceCandidate",
".",
"candidate",
";",
"if",
"(",
"sdp",
".",
"indexOf",
"(",
"\"typ relay\"",
")",
">",
"0",
")",
"{",
"// is turn candidate",
"if",
"(",
"document",
".",
"getElementById",
"(",
"\"allowTurn\"",
")",
".",
"checked",
")",
"{",
"return",
"iceCandidate",
";",
"}",
"else",
"{",
"return",
"null",
";",
"}",
"}",
"else",
"if",
"(",
"sdp",
".",
"indexOf",
"(",
"\"typ srflx\"",
")",
">",
"0",
")",
"{",
"// is turn candidate",
"if",
"(",
"document",
".",
"getElementById",
"(",
"\"allowStun\"",
")",
".",
"checked",
")",
"{",
"return",
"iceCandidate",
";",
"}",
"else",
"{",
"return",
"null",
";",
"}",
"}",
"else",
"if",
"(",
"sdp",
".",
"indexOf",
"(",
"\"typ host\"",
")",
">",
"0",
")",
"{",
"// is turn candidate",
"if",
"(",
"document",
".",
"getElementById",
"(",
"\"allowLocal\"",
")",
".",
"checked",
")",
"{",
"return",
"iceCandidate",
";",
"}",
"else",
"{",
"return",
"null",
";",
"}",
"}",
"else",
"{",
"console",
".",
"log",
"(",
"\"Unrecognized type of ice candidate, passing through: \"",
"+",
"sdp",
")",
";",
"}",
"}"
] | filter ice candidates according to the ice candidates checkbox. | [
"filter",
"ice",
"candidates",
"according",
"to",
"the",
"ice",
"candidates",
"checkbox",
"."
] | 5ea69776f319fab15a784f94db91a2c1f5154ef5 | https://github.com/priologic/easyrtc/blob/5ea69776f319fab15a784f94db91a2c1f5154ef5/demos/js/demo_ice_filter.js#L6-L35 |
5,509 | priologic/easyrtc | demos/js/demo_multiparty.js | setThumbSizeAspect | function setThumbSizeAspect(percentSize, percentLeft, percentTop, parentw, parenth, aspect) {
var width, height;
if( parentw < parenth*aspectRatio){
width = parentw * percentSize;
height = width/aspect;
}
else {
height = parenth * percentSize;
width = height*aspect;
}
var left;
if( percentLeft < 0) {
left = parentw - width;
}
else {
left = 0;
}
left += Math.floor(percentLeft*parentw);
var top = 0;
if( percentTop < 0) {
top = parenth - height;
}
else {
top = 0;
}
top += Math.floor(percentTop*parenth);
return {
left:left,
top:top,
width:width,
height:height
};
} | javascript | function setThumbSizeAspect(percentSize, percentLeft, percentTop, parentw, parenth, aspect) {
var width, height;
if( parentw < parenth*aspectRatio){
width = parentw * percentSize;
height = width/aspect;
}
else {
height = parenth * percentSize;
width = height*aspect;
}
var left;
if( percentLeft < 0) {
left = parentw - width;
}
else {
left = 0;
}
left += Math.floor(percentLeft*parentw);
var top = 0;
if( percentTop < 0) {
top = parenth - height;
}
else {
top = 0;
}
top += Math.floor(percentTop*parenth);
return {
left:left,
top:top,
width:width,
height:height
};
} | [
"function",
"setThumbSizeAspect",
"(",
"percentSize",
",",
"percentLeft",
",",
"percentTop",
",",
"parentw",
",",
"parenth",
",",
"aspect",
")",
"{",
"var",
"width",
",",
"height",
";",
"if",
"(",
"parentw",
"<",
"parenth",
"*",
"aspectRatio",
")",
"{",
"width",
"=",
"parentw",
"*",
"percentSize",
";",
"height",
"=",
"width",
"/",
"aspect",
";",
"}",
"else",
"{",
"height",
"=",
"parenth",
"*",
"percentSize",
";",
"width",
"=",
"height",
"*",
"aspect",
";",
"}",
"var",
"left",
";",
"if",
"(",
"percentLeft",
"<",
"0",
")",
"{",
"left",
"=",
"parentw",
"-",
"width",
";",
"}",
"else",
"{",
"left",
"=",
"0",
";",
"}",
"left",
"+=",
"Math",
".",
"floor",
"(",
"percentLeft",
"*",
"parentw",
")",
";",
"var",
"top",
"=",
"0",
";",
"if",
"(",
"percentTop",
"<",
"0",
")",
"{",
"top",
"=",
"parenth",
"-",
"height",
";",
"}",
"else",
"{",
"top",
"=",
"0",
";",
"}",
"top",
"+=",
"Math",
".",
"floor",
"(",
"percentTop",
"*",
"parenth",
")",
";",
"return",
"{",
"left",
":",
"left",
",",
"top",
":",
"top",
",",
"width",
":",
"width",
",",
"height",
":",
"height",
"}",
";",
"}"
] | a negative percentLeft is interpreted as setting the right edge of the object that distance from the right edge of the parent. Similar for percentTop. | [
"a",
"negative",
"percentLeft",
"is",
"interpreted",
"as",
"setting",
"the",
"right",
"edge",
"of",
"the",
"object",
"that",
"distance",
"from",
"the",
"right",
"edge",
"of",
"the",
"parent",
".",
"Similar",
"for",
"percentTop",
"."
] | 5ea69776f319fab15a784f94db91a2c1f5154ef5 | https://github.com/priologic/easyrtc/blob/5ea69776f319fab15a784f94db91a2c1f5154ef5/demos/js/demo_multiparty.js#L70-L103 |
5,510 | priologic/easyrtc | demos/js/demo_multiparty.js | establishConnection | function establishConnection(position) {
function callSuccess() {
connectCount++;
if( connectCount < maxCALLERS && position > 0) {
establishConnection(position-1);
}
}
function callFailure(errorCode, errorText) {
easyrtc.showError(errorCode, errorText);
if( connectCount < maxCALLERS && position > 0) {
establishConnection(position-1);
}
}
easyrtc.call(list[position], callSuccess, callFailure);
} | javascript | function establishConnection(position) {
function callSuccess() {
connectCount++;
if( connectCount < maxCALLERS && position > 0) {
establishConnection(position-1);
}
}
function callFailure(errorCode, errorText) {
easyrtc.showError(errorCode, errorText);
if( connectCount < maxCALLERS && position > 0) {
establishConnection(position-1);
}
}
easyrtc.call(list[position], callSuccess, callFailure);
} | [
"function",
"establishConnection",
"(",
"position",
")",
"{",
"function",
"callSuccess",
"(",
")",
"{",
"connectCount",
"++",
";",
"if",
"(",
"connectCount",
"<",
"maxCALLERS",
"&&",
"position",
">",
"0",
")",
"{",
"establishConnection",
"(",
"position",
"-",
"1",
")",
";",
"}",
"}",
"function",
"callFailure",
"(",
"errorCode",
",",
"errorText",
")",
"{",
"easyrtc",
".",
"showError",
"(",
"errorCode",
",",
"errorText",
")",
";",
"if",
"(",
"connectCount",
"<",
"maxCALLERS",
"&&",
"position",
">",
"0",
")",
"{",
"establishConnection",
"(",
"position",
"-",
"1",
")",
";",
"}",
"}",
"easyrtc",
".",
"call",
"(",
"list",
"[",
"position",
"]",
",",
"callSuccess",
",",
"callFailure",
")",
";",
"}"
] | Connect in reverse order. Latter arriving people are more likely to have empty slots. | [
"Connect",
"in",
"reverse",
"order",
".",
"Latter",
"arriving",
"people",
"are",
"more",
"likely",
"to",
"have",
"empty",
"slots",
"."
] | 5ea69776f319fab15a784f94db91a2c1f5154ef5 | https://github.com/priologic/easyrtc/blob/5ea69776f319fab15a784f94db91a2c1f5154ef5/demos/js/demo_multiparty.js#L541-L556 |
5,511 | priologic/easyrtc | api/easyrtc.js | getCommonCapabilities | function getCommonCapabilities(localCapabilities, remoteCapabilities) {
var commonCapabilities = {
codecs: [],
headerExtensions: [],
fecMechanisms: []
};
var findCodecByPayloadType = function(pt, codecs) {
pt = parseInt(pt, 10);
for (var i = 0; i < codecs.length; i++) {
if (codecs[i].payloadType === pt ||
codecs[i].preferredPayloadType === pt) {
return codecs[i];
}
}
};
var rtxCapabilityMatches = function(lRtx, rRtx, lCodecs, rCodecs) {
var lCodec = findCodecByPayloadType(lRtx.parameters.apt, lCodecs);
var rCodec = findCodecByPayloadType(rRtx.parameters.apt, rCodecs);
return lCodec && rCodec &&
lCodec.name.toLowerCase() === rCodec.name.toLowerCase();
};
localCapabilities.codecs.forEach(function(lCodec) {
for (var i = 0; i < remoteCapabilities.codecs.length; i++) {
var rCodec = remoteCapabilities.codecs[i];
if (lCodec.name.toLowerCase() === rCodec.name.toLowerCase() &&
lCodec.clockRate === rCodec.clockRate) {
if (lCodec.name.toLowerCase() === 'rtx' &&
lCodec.parameters && rCodec.parameters.apt) {
// for RTX we need to find the local rtx that has a apt
// which points to the same local codec as the remote one.
if (!rtxCapabilityMatches(lCodec, rCodec,
localCapabilities.codecs, remoteCapabilities.codecs)) {
continue;
}
}
rCodec = JSON.parse(JSON.stringify(rCodec)); // deepcopy
// number of channels is the highest common number of channels
rCodec.numChannels = Math.min(lCodec.numChannels,
rCodec.numChannels);
// push rCodec so we reply with offerer payload type
commonCapabilities.codecs.push(rCodec);
// determine common feedback mechanisms
rCodec.rtcpFeedback = rCodec.rtcpFeedback.filter(function(fb) {
for (var j = 0; j < lCodec.rtcpFeedback.length; j++) {
if (lCodec.rtcpFeedback[j].type === fb.type &&
lCodec.rtcpFeedback[j].parameter === fb.parameter) {
return true;
}
}
return false;
});
// FIXME: also need to determine .parameters
// see https://github.com/openpeer/ortc/issues/569
break;
}
}
});
localCapabilities.headerExtensions.forEach(function(lHeaderExtension) {
for (var i = 0; i < remoteCapabilities.headerExtensions.length;
i++) {
var rHeaderExtension = remoteCapabilities.headerExtensions[i];
if (lHeaderExtension.uri === rHeaderExtension.uri) {
commonCapabilities.headerExtensions.push(rHeaderExtension);
break;
}
}
});
// FIXME: fecMechanisms
return commonCapabilities;
} | javascript | function getCommonCapabilities(localCapabilities, remoteCapabilities) {
var commonCapabilities = {
codecs: [],
headerExtensions: [],
fecMechanisms: []
};
var findCodecByPayloadType = function(pt, codecs) {
pt = parseInt(pt, 10);
for (var i = 0; i < codecs.length; i++) {
if (codecs[i].payloadType === pt ||
codecs[i].preferredPayloadType === pt) {
return codecs[i];
}
}
};
var rtxCapabilityMatches = function(lRtx, rRtx, lCodecs, rCodecs) {
var lCodec = findCodecByPayloadType(lRtx.parameters.apt, lCodecs);
var rCodec = findCodecByPayloadType(rRtx.parameters.apt, rCodecs);
return lCodec && rCodec &&
lCodec.name.toLowerCase() === rCodec.name.toLowerCase();
};
localCapabilities.codecs.forEach(function(lCodec) {
for (var i = 0; i < remoteCapabilities.codecs.length; i++) {
var rCodec = remoteCapabilities.codecs[i];
if (lCodec.name.toLowerCase() === rCodec.name.toLowerCase() &&
lCodec.clockRate === rCodec.clockRate) {
if (lCodec.name.toLowerCase() === 'rtx' &&
lCodec.parameters && rCodec.parameters.apt) {
// for RTX we need to find the local rtx that has a apt
// which points to the same local codec as the remote one.
if (!rtxCapabilityMatches(lCodec, rCodec,
localCapabilities.codecs, remoteCapabilities.codecs)) {
continue;
}
}
rCodec = JSON.parse(JSON.stringify(rCodec)); // deepcopy
// number of channels is the highest common number of channels
rCodec.numChannels = Math.min(lCodec.numChannels,
rCodec.numChannels);
// push rCodec so we reply with offerer payload type
commonCapabilities.codecs.push(rCodec);
// determine common feedback mechanisms
rCodec.rtcpFeedback = rCodec.rtcpFeedback.filter(function(fb) {
for (var j = 0; j < lCodec.rtcpFeedback.length; j++) {
if (lCodec.rtcpFeedback[j].type === fb.type &&
lCodec.rtcpFeedback[j].parameter === fb.parameter) {
return true;
}
}
return false;
});
// FIXME: also need to determine .parameters
// see https://github.com/openpeer/ortc/issues/569
break;
}
}
});
localCapabilities.headerExtensions.forEach(function(lHeaderExtension) {
for (var i = 0; i < remoteCapabilities.headerExtensions.length;
i++) {
var rHeaderExtension = remoteCapabilities.headerExtensions[i];
if (lHeaderExtension.uri === rHeaderExtension.uri) {
commonCapabilities.headerExtensions.push(rHeaderExtension);
break;
}
}
});
// FIXME: fecMechanisms
return commonCapabilities;
} | [
"function",
"getCommonCapabilities",
"(",
"localCapabilities",
",",
"remoteCapabilities",
")",
"{",
"var",
"commonCapabilities",
"=",
"{",
"codecs",
":",
"[",
"]",
",",
"headerExtensions",
":",
"[",
"]",
",",
"fecMechanisms",
":",
"[",
"]",
"}",
";",
"var",
"findCodecByPayloadType",
"=",
"function",
"(",
"pt",
",",
"codecs",
")",
"{",
"pt",
"=",
"parseInt",
"(",
"pt",
",",
"10",
")",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"codecs",
".",
"length",
";",
"i",
"++",
")",
"{",
"if",
"(",
"codecs",
"[",
"i",
"]",
".",
"payloadType",
"===",
"pt",
"||",
"codecs",
"[",
"i",
"]",
".",
"preferredPayloadType",
"===",
"pt",
")",
"{",
"return",
"codecs",
"[",
"i",
"]",
";",
"}",
"}",
"}",
";",
"var",
"rtxCapabilityMatches",
"=",
"function",
"(",
"lRtx",
",",
"rRtx",
",",
"lCodecs",
",",
"rCodecs",
")",
"{",
"var",
"lCodec",
"=",
"findCodecByPayloadType",
"(",
"lRtx",
".",
"parameters",
".",
"apt",
",",
"lCodecs",
")",
";",
"var",
"rCodec",
"=",
"findCodecByPayloadType",
"(",
"rRtx",
".",
"parameters",
".",
"apt",
",",
"rCodecs",
")",
";",
"return",
"lCodec",
"&&",
"rCodec",
"&&",
"lCodec",
".",
"name",
".",
"toLowerCase",
"(",
")",
"===",
"rCodec",
".",
"name",
".",
"toLowerCase",
"(",
")",
";",
"}",
";",
"localCapabilities",
".",
"codecs",
".",
"forEach",
"(",
"function",
"(",
"lCodec",
")",
"{",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"remoteCapabilities",
".",
"codecs",
".",
"length",
";",
"i",
"++",
")",
"{",
"var",
"rCodec",
"=",
"remoteCapabilities",
".",
"codecs",
"[",
"i",
"]",
";",
"if",
"(",
"lCodec",
".",
"name",
".",
"toLowerCase",
"(",
")",
"===",
"rCodec",
".",
"name",
".",
"toLowerCase",
"(",
")",
"&&",
"lCodec",
".",
"clockRate",
"===",
"rCodec",
".",
"clockRate",
")",
"{",
"if",
"(",
"lCodec",
".",
"name",
".",
"toLowerCase",
"(",
")",
"===",
"'rtx'",
"&&",
"lCodec",
".",
"parameters",
"&&",
"rCodec",
".",
"parameters",
".",
"apt",
")",
"{",
"// for RTX we need to find the local rtx that has a apt",
"// which points to the same local codec as the remote one.",
"if",
"(",
"!",
"rtxCapabilityMatches",
"(",
"lCodec",
",",
"rCodec",
",",
"localCapabilities",
".",
"codecs",
",",
"remoteCapabilities",
".",
"codecs",
")",
")",
"{",
"continue",
";",
"}",
"}",
"rCodec",
"=",
"JSON",
".",
"parse",
"(",
"JSON",
".",
"stringify",
"(",
"rCodec",
")",
")",
";",
"// deepcopy",
"// number of channels is the highest common number of channels",
"rCodec",
".",
"numChannels",
"=",
"Math",
".",
"min",
"(",
"lCodec",
".",
"numChannels",
",",
"rCodec",
".",
"numChannels",
")",
";",
"// push rCodec so we reply with offerer payload type",
"commonCapabilities",
".",
"codecs",
".",
"push",
"(",
"rCodec",
")",
";",
"// determine common feedback mechanisms",
"rCodec",
".",
"rtcpFeedback",
"=",
"rCodec",
".",
"rtcpFeedback",
".",
"filter",
"(",
"function",
"(",
"fb",
")",
"{",
"for",
"(",
"var",
"j",
"=",
"0",
";",
"j",
"<",
"lCodec",
".",
"rtcpFeedback",
".",
"length",
";",
"j",
"++",
")",
"{",
"if",
"(",
"lCodec",
".",
"rtcpFeedback",
"[",
"j",
"]",
".",
"type",
"===",
"fb",
".",
"type",
"&&",
"lCodec",
".",
"rtcpFeedback",
"[",
"j",
"]",
".",
"parameter",
"===",
"fb",
".",
"parameter",
")",
"{",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}",
")",
";",
"// FIXME: also need to determine .parameters",
"// see https://github.com/openpeer/ortc/issues/569",
"break",
";",
"}",
"}",
"}",
")",
";",
"localCapabilities",
".",
"headerExtensions",
".",
"forEach",
"(",
"function",
"(",
"lHeaderExtension",
")",
"{",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"remoteCapabilities",
".",
"headerExtensions",
".",
"length",
";",
"i",
"++",
")",
"{",
"var",
"rHeaderExtension",
"=",
"remoteCapabilities",
".",
"headerExtensions",
"[",
"i",
"]",
";",
"if",
"(",
"lHeaderExtension",
".",
"uri",
"===",
"rHeaderExtension",
".",
"uri",
")",
"{",
"commonCapabilities",
".",
"headerExtensions",
".",
"push",
"(",
"rHeaderExtension",
")",
";",
"break",
";",
"}",
"}",
"}",
")",
";",
"// FIXME: fecMechanisms",
"return",
"commonCapabilities",
";",
"}"
] | Determines the intersection of local and remote capabilities. | [
"Determines",
"the",
"intersection",
"of",
"local",
"and",
"remote",
"capabilities",
"."
] | 5ea69776f319fab15a784f94db91a2c1f5154ef5 | https://github.com/priologic/easyrtc/blob/5ea69776f319fab15a784f94db91a2c1f5154ef5/api/easyrtc.js#L182-L257 |
5,512 | priologic/easyrtc | api/easyrtc.js | isActionAllowedInSignalingState | function isActionAllowedInSignalingState(action, type, signalingState) {
return {
offer: {
setLocalDescription: ['stable', 'have-local-offer'],
setRemoteDescription: ['stable', 'have-remote-offer']
},
answer: {
setLocalDescription: ['have-remote-offer', 'have-local-pranswer'],
setRemoteDescription: ['have-local-offer', 'have-remote-pranswer']
}
}[type][action].indexOf(signalingState) !== -1;
} | javascript | function isActionAllowedInSignalingState(action, type, signalingState) {
return {
offer: {
setLocalDescription: ['stable', 'have-local-offer'],
setRemoteDescription: ['stable', 'have-remote-offer']
},
answer: {
setLocalDescription: ['have-remote-offer', 'have-local-pranswer'],
setRemoteDescription: ['have-local-offer', 'have-remote-pranswer']
}
}[type][action].indexOf(signalingState) !== -1;
} | [
"function",
"isActionAllowedInSignalingState",
"(",
"action",
",",
"type",
",",
"signalingState",
")",
"{",
"return",
"{",
"offer",
":",
"{",
"setLocalDescription",
":",
"[",
"'stable'",
",",
"'have-local-offer'",
"]",
",",
"setRemoteDescription",
":",
"[",
"'stable'",
",",
"'have-remote-offer'",
"]",
"}",
",",
"answer",
":",
"{",
"setLocalDescription",
":",
"[",
"'have-remote-offer'",
",",
"'have-local-pranswer'",
"]",
",",
"setRemoteDescription",
":",
"[",
"'have-local-offer'",
",",
"'have-remote-pranswer'",
"]",
"}",
"}",
"[",
"type",
"]",
"[",
"action",
"]",
".",
"indexOf",
"(",
"signalingState",
")",
"!==",
"-",
"1",
";",
"}"
] | is action=setLocalDescription with type allowed in signalingState | [
"is",
"action",
"=",
"setLocalDescription",
"with",
"type",
"allowed",
"in",
"signalingState"
] | 5ea69776f319fab15a784f94db91a2c1f5154ef5 | https://github.com/priologic/easyrtc/blob/5ea69776f319fab15a784f94db91a2c1f5154ef5/api/easyrtc.js#L260-L271 |
5,513 | priologic/easyrtc | api/easyrtc.js | function(window) {
var URL = window && window.URL;
if (!(typeof window === 'object' && window.HTMLMediaElement &&
'srcObject' in window.HTMLMediaElement.prototype &&
URL.createObjectURL && URL.revokeObjectURL)) {
// Only shim CreateObjectURL using srcObject if srcObject exists.
return undefined;
}
var nativeCreateObjectURL = URL.createObjectURL.bind(URL);
var nativeRevokeObjectURL = URL.revokeObjectURL.bind(URL);
var streams = new Map(), newId = 0;
URL.createObjectURL = function(stream) {
if ('getTracks' in stream) {
var url = 'polyblob:' + (++newId);
streams.set(url, stream);
utils.deprecated('URL.createObjectURL(stream)',
'elem.srcObject = stream');
return url;
}
return nativeCreateObjectURL(stream);
};
URL.revokeObjectURL = function(url) {
nativeRevokeObjectURL(url);
streams.delete(url);
};
var dsc = Object.getOwnPropertyDescriptor(window.HTMLMediaElement.prototype,
'src');
Object.defineProperty(window.HTMLMediaElement.prototype, 'src', {
get: function() {
return dsc.get.apply(this);
},
set: function(url) {
this.srcObject = streams.get(url) || null;
return dsc.set.apply(this, [url]);
}
});
var nativeSetAttribute = window.HTMLMediaElement.prototype.setAttribute;
window.HTMLMediaElement.prototype.setAttribute = function() {
if (arguments.length === 2 &&
('' + arguments[0]).toLowerCase() === 'src') {
this.srcObject = streams.get(arguments[1]) || null;
}
return nativeSetAttribute.apply(this, arguments);
};
} | javascript | function(window) {
var URL = window && window.URL;
if (!(typeof window === 'object' && window.HTMLMediaElement &&
'srcObject' in window.HTMLMediaElement.prototype &&
URL.createObjectURL && URL.revokeObjectURL)) {
// Only shim CreateObjectURL using srcObject if srcObject exists.
return undefined;
}
var nativeCreateObjectURL = URL.createObjectURL.bind(URL);
var nativeRevokeObjectURL = URL.revokeObjectURL.bind(URL);
var streams = new Map(), newId = 0;
URL.createObjectURL = function(stream) {
if ('getTracks' in stream) {
var url = 'polyblob:' + (++newId);
streams.set(url, stream);
utils.deprecated('URL.createObjectURL(stream)',
'elem.srcObject = stream');
return url;
}
return nativeCreateObjectURL(stream);
};
URL.revokeObjectURL = function(url) {
nativeRevokeObjectURL(url);
streams.delete(url);
};
var dsc = Object.getOwnPropertyDescriptor(window.HTMLMediaElement.prototype,
'src');
Object.defineProperty(window.HTMLMediaElement.prototype, 'src', {
get: function() {
return dsc.get.apply(this);
},
set: function(url) {
this.srcObject = streams.get(url) || null;
return dsc.set.apply(this, [url]);
}
});
var nativeSetAttribute = window.HTMLMediaElement.prototype.setAttribute;
window.HTMLMediaElement.prototype.setAttribute = function() {
if (arguments.length === 2 &&
('' + arguments[0]).toLowerCase() === 'src') {
this.srcObject = streams.get(arguments[1]) || null;
}
return nativeSetAttribute.apply(this, arguments);
};
} | [
"function",
"(",
"window",
")",
"{",
"var",
"URL",
"=",
"window",
"&&",
"window",
".",
"URL",
";",
"if",
"(",
"!",
"(",
"typeof",
"window",
"===",
"'object'",
"&&",
"window",
".",
"HTMLMediaElement",
"&&",
"'srcObject'",
"in",
"window",
".",
"HTMLMediaElement",
".",
"prototype",
"&&",
"URL",
".",
"createObjectURL",
"&&",
"URL",
".",
"revokeObjectURL",
")",
")",
"{",
"// Only shim CreateObjectURL using srcObject if srcObject exists.",
"return",
"undefined",
";",
"}",
"var",
"nativeCreateObjectURL",
"=",
"URL",
".",
"createObjectURL",
".",
"bind",
"(",
"URL",
")",
";",
"var",
"nativeRevokeObjectURL",
"=",
"URL",
".",
"revokeObjectURL",
".",
"bind",
"(",
"URL",
")",
";",
"var",
"streams",
"=",
"new",
"Map",
"(",
")",
",",
"newId",
"=",
"0",
";",
"URL",
".",
"createObjectURL",
"=",
"function",
"(",
"stream",
")",
"{",
"if",
"(",
"'getTracks'",
"in",
"stream",
")",
"{",
"var",
"url",
"=",
"'polyblob:'",
"+",
"(",
"++",
"newId",
")",
";",
"streams",
".",
"set",
"(",
"url",
",",
"stream",
")",
";",
"utils",
".",
"deprecated",
"(",
"'URL.createObjectURL(stream)'",
",",
"'elem.srcObject = stream'",
")",
";",
"return",
"url",
";",
"}",
"return",
"nativeCreateObjectURL",
"(",
"stream",
")",
";",
"}",
";",
"URL",
".",
"revokeObjectURL",
"=",
"function",
"(",
"url",
")",
"{",
"nativeRevokeObjectURL",
"(",
"url",
")",
";",
"streams",
".",
"delete",
"(",
"url",
")",
";",
"}",
";",
"var",
"dsc",
"=",
"Object",
".",
"getOwnPropertyDescriptor",
"(",
"window",
".",
"HTMLMediaElement",
".",
"prototype",
",",
"'src'",
")",
";",
"Object",
".",
"defineProperty",
"(",
"window",
".",
"HTMLMediaElement",
".",
"prototype",
",",
"'src'",
",",
"{",
"get",
":",
"function",
"(",
")",
"{",
"return",
"dsc",
".",
"get",
".",
"apply",
"(",
"this",
")",
";",
"}",
",",
"set",
":",
"function",
"(",
"url",
")",
"{",
"this",
".",
"srcObject",
"=",
"streams",
".",
"get",
"(",
"url",
")",
"||",
"null",
";",
"return",
"dsc",
".",
"set",
".",
"apply",
"(",
"this",
",",
"[",
"url",
"]",
")",
";",
"}",
"}",
")",
";",
"var",
"nativeSetAttribute",
"=",
"window",
".",
"HTMLMediaElement",
".",
"prototype",
".",
"setAttribute",
";",
"window",
".",
"HTMLMediaElement",
".",
"prototype",
".",
"setAttribute",
"=",
"function",
"(",
")",
"{",
"if",
"(",
"arguments",
".",
"length",
"===",
"2",
"&&",
"(",
"''",
"+",
"arguments",
"[",
"0",
"]",
")",
".",
"toLowerCase",
"(",
")",
"===",
"'src'",
")",
"{",
"this",
".",
"srcObject",
"=",
"streams",
".",
"get",
"(",
"arguments",
"[",
"1",
"]",
")",
"||",
"null",
";",
"}",
"return",
"nativeSetAttribute",
".",
"apply",
"(",
"this",
",",
"arguments",
")",
";",
"}",
";",
"}"
] | shimCreateObjectURL must be called before shimSourceObject to avoid loop. | [
"shimCreateObjectURL",
"must",
"be",
"called",
"before",
"shimSourceObject",
"to",
"avoid",
"loop",
"."
] | 5ea69776f319fab15a784f94db91a2c1f5154ef5 | https://github.com/priologic/easyrtc/blob/5ea69776f319fab15a784f94db91a2c1f5154ef5/api/easyrtc.js#L4038-L4087 |
|
5,514 | priologic/easyrtc | api/easyrtc.js | function(constraints, onSuccess, onError) {
var constraintsToFF37_ = function(c) {
if (typeof c !== 'object' || c.require) {
return c;
}
var require = [];
Object.keys(c).forEach(function(key) {
if (key === 'require' || key === 'advanced' || key === 'mediaSource') {
return;
}
var r = c[key] = (typeof c[key] === 'object') ?
c[key] : {ideal: c[key]};
if (r.min !== undefined ||
r.max !== undefined || r.exact !== undefined) {
require.push(key);
}
if (r.exact !== undefined) {
if (typeof r.exact === 'number') {
r. min = r.max = r.exact;
} else {
c[key] = r.exact;
}
delete r.exact;
}
if (r.ideal !== undefined) {
c.advanced = c.advanced || [];
var oc = {};
if (typeof r.ideal === 'number') {
oc[key] = {min: r.ideal, max: r.ideal};
} else {
oc[key] = r.ideal;
}
c.advanced.push(oc);
delete r.ideal;
if (!Object.keys(r).length) {
delete c[key];
}
}
});
if (require.length) {
c.require = require;
}
return c;
};
constraints = JSON.parse(JSON.stringify(constraints));
if (browserDetails.version < 38) {
logging('spec: ' + JSON.stringify(constraints));
if (constraints.audio) {
constraints.audio = constraintsToFF37_(constraints.audio);
}
if (constraints.video) {
constraints.video = constraintsToFF37_(constraints.video);
}
logging('ff37: ' + JSON.stringify(constraints));
}
return navigator.mozGetUserMedia(constraints, onSuccess, function(e) {
onError(shimError_(e));
});
} | javascript | function(constraints, onSuccess, onError) {
var constraintsToFF37_ = function(c) {
if (typeof c !== 'object' || c.require) {
return c;
}
var require = [];
Object.keys(c).forEach(function(key) {
if (key === 'require' || key === 'advanced' || key === 'mediaSource') {
return;
}
var r = c[key] = (typeof c[key] === 'object') ?
c[key] : {ideal: c[key]};
if (r.min !== undefined ||
r.max !== undefined || r.exact !== undefined) {
require.push(key);
}
if (r.exact !== undefined) {
if (typeof r.exact === 'number') {
r. min = r.max = r.exact;
} else {
c[key] = r.exact;
}
delete r.exact;
}
if (r.ideal !== undefined) {
c.advanced = c.advanced || [];
var oc = {};
if (typeof r.ideal === 'number') {
oc[key] = {min: r.ideal, max: r.ideal};
} else {
oc[key] = r.ideal;
}
c.advanced.push(oc);
delete r.ideal;
if (!Object.keys(r).length) {
delete c[key];
}
}
});
if (require.length) {
c.require = require;
}
return c;
};
constraints = JSON.parse(JSON.stringify(constraints));
if (browserDetails.version < 38) {
logging('spec: ' + JSON.stringify(constraints));
if (constraints.audio) {
constraints.audio = constraintsToFF37_(constraints.audio);
}
if (constraints.video) {
constraints.video = constraintsToFF37_(constraints.video);
}
logging('ff37: ' + JSON.stringify(constraints));
}
return navigator.mozGetUserMedia(constraints, onSuccess, function(e) {
onError(shimError_(e));
});
} | [
"function",
"(",
"constraints",
",",
"onSuccess",
",",
"onError",
")",
"{",
"var",
"constraintsToFF37_",
"=",
"function",
"(",
"c",
")",
"{",
"if",
"(",
"typeof",
"c",
"!==",
"'object'",
"||",
"c",
".",
"require",
")",
"{",
"return",
"c",
";",
"}",
"var",
"require",
"=",
"[",
"]",
";",
"Object",
".",
"keys",
"(",
"c",
")",
".",
"forEach",
"(",
"function",
"(",
"key",
")",
"{",
"if",
"(",
"key",
"===",
"'require'",
"||",
"key",
"===",
"'advanced'",
"||",
"key",
"===",
"'mediaSource'",
")",
"{",
"return",
";",
"}",
"var",
"r",
"=",
"c",
"[",
"key",
"]",
"=",
"(",
"typeof",
"c",
"[",
"key",
"]",
"===",
"'object'",
")",
"?",
"c",
"[",
"key",
"]",
":",
"{",
"ideal",
":",
"c",
"[",
"key",
"]",
"}",
";",
"if",
"(",
"r",
".",
"min",
"!==",
"undefined",
"||",
"r",
".",
"max",
"!==",
"undefined",
"||",
"r",
".",
"exact",
"!==",
"undefined",
")",
"{",
"require",
".",
"push",
"(",
"key",
")",
";",
"}",
"if",
"(",
"r",
".",
"exact",
"!==",
"undefined",
")",
"{",
"if",
"(",
"typeof",
"r",
".",
"exact",
"===",
"'number'",
")",
"{",
"r",
".",
"min",
"=",
"r",
".",
"max",
"=",
"r",
".",
"exact",
";",
"}",
"else",
"{",
"c",
"[",
"key",
"]",
"=",
"r",
".",
"exact",
";",
"}",
"delete",
"r",
".",
"exact",
";",
"}",
"if",
"(",
"r",
".",
"ideal",
"!==",
"undefined",
")",
"{",
"c",
".",
"advanced",
"=",
"c",
".",
"advanced",
"||",
"[",
"]",
";",
"var",
"oc",
"=",
"{",
"}",
";",
"if",
"(",
"typeof",
"r",
".",
"ideal",
"===",
"'number'",
")",
"{",
"oc",
"[",
"key",
"]",
"=",
"{",
"min",
":",
"r",
".",
"ideal",
",",
"max",
":",
"r",
".",
"ideal",
"}",
";",
"}",
"else",
"{",
"oc",
"[",
"key",
"]",
"=",
"r",
".",
"ideal",
";",
"}",
"c",
".",
"advanced",
".",
"push",
"(",
"oc",
")",
";",
"delete",
"r",
".",
"ideal",
";",
"if",
"(",
"!",
"Object",
".",
"keys",
"(",
"r",
")",
".",
"length",
")",
"{",
"delete",
"c",
"[",
"key",
"]",
";",
"}",
"}",
"}",
")",
";",
"if",
"(",
"require",
".",
"length",
")",
"{",
"c",
".",
"require",
"=",
"require",
";",
"}",
"return",
"c",
";",
"}",
";",
"constraints",
"=",
"JSON",
".",
"parse",
"(",
"JSON",
".",
"stringify",
"(",
"constraints",
")",
")",
";",
"if",
"(",
"browserDetails",
".",
"version",
"<",
"38",
")",
"{",
"logging",
"(",
"'spec: '",
"+",
"JSON",
".",
"stringify",
"(",
"constraints",
")",
")",
";",
"if",
"(",
"constraints",
".",
"audio",
")",
"{",
"constraints",
".",
"audio",
"=",
"constraintsToFF37_",
"(",
"constraints",
".",
"audio",
")",
";",
"}",
"if",
"(",
"constraints",
".",
"video",
")",
"{",
"constraints",
".",
"video",
"=",
"constraintsToFF37_",
"(",
"constraints",
".",
"video",
")",
";",
"}",
"logging",
"(",
"'ff37: '",
"+",
"JSON",
".",
"stringify",
"(",
"constraints",
")",
")",
";",
"}",
"return",
"navigator",
".",
"mozGetUserMedia",
"(",
"constraints",
",",
"onSuccess",
",",
"function",
"(",
"e",
")",
"{",
"onError",
"(",
"shimError_",
"(",
"e",
")",
")",
";",
"}",
")",
";",
"}"
] | getUserMedia constraints shim. | [
"getUserMedia",
"constraints",
"shim",
"."
] | 5ea69776f319fab15a784f94db91a2c1f5154ef5 | https://github.com/priologic/easyrtc/blob/5ea69776f319fab15a784f94db91a2c1f5154ef5/api/easyrtc.js#L4791-L4849 |
|
5,515 | priologic/easyrtc | api/easyrtc.js | extractVersion | function extractVersion(uastring, expr, pos) {
var match = uastring.match(expr);
return match && match.length >= pos && parseInt(match[pos], 10);
} | javascript | function extractVersion(uastring, expr, pos) {
var match = uastring.match(expr);
return match && match.length >= pos && parseInt(match[pos], 10);
} | [
"function",
"extractVersion",
"(",
"uastring",
",",
"expr",
",",
"pos",
")",
"{",
"var",
"match",
"=",
"uastring",
".",
"match",
"(",
"expr",
")",
";",
"return",
"match",
"&&",
"match",
".",
"length",
">=",
"pos",
"&&",
"parseInt",
"(",
"match",
"[",
"pos",
"]",
",",
"10",
")",
";",
"}"
] | Extract browser version out of the provided user agent string.
@param {!string} uastring userAgent string.
@param {!string} expr Regular expression used as match criteria.
@param {!number} pos position in the version string to be returned.
@return {!number} browser version. | [
"Extract",
"browser",
"version",
"out",
"of",
"the",
"provided",
"user",
"agent",
"string",
"."
] | 5ea69776f319fab15a784f94db91a2c1f5154ef5 | https://github.com/priologic/easyrtc/blob/5ea69776f319fab15a784f94db91a2c1f5154ef5/api/easyrtc.js#L5300-L5303 |
5,516 | priologic/easyrtc | api/easyrtc.js | function(window) {
var navigator = window && window.navigator;
// Returned result object.
var result = {};
result.browser = null;
result.version = null;
// Fail early if it's not a browser
if (typeof window === 'undefined' || !window.navigator) {
result.browser = 'Not a browser.';
return result;
}
if (navigator.mozGetUserMedia) { // Firefox.
result.browser = 'firefox';
result.version = extractVersion(navigator.userAgent,
/Firefox\/(\d+)\./, 1);
} else if (navigator.webkitGetUserMedia) {
// Chrome, Chromium, Webview, Opera.
// Version matches Chrome/WebRTC version.
result.browser = 'chrome';
result.version = extractVersion(navigator.userAgent,
/Chrom(e|ium)\/(\d+)\./, 2);
} else if (navigator.mediaDevices &&
navigator.userAgent.match(/Edge\/(\d+).(\d+)$/)) { // Edge.
result.browser = 'edge';
result.version = extractVersion(navigator.userAgent,
/Edge\/(\d+).(\d+)$/, 2);
} else if (window.RTCPeerConnection &&
navigator.userAgent.match(/AppleWebKit\/(\d+)\./)) { // Safari.
result.browser = 'safari';
result.version = extractVersion(navigator.userAgent,
/AppleWebKit\/(\d+)\./, 1);
} else { // Default fallthrough: not supported.
result.browser = 'Not a supported browser.';
return result;
}
return result;
} | javascript | function(window) {
var navigator = window && window.navigator;
// Returned result object.
var result = {};
result.browser = null;
result.version = null;
// Fail early if it's not a browser
if (typeof window === 'undefined' || !window.navigator) {
result.browser = 'Not a browser.';
return result;
}
if (navigator.mozGetUserMedia) { // Firefox.
result.browser = 'firefox';
result.version = extractVersion(navigator.userAgent,
/Firefox\/(\d+)\./, 1);
} else if (navigator.webkitGetUserMedia) {
// Chrome, Chromium, Webview, Opera.
// Version matches Chrome/WebRTC version.
result.browser = 'chrome';
result.version = extractVersion(navigator.userAgent,
/Chrom(e|ium)\/(\d+)\./, 2);
} else if (navigator.mediaDevices &&
navigator.userAgent.match(/Edge\/(\d+).(\d+)$/)) { // Edge.
result.browser = 'edge';
result.version = extractVersion(navigator.userAgent,
/Edge\/(\d+).(\d+)$/, 2);
} else if (window.RTCPeerConnection &&
navigator.userAgent.match(/AppleWebKit\/(\d+)\./)) { // Safari.
result.browser = 'safari';
result.version = extractVersion(navigator.userAgent,
/AppleWebKit\/(\d+)\./, 1);
} else { // Default fallthrough: not supported.
result.browser = 'Not a supported browser.';
return result;
}
return result;
} | [
"function",
"(",
"window",
")",
"{",
"var",
"navigator",
"=",
"window",
"&&",
"window",
".",
"navigator",
";",
"// Returned result object.",
"var",
"result",
"=",
"{",
"}",
";",
"result",
".",
"browser",
"=",
"null",
";",
"result",
".",
"version",
"=",
"null",
";",
"// Fail early if it's not a browser",
"if",
"(",
"typeof",
"window",
"===",
"'undefined'",
"||",
"!",
"window",
".",
"navigator",
")",
"{",
"result",
".",
"browser",
"=",
"'Not a browser.'",
";",
"return",
"result",
";",
"}",
"if",
"(",
"navigator",
".",
"mozGetUserMedia",
")",
"{",
"// Firefox.",
"result",
".",
"browser",
"=",
"'firefox'",
";",
"result",
".",
"version",
"=",
"extractVersion",
"(",
"navigator",
".",
"userAgent",
",",
"/",
"Firefox\\/(\\d+)\\.",
"/",
",",
"1",
")",
";",
"}",
"else",
"if",
"(",
"navigator",
".",
"webkitGetUserMedia",
")",
"{",
"// Chrome, Chromium, Webview, Opera.",
"// Version matches Chrome/WebRTC version.",
"result",
".",
"browser",
"=",
"'chrome'",
";",
"result",
".",
"version",
"=",
"extractVersion",
"(",
"navigator",
".",
"userAgent",
",",
"/",
"Chrom(e|ium)\\/(\\d+)\\.",
"/",
",",
"2",
")",
";",
"}",
"else",
"if",
"(",
"navigator",
".",
"mediaDevices",
"&&",
"navigator",
".",
"userAgent",
".",
"match",
"(",
"/",
"Edge\\/(\\d+).(\\d+)$",
"/",
")",
")",
"{",
"// Edge.",
"result",
".",
"browser",
"=",
"'edge'",
";",
"result",
".",
"version",
"=",
"extractVersion",
"(",
"navigator",
".",
"userAgent",
",",
"/",
"Edge\\/(\\d+).(\\d+)$",
"/",
",",
"2",
")",
";",
"}",
"else",
"if",
"(",
"window",
".",
"RTCPeerConnection",
"&&",
"navigator",
".",
"userAgent",
".",
"match",
"(",
"/",
"AppleWebKit\\/(\\d+)\\.",
"/",
")",
")",
"{",
"// Safari.",
"result",
".",
"browser",
"=",
"'safari'",
";",
"result",
".",
"version",
"=",
"extractVersion",
"(",
"navigator",
".",
"userAgent",
",",
"/",
"AppleWebKit\\/(\\d+)\\.",
"/",
",",
"1",
")",
";",
"}",
"else",
"{",
"// Default fallthrough: not supported.",
"result",
".",
"browser",
"=",
"'Not a supported browser.'",
";",
"return",
"result",
";",
"}",
"return",
"result",
";",
"}"
] | Browser detector.
@return {object} result containing browser and version
properties. | [
"Browser",
"detector",
"."
] | 5ea69776f319fab15a784f94db91a2c1f5154ef5 | https://github.com/priologic/easyrtc/blob/5ea69776f319fab15a784f94db91a2c1f5154ef5/api/easyrtc.js#L5417-L5457 |
|
5,517 | priologic/easyrtc | api/easyrtc.js | addStreamToPeerConnection | function addStreamToPeerConnection(stream, peerConnection) {
if( peerConnection.addStream ) {
var existingStreams = peerConnection.getLocalStreams();
if (existingStreams.indexOf(stream) === -1) {
peerConnection.addStream(stream);
}
}
else {
var existingTracks = peerConnection.getSenders();
var tracks = stream.getAudioTracks();
var i;
for( i = 0; i < tracks.length; i++ ) {
if (existingTracks.indexOf(tracks[i]) === -1) {
peerConnection.addTrack( tracks[i]);
}
}
tracks = stream.getVideoTracks();
for( i = 0; i < tracks.length; i++ ) {
if (existingTracks.indexOf(tracks[i]) === -1) {
peerConnection.addTrack( tracks[i]);
}
}
}
} | javascript | function addStreamToPeerConnection(stream, peerConnection) {
if( peerConnection.addStream ) {
var existingStreams = peerConnection.getLocalStreams();
if (existingStreams.indexOf(stream) === -1) {
peerConnection.addStream(stream);
}
}
else {
var existingTracks = peerConnection.getSenders();
var tracks = stream.getAudioTracks();
var i;
for( i = 0; i < tracks.length; i++ ) {
if (existingTracks.indexOf(tracks[i]) === -1) {
peerConnection.addTrack( tracks[i]);
}
}
tracks = stream.getVideoTracks();
for( i = 0; i < tracks.length; i++ ) {
if (existingTracks.indexOf(tracks[i]) === -1) {
peerConnection.addTrack( tracks[i]);
}
}
}
} | [
"function",
"addStreamToPeerConnection",
"(",
"stream",
",",
"peerConnection",
")",
"{",
"if",
"(",
"peerConnection",
".",
"addStream",
")",
"{",
"var",
"existingStreams",
"=",
"peerConnection",
".",
"getLocalStreams",
"(",
")",
";",
"if",
"(",
"existingStreams",
".",
"indexOf",
"(",
"stream",
")",
"===",
"-",
"1",
")",
"{",
"peerConnection",
".",
"addStream",
"(",
"stream",
")",
";",
"}",
"}",
"else",
"{",
"var",
"existingTracks",
"=",
"peerConnection",
".",
"getSenders",
"(",
")",
";",
"var",
"tracks",
"=",
"stream",
".",
"getAudioTracks",
"(",
")",
";",
"var",
"i",
";",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"tracks",
".",
"length",
";",
"i",
"++",
")",
"{",
"if",
"(",
"existingTracks",
".",
"indexOf",
"(",
"tracks",
"[",
"i",
"]",
")",
"===",
"-",
"1",
")",
"{",
"peerConnection",
".",
"addTrack",
"(",
"tracks",
"[",
"i",
"]",
")",
";",
"}",
"}",
"tracks",
"=",
"stream",
".",
"getVideoTracks",
"(",
")",
";",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"tracks",
".",
"length",
";",
"i",
"++",
")",
"{",
"if",
"(",
"existingTracks",
".",
"indexOf",
"(",
"tracks",
"[",
"i",
"]",
")",
"===",
"-",
"1",
")",
"{",
"peerConnection",
".",
"addTrack",
"(",
"tracks",
"[",
"i",
"]",
")",
";",
"}",
"}",
"}",
"}"
] | this private method handles adding a stream to a peer connection. chrome only supports adding streams, safari only supports adding tracks. | [
"this",
"private",
"method",
"handles",
"adding",
"a",
"stream",
"to",
"a",
"peer",
"connection",
".",
"chrome",
"only",
"supports",
"adding",
"streams",
"safari",
"only",
"supports",
"adding",
"tracks",
"."
] | 5ea69776f319fab15a784f94db91a2c1f5154ef5 | https://github.com/priologic/easyrtc/blob/5ea69776f319fab15a784f94db91a2c1f5154ef5/api/easyrtc.js#L5731-L5754 |
5,518 | priologic/easyrtc | api/easyrtc.js | isSocketConnected | function isSocketConnected(socket) {
return socket && (
(socket.socket && socket.socket.connected) || socket.connected
);
} | javascript | function isSocketConnected(socket) {
return socket && (
(socket.socket && socket.socket.connected) || socket.connected
);
} | [
"function",
"isSocketConnected",
"(",
"socket",
")",
"{",
"return",
"socket",
"&&",
"(",
"(",
"socket",
".",
"socket",
"&&",
"socket",
".",
"socket",
".",
"connected",
")",
"||",
"socket",
".",
"connected",
")",
";",
"}"
] | This function checks if a socket is actually connected.
@private
@param {Object} socket a socket.io socket.
@return true if the socket exists and is connected, false otherwise. | [
"This",
"function",
"checks",
"if",
"a",
"socket",
"is",
"actually",
"connected",
"."
] | 5ea69776f319fab15a784f94db91a2c1f5154ef5 | https://github.com/priologic/easyrtc/blob/5ea69776f319fab15a784f94db91a2c1f5154ef5/api/easyrtc.js#L5804-L5808 |
5,519 | priologic/easyrtc | api/easyrtc.js | event | function event(eventName, callingFunction) {
if (typeof eventName !== 'string') {
self.showError(self.errCodes.DEVELOPER_ERR, callingFunction + " called without a string as the first argument");
throw "developer error";
}
if (!allowedEvents[eventName]) {
self.showError(self.errCodes.DEVELOPER_ERR, callingFunction + " called with a bad event name = " + eventName);
throw "developer error";
}
} | javascript | function event(eventName, callingFunction) {
if (typeof eventName !== 'string') {
self.showError(self.errCodes.DEVELOPER_ERR, callingFunction + " called without a string as the first argument");
throw "developer error";
}
if (!allowedEvents[eventName]) {
self.showError(self.errCodes.DEVELOPER_ERR, callingFunction + " called with a bad event name = " + eventName);
throw "developer error";
}
} | [
"function",
"event",
"(",
"eventName",
",",
"callingFunction",
")",
"{",
"if",
"(",
"typeof",
"eventName",
"!==",
"'string'",
")",
"{",
"self",
".",
"showError",
"(",
"self",
".",
"errCodes",
".",
"DEVELOPER_ERR",
",",
"callingFunction",
"+",
"\" called without a string as the first argument\"",
")",
";",
"throw",
"\"developer error\"",
";",
"}",
"if",
"(",
"!",
"allowedEvents",
"[",
"eventName",
"]",
")",
"{",
"self",
".",
"showError",
"(",
"self",
".",
"errCodes",
".",
"DEVELOPER_ERR",
",",
"callingFunction",
"+",
"\" called with a bad event name = \"",
"+",
"eventName",
")",
";",
"throw",
"\"developer error\"",
";",
"}",
"}"
] | This function checks if an attempt was made to add an event listener or
or emit an unlisted event, since such is typically a typo.
@private
@param {String} eventName
@param {String} callingFunction the name of the calling function. | [
"This",
"function",
"checks",
"if",
"an",
"attempt",
"was",
"made",
"to",
"add",
"an",
"event",
"listener",
"or",
"or",
"emit",
"an",
"unlisted",
"event",
"since",
"such",
"is",
"typically",
"a",
"typo",
"."
] | 5ea69776f319fab15a784f94db91a2c1f5154ef5 | https://github.com/priologic/easyrtc/blob/5ea69776f319fab15a784f94db91a2c1f5154ef5/api/easyrtc.js#L5857-L5866 |
5,520 | priologic/easyrtc | api/easyrtc.js | disconnectBody | function disconnectBody() {
var key;
self.loggingOut = true;
offersPending = {};
acceptancePending = {};
self.disconnecting = true;
closedChannel = self.webSocket;
if( stillAliveTimer ) {
clearTimeout(stillAliveTimer);
stillAliveTimer = null;
}
if (self.webSocketConnected) {
if (!preallocatedSocketIo) {
self.webSocket.close();
}
self.webSocketConnected = false;
}
self.hangupAll();
if (roomOccupantListener) {
for (key in lastLoggedInList) {
if (lastLoggedInList.hasOwnProperty(key)) {
roomOccupantListener(key, {}, false);
}
}
}
lastLoggedInList = {};
self.emitEvent("roomOccupant", {});
self.roomData = {};
self.roomJoin = {};
self.loggingOut = false;
self.myEasyrtcid = null;
self.disconnecting = false;
oldConfig = {};
} | javascript | function disconnectBody() {
var key;
self.loggingOut = true;
offersPending = {};
acceptancePending = {};
self.disconnecting = true;
closedChannel = self.webSocket;
if( stillAliveTimer ) {
clearTimeout(stillAliveTimer);
stillAliveTimer = null;
}
if (self.webSocketConnected) {
if (!preallocatedSocketIo) {
self.webSocket.close();
}
self.webSocketConnected = false;
}
self.hangupAll();
if (roomOccupantListener) {
for (key in lastLoggedInList) {
if (lastLoggedInList.hasOwnProperty(key)) {
roomOccupantListener(key, {}, false);
}
}
}
lastLoggedInList = {};
self.emitEvent("roomOccupant", {});
self.roomData = {};
self.roomJoin = {};
self.loggingOut = false;
self.myEasyrtcid = null;
self.disconnecting = false;
oldConfig = {};
} | [
"function",
"disconnectBody",
"(",
")",
"{",
"var",
"key",
";",
"self",
".",
"loggingOut",
"=",
"true",
";",
"offersPending",
"=",
"{",
"}",
";",
"acceptancePending",
"=",
"{",
"}",
";",
"self",
".",
"disconnecting",
"=",
"true",
";",
"closedChannel",
"=",
"self",
".",
"webSocket",
";",
"if",
"(",
"stillAliveTimer",
")",
"{",
"clearTimeout",
"(",
"stillAliveTimer",
")",
";",
"stillAliveTimer",
"=",
"null",
";",
"}",
"if",
"(",
"self",
".",
"webSocketConnected",
")",
"{",
"if",
"(",
"!",
"preallocatedSocketIo",
")",
"{",
"self",
".",
"webSocket",
".",
"close",
"(",
")",
";",
"}",
"self",
".",
"webSocketConnected",
"=",
"false",
";",
"}",
"self",
".",
"hangupAll",
"(",
")",
";",
"if",
"(",
"roomOccupantListener",
")",
"{",
"for",
"(",
"key",
"in",
"lastLoggedInList",
")",
"{",
"if",
"(",
"lastLoggedInList",
".",
"hasOwnProperty",
"(",
"key",
")",
")",
"{",
"roomOccupantListener",
"(",
"key",
",",
"{",
"}",
",",
"false",
")",
";",
"}",
"}",
"}",
"lastLoggedInList",
"=",
"{",
"}",
";",
"self",
".",
"emitEvent",
"(",
"\"roomOccupant\"",
",",
"{",
"}",
")",
";",
"self",
".",
"roomData",
"=",
"{",
"}",
";",
"self",
".",
"roomJoin",
"=",
"{",
"}",
";",
"self",
".",
"loggingOut",
"=",
"false",
";",
"self",
".",
"myEasyrtcid",
"=",
"null",
";",
"self",
".",
"disconnecting",
"=",
"false",
";",
"oldConfig",
"=",
"{",
"}",
";",
"}"
] | easyrtc.disconnect performs a clean disconnection of the client from the server. | [
"easyrtc",
".",
"disconnect",
"performs",
"a",
"clean",
"disconnection",
"of",
"the",
"client",
"from",
"the",
"server",
"."
] | 5ea69776f319fab15a784f94db91a2c1f5154ef5 | https://github.com/priologic/easyrtc/blob/5ea69776f319fab15a784f94db91a2c1f5154ef5/api/easyrtc.js#L8392-L8427 |
5,521 | priologic/easyrtc | api/easyrtc.js | function() {
var alteredData = findDeltas(oldConfig, newConfig);
//
// send all the configuration information that changes during the session
//
if (alteredData) {
logDebug("cfg=" + JSON.stringify(alteredData.added));
if (self.webSocket) {
sendSignalling(null, "setUserCfg", {setUserCfg: alteredData.added}, null, null);
}
}
oldConfig = newConfig;
} | javascript | function() {
var alteredData = findDeltas(oldConfig, newConfig);
//
// send all the configuration information that changes during the session
//
if (alteredData) {
logDebug("cfg=" + JSON.stringify(alteredData.added));
if (self.webSocket) {
sendSignalling(null, "setUserCfg", {setUserCfg: alteredData.added}, null, null);
}
}
oldConfig = newConfig;
} | [
"function",
"(",
")",
"{",
"var",
"alteredData",
"=",
"findDeltas",
"(",
"oldConfig",
",",
"newConfig",
")",
";",
"//",
"// send all the configuration information that changes during the session",
"//",
"if",
"(",
"alteredData",
")",
"{",
"logDebug",
"(",
"\"cfg=\"",
"+",
"JSON",
".",
"stringify",
"(",
"alteredData",
".",
"added",
")",
")",
";",
"if",
"(",
"self",
".",
"webSocket",
")",
"{",
"sendSignalling",
"(",
"null",
",",
"\"setUserCfg\"",
",",
"{",
"setUserCfg",
":",
"alteredData",
".",
"added",
"}",
",",
"null",
",",
"null",
")",
";",
"}",
"}",
"oldConfig",
"=",
"newConfig",
";",
"}"
] | we need to give the getStats calls a chance to fish out the data. The longest I've seen it take is 5 milliseconds so 100 should be overkill. | [
"we",
"need",
"to",
"give",
"the",
"getStats",
"calls",
"a",
"chance",
"to",
"fish",
"out",
"the",
"data",
".",
"The",
"longest",
"I",
"ve",
"seen",
"it",
"take",
"is",
"5",
"milliseconds",
"so",
"100",
"should",
"be",
"overkill",
"."
] | 5ea69776f319fab15a784f94db91a2c1f5154ef5 | https://github.com/priologic/easyrtc/blob/5ea69776f319fab15a784f94db91a2c1f5154ef5/api/easyrtc.js#L8993-L9006 |
|
5,522 | priologic/easyrtc | api/easyrtc.js | checkIceGatheringState | function checkIceGatheringState(otherPeer) {
console.log("entered checkIceGatheringState");
if( peerConns[otherPeer] && peerConns[otherPeer].pc && peerConns[otherPeer].pc.iceGatheringState ) {
if( peerConns[otherPeer].pc.iceGatheringState === "complete" ) {
self.sendPeerMessage(otherPeer, "iceGatheringDone", {});
console.log("sent iceGatherDone message to ", otherPeer);
}
else {
setTimeout( function() {
checkIceGatheringState(otherPeer);
}, 500);
}
}
else {
console.log("checkIceGatherState: leaving");
// peer left, ignore
}
} | javascript | function checkIceGatheringState(otherPeer) {
console.log("entered checkIceGatheringState");
if( peerConns[otherPeer] && peerConns[otherPeer].pc && peerConns[otherPeer].pc.iceGatheringState ) {
if( peerConns[otherPeer].pc.iceGatheringState === "complete" ) {
self.sendPeerMessage(otherPeer, "iceGatheringDone", {});
console.log("sent iceGatherDone message to ", otherPeer);
}
else {
setTimeout( function() {
checkIceGatheringState(otherPeer);
}, 500);
}
}
else {
console.log("checkIceGatherState: leaving");
// peer left, ignore
}
} | [
"function",
"checkIceGatheringState",
"(",
"otherPeer",
")",
"{",
"console",
".",
"log",
"(",
"\"entered checkIceGatheringState\"",
")",
";",
"if",
"(",
"peerConns",
"[",
"otherPeer",
"]",
"&&",
"peerConns",
"[",
"otherPeer",
"]",
".",
"pc",
"&&",
"peerConns",
"[",
"otherPeer",
"]",
".",
"pc",
".",
"iceGatheringState",
")",
"{",
"if",
"(",
"peerConns",
"[",
"otherPeer",
"]",
".",
"pc",
".",
"iceGatheringState",
"===",
"\"complete\"",
")",
"{",
"self",
".",
"sendPeerMessage",
"(",
"otherPeer",
",",
"\"iceGatheringDone\"",
",",
"{",
"}",
")",
";",
"console",
".",
"log",
"(",
"\"sent iceGatherDone message to \"",
",",
"otherPeer",
")",
";",
"}",
"else",
"{",
"setTimeout",
"(",
"function",
"(",
")",
"{",
"checkIceGatheringState",
"(",
"otherPeer",
")",
";",
"}",
",",
"500",
")",
";",
"}",
"}",
"else",
"{",
"console",
".",
"log",
"(",
"\"checkIceGatherState: leaving\"",
")",
";",
"// peer left, ignore",
"}",
"}"
] | this is a support function for halfTrickIce support. it sends a message to the peer when ice collection has finished on this side. it is only invoked for peers that have sent us a supportHalfTrickIce message. | [
"this",
"is",
"a",
"support",
"function",
"for",
"halfTrickIce",
"support",
".",
"it",
"sends",
"a",
"message",
"to",
"the",
"peer",
"when",
"ice",
"collection",
"has",
"finished",
"on",
"this",
"side",
".",
"it",
"is",
"only",
"invoked",
"for",
"peers",
"that",
"have",
"sent",
"us",
"a",
"supportHalfTrickIce",
"message",
"."
] | 5ea69776f319fab15a784f94db91a2c1f5154ef5 | https://github.com/priologic/easyrtc/blob/5ea69776f319fab15a784f94db91a2c1f5154ef5/api/easyrtc.js#L11194-L11211 |
5,523 | priologic/easyrtc | api/easyrtc.js | validateVideoIds | function validateVideoIds(monitorVideoId, videoIds) {
var i;
// verify that video ids were not typos.
if (monitorVideoId && !document.getElementById(monitorVideoId)) {
easyrtc.showError(easyrtc.errCodes.DEVELOPER_ERR, "The monitor video id passed to easyApp was bad, saw " + monitorVideoId);
return false;
}
for (i in videoIds) {
if (!videoIds.hasOwnProperty(i)) {
continue;
}
var name = videoIds[i];
if (!document.getElementById(name)) {
easyrtc.showError(easyrtc.errCodes.DEVELOPER_ERR, "The caller video id '" + name + "' passed to easyApp was bad.");
return false;
}
}
return true;
} | javascript | function validateVideoIds(monitorVideoId, videoIds) {
var i;
// verify that video ids were not typos.
if (monitorVideoId && !document.getElementById(monitorVideoId)) {
easyrtc.showError(easyrtc.errCodes.DEVELOPER_ERR, "The monitor video id passed to easyApp was bad, saw " + monitorVideoId);
return false;
}
for (i in videoIds) {
if (!videoIds.hasOwnProperty(i)) {
continue;
}
var name = videoIds[i];
if (!document.getElementById(name)) {
easyrtc.showError(easyrtc.errCodes.DEVELOPER_ERR, "The caller video id '" + name + "' passed to easyApp was bad.");
return false;
}
}
return true;
} | [
"function",
"validateVideoIds",
"(",
"monitorVideoId",
",",
"videoIds",
")",
"{",
"var",
"i",
";",
"// verify that video ids were not typos.",
"if",
"(",
"monitorVideoId",
"&&",
"!",
"document",
".",
"getElementById",
"(",
"monitorVideoId",
")",
")",
"{",
"easyrtc",
".",
"showError",
"(",
"easyrtc",
".",
"errCodes",
".",
"DEVELOPER_ERR",
",",
"\"The monitor video id passed to easyApp was bad, saw \"",
"+",
"monitorVideoId",
")",
";",
"return",
"false",
";",
"}",
"for",
"(",
"i",
"in",
"videoIds",
")",
"{",
"if",
"(",
"!",
"videoIds",
".",
"hasOwnProperty",
"(",
"i",
")",
")",
"{",
"continue",
";",
"}",
"var",
"name",
"=",
"videoIds",
"[",
"i",
"]",
";",
"if",
"(",
"!",
"document",
".",
"getElementById",
"(",
"name",
")",
")",
"{",
"easyrtc",
".",
"showError",
"(",
"easyrtc",
".",
"errCodes",
".",
"DEVELOPER_ERR",
",",
"\"The caller video id '\"",
"+",
"name",
"+",
"\"' passed to easyApp was bad.\"",
")",
";",
"return",
"false",
";",
"}",
"}",
"return",
"true",
";",
"}"
] | Validates that the video ids correspond to dom objects.
@param {String} monitorVideoId
@param {Array} videoIds
@returns {Boolean}
@private | [
"Validates",
"that",
"the",
"video",
"ids",
"correspond",
"to",
"dom",
"objects",
"."
] | 5ea69776f319fab15a784f94db91a2c1f5154ef5 | https://github.com/priologic/easyrtc/blob/5ea69776f319fab15a784f94db91a2c1f5154ef5/api/easyrtc.js#L11375-L11394 |
5,524 | priologic/easyrtc | demos/js/demo_data_channel_messaging.js | connect | function connect() {
easyrtc.enableDebug(false);
easyrtc.enableDataChannels(true);
easyrtc.enableVideo(false);
easyrtc.enableAudio(false);
easyrtc.enableVideoReceive(false);
easyrtc.enableAudioReceive(false);
easyrtc.setDataChannelOpenListener(openListener);
easyrtc.setDataChannelCloseListener(closeListener);
easyrtc.setPeerListener(addToConversation);
easyrtc.setRoomOccupantListener(convertListToButtons);
easyrtc.connect("easyrtc.dataMessaging", loginSuccess, loginFailure);
} | javascript | function connect() {
easyrtc.enableDebug(false);
easyrtc.enableDataChannels(true);
easyrtc.enableVideo(false);
easyrtc.enableAudio(false);
easyrtc.enableVideoReceive(false);
easyrtc.enableAudioReceive(false);
easyrtc.setDataChannelOpenListener(openListener);
easyrtc.setDataChannelCloseListener(closeListener);
easyrtc.setPeerListener(addToConversation);
easyrtc.setRoomOccupantListener(convertListToButtons);
easyrtc.connect("easyrtc.dataMessaging", loginSuccess, loginFailure);
} | [
"function",
"connect",
"(",
")",
"{",
"easyrtc",
".",
"enableDebug",
"(",
"false",
")",
";",
"easyrtc",
".",
"enableDataChannels",
"(",
"true",
")",
";",
"easyrtc",
".",
"enableVideo",
"(",
"false",
")",
";",
"easyrtc",
".",
"enableAudio",
"(",
"false",
")",
";",
"easyrtc",
".",
"enableVideoReceive",
"(",
"false",
")",
";",
"easyrtc",
".",
"enableAudioReceive",
"(",
"false",
")",
";",
"easyrtc",
".",
"setDataChannelOpenListener",
"(",
"openListener",
")",
";",
"easyrtc",
".",
"setDataChannelCloseListener",
"(",
"closeListener",
")",
";",
"easyrtc",
".",
"setPeerListener",
"(",
"addToConversation",
")",
";",
"easyrtc",
".",
"setRoomOccupantListener",
"(",
"convertListToButtons",
")",
";",
"easyrtc",
".",
"connect",
"(",
"\"easyrtc.dataMessaging\"",
",",
"loginSuccess",
",",
"loginFailure",
")",
";",
"}"
] | tracks which channels are active | [
"tracks",
"which",
"channels",
"are",
"active"
] | 5ea69776f319fab15a784f94db91a2c1f5154ef5 | https://github.com/priologic/easyrtc/blob/5ea69776f319fab15a784f94db91a2c1f5154ef5/demos/js/demo_data_channel_messaging.js#L31-L43 |
5,525 | priologic/easyrtc | api/labs/easyrtc_sc_extension/background-script.js | onAccessApproved | function onAccessApproved(sourceId) {
pending = false;
// if "cancel" button is clicked
if(!sourceId || !sourceId.length) {
return port.postMessage('PermissionDeniedError');
}
// "ok" button is clicked; share "sourceId" with the
// content-script which will forward it to the webpage
port.postMessage({
chromeMediaSourceId: sourceId
});
} | javascript | function onAccessApproved(sourceId) {
pending = false;
// if "cancel" button is clicked
if(!sourceId || !sourceId.length) {
return port.postMessage('PermissionDeniedError');
}
// "ok" button is clicked; share "sourceId" with the
// content-script which will forward it to the webpage
port.postMessage({
chromeMediaSourceId: sourceId
});
} | [
"function",
"onAccessApproved",
"(",
"sourceId",
")",
"{",
"pending",
"=",
"false",
";",
"// if \"cancel\" button is clicked",
"if",
"(",
"!",
"sourceId",
"||",
"!",
"sourceId",
".",
"length",
")",
"{",
"return",
"port",
".",
"postMessage",
"(",
"'PermissionDeniedError'",
")",
";",
"}",
"// \"ok\" button is clicked; share \"sourceId\" with the",
"// content-script which will forward it to the webpage",
"port",
".",
"postMessage",
"(",
"{",
"chromeMediaSourceId",
":",
"sourceId",
"}",
")",
";",
"}"
] | on getting sourceId "sourceId" will be empty if permission is denied. | [
"on",
"getting",
"sourceId",
"sourceId",
"will",
"be",
"empty",
"if",
"permission",
"is",
"denied",
"."
] | 5ea69776f319fab15a784f94db91a2c1f5154ef5 | https://github.com/priologic/easyrtc/blob/5ea69776f319fab15a784f94db91a2c1f5154ef5/api/labs/easyrtc_sc_extension/background-script.js#L12-L26 |
5,526 | priologic/easyrtc | api/labs/easyrtc_sc_extension/background-script.js | portOnMessageHanlder | function portOnMessageHanlder(message) {
if(message === 'get-sourceId' && !pending) {
pending = true;
chrome.desktopCapture.chooseDesktopMedia(session, port.sender.tab, onAccessApproved);
}
} | javascript | function portOnMessageHanlder(message) {
if(message === 'get-sourceId' && !pending) {
pending = true;
chrome.desktopCapture.chooseDesktopMedia(session, port.sender.tab, onAccessApproved);
}
} | [
"function",
"portOnMessageHanlder",
"(",
"message",
")",
"{",
"if",
"(",
"message",
"===",
"'get-sourceId'",
"&&",
"!",
"pending",
")",
"{",
"pending",
"=",
"true",
";",
"chrome",
".",
"desktopCapture",
".",
"chooseDesktopMedia",
"(",
"session",
",",
"port",
".",
"sender",
".",
"tab",
",",
"onAccessApproved",
")",
";",
"}",
"}"
] | this one is called for each message from "content-script.js" | [
"this",
"one",
"is",
"called",
"for",
"each",
"message",
"from",
"content",
"-",
"script",
".",
"js"
] | 5ea69776f319fab15a784f94db91a2c1f5154ef5 | https://github.com/priologic/easyrtc/blob/5ea69776f319fab15a784f94db91a2c1f5154ef5/api/labs/easyrtc_sc_extension/background-script.js#L29-L34 |
5,527 | yaronn/blessed-contrib | examples/dashboard.js | fillBar | function fillBar() {
var arr = []
for (var i=0; i<servers.length; i++) {
arr.push(Math.round(Math.random()*10))
}
bar.setData({titles: servers, data: arr})
} | javascript | function fillBar() {
var arr = []
for (var i=0; i<servers.length; i++) {
arr.push(Math.round(Math.random()*10))
}
bar.setData({titles: servers, data: arr})
} | [
"function",
"fillBar",
"(",
")",
"{",
"var",
"arr",
"=",
"[",
"]",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"servers",
".",
"length",
";",
"i",
"++",
")",
"{",
"arr",
".",
"push",
"(",
"Math",
".",
"round",
"(",
"Math",
".",
"random",
"(",
")",
"*",
"10",
")",
")",
"}",
"bar",
".",
"setData",
"(",
"{",
"titles",
":",
"servers",
",",
"data",
":",
"arr",
"}",
")",
"}"
] | set dummy data on bar chart | [
"set",
"dummy",
"data",
"on",
"bar",
"chart"
] | a497e6d3a54f3947f94a22823dfed832837e2802 | https://github.com/yaronn/blessed-contrib/blob/a497e6d3a54f3947f94a22823dfed832837e2802/examples/dashboard.js#L130-L136 |
5,528 | yaronn/blessed-contrib | lib/widget/charts/line.js | getMaxY | function getMaxY() {
if (self.options.maxY) {
return self.options.maxY;
}
var max = -Infinity;
for(let i = 0; i < data.length; i++) {
if (data[i].y.length) {
var current = _.max(data[i].y, parseFloat);
if (current > max) {
max = current;
}
}
}
return max + (max - self.options.minY) * 0.2;
} | javascript | function getMaxY() {
if (self.options.maxY) {
return self.options.maxY;
}
var max = -Infinity;
for(let i = 0; i < data.length; i++) {
if (data[i].y.length) {
var current = _.max(data[i].y, parseFloat);
if (current > max) {
max = current;
}
}
}
return max + (max - self.options.minY) * 0.2;
} | [
"function",
"getMaxY",
"(",
")",
"{",
"if",
"(",
"self",
".",
"options",
".",
"maxY",
")",
"{",
"return",
"self",
".",
"options",
".",
"maxY",
";",
"}",
"var",
"max",
"=",
"-",
"Infinity",
";",
"for",
"(",
"let",
"i",
"=",
"0",
";",
"i",
"<",
"data",
".",
"length",
";",
"i",
"++",
")",
"{",
"if",
"(",
"data",
"[",
"i",
"]",
".",
"y",
".",
"length",
")",
"{",
"var",
"current",
"=",
"_",
".",
"max",
"(",
"data",
"[",
"i",
"]",
".",
"y",
",",
"parseFloat",
")",
";",
"if",
"(",
"current",
">",
"max",
")",
"{",
"max",
"=",
"current",
";",
"}",
"}",
"}",
"return",
"max",
"+",
"(",
"max",
"-",
"self",
".",
"options",
".",
"minY",
")",
"*",
"0.2",
";",
"}"
] | iteratee for lodash _.max | [
"iteratee",
"for",
"lodash",
"_",
".",
"max"
] | a497e6d3a54f3947f94a22823dfed832837e2802 | https://github.com/yaronn/blessed-contrib/blob/a497e6d3a54f3947f94a22823dfed832837e2802/lib/widget/charts/line.js#L87-L104 |
5,529 | yaronn/blessed-contrib | lib/widget/charts/line.js | drawLine | function drawLine(values, style, minY) {
style = style || {}
var color = self.options.style.line
c.strokeStyle = style.line || color
c.moveTo(0, 0)
c.beginPath();
c.lineTo(getXPixel(0), getYPixel(values[0], minY));
for(var k = 1; k < values.length; k++) {
c.lineTo(getXPixel(k), getYPixel(values[k], minY));
}
c.stroke();
} | javascript | function drawLine(values, style, minY) {
style = style || {}
var color = self.options.style.line
c.strokeStyle = style.line || color
c.moveTo(0, 0)
c.beginPath();
c.lineTo(getXPixel(0), getYPixel(values[0], minY));
for(var k = 1; k < values.length; k++) {
c.lineTo(getXPixel(k), getYPixel(values[k], minY));
}
c.stroke();
} | [
"function",
"drawLine",
"(",
"values",
",",
"style",
",",
"minY",
")",
"{",
"style",
"=",
"style",
"||",
"{",
"}",
"var",
"color",
"=",
"self",
".",
"options",
".",
"style",
".",
"line",
"c",
".",
"strokeStyle",
"=",
"style",
".",
"line",
"||",
"color",
"c",
".",
"moveTo",
"(",
"0",
",",
"0",
")",
"c",
".",
"beginPath",
"(",
")",
";",
"c",
".",
"lineTo",
"(",
"getXPixel",
"(",
"0",
")",
",",
"getYPixel",
"(",
"values",
"[",
"0",
"]",
",",
"minY",
")",
")",
";",
"for",
"(",
"var",
"k",
"=",
"1",
";",
"k",
"<",
"values",
".",
"length",
";",
"k",
"++",
")",
"{",
"c",
".",
"lineTo",
"(",
"getXPixel",
"(",
"k",
")",
",",
"getYPixel",
"(",
"values",
"[",
"k",
"]",
",",
"minY",
")",
")",
";",
"}",
"c",
".",
"stroke",
"(",
")",
";",
"}"
] | Draw the line graph | [
"Draw",
"the",
"line",
"graph"
] | a497e6d3a54f3947f94a22823dfed832837e2802 | https://github.com/yaronn/blessed-contrib/blob/a497e6d3a54f3947f94a22823dfed832837e2802/lib/widget/charts/line.js#L152-L166 |
5,530 | Streamedian/html5_rtsp_player | streamedian.min.js | function(ev) {
this.count = this.count || 0;
if (this.count >= 256 || rng_pptr >= rng_psize) {
if (window.removeEventListener)
window.removeEventListener("mousemove", onMouseMoveListener, false);
else if (window.detachEvent)
window.detachEvent("onmousemove", onMouseMoveListener);
return;
}
try {
var mouseCoordinates = ev.x + ev.y;
rng_pool[rng_pptr++] = mouseCoordinates & 255;
this.count += 1;
} catch (e) {
// Sometimes Firefox will deny permission to access event properties for some reason. Ignore.
}
} | javascript | function(ev) {
this.count = this.count || 0;
if (this.count >= 256 || rng_pptr >= rng_psize) {
if (window.removeEventListener)
window.removeEventListener("mousemove", onMouseMoveListener, false);
else if (window.detachEvent)
window.detachEvent("onmousemove", onMouseMoveListener);
return;
}
try {
var mouseCoordinates = ev.x + ev.y;
rng_pool[rng_pptr++] = mouseCoordinates & 255;
this.count += 1;
} catch (e) {
// Sometimes Firefox will deny permission to access event properties for some reason. Ignore.
}
} | [
"function",
"(",
"ev",
")",
"{",
"this",
".",
"count",
"=",
"this",
".",
"count",
"||",
"0",
";",
"if",
"(",
"this",
".",
"count",
">=",
"256",
"||",
"rng_pptr",
">=",
"rng_psize",
")",
"{",
"if",
"(",
"window",
".",
"removeEventListener",
")",
"window",
".",
"removeEventListener",
"(",
"\"mousemove\"",
",",
"onMouseMoveListener",
",",
"false",
")",
";",
"else",
"if",
"(",
"window",
".",
"detachEvent",
")",
"window",
".",
"detachEvent",
"(",
"\"onmousemove\"",
",",
"onMouseMoveListener",
")",
";",
"return",
";",
"}",
"try",
"{",
"var",
"mouseCoordinates",
"=",
"ev",
".",
"x",
"+",
"ev",
".",
"y",
";",
"rng_pool",
"[",
"rng_pptr",
"++",
"]",
"=",
"mouseCoordinates",
"&",
"255",
";",
"this",
".",
"count",
"+=",
"1",
";",
"}",
"catch",
"(",
"e",
")",
"{",
"// Sometimes Firefox will deny permission to access event properties for some reason. Ignore.",
"}",
"}"
] | Use mouse events for entropy, if we do not have enough entropy by the time we need it, entropy will be generated by Math.random. | [
"Use",
"mouse",
"events",
"for",
"entropy",
"if",
"we",
"do",
"not",
"have",
"enough",
"entropy",
"by",
"the",
"time",
"we",
"need",
"it",
"entropy",
"will",
"be",
"generated",
"by",
"Math",
".",
"random",
"."
] | 4d04d4a075992cc5ef828ed644d9a3e4a00606d7 | https://github.com/Streamedian/html5_rtsp_player/blob/4d04d4a075992cc5ef828ed644d9a3e4a00606d7/streamedian.min.js#L5133-L5149 |
|
5,531 | CJex/regulex | src/Kit.js | hashUnique | function hashUnique(a) {
var table={},i=0,j=0,l=a.length,x;
for (;i<l;i++) {
x=a[i];
if (table.hasOwnProperty(x)) continue;
table[x]=1;
a[j++]=x;
}
a.length=j;
return a;
} | javascript | function hashUnique(a) {
var table={},i=0,j=0,l=a.length,x;
for (;i<l;i++) {
x=a[i];
if (table.hasOwnProperty(x)) continue;
table[x]=1;
a[j++]=x;
}
a.length=j;
return a;
} | [
"function",
"hashUnique",
"(",
"a",
")",
"{",
"var",
"table",
"=",
"{",
"}",
",",
"i",
"=",
"0",
",",
"j",
"=",
"0",
",",
"l",
"=",
"a",
".",
"length",
",",
"x",
";",
"for",
"(",
";",
"i",
"<",
"l",
";",
"i",
"++",
")",
"{",
"x",
"=",
"a",
"[",
"i",
"]",
";",
"if",
"(",
"table",
".",
"hasOwnProperty",
"(",
"x",
")",
")",
"continue",
";",
"table",
"[",
"x",
"]",
"=",
"1",
";",
"a",
"[",
"j",
"++",
"]",
"=",
"x",
";",
"}",
"a",
".",
"length",
"=",
"j",
";",
"return",
"a",
";",
"}"
] | Unique by toString.
This function will corrupt the original array but preserve the original order. | [
"Unique",
"by",
"toString",
".",
"This",
"function",
"will",
"corrupt",
"the",
"original",
"array",
"but",
"preserve",
"the",
"original",
"order",
"."
] | 398d0b6d8b30a4d47999e4400c935ffddf30a4f1 | https://github.com/CJex/regulex/blob/398d0b6d8b30a4d47999e4400c935ffddf30a4f1/src/Kit.js#L112-L122 |
5,532 | CJex/regulex | src/Kit.js | parseCharset | function parseCharset(charset /*:String*/) {
charset=charset.split('');
var chars=[],ranges=[],
exclude = charset[0]==='^' && charset.length > 1 && charset.shift();
charset.forEach(function (c) {
if (chars[0]=='-' && chars.length>1) {//chars=['-','a'],c=='z'
if (chars[1] > c ) // z-a is invalid
throw new Error('Charset range out of order:'+chars[1]+'-'+c+'!');
ranges.push(chars[1]+c);
chars.splice(0,2);
} else chars.unshift(c);
});
ranges=ranges.concat(chars);
//convert exclude to include
return exclude?negate(ranges):classify(ranges).ranges;
} | javascript | function parseCharset(charset /*:String*/) {
charset=charset.split('');
var chars=[],ranges=[],
exclude = charset[0]==='^' && charset.length > 1 && charset.shift();
charset.forEach(function (c) {
if (chars[0]=='-' && chars.length>1) {//chars=['-','a'],c=='z'
if (chars[1] > c ) // z-a is invalid
throw new Error('Charset range out of order:'+chars[1]+'-'+c+'!');
ranges.push(chars[1]+c);
chars.splice(0,2);
} else chars.unshift(c);
});
ranges=ranges.concat(chars);
//convert exclude to include
return exclude?negate(ranges):classify(ranges).ranges;
} | [
"function",
"parseCharset",
"(",
"charset",
"/*:String*/",
")",
"{",
"charset",
"=",
"charset",
".",
"split",
"(",
"''",
")",
";",
"var",
"chars",
"=",
"[",
"]",
",",
"ranges",
"=",
"[",
"]",
",",
"exclude",
"=",
"charset",
"[",
"0",
"]",
"===",
"'^'",
"&&",
"charset",
".",
"length",
">",
"1",
"&&",
"charset",
".",
"shift",
"(",
")",
";",
"charset",
".",
"forEach",
"(",
"function",
"(",
"c",
")",
"{",
"if",
"(",
"chars",
"[",
"0",
"]",
"==",
"'-'",
"&&",
"chars",
".",
"length",
">",
"1",
")",
"{",
"//chars=['-','a'],c=='z'",
"if",
"(",
"chars",
"[",
"1",
"]",
">",
"c",
")",
"// z-a is invalid",
"throw",
"new",
"Error",
"(",
"'Charset range out of order:'",
"+",
"chars",
"[",
"1",
"]",
"+",
"'-'",
"+",
"c",
"+",
"'!'",
")",
";",
"ranges",
".",
"push",
"(",
"chars",
"[",
"1",
"]",
"+",
"c",
")",
";",
"chars",
".",
"splice",
"(",
"0",
",",
"2",
")",
";",
"}",
"else",
"chars",
".",
"unshift",
"(",
"c",
")",
";",
"}",
")",
";",
"ranges",
"=",
"ranges",
".",
"concat",
"(",
"chars",
")",
";",
"//convert exclude to include",
"return",
"exclude",
"?",
"negate",
"(",
"ranges",
")",
":",
"classify",
"(",
"ranges",
")",
".",
"ranges",
";",
"}"
] | Parse simple regex style charset string like '^a-bcdf' to disjoint ranges.
Character classes like "\w\s" are not supported!
@param {String} charset Valid regex charset [^a-z0-9_] input as "^a-z0-9_".
@return {[Range]} return sorted disjoint ranges | [
"Parse",
"simple",
"regex",
"style",
"charset",
"string",
"like",
"^a",
"-",
"bcdf",
"to",
"disjoint",
"ranges",
".",
"Character",
"classes",
"like",
"\\",
"w",
"\\",
"s",
"are",
"not",
"supported!"
] | 398d0b6d8b30a4d47999e4400c935ffddf30a4f1 | https://github.com/CJex/regulex/blob/398d0b6d8b30a4d47999e4400c935ffddf30a4f1/src/Kit.js#L288-L303 |
5,533 | CJex/regulex | src/Kit.js | toPrint | function toPrint(s,isRaw) {
var ctrl=/[\x00-\x1F\x7F-\x9F]/,unicode=/[\u009F-\uFFFF]/;
s=s.split('').map(function (c) {
if (!isRaw && printEscapeMap.hasOwnProperty(c)) return printEscapeMap[c];
else if (unicode.test(c)) return '\\u'+('00'+ord(c).toString(16).toUpperCase()).slice(-4);
else if (ctrl.test(c)) return '\\x'+("0"+ord(c).toString(16).toUpperCase()).slice(-2);
return c;
}).join('');
return s;
} | javascript | function toPrint(s,isRaw) {
var ctrl=/[\x00-\x1F\x7F-\x9F]/,unicode=/[\u009F-\uFFFF]/;
s=s.split('').map(function (c) {
if (!isRaw && printEscapeMap.hasOwnProperty(c)) return printEscapeMap[c];
else if (unicode.test(c)) return '\\u'+('00'+ord(c).toString(16).toUpperCase()).slice(-4);
else if (ctrl.test(c)) return '\\x'+("0"+ord(c).toString(16).toUpperCase()).slice(-2);
return c;
}).join('');
return s;
} | [
"function",
"toPrint",
"(",
"s",
",",
"isRaw",
")",
"{",
"var",
"ctrl",
"=",
"/",
"[\\x00-\\x1F\\x7F-\\x9F]",
"/",
",",
"unicode",
"=",
"/",
"[\\u009F-\\uFFFF]",
"/",
";",
"s",
"=",
"s",
".",
"split",
"(",
"''",
")",
".",
"map",
"(",
"function",
"(",
"c",
")",
"{",
"if",
"(",
"!",
"isRaw",
"&&",
"printEscapeMap",
".",
"hasOwnProperty",
"(",
"c",
")",
")",
"return",
"printEscapeMap",
"[",
"c",
"]",
";",
"else",
"if",
"(",
"unicode",
".",
"test",
"(",
"c",
")",
")",
"return",
"'\\\\u'",
"+",
"(",
"'00'",
"+",
"ord",
"(",
"c",
")",
".",
"toString",
"(",
"16",
")",
".",
"toUpperCase",
"(",
")",
")",
".",
"slice",
"(",
"-",
"4",
")",
";",
"else",
"if",
"(",
"ctrl",
".",
"test",
"(",
"c",
")",
")",
"return",
"'\\\\x'",
"+",
"(",
"\"0\"",
"+",
"ord",
"(",
"c",
")",
".",
"toString",
"(",
"16",
")",
".",
"toUpperCase",
"(",
")",
")",
".",
"slice",
"(",
"-",
"2",
")",
";",
"return",
"c",
";",
"}",
")",
".",
"join",
"(",
"''",
")",
";",
"return",
"s",
";",
"}"
] | Convert string to printable,replace all control chars and unicode to hex escape | [
"Convert",
"string",
"to",
"printable",
"replace",
"all",
"control",
"chars",
"and",
"unicode",
"to",
"hex",
"escape"
] | 398d0b6d8b30a4d47999e4400c935ffddf30a4f1 | https://github.com/CJex/regulex/blob/398d0b6d8b30a4d47999e4400c935ffddf30a4f1/src/Kit.js#L343-L352 |
5,534 | CJex/regulex | src/parse.js | endChoice | function endChoice(stack) {
if (stack._parentChoice) {
var choice=stack._parentChoice;
delete stack._parentChoice;
delete stack._parentGroup;
delete stack.groupCounter;
var parentStack=choice._parentStack;
delete choice._parentStack;
return parentStack;
}
return stack;
} | javascript | function endChoice(stack) {
if (stack._parentChoice) {
var choice=stack._parentChoice;
delete stack._parentChoice;
delete stack._parentGroup;
delete stack.groupCounter;
var parentStack=choice._parentStack;
delete choice._parentStack;
return parentStack;
}
return stack;
} | [
"function",
"endChoice",
"(",
"stack",
")",
"{",
"if",
"(",
"stack",
".",
"_parentChoice",
")",
"{",
"var",
"choice",
"=",
"stack",
".",
"_parentChoice",
";",
"delete",
"stack",
".",
"_parentChoice",
";",
"delete",
"stack",
".",
"_parentGroup",
";",
"delete",
"stack",
".",
"groupCounter",
";",
"var",
"parentStack",
"=",
"choice",
".",
"_parentStack",
";",
"delete",
"choice",
".",
"_parentStack",
";",
"return",
"parentStack",
";",
"}",
"return",
"stack",
";",
"}"
] | if current stack is a choice's branch,return the original parent stack | [
"if",
"current",
"stack",
"is",
"a",
"choice",
"s",
"branch",
"return",
"the",
"original",
"parent",
"stack"
] | 398d0b6d8b30a4d47999e4400c935ffddf30a4f1 | https://github.com/CJex/regulex/blob/398d0b6d8b30a4d47999e4400c935ffddf30a4f1/src/parse.js#L633-L645 |
5,535 | CJex/regulex | src/NFA.js | structure | function structure(a) {
a.accepts=a.accepts.split(',');
var ts=a.trans,
i=ts.length,t,s,from,to;
while (i--) {
t=ts[i];
s=t[0].split('>');
from=s[0].split(',');
to=s[1].split(',');
ts[i]={from:from,to:to,charset:t[1],action:t[2],assert:t[3]};
}
a.compact=false;
return a;
} | javascript | function structure(a) {
a.accepts=a.accepts.split(',');
var ts=a.trans,
i=ts.length,t,s,from,to;
while (i--) {
t=ts[i];
s=t[0].split('>');
from=s[0].split(',');
to=s[1].split(',');
ts[i]={from:from,to:to,charset:t[1],action:t[2],assert:t[3]};
}
a.compact=false;
return a;
} | [
"function",
"structure",
"(",
"a",
")",
"{",
"a",
".",
"accepts",
"=",
"a",
".",
"accepts",
".",
"split",
"(",
"','",
")",
";",
"var",
"ts",
"=",
"a",
".",
"trans",
",",
"i",
"=",
"ts",
".",
"length",
",",
"t",
",",
"s",
",",
"from",
",",
"to",
";",
"while",
"(",
"i",
"--",
")",
"{",
"t",
"=",
"ts",
"[",
"i",
"]",
";",
"s",
"=",
"t",
"[",
"0",
"]",
".",
"split",
"(",
"'>'",
")",
";",
"from",
"=",
"s",
"[",
"0",
"]",
".",
"split",
"(",
"','",
")",
";",
"to",
"=",
"s",
"[",
"1",
"]",
".",
"split",
"(",
"','",
")",
";",
"ts",
"[",
"i",
"]",
"=",
"{",
"from",
":",
"from",
",",
"to",
":",
"to",
",",
"charset",
":",
"t",
"[",
"1",
"]",
",",
"action",
":",
"t",
"[",
"2",
"]",
",",
"assert",
":",
"t",
"[",
"3",
"]",
"}",
";",
"}",
"a",
".",
"compact",
"=",
"false",
";",
"return",
"a",
";",
"}"
] | Convert CompactNFAConfig to NFAConfig
@param {CompactNFAConfig} a
type CompactNFAConfig={compact:true,accepts:CompactStateSet,trans:[CompactTransition]}
type CompactStateSet = StateSet.join(",")
type CompactTransition = [CompactStateMap,Charset,Action,Assert]
type CompactStateMap = FromStateSet.join(",")+">"+ToStateSet.join(",") | [
"Convert",
"CompactNFAConfig",
"to",
"NFAConfig"
] | 398d0b6d8b30a4d47999e4400c935ffddf30a4f1 | https://github.com/CJex/regulex/blob/398d0b6d8b30a4d47999e4400c935ffddf30a4f1/src/NFA.js#L289-L302 |
5,536 | petkaantonov/bluebird | src/util.js | function(Child, Parent) {
var hasProp = {}.hasOwnProperty;
function T() {
this.constructor = Child;
this.constructor$ = Parent;
for (var propertyName in Parent.prototype) {
if (hasProp.call(Parent.prototype, propertyName) &&
propertyName.charAt(propertyName.length-1) !== "$"
) {
this[propertyName + "$"] = Parent.prototype[propertyName];
}
}
}
T.prototype = Parent.prototype;
Child.prototype = new T();
return Child.prototype;
} | javascript | function(Child, Parent) {
var hasProp = {}.hasOwnProperty;
function T() {
this.constructor = Child;
this.constructor$ = Parent;
for (var propertyName in Parent.prototype) {
if (hasProp.call(Parent.prototype, propertyName) &&
propertyName.charAt(propertyName.length-1) !== "$"
) {
this[propertyName + "$"] = Parent.prototype[propertyName];
}
}
}
T.prototype = Parent.prototype;
Child.prototype = new T();
return Child.prototype;
} | [
"function",
"(",
"Child",
",",
"Parent",
")",
"{",
"var",
"hasProp",
"=",
"{",
"}",
".",
"hasOwnProperty",
";",
"function",
"T",
"(",
")",
"{",
"this",
".",
"constructor",
"=",
"Child",
";",
"this",
".",
"constructor$",
"=",
"Parent",
";",
"for",
"(",
"var",
"propertyName",
"in",
"Parent",
".",
"prototype",
")",
"{",
"if",
"(",
"hasProp",
".",
"call",
"(",
"Parent",
".",
"prototype",
",",
"propertyName",
")",
"&&",
"propertyName",
".",
"charAt",
"(",
"propertyName",
".",
"length",
"-",
"1",
")",
"!==",
"\"$\"",
")",
"{",
"this",
"[",
"propertyName",
"+",
"\"$\"",
"]",
"=",
"Parent",
".",
"prototype",
"[",
"propertyName",
"]",
";",
"}",
"}",
"}",
"T",
".",
"prototype",
"=",
"Parent",
".",
"prototype",
";",
"Child",
".",
"prototype",
"=",
"new",
"T",
"(",
")",
";",
"return",
"Child",
".",
"prototype",
";",
"}"
] | Un-magical enough that using this doesn't prevent extending classes from outside using any convention | [
"Un",
"-",
"magical",
"enough",
"that",
"using",
"this",
"doesn",
"t",
"prevent",
"extending",
"classes",
"from",
"outside",
"using",
"any",
"convention"
] | 17f69f3b0fa89a0b7a5cfb9a6546d1180a3610e0 | https://github.com/petkaantonov/bluebird/blob/17f69f3b0fa89a0b7a5cfb9a6546d1180a3610e0/src/util.js#L34-L51 |
|
5,537 | petkaantonov/bluebird | src/async.js | AsyncInvokeLater | function AsyncInvokeLater(fn, receiver, arg) {
ASSERT(arguments.length === 3);
this._lateQueue.push(fn, receiver, arg);
this._queueTick();
} | javascript | function AsyncInvokeLater(fn, receiver, arg) {
ASSERT(arguments.length === 3);
this._lateQueue.push(fn, receiver, arg);
this._queueTick();
} | [
"function",
"AsyncInvokeLater",
"(",
"fn",
",",
"receiver",
",",
"arg",
")",
"{",
"ASSERT",
"(",
"arguments",
".",
"length",
"===",
"3",
")",
";",
"this",
".",
"_lateQueue",
".",
"push",
"(",
"fn",
",",
"receiver",
",",
"arg",
")",
";",
"this",
".",
"_queueTick",
"(",
")",
";",
"}"
] | When the fn absolutely needs to be called after the queue has been completely flushed | [
"When",
"the",
"fn",
"absolutely",
"needs",
"to",
"be",
"called",
"after",
"the",
"queue",
"has",
"been",
"completely",
"flushed"
] | 17f69f3b0fa89a0b7a5cfb9a6546d1180a3610e0 | https://github.com/petkaantonov/bluebird/blob/17f69f3b0fa89a0b7a5cfb9a6546d1180a3610e0/src/async.js#L80-L84 |
5,538 | petkaantonov/bluebird | src/async.js | _drainQueueStep | function _drainQueueStep(queue) {
var fn = queue.shift();
if (typeof fn !== "function") {
fn._settlePromises();
} else {
var receiver = queue.shift();
var arg = queue.shift();
fn.call(receiver, arg);
}
} | javascript | function _drainQueueStep(queue) {
var fn = queue.shift();
if (typeof fn !== "function") {
fn._settlePromises();
} else {
var receiver = queue.shift();
var arg = queue.shift();
fn.call(receiver, arg);
}
} | [
"function",
"_drainQueueStep",
"(",
"queue",
")",
"{",
"var",
"fn",
"=",
"queue",
".",
"shift",
"(",
")",
";",
"if",
"(",
"typeof",
"fn",
"!==",
"\"function\"",
")",
"{",
"fn",
".",
"_settlePromises",
"(",
")",
";",
"}",
"else",
"{",
"var",
"receiver",
"=",
"queue",
".",
"shift",
"(",
")",
";",
"var",
"arg",
"=",
"queue",
".",
"shift",
"(",
")",
";",
"fn",
".",
"call",
"(",
"receiver",
",",
"arg",
")",
";",
"}",
"}"
] | Shift the queue in a separate function to allow garbage collection after each step | [
"Shift",
"the",
"queue",
"in",
"a",
"separate",
"function",
"to",
"allow",
"garbage",
"collection",
"after",
"each",
"step"
] | 17f69f3b0fa89a0b7a5cfb9a6546d1180a3610e0 | https://github.com/petkaantonov/bluebird/blob/17f69f3b0fa89a0b7a5cfb9a6546d1180a3610e0/src/async.js#L143-L152 |
5,539 | petkaantonov/bluebird | benchmark/lib/timers-ctx.js | insert | function insert(item, msecs) {
item._idleStart = Timer.now();
item._idleTimeout = msecs;
if (msecs < 0) return;
var list;
if (lists[msecs]) {
list = lists[msecs];
} else {
list = new Timer();
list.start(msecs, 0);
L.init(list);
lists[msecs] = list;
list.msecs = msecs;
list[kOnTimeout] = listOnTimeout;
}
L.append(list, item);
assert(!L.isEmpty(list)); // list is not empty
} | javascript | function insert(item, msecs) {
item._idleStart = Timer.now();
item._idleTimeout = msecs;
if (msecs < 0) return;
var list;
if (lists[msecs]) {
list = lists[msecs];
} else {
list = new Timer();
list.start(msecs, 0);
L.init(list);
lists[msecs] = list;
list.msecs = msecs;
list[kOnTimeout] = listOnTimeout;
}
L.append(list, item);
assert(!L.isEmpty(list)); // list is not empty
} | [
"function",
"insert",
"(",
"item",
",",
"msecs",
")",
"{",
"item",
".",
"_idleStart",
"=",
"Timer",
".",
"now",
"(",
")",
";",
"item",
".",
"_idleTimeout",
"=",
"msecs",
";",
"if",
"(",
"msecs",
"<",
"0",
")",
"return",
";",
"var",
"list",
";",
"if",
"(",
"lists",
"[",
"msecs",
"]",
")",
"{",
"list",
"=",
"lists",
"[",
"msecs",
"]",
";",
"}",
"else",
"{",
"list",
"=",
"new",
"Timer",
"(",
")",
";",
"list",
".",
"start",
"(",
"msecs",
",",
"0",
")",
";",
"L",
".",
"init",
"(",
"list",
")",
";",
"lists",
"[",
"msecs",
"]",
"=",
"list",
";",
"list",
".",
"msecs",
"=",
"msecs",
";",
"list",
"[",
"kOnTimeout",
"]",
"=",
"listOnTimeout",
";",
"}",
"L",
".",
"append",
"(",
"list",
",",
"item",
")",
";",
"assert",
"(",
"!",
"L",
".",
"isEmpty",
"(",
"list",
")",
")",
";",
"// list is not empty",
"}"
] | the main function - creates lists on demand and the watchers associated with them. | [
"the",
"main",
"function",
"-",
"creates",
"lists",
"on",
"demand",
"and",
"the",
"watchers",
"associated",
"with",
"them",
"."
] | 17f69f3b0fa89a0b7a5cfb9a6546d1180a3610e0 | https://github.com/petkaantonov/bluebird/blob/17f69f3b0fa89a0b7a5cfb9a6546d1180a3610e0/benchmark/lib/timers-ctx.js#L50-L73 |
5,540 | petkaantonov/bluebird | benchmark/lib/fakesP-ctx.js | dummyP | function dummyP(n) {
return function lifted() {
var deferred = Promise.pending();
timers.setTimeout(nodeback, deferred, global.asyncTime || 100);
return deferred.promise;
}
} | javascript | function dummyP(n) {
return function lifted() {
var deferred = Promise.pending();
timers.setTimeout(nodeback, deferred, global.asyncTime || 100);
return deferred.promise;
}
} | [
"function",
"dummyP",
"(",
"n",
")",
"{",
"return",
"function",
"lifted",
"(",
")",
"{",
"var",
"deferred",
"=",
"Promise",
".",
"pending",
"(",
")",
";",
"timers",
".",
"setTimeout",
"(",
"nodeback",
",",
"deferred",
",",
"global",
".",
"asyncTime",
"||",
"100",
")",
";",
"return",
"deferred",
".",
"promise",
";",
"}",
"}"
] | A function taking n values or promises and returning a promise | [
"A",
"function",
"taking",
"n",
"values",
"or",
"promises",
"and",
"returning",
"a",
"promise"
] | 17f69f3b0fa89a0b7a5cfb9a6546d1180a3610e0 | https://github.com/petkaantonov/bluebird/blob/17f69f3b0fa89a0b7a5cfb9a6546d1180a3610e0/benchmark/lib/fakesP-ctx.js#L65-L71 |
5,541 | petkaantonov/bluebird | tools/ast_passes.js | function( src, fileName ) {
var ast = parse(src, fileName);
walk.simple(ast, {
ExpressionStatement: function( node ) {
if( node.expression.type !== 'CallExpression' ) {
return;
}
var start = node.start;
var end = node.end;
node = node.expression;
var callee = node.callee;
if( callee.name === "CONSTANT" &&
callee.type === "Identifier" ) {
if( node.arguments.length !== 2 ) {
throw new Error( "Exactly 2 arguments must be passed to CONSTANT\n" +
src.substring(start, end)
);
}
if( node.arguments[0].type !== "Identifier" ) {
throw new Error( "Can only define identifier as a constant\n" +
src.substring(start, end)
);
}
var args = node.arguments;
var name = args[0];
var nameStr = name.name;
var expr = args[1];
var e = eval;
constants[nameStr] = {
identifier: name,
value: e(nodeToString(expr))
};
walk.simple( expr, {
Identifier: function( node ) {
ignore.push(node);
}
});
global[nameStr] = constants[nameStr].value;
}
}
});
} | javascript | function( src, fileName ) {
var ast = parse(src, fileName);
walk.simple(ast, {
ExpressionStatement: function( node ) {
if( node.expression.type !== 'CallExpression' ) {
return;
}
var start = node.start;
var end = node.end;
node = node.expression;
var callee = node.callee;
if( callee.name === "CONSTANT" &&
callee.type === "Identifier" ) {
if( node.arguments.length !== 2 ) {
throw new Error( "Exactly 2 arguments must be passed to CONSTANT\n" +
src.substring(start, end)
);
}
if( node.arguments[0].type !== "Identifier" ) {
throw new Error( "Can only define identifier as a constant\n" +
src.substring(start, end)
);
}
var args = node.arguments;
var name = args[0];
var nameStr = name.name;
var expr = args[1];
var e = eval;
constants[nameStr] = {
identifier: name,
value: e(nodeToString(expr))
};
walk.simple( expr, {
Identifier: function( node ) {
ignore.push(node);
}
});
global[nameStr] = constants[nameStr].value;
}
}
});
} | [
"function",
"(",
"src",
",",
"fileName",
")",
"{",
"var",
"ast",
"=",
"parse",
"(",
"src",
",",
"fileName",
")",
";",
"walk",
".",
"simple",
"(",
"ast",
",",
"{",
"ExpressionStatement",
":",
"function",
"(",
"node",
")",
"{",
"if",
"(",
"node",
".",
"expression",
".",
"type",
"!==",
"'CallExpression'",
")",
"{",
"return",
";",
"}",
"var",
"start",
"=",
"node",
".",
"start",
";",
"var",
"end",
"=",
"node",
".",
"end",
";",
"node",
"=",
"node",
".",
"expression",
";",
"var",
"callee",
"=",
"node",
".",
"callee",
";",
"if",
"(",
"callee",
".",
"name",
"===",
"\"CONSTANT\"",
"&&",
"callee",
".",
"type",
"===",
"\"Identifier\"",
")",
"{",
"if",
"(",
"node",
".",
"arguments",
".",
"length",
"!==",
"2",
")",
"{",
"throw",
"new",
"Error",
"(",
"\"Exactly 2 arguments must be passed to CONSTANT\\n\"",
"+",
"src",
".",
"substring",
"(",
"start",
",",
"end",
")",
")",
";",
"}",
"if",
"(",
"node",
".",
"arguments",
"[",
"0",
"]",
".",
"type",
"!==",
"\"Identifier\"",
")",
"{",
"throw",
"new",
"Error",
"(",
"\"Can only define identifier as a constant\\n\"",
"+",
"src",
".",
"substring",
"(",
"start",
",",
"end",
")",
")",
";",
"}",
"var",
"args",
"=",
"node",
".",
"arguments",
";",
"var",
"name",
"=",
"args",
"[",
"0",
"]",
";",
"var",
"nameStr",
"=",
"name",
".",
"name",
";",
"var",
"expr",
"=",
"args",
"[",
"1",
"]",
";",
"var",
"e",
"=",
"eval",
";",
"constants",
"[",
"nameStr",
"]",
"=",
"{",
"identifier",
":",
"name",
",",
"value",
":",
"e",
"(",
"nodeToString",
"(",
"expr",
")",
")",
"}",
";",
"walk",
".",
"simple",
"(",
"expr",
",",
"{",
"Identifier",
":",
"function",
"(",
"node",
")",
"{",
"ignore",
".",
"push",
"(",
"node",
")",
";",
"}",
"}",
")",
";",
"global",
"[",
"nameStr",
"]",
"=",
"constants",
"[",
"nameStr",
"]",
".",
"value",
";",
"}",
"}",
"}",
")",
";",
"}"
] | Parse constants in from constants.js | [
"Parse",
"constants",
"in",
"from",
"constants",
".",
"js"
] | 17f69f3b0fa89a0b7a5cfb9a6546d1180a3610e0 | https://github.com/petkaantonov/bluebird/blob/17f69f3b0fa89a0b7a5cfb9a6546d1180a3610e0/tools/ast_passes.js#L492-L539 |
|
5,542 | petkaantonov/bluebird | tools/ast_passes.js | function( src, fileName ) {
var results = [];
var identifiers = [];
var ast = parse(src, fileName);
walk.simple(ast, {
Identifier: function( node ) {
identifiers.push( node );
}
});
for( var i = 0, len = identifiers.length; i < len; ++i ) {
var id = identifiers[i];
if( ignore.indexOf(id) > -1 ) {
continue;
}
var constant = constants[id.name];
if( constant === void 0 ) {
continue;
}
if( constant.identifier === id ) {
continue;
}
results.push( new ConstantReplacement( constant.value, id.start, id.end ) );
}
return convertSrc( src, results );
} | javascript | function( src, fileName ) {
var results = [];
var identifiers = [];
var ast = parse(src, fileName);
walk.simple(ast, {
Identifier: function( node ) {
identifiers.push( node );
}
});
for( var i = 0, len = identifiers.length; i < len; ++i ) {
var id = identifiers[i];
if( ignore.indexOf(id) > -1 ) {
continue;
}
var constant = constants[id.name];
if( constant === void 0 ) {
continue;
}
if( constant.identifier === id ) {
continue;
}
results.push( new ConstantReplacement( constant.value, id.start, id.end ) );
}
return convertSrc( src, results );
} | [
"function",
"(",
"src",
",",
"fileName",
")",
"{",
"var",
"results",
"=",
"[",
"]",
";",
"var",
"identifiers",
"=",
"[",
"]",
";",
"var",
"ast",
"=",
"parse",
"(",
"src",
",",
"fileName",
")",
";",
"walk",
".",
"simple",
"(",
"ast",
",",
"{",
"Identifier",
":",
"function",
"(",
"node",
")",
"{",
"identifiers",
".",
"push",
"(",
"node",
")",
";",
"}",
"}",
")",
";",
"for",
"(",
"var",
"i",
"=",
"0",
",",
"len",
"=",
"identifiers",
".",
"length",
";",
"i",
"<",
"len",
";",
"++",
"i",
")",
"{",
"var",
"id",
"=",
"identifiers",
"[",
"i",
"]",
";",
"if",
"(",
"ignore",
".",
"indexOf",
"(",
"id",
")",
">",
"-",
"1",
")",
"{",
"continue",
";",
"}",
"var",
"constant",
"=",
"constants",
"[",
"id",
".",
"name",
"]",
";",
"if",
"(",
"constant",
"===",
"void",
"0",
")",
"{",
"continue",
";",
"}",
"if",
"(",
"constant",
".",
"identifier",
"===",
"id",
")",
"{",
"continue",
";",
"}",
"results",
".",
"push",
"(",
"new",
"ConstantReplacement",
"(",
"constant",
".",
"value",
",",
"id",
".",
"start",
",",
"id",
".",
"end",
")",
")",
";",
"}",
"return",
"convertSrc",
"(",
"src",
",",
"results",
")",
";",
"}"
] | Expand constants in normal source files | [
"Expand",
"constants",
"in",
"normal",
"source",
"files"
] | 17f69f3b0fa89a0b7a5cfb9a6546d1180a3610e0 | https://github.com/petkaantonov/bluebird/blob/17f69f3b0fa89a0b7a5cfb9a6546d1180a3610e0/tools/ast_passes.js#L542-L569 |
|
5,543 | electron-userland/electron-packager | targets.js | validateListFromOptions | function validateListFromOptions (opts, name) {
if (opts.all) return Array.from(supported[name].values())
let list = opts[name]
if (!list) {
if (name === 'arch') {
list = hostArch()
} else {
list = process[name]
}
} else if (list === 'all') {
return Array.from(supported[name].values())
}
if (!Array.isArray(list)) {
if (typeof list === 'string') {
list = list.split(/,\s*/)
} else {
return unsupportedListOption(name, list, supported[name])
}
}
const officialElectronPackages = usingOfficialElectronPackages(opts)
for (let value of list) {
if (officialElectronPackages && !supported[name].has(value)) {
return unsupportedListOption(name, value, supported[name])
}
}
return list
} | javascript | function validateListFromOptions (opts, name) {
if (opts.all) return Array.from(supported[name].values())
let list = opts[name]
if (!list) {
if (name === 'arch') {
list = hostArch()
} else {
list = process[name]
}
} else if (list === 'all') {
return Array.from(supported[name].values())
}
if (!Array.isArray(list)) {
if (typeof list === 'string') {
list = list.split(/,\s*/)
} else {
return unsupportedListOption(name, list, supported[name])
}
}
const officialElectronPackages = usingOfficialElectronPackages(opts)
for (let value of list) {
if (officialElectronPackages && !supported[name].has(value)) {
return unsupportedListOption(name, value, supported[name])
}
}
return list
} | [
"function",
"validateListFromOptions",
"(",
"opts",
",",
"name",
")",
"{",
"if",
"(",
"opts",
".",
"all",
")",
"return",
"Array",
".",
"from",
"(",
"supported",
"[",
"name",
"]",
".",
"values",
"(",
")",
")",
"let",
"list",
"=",
"opts",
"[",
"name",
"]",
"if",
"(",
"!",
"list",
")",
"{",
"if",
"(",
"name",
"===",
"'arch'",
")",
"{",
"list",
"=",
"hostArch",
"(",
")",
"}",
"else",
"{",
"list",
"=",
"process",
"[",
"name",
"]",
"}",
"}",
"else",
"if",
"(",
"list",
"===",
"'all'",
")",
"{",
"return",
"Array",
".",
"from",
"(",
"supported",
"[",
"name",
"]",
".",
"values",
"(",
")",
")",
"}",
"if",
"(",
"!",
"Array",
".",
"isArray",
"(",
"list",
")",
")",
"{",
"if",
"(",
"typeof",
"list",
"===",
"'string'",
")",
"{",
"list",
"=",
"list",
".",
"split",
"(",
"/",
",\\s*",
"/",
")",
"}",
"else",
"{",
"return",
"unsupportedListOption",
"(",
"name",
",",
"list",
",",
"supported",
"[",
"name",
"]",
")",
"}",
"}",
"const",
"officialElectronPackages",
"=",
"usingOfficialElectronPackages",
"(",
"opts",
")",
"for",
"(",
"let",
"value",
"of",
"list",
")",
"{",
"if",
"(",
"officialElectronPackages",
"&&",
"!",
"supported",
"[",
"name",
"]",
".",
"has",
"(",
"value",
")",
")",
"{",
"return",
"unsupportedListOption",
"(",
"name",
",",
"value",
",",
"supported",
"[",
"name",
"]",
")",
"}",
"}",
"return",
"list",
"}"
] | Validates list of architectures or platforms. Returns a normalized array if successful, or throws an Error. | [
"Validates",
"list",
"of",
"architectures",
"or",
"platforms",
".",
"Returns",
"a",
"normalized",
"array",
"if",
"successful",
"or",
"throws",
"an",
"Error",
"."
] | e65bc99ea3e06f9b72305d3fcf6589bdcb54810b | https://github.com/electron-userland/electron-packager/blob/e65bc99ea3e06f9b72305d3fcf6589bdcb54810b/targets.js#L104-L135 |
5,544 | FineUploader/fine-uploader | client/js/azure/azure.xhr.upload.handler.js | function(reason) {
log(qq.format("Failed to determine blob name for ID {} - {}", id, reason), "error");
promise.failure({error: reason});
} | javascript | function(reason) {
log(qq.format("Failed to determine blob name for ID {} - {}", id, reason), "error");
promise.failure({error: reason});
} | [
"function",
"(",
"reason",
")",
"{",
"log",
"(",
"qq",
".",
"format",
"(",
"\"Failed to determine blob name for ID {} - {}\"",
",",
"id",
",",
"reason",
")",
",",
"\"error\"",
")",
";",
"promise",
".",
"failure",
"(",
"{",
"error",
":",
"reason",
"}",
")",
";",
"}"
] | We may have multiple SAS requests in progress for the same file, so we must include the chunk idx as part of the ID when communicating with the SAS ajax requester to avoid collisions. | [
"We",
"may",
"have",
"multiple",
"SAS",
"requests",
"in",
"progress",
"for",
"the",
"same",
"file",
"so",
"we",
"must",
"include",
"the",
"chunk",
"idx",
"as",
"part",
"of",
"the",
"ID",
"when",
"communicating",
"with",
"the",
"SAS",
"ajax",
"requester",
"to",
"avoid",
"collisions",
"."
] | 057cc83a7e7657d032a75cf4a6b3612c7b4191da | https://github.com/FineUploader/fine-uploader/blob/057cc83a7e7657d032a75cf4a6b3612c7b4191da/client/js/azure/azure.xhr.upload.handler.js#L121-L124 |
|
5,545 | FineUploader/fine-uploader | client/js/ui.handler.edit.filename.js | handleNameUpdate | function handleNameUpdate(newFilenameInputEl, fileId) {
var newName = newFilenameInputEl.value,
origExtension;
if (newName !== undefined && qq.trimStr(newName).length > 0) {
origExtension = getOriginalExtension(fileId);
if (origExtension !== undefined) {
newName = newName + "." + origExtension;
}
spec.onSetName(fileId, newName);
}
spec.onEditingStatusChange(fileId, false);
} | javascript | function handleNameUpdate(newFilenameInputEl, fileId) {
var newName = newFilenameInputEl.value,
origExtension;
if (newName !== undefined && qq.trimStr(newName).length > 0) {
origExtension = getOriginalExtension(fileId);
if (origExtension !== undefined) {
newName = newName + "." + origExtension;
}
spec.onSetName(fileId, newName);
}
spec.onEditingStatusChange(fileId, false);
} | [
"function",
"handleNameUpdate",
"(",
"newFilenameInputEl",
",",
"fileId",
")",
"{",
"var",
"newName",
"=",
"newFilenameInputEl",
".",
"value",
",",
"origExtension",
";",
"if",
"(",
"newName",
"!==",
"undefined",
"&&",
"qq",
".",
"trimStr",
"(",
"newName",
")",
".",
"length",
">",
"0",
")",
"{",
"origExtension",
"=",
"getOriginalExtension",
"(",
"fileId",
")",
";",
"if",
"(",
"origExtension",
"!==",
"undefined",
")",
"{",
"newName",
"=",
"newName",
"+",
"\".\"",
"+",
"origExtension",
";",
"}",
"spec",
".",
"onSetName",
"(",
"fileId",
",",
"newName",
")",
";",
"}",
"spec",
".",
"onEditingStatusChange",
"(",
"fileId",
",",
"false",
")",
";",
"}"
] | Callback iff the name has been changed | [
"Callback",
"iff",
"the",
"name",
"has",
"been",
"changed"
] | 057cc83a7e7657d032a75cf4a6b3612c7b4191da | https://github.com/FineUploader/fine-uploader/blob/057cc83a7e7657d032a75cf4a6b3612c7b4191da/client/js/ui.handler.edit.filename.js#L33-L48 |
5,546 | FineUploader/fine-uploader | client/js/ui.handler.edit.filename.js | registerInputBlurHandler | function registerInputBlurHandler(inputEl, fileId) {
inheritedInternalApi.getDisposeSupport().attach(inputEl, "blur", function() {
handleNameUpdate(inputEl, fileId);
});
} | javascript | function registerInputBlurHandler(inputEl, fileId) {
inheritedInternalApi.getDisposeSupport().attach(inputEl, "blur", function() {
handleNameUpdate(inputEl, fileId);
});
} | [
"function",
"registerInputBlurHandler",
"(",
"inputEl",
",",
"fileId",
")",
"{",
"inheritedInternalApi",
".",
"getDisposeSupport",
"(",
")",
".",
"attach",
"(",
"inputEl",
",",
"\"blur\"",
",",
"function",
"(",
")",
"{",
"handleNameUpdate",
"(",
"inputEl",
",",
"fileId",
")",
";",
"}",
")",
";",
"}"
] | The name has been updated if the filename edit input loses focus. | [
"The",
"name",
"has",
"been",
"updated",
"if",
"the",
"filename",
"edit",
"input",
"loses",
"focus",
"."
] | 057cc83a7e7657d032a75cf4a6b3612c7b4191da | https://github.com/FineUploader/fine-uploader/blob/057cc83a7e7657d032a75cf4a6b3612c7b4191da/client/js/ui.handler.edit.filename.js#L51-L55 |
5,547 | FineUploader/fine-uploader | client/js/ui.handler.edit.filename.js | registerInputEnterKeyHandler | function registerInputEnterKeyHandler(inputEl, fileId) {
inheritedInternalApi.getDisposeSupport().attach(inputEl, "keyup", function(event) {
var code = event.keyCode || event.which;
if (code === 13) {
handleNameUpdate(inputEl, fileId);
}
});
} | javascript | function registerInputEnterKeyHandler(inputEl, fileId) {
inheritedInternalApi.getDisposeSupport().attach(inputEl, "keyup", function(event) {
var code = event.keyCode || event.which;
if (code === 13) {
handleNameUpdate(inputEl, fileId);
}
});
} | [
"function",
"registerInputEnterKeyHandler",
"(",
"inputEl",
",",
"fileId",
")",
"{",
"inheritedInternalApi",
".",
"getDisposeSupport",
"(",
")",
".",
"attach",
"(",
"inputEl",
",",
"\"keyup\"",
",",
"function",
"(",
"event",
")",
"{",
"var",
"code",
"=",
"event",
".",
"keyCode",
"||",
"event",
".",
"which",
";",
"if",
"(",
"code",
"===",
"13",
")",
"{",
"handleNameUpdate",
"(",
"inputEl",
",",
"fileId",
")",
";",
"}",
"}",
")",
";",
"}"
] | The name has been updated if the user presses enter. | [
"The",
"name",
"has",
"been",
"updated",
"if",
"the",
"user",
"presses",
"enter",
"."
] | 057cc83a7e7657d032a75cf4a6b3612c7b4191da | https://github.com/FineUploader/fine-uploader/blob/057cc83a7e7657d032a75cf4a6b3612c7b4191da/client/js/ui.handler.edit.filename.js#L58-L67 |
5,548 | FineUploader/fine-uploader | client/js/dnd.js | getFilesInDirectory | function getFilesInDirectory(entry, reader, accumEntries, existingPromise) {
var promise = existingPromise || new qq.Promise(),
dirReader = reader || entry.createReader();
dirReader.readEntries(
function readSuccess(entries) {
var newEntries = accumEntries ? accumEntries.concat(entries) : entries;
if (entries.length) {
setTimeout(function() { // prevent stack overflow, however unlikely
getFilesInDirectory(entry, dirReader, newEntries, promise);
}, 0);
}
else {
promise.success(newEntries);
}
},
promise.failure
);
return promise;
} | javascript | function getFilesInDirectory(entry, reader, accumEntries, existingPromise) {
var promise = existingPromise || new qq.Promise(),
dirReader = reader || entry.createReader();
dirReader.readEntries(
function readSuccess(entries) {
var newEntries = accumEntries ? accumEntries.concat(entries) : entries;
if (entries.length) {
setTimeout(function() { // prevent stack overflow, however unlikely
getFilesInDirectory(entry, dirReader, newEntries, promise);
}, 0);
}
else {
promise.success(newEntries);
}
},
promise.failure
);
return promise;
} | [
"function",
"getFilesInDirectory",
"(",
"entry",
",",
"reader",
",",
"accumEntries",
",",
"existingPromise",
")",
"{",
"var",
"promise",
"=",
"existingPromise",
"||",
"new",
"qq",
".",
"Promise",
"(",
")",
",",
"dirReader",
"=",
"reader",
"||",
"entry",
".",
"createReader",
"(",
")",
";",
"dirReader",
".",
"readEntries",
"(",
"function",
"readSuccess",
"(",
"entries",
")",
"{",
"var",
"newEntries",
"=",
"accumEntries",
"?",
"accumEntries",
".",
"concat",
"(",
"entries",
")",
":",
"entries",
";",
"if",
"(",
"entries",
".",
"length",
")",
"{",
"setTimeout",
"(",
"function",
"(",
")",
"{",
"// prevent stack overflow, however unlikely",
"getFilesInDirectory",
"(",
"entry",
",",
"dirReader",
",",
"newEntries",
",",
"promise",
")",
";",
"}",
",",
"0",
")",
";",
"}",
"else",
"{",
"promise",
".",
"success",
"(",
"newEntries",
")",
";",
"}",
"}",
",",
"promise",
".",
"failure",
")",
";",
"return",
"promise",
";",
"}"
] | Promissory. Guaranteed to read all files in the root of the passed directory. | [
"Promissory",
".",
"Guaranteed",
"to",
"read",
"all",
"files",
"in",
"the",
"root",
"of",
"the",
"passed",
"directory",
"."
] | 057cc83a7e7657d032a75cf4a6b3612c7b4191da | https://github.com/FineUploader/fine-uploader/blob/057cc83a7e7657d032a75cf4a6b3612c7b4191da/client/js/dnd.js#L93-L115 |
5,549 | FineUploader/fine-uploader | client/js/jquery-plugin.js | addCallbacks | function addCallbacks(transformedOpts, newUploaderInstance) {
var callbacks = transformedOpts.callbacks = {};
$.each(newUploaderInstance._options.callbacks, function(prop, nonJqueryCallback) {
var name, callbackEventTarget;
name = /^on(\w+)/.exec(prop)[1];
name = name.substring(0, 1).toLowerCase() + name.substring(1);
callbackEventTarget = $el;
callbacks[prop] = function() {
var originalArgs = Array.prototype.slice.call(arguments),
transformedArgs = [],
nonJqueryCallbackRetVal, jqueryEventCallbackRetVal;
$.each(originalArgs, function(idx, arg) {
transformedArgs.push(maybeWrapInJquery(arg));
});
nonJqueryCallbackRetVal = nonJqueryCallback.apply(this, originalArgs);
try {
jqueryEventCallbackRetVal = callbackEventTarget.triggerHandler(name, transformedArgs);
}
catch (error) {
qq.log("Caught error in Fine Uploader jQuery event handler: " + error.message, "error");
}
/*jshint -W116*/
if (nonJqueryCallbackRetVal != null) {
return nonJqueryCallbackRetVal;
}
return jqueryEventCallbackRetVal;
};
});
newUploaderInstance._options.callbacks = callbacks;
} | javascript | function addCallbacks(transformedOpts, newUploaderInstance) {
var callbacks = transformedOpts.callbacks = {};
$.each(newUploaderInstance._options.callbacks, function(prop, nonJqueryCallback) {
var name, callbackEventTarget;
name = /^on(\w+)/.exec(prop)[1];
name = name.substring(0, 1).toLowerCase() + name.substring(1);
callbackEventTarget = $el;
callbacks[prop] = function() {
var originalArgs = Array.prototype.slice.call(arguments),
transformedArgs = [],
nonJqueryCallbackRetVal, jqueryEventCallbackRetVal;
$.each(originalArgs, function(idx, arg) {
transformedArgs.push(maybeWrapInJquery(arg));
});
nonJqueryCallbackRetVal = nonJqueryCallback.apply(this, originalArgs);
try {
jqueryEventCallbackRetVal = callbackEventTarget.triggerHandler(name, transformedArgs);
}
catch (error) {
qq.log("Caught error in Fine Uploader jQuery event handler: " + error.message, "error");
}
/*jshint -W116*/
if (nonJqueryCallbackRetVal != null) {
return nonJqueryCallbackRetVal;
}
return jqueryEventCallbackRetVal;
};
});
newUploaderInstance._options.callbacks = callbacks;
} | [
"function",
"addCallbacks",
"(",
"transformedOpts",
",",
"newUploaderInstance",
")",
"{",
"var",
"callbacks",
"=",
"transformedOpts",
".",
"callbacks",
"=",
"{",
"}",
";",
"$",
".",
"each",
"(",
"newUploaderInstance",
".",
"_options",
".",
"callbacks",
",",
"function",
"(",
"prop",
",",
"nonJqueryCallback",
")",
"{",
"var",
"name",
",",
"callbackEventTarget",
";",
"name",
"=",
"/",
"^on(\\w+)",
"/",
".",
"exec",
"(",
"prop",
")",
"[",
"1",
"]",
";",
"name",
"=",
"name",
".",
"substring",
"(",
"0",
",",
"1",
")",
".",
"toLowerCase",
"(",
")",
"+",
"name",
".",
"substring",
"(",
"1",
")",
";",
"callbackEventTarget",
"=",
"$el",
";",
"callbacks",
"[",
"prop",
"]",
"=",
"function",
"(",
")",
"{",
"var",
"originalArgs",
"=",
"Array",
".",
"prototype",
".",
"slice",
".",
"call",
"(",
"arguments",
")",
",",
"transformedArgs",
"=",
"[",
"]",
",",
"nonJqueryCallbackRetVal",
",",
"jqueryEventCallbackRetVal",
";",
"$",
".",
"each",
"(",
"originalArgs",
",",
"function",
"(",
"idx",
",",
"arg",
")",
"{",
"transformedArgs",
".",
"push",
"(",
"maybeWrapInJquery",
"(",
"arg",
")",
")",
";",
"}",
")",
";",
"nonJqueryCallbackRetVal",
"=",
"nonJqueryCallback",
".",
"apply",
"(",
"this",
",",
"originalArgs",
")",
";",
"try",
"{",
"jqueryEventCallbackRetVal",
"=",
"callbackEventTarget",
".",
"triggerHandler",
"(",
"name",
",",
"transformedArgs",
")",
";",
"}",
"catch",
"(",
"error",
")",
"{",
"qq",
".",
"log",
"(",
"\"Caught error in Fine Uploader jQuery event handler: \"",
"+",
"error",
".",
"message",
",",
"\"error\"",
")",
";",
"}",
"/*jshint -W116*/",
"if",
"(",
"nonJqueryCallbackRetVal",
"!=",
"null",
")",
"{",
"return",
"nonJqueryCallbackRetVal",
";",
"}",
"return",
"jqueryEventCallbackRetVal",
";",
"}",
";",
"}",
")",
";",
"newUploaderInstance",
".",
"_options",
".",
"callbacks",
"=",
"callbacks",
";",
"}"
] | Implement all callbacks defined in Fine Uploader as functions that trigger appropriately names events and return the result of executing the bound handler back to Fine Uploader | [
"Implement",
"all",
"callbacks",
"defined",
"in",
"Fine",
"Uploader",
"as",
"functions",
"that",
"trigger",
"appropriately",
"names",
"events",
"and",
"return",
"the",
"result",
"of",
"executing",
"the",
"bound",
"handler",
"back",
"to",
"Fine",
"Uploader"
] | 057cc83a7e7657d032a75cf4a6b3612c7b4191da | https://github.com/FineUploader/fine-uploader/blob/057cc83a7e7657d032a75cf4a6b3612c7b4191da/client/js/jquery-plugin.js#L72-L109 |
5,550 | FineUploader/fine-uploader | client/js/jquery-plugin.js | maybeWrapInJquery | function maybeWrapInJquery(val) {
var transformedVal = val;
// If the command is returning an `HTMLElement` or `HTMLDocument`, wrap it in a `jQuery` object
/*jshint -W116*/
if (val != null && typeof val === "object" &&
(val.nodeType === 1 || val.nodeType === 9) && val.cloneNode) {
transformedVal = $(val);
}
return transformedVal;
} | javascript | function maybeWrapInJquery(val) {
var transformedVal = val;
// If the command is returning an `HTMLElement` or `HTMLDocument`, wrap it in a `jQuery` object
/*jshint -W116*/
if (val != null && typeof val === "object" &&
(val.nodeType === 1 || val.nodeType === 9) && val.cloneNode) {
transformedVal = $(val);
}
return transformedVal;
} | [
"function",
"maybeWrapInJquery",
"(",
"val",
")",
"{",
"var",
"transformedVal",
"=",
"val",
";",
"// If the command is returning an `HTMLElement` or `HTMLDocument`, wrap it in a `jQuery` object",
"/*jshint -W116*/",
"if",
"(",
"val",
"!=",
"null",
"&&",
"typeof",
"val",
"===",
"\"object\"",
"&&",
"(",
"val",
".",
"nodeType",
"===",
"1",
"||",
"val",
".",
"nodeType",
"===",
"9",
")",
"&&",
"val",
".",
"cloneNode",
")",
"{",
"transformedVal",
"=",
"$",
"(",
"val",
")",
";",
"}",
"return",
"transformedVal",
";",
"}"
] | If the value is an `HTMLElement` or `HTMLDocument`, wrap it in a `jQuery` object | [
"If",
"the",
"value",
"is",
"an",
"HTMLElement",
"or",
"HTMLDocument",
"wrap",
"it",
"in",
"a",
"jQuery",
"object"
] | 057cc83a7e7657d032a75cf4a6b3612c7b4191da | https://github.com/FineUploader/fine-uploader/blob/057cc83a7e7657d032a75cf4a6b3612c7b4191da/client/js/jquery-plugin.js#L187-L199 |
5,551 | FineUploader/fine-uploader | client/js/total-progress.js | function(id, loaded, total) {
updateTotalProgress(id, loaded, total);
perFileProgress[id] = {loaded: loaded, total: total};
} | javascript | function(id, loaded, total) {
updateTotalProgress(id, loaded, total);
perFileProgress[id] = {loaded: loaded, total: total};
} | [
"function",
"(",
"id",
",",
"loaded",
",",
"total",
")",
"{",
"updateTotalProgress",
"(",
"id",
",",
"loaded",
",",
"total",
")",
";",
"perFileProgress",
"[",
"id",
"]",
"=",
"{",
"loaded",
":",
"loaded",
",",
"total",
":",
"total",
"}",
";",
"}"
] | Called whenever the upload progress of an individual file has changed. | [
"Called",
"whenever",
"the",
"upload",
"progress",
"of",
"an",
"individual",
"file",
"has",
"changed",
"."
] | 057cc83a7e7657d032a75cf4a6b3612c7b4191da | https://github.com/FineUploader/fine-uploader/blob/057cc83a7e7657d032a75cf4a6b3612c7b4191da/client/js/total-progress.js#L110-L113 |
|
5,552 | FineUploader/fine-uploader | client/js/ui.handler.click.filename.js | examineEvent | function examineEvent(target, event) {
if (spec.templating.isFileName(target) || spec.templating.isEditIcon(target)) {
var fileId = spec.templating.getFileId(target),
status = spec.onGetUploadStatus(fileId);
// We only allow users to change filenames of files that have been submitted but not yet uploaded.
if (status === qq.status.SUBMITTED) {
spec.log(qq.format("Detected valid filename click event on file '{}', ID: {}.", spec.onGetName(fileId), fileId));
qq.preventDefault(event);
inheritedInternalApi.handleFilenameEdit(fileId, target, true);
}
}
} | javascript | function examineEvent(target, event) {
if (spec.templating.isFileName(target) || spec.templating.isEditIcon(target)) {
var fileId = spec.templating.getFileId(target),
status = spec.onGetUploadStatus(fileId);
// We only allow users to change filenames of files that have been submitted but not yet uploaded.
if (status === qq.status.SUBMITTED) {
spec.log(qq.format("Detected valid filename click event on file '{}', ID: {}.", spec.onGetName(fileId), fileId));
qq.preventDefault(event);
inheritedInternalApi.handleFilenameEdit(fileId, target, true);
}
}
} | [
"function",
"examineEvent",
"(",
"target",
",",
"event",
")",
"{",
"if",
"(",
"spec",
".",
"templating",
".",
"isFileName",
"(",
"target",
")",
"||",
"spec",
".",
"templating",
".",
"isEditIcon",
"(",
"target",
")",
")",
"{",
"var",
"fileId",
"=",
"spec",
".",
"templating",
".",
"getFileId",
"(",
"target",
")",
",",
"status",
"=",
"spec",
".",
"onGetUploadStatus",
"(",
"fileId",
")",
";",
"// We only allow users to change filenames of files that have been submitted but not yet uploaded.",
"if",
"(",
"status",
"===",
"qq",
".",
"status",
".",
"SUBMITTED",
")",
"{",
"spec",
".",
"log",
"(",
"qq",
".",
"format",
"(",
"\"Detected valid filename click event on file '{}', ID: {}.\"",
",",
"spec",
".",
"onGetName",
"(",
"fileId",
")",
",",
"fileId",
")",
")",
";",
"qq",
".",
"preventDefault",
"(",
"event",
")",
";",
"inheritedInternalApi",
".",
"handleFilenameEdit",
"(",
"fileId",
",",
"target",
",",
"true",
")",
";",
"}",
"}",
"}"
] | This will be called by the parent handler when a `click` event is received on the list element. | [
"This",
"will",
"be",
"called",
"by",
"the",
"parent",
"handler",
"when",
"a",
"click",
"event",
"is",
"received",
"on",
"the",
"list",
"element",
"."
] | 057cc83a7e7657d032a75cf4a6b3612c7b4191da | https://github.com/FineUploader/fine-uploader/blob/057cc83a7e7657d032a75cf4a6b3612c7b4191da/client/js/ui.handler.click.filename.js#L21-L34 |
5,553 | FineUploader/fine-uploader | client/js/image-support/exif.js | getDirEntryCount | function getDirEntryCount(app1Start, littleEndian) {
var promise = new qq.Promise();
qq.readBlobToHex(fileOrBlob, app1Start + 18, 2).then(function(hex) {
if (littleEndian) {
return promise.success(parseLittleEndian(hex));
}
else {
promise.success(parseInt(hex, 16));
}
});
return promise;
} | javascript | function getDirEntryCount(app1Start, littleEndian) {
var promise = new qq.Promise();
qq.readBlobToHex(fileOrBlob, app1Start + 18, 2).then(function(hex) {
if (littleEndian) {
return promise.success(parseLittleEndian(hex));
}
else {
promise.success(parseInt(hex, 16));
}
});
return promise;
} | [
"function",
"getDirEntryCount",
"(",
"app1Start",
",",
"littleEndian",
")",
"{",
"var",
"promise",
"=",
"new",
"qq",
".",
"Promise",
"(",
")",
";",
"qq",
".",
"readBlobToHex",
"(",
"fileOrBlob",
",",
"app1Start",
"+",
"18",
",",
"2",
")",
".",
"then",
"(",
"function",
"(",
"hex",
")",
"{",
"if",
"(",
"littleEndian",
")",
"{",
"return",
"promise",
".",
"success",
"(",
"parseLittleEndian",
"(",
"hex",
")",
")",
";",
"}",
"else",
"{",
"promise",
".",
"success",
"(",
"parseInt",
"(",
"hex",
",",
"16",
")",
")",
";",
"}",
"}",
")",
";",
"return",
"promise",
";",
"}"
] | Determine the number of directory entries in the EXIF header. | [
"Determine",
"the",
"number",
"of",
"directory",
"entries",
"in",
"the",
"EXIF",
"header",
"."
] | 057cc83a7e7657d032a75cf4a6b3612c7b4191da | https://github.com/FineUploader/fine-uploader/blob/057cc83a7e7657d032a75cf4a6b3612c7b4191da/client/js/image-support/exif.js#L99-L112 |
5,554 | FineUploader/fine-uploader | client/js/image-support/exif.js | getIfd | function getIfd(app1Start, dirEntries) {
var offset = app1Start + 20,
bytes = dirEntries * 12;
return qq.readBlobToHex(fileOrBlob, offset, bytes);
} | javascript | function getIfd(app1Start, dirEntries) {
var offset = app1Start + 20,
bytes = dirEntries * 12;
return qq.readBlobToHex(fileOrBlob, offset, bytes);
} | [
"function",
"getIfd",
"(",
"app1Start",
",",
"dirEntries",
")",
"{",
"var",
"offset",
"=",
"app1Start",
"+",
"20",
",",
"bytes",
"=",
"dirEntries",
"*",
"12",
";",
"return",
"qq",
".",
"readBlobToHex",
"(",
"fileOrBlob",
",",
"offset",
",",
"bytes",
")",
";",
"}"
] | Get the IFD portion of the EXIF header as a hex string. | [
"Get",
"the",
"IFD",
"portion",
"of",
"the",
"EXIF",
"header",
"as",
"a",
"hex",
"string",
"."
] | 057cc83a7e7657d032a75cf4a6b3612c7b4191da | https://github.com/FineUploader/fine-uploader/blob/057cc83a7e7657d032a75cf4a6b3612c7b4191da/client/js/image-support/exif.js#L115-L120 |
5,555 | FineUploader/fine-uploader | client/js/image-support/exif.js | getTagValues | function getTagValues(littleEndian, dirEntries) {
var TAG_VAL_OFFSET = 16,
tagsToFind = qq.extend([], TAG_IDS),
vals = {};
qq.each(dirEntries, function(idx, entry) {
var idHex = entry.slice(0, 4),
id = littleEndian ? parseLittleEndian(idHex) : parseInt(idHex, 16),
tagsToFindIdx = tagsToFind.indexOf(id),
tagValHex, tagName, tagValLength;
if (tagsToFindIdx >= 0) {
tagName = TAG_INFO[id].name;
tagValLength = TAG_INFO[id].bytes;
tagValHex = entry.slice(TAG_VAL_OFFSET, TAG_VAL_OFFSET + (tagValLength * 2));
vals[tagName] = littleEndian ? parseLittleEndian(tagValHex) : parseInt(tagValHex, 16);
tagsToFind.splice(tagsToFindIdx, 1);
}
if (tagsToFind.length === 0) {
return false;
}
});
return vals;
} | javascript | function getTagValues(littleEndian, dirEntries) {
var TAG_VAL_OFFSET = 16,
tagsToFind = qq.extend([], TAG_IDS),
vals = {};
qq.each(dirEntries, function(idx, entry) {
var idHex = entry.slice(0, 4),
id = littleEndian ? parseLittleEndian(idHex) : parseInt(idHex, 16),
tagsToFindIdx = tagsToFind.indexOf(id),
tagValHex, tagName, tagValLength;
if (tagsToFindIdx >= 0) {
tagName = TAG_INFO[id].name;
tagValLength = TAG_INFO[id].bytes;
tagValHex = entry.slice(TAG_VAL_OFFSET, TAG_VAL_OFFSET + (tagValLength * 2));
vals[tagName] = littleEndian ? parseLittleEndian(tagValHex) : parseInt(tagValHex, 16);
tagsToFind.splice(tagsToFindIdx, 1);
}
if (tagsToFind.length === 0) {
return false;
}
});
return vals;
} | [
"function",
"getTagValues",
"(",
"littleEndian",
",",
"dirEntries",
")",
"{",
"var",
"TAG_VAL_OFFSET",
"=",
"16",
",",
"tagsToFind",
"=",
"qq",
".",
"extend",
"(",
"[",
"]",
",",
"TAG_IDS",
")",
",",
"vals",
"=",
"{",
"}",
";",
"qq",
".",
"each",
"(",
"dirEntries",
",",
"function",
"(",
"idx",
",",
"entry",
")",
"{",
"var",
"idHex",
"=",
"entry",
".",
"slice",
"(",
"0",
",",
"4",
")",
",",
"id",
"=",
"littleEndian",
"?",
"parseLittleEndian",
"(",
"idHex",
")",
":",
"parseInt",
"(",
"idHex",
",",
"16",
")",
",",
"tagsToFindIdx",
"=",
"tagsToFind",
".",
"indexOf",
"(",
"id",
")",
",",
"tagValHex",
",",
"tagName",
",",
"tagValLength",
";",
"if",
"(",
"tagsToFindIdx",
">=",
"0",
")",
"{",
"tagName",
"=",
"TAG_INFO",
"[",
"id",
"]",
".",
"name",
";",
"tagValLength",
"=",
"TAG_INFO",
"[",
"id",
"]",
".",
"bytes",
";",
"tagValHex",
"=",
"entry",
".",
"slice",
"(",
"TAG_VAL_OFFSET",
",",
"TAG_VAL_OFFSET",
"+",
"(",
"tagValLength",
"*",
"2",
")",
")",
";",
"vals",
"[",
"tagName",
"]",
"=",
"littleEndian",
"?",
"parseLittleEndian",
"(",
"tagValHex",
")",
":",
"parseInt",
"(",
"tagValHex",
",",
"16",
")",
";",
"tagsToFind",
".",
"splice",
"(",
"tagsToFindIdx",
",",
"1",
")",
";",
"}",
"if",
"(",
"tagsToFind",
".",
"length",
"===",
"0",
")",
"{",
"return",
"false",
";",
"}",
"}",
")",
";",
"return",
"vals",
";",
"}"
] | Obtain values for all relevant tags and return them. | [
"Obtain",
"values",
"for",
"all",
"relevant",
"tags",
"and",
"return",
"them",
"."
] | 057cc83a7e7657d032a75cf4a6b3612c7b4191da | https://github.com/FineUploader/fine-uploader/blob/057cc83a7e7657d032a75cf4a6b3612c7b4191da/client/js/image-support/exif.js#L136-L162 |
5,556 | FineUploader/fine-uploader | client/js/s3/multipart.complete.ajax.requester.js | handleCompleteRequestComplete | function handleCompleteRequestComplete(id, xhr, isError) {
var promise = pendingCompleteRequests[id],
domParser = new DOMParser(),
bucket = options.getBucket(id),
key = options.getKey(id),
responseDoc = domParser.parseFromString(xhr.responseText, "application/xml"),
bucketEls = responseDoc.getElementsByTagName("Bucket"),
keyEls = responseDoc.getElementsByTagName("Key");
delete pendingCompleteRequests[id];
options.log(qq.format("Complete response status {}, body = {}", xhr.status, xhr.responseText));
// If the base requester has determine this a failure, give up.
if (isError) {
options.log(qq.format("Complete Multipart Upload request for {} failed with status {}.", id, xhr.status), "error");
}
else {
// Make sure the correct bucket and key has been specified in the XML response from AWS.
if (bucketEls.length && keyEls.length) {
if (bucketEls[0].textContent !== bucket) {
isError = true;
options.log(qq.format("Wrong bucket in response to Complete Multipart Upload request for {}.", id), "error");
}
// TODO Compare key name from response w/ expected key name if AWS ever fixes the encoding of key names in this response.
}
else {
isError = true;
options.log(qq.format("Missing bucket and/or key in response to Complete Multipart Upload request for {}.", id), "error");
}
}
if (isError) {
promise.failure("Problem combining the file parts!", xhr);
}
else {
promise.success({}, xhr);
}
} | javascript | function handleCompleteRequestComplete(id, xhr, isError) {
var promise = pendingCompleteRequests[id],
domParser = new DOMParser(),
bucket = options.getBucket(id),
key = options.getKey(id),
responseDoc = domParser.parseFromString(xhr.responseText, "application/xml"),
bucketEls = responseDoc.getElementsByTagName("Bucket"),
keyEls = responseDoc.getElementsByTagName("Key");
delete pendingCompleteRequests[id];
options.log(qq.format("Complete response status {}, body = {}", xhr.status, xhr.responseText));
// If the base requester has determine this a failure, give up.
if (isError) {
options.log(qq.format("Complete Multipart Upload request for {} failed with status {}.", id, xhr.status), "error");
}
else {
// Make sure the correct bucket and key has been specified in the XML response from AWS.
if (bucketEls.length && keyEls.length) {
if (bucketEls[0].textContent !== bucket) {
isError = true;
options.log(qq.format("Wrong bucket in response to Complete Multipart Upload request for {}.", id), "error");
}
// TODO Compare key name from response w/ expected key name if AWS ever fixes the encoding of key names in this response.
}
else {
isError = true;
options.log(qq.format("Missing bucket and/or key in response to Complete Multipart Upload request for {}.", id), "error");
}
}
if (isError) {
promise.failure("Problem combining the file parts!", xhr);
}
else {
promise.success({}, xhr);
}
} | [
"function",
"handleCompleteRequestComplete",
"(",
"id",
",",
"xhr",
",",
"isError",
")",
"{",
"var",
"promise",
"=",
"pendingCompleteRequests",
"[",
"id",
"]",
",",
"domParser",
"=",
"new",
"DOMParser",
"(",
")",
",",
"bucket",
"=",
"options",
".",
"getBucket",
"(",
"id",
")",
",",
"key",
"=",
"options",
".",
"getKey",
"(",
"id",
")",
",",
"responseDoc",
"=",
"domParser",
".",
"parseFromString",
"(",
"xhr",
".",
"responseText",
",",
"\"application/xml\"",
")",
",",
"bucketEls",
"=",
"responseDoc",
".",
"getElementsByTagName",
"(",
"\"Bucket\"",
")",
",",
"keyEls",
"=",
"responseDoc",
".",
"getElementsByTagName",
"(",
"\"Key\"",
")",
";",
"delete",
"pendingCompleteRequests",
"[",
"id",
"]",
";",
"options",
".",
"log",
"(",
"qq",
".",
"format",
"(",
"\"Complete response status {}, body = {}\"",
",",
"xhr",
".",
"status",
",",
"xhr",
".",
"responseText",
")",
")",
";",
"// If the base requester has determine this a failure, give up.",
"if",
"(",
"isError",
")",
"{",
"options",
".",
"log",
"(",
"qq",
".",
"format",
"(",
"\"Complete Multipart Upload request for {} failed with status {}.\"",
",",
"id",
",",
"xhr",
".",
"status",
")",
",",
"\"error\"",
")",
";",
"}",
"else",
"{",
"// Make sure the correct bucket and key has been specified in the XML response from AWS.",
"if",
"(",
"bucketEls",
".",
"length",
"&&",
"keyEls",
".",
"length",
")",
"{",
"if",
"(",
"bucketEls",
"[",
"0",
"]",
".",
"textContent",
"!==",
"bucket",
")",
"{",
"isError",
"=",
"true",
";",
"options",
".",
"log",
"(",
"qq",
".",
"format",
"(",
"\"Wrong bucket in response to Complete Multipart Upload request for {}.\"",
",",
"id",
")",
",",
"\"error\"",
")",
";",
"}",
"// TODO Compare key name from response w/ expected key name if AWS ever fixes the encoding of key names in this response.",
"}",
"else",
"{",
"isError",
"=",
"true",
";",
"options",
".",
"log",
"(",
"qq",
".",
"format",
"(",
"\"Missing bucket and/or key in response to Complete Multipart Upload request for {}.\"",
",",
"id",
")",
",",
"\"error\"",
")",
";",
"}",
"}",
"if",
"(",
"isError",
")",
"{",
"promise",
".",
"failure",
"(",
"\"Problem combining the file parts!\"",
",",
"xhr",
")",
";",
"}",
"else",
"{",
"promise",
".",
"success",
"(",
"{",
"}",
",",
"xhr",
")",
";",
"}",
"}"
] | Called by the base ajax requester when the response has been received. We definitively determine here if the
"Complete MPU" request has been a success or not.
@param id ID associated with the file.
@param xhr `XMLHttpRequest` object containing the response, among other things.
@param isError A boolean indicating success or failure according to the base ajax requester (primarily based on status code). | [
"Called",
"by",
"the",
"base",
"ajax",
"requester",
"when",
"the",
"response",
"has",
"been",
"received",
".",
"We",
"definitively",
"determine",
"here",
"if",
"the",
"Complete",
"MPU",
"request",
"has",
"been",
"a",
"success",
"or",
"not",
"."
] | 057cc83a7e7657d032a75cf4a6b3612c7b4191da | https://github.com/FineUploader/fine-uploader/blob/057cc83a7e7657d032a75cf4a6b3612c7b4191da/client/js/s3/multipart.complete.ajax.requester.js#L69-L108 |
5,557 | FineUploader/fine-uploader | client/js/s3/multipart.complete.ajax.requester.js | function(id, uploadId, etagEntries) {
var promise = new qq.Promise(),
body = getCompleteRequestBody(etagEntries);
getHeaders(id, uploadId, body).then(function(headers, endOfUrl) {
options.log("Submitting S3 complete multipart upload request for " + id);
pendingCompleteRequests[id] = promise;
delete headers["Content-Type"];
requester.initTransport(id)
.withPath(endOfUrl)
.withHeaders(headers)
.withPayload(body)
.send();
}, promise.failure);
return promise;
} | javascript | function(id, uploadId, etagEntries) {
var promise = new qq.Promise(),
body = getCompleteRequestBody(etagEntries);
getHeaders(id, uploadId, body).then(function(headers, endOfUrl) {
options.log("Submitting S3 complete multipart upload request for " + id);
pendingCompleteRequests[id] = promise;
delete headers["Content-Type"];
requester.initTransport(id)
.withPath(endOfUrl)
.withHeaders(headers)
.withPayload(body)
.send();
}, promise.failure);
return promise;
} | [
"function",
"(",
"id",
",",
"uploadId",
",",
"etagEntries",
")",
"{",
"var",
"promise",
"=",
"new",
"qq",
".",
"Promise",
"(",
")",
",",
"body",
"=",
"getCompleteRequestBody",
"(",
"etagEntries",
")",
";",
"getHeaders",
"(",
"id",
",",
"uploadId",
",",
"body",
")",
".",
"then",
"(",
"function",
"(",
"headers",
",",
"endOfUrl",
")",
"{",
"options",
".",
"log",
"(",
"\"Submitting S3 complete multipart upload request for \"",
"+",
"id",
")",
";",
"pendingCompleteRequests",
"[",
"id",
"]",
"=",
"promise",
";",
"delete",
"headers",
"[",
"\"Content-Type\"",
"]",
";",
"requester",
".",
"initTransport",
"(",
"id",
")",
".",
"withPath",
"(",
"endOfUrl",
")",
".",
"withHeaders",
"(",
"headers",
")",
".",
"withPayload",
"(",
"body",
")",
".",
"send",
"(",
")",
";",
"}",
",",
"promise",
".",
"failure",
")",
";",
"return",
"promise",
";",
"}"
] | Sends the "Complete" request and fulfills the returned promise when the success of this request is known.
@param id ID associated with the file.
@param uploadId AWS uploadId for this file
@param etagEntries Array of objects containing `etag` values and their associated `part` numbers.
@returns {qq.Promise} | [
"Sends",
"the",
"Complete",
"request",
"and",
"fulfills",
"the",
"returned",
"promise",
"when",
"the",
"success",
"of",
"this",
"request",
"is",
"known",
"."
] | 057cc83a7e7657d032a75cf4a6b3612c7b4191da | https://github.com/FineUploader/fine-uploader/blob/057cc83a7e7657d032a75cf4a6b3612c7b4191da/client/js/s3/multipart.complete.ajax.requester.js#L165-L183 |
|
5,558 | FineUploader/fine-uploader | client/js/identify.js | function() {
var self = this,
identifier = new qq.Promise(),
previewable = false,
name = fileOrBlob.name === undefined ? "blob" : fileOrBlob.name;
log(qq.format("Attempting to determine if {} can be rendered in this browser", name));
log("First pass: check type attribute of blob object.");
if (this.isPreviewableSync()) {
log("Second pass: check for magic bytes in file header.");
qq.readBlobToHex(fileOrBlob, 0, 4).then(function(hex) {
qq.each(self.PREVIEWABLE_MIME_TYPES, function(mime, bytes) {
if (isIdentifiable(bytes, hex)) {
// Safari is the only supported browser that can deal with TIFFs natively,
// so, if this is a TIFF and the UA isn't Safari, declare this file "non-previewable".
if (mime !== "image/tiff" || qq.supportedFeatures.tiffPreviews) {
previewable = true;
identifier.success(mime);
}
return false;
}
});
log(qq.format("'{}' is {} able to be rendered in this browser", name, previewable ? "" : "NOT"));
if (!previewable) {
identifier.failure();
}
},
function() {
log("Error reading file w/ name '" + name + "'. Not able to be rendered in this browser.");
identifier.failure();
});
}
else {
identifier.failure();
}
return identifier;
} | javascript | function() {
var self = this,
identifier = new qq.Promise(),
previewable = false,
name = fileOrBlob.name === undefined ? "blob" : fileOrBlob.name;
log(qq.format("Attempting to determine if {} can be rendered in this browser", name));
log("First pass: check type attribute of blob object.");
if (this.isPreviewableSync()) {
log("Second pass: check for magic bytes in file header.");
qq.readBlobToHex(fileOrBlob, 0, 4).then(function(hex) {
qq.each(self.PREVIEWABLE_MIME_TYPES, function(mime, bytes) {
if (isIdentifiable(bytes, hex)) {
// Safari is the only supported browser that can deal with TIFFs natively,
// so, if this is a TIFF and the UA isn't Safari, declare this file "non-previewable".
if (mime !== "image/tiff" || qq.supportedFeatures.tiffPreviews) {
previewable = true;
identifier.success(mime);
}
return false;
}
});
log(qq.format("'{}' is {} able to be rendered in this browser", name, previewable ? "" : "NOT"));
if (!previewable) {
identifier.failure();
}
},
function() {
log("Error reading file w/ name '" + name + "'. Not able to be rendered in this browser.");
identifier.failure();
});
}
else {
identifier.failure();
}
return identifier;
} | [
"function",
"(",
")",
"{",
"var",
"self",
"=",
"this",
",",
"identifier",
"=",
"new",
"qq",
".",
"Promise",
"(",
")",
",",
"previewable",
"=",
"false",
",",
"name",
"=",
"fileOrBlob",
".",
"name",
"===",
"undefined",
"?",
"\"blob\"",
":",
"fileOrBlob",
".",
"name",
";",
"log",
"(",
"qq",
".",
"format",
"(",
"\"Attempting to determine if {} can be rendered in this browser\"",
",",
"name",
")",
")",
";",
"log",
"(",
"\"First pass: check type attribute of blob object.\"",
")",
";",
"if",
"(",
"this",
".",
"isPreviewableSync",
"(",
")",
")",
"{",
"log",
"(",
"\"Second pass: check for magic bytes in file header.\"",
")",
";",
"qq",
".",
"readBlobToHex",
"(",
"fileOrBlob",
",",
"0",
",",
"4",
")",
".",
"then",
"(",
"function",
"(",
"hex",
")",
"{",
"qq",
".",
"each",
"(",
"self",
".",
"PREVIEWABLE_MIME_TYPES",
",",
"function",
"(",
"mime",
",",
"bytes",
")",
"{",
"if",
"(",
"isIdentifiable",
"(",
"bytes",
",",
"hex",
")",
")",
"{",
"// Safari is the only supported browser that can deal with TIFFs natively,",
"// so, if this is a TIFF and the UA isn't Safari, declare this file \"non-previewable\".",
"if",
"(",
"mime",
"!==",
"\"image/tiff\"",
"||",
"qq",
".",
"supportedFeatures",
".",
"tiffPreviews",
")",
"{",
"previewable",
"=",
"true",
";",
"identifier",
".",
"success",
"(",
"mime",
")",
";",
"}",
"return",
"false",
";",
"}",
"}",
")",
";",
"log",
"(",
"qq",
".",
"format",
"(",
"\"'{}' is {} able to be rendered in this browser\"",
",",
"name",
",",
"previewable",
"?",
"\"\"",
":",
"\"NOT\"",
")",
")",
";",
"if",
"(",
"!",
"previewable",
")",
"{",
"identifier",
".",
"failure",
"(",
")",
";",
"}",
"}",
",",
"function",
"(",
")",
"{",
"log",
"(",
"\"Error reading file w/ name '\"",
"+",
"name",
"+",
"\"'. Not able to be rendered in this browser.\"",
")",
";",
"identifier",
".",
"failure",
"(",
")",
";",
"}",
")",
";",
"}",
"else",
"{",
"identifier",
".",
"failure",
"(",
")",
";",
"}",
"return",
"identifier",
";",
"}"
] | Determines if a Blob can be displayed natively in the current browser. This is done by reading magic
bytes in the beginning of the file, so this is an asynchronous operation. Before we attempt to read the
file, we will examine the blob's type attribute to save CPU cycles.
@returns {qq.Promise} Promise that is fulfilled when identification is complete.
If successful, the MIME string is passed to the success handler. | [
"Determines",
"if",
"a",
"Blob",
"can",
"be",
"displayed",
"natively",
"in",
"the",
"current",
"browser",
".",
"This",
"is",
"done",
"by",
"reading",
"magic",
"bytes",
"in",
"the",
"beginning",
"of",
"the",
"file",
"so",
"this",
"is",
"an",
"asynchronous",
"operation",
".",
"Before",
"we",
"attempt",
"to",
"read",
"the",
"file",
"we",
"will",
"examine",
"the",
"blob",
"s",
"type",
"attribute",
"to",
"save",
"CPU",
"cycles",
"."
] | 057cc83a7e7657d032a75cf4a6b3612c7b4191da | https://github.com/FineUploader/fine-uploader/blob/057cc83a7e7657d032a75cf4a6b3612c7b4191da/client/js/identify.js#L28-L71 |
|
5,559 | FineUploader/fine-uploader | client/js/s3/s3.xhr.upload.handler.js | function(id, xhr, chunkIdx) {
var response = upload.response.parse(id, xhr),
etag;
if (response.success) {
etag = xhr.getResponseHeader("ETag");
if (!handler._getPersistableData(id).etags) {
handler._getPersistableData(id).etags = [];
}
handler._getPersistableData(id).etags.push({part: chunkIdx + 1, etag: etag});
}
} | javascript | function(id, xhr, chunkIdx) {
var response = upload.response.parse(id, xhr),
etag;
if (response.success) {
etag = xhr.getResponseHeader("ETag");
if (!handler._getPersistableData(id).etags) {
handler._getPersistableData(id).etags = [];
}
handler._getPersistableData(id).etags.push({part: chunkIdx + 1, etag: etag});
}
} | [
"function",
"(",
"id",
",",
"xhr",
",",
"chunkIdx",
")",
"{",
"var",
"response",
"=",
"upload",
".",
"response",
".",
"parse",
"(",
"id",
",",
"xhr",
")",
",",
"etag",
";",
"if",
"(",
"response",
".",
"success",
")",
"{",
"etag",
"=",
"xhr",
".",
"getResponseHeader",
"(",
"\"ETag\"",
")",
";",
"if",
"(",
"!",
"handler",
".",
"_getPersistableData",
"(",
"id",
")",
".",
"etags",
")",
"{",
"handler",
".",
"_getPersistableData",
"(",
"id",
")",
".",
"etags",
"=",
"[",
"]",
";",
"}",
"handler",
".",
"_getPersistableData",
"(",
"id",
")",
".",
"etags",
".",
"push",
"(",
"{",
"part",
":",
"chunkIdx",
"+",
"1",
",",
"etag",
":",
"etag",
"}",
")",
";",
"}",
"}"
] | The last step in handling a chunked upload. This is called after each chunk has been sent. The request may be successful, or not. If it was successful, we must extract the "ETag" element in the XML response and store that along with the associated part number. We need these items to "Complete" the multipart upload after all chunks have been successfully sent. | [
"The",
"last",
"step",
"in",
"handling",
"a",
"chunked",
"upload",
".",
"This",
"is",
"called",
"after",
"each",
"chunk",
"has",
"been",
"sent",
".",
"The",
"request",
"may",
"be",
"successful",
"or",
"not",
".",
"If",
"it",
"was",
"successful",
"we",
"must",
"extract",
"the",
"ETag",
"element",
"in",
"the",
"XML",
"response",
"and",
"store",
"that",
"along",
"with",
"the",
"associated",
"part",
"number",
".",
"We",
"need",
"these",
"items",
"to",
"Complete",
"the",
"multipart",
"upload",
"after",
"all",
"chunks",
"have",
"been",
"successfully",
"sent",
"."
] | 057cc83a7e7657d032a75cf4a6b3612c7b4191da | https://github.com/FineUploader/fine-uploader/blob/057cc83a7e7657d032a75cf4a6b3612c7b4191da/client/js/s3/s3.xhr.upload.handler.js#L56-L68 |
|
5,560 | FineUploader/fine-uploader | client/js/s3/s3.xhr.upload.handler.js | function(awsParams) {
xhr.open("POST", url, true);
qq.obj2FormData(awsParams, formData);
// AWS requires the file field be named "file".
formData.append("file", fileOrBlob);
promise.success(formData);
} | javascript | function(awsParams) {
xhr.open("POST", url, true);
qq.obj2FormData(awsParams, formData);
// AWS requires the file field be named "file".
formData.append("file", fileOrBlob);
promise.success(formData);
} | [
"function",
"(",
"awsParams",
")",
"{",
"xhr",
".",
"open",
"(",
"\"POST\"",
",",
"url",
",",
"true",
")",
";",
"qq",
".",
"obj2FormData",
"(",
"awsParams",
",",
"formData",
")",
";",
"// AWS requires the file field be named \"file\".",
"formData",
".",
"append",
"(",
"\"file\"",
",",
"fileOrBlob",
")",
";",
"promise",
".",
"success",
"(",
"formData",
")",
";",
"}"
] | Success - all params determined | [
"Success",
"-",
"all",
"params",
"determined"
] | 057cc83a7e7657d032a75cf4a6b3612c7b4191da | https://github.com/FineUploader/fine-uploader/blob/057cc83a7e7657d032a75cf4a6b3612c7b4191da/client/js/s3/s3.xhr.upload.handler.js#L349-L358 |
|
5,561 | FineUploader/fine-uploader | client/js/s3/s3.xhr.upload.handler.js | function(awsResponseXml) {
var parser = new DOMParser(),
parsedDoc = parser.parseFromString(awsResponseXml, "application/xml"),
errorEls = parsedDoc.getElementsByTagName("Error"),
errorDetails = {},
codeEls, messageEls;
if (errorEls.length) {
codeEls = parsedDoc.getElementsByTagName("Code");
messageEls = parsedDoc.getElementsByTagName("Message");
if (messageEls.length) {
errorDetails.message = messageEls[0].textContent;
}
if (codeEls.length) {
errorDetails.code = codeEls[0].textContent;
}
return errorDetails;
}
} | javascript | function(awsResponseXml) {
var parser = new DOMParser(),
parsedDoc = parser.parseFromString(awsResponseXml, "application/xml"),
errorEls = parsedDoc.getElementsByTagName("Error"),
errorDetails = {},
codeEls, messageEls;
if (errorEls.length) {
codeEls = parsedDoc.getElementsByTagName("Code");
messageEls = parsedDoc.getElementsByTagName("Message");
if (messageEls.length) {
errorDetails.message = messageEls[0].textContent;
}
if (codeEls.length) {
errorDetails.code = codeEls[0].textContent;
}
return errorDetails;
}
} | [
"function",
"(",
"awsResponseXml",
")",
"{",
"var",
"parser",
"=",
"new",
"DOMParser",
"(",
")",
",",
"parsedDoc",
"=",
"parser",
".",
"parseFromString",
"(",
"awsResponseXml",
",",
"\"application/xml\"",
")",
",",
"errorEls",
"=",
"parsedDoc",
".",
"getElementsByTagName",
"(",
"\"Error\"",
")",
",",
"errorDetails",
"=",
"{",
"}",
",",
"codeEls",
",",
"messageEls",
";",
"if",
"(",
"errorEls",
".",
"length",
")",
"{",
"codeEls",
"=",
"parsedDoc",
".",
"getElementsByTagName",
"(",
"\"Code\"",
")",
";",
"messageEls",
"=",
"parsedDoc",
".",
"getElementsByTagName",
"(",
"\"Message\"",
")",
";",
"if",
"(",
"messageEls",
".",
"length",
")",
"{",
"errorDetails",
".",
"message",
"=",
"messageEls",
"[",
"0",
"]",
".",
"textContent",
";",
"}",
"if",
"(",
"codeEls",
".",
"length",
")",
"{",
"errorDetails",
".",
"code",
"=",
"codeEls",
"[",
"0",
"]",
".",
"textContent",
";",
"}",
"return",
"errorDetails",
";",
"}",
"}"
] | This parses an XML response by extracting the "Message" and "Code" elements that accompany AWS error responses.
@param awsResponseXml XML response from AWS
@returns {object} Object w/ `code` and `message` properties, or undefined if we couldn't find error info in the XML document. | [
"This",
"parses",
"an",
"XML",
"response",
"by",
"extracting",
"the",
"Message",
"and",
"Code",
"elements",
"that",
"accompany",
"AWS",
"error",
"responses",
"."
] | 057cc83a7e7657d032a75cf4a6b3612c7b4191da | https://github.com/FineUploader/fine-uploader/blob/057cc83a7e7657d032a75cf4a6b3612c7b4191da/client/js/s3/s3.xhr.upload.handler.js#L507-L528 |
|
5,562 | FineUploader/fine-uploader | client/js/s3/multipart.abort.ajax.requester.js | function(id, uploadId) {
getHeaders(id, uploadId).then(function(headers, endOfUrl) {
options.log("Submitting S3 Abort multipart upload request for " + id);
requester.initTransport(id)
.withPath(endOfUrl)
.withHeaders(headers)
.send();
});
} | javascript | function(id, uploadId) {
getHeaders(id, uploadId).then(function(headers, endOfUrl) {
options.log("Submitting S3 Abort multipart upload request for " + id);
requester.initTransport(id)
.withPath(endOfUrl)
.withHeaders(headers)
.send();
});
} | [
"function",
"(",
"id",
",",
"uploadId",
")",
"{",
"getHeaders",
"(",
"id",
",",
"uploadId",
")",
".",
"then",
"(",
"function",
"(",
"headers",
",",
"endOfUrl",
")",
"{",
"options",
".",
"log",
"(",
"\"Submitting S3 Abort multipart upload request for \"",
"+",
"id",
")",
";",
"requester",
".",
"initTransport",
"(",
"id",
")",
".",
"withPath",
"(",
"endOfUrl",
")",
".",
"withHeaders",
"(",
"headers",
")",
".",
"send",
"(",
")",
";",
"}",
")",
";",
"}"
] | Sends the "Abort" request.
@param id ID associated with the file.
@param uploadId AWS uploadId for this file | [
"Sends",
"the",
"Abort",
"request",
"."
] | 057cc83a7e7657d032a75cf4a6b3612c7b4191da | https://github.com/FineUploader/fine-uploader/blob/057cc83a7e7657d032a75cf4a6b3612c7b4191da/client/js/s3/multipart.abort.ajax.requester.js#L113-L121 |
|
5,563 | FineUploader/fine-uploader | client/js/uploader.basic.api.js | function(fileId, imgOrCanvas, maxSize, fromServer, customResizeFunction) {
var promiseToReturn = new qq.Promise(),
fileOrUrl, options;
if (this._imageGenerator) {
fileOrUrl = this._thumbnailUrls[fileId];
options = {
customResizeFunction: customResizeFunction,
maxSize: maxSize > 0 ? maxSize : null,
scale: maxSize > 0
};
// If client-side preview generation is possible
// and we are not specifically looking for the image URl returned by the server...
if (!fromServer && qq.supportedFeatures.imagePreviews) {
fileOrUrl = this.getFile(fileId);
}
/* jshint eqeqeq:false,eqnull:true */
if (fileOrUrl == null) {
promiseToReturn.failure({container: imgOrCanvas, error: "File or URL not found."});
}
else {
this._imageGenerator.generate(fileOrUrl, imgOrCanvas, options).then(
function success(modifiedContainer) {
promiseToReturn.success(modifiedContainer);
},
function failure(container, reason) {
promiseToReturn.failure({container: container, error: reason || "Problem generating thumbnail"});
}
);
}
}
else {
promiseToReturn.failure({container: imgOrCanvas, error: "Missing image generator module"});
}
return promiseToReturn;
} | javascript | function(fileId, imgOrCanvas, maxSize, fromServer, customResizeFunction) {
var promiseToReturn = new qq.Promise(),
fileOrUrl, options;
if (this._imageGenerator) {
fileOrUrl = this._thumbnailUrls[fileId];
options = {
customResizeFunction: customResizeFunction,
maxSize: maxSize > 0 ? maxSize : null,
scale: maxSize > 0
};
// If client-side preview generation is possible
// and we are not specifically looking for the image URl returned by the server...
if (!fromServer && qq.supportedFeatures.imagePreviews) {
fileOrUrl = this.getFile(fileId);
}
/* jshint eqeqeq:false,eqnull:true */
if (fileOrUrl == null) {
promiseToReturn.failure({container: imgOrCanvas, error: "File or URL not found."});
}
else {
this._imageGenerator.generate(fileOrUrl, imgOrCanvas, options).then(
function success(modifiedContainer) {
promiseToReturn.success(modifiedContainer);
},
function failure(container, reason) {
promiseToReturn.failure({container: container, error: reason || "Problem generating thumbnail"});
}
);
}
}
else {
promiseToReturn.failure({container: imgOrCanvas, error: "Missing image generator module"});
}
return promiseToReturn;
} | [
"function",
"(",
"fileId",
",",
"imgOrCanvas",
",",
"maxSize",
",",
"fromServer",
",",
"customResizeFunction",
")",
"{",
"var",
"promiseToReturn",
"=",
"new",
"qq",
".",
"Promise",
"(",
")",
",",
"fileOrUrl",
",",
"options",
";",
"if",
"(",
"this",
".",
"_imageGenerator",
")",
"{",
"fileOrUrl",
"=",
"this",
".",
"_thumbnailUrls",
"[",
"fileId",
"]",
";",
"options",
"=",
"{",
"customResizeFunction",
":",
"customResizeFunction",
",",
"maxSize",
":",
"maxSize",
">",
"0",
"?",
"maxSize",
":",
"null",
",",
"scale",
":",
"maxSize",
">",
"0",
"}",
";",
"// If client-side preview generation is possible",
"// and we are not specifically looking for the image URl returned by the server...",
"if",
"(",
"!",
"fromServer",
"&&",
"qq",
".",
"supportedFeatures",
".",
"imagePreviews",
")",
"{",
"fileOrUrl",
"=",
"this",
".",
"getFile",
"(",
"fileId",
")",
";",
"}",
"/* jshint eqeqeq:false,eqnull:true */",
"if",
"(",
"fileOrUrl",
"==",
"null",
")",
"{",
"promiseToReturn",
".",
"failure",
"(",
"{",
"container",
":",
"imgOrCanvas",
",",
"error",
":",
"\"File or URL not found.\"",
"}",
")",
";",
"}",
"else",
"{",
"this",
".",
"_imageGenerator",
".",
"generate",
"(",
"fileOrUrl",
",",
"imgOrCanvas",
",",
"options",
")",
".",
"then",
"(",
"function",
"success",
"(",
"modifiedContainer",
")",
"{",
"promiseToReturn",
".",
"success",
"(",
"modifiedContainer",
")",
";",
"}",
",",
"function",
"failure",
"(",
"container",
",",
"reason",
")",
"{",
"promiseToReturn",
".",
"failure",
"(",
"{",
"container",
":",
"container",
",",
"error",
":",
"reason",
"||",
"\"Problem generating thumbnail\"",
"}",
")",
";",
"}",
")",
";",
"}",
"}",
"else",
"{",
"promiseToReturn",
".",
"failure",
"(",
"{",
"container",
":",
"imgOrCanvas",
",",
"error",
":",
"\"Missing image generator module\"",
"}",
")",
";",
"}",
"return",
"promiseToReturn",
";",
"}"
] | Generate a variable size thumbnail on an img or canvas, returning a promise that is fulfilled when the attempt completes. Thumbnail can either be based off of a URL for an image returned by the server in the upload response, or the associated `Blob`. | [
"Generate",
"a",
"variable",
"size",
"thumbnail",
"on",
"an",
"img",
"or",
"canvas",
"returning",
"a",
"promise",
"that",
"is",
"fulfilled",
"when",
"the",
"attempt",
"completes",
".",
"Thumbnail",
"can",
"either",
"be",
"based",
"off",
"of",
"a",
"URL",
"for",
"an",
"image",
"returned",
"by",
"the",
"server",
"in",
"the",
"upload",
"response",
"or",
"the",
"associated",
"Blob",
"."
] | 057cc83a7e7657d032a75cf4a6b3612c7b4191da | https://github.com/FineUploader/fine-uploader/blob/057cc83a7e7657d032a75cf4a6b3612c7b4191da/client/js/uploader.basic.api.js#L173-L212 |
|
5,564 | FineUploader/fine-uploader | client/js/uploader.basic.api.js | function(id) {
var uploadDataEntry = this.getUploads({id: id}),
parentId = null;
if (uploadDataEntry) {
if (uploadDataEntry.parentId !== undefined) {
parentId = uploadDataEntry.parentId;
}
}
return parentId;
} | javascript | function(id) {
var uploadDataEntry = this.getUploads({id: id}),
parentId = null;
if (uploadDataEntry) {
if (uploadDataEntry.parentId !== undefined) {
parentId = uploadDataEntry.parentId;
}
}
return parentId;
} | [
"function",
"(",
"id",
")",
"{",
"var",
"uploadDataEntry",
"=",
"this",
".",
"getUploads",
"(",
"{",
"id",
":",
"id",
"}",
")",
",",
"parentId",
"=",
"null",
";",
"if",
"(",
"uploadDataEntry",
")",
"{",
"if",
"(",
"uploadDataEntry",
".",
"parentId",
"!==",
"undefined",
")",
"{",
"parentId",
"=",
"uploadDataEntry",
".",
"parentId",
";",
"}",
"}",
"return",
"parentId",
";",
"}"
] | Parent ID for a specific file, or null if this is the parent, or if it has no parent. | [
"Parent",
"ID",
"for",
"a",
"specific",
"file",
"or",
"null",
"if",
"this",
"is",
"the",
"parent",
"or",
"if",
"it",
"has",
"no",
"parent",
"."
] | 057cc83a7e7657d032a75cf4a6b3612c7b4191da | https://github.com/FineUploader/fine-uploader/blob/057cc83a7e7657d032a75cf4a6b3612c7b4191da/client/js/uploader.basic.api.js#L252-L263 |
|
5,565 | FineUploader/fine-uploader | client/js/uploader.basic.api.js | function(spec) {
var self = this,
acceptFiles = spec.accept || this._options.validation.acceptFiles,
allowedExtensions = spec.allowedExtensions || this._options.validation.allowedExtensions,
button;
function allowMultiple() {
if (qq.supportedFeatures.ajaxUploading) {
// Workaround for bug in iOS7+ (see #1039)
if (self._options.workarounds.iosEmptyVideos &&
qq.ios() &&
!qq.ios6() &&
self._isAllowedExtension(allowedExtensions, ".mov")) {
return false;
}
if (spec.multiple === undefined) {
return self._options.multiple;
}
return spec.multiple;
}
return false;
}
button = new qq.UploadButton({
acceptFiles: acceptFiles,
element: spec.element,
focusClass: this._options.classes.buttonFocus,
folders: spec.folders,
hoverClass: this._options.classes.buttonHover,
ios8BrowserCrashWorkaround: this._options.workarounds.ios8BrowserCrash,
multiple: allowMultiple(),
name: this._options.request.inputName,
onChange: function(input) {
self._onInputChange(input);
},
title: spec.title == null ? this._options.text.fileInputTitle : spec.title
});
this._disposeSupport.addDisposer(function() {
button.dispose();
});
self._buttons.push(button);
return button;
} | javascript | function(spec) {
var self = this,
acceptFiles = spec.accept || this._options.validation.acceptFiles,
allowedExtensions = spec.allowedExtensions || this._options.validation.allowedExtensions,
button;
function allowMultiple() {
if (qq.supportedFeatures.ajaxUploading) {
// Workaround for bug in iOS7+ (see #1039)
if (self._options.workarounds.iosEmptyVideos &&
qq.ios() &&
!qq.ios6() &&
self._isAllowedExtension(allowedExtensions, ".mov")) {
return false;
}
if (spec.multiple === undefined) {
return self._options.multiple;
}
return spec.multiple;
}
return false;
}
button = new qq.UploadButton({
acceptFiles: acceptFiles,
element: spec.element,
focusClass: this._options.classes.buttonFocus,
folders: spec.folders,
hoverClass: this._options.classes.buttonHover,
ios8BrowserCrashWorkaround: this._options.workarounds.ios8BrowserCrash,
multiple: allowMultiple(),
name: this._options.request.inputName,
onChange: function(input) {
self._onInputChange(input);
},
title: spec.title == null ? this._options.text.fileInputTitle : spec.title
});
this._disposeSupport.addDisposer(function() {
button.dispose();
});
self._buttons.push(button);
return button;
} | [
"function",
"(",
"spec",
")",
"{",
"var",
"self",
"=",
"this",
",",
"acceptFiles",
"=",
"spec",
".",
"accept",
"||",
"this",
".",
"_options",
".",
"validation",
".",
"acceptFiles",
",",
"allowedExtensions",
"=",
"spec",
".",
"allowedExtensions",
"||",
"this",
".",
"_options",
".",
"validation",
".",
"allowedExtensions",
",",
"button",
";",
"function",
"allowMultiple",
"(",
")",
"{",
"if",
"(",
"qq",
".",
"supportedFeatures",
".",
"ajaxUploading",
")",
"{",
"// Workaround for bug in iOS7+ (see #1039)",
"if",
"(",
"self",
".",
"_options",
".",
"workarounds",
".",
"iosEmptyVideos",
"&&",
"qq",
".",
"ios",
"(",
")",
"&&",
"!",
"qq",
".",
"ios6",
"(",
")",
"&&",
"self",
".",
"_isAllowedExtension",
"(",
"allowedExtensions",
",",
"\".mov\"",
")",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"spec",
".",
"multiple",
"===",
"undefined",
")",
"{",
"return",
"self",
".",
"_options",
".",
"multiple",
";",
"}",
"return",
"spec",
".",
"multiple",
";",
"}",
"return",
"false",
";",
"}",
"button",
"=",
"new",
"qq",
".",
"UploadButton",
"(",
"{",
"acceptFiles",
":",
"acceptFiles",
",",
"element",
":",
"spec",
".",
"element",
",",
"focusClass",
":",
"this",
".",
"_options",
".",
"classes",
".",
"buttonFocus",
",",
"folders",
":",
"spec",
".",
"folders",
",",
"hoverClass",
":",
"this",
".",
"_options",
".",
"classes",
".",
"buttonHover",
",",
"ios8BrowserCrashWorkaround",
":",
"this",
".",
"_options",
".",
"workarounds",
".",
"ios8BrowserCrash",
",",
"multiple",
":",
"allowMultiple",
"(",
")",
",",
"name",
":",
"this",
".",
"_options",
".",
"request",
".",
"inputName",
",",
"onChange",
":",
"function",
"(",
"input",
")",
"{",
"self",
".",
"_onInputChange",
"(",
"input",
")",
";",
"}",
",",
"title",
":",
"spec",
".",
"title",
"==",
"null",
"?",
"this",
".",
"_options",
".",
"text",
".",
"fileInputTitle",
":",
"spec",
".",
"title",
"}",
")",
";",
"this",
".",
"_disposeSupport",
".",
"addDisposer",
"(",
"function",
"(",
")",
"{",
"button",
".",
"dispose",
"(",
")",
";",
"}",
")",
";",
"self",
".",
"_buttons",
".",
"push",
"(",
"button",
")",
";",
"return",
"button",
";",
"}"
] | Generate a tracked upload button.
@param spec Object containing a required `element` property
along with optional `multiple`, `accept`, and `folders`.
@returns {qq.UploadButton}
@private | [
"Generate",
"a",
"tracked",
"upload",
"button",
"."
] | 057cc83a7e7657d032a75cf4a6b3612c7b4191da | https://github.com/FineUploader/fine-uploader/blob/057cc83a7e7657d032a75cf4a6b3612c7b4191da/client/js/uploader.basic.api.js#L670-L719 |
|
5,566 | FineUploader/fine-uploader | client/js/uploader.basic.api.js | function(buttonOrFileInputOrFile) {
var inputs, fileInput,
fileBlobOrInput = buttonOrFileInputOrFile;
// We want the reference file/blob here if this is a proxy (a file that will be generated on-demand later)
if (fileBlobOrInput instanceof qq.BlobProxy) {
fileBlobOrInput = fileBlobOrInput.referenceBlob;
}
// If the item is a `Blob` it will never be associated with a button or drop zone.
if (fileBlobOrInput && !qq.isBlob(fileBlobOrInput)) {
if (qq.isFile(fileBlobOrInput)) {
return fileBlobOrInput.qqButtonId;
}
else if (fileBlobOrInput.tagName.toLowerCase() === "input" &&
fileBlobOrInput.type.toLowerCase() === "file") {
return fileBlobOrInput.getAttribute(qq.UploadButton.BUTTON_ID_ATTR_NAME);
}
inputs = fileBlobOrInput.getElementsByTagName("input");
qq.each(inputs, function(idx, input) {
if (input.getAttribute("type") === "file") {
fileInput = input;
return false;
}
});
if (fileInput) {
return fileInput.getAttribute(qq.UploadButton.BUTTON_ID_ATTR_NAME);
}
}
} | javascript | function(buttonOrFileInputOrFile) {
var inputs, fileInput,
fileBlobOrInput = buttonOrFileInputOrFile;
// We want the reference file/blob here if this is a proxy (a file that will be generated on-demand later)
if (fileBlobOrInput instanceof qq.BlobProxy) {
fileBlobOrInput = fileBlobOrInput.referenceBlob;
}
// If the item is a `Blob` it will never be associated with a button or drop zone.
if (fileBlobOrInput && !qq.isBlob(fileBlobOrInput)) {
if (qq.isFile(fileBlobOrInput)) {
return fileBlobOrInput.qqButtonId;
}
else if (fileBlobOrInput.tagName.toLowerCase() === "input" &&
fileBlobOrInput.type.toLowerCase() === "file") {
return fileBlobOrInput.getAttribute(qq.UploadButton.BUTTON_ID_ATTR_NAME);
}
inputs = fileBlobOrInput.getElementsByTagName("input");
qq.each(inputs, function(idx, input) {
if (input.getAttribute("type") === "file") {
fileInput = input;
return false;
}
});
if (fileInput) {
return fileInput.getAttribute(qq.UploadButton.BUTTON_ID_ATTR_NAME);
}
}
} | [
"function",
"(",
"buttonOrFileInputOrFile",
")",
"{",
"var",
"inputs",
",",
"fileInput",
",",
"fileBlobOrInput",
"=",
"buttonOrFileInputOrFile",
";",
"// We want the reference file/blob here if this is a proxy (a file that will be generated on-demand later)",
"if",
"(",
"fileBlobOrInput",
"instanceof",
"qq",
".",
"BlobProxy",
")",
"{",
"fileBlobOrInput",
"=",
"fileBlobOrInput",
".",
"referenceBlob",
";",
"}",
"// If the item is a `Blob` it will never be associated with a button or drop zone.",
"if",
"(",
"fileBlobOrInput",
"&&",
"!",
"qq",
".",
"isBlob",
"(",
"fileBlobOrInput",
")",
")",
"{",
"if",
"(",
"qq",
".",
"isFile",
"(",
"fileBlobOrInput",
")",
")",
"{",
"return",
"fileBlobOrInput",
".",
"qqButtonId",
";",
"}",
"else",
"if",
"(",
"fileBlobOrInput",
".",
"tagName",
".",
"toLowerCase",
"(",
")",
"===",
"\"input\"",
"&&",
"fileBlobOrInput",
".",
"type",
".",
"toLowerCase",
"(",
")",
"===",
"\"file\"",
")",
"{",
"return",
"fileBlobOrInput",
".",
"getAttribute",
"(",
"qq",
".",
"UploadButton",
".",
"BUTTON_ID_ATTR_NAME",
")",
";",
"}",
"inputs",
"=",
"fileBlobOrInput",
".",
"getElementsByTagName",
"(",
"\"input\"",
")",
";",
"qq",
".",
"each",
"(",
"inputs",
",",
"function",
"(",
"idx",
",",
"input",
")",
"{",
"if",
"(",
"input",
".",
"getAttribute",
"(",
"\"type\"",
")",
"===",
"\"file\"",
")",
"{",
"fileInput",
"=",
"input",
";",
"return",
"false",
";",
"}",
"}",
")",
";",
"if",
"(",
"fileInput",
")",
"{",
"return",
"fileInput",
".",
"getAttribute",
"(",
"qq",
".",
"UploadButton",
".",
"BUTTON_ID_ATTR_NAME",
")",
";",
"}",
"}",
"}"
] | Gets the internally used tracking ID for a button.
@param buttonOrFileInputOrFile `File`, `<input type="file">`, or a button container element
@returns {*} The button's ID, or undefined if no ID is recoverable
@private | [
"Gets",
"the",
"internally",
"used",
"tracking",
"ID",
"for",
"a",
"button",
"."
] | 057cc83a7e7657d032a75cf4a6b3612c7b4191da | https://github.com/FineUploader/fine-uploader/blob/057cc83a7e7657d032a75cf4a6b3612c7b4191da/client/js/uploader.basic.api.js#L942-L975 |
|
5,567 | FineUploader/fine-uploader | client/js/uploader.basic.api.js | function() {
if (this._options.camera.ios && qq.ios()) {
var acceptIosCamera = "image/*;capture=camera",
button = this._options.camera.button,
buttonId = button ? this._getButtonId(button) : this._defaultButtonId,
optionRoot = this._options;
// If we are not targeting the default button, it is an "extra" button
if (buttonId && buttonId !== this._defaultButtonId) {
optionRoot = this._extraButtonSpecs[buttonId];
}
// Camera access won't work in iOS if the `multiple` attribute is present on the file input
optionRoot.multiple = false;
// update the options
if (optionRoot.validation.acceptFiles === null) {
optionRoot.validation.acceptFiles = acceptIosCamera;
}
else {
optionRoot.validation.acceptFiles += "," + acceptIosCamera;
}
// update the already-created button
qq.each(this._buttons, function(idx, button) {
if (button.getButtonId() === buttonId) {
button.setMultiple(optionRoot.multiple);
button.setAcceptFiles(optionRoot.acceptFiles);
return false;
}
});
}
} | javascript | function() {
if (this._options.camera.ios && qq.ios()) {
var acceptIosCamera = "image/*;capture=camera",
button = this._options.camera.button,
buttonId = button ? this._getButtonId(button) : this._defaultButtonId,
optionRoot = this._options;
// If we are not targeting the default button, it is an "extra" button
if (buttonId && buttonId !== this._defaultButtonId) {
optionRoot = this._extraButtonSpecs[buttonId];
}
// Camera access won't work in iOS if the `multiple` attribute is present on the file input
optionRoot.multiple = false;
// update the options
if (optionRoot.validation.acceptFiles === null) {
optionRoot.validation.acceptFiles = acceptIosCamera;
}
else {
optionRoot.validation.acceptFiles += "," + acceptIosCamera;
}
// update the already-created button
qq.each(this._buttons, function(idx, button) {
if (button.getButtonId() === buttonId) {
button.setMultiple(optionRoot.multiple);
button.setAcceptFiles(optionRoot.acceptFiles);
return false;
}
});
}
} | [
"function",
"(",
")",
"{",
"if",
"(",
"this",
".",
"_options",
".",
"camera",
".",
"ios",
"&&",
"qq",
".",
"ios",
"(",
")",
")",
"{",
"var",
"acceptIosCamera",
"=",
"\"image/*;capture=camera\"",
",",
"button",
"=",
"this",
".",
"_options",
".",
"camera",
".",
"button",
",",
"buttonId",
"=",
"button",
"?",
"this",
".",
"_getButtonId",
"(",
"button",
")",
":",
"this",
".",
"_defaultButtonId",
",",
"optionRoot",
"=",
"this",
".",
"_options",
";",
"// If we are not targeting the default button, it is an \"extra\" button",
"if",
"(",
"buttonId",
"&&",
"buttonId",
"!==",
"this",
".",
"_defaultButtonId",
")",
"{",
"optionRoot",
"=",
"this",
".",
"_extraButtonSpecs",
"[",
"buttonId",
"]",
";",
"}",
"// Camera access won't work in iOS if the `multiple` attribute is present on the file input",
"optionRoot",
".",
"multiple",
"=",
"false",
";",
"// update the options",
"if",
"(",
"optionRoot",
".",
"validation",
".",
"acceptFiles",
"===",
"null",
")",
"{",
"optionRoot",
".",
"validation",
".",
"acceptFiles",
"=",
"acceptIosCamera",
";",
"}",
"else",
"{",
"optionRoot",
".",
"validation",
".",
"acceptFiles",
"+=",
"\",\"",
"+",
"acceptIosCamera",
";",
"}",
"// update the already-created button",
"qq",
".",
"each",
"(",
"this",
".",
"_buttons",
",",
"function",
"(",
"idx",
",",
"button",
")",
"{",
"if",
"(",
"button",
".",
"getButtonId",
"(",
")",
"===",
"buttonId",
")",
"{",
"button",
".",
"setMultiple",
"(",
"optionRoot",
".",
"multiple",
")",
";",
"button",
".",
"setAcceptFiles",
"(",
"optionRoot",
".",
"acceptFiles",
")",
";",
"return",
"false",
";",
"}",
"}",
")",
";",
"}",
"}"
] | Allows camera access on either the default or an extra button for iOS devices. | [
"Allows",
"camera",
"access",
"on",
"either",
"the",
"default",
"or",
"an",
"extra",
"button",
"for",
"iOS",
"devices",
"."
] | 057cc83a7e7657d032a75cf4a6b3612c7b4191da | https://github.com/FineUploader/fine-uploader/blob/057cc83a7e7657d032a75cf4a6b3612c7b4191da/client/js/uploader.basic.api.js#L1028-L1061 |
|
5,568 | FineUploader/fine-uploader | client/js/uploader.basic.api.js | function(spec) {
var button = this._createUploadButton({
accept: spec.validation.acceptFiles,
allowedExtensions: spec.validation.allowedExtensions,
element: spec.element,
folders: spec.folders,
multiple: spec.multiple,
title: spec.fileInputTitle
});
this._extraButtonSpecs[button.getButtonId()] = spec;
} | javascript | function(spec) {
var button = this._createUploadButton({
accept: spec.validation.acceptFiles,
allowedExtensions: spec.validation.allowedExtensions,
element: spec.element,
folders: spec.folders,
multiple: spec.multiple,
title: spec.fileInputTitle
});
this._extraButtonSpecs[button.getButtonId()] = spec;
} | [
"function",
"(",
"spec",
")",
"{",
"var",
"button",
"=",
"this",
".",
"_createUploadButton",
"(",
"{",
"accept",
":",
"spec",
".",
"validation",
".",
"acceptFiles",
",",
"allowedExtensions",
":",
"spec",
".",
"validation",
".",
"allowedExtensions",
",",
"element",
":",
"spec",
".",
"element",
",",
"folders",
":",
"spec",
".",
"folders",
",",
"multiple",
":",
"spec",
".",
"multiple",
",",
"title",
":",
"spec",
".",
"fileInputTitle",
"}",
")",
";",
"this",
".",
"_extraButtonSpecs",
"[",
"button",
".",
"getButtonId",
"(",
")",
"]",
"=",
"spec",
";",
"}"
] | Creates an extra button element | [
"Creates",
"an",
"extra",
"button",
"element"
] | 057cc83a7e7657d032a75cf4a6b3612c7b4191da | https://github.com/FineUploader/fine-uploader/blob/057cc83a7e7657d032a75cf4a6b3612c7b4191da/client/js/uploader.basic.api.js#L1192-L1203 |
|
5,569 | FineUploader/fine-uploader | client/js/uploader.basic.api.js | function(id) {
var buttonId;
if (qq.supportedFeatures.ajaxUploading) {
buttonId = this._handler.getFile(id).qqButtonId;
}
else {
buttonId = this._getButtonId(this._handler.getInput(id));
}
if (buttonId) {
this._buttonIdsForFileIds[id] = buttonId;
}
} | javascript | function(id) {
var buttonId;
if (qq.supportedFeatures.ajaxUploading) {
buttonId = this._handler.getFile(id).qqButtonId;
}
else {
buttonId = this._getButtonId(this._handler.getInput(id));
}
if (buttonId) {
this._buttonIdsForFileIds[id] = buttonId;
}
} | [
"function",
"(",
"id",
")",
"{",
"var",
"buttonId",
";",
"if",
"(",
"qq",
".",
"supportedFeatures",
".",
"ajaxUploading",
")",
"{",
"buttonId",
"=",
"this",
".",
"_handler",
".",
"getFile",
"(",
"id",
")",
".",
"qqButtonId",
";",
"}",
"else",
"{",
"buttonId",
"=",
"this",
".",
"_getButtonId",
"(",
"this",
".",
"_handler",
".",
"getInput",
"(",
"id",
")",
")",
";",
"}",
"if",
"(",
"buttonId",
")",
"{",
"this",
".",
"_buttonIdsForFileIds",
"[",
"id",
"]",
"=",
"buttonId",
";",
"}",
"}"
] | Maps a file with the button that was used to select it. | [
"Maps",
"a",
"file",
"with",
"the",
"button",
"that",
"was",
"used",
"to",
"select",
"it",
"."
] | 057cc83a7e7657d032a75cf4a6b3612c7b4191da | https://github.com/FineUploader/fine-uploader/blob/057cc83a7e7657d032a75cf4a6b3612c7b4191da/client/js/uploader.basic.api.js#L1810-L1823 |
|
5,570 | FineUploader/fine-uploader | client/js/uploader.basic.api.js | function(fileWrapper, validationDescriptor) {
var self = this,
file = (function() {
if (fileWrapper.file instanceof qq.BlobProxy) {
return fileWrapper.file.referenceBlob;
}
return fileWrapper.file;
}()),
name = validationDescriptor.name,
size = validationDescriptor.size,
buttonId = this._getButtonId(fileWrapper.file),
validationBase = this._getValidationBase(buttonId),
validityChecker = new qq.Promise();
validityChecker.then(
function() {},
function() {
self._fileOrBlobRejected(fileWrapper.id, name);
});
if (qq.isFileOrInput(file) && !this._isAllowedExtension(validationBase.allowedExtensions, name)) {
this._itemError("typeError", name, file);
return validityChecker.failure();
}
if (!this._options.validation.allowEmpty && size === 0) {
this._itemError("emptyError", name, file);
return validityChecker.failure();
}
if (size > 0 && validationBase.sizeLimit && size > validationBase.sizeLimit) {
this._itemError("sizeError", name, file);
return validityChecker.failure();
}
if (size > 0 && size < validationBase.minSizeLimit) {
this._itemError("minSizeError", name, file);
return validityChecker.failure();
}
if (qq.ImageValidation && qq.supportedFeatures.imagePreviews && qq.isFile(file)) {
new qq.ImageValidation(file, qq.bind(self.log, self)).validate(validationBase.image).then(
validityChecker.success,
function(errorCode) {
self._itemError(errorCode + "ImageError", name, file);
validityChecker.failure();
}
);
}
else {
validityChecker.success();
}
return validityChecker;
} | javascript | function(fileWrapper, validationDescriptor) {
var self = this,
file = (function() {
if (fileWrapper.file instanceof qq.BlobProxy) {
return fileWrapper.file.referenceBlob;
}
return fileWrapper.file;
}()),
name = validationDescriptor.name,
size = validationDescriptor.size,
buttonId = this._getButtonId(fileWrapper.file),
validationBase = this._getValidationBase(buttonId),
validityChecker = new qq.Promise();
validityChecker.then(
function() {},
function() {
self._fileOrBlobRejected(fileWrapper.id, name);
});
if (qq.isFileOrInput(file) && !this._isAllowedExtension(validationBase.allowedExtensions, name)) {
this._itemError("typeError", name, file);
return validityChecker.failure();
}
if (!this._options.validation.allowEmpty && size === 0) {
this._itemError("emptyError", name, file);
return validityChecker.failure();
}
if (size > 0 && validationBase.sizeLimit && size > validationBase.sizeLimit) {
this._itemError("sizeError", name, file);
return validityChecker.failure();
}
if (size > 0 && size < validationBase.minSizeLimit) {
this._itemError("minSizeError", name, file);
return validityChecker.failure();
}
if (qq.ImageValidation && qq.supportedFeatures.imagePreviews && qq.isFile(file)) {
new qq.ImageValidation(file, qq.bind(self.log, self)).validate(validationBase.image).then(
validityChecker.success,
function(errorCode) {
self._itemError(errorCode + "ImageError", name, file);
validityChecker.failure();
}
);
}
else {
validityChecker.success();
}
return validityChecker;
} | [
"function",
"(",
"fileWrapper",
",",
"validationDescriptor",
")",
"{",
"var",
"self",
"=",
"this",
",",
"file",
"=",
"(",
"function",
"(",
")",
"{",
"if",
"(",
"fileWrapper",
".",
"file",
"instanceof",
"qq",
".",
"BlobProxy",
")",
"{",
"return",
"fileWrapper",
".",
"file",
".",
"referenceBlob",
";",
"}",
"return",
"fileWrapper",
".",
"file",
";",
"}",
"(",
")",
")",
",",
"name",
"=",
"validationDescriptor",
".",
"name",
",",
"size",
"=",
"validationDescriptor",
".",
"size",
",",
"buttonId",
"=",
"this",
".",
"_getButtonId",
"(",
"fileWrapper",
".",
"file",
")",
",",
"validationBase",
"=",
"this",
".",
"_getValidationBase",
"(",
"buttonId",
")",
",",
"validityChecker",
"=",
"new",
"qq",
".",
"Promise",
"(",
")",
";",
"validityChecker",
".",
"then",
"(",
"function",
"(",
")",
"{",
"}",
",",
"function",
"(",
")",
"{",
"self",
".",
"_fileOrBlobRejected",
"(",
"fileWrapper",
".",
"id",
",",
"name",
")",
";",
"}",
")",
";",
"if",
"(",
"qq",
".",
"isFileOrInput",
"(",
"file",
")",
"&&",
"!",
"this",
".",
"_isAllowedExtension",
"(",
"validationBase",
".",
"allowedExtensions",
",",
"name",
")",
")",
"{",
"this",
".",
"_itemError",
"(",
"\"typeError\"",
",",
"name",
",",
"file",
")",
";",
"return",
"validityChecker",
".",
"failure",
"(",
")",
";",
"}",
"if",
"(",
"!",
"this",
".",
"_options",
".",
"validation",
".",
"allowEmpty",
"&&",
"size",
"===",
"0",
")",
"{",
"this",
".",
"_itemError",
"(",
"\"emptyError\"",
",",
"name",
",",
"file",
")",
";",
"return",
"validityChecker",
".",
"failure",
"(",
")",
";",
"}",
"if",
"(",
"size",
">",
"0",
"&&",
"validationBase",
".",
"sizeLimit",
"&&",
"size",
">",
"validationBase",
".",
"sizeLimit",
")",
"{",
"this",
".",
"_itemError",
"(",
"\"sizeError\"",
",",
"name",
",",
"file",
")",
";",
"return",
"validityChecker",
".",
"failure",
"(",
")",
";",
"}",
"if",
"(",
"size",
">",
"0",
"&&",
"size",
"<",
"validationBase",
".",
"minSizeLimit",
")",
"{",
"this",
".",
"_itemError",
"(",
"\"minSizeError\"",
",",
"name",
",",
"file",
")",
";",
"return",
"validityChecker",
".",
"failure",
"(",
")",
";",
"}",
"if",
"(",
"qq",
".",
"ImageValidation",
"&&",
"qq",
".",
"supportedFeatures",
".",
"imagePreviews",
"&&",
"qq",
".",
"isFile",
"(",
"file",
")",
")",
"{",
"new",
"qq",
".",
"ImageValidation",
"(",
"file",
",",
"qq",
".",
"bind",
"(",
"self",
".",
"log",
",",
"self",
")",
")",
".",
"validate",
"(",
"validationBase",
".",
"image",
")",
".",
"then",
"(",
"validityChecker",
".",
"success",
",",
"function",
"(",
"errorCode",
")",
"{",
"self",
".",
"_itemError",
"(",
"errorCode",
"+",
"\"ImageError\"",
",",
"name",
",",
"file",
")",
";",
"validityChecker",
".",
"failure",
"(",
")",
";",
"}",
")",
";",
"}",
"else",
"{",
"validityChecker",
".",
"success",
"(",
")",
";",
"}",
"return",
"validityChecker",
";",
"}"
] | Performs some internal validation checks on an item, defined in the `validation` option.
@param fileWrapper Wrapper containing a `file` along with an `id`
@param validationDescriptor Normalized information about the item (`size`, `name`).
@returns qq.Promise with appropriate callbacks invoked depending on the validity of the file
@private | [
"Performs",
"some",
"internal",
"validation",
"checks",
"on",
"an",
"item",
"defined",
"in",
"the",
"validation",
"option",
"."
] | 057cc83a7e7657d032a75cf4a6b3612c7b4191da | https://github.com/FineUploader/fine-uploader/blob/057cc83a7e7657d032a75cf4a6b3612c7b4191da/client/js/uploader.basic.api.js#L1895-L1949 |
|
5,571 | FineUploader/fine-uploader | client/js/image-support/scaler.js | function(sizes) {
"use strict";
sizes = qq.extend([], sizes);
return sizes.sort(function(a, b) {
if (a.maxSize > b.maxSize) {
return 1;
}
if (a.maxSize < b.maxSize) {
return -1;
}
return 0;
});
} | javascript | function(sizes) {
"use strict";
sizes = qq.extend([], sizes);
return sizes.sort(function(a, b) {
if (a.maxSize > b.maxSize) {
return 1;
}
if (a.maxSize < b.maxSize) {
return -1;
}
return 0;
});
} | [
"function",
"(",
"sizes",
")",
"{",
"\"use strict\"",
";",
"sizes",
"=",
"qq",
".",
"extend",
"(",
"[",
"]",
",",
"sizes",
")",
";",
"return",
"sizes",
".",
"sort",
"(",
"function",
"(",
"a",
",",
"b",
")",
"{",
"if",
"(",
"a",
".",
"maxSize",
">",
"b",
".",
"maxSize",
")",
"{",
"return",
"1",
";",
"}",
"if",
"(",
"a",
".",
"maxSize",
"<",
"b",
".",
"maxSize",
")",
"{",
"return",
"-",
"1",
";",
"}",
"return",
"0",
";",
"}",
")",
";",
"}"
] | We want the smallest scaled file to be uploaded first | [
"We",
"want",
"the",
"smallest",
"scaled",
"file",
"to",
"be",
"uploaded",
"first"
] | 057cc83a7e7657d032a75cf4a6b3612c7b4191da | https://github.com/FineUploader/fine-uploader/blob/057cc83a7e7657d032a75cf4a6b3612c7b4191da/client/js/image-support/scaler.js#L276-L290 |
|
5,572 | FineUploader/fine-uploader | client/js/image-support/scaler.js | function(originalImage, scaledImageDataUri, log) {
"use strict";
var reader = new FileReader(),
insertionEffort = new qq.Promise(),
originalImageDataUri = "";
reader.onload = function() {
originalImageDataUri = reader.result;
insertionEffort.success(qq.ExifRestorer.restore(originalImageDataUri, scaledImageDataUri));
};
reader.onerror = function() {
log("Problem reading " + originalImage.name + " during attempt to transfer EXIF data to scaled version.", "error");
insertionEffort.failure();
};
reader.readAsDataURL(originalImage);
return insertionEffort;
} | javascript | function(originalImage, scaledImageDataUri, log) {
"use strict";
var reader = new FileReader(),
insertionEffort = new qq.Promise(),
originalImageDataUri = "";
reader.onload = function() {
originalImageDataUri = reader.result;
insertionEffort.success(qq.ExifRestorer.restore(originalImageDataUri, scaledImageDataUri));
};
reader.onerror = function() {
log("Problem reading " + originalImage.name + " during attempt to transfer EXIF data to scaled version.", "error");
insertionEffort.failure();
};
reader.readAsDataURL(originalImage);
return insertionEffort;
} | [
"function",
"(",
"originalImage",
",",
"scaledImageDataUri",
",",
"log",
")",
"{",
"\"use strict\"",
";",
"var",
"reader",
"=",
"new",
"FileReader",
"(",
")",
",",
"insertionEffort",
"=",
"new",
"qq",
".",
"Promise",
"(",
")",
",",
"originalImageDataUri",
"=",
"\"\"",
";",
"reader",
".",
"onload",
"=",
"function",
"(",
")",
"{",
"originalImageDataUri",
"=",
"reader",
".",
"result",
";",
"insertionEffort",
".",
"success",
"(",
"qq",
".",
"ExifRestorer",
".",
"restore",
"(",
"originalImageDataUri",
",",
"scaledImageDataUri",
")",
")",
";",
"}",
";",
"reader",
".",
"onerror",
"=",
"function",
"(",
")",
"{",
"log",
"(",
"\"Problem reading \"",
"+",
"originalImage",
".",
"name",
"+",
"\" during attempt to transfer EXIF data to scaled version.\"",
",",
"\"error\"",
")",
";",
"insertionEffort",
".",
"failure",
"(",
")",
";",
"}",
";",
"reader",
".",
"readAsDataURL",
"(",
"originalImage",
")",
";",
"return",
"insertionEffort",
";",
"}"
] | Attempt to insert the original image's EXIF header into a scaled version. | [
"Attempt",
"to",
"insert",
"the",
"original",
"image",
"s",
"EXIF",
"header",
"into",
"a",
"scaled",
"version",
"."
] | 057cc83a7e7657d032a75cf4a6b3612c7b4191da | https://github.com/FineUploader/fine-uploader/blob/057cc83a7e7657d032a75cf4a6b3612c7b4191da/client/js/image-support/scaler.js#L340-L360 |
|
5,573 | FineUploader/fine-uploader | client/js/form-support.js | maybeUploadOnSubmit | function maybeUploadOnSubmit(formEl) {
var nativeSubmit = formEl.submit;
// Intercept and squelch submit events.
qq(formEl).attach("submit", function(event) {
event = event || window.event;
if (event.preventDefault) {
event.preventDefault();
}
else {
event.returnValue = false;
}
validateForm(formEl, nativeSubmit) && startUpload();
});
// The form's `submit()` function may be called instead (i.e. via jQuery.submit()).
// Intercept that too.
formEl.submit = function() {
validateForm(formEl, nativeSubmit) && startUpload();
};
} | javascript | function maybeUploadOnSubmit(formEl) {
var nativeSubmit = formEl.submit;
// Intercept and squelch submit events.
qq(formEl).attach("submit", function(event) {
event = event || window.event;
if (event.preventDefault) {
event.preventDefault();
}
else {
event.returnValue = false;
}
validateForm(formEl, nativeSubmit) && startUpload();
});
// The form's `submit()` function may be called instead (i.e. via jQuery.submit()).
// Intercept that too.
formEl.submit = function() {
validateForm(formEl, nativeSubmit) && startUpload();
};
} | [
"function",
"maybeUploadOnSubmit",
"(",
"formEl",
")",
"{",
"var",
"nativeSubmit",
"=",
"formEl",
".",
"submit",
";",
"// Intercept and squelch submit events.",
"qq",
"(",
"formEl",
")",
".",
"attach",
"(",
"\"submit\"",
",",
"function",
"(",
"event",
")",
"{",
"event",
"=",
"event",
"||",
"window",
".",
"event",
";",
"if",
"(",
"event",
".",
"preventDefault",
")",
"{",
"event",
".",
"preventDefault",
"(",
")",
";",
"}",
"else",
"{",
"event",
".",
"returnValue",
"=",
"false",
";",
"}",
"validateForm",
"(",
"formEl",
",",
"nativeSubmit",
")",
"&&",
"startUpload",
"(",
")",
";",
"}",
")",
";",
"// The form's `submit()` function may be called instead (i.e. via jQuery.submit()).",
"// Intercept that too.",
"formEl",
".",
"submit",
"=",
"function",
"(",
")",
"{",
"validateForm",
"(",
"formEl",
",",
"nativeSubmit",
")",
"&&",
"startUpload",
"(",
")",
";",
"}",
";",
"}"
] | Intercept form submit attempts, unless the integrator has told us not to do this. | [
"Intercept",
"form",
"submit",
"attempts",
"unless",
"the",
"integrator",
"has",
"told",
"us",
"not",
"to",
"do",
"this",
"."
] | 057cc83a7e7657d032a75cf4a6b3612c7b4191da | https://github.com/FineUploader/fine-uploader/blob/057cc83a7e7657d032a75cf4a6b3612c7b4191da/client/js/form-support.js#L62-L84 |
5,574 | FineUploader/fine-uploader | client/js/upload-data.js | function(spec) {
var status = spec.status || qq.status.SUBMITTING,
id = data.push({
name: spec.name,
originalName: spec.name,
uuid: spec.uuid,
size: spec.size == null ? -1 : spec.size,
status: status,
file: spec.file
}) - 1;
if (spec.batchId) {
data[id].batchId = spec.batchId;
if (byBatchId[spec.batchId] === undefined) {
byBatchId[spec.batchId] = [];
}
byBatchId[spec.batchId].push(id);
}
if (spec.proxyGroupId) {
data[id].proxyGroupId = spec.proxyGroupId;
if (byProxyGroupId[spec.proxyGroupId] === undefined) {
byProxyGroupId[spec.proxyGroupId] = [];
}
byProxyGroupId[spec.proxyGroupId].push(id);
}
data[id].id = id;
byUuid[spec.uuid] = id;
if (byStatus[status] === undefined) {
byStatus[status] = [];
}
byStatus[status].push(id);
spec.onBeforeStatusChange && spec.onBeforeStatusChange(id);
uploaderProxy.onStatusChange(id, null, status);
return id;
} | javascript | function(spec) {
var status = spec.status || qq.status.SUBMITTING,
id = data.push({
name: spec.name,
originalName: spec.name,
uuid: spec.uuid,
size: spec.size == null ? -1 : spec.size,
status: status,
file: spec.file
}) - 1;
if (spec.batchId) {
data[id].batchId = spec.batchId;
if (byBatchId[spec.batchId] === undefined) {
byBatchId[spec.batchId] = [];
}
byBatchId[spec.batchId].push(id);
}
if (spec.proxyGroupId) {
data[id].proxyGroupId = spec.proxyGroupId;
if (byProxyGroupId[spec.proxyGroupId] === undefined) {
byProxyGroupId[spec.proxyGroupId] = [];
}
byProxyGroupId[spec.proxyGroupId].push(id);
}
data[id].id = id;
byUuid[spec.uuid] = id;
if (byStatus[status] === undefined) {
byStatus[status] = [];
}
byStatus[status].push(id);
spec.onBeforeStatusChange && spec.onBeforeStatusChange(id);
uploaderProxy.onStatusChange(id, null, status);
return id;
} | [
"function",
"(",
"spec",
")",
"{",
"var",
"status",
"=",
"spec",
".",
"status",
"||",
"qq",
".",
"status",
".",
"SUBMITTING",
",",
"id",
"=",
"data",
".",
"push",
"(",
"{",
"name",
":",
"spec",
".",
"name",
",",
"originalName",
":",
"spec",
".",
"name",
",",
"uuid",
":",
"spec",
".",
"uuid",
",",
"size",
":",
"spec",
".",
"size",
"==",
"null",
"?",
"-",
"1",
":",
"spec",
".",
"size",
",",
"status",
":",
"status",
",",
"file",
":",
"spec",
".",
"file",
"}",
")",
"-",
"1",
";",
"if",
"(",
"spec",
".",
"batchId",
")",
"{",
"data",
"[",
"id",
"]",
".",
"batchId",
"=",
"spec",
".",
"batchId",
";",
"if",
"(",
"byBatchId",
"[",
"spec",
".",
"batchId",
"]",
"===",
"undefined",
")",
"{",
"byBatchId",
"[",
"spec",
".",
"batchId",
"]",
"=",
"[",
"]",
";",
"}",
"byBatchId",
"[",
"spec",
".",
"batchId",
"]",
".",
"push",
"(",
"id",
")",
";",
"}",
"if",
"(",
"spec",
".",
"proxyGroupId",
")",
"{",
"data",
"[",
"id",
"]",
".",
"proxyGroupId",
"=",
"spec",
".",
"proxyGroupId",
";",
"if",
"(",
"byProxyGroupId",
"[",
"spec",
".",
"proxyGroupId",
"]",
"===",
"undefined",
")",
"{",
"byProxyGroupId",
"[",
"spec",
".",
"proxyGroupId",
"]",
"=",
"[",
"]",
";",
"}",
"byProxyGroupId",
"[",
"spec",
".",
"proxyGroupId",
"]",
".",
"push",
"(",
"id",
")",
";",
"}",
"data",
"[",
"id",
"]",
".",
"id",
"=",
"id",
";",
"byUuid",
"[",
"spec",
".",
"uuid",
"]",
"=",
"id",
";",
"if",
"(",
"byStatus",
"[",
"status",
"]",
"===",
"undefined",
")",
"{",
"byStatus",
"[",
"status",
"]",
"=",
"[",
"]",
";",
"}",
"byStatus",
"[",
"status",
"]",
".",
"push",
"(",
"id",
")",
";",
"spec",
".",
"onBeforeStatusChange",
"&&",
"spec",
".",
"onBeforeStatusChange",
"(",
"id",
")",
";",
"uploaderProxy",
".",
"onStatusChange",
"(",
"id",
",",
"null",
",",
"status",
")",
";",
"return",
"id",
";",
"}"
] | Adds a new file to the data cache for tracking purposes.
@param spec Data that describes this file. Possible properties are:
- uuid: Initial UUID for this file.
- name: Initial name of this file.
- size: Size of this file, omit if this cannot be determined
- status: Initial `qq.status` for this file. Omit for `qq.status.SUBMITTING`.
- batchId: ID of the batch this file belongs to
- proxyGroupId: ID of the proxy group associated with this file
- onBeforeStatusChange(fileId): callback that is executed before the status change is broadcast
@returns {number} Internal ID for this file. | [
"Adds",
"a",
"new",
"file",
"to",
"the",
"data",
"cache",
"for",
"tracking",
"purposes",
"."
] | 057cc83a7e7657d032a75cf4a6b3612c7b4191da | https://github.com/FineUploader/fine-uploader/blob/057cc83a7e7657d032a75cf4a6b3612c7b4191da/client/js/upload-data.js#L72-L113 |
|
5,575 | FineUploader/fine-uploader | client/js/azure/util.js | function(name) {
if (qq.azure.util._paramNameMatchesAzureParameter(name)) {
return name;
}
else {
return qq.azure.util.AZURE_PARAM_PREFIX + name;
}
} | javascript | function(name) {
if (qq.azure.util._paramNameMatchesAzureParameter(name)) {
return name;
}
else {
return qq.azure.util.AZURE_PARAM_PREFIX + name;
}
} | [
"function",
"(",
"name",
")",
"{",
"if",
"(",
"qq",
".",
"azure",
".",
"util",
".",
"_paramNameMatchesAzureParameter",
"(",
"name",
")",
")",
"{",
"return",
"name",
";",
"}",
"else",
"{",
"return",
"qq",
".",
"azure",
".",
"util",
".",
"AZURE_PARAM_PREFIX",
"+",
"name",
";",
"}",
"}"
] | Create Prefixed request headers which are appropriate for Azure.
If the request header is appropriate for Azure (e.g. Cache-Control) then it should be
passed along without a metadata prefix. For all other request header parameter names,
qq.azure.util.AZURE_PARAM_PREFIX should be prepended.
@param name Name of the Request Header parameter to construct a (possibly) prefixed name.
@returns {String} A valid Request Header parameter name. | [
"Create",
"Prefixed",
"request",
"headers",
"which",
"are",
"appropriate",
"for",
"Azure",
"."
] | 057cc83a7e7657d032a75cf4a6b3612c7b4191da | https://github.com/FineUploader/fine-uploader/blob/057cc83a7e7657d032a75cf4a6b3612c7b4191da/client/js/azure/util.js#L39-L46 |
|
5,576 | FineUploader/fine-uploader | client/js/ui.handler.focusin.filenameinput.js | handleInputFocus | function handleInputFocus(target, event) {
if (spec.templating.isEditInput(target)) {
var fileId = spec.templating.getFileId(target),
status = spec.onGetUploadStatus(fileId);
if (status === qq.status.SUBMITTED) {
spec.log(qq.format("Detected valid filename input focus event on file '{}', ID: {}.", spec.onGetName(fileId), fileId));
inheritedInternalApi.handleFilenameEdit(fileId, target);
}
}
} | javascript | function handleInputFocus(target, event) {
if (spec.templating.isEditInput(target)) {
var fileId = spec.templating.getFileId(target),
status = spec.onGetUploadStatus(fileId);
if (status === qq.status.SUBMITTED) {
spec.log(qq.format("Detected valid filename input focus event on file '{}', ID: {}.", spec.onGetName(fileId), fileId));
inheritedInternalApi.handleFilenameEdit(fileId, target);
}
}
} | [
"function",
"handleInputFocus",
"(",
"target",
",",
"event",
")",
"{",
"if",
"(",
"spec",
".",
"templating",
".",
"isEditInput",
"(",
"target",
")",
")",
"{",
"var",
"fileId",
"=",
"spec",
".",
"templating",
".",
"getFileId",
"(",
"target",
")",
",",
"status",
"=",
"spec",
".",
"onGetUploadStatus",
"(",
"fileId",
")",
";",
"if",
"(",
"status",
"===",
"qq",
".",
"status",
".",
"SUBMITTED",
")",
"{",
"spec",
".",
"log",
"(",
"qq",
".",
"format",
"(",
"\"Detected valid filename input focus event on file '{}', ID: {}.\"",
",",
"spec",
".",
"onGetName",
"(",
"fileId",
")",
",",
"fileId",
")",
")",
";",
"inheritedInternalApi",
".",
"handleFilenameEdit",
"(",
"fileId",
",",
"target",
")",
";",
"}",
"}",
"}"
] | This will be called by the parent handler when a `focusin` event is received on the list element. | [
"This",
"will",
"be",
"called",
"by",
"the",
"parent",
"handler",
"when",
"a",
"focusin",
"event",
"is",
"received",
"on",
"the",
"list",
"element",
"."
] | 057cc83a7e7657d032a75cf4a6b3612c7b4191da | https://github.com/FineUploader/fine-uploader/blob/057cc83a7e7657d032a75cf4a6b3612c7b4191da/client/js/ui.handler.focusin.filenameinput.js#L17-L27 |
5,577 | FineUploader/fine-uploader | client/js/image-support/image.js | draw | function draw(fileOrBlob, container, options) {
var drawPreview = new qq.Promise(),
identifier = new qq.Identify(fileOrBlob, log),
maxSize = options.maxSize,
// jshint eqnull:true
orient = options.orient == null ? true : options.orient,
megapixErrorHandler = function() {
container.onerror = null;
container.onload = null;
log("Could not render preview, file may be too large!", "error");
drawPreview.failure(container, "Browser cannot render image!");
};
identifier.isPreviewable().then(
function(mime) {
// If options explicitly specify that Orientation is not desired,
// replace the orient task with a dummy promise that "succeeds" immediately.
var dummyExif = {
parse: function() {
return new qq.Promise().success();
}
},
exif = orient ? new qq.Exif(fileOrBlob, log) : dummyExif,
mpImg = new qq.MegaPixImage(fileOrBlob, megapixErrorHandler);
if (registerThumbnailRenderedListener(container, drawPreview)) {
exif.parse().then(
function(exif) {
var orientation = exif && exif.Orientation;
mpImg.render(container, {
maxWidth: maxSize,
maxHeight: maxSize,
orientation: orientation,
mime: mime,
resize: options.customResizeFunction
});
},
function(failureMsg) {
log(qq.format("EXIF data could not be parsed ({}). Assuming orientation = 1.", failureMsg));
mpImg.render(container, {
maxWidth: maxSize,
maxHeight: maxSize,
mime: mime,
resize: options.customResizeFunction
});
}
);
}
},
function() {
log("Not previewable");
drawPreview.failure(container, "Not previewable");
}
);
return drawPreview;
} | javascript | function draw(fileOrBlob, container, options) {
var drawPreview = new qq.Promise(),
identifier = new qq.Identify(fileOrBlob, log),
maxSize = options.maxSize,
// jshint eqnull:true
orient = options.orient == null ? true : options.orient,
megapixErrorHandler = function() {
container.onerror = null;
container.onload = null;
log("Could not render preview, file may be too large!", "error");
drawPreview.failure(container, "Browser cannot render image!");
};
identifier.isPreviewable().then(
function(mime) {
// If options explicitly specify that Orientation is not desired,
// replace the orient task with a dummy promise that "succeeds" immediately.
var dummyExif = {
parse: function() {
return new qq.Promise().success();
}
},
exif = orient ? new qq.Exif(fileOrBlob, log) : dummyExif,
mpImg = new qq.MegaPixImage(fileOrBlob, megapixErrorHandler);
if (registerThumbnailRenderedListener(container, drawPreview)) {
exif.parse().then(
function(exif) {
var orientation = exif && exif.Orientation;
mpImg.render(container, {
maxWidth: maxSize,
maxHeight: maxSize,
orientation: orientation,
mime: mime,
resize: options.customResizeFunction
});
},
function(failureMsg) {
log(qq.format("EXIF data could not be parsed ({}). Assuming orientation = 1.", failureMsg));
mpImg.render(container, {
maxWidth: maxSize,
maxHeight: maxSize,
mime: mime,
resize: options.customResizeFunction
});
}
);
}
},
function() {
log("Not previewable");
drawPreview.failure(container, "Not previewable");
}
);
return drawPreview;
} | [
"function",
"draw",
"(",
"fileOrBlob",
",",
"container",
",",
"options",
")",
"{",
"var",
"drawPreview",
"=",
"new",
"qq",
".",
"Promise",
"(",
")",
",",
"identifier",
"=",
"new",
"qq",
".",
"Identify",
"(",
"fileOrBlob",
",",
"log",
")",
",",
"maxSize",
"=",
"options",
".",
"maxSize",
",",
"// jshint eqnull:true",
"orient",
"=",
"options",
".",
"orient",
"==",
"null",
"?",
"true",
":",
"options",
".",
"orient",
",",
"megapixErrorHandler",
"=",
"function",
"(",
")",
"{",
"container",
".",
"onerror",
"=",
"null",
";",
"container",
".",
"onload",
"=",
"null",
";",
"log",
"(",
"\"Could not render preview, file may be too large!\"",
",",
"\"error\"",
")",
";",
"drawPreview",
".",
"failure",
"(",
"container",
",",
"\"Browser cannot render image!\"",
")",
";",
"}",
";",
"identifier",
".",
"isPreviewable",
"(",
")",
".",
"then",
"(",
"function",
"(",
"mime",
")",
"{",
"// If options explicitly specify that Orientation is not desired,",
"// replace the orient task with a dummy promise that \"succeeds\" immediately.",
"var",
"dummyExif",
"=",
"{",
"parse",
":",
"function",
"(",
")",
"{",
"return",
"new",
"qq",
".",
"Promise",
"(",
")",
".",
"success",
"(",
")",
";",
"}",
"}",
",",
"exif",
"=",
"orient",
"?",
"new",
"qq",
".",
"Exif",
"(",
"fileOrBlob",
",",
"log",
")",
":",
"dummyExif",
",",
"mpImg",
"=",
"new",
"qq",
".",
"MegaPixImage",
"(",
"fileOrBlob",
",",
"megapixErrorHandler",
")",
";",
"if",
"(",
"registerThumbnailRenderedListener",
"(",
"container",
",",
"drawPreview",
")",
")",
"{",
"exif",
".",
"parse",
"(",
")",
".",
"then",
"(",
"function",
"(",
"exif",
")",
"{",
"var",
"orientation",
"=",
"exif",
"&&",
"exif",
".",
"Orientation",
";",
"mpImg",
".",
"render",
"(",
"container",
",",
"{",
"maxWidth",
":",
"maxSize",
",",
"maxHeight",
":",
"maxSize",
",",
"orientation",
":",
"orientation",
",",
"mime",
":",
"mime",
",",
"resize",
":",
"options",
".",
"customResizeFunction",
"}",
")",
";",
"}",
",",
"function",
"(",
"failureMsg",
")",
"{",
"log",
"(",
"qq",
".",
"format",
"(",
"\"EXIF data could not be parsed ({}). Assuming orientation = 1.\"",
",",
"failureMsg",
")",
")",
";",
"mpImg",
".",
"render",
"(",
"container",
",",
"{",
"maxWidth",
":",
"maxSize",
",",
"maxHeight",
":",
"maxSize",
",",
"mime",
":",
"mime",
",",
"resize",
":",
"options",
".",
"customResizeFunction",
"}",
")",
";",
"}",
")",
";",
"}",
"}",
",",
"function",
"(",
")",
"{",
"log",
"(",
"\"Not previewable\"",
")",
";",
"drawPreview",
".",
"failure",
"(",
"container",
",",
"\"Not previewable\"",
")",
";",
"}",
")",
";",
"return",
"drawPreview",
";",
"}"
] | Draw a preview iff the current UA can natively display it. Also rotate the image if necessary. | [
"Draw",
"a",
"preview",
"iff",
"the",
"current",
"UA",
"can",
"natively",
"display",
"it",
".",
"Also",
"rotate",
"the",
"image",
"if",
"necessary",
"."
] | 057cc83a7e7657d032a75cf4a6b3612c7b4191da | https://github.com/FineUploader/fine-uploader/blob/057cc83a7e7657d032a75cf4a6b3612c7b4191da/client/js/image-support/image.js#L136-L196 |
5,578 | FineUploader/fine-uploader | client/js/third-party/crypto-js/core.js | function (nBytes) {
var words = [];
for (var i = 0; i < nBytes; i += 4) {
words.push((Math.random() * 0x100000000) | 0);
}
return new WordArray.init(words, nBytes);
} | javascript | function (nBytes) {
var words = [];
for (var i = 0; i < nBytes; i += 4) {
words.push((Math.random() * 0x100000000) | 0);
}
return new WordArray.init(words, nBytes);
} | [
"function",
"(",
"nBytes",
")",
"{",
"var",
"words",
"=",
"[",
"]",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"nBytes",
";",
"i",
"+=",
"4",
")",
"{",
"words",
".",
"push",
"(",
"(",
"Math",
".",
"random",
"(",
")",
"*",
"0x100000000",
")",
"|",
"0",
")",
";",
"}",
"return",
"new",
"WordArray",
".",
"init",
"(",
"words",
",",
"nBytes",
")",
";",
"}"
] | Creates a word array filled with random bytes.
@param {number} nBytes The number of random bytes to generate.
@return {WordArray} The random word array.
@static
@example
var wordArray = CryptoJS.lib.WordArray.random(16); | [
"Creates",
"a",
"word",
"array",
"filled",
"with",
"random",
"bytes",
"."
] | 057cc83a7e7657d032a75cf4a6b3612c7b4191da | https://github.com/FineUploader/fine-uploader/blob/057cc83a7e7657d032a75cf4a6b3612c7b4191da/client/js/third-party/crypto-js/core.js#L280-L287 |
|
5,579 | FineUploader/fine-uploader | client/js/third-party/crypto-js/core.js | function (data) {
// Convert string to WordArray, else assume WordArray already
if (typeof data == 'string') {
data = Utf8.parse(data);
}
// Append
this._data.concat(data);
this._nDataBytes += data.sigBytes;
} | javascript | function (data) {
// Convert string to WordArray, else assume WordArray already
if (typeof data == 'string') {
data = Utf8.parse(data);
}
// Append
this._data.concat(data);
this._nDataBytes += data.sigBytes;
} | [
"function",
"(",
"data",
")",
"{",
"// Convert string to WordArray, else assume WordArray already",
"if",
"(",
"typeof",
"data",
"==",
"'string'",
")",
"{",
"data",
"=",
"Utf8",
".",
"parse",
"(",
"data",
")",
";",
"}",
"// Append",
"this",
".",
"_data",
".",
"concat",
"(",
"data",
")",
";",
"this",
".",
"_nDataBytes",
"+=",
"data",
".",
"sigBytes",
";",
"}"
] | Adds new data to this block algorithm's buffer.
@param {WordArray|string} data The data to append. Strings are converted to a WordArray using UTF-8.
@example
bufferedBlockAlgorithm._append('data');
bufferedBlockAlgorithm._append(wordArray); | [
"Adds",
"new",
"data",
"to",
"this",
"block",
"algorithm",
"s",
"buffer",
"."
] | 057cc83a7e7657d032a75cf4a6b3612c7b4191da | https://github.com/FineUploader/fine-uploader/blob/057cc83a7e7657d032a75cf4a6b3612c7b4191da/client/js/third-party/crypto-js/core.js#L488-L497 |
|
5,580 | FineUploader/fine-uploader | client/js/third-party/crypto-js/core.js | function (hasher) {
return function (message, key) {
return new C_algo.HMAC.init(hasher, key).finalize(message);
};
} | javascript | function (hasher) {
return function (message, key) {
return new C_algo.HMAC.init(hasher, key).finalize(message);
};
} | [
"function",
"(",
"hasher",
")",
"{",
"return",
"function",
"(",
"message",
",",
"key",
")",
"{",
"return",
"new",
"C_algo",
".",
"HMAC",
".",
"init",
"(",
"hasher",
",",
"key",
")",
".",
"finalize",
"(",
"message",
")",
";",
"}",
";",
"}"
] | Creates a shortcut function to the HMAC's object interface.
@param {Hasher} hasher The hasher to use in this HMAC helper.
@return {Function} The shortcut function.
@static
@example
var HmacSHA256 = CryptoJS.lib.Hasher._createHmacHelper(CryptoJS.algo.SHA256); | [
"Creates",
"a",
"shortcut",
"function",
"to",
"the",
"HMAC",
"s",
"object",
"interface",
"."
] | 057cc83a7e7657d032a75cf4a6b3612c7b4191da | https://github.com/FineUploader/fine-uploader/blob/057cc83a7e7657d032a75cf4a6b3612c7b4191da/client/js/third-party/crypto-js/core.js#L699-L703 |
|
5,581 | FineUploader/fine-uploader | client/js/s3/util.js | function(endpoint) {
var patterns = [
//bucket in domain
/^(?:https?:\/\/)?([a-z0-9.\-_]+)\.s3(?:-[a-z0-9\-]+)?\.amazonaws\.com/i,
//bucket in path
/^(?:https?:\/\/)?s3(?:-[a-z0-9\-]+)?\.amazonaws\.com\/([a-z0-9.\-_]+)/i,
//custom domain
/^(?:https?:\/\/)?([a-z0-9.\-_]+)/i
],
bucket;
qq.each(patterns, function(idx, pattern) {
var match = pattern.exec(endpoint);
if (match) {
bucket = match[1];
return false;
}
});
return bucket;
} | javascript | function(endpoint) {
var patterns = [
//bucket in domain
/^(?:https?:\/\/)?([a-z0-9.\-_]+)\.s3(?:-[a-z0-9\-]+)?\.amazonaws\.com/i,
//bucket in path
/^(?:https?:\/\/)?s3(?:-[a-z0-9\-]+)?\.amazonaws\.com\/([a-z0-9.\-_]+)/i,
//custom domain
/^(?:https?:\/\/)?([a-z0-9.\-_]+)/i
],
bucket;
qq.each(patterns, function(idx, pattern) {
var match = pattern.exec(endpoint);
if (match) {
bucket = match[1];
return false;
}
});
return bucket;
} | [
"function",
"(",
"endpoint",
")",
"{",
"var",
"patterns",
"=",
"[",
"//bucket in domain",
"/",
"^(?:https?:\\/\\/)?([a-z0-9.\\-_]+)\\.s3(?:-[a-z0-9\\-]+)?\\.amazonaws\\.com",
"/",
"i",
",",
"//bucket in path",
"/",
"^(?:https?:\\/\\/)?s3(?:-[a-z0-9\\-]+)?\\.amazonaws\\.com\\/([a-z0-9.\\-_]+)",
"/",
"i",
",",
"//custom domain",
"/",
"^(?:https?:\\/\\/)?([a-z0-9.\\-_]+)",
"/",
"i",
"]",
",",
"bucket",
";",
"qq",
".",
"each",
"(",
"patterns",
",",
"function",
"(",
"idx",
",",
"pattern",
")",
"{",
"var",
"match",
"=",
"pattern",
".",
"exec",
"(",
"endpoint",
")",
";",
"if",
"(",
"match",
")",
"{",
"bucket",
"=",
"match",
"[",
"1",
"]",
";",
"return",
"false",
";",
"}",
"}",
")",
";",
"return",
"bucket",
";",
"}"
] | This allows for the region to be specified in the bucket's endpoint URL, or not.
Examples of some valid endpoints are:
http://foo.s3.amazonaws.com
https://foo.s3.amazonaws.com
http://foo.s3-ap-northeast-1.amazonaws.com
foo.s3.amazonaws.com
http://foo.bar.com
http://s3.amazonaws.com/foo.bar.com
...etc
@param endpoint The bucket's URL.
@returns {String || undefined} The bucket name, or undefined if the URL cannot be parsed. | [
"This",
"allows",
"for",
"the",
"region",
"to",
"be",
"specified",
"in",
"the",
"bucket",
"s",
"endpoint",
"URL",
"or",
"not",
"."
] | 057cc83a7e7657d032a75cf4a6b3612c7b4191da | https://github.com/FineUploader/fine-uploader/blob/057cc83a7e7657d032a75cf4a6b3612c7b4191da/client/js/s3/util.js#L69-L90 |
|
5,582 | FineUploader/fine-uploader | client/js/s3/util.js | function(name) {
if (qq.indexOf(qq.s3.util.UNPREFIXED_PARAM_NAMES, name) >= 0) {
return name;
}
return qq.s3.util.AWS_PARAM_PREFIX + name;
} | javascript | function(name) {
if (qq.indexOf(qq.s3.util.UNPREFIXED_PARAM_NAMES, name) >= 0) {
return name;
}
return qq.s3.util.AWS_PARAM_PREFIX + name;
} | [
"function",
"(",
"name",
")",
"{",
"if",
"(",
"qq",
".",
"indexOf",
"(",
"qq",
".",
"s3",
".",
"util",
".",
"UNPREFIXED_PARAM_NAMES",
",",
"name",
")",
">=",
"0",
")",
"{",
"return",
"name",
";",
"}",
"return",
"qq",
".",
"s3",
".",
"util",
".",
"AWS_PARAM_PREFIX",
"+",
"name",
";",
"}"
] | Create Prefixed request headers which are appropriate for S3.
If the request header is appropriate for S3 (e.g. Cache-Control) then pass
it along without a metadata prefix. For all other request header parameter names,
apply qq.s3.util.AWS_PARAM_PREFIX before the name.
See: http://docs.aws.amazon.com/AmazonS3/latest/API/RESTObjectPUT.html | [
"Create",
"Prefixed",
"request",
"headers",
"which",
"are",
"appropriate",
"for",
"S3",
"."
] | 057cc83a7e7657d032a75cf4a6b3612c7b4191da | https://github.com/FineUploader/fine-uploader/blob/057cc83a7e7657d032a75cf4a6b3612c7b4191da/client/js/s3/util.js#L99-L104 |
|
5,583 | FineUploader/fine-uploader | client/js/s3/util.js | function(policy, minSize, maxSize) {
var adjustedMinSize = minSize < 0 ? 0 : minSize,
// Adjust a maxSize of 0 to the largest possible integer, since we must specify a high and a low in the request
adjustedMaxSize = maxSize <= 0 ? 9007199254740992 : maxSize;
if (minSize > 0 || maxSize > 0) {
policy.conditions.push(["content-length-range", adjustedMinSize.toString(), adjustedMaxSize.toString()]);
}
} | javascript | function(policy, minSize, maxSize) {
var adjustedMinSize = minSize < 0 ? 0 : minSize,
// Adjust a maxSize of 0 to the largest possible integer, since we must specify a high and a low in the request
adjustedMaxSize = maxSize <= 0 ? 9007199254740992 : maxSize;
if (minSize > 0 || maxSize > 0) {
policy.conditions.push(["content-length-range", adjustedMinSize.toString(), adjustedMaxSize.toString()]);
}
} | [
"function",
"(",
"policy",
",",
"minSize",
",",
"maxSize",
")",
"{",
"var",
"adjustedMinSize",
"=",
"minSize",
"<",
"0",
"?",
"0",
":",
"minSize",
",",
"// Adjust a maxSize of 0 to the largest possible integer, since we must specify a high and a low in the request",
"adjustedMaxSize",
"=",
"maxSize",
"<=",
"0",
"?",
"9007199254740992",
":",
"maxSize",
";",
"if",
"(",
"minSize",
">",
"0",
"||",
"maxSize",
">",
"0",
")",
"{",
"policy",
".",
"conditions",
".",
"push",
"(",
"[",
"\"content-length-range\"",
",",
"adjustedMinSize",
".",
"toString",
"(",
")",
",",
"adjustedMaxSize",
".",
"toString",
"(",
")",
"]",
")",
";",
"}",
"}"
] | Add a condition to an existing S3 upload request policy document used to ensure AWS enforces any size
restrictions placed on files server-side. This is important to do, in case users mess with the client-side
checks already in place.
@param policy Policy document as an `Object`, with a `conditions` property already attached
@param minSize Minimum acceptable size, in bytes
@param maxSize Maximum acceptable size, in bytes (0 = unlimited) | [
"Add",
"a",
"condition",
"to",
"an",
"existing",
"S3",
"upload",
"request",
"policy",
"document",
"used",
"to",
"ensure",
"AWS",
"enforces",
"any",
"size",
"restrictions",
"placed",
"on",
"files",
"server",
"-",
"side",
".",
"This",
"is",
"important",
"to",
"do",
"in",
"case",
"users",
"mess",
"with",
"the",
"client",
"-",
"side",
"checks",
"already",
"in",
"place",
"."
] | 057cc83a7e7657d032a75cf4a6b3612c7b4191da | https://github.com/FineUploader/fine-uploader/blob/057cc83a7e7657d032a75cf4a6b3612c7b4191da/client/js/s3/util.js#L361-L369 |
|
5,584 | FineUploader/fine-uploader | client/js/s3/util.js | function(iframe) {
var doc = iframe.contentDocument || iframe.contentWindow.document,
queryString = doc.location.search,
match = /bucket=(.+)&key=(.+)&etag=(.+)/.exec(queryString);
if (match) {
return {
bucket: match[1],
key: match[2],
etag: match[3].replace(/%22/g, "")
};
}
} | javascript | function(iframe) {
var doc = iframe.contentDocument || iframe.contentWindow.document,
queryString = doc.location.search,
match = /bucket=(.+)&key=(.+)&etag=(.+)/.exec(queryString);
if (match) {
return {
bucket: match[1],
key: match[2],
etag: match[3].replace(/%22/g, "")
};
}
} | [
"function",
"(",
"iframe",
")",
"{",
"var",
"doc",
"=",
"iframe",
".",
"contentDocument",
"||",
"iframe",
".",
"contentWindow",
".",
"document",
",",
"queryString",
"=",
"doc",
".",
"location",
".",
"search",
",",
"match",
"=",
"/",
"bucket=(.+)&key=(.+)&etag=(.+)",
"/",
".",
"exec",
"(",
"queryString",
")",
";",
"if",
"(",
"match",
")",
"{",
"return",
"{",
"bucket",
":",
"match",
"[",
"1",
"]",
",",
"key",
":",
"match",
"[",
"2",
"]",
",",
"etag",
":",
"match",
"[",
"3",
"]",
".",
"replace",
"(",
"/",
"%22",
"/",
"g",
",",
"\"\"",
")",
"}",
";",
"}",
"}"
] | Looks at a response from S3 contained in an iframe and parses the query string in an attempt to identify
the associated resource.
@param iframe Iframe containing response
@returns {{bucket: *, key: *, etag: *}} | [
"Looks",
"at",
"a",
"response",
"from",
"S3",
"contained",
"in",
"an",
"iframe",
"and",
"parses",
"the",
"query",
"string",
"in",
"an",
"attempt",
"to",
"identify",
"the",
"associated",
"resource",
"."
] | 057cc83a7e7657d032a75cf4a6b3612c7b4191da | https://github.com/FineUploader/fine-uploader/blob/057cc83a7e7657d032a75cf4a6b3612c7b4191da/client/js/s3/util.js#L422-L434 |
|
5,585 | FineUploader/fine-uploader | client/js/ajax.requester.js | getCorsAjaxTransport | function getCorsAjaxTransport() {
var xhrOrXdr;
if (window.XMLHttpRequest || window.ActiveXObject) {
xhrOrXdr = qq.createXhrInstance();
if (xhrOrXdr.withCredentials === undefined) {
xhrOrXdr = new XDomainRequest();
// Workaround for XDR bug in IE9 - https://social.msdn.microsoft.com/Forums/ie/en-US/30ef3add-767c-4436-b8a9-f1ca19b4812e/ie9-rtm-xdomainrequest-issued-requests-may-abort-if-all-event-handlers-not-specified?forum=iewebdevelopment
xhrOrXdr.onload = function() {};
xhrOrXdr.onerror = function() {};
xhrOrXdr.ontimeout = function() {};
xhrOrXdr.onprogress = function() {};
}
}
return xhrOrXdr;
} | javascript | function getCorsAjaxTransport() {
var xhrOrXdr;
if (window.XMLHttpRequest || window.ActiveXObject) {
xhrOrXdr = qq.createXhrInstance();
if (xhrOrXdr.withCredentials === undefined) {
xhrOrXdr = new XDomainRequest();
// Workaround for XDR bug in IE9 - https://social.msdn.microsoft.com/Forums/ie/en-US/30ef3add-767c-4436-b8a9-f1ca19b4812e/ie9-rtm-xdomainrequest-issued-requests-may-abort-if-all-event-handlers-not-specified?forum=iewebdevelopment
xhrOrXdr.onload = function() {};
xhrOrXdr.onerror = function() {};
xhrOrXdr.ontimeout = function() {};
xhrOrXdr.onprogress = function() {};
}
}
return xhrOrXdr;
} | [
"function",
"getCorsAjaxTransport",
"(",
")",
"{",
"var",
"xhrOrXdr",
";",
"if",
"(",
"window",
".",
"XMLHttpRequest",
"||",
"window",
".",
"ActiveXObject",
")",
"{",
"xhrOrXdr",
"=",
"qq",
".",
"createXhrInstance",
"(",
")",
";",
"if",
"(",
"xhrOrXdr",
".",
"withCredentials",
"===",
"undefined",
")",
"{",
"xhrOrXdr",
"=",
"new",
"XDomainRequest",
"(",
")",
";",
"// Workaround for XDR bug in IE9 - https://social.msdn.microsoft.com/Forums/ie/en-US/30ef3add-767c-4436-b8a9-f1ca19b4812e/ie9-rtm-xdomainrequest-issued-requests-may-abort-if-all-event-handlers-not-specified?forum=iewebdevelopment",
"xhrOrXdr",
".",
"onload",
"=",
"function",
"(",
")",
"{",
"}",
";",
"xhrOrXdr",
".",
"onerror",
"=",
"function",
"(",
")",
"{",
"}",
";",
"xhrOrXdr",
".",
"ontimeout",
"=",
"function",
"(",
")",
"{",
"}",
";",
"xhrOrXdr",
".",
"onprogress",
"=",
"function",
"(",
")",
"{",
"}",
";",
"}",
"}",
"return",
"xhrOrXdr",
";",
"}"
] | Returns either a new `XMLHttpRequest` or `XDomainRequest` instance. | [
"Returns",
"either",
"a",
"new",
"XMLHttpRequest",
"or",
"XDomainRequest",
"instance",
"."
] | 057cc83a7e7657d032a75cf4a6b3612c7b4191da | https://github.com/FineUploader/fine-uploader/blob/057cc83a7e7657d032a75cf4a6b3612c7b4191da/client/js/ajax.requester.js#L73-L90 |
5,586 | FineUploader/fine-uploader | client/js/ajax.requester.js | dequeue | function dequeue(id) {
var i = qq.indexOf(queue, id),
max = options.maxConnections,
nextId;
delete requestData[id];
queue.splice(i, 1);
if (queue.length >= max && i < max) {
nextId = queue[max - 1];
sendRequest(nextId);
}
} | javascript | function dequeue(id) {
var i = qq.indexOf(queue, id),
max = options.maxConnections,
nextId;
delete requestData[id];
queue.splice(i, 1);
if (queue.length >= max && i < max) {
nextId = queue[max - 1];
sendRequest(nextId);
}
} | [
"function",
"dequeue",
"(",
"id",
")",
"{",
"var",
"i",
"=",
"qq",
".",
"indexOf",
"(",
"queue",
",",
"id",
")",
",",
"max",
"=",
"options",
".",
"maxConnections",
",",
"nextId",
";",
"delete",
"requestData",
"[",
"id",
"]",
";",
"queue",
".",
"splice",
"(",
"i",
",",
"1",
")",
";",
"if",
"(",
"queue",
".",
"length",
">=",
"max",
"&&",
"i",
"<",
"max",
")",
"{",
"nextId",
"=",
"queue",
"[",
"max",
"-",
"1",
"]",
";",
"sendRequest",
"(",
"nextId",
")",
";",
"}",
"}"
] | Removes element from queue, sends next request | [
"Removes",
"element",
"from",
"queue",
"sends",
"next",
"request"
] | 057cc83a7e7657d032a75cf4a6b3612c7b4191da | https://github.com/FineUploader/fine-uploader/blob/057cc83a7e7657d032a75cf4a6b3612c7b4191da/client/js/ajax.requester.js#L116-L128 |
5,587 | FineUploader/fine-uploader | client/js/ajax.requester.js | function(optXhr) {
if (cacheBuster && qq.indexOf(["GET", "DELETE"], options.method) >= 0) {
params.qqtimestamp = new Date().getTime();
}
return prepareToSend(id, optXhr, path, params, additionalQueryParams, headers, payload);
} | javascript | function(optXhr) {
if (cacheBuster && qq.indexOf(["GET", "DELETE"], options.method) >= 0) {
params.qqtimestamp = new Date().getTime();
}
return prepareToSend(id, optXhr, path, params, additionalQueryParams, headers, payload);
} | [
"function",
"(",
"optXhr",
")",
"{",
"if",
"(",
"cacheBuster",
"&&",
"qq",
".",
"indexOf",
"(",
"[",
"\"GET\"",
",",
"\"DELETE\"",
"]",
",",
"options",
".",
"method",
")",
">=",
"0",
")",
"{",
"params",
".",
"qqtimestamp",
"=",
"new",
"Date",
"(",
")",
".",
"getTime",
"(",
")",
";",
"}",
"return",
"prepareToSend",
"(",
"id",
",",
"optXhr",
",",
"path",
",",
"params",
",",
"additionalQueryParams",
",",
"headers",
",",
"payload",
")",
";",
"}"
] | Send the constructed request. | [
"Send",
"the",
"constructed",
"request",
"."
] | 057cc83a7e7657d032a75cf4a6b3612c7b4191da | https://github.com/FineUploader/fine-uploader/blob/057cc83a7e7657d032a75cf4a6b3612c7b4191da/client/js/ajax.requester.js#L390-L396 |
|
5,588 | FineUploader/fine-uploader | client/js/s3/uploader.basic.js | function() {
var self = this,
additionalOptions = {
aclStore: this._aclStore,
getBucket: qq.bind(this._determineBucket, this),
getHost: qq.bind(this._determineHost, this),
getKeyName: qq.bind(this._determineKeyName, this),
iframeSupport: this._options.iframeSupport,
objectProperties: this._options.objectProperties,
signature: this._options.signature,
clockDrift: this._options.request.clockDrift,
// pass size limit validation values to include in the request so AWS enforces this server-side
validation: {
minSizeLimit: this._options.validation.minSizeLimit,
maxSizeLimit: this._options.validation.sizeLimit
}
};
// We assume HTTP if it is missing from the start of the endpoint string.
qq.override(this._endpointStore, function(super_) {
return {
get: function(id) {
var endpoint = super_.get(id);
if (endpoint.indexOf("http") < 0) {
return "http://" + endpoint;
}
return endpoint;
}
};
});
// Some param names should be lower case to avoid signature mismatches
qq.override(this._paramsStore, function(super_) {
return {
get: function(id) {
var oldParams = super_.get(id),
modifiedParams = {};
qq.each(oldParams, function(name, val) {
var paramName = name;
if (qq.indexOf(qq.s3.util.CASE_SENSITIVE_PARAM_NAMES, paramName) < 0) {
paramName = paramName.toLowerCase();
}
modifiedParams[paramName] = qq.isFunction(val) ? val() : val;
});
return modifiedParams;
}
};
});
additionalOptions.signature.credentialsProvider = {
get: function() {
return self._currentCredentials;
},
onExpired: function() {
var updateCredentials = new qq.Promise(),
callbackRetVal = self._options.callbacks.onCredentialsExpired();
if (qq.isGenericPromise(callbackRetVal)) {
callbackRetVal.then(function(credentials) {
try {
self.setCredentials(credentials);
updateCredentials.success();
}
catch (error) {
self.log("Invalid credentials returned from onCredentialsExpired callback! (" + error.message + ")", "error");
updateCredentials.failure("onCredentialsExpired did not return valid credentials.");
}
}, function(errorMsg) {
self.log("onCredentialsExpired callback indicated failure! (" + errorMsg + ")", "error");
updateCredentials.failure("onCredentialsExpired callback failed.");
});
}
else {
self.log("onCredentialsExpired callback did not return a promise!", "error");
updateCredentials.failure("Unexpected return value for onCredentialsExpired.");
}
return updateCredentials;
}
};
return qq.FineUploaderBasic.prototype._createUploadHandler.call(this, additionalOptions, "s3");
} | javascript | function() {
var self = this,
additionalOptions = {
aclStore: this._aclStore,
getBucket: qq.bind(this._determineBucket, this),
getHost: qq.bind(this._determineHost, this),
getKeyName: qq.bind(this._determineKeyName, this),
iframeSupport: this._options.iframeSupport,
objectProperties: this._options.objectProperties,
signature: this._options.signature,
clockDrift: this._options.request.clockDrift,
// pass size limit validation values to include in the request so AWS enforces this server-side
validation: {
minSizeLimit: this._options.validation.minSizeLimit,
maxSizeLimit: this._options.validation.sizeLimit
}
};
// We assume HTTP if it is missing from the start of the endpoint string.
qq.override(this._endpointStore, function(super_) {
return {
get: function(id) {
var endpoint = super_.get(id);
if (endpoint.indexOf("http") < 0) {
return "http://" + endpoint;
}
return endpoint;
}
};
});
// Some param names should be lower case to avoid signature mismatches
qq.override(this._paramsStore, function(super_) {
return {
get: function(id) {
var oldParams = super_.get(id),
modifiedParams = {};
qq.each(oldParams, function(name, val) {
var paramName = name;
if (qq.indexOf(qq.s3.util.CASE_SENSITIVE_PARAM_NAMES, paramName) < 0) {
paramName = paramName.toLowerCase();
}
modifiedParams[paramName] = qq.isFunction(val) ? val() : val;
});
return modifiedParams;
}
};
});
additionalOptions.signature.credentialsProvider = {
get: function() {
return self._currentCredentials;
},
onExpired: function() {
var updateCredentials = new qq.Promise(),
callbackRetVal = self._options.callbacks.onCredentialsExpired();
if (qq.isGenericPromise(callbackRetVal)) {
callbackRetVal.then(function(credentials) {
try {
self.setCredentials(credentials);
updateCredentials.success();
}
catch (error) {
self.log("Invalid credentials returned from onCredentialsExpired callback! (" + error.message + ")", "error");
updateCredentials.failure("onCredentialsExpired did not return valid credentials.");
}
}, function(errorMsg) {
self.log("onCredentialsExpired callback indicated failure! (" + errorMsg + ")", "error");
updateCredentials.failure("onCredentialsExpired callback failed.");
});
}
else {
self.log("onCredentialsExpired callback did not return a promise!", "error");
updateCredentials.failure("Unexpected return value for onCredentialsExpired.");
}
return updateCredentials;
}
};
return qq.FineUploaderBasic.prototype._createUploadHandler.call(this, additionalOptions, "s3");
} | [
"function",
"(",
")",
"{",
"var",
"self",
"=",
"this",
",",
"additionalOptions",
"=",
"{",
"aclStore",
":",
"this",
".",
"_aclStore",
",",
"getBucket",
":",
"qq",
".",
"bind",
"(",
"this",
".",
"_determineBucket",
",",
"this",
")",
",",
"getHost",
":",
"qq",
".",
"bind",
"(",
"this",
".",
"_determineHost",
",",
"this",
")",
",",
"getKeyName",
":",
"qq",
".",
"bind",
"(",
"this",
".",
"_determineKeyName",
",",
"this",
")",
",",
"iframeSupport",
":",
"this",
".",
"_options",
".",
"iframeSupport",
",",
"objectProperties",
":",
"this",
".",
"_options",
".",
"objectProperties",
",",
"signature",
":",
"this",
".",
"_options",
".",
"signature",
",",
"clockDrift",
":",
"this",
".",
"_options",
".",
"request",
".",
"clockDrift",
",",
"// pass size limit validation values to include in the request so AWS enforces this server-side",
"validation",
":",
"{",
"minSizeLimit",
":",
"this",
".",
"_options",
".",
"validation",
".",
"minSizeLimit",
",",
"maxSizeLimit",
":",
"this",
".",
"_options",
".",
"validation",
".",
"sizeLimit",
"}",
"}",
";",
"// We assume HTTP if it is missing from the start of the endpoint string.",
"qq",
".",
"override",
"(",
"this",
".",
"_endpointStore",
",",
"function",
"(",
"super_",
")",
"{",
"return",
"{",
"get",
":",
"function",
"(",
"id",
")",
"{",
"var",
"endpoint",
"=",
"super_",
".",
"get",
"(",
"id",
")",
";",
"if",
"(",
"endpoint",
".",
"indexOf",
"(",
"\"http\"",
")",
"<",
"0",
")",
"{",
"return",
"\"http://\"",
"+",
"endpoint",
";",
"}",
"return",
"endpoint",
";",
"}",
"}",
";",
"}",
")",
";",
"// Some param names should be lower case to avoid signature mismatches",
"qq",
".",
"override",
"(",
"this",
".",
"_paramsStore",
",",
"function",
"(",
"super_",
")",
"{",
"return",
"{",
"get",
":",
"function",
"(",
"id",
")",
"{",
"var",
"oldParams",
"=",
"super_",
".",
"get",
"(",
"id",
")",
",",
"modifiedParams",
"=",
"{",
"}",
";",
"qq",
".",
"each",
"(",
"oldParams",
",",
"function",
"(",
"name",
",",
"val",
")",
"{",
"var",
"paramName",
"=",
"name",
";",
"if",
"(",
"qq",
".",
"indexOf",
"(",
"qq",
".",
"s3",
".",
"util",
".",
"CASE_SENSITIVE_PARAM_NAMES",
",",
"paramName",
")",
"<",
"0",
")",
"{",
"paramName",
"=",
"paramName",
".",
"toLowerCase",
"(",
")",
";",
"}",
"modifiedParams",
"[",
"paramName",
"]",
"=",
"qq",
".",
"isFunction",
"(",
"val",
")",
"?",
"val",
"(",
")",
":",
"val",
";",
"}",
")",
";",
"return",
"modifiedParams",
";",
"}",
"}",
";",
"}",
")",
";",
"additionalOptions",
".",
"signature",
".",
"credentialsProvider",
"=",
"{",
"get",
":",
"function",
"(",
")",
"{",
"return",
"self",
".",
"_currentCredentials",
";",
"}",
",",
"onExpired",
":",
"function",
"(",
")",
"{",
"var",
"updateCredentials",
"=",
"new",
"qq",
".",
"Promise",
"(",
")",
",",
"callbackRetVal",
"=",
"self",
".",
"_options",
".",
"callbacks",
".",
"onCredentialsExpired",
"(",
")",
";",
"if",
"(",
"qq",
".",
"isGenericPromise",
"(",
"callbackRetVal",
")",
")",
"{",
"callbackRetVal",
".",
"then",
"(",
"function",
"(",
"credentials",
")",
"{",
"try",
"{",
"self",
".",
"setCredentials",
"(",
"credentials",
")",
";",
"updateCredentials",
".",
"success",
"(",
")",
";",
"}",
"catch",
"(",
"error",
")",
"{",
"self",
".",
"log",
"(",
"\"Invalid credentials returned from onCredentialsExpired callback! (\"",
"+",
"error",
".",
"message",
"+",
"\")\"",
",",
"\"error\"",
")",
";",
"updateCredentials",
".",
"failure",
"(",
"\"onCredentialsExpired did not return valid credentials.\"",
")",
";",
"}",
"}",
",",
"function",
"(",
"errorMsg",
")",
"{",
"self",
".",
"log",
"(",
"\"onCredentialsExpired callback indicated failure! (\"",
"+",
"errorMsg",
"+",
"\")\"",
",",
"\"error\"",
")",
";",
"updateCredentials",
".",
"failure",
"(",
"\"onCredentialsExpired callback failed.\"",
")",
";",
"}",
")",
";",
"}",
"else",
"{",
"self",
".",
"log",
"(",
"\"onCredentialsExpired callback did not return a promise!\"",
",",
"\"error\"",
")",
";",
"updateCredentials",
".",
"failure",
"(",
"\"Unexpected return value for onCredentialsExpired.\"",
")",
";",
"}",
"return",
"updateCredentials",
";",
"}",
"}",
";",
"return",
"qq",
".",
"FineUploaderBasic",
".",
"prototype",
".",
"_createUploadHandler",
".",
"call",
"(",
"this",
",",
"additionalOptions",
",",
"\"s3\"",
")",
";",
"}"
] | Ensures the parent's upload handler creator passes any additional S3-specific options to the handler as well
as information required to instantiate the specific handler based on the current browser's capabilities.
@returns {qq.UploadHandlerController}
@private | [
"Ensures",
"the",
"parent",
"s",
"upload",
"handler",
"creator",
"passes",
"any",
"additional",
"S3",
"-",
"specific",
"options",
"to",
"the",
"handler",
"as",
"well",
"as",
"information",
"required",
"to",
"instantiate",
"the",
"specific",
"handler",
"based",
"on",
"the",
"current",
"browser",
"s",
"capabilities",
"."
] | 057cc83a7e7657d032a75cf4a6b3612c7b4191da | https://github.com/FineUploader/fine-uploader/blob/057cc83a7e7657d032a75cf4a6b3612c7b4191da/client/js/s3/uploader.basic.js#L197-L286 |
|
5,589 | FineUploader/fine-uploader | client/js/s3/uploader.basic.js | function(keynameFunc, id, successCallback, failureCallback) {
var self = this,
onSuccess = function(keyname) {
successCallback(keyname);
},
onFailure = function(reason) {
self.log(qq.format("Failed to retrieve key name for {}. Reason: {}", id, reason || "null"), "error");
failureCallback(reason);
},
keyname = keynameFunc.call(this, id);
if (qq.isGenericPromise(keyname)) {
keyname.then(onSuccess, onFailure);
}
/*jshint -W116*/
else if (keyname == null) {
onFailure();
}
else {
onSuccess(keyname);
}
} | javascript | function(keynameFunc, id, successCallback, failureCallback) {
var self = this,
onSuccess = function(keyname) {
successCallback(keyname);
},
onFailure = function(reason) {
self.log(qq.format("Failed to retrieve key name for {}. Reason: {}", id, reason || "null"), "error");
failureCallback(reason);
},
keyname = keynameFunc.call(this, id);
if (qq.isGenericPromise(keyname)) {
keyname.then(onSuccess, onFailure);
}
/*jshint -W116*/
else if (keyname == null) {
onFailure();
}
else {
onSuccess(keyname);
}
} | [
"function",
"(",
"keynameFunc",
",",
"id",
",",
"successCallback",
",",
"failureCallback",
")",
"{",
"var",
"self",
"=",
"this",
",",
"onSuccess",
"=",
"function",
"(",
"keyname",
")",
"{",
"successCallback",
"(",
"keyname",
")",
";",
"}",
",",
"onFailure",
"=",
"function",
"(",
"reason",
")",
"{",
"self",
".",
"log",
"(",
"qq",
".",
"format",
"(",
"\"Failed to retrieve key name for {}. Reason: {}\"",
",",
"id",
",",
"reason",
"||",
"\"null\"",
")",
",",
"\"error\"",
")",
";",
"failureCallback",
"(",
"reason",
")",
";",
"}",
",",
"keyname",
"=",
"keynameFunc",
".",
"call",
"(",
"this",
",",
"id",
")",
";",
"if",
"(",
"qq",
".",
"isGenericPromise",
"(",
"keyname",
")",
")",
"{",
"keyname",
".",
"then",
"(",
"onSuccess",
",",
"onFailure",
")",
";",
"}",
"/*jshint -W116*/",
"else",
"if",
"(",
"keyname",
"==",
"null",
")",
"{",
"onFailure",
"(",
")",
";",
"}",
"else",
"{",
"onSuccess",
"(",
"keyname",
")",
";",
"}",
"}"
] | Called by the internal onUpload handler if the integrator has supplied a function to determine
the file's key name. The integrator's function may be promissory. We also need to fulfill
the promise contract associated with the caller as well.
@param keynameFunc Integrator-supplied function that must be executed to determine the key name. May be promissory.
@param id ID of the associated file
@param successCallback Invoke this if key name retrieval is successful, passing in the key name.
@param failureCallback Invoke this if key name retrieval was unsuccessful.
@private | [
"Called",
"by",
"the",
"internal",
"onUpload",
"handler",
"if",
"the",
"integrator",
"has",
"supplied",
"a",
"function",
"to",
"determine",
"the",
"file",
"s",
"key",
"name",
".",
"The",
"integrator",
"s",
"function",
"may",
"be",
"promissory",
".",
"We",
"also",
"need",
"to",
"fulfill",
"the",
"promise",
"contract",
"associated",
"with",
"the",
"caller",
"as",
"well",
"."
] | 057cc83a7e7657d032a75cf4a6b3612c7b4191da | https://github.com/FineUploader/fine-uploader/blob/057cc83a7e7657d032a75cf4a6b3612c7b4191da/client/js/s3/uploader.basic.js#L384-L405 |
|
5,590 | FineUploader/fine-uploader | client/js/s3/uploader.basic.js | function(id, onSuccessCallback) {
var additionalMandatedParams = {
key: this.getKey(id),
bucket: this.getBucket(id)
};
return qq.FineUploaderBasic.prototype._onSubmitDelete.call(this, id, onSuccessCallback, additionalMandatedParams);
} | javascript | function(id, onSuccessCallback) {
var additionalMandatedParams = {
key: this.getKey(id),
bucket: this.getBucket(id)
};
return qq.FineUploaderBasic.prototype._onSubmitDelete.call(this, id, onSuccessCallback, additionalMandatedParams);
} | [
"function",
"(",
"id",
",",
"onSuccessCallback",
")",
"{",
"var",
"additionalMandatedParams",
"=",
"{",
"key",
":",
"this",
".",
"getKey",
"(",
"id",
")",
",",
"bucket",
":",
"this",
".",
"getBucket",
"(",
"id",
")",
"}",
";",
"return",
"qq",
".",
"FineUploaderBasic",
".",
"prototype",
".",
"_onSubmitDelete",
".",
"call",
"(",
"this",
",",
"id",
",",
"onSuccessCallback",
",",
"additionalMandatedParams",
")",
";",
"}"
] | Hooks into the base internal `_onSubmitDelete` to add key and bucket params to the delete file request. | [
"Hooks",
"into",
"the",
"base",
"internal",
"_onSubmitDelete",
"to",
"add",
"key",
"and",
"bucket",
"params",
"to",
"the",
"delete",
"file",
"request",
"."
] | 057cc83a7e7657d032a75cf4a6b3612c7b4191da | https://github.com/FineUploader/fine-uploader/blob/057cc83a7e7657d032a75cf4a6b3612c7b4191da/client/js/s3/uploader.basic.js#L426-L433 |
|
5,591 | FineUploader/fine-uploader | client/js/upload-handler/upload.handler.controller.js | function(id, chunkIdx, response, xhr) {
var chunkData = handler._getChunkData(id, chunkIdx);
handler._getFileState(id).attemptingResume = false;
delete handler._getFileState(id).temp.chunkProgress[chunkIdx];
handler._getFileState(id).loaded += chunkData.size;
options.onUploadChunkSuccess(id, handler._getChunkDataForCallback(chunkData), response, xhr);
} | javascript | function(id, chunkIdx, response, xhr) {
var chunkData = handler._getChunkData(id, chunkIdx);
handler._getFileState(id).attemptingResume = false;
delete handler._getFileState(id).temp.chunkProgress[chunkIdx];
handler._getFileState(id).loaded += chunkData.size;
options.onUploadChunkSuccess(id, handler._getChunkDataForCallback(chunkData), response, xhr);
} | [
"function",
"(",
"id",
",",
"chunkIdx",
",",
"response",
",",
"xhr",
")",
"{",
"var",
"chunkData",
"=",
"handler",
".",
"_getChunkData",
"(",
"id",
",",
"chunkIdx",
")",
";",
"handler",
".",
"_getFileState",
"(",
"id",
")",
".",
"attemptingResume",
"=",
"false",
";",
"delete",
"handler",
".",
"_getFileState",
"(",
"id",
")",
".",
"temp",
".",
"chunkProgress",
"[",
"chunkIdx",
"]",
";",
"handler",
".",
"_getFileState",
"(",
"id",
")",
".",
"loaded",
"+=",
"chunkData",
".",
"size",
";",
"options",
".",
"onUploadChunkSuccess",
"(",
"id",
",",
"handler",
".",
"_getChunkDataForCallback",
"(",
"chunkData",
")",
",",
"response",
",",
"xhr",
")",
";",
"}"
] | Called when each chunk has uploaded successfully | [
"Called",
"when",
"each",
"chunk",
"has",
"uploaded",
"successfully"
] | 057cc83a7e7657d032a75cf4a6b3612c7b4191da | https://github.com/FineUploader/fine-uploader/blob/057cc83a7e7657d032a75cf4a6b3612c7b4191da/client/js/upload-handler/upload.handler.controller.js#L46-L55 |
|
5,592 | FineUploader/fine-uploader | client/js/upload-handler/upload.handler.controller.js | function(id) {
var size = options.getSize(id),
name = options.getName(id);
log("All chunks have been uploaded for " + id + " - finalizing....");
handler.finalizeChunks(id).then(
function(response, xhr) {
log("Finalize successful for " + id);
var normaizedResponse = upload.normalizeResponse(response, true);
options.onProgress(id, name, size, size);
handler._maybeDeletePersistedChunkData(id);
upload.cleanup(id, normaizedResponse, xhr);
},
function(response, xhr) {
var normalizedResponse = upload.normalizeResponse(response, false);
log("Problem finalizing chunks for file ID " + id + " - " + normalizedResponse.error, "error");
if (
normalizedResponse.reset ||
(xhr && options.chunking.success.resetOnStatus.indexOf(xhr.status) >= 0)
) {
chunked.reset(id);
}
if (!options.onAutoRetry(id, name, normalizedResponse, xhr)) {
upload.cleanup(id, normalizedResponse, xhr);
}
}
);
} | javascript | function(id) {
var size = options.getSize(id),
name = options.getName(id);
log("All chunks have been uploaded for " + id + " - finalizing....");
handler.finalizeChunks(id).then(
function(response, xhr) {
log("Finalize successful for " + id);
var normaizedResponse = upload.normalizeResponse(response, true);
options.onProgress(id, name, size, size);
handler._maybeDeletePersistedChunkData(id);
upload.cleanup(id, normaizedResponse, xhr);
},
function(response, xhr) {
var normalizedResponse = upload.normalizeResponse(response, false);
log("Problem finalizing chunks for file ID " + id + " - " + normalizedResponse.error, "error");
if (
normalizedResponse.reset ||
(xhr && options.chunking.success.resetOnStatus.indexOf(xhr.status) >= 0)
) {
chunked.reset(id);
}
if (!options.onAutoRetry(id, name, normalizedResponse, xhr)) {
upload.cleanup(id, normalizedResponse, xhr);
}
}
);
} | [
"function",
"(",
"id",
")",
"{",
"var",
"size",
"=",
"options",
".",
"getSize",
"(",
"id",
")",
",",
"name",
"=",
"options",
".",
"getName",
"(",
"id",
")",
";",
"log",
"(",
"\"All chunks have been uploaded for \"",
"+",
"id",
"+",
"\" - finalizing....\"",
")",
";",
"handler",
".",
"finalizeChunks",
"(",
"id",
")",
".",
"then",
"(",
"function",
"(",
"response",
",",
"xhr",
")",
"{",
"log",
"(",
"\"Finalize successful for \"",
"+",
"id",
")",
";",
"var",
"normaizedResponse",
"=",
"upload",
".",
"normalizeResponse",
"(",
"response",
",",
"true",
")",
";",
"options",
".",
"onProgress",
"(",
"id",
",",
"name",
",",
"size",
",",
"size",
")",
";",
"handler",
".",
"_maybeDeletePersistedChunkData",
"(",
"id",
")",
";",
"upload",
".",
"cleanup",
"(",
"id",
",",
"normaizedResponse",
",",
"xhr",
")",
";",
"}",
",",
"function",
"(",
"response",
",",
"xhr",
")",
"{",
"var",
"normalizedResponse",
"=",
"upload",
".",
"normalizeResponse",
"(",
"response",
",",
"false",
")",
";",
"log",
"(",
"\"Problem finalizing chunks for file ID \"",
"+",
"id",
"+",
"\" - \"",
"+",
"normalizedResponse",
".",
"error",
",",
"\"error\"",
")",
";",
"if",
"(",
"normalizedResponse",
".",
"reset",
"||",
"(",
"xhr",
"&&",
"options",
".",
"chunking",
".",
"success",
".",
"resetOnStatus",
".",
"indexOf",
"(",
"xhr",
".",
"status",
")",
">=",
"0",
")",
")",
"{",
"chunked",
".",
"reset",
"(",
"id",
")",
";",
"}",
"if",
"(",
"!",
"options",
".",
"onAutoRetry",
"(",
"id",
",",
"name",
",",
"normalizedResponse",
",",
"xhr",
")",
")",
"{",
"upload",
".",
"cleanup",
"(",
"id",
",",
"normalizedResponse",
",",
"xhr",
")",
";",
"}",
"}",
")",
";",
"}"
] | Called when all chunks have been successfully uploaded and we want to ask the handler to perform any logic associated with closing out the file, such as combining the chunks. | [
"Called",
"when",
"all",
"chunks",
"have",
"been",
"successfully",
"uploaded",
"and",
"we",
"want",
"to",
"ask",
"the",
"handler",
"to",
"perform",
"any",
"logic",
"associated",
"with",
"closing",
"out",
"the",
"file",
"such",
"as",
"combining",
"the",
"chunks",
"."
] | 057cc83a7e7657d032a75cf4a6b3612c7b4191da | https://github.com/FineUploader/fine-uploader/blob/057cc83a7e7657d032a75cf4a6b3612c7b4191da/client/js/upload-handler/upload.handler.controller.js#L59-L91 |
|
5,593 | FineUploader/fine-uploader | client/js/upload-handler/upload.handler.controller.js | function(errorMessage) {
var errorResponse = {};
if (errorMessage) {
errorResponse.error = errorMessage;
}
log(qq.format("Failed to generate blob for ID {}. Error message: {}.", id, errorMessage), "error");
options.onComplete(id, options.getName(id), qq.extend(errorResponse, preventRetryResponse), null);
upload.maybeSendDeferredFiles(id);
connectionManager.free(id);
} | javascript | function(errorMessage) {
var errorResponse = {};
if (errorMessage) {
errorResponse.error = errorMessage;
}
log(qq.format("Failed to generate blob for ID {}. Error message: {}.", id, errorMessage), "error");
options.onComplete(id, options.getName(id), qq.extend(errorResponse, preventRetryResponse), null);
upload.maybeSendDeferredFiles(id);
connectionManager.free(id);
} | [
"function",
"(",
"errorMessage",
")",
"{",
"var",
"errorResponse",
"=",
"{",
"}",
";",
"if",
"(",
"errorMessage",
")",
"{",
"errorResponse",
".",
"error",
"=",
"errorMessage",
";",
"}",
"log",
"(",
"qq",
".",
"format",
"(",
"\"Failed to generate blob for ID {}. Error message: {}.\"",
",",
"id",
",",
"errorMessage",
")",
",",
"\"error\"",
")",
";",
"options",
".",
"onComplete",
"(",
"id",
",",
"options",
".",
"getName",
"(",
"id",
")",
",",
"qq",
".",
"extend",
"(",
"errorResponse",
",",
"preventRetryResponse",
")",
",",
"null",
")",
";",
"upload",
".",
"maybeSendDeferredFiles",
"(",
"id",
")",
";",
"connectionManager",
".",
"free",
"(",
"id",
")",
";",
"}"
] | Blob could not be generated. Fail the upload & attempt to prevent retries. Also bubble error message. | [
"Blob",
"could",
"not",
"be",
"generated",
".",
"Fail",
"the",
"upload",
"&",
"attempt",
"to",
"prevent",
"retries",
".",
"Also",
"bubble",
"error",
"message",
"."
] | 057cc83a7e7657d032a75cf4a6b3612c7b4191da | https://github.com/FineUploader/fine-uploader/blob/057cc83a7e7657d032a75cf4a6b3612c7b4191da/client/js/upload-handler/upload.handler.controller.js#L519-L531 |
|
5,594 | FineUploader/fine-uploader | client/js/upload-handler/upload.handler.controller.js | function(originalResponse, successful) {
var response = originalResponse;
// The passed "response" param may not be a response at all.
// It could be a string, detailing the error, for example.
if (!qq.isObject(originalResponse)) {
response = {};
if (qq.isString(originalResponse) && !successful) {
response.error = originalResponse;
}
}
response.success = successful;
return response;
} | javascript | function(originalResponse, successful) {
var response = originalResponse;
// The passed "response" param may not be a response at all.
// It could be a string, detailing the error, for example.
if (!qq.isObject(originalResponse)) {
response = {};
if (qq.isString(originalResponse) && !successful) {
response.error = originalResponse;
}
}
response.success = successful;
return response;
} | [
"function",
"(",
"originalResponse",
",",
"successful",
")",
"{",
"var",
"response",
"=",
"originalResponse",
";",
"// The passed \"response\" param may not be a response at all.",
"// It could be a string, detailing the error, for example.",
"if",
"(",
"!",
"qq",
".",
"isObject",
"(",
"originalResponse",
")",
")",
"{",
"response",
"=",
"{",
"}",
";",
"if",
"(",
"qq",
".",
"isString",
"(",
"originalResponse",
")",
"&&",
"!",
"successful",
")",
"{",
"response",
".",
"error",
"=",
"originalResponse",
";",
"}",
"}",
"response",
".",
"success",
"=",
"successful",
";",
"return",
"response",
";",
"}"
] | The response coming from handler implementations may be in various formats. Instead of hoping a promise nested 5 levels deep will always return an object as its first param, let's just normalize the response here. | [
"The",
"response",
"coming",
"from",
"handler",
"implementations",
"may",
"be",
"in",
"various",
"formats",
".",
"Instead",
"of",
"hoping",
"a",
"promise",
"nested",
"5",
"levels",
"deep",
"will",
"always",
"return",
"an",
"object",
"as",
"its",
"first",
"param",
"let",
"s",
"just",
"normalize",
"the",
"response",
"here",
"."
] | 057cc83a7e7657d032a75cf4a6b3612c7b4191da | https://github.com/FineUploader/fine-uploader/blob/057cc83a7e7657d032a75cf4a6b3612c7b4191da/client/js/upload-handler/upload.handler.controller.js#L575-L591 |
|
5,595 | FineUploader/fine-uploader | client/js/upload-handler/upload.handler.controller.js | function() {
var waitingOrConnected = connectionManager.getWaitingOrConnected(),
i;
// ensure files are cancelled in reverse order which they were added
// to avoid a flash of time where a queued file begins to upload before it is canceled
if (waitingOrConnected.length) {
for (i = waitingOrConnected.length - 1; i >= 0; i--) {
controller.cancel(waitingOrConnected[i]);
}
}
connectionManager.reset();
} | javascript | function() {
var waitingOrConnected = connectionManager.getWaitingOrConnected(),
i;
// ensure files are cancelled in reverse order which they were added
// to avoid a flash of time where a queued file begins to upload before it is canceled
if (waitingOrConnected.length) {
for (i = waitingOrConnected.length - 1; i >= 0; i--) {
controller.cancel(waitingOrConnected[i]);
}
}
connectionManager.reset();
} | [
"function",
"(",
")",
"{",
"var",
"waitingOrConnected",
"=",
"connectionManager",
".",
"getWaitingOrConnected",
"(",
")",
",",
"i",
";",
"// ensure files are cancelled in reverse order which they were added",
"// to avoid a flash of time where a queued file begins to upload before it is canceled",
"if",
"(",
"waitingOrConnected",
".",
"length",
")",
"{",
"for",
"(",
"i",
"=",
"waitingOrConnected",
".",
"length",
"-",
"1",
";",
"i",
">=",
"0",
";",
"i",
"--",
")",
"{",
"controller",
".",
"cancel",
"(",
"waitingOrConnected",
"[",
"i",
"]",
")",
";",
"}",
"}",
"connectionManager",
".",
"reset",
"(",
")",
";",
"}"
] | Cancels all queued or in-progress uploads | [
"Cancels",
"all",
"queued",
"or",
"in",
"-",
"progress",
"uploads"
] | 057cc83a7e7657d032a75cf4a6b3612c7b4191da | https://github.com/FineUploader/fine-uploader/blob/057cc83a7e7657d032a75cf4a6b3612c7b4191da/client/js/upload-handler/upload.handler.controller.js#L703-L716 |
|
5,596 | FineUploader/fine-uploader | client/js/upload-handler/upload.handler.controller.js | function(id) {
if (controller.isResumable(id) && handler.pause && controller.isValid(id) && handler.pause(id)) {
connectionManager.free(id);
handler.moveInProgressToRemaining(id);
return true;
}
return false;
} | javascript | function(id) {
if (controller.isResumable(id) && handler.pause && controller.isValid(id) && handler.pause(id)) {
connectionManager.free(id);
handler.moveInProgressToRemaining(id);
return true;
}
return false;
} | [
"function",
"(",
"id",
")",
"{",
"if",
"(",
"controller",
".",
"isResumable",
"(",
"id",
")",
"&&",
"handler",
".",
"pause",
"&&",
"controller",
".",
"isValid",
"(",
"id",
")",
"&&",
"handler",
".",
"pause",
"(",
"id",
")",
")",
"{",
"connectionManager",
".",
"free",
"(",
"id",
")",
";",
"handler",
".",
"moveInProgressToRemaining",
"(",
"id",
")",
";",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
] | Attempts to pause the associated upload if the specific handler supports this and the file is "valid".
@param id ID of the upload/file to pause
@returns {boolean} true if the upload was paused | [
"Attempts",
"to",
"pause",
"the",
"associated",
"upload",
"if",
"the",
"specific",
"handler",
"supports",
"this",
"and",
"the",
"file",
"is",
"valid",
"."
] | 057cc83a7e7657d032a75cf4a6b3612c7b4191da | https://github.com/FineUploader/fine-uploader/blob/057cc83a7e7657d032a75cf4a6b3612c7b4191da/client/js/upload-handler/upload.handler.controller.js#L797-L804 |
|
5,597 | FineUploader/fine-uploader | client/js/features.js | isChrome14OrHigher | function isChrome14OrHigher() {
return (qq.chrome() || qq.opera()) &&
navigator.userAgent.match(/Chrome\/[1][4-9]|Chrome\/[2-9][0-9]/) !== undefined;
} | javascript | function isChrome14OrHigher() {
return (qq.chrome() || qq.opera()) &&
navigator.userAgent.match(/Chrome\/[1][4-9]|Chrome\/[2-9][0-9]/) !== undefined;
} | [
"function",
"isChrome14OrHigher",
"(",
")",
"{",
"return",
"(",
"qq",
".",
"chrome",
"(",
")",
"||",
"qq",
".",
"opera",
"(",
")",
")",
"&&",
"navigator",
".",
"userAgent",
".",
"match",
"(",
"/",
"Chrome\\/[1][4-9]|Chrome\\/[2-9][0-9]",
"/",
")",
"!==",
"undefined",
";",
"}"
] | only way to test for complete Clipboard API support at this time | [
"only",
"way",
"to",
"test",
"for",
"complete",
"Clipboard",
"API",
"support",
"at",
"this",
"time"
] | 057cc83a7e7657d032a75cf4a6b3612c7b4191da | https://github.com/FineUploader/fine-uploader/blob/057cc83a7e7657d032a75cf4a6b3612c7b4191da/client/js/features.js#L42-L45 |
5,598 | FineUploader/fine-uploader | client/js/features.js | isCrossOriginXhrSupported | function isCrossOriginXhrSupported() {
if (window.XMLHttpRequest) {
var xhr = qq.createXhrInstance();
//Commonly accepted test for XHR CORS support.
return xhr.withCredentials !== undefined;
}
return false;
} | javascript | function isCrossOriginXhrSupported() {
if (window.XMLHttpRequest) {
var xhr = qq.createXhrInstance();
//Commonly accepted test for XHR CORS support.
return xhr.withCredentials !== undefined;
}
return false;
} | [
"function",
"isCrossOriginXhrSupported",
"(",
")",
"{",
"if",
"(",
"window",
".",
"XMLHttpRequest",
")",
"{",
"var",
"xhr",
"=",
"qq",
".",
"createXhrInstance",
"(",
")",
";",
"//Commonly accepted test for XHR CORS support.",
"return",
"xhr",
".",
"withCredentials",
"!==",
"undefined",
";",
"}",
"return",
"false",
";",
"}"
] | Ensure we can send cross-origin `XMLHttpRequest`s | [
"Ensure",
"we",
"can",
"send",
"cross",
"-",
"origin",
"XMLHttpRequest",
"s"
] | 057cc83a7e7657d032a75cf4a6b3612c7b4191da | https://github.com/FineUploader/fine-uploader/blob/057cc83a7e7657d032a75cf4a6b3612c7b4191da/client/js/features.js#L48-L57 |
5,599 | FineUploader/fine-uploader | client/js/s3/request-signer.js | function(id, toBeSigned) {
var params = toBeSigned,
signatureConstructor = toBeSigned.signatureConstructor,
signatureEffort = new qq.Promise(),
queryParams;
if (options.signatureSpec.version === 4) {
queryParams = {v4: true};
}
if (credentialsProvider.get().secretKey && qq.CryptoJS) {
if (credentialsProvider.get().expiration.getTime() > Date.now()) {
determineSignatureClientSide(id, toBeSigned, signatureEffort);
}
// If credentials are expired, ask for new ones before attempting to sign request
else {
credentialsProvider.onExpired().then(function() {
determineSignatureClientSide(id, toBeSigned,
signatureEffort,
credentialsProvider.get().accessKey,
credentialsProvider.get().sessionToken);
}, function(errorMsg) {
options.log("Attempt to update expired credentials apparently failed! Unable to sign request. ", "error");
signatureEffort.failure("Unable to sign request - expired credentials.");
});
}
}
else {
options.log("Submitting S3 signature request for " + id);
if (signatureConstructor) {
signatureConstructor.getToSign(id).then(function(signatureArtifacts) {
params = {headers: signatureArtifacts.stringToSignRaw};
requester.initTransport(id)
.withParams(params)
.withQueryParams(queryParams)
.send();
}, function (err) {
options.log("Failed to construct signature. ", "error");
signatureEffort.failure("Failed to construct signature.");
});
}
else {
requester.initTransport(id)
.withParams(params)
.withQueryParams(queryParams)
.send();
}
pendingSignatures[id] = {
promise: signatureEffort,
signatureConstructor: signatureConstructor
};
}
return signatureEffort;
} | javascript | function(id, toBeSigned) {
var params = toBeSigned,
signatureConstructor = toBeSigned.signatureConstructor,
signatureEffort = new qq.Promise(),
queryParams;
if (options.signatureSpec.version === 4) {
queryParams = {v4: true};
}
if (credentialsProvider.get().secretKey && qq.CryptoJS) {
if (credentialsProvider.get().expiration.getTime() > Date.now()) {
determineSignatureClientSide(id, toBeSigned, signatureEffort);
}
// If credentials are expired, ask for new ones before attempting to sign request
else {
credentialsProvider.onExpired().then(function() {
determineSignatureClientSide(id, toBeSigned,
signatureEffort,
credentialsProvider.get().accessKey,
credentialsProvider.get().sessionToken);
}, function(errorMsg) {
options.log("Attempt to update expired credentials apparently failed! Unable to sign request. ", "error");
signatureEffort.failure("Unable to sign request - expired credentials.");
});
}
}
else {
options.log("Submitting S3 signature request for " + id);
if (signatureConstructor) {
signatureConstructor.getToSign(id).then(function(signatureArtifacts) {
params = {headers: signatureArtifacts.stringToSignRaw};
requester.initTransport(id)
.withParams(params)
.withQueryParams(queryParams)
.send();
}, function (err) {
options.log("Failed to construct signature. ", "error");
signatureEffort.failure("Failed to construct signature.");
});
}
else {
requester.initTransport(id)
.withParams(params)
.withQueryParams(queryParams)
.send();
}
pendingSignatures[id] = {
promise: signatureEffort,
signatureConstructor: signatureConstructor
};
}
return signatureEffort;
} | [
"function",
"(",
"id",
",",
"toBeSigned",
")",
"{",
"var",
"params",
"=",
"toBeSigned",
",",
"signatureConstructor",
"=",
"toBeSigned",
".",
"signatureConstructor",
",",
"signatureEffort",
"=",
"new",
"qq",
".",
"Promise",
"(",
")",
",",
"queryParams",
";",
"if",
"(",
"options",
".",
"signatureSpec",
".",
"version",
"===",
"4",
")",
"{",
"queryParams",
"=",
"{",
"v4",
":",
"true",
"}",
";",
"}",
"if",
"(",
"credentialsProvider",
".",
"get",
"(",
")",
".",
"secretKey",
"&&",
"qq",
".",
"CryptoJS",
")",
"{",
"if",
"(",
"credentialsProvider",
".",
"get",
"(",
")",
".",
"expiration",
".",
"getTime",
"(",
")",
">",
"Date",
".",
"now",
"(",
")",
")",
"{",
"determineSignatureClientSide",
"(",
"id",
",",
"toBeSigned",
",",
"signatureEffort",
")",
";",
"}",
"// If credentials are expired, ask for new ones before attempting to sign request",
"else",
"{",
"credentialsProvider",
".",
"onExpired",
"(",
")",
".",
"then",
"(",
"function",
"(",
")",
"{",
"determineSignatureClientSide",
"(",
"id",
",",
"toBeSigned",
",",
"signatureEffort",
",",
"credentialsProvider",
".",
"get",
"(",
")",
".",
"accessKey",
",",
"credentialsProvider",
".",
"get",
"(",
")",
".",
"sessionToken",
")",
";",
"}",
",",
"function",
"(",
"errorMsg",
")",
"{",
"options",
".",
"log",
"(",
"\"Attempt to update expired credentials apparently failed! Unable to sign request. \"",
",",
"\"error\"",
")",
";",
"signatureEffort",
".",
"failure",
"(",
"\"Unable to sign request - expired credentials.\"",
")",
";",
"}",
")",
";",
"}",
"}",
"else",
"{",
"options",
".",
"log",
"(",
"\"Submitting S3 signature request for \"",
"+",
"id",
")",
";",
"if",
"(",
"signatureConstructor",
")",
"{",
"signatureConstructor",
".",
"getToSign",
"(",
"id",
")",
".",
"then",
"(",
"function",
"(",
"signatureArtifacts",
")",
"{",
"params",
"=",
"{",
"headers",
":",
"signatureArtifacts",
".",
"stringToSignRaw",
"}",
";",
"requester",
".",
"initTransport",
"(",
"id",
")",
".",
"withParams",
"(",
"params",
")",
".",
"withQueryParams",
"(",
"queryParams",
")",
".",
"send",
"(",
")",
";",
"}",
",",
"function",
"(",
"err",
")",
"{",
"options",
".",
"log",
"(",
"\"Failed to construct signature. \"",
",",
"\"error\"",
")",
";",
"signatureEffort",
".",
"failure",
"(",
"\"Failed to construct signature.\"",
")",
";",
"}",
")",
";",
"}",
"else",
"{",
"requester",
".",
"initTransport",
"(",
"id",
")",
".",
"withParams",
"(",
"params",
")",
".",
"withQueryParams",
"(",
"queryParams",
")",
".",
"send",
"(",
")",
";",
"}",
"pendingSignatures",
"[",
"id",
"]",
"=",
"{",
"promise",
":",
"signatureEffort",
",",
"signatureConstructor",
":",
"signatureConstructor",
"}",
";",
"}",
"return",
"signatureEffort",
";",
"}"
] | On success, an object containing the parsed JSON response will be passed into the success handler if the
request succeeds. Otherwise an error message will be passed into the failure method.
@param id File ID.
@param toBeSigned an Object that holds the item(s) to be signed
@returns {qq.Promise} A promise that is fulfilled when the response has been received. | [
"On",
"success",
"an",
"object",
"containing",
"the",
"parsed",
"JSON",
"response",
"will",
"be",
"passed",
"into",
"the",
"success",
"handler",
"if",
"the",
"request",
"succeeds",
".",
"Otherwise",
"an",
"error",
"message",
"will",
"be",
"passed",
"into",
"the",
"failure",
"method",
"."
] | 057cc83a7e7657d032a75cf4a6b3612c7b4191da | https://github.com/FineUploader/fine-uploader/blob/057cc83a7e7657d032a75cf4a6b3612c7b4191da/client/js/s3/request-signer.js#L489-L545 |
Subsets and Splits