id
int32 0
58k
| repo
stringlengths 5
67
| path
stringlengths 4
116
| func_name
stringlengths 0
58
| original_string
stringlengths 52
373k
| language
stringclasses 1
value | code
stringlengths 52
373k
| code_tokens
list | docstring
stringlengths 4
11.8k
| docstring_tokens
list | sha
stringlengths 40
40
| url
stringlengths 86
226
|
|---|---|---|---|---|---|---|---|---|---|---|---|
10,700
|
mar10/fancytree
|
dist/jquery.fancytree-all-deps.js
|
_goto
|
function _goto(n) {
if (n) {
// setFocus/setActive will scroll later (if autoScroll is specified)
try {
n.makeVisible({ scrollIntoView: false });
} catch (e) {} // #272
// Node may still be hidden by a filter
if (!$(n.span).is(":visible")) {
n.debug("Navigate: skipping hidden node");
n.navigate(where, activate);
return;
}
return activate === false ? n.setFocus() : n.setActive();
}
}
|
javascript
|
function _goto(n) {
if (n) {
// setFocus/setActive will scroll later (if autoScroll is specified)
try {
n.makeVisible({ scrollIntoView: false });
} catch (e) {} // #272
// Node may still be hidden by a filter
if (!$(n.span).is(":visible")) {
n.debug("Navigate: skipping hidden node");
n.navigate(where, activate);
return;
}
return activate === false ? n.setFocus() : n.setActive();
}
}
|
[
"function",
"_goto",
"(",
"n",
")",
"{",
"if",
"(",
"n",
")",
"{",
"// setFocus/setActive will scroll later (if autoScroll is specified)",
"try",
"{",
"n",
".",
"makeVisible",
"(",
"{",
"scrollIntoView",
":",
"false",
"}",
")",
";",
"}",
"catch",
"(",
"e",
")",
"{",
"}",
"// #272",
"// Node may still be hidden by a filter",
"if",
"(",
"!",
"$",
"(",
"n",
".",
"span",
")",
".",
"is",
"(",
"\":visible\"",
")",
")",
"{",
"n",
".",
"debug",
"(",
"\"Navigate: skipping hidden node\"",
")",
";",
"n",
".",
"navigate",
"(",
"where",
",",
"activate",
")",
";",
"return",
";",
"}",
"return",
"activate",
"===",
"false",
"?",
"n",
".",
"setFocus",
"(",
")",
":",
"n",
".",
"setActive",
"(",
")",
";",
"}",
"}"
] |
Navigate to node
|
[
"Navigate",
"to",
"node"
] |
54307b76844177207e321c5b88eb03a23a6e23a2
|
https://github.com/mar10/fancytree/blob/54307b76844177207e321c5b88eb03a23a6e23a2/dist/jquery.fancytree-all-deps.js#L3137-L3151
|
10,701
|
mar10/fancytree
|
dist/jquery.fancytree-all-deps.js
|
function(cmp, deep) {
var i,
l,
cl = this.children;
if (!cl) {
return;
}
cmp =
cmp ||
function(a, b) {
var x = a.title.toLowerCase(),
y = b.title.toLowerCase();
return x === y ? 0 : x > y ? 1 : -1;
};
cl.sort(cmp);
if (deep) {
for (i = 0, l = cl.length; i < l; i++) {
if (cl[i].children) {
cl[i].sortChildren(cmp, "$norender$");
}
}
}
if (deep !== "$norender$") {
this.render();
}
this.triggerModifyChild("sort");
}
|
javascript
|
function(cmp, deep) {
var i,
l,
cl = this.children;
if (!cl) {
return;
}
cmp =
cmp ||
function(a, b) {
var x = a.title.toLowerCase(),
y = b.title.toLowerCase();
return x === y ? 0 : x > y ? 1 : -1;
};
cl.sort(cmp);
if (deep) {
for (i = 0, l = cl.length; i < l; i++) {
if (cl[i].children) {
cl[i].sortChildren(cmp, "$norender$");
}
}
}
if (deep !== "$norender$") {
this.render();
}
this.triggerModifyChild("sort");
}
|
[
"function",
"(",
"cmp",
",",
"deep",
")",
"{",
"var",
"i",
",",
"l",
",",
"cl",
"=",
"this",
".",
"children",
";",
"if",
"(",
"!",
"cl",
")",
"{",
"return",
";",
"}",
"cmp",
"=",
"cmp",
"||",
"function",
"(",
"a",
",",
"b",
")",
"{",
"var",
"x",
"=",
"a",
".",
"title",
".",
"toLowerCase",
"(",
")",
",",
"y",
"=",
"b",
".",
"title",
".",
"toLowerCase",
"(",
")",
";",
"return",
"x",
"===",
"y",
"?",
"0",
":",
"x",
">",
"y",
"?",
"1",
":",
"-",
"1",
";",
"}",
";",
"cl",
".",
"sort",
"(",
"cmp",
")",
";",
"if",
"(",
"deep",
")",
"{",
"for",
"(",
"i",
"=",
"0",
",",
"l",
"=",
"cl",
".",
"length",
";",
"i",
"<",
"l",
";",
"i",
"++",
")",
"{",
"if",
"(",
"cl",
"[",
"i",
"]",
".",
"children",
")",
"{",
"cl",
"[",
"i",
"]",
".",
"sortChildren",
"(",
"cmp",
",",
"\"$norender$\"",
")",
";",
"}",
"}",
"}",
"if",
"(",
"deep",
"!==",
"\"$norender$\"",
")",
"{",
"this",
".",
"render",
"(",
")",
";",
"}",
"this",
".",
"triggerModifyChild",
"(",
"\"sort\"",
")",
";",
"}"
] |
Sort child list by title.
@param {function} [cmp] custom compare function(a, b) that returns -1, 0, or 1 (defaults to sort by title).
@param {boolean} [deep=false] pass true to sort all descendant nodes
|
[
"Sort",
"child",
"list",
"by",
"title",
"."
] |
54307b76844177207e321c5b88eb03a23a6e23a2
|
https://github.com/mar10/fancytree/blob/54307b76844177207e321c5b88eb03a23a6e23a2/dist/jquery.fancytree-all-deps.js#L3609-L3636
|
|
10,702
|
mar10/fancytree
|
dist/jquery.fancytree-all-deps.js
|
function(value, flag) {
var className,
hasClass,
rnotwhite = /\S+/g,
classNames = value.match(rnotwhite) || [],
i = 0,
wasAdded = false,
statusElem = this[this.tree.statusClassPropName],
curClasses = " " + (this.extraClasses || "") + " ";
// this.info("toggleClass('" + value + "', " + flag + ")", curClasses);
// Modify DOM element directly if it already exists
if (statusElem) {
$(statusElem).toggleClass(value, flag);
}
// Modify node.extraClasses to make this change persistent
// Toggle if flag was not passed
while ((className = classNames[i++])) {
hasClass = curClasses.indexOf(" " + className + " ") >= 0;
flag = flag === undefined ? !hasClass : !!flag;
if (flag) {
if (!hasClass) {
curClasses += className + " ";
wasAdded = true;
}
} else {
while (curClasses.indexOf(" " + className + " ") > -1) {
curClasses = curClasses.replace(
" " + className + " ",
" "
);
}
}
}
this.extraClasses = $.trim(curClasses);
// this.info("-> toggleClass('" + value + "', " + flag + "): '" + this.extraClasses + "'");
return wasAdded;
}
|
javascript
|
function(value, flag) {
var className,
hasClass,
rnotwhite = /\S+/g,
classNames = value.match(rnotwhite) || [],
i = 0,
wasAdded = false,
statusElem = this[this.tree.statusClassPropName],
curClasses = " " + (this.extraClasses || "") + " ";
// this.info("toggleClass('" + value + "', " + flag + ")", curClasses);
// Modify DOM element directly if it already exists
if (statusElem) {
$(statusElem).toggleClass(value, flag);
}
// Modify node.extraClasses to make this change persistent
// Toggle if flag was not passed
while ((className = classNames[i++])) {
hasClass = curClasses.indexOf(" " + className + " ") >= 0;
flag = flag === undefined ? !hasClass : !!flag;
if (flag) {
if (!hasClass) {
curClasses += className + " ";
wasAdded = true;
}
} else {
while (curClasses.indexOf(" " + className + " ") > -1) {
curClasses = curClasses.replace(
" " + className + " ",
" "
);
}
}
}
this.extraClasses = $.trim(curClasses);
// this.info("-> toggleClass('" + value + "', " + flag + "): '" + this.extraClasses + "'");
return wasAdded;
}
|
[
"function",
"(",
"value",
",",
"flag",
")",
"{",
"var",
"className",
",",
"hasClass",
",",
"rnotwhite",
"=",
"/",
"\\S+",
"/",
"g",
",",
"classNames",
"=",
"value",
".",
"match",
"(",
"rnotwhite",
")",
"||",
"[",
"]",
",",
"i",
"=",
"0",
",",
"wasAdded",
"=",
"false",
",",
"statusElem",
"=",
"this",
"[",
"this",
".",
"tree",
".",
"statusClassPropName",
"]",
",",
"curClasses",
"=",
"\" \"",
"+",
"(",
"this",
".",
"extraClasses",
"||",
"\"\"",
")",
"+",
"\" \"",
";",
"// this.info(\"toggleClass('\" + value + \"', \" + flag + \")\", curClasses);",
"// Modify DOM element directly if it already exists",
"if",
"(",
"statusElem",
")",
"{",
"$",
"(",
"statusElem",
")",
".",
"toggleClass",
"(",
"value",
",",
"flag",
")",
";",
"}",
"// Modify node.extraClasses to make this change persistent",
"// Toggle if flag was not passed",
"while",
"(",
"(",
"className",
"=",
"classNames",
"[",
"i",
"++",
"]",
")",
")",
"{",
"hasClass",
"=",
"curClasses",
".",
"indexOf",
"(",
"\" \"",
"+",
"className",
"+",
"\" \"",
")",
">=",
"0",
";",
"flag",
"=",
"flag",
"===",
"undefined",
"?",
"!",
"hasClass",
":",
"!",
"!",
"flag",
";",
"if",
"(",
"flag",
")",
"{",
"if",
"(",
"!",
"hasClass",
")",
"{",
"curClasses",
"+=",
"className",
"+",
"\" \"",
";",
"wasAdded",
"=",
"true",
";",
"}",
"}",
"else",
"{",
"while",
"(",
"curClasses",
".",
"indexOf",
"(",
"\" \"",
"+",
"className",
"+",
"\" \"",
")",
">",
"-",
"1",
")",
"{",
"curClasses",
"=",
"curClasses",
".",
"replace",
"(",
"\" \"",
"+",
"className",
"+",
"\" \"",
",",
"\" \"",
")",
";",
"}",
"}",
"}",
"this",
".",
"extraClasses",
"=",
"$",
".",
"trim",
"(",
"curClasses",
")",
";",
"// this.info(\"-> toggleClass('\" + value + \"', \" + flag + \"): '\" + this.extraClasses + \"'\");",
"return",
"wasAdded",
";",
"}"
] |
Set, clear, or toggle class of node's span tag and .extraClasses.
@param {string} className class name (separate multiple classes by space)
@param {boolean} [flag] true/false to add/remove class. If omitted, class is toggled.
@returns {boolean} true if a class was added
@since 2.17
|
[
"Set",
"clear",
"or",
"toggle",
"class",
"of",
"node",
"s",
"span",
"tag",
"and",
".",
"extraClasses",
"."
] |
54307b76844177207e321c5b88eb03a23a6e23a2
|
https://github.com/mar10/fancytree/blob/54307b76844177207e321c5b88eb03a23a6e23a2/dist/jquery.fancytree-all-deps.js#L3690-L3727
|
|
10,703
|
mar10/fancytree
|
dist/jquery.fancytree-all-deps.js
|
function(operation, childNode, extra) {
var data,
modifyChild = this.tree.options.modifyChild;
if (modifyChild) {
if (childNode && childNode.parent !== this) {
$.error(
"childNode " + childNode + " is not a child of " + this
);
}
data = {
node: this,
tree: this.tree,
operation: operation,
childNode: childNode || null,
};
if (extra) {
$.extend(data, extra);
}
modifyChild({ type: "modifyChild" }, data);
}
}
|
javascript
|
function(operation, childNode, extra) {
var data,
modifyChild = this.tree.options.modifyChild;
if (modifyChild) {
if (childNode && childNode.parent !== this) {
$.error(
"childNode " + childNode + " is not a child of " + this
);
}
data = {
node: this,
tree: this.tree,
operation: operation,
childNode: childNode || null,
};
if (extra) {
$.extend(data, extra);
}
modifyChild({ type: "modifyChild" }, data);
}
}
|
[
"function",
"(",
"operation",
",",
"childNode",
",",
"extra",
")",
"{",
"var",
"data",
",",
"modifyChild",
"=",
"this",
".",
"tree",
".",
"options",
".",
"modifyChild",
";",
"if",
"(",
"modifyChild",
")",
"{",
"if",
"(",
"childNode",
"&&",
"childNode",
".",
"parent",
"!==",
"this",
")",
"{",
"$",
".",
"error",
"(",
"\"childNode \"",
"+",
"childNode",
"+",
"\" is not a child of \"",
"+",
"this",
")",
";",
"}",
"data",
"=",
"{",
"node",
":",
"this",
",",
"tree",
":",
"this",
".",
"tree",
",",
"operation",
":",
"operation",
",",
"childNode",
":",
"childNode",
"||",
"null",
",",
"}",
";",
"if",
"(",
"extra",
")",
"{",
"$",
".",
"extend",
"(",
"data",
",",
"extra",
")",
";",
"}",
"modifyChild",
"(",
"{",
"type",
":",
"\"modifyChild\"",
"}",
",",
"data",
")",
";",
"}",
"}"
] |
Trigger `modifyChild` event on a parent to signal that a child was modified.
@param {string} operation Type of change: 'add', 'remove', 'rename', 'move', 'data', ...
@param {FancytreeNode} [childNode]
@param {object} [extra]
|
[
"Trigger",
"modifyChild",
"event",
"on",
"a",
"parent",
"to",
"signal",
"that",
"a",
"child",
"was",
"modified",
"."
] |
54307b76844177207e321c5b88eb03a23a6e23a2
|
https://github.com/mar10/fancytree/blob/54307b76844177207e321c5b88eb03a23a6e23a2/dist/jquery.fancytree-all-deps.js#L3746-L3767
|
|
10,704
|
mar10/fancytree
|
dist/jquery.fancytree-all-deps.js
|
function(flag) {
flag = flag !== false; // Confusing use of '!'
/*jshint -W018 */ if (!!this._enableUpdate === !!flag) {
return flag;
}
/*jshint +W018 */
this._enableUpdate = flag;
if (flag) {
this.debug("enableUpdate(true): redraw "); //, this._dirtyRoots);
this.render();
} else {
// this._dirtyRoots = null;
this.debug("enableUpdate(false)...");
}
return !flag; // return previous value
}
|
javascript
|
function(flag) {
flag = flag !== false; // Confusing use of '!'
/*jshint -W018 */ if (!!this._enableUpdate === !!flag) {
return flag;
}
/*jshint +W018 */
this._enableUpdate = flag;
if (flag) {
this.debug("enableUpdate(true): redraw "); //, this._dirtyRoots);
this.render();
} else {
// this._dirtyRoots = null;
this.debug("enableUpdate(false)...");
}
return !flag; // return previous value
}
|
[
"function",
"(",
"flag",
")",
"{",
"flag",
"=",
"flag",
"!==",
"false",
";",
"// Confusing use of '!'",
"/*jshint -W018 */",
"if",
"(",
"!",
"!",
"this",
".",
"_enableUpdate",
"===",
"!",
"!",
"flag",
")",
"{",
"return",
"flag",
";",
"}",
"/*jshint +W018 */",
"this",
".",
"_enableUpdate",
"=",
"flag",
";",
"if",
"(",
"flag",
")",
"{",
"this",
".",
"debug",
"(",
"\"enableUpdate(true): redraw \"",
")",
";",
"//, this._dirtyRoots);",
"this",
".",
"render",
"(",
")",
";",
"}",
"else",
"{",
"// \tthis._dirtyRoots = null;",
"this",
".",
"debug",
"(",
"\"enableUpdate(false)...\"",
")",
";",
"}",
"return",
"!",
"flag",
";",
"// return previous value",
"}"
] |
Temporarily suppress rendering to improve performance on bulk-updates.
@param {boolean} flag
@returns {boolean} previous status
@since 2.19
|
[
"Temporarily",
"suppress",
"rendering",
"to",
"improve",
"performance",
"on",
"bulk",
"-",
"updates",
"."
] |
54307b76844177207e321c5b88eb03a23a6e23a2
|
https://github.com/mar10/fancytree/blob/54307b76844177207e321c5b88eb03a23a6e23a2/dist/jquery.fancytree-all-deps.js#L4285-L4300
|
|
10,705
|
mar10/fancytree
|
dist/jquery.fancytree-all-deps.js
|
function(match, startNode, visibleOnly) {
match =
typeof match === "string"
? _makeNodeTitleStartMatcher(match)
: match;
startNode = startNode || this.getFirstChild();
var stopNode = null,
parentChildren = startNode.parent.children,
matchingNode = null,
walkVisible = function(parent, idx, fn) {
var i,
grandParent,
parentChildren = parent.children,
siblingCount = parentChildren.length,
node = parentChildren[idx];
// visit node itself
if (node && fn(node) === false) {
return false;
}
// visit descendants
if (node && node.children && node.expanded) {
if (walkVisible(node, 0, fn) === false) {
return false;
}
}
// visit subsequent siblings
for (i = idx + 1; i < siblingCount; i++) {
if (walkVisible(parent, i, fn) === false) {
return false;
}
}
// visit parent's subsequent siblings
grandParent = parent.parent;
if (grandParent) {
return walkVisible(
grandParent,
grandParent.children.indexOf(parent) + 1,
fn
);
} else {
// wrap-around: restart with first node
return walkVisible(parent, 0, fn);
}
};
walkVisible(
startNode.parent,
parentChildren.indexOf(startNode),
function(node) {
// Stop iteration if we see the start node a second time
if (node === stopNode) {
return false;
}
stopNode = stopNode || node;
// Ignore nodes hidden by a filter
if (!$(node.span).is(":visible")) {
node.debug("quicksearch: skipping hidden node");
return;
}
// Test if we found a match, but search for a second match if this
// was the currently active node
if (match(node)) {
// node.debug("quicksearch match " + node.title, startNode);
matchingNode = node;
if (matchingNode !== startNode) {
return false;
}
}
}
);
return matchingNode;
}
|
javascript
|
function(match, startNode, visibleOnly) {
match =
typeof match === "string"
? _makeNodeTitleStartMatcher(match)
: match;
startNode = startNode || this.getFirstChild();
var stopNode = null,
parentChildren = startNode.parent.children,
matchingNode = null,
walkVisible = function(parent, idx, fn) {
var i,
grandParent,
parentChildren = parent.children,
siblingCount = parentChildren.length,
node = parentChildren[idx];
// visit node itself
if (node && fn(node) === false) {
return false;
}
// visit descendants
if (node && node.children && node.expanded) {
if (walkVisible(node, 0, fn) === false) {
return false;
}
}
// visit subsequent siblings
for (i = idx + 1; i < siblingCount; i++) {
if (walkVisible(parent, i, fn) === false) {
return false;
}
}
// visit parent's subsequent siblings
grandParent = parent.parent;
if (grandParent) {
return walkVisible(
grandParent,
grandParent.children.indexOf(parent) + 1,
fn
);
} else {
// wrap-around: restart with first node
return walkVisible(parent, 0, fn);
}
};
walkVisible(
startNode.parent,
parentChildren.indexOf(startNode),
function(node) {
// Stop iteration if we see the start node a second time
if (node === stopNode) {
return false;
}
stopNode = stopNode || node;
// Ignore nodes hidden by a filter
if (!$(node.span).is(":visible")) {
node.debug("quicksearch: skipping hidden node");
return;
}
// Test if we found a match, but search for a second match if this
// was the currently active node
if (match(node)) {
// node.debug("quicksearch match " + node.title, startNode);
matchingNode = node;
if (matchingNode !== startNode) {
return false;
}
}
}
);
return matchingNode;
}
|
[
"function",
"(",
"match",
",",
"startNode",
",",
"visibleOnly",
")",
"{",
"match",
"=",
"typeof",
"match",
"===",
"\"string\"",
"?",
"_makeNodeTitleStartMatcher",
"(",
"match",
")",
":",
"match",
";",
"startNode",
"=",
"startNode",
"||",
"this",
".",
"getFirstChild",
"(",
")",
";",
"var",
"stopNode",
"=",
"null",
",",
"parentChildren",
"=",
"startNode",
".",
"parent",
".",
"children",
",",
"matchingNode",
"=",
"null",
",",
"walkVisible",
"=",
"function",
"(",
"parent",
",",
"idx",
",",
"fn",
")",
"{",
"var",
"i",
",",
"grandParent",
",",
"parentChildren",
"=",
"parent",
".",
"children",
",",
"siblingCount",
"=",
"parentChildren",
".",
"length",
",",
"node",
"=",
"parentChildren",
"[",
"idx",
"]",
";",
"// visit node itself",
"if",
"(",
"node",
"&&",
"fn",
"(",
"node",
")",
"===",
"false",
")",
"{",
"return",
"false",
";",
"}",
"// visit descendants",
"if",
"(",
"node",
"&&",
"node",
".",
"children",
"&&",
"node",
".",
"expanded",
")",
"{",
"if",
"(",
"walkVisible",
"(",
"node",
",",
"0",
",",
"fn",
")",
"===",
"false",
")",
"{",
"return",
"false",
";",
"}",
"}",
"// visit subsequent siblings",
"for",
"(",
"i",
"=",
"idx",
"+",
"1",
";",
"i",
"<",
"siblingCount",
";",
"i",
"++",
")",
"{",
"if",
"(",
"walkVisible",
"(",
"parent",
",",
"i",
",",
"fn",
")",
"===",
"false",
")",
"{",
"return",
"false",
";",
"}",
"}",
"// visit parent's subsequent siblings",
"grandParent",
"=",
"parent",
".",
"parent",
";",
"if",
"(",
"grandParent",
")",
"{",
"return",
"walkVisible",
"(",
"grandParent",
",",
"grandParent",
".",
"children",
".",
"indexOf",
"(",
"parent",
")",
"+",
"1",
",",
"fn",
")",
";",
"}",
"else",
"{",
"// wrap-around: restart with first node",
"return",
"walkVisible",
"(",
"parent",
",",
"0",
",",
"fn",
")",
";",
"}",
"}",
";",
"walkVisible",
"(",
"startNode",
".",
"parent",
",",
"parentChildren",
".",
"indexOf",
"(",
"startNode",
")",
",",
"function",
"(",
"node",
")",
"{",
"// Stop iteration if we see the start node a second time",
"if",
"(",
"node",
"===",
"stopNode",
")",
"{",
"return",
"false",
";",
"}",
"stopNode",
"=",
"stopNode",
"||",
"node",
";",
"// Ignore nodes hidden by a filter",
"if",
"(",
"!",
"$",
"(",
"node",
".",
"span",
")",
".",
"is",
"(",
"\":visible\"",
")",
")",
"{",
"node",
".",
"debug",
"(",
"\"quicksearch: skipping hidden node\"",
")",
";",
"return",
";",
"}",
"// Test if we found a match, but search for a second match if this",
"// was the currently active node",
"if",
"(",
"match",
"(",
"node",
")",
")",
"{",
"// node.debug(\"quicksearch match \" + node.title, startNode);",
"matchingNode",
"=",
"node",
";",
"if",
"(",
"matchingNode",
"!==",
"startNode",
")",
"{",
"return",
"false",
";",
"}",
"}",
"}",
")",
";",
"return",
"matchingNode",
";",
"}"
] |
Find the next visible node that starts with `match`, starting at `startNode`
and wrap-around at the end.
@param {string|function} match
@param {FancytreeNode} [startNode] defaults to first node
@returns {FancytreeNode} matching node or null
|
[
"Find",
"the",
"next",
"visible",
"node",
"that",
"starts",
"with",
"match",
"starting",
"at",
"startNode",
"and",
"wrap",
"-",
"around",
"at",
"the",
"end",
"."
] |
54307b76844177207e321c5b88eb03a23a6e23a2
|
https://github.com/mar10/fancytree/blob/54307b76844177207e321c5b88eb03a23a6e23a2/dist/jquery.fancytree-all-deps.js#L4350-L4422
|
|
10,706
|
mar10/fancytree
|
dist/jquery.fancytree-all-deps.js
|
function(key, searchRoot) {
// Search the DOM by element ID (assuming this is faster than traversing all nodes).
var el, match;
// TODO: use tree.keyMap if available
// TODO: check opts.generateIds === true
if (!searchRoot) {
el = document.getElementById(this.options.idPrefix + key);
if (el) {
return el.ftnode ? el.ftnode : null;
}
}
// Not found in the DOM, but still may be in an unrendered part of tree
searchRoot = searchRoot || this.rootNode;
match = null;
searchRoot.visit(function(node) {
if (node.key === key) {
match = node;
return false; // Stop iteration
}
}, true);
return match;
}
|
javascript
|
function(key, searchRoot) {
// Search the DOM by element ID (assuming this is faster than traversing all nodes).
var el, match;
// TODO: use tree.keyMap if available
// TODO: check opts.generateIds === true
if (!searchRoot) {
el = document.getElementById(this.options.idPrefix + key);
if (el) {
return el.ftnode ? el.ftnode : null;
}
}
// Not found in the DOM, but still may be in an unrendered part of tree
searchRoot = searchRoot || this.rootNode;
match = null;
searchRoot.visit(function(node) {
if (node.key === key) {
match = node;
return false; // Stop iteration
}
}, true);
return match;
}
|
[
"function",
"(",
"key",
",",
"searchRoot",
")",
"{",
"// Search the DOM by element ID (assuming this is faster than traversing all nodes).",
"var",
"el",
",",
"match",
";",
"// TODO: use tree.keyMap if available",
"// TODO: check opts.generateIds === true",
"if",
"(",
"!",
"searchRoot",
")",
"{",
"el",
"=",
"document",
".",
"getElementById",
"(",
"this",
".",
"options",
".",
"idPrefix",
"+",
"key",
")",
";",
"if",
"(",
"el",
")",
"{",
"return",
"el",
".",
"ftnode",
"?",
"el",
".",
"ftnode",
":",
"null",
";",
"}",
"}",
"// Not found in the DOM, but still may be in an unrendered part of tree",
"searchRoot",
"=",
"searchRoot",
"||",
"this",
".",
"rootNode",
";",
"match",
"=",
"null",
";",
"searchRoot",
".",
"visit",
"(",
"function",
"(",
"node",
")",
"{",
"if",
"(",
"node",
".",
"key",
"===",
"key",
")",
"{",
"match",
"=",
"node",
";",
"return",
"false",
";",
"// Stop iteration",
"}",
"}",
",",
"true",
")",
";",
"return",
"match",
";",
"}"
] |
Return node with a given key or null if not found.
@param {string} key
@param {FancytreeNode} [searchRoot] only search below this node
@returns {FancytreeNode | null}
|
[
"Return",
"node",
"with",
"a",
"given",
"key",
"or",
"null",
"if",
"not",
"found",
"."
] |
54307b76844177207e321c5b88eb03a23a6e23a2
|
https://github.com/mar10/fancytree/blob/54307b76844177207e321c5b88eb03a23a6e23a2/dist/jquery.fancytree-all-deps.js#L4545-L4566
|
|
10,707
|
mar10/fancytree
|
dist/jquery.fancytree-all-deps.js
|
function(ctx, callOpts) {
// TODO: return promise?
var ac,
i,
l,
node = ctx.node;
if (node.parent) {
ac = node.parent.children;
for (i = 0, l = ac.length; i < l; i++) {
if (ac[i] !== node && ac[i].expanded) {
this._callHook(
"nodeSetExpanded",
ac[i],
false,
callOpts
);
}
}
}
}
|
javascript
|
function(ctx, callOpts) {
// TODO: return promise?
var ac,
i,
l,
node = ctx.node;
if (node.parent) {
ac = node.parent.children;
for (i = 0, l = ac.length; i < l; i++) {
if (ac[i] !== node && ac[i].expanded) {
this._callHook(
"nodeSetExpanded",
ac[i],
false,
callOpts
);
}
}
}
}
|
[
"function",
"(",
"ctx",
",",
"callOpts",
")",
"{",
"// TODO: return promise?",
"var",
"ac",
",",
"i",
",",
"l",
",",
"node",
"=",
"ctx",
".",
"node",
";",
"if",
"(",
"node",
".",
"parent",
")",
"{",
"ac",
"=",
"node",
".",
"parent",
".",
"children",
";",
"for",
"(",
"i",
"=",
"0",
",",
"l",
"=",
"ac",
".",
"length",
";",
"i",
"<",
"l",
";",
"i",
"++",
")",
"{",
"if",
"(",
"ac",
"[",
"i",
"]",
"!==",
"node",
"&&",
"ac",
"[",
"i",
"]",
".",
"expanded",
")",
"{",
"this",
".",
"_callHook",
"(",
"\"nodeSetExpanded\"",
",",
"ac",
"[",
"i",
"]",
",",
"false",
",",
"callOpts",
")",
";",
"}",
"}",
"}",
"}"
] |
Collapse all other children of same parent.
@param {EventData} ctx
@param {object} callOpts
|
[
"Collapse",
"all",
"other",
"children",
"of",
"same",
"parent",
"."
] |
54307b76844177207e321c5b88eb03a23a6e23a2
|
https://github.com/mar10/fancytree/blob/54307b76844177207e321c5b88eb03a23a6e23a2/dist/jquery.fancytree-all-deps.js#L5148-L5168
|
|
10,708
|
mar10/fancytree
|
dist/jquery.fancytree-all-deps.js
|
function(ctx) {
var node = ctx.node;
// FT.debug("nodeRemoveMarkup()", node.toString());
// TODO: Unlink attr.ftnode to support GC
if (node.li) {
$(node.li).remove();
node.li = null;
}
this.nodeRemoveChildMarkup(ctx);
}
|
javascript
|
function(ctx) {
var node = ctx.node;
// FT.debug("nodeRemoveMarkup()", node.toString());
// TODO: Unlink attr.ftnode to support GC
if (node.li) {
$(node.li).remove();
node.li = null;
}
this.nodeRemoveChildMarkup(ctx);
}
|
[
"function",
"(",
"ctx",
")",
"{",
"var",
"node",
"=",
"ctx",
".",
"node",
";",
"// FT.debug(\"nodeRemoveMarkup()\", node.toString());",
"// TODO: Unlink attr.ftnode to support GC",
"if",
"(",
"node",
".",
"li",
")",
"{",
"$",
"(",
"node",
".",
"li",
")",
".",
"remove",
"(",
")",
";",
"node",
".",
"li",
"=",
"null",
";",
"}",
"this",
".",
"nodeRemoveChildMarkup",
"(",
"ctx",
")",
";",
"}"
] |
Remove HTML markup for ctx.node and all its descendents.
@param {EventData} ctx
|
[
"Remove",
"HTML",
"markup",
"for",
"ctx",
".",
"node",
"and",
"all",
"its",
"descendents",
"."
] |
54307b76844177207e321c5b88eb03a23a6e23a2
|
https://github.com/mar10/fancytree/blob/54307b76844177207e321c5b88eb03a23a6e23a2/dist/jquery.fancytree-all-deps.js#L5741-L5750
|
|
10,709
|
mar10/fancytree
|
dist/jquery.fancytree-all-deps.js
|
function(ctx, flag) {
// ctx.node.debug("nodeSetFocus(" + flag + ")");
var ctx2,
tree = ctx.tree,
node = ctx.node,
opts = tree.options,
// et = ctx.originalEvent && ctx.originalEvent.type,
isInput = ctx.originalEvent
? $(ctx.originalEvent.target).is(":input")
: false;
flag = flag !== false;
// (node || tree).debug("nodeSetFocus(" + flag + "), event: " + et + ", isInput: "+ isInput);
// Blur previous node if any
if (tree.focusNode) {
if (tree.focusNode === node && flag) {
// node.debug("nodeSetFocus(" + flag + "): nothing to do");
return;
}
ctx2 = $.extend({}, ctx, { node: tree.focusNode });
tree.focusNode = null;
this._triggerNodeEvent("blur", ctx2);
this._callHook("nodeRenderStatus", ctx2);
}
// Set focus to container and node
if (flag) {
if (!this.hasFocus()) {
node.debug("nodeSetFocus: forcing container focus");
this._callHook("treeSetFocus", ctx, true, {
calledByNode: true,
});
}
node.makeVisible({ scrollIntoView: false });
tree.focusNode = node;
if (opts.titlesTabbable) {
if (!isInput) {
// #621
$(node.span)
.find(".fancytree-title")
.focus();
}
} else {
// We cannot set KB focus to a node, so use the tree container
// #563, #570: IE scrolls on every call to .focus(), if the container
// is partially outside the viewport. So do it only, when absolutely
// neccessary:
if (
$(document.activeElement).closest(
".fancytree-container"
).length === 0
) {
$(tree.$container).focus();
}
}
if (opts.aria) {
// Set active descendant to node's span ID (create one, if needed)
$(tree.$container).attr(
"aria-activedescendant",
$(node.tr || node.li)
.uniqueId()
.attr("id")
);
// "ftal_" + opts.idPrefix + node.key);
}
// $(node.span).find(".fancytree-title").focus();
this._triggerNodeEvent("focus", ctx);
// if( opts.autoActivate ){
// tree.nodeSetActive(ctx, true);
// }
if (opts.autoScroll) {
node.scrollIntoView();
}
this._callHook("nodeRenderStatus", ctx);
}
}
|
javascript
|
function(ctx, flag) {
// ctx.node.debug("nodeSetFocus(" + flag + ")");
var ctx2,
tree = ctx.tree,
node = ctx.node,
opts = tree.options,
// et = ctx.originalEvent && ctx.originalEvent.type,
isInput = ctx.originalEvent
? $(ctx.originalEvent.target).is(":input")
: false;
flag = flag !== false;
// (node || tree).debug("nodeSetFocus(" + flag + "), event: " + et + ", isInput: "+ isInput);
// Blur previous node if any
if (tree.focusNode) {
if (tree.focusNode === node && flag) {
// node.debug("nodeSetFocus(" + flag + "): nothing to do");
return;
}
ctx2 = $.extend({}, ctx, { node: tree.focusNode });
tree.focusNode = null;
this._triggerNodeEvent("blur", ctx2);
this._callHook("nodeRenderStatus", ctx2);
}
// Set focus to container and node
if (flag) {
if (!this.hasFocus()) {
node.debug("nodeSetFocus: forcing container focus");
this._callHook("treeSetFocus", ctx, true, {
calledByNode: true,
});
}
node.makeVisible({ scrollIntoView: false });
tree.focusNode = node;
if (opts.titlesTabbable) {
if (!isInput) {
// #621
$(node.span)
.find(".fancytree-title")
.focus();
}
} else {
// We cannot set KB focus to a node, so use the tree container
// #563, #570: IE scrolls on every call to .focus(), if the container
// is partially outside the viewport. So do it only, when absolutely
// neccessary:
if (
$(document.activeElement).closest(
".fancytree-container"
).length === 0
) {
$(tree.$container).focus();
}
}
if (opts.aria) {
// Set active descendant to node's span ID (create one, if needed)
$(tree.$container).attr(
"aria-activedescendant",
$(node.tr || node.li)
.uniqueId()
.attr("id")
);
// "ftal_" + opts.idPrefix + node.key);
}
// $(node.span).find(".fancytree-title").focus();
this._triggerNodeEvent("focus", ctx);
// if( opts.autoActivate ){
// tree.nodeSetActive(ctx, true);
// }
if (opts.autoScroll) {
node.scrollIntoView();
}
this._callHook("nodeRenderStatus", ctx);
}
}
|
[
"function",
"(",
"ctx",
",",
"flag",
")",
"{",
"// ctx.node.debug(\"nodeSetFocus(\" + flag + \")\");",
"var",
"ctx2",
",",
"tree",
"=",
"ctx",
".",
"tree",
",",
"node",
"=",
"ctx",
".",
"node",
",",
"opts",
"=",
"tree",
".",
"options",
",",
"// et = ctx.originalEvent && ctx.originalEvent.type,",
"isInput",
"=",
"ctx",
".",
"originalEvent",
"?",
"$",
"(",
"ctx",
".",
"originalEvent",
".",
"target",
")",
".",
"is",
"(",
"\":input\"",
")",
":",
"false",
";",
"flag",
"=",
"flag",
"!==",
"false",
";",
"// (node || tree).debug(\"nodeSetFocus(\" + flag + \"), event: \" + et + \", isInput: \"+ isInput);",
"// Blur previous node if any",
"if",
"(",
"tree",
".",
"focusNode",
")",
"{",
"if",
"(",
"tree",
".",
"focusNode",
"===",
"node",
"&&",
"flag",
")",
"{",
"// node.debug(\"nodeSetFocus(\" + flag + \"): nothing to do\");",
"return",
";",
"}",
"ctx2",
"=",
"$",
".",
"extend",
"(",
"{",
"}",
",",
"ctx",
",",
"{",
"node",
":",
"tree",
".",
"focusNode",
"}",
")",
";",
"tree",
".",
"focusNode",
"=",
"null",
";",
"this",
".",
"_triggerNodeEvent",
"(",
"\"blur\"",
",",
"ctx2",
")",
";",
"this",
".",
"_callHook",
"(",
"\"nodeRenderStatus\"",
",",
"ctx2",
")",
";",
"}",
"// Set focus to container and node",
"if",
"(",
"flag",
")",
"{",
"if",
"(",
"!",
"this",
".",
"hasFocus",
"(",
")",
")",
"{",
"node",
".",
"debug",
"(",
"\"nodeSetFocus: forcing container focus\"",
")",
";",
"this",
".",
"_callHook",
"(",
"\"treeSetFocus\"",
",",
"ctx",
",",
"true",
",",
"{",
"calledByNode",
":",
"true",
",",
"}",
")",
";",
"}",
"node",
".",
"makeVisible",
"(",
"{",
"scrollIntoView",
":",
"false",
"}",
")",
";",
"tree",
".",
"focusNode",
"=",
"node",
";",
"if",
"(",
"opts",
".",
"titlesTabbable",
")",
"{",
"if",
"(",
"!",
"isInput",
")",
"{",
"// #621",
"$",
"(",
"node",
".",
"span",
")",
".",
"find",
"(",
"\".fancytree-title\"",
")",
".",
"focus",
"(",
")",
";",
"}",
"}",
"else",
"{",
"// We cannot set KB focus to a node, so use the tree container",
"// #563, #570: IE scrolls on every call to .focus(), if the container",
"// is partially outside the viewport. So do it only, when absolutely",
"// neccessary:",
"if",
"(",
"$",
"(",
"document",
".",
"activeElement",
")",
".",
"closest",
"(",
"\".fancytree-container\"",
")",
".",
"length",
"===",
"0",
")",
"{",
"$",
"(",
"tree",
".",
"$container",
")",
".",
"focus",
"(",
")",
";",
"}",
"}",
"if",
"(",
"opts",
".",
"aria",
")",
"{",
"// Set active descendant to node's span ID (create one, if needed)",
"$",
"(",
"tree",
".",
"$container",
")",
".",
"attr",
"(",
"\"aria-activedescendant\"",
",",
"$",
"(",
"node",
".",
"tr",
"||",
"node",
".",
"li",
")",
".",
"uniqueId",
"(",
")",
".",
"attr",
"(",
"\"id\"",
")",
")",
";",
"// \"ftal_\" + opts.idPrefix + node.key);",
"}",
"// $(node.span).find(\".fancytree-title\").focus();",
"this",
".",
"_triggerNodeEvent",
"(",
"\"focus\"",
",",
"ctx",
")",
";",
"// if( opts.autoActivate ){",
"// \ttree.nodeSetActive(ctx, true);",
"// }",
"if",
"(",
"opts",
".",
"autoScroll",
")",
"{",
"node",
".",
"scrollIntoView",
"(",
")",
";",
"}",
"this",
".",
"_callHook",
"(",
"\"nodeRenderStatus\"",
",",
"ctx",
")",
";",
"}",
"}"
] |
Focus or blur this node.
@param {EventData} ctx
@param {boolean} [flag=true]
|
[
"Focus",
"or",
"blur",
"this",
"node",
"."
] |
54307b76844177207e321c5b88eb03a23a6e23a2
|
https://github.com/mar10/fancytree/blob/54307b76844177207e321c5b88eb03a23a6e23a2/dist/jquery.fancytree-all-deps.js#L6618-L6693
|
|
10,710
|
mar10/fancytree
|
dist/jquery.fancytree-all-deps.js
|
function(ctx) {
var tree = ctx.tree;
tree.activeNode = null;
tree.focusNode = null;
tree.$div.find(">ul.fancytree-container").empty();
// TODO: call destructors and remove reference loops
tree.rootNode.children = null;
}
|
javascript
|
function(ctx) {
var tree = ctx.tree;
tree.activeNode = null;
tree.focusNode = null;
tree.$div.find(">ul.fancytree-container").empty();
// TODO: call destructors and remove reference loops
tree.rootNode.children = null;
}
|
[
"function",
"(",
"ctx",
")",
"{",
"var",
"tree",
"=",
"ctx",
".",
"tree",
";",
"tree",
".",
"activeNode",
"=",
"null",
";",
"tree",
".",
"focusNode",
"=",
"null",
";",
"tree",
".",
"$div",
".",
"find",
"(",
"\">ul.fancytree-container\"",
")",
".",
"empty",
"(",
")",
";",
"// TODO: call destructors and remove reference loops",
"tree",
".",
"rootNode",
".",
"children",
"=",
"null",
";",
"}"
] |
Remove all nodes.
@param {EventData} ctx
|
[
"Remove",
"all",
"nodes",
"."
] |
54307b76844177207e321c5b88eb03a23a6e23a2
|
https://github.com/mar10/fancytree/blob/54307b76844177207e321c5b88eb03a23a6e23a2/dist/jquery.fancytree-all-deps.js#L6914-L6921
|
|
10,711
|
mar10/fancytree
|
dist/jquery.fancytree-all-deps.js
|
function(el) {
var widget;
if (el instanceof Fancytree) {
return el; // el already was a Fancytree
}
if (el === undefined) {
el = 0; // get first tree
}
if (typeof el === "number") {
el = $(".fancytree-container").eq(el); // el was an integer: return nth instance
} else if (typeof el === "string") {
el = $(el).eq(0); // el was a selector: use first match
} else if (el instanceof $) {
el = el.eq(0); // el was a jQuery object: use the first DOM element
} else if (el.originalEvent !== undefined) {
el = $(el.target); // el was an Event
}
el = el.closest(":ui-fancytree");
widget = el.data("ui-fancytree") || el.data("fancytree"); // the latter is required by jQuery <= 1.8
return widget ? widget.tree : null;
}
|
javascript
|
function(el) {
var widget;
if (el instanceof Fancytree) {
return el; // el already was a Fancytree
}
if (el === undefined) {
el = 0; // get first tree
}
if (typeof el === "number") {
el = $(".fancytree-container").eq(el); // el was an integer: return nth instance
} else if (typeof el === "string") {
el = $(el).eq(0); // el was a selector: use first match
} else if (el instanceof $) {
el = el.eq(0); // el was a jQuery object: use the first DOM element
} else if (el.originalEvent !== undefined) {
el = $(el.target); // el was an Event
}
el = el.closest(":ui-fancytree");
widget = el.data("ui-fancytree") || el.data("fancytree"); // the latter is required by jQuery <= 1.8
return widget ? widget.tree : null;
}
|
[
"function",
"(",
"el",
")",
"{",
"var",
"widget",
";",
"if",
"(",
"el",
"instanceof",
"Fancytree",
")",
"{",
"return",
"el",
";",
"// el already was a Fancytree",
"}",
"if",
"(",
"el",
"===",
"undefined",
")",
"{",
"el",
"=",
"0",
";",
"// get first tree",
"}",
"if",
"(",
"typeof",
"el",
"===",
"\"number\"",
")",
"{",
"el",
"=",
"$",
"(",
"\".fancytree-container\"",
")",
".",
"eq",
"(",
"el",
")",
";",
"// el was an integer: return nth instance",
"}",
"else",
"if",
"(",
"typeof",
"el",
"===",
"\"string\"",
")",
"{",
"el",
"=",
"$",
"(",
"el",
")",
".",
"eq",
"(",
"0",
")",
";",
"// el was a selector: use first match",
"}",
"else",
"if",
"(",
"el",
"instanceof",
"$",
")",
"{",
"el",
"=",
"el",
".",
"eq",
"(",
"0",
")",
";",
"// el was a jQuery object: use the first DOM element",
"}",
"else",
"if",
"(",
"el",
".",
"originalEvent",
"!==",
"undefined",
")",
"{",
"el",
"=",
"$",
"(",
"el",
".",
"target",
")",
";",
"// el was an Event",
"}",
"el",
"=",
"el",
".",
"closest",
"(",
"\":ui-fancytree\"",
")",
";",
"widget",
"=",
"el",
".",
"data",
"(",
"\"ui-fancytree\"",
")",
"||",
"el",
".",
"data",
"(",
"\"fancytree\"",
")",
";",
"// the latter is required by jQuery <= 1.8",
"return",
"widget",
"?",
"widget",
".",
"tree",
":",
"null",
";",
"}"
] |
Return a Fancytree instance, from element, index, event, or jQueryObject.
@param {Element | jQueryObject | Event | integer | string} [el]
@returns {Fancytree} matching tree or null
@example
$.ui.fancytree.getTree(); // Get first Fancytree instance on page
$.ui.fancytree.getTree(1); // Get second Fancytree instance on page
$.ui.fancytree.getTree("#tree"); // Get tree for this matching element
@since 2.13
|
[
"Return",
"a",
"Fancytree",
"instance",
"from",
"element",
"index",
"event",
"or",
"jQueryObject",
"."
] |
54307b76844177207e321c5b88eb03a23a6e23a2
|
https://github.com/mar10/fancytree/blob/54307b76844177207e321c5b88eb03a23a6e23a2/dist/jquery.fancytree-all-deps.js#L7859-L7880
|
|
10,712
|
mar10/fancytree
|
dist/jquery.fancytree-all-deps.js
|
function(
optionName,
node,
nodeObject,
treeOptions,
defaultValue
) {
var ctx,
res,
tree = node.tree,
treeOpt = treeOptions[optionName],
nodeOpt = nodeObject[optionName];
if ($.isFunction(treeOpt)) {
ctx = {
node: node,
tree: tree,
widget: tree.widget,
options: tree.widget.options,
typeInfo: tree.types[node.type] || {},
};
res = treeOpt.call(tree, { type: optionName }, ctx);
if (res == null) {
res = nodeOpt;
}
} else {
res = nodeOpt != null ? nodeOpt : treeOpt;
}
if (res == null) {
res = defaultValue; // no option set at all: return default
}
return res;
}
|
javascript
|
function(
optionName,
node,
nodeObject,
treeOptions,
defaultValue
) {
var ctx,
res,
tree = node.tree,
treeOpt = treeOptions[optionName],
nodeOpt = nodeObject[optionName];
if ($.isFunction(treeOpt)) {
ctx = {
node: node,
tree: tree,
widget: tree.widget,
options: tree.widget.options,
typeInfo: tree.types[node.type] || {},
};
res = treeOpt.call(tree, { type: optionName }, ctx);
if (res == null) {
res = nodeOpt;
}
} else {
res = nodeOpt != null ? nodeOpt : treeOpt;
}
if (res == null) {
res = defaultValue; // no option set at all: return default
}
return res;
}
|
[
"function",
"(",
"optionName",
",",
"node",
",",
"nodeObject",
",",
"treeOptions",
",",
"defaultValue",
")",
"{",
"var",
"ctx",
",",
"res",
",",
"tree",
"=",
"node",
".",
"tree",
",",
"treeOpt",
"=",
"treeOptions",
"[",
"optionName",
"]",
",",
"nodeOpt",
"=",
"nodeObject",
"[",
"optionName",
"]",
";",
"if",
"(",
"$",
".",
"isFunction",
"(",
"treeOpt",
")",
")",
"{",
"ctx",
"=",
"{",
"node",
":",
"node",
",",
"tree",
":",
"tree",
",",
"widget",
":",
"tree",
".",
"widget",
",",
"options",
":",
"tree",
".",
"widget",
".",
"options",
",",
"typeInfo",
":",
"tree",
".",
"types",
"[",
"node",
".",
"type",
"]",
"||",
"{",
"}",
",",
"}",
";",
"res",
"=",
"treeOpt",
".",
"call",
"(",
"tree",
",",
"{",
"type",
":",
"optionName",
"}",
",",
"ctx",
")",
";",
"if",
"(",
"res",
"==",
"null",
")",
"{",
"res",
"=",
"nodeOpt",
";",
"}",
"}",
"else",
"{",
"res",
"=",
"nodeOpt",
"!=",
"null",
"?",
"nodeOpt",
":",
"treeOpt",
";",
"}",
"if",
"(",
"res",
"==",
"null",
")",
"{",
"res",
"=",
"defaultValue",
";",
"// no option set at all: return default",
"}",
"return",
"res",
";",
"}"
] |
Return an option value that has a default, but may be overridden by a
callback or a node instance attribute.
Evaluation sequence:<br>
If tree.options.<optionName> is a callback that returns something, use that.<br>
Else if node.<optionName> is defined, use that.<br>
Else if tree.options.<optionName> is a value, use that.<br>
Else use `defaultValue`.
@param {string} optionName name of the option property (on node and tree)
@param {FancytreeNode} node passed to the callback
@param {object} nodeObject where to look for the local option property, e.g. `node` or `node.data`
@param {object} treeOption where to look for the tree option, e.g. `tree.options` or `tree.options.dnd5`
@param {any} [defaultValue]
@returns {any}
@example
// Check for node.foo, tree,options.foo(), and tree.options.foo:
$.ui.fancytree.evalOption("foo", node, node, tree.options);
// Check for node.data.bar, tree,options.qux.bar(), and tree.options.qux.bar:
$.ui.fancytree.evalOption("bar", node, node.data, tree.options.qux);
@since 2.22
|
[
"Return",
"an",
"option",
"value",
"that",
"has",
"a",
"default",
"but",
"may",
"be",
"overridden",
"by",
"a",
"callback",
"or",
"a",
"node",
"instance",
"attribute",
"."
] |
54307b76844177207e321c5b88eb03a23a6e23a2
|
https://github.com/mar10/fancytree/blob/54307b76844177207e321c5b88eb03a23a6e23a2/dist/jquery.fancytree-all-deps.js#L7906-L7938
|
|
10,713
|
mar10/fancytree
|
dist/jquery.fancytree-all-deps.js
|
function(span, baseClass, icon) {
var $span = $(span);
if (typeof icon === "string") {
$span.attr("class", baseClass + " " + icon);
} else {
// support object syntax: { text: ligature, addClasse: classname }
if (icon.text) {
$span.text("" + icon.text);
} else if (icon.html) {
span.innerHTML = icon.html;
}
$span.attr(
"class",
baseClass + " " + (icon.addClass || "")
);
}
}
|
javascript
|
function(span, baseClass, icon) {
var $span = $(span);
if (typeof icon === "string") {
$span.attr("class", baseClass + " " + icon);
} else {
// support object syntax: { text: ligature, addClasse: classname }
if (icon.text) {
$span.text("" + icon.text);
} else if (icon.html) {
span.innerHTML = icon.html;
}
$span.attr(
"class",
baseClass + " " + (icon.addClass || "")
);
}
}
|
[
"function",
"(",
"span",
",",
"baseClass",
",",
"icon",
")",
"{",
"var",
"$span",
"=",
"$",
"(",
"span",
")",
";",
"if",
"(",
"typeof",
"icon",
"===",
"\"string\"",
")",
"{",
"$span",
".",
"attr",
"(",
"\"class\"",
",",
"baseClass",
"+",
"\" \"",
"+",
"icon",
")",
";",
"}",
"else",
"{",
"// support object syntax: { text: ligature, addClasse: classname }",
"if",
"(",
"icon",
".",
"text",
")",
"{",
"$span",
".",
"text",
"(",
"\"\"",
"+",
"icon",
".",
"text",
")",
";",
"}",
"else",
"if",
"(",
"icon",
".",
"html",
")",
"{",
"span",
".",
"innerHTML",
"=",
"icon",
".",
"html",
";",
"}",
"$span",
".",
"attr",
"(",
"\"class\"",
",",
"baseClass",
"+",
"\" \"",
"+",
"(",
"icon",
".",
"addClass",
"||",
"\"\"",
")",
")",
";",
"}",
"}"
] |
Set expander, checkbox, or node icon, supporting string and object format.
@param {Element | jQueryObject} span
@param {string} baseClass
@param {string | object} icon
@since 2.27
|
[
"Set",
"expander",
"checkbox",
"or",
"node",
"icon",
"supporting",
"string",
"and",
"object",
"format",
"."
] |
54307b76844177207e321c5b88eb03a23a6e23a2
|
https://github.com/mar10/fancytree/blob/54307b76844177207e321c5b88eb03a23a6e23a2/dist/jquery.fancytree-all-deps.js#L7946-L7963
|
|
10,714
|
mar10/fancytree
|
dist/jquery.fancytree-all-deps.js
|
function(event) {
// Poor-man's hotkeys. See here for a complete implementation:
// https://github.com/jeresig/jquery.hotkeys
var which = event.which,
et = event.type,
s = [];
if (event.altKey) {
s.push("alt");
}
if (event.ctrlKey) {
s.push("ctrl");
}
if (event.metaKey) {
s.push("meta");
}
if (event.shiftKey) {
s.push("shift");
}
if (et === "click" || et === "dblclick") {
s.push(MOUSE_BUTTONS[event.button] + et);
} else {
if (!IGNORE_KEYCODES[which]) {
s.push(
SPECIAL_KEYCODES[which] ||
String.fromCharCode(which).toLowerCase()
);
}
}
return s.join("+");
}
|
javascript
|
function(event) {
// Poor-man's hotkeys. See here for a complete implementation:
// https://github.com/jeresig/jquery.hotkeys
var which = event.which,
et = event.type,
s = [];
if (event.altKey) {
s.push("alt");
}
if (event.ctrlKey) {
s.push("ctrl");
}
if (event.metaKey) {
s.push("meta");
}
if (event.shiftKey) {
s.push("shift");
}
if (et === "click" || et === "dblclick") {
s.push(MOUSE_BUTTONS[event.button] + et);
} else {
if (!IGNORE_KEYCODES[which]) {
s.push(
SPECIAL_KEYCODES[which] ||
String.fromCharCode(which).toLowerCase()
);
}
}
return s.join("+");
}
|
[
"function",
"(",
"event",
")",
"{",
"// Poor-man's hotkeys. See here for a complete implementation:",
"// https://github.com/jeresig/jquery.hotkeys",
"var",
"which",
"=",
"event",
".",
"which",
",",
"et",
"=",
"event",
".",
"type",
",",
"s",
"=",
"[",
"]",
";",
"if",
"(",
"event",
".",
"altKey",
")",
"{",
"s",
".",
"push",
"(",
"\"alt\"",
")",
";",
"}",
"if",
"(",
"event",
".",
"ctrlKey",
")",
"{",
"s",
".",
"push",
"(",
"\"ctrl\"",
")",
";",
"}",
"if",
"(",
"event",
".",
"metaKey",
")",
"{",
"s",
".",
"push",
"(",
"\"meta\"",
")",
";",
"}",
"if",
"(",
"event",
".",
"shiftKey",
")",
"{",
"s",
".",
"push",
"(",
"\"shift\"",
")",
";",
"}",
"if",
"(",
"et",
"===",
"\"click\"",
"||",
"et",
"===",
"\"dblclick\"",
")",
"{",
"s",
".",
"push",
"(",
"MOUSE_BUTTONS",
"[",
"event",
".",
"button",
"]",
"+",
"et",
")",
";",
"}",
"else",
"{",
"if",
"(",
"!",
"IGNORE_KEYCODES",
"[",
"which",
"]",
")",
"{",
"s",
".",
"push",
"(",
"SPECIAL_KEYCODES",
"[",
"which",
"]",
"||",
"String",
".",
"fromCharCode",
"(",
"which",
")",
".",
"toLowerCase",
"(",
")",
")",
";",
"}",
"}",
"return",
"s",
".",
"join",
"(",
"\"+\"",
")",
";",
"}"
] |
Convert a keydown or mouse event to a canonical string like 'ctrl+a',
'ctrl+shift+f2', 'shift+leftdblclick'.
This is especially handy for switch-statements in event handlers.
@param {event}
@returns {string}
@example
switch( $.ui.fancytree.eventToString(event) ) {
case "-":
tree.nodeSetExpanded(ctx, false);
break;
case "shift+return":
tree.nodeSetActive(ctx, true);
break;
case "down":
res = node.navigate(event.which, activate);
break;
default:
handled = false;
}
if( handled ){
event.preventDefault();
}
|
[
"Convert",
"a",
"keydown",
"or",
"mouse",
"event",
"to",
"a",
"canonical",
"string",
"like",
"ctrl",
"+",
"a",
"ctrl",
"+",
"shift",
"+",
"f2",
"shift",
"+",
"leftdblclick",
"."
] |
54307b76844177207e321c5b88eb03a23a6e23a2
|
https://github.com/mar10/fancytree/blob/54307b76844177207e321c5b88eb03a23a6e23a2/dist/jquery.fancytree-all-deps.js#L7991-L8022
|
|
10,715
|
mar10/fancytree
|
dist/jquery.fancytree-all-deps.js
|
function(instance, methodName, handler, context) {
var prevSuper,
_super = instance[methodName] || $.noop;
instance[methodName] = function() {
var self = context || this;
try {
prevSuper = self._super;
self._super = _super;
return handler.apply(self, arguments);
} finally {
self._super = prevSuper;
}
};
}
|
javascript
|
function(instance, methodName, handler, context) {
var prevSuper,
_super = instance[methodName] || $.noop;
instance[methodName] = function() {
var self = context || this;
try {
prevSuper = self._super;
self._super = _super;
return handler.apply(self, arguments);
} finally {
self._super = prevSuper;
}
};
}
|
[
"function",
"(",
"instance",
",",
"methodName",
",",
"handler",
",",
"context",
")",
"{",
"var",
"prevSuper",
",",
"_super",
"=",
"instance",
"[",
"methodName",
"]",
"||",
"$",
".",
"noop",
";",
"instance",
"[",
"methodName",
"]",
"=",
"function",
"(",
")",
"{",
"var",
"self",
"=",
"context",
"||",
"this",
";",
"try",
"{",
"prevSuper",
"=",
"self",
".",
"_super",
";",
"self",
".",
"_super",
"=",
"_super",
";",
"return",
"handler",
".",
"apply",
"(",
"self",
",",
"arguments",
")",
";",
"}",
"finally",
"{",
"self",
".",
"_super",
"=",
"prevSuper",
";",
"}",
"}",
";",
"}"
] |
Return a wrapped handler method, that provides `this._super`.
@example
Implement `opts.createNode` event to add the 'draggable' attribute
$.ui.fancytree.overrideMethod(ctx.options, "createNode", function(event, data) {
Default processing if any
this._super.apply(this, arguments);
Add 'draggable' attribute
data.node.span.draggable = true;
});
@param {object} instance
@param {string} methodName
@param {function} handler
@param {object} [context] optional context
|
[
"Return",
"a",
"wrapped",
"handler",
"method",
"that",
"provides",
"this",
".",
"_super",
"."
] |
54307b76844177207e321c5b88eb03a23a6e23a2
|
https://github.com/mar10/fancytree/blob/54307b76844177207e321c5b88eb03a23a6e23a2/dist/jquery.fancytree-all-deps.js#L8055-L8070
|
|
10,716
|
mar10/fancytree
|
dist/jquery.fancytree-all-deps.js
|
function(definition) {
_assert(
definition.name != null,
"extensions must have a `name` property."
);
_assert(
definition.version != null,
"extensions must have a `version` property."
);
$.ui.fancytree._extensions[definition.name] = definition;
}
|
javascript
|
function(definition) {
_assert(
definition.name != null,
"extensions must have a `name` property."
);
_assert(
definition.version != null,
"extensions must have a `version` property."
);
$.ui.fancytree._extensions[definition.name] = definition;
}
|
[
"function",
"(",
"definition",
")",
"{",
"_assert",
"(",
"definition",
".",
"name",
"!=",
"null",
",",
"\"extensions must have a `name` property.\"",
")",
";",
"_assert",
"(",
"definition",
".",
"version",
"!=",
"null",
",",
"\"extensions must have a `version` property.\"",
")",
";",
"$",
".",
"ui",
".",
"fancytree",
".",
"_extensions",
"[",
"definition",
".",
"name",
"]",
"=",
"definition",
";",
"}"
] |
Add Fancytree extension definition to the list of globally available extensions.
@param {object} definition
|
[
"Add",
"Fancytree",
"extension",
"definition",
"to",
"the",
"list",
"of",
"globally",
"available",
"extensions",
"."
] |
54307b76844177207e321c5b88eb03a23a6e23a2
|
https://github.com/mar10/fancytree/blob/54307b76844177207e321c5b88eb03a23a6e23a2/dist/jquery.fancytree-all-deps.js#L8189-L8199
|
|
10,717
|
mar10/fancytree
|
lib/jquery.planize.js
|
function() {
var level = 0;
var levels = [0,0,0,0,0,0,0];
var hLevelText = '';
var prependText = '';
var prevLevel = 0;
var n = 0;
self.children('*:header:visible').each(function(index, heading) {
log('Processing heading %o', heading);
level = parseInt(heading.tagName.substring(1));
if (config.min_level <= level && level <= config.max_level) {
n++;
levels[level]++;
for (var l = 1; l <= level; l++) {
hLevelText += levels[l] > 0 ? levels[l] + config.number_separator : '';
}
levels[level + 1] = 0;
hLevelText = hLevelText.substring(0, hLevelText.length - 1);
prependText = hLevelText;
if (config.generate_toc || config.add_anchors) {
if (config.generate_toc) {
var link = '<a href="#h' + hLevelText + '">' +jQuery('<span/>').text(jQuery(this).text()).html() + '</a>';
var elem = "\n"+'<li>' + hLevelText + (config.number_suffix ? config.number_suffix : '') + ' ' + link;
if (level < prevLevel) {
log(hLevelText + ', unnesting because:' + level + '<' + prevLevel);
var unnest = '';
while (level < prevLevel) {
unnest += '</ul>';
prevLevel--;
}
toc += unnest + elem + '</li>';
} else if (level > prevLevel) {
log(hLevelText + ', nesting because:' + level + '>' + prevLevel);
toc += '<ul>' + elem;
} else {
log(hLevelText + ', same level (' + level + ')');
toc += elem;
}
}
prependText = '<span id="h' + hLevelText + '"></span>' + hLevelText;
}
if (config.number_suffix) {
prependText += config.number_suffix;
}
jQuery(this).prepend(prependText + ' ');
prependText = hLevelText = '';
prevLevel = level;
}
});
if (config.generate_toc) {
if (config.toc_title) {
toc = '<h4>' + config.toc_title + '</h4>' + toc;
}
if (n == 0) {
toc += config.toc_none ? '<p>' + config.toc_none + '</p>' : '';
}
jQuery(config.toc_elem ? config.toc_elem : 'body').append(toc);
}
processed = true;
}
|
javascript
|
function() {
var level = 0;
var levels = [0,0,0,0,0,0,0];
var hLevelText = '';
var prependText = '';
var prevLevel = 0;
var n = 0;
self.children('*:header:visible').each(function(index, heading) {
log('Processing heading %o', heading);
level = parseInt(heading.tagName.substring(1));
if (config.min_level <= level && level <= config.max_level) {
n++;
levels[level]++;
for (var l = 1; l <= level; l++) {
hLevelText += levels[l] > 0 ? levels[l] + config.number_separator : '';
}
levels[level + 1] = 0;
hLevelText = hLevelText.substring(0, hLevelText.length - 1);
prependText = hLevelText;
if (config.generate_toc || config.add_anchors) {
if (config.generate_toc) {
var link = '<a href="#h' + hLevelText + '">' +jQuery('<span/>').text(jQuery(this).text()).html() + '</a>';
var elem = "\n"+'<li>' + hLevelText + (config.number_suffix ? config.number_suffix : '') + ' ' + link;
if (level < prevLevel) {
log(hLevelText + ', unnesting because:' + level + '<' + prevLevel);
var unnest = '';
while (level < prevLevel) {
unnest += '</ul>';
prevLevel--;
}
toc += unnest + elem + '</li>';
} else if (level > prevLevel) {
log(hLevelText + ', nesting because:' + level + '>' + prevLevel);
toc += '<ul>' + elem;
} else {
log(hLevelText + ', same level (' + level + ')');
toc += elem;
}
}
prependText = '<span id="h' + hLevelText + '"></span>' + hLevelText;
}
if (config.number_suffix) {
prependText += config.number_suffix;
}
jQuery(this).prepend(prependText + ' ');
prependText = hLevelText = '';
prevLevel = level;
}
});
if (config.generate_toc) {
if (config.toc_title) {
toc = '<h4>' + config.toc_title + '</h4>' + toc;
}
if (n == 0) {
toc += config.toc_none ? '<p>' + config.toc_none + '</p>' : '';
}
jQuery(config.toc_elem ? config.toc_elem : 'body').append(toc);
}
processed = true;
}
|
[
"function",
"(",
")",
"{",
"var",
"level",
"=",
"0",
";",
"var",
"levels",
"=",
"[",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
"]",
";",
"var",
"hLevelText",
"=",
"''",
";",
"var",
"prependText",
"=",
"''",
";",
"var",
"prevLevel",
"=",
"0",
";",
"var",
"n",
"=",
"0",
";",
"self",
".",
"children",
"(",
"'*:header:visible'",
")",
".",
"each",
"(",
"function",
"(",
"index",
",",
"heading",
")",
"{",
"log",
"(",
"'Processing heading %o'",
",",
"heading",
")",
";",
"level",
"=",
"parseInt",
"(",
"heading",
".",
"tagName",
".",
"substring",
"(",
"1",
")",
")",
";",
"if",
"(",
"config",
".",
"min_level",
"<=",
"level",
"&&",
"level",
"<=",
"config",
".",
"max_level",
")",
"{",
"n",
"++",
";",
"levels",
"[",
"level",
"]",
"++",
";",
"for",
"(",
"var",
"l",
"=",
"1",
";",
"l",
"<=",
"level",
";",
"l",
"++",
")",
"{",
"hLevelText",
"+=",
"levels",
"[",
"l",
"]",
">",
"0",
"?",
"levels",
"[",
"l",
"]",
"+",
"config",
".",
"number_separator",
":",
"''",
";",
"}",
"levels",
"[",
"level",
"+",
"1",
"]",
"=",
"0",
";",
"hLevelText",
"=",
"hLevelText",
".",
"substring",
"(",
"0",
",",
"hLevelText",
".",
"length",
"-",
"1",
")",
";",
"prependText",
"=",
"hLevelText",
";",
"if",
"(",
"config",
".",
"generate_toc",
"||",
"config",
".",
"add_anchors",
")",
"{",
"if",
"(",
"config",
".",
"generate_toc",
")",
"{",
"var",
"link",
"=",
"'<a href=\"#h'",
"+",
"hLevelText",
"+",
"'\">'",
"+",
"jQuery",
"(",
"'<span/>'",
")",
".",
"text",
"(",
"jQuery",
"(",
"this",
")",
".",
"text",
"(",
")",
")",
".",
"html",
"(",
")",
"+",
"'</a>'",
";",
"var",
"elem",
"=",
"\"\\n\"",
"+",
"'<li>'",
"+",
"hLevelText",
"+",
"(",
"config",
".",
"number_suffix",
"?",
"config",
".",
"number_suffix",
":",
"''",
")",
"+",
"' '",
"+",
"link",
";",
"if",
"(",
"level",
"<",
"prevLevel",
")",
"{",
"log",
"(",
"hLevelText",
"+",
"', unnesting because:'",
"+",
"level",
"+",
"'<'",
"+",
"prevLevel",
")",
";",
"var",
"unnest",
"=",
"''",
";",
"while",
"(",
"level",
"<",
"prevLevel",
")",
"{",
"unnest",
"+=",
"'</ul>'",
";",
"prevLevel",
"--",
";",
"}",
"toc",
"+=",
"unnest",
"+",
"elem",
"+",
"'</li>'",
";",
"}",
"else",
"if",
"(",
"level",
">",
"prevLevel",
")",
"{",
"log",
"(",
"hLevelText",
"+",
"', nesting because:'",
"+",
"level",
"+",
"'>'",
"+",
"prevLevel",
")",
";",
"toc",
"+=",
"'<ul>'",
"+",
"elem",
";",
"}",
"else",
"{",
"log",
"(",
"hLevelText",
"+",
"', same level ('",
"+",
"level",
"+",
"')'",
")",
";",
"toc",
"+=",
"elem",
";",
"}",
"}",
"prependText",
"=",
"'<span id=\"h'",
"+",
"hLevelText",
"+",
"'\"></span>'",
"+",
"hLevelText",
";",
"}",
"if",
"(",
"config",
".",
"number_suffix",
")",
"{",
"prependText",
"+=",
"config",
".",
"number_suffix",
";",
"}",
"jQuery",
"(",
"this",
")",
".",
"prepend",
"(",
"prependText",
"+",
"' '",
")",
";",
"prependText",
"=",
"hLevelText",
"=",
"''",
";",
"prevLevel",
"=",
"level",
";",
"}",
"}",
")",
";",
"if",
"(",
"config",
".",
"generate_toc",
")",
"{",
"if",
"(",
"config",
".",
"toc_title",
")",
"{",
"toc",
"=",
"'<h4>'",
"+",
"config",
".",
"toc_title",
"+",
"'</h4>'",
"+",
"toc",
";",
"}",
"if",
"(",
"n",
"==",
"0",
")",
"{",
"toc",
"+=",
"config",
".",
"toc_none",
"?",
"'<p>'",
"+",
"config",
".",
"toc_none",
"+",
"'</p>'",
":",
"''",
";",
"}",
"jQuery",
"(",
"config",
".",
"toc_elem",
"?",
"config",
".",
"toc_elem",
":",
"'body'",
")",
".",
"append",
"(",
"toc",
")",
";",
"}",
"processed",
"=",
"true",
";",
"}"
] |
Prepends all headers text with the current tree number reference
@return void
|
[
"Prepends",
"all",
"headers",
"text",
"with",
"the",
"current",
"tree",
"number",
"reference"
] |
54307b76844177207e321c5b88eb03a23a6e23a2
|
https://github.com/mar10/fancytree/blob/54307b76844177207e321c5b88eb03a23a6e23a2/lib/jquery.planize.js#L59-L120
|
|
10,718
|
mar10/fancytree
|
lib/jquery.planize.js
|
function() {
if (!config.debug) {
return;
}
try {
console.log.apply(console, arguments);
} catch(e) {
try {
opera.postError.apply(opera, arguments);
} catch(e){}
}
}
|
javascript
|
function() {
if (!config.debug) {
return;
}
try {
console.log.apply(console, arguments);
} catch(e) {
try {
opera.postError.apply(opera, arguments);
} catch(e){}
}
}
|
[
"function",
"(",
")",
"{",
"if",
"(",
"!",
"config",
".",
"debug",
")",
"{",
"return",
";",
"}",
"try",
"{",
"console",
".",
"log",
".",
"apply",
"(",
"console",
",",
"arguments",
")",
";",
"}",
"catch",
"(",
"e",
")",
"{",
"try",
"{",
"opera",
".",
"postError",
".",
"apply",
"(",
"opera",
",",
"arguments",
")",
";",
"}",
"catch",
"(",
"e",
")",
"{",
"}",
"}",
"}"
] |
Logs a message into the firebug or opera console if available
|
[
"Logs",
"a",
"message",
"into",
"the",
"firebug",
"or",
"opera",
"console",
"if",
"available"
] |
54307b76844177207e321c5b88eb03a23a6e23a2
|
https://github.com/mar10/fancytree/blob/54307b76844177207e321c5b88eb03a23a6e23a2/lib/jquery.planize.js#L126-L137
|
|
10,719
|
mar10/fancytree
|
lib/jquery.configurator.js
|
function(){
var plugin = $(this.element).data("ui-" + this.options.pluginName) || $(this.element).data(this.options.pluginName),
opts = this.options,
actualOpts = plugin.options,
availOptList = opts.optionList,
$opts = $(this.options.optionTarget).empty(),
$ul = $("<ul>").appendTo($opts),
$li = null;
$.each(availOptList, function(i, o){
if( typeof o.value === "boolean"){
$li = $("<li>").append(
$("<input>", {
id: o.name,
name: o.name,
type: "checkbox",
checked: !!actualOpts[o.name] //o.value
})
).append(
$("<label>", {"for": o.name, text: " " + o.hint})
);
}else if( typeof o.value === "number" || typeof o.value === "string"){
$li = $("<li>").append(
$("<label>", {"for": o.name, text: " " + o.name})
).append(
$("<input>", {
id: o.name,
name: o.name,
type: "text",
value: actualOpts[o.name] //o.value
})
);
}else if( $.isArray(o.value) ){
$li = $("<li>")
.append(
$("<label>", {"for": o.name, text: " " + o.name})
).append(
$("<select>", {
id: o.name,
name: o.name,
size: 1
})
);
var $sel = $li.find("select");
$.each(o.value, function(){
$sel.append($("<option>", {
value: this.value,
text: this.name,
selected: (actualOpts[o.name] == this.value) //this.selected
}));
});
}
$ul.append($li);
});
}
|
javascript
|
function(){
var plugin = $(this.element).data("ui-" + this.options.pluginName) || $(this.element).data(this.options.pluginName),
opts = this.options,
actualOpts = plugin.options,
availOptList = opts.optionList,
$opts = $(this.options.optionTarget).empty(),
$ul = $("<ul>").appendTo($opts),
$li = null;
$.each(availOptList, function(i, o){
if( typeof o.value === "boolean"){
$li = $("<li>").append(
$("<input>", {
id: o.name,
name: o.name,
type: "checkbox",
checked: !!actualOpts[o.name] //o.value
})
).append(
$("<label>", {"for": o.name, text: " " + o.hint})
);
}else if( typeof o.value === "number" || typeof o.value === "string"){
$li = $("<li>").append(
$("<label>", {"for": o.name, text: " " + o.name})
).append(
$("<input>", {
id: o.name,
name: o.name,
type: "text",
value: actualOpts[o.name] //o.value
})
);
}else if( $.isArray(o.value) ){
$li = $("<li>")
.append(
$("<label>", {"for": o.name, text: " " + o.name})
).append(
$("<select>", {
id: o.name,
name: o.name,
size: 1
})
);
var $sel = $li.find("select");
$.each(o.value, function(){
$sel.append($("<option>", {
value: this.value,
text: this.name,
selected: (actualOpts[o.name] == this.value) //this.selected
}));
});
}
$ul.append($li);
});
}
|
[
"function",
"(",
")",
"{",
"var",
"plugin",
"=",
"$",
"(",
"this",
".",
"element",
")",
".",
"data",
"(",
"\"ui-\"",
"+",
"this",
".",
"options",
".",
"pluginName",
")",
"||",
"$",
"(",
"this",
".",
"element",
")",
".",
"data",
"(",
"this",
".",
"options",
".",
"pluginName",
")",
",",
"opts",
"=",
"this",
".",
"options",
",",
"actualOpts",
"=",
"plugin",
".",
"options",
",",
"availOptList",
"=",
"opts",
".",
"optionList",
",",
"$opts",
"=",
"$",
"(",
"this",
".",
"options",
".",
"optionTarget",
")",
".",
"empty",
"(",
")",
",",
"$ul",
"=",
"$",
"(",
"\"<ul>\"",
")",
".",
"appendTo",
"(",
"$opts",
")",
",",
"$li",
"=",
"null",
";",
"$",
".",
"each",
"(",
"availOptList",
",",
"function",
"(",
"i",
",",
"o",
")",
"{",
"if",
"(",
"typeof",
"o",
".",
"value",
"===",
"\"boolean\"",
")",
"{",
"$li",
"=",
"$",
"(",
"\"<li>\"",
")",
".",
"append",
"(",
"$",
"(",
"\"<input>\"",
",",
"{",
"id",
":",
"o",
".",
"name",
",",
"name",
":",
"o",
".",
"name",
",",
"type",
":",
"\"checkbox\"",
",",
"checked",
":",
"!",
"!",
"actualOpts",
"[",
"o",
".",
"name",
"]",
"//o.value",
"}",
")",
")",
".",
"append",
"(",
"$",
"(",
"\"<label>\"",
",",
"{",
"\"for\"",
":",
"o",
".",
"name",
",",
"text",
":",
"\" \"",
"+",
"o",
".",
"hint",
"}",
")",
")",
";",
"}",
"else",
"if",
"(",
"typeof",
"o",
".",
"value",
"===",
"\"number\"",
"||",
"typeof",
"o",
".",
"value",
"===",
"\"string\"",
")",
"{",
"$li",
"=",
"$",
"(",
"\"<li>\"",
")",
".",
"append",
"(",
"$",
"(",
"\"<label>\"",
",",
"{",
"\"for\"",
":",
"o",
".",
"name",
",",
"text",
":",
"\" \"",
"+",
"o",
".",
"name",
"}",
")",
")",
".",
"append",
"(",
"$",
"(",
"\"<input>\"",
",",
"{",
"id",
":",
"o",
".",
"name",
",",
"name",
":",
"o",
".",
"name",
",",
"type",
":",
"\"text\"",
",",
"value",
":",
"actualOpts",
"[",
"o",
".",
"name",
"]",
"//o.value",
"}",
")",
")",
";",
"}",
"else",
"if",
"(",
"$",
".",
"isArray",
"(",
"o",
".",
"value",
")",
")",
"{",
"$li",
"=",
"$",
"(",
"\"<li>\"",
")",
".",
"append",
"(",
"$",
"(",
"\"<label>\"",
",",
"{",
"\"for\"",
":",
"o",
".",
"name",
",",
"text",
":",
"\" \"",
"+",
"o",
".",
"name",
"}",
")",
")",
".",
"append",
"(",
"$",
"(",
"\"<select>\"",
",",
"{",
"id",
":",
"o",
".",
"name",
",",
"name",
":",
"o",
".",
"name",
",",
"size",
":",
"1",
"}",
")",
")",
";",
"var",
"$sel",
"=",
"$li",
".",
"find",
"(",
"\"select\"",
")",
";",
"$",
".",
"each",
"(",
"o",
".",
"value",
",",
"function",
"(",
")",
"{",
"$sel",
".",
"append",
"(",
"$",
"(",
"\"<option>\"",
",",
"{",
"value",
":",
"this",
".",
"value",
",",
"text",
":",
"this",
".",
"name",
",",
"selected",
":",
"(",
"actualOpts",
"[",
"o",
".",
"name",
"]",
"==",
"this",
".",
"value",
")",
"//this.selected",
"}",
")",
")",
";",
"}",
")",
";",
"}",
"$ul",
".",
"append",
"(",
"$li",
")",
";",
"}",
")",
";",
"}"
] |
Render checkboxes and other controls into configurator panel.
|
[
"Render",
"checkboxes",
"and",
"other",
"controls",
"into",
"configurator",
"panel",
"."
] |
54307b76844177207e321c5b88eb03a23a6e23a2
|
https://github.com/mar10/fancytree/blob/54307b76844177207e321c5b88eb03a23a6e23a2/lib/jquery.configurator.js#L93-L146
|
|
10,720
|
mar10/fancytree
|
lib/jquery.configurator.js
|
function(){
var plugin = $(this.element).data("ui-" + this.options.pluginName) || $(this.element).data(this.options.pluginName),
opts = this.options,
actualOpts = plugin.options,
availOptList = opts.optionList,
lines = [],
header = opts.header || '$("#selector").' + opts.pluginName + "({",
footer = "});",
i;
// Make a filtered copy of the option list (so we get the last ',' right)
if(this.options.hideDefaults){
availOptList = [];
for(i=0; i<this.options.optionList.length; i++){
var o = this.options.optionList[i],
n = o.name,
defVal = o.value;
if($.isArray(defVal)){
defVal = $.map(defVal, function(e){ return e.selected ? e.value : null;})[0];
}
if( actualOpts[n] !== defVal /*&& actualOpts[n] !== undefined*/){
availOptList.push(o);
}
}
}
//
lines.push(header);
for(i=0; i<availOptList.length; i++){
var o = availOptList[i],
actualVal = actualOpts[o.name],
line = " " + o.name + ": ";
if(typeof actualVal === "string"){
line += '"' + actualVal + '"';
}else if($.isPlainObject(actualVal)){
line += JSON.stringify(actualVal);
}else{
line += "" + actualVal;
}
if( i < (availOptList.length - 1) ){
line += ",";
}
if( opts.showComments ){
line += " // " + o.hint;
}
lines.push(line);
}
lines.push(footer);
$(opts.sourceTarget).addClass("ui-configurator-source").text(lines.join("\n"));
this._trigger("render");
}
|
javascript
|
function(){
var plugin = $(this.element).data("ui-" + this.options.pluginName) || $(this.element).data(this.options.pluginName),
opts = this.options,
actualOpts = plugin.options,
availOptList = opts.optionList,
lines = [],
header = opts.header || '$("#selector").' + opts.pluginName + "({",
footer = "});",
i;
// Make a filtered copy of the option list (so we get the last ',' right)
if(this.options.hideDefaults){
availOptList = [];
for(i=0; i<this.options.optionList.length; i++){
var o = this.options.optionList[i],
n = o.name,
defVal = o.value;
if($.isArray(defVal)){
defVal = $.map(defVal, function(e){ return e.selected ? e.value : null;})[0];
}
if( actualOpts[n] !== defVal /*&& actualOpts[n] !== undefined*/){
availOptList.push(o);
}
}
}
//
lines.push(header);
for(i=0; i<availOptList.length; i++){
var o = availOptList[i],
actualVal = actualOpts[o.name],
line = " " + o.name + ": ";
if(typeof actualVal === "string"){
line += '"' + actualVal + '"';
}else if($.isPlainObject(actualVal)){
line += JSON.stringify(actualVal);
}else{
line += "" + actualVal;
}
if( i < (availOptList.length - 1) ){
line += ",";
}
if( opts.showComments ){
line += " // " + o.hint;
}
lines.push(line);
}
lines.push(footer);
$(opts.sourceTarget).addClass("ui-configurator-source").text(lines.join("\n"));
this._trigger("render");
}
|
[
"function",
"(",
")",
"{",
"var",
"plugin",
"=",
"$",
"(",
"this",
".",
"element",
")",
".",
"data",
"(",
"\"ui-\"",
"+",
"this",
".",
"options",
".",
"pluginName",
")",
"||",
"$",
"(",
"this",
".",
"element",
")",
".",
"data",
"(",
"this",
".",
"options",
".",
"pluginName",
")",
",",
"opts",
"=",
"this",
".",
"options",
",",
"actualOpts",
"=",
"plugin",
".",
"options",
",",
"availOptList",
"=",
"opts",
".",
"optionList",
",",
"lines",
"=",
"[",
"]",
",",
"header",
"=",
"opts",
".",
"header",
"||",
"'$(\"#selector\").'",
"+",
"opts",
".",
"pluginName",
"+",
"\"({\"",
",",
"footer",
"=",
"\"});\"",
",",
"i",
";",
"// Make a filtered copy of the option list (so we get the last ',' right)",
"if",
"(",
"this",
".",
"options",
".",
"hideDefaults",
")",
"{",
"availOptList",
"=",
"[",
"]",
";",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"this",
".",
"options",
".",
"optionList",
".",
"length",
";",
"i",
"++",
")",
"{",
"var",
"o",
"=",
"this",
".",
"options",
".",
"optionList",
"[",
"i",
"]",
",",
"n",
"=",
"o",
".",
"name",
",",
"defVal",
"=",
"o",
".",
"value",
";",
"if",
"(",
"$",
".",
"isArray",
"(",
"defVal",
")",
")",
"{",
"defVal",
"=",
"$",
".",
"map",
"(",
"defVal",
",",
"function",
"(",
"e",
")",
"{",
"return",
"e",
".",
"selected",
"?",
"e",
".",
"value",
":",
"null",
";",
"}",
")",
"[",
"0",
"]",
";",
"}",
"if",
"(",
"actualOpts",
"[",
"n",
"]",
"!==",
"defVal",
"/*&& actualOpts[n] !== undefined*/",
")",
"{",
"availOptList",
".",
"push",
"(",
"o",
")",
";",
"}",
"}",
"}",
"//",
"lines",
".",
"push",
"(",
"header",
")",
";",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"availOptList",
".",
"length",
";",
"i",
"++",
")",
"{",
"var",
"o",
"=",
"availOptList",
"[",
"i",
"]",
",",
"actualVal",
"=",
"actualOpts",
"[",
"o",
".",
"name",
"]",
",",
"line",
"=",
"\" \"",
"+",
"o",
".",
"name",
"+",
"\": \"",
";",
"if",
"(",
"typeof",
"actualVal",
"===",
"\"string\"",
")",
"{",
"line",
"+=",
"'\"'",
"+",
"actualVal",
"+",
"'\"'",
";",
"}",
"else",
"if",
"(",
"$",
".",
"isPlainObject",
"(",
"actualVal",
")",
")",
"{",
"line",
"+=",
"JSON",
".",
"stringify",
"(",
"actualVal",
")",
";",
"}",
"else",
"{",
"line",
"+=",
"\"\"",
"+",
"actualVal",
";",
"}",
"if",
"(",
"i",
"<",
"(",
"availOptList",
".",
"length",
"-",
"1",
")",
")",
"{",
"line",
"+=",
"\",\"",
";",
"}",
"if",
"(",
"opts",
".",
"showComments",
")",
"{",
"line",
"+=",
"\" // \"",
"+",
"o",
".",
"hint",
";",
"}",
"lines",
".",
"push",
"(",
"line",
")",
";",
"}",
"lines",
".",
"push",
"(",
"footer",
")",
";",
"$",
"(",
"opts",
".",
"sourceTarget",
")",
".",
"addClass",
"(",
"\"ui-configurator-source\"",
")",
".",
"text",
"(",
"lines",
".",
"join",
"(",
"\"\\n\"",
")",
")",
";",
"this",
".",
"_trigger",
"(",
"\"render\"",
")",
";",
"}"
] |
Render source code into source panel.
|
[
"Render",
"source",
"code",
"into",
"source",
"panel",
"."
] |
54307b76844177207e321c5b88eb03a23a6e23a2
|
https://github.com/mar10/fancytree/blob/54307b76844177207e321c5b88eb03a23a6e23a2/lib/jquery.configurator.js#L150-L198
|
|
10,721
|
mar10/fancytree
|
demo/taxonomy-browser/taxonomy-browser-itis.js
|
updateControls
|
function updateControls() {
var query = $.trim($("input[name=query]").val());
$("#btnPin").attr("disabled", !taxonTree.getActiveNode());
$("#btnUnpin")
.attr("disabled", !taxonTree.isFilterActive())
.toggleClass("btn-success", taxonTree.isFilterActive());
$("#btnResetSearch").attr("disabled", query.length === 0);
$("#btnSearch").attr("disabled", query.length < 2);
}
|
javascript
|
function updateControls() {
var query = $.trim($("input[name=query]").val());
$("#btnPin").attr("disabled", !taxonTree.getActiveNode());
$("#btnUnpin")
.attr("disabled", !taxonTree.isFilterActive())
.toggleClass("btn-success", taxonTree.isFilterActive());
$("#btnResetSearch").attr("disabled", query.length === 0);
$("#btnSearch").attr("disabled", query.length < 2);
}
|
[
"function",
"updateControls",
"(",
")",
"{",
"var",
"query",
"=",
"$",
".",
"trim",
"(",
"$",
"(",
"\"input[name=query]\"",
")",
".",
"val",
"(",
")",
")",
";",
"$",
"(",
"\"#btnPin\"",
")",
".",
"attr",
"(",
"\"disabled\"",
",",
"!",
"taxonTree",
".",
"getActiveNode",
"(",
")",
")",
";",
"$",
"(",
"\"#btnUnpin\"",
")",
".",
"attr",
"(",
"\"disabled\"",
",",
"!",
"taxonTree",
".",
"isFilterActive",
"(",
")",
")",
".",
"toggleClass",
"(",
"\"btn-success\"",
",",
"taxonTree",
".",
"isFilterActive",
"(",
")",
")",
";",
"$",
"(",
"\"#btnResetSearch\"",
")",
".",
"attr",
"(",
"\"disabled\"",
",",
"query",
".",
"length",
"===",
"0",
")",
";",
"$",
"(",
"\"#btnSearch\"",
")",
".",
"attr",
"(",
"\"disabled\"",
",",
"query",
".",
"length",
"<",
"2",
")",
";",
"}"
] |
Update UI elements according to current status
|
[
"Update",
"UI",
"elements",
"according",
"to",
"current",
"status"
] |
54307b76844177207e321c5b88eb03a23a6e23a2
|
https://github.com/mar10/fancytree/blob/54307b76844177207e321c5b88eb03a23a6e23a2/demo/taxonomy-browser/taxonomy-browser-itis.js#L46-L55
|
10,722
|
mar10/fancytree
|
demo/taxonomy-browser/taxonomy-browser-itis.js
|
_delay
|
function _delay(tag, ms, callback) {
/*jshint -W040:true */
var self = this;
tag = "" + (tag || "default");
if (timerMap[tag] != null) {
clearTimeout(timerMap[tag]);
delete timerMap[tag];
// console.log("Cancel timer '" + tag + "'");
}
if (ms == null || callback == null) {
return;
}
// console.log("Start timer '" + tag + "'");
timerMap[tag] = setTimeout(function() {
// console.log("Execute timer '" + tag + "'");
callback.call(self);
}, +ms);
}
|
javascript
|
function _delay(tag, ms, callback) {
/*jshint -W040:true */
var self = this;
tag = "" + (tag || "default");
if (timerMap[tag] != null) {
clearTimeout(timerMap[tag]);
delete timerMap[tag];
// console.log("Cancel timer '" + tag + "'");
}
if (ms == null || callback == null) {
return;
}
// console.log("Start timer '" + tag + "'");
timerMap[tag] = setTimeout(function() {
// console.log("Execute timer '" + tag + "'");
callback.call(self);
}, +ms);
}
|
[
"function",
"_delay",
"(",
"tag",
",",
"ms",
",",
"callback",
")",
"{",
"/*jshint -W040:true */",
"var",
"self",
"=",
"this",
";",
"tag",
"=",
"\"\"",
"+",
"(",
"tag",
"||",
"\"default\"",
")",
";",
"if",
"(",
"timerMap",
"[",
"tag",
"]",
"!=",
"null",
")",
"{",
"clearTimeout",
"(",
"timerMap",
"[",
"tag",
"]",
")",
";",
"delete",
"timerMap",
"[",
"tag",
"]",
";",
"// console.log(\"Cancel timer '\" + tag + \"'\");",
"}",
"if",
"(",
"ms",
"==",
"null",
"||",
"callback",
"==",
"null",
")",
"{",
"return",
";",
"}",
"// console.log(\"Start timer '\" + tag + \"'\");",
"timerMap",
"[",
"tag",
"]",
"=",
"setTimeout",
"(",
"function",
"(",
")",
"{",
"// console.log(\"Execute timer '\" + tag + \"'\");",
"callback",
".",
"call",
"(",
"self",
")",
";",
"}",
",",
"+",
"ms",
")",
";",
"}"
] |
Invoke callback after `ms` milliseconds.
Any pending action of this type is cancelled before.
|
[
"Invoke",
"callback",
"after",
"ms",
"milliseconds",
".",
"Any",
"pending",
"action",
"of",
"this",
"type",
"is",
"cancelled",
"before",
"."
] |
54307b76844177207e321c5b88eb03a23a6e23a2
|
https://github.com/mar10/fancytree/blob/54307b76844177207e321c5b88eb03a23a6e23a2/demo/taxonomy-browser/taxonomy-browser-itis.js#L61-L79
|
10,723
|
UnitedIncome/serverless-python-requirements
|
lib/inject.js
|
moveModuleUp
|
function moveModuleUp(source, target, module) {
const targetZip = new JSZip();
return fse
.readFileAsync(source)
.then(buffer => JSZip.loadAsync(buffer))
.then(sourceZip => sourceZip.filter(file => file.startsWith(module + '/')))
.map(srcZipObj =>
zipFile(
targetZip,
srcZipObj.name.replace(module + '/', ''),
srcZipObj.async('nodebuffer')
)
)
.then(() => writeZip(targetZip, target));
}
|
javascript
|
function moveModuleUp(source, target, module) {
const targetZip = new JSZip();
return fse
.readFileAsync(source)
.then(buffer => JSZip.loadAsync(buffer))
.then(sourceZip => sourceZip.filter(file => file.startsWith(module + '/')))
.map(srcZipObj =>
zipFile(
targetZip,
srcZipObj.name.replace(module + '/', ''),
srcZipObj.async('nodebuffer')
)
)
.then(() => writeZip(targetZip, target));
}
|
[
"function",
"moveModuleUp",
"(",
"source",
",",
"target",
",",
"module",
")",
"{",
"const",
"targetZip",
"=",
"new",
"JSZip",
"(",
")",
";",
"return",
"fse",
".",
"readFileAsync",
"(",
"source",
")",
".",
"then",
"(",
"buffer",
"=>",
"JSZip",
".",
"loadAsync",
"(",
"buffer",
")",
")",
".",
"then",
"(",
"sourceZip",
"=>",
"sourceZip",
".",
"filter",
"(",
"file",
"=>",
"file",
".",
"startsWith",
"(",
"module",
"+",
"'/'",
")",
")",
")",
".",
"map",
"(",
"srcZipObj",
"=>",
"zipFile",
"(",
"targetZip",
",",
"srcZipObj",
".",
"name",
".",
"replace",
"(",
"module",
"+",
"'/'",
",",
"''",
")",
",",
"srcZipObj",
".",
"async",
"(",
"'nodebuffer'",
")",
")",
")",
".",
"then",
"(",
"(",
")",
"=>",
"writeZip",
"(",
"targetZip",
",",
"target",
")",
")",
";",
"}"
] |
Remove all modules but the selected module from a package.
@param {string} source path to original package
@param {string} target path to result package
@param {string} module module to keep
@return {Promise} the JSZip object written out.
|
[
"Remove",
"all",
"modules",
"but",
"the",
"selected",
"module",
"from",
"a",
"package",
"."
] |
2e8117502606fd4bd82c19c3050ba0350adb2789
|
https://github.com/UnitedIncome/serverless-python-requirements/blob/2e8117502606fd4bd82c19c3050ba0350adb2789/lib/inject.js#L58-L73
|
10,724
|
UnitedIncome/serverless-python-requirements
|
lib/clean.js
|
cleanup
|
function cleanup() {
const artifacts = ['.requirements'];
if (this.options.zip) {
if (this.serverless.service.package.individually) {
this.targetFuncs.forEach(f => {
artifacts.push(path.join(f.module, '.requirements.zip'));
artifacts.push(path.join(f.module, 'unzip_requirements.py'));
});
} else {
artifacts.push('.requirements.zip');
artifacts.push('unzip_requirements.py');
}
}
return BbPromise.all(
artifacts.map(artifact =>
fse.removeAsync(path.join(this.servicePath, artifact))
)
);
}
|
javascript
|
function cleanup() {
const artifacts = ['.requirements'];
if (this.options.zip) {
if (this.serverless.service.package.individually) {
this.targetFuncs.forEach(f => {
artifacts.push(path.join(f.module, '.requirements.zip'));
artifacts.push(path.join(f.module, 'unzip_requirements.py'));
});
} else {
artifacts.push('.requirements.zip');
artifacts.push('unzip_requirements.py');
}
}
return BbPromise.all(
artifacts.map(artifact =>
fse.removeAsync(path.join(this.servicePath, artifact))
)
);
}
|
[
"function",
"cleanup",
"(",
")",
"{",
"const",
"artifacts",
"=",
"[",
"'.requirements'",
"]",
";",
"if",
"(",
"this",
".",
"options",
".",
"zip",
")",
"{",
"if",
"(",
"this",
".",
"serverless",
".",
"service",
".",
"package",
".",
"individually",
")",
"{",
"this",
".",
"targetFuncs",
".",
"forEach",
"(",
"f",
"=>",
"{",
"artifacts",
".",
"push",
"(",
"path",
".",
"join",
"(",
"f",
".",
"module",
",",
"'.requirements.zip'",
")",
")",
";",
"artifacts",
".",
"push",
"(",
"path",
".",
"join",
"(",
"f",
".",
"module",
",",
"'unzip_requirements.py'",
")",
")",
";",
"}",
")",
";",
"}",
"else",
"{",
"artifacts",
".",
"push",
"(",
"'.requirements.zip'",
")",
";",
"artifacts",
".",
"push",
"(",
"'unzip_requirements.py'",
")",
";",
"}",
"}",
"return",
"BbPromise",
".",
"all",
"(",
"artifacts",
".",
"map",
"(",
"artifact",
"=>",
"fse",
".",
"removeAsync",
"(",
"path",
".",
"join",
"(",
"this",
".",
"servicePath",
",",
"artifact",
")",
")",
")",
")",
";",
"}"
] |
clean up .requirements and .requirements.zip and unzip_requirements.py
@return {Promise}
|
[
"clean",
"up",
".",
"requirements",
"and",
".",
"requirements",
".",
"zip",
"and",
"unzip_requirements",
".",
"py"
] |
2e8117502606fd4bd82c19c3050ba0350adb2789
|
https://github.com/UnitedIncome/serverless-python-requirements/blob/2e8117502606fd4bd82c19c3050ba0350adb2789/lib/clean.js#L13-L32
|
10,725
|
UnitedIncome/serverless-python-requirements
|
lib/clean.js
|
cleanupCache
|
function cleanupCache() {
const cacheLocation = getUserCachePath(this.options);
if (fse.existsSync(cacheLocation)) {
if (this.serverless) {
this.serverless.cli.log(`Removing static caches at: ${cacheLocation}`);
}
// Only remove cache folders that we added, just incase someone accidentally puts a weird
// static cache location so we don't remove a bunch of personal stuff
const promises = [];
glob
.sync([path.join(cacheLocation, '*slspyc/')], { mark: true, dot: false })
.forEach(file => {
promises.push(fse.removeAsync(file));
});
return BbPromise.all(promises);
} else {
if (this.serverless) {
this.serverless.cli.log(`No static cache found`);
}
return BbPromise.resolve();
}
}
|
javascript
|
function cleanupCache() {
const cacheLocation = getUserCachePath(this.options);
if (fse.existsSync(cacheLocation)) {
if (this.serverless) {
this.serverless.cli.log(`Removing static caches at: ${cacheLocation}`);
}
// Only remove cache folders that we added, just incase someone accidentally puts a weird
// static cache location so we don't remove a bunch of personal stuff
const promises = [];
glob
.sync([path.join(cacheLocation, '*slspyc/')], { mark: true, dot: false })
.forEach(file => {
promises.push(fse.removeAsync(file));
});
return BbPromise.all(promises);
} else {
if (this.serverless) {
this.serverless.cli.log(`No static cache found`);
}
return BbPromise.resolve();
}
}
|
[
"function",
"cleanupCache",
"(",
")",
"{",
"const",
"cacheLocation",
"=",
"getUserCachePath",
"(",
"this",
".",
"options",
")",
";",
"if",
"(",
"fse",
".",
"existsSync",
"(",
"cacheLocation",
")",
")",
"{",
"if",
"(",
"this",
".",
"serverless",
")",
"{",
"this",
".",
"serverless",
".",
"cli",
".",
"log",
"(",
"`",
"${",
"cacheLocation",
"}",
"`",
")",
";",
"}",
"// Only remove cache folders that we added, just incase someone accidentally puts a weird",
"// static cache location so we don't remove a bunch of personal stuff",
"const",
"promises",
"=",
"[",
"]",
";",
"glob",
".",
"sync",
"(",
"[",
"path",
".",
"join",
"(",
"cacheLocation",
",",
"'*slspyc/'",
")",
"]",
",",
"{",
"mark",
":",
"true",
",",
"dot",
":",
"false",
"}",
")",
".",
"forEach",
"(",
"file",
"=>",
"{",
"promises",
".",
"push",
"(",
"fse",
".",
"removeAsync",
"(",
"file",
")",
")",
";",
"}",
")",
";",
"return",
"BbPromise",
".",
"all",
"(",
"promises",
")",
";",
"}",
"else",
"{",
"if",
"(",
"this",
".",
"serverless",
")",
"{",
"this",
".",
"serverless",
".",
"cli",
".",
"log",
"(",
"`",
"`",
")",
";",
"}",
"return",
"BbPromise",
".",
"resolve",
"(",
")",
";",
"}",
"}"
] |
Clean up static cache, remove all items in there
@return {Promise}
|
[
"Clean",
"up",
"static",
"cache",
"remove",
"all",
"items",
"in",
"there"
] |
2e8117502606fd4bd82c19c3050ba0350adb2789
|
https://github.com/UnitedIncome/serverless-python-requirements/blob/2e8117502606fd4bd82c19c3050ba0350adb2789/lib/clean.js#L38-L60
|
10,726
|
UnitedIncome/serverless-python-requirements
|
lib/docker.js
|
dockerCommand
|
function dockerCommand(options) {
const cmd = 'docker';
const ps = spawnSync(cmd, options, { encoding: 'utf-8' });
if (ps.error) {
if (ps.error.code === 'ENOENT') {
throw new Error('docker not found! Please install it.');
}
throw new Error(ps.error);
} else if (ps.status !== 0) {
throw new Error(ps.stderr);
}
return ps;
}
|
javascript
|
function dockerCommand(options) {
const cmd = 'docker';
const ps = spawnSync(cmd, options, { encoding: 'utf-8' });
if (ps.error) {
if (ps.error.code === 'ENOENT') {
throw new Error('docker not found! Please install it.');
}
throw new Error(ps.error);
} else if (ps.status !== 0) {
throw new Error(ps.stderr);
}
return ps;
}
|
[
"function",
"dockerCommand",
"(",
"options",
")",
"{",
"const",
"cmd",
"=",
"'docker'",
";",
"const",
"ps",
"=",
"spawnSync",
"(",
"cmd",
",",
"options",
",",
"{",
"encoding",
":",
"'utf-8'",
"}",
")",
";",
"if",
"(",
"ps",
".",
"error",
")",
"{",
"if",
"(",
"ps",
".",
"error",
".",
"code",
"===",
"'ENOENT'",
")",
"{",
"throw",
"new",
"Error",
"(",
"'docker not found! Please install it.'",
")",
";",
"}",
"throw",
"new",
"Error",
"(",
"ps",
".",
"error",
")",
";",
"}",
"else",
"if",
"(",
"ps",
".",
"status",
"!==",
"0",
")",
"{",
"throw",
"new",
"Error",
"(",
"ps",
".",
"stderr",
")",
";",
"}",
"return",
"ps",
";",
"}"
] |
Helper function to run a docker command
@param {string[]} options
@return {Object}
|
[
"Helper",
"function",
"to",
"run",
"a",
"docker",
"command"
] |
2e8117502606fd4bd82c19c3050ba0350adb2789
|
https://github.com/UnitedIncome/serverless-python-requirements/blob/2e8117502606fd4bd82c19c3050ba0350adb2789/lib/docker.js#L11-L23
|
10,727
|
UnitedIncome/serverless-python-requirements
|
lib/docker.js
|
tryBindPath
|
function tryBindPath(serverless, bindPath, testFile) {
const options = [
'run',
'--rm',
'-v',
`${bindPath}:/test`,
'alpine',
'ls',
`/test/${testFile}`
];
try {
const ps = dockerCommand(options);
if (process.env.SLS_DEBUG) {
serverless.cli.log(`Trying bindPath ${bindPath} (${options})`);
serverless.cli.log(ps.stdout.trim());
}
return ps.stdout.trim() === `/test/${testFile}`;
} catch (err) {
return false;
}
}
|
javascript
|
function tryBindPath(serverless, bindPath, testFile) {
const options = [
'run',
'--rm',
'-v',
`${bindPath}:/test`,
'alpine',
'ls',
`/test/${testFile}`
];
try {
const ps = dockerCommand(options);
if (process.env.SLS_DEBUG) {
serverless.cli.log(`Trying bindPath ${bindPath} (${options})`);
serverless.cli.log(ps.stdout.trim());
}
return ps.stdout.trim() === `/test/${testFile}`;
} catch (err) {
return false;
}
}
|
[
"function",
"tryBindPath",
"(",
"serverless",
",",
"bindPath",
",",
"testFile",
")",
"{",
"const",
"options",
"=",
"[",
"'run'",
",",
"'--rm'",
",",
"'-v'",
",",
"`",
"${",
"bindPath",
"}",
"`",
",",
"'alpine'",
",",
"'ls'",
",",
"`",
"${",
"testFile",
"}",
"`",
"]",
";",
"try",
"{",
"const",
"ps",
"=",
"dockerCommand",
"(",
"options",
")",
";",
"if",
"(",
"process",
".",
"env",
".",
"SLS_DEBUG",
")",
"{",
"serverless",
".",
"cli",
".",
"log",
"(",
"`",
"${",
"bindPath",
"}",
"${",
"options",
"}",
"`",
")",
";",
"serverless",
".",
"cli",
".",
"log",
"(",
"ps",
".",
"stdout",
".",
"trim",
"(",
")",
")",
";",
"}",
"return",
"ps",
".",
"stdout",
".",
"trim",
"(",
")",
"===",
"`",
"${",
"testFile",
"}",
"`",
";",
"}",
"catch",
"(",
"err",
")",
"{",
"return",
"false",
";",
"}",
"}"
] |
Test bind path to make sure it's working
@param {string} bindPath
@return {boolean}
|
[
"Test",
"bind",
"path",
"to",
"make",
"sure",
"it",
"s",
"working"
] |
2e8117502606fd4bd82c19c3050ba0350adb2789
|
https://github.com/UnitedIncome/serverless-python-requirements/blob/2e8117502606fd4bd82c19c3050ba0350adb2789/lib/docker.js#L65-L85
|
10,728
|
UnitedIncome/serverless-python-requirements
|
lib/docker.js
|
getBindPath
|
function getBindPath(serverless, servicePath) {
// Determine bind path
if (process.platform !== 'win32' && !isWsl) {
return servicePath;
}
// test docker is available
dockerCommand(['version']);
// find good bind path for Windows
let bindPaths = [];
let baseBindPath = servicePath.replace(/\\([^\s])/g, '/$1');
let drive;
let path;
bindPaths.push(baseBindPath);
if (baseBindPath.startsWith('/mnt/')) {
// cygwin "/mnt/C/users/..."
baseBindPath = baseBindPath.replace(/^\/mnt\//, '/');
}
if (baseBindPath[1] == ':') {
// normal windows "c:/users/..."
drive = baseBindPath[0];
path = baseBindPath.substring(3);
} else if (baseBindPath[0] == '/' && baseBindPath[2] == '/') {
// gitbash "/c/users/..."
drive = baseBindPath[1];
path = baseBindPath.substring(3);
} else {
throw new Error(`Unknown path format ${baseBindPath.substr(10)}...`);
}
bindPaths.push(`/${drive.toLowerCase()}/${path}`); // Docker Toolbox (seems like Docker for Windows can support this too)
bindPaths.push(`${drive.toLowerCase()}:/${path}`); // Docker for Windows
// other options just in case
bindPaths.push(`/${drive.toUpperCase()}/${path}`);
bindPaths.push(`/mnt/${drive.toLowerCase()}/${path}`);
bindPaths.push(`/mnt/${drive.toUpperCase()}/${path}`);
bindPaths.push(`${drive.toUpperCase()}:/${path}`);
const testFile = findTestFile(servicePath);
for (let i = 0; i < bindPaths.length; i++) {
const bindPath = bindPaths[i];
if (tryBindPath(serverless, bindPath, testFile)) {
return bindPath;
}
}
throw new Error('Unable to find good bind path format');
}
|
javascript
|
function getBindPath(serverless, servicePath) {
// Determine bind path
if (process.platform !== 'win32' && !isWsl) {
return servicePath;
}
// test docker is available
dockerCommand(['version']);
// find good bind path for Windows
let bindPaths = [];
let baseBindPath = servicePath.replace(/\\([^\s])/g, '/$1');
let drive;
let path;
bindPaths.push(baseBindPath);
if (baseBindPath.startsWith('/mnt/')) {
// cygwin "/mnt/C/users/..."
baseBindPath = baseBindPath.replace(/^\/mnt\//, '/');
}
if (baseBindPath[1] == ':') {
// normal windows "c:/users/..."
drive = baseBindPath[0];
path = baseBindPath.substring(3);
} else if (baseBindPath[0] == '/' && baseBindPath[2] == '/') {
// gitbash "/c/users/..."
drive = baseBindPath[1];
path = baseBindPath.substring(3);
} else {
throw new Error(`Unknown path format ${baseBindPath.substr(10)}...`);
}
bindPaths.push(`/${drive.toLowerCase()}/${path}`); // Docker Toolbox (seems like Docker for Windows can support this too)
bindPaths.push(`${drive.toLowerCase()}:/${path}`); // Docker for Windows
// other options just in case
bindPaths.push(`/${drive.toUpperCase()}/${path}`);
bindPaths.push(`/mnt/${drive.toLowerCase()}/${path}`);
bindPaths.push(`/mnt/${drive.toUpperCase()}/${path}`);
bindPaths.push(`${drive.toUpperCase()}:/${path}`);
const testFile = findTestFile(servicePath);
for (let i = 0; i < bindPaths.length; i++) {
const bindPath = bindPaths[i];
if (tryBindPath(serverless, bindPath, testFile)) {
return bindPath;
}
}
throw new Error('Unable to find good bind path format');
}
|
[
"function",
"getBindPath",
"(",
"serverless",
",",
"servicePath",
")",
"{",
"// Determine bind path",
"if",
"(",
"process",
".",
"platform",
"!==",
"'win32'",
"&&",
"!",
"isWsl",
")",
"{",
"return",
"servicePath",
";",
"}",
"// test docker is available",
"dockerCommand",
"(",
"[",
"'version'",
"]",
")",
";",
"// find good bind path for Windows",
"let",
"bindPaths",
"=",
"[",
"]",
";",
"let",
"baseBindPath",
"=",
"servicePath",
".",
"replace",
"(",
"/",
"\\\\([^\\s])",
"/",
"g",
",",
"'/$1'",
")",
";",
"let",
"drive",
";",
"let",
"path",
";",
"bindPaths",
".",
"push",
"(",
"baseBindPath",
")",
";",
"if",
"(",
"baseBindPath",
".",
"startsWith",
"(",
"'/mnt/'",
")",
")",
"{",
"// cygwin \"/mnt/C/users/...\"",
"baseBindPath",
"=",
"baseBindPath",
".",
"replace",
"(",
"/",
"^\\/mnt\\/",
"/",
",",
"'/'",
")",
";",
"}",
"if",
"(",
"baseBindPath",
"[",
"1",
"]",
"==",
"':'",
")",
"{",
"// normal windows \"c:/users/...\"",
"drive",
"=",
"baseBindPath",
"[",
"0",
"]",
";",
"path",
"=",
"baseBindPath",
".",
"substring",
"(",
"3",
")",
";",
"}",
"else",
"if",
"(",
"baseBindPath",
"[",
"0",
"]",
"==",
"'/'",
"&&",
"baseBindPath",
"[",
"2",
"]",
"==",
"'/'",
")",
"{",
"// gitbash \"/c/users/...\"",
"drive",
"=",
"baseBindPath",
"[",
"1",
"]",
";",
"path",
"=",
"baseBindPath",
".",
"substring",
"(",
"3",
")",
";",
"}",
"else",
"{",
"throw",
"new",
"Error",
"(",
"`",
"${",
"baseBindPath",
".",
"substr",
"(",
"10",
")",
"}",
"`",
")",
";",
"}",
"bindPaths",
".",
"push",
"(",
"`",
"${",
"drive",
".",
"toLowerCase",
"(",
")",
"}",
"${",
"path",
"}",
"`",
")",
";",
"// Docker Toolbox (seems like Docker for Windows can support this too)",
"bindPaths",
".",
"push",
"(",
"`",
"${",
"drive",
".",
"toLowerCase",
"(",
")",
"}",
"${",
"path",
"}",
"`",
")",
";",
"// Docker for Windows",
"// other options just in case",
"bindPaths",
".",
"push",
"(",
"`",
"${",
"drive",
".",
"toUpperCase",
"(",
")",
"}",
"${",
"path",
"}",
"`",
")",
";",
"bindPaths",
".",
"push",
"(",
"`",
"${",
"drive",
".",
"toLowerCase",
"(",
")",
"}",
"${",
"path",
"}",
"`",
")",
";",
"bindPaths",
".",
"push",
"(",
"`",
"${",
"drive",
".",
"toUpperCase",
"(",
")",
"}",
"${",
"path",
"}",
"`",
")",
";",
"bindPaths",
".",
"push",
"(",
"`",
"${",
"drive",
".",
"toUpperCase",
"(",
")",
"}",
"${",
"path",
"}",
"`",
")",
";",
"const",
"testFile",
"=",
"findTestFile",
"(",
"servicePath",
")",
";",
"for",
"(",
"let",
"i",
"=",
"0",
";",
"i",
"<",
"bindPaths",
".",
"length",
";",
"i",
"++",
")",
"{",
"const",
"bindPath",
"=",
"bindPaths",
"[",
"i",
"]",
";",
"if",
"(",
"tryBindPath",
"(",
"serverless",
",",
"bindPath",
",",
"testFile",
")",
")",
"{",
"return",
"bindPath",
";",
"}",
"}",
"throw",
"new",
"Error",
"(",
"'Unable to find good bind path format'",
")",
";",
"}"
] |
Get bind path depending on os platform
@param {object} serverless
@param {string} servicePath
@return {string} The bind path.
|
[
"Get",
"bind",
"path",
"depending",
"on",
"os",
"platform"
] |
2e8117502606fd4bd82c19c3050ba0350adb2789
|
https://github.com/UnitedIncome/serverless-python-requirements/blob/2e8117502606fd4bd82c19c3050ba0350adb2789/lib/docker.js#L93-L143
|
10,729
|
UnitedIncome/serverless-python-requirements
|
lib/docker.js
|
getDockerUid
|
function getDockerUid(bindPath) {
const options = [
'run',
'--rm',
'-v',
`${bindPath}:/test`,
'alpine',
'stat',
'-c',
'%u',
'/bin/sh'
];
const ps = dockerCommand(options);
return ps.stdout.trim();
}
|
javascript
|
function getDockerUid(bindPath) {
const options = [
'run',
'--rm',
'-v',
`${bindPath}:/test`,
'alpine',
'stat',
'-c',
'%u',
'/bin/sh'
];
const ps = dockerCommand(options);
return ps.stdout.trim();
}
|
[
"function",
"getDockerUid",
"(",
"bindPath",
")",
"{",
"const",
"options",
"=",
"[",
"'run'",
",",
"'--rm'",
",",
"'-v'",
",",
"`",
"${",
"bindPath",
"}",
"`",
",",
"'alpine'",
",",
"'stat'",
",",
"'-c'",
",",
"'%u'",
",",
"'/bin/sh'",
"]",
";",
"const",
"ps",
"=",
"dockerCommand",
"(",
"options",
")",
";",
"return",
"ps",
".",
"stdout",
".",
"trim",
"(",
")",
";",
"}"
] |
Find out what uid the docker machine is using
@param {string} bindPath
@return {boolean}
|
[
"Find",
"out",
"what",
"uid",
"the",
"docker",
"machine",
"is",
"using"
] |
2e8117502606fd4bd82c19c3050ba0350adb2789
|
https://github.com/UnitedIncome/serverless-python-requirements/blob/2e8117502606fd4bd82c19c3050ba0350adb2789/lib/docker.js#L150-L164
|
10,730
|
UnitedIncome/serverless-python-requirements
|
lib/layer.js
|
zipRequirements
|
function zipRequirements() {
const rootZip = new JSZip();
const src = path.join('.serverless', 'requirements');
const runtimepath = 'python';
return addTree(rootZip.folder(runtimepath), src).then(() =>
writeZip(rootZip, path.join('.serverless', 'pythonRequirements.zip'))
);
}
|
javascript
|
function zipRequirements() {
const rootZip = new JSZip();
const src = path.join('.serverless', 'requirements');
const runtimepath = 'python';
return addTree(rootZip.folder(runtimepath), src).then(() =>
writeZip(rootZip, path.join('.serverless', 'pythonRequirements.zip'))
);
}
|
[
"function",
"zipRequirements",
"(",
")",
"{",
"const",
"rootZip",
"=",
"new",
"JSZip",
"(",
")",
";",
"const",
"src",
"=",
"path",
".",
"join",
"(",
"'.serverless'",
",",
"'requirements'",
")",
";",
"const",
"runtimepath",
"=",
"'python'",
";",
"return",
"addTree",
"(",
"rootZip",
".",
"folder",
"(",
"runtimepath",
")",
",",
"src",
")",
".",
"then",
"(",
"(",
")",
"=>",
"writeZip",
"(",
"rootZip",
",",
"path",
".",
"join",
"(",
"'.serverless'",
",",
"'pythonRequirements.zip'",
")",
")",
")",
";",
"}"
] |
Zip up requirements to be used as layer package.
@return {Promise} the JSZip object constructed.
|
[
"Zip",
"up",
"requirements",
"to",
"be",
"used",
"as",
"layer",
"package",
"."
] |
2e8117502606fd4bd82c19c3050ba0350adb2789
|
https://github.com/UnitedIncome/serverless-python-requirements/blob/2e8117502606fd4bd82c19c3050ba0350adb2789/lib/layer.js#L13-L21
|
10,731
|
UnitedIncome/serverless-python-requirements
|
lib/layer.js
|
createLayers
|
function createLayers() {
if (!this.serverless.service.layers) {
this.serverless.service.layers = {};
}
this.serverless.service.layers['pythonRequirements'] = Object.assign(
{
artifact: path.join('.serverless', 'pythonRequirements.zip'),
name: `${
this.serverless.service.service
}-${this.serverless.providers.aws.getStage()}-python-requirements`,
description:
'Python requirements generated by serverless-python-requirements.',
compatibleRuntimes: [this.serverless.service.provider.runtime]
},
this.options.layer
);
return BbPromise.resolve();
}
|
javascript
|
function createLayers() {
if (!this.serverless.service.layers) {
this.serverless.service.layers = {};
}
this.serverless.service.layers['pythonRequirements'] = Object.assign(
{
artifact: path.join('.serverless', 'pythonRequirements.zip'),
name: `${
this.serverless.service.service
}-${this.serverless.providers.aws.getStage()}-python-requirements`,
description:
'Python requirements generated by serverless-python-requirements.',
compatibleRuntimes: [this.serverless.service.provider.runtime]
},
this.options.layer
);
return BbPromise.resolve();
}
|
[
"function",
"createLayers",
"(",
")",
"{",
"if",
"(",
"!",
"this",
".",
"serverless",
".",
"service",
".",
"layers",
")",
"{",
"this",
".",
"serverless",
".",
"service",
".",
"layers",
"=",
"{",
"}",
";",
"}",
"this",
".",
"serverless",
".",
"service",
".",
"layers",
"[",
"'pythonRequirements'",
"]",
"=",
"Object",
".",
"assign",
"(",
"{",
"artifact",
":",
"path",
".",
"join",
"(",
"'.serverless'",
",",
"'pythonRequirements.zip'",
")",
",",
"name",
":",
"`",
"${",
"this",
".",
"serverless",
".",
"service",
".",
"service",
"}",
"${",
"this",
".",
"serverless",
".",
"providers",
".",
"aws",
".",
"getStage",
"(",
")",
"}",
"`",
",",
"description",
":",
"'Python requirements generated by serverless-python-requirements.'",
",",
"compatibleRuntimes",
":",
"[",
"this",
".",
"serverless",
".",
"service",
".",
"provider",
".",
"runtime",
"]",
"}",
",",
"this",
".",
"options",
".",
"layer",
")",
";",
"return",
"BbPromise",
".",
"resolve",
"(",
")",
";",
"}"
] |
Creates a layer on the serverless service for the requirements zip.
@return {Promise} empty promise
|
[
"Creates",
"a",
"layer",
"on",
"the",
"serverless",
"service",
"for",
"the",
"requirements",
"zip",
"."
] |
2e8117502606fd4bd82c19c3050ba0350adb2789
|
https://github.com/UnitedIncome/serverless-python-requirements/blob/2e8117502606fd4bd82c19c3050ba0350adb2789/lib/layer.js#L27-L45
|
10,732
|
UnitedIncome/serverless-python-requirements
|
lib/layer.js
|
layerRequirements
|
function layerRequirements() {
if (!this.options.layer) {
return BbPromise.resolve();
}
this.serverless.cli.log('Packaging Python Requirements Lambda Layer...');
return BbPromise.bind(this)
.then(zipRequirements)
.then(createLayers);
}
|
javascript
|
function layerRequirements() {
if (!this.options.layer) {
return BbPromise.resolve();
}
this.serverless.cli.log('Packaging Python Requirements Lambda Layer...');
return BbPromise.bind(this)
.then(zipRequirements)
.then(createLayers);
}
|
[
"function",
"layerRequirements",
"(",
")",
"{",
"if",
"(",
"!",
"this",
".",
"options",
".",
"layer",
")",
"{",
"return",
"BbPromise",
".",
"resolve",
"(",
")",
";",
"}",
"this",
".",
"serverless",
".",
"cli",
".",
"log",
"(",
"'Packaging Python Requirements Lambda Layer...'",
")",
";",
"return",
"BbPromise",
".",
"bind",
"(",
"this",
")",
".",
"then",
"(",
"zipRequirements",
")",
".",
"then",
"(",
"createLayers",
")",
";",
"}"
] |
Creates a layer from the installed requirements.
@return {Promise} the combined promise for requirements layer.
|
[
"Creates",
"a",
"layer",
"from",
"the",
"installed",
"requirements",
"."
] |
2e8117502606fd4bd82c19c3050ba0350adb2789
|
https://github.com/UnitedIncome/serverless-python-requirements/blob/2e8117502606fd4bd82c19c3050ba0350adb2789/lib/layer.js#L51-L61
|
10,733
|
UnitedIncome/serverless-python-requirements
|
lib/zip.js
|
addVendorHelper
|
function addVendorHelper() {
if (this.options.zip) {
if (this.serverless.service.package.individually) {
return BbPromise.resolve(this.targetFuncs)
.map(f => {
if (!get(f, 'package.include')) {
set(f, ['package', 'include'], []);
}
if (!get(f, 'module')) {
set(f, ['module'], '.');
}
f.package.include.push('unzip_requirements.py');
return f;
})
.then(functions => uniqBy(functions, func => func.module))
.map(f => {
this.serverless.cli.log(
`Adding Python requirements helper to ${f.module}...`
);
return fse.copyAsync(
path.resolve(__dirname, '../unzip_requirements.py'),
path.join(this.servicePath, f.module, 'unzip_requirements.py')
);
});
} else {
this.serverless.cli.log('Adding Python requirements helper...');
if (!get(this.serverless.service, 'package.include')) {
set(this.serverless.service, ['package', 'include'], []);
}
this.serverless.service.package.include.push('unzip_requirements.py');
return fse.copyAsync(
path.resolve(__dirname, '../unzip_requirements.py'),
path.join(this.servicePath, 'unzip_requirements.py')
);
}
}
}
|
javascript
|
function addVendorHelper() {
if (this.options.zip) {
if (this.serverless.service.package.individually) {
return BbPromise.resolve(this.targetFuncs)
.map(f => {
if (!get(f, 'package.include')) {
set(f, ['package', 'include'], []);
}
if (!get(f, 'module')) {
set(f, ['module'], '.');
}
f.package.include.push('unzip_requirements.py');
return f;
})
.then(functions => uniqBy(functions, func => func.module))
.map(f => {
this.serverless.cli.log(
`Adding Python requirements helper to ${f.module}...`
);
return fse.copyAsync(
path.resolve(__dirname, '../unzip_requirements.py'),
path.join(this.servicePath, f.module, 'unzip_requirements.py')
);
});
} else {
this.serverless.cli.log('Adding Python requirements helper...');
if (!get(this.serverless.service, 'package.include')) {
set(this.serverless.service, ['package', 'include'], []);
}
this.serverless.service.package.include.push('unzip_requirements.py');
return fse.copyAsync(
path.resolve(__dirname, '../unzip_requirements.py'),
path.join(this.servicePath, 'unzip_requirements.py')
);
}
}
}
|
[
"function",
"addVendorHelper",
"(",
")",
"{",
"if",
"(",
"this",
".",
"options",
".",
"zip",
")",
"{",
"if",
"(",
"this",
".",
"serverless",
".",
"service",
".",
"package",
".",
"individually",
")",
"{",
"return",
"BbPromise",
".",
"resolve",
"(",
"this",
".",
"targetFuncs",
")",
".",
"map",
"(",
"f",
"=>",
"{",
"if",
"(",
"!",
"get",
"(",
"f",
",",
"'package.include'",
")",
")",
"{",
"set",
"(",
"f",
",",
"[",
"'package'",
",",
"'include'",
"]",
",",
"[",
"]",
")",
";",
"}",
"if",
"(",
"!",
"get",
"(",
"f",
",",
"'module'",
")",
")",
"{",
"set",
"(",
"f",
",",
"[",
"'module'",
"]",
",",
"'.'",
")",
";",
"}",
"f",
".",
"package",
".",
"include",
".",
"push",
"(",
"'unzip_requirements.py'",
")",
";",
"return",
"f",
";",
"}",
")",
".",
"then",
"(",
"functions",
"=>",
"uniqBy",
"(",
"functions",
",",
"func",
"=>",
"func",
".",
"module",
")",
")",
".",
"map",
"(",
"f",
"=>",
"{",
"this",
".",
"serverless",
".",
"cli",
".",
"log",
"(",
"`",
"${",
"f",
".",
"module",
"}",
"`",
")",
";",
"return",
"fse",
".",
"copyAsync",
"(",
"path",
".",
"resolve",
"(",
"__dirname",
",",
"'../unzip_requirements.py'",
")",
",",
"path",
".",
"join",
"(",
"this",
".",
"servicePath",
",",
"f",
".",
"module",
",",
"'unzip_requirements.py'",
")",
")",
";",
"}",
")",
";",
"}",
"else",
"{",
"this",
".",
"serverless",
".",
"cli",
".",
"log",
"(",
"'Adding Python requirements helper...'",
")",
";",
"if",
"(",
"!",
"get",
"(",
"this",
".",
"serverless",
".",
"service",
",",
"'package.include'",
")",
")",
"{",
"set",
"(",
"this",
".",
"serverless",
".",
"service",
",",
"[",
"'package'",
",",
"'include'",
"]",
",",
"[",
"]",
")",
";",
"}",
"this",
".",
"serverless",
".",
"service",
".",
"package",
".",
"include",
".",
"push",
"(",
"'unzip_requirements.py'",
")",
";",
"return",
"fse",
".",
"copyAsync",
"(",
"path",
".",
"resolve",
"(",
"__dirname",
",",
"'../unzip_requirements.py'",
")",
",",
"path",
".",
"join",
"(",
"this",
".",
"servicePath",
",",
"'unzip_requirements.py'",
")",
")",
";",
"}",
"}",
"}"
] |
Add the vendor helper to the current service tree.
@return {Promise}
|
[
"Add",
"the",
"vendor",
"helper",
"to",
"the",
"current",
"service",
"tree",
"."
] |
2e8117502606fd4bd82c19c3050ba0350adb2789
|
https://github.com/UnitedIncome/serverless-python-requirements/blob/2e8117502606fd4bd82c19c3050ba0350adb2789/lib/zip.js#L16-L56
|
10,734
|
UnitedIncome/serverless-python-requirements
|
lib/zip.js
|
removeVendorHelper
|
function removeVendorHelper() {
if (this.options.zip && this.options.cleanupZipHelper) {
if (this.serverless.service.package.individually) {
return BbPromise.resolve(this.targetFuncs)
.map(f => {
if (!get(f, 'module')) {
set(f, ['module'], '.');
}
return f;
})
.then(funcs => uniqBy(funcs, f => f.module))
.map(f => {
this.serverless.cli.log(
`Removing Python requirements helper from ${f.module}...`
);
return fse.removeAsync(
path.join(this.servicePath, f.module, 'unzip_requirements.py')
);
});
} else {
this.serverless.cli.log('Removing Python requirements helper...');
return fse.removeAsync(
path.join(this.servicePath, 'unzip_requirements.py')
);
}
}
}
|
javascript
|
function removeVendorHelper() {
if (this.options.zip && this.options.cleanupZipHelper) {
if (this.serverless.service.package.individually) {
return BbPromise.resolve(this.targetFuncs)
.map(f => {
if (!get(f, 'module')) {
set(f, ['module'], '.');
}
return f;
})
.then(funcs => uniqBy(funcs, f => f.module))
.map(f => {
this.serverless.cli.log(
`Removing Python requirements helper from ${f.module}...`
);
return fse.removeAsync(
path.join(this.servicePath, f.module, 'unzip_requirements.py')
);
});
} else {
this.serverless.cli.log('Removing Python requirements helper...');
return fse.removeAsync(
path.join(this.servicePath, 'unzip_requirements.py')
);
}
}
}
|
[
"function",
"removeVendorHelper",
"(",
")",
"{",
"if",
"(",
"this",
".",
"options",
".",
"zip",
"&&",
"this",
".",
"options",
".",
"cleanupZipHelper",
")",
"{",
"if",
"(",
"this",
".",
"serverless",
".",
"service",
".",
"package",
".",
"individually",
")",
"{",
"return",
"BbPromise",
".",
"resolve",
"(",
"this",
".",
"targetFuncs",
")",
".",
"map",
"(",
"f",
"=>",
"{",
"if",
"(",
"!",
"get",
"(",
"f",
",",
"'module'",
")",
")",
"{",
"set",
"(",
"f",
",",
"[",
"'module'",
"]",
",",
"'.'",
")",
";",
"}",
"return",
"f",
";",
"}",
")",
".",
"then",
"(",
"funcs",
"=>",
"uniqBy",
"(",
"funcs",
",",
"f",
"=>",
"f",
".",
"module",
")",
")",
".",
"map",
"(",
"f",
"=>",
"{",
"this",
".",
"serverless",
".",
"cli",
".",
"log",
"(",
"`",
"${",
"f",
".",
"module",
"}",
"`",
")",
";",
"return",
"fse",
".",
"removeAsync",
"(",
"path",
".",
"join",
"(",
"this",
".",
"servicePath",
",",
"f",
".",
"module",
",",
"'unzip_requirements.py'",
")",
")",
";",
"}",
")",
";",
"}",
"else",
"{",
"this",
".",
"serverless",
".",
"cli",
".",
"log",
"(",
"'Removing Python requirements helper...'",
")",
";",
"return",
"fse",
".",
"removeAsync",
"(",
"path",
".",
"join",
"(",
"this",
".",
"servicePath",
",",
"'unzip_requirements.py'",
")",
")",
";",
"}",
"}",
"}"
] |
Remove the vendor helper from the current service tree.
@return {Promise} the promise to remove the vendor helper.
|
[
"Remove",
"the",
"vendor",
"helper",
"from",
"the",
"current",
"service",
"tree",
"."
] |
2e8117502606fd4bd82c19c3050ba0350adb2789
|
https://github.com/UnitedIncome/serverless-python-requirements/blob/2e8117502606fd4bd82c19c3050ba0350adb2789/lib/zip.js#L62-L88
|
10,735
|
UnitedIncome/serverless-python-requirements
|
lib/zipTree.js
|
addTree
|
function addTree(zip, src) {
const srcN = path.normalize(src);
return fse
.readdirAsync(srcN)
.map(name => {
const srcPath = path.join(srcN, name);
return fse.statAsync(srcPath).then(stat => {
if (stat.isDirectory()) {
return addTree(zip.folder(name), srcPath);
} else {
const opts = { date: stat.mtime, unixPermissions: stat.mode };
return fse
.readFileAsync(srcPath)
.then(data => zip.file(name, data, opts));
}
});
})
.then(() => zip); // Original zip for chaining.
}
|
javascript
|
function addTree(zip, src) {
const srcN = path.normalize(src);
return fse
.readdirAsync(srcN)
.map(name => {
const srcPath = path.join(srcN, name);
return fse.statAsync(srcPath).then(stat => {
if (stat.isDirectory()) {
return addTree(zip.folder(name), srcPath);
} else {
const opts = { date: stat.mtime, unixPermissions: stat.mode };
return fse
.readFileAsync(srcPath)
.then(data => zip.file(name, data, opts));
}
});
})
.then(() => zip); // Original zip for chaining.
}
|
[
"function",
"addTree",
"(",
"zip",
",",
"src",
")",
"{",
"const",
"srcN",
"=",
"path",
".",
"normalize",
"(",
"src",
")",
";",
"return",
"fse",
".",
"readdirAsync",
"(",
"srcN",
")",
".",
"map",
"(",
"name",
"=>",
"{",
"const",
"srcPath",
"=",
"path",
".",
"join",
"(",
"srcN",
",",
"name",
")",
";",
"return",
"fse",
".",
"statAsync",
"(",
"srcPath",
")",
".",
"then",
"(",
"stat",
"=>",
"{",
"if",
"(",
"stat",
".",
"isDirectory",
"(",
")",
")",
"{",
"return",
"addTree",
"(",
"zip",
".",
"folder",
"(",
"name",
")",
",",
"srcPath",
")",
";",
"}",
"else",
"{",
"const",
"opts",
"=",
"{",
"date",
":",
"stat",
".",
"mtime",
",",
"unixPermissions",
":",
"stat",
".",
"mode",
"}",
";",
"return",
"fse",
".",
"readFileAsync",
"(",
"srcPath",
")",
".",
"then",
"(",
"data",
"=>",
"zip",
".",
"file",
"(",
"name",
",",
"data",
",",
"opts",
")",
")",
";",
"}",
"}",
")",
";",
"}",
")",
".",
"then",
"(",
"(",
")",
"=>",
"zip",
")",
";",
"// Original zip for chaining.",
"}"
] |
Add a directory recursively to a zip file. Files in src will be added to the top folder of zip.
@param {JSZip} zip a zip object in the folder you want to add files to.
@param {string} src the source folder.
@return {Promise} a promise offering the original JSZip object.
|
[
"Add",
"a",
"directory",
"recursively",
"to",
"a",
"zip",
"file",
".",
"Files",
"in",
"src",
"will",
"be",
"added",
"to",
"the",
"top",
"folder",
"of",
"zip",
"."
] |
2e8117502606fd4bd82c19c3050ba0350adb2789
|
https://github.com/UnitedIncome/serverless-python-requirements/blob/2e8117502606fd4bd82c19c3050ba0350adb2789/lib/zipTree.js#L13-L33
|
10,736
|
UnitedIncome/serverless-python-requirements
|
lib/zipTree.js
|
writeZip
|
function writeZip(zip, targetPath) {
const opts = {
platform: process.platform == 'win32' ? 'DOS' : 'UNIX',
compression: 'DEFLATE',
compressionOptions: {
level: 9
}
};
return new BbPromise(resolve =>
zip
.generateNodeStream(opts)
.pipe(fse.createWriteStream(targetPath))
.on('finish', resolve)
).then(() => null);
}
|
javascript
|
function writeZip(zip, targetPath) {
const opts = {
platform: process.platform == 'win32' ? 'DOS' : 'UNIX',
compression: 'DEFLATE',
compressionOptions: {
level: 9
}
};
return new BbPromise(resolve =>
zip
.generateNodeStream(opts)
.pipe(fse.createWriteStream(targetPath))
.on('finish', resolve)
).then(() => null);
}
|
[
"function",
"writeZip",
"(",
"zip",
",",
"targetPath",
")",
"{",
"const",
"opts",
"=",
"{",
"platform",
":",
"process",
".",
"platform",
"==",
"'win32'",
"?",
"'DOS'",
":",
"'UNIX'",
",",
"compression",
":",
"'DEFLATE'",
",",
"compressionOptions",
":",
"{",
"level",
":",
"9",
"}",
"}",
";",
"return",
"new",
"BbPromise",
"(",
"resolve",
"=>",
"zip",
".",
"generateNodeStream",
"(",
"opts",
")",
".",
"pipe",
"(",
"fse",
".",
"createWriteStream",
"(",
"targetPath",
")",
")",
".",
"on",
"(",
"'finish'",
",",
"resolve",
")",
")",
".",
"then",
"(",
"(",
")",
"=>",
"null",
")",
";",
"}"
] |
Write zip contents to a file.
@param {JSZip} zip the zip object
@param {string} targetPath path to write the zip file to.
@return {Promise} a promise resolving to null.
|
[
"Write",
"zip",
"contents",
"to",
"a",
"file",
"."
] |
2e8117502606fd4bd82c19c3050ba0350adb2789
|
https://github.com/UnitedIncome/serverless-python-requirements/blob/2e8117502606fd4bd82c19c3050ba0350adb2789/lib/zipTree.js#L41-L55
|
10,737
|
UnitedIncome/serverless-python-requirements
|
lib/zipTree.js
|
zipFile
|
function zipFile(zip, zipPath, bufferPromise, fileOpts) {
return bufferPromise
.then(buffer =>
zip.file(
zipPath,
buffer,
Object.assign(
{},
{
// necessary to get the same hash when zipping the same content
date: new Date(0)
},
fileOpts
)
)
)
.then(() => zip);
}
|
javascript
|
function zipFile(zip, zipPath, bufferPromise, fileOpts) {
return bufferPromise
.then(buffer =>
zip.file(
zipPath,
buffer,
Object.assign(
{},
{
// necessary to get the same hash when zipping the same content
date: new Date(0)
},
fileOpts
)
)
)
.then(() => zip);
}
|
[
"function",
"zipFile",
"(",
"zip",
",",
"zipPath",
",",
"bufferPromise",
",",
"fileOpts",
")",
"{",
"return",
"bufferPromise",
".",
"then",
"(",
"buffer",
"=>",
"zip",
".",
"file",
"(",
"zipPath",
",",
"buffer",
",",
"Object",
".",
"assign",
"(",
"{",
"}",
",",
"{",
"// necessary to get the same hash when zipping the same content",
"date",
":",
"new",
"Date",
"(",
"0",
")",
"}",
",",
"fileOpts",
")",
")",
")",
".",
"then",
"(",
"(",
")",
"=>",
"zip",
")",
";",
"}"
] |
Add a new file to a zip file from a buffer.
@param {JSZip} zip the zip object to add the file to.
@param {string} zipPath the target path in the zip.
@param {Promise} bufferPromise a promise providing a nodebuffer.
@return {Promise} a promise providing the JSZip object.
@param {object} fileOpts an object with the opts to save for the file in the zip.
|
[
"Add",
"a",
"new",
"file",
"to",
"a",
"zip",
"file",
"from",
"a",
"buffer",
"."
] |
2e8117502606fd4bd82c19c3050ba0350adb2789
|
https://github.com/UnitedIncome/serverless-python-requirements/blob/2e8117502606fd4bd82c19c3050ba0350adb2789/lib/zipTree.js#L65-L82
|
10,738
|
UnitedIncome/serverless-python-requirements
|
lib/pip.js
|
mergeCommands
|
function mergeCommands(commands) {
const cmds = filterCommands(commands);
if (cmds.length === 0) {
throw new Error('Expected at least one non-empty command');
} else if (cmds.length === 1) {
return cmds[0];
} else {
// Quote the arguments in each command and join them all using &&.
const script = cmds.map(quote).join(' && ');
return ['/bin/sh', '-c', script];
}
}
|
javascript
|
function mergeCommands(commands) {
const cmds = filterCommands(commands);
if (cmds.length === 0) {
throw new Error('Expected at least one non-empty command');
} else if (cmds.length === 1) {
return cmds[0];
} else {
// Quote the arguments in each command and join them all using &&.
const script = cmds.map(quote).join(' && ');
return ['/bin/sh', '-c', script];
}
}
|
[
"function",
"mergeCommands",
"(",
"commands",
")",
"{",
"const",
"cmds",
"=",
"filterCommands",
"(",
"commands",
")",
";",
"if",
"(",
"cmds",
".",
"length",
"===",
"0",
")",
"{",
"throw",
"new",
"Error",
"(",
"'Expected at least one non-empty command'",
")",
";",
"}",
"else",
"if",
"(",
"cmds",
".",
"length",
"===",
"1",
")",
"{",
"return",
"cmds",
"[",
"0",
"]",
";",
"}",
"else",
"{",
"// Quote the arguments in each command and join them all using &&.",
"const",
"script",
"=",
"cmds",
".",
"map",
"(",
"quote",
")",
".",
"join",
"(",
"' && '",
")",
";",
"return",
"[",
"'/bin/sh'",
",",
"'-c'",
",",
"script",
"]",
";",
"}",
"}"
] |
Render zero or more commands as a single command for a Unix environment.
In this context, a "command" is a list of arguments. An empty list or falsy value is ommitted.
@param {string[][]} many commands to merge.
@return {string[]} a single list of words.
|
[
"Render",
"zero",
"or",
"more",
"commands",
"as",
"a",
"single",
"command",
"for",
"a",
"Unix",
"environment",
".",
"In",
"this",
"context",
"a",
"command",
"is",
"a",
"list",
"of",
"arguments",
".",
"An",
"empty",
"list",
"or",
"falsy",
"value",
"is",
"ommitted",
"."
] |
2e8117502606fd4bd82c19c3050ba0350adb2789
|
https://github.com/UnitedIncome/serverless-python-requirements/blob/2e8117502606fd4bd82c19c3050ba0350adb2789/lib/pip.js#L34-L45
|
10,739
|
UnitedIncome/serverless-python-requirements
|
lib/pip.js
|
generateRequirementsFile
|
function generateRequirementsFile(
requirementsPath,
targetFile,
serverless,
servicePath,
options
) {
if (
options.usePoetry &&
fse.existsSync(path.join(servicePath, 'pyproject.toml'))
) {
filterRequirementsFile(
path.join(servicePath, '.serverless/requirements.txt'),
targetFile,
options
);
serverless.cli.log(
`Parsed requirements.txt from pyproject.toml in ${targetFile}...`
);
} else if (
options.usePipenv &&
fse.existsSync(path.join(servicePath, 'Pipfile'))
) {
filterRequirementsFile(
path.join(servicePath, '.serverless/requirements.txt'),
targetFile,
options
);
serverless.cli.log(
`Parsed requirements.txt from Pipfile in ${targetFile}...`
);
} else {
filterRequirementsFile(requirementsPath, targetFile, options);
serverless.cli.log(
`Generated requirements from ${requirementsPath} in ${targetFile}...`
);
}
}
|
javascript
|
function generateRequirementsFile(
requirementsPath,
targetFile,
serverless,
servicePath,
options
) {
if (
options.usePoetry &&
fse.existsSync(path.join(servicePath, 'pyproject.toml'))
) {
filterRequirementsFile(
path.join(servicePath, '.serverless/requirements.txt'),
targetFile,
options
);
serverless.cli.log(
`Parsed requirements.txt from pyproject.toml in ${targetFile}...`
);
} else if (
options.usePipenv &&
fse.existsSync(path.join(servicePath, 'Pipfile'))
) {
filterRequirementsFile(
path.join(servicePath, '.serverless/requirements.txt'),
targetFile,
options
);
serverless.cli.log(
`Parsed requirements.txt from Pipfile in ${targetFile}...`
);
} else {
filterRequirementsFile(requirementsPath, targetFile, options);
serverless.cli.log(
`Generated requirements from ${requirementsPath} in ${targetFile}...`
);
}
}
|
[
"function",
"generateRequirementsFile",
"(",
"requirementsPath",
",",
"targetFile",
",",
"serverless",
",",
"servicePath",
",",
"options",
")",
"{",
"if",
"(",
"options",
".",
"usePoetry",
"&&",
"fse",
".",
"existsSync",
"(",
"path",
".",
"join",
"(",
"servicePath",
",",
"'pyproject.toml'",
")",
")",
")",
"{",
"filterRequirementsFile",
"(",
"path",
".",
"join",
"(",
"servicePath",
",",
"'.serverless/requirements.txt'",
")",
",",
"targetFile",
",",
"options",
")",
";",
"serverless",
".",
"cli",
".",
"log",
"(",
"`",
"${",
"targetFile",
"}",
"`",
")",
";",
"}",
"else",
"if",
"(",
"options",
".",
"usePipenv",
"&&",
"fse",
".",
"existsSync",
"(",
"path",
".",
"join",
"(",
"servicePath",
",",
"'Pipfile'",
")",
")",
")",
"{",
"filterRequirementsFile",
"(",
"path",
".",
"join",
"(",
"servicePath",
",",
"'.serverless/requirements.txt'",
")",
",",
"targetFile",
",",
"options",
")",
";",
"serverless",
".",
"cli",
".",
"log",
"(",
"`",
"${",
"targetFile",
"}",
"`",
")",
";",
"}",
"else",
"{",
"filterRequirementsFile",
"(",
"requirementsPath",
",",
"targetFile",
",",
"options",
")",
";",
"serverless",
".",
"cli",
".",
"log",
"(",
"`",
"${",
"requirementsPath",
"}",
"${",
"targetFile",
"}",
"`",
")",
";",
"}",
"}"
] |
Just generate the requirements file in the .serverless folder
@param {string} requirementsPath
@param {string} targetFile
@param {Object} serverless
@param {string} servicePath
@param {Object} options
@return {undefined}
|
[
"Just",
"generate",
"the",
"requirements",
"file",
"in",
"the",
".",
"serverless",
"folder"
] |
2e8117502606fd4bd82c19c3050ba0350adb2789
|
https://github.com/UnitedIncome/serverless-python-requirements/blob/2e8117502606fd4bd82c19c3050ba0350adb2789/lib/pip.js#L56-L93
|
10,740
|
UnitedIncome/serverless-python-requirements
|
lib/pip.js
|
copyVendors
|
function copyVendors(vendorFolder, targetFolder, serverless) {
// Create target folder if it does not exist
fse.ensureDirSync(targetFolder);
serverless.cli.log(
`Copying vendor libraries from ${vendorFolder} to ${targetFolder}...`
);
fse.readdirSync(vendorFolder).map(file => {
let source = path.join(vendorFolder, file);
let dest = path.join(targetFolder, file);
if (fse.existsSync(dest)) {
rimraf.sync(dest);
}
fse.copySync(source, dest);
});
}
|
javascript
|
function copyVendors(vendorFolder, targetFolder, serverless) {
// Create target folder if it does not exist
fse.ensureDirSync(targetFolder);
serverless.cli.log(
`Copying vendor libraries from ${vendorFolder} to ${targetFolder}...`
);
fse.readdirSync(vendorFolder).map(file => {
let source = path.join(vendorFolder, file);
let dest = path.join(targetFolder, file);
if (fse.existsSync(dest)) {
rimraf.sync(dest);
}
fse.copySync(source, dest);
});
}
|
[
"function",
"copyVendors",
"(",
"vendorFolder",
",",
"targetFolder",
",",
"serverless",
")",
"{",
"// Create target folder if it does not exist",
"fse",
".",
"ensureDirSync",
"(",
"targetFolder",
")",
";",
"serverless",
".",
"cli",
".",
"log",
"(",
"`",
"${",
"vendorFolder",
"}",
"${",
"targetFolder",
"}",
"`",
")",
";",
"fse",
".",
"readdirSync",
"(",
"vendorFolder",
")",
".",
"map",
"(",
"file",
"=>",
"{",
"let",
"source",
"=",
"path",
".",
"join",
"(",
"vendorFolder",
",",
"file",
")",
";",
"let",
"dest",
"=",
"path",
".",
"join",
"(",
"targetFolder",
",",
"file",
")",
";",
"if",
"(",
"fse",
".",
"existsSync",
"(",
"dest",
")",
")",
"{",
"rimraf",
".",
"sync",
"(",
"dest",
")",
";",
"}",
"fse",
".",
"copySync",
"(",
"source",
",",
"dest",
")",
";",
"}",
")",
";",
"}"
] |
Copy everything from vendorFolder to targetFolder
@param {string} vendorFolder
@param {string} targetFolder
@param {Object} serverless
@return {undefined}
|
[
"Copy",
"everything",
"from",
"vendorFolder",
"to",
"targetFolder"
] |
2e8117502606fd4bd82c19c3050ba0350adb2789
|
https://github.com/UnitedIncome/serverless-python-requirements/blob/2e8117502606fd4bd82c19c3050ba0350adb2789/lib/pip.js#L377-L393
|
10,741
|
UnitedIncome/serverless-python-requirements
|
lib/pip.js
|
requirementsFileExists
|
function requirementsFileExists(servicePath, options, fileName) {
if (
options.usePoetry &&
fse.existsSync(path.join(servicePath, 'pyproject.toml'))
) {
return true;
}
if (options.usePipenv && fse.existsSync(path.join(servicePath, 'Pipfile'))) {
return true;
}
if (fse.existsSync(fileName)) {
return true;
}
return false;
}
|
javascript
|
function requirementsFileExists(servicePath, options, fileName) {
if (
options.usePoetry &&
fse.existsSync(path.join(servicePath, 'pyproject.toml'))
) {
return true;
}
if (options.usePipenv && fse.existsSync(path.join(servicePath, 'Pipfile'))) {
return true;
}
if (fse.existsSync(fileName)) {
return true;
}
return false;
}
|
[
"function",
"requirementsFileExists",
"(",
"servicePath",
",",
"options",
",",
"fileName",
")",
"{",
"if",
"(",
"options",
".",
"usePoetry",
"&&",
"fse",
".",
"existsSync",
"(",
"path",
".",
"join",
"(",
"servicePath",
",",
"'pyproject.toml'",
")",
")",
")",
"{",
"return",
"true",
";",
"}",
"if",
"(",
"options",
".",
"usePipenv",
"&&",
"fse",
".",
"existsSync",
"(",
"path",
".",
"join",
"(",
"servicePath",
",",
"'Pipfile'",
")",
")",
")",
"{",
"return",
"true",
";",
"}",
"if",
"(",
"fse",
".",
"existsSync",
"(",
"fileName",
")",
")",
"{",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
] |
This checks if requirements file exists.
@param {string} servicePath
@param {Object} options
@param {string} fileName
|
[
"This",
"checks",
"if",
"requirements",
"file",
"exists",
"."
] |
2e8117502606fd4bd82c19c3050ba0350adb2789
|
https://github.com/UnitedIncome/serverless-python-requirements/blob/2e8117502606fd4bd82c19c3050ba0350adb2789/lib/pip.js#L401-L418
|
10,742
|
UnitedIncome/serverless-python-requirements
|
lib/pip.js
|
installRequirementsIfNeeded
|
function installRequirementsIfNeeded(
servicePath,
modulePath,
options,
funcOptions,
serverless
) {
// Our source requirements, under our service path, and our module path (if specified)
const fileName = path.join(servicePath, modulePath, options.fileName);
// Skip requirements generation, if requirements file doesn't exist
if (!requirementsFileExists(servicePath, options, fileName)) {
return false;
}
let requirementsTxtDirectory;
// Copy our requirements to another path in .serverless (incase of individually packaged)
if (modulePath && modulePath !== '.') {
requirementsTxtDirectory = path.join(
servicePath,
'.serverless',
modulePath
);
} else {
requirementsTxtDirectory = path.join(servicePath, '.serverless');
}
fse.ensureDirSync(requirementsTxtDirectory);
const slsReqsTxt = path.join(requirementsTxtDirectory, 'requirements.txt');
generateRequirementsFile(
fileName,
slsReqsTxt,
serverless,
servicePath,
options
);
// If no requirements file or an empty requirements file, then do nothing
if (!fse.existsSync(slsReqsTxt) || fse.statSync(slsReqsTxt).size == 0) {
serverless.cli.log(
`Skipping empty output requirements.txt file from ${slsReqsTxt}`
);
return false;
}
// Then generate our MD5 Sum of this requirements file to determine where it should "go" to and/or pull cache from
const reqChecksum = sha256Path(slsReqsTxt);
// Then figure out where this cache should be, if we're caching, if we're in a module, etc
const workingReqsFolder = getRequirementsWorkingPath(
reqChecksum,
requirementsTxtDirectory,
options
);
// Check if our static cache is present and is valid
if (fse.existsSync(workingReqsFolder)) {
if (
fse.existsSync(path.join(workingReqsFolder, '.completed_requirements')) &&
workingReqsFolder.endsWith('_slspyc')
) {
serverless.cli.log(
`Using static cache of requirements found at ${workingReqsFolder} ...`
);
// We'll "touch" the folder, as to bring it to the start of the FIFO cache
fse.utimesSync(workingReqsFolder, new Date(), new Date());
return workingReqsFolder;
}
// Remove our old folder if it didn't complete properly, but _just incase_ only remove it if named properly...
if (
workingReqsFolder.endsWith('_slspyc') ||
workingReqsFolder.endsWith('.requirements')
) {
rimraf.sync(workingReqsFolder);
}
}
// Ensuring the working reqs folder exists
fse.ensureDirSync(workingReqsFolder);
// Copy our requirements.txt into our working folder...
fse.copySync(slsReqsTxt, path.join(workingReqsFolder, 'requirements.txt'));
// Then install our requirements from this folder
installRequirements(workingReqsFolder, serverless, options);
// Copy vendor libraries to requirements folder
if (options.vendor) {
copyVendors(options.vendor, workingReqsFolder, serverless);
}
if (funcOptions.vendor) {
copyVendors(funcOptions.vendor, workingReqsFolder, serverless);
}
// Then touch our ".completed_requirements" file so we know we can use this for static cache
if (options.useStaticCache) {
fse.closeSync(
fse.openSync(path.join(workingReqsFolder, '.completed_requirements'), 'w')
);
}
return workingReqsFolder;
}
|
javascript
|
function installRequirementsIfNeeded(
servicePath,
modulePath,
options,
funcOptions,
serverless
) {
// Our source requirements, under our service path, and our module path (if specified)
const fileName = path.join(servicePath, modulePath, options.fileName);
// Skip requirements generation, if requirements file doesn't exist
if (!requirementsFileExists(servicePath, options, fileName)) {
return false;
}
let requirementsTxtDirectory;
// Copy our requirements to another path in .serverless (incase of individually packaged)
if (modulePath && modulePath !== '.') {
requirementsTxtDirectory = path.join(
servicePath,
'.serverless',
modulePath
);
} else {
requirementsTxtDirectory = path.join(servicePath, '.serverless');
}
fse.ensureDirSync(requirementsTxtDirectory);
const slsReqsTxt = path.join(requirementsTxtDirectory, 'requirements.txt');
generateRequirementsFile(
fileName,
slsReqsTxt,
serverless,
servicePath,
options
);
// If no requirements file or an empty requirements file, then do nothing
if (!fse.existsSync(slsReqsTxt) || fse.statSync(slsReqsTxt).size == 0) {
serverless.cli.log(
`Skipping empty output requirements.txt file from ${slsReqsTxt}`
);
return false;
}
// Then generate our MD5 Sum of this requirements file to determine where it should "go" to and/or pull cache from
const reqChecksum = sha256Path(slsReqsTxt);
// Then figure out where this cache should be, if we're caching, if we're in a module, etc
const workingReqsFolder = getRequirementsWorkingPath(
reqChecksum,
requirementsTxtDirectory,
options
);
// Check if our static cache is present and is valid
if (fse.existsSync(workingReqsFolder)) {
if (
fse.existsSync(path.join(workingReqsFolder, '.completed_requirements')) &&
workingReqsFolder.endsWith('_slspyc')
) {
serverless.cli.log(
`Using static cache of requirements found at ${workingReqsFolder} ...`
);
// We'll "touch" the folder, as to bring it to the start of the FIFO cache
fse.utimesSync(workingReqsFolder, new Date(), new Date());
return workingReqsFolder;
}
// Remove our old folder if it didn't complete properly, but _just incase_ only remove it if named properly...
if (
workingReqsFolder.endsWith('_slspyc') ||
workingReqsFolder.endsWith('.requirements')
) {
rimraf.sync(workingReqsFolder);
}
}
// Ensuring the working reqs folder exists
fse.ensureDirSync(workingReqsFolder);
// Copy our requirements.txt into our working folder...
fse.copySync(slsReqsTxt, path.join(workingReqsFolder, 'requirements.txt'));
// Then install our requirements from this folder
installRequirements(workingReqsFolder, serverless, options);
// Copy vendor libraries to requirements folder
if (options.vendor) {
copyVendors(options.vendor, workingReqsFolder, serverless);
}
if (funcOptions.vendor) {
copyVendors(funcOptions.vendor, workingReqsFolder, serverless);
}
// Then touch our ".completed_requirements" file so we know we can use this for static cache
if (options.useStaticCache) {
fse.closeSync(
fse.openSync(path.join(workingReqsFolder, '.completed_requirements'), 'w')
);
}
return workingReqsFolder;
}
|
[
"function",
"installRequirementsIfNeeded",
"(",
"servicePath",
",",
"modulePath",
",",
"options",
",",
"funcOptions",
",",
"serverless",
")",
"{",
"// Our source requirements, under our service path, and our module path (if specified)",
"const",
"fileName",
"=",
"path",
".",
"join",
"(",
"servicePath",
",",
"modulePath",
",",
"options",
".",
"fileName",
")",
";",
"// Skip requirements generation, if requirements file doesn't exist",
"if",
"(",
"!",
"requirementsFileExists",
"(",
"servicePath",
",",
"options",
",",
"fileName",
")",
")",
"{",
"return",
"false",
";",
"}",
"let",
"requirementsTxtDirectory",
";",
"// Copy our requirements to another path in .serverless (incase of individually packaged)",
"if",
"(",
"modulePath",
"&&",
"modulePath",
"!==",
"'.'",
")",
"{",
"requirementsTxtDirectory",
"=",
"path",
".",
"join",
"(",
"servicePath",
",",
"'.serverless'",
",",
"modulePath",
")",
";",
"}",
"else",
"{",
"requirementsTxtDirectory",
"=",
"path",
".",
"join",
"(",
"servicePath",
",",
"'.serverless'",
")",
";",
"}",
"fse",
".",
"ensureDirSync",
"(",
"requirementsTxtDirectory",
")",
";",
"const",
"slsReqsTxt",
"=",
"path",
".",
"join",
"(",
"requirementsTxtDirectory",
",",
"'requirements.txt'",
")",
";",
"generateRequirementsFile",
"(",
"fileName",
",",
"slsReqsTxt",
",",
"serverless",
",",
"servicePath",
",",
"options",
")",
";",
"// If no requirements file or an empty requirements file, then do nothing",
"if",
"(",
"!",
"fse",
".",
"existsSync",
"(",
"slsReqsTxt",
")",
"||",
"fse",
".",
"statSync",
"(",
"slsReqsTxt",
")",
".",
"size",
"==",
"0",
")",
"{",
"serverless",
".",
"cli",
".",
"log",
"(",
"`",
"${",
"slsReqsTxt",
"}",
"`",
")",
";",
"return",
"false",
";",
"}",
"// Then generate our MD5 Sum of this requirements file to determine where it should \"go\" to and/or pull cache from",
"const",
"reqChecksum",
"=",
"sha256Path",
"(",
"slsReqsTxt",
")",
";",
"// Then figure out where this cache should be, if we're caching, if we're in a module, etc",
"const",
"workingReqsFolder",
"=",
"getRequirementsWorkingPath",
"(",
"reqChecksum",
",",
"requirementsTxtDirectory",
",",
"options",
")",
";",
"// Check if our static cache is present and is valid",
"if",
"(",
"fse",
".",
"existsSync",
"(",
"workingReqsFolder",
")",
")",
"{",
"if",
"(",
"fse",
".",
"existsSync",
"(",
"path",
".",
"join",
"(",
"workingReqsFolder",
",",
"'.completed_requirements'",
")",
")",
"&&",
"workingReqsFolder",
".",
"endsWith",
"(",
"'_slspyc'",
")",
")",
"{",
"serverless",
".",
"cli",
".",
"log",
"(",
"`",
"${",
"workingReqsFolder",
"}",
"`",
")",
";",
"// We'll \"touch\" the folder, as to bring it to the start of the FIFO cache",
"fse",
".",
"utimesSync",
"(",
"workingReqsFolder",
",",
"new",
"Date",
"(",
")",
",",
"new",
"Date",
"(",
")",
")",
";",
"return",
"workingReqsFolder",
";",
"}",
"// Remove our old folder if it didn't complete properly, but _just incase_ only remove it if named properly...",
"if",
"(",
"workingReqsFolder",
".",
"endsWith",
"(",
"'_slspyc'",
")",
"||",
"workingReqsFolder",
".",
"endsWith",
"(",
"'.requirements'",
")",
")",
"{",
"rimraf",
".",
"sync",
"(",
"workingReqsFolder",
")",
";",
"}",
"}",
"// Ensuring the working reqs folder exists",
"fse",
".",
"ensureDirSync",
"(",
"workingReqsFolder",
")",
";",
"// Copy our requirements.txt into our working folder...",
"fse",
".",
"copySync",
"(",
"slsReqsTxt",
",",
"path",
".",
"join",
"(",
"workingReqsFolder",
",",
"'requirements.txt'",
")",
")",
";",
"// Then install our requirements from this folder",
"installRequirements",
"(",
"workingReqsFolder",
",",
"serverless",
",",
"options",
")",
";",
"// Copy vendor libraries to requirements folder",
"if",
"(",
"options",
".",
"vendor",
")",
"{",
"copyVendors",
"(",
"options",
".",
"vendor",
",",
"workingReqsFolder",
",",
"serverless",
")",
";",
"}",
"if",
"(",
"funcOptions",
".",
"vendor",
")",
"{",
"copyVendors",
"(",
"funcOptions",
".",
"vendor",
",",
"workingReqsFolder",
",",
"serverless",
")",
";",
"}",
"// Then touch our \".completed_requirements\" file so we know we can use this for static cache",
"if",
"(",
"options",
".",
"useStaticCache",
")",
"{",
"fse",
".",
"closeSync",
"(",
"fse",
".",
"openSync",
"(",
"path",
".",
"join",
"(",
"workingReqsFolder",
",",
"'.completed_requirements'",
")",
",",
"'w'",
")",
")",
";",
"}",
"return",
"workingReqsFolder",
";",
"}"
] |
This evaluates if requirements are actually needed to be installed, but fails
gracefully if no req file is found intentionally. It also assists with code
re-use for this logic pertaining to individually packaged functions
@param {string} servicePath
@param {string} modulePath
@param {Object} options
@param {Object} funcOptions
@param {Object} serverless
@return {string}
|
[
"This",
"evaluates",
"if",
"requirements",
"are",
"actually",
"needed",
"to",
"be",
"installed",
"but",
"fails",
"gracefully",
"if",
"no",
"req",
"file",
"is",
"found",
"intentionally",
".",
"It",
"also",
"assists",
"with",
"code",
"re",
"-",
"use",
"for",
"this",
"logic",
"pertaining",
"to",
"individually",
"packaged",
"functions"
] |
2e8117502606fd4bd82c19c3050ba0350adb2789
|
https://github.com/UnitedIncome/serverless-python-requirements/blob/2e8117502606fd4bd82c19c3050ba0350adb2789/lib/pip.js#L431-L532
|
10,743
|
UnitedIncome/serverless-python-requirements
|
lib/pip.js
|
installAllRequirements
|
function installAllRequirements() {
// fse.ensureDirSync(path.join(this.servicePath, '.serverless'));
// First, check and delete cache versions, if enabled
checkForAndDeleteMaxCacheVersions(this.options, this.serverless);
// Then if we're going to package functions individually...
if (this.serverless.service.package.individually) {
let doneModules = [];
this.targetFuncs
.filter(func =>
(func.runtime || this.serverless.service.provider.runtime).match(
/^python.*/
)
)
.map(f => {
if (!get(f, 'module')) {
set(f, ['module'], '.');
}
// If we didn't already process a module (functions can re-use modules)
if (!doneModules.includes(f.module)) {
const reqsInstalledAt = installRequirementsIfNeeded(
this.servicePath,
f.module,
this.options,
f,
this.serverless
);
// Add modulePath into .serverless for each module so it's easier for injecting and for users to see where reqs are
let modulePath = path.join(
this.servicePath,
'.serverless',
`${f.module}`,
'requirements'
);
// Only do if we didn't already do it
if (
reqsInstalledAt &&
!fse.existsSync(modulePath) &&
reqsInstalledAt != modulePath
) {
if (this.options.useStaticCache) {
// Windows can't symlink so we have to copy on Windows,
// it's not as fast, but at least it works
if (process.platform == 'win32') {
fse.copySync(reqsInstalledAt, modulePath);
} else {
fse.symlink(reqsInstalledAt, modulePath);
}
} else {
fse.rename(reqsInstalledAt, modulePath);
}
}
doneModules.push(f.module);
}
});
} else {
const reqsInstalledAt = installRequirementsIfNeeded(
this.servicePath,
'',
this.options,
{},
this.serverless
);
// Add symlinks into .serverless for so it's easier for injecting and for users to see where reqs are
let symlinkPath = path.join(
this.servicePath,
'.serverless',
`requirements`
);
// Only do if we didn't already do it
if (
reqsInstalledAt &&
!fse.existsSync(symlinkPath) &&
reqsInstalledAt != symlinkPath
) {
// Windows can't symlink so we have to use junction on Windows
if (process.platform == 'win32') {
fse.symlink(reqsInstalledAt, symlinkPath, 'junction');
} else {
fse.symlink(reqsInstalledAt, symlinkPath);
}
}
}
}
|
javascript
|
function installAllRequirements() {
// fse.ensureDirSync(path.join(this.servicePath, '.serverless'));
// First, check and delete cache versions, if enabled
checkForAndDeleteMaxCacheVersions(this.options, this.serverless);
// Then if we're going to package functions individually...
if (this.serverless.service.package.individually) {
let doneModules = [];
this.targetFuncs
.filter(func =>
(func.runtime || this.serverless.service.provider.runtime).match(
/^python.*/
)
)
.map(f => {
if (!get(f, 'module')) {
set(f, ['module'], '.');
}
// If we didn't already process a module (functions can re-use modules)
if (!doneModules.includes(f.module)) {
const reqsInstalledAt = installRequirementsIfNeeded(
this.servicePath,
f.module,
this.options,
f,
this.serverless
);
// Add modulePath into .serverless for each module so it's easier for injecting and for users to see where reqs are
let modulePath = path.join(
this.servicePath,
'.serverless',
`${f.module}`,
'requirements'
);
// Only do if we didn't already do it
if (
reqsInstalledAt &&
!fse.existsSync(modulePath) &&
reqsInstalledAt != modulePath
) {
if (this.options.useStaticCache) {
// Windows can't symlink so we have to copy on Windows,
// it's not as fast, but at least it works
if (process.platform == 'win32') {
fse.copySync(reqsInstalledAt, modulePath);
} else {
fse.symlink(reqsInstalledAt, modulePath);
}
} else {
fse.rename(reqsInstalledAt, modulePath);
}
}
doneModules.push(f.module);
}
});
} else {
const reqsInstalledAt = installRequirementsIfNeeded(
this.servicePath,
'',
this.options,
{},
this.serverless
);
// Add symlinks into .serverless for so it's easier for injecting and for users to see where reqs are
let symlinkPath = path.join(
this.servicePath,
'.serverless',
`requirements`
);
// Only do if we didn't already do it
if (
reqsInstalledAt &&
!fse.existsSync(symlinkPath) &&
reqsInstalledAt != symlinkPath
) {
// Windows can't symlink so we have to use junction on Windows
if (process.platform == 'win32') {
fse.symlink(reqsInstalledAt, symlinkPath, 'junction');
} else {
fse.symlink(reqsInstalledAt, symlinkPath);
}
}
}
}
|
[
"function",
"installAllRequirements",
"(",
")",
"{",
"// fse.ensureDirSync(path.join(this.servicePath, '.serverless'));",
"// First, check and delete cache versions, if enabled",
"checkForAndDeleteMaxCacheVersions",
"(",
"this",
".",
"options",
",",
"this",
".",
"serverless",
")",
";",
"// Then if we're going to package functions individually...",
"if",
"(",
"this",
".",
"serverless",
".",
"service",
".",
"package",
".",
"individually",
")",
"{",
"let",
"doneModules",
"=",
"[",
"]",
";",
"this",
".",
"targetFuncs",
".",
"filter",
"(",
"func",
"=>",
"(",
"func",
".",
"runtime",
"||",
"this",
".",
"serverless",
".",
"service",
".",
"provider",
".",
"runtime",
")",
".",
"match",
"(",
"/",
"^python.*",
"/",
")",
")",
".",
"map",
"(",
"f",
"=>",
"{",
"if",
"(",
"!",
"get",
"(",
"f",
",",
"'module'",
")",
")",
"{",
"set",
"(",
"f",
",",
"[",
"'module'",
"]",
",",
"'.'",
")",
";",
"}",
"// If we didn't already process a module (functions can re-use modules)",
"if",
"(",
"!",
"doneModules",
".",
"includes",
"(",
"f",
".",
"module",
")",
")",
"{",
"const",
"reqsInstalledAt",
"=",
"installRequirementsIfNeeded",
"(",
"this",
".",
"servicePath",
",",
"f",
".",
"module",
",",
"this",
".",
"options",
",",
"f",
",",
"this",
".",
"serverless",
")",
";",
"// Add modulePath into .serverless for each module so it's easier for injecting and for users to see where reqs are",
"let",
"modulePath",
"=",
"path",
".",
"join",
"(",
"this",
".",
"servicePath",
",",
"'.serverless'",
",",
"`",
"${",
"f",
".",
"module",
"}",
"`",
",",
"'requirements'",
")",
";",
"// Only do if we didn't already do it",
"if",
"(",
"reqsInstalledAt",
"&&",
"!",
"fse",
".",
"existsSync",
"(",
"modulePath",
")",
"&&",
"reqsInstalledAt",
"!=",
"modulePath",
")",
"{",
"if",
"(",
"this",
".",
"options",
".",
"useStaticCache",
")",
"{",
"// Windows can't symlink so we have to copy on Windows,",
"// it's not as fast, but at least it works",
"if",
"(",
"process",
".",
"platform",
"==",
"'win32'",
")",
"{",
"fse",
".",
"copySync",
"(",
"reqsInstalledAt",
",",
"modulePath",
")",
";",
"}",
"else",
"{",
"fse",
".",
"symlink",
"(",
"reqsInstalledAt",
",",
"modulePath",
")",
";",
"}",
"}",
"else",
"{",
"fse",
".",
"rename",
"(",
"reqsInstalledAt",
",",
"modulePath",
")",
";",
"}",
"}",
"doneModules",
".",
"push",
"(",
"f",
".",
"module",
")",
";",
"}",
"}",
")",
";",
"}",
"else",
"{",
"const",
"reqsInstalledAt",
"=",
"installRequirementsIfNeeded",
"(",
"this",
".",
"servicePath",
",",
"''",
",",
"this",
".",
"options",
",",
"{",
"}",
",",
"this",
".",
"serverless",
")",
";",
"// Add symlinks into .serverless for so it's easier for injecting and for users to see where reqs are",
"let",
"symlinkPath",
"=",
"path",
".",
"join",
"(",
"this",
".",
"servicePath",
",",
"'.serverless'",
",",
"`",
"`",
")",
";",
"// Only do if we didn't already do it",
"if",
"(",
"reqsInstalledAt",
"&&",
"!",
"fse",
".",
"existsSync",
"(",
"symlinkPath",
")",
"&&",
"reqsInstalledAt",
"!=",
"symlinkPath",
")",
"{",
"// Windows can't symlink so we have to use junction on Windows",
"if",
"(",
"process",
".",
"platform",
"==",
"'win32'",
")",
"{",
"fse",
".",
"symlink",
"(",
"reqsInstalledAt",
",",
"symlinkPath",
",",
"'junction'",
")",
";",
"}",
"else",
"{",
"fse",
".",
"symlink",
"(",
"reqsInstalledAt",
",",
"symlinkPath",
")",
";",
"}",
"}",
"}",
"}"
] |
pip install the requirements to the requirements directory
@return {undefined}
|
[
"pip",
"install",
"the",
"requirements",
"to",
"the",
"requirements",
"directory"
] |
2e8117502606fd4bd82c19c3050ba0350adb2789
|
https://github.com/UnitedIncome/serverless-python-requirements/blob/2e8117502606fd4bd82c19c3050ba0350adb2789/lib/pip.js#L538-L621
|
10,744
|
UnitedIncome/serverless-python-requirements
|
lib/shared.js
|
checkForAndDeleteMaxCacheVersions
|
function checkForAndDeleteMaxCacheVersions(options, serverless) {
// If we're using the static cache, and we have static cache max versions enabled
if (
options.useStaticCache &&
options.staticCacheMaxVersions &&
parseInt(options.staticCacheMaxVersions) > 0
) {
// Get the list of our cache files
const files = glob.sync(
[path.join(getUserCachePath(options), '*_slspyc/')],
{ mark: true }
);
// Check if we have too many
if (files.length >= options.staticCacheMaxVersions) {
// Sort by modified time
files.sort(function(a, b) {
return (
fse.statSync(a).mtime.getTime() - fse.statSync(b).mtime.getTime()
);
});
// Remove the older files...
var items = 0;
for (
var i = 0;
i < files.length - options.staticCacheMaxVersions + 1;
i++
) {
rimraf.sync(files[i]);
items++;
}
// Log the number of cache files flushed
serverless.cli.log(
`Removed ${items} items from cache because of staticCacheMaxVersions`
);
}
}
}
|
javascript
|
function checkForAndDeleteMaxCacheVersions(options, serverless) {
// If we're using the static cache, and we have static cache max versions enabled
if (
options.useStaticCache &&
options.staticCacheMaxVersions &&
parseInt(options.staticCacheMaxVersions) > 0
) {
// Get the list of our cache files
const files = glob.sync(
[path.join(getUserCachePath(options), '*_slspyc/')],
{ mark: true }
);
// Check if we have too many
if (files.length >= options.staticCacheMaxVersions) {
// Sort by modified time
files.sort(function(a, b) {
return (
fse.statSync(a).mtime.getTime() - fse.statSync(b).mtime.getTime()
);
});
// Remove the older files...
var items = 0;
for (
var i = 0;
i < files.length - options.staticCacheMaxVersions + 1;
i++
) {
rimraf.sync(files[i]);
items++;
}
// Log the number of cache files flushed
serverless.cli.log(
`Removed ${items} items from cache because of staticCacheMaxVersions`
);
}
}
}
|
[
"function",
"checkForAndDeleteMaxCacheVersions",
"(",
"options",
",",
"serverless",
")",
"{",
"// If we're using the static cache, and we have static cache max versions enabled",
"if",
"(",
"options",
".",
"useStaticCache",
"&&",
"options",
".",
"staticCacheMaxVersions",
"&&",
"parseInt",
"(",
"options",
".",
"staticCacheMaxVersions",
")",
">",
"0",
")",
"{",
"// Get the list of our cache files",
"const",
"files",
"=",
"glob",
".",
"sync",
"(",
"[",
"path",
".",
"join",
"(",
"getUserCachePath",
"(",
"options",
")",
",",
"'*_slspyc/'",
")",
"]",
",",
"{",
"mark",
":",
"true",
"}",
")",
";",
"// Check if we have too many",
"if",
"(",
"files",
".",
"length",
">=",
"options",
".",
"staticCacheMaxVersions",
")",
"{",
"// Sort by modified time",
"files",
".",
"sort",
"(",
"function",
"(",
"a",
",",
"b",
")",
"{",
"return",
"(",
"fse",
".",
"statSync",
"(",
"a",
")",
".",
"mtime",
".",
"getTime",
"(",
")",
"-",
"fse",
".",
"statSync",
"(",
"b",
")",
".",
"mtime",
".",
"getTime",
"(",
")",
")",
";",
"}",
")",
";",
"// Remove the older files...",
"var",
"items",
"=",
"0",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"files",
".",
"length",
"-",
"options",
".",
"staticCacheMaxVersions",
"+",
"1",
";",
"i",
"++",
")",
"{",
"rimraf",
".",
"sync",
"(",
"files",
"[",
"i",
"]",
")",
";",
"items",
"++",
";",
"}",
"// Log the number of cache files flushed",
"serverless",
".",
"cli",
".",
"log",
"(",
"`",
"${",
"items",
"}",
"`",
")",
";",
"}",
"}",
"}"
] |
This helper will check if we're using static cache and have max
versions enabled and will delete older versions in a fifo fashion
@param {Object} options
@param {Object} serverless
@return {undefined}
|
[
"This",
"helper",
"will",
"check",
"if",
"we",
"re",
"using",
"static",
"cache",
"and",
"have",
"max",
"versions",
"enabled",
"and",
"will",
"delete",
"older",
"versions",
"in",
"a",
"fifo",
"fashion"
] |
2e8117502606fd4bd82c19c3050ba0350adb2789
|
https://github.com/UnitedIncome/serverless-python-requirements/blob/2e8117502606fd4bd82c19c3050ba0350adb2789/lib/shared.js#L15-L51
|
10,745
|
UnitedIncome/serverless-python-requirements
|
lib/shared.js
|
getRequirementsWorkingPath
|
function getRequirementsWorkingPath(
subfolder,
requirementsTxtDirectory,
options
) {
// If we want to use the static cache
if (options && options.useStaticCache) {
if (subfolder) {
subfolder = subfolder + '_slspyc';
}
// If we have max number of cache items...
return path.join(getUserCachePath(options), subfolder);
}
// If we don't want to use the static cache, then fallback to the way things used to work
return path.join(requirementsTxtDirectory, 'requirements');
}
|
javascript
|
function getRequirementsWorkingPath(
subfolder,
requirementsTxtDirectory,
options
) {
// If we want to use the static cache
if (options && options.useStaticCache) {
if (subfolder) {
subfolder = subfolder + '_slspyc';
}
// If we have max number of cache items...
return path.join(getUserCachePath(options), subfolder);
}
// If we don't want to use the static cache, then fallback to the way things used to work
return path.join(requirementsTxtDirectory, 'requirements');
}
|
[
"function",
"getRequirementsWorkingPath",
"(",
"subfolder",
",",
"requirementsTxtDirectory",
",",
"options",
")",
"{",
"// If we want to use the static cache",
"if",
"(",
"options",
"&&",
"options",
".",
"useStaticCache",
")",
"{",
"if",
"(",
"subfolder",
")",
"{",
"subfolder",
"=",
"subfolder",
"+",
"'_slspyc'",
";",
"}",
"// If we have max number of cache items...",
"return",
"path",
".",
"join",
"(",
"getUserCachePath",
"(",
"options",
")",
",",
"subfolder",
")",
";",
"}",
"// If we don't want to use the static cache, then fallback to the way things used to work",
"return",
"path",
".",
"join",
"(",
"requirementsTxtDirectory",
",",
"'requirements'",
")",
";",
"}"
] |
The working path that all requirements will be compiled into
@param {string} subfolder
@param {string} servicePath
@param {Object} options
@return {string}
|
[
"The",
"working",
"path",
"that",
"all",
"requirements",
"will",
"be",
"compiled",
"into"
] |
2e8117502606fd4bd82c19c3050ba0350adb2789
|
https://github.com/UnitedIncome/serverless-python-requirements/blob/2e8117502606fd4bd82c19c3050ba0350adb2789/lib/shared.js#L60-L77
|
10,746
|
UnitedIncome/serverless-python-requirements
|
lib/shared.js
|
getUserCachePath
|
function getUserCachePath(options) {
// If we've manually set the static cache location
if (options && options.cacheLocation) {
return path.resolve(options.cacheLocation);
}
// Otherwise, find/use the python-ey appdirs cache location
const dirs = new Appdir({
appName: 'serverless-python-requirements',
appAuthor: 'UnitedIncome'
});
return dirs.userCache();
}
|
javascript
|
function getUserCachePath(options) {
// If we've manually set the static cache location
if (options && options.cacheLocation) {
return path.resolve(options.cacheLocation);
}
// Otherwise, find/use the python-ey appdirs cache location
const dirs = new Appdir({
appName: 'serverless-python-requirements',
appAuthor: 'UnitedIncome'
});
return dirs.userCache();
}
|
[
"function",
"getUserCachePath",
"(",
"options",
")",
"{",
"// If we've manually set the static cache location",
"if",
"(",
"options",
"&&",
"options",
".",
"cacheLocation",
")",
"{",
"return",
"path",
".",
"resolve",
"(",
"options",
".",
"cacheLocation",
")",
";",
"}",
"// Otherwise, find/use the python-ey appdirs cache location",
"const",
"dirs",
"=",
"new",
"Appdir",
"(",
"{",
"appName",
":",
"'serverless-python-requirements'",
",",
"appAuthor",
":",
"'UnitedIncome'",
"}",
")",
";",
"return",
"dirs",
".",
"userCache",
"(",
")",
";",
"}"
] |
The static cache path that will be used for this system + options, used if static cache is enabled
@param {Object} options
@return {string}
|
[
"The",
"static",
"cache",
"path",
"that",
"will",
"be",
"used",
"for",
"this",
"system",
"+",
"options",
"used",
"if",
"static",
"cache",
"is",
"enabled"
] |
2e8117502606fd4bd82c19c3050ba0350adb2789
|
https://github.com/UnitedIncome/serverless-python-requirements/blob/2e8117502606fd4bd82c19c3050ba0350adb2789/lib/shared.js#L84-L96
|
10,747
|
UnitedIncome/serverless-python-requirements
|
lib/poetry.js
|
isPoetryProject
|
function isPoetryProject(servicePath) {
const pyprojectPath = path.join(servicePath, 'pyproject.toml');
if (!fse.existsSync(pyprojectPath)) {
return false;
}
const pyprojectToml = fs.readFileSync(pyprojectPath);
const pyproject = tomlParse(pyprojectToml);
const buildSystemReqs =
(pyproject['build-system'] && pyproject['build-system']['requires']) || [];
for (var i = 0; i < buildSystemReqs.length; i++) {
if (buildSystemReqs[i].startsWith('poetry')) {
return true;
}
}
return false;
}
|
javascript
|
function isPoetryProject(servicePath) {
const pyprojectPath = path.join(servicePath, 'pyproject.toml');
if (!fse.existsSync(pyprojectPath)) {
return false;
}
const pyprojectToml = fs.readFileSync(pyprojectPath);
const pyproject = tomlParse(pyprojectToml);
const buildSystemReqs =
(pyproject['build-system'] && pyproject['build-system']['requires']) || [];
for (var i = 0; i < buildSystemReqs.length; i++) {
if (buildSystemReqs[i].startsWith('poetry')) {
return true;
}
}
return false;
}
|
[
"function",
"isPoetryProject",
"(",
"servicePath",
")",
"{",
"const",
"pyprojectPath",
"=",
"path",
".",
"join",
"(",
"servicePath",
",",
"'pyproject.toml'",
")",
";",
"if",
"(",
"!",
"fse",
".",
"existsSync",
"(",
"pyprojectPath",
")",
")",
"{",
"return",
"false",
";",
"}",
"const",
"pyprojectToml",
"=",
"fs",
".",
"readFileSync",
"(",
"pyprojectPath",
")",
";",
"const",
"pyproject",
"=",
"tomlParse",
"(",
"pyprojectToml",
")",
";",
"const",
"buildSystemReqs",
"=",
"(",
"pyproject",
"[",
"'build-system'",
"]",
"&&",
"pyproject",
"[",
"'build-system'",
"]",
"[",
"'requires'",
"]",
")",
"||",
"[",
"]",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"buildSystemReqs",
".",
"length",
";",
"i",
"++",
")",
"{",
"if",
"(",
"buildSystemReqs",
"[",
"i",
"]",
".",
"startsWith",
"(",
"'poetry'",
")",
")",
"{",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}"
] |
Check if pyproject.toml file exists and is a poetry project.
|
[
"Check",
"if",
"pyproject",
".",
"toml",
"file",
"exists",
"and",
"is",
"a",
"poetry",
"project",
"."
] |
2e8117502606fd4bd82c19c3050ba0350adb2789
|
https://github.com/UnitedIncome/serverless-python-requirements/blob/2e8117502606fd4bd82c19c3050ba0350adb2789/lib/poetry.js#L45-L65
|
10,748
|
google/lovefield
|
gulpfile.js
|
function(browser) {
return runner.runJsUnitTests(options.filter, browser).then(
function(results) {
var failedCount = results.reduce(function(prev, item) {
return prev + (item['pass'] ? 0 : 1);
}, 0);
log(results.length + ' tests, ' + failedCount + ' failure(s).');
log('[ ' + chalk.cyan(browser) + ' ] JSUnit tests: ',
failedCount > 0 ? chalk.red('FAILED') : chalk.green('PASSED'));
if (failedCount > 0) {
throw new Error();
}
}, finalize);
}
|
javascript
|
function(browser) {
return runner.runJsUnitTests(options.filter, browser).then(
function(results) {
var failedCount = results.reduce(function(prev, item) {
return prev + (item['pass'] ? 0 : 1);
}, 0);
log(results.length + ' tests, ' + failedCount + ' failure(s).');
log('[ ' + chalk.cyan(browser) + ' ] JSUnit tests: ',
failedCount > 0 ? chalk.red('FAILED') : chalk.green('PASSED'));
if (failedCount > 0) {
throw new Error();
}
}, finalize);
}
|
[
"function",
"(",
"browser",
")",
"{",
"return",
"runner",
".",
"runJsUnitTests",
"(",
"options",
".",
"filter",
",",
"browser",
")",
".",
"then",
"(",
"function",
"(",
"results",
")",
"{",
"var",
"failedCount",
"=",
"results",
".",
"reduce",
"(",
"function",
"(",
"prev",
",",
"item",
")",
"{",
"return",
"prev",
"+",
"(",
"item",
"[",
"'pass'",
"]",
"?",
"0",
":",
"1",
")",
";",
"}",
",",
"0",
")",
";",
"log",
"(",
"results",
".",
"length",
"+",
"' tests, '",
"+",
"failedCount",
"+",
"' failure(s).'",
")",
";",
"log",
"(",
"'[ '",
"+",
"chalk",
".",
"cyan",
"(",
"browser",
")",
"+",
"' ] JSUnit tests: '",
",",
"failedCount",
">",
"0",
"?",
"chalk",
".",
"red",
"(",
"'FAILED'",
")",
":",
"chalk",
".",
"green",
"(",
"'PASSED'",
")",
")",
";",
"if",
"(",
"failedCount",
">",
"0",
")",
"{",
"throw",
"new",
"Error",
"(",
")",
";",
"}",
"}",
",",
"finalize",
")",
";",
"}"
] |
Run only JSUnit tests.
|
[
"Run",
"only",
"JSUnit",
"tests",
"."
] |
46f70024af70dd665d790170700a3c109b4922f5
|
https://github.com/google/lovefield/blob/46f70024af70dd665d790170700a3c109b4922f5/gulpfile.js#L153-L166
|
|
10,749
|
google/lovefield
|
lib/proc/index_key_range_calculator.js
|
calculateCartesianProduct
|
function calculateCartesianProduct(keyRangeSets) {
goog.asserts.assert(
keyRangeSets.length > 1,
'Should only be called for cross-column indices.');
var keyRangeSetsAsArrays = keyRangeSets.map(
function(keyRangeSet) {
return keyRangeSet.getValues();
});
var it = goog.iter.product.apply(null, keyRangeSetsAsArrays);
var combinations = [];
goog.iter.forEach(it, function(value) {
combinations.push(value);
});
return combinations;
}
|
javascript
|
function calculateCartesianProduct(keyRangeSets) {
goog.asserts.assert(
keyRangeSets.length > 1,
'Should only be called for cross-column indices.');
var keyRangeSetsAsArrays = keyRangeSets.map(
function(keyRangeSet) {
return keyRangeSet.getValues();
});
var it = goog.iter.product.apply(null, keyRangeSetsAsArrays);
var combinations = [];
goog.iter.forEach(it, function(value) {
combinations.push(value);
});
return combinations;
}
|
[
"function",
"calculateCartesianProduct",
"(",
"keyRangeSets",
")",
"{",
"goog",
".",
"asserts",
".",
"assert",
"(",
"keyRangeSets",
".",
"length",
">",
"1",
",",
"'Should only be called for cross-column indices.'",
")",
";",
"var",
"keyRangeSetsAsArrays",
"=",
"keyRangeSets",
".",
"map",
"(",
"function",
"(",
"keyRangeSet",
")",
"{",
"return",
"keyRangeSet",
".",
"getValues",
"(",
")",
";",
"}",
")",
";",
"var",
"it",
"=",
"goog",
".",
"iter",
".",
"product",
".",
"apply",
"(",
"null",
",",
"keyRangeSetsAsArrays",
")",
";",
"var",
"combinations",
"=",
"[",
"]",
";",
"goog",
".",
"iter",
".",
"forEach",
"(",
"it",
",",
"function",
"(",
"value",
")",
"{",
"combinations",
".",
"push",
"(",
"value",
")",
";",
"}",
")",
";",
"return",
"combinations",
";",
"}"
] |
Finds the cartesian product of a collection of SingleKeyRangeSets.
@param {!Array<!lf.index.SingleKeyRangeSet>} keyRangeSets A SingleKeyRangeSet
at position i in the input array corresponds to all possible values for
the ith dimension in the N-dimensional space (where N is the number of
columns in the cross-column index).
@return {!Array<!lf.index.KeyRange>} The cross-column key range combinations.
|
[
"Finds",
"the",
"cartesian",
"product",
"of",
"a",
"collection",
"of",
"SingleKeyRangeSets",
"."
] |
46f70024af70dd665d790170700a3c109b4922f5
|
https://github.com/google/lovefield/blob/46f70024af70dd665d790170700a3c109b4922f5/lib/proc/index_key_range_calculator.js#L227-L243
|
10,750
|
google/lovefield
|
tools/scan_deps.js
|
scanDeps
|
function scanDeps() {
var provideMap = new ProvideMap_();
var requireMap = new RequireMap_();
scanFiles(relativeGlob('lib'), provideMap, requireMap);
var closureRequire = new RequireMap_();
var closureProvide = new ProvideMap_();
var closurePath = config.CLOSURE_LIBRARY_PATH + '/closure/goog';
scanFiles(relativeGlob(closurePath), closureProvide, closureRequire);
var closureDeps =
extractClosureDependencies(requireMap, closureRequire, closureProvide);
var edges = requireMap.getTopoSortEntry(provideMap, closureProvide);
var edgesClosure = closureRequire.getTopoSortEntry(
closureProvide, closureProvide, closureDeps);
var topoSorter = new Toposort();
edges.forEach(function(entry) {
topoSorter.add(entry.name, entry.depends);
});
var topoSorterClosure = new Toposort();
edgesClosure.forEach(function(entry) {
topoSorterClosure.add(entry.name, entry.depends);
});
var files = [pathMod.resolve(
pathMod.join(config.CLOSURE_LIBRARY_PATH, 'closure/goog/base.js'))];
files = files.concat(topoSorterClosure.sort().reverse());
files = files.concat(topoSorter.sort().reverse());
return files;
}
|
javascript
|
function scanDeps() {
var provideMap = new ProvideMap_();
var requireMap = new RequireMap_();
scanFiles(relativeGlob('lib'), provideMap, requireMap);
var closureRequire = new RequireMap_();
var closureProvide = new ProvideMap_();
var closurePath = config.CLOSURE_LIBRARY_PATH + '/closure/goog';
scanFiles(relativeGlob(closurePath), closureProvide, closureRequire);
var closureDeps =
extractClosureDependencies(requireMap, closureRequire, closureProvide);
var edges = requireMap.getTopoSortEntry(provideMap, closureProvide);
var edgesClosure = closureRequire.getTopoSortEntry(
closureProvide, closureProvide, closureDeps);
var topoSorter = new Toposort();
edges.forEach(function(entry) {
topoSorter.add(entry.name, entry.depends);
});
var topoSorterClosure = new Toposort();
edgesClosure.forEach(function(entry) {
topoSorterClosure.add(entry.name, entry.depends);
});
var files = [pathMod.resolve(
pathMod.join(config.CLOSURE_LIBRARY_PATH, 'closure/goog/base.js'))];
files = files.concat(topoSorterClosure.sort().reverse());
files = files.concat(topoSorter.sort().reverse());
return files;
}
|
[
"function",
"scanDeps",
"(",
")",
"{",
"var",
"provideMap",
"=",
"new",
"ProvideMap_",
"(",
")",
";",
"var",
"requireMap",
"=",
"new",
"RequireMap_",
"(",
")",
";",
"scanFiles",
"(",
"relativeGlob",
"(",
"'lib'",
")",
",",
"provideMap",
",",
"requireMap",
")",
";",
"var",
"closureRequire",
"=",
"new",
"RequireMap_",
"(",
")",
";",
"var",
"closureProvide",
"=",
"new",
"ProvideMap_",
"(",
")",
";",
"var",
"closurePath",
"=",
"config",
".",
"CLOSURE_LIBRARY_PATH",
"+",
"'/closure/goog'",
";",
"scanFiles",
"(",
"relativeGlob",
"(",
"closurePath",
")",
",",
"closureProvide",
",",
"closureRequire",
")",
";",
"var",
"closureDeps",
"=",
"extractClosureDependencies",
"(",
"requireMap",
",",
"closureRequire",
",",
"closureProvide",
")",
";",
"var",
"edges",
"=",
"requireMap",
".",
"getTopoSortEntry",
"(",
"provideMap",
",",
"closureProvide",
")",
";",
"var",
"edgesClosure",
"=",
"closureRequire",
".",
"getTopoSortEntry",
"(",
"closureProvide",
",",
"closureProvide",
",",
"closureDeps",
")",
";",
"var",
"topoSorter",
"=",
"new",
"Toposort",
"(",
")",
";",
"edges",
".",
"forEach",
"(",
"function",
"(",
"entry",
")",
"{",
"topoSorter",
".",
"add",
"(",
"entry",
".",
"name",
",",
"entry",
".",
"depends",
")",
";",
"}",
")",
";",
"var",
"topoSorterClosure",
"=",
"new",
"Toposort",
"(",
")",
";",
"edgesClosure",
".",
"forEach",
"(",
"function",
"(",
"entry",
")",
"{",
"topoSorterClosure",
".",
"add",
"(",
"entry",
".",
"name",
",",
"entry",
".",
"depends",
")",
";",
"}",
")",
";",
"var",
"files",
"=",
"[",
"pathMod",
".",
"resolve",
"(",
"pathMod",
".",
"join",
"(",
"config",
".",
"CLOSURE_LIBRARY_PATH",
",",
"'closure/goog/base.js'",
")",
")",
"]",
";",
"files",
"=",
"files",
".",
"concat",
"(",
"topoSorterClosure",
".",
"sort",
"(",
")",
".",
"reverse",
"(",
")",
")",
";",
"files",
"=",
"files",
".",
"concat",
"(",
"topoSorter",
".",
"sort",
"(",
")",
".",
"reverse",
"(",
")",
")",
";",
"return",
"files",
";",
"}"
] |
Find Closure dependency files for the lib.
@return {!Array<string>}
|
[
"Find",
"Closure",
"dependency",
"files",
"for",
"the",
"lib",
"."
] |
46f70024af70dd665d790170700a3c109b4922f5
|
https://github.com/google/lovefield/blob/46f70024af70dd665d790170700a3c109b4922f5/tools/scan_deps.js#L292-L324
|
10,751
|
google/lovefield
|
tools/scan_deps.js
|
genAddDependency
|
function genAddDependency(basePath, provideMap, requireMap) {
var provide = provideMap.getAllProvides();
var require = requireMap.getAllRequires();
var set = new Set();
provide.forEach(function(value, key) {
set.add(key);
});
require.forEach(function(value, key) {
set.add(key);
});
var results = [];
set.forEach(function(key) {
var relativeServePath = pathMod.join(
'../../', pathMod.relative(basePath, key));
if (osMod.platform().indexOf('win') != -1) {
// For the case of Windows relativeServePath contains backslashes. Need to
// escape the backward slash, otherwise it will not appear in the deps.js
// file correctly. An alternative would be to convert backslashes to
// forward slashes which works just as fine in the context of a browser.
relativeServePath = relativeServePath.replace(/\\/g, '\\\\');
}
var line = 'goog.addDependency("' + relativeServePath + '", ';
var isModule = false;
if (provide.has(key)) {
var value = /** @type {!Array<string>} */ (provide.get(key));
line += JSON.stringify(value) + ', ';
isModule = provideMap.isModule(key);
} else {
line += '[], ';
}
if (require.has(key)) {
line += JSON.stringify(require.get(key));
} else {
line += '[]';
}
line += isModule ? ', true);' : ');';
results.push(line);
});
return results;
}
|
javascript
|
function genAddDependency(basePath, provideMap, requireMap) {
var provide = provideMap.getAllProvides();
var require = requireMap.getAllRequires();
var set = new Set();
provide.forEach(function(value, key) {
set.add(key);
});
require.forEach(function(value, key) {
set.add(key);
});
var results = [];
set.forEach(function(key) {
var relativeServePath = pathMod.join(
'../../', pathMod.relative(basePath, key));
if (osMod.platform().indexOf('win') != -1) {
// For the case of Windows relativeServePath contains backslashes. Need to
// escape the backward slash, otherwise it will not appear in the deps.js
// file correctly. An alternative would be to convert backslashes to
// forward slashes which works just as fine in the context of a browser.
relativeServePath = relativeServePath.replace(/\\/g, '\\\\');
}
var line = 'goog.addDependency("' + relativeServePath + '", ';
var isModule = false;
if (provide.has(key)) {
var value = /** @type {!Array<string>} */ (provide.get(key));
line += JSON.stringify(value) + ', ';
isModule = provideMap.isModule(key);
} else {
line += '[], ';
}
if (require.has(key)) {
line += JSON.stringify(require.get(key));
} else {
line += '[]';
}
line += isModule ? ', true);' : ');';
results.push(line);
});
return results;
}
|
[
"function",
"genAddDependency",
"(",
"basePath",
",",
"provideMap",
",",
"requireMap",
")",
"{",
"var",
"provide",
"=",
"provideMap",
".",
"getAllProvides",
"(",
")",
";",
"var",
"require",
"=",
"requireMap",
".",
"getAllRequires",
"(",
")",
";",
"var",
"set",
"=",
"new",
"Set",
"(",
")",
";",
"provide",
".",
"forEach",
"(",
"function",
"(",
"value",
",",
"key",
")",
"{",
"set",
".",
"add",
"(",
"key",
")",
";",
"}",
")",
";",
"require",
".",
"forEach",
"(",
"function",
"(",
"value",
",",
"key",
")",
"{",
"set",
".",
"add",
"(",
"key",
")",
";",
"}",
")",
";",
"var",
"results",
"=",
"[",
"]",
";",
"set",
".",
"forEach",
"(",
"function",
"(",
"key",
")",
"{",
"var",
"relativeServePath",
"=",
"pathMod",
".",
"join",
"(",
"'../../'",
",",
"pathMod",
".",
"relative",
"(",
"basePath",
",",
"key",
")",
")",
";",
"if",
"(",
"osMod",
".",
"platform",
"(",
")",
".",
"indexOf",
"(",
"'win'",
")",
"!=",
"-",
"1",
")",
"{",
"// For the case of Windows relativeServePath contains backslashes. Need to",
"// escape the backward slash, otherwise it will not appear in the deps.js",
"// file correctly. An alternative would be to convert backslashes to",
"// forward slashes which works just as fine in the context of a browser.",
"relativeServePath",
"=",
"relativeServePath",
".",
"replace",
"(",
"/",
"\\\\",
"/",
"g",
",",
"'\\\\\\\\'",
")",
";",
"}",
"var",
"line",
"=",
"'goog.addDependency(\"'",
"+",
"relativeServePath",
"+",
"'\", '",
";",
"var",
"isModule",
"=",
"false",
";",
"if",
"(",
"provide",
".",
"has",
"(",
"key",
")",
")",
"{",
"var",
"value",
"=",
"/** @type {!Array<string>} */",
"(",
"provide",
".",
"get",
"(",
"key",
")",
")",
";",
"line",
"+=",
"JSON",
".",
"stringify",
"(",
"value",
")",
"+",
"', '",
";",
"isModule",
"=",
"provideMap",
".",
"isModule",
"(",
"key",
")",
";",
"}",
"else",
"{",
"line",
"+=",
"'[], '",
";",
"}",
"if",
"(",
"require",
".",
"has",
"(",
"key",
")",
")",
"{",
"line",
"+=",
"JSON",
".",
"stringify",
"(",
"require",
".",
"get",
"(",
"key",
")",
")",
";",
"}",
"else",
"{",
"line",
"+=",
"'[]'",
";",
"}",
"line",
"+=",
"isModule",
"?",
"', true);'",
":",
"');'",
";",
"results",
".",
"push",
"(",
"line",
")",
";",
"}",
")",
";",
"return",
"results",
";",
"}"
] |
Generates goog.addDependency.
@param {string} basePath
@param {!ProvideMap_} provideMap
@param {!RequireMap_} requireMap
@return {!Array<string>}
|
[
"Generates",
"goog",
".",
"addDependency",
"."
] |
46f70024af70dd665d790170700a3c109b4922f5
|
https://github.com/google/lovefield/blob/46f70024af70dd665d790170700a3c109b4922f5/tools/scan_deps.js#L334-L380
|
10,752
|
google/lovefield
|
tools/scan_deps.js
|
genDeps
|
function genDeps(basePath, targets) {
var provideMap = new ProvideMap_();
var requireMap = new RequireMap_();
var files = [];
targets.forEach(function(target) {
files = files.concat(relativeGlob(target));
});
scanFiles(files, provideMap, requireMap);
var results = genAddDependency(basePath, provideMap, requireMap);
return results.join('\n');
}
|
javascript
|
function genDeps(basePath, targets) {
var provideMap = new ProvideMap_();
var requireMap = new RequireMap_();
var files = [];
targets.forEach(function(target) {
files = files.concat(relativeGlob(target));
});
scanFiles(files, provideMap, requireMap);
var results = genAddDependency(basePath, provideMap, requireMap);
return results.join('\n');
}
|
[
"function",
"genDeps",
"(",
"basePath",
",",
"targets",
")",
"{",
"var",
"provideMap",
"=",
"new",
"ProvideMap_",
"(",
")",
";",
"var",
"requireMap",
"=",
"new",
"RequireMap_",
"(",
")",
";",
"var",
"files",
"=",
"[",
"]",
";",
"targets",
".",
"forEach",
"(",
"function",
"(",
"target",
")",
"{",
"files",
"=",
"files",
".",
"concat",
"(",
"relativeGlob",
"(",
"target",
")",
")",
";",
"}",
")",
";",
"scanFiles",
"(",
"files",
",",
"provideMap",
",",
"requireMap",
")",
";",
"var",
"results",
"=",
"genAddDependency",
"(",
"basePath",
",",
"provideMap",
",",
"requireMap",
")",
";",
"return",
"results",
".",
"join",
"(",
"'\\n'",
")",
";",
"}"
] |
Generates deps.js used for testing.
@param {string} basePath
@param {!Array<string>} targets
@return {string}
|
[
"Generates",
"deps",
".",
"js",
"used",
"for",
"testing",
"."
] |
46f70024af70dd665d790170700a3c109b4922f5
|
https://github.com/google/lovefield/blob/46f70024af70dd665d790170700a3c109b4922f5/tools/scan_deps.js#L389-L401
|
10,753
|
google/lovefield
|
tools/scan_deps.js
|
genModuleDeps
|
function genModuleDeps(scriptPath) {
var provideMap = new ProvideMap_();
var requireMap = new RequireMap_();
scanFiles([scriptPath], provideMap, requireMap);
var dumpValues = function(map) {
var results = [];
map.forEach(function(value, key) {
results = results.concat(value);
});
return results;
};
var relativePath = pathMod.join('../..', scriptPath);
if (osMod.platform().indexOf('win') != -1) {
relativePath = relativePath.replace(/\\/g, '\\\\');
}
var provide = provideMap.getAllProvides();
var require = requireMap.getAllRequires();
return 'goog.addDependency("' + relativePath + '", ' +
JSON.stringify(dumpValues(provide)) + ', ' +
JSON.stringify(dumpValues(require)) + ', true);';
}
|
javascript
|
function genModuleDeps(scriptPath) {
var provideMap = new ProvideMap_();
var requireMap = new RequireMap_();
scanFiles([scriptPath], provideMap, requireMap);
var dumpValues = function(map) {
var results = [];
map.forEach(function(value, key) {
results = results.concat(value);
});
return results;
};
var relativePath = pathMod.join('../..', scriptPath);
if (osMod.platform().indexOf('win') != -1) {
relativePath = relativePath.replace(/\\/g, '\\\\');
}
var provide = provideMap.getAllProvides();
var require = requireMap.getAllRequires();
return 'goog.addDependency("' + relativePath + '", ' +
JSON.stringify(dumpValues(provide)) + ', ' +
JSON.stringify(dumpValues(require)) + ', true);';
}
|
[
"function",
"genModuleDeps",
"(",
"scriptPath",
")",
"{",
"var",
"provideMap",
"=",
"new",
"ProvideMap_",
"(",
")",
";",
"var",
"requireMap",
"=",
"new",
"RequireMap_",
"(",
")",
";",
"scanFiles",
"(",
"[",
"scriptPath",
"]",
",",
"provideMap",
",",
"requireMap",
")",
";",
"var",
"dumpValues",
"=",
"function",
"(",
"map",
")",
"{",
"var",
"results",
"=",
"[",
"]",
";",
"map",
".",
"forEach",
"(",
"function",
"(",
"value",
",",
"key",
")",
"{",
"results",
"=",
"results",
".",
"concat",
"(",
"value",
")",
";",
"}",
")",
";",
"return",
"results",
";",
"}",
";",
"var",
"relativePath",
"=",
"pathMod",
".",
"join",
"(",
"'../..'",
",",
"scriptPath",
")",
";",
"if",
"(",
"osMod",
".",
"platform",
"(",
")",
".",
"indexOf",
"(",
"'win'",
")",
"!=",
"-",
"1",
")",
"{",
"relativePath",
"=",
"relativePath",
".",
"replace",
"(",
"/",
"\\\\",
"/",
"g",
",",
"'\\\\\\\\'",
")",
";",
"}",
"var",
"provide",
"=",
"provideMap",
".",
"getAllProvides",
"(",
")",
";",
"var",
"require",
"=",
"requireMap",
".",
"getAllRequires",
"(",
")",
";",
"return",
"'goog.addDependency(\"'",
"+",
"relativePath",
"+",
"'\", '",
"+",
"JSON",
".",
"stringify",
"(",
"dumpValues",
"(",
"provide",
")",
")",
"+",
"', '",
"+",
"JSON",
".",
"stringify",
"(",
"dumpValues",
"(",
"require",
")",
")",
"+",
"', true);'",
";",
"}"
] |
Generate addDependency for single module.
@param {string} scriptPath
@return {string}
|
[
"Generate",
"addDependency",
"for",
"single",
"module",
"."
] |
46f70024af70dd665d790170700a3c109b4922f5
|
https://github.com/google/lovefield/blob/46f70024af70dd665d790170700a3c109b4922f5/tools/scan_deps.js#L409-L431
|
10,754
|
google/lovefield
|
lib/proc/index_join_pass.js
|
function(table) {
return table.getEffectiveName() ==
joinStep.predicate.rightColumn.getTable().getEffectiveName() ?
joinStep.predicate.rightColumn : joinStep.predicate.leftColumn;
}
|
javascript
|
function(table) {
return table.getEffectiveName() ==
joinStep.predicate.rightColumn.getTable().getEffectiveName() ?
joinStep.predicate.rightColumn : joinStep.predicate.leftColumn;
}
|
[
"function",
"(",
"table",
")",
"{",
"return",
"table",
".",
"getEffectiveName",
"(",
")",
"==",
"joinStep",
".",
"predicate",
".",
"rightColumn",
".",
"getTable",
"(",
")",
".",
"getEffectiveName",
"(",
")",
"?",
"joinStep",
".",
"predicate",
".",
"rightColumn",
":",
"joinStep",
".",
"predicate",
".",
"leftColumn",
";",
"}"
] |
Finds which of the two joined columns corresponds to the given table.
@param {!lf.schema.Table} table
@return {!lf.schema.Column}
|
[
"Finds",
"which",
"of",
"the",
"two",
"joined",
"columns",
"corresponds",
"to",
"the",
"given",
"table",
"."
] |
46f70024af70dd665d790170700a3c109b4922f5
|
https://github.com/google/lovefield/blob/46f70024af70dd665d790170700a3c109b4922f5/lib/proc/index_join_pass.js#L96-L100
|
|
10,755
|
google/lovefield
|
lib/proc/index_join_pass.js
|
function(executionStep) {
// In order to use and index for implementing a join, the entire relation
// must be fed to the JoinStep, otherwise the index can't be used.
if (!(executionStep instanceof lf.proc.TableAccessFullStep)) {
return null;
}
var candidateColumn = getColumnForTable(executionStep.table);
return goog.isNull(candidateColumn.getIndex()) ? null : candidateColumn;
}
|
javascript
|
function(executionStep) {
// In order to use and index for implementing a join, the entire relation
// must be fed to the JoinStep, otherwise the index can't be used.
if (!(executionStep instanceof lf.proc.TableAccessFullStep)) {
return null;
}
var candidateColumn = getColumnForTable(executionStep.table);
return goog.isNull(candidateColumn.getIndex()) ? null : candidateColumn;
}
|
[
"function",
"(",
"executionStep",
")",
"{",
"// In order to use and index for implementing a join, the entire relation",
"// must be fed to the JoinStep, otherwise the index can't be used.",
"if",
"(",
"!",
"(",
"executionStep",
"instanceof",
"lf",
".",
"proc",
".",
"TableAccessFullStep",
")",
")",
"{",
"return",
"null",
";",
"}",
"var",
"candidateColumn",
"=",
"getColumnForTable",
"(",
"executionStep",
".",
"table",
")",
";",
"return",
"goog",
".",
"isNull",
"(",
"candidateColumn",
".",
"getIndex",
"(",
")",
")",
"?",
"null",
":",
"candidateColumn",
";",
"}"
] |
Extracts the candidate indexed column for the given execution step node.
@param {!lf.proc.PhysicalQueryPlanNode} executionStep
@return {?lf.schema.Column} The candidate column or null if no such column
exists.
|
[
"Extracts",
"the",
"candidate",
"indexed",
"column",
"for",
"the",
"given",
"execution",
"step",
"node",
"."
] |
46f70024af70dd665d790170700a3c109b4922f5
|
https://github.com/google/lovefield/blob/46f70024af70dd665d790170700a3c109b4922f5/lib/proc/index_join_pass.js#L108-L116
|
|
10,756
|
google/lovefield
|
demos/moviedb/demo-binding.js
|
addSampleData
|
function addSampleData() {
return Promise.all([
insertPersonData('actor.json', db.getSchema().table('Actor')),
insertPersonData('director.json', db.getSchema().table('Director')),
insertData('movie.json', db.getSchema().table('Movie')),
insertData('movieactor.json', db.getSchema().table('MovieActor')),
insertData('moviedirector.json', db.getSchema().table('MovieDirector')),
insertData('moviegenre.json', db.getSchema().table('MovieGenre'))
]).then(function(queries) {
var tx = db.createTransaction();
return tx.exec(queries);
});
}
|
javascript
|
function addSampleData() {
return Promise.all([
insertPersonData('actor.json', db.getSchema().table('Actor')),
insertPersonData('director.json', db.getSchema().table('Director')),
insertData('movie.json', db.getSchema().table('Movie')),
insertData('movieactor.json', db.getSchema().table('MovieActor')),
insertData('moviedirector.json', db.getSchema().table('MovieDirector')),
insertData('moviegenre.json', db.getSchema().table('MovieGenre'))
]).then(function(queries) {
var tx = db.createTransaction();
return tx.exec(queries);
});
}
|
[
"function",
"addSampleData",
"(",
")",
"{",
"return",
"Promise",
".",
"all",
"(",
"[",
"insertPersonData",
"(",
"'actor.json'",
",",
"db",
".",
"getSchema",
"(",
")",
".",
"table",
"(",
"'Actor'",
")",
")",
",",
"insertPersonData",
"(",
"'director.json'",
",",
"db",
".",
"getSchema",
"(",
")",
".",
"table",
"(",
"'Director'",
")",
")",
",",
"insertData",
"(",
"'movie.json'",
",",
"db",
".",
"getSchema",
"(",
")",
".",
"table",
"(",
"'Movie'",
")",
")",
",",
"insertData",
"(",
"'movieactor.json'",
",",
"db",
".",
"getSchema",
"(",
")",
".",
"table",
"(",
"'MovieActor'",
")",
")",
",",
"insertData",
"(",
"'moviedirector.json'",
",",
"db",
".",
"getSchema",
"(",
")",
".",
"table",
"(",
"'MovieDirector'",
")",
")",
",",
"insertData",
"(",
"'moviegenre.json'",
",",
"db",
".",
"getSchema",
"(",
")",
".",
"table",
"(",
"'MovieGenre'",
")",
")",
"]",
")",
".",
"then",
"(",
"function",
"(",
"queries",
")",
"{",
"var",
"tx",
"=",
"db",
".",
"createTransaction",
"(",
")",
";",
"return",
"tx",
".",
"exec",
"(",
"queries",
")",
";",
"}",
")",
";",
"}"
] |
Adds sample data to the database.
@return {!IThenable}
|
[
"Adds",
"sample",
"data",
"to",
"the",
"database",
"."
] |
46f70024af70dd665d790170700a3c109b4922f5
|
https://github.com/google/lovefield/blob/46f70024af70dd665d790170700a3c109b4922f5/demos/moviedb/demo-binding.js#L128-L140
|
10,757
|
google/lovefield
|
lib/tree.js
|
function(original, clone) {
if (goog.isNull(original)) {
return;
}
var cloneFull = original.getChildCount() == clone.getChildCount();
if (cloneFull) {
var cloneIndex = copyParentStack.indexOf(clone);
if (cloneIndex != -1) {
copyParentStack.splice(cloneIndex, 1);
}
}
}
|
javascript
|
function(original, clone) {
if (goog.isNull(original)) {
return;
}
var cloneFull = original.getChildCount() == clone.getChildCount();
if (cloneFull) {
var cloneIndex = copyParentStack.indexOf(clone);
if (cloneIndex != -1) {
copyParentStack.splice(cloneIndex, 1);
}
}
}
|
[
"function",
"(",
"original",
",",
"clone",
")",
"{",
"if",
"(",
"goog",
".",
"isNull",
"(",
"original",
")",
")",
"{",
"return",
";",
"}",
"var",
"cloneFull",
"=",
"original",
".",
"getChildCount",
"(",
")",
"==",
"clone",
".",
"getChildCount",
"(",
")",
";",
"if",
"(",
"cloneFull",
")",
"{",
"var",
"cloneIndex",
"=",
"copyParentStack",
".",
"indexOf",
"(",
"clone",
")",
";",
"if",
"(",
"cloneIndex",
"!=",
"-",
"1",
")",
"{",
"copyParentStack",
".",
"splice",
"(",
"cloneIndex",
",",
"1",
")",
";",
"}",
"}",
"}"
] |
Removes a node from the parent stack, if that node has already reached its
target number of children.
@param {?lf.structs.TreeNode} original The original node.
@param {!lf.structs.TreeNode} clone The corresponding cloned node.
|
[
"Removes",
"a",
"node",
"from",
"the",
"parent",
"stack",
"if",
"that",
"node",
"has",
"already",
"reached",
"its",
"target",
"number",
"of",
"children",
"."
] |
46f70024af70dd665d790170700a3c109b4922f5
|
https://github.com/google/lovefield/blob/46f70024af70dd665d790170700a3c109b4922f5/lib/tree.js#L44-L56
|
|
10,758
|
google/lovefield
|
lib/index/btree.js
|
function(coverage) {
return coverage[0] ?
(coverage[1] ? lf.index.Favor.TIE : lf.index.Favor.LHS) :
lf.index.Favor.RHS;
}
|
javascript
|
function(coverage) {
return coverage[0] ?
(coverage[1] ? lf.index.Favor.TIE : lf.index.Favor.LHS) :
lf.index.Favor.RHS;
}
|
[
"function",
"(",
"coverage",
")",
"{",
"return",
"coverage",
"[",
"0",
"]",
"?",
"(",
"coverage",
"[",
"1",
"]",
"?",
"lf",
".",
"index",
".",
"Favor",
".",
"TIE",
":",
"lf",
".",
"index",
".",
"Favor",
".",
"LHS",
")",
":",
"lf",
".",
"index",
".",
"Favor",
".",
"RHS",
";",
"}"
] |
Position of range relative to the key.
|
[
"Position",
"of",
"range",
"relative",
"to",
"the",
"key",
"."
] |
46f70024af70dd665d790170700a3c109b4922f5
|
https://github.com/google/lovefield/blob/46f70024af70dd665d790170700a3c109b4922f5/lib/index/btree.js#L1193-L1197
|
|
10,759
|
google/lovefield
|
demos/moviedb/demo-jquery.js
|
selectAllMovies
|
function selectAllMovies() {
var movie = db.getSchema().table('Movie');
db.select(movie.id, movie.title, movie.year).
from(movie).exec().then(
function(results) {
var elapsed = Date.now() - startTime;
$('#load_time').text(elapsed.toString() + 'ms');
$('#master').bootstrapTable('load', results).
on('click-row.bs.table', function(e, row, $element) {
startTime = Date.now();
generateDetails(row.id);
});
});
}
|
javascript
|
function selectAllMovies() {
var movie = db.getSchema().table('Movie');
db.select(movie.id, movie.title, movie.year).
from(movie).exec().then(
function(results) {
var elapsed = Date.now() - startTime;
$('#load_time').text(elapsed.toString() + 'ms');
$('#master').bootstrapTable('load', results).
on('click-row.bs.table', function(e, row, $element) {
startTime = Date.now();
generateDetails(row.id);
});
});
}
|
[
"function",
"selectAllMovies",
"(",
")",
"{",
"var",
"movie",
"=",
"db",
".",
"getSchema",
"(",
")",
".",
"table",
"(",
"'Movie'",
")",
";",
"db",
".",
"select",
"(",
"movie",
".",
"id",
",",
"movie",
".",
"title",
",",
"movie",
".",
"year",
")",
".",
"from",
"(",
"movie",
")",
".",
"exec",
"(",
")",
".",
"then",
"(",
"function",
"(",
"results",
")",
"{",
"var",
"elapsed",
"=",
"Date",
".",
"now",
"(",
")",
"-",
"startTime",
";",
"$",
"(",
"'#load_time'",
")",
".",
"text",
"(",
"elapsed",
".",
"toString",
"(",
")",
"+",
"'ms'",
")",
";",
"$",
"(",
"'#master'",
")",
".",
"bootstrapTable",
"(",
"'load'",
",",
"results",
")",
".",
"on",
"(",
"'click-row.bs.table'",
",",
"function",
"(",
"e",
",",
"row",
",",
"$element",
")",
"{",
"startTime",
"=",
"Date",
".",
"now",
"(",
")",
";",
"generateDetails",
"(",
"row",
".",
"id",
")",
";",
"}",
")",
";",
"}",
")",
";",
"}"
] |
Selects all movies.
|
[
"Selects",
"all",
"movies",
"."
] |
46f70024af70dd665d790170700a3c109b4922f5
|
https://github.com/google/lovefield/blob/46f70024af70dd665d790170700a3c109b4922f5/demos/moviedb/demo-jquery.js#L148-L161
|
10,760
|
google/lovefield
|
demos/moviedb/demo-jquery.js
|
generateDetails
|
function generateDetails(id) {
var m = db.getSchema().table('Movie');
var ma = db.getSchema().table('MovieActor');
var md = db.getSchema().table('MovieDirector');
var a = db.getSchema().table('Actor');
var d = db.getSchema().table('Director');
var details = {};
var promises = [];
promises.push(
db.select().
from(m).
where(m.id.eq(id)).
exec().
then(function(rows) {
details['title'] = rows[0]['title'];
details['year'] = rows[0]['year'];
details['rating'] = rows[0]['rating'];
details['company'] = rows[0]['company'];
}));
promises.push(
db.select().
from(ma).
innerJoin(a, a.id.eq(ma.actorId)).
where(ma.movieId.eq(id)).
orderBy(a.lastName).
exec().then(function(rows) {
details['actors'] = rows.map(function(row) {
return row['Actor']['lastName'] + ', ' +
row['Actor']['firstName'];
}).join('<br/>');
}));
promises.push(
db.select().
from(md, d).
where(lf.op.and(md.movieId.eq(id), d.id.eq(md.directorId))).
orderBy(d.lastName).
exec().then(function(rows) {
details['directors'] = rows.map(function(row) {
return row['Director']['lastName'] + ', ' +
row['Director']['firstName'];
}).join('<br/>');
}));
Promise.all(promises).then(function() {
displayDetails(details);
});
}
|
javascript
|
function generateDetails(id) {
var m = db.getSchema().table('Movie');
var ma = db.getSchema().table('MovieActor');
var md = db.getSchema().table('MovieDirector');
var a = db.getSchema().table('Actor');
var d = db.getSchema().table('Director');
var details = {};
var promises = [];
promises.push(
db.select().
from(m).
where(m.id.eq(id)).
exec().
then(function(rows) {
details['title'] = rows[0]['title'];
details['year'] = rows[0]['year'];
details['rating'] = rows[0]['rating'];
details['company'] = rows[0]['company'];
}));
promises.push(
db.select().
from(ma).
innerJoin(a, a.id.eq(ma.actorId)).
where(ma.movieId.eq(id)).
orderBy(a.lastName).
exec().then(function(rows) {
details['actors'] = rows.map(function(row) {
return row['Actor']['lastName'] + ', ' +
row['Actor']['firstName'];
}).join('<br/>');
}));
promises.push(
db.select().
from(md, d).
where(lf.op.and(md.movieId.eq(id), d.id.eq(md.directorId))).
orderBy(d.lastName).
exec().then(function(rows) {
details['directors'] = rows.map(function(row) {
return row['Director']['lastName'] + ', ' +
row['Director']['firstName'];
}).join('<br/>');
}));
Promise.all(promises).then(function() {
displayDetails(details);
});
}
|
[
"function",
"generateDetails",
"(",
"id",
")",
"{",
"var",
"m",
"=",
"db",
".",
"getSchema",
"(",
")",
".",
"table",
"(",
"'Movie'",
")",
";",
"var",
"ma",
"=",
"db",
".",
"getSchema",
"(",
")",
".",
"table",
"(",
"'MovieActor'",
")",
";",
"var",
"md",
"=",
"db",
".",
"getSchema",
"(",
")",
".",
"table",
"(",
"'MovieDirector'",
")",
";",
"var",
"a",
"=",
"db",
".",
"getSchema",
"(",
")",
".",
"table",
"(",
"'Actor'",
")",
";",
"var",
"d",
"=",
"db",
".",
"getSchema",
"(",
")",
".",
"table",
"(",
"'Director'",
")",
";",
"var",
"details",
"=",
"{",
"}",
";",
"var",
"promises",
"=",
"[",
"]",
";",
"promises",
".",
"push",
"(",
"db",
".",
"select",
"(",
")",
".",
"from",
"(",
"m",
")",
".",
"where",
"(",
"m",
".",
"id",
".",
"eq",
"(",
"id",
")",
")",
".",
"exec",
"(",
")",
".",
"then",
"(",
"function",
"(",
"rows",
")",
"{",
"details",
"[",
"'title'",
"]",
"=",
"rows",
"[",
"0",
"]",
"[",
"'title'",
"]",
";",
"details",
"[",
"'year'",
"]",
"=",
"rows",
"[",
"0",
"]",
"[",
"'year'",
"]",
";",
"details",
"[",
"'rating'",
"]",
"=",
"rows",
"[",
"0",
"]",
"[",
"'rating'",
"]",
";",
"details",
"[",
"'company'",
"]",
"=",
"rows",
"[",
"0",
"]",
"[",
"'company'",
"]",
";",
"}",
")",
")",
";",
"promises",
".",
"push",
"(",
"db",
".",
"select",
"(",
")",
".",
"from",
"(",
"ma",
")",
".",
"innerJoin",
"(",
"a",
",",
"a",
".",
"id",
".",
"eq",
"(",
"ma",
".",
"actorId",
")",
")",
".",
"where",
"(",
"ma",
".",
"movieId",
".",
"eq",
"(",
"id",
")",
")",
".",
"orderBy",
"(",
"a",
".",
"lastName",
")",
".",
"exec",
"(",
")",
".",
"then",
"(",
"function",
"(",
"rows",
")",
"{",
"details",
"[",
"'actors'",
"]",
"=",
"rows",
".",
"map",
"(",
"function",
"(",
"row",
")",
"{",
"return",
"row",
"[",
"'Actor'",
"]",
"[",
"'lastName'",
"]",
"+",
"', '",
"+",
"row",
"[",
"'Actor'",
"]",
"[",
"'firstName'",
"]",
";",
"}",
")",
".",
"join",
"(",
"'<br/>'",
")",
";",
"}",
")",
")",
";",
"promises",
".",
"push",
"(",
"db",
".",
"select",
"(",
")",
".",
"from",
"(",
"md",
",",
"d",
")",
".",
"where",
"(",
"lf",
".",
"op",
".",
"and",
"(",
"md",
".",
"movieId",
".",
"eq",
"(",
"id",
")",
",",
"d",
".",
"id",
".",
"eq",
"(",
"md",
".",
"directorId",
")",
")",
")",
".",
"orderBy",
"(",
"d",
".",
"lastName",
")",
".",
"exec",
"(",
")",
".",
"then",
"(",
"function",
"(",
"rows",
")",
"{",
"details",
"[",
"'directors'",
"]",
"=",
"rows",
".",
"map",
"(",
"function",
"(",
"row",
")",
"{",
"return",
"row",
"[",
"'Director'",
"]",
"[",
"'lastName'",
"]",
"+",
"', '",
"+",
"row",
"[",
"'Director'",
"]",
"[",
"'firstName'",
"]",
";",
"}",
")",
".",
"join",
"(",
"'<br/>'",
")",
";",
"}",
")",
")",
";",
"Promise",
".",
"all",
"(",
"promises",
")",
".",
"then",
"(",
"function",
"(",
")",
"{",
"displayDetails",
"(",
"details",
")",
";",
"}",
")",
";",
"}"
] |
Display details results for selected movie.
@param {string} id
|
[
"Display",
"details",
"results",
"for",
"selected",
"movie",
"."
] |
46f70024af70dd665d790170700a3c109b4922f5
|
https://github.com/google/lovefield/blob/46f70024af70dd665d790170700a3c109b4922f5/demos/moviedb/demo-jquery.js#L168-L214
|
10,761
|
google/lovefield
|
tools/node_bootstrap.js
|
bootstrap
|
function bootstrap(lovefieldBinary) {
// Setting "window" to be Node's global context.
global.window = global;
// Setting "self" to be Node's global context. This must be placed after
// global.window.
global.self = global;
// Setting "document" to a dummy object, even though it is not actually used,
// because it results in a runtime error when using lovefield.min.js.
global.document = {};
vmMod.runInThisContext(fsMod.readFileSync(lovefieldBinary), lovefieldBinary);
}
|
javascript
|
function bootstrap(lovefieldBinary) {
// Setting "window" to be Node's global context.
global.window = global;
// Setting "self" to be Node's global context. This must be placed after
// global.window.
global.self = global;
// Setting "document" to a dummy object, even though it is not actually used,
// because it results in a runtime error when using lovefield.min.js.
global.document = {};
vmMod.runInThisContext(fsMod.readFileSync(lovefieldBinary), lovefieldBinary);
}
|
[
"function",
"bootstrap",
"(",
"lovefieldBinary",
")",
"{",
"// Setting \"window\" to be Node's global context.",
"global",
".",
"window",
"=",
"global",
";",
"// Setting \"self\" to be Node's global context. This must be placed after",
"// global.window.",
"global",
".",
"self",
"=",
"global",
";",
"// Setting \"document\" to a dummy object, even though it is not actually used,",
"// because it results in a runtime error when using lovefield.min.js.",
"global",
".",
"document",
"=",
"{",
"}",
";",
"vmMod",
".",
"runInThisContext",
"(",
"fsMod",
".",
"readFileSync",
"(",
"lovefieldBinary",
")",
",",
"lovefieldBinary",
")",
";",
"}"
] |
Bootstraps a lovefield binary such that is runnable in nodejs.
@param {string} lovefieldBinary The aboslute path of the binary file.
|
[
"Bootstraps",
"a",
"lovefield",
"binary",
"such",
"that",
"is",
"runnable",
"in",
"nodejs",
"."
] |
46f70024af70dd665d790170700a3c109b4922f5
|
https://github.com/google/lovefield/blob/46f70024af70dd665d790170700a3c109b4922f5/tools/node_bootstrap.js#L35-L48
|
10,762
|
google/lovefield
|
tools/builder.js
|
runSpac
|
function runSpac(schemaFilePath, namespace, outputDir) {
var spacPath = pathMod.resolve(pathMod.join(__dirname, '../spac/spac.js'));
var spac = childProcess.fork(
spacPath,
[
'--schema=' + schemaFilePath,
'--namespace=' + namespace,
'--outputdir=' + outputDir,
'--nocombine=true'
]);
return new Promise(function(resolve, reject) {
spac.on('close', function(code) {
if (code == 0) {
resolve();
} else {
var error = new Error(
'ERROR: unable to generate code from ' + schemaFilePath + '\r\n');
log(error);
reject(error);
}
});
});
}
|
javascript
|
function runSpac(schemaFilePath, namespace, outputDir) {
var spacPath = pathMod.resolve(pathMod.join(__dirname, '../spac/spac.js'));
var spac = childProcess.fork(
spacPath,
[
'--schema=' + schemaFilePath,
'--namespace=' + namespace,
'--outputdir=' + outputDir,
'--nocombine=true'
]);
return new Promise(function(resolve, reject) {
spac.on('close', function(code) {
if (code == 0) {
resolve();
} else {
var error = new Error(
'ERROR: unable to generate code from ' + schemaFilePath + '\r\n');
log(error);
reject(error);
}
});
});
}
|
[
"function",
"runSpac",
"(",
"schemaFilePath",
",",
"namespace",
",",
"outputDir",
")",
"{",
"var",
"spacPath",
"=",
"pathMod",
".",
"resolve",
"(",
"pathMod",
".",
"join",
"(",
"__dirname",
",",
"'../spac/spac.js'",
")",
")",
";",
"var",
"spac",
"=",
"childProcess",
".",
"fork",
"(",
"spacPath",
",",
"[",
"'--schema='",
"+",
"schemaFilePath",
",",
"'--namespace='",
"+",
"namespace",
",",
"'--outputdir='",
"+",
"outputDir",
",",
"'--nocombine=true'",
"]",
")",
";",
"return",
"new",
"Promise",
"(",
"function",
"(",
"resolve",
",",
"reject",
")",
"{",
"spac",
".",
"on",
"(",
"'close'",
",",
"function",
"(",
"code",
")",
"{",
"if",
"(",
"code",
"==",
"0",
")",
"{",
"resolve",
"(",
")",
";",
"}",
"else",
"{",
"var",
"error",
"=",
"new",
"Error",
"(",
"'ERROR: unable to generate code from '",
"+",
"schemaFilePath",
"+",
"'\\r\\n'",
")",
";",
"log",
"(",
"error",
")",
";",
"reject",
"(",
"error",
")",
";",
"}",
"}",
")",
";",
"}",
")",
";",
"}"
] |
Runs SPAC to generate code.
@param {string} schemaFilePath
@param {string} namespace
@param {string} outputDir
@return {!IThenable}
|
[
"Runs",
"SPAC",
"to",
"generate",
"code",
"."
] |
46f70024af70dd665d790170700a3c109b4922f5
|
https://github.com/google/lovefield/blob/46f70024af70dd665d790170700a3c109b4922f5/tools/builder.js#L219-L242
|
10,763
|
google/lovefield
|
spac/codegen.js
|
function(col, defaultValue) {
var lhs = ' ' + prefix + '.' + col.getName() + ' = ';
body.push(lhs + (col.isNullable() ? 'null' : defaultValue) + ';');
}
|
javascript
|
function(col, defaultValue) {
var lhs = ' ' + prefix + '.' + col.getName() + ' = ';
body.push(lhs + (col.isNullable() ? 'null' : defaultValue) + ';');
}
|
[
"function",
"(",
"col",
",",
"defaultValue",
")",
"{",
"var",
"lhs",
"=",
"' '",
"+",
"prefix",
"+",
"'.'",
"+",
"col",
".",
"getName",
"(",
")",
"+",
"' = '",
";",
"body",
".",
"push",
"(",
"lhs",
"+",
"(",
"col",
".",
"isNullable",
"(",
")",
"?",
"'null'",
":",
"defaultValue",
")",
"+",
"';'",
")",
";",
"}"
] |
Object body for UserType default object.
@param {!lf.schema.Column} col
@param {string} defaultValue
|
[
"Object",
"body",
"for",
"UserType",
"default",
"object",
"."
] |
46f70024af70dd665d790170700a3c109b4922f5
|
https://github.com/google/lovefield/blob/46f70024af70dd665d790170700a3c109b4922f5/spac/codegen.js#L318-L321
|
|
10,764
|
akxcv/vuera
|
dist/vuera.cjs.js
|
babelReactResolver$$1
|
function babelReactResolver$$1(component, props, children) {
return isReactComponent(component) ? React.createElement(component, props, children) : React.createElement(VueContainer, Object.assign({ component: component }, props), children);
}
|
javascript
|
function babelReactResolver$$1(component, props, children) {
return isReactComponent(component) ? React.createElement(component, props, children) : React.createElement(VueContainer, Object.assign({ component: component }, props), children);
}
|
[
"function",
"babelReactResolver$$1",
"(",
"component",
",",
"props",
",",
"children",
")",
"{",
"return",
"isReactComponent",
"(",
"component",
")",
"?",
"React",
".",
"createElement",
"(",
"component",
",",
"props",
",",
"children",
")",
":",
"React",
".",
"createElement",
"(",
"VueContainer",
",",
"Object",
".",
"assign",
"(",
"{",
"component",
":",
"component",
"}",
",",
"props",
")",
",",
"children",
")",
";",
"}"
] |
This function gets imported by the babel plugin. It wraps a suspected React element and, if it
isn't a valid React element, wraps it into a Vue container.
|
[
"This",
"function",
"gets",
"imported",
"by",
"the",
"babel",
"plugin",
".",
"It",
"wraps",
"a",
"suspected",
"React",
"element",
"and",
"if",
"it",
"isn",
"t",
"a",
"valid",
"React",
"element",
"wraps",
"it",
"into",
"a",
"Vue",
"container",
"."
] |
246a58c4750f4ee5a4a5980810babecac2c87c20
|
https://github.com/akxcv/vuera/blob/246a58c4750f4ee5a4a5980810babecac2c87c20/dist/vuera.cjs.js#L479-L481
|
10,765
|
ericf/express-handlebars
|
examples/advanced/server.js
|
exposeTemplates
|
function exposeTemplates(req, res, next) {
// Uses the `ExpressHandlebars` instance to get the get the **precompiled**
// templates which will be shared with the client-side of the app.
hbs.getTemplates('shared/templates/', {
cache : app.enabled('view cache'),
precompiled: true
}).then(function (templates) {
// RegExp to remove the ".handlebars" extension from the template names.
var extRegex = new RegExp(hbs.extname + '$');
// Creates an array of templates which are exposed via
// `res.locals.templates`.
templates = Object.keys(templates).map(function (name) {
return {
name : name.replace(extRegex, ''),
template: templates[name]
};
});
// Exposes the templates during view rendering.
if (templates.length) {
res.locals.templates = templates;
}
setImmediate(next);
})
.catch(next);
}
|
javascript
|
function exposeTemplates(req, res, next) {
// Uses the `ExpressHandlebars` instance to get the get the **precompiled**
// templates which will be shared with the client-side of the app.
hbs.getTemplates('shared/templates/', {
cache : app.enabled('view cache'),
precompiled: true
}).then(function (templates) {
// RegExp to remove the ".handlebars" extension from the template names.
var extRegex = new RegExp(hbs.extname + '$');
// Creates an array of templates which are exposed via
// `res.locals.templates`.
templates = Object.keys(templates).map(function (name) {
return {
name : name.replace(extRegex, ''),
template: templates[name]
};
});
// Exposes the templates during view rendering.
if (templates.length) {
res.locals.templates = templates;
}
setImmediate(next);
})
.catch(next);
}
|
[
"function",
"exposeTemplates",
"(",
"req",
",",
"res",
",",
"next",
")",
"{",
"// Uses the `ExpressHandlebars` instance to get the get the **precompiled**",
"// templates which will be shared with the client-side of the app.",
"hbs",
".",
"getTemplates",
"(",
"'shared/templates/'",
",",
"{",
"cache",
":",
"app",
".",
"enabled",
"(",
"'view cache'",
")",
",",
"precompiled",
":",
"true",
"}",
")",
".",
"then",
"(",
"function",
"(",
"templates",
")",
"{",
"// RegExp to remove the \".handlebars\" extension from the template names.",
"var",
"extRegex",
"=",
"new",
"RegExp",
"(",
"hbs",
".",
"extname",
"+",
"'$'",
")",
";",
"// Creates an array of templates which are exposed via",
"// `res.locals.templates`.",
"templates",
"=",
"Object",
".",
"keys",
"(",
"templates",
")",
".",
"map",
"(",
"function",
"(",
"name",
")",
"{",
"return",
"{",
"name",
":",
"name",
".",
"replace",
"(",
"extRegex",
",",
"''",
")",
",",
"template",
":",
"templates",
"[",
"name",
"]",
"}",
";",
"}",
")",
";",
"// Exposes the templates during view rendering.",
"if",
"(",
"templates",
".",
"length",
")",
"{",
"res",
".",
"locals",
".",
"templates",
"=",
"templates",
";",
"}",
"setImmediate",
"(",
"next",
")",
";",
"}",
")",
".",
"catch",
"(",
"next",
")",
";",
"}"
] |
Middleware to expose the app's shared templates to the client-side of the app for pages which need them.
|
[
"Middleware",
"to",
"expose",
"the",
"app",
"s",
"shared",
"templates",
"to",
"the",
"client",
"-",
"side",
"of",
"the",
"app",
"for",
"pages",
"which",
"need",
"them",
"."
] |
6ce977a541d50d1b7d7bd42fadf782a48899e29a
|
https://github.com/ericf/express-handlebars/blob/6ce977a541d50d1b7d7bd42fadf782a48899e29a/examples/advanced/server.js#L30-L57
|
10,766
|
openseadragon/openseadragon
|
src/control.js
|
function( opacity ) {
if ( this.element[ $.SIGNAL ] && $.Browser.vendor == $.BROWSERS.IE ) {
$.setElementOpacity( this.element, opacity, true );
} else {
$.setElementOpacity( this.wrapper, opacity, true );
}
}
|
javascript
|
function( opacity ) {
if ( this.element[ $.SIGNAL ] && $.Browser.vendor == $.BROWSERS.IE ) {
$.setElementOpacity( this.element, opacity, true );
} else {
$.setElementOpacity( this.wrapper, opacity, true );
}
}
|
[
"function",
"(",
"opacity",
")",
"{",
"if",
"(",
"this",
".",
"element",
"[",
"$",
".",
"SIGNAL",
"]",
"&&",
"$",
".",
"Browser",
".",
"vendor",
"==",
"$",
".",
"BROWSERS",
".",
"IE",
")",
"{",
"$",
".",
"setElementOpacity",
"(",
"this",
".",
"element",
",",
"opacity",
",",
"true",
")",
";",
"}",
"else",
"{",
"$",
".",
"setElementOpacity",
"(",
"this",
".",
"wrapper",
",",
"opacity",
",",
"true",
")",
";",
"}",
"}"
] |
Sets the opacity level for the control.
@function
@param {Number} opactiy - a value between 1 and 0 inclusively.
|
[
"Sets",
"the",
"opacity",
"level",
"for",
"the",
"control",
"."
] |
e7108f23602575fc6eb152d4b82a8b44b2ca698e
|
https://github.com/openseadragon/openseadragon/blob/e7108f23602575fc6eb152d4b82a8b44b2ca698e/src/control.js#L192-L198
|
|
10,767
|
openseadragon/openseadragon
|
src/navigator.js
|
function( viewport ) {
var viewerSize,
newWidth,
newHeight,
bounds,
topleft,
bottomright;
viewerSize = $.getElementSize( this.viewer.element );
if ( this._resizeWithViewer && viewerSize.x && viewerSize.y && !viewerSize.equals( this.oldViewerSize ) ) {
this.oldViewerSize = viewerSize;
if ( this.maintainSizeRatio || !this.elementArea) {
newWidth = viewerSize.x * this.sizeRatio;
newHeight = viewerSize.y * this.sizeRatio;
} else {
newWidth = Math.sqrt(this.elementArea * (viewerSize.x / viewerSize.y));
newHeight = this.elementArea / newWidth;
}
this.element.style.width = Math.round( newWidth ) + 'px';
this.element.style.height = Math.round( newHeight ) + 'px';
if (!this.elementArea) {
this.elementArea = newWidth * newHeight;
}
this.updateSize();
}
if (viewport && this.viewport) {
bounds = viewport.getBoundsNoRotate(true);
topleft = this.viewport.pixelFromPointNoRotate(bounds.getTopLeft(), false);
bottomright = this.viewport.pixelFromPointNoRotate(bounds.getBottomRight(), false)
.minus( this.totalBorderWidths );
//update style for navigator-box
var style = this.displayRegion.style;
style.display = this.world.getItemCount() ? 'block' : 'none';
style.top = Math.round( topleft.y ) + 'px';
style.left = Math.round( topleft.x ) + 'px';
var width = Math.abs( topleft.x - bottomright.x );
var height = Math.abs( topleft.y - bottomright.y );
// make sure width and height are non-negative so IE doesn't throw
style.width = Math.round( Math.max( width, 0 ) ) + 'px';
style.height = Math.round( Math.max( height, 0 ) ) + 'px';
}
}
|
javascript
|
function( viewport ) {
var viewerSize,
newWidth,
newHeight,
bounds,
topleft,
bottomright;
viewerSize = $.getElementSize( this.viewer.element );
if ( this._resizeWithViewer && viewerSize.x && viewerSize.y && !viewerSize.equals( this.oldViewerSize ) ) {
this.oldViewerSize = viewerSize;
if ( this.maintainSizeRatio || !this.elementArea) {
newWidth = viewerSize.x * this.sizeRatio;
newHeight = viewerSize.y * this.sizeRatio;
} else {
newWidth = Math.sqrt(this.elementArea * (viewerSize.x / viewerSize.y));
newHeight = this.elementArea / newWidth;
}
this.element.style.width = Math.round( newWidth ) + 'px';
this.element.style.height = Math.round( newHeight ) + 'px';
if (!this.elementArea) {
this.elementArea = newWidth * newHeight;
}
this.updateSize();
}
if (viewport && this.viewport) {
bounds = viewport.getBoundsNoRotate(true);
topleft = this.viewport.pixelFromPointNoRotate(bounds.getTopLeft(), false);
bottomright = this.viewport.pixelFromPointNoRotate(bounds.getBottomRight(), false)
.minus( this.totalBorderWidths );
//update style for navigator-box
var style = this.displayRegion.style;
style.display = this.world.getItemCount() ? 'block' : 'none';
style.top = Math.round( topleft.y ) + 'px';
style.left = Math.round( topleft.x ) + 'px';
var width = Math.abs( topleft.x - bottomright.x );
var height = Math.abs( topleft.y - bottomright.y );
// make sure width and height are non-negative so IE doesn't throw
style.width = Math.round( Math.max( width, 0 ) ) + 'px';
style.height = Math.round( Math.max( height, 0 ) ) + 'px';
}
}
|
[
"function",
"(",
"viewport",
")",
"{",
"var",
"viewerSize",
",",
"newWidth",
",",
"newHeight",
",",
"bounds",
",",
"topleft",
",",
"bottomright",
";",
"viewerSize",
"=",
"$",
".",
"getElementSize",
"(",
"this",
".",
"viewer",
".",
"element",
")",
";",
"if",
"(",
"this",
".",
"_resizeWithViewer",
"&&",
"viewerSize",
".",
"x",
"&&",
"viewerSize",
".",
"y",
"&&",
"!",
"viewerSize",
".",
"equals",
"(",
"this",
".",
"oldViewerSize",
")",
")",
"{",
"this",
".",
"oldViewerSize",
"=",
"viewerSize",
";",
"if",
"(",
"this",
".",
"maintainSizeRatio",
"||",
"!",
"this",
".",
"elementArea",
")",
"{",
"newWidth",
"=",
"viewerSize",
".",
"x",
"*",
"this",
".",
"sizeRatio",
";",
"newHeight",
"=",
"viewerSize",
".",
"y",
"*",
"this",
".",
"sizeRatio",
";",
"}",
"else",
"{",
"newWidth",
"=",
"Math",
".",
"sqrt",
"(",
"this",
".",
"elementArea",
"*",
"(",
"viewerSize",
".",
"x",
"/",
"viewerSize",
".",
"y",
")",
")",
";",
"newHeight",
"=",
"this",
".",
"elementArea",
"/",
"newWidth",
";",
"}",
"this",
".",
"element",
".",
"style",
".",
"width",
"=",
"Math",
".",
"round",
"(",
"newWidth",
")",
"+",
"'px'",
";",
"this",
".",
"element",
".",
"style",
".",
"height",
"=",
"Math",
".",
"round",
"(",
"newHeight",
")",
"+",
"'px'",
";",
"if",
"(",
"!",
"this",
".",
"elementArea",
")",
"{",
"this",
".",
"elementArea",
"=",
"newWidth",
"*",
"newHeight",
";",
"}",
"this",
".",
"updateSize",
"(",
")",
";",
"}",
"if",
"(",
"viewport",
"&&",
"this",
".",
"viewport",
")",
"{",
"bounds",
"=",
"viewport",
".",
"getBoundsNoRotate",
"(",
"true",
")",
";",
"topleft",
"=",
"this",
".",
"viewport",
".",
"pixelFromPointNoRotate",
"(",
"bounds",
".",
"getTopLeft",
"(",
")",
",",
"false",
")",
";",
"bottomright",
"=",
"this",
".",
"viewport",
".",
"pixelFromPointNoRotate",
"(",
"bounds",
".",
"getBottomRight",
"(",
")",
",",
"false",
")",
".",
"minus",
"(",
"this",
".",
"totalBorderWidths",
")",
";",
"//update style for navigator-box",
"var",
"style",
"=",
"this",
".",
"displayRegion",
".",
"style",
";",
"style",
".",
"display",
"=",
"this",
".",
"world",
".",
"getItemCount",
"(",
")",
"?",
"'block'",
":",
"'none'",
";",
"style",
".",
"top",
"=",
"Math",
".",
"round",
"(",
"topleft",
".",
"y",
")",
"+",
"'px'",
";",
"style",
".",
"left",
"=",
"Math",
".",
"round",
"(",
"topleft",
".",
"x",
")",
"+",
"'px'",
";",
"var",
"width",
"=",
"Math",
".",
"abs",
"(",
"topleft",
".",
"x",
"-",
"bottomright",
".",
"x",
")",
";",
"var",
"height",
"=",
"Math",
".",
"abs",
"(",
"topleft",
".",
"y",
"-",
"bottomright",
".",
"y",
")",
";",
"// make sure width and height are non-negative so IE doesn't throw",
"style",
".",
"width",
"=",
"Math",
".",
"round",
"(",
"Math",
".",
"max",
"(",
"width",
",",
"0",
")",
")",
"+",
"'px'",
";",
"style",
".",
"height",
"=",
"Math",
".",
"round",
"(",
"Math",
".",
"max",
"(",
"height",
",",
"0",
")",
")",
"+",
"'px'",
";",
"}",
"}"
] |
Used to update the navigator minimap's viewport rectangle when a change in the viewer's viewport occurs.
@function
@param {OpenSeadragon.Viewport} The viewport this navigator is tracking.
|
[
"Used",
"to",
"update",
"the",
"navigator",
"minimap",
"s",
"viewport",
"rectangle",
"when",
"a",
"change",
"in",
"the",
"viewer",
"s",
"viewport",
"occurs",
"."
] |
e7108f23602575fc6eb152d4b82a8b44b2ca698e
|
https://github.com/openseadragon/openseadragon/blob/e7108f23602575fc6eb152d4b82a8b44b2ca698e/src/navigator.js#L302-L353
|
|
10,768
|
openseadragon/openseadragon
|
src/navigator.js
|
function(options) {
var _this = this;
var original = options.originalTiledImage;
delete options.original;
var optionsClone = $.extend({}, options, {
success: function(event) {
var myItem = event.item;
myItem._originalForNavigator = original;
_this._matchBounds(myItem, original, true);
function matchBounds() {
_this._matchBounds(myItem, original);
}
function matchOpacity() {
_this._matchOpacity(myItem, original);
}
function matchCompositeOperation() {
_this._matchCompositeOperation(myItem, original);
}
original.addHandler('bounds-change', matchBounds);
original.addHandler('clip-change', matchBounds);
original.addHandler('opacity-change', matchOpacity);
original.addHandler('composite-operation-change', matchCompositeOperation);
}
});
return $.Viewer.prototype.addTiledImage.apply(this, [optionsClone]);
}
|
javascript
|
function(options) {
var _this = this;
var original = options.originalTiledImage;
delete options.original;
var optionsClone = $.extend({}, options, {
success: function(event) {
var myItem = event.item;
myItem._originalForNavigator = original;
_this._matchBounds(myItem, original, true);
function matchBounds() {
_this._matchBounds(myItem, original);
}
function matchOpacity() {
_this._matchOpacity(myItem, original);
}
function matchCompositeOperation() {
_this._matchCompositeOperation(myItem, original);
}
original.addHandler('bounds-change', matchBounds);
original.addHandler('clip-change', matchBounds);
original.addHandler('opacity-change', matchOpacity);
original.addHandler('composite-operation-change', matchCompositeOperation);
}
});
return $.Viewer.prototype.addTiledImage.apply(this, [optionsClone]);
}
|
[
"function",
"(",
"options",
")",
"{",
"var",
"_this",
"=",
"this",
";",
"var",
"original",
"=",
"options",
".",
"originalTiledImage",
";",
"delete",
"options",
".",
"original",
";",
"var",
"optionsClone",
"=",
"$",
".",
"extend",
"(",
"{",
"}",
",",
"options",
",",
"{",
"success",
":",
"function",
"(",
"event",
")",
"{",
"var",
"myItem",
"=",
"event",
".",
"item",
";",
"myItem",
".",
"_originalForNavigator",
"=",
"original",
";",
"_this",
".",
"_matchBounds",
"(",
"myItem",
",",
"original",
",",
"true",
")",
";",
"function",
"matchBounds",
"(",
")",
"{",
"_this",
".",
"_matchBounds",
"(",
"myItem",
",",
"original",
")",
";",
"}",
"function",
"matchOpacity",
"(",
")",
"{",
"_this",
".",
"_matchOpacity",
"(",
"myItem",
",",
"original",
")",
";",
"}",
"function",
"matchCompositeOperation",
"(",
")",
"{",
"_this",
".",
"_matchCompositeOperation",
"(",
"myItem",
",",
"original",
")",
";",
"}",
"original",
".",
"addHandler",
"(",
"'bounds-change'",
",",
"matchBounds",
")",
";",
"original",
".",
"addHandler",
"(",
"'clip-change'",
",",
"matchBounds",
")",
";",
"original",
".",
"addHandler",
"(",
"'opacity-change'",
",",
"matchOpacity",
")",
";",
"original",
".",
"addHandler",
"(",
"'composite-operation-change'",
",",
"matchCompositeOperation",
")",
";",
"}",
"}",
")",
";",
"return",
"$",
".",
"Viewer",
".",
"prototype",
".",
"addTiledImage",
".",
"apply",
"(",
"this",
",",
"[",
"optionsClone",
"]",
")",
";",
"}"
] |
overrides Viewer.addTiledImage
|
[
"overrides",
"Viewer",
".",
"addTiledImage"
] |
e7108f23602575fc6eb152d4b82a8b44b2ca698e
|
https://github.com/openseadragon/openseadragon/blob/e7108f23602575fc6eb152d4b82a8b44b2ca698e/src/navigator.js#L356-L388
|
|
10,769
|
openseadragon/openseadragon
|
src/tiledimage.js
|
function() {
var xUpdated = this._xSpring.update();
var yUpdated = this._ySpring.update();
var scaleUpdated = this._scaleSpring.update();
var degreesUpdated = this._degreesSpring.update();
if (xUpdated || yUpdated || scaleUpdated || degreesUpdated) {
this._updateForScale();
this._needsDraw = true;
return true;
}
return false;
}
|
javascript
|
function() {
var xUpdated = this._xSpring.update();
var yUpdated = this._ySpring.update();
var scaleUpdated = this._scaleSpring.update();
var degreesUpdated = this._degreesSpring.update();
if (xUpdated || yUpdated || scaleUpdated || degreesUpdated) {
this._updateForScale();
this._needsDraw = true;
return true;
}
return false;
}
|
[
"function",
"(",
")",
"{",
"var",
"xUpdated",
"=",
"this",
".",
"_xSpring",
".",
"update",
"(",
")",
";",
"var",
"yUpdated",
"=",
"this",
".",
"_ySpring",
".",
"update",
"(",
")",
";",
"var",
"scaleUpdated",
"=",
"this",
".",
"_scaleSpring",
".",
"update",
"(",
")",
";",
"var",
"degreesUpdated",
"=",
"this",
".",
"_degreesSpring",
".",
"update",
"(",
")",
";",
"if",
"(",
"xUpdated",
"||",
"yUpdated",
"||",
"scaleUpdated",
"||",
"degreesUpdated",
")",
"{",
"this",
".",
"_updateForScale",
"(",
")",
";",
"this",
".",
"_needsDraw",
"=",
"true",
";",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
] |
Updates the TiledImage's bounds, animating if needed.
@returns {Boolean} Whether the TiledImage animated.
|
[
"Updates",
"the",
"TiledImage",
"s",
"bounds",
"animating",
"if",
"needed",
"."
] |
e7108f23602575fc6eb152d4b82a8b44b2ca698e
|
https://github.com/openseadragon/openseadragon/blob/e7108f23602575fc6eb152d4b82a8b44b2ca698e/src/tiledimage.js#L294-L307
|
|
10,770
|
openseadragon/openseadragon
|
src/tiledimage.js
|
function(current) {
return current ?
new $.Rect(
this._xSpring.current.value,
this._ySpring.current.value,
this._worldWidthCurrent,
this._worldHeightCurrent) :
new $.Rect(
this._xSpring.target.value,
this._ySpring.target.value,
this._worldWidthTarget,
this._worldHeightTarget);
}
|
javascript
|
function(current) {
return current ?
new $.Rect(
this._xSpring.current.value,
this._ySpring.current.value,
this._worldWidthCurrent,
this._worldHeightCurrent) :
new $.Rect(
this._xSpring.target.value,
this._ySpring.target.value,
this._worldWidthTarget,
this._worldHeightTarget);
}
|
[
"function",
"(",
"current",
")",
"{",
"return",
"current",
"?",
"new",
"$",
".",
"Rect",
"(",
"this",
".",
"_xSpring",
".",
"current",
".",
"value",
",",
"this",
".",
"_ySpring",
".",
"current",
".",
"value",
",",
"this",
".",
"_worldWidthCurrent",
",",
"this",
".",
"_worldHeightCurrent",
")",
":",
"new",
"$",
".",
"Rect",
"(",
"this",
".",
"_xSpring",
".",
"target",
".",
"value",
",",
"this",
".",
"_ySpring",
".",
"target",
".",
"value",
",",
"this",
".",
"_worldWidthTarget",
",",
"this",
".",
"_worldHeightTarget",
")",
";",
"}"
] |
Get this TiledImage's bounds in viewport coordinates without taking
rotation into account.
@param {Boolean} [current=false] - Pass true for the current location;
false for target location.
@returns {OpenSeadragon.Rect} This TiledImage's bounds in viewport coordinates.
|
[
"Get",
"this",
"TiledImage",
"s",
"bounds",
"in",
"viewport",
"coordinates",
"without",
"taking",
"rotation",
"into",
"account",
"."
] |
e7108f23602575fc6eb152d4b82a8b44b2ca698e
|
https://github.com/openseadragon/openseadragon/blob/e7108f23602575fc6eb152d4b82a8b44b2ca698e/src/tiledimage.js#L349-L361
|
|
10,771
|
openseadragon/openseadragon
|
src/tiledimage.js
|
function(current) {
var bounds = this.getBoundsNoRotate(current);
if (this._clip) {
var worldWidth = current ?
this._worldWidthCurrent : this._worldWidthTarget;
var ratio = worldWidth / this.source.dimensions.x;
var clip = this._clip.times(ratio);
bounds = new $.Rect(
bounds.x + clip.x,
bounds.y + clip.y,
clip.width,
clip.height);
}
return bounds.rotate(this.getRotation(current), this._getRotationPoint(current));
}
|
javascript
|
function(current) {
var bounds = this.getBoundsNoRotate(current);
if (this._clip) {
var worldWidth = current ?
this._worldWidthCurrent : this._worldWidthTarget;
var ratio = worldWidth / this.source.dimensions.x;
var clip = this._clip.times(ratio);
bounds = new $.Rect(
bounds.x + clip.x,
bounds.y + clip.y,
clip.width,
clip.height);
}
return bounds.rotate(this.getRotation(current), this._getRotationPoint(current));
}
|
[
"function",
"(",
"current",
")",
"{",
"var",
"bounds",
"=",
"this",
".",
"getBoundsNoRotate",
"(",
"current",
")",
";",
"if",
"(",
"this",
".",
"_clip",
")",
"{",
"var",
"worldWidth",
"=",
"current",
"?",
"this",
".",
"_worldWidthCurrent",
":",
"this",
".",
"_worldWidthTarget",
";",
"var",
"ratio",
"=",
"worldWidth",
"/",
"this",
".",
"source",
".",
"dimensions",
".",
"x",
";",
"var",
"clip",
"=",
"this",
".",
"_clip",
".",
"times",
"(",
"ratio",
")",
";",
"bounds",
"=",
"new",
"$",
".",
"Rect",
"(",
"bounds",
".",
"x",
"+",
"clip",
".",
"x",
",",
"bounds",
".",
"y",
"+",
"clip",
".",
"y",
",",
"clip",
".",
"width",
",",
"clip",
".",
"height",
")",
";",
"}",
"return",
"bounds",
".",
"rotate",
"(",
"this",
".",
"getRotation",
"(",
"current",
")",
",",
"this",
".",
"_getRotationPoint",
"(",
"current",
")",
")",
";",
"}"
] |
Get the bounds of the displayed part of the tiled image.
@param {Boolean} [current=false] Pass true for the current location,
false for the target location.
@returns {$.Rect} The clipped bounds in viewport coordinates.
|
[
"Get",
"the",
"bounds",
"of",
"the",
"displayed",
"part",
"of",
"the",
"tiled",
"image",
"."
] |
e7108f23602575fc6eb152d4b82a8b44b2ca698e
|
https://github.com/openseadragon/openseadragon/blob/e7108f23602575fc6eb152d4b82a8b44b2ca698e/src/tiledimage.js#L375-L389
|
|
10,772
|
openseadragon/openseadragon
|
src/tiledimage.js
|
function( pixel ) {
var viewerCoordinates = pixel.minus(
OpenSeadragon.getElementPosition( this.viewer.element ));
return this.viewerElementToImageCoordinates( viewerCoordinates );
}
|
javascript
|
function( pixel ) {
var viewerCoordinates = pixel.minus(
OpenSeadragon.getElementPosition( this.viewer.element ));
return this.viewerElementToImageCoordinates( viewerCoordinates );
}
|
[
"function",
"(",
"pixel",
")",
"{",
"var",
"viewerCoordinates",
"=",
"pixel",
".",
"minus",
"(",
"OpenSeadragon",
".",
"getElementPosition",
"(",
"this",
".",
"viewer",
".",
"element",
")",
")",
";",
"return",
"this",
".",
"viewerElementToImageCoordinates",
"(",
"viewerCoordinates",
")",
";",
"}"
] |
Convert pixel coordinates relative to the window to image coordinates.
@param {OpenSeadragon.Point} pixel
@returns {OpenSeadragon.Point}
|
[
"Convert",
"pixel",
"coordinates",
"relative",
"to",
"the",
"window",
"to",
"image",
"coordinates",
"."
] |
e7108f23602575fc6eb152d4b82a8b44b2ca698e
|
https://github.com/openseadragon/openseadragon/blob/e7108f23602575fc6eb152d4b82a8b44b2ca698e/src/tiledimage.js#L559-L563
|
|
10,773
|
openseadragon/openseadragon
|
src/tiledimage.js
|
function( pixel ) {
var viewerCoordinates = this.imageToViewerElementCoordinates( pixel );
return viewerCoordinates.plus(
OpenSeadragon.getElementPosition( this.viewer.element ));
}
|
javascript
|
function( pixel ) {
var viewerCoordinates = this.imageToViewerElementCoordinates( pixel );
return viewerCoordinates.plus(
OpenSeadragon.getElementPosition( this.viewer.element ));
}
|
[
"function",
"(",
"pixel",
")",
"{",
"var",
"viewerCoordinates",
"=",
"this",
".",
"imageToViewerElementCoordinates",
"(",
"pixel",
")",
";",
"return",
"viewerCoordinates",
".",
"plus",
"(",
"OpenSeadragon",
".",
"getElementPosition",
"(",
"this",
".",
"viewer",
".",
"element",
")",
")",
";",
"}"
] |
Convert image coordinates to pixel coordinates relative to the window.
@param {OpenSeadragon.Point} pixel
@returns {OpenSeadragon.Point}
|
[
"Convert",
"image",
"coordinates",
"to",
"pixel",
"coordinates",
"relative",
"to",
"the",
"window",
"."
] |
e7108f23602575fc6eb152d4b82a8b44b2ca698e
|
https://github.com/openseadragon/openseadragon/blob/e7108f23602575fc6eb152d4b82a8b44b2ca698e/src/tiledimage.js#L570-L574
|
|
10,774
|
openseadragon/openseadragon
|
src/tiledimage.js
|
function(position, immediately) {
var sameTarget = (this._xSpring.target.value === position.x &&
this._ySpring.target.value === position.y);
if (immediately) {
if (sameTarget && this._xSpring.current.value === position.x &&
this._ySpring.current.value === position.y) {
return;
}
this._xSpring.resetTo(position.x);
this._ySpring.resetTo(position.y);
this._needsDraw = true;
} else {
if (sameTarget) {
return;
}
this._xSpring.springTo(position.x);
this._ySpring.springTo(position.y);
this._needsDraw = true;
}
if (!sameTarget) {
this._raiseBoundsChange();
}
}
|
javascript
|
function(position, immediately) {
var sameTarget = (this._xSpring.target.value === position.x &&
this._ySpring.target.value === position.y);
if (immediately) {
if (sameTarget && this._xSpring.current.value === position.x &&
this._ySpring.current.value === position.y) {
return;
}
this._xSpring.resetTo(position.x);
this._ySpring.resetTo(position.y);
this._needsDraw = true;
} else {
if (sameTarget) {
return;
}
this._xSpring.springTo(position.x);
this._ySpring.springTo(position.y);
this._needsDraw = true;
}
if (!sameTarget) {
this._raiseBoundsChange();
}
}
|
[
"function",
"(",
"position",
",",
"immediately",
")",
"{",
"var",
"sameTarget",
"=",
"(",
"this",
".",
"_xSpring",
".",
"target",
".",
"value",
"===",
"position",
".",
"x",
"&&",
"this",
".",
"_ySpring",
".",
"target",
".",
"value",
"===",
"position",
".",
"y",
")",
";",
"if",
"(",
"immediately",
")",
"{",
"if",
"(",
"sameTarget",
"&&",
"this",
".",
"_xSpring",
".",
"current",
".",
"value",
"===",
"position",
".",
"x",
"&&",
"this",
".",
"_ySpring",
".",
"current",
".",
"value",
"===",
"position",
".",
"y",
")",
"{",
"return",
";",
"}",
"this",
".",
"_xSpring",
".",
"resetTo",
"(",
"position",
".",
"x",
")",
";",
"this",
".",
"_ySpring",
".",
"resetTo",
"(",
"position",
".",
"y",
")",
";",
"this",
".",
"_needsDraw",
"=",
"true",
";",
"}",
"else",
"{",
"if",
"(",
"sameTarget",
")",
"{",
"return",
";",
"}",
"this",
".",
"_xSpring",
".",
"springTo",
"(",
"position",
".",
"x",
")",
";",
"this",
".",
"_ySpring",
".",
"springTo",
"(",
"position",
".",
"y",
")",
";",
"this",
".",
"_needsDraw",
"=",
"true",
";",
"}",
"if",
"(",
"!",
"sameTarget",
")",
"{",
"this",
".",
"_raiseBoundsChange",
"(",
")",
";",
"}",
"}"
] |
Sets the TiledImage's position in the world.
@param {OpenSeadragon.Point} position - The new position, in viewport coordinates.
@param {Boolean} [immediately=false] - Whether to animate to the new position or snap immediately.
@fires OpenSeadragon.TiledImage.event:bounds-change
|
[
"Sets",
"the",
"TiledImage",
"s",
"position",
"in",
"the",
"world",
"."
] |
e7108f23602575fc6eb152d4b82a8b44b2ca698e
|
https://github.com/openseadragon/openseadragon/blob/e7108f23602575fc6eb152d4b82a8b44b2ca698e/src/tiledimage.js#L629-L655
|
|
10,775
|
openseadragon/openseadragon
|
src/tiledimage.js
|
function(degrees, immediately) {
if (this._degreesSpring.target.value === degrees &&
this._degreesSpring.isAtTargetValue()) {
return;
}
if (immediately) {
this._degreesSpring.resetTo(degrees);
} else {
this._degreesSpring.springTo(degrees);
}
this._needsDraw = true;
this._raiseBoundsChange();
}
|
javascript
|
function(degrees, immediately) {
if (this._degreesSpring.target.value === degrees &&
this._degreesSpring.isAtTargetValue()) {
return;
}
if (immediately) {
this._degreesSpring.resetTo(degrees);
} else {
this._degreesSpring.springTo(degrees);
}
this._needsDraw = true;
this._raiseBoundsChange();
}
|
[
"function",
"(",
"degrees",
",",
"immediately",
")",
"{",
"if",
"(",
"this",
".",
"_degreesSpring",
".",
"target",
".",
"value",
"===",
"degrees",
"&&",
"this",
".",
"_degreesSpring",
".",
"isAtTargetValue",
"(",
")",
")",
"{",
"return",
";",
"}",
"if",
"(",
"immediately",
")",
"{",
"this",
".",
"_degreesSpring",
".",
"resetTo",
"(",
"degrees",
")",
";",
"}",
"else",
"{",
"this",
".",
"_degreesSpring",
".",
"springTo",
"(",
"degrees",
")",
";",
"}",
"this",
".",
"_needsDraw",
"=",
"true",
";",
"this",
".",
"_raiseBoundsChange",
"(",
")",
";",
"}"
] |
Set the current rotation of this tiled image in degrees.
@param {Number} degrees the rotation in degrees.
@param {Boolean} [immediately=false] Whether to animate to the new angle
or rotate immediately.
@fires OpenSeadragon.TiledImage.event:bounds-change
|
[
"Set",
"the",
"current",
"rotation",
"of",
"this",
"tiled",
"image",
"in",
"degrees",
"."
] |
e7108f23602575fc6eb152d4b82a8b44b2ca698e
|
https://github.com/openseadragon/openseadragon/blob/e7108f23602575fc6eb152d4b82a8b44b2ca698e/src/tiledimage.js#L845-L857
|
|
10,776
|
openseadragon/openseadragon
|
src/drawer.js
|
function( opacity ) {
$.console.error("drawer.setOpacity is deprecated. Use tiledImage.setOpacity instead.");
var world = this.viewer.world;
for (var i = 0; i < world.getItemCount(); i++) {
world.getItemAt( i ).setOpacity( opacity );
}
return this;
}
|
javascript
|
function( opacity ) {
$.console.error("drawer.setOpacity is deprecated. Use tiledImage.setOpacity instead.");
var world = this.viewer.world;
for (var i = 0; i < world.getItemCount(); i++) {
world.getItemAt( i ).setOpacity( opacity );
}
return this;
}
|
[
"function",
"(",
"opacity",
")",
"{",
"$",
".",
"console",
".",
"error",
"(",
"\"drawer.setOpacity is deprecated. Use tiledImage.setOpacity instead.\"",
")",
";",
"var",
"world",
"=",
"this",
".",
"viewer",
".",
"world",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"world",
".",
"getItemCount",
"(",
")",
";",
"i",
"++",
")",
"{",
"world",
".",
"getItemAt",
"(",
"i",
")",
".",
"setOpacity",
"(",
"opacity",
")",
";",
"}",
"return",
"this",
";",
"}"
] |
Set the opacity of the drawer.
@param {Number} opacity
@return {OpenSeadragon.Drawer} Chainable.
|
[
"Set",
"the",
"opacity",
"of",
"the",
"drawer",
"."
] |
e7108f23602575fc6eb152d4b82a8b44b2ca698e
|
https://github.com/openseadragon/openseadragon/blob/e7108f23602575fc6eb152d4b82a8b44b2ca698e/src/drawer.js#L174-L181
|
|
10,777
|
openseadragon/openseadragon
|
src/drawer.js
|
function() {
$.console.error("drawer.getOpacity is deprecated. Use tiledImage.getOpacity instead.");
var world = this.viewer.world;
var maxOpacity = 0;
for (var i = 0; i < world.getItemCount(); i++) {
var opacity = world.getItemAt( i ).getOpacity();
if ( opacity > maxOpacity ) {
maxOpacity = opacity;
}
}
return maxOpacity;
}
|
javascript
|
function() {
$.console.error("drawer.getOpacity is deprecated. Use tiledImage.getOpacity instead.");
var world = this.viewer.world;
var maxOpacity = 0;
for (var i = 0; i < world.getItemCount(); i++) {
var opacity = world.getItemAt( i ).getOpacity();
if ( opacity > maxOpacity ) {
maxOpacity = opacity;
}
}
return maxOpacity;
}
|
[
"function",
"(",
")",
"{",
"$",
".",
"console",
".",
"error",
"(",
"\"drawer.getOpacity is deprecated. Use tiledImage.getOpacity instead.\"",
")",
";",
"var",
"world",
"=",
"this",
".",
"viewer",
".",
"world",
";",
"var",
"maxOpacity",
"=",
"0",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"world",
".",
"getItemCount",
"(",
")",
";",
"i",
"++",
")",
"{",
"var",
"opacity",
"=",
"world",
".",
"getItemAt",
"(",
"i",
")",
".",
"getOpacity",
"(",
")",
";",
"if",
"(",
"opacity",
">",
"maxOpacity",
")",
"{",
"maxOpacity",
"=",
"opacity",
";",
"}",
"}",
"return",
"maxOpacity",
";",
"}"
] |
Get the opacity of the drawer.
@returns {Number}
|
[
"Get",
"the",
"opacity",
"of",
"the",
"drawer",
"."
] |
e7108f23602575fc6eb152d4b82a8b44b2ca698e
|
https://github.com/openseadragon/openseadragon/blob/e7108f23602575fc6eb152d4b82a8b44b2ca698e/src/drawer.js#L187-L198
|
|
10,778
|
openseadragon/openseadragon
|
src/drawer.js
|
function() {
this.canvas.innerHTML = "";
if ( this.useCanvas ) {
var viewportSize = this._calculateCanvasSize();
if( this.canvas.width != viewportSize.x ||
this.canvas.height != viewportSize.y ) {
this.canvas.width = viewportSize.x;
this.canvas.height = viewportSize.y;
this._updateImageSmoothingEnabled(this.context);
if ( this.sketchCanvas !== null ) {
var sketchCanvasSize = this._calculateSketchCanvasSize();
this.sketchCanvas.width = sketchCanvasSize.x;
this.sketchCanvas.height = sketchCanvasSize.y;
this._updateImageSmoothingEnabled(this.sketchContext);
}
}
this._clear();
}
}
|
javascript
|
function() {
this.canvas.innerHTML = "";
if ( this.useCanvas ) {
var viewportSize = this._calculateCanvasSize();
if( this.canvas.width != viewportSize.x ||
this.canvas.height != viewportSize.y ) {
this.canvas.width = viewportSize.x;
this.canvas.height = viewportSize.y;
this._updateImageSmoothingEnabled(this.context);
if ( this.sketchCanvas !== null ) {
var sketchCanvasSize = this._calculateSketchCanvasSize();
this.sketchCanvas.width = sketchCanvasSize.x;
this.sketchCanvas.height = sketchCanvasSize.y;
this._updateImageSmoothingEnabled(this.sketchContext);
}
}
this._clear();
}
}
|
[
"function",
"(",
")",
"{",
"this",
".",
"canvas",
".",
"innerHTML",
"=",
"\"\"",
";",
"if",
"(",
"this",
".",
"useCanvas",
")",
"{",
"var",
"viewportSize",
"=",
"this",
".",
"_calculateCanvasSize",
"(",
")",
";",
"if",
"(",
"this",
".",
"canvas",
".",
"width",
"!=",
"viewportSize",
".",
"x",
"||",
"this",
".",
"canvas",
".",
"height",
"!=",
"viewportSize",
".",
"y",
")",
"{",
"this",
".",
"canvas",
".",
"width",
"=",
"viewportSize",
".",
"x",
";",
"this",
".",
"canvas",
".",
"height",
"=",
"viewportSize",
".",
"y",
";",
"this",
".",
"_updateImageSmoothingEnabled",
"(",
"this",
".",
"context",
")",
";",
"if",
"(",
"this",
".",
"sketchCanvas",
"!==",
"null",
")",
"{",
"var",
"sketchCanvasSize",
"=",
"this",
".",
"_calculateSketchCanvasSize",
"(",
")",
";",
"this",
".",
"sketchCanvas",
".",
"width",
"=",
"sketchCanvasSize",
".",
"x",
";",
"this",
".",
"sketchCanvas",
".",
"height",
"=",
"sketchCanvasSize",
".",
"y",
";",
"this",
".",
"_updateImageSmoothingEnabled",
"(",
"this",
".",
"sketchContext",
")",
";",
"}",
"}",
"this",
".",
"_clear",
"(",
")",
";",
"}",
"}"
] |
Clears the Drawer so it's ready to draw another frame.
|
[
"Clears",
"the",
"Drawer",
"so",
"it",
"s",
"ready",
"to",
"draw",
"another",
"frame",
"."
] |
e7108f23602575fc6eb152d4b82a8b44b2ca698e
|
https://github.com/openseadragon/openseadragon/blob/e7108f23602575fc6eb152d4b82a8b44b2ca698e/src/drawer.js#L248-L266
|
|
10,779
|
openseadragon/openseadragon
|
src/drawer.js
|
function(tile, drawingHandler, useSketch, scale, translate) {
$.console.assert(tile, '[Drawer.drawTile] tile is required');
$.console.assert(drawingHandler, '[Drawer.drawTile] drawingHandler is required');
if (this.useCanvas) {
var context = this._getContext(useSketch);
scale = scale || 1;
tile.drawCanvas(context, drawingHandler, scale, translate);
} else {
tile.drawHTML( this.canvas );
}
}
|
javascript
|
function(tile, drawingHandler, useSketch, scale, translate) {
$.console.assert(tile, '[Drawer.drawTile] tile is required');
$.console.assert(drawingHandler, '[Drawer.drawTile] drawingHandler is required');
if (this.useCanvas) {
var context = this._getContext(useSketch);
scale = scale || 1;
tile.drawCanvas(context, drawingHandler, scale, translate);
} else {
tile.drawHTML( this.canvas );
}
}
|
[
"function",
"(",
"tile",
",",
"drawingHandler",
",",
"useSketch",
",",
"scale",
",",
"translate",
")",
"{",
"$",
".",
"console",
".",
"assert",
"(",
"tile",
",",
"'[Drawer.drawTile] tile is required'",
")",
";",
"$",
".",
"console",
".",
"assert",
"(",
"drawingHandler",
",",
"'[Drawer.drawTile] drawingHandler is required'",
")",
";",
"if",
"(",
"this",
".",
"useCanvas",
")",
"{",
"var",
"context",
"=",
"this",
".",
"_getContext",
"(",
"useSketch",
")",
";",
"scale",
"=",
"scale",
"||",
"1",
";",
"tile",
".",
"drawCanvas",
"(",
"context",
",",
"drawingHandler",
",",
"scale",
",",
"translate",
")",
";",
"}",
"else",
"{",
"tile",
".",
"drawHTML",
"(",
"this",
".",
"canvas",
")",
";",
"}",
"}"
] |
Draws the given tile.
@param {OpenSeadragon.Tile} tile - The tile to draw.
@param {Function} drawingHandler - Method for firing the drawing event if using canvas.
drawingHandler({context, tile, rendered})
@param {Boolean} useSketch - Whether to use the sketch canvas or not.
where <code>rendered</code> is the context with the pre-drawn image.
@param {Float} [scale=1] - Apply a scale to tile position and size. Defaults to 1.
@param {OpenSeadragon.Point} [translate] A translation vector to offset tile position
|
[
"Draws",
"the",
"given",
"tile",
"."
] |
e7108f23602575fc6eb152d4b82a8b44b2ca698e
|
https://github.com/openseadragon/openseadragon/blob/e7108f23602575fc6eb152d4b82a8b44b2ca698e/src/drawer.js#L309-L320
|
|
10,780
|
openseadragon/openseadragon
|
src/drawer.js
|
function(opacity, scale, translate, compositeOperation) {
var options = opacity;
if (!$.isPlainObject(options)) {
options = {
opacity: opacity,
scale: scale,
translate: translate,
compositeOperation: compositeOperation
};
}
if (!this.useCanvas || !this.sketchCanvas) {
return;
}
opacity = options.opacity;
compositeOperation = options.compositeOperation;
var bounds = options.bounds;
this.context.save();
this.context.globalAlpha = opacity;
if (compositeOperation) {
this.context.globalCompositeOperation = compositeOperation;
}
if (bounds) {
// Internet Explorer, Microsoft Edge, and Safari have problems
// when you call context.drawImage with negative x or y
// or x + width or y + height greater than the canvas width or height respectively.
if (bounds.x < 0) {
bounds.width += bounds.x;
bounds.x = 0;
}
if (bounds.x + bounds.width > this.canvas.width) {
bounds.width = this.canvas.width - bounds.x;
}
if (bounds.y < 0) {
bounds.height += bounds.y;
bounds.y = 0;
}
if (bounds.y + bounds.height > this.canvas.height) {
bounds.height = this.canvas.height - bounds.y;
}
this.context.drawImage(
this.sketchCanvas,
bounds.x,
bounds.y,
bounds.width,
bounds.height,
bounds.x,
bounds.y,
bounds.width,
bounds.height
);
} else {
scale = options.scale || 1;
translate = options.translate;
var position = translate instanceof $.Point ?
translate : new $.Point(0, 0);
var widthExt = 0;
var heightExt = 0;
if (translate) {
var widthDiff = this.sketchCanvas.width - this.canvas.width;
var heightDiff = this.sketchCanvas.height - this.canvas.height;
widthExt = Math.round(widthDiff / 2);
heightExt = Math.round(heightDiff / 2);
}
this.context.drawImage(
this.sketchCanvas,
position.x - widthExt * scale,
position.y - heightExt * scale,
(this.canvas.width + 2 * widthExt) * scale,
(this.canvas.height + 2 * heightExt) * scale,
-widthExt,
-heightExt,
this.canvas.width + 2 * widthExt,
this.canvas.height + 2 * heightExt
);
}
this.context.restore();
}
|
javascript
|
function(opacity, scale, translate, compositeOperation) {
var options = opacity;
if (!$.isPlainObject(options)) {
options = {
opacity: opacity,
scale: scale,
translate: translate,
compositeOperation: compositeOperation
};
}
if (!this.useCanvas || !this.sketchCanvas) {
return;
}
opacity = options.opacity;
compositeOperation = options.compositeOperation;
var bounds = options.bounds;
this.context.save();
this.context.globalAlpha = opacity;
if (compositeOperation) {
this.context.globalCompositeOperation = compositeOperation;
}
if (bounds) {
// Internet Explorer, Microsoft Edge, and Safari have problems
// when you call context.drawImage with negative x or y
// or x + width or y + height greater than the canvas width or height respectively.
if (bounds.x < 0) {
bounds.width += bounds.x;
bounds.x = 0;
}
if (bounds.x + bounds.width > this.canvas.width) {
bounds.width = this.canvas.width - bounds.x;
}
if (bounds.y < 0) {
bounds.height += bounds.y;
bounds.y = 0;
}
if (bounds.y + bounds.height > this.canvas.height) {
bounds.height = this.canvas.height - bounds.y;
}
this.context.drawImage(
this.sketchCanvas,
bounds.x,
bounds.y,
bounds.width,
bounds.height,
bounds.x,
bounds.y,
bounds.width,
bounds.height
);
} else {
scale = options.scale || 1;
translate = options.translate;
var position = translate instanceof $.Point ?
translate : new $.Point(0, 0);
var widthExt = 0;
var heightExt = 0;
if (translate) {
var widthDiff = this.sketchCanvas.width - this.canvas.width;
var heightDiff = this.sketchCanvas.height - this.canvas.height;
widthExt = Math.round(widthDiff / 2);
heightExt = Math.round(heightDiff / 2);
}
this.context.drawImage(
this.sketchCanvas,
position.x - widthExt * scale,
position.y - heightExt * scale,
(this.canvas.width + 2 * widthExt) * scale,
(this.canvas.height + 2 * heightExt) * scale,
-widthExt,
-heightExt,
this.canvas.width + 2 * widthExt,
this.canvas.height + 2 * heightExt
);
}
this.context.restore();
}
|
[
"function",
"(",
"opacity",
",",
"scale",
",",
"translate",
",",
"compositeOperation",
")",
"{",
"var",
"options",
"=",
"opacity",
";",
"if",
"(",
"!",
"$",
".",
"isPlainObject",
"(",
"options",
")",
")",
"{",
"options",
"=",
"{",
"opacity",
":",
"opacity",
",",
"scale",
":",
"scale",
",",
"translate",
":",
"translate",
",",
"compositeOperation",
":",
"compositeOperation",
"}",
";",
"}",
"if",
"(",
"!",
"this",
".",
"useCanvas",
"||",
"!",
"this",
".",
"sketchCanvas",
")",
"{",
"return",
";",
"}",
"opacity",
"=",
"options",
".",
"opacity",
";",
"compositeOperation",
"=",
"options",
".",
"compositeOperation",
";",
"var",
"bounds",
"=",
"options",
".",
"bounds",
";",
"this",
".",
"context",
".",
"save",
"(",
")",
";",
"this",
".",
"context",
".",
"globalAlpha",
"=",
"opacity",
";",
"if",
"(",
"compositeOperation",
")",
"{",
"this",
".",
"context",
".",
"globalCompositeOperation",
"=",
"compositeOperation",
";",
"}",
"if",
"(",
"bounds",
")",
"{",
"// Internet Explorer, Microsoft Edge, and Safari have problems",
"// when you call context.drawImage with negative x or y",
"// or x + width or y + height greater than the canvas width or height respectively.",
"if",
"(",
"bounds",
".",
"x",
"<",
"0",
")",
"{",
"bounds",
".",
"width",
"+=",
"bounds",
".",
"x",
";",
"bounds",
".",
"x",
"=",
"0",
";",
"}",
"if",
"(",
"bounds",
".",
"x",
"+",
"bounds",
".",
"width",
">",
"this",
".",
"canvas",
".",
"width",
")",
"{",
"bounds",
".",
"width",
"=",
"this",
".",
"canvas",
".",
"width",
"-",
"bounds",
".",
"x",
";",
"}",
"if",
"(",
"bounds",
".",
"y",
"<",
"0",
")",
"{",
"bounds",
".",
"height",
"+=",
"bounds",
".",
"y",
";",
"bounds",
".",
"y",
"=",
"0",
";",
"}",
"if",
"(",
"bounds",
".",
"y",
"+",
"bounds",
".",
"height",
">",
"this",
".",
"canvas",
".",
"height",
")",
"{",
"bounds",
".",
"height",
"=",
"this",
".",
"canvas",
".",
"height",
"-",
"bounds",
".",
"y",
";",
"}",
"this",
".",
"context",
".",
"drawImage",
"(",
"this",
".",
"sketchCanvas",
",",
"bounds",
".",
"x",
",",
"bounds",
".",
"y",
",",
"bounds",
".",
"width",
",",
"bounds",
".",
"height",
",",
"bounds",
".",
"x",
",",
"bounds",
".",
"y",
",",
"bounds",
".",
"width",
",",
"bounds",
".",
"height",
")",
";",
"}",
"else",
"{",
"scale",
"=",
"options",
".",
"scale",
"||",
"1",
";",
"translate",
"=",
"options",
".",
"translate",
";",
"var",
"position",
"=",
"translate",
"instanceof",
"$",
".",
"Point",
"?",
"translate",
":",
"new",
"$",
".",
"Point",
"(",
"0",
",",
"0",
")",
";",
"var",
"widthExt",
"=",
"0",
";",
"var",
"heightExt",
"=",
"0",
";",
"if",
"(",
"translate",
")",
"{",
"var",
"widthDiff",
"=",
"this",
".",
"sketchCanvas",
".",
"width",
"-",
"this",
".",
"canvas",
".",
"width",
";",
"var",
"heightDiff",
"=",
"this",
".",
"sketchCanvas",
".",
"height",
"-",
"this",
".",
"canvas",
".",
"height",
";",
"widthExt",
"=",
"Math",
".",
"round",
"(",
"widthDiff",
"/",
"2",
")",
";",
"heightExt",
"=",
"Math",
".",
"round",
"(",
"heightDiff",
"/",
"2",
")",
";",
"}",
"this",
".",
"context",
".",
"drawImage",
"(",
"this",
".",
"sketchCanvas",
",",
"position",
".",
"x",
"-",
"widthExt",
"*",
"scale",
",",
"position",
".",
"y",
"-",
"heightExt",
"*",
"scale",
",",
"(",
"this",
".",
"canvas",
".",
"width",
"+",
"2",
"*",
"widthExt",
")",
"*",
"scale",
",",
"(",
"this",
".",
"canvas",
".",
"height",
"+",
"2",
"*",
"heightExt",
")",
"*",
"scale",
",",
"-",
"widthExt",
",",
"-",
"heightExt",
",",
"this",
".",
"canvas",
".",
"width",
"+",
"2",
"*",
"widthExt",
",",
"this",
".",
"canvas",
".",
"height",
"+",
"2",
"*",
"heightExt",
")",
";",
"}",
"this",
".",
"context",
".",
"restore",
"(",
")",
";",
"}"
] |
Blends the sketch canvas in the main canvas.
@param {Object} options The options
@param {Float} options.opacity The opacity of the blending.
@param {Float} [options.scale=1] The scale at which tiles were drawn on
the sketch. Default is 1.
Use scale to draw at a lower scale and then enlarge onto the main canvas.
@param {OpenSeadragon.Point} [options.translate] A translation vector
that was used to draw the tiles
@param {String} [options.compositeOperation] - How the image is
composited onto other images; see compositeOperation in
{@link OpenSeadragon.Options} for possible values.
@param {OpenSeadragon.Rect} [options.bounds] The part of the sketch
canvas to blend in the main canvas. If specified, options.scale and
options.translate get ignored.
|
[
"Blends",
"the",
"sketch",
"canvas",
"in",
"the",
"main",
"canvas",
"."
] |
e7108f23602575fc6eb152d4b82a8b44b2ca698e
|
https://github.com/openseadragon/openseadragon/blob/e7108f23602575fc6eb152d4b82a8b44b2ca698e/src/drawer.js#L413-L492
|
|
10,781
|
openseadragon/openseadragon
|
src/drawer.js
|
function(sketch) {
var canvas = this._getContext(sketch).canvas;
return new $.Point(canvas.width, canvas.height);
}
|
javascript
|
function(sketch) {
var canvas = this._getContext(sketch).canvas;
return new $.Point(canvas.width, canvas.height);
}
|
[
"function",
"(",
"sketch",
")",
"{",
"var",
"canvas",
"=",
"this",
".",
"_getContext",
"(",
"sketch",
")",
".",
"canvas",
";",
"return",
"new",
"$",
".",
"Point",
"(",
"canvas",
".",
"width",
",",
"canvas",
".",
"height",
")",
";",
"}"
] |
Get the canvas size
@param {Boolean} sketch If set to true return the size of the sketch canvas
@returns {OpenSeadragon.Point} The size of the canvas
|
[
"Get",
"the",
"canvas",
"size"
] |
e7108f23602575fc6eb152d4b82a8b44b2ca698e
|
https://github.com/openseadragon/openseadragon/blob/e7108f23602575fc6eb152d4b82a8b44b2ca698e/src/drawer.js#L647-L650
|
|
10,782
|
openseadragon/openseadragon
|
src/tilesource.js
|
processResponse
|
function processResponse( xhr ){
var responseText = xhr.responseText,
status = xhr.status,
statusText,
data;
if ( !xhr ) {
throw new Error( $.getString( "Errors.Security" ) );
} else if ( xhr.status !== 200 && xhr.status !== 0 ) {
status = xhr.status;
statusText = ( status == 404 ) ?
"Not Found" :
xhr.statusText;
throw new Error( $.getString( "Errors.Status", status, statusText ) );
}
if( responseText.match(/\s*<.*/) ){
try{
data = ( xhr.responseXML && xhr.responseXML.documentElement ) ?
xhr.responseXML :
$.parseXml( responseText );
} catch (e){
data = xhr.responseText;
}
}else if( responseText.match(/\s*[\{\[].*/) ){
try{
data = $.parseJSON(responseText);
} catch(e){
data = responseText;
}
}else{
data = responseText;
}
return data;
}
|
javascript
|
function processResponse( xhr ){
var responseText = xhr.responseText,
status = xhr.status,
statusText,
data;
if ( !xhr ) {
throw new Error( $.getString( "Errors.Security" ) );
} else if ( xhr.status !== 200 && xhr.status !== 0 ) {
status = xhr.status;
statusText = ( status == 404 ) ?
"Not Found" :
xhr.statusText;
throw new Error( $.getString( "Errors.Status", status, statusText ) );
}
if( responseText.match(/\s*<.*/) ){
try{
data = ( xhr.responseXML && xhr.responseXML.documentElement ) ?
xhr.responseXML :
$.parseXml( responseText );
} catch (e){
data = xhr.responseText;
}
}else if( responseText.match(/\s*[\{\[].*/) ){
try{
data = $.parseJSON(responseText);
} catch(e){
data = responseText;
}
}else{
data = responseText;
}
return data;
}
|
[
"function",
"processResponse",
"(",
"xhr",
")",
"{",
"var",
"responseText",
"=",
"xhr",
".",
"responseText",
",",
"status",
"=",
"xhr",
".",
"status",
",",
"statusText",
",",
"data",
";",
"if",
"(",
"!",
"xhr",
")",
"{",
"throw",
"new",
"Error",
"(",
"$",
".",
"getString",
"(",
"\"Errors.Security\"",
")",
")",
";",
"}",
"else",
"if",
"(",
"xhr",
".",
"status",
"!==",
"200",
"&&",
"xhr",
".",
"status",
"!==",
"0",
")",
"{",
"status",
"=",
"xhr",
".",
"status",
";",
"statusText",
"=",
"(",
"status",
"==",
"404",
")",
"?",
"\"Not Found\"",
":",
"xhr",
".",
"statusText",
";",
"throw",
"new",
"Error",
"(",
"$",
".",
"getString",
"(",
"\"Errors.Status\"",
",",
"status",
",",
"statusText",
")",
")",
";",
"}",
"if",
"(",
"responseText",
".",
"match",
"(",
"/",
"\\s*<.*",
"/",
")",
")",
"{",
"try",
"{",
"data",
"=",
"(",
"xhr",
".",
"responseXML",
"&&",
"xhr",
".",
"responseXML",
".",
"documentElement",
")",
"?",
"xhr",
".",
"responseXML",
":",
"$",
".",
"parseXml",
"(",
"responseText",
")",
";",
"}",
"catch",
"(",
"e",
")",
"{",
"data",
"=",
"xhr",
".",
"responseText",
";",
"}",
"}",
"else",
"if",
"(",
"responseText",
".",
"match",
"(",
"/",
"\\s*[\\{\\[].*",
"/",
")",
")",
"{",
"try",
"{",
"data",
"=",
"$",
".",
"parseJSON",
"(",
"responseText",
")",
";",
"}",
"catch",
"(",
"e",
")",
"{",
"data",
"=",
"responseText",
";",
"}",
"}",
"else",
"{",
"data",
"=",
"responseText",
";",
"}",
"return",
"data",
";",
"}"
] |
Decides whether to try to process the response as xml, json, or hand back
the text
@private
@inner
@function
@param {XMLHttpRequest} xhr - the completed network request
|
[
"Decides",
"whether",
"to",
"try",
"to",
"process",
"the",
"response",
"as",
"xml",
"json",
"or",
"hand",
"back",
"the",
"text"
] |
e7108f23602575fc6eb152d4b82a8b44b2ca698e
|
https://github.com/openseadragon/openseadragon/blob/e7108f23602575fc6eb152d4b82a8b44b2ca698e/src/tilesource.js#L633-L667
|
10,783
|
openseadragon/openseadragon
|
src/tilecache.js
|
function( options ) {
$.console.assert( options, "[TileCache.cacheTile] options is required" );
$.console.assert( options.tile, "[TileCache.cacheTile] options.tile is required" );
$.console.assert( options.tile.cacheKey, "[TileCache.cacheTile] options.tile.cacheKey is required" );
$.console.assert( options.tiledImage, "[TileCache.cacheTile] options.tiledImage is required" );
var cutoff = options.cutoff || 0;
var insertionIndex = this._tilesLoaded.length;
var imageRecord = this._imagesLoaded[options.tile.cacheKey];
if (!imageRecord) {
$.console.assert( options.image, "[TileCache.cacheTile] options.image is required to create an ImageRecord" );
imageRecord = this._imagesLoaded[options.tile.cacheKey] = new ImageRecord({
image: options.image
});
this._imagesLoadedCount++;
}
imageRecord.addTile(options.tile);
options.tile.cacheImageRecord = imageRecord;
// Note that just because we're unloading a tile doesn't necessarily mean
// we're unloading an image. With repeated calls it should sort itself out, though.
if ( this._imagesLoadedCount > this._maxImageCacheCount ) {
var worstTile = null;
var worstTileIndex = -1;
var worstTileRecord = null;
var prevTile, worstTime, worstLevel, prevTime, prevLevel, prevTileRecord;
for ( var i = this._tilesLoaded.length - 1; i >= 0; i-- ) {
prevTileRecord = this._tilesLoaded[ i ];
prevTile = prevTileRecord.tile;
if ( prevTile.level <= cutoff || prevTile.beingDrawn ) {
continue;
} else if ( !worstTile ) {
worstTile = prevTile;
worstTileIndex = i;
worstTileRecord = prevTileRecord;
continue;
}
prevTime = prevTile.lastTouchTime;
worstTime = worstTile.lastTouchTime;
prevLevel = prevTile.level;
worstLevel = worstTile.level;
if ( prevTime < worstTime ||
( prevTime == worstTime && prevLevel > worstLevel ) ) {
worstTile = prevTile;
worstTileIndex = i;
worstTileRecord = prevTileRecord;
}
}
if ( worstTile && worstTileIndex >= 0 ) {
this._unloadTile(worstTileRecord);
insertionIndex = worstTileIndex;
}
}
this._tilesLoaded[ insertionIndex ] = new TileRecord({
tile: options.tile,
tiledImage: options.tiledImage
});
}
|
javascript
|
function( options ) {
$.console.assert( options, "[TileCache.cacheTile] options is required" );
$.console.assert( options.tile, "[TileCache.cacheTile] options.tile is required" );
$.console.assert( options.tile.cacheKey, "[TileCache.cacheTile] options.tile.cacheKey is required" );
$.console.assert( options.tiledImage, "[TileCache.cacheTile] options.tiledImage is required" );
var cutoff = options.cutoff || 0;
var insertionIndex = this._tilesLoaded.length;
var imageRecord = this._imagesLoaded[options.tile.cacheKey];
if (!imageRecord) {
$.console.assert( options.image, "[TileCache.cacheTile] options.image is required to create an ImageRecord" );
imageRecord = this._imagesLoaded[options.tile.cacheKey] = new ImageRecord({
image: options.image
});
this._imagesLoadedCount++;
}
imageRecord.addTile(options.tile);
options.tile.cacheImageRecord = imageRecord;
// Note that just because we're unloading a tile doesn't necessarily mean
// we're unloading an image. With repeated calls it should sort itself out, though.
if ( this._imagesLoadedCount > this._maxImageCacheCount ) {
var worstTile = null;
var worstTileIndex = -1;
var worstTileRecord = null;
var prevTile, worstTime, worstLevel, prevTime, prevLevel, prevTileRecord;
for ( var i = this._tilesLoaded.length - 1; i >= 0; i-- ) {
prevTileRecord = this._tilesLoaded[ i ];
prevTile = prevTileRecord.tile;
if ( prevTile.level <= cutoff || prevTile.beingDrawn ) {
continue;
} else if ( !worstTile ) {
worstTile = prevTile;
worstTileIndex = i;
worstTileRecord = prevTileRecord;
continue;
}
prevTime = prevTile.lastTouchTime;
worstTime = worstTile.lastTouchTime;
prevLevel = prevTile.level;
worstLevel = worstTile.level;
if ( prevTime < worstTime ||
( prevTime == worstTime && prevLevel > worstLevel ) ) {
worstTile = prevTile;
worstTileIndex = i;
worstTileRecord = prevTileRecord;
}
}
if ( worstTile && worstTileIndex >= 0 ) {
this._unloadTile(worstTileRecord);
insertionIndex = worstTileIndex;
}
}
this._tilesLoaded[ insertionIndex ] = new TileRecord({
tile: options.tile,
tiledImage: options.tiledImage
});
}
|
[
"function",
"(",
"options",
")",
"{",
"$",
".",
"console",
".",
"assert",
"(",
"options",
",",
"\"[TileCache.cacheTile] options is required\"",
")",
";",
"$",
".",
"console",
".",
"assert",
"(",
"options",
".",
"tile",
",",
"\"[TileCache.cacheTile] options.tile is required\"",
")",
";",
"$",
".",
"console",
".",
"assert",
"(",
"options",
".",
"tile",
".",
"cacheKey",
",",
"\"[TileCache.cacheTile] options.tile.cacheKey is required\"",
")",
";",
"$",
".",
"console",
".",
"assert",
"(",
"options",
".",
"tiledImage",
",",
"\"[TileCache.cacheTile] options.tiledImage is required\"",
")",
";",
"var",
"cutoff",
"=",
"options",
".",
"cutoff",
"||",
"0",
";",
"var",
"insertionIndex",
"=",
"this",
".",
"_tilesLoaded",
".",
"length",
";",
"var",
"imageRecord",
"=",
"this",
".",
"_imagesLoaded",
"[",
"options",
".",
"tile",
".",
"cacheKey",
"]",
";",
"if",
"(",
"!",
"imageRecord",
")",
"{",
"$",
".",
"console",
".",
"assert",
"(",
"options",
".",
"image",
",",
"\"[TileCache.cacheTile] options.image is required to create an ImageRecord\"",
")",
";",
"imageRecord",
"=",
"this",
".",
"_imagesLoaded",
"[",
"options",
".",
"tile",
".",
"cacheKey",
"]",
"=",
"new",
"ImageRecord",
"(",
"{",
"image",
":",
"options",
".",
"image",
"}",
")",
";",
"this",
".",
"_imagesLoadedCount",
"++",
";",
"}",
"imageRecord",
".",
"addTile",
"(",
"options",
".",
"tile",
")",
";",
"options",
".",
"tile",
".",
"cacheImageRecord",
"=",
"imageRecord",
";",
"// Note that just because we're unloading a tile doesn't necessarily mean",
"// we're unloading an image. With repeated calls it should sort itself out, though.",
"if",
"(",
"this",
".",
"_imagesLoadedCount",
">",
"this",
".",
"_maxImageCacheCount",
")",
"{",
"var",
"worstTile",
"=",
"null",
";",
"var",
"worstTileIndex",
"=",
"-",
"1",
";",
"var",
"worstTileRecord",
"=",
"null",
";",
"var",
"prevTile",
",",
"worstTime",
",",
"worstLevel",
",",
"prevTime",
",",
"prevLevel",
",",
"prevTileRecord",
";",
"for",
"(",
"var",
"i",
"=",
"this",
".",
"_tilesLoaded",
".",
"length",
"-",
"1",
";",
"i",
">=",
"0",
";",
"i",
"--",
")",
"{",
"prevTileRecord",
"=",
"this",
".",
"_tilesLoaded",
"[",
"i",
"]",
";",
"prevTile",
"=",
"prevTileRecord",
".",
"tile",
";",
"if",
"(",
"prevTile",
".",
"level",
"<=",
"cutoff",
"||",
"prevTile",
".",
"beingDrawn",
")",
"{",
"continue",
";",
"}",
"else",
"if",
"(",
"!",
"worstTile",
")",
"{",
"worstTile",
"=",
"prevTile",
";",
"worstTileIndex",
"=",
"i",
";",
"worstTileRecord",
"=",
"prevTileRecord",
";",
"continue",
";",
"}",
"prevTime",
"=",
"prevTile",
".",
"lastTouchTime",
";",
"worstTime",
"=",
"worstTile",
".",
"lastTouchTime",
";",
"prevLevel",
"=",
"prevTile",
".",
"level",
";",
"worstLevel",
"=",
"worstTile",
".",
"level",
";",
"if",
"(",
"prevTime",
"<",
"worstTime",
"||",
"(",
"prevTime",
"==",
"worstTime",
"&&",
"prevLevel",
">",
"worstLevel",
")",
")",
"{",
"worstTile",
"=",
"prevTile",
";",
"worstTileIndex",
"=",
"i",
";",
"worstTileRecord",
"=",
"prevTileRecord",
";",
"}",
"}",
"if",
"(",
"worstTile",
"&&",
"worstTileIndex",
">=",
"0",
")",
"{",
"this",
".",
"_unloadTile",
"(",
"worstTileRecord",
")",
";",
"insertionIndex",
"=",
"worstTileIndex",
";",
"}",
"}",
"this",
".",
"_tilesLoaded",
"[",
"insertionIndex",
"]",
"=",
"new",
"TileRecord",
"(",
"{",
"tile",
":",
"options",
".",
"tile",
",",
"tiledImage",
":",
"options",
".",
"tiledImage",
"}",
")",
";",
"}"
] |
Caches the specified tile, removing an old tile if necessary to stay under the
maxImageCacheCount specified on construction. Note that if multiple tiles reference
the same image, there may be more tiles than maxImageCacheCount; the goal is to keep
the number of images below that number. Note, as well, that even the number of images
may temporarily surpass that number, but should eventually come back down to the max specified.
@param {Object} options - Tile info.
@param {OpenSeadragon.Tile} options.tile - The tile to cache.
@param {String} options.tile.cacheKey - The unique key used to identify this tile in the cache.
@param {Image} options.image - The image of the tile to cache.
@param {OpenSeadragon.TiledImage} options.tiledImage - The TiledImage that owns that tile.
@param {Number} [options.cutoff=0] - If adding this tile goes over the cache max count, this
function will release an old tile. The cutoff option specifies a tile level at or below which
tiles will not be released.
|
[
"Caches",
"the",
"specified",
"tile",
"removing",
"an",
"old",
"tile",
"if",
"necessary",
"to",
"stay",
"under",
"the",
"maxImageCacheCount",
"specified",
"on",
"construction",
".",
"Note",
"that",
"if",
"multiple",
"tiles",
"reference",
"the",
"same",
"image",
"there",
"may",
"be",
"more",
"tiles",
"than",
"maxImageCacheCount",
";",
"the",
"goal",
"is",
"to",
"keep",
"the",
"number",
"of",
"images",
"below",
"that",
"number",
".",
"Note",
"as",
"well",
"that",
"even",
"the",
"number",
"of",
"images",
"may",
"temporarily",
"surpass",
"that",
"number",
"but",
"should",
"eventually",
"come",
"back",
"down",
"to",
"the",
"max",
"specified",
"."
] |
e7108f23602575fc6eb152d4b82a8b44b2ca698e
|
https://github.com/openseadragon/openseadragon/blob/e7108f23602575fc6eb152d4b82a8b44b2ca698e/src/tilecache.js#L150-L216
|
|
10,784
|
openseadragon/openseadragon
|
src/tilecache.js
|
function( tiledImage ) {
$.console.assert(tiledImage, '[TileCache.clearTilesFor] tiledImage is required');
var tileRecord;
for ( var i = 0; i < this._tilesLoaded.length; ++i ) {
tileRecord = this._tilesLoaded[ i ];
if ( tileRecord.tiledImage === tiledImage ) {
this._unloadTile(tileRecord);
this._tilesLoaded.splice( i, 1 );
i--;
}
}
}
|
javascript
|
function( tiledImage ) {
$.console.assert(tiledImage, '[TileCache.clearTilesFor] tiledImage is required');
var tileRecord;
for ( var i = 0; i < this._tilesLoaded.length; ++i ) {
tileRecord = this._tilesLoaded[ i ];
if ( tileRecord.tiledImage === tiledImage ) {
this._unloadTile(tileRecord);
this._tilesLoaded.splice( i, 1 );
i--;
}
}
}
|
[
"function",
"(",
"tiledImage",
")",
"{",
"$",
".",
"console",
".",
"assert",
"(",
"tiledImage",
",",
"'[TileCache.clearTilesFor] tiledImage is required'",
")",
";",
"var",
"tileRecord",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"this",
".",
"_tilesLoaded",
".",
"length",
";",
"++",
"i",
")",
"{",
"tileRecord",
"=",
"this",
".",
"_tilesLoaded",
"[",
"i",
"]",
";",
"if",
"(",
"tileRecord",
".",
"tiledImage",
"===",
"tiledImage",
")",
"{",
"this",
".",
"_unloadTile",
"(",
"tileRecord",
")",
";",
"this",
".",
"_tilesLoaded",
".",
"splice",
"(",
"i",
",",
"1",
")",
";",
"i",
"--",
";",
"}",
"}",
"}"
] |
Clears all tiles associated with the specified tiledImage.
@param {OpenSeadragon.TiledImage} tiledImage
|
[
"Clears",
"all",
"tiles",
"associated",
"with",
"the",
"specified",
"tiledImage",
"."
] |
e7108f23602575fc6eb152d4b82a8b44b2ca698e
|
https://github.com/openseadragon/openseadragon/blob/e7108f23602575fc6eb152d4b82a8b44b2ca698e/src/tilecache.js#L222-L233
|
|
10,785
|
openseadragon/openseadragon
|
src/openseadragon.js
|
function( object, method ) {
return function(){
var args = arguments;
if ( args === undefined ){
args = [];
}
return method.apply( object, args );
};
}
|
javascript
|
function( object, method ) {
return function(){
var args = arguments;
if ( args === undefined ){
args = [];
}
return method.apply( object, args );
};
}
|
[
"function",
"(",
"object",
",",
"method",
")",
"{",
"return",
"function",
"(",
")",
"{",
"var",
"args",
"=",
"arguments",
";",
"if",
"(",
"args",
"===",
"undefined",
")",
"{",
"args",
"=",
"[",
"]",
";",
"}",
"return",
"method",
".",
"apply",
"(",
"object",
",",
"args",
")",
";",
"}",
";",
"}"
] |
Returns a function which invokes the method as if it were a method belonging to the object.
@function
@param {Object} object
@param {Function} method
@returns {Function}
|
[
"Returns",
"a",
"function",
"which",
"invokes",
"the",
"method",
"as",
"if",
"it",
"were",
"a",
"method",
"belonging",
"to",
"the",
"object",
"."
] |
e7108f23602575fc6eb152d4b82a8b44b2ca698e
|
https://github.com/openseadragon/openseadragon/blob/e7108f23602575fc6eb152d4b82a8b44b2ca698e/src/openseadragon.js#L1297-L1305
|
|
10,786
|
openseadragon/openseadragon
|
src/openseadragon.js
|
function( element ) {
var result = new $.Point(),
isFixed,
offsetParent;
element = $.getElement( element );
isFixed = $.getElementStyle( element ).position == "fixed";
offsetParent = getOffsetParent( element, isFixed );
while ( offsetParent ) {
result.x += element.offsetLeft;
result.y += element.offsetTop;
if ( isFixed ) {
result = result.plus( $.getPageScroll() );
}
element = offsetParent;
isFixed = $.getElementStyle( element ).position == "fixed";
offsetParent = getOffsetParent( element, isFixed );
}
return result;
}
|
javascript
|
function( element ) {
var result = new $.Point(),
isFixed,
offsetParent;
element = $.getElement( element );
isFixed = $.getElementStyle( element ).position == "fixed";
offsetParent = getOffsetParent( element, isFixed );
while ( offsetParent ) {
result.x += element.offsetLeft;
result.y += element.offsetTop;
if ( isFixed ) {
result = result.plus( $.getPageScroll() );
}
element = offsetParent;
isFixed = $.getElementStyle( element ).position == "fixed";
offsetParent = getOffsetParent( element, isFixed );
}
return result;
}
|
[
"function",
"(",
"element",
")",
"{",
"var",
"result",
"=",
"new",
"$",
".",
"Point",
"(",
")",
",",
"isFixed",
",",
"offsetParent",
";",
"element",
"=",
"$",
".",
"getElement",
"(",
"element",
")",
";",
"isFixed",
"=",
"$",
".",
"getElementStyle",
"(",
"element",
")",
".",
"position",
"==",
"\"fixed\"",
";",
"offsetParent",
"=",
"getOffsetParent",
"(",
"element",
",",
"isFixed",
")",
";",
"while",
"(",
"offsetParent",
")",
"{",
"result",
".",
"x",
"+=",
"element",
".",
"offsetLeft",
";",
"result",
".",
"y",
"+=",
"element",
".",
"offsetTop",
";",
"if",
"(",
"isFixed",
")",
"{",
"result",
"=",
"result",
".",
"plus",
"(",
"$",
".",
"getPageScroll",
"(",
")",
")",
";",
"}",
"element",
"=",
"offsetParent",
";",
"isFixed",
"=",
"$",
".",
"getElementStyle",
"(",
"element",
")",
".",
"position",
"==",
"\"fixed\"",
";",
"offsetParent",
"=",
"getOffsetParent",
"(",
"element",
",",
"isFixed",
")",
";",
"}",
"return",
"result",
";",
"}"
] |
Determines the position of the upper-left corner of the element.
@function
@param {Element|String} element - the element we want the position for.
@returns {OpenSeadragon.Point} - the position of the upper left corner of the element.
|
[
"Determines",
"the",
"position",
"of",
"the",
"upper",
"-",
"left",
"corner",
"of",
"the",
"element",
"."
] |
e7108f23602575fc6eb152d4b82a8b44b2ca698e
|
https://github.com/openseadragon/openseadragon/blob/e7108f23602575fc6eb152d4b82a8b44b2ca698e/src/openseadragon.js#L1349-L1373
|
|
10,787
|
openseadragon/openseadragon
|
src/openseadragon.js
|
function(property) {
var memo = {};
$.getCssPropertyWithVendorPrefix = function(property) {
if (memo[property] !== undefined) {
return memo[property];
}
var style = document.createElement('div').style;
var result = null;
if (style[property] !== undefined) {
result = property;
} else {
var prefixes = ['Webkit', 'Moz', 'MS', 'O',
'webkit', 'moz', 'ms', 'o'];
var suffix = $.capitalizeFirstLetter(property);
for (var i = 0; i < prefixes.length; i++) {
var prop = prefixes[i] + suffix;
if (style[prop] !== undefined) {
result = prop;
break;
}
}
}
memo[property] = result;
return result;
};
return $.getCssPropertyWithVendorPrefix(property);
}
|
javascript
|
function(property) {
var memo = {};
$.getCssPropertyWithVendorPrefix = function(property) {
if (memo[property] !== undefined) {
return memo[property];
}
var style = document.createElement('div').style;
var result = null;
if (style[property] !== undefined) {
result = property;
} else {
var prefixes = ['Webkit', 'Moz', 'MS', 'O',
'webkit', 'moz', 'ms', 'o'];
var suffix = $.capitalizeFirstLetter(property);
for (var i = 0; i < prefixes.length; i++) {
var prop = prefixes[i] + suffix;
if (style[prop] !== undefined) {
result = prop;
break;
}
}
}
memo[property] = result;
return result;
};
return $.getCssPropertyWithVendorPrefix(property);
}
|
[
"function",
"(",
"property",
")",
"{",
"var",
"memo",
"=",
"{",
"}",
";",
"$",
".",
"getCssPropertyWithVendorPrefix",
"=",
"function",
"(",
"property",
")",
"{",
"if",
"(",
"memo",
"[",
"property",
"]",
"!==",
"undefined",
")",
"{",
"return",
"memo",
"[",
"property",
"]",
";",
"}",
"var",
"style",
"=",
"document",
".",
"createElement",
"(",
"'div'",
")",
".",
"style",
";",
"var",
"result",
"=",
"null",
";",
"if",
"(",
"style",
"[",
"property",
"]",
"!==",
"undefined",
")",
"{",
"result",
"=",
"property",
";",
"}",
"else",
"{",
"var",
"prefixes",
"=",
"[",
"'Webkit'",
",",
"'Moz'",
",",
"'MS'",
",",
"'O'",
",",
"'webkit'",
",",
"'moz'",
",",
"'ms'",
",",
"'o'",
"]",
";",
"var",
"suffix",
"=",
"$",
".",
"capitalizeFirstLetter",
"(",
"property",
")",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"prefixes",
".",
"length",
";",
"i",
"++",
")",
"{",
"var",
"prop",
"=",
"prefixes",
"[",
"i",
"]",
"+",
"suffix",
";",
"if",
"(",
"style",
"[",
"prop",
"]",
"!==",
"undefined",
")",
"{",
"result",
"=",
"prop",
";",
"break",
";",
"}",
"}",
"}",
"memo",
"[",
"property",
"]",
"=",
"result",
";",
"return",
"result",
";",
"}",
";",
"return",
"$",
".",
"getCssPropertyWithVendorPrefix",
"(",
"property",
")",
";",
"}"
] |
Returns the property with the correct vendor prefix appended.
@param {String} property the property name
@returns {String} the property with the correct prefix or null if not
supported.
|
[
"Returns",
"the",
"property",
"with",
"the",
"correct",
"vendor",
"prefix",
"appended",
"."
] |
e7108f23602575fc6eb152d4b82a8b44b2ca698e
|
https://github.com/openseadragon/openseadragon/blob/e7108f23602575fc6eb152d4b82a8b44b2ca698e/src/openseadragon.js#L1452-L1479
|
|
10,788
|
openseadragon/openseadragon
|
src/openseadragon.js
|
function( event ) {
if( event ){
$.getEvent = function( event ) {
return event;
};
} else {
$.getEvent = function() {
return window.event;
};
}
return $.getEvent( event );
}
|
javascript
|
function( event ) {
if( event ){
$.getEvent = function( event ) {
return event;
};
} else {
$.getEvent = function() {
return window.event;
};
}
return $.getEvent( event );
}
|
[
"function",
"(",
"event",
")",
"{",
"if",
"(",
"event",
")",
"{",
"$",
".",
"getEvent",
"=",
"function",
"(",
"event",
")",
"{",
"return",
"event",
";",
"}",
";",
"}",
"else",
"{",
"$",
".",
"getEvent",
"=",
"function",
"(",
")",
"{",
"return",
"window",
".",
"event",
";",
"}",
";",
"}",
"return",
"$",
".",
"getEvent",
"(",
"event",
")",
";",
"}"
] |
Gets the latest event, really only useful internally since its
specific to IE behavior.
@function
@param {Event} [event]
@returns {Event}
@deprecated For internal use only
@private
|
[
"Gets",
"the",
"latest",
"event",
"really",
"only",
"useful",
"internally",
"since",
"its",
"specific",
"to",
"IE",
"behavior",
"."
] |
e7108f23602575fc6eb152d4b82a8b44b2ca698e
|
https://github.com/openseadragon/openseadragon/blob/e7108f23602575fc6eb152d4b82a8b44b2ca698e/src/openseadragon.js#L1529-L1540
|
|
10,789
|
openseadragon/openseadragon
|
src/openseadragon.js
|
function( event ) {
if ( typeof ( event.pageX ) == "number" ) {
$.getMousePosition = function( event ){
var result = new $.Point();
event = $.getEvent( event );
result.x = event.pageX;
result.y = event.pageY;
return result;
};
} else if ( typeof ( event.clientX ) == "number" ) {
$.getMousePosition = function( event ){
var result = new $.Point();
event = $.getEvent( event );
result.x =
event.clientX +
document.body.scrollLeft +
document.documentElement.scrollLeft;
result.y =
event.clientY +
document.body.scrollTop +
document.documentElement.scrollTop;
return result;
};
} else {
throw new Error(
"Unknown event mouse position, no known technique."
);
}
return $.getMousePosition( event );
}
|
javascript
|
function( event ) {
if ( typeof ( event.pageX ) == "number" ) {
$.getMousePosition = function( event ){
var result = new $.Point();
event = $.getEvent( event );
result.x = event.pageX;
result.y = event.pageY;
return result;
};
} else if ( typeof ( event.clientX ) == "number" ) {
$.getMousePosition = function( event ){
var result = new $.Point();
event = $.getEvent( event );
result.x =
event.clientX +
document.body.scrollLeft +
document.documentElement.scrollLeft;
result.y =
event.clientY +
document.body.scrollTop +
document.documentElement.scrollTop;
return result;
};
} else {
throw new Error(
"Unknown event mouse position, no known technique."
);
}
return $.getMousePosition( event );
}
|
[
"function",
"(",
"event",
")",
"{",
"if",
"(",
"typeof",
"(",
"event",
".",
"pageX",
")",
"==",
"\"number\"",
")",
"{",
"$",
".",
"getMousePosition",
"=",
"function",
"(",
"event",
")",
"{",
"var",
"result",
"=",
"new",
"$",
".",
"Point",
"(",
")",
";",
"event",
"=",
"$",
".",
"getEvent",
"(",
"event",
")",
";",
"result",
".",
"x",
"=",
"event",
".",
"pageX",
";",
"result",
".",
"y",
"=",
"event",
".",
"pageY",
";",
"return",
"result",
";",
"}",
";",
"}",
"else",
"if",
"(",
"typeof",
"(",
"event",
".",
"clientX",
")",
"==",
"\"number\"",
")",
"{",
"$",
".",
"getMousePosition",
"=",
"function",
"(",
"event",
")",
"{",
"var",
"result",
"=",
"new",
"$",
".",
"Point",
"(",
")",
";",
"event",
"=",
"$",
".",
"getEvent",
"(",
"event",
")",
";",
"result",
".",
"x",
"=",
"event",
".",
"clientX",
"+",
"document",
".",
"body",
".",
"scrollLeft",
"+",
"document",
".",
"documentElement",
".",
"scrollLeft",
";",
"result",
".",
"y",
"=",
"event",
".",
"clientY",
"+",
"document",
".",
"body",
".",
"scrollTop",
"+",
"document",
".",
"documentElement",
".",
"scrollTop",
";",
"return",
"result",
";",
"}",
";",
"}",
"else",
"{",
"throw",
"new",
"Error",
"(",
"\"Unknown event mouse position, no known technique.\"",
")",
";",
"}",
"return",
"$",
".",
"getMousePosition",
"(",
"event",
")",
";",
"}"
] |
Gets the position of the mouse on the screen for a given event.
@function
@param {Event} [event]
@returns {OpenSeadragon.Point}
|
[
"Gets",
"the",
"position",
"of",
"the",
"mouse",
"on",
"the",
"screen",
"for",
"a",
"given",
"event",
"."
] |
e7108f23602575fc6eb152d4b82a8b44b2ca698e
|
https://github.com/openseadragon/openseadragon/blob/e7108f23602575fc6eb152d4b82a8b44b2ca698e/src/openseadragon.js#L1549-L1584
|
|
10,790
|
openseadragon/openseadragon
|
src/openseadragon.js
|
function() {
var docElement = document.documentElement || {},
body = document.body || {};
if ( typeof ( window.pageXOffset ) == "number" ) {
$.getPageScroll = function(){
return new $.Point(
window.pageXOffset,
window.pageYOffset
);
};
} else if ( body.scrollLeft || body.scrollTop ) {
$.getPageScroll = function(){
return new $.Point(
document.body.scrollLeft,
document.body.scrollTop
);
};
} else if ( docElement.scrollLeft || docElement.scrollTop ) {
$.getPageScroll = function(){
return new $.Point(
document.documentElement.scrollLeft,
document.documentElement.scrollTop
);
};
} else {
// We can't reassign the function yet, as there was no scroll.
return new $.Point(0, 0);
}
return $.getPageScroll();
}
|
javascript
|
function() {
var docElement = document.documentElement || {},
body = document.body || {};
if ( typeof ( window.pageXOffset ) == "number" ) {
$.getPageScroll = function(){
return new $.Point(
window.pageXOffset,
window.pageYOffset
);
};
} else if ( body.scrollLeft || body.scrollTop ) {
$.getPageScroll = function(){
return new $.Point(
document.body.scrollLeft,
document.body.scrollTop
);
};
} else if ( docElement.scrollLeft || docElement.scrollTop ) {
$.getPageScroll = function(){
return new $.Point(
document.documentElement.scrollLeft,
document.documentElement.scrollTop
);
};
} else {
// We can't reassign the function yet, as there was no scroll.
return new $.Point(0, 0);
}
return $.getPageScroll();
}
|
[
"function",
"(",
")",
"{",
"var",
"docElement",
"=",
"document",
".",
"documentElement",
"||",
"{",
"}",
",",
"body",
"=",
"document",
".",
"body",
"||",
"{",
"}",
";",
"if",
"(",
"typeof",
"(",
"window",
".",
"pageXOffset",
")",
"==",
"\"number\"",
")",
"{",
"$",
".",
"getPageScroll",
"=",
"function",
"(",
")",
"{",
"return",
"new",
"$",
".",
"Point",
"(",
"window",
".",
"pageXOffset",
",",
"window",
".",
"pageYOffset",
")",
";",
"}",
";",
"}",
"else",
"if",
"(",
"body",
".",
"scrollLeft",
"||",
"body",
".",
"scrollTop",
")",
"{",
"$",
".",
"getPageScroll",
"=",
"function",
"(",
")",
"{",
"return",
"new",
"$",
".",
"Point",
"(",
"document",
".",
"body",
".",
"scrollLeft",
",",
"document",
".",
"body",
".",
"scrollTop",
")",
";",
"}",
";",
"}",
"else",
"if",
"(",
"docElement",
".",
"scrollLeft",
"||",
"docElement",
".",
"scrollTop",
")",
"{",
"$",
".",
"getPageScroll",
"=",
"function",
"(",
")",
"{",
"return",
"new",
"$",
".",
"Point",
"(",
"document",
".",
"documentElement",
".",
"scrollLeft",
",",
"document",
".",
"documentElement",
".",
"scrollTop",
")",
";",
"}",
";",
"}",
"else",
"{",
"// We can't reassign the function yet, as there was no scroll.",
"return",
"new",
"$",
".",
"Point",
"(",
"0",
",",
"0",
")",
";",
"}",
"return",
"$",
".",
"getPageScroll",
"(",
")",
";",
"}"
] |
Determines the page's current scroll position.
@function
@returns {OpenSeadragon.Point}
|
[
"Determines",
"the",
"page",
"s",
"current",
"scroll",
"position",
"."
] |
e7108f23602575fc6eb152d4b82a8b44b2ca698e
|
https://github.com/openseadragon/openseadragon/blob/e7108f23602575fc6eb152d4b82a8b44b2ca698e/src/openseadragon.js#L1592-L1623
|
|
10,791
|
openseadragon/openseadragon
|
src/openseadragon.js
|
function( scroll ) {
if ( typeof ( window.scrollTo ) !== "undefined" ) {
$.setPageScroll = function( scroll ) {
window.scrollTo( scroll.x, scroll.y );
};
} else {
var originalScroll = $.getPageScroll();
if ( originalScroll.x === scroll.x &&
originalScroll.y === scroll.y ) {
// We are already correctly positioned and there
// is no way to detect the correct method.
return;
}
document.body.scrollLeft = scroll.x;
document.body.scrollTop = scroll.y;
var currentScroll = $.getPageScroll();
if ( currentScroll.x !== originalScroll.x &&
currentScroll.y !== originalScroll.y ) {
$.setPageScroll = function( scroll ) {
document.body.scrollLeft = scroll.x;
document.body.scrollTop = scroll.y;
};
return;
}
document.documentElement.scrollLeft = scroll.x;
document.documentElement.scrollTop = scroll.y;
currentScroll = $.getPageScroll();
if ( currentScroll.x !== originalScroll.x &&
currentScroll.y !== originalScroll.y ) {
$.setPageScroll = function( scroll ) {
document.documentElement.scrollLeft = scroll.x;
document.documentElement.scrollTop = scroll.y;
};
return;
}
// We can't find anything working, so we do nothing.
$.setPageScroll = function( scroll ) {
};
}
return $.setPageScroll( scroll );
}
|
javascript
|
function( scroll ) {
if ( typeof ( window.scrollTo ) !== "undefined" ) {
$.setPageScroll = function( scroll ) {
window.scrollTo( scroll.x, scroll.y );
};
} else {
var originalScroll = $.getPageScroll();
if ( originalScroll.x === scroll.x &&
originalScroll.y === scroll.y ) {
// We are already correctly positioned and there
// is no way to detect the correct method.
return;
}
document.body.scrollLeft = scroll.x;
document.body.scrollTop = scroll.y;
var currentScroll = $.getPageScroll();
if ( currentScroll.x !== originalScroll.x &&
currentScroll.y !== originalScroll.y ) {
$.setPageScroll = function( scroll ) {
document.body.scrollLeft = scroll.x;
document.body.scrollTop = scroll.y;
};
return;
}
document.documentElement.scrollLeft = scroll.x;
document.documentElement.scrollTop = scroll.y;
currentScroll = $.getPageScroll();
if ( currentScroll.x !== originalScroll.x &&
currentScroll.y !== originalScroll.y ) {
$.setPageScroll = function( scroll ) {
document.documentElement.scrollLeft = scroll.x;
document.documentElement.scrollTop = scroll.y;
};
return;
}
// We can't find anything working, so we do nothing.
$.setPageScroll = function( scroll ) {
};
}
return $.setPageScroll( scroll );
}
|
[
"function",
"(",
"scroll",
")",
"{",
"if",
"(",
"typeof",
"(",
"window",
".",
"scrollTo",
")",
"!==",
"\"undefined\"",
")",
"{",
"$",
".",
"setPageScroll",
"=",
"function",
"(",
"scroll",
")",
"{",
"window",
".",
"scrollTo",
"(",
"scroll",
".",
"x",
",",
"scroll",
".",
"y",
")",
";",
"}",
";",
"}",
"else",
"{",
"var",
"originalScroll",
"=",
"$",
".",
"getPageScroll",
"(",
")",
";",
"if",
"(",
"originalScroll",
".",
"x",
"===",
"scroll",
".",
"x",
"&&",
"originalScroll",
".",
"y",
"===",
"scroll",
".",
"y",
")",
"{",
"// We are already correctly positioned and there",
"// is no way to detect the correct method.",
"return",
";",
"}",
"document",
".",
"body",
".",
"scrollLeft",
"=",
"scroll",
".",
"x",
";",
"document",
".",
"body",
".",
"scrollTop",
"=",
"scroll",
".",
"y",
";",
"var",
"currentScroll",
"=",
"$",
".",
"getPageScroll",
"(",
")",
";",
"if",
"(",
"currentScroll",
".",
"x",
"!==",
"originalScroll",
".",
"x",
"&&",
"currentScroll",
".",
"y",
"!==",
"originalScroll",
".",
"y",
")",
"{",
"$",
".",
"setPageScroll",
"=",
"function",
"(",
"scroll",
")",
"{",
"document",
".",
"body",
".",
"scrollLeft",
"=",
"scroll",
".",
"x",
";",
"document",
".",
"body",
".",
"scrollTop",
"=",
"scroll",
".",
"y",
";",
"}",
";",
"return",
";",
"}",
"document",
".",
"documentElement",
".",
"scrollLeft",
"=",
"scroll",
".",
"x",
";",
"document",
".",
"documentElement",
".",
"scrollTop",
"=",
"scroll",
".",
"y",
";",
"currentScroll",
"=",
"$",
".",
"getPageScroll",
"(",
")",
";",
"if",
"(",
"currentScroll",
".",
"x",
"!==",
"originalScroll",
".",
"x",
"&&",
"currentScroll",
".",
"y",
"!==",
"originalScroll",
".",
"y",
")",
"{",
"$",
".",
"setPageScroll",
"=",
"function",
"(",
"scroll",
")",
"{",
"document",
".",
"documentElement",
".",
"scrollLeft",
"=",
"scroll",
".",
"x",
";",
"document",
".",
"documentElement",
".",
"scrollTop",
"=",
"scroll",
".",
"y",
";",
"}",
";",
"return",
";",
"}",
"// We can't find anything working, so we do nothing.",
"$",
".",
"setPageScroll",
"=",
"function",
"(",
"scroll",
")",
"{",
"}",
";",
"}",
"return",
"$",
".",
"setPageScroll",
"(",
"scroll",
")",
";",
"}"
] |
Set the page scroll position.
@function
@returns {OpenSeadragon.Point}
|
[
"Set",
"the",
"page",
"scroll",
"position",
"."
] |
e7108f23602575fc6eb152d4b82a8b44b2ca698e
|
https://github.com/openseadragon/openseadragon/blob/e7108f23602575fc6eb152d4b82a8b44b2ca698e/src/openseadragon.js#L1630-L1674
|
|
10,792
|
openseadragon/openseadragon
|
src/openseadragon.js
|
function() {
var docElement = document.documentElement || {},
body = document.body || {};
if ( typeof ( window.innerWidth ) == 'number' ) {
$.getWindowSize = function(){
return new $.Point(
window.innerWidth,
window.innerHeight
);
};
} else if ( docElement.clientWidth || docElement.clientHeight ) {
$.getWindowSize = function(){
return new $.Point(
document.documentElement.clientWidth,
document.documentElement.clientHeight
);
};
} else if ( body.clientWidth || body.clientHeight ) {
$.getWindowSize = function(){
return new $.Point(
document.body.clientWidth,
document.body.clientHeight
);
};
} else {
throw new Error("Unknown window size, no known technique.");
}
return $.getWindowSize();
}
|
javascript
|
function() {
var docElement = document.documentElement || {},
body = document.body || {};
if ( typeof ( window.innerWidth ) == 'number' ) {
$.getWindowSize = function(){
return new $.Point(
window.innerWidth,
window.innerHeight
);
};
} else if ( docElement.clientWidth || docElement.clientHeight ) {
$.getWindowSize = function(){
return new $.Point(
document.documentElement.clientWidth,
document.documentElement.clientHeight
);
};
} else if ( body.clientWidth || body.clientHeight ) {
$.getWindowSize = function(){
return new $.Point(
document.body.clientWidth,
document.body.clientHeight
);
};
} else {
throw new Error("Unknown window size, no known technique.");
}
return $.getWindowSize();
}
|
[
"function",
"(",
")",
"{",
"var",
"docElement",
"=",
"document",
".",
"documentElement",
"||",
"{",
"}",
",",
"body",
"=",
"document",
".",
"body",
"||",
"{",
"}",
";",
"if",
"(",
"typeof",
"(",
"window",
".",
"innerWidth",
")",
"==",
"'number'",
")",
"{",
"$",
".",
"getWindowSize",
"=",
"function",
"(",
")",
"{",
"return",
"new",
"$",
".",
"Point",
"(",
"window",
".",
"innerWidth",
",",
"window",
".",
"innerHeight",
")",
";",
"}",
";",
"}",
"else",
"if",
"(",
"docElement",
".",
"clientWidth",
"||",
"docElement",
".",
"clientHeight",
")",
"{",
"$",
".",
"getWindowSize",
"=",
"function",
"(",
")",
"{",
"return",
"new",
"$",
".",
"Point",
"(",
"document",
".",
"documentElement",
".",
"clientWidth",
",",
"document",
".",
"documentElement",
".",
"clientHeight",
")",
";",
"}",
";",
"}",
"else",
"if",
"(",
"body",
".",
"clientWidth",
"||",
"body",
".",
"clientHeight",
")",
"{",
"$",
".",
"getWindowSize",
"=",
"function",
"(",
")",
"{",
"return",
"new",
"$",
".",
"Point",
"(",
"document",
".",
"body",
".",
"clientWidth",
",",
"document",
".",
"body",
".",
"clientHeight",
")",
";",
"}",
";",
"}",
"else",
"{",
"throw",
"new",
"Error",
"(",
"\"Unknown window size, no known technique.\"",
")",
";",
"}",
"return",
"$",
".",
"getWindowSize",
"(",
")",
";",
"}"
] |
Determines the size of the browsers window.
@function
@returns {OpenSeadragon.Point}
|
[
"Determines",
"the",
"size",
"of",
"the",
"browsers",
"window",
"."
] |
e7108f23602575fc6eb152d4b82a8b44b2ca698e
|
https://github.com/openseadragon/openseadragon/blob/e7108f23602575fc6eb152d4b82a8b44b2ca698e/src/openseadragon.js#L1681-L1711
|
|
10,793
|
openseadragon/openseadragon
|
src/openseadragon.js
|
function( element ) {
// Convert a possible ID to an actual HTMLElement
element = $.getElement( element );
/*
CSS tables require you to have a display:table/row/cell hierarchy so we need to create
three nested wrapper divs:
*/
var wrappers = [
$.makeNeutralElement( 'div' ),
$.makeNeutralElement( 'div' ),
$.makeNeutralElement( 'div' )
];
// It feels like we should be able to pass style dicts to makeNeutralElement:
$.extend(wrappers[0].style, {
display: "table",
height: "100%",
width: "100%"
});
$.extend(wrappers[1].style, {
display: "table-row"
});
$.extend(wrappers[2].style, {
display: "table-cell",
verticalAlign: "middle",
textAlign: "center"
});
wrappers[0].appendChild(wrappers[1]);
wrappers[1].appendChild(wrappers[2]);
wrappers[2].appendChild(element);
return wrappers[0];
}
|
javascript
|
function( element ) {
// Convert a possible ID to an actual HTMLElement
element = $.getElement( element );
/*
CSS tables require you to have a display:table/row/cell hierarchy so we need to create
three nested wrapper divs:
*/
var wrappers = [
$.makeNeutralElement( 'div' ),
$.makeNeutralElement( 'div' ),
$.makeNeutralElement( 'div' )
];
// It feels like we should be able to pass style dicts to makeNeutralElement:
$.extend(wrappers[0].style, {
display: "table",
height: "100%",
width: "100%"
});
$.extend(wrappers[1].style, {
display: "table-row"
});
$.extend(wrappers[2].style, {
display: "table-cell",
verticalAlign: "middle",
textAlign: "center"
});
wrappers[0].appendChild(wrappers[1]);
wrappers[1].appendChild(wrappers[2]);
wrappers[2].appendChild(element);
return wrappers[0];
}
|
[
"function",
"(",
"element",
")",
"{",
"// Convert a possible ID to an actual HTMLElement",
"element",
"=",
"$",
".",
"getElement",
"(",
"element",
")",
";",
"/*\n CSS tables require you to have a display:table/row/cell hierarchy so we need to create\n three nested wrapper divs:\n */",
"var",
"wrappers",
"=",
"[",
"$",
".",
"makeNeutralElement",
"(",
"'div'",
")",
",",
"$",
".",
"makeNeutralElement",
"(",
"'div'",
")",
",",
"$",
".",
"makeNeutralElement",
"(",
"'div'",
")",
"]",
";",
"// It feels like we should be able to pass style dicts to makeNeutralElement:",
"$",
".",
"extend",
"(",
"wrappers",
"[",
"0",
"]",
".",
"style",
",",
"{",
"display",
":",
"\"table\"",
",",
"height",
":",
"\"100%\"",
",",
"width",
":",
"\"100%\"",
"}",
")",
";",
"$",
".",
"extend",
"(",
"wrappers",
"[",
"1",
"]",
".",
"style",
",",
"{",
"display",
":",
"\"table-row\"",
"}",
")",
";",
"$",
".",
"extend",
"(",
"wrappers",
"[",
"2",
"]",
".",
"style",
",",
"{",
"display",
":",
"\"table-cell\"",
",",
"verticalAlign",
":",
"\"middle\"",
",",
"textAlign",
":",
"\"center\"",
"}",
")",
";",
"wrappers",
"[",
"0",
"]",
".",
"appendChild",
"(",
"wrappers",
"[",
"1",
"]",
")",
";",
"wrappers",
"[",
"1",
"]",
".",
"appendChild",
"(",
"wrappers",
"[",
"2",
"]",
")",
";",
"wrappers",
"[",
"2",
"]",
".",
"appendChild",
"(",
"element",
")",
";",
"return",
"wrappers",
"[",
"0",
"]",
";",
"}"
] |
Wraps the given element in a nest of divs so that the element can
be easily centered using CSS tables
@function
@param {Element|String} element
@returns {Element} outermost wrapper element
|
[
"Wraps",
"the",
"given",
"element",
"in",
"a",
"nest",
"of",
"divs",
"so",
"that",
"the",
"element",
"can",
"be",
"easily",
"centered",
"using",
"CSS",
"tables"
] |
e7108f23602575fc6eb152d4b82a8b44b2ca698e
|
https://github.com/openseadragon/openseadragon/blob/e7108f23602575fc6eb152d4b82a8b44b2ca698e/src/openseadragon.js#L1721-L1758
|
|
10,794
|
openseadragon/openseadragon
|
src/openseadragon.js
|
function( tagName ) {
var element = document.createElement( tagName ),
style = element.style;
style.background = "transparent none";
style.border = "none";
style.margin = "0px";
style.padding = "0px";
style.position = "static";
return element;
}
|
javascript
|
function( tagName ) {
var element = document.createElement( tagName ),
style = element.style;
style.background = "transparent none";
style.border = "none";
style.margin = "0px";
style.padding = "0px";
style.position = "static";
return element;
}
|
[
"function",
"(",
"tagName",
")",
"{",
"var",
"element",
"=",
"document",
".",
"createElement",
"(",
"tagName",
")",
",",
"style",
"=",
"element",
".",
"style",
";",
"style",
".",
"background",
"=",
"\"transparent none\"",
";",
"style",
".",
"border",
"=",
"\"none\"",
";",
"style",
".",
"margin",
"=",
"\"0px\"",
";",
"style",
".",
"padding",
"=",
"\"0px\"",
";",
"style",
".",
"position",
"=",
"\"static\"",
";",
"return",
"element",
";",
"}"
] |
Creates an easily positionable element of the given type that therefor
serves as an excellent container element.
@function
@param {String} tagName
@returns {Element}
|
[
"Creates",
"an",
"easily",
"positionable",
"element",
"of",
"the",
"given",
"type",
"that",
"therefor",
"serves",
"as",
"an",
"excellent",
"container",
"element",
"."
] |
e7108f23602575fc6eb152d4b82a8b44b2ca698e
|
https://github.com/openseadragon/openseadragon/blob/e7108f23602575fc6eb152d4b82a8b44b2ca698e/src/openseadragon.js#L1768-L1779
|
|
10,795
|
openseadragon/openseadragon
|
src/openseadragon.js
|
function( src ) {
$.makeTransparentImage = function( src ){
var img = $.makeNeutralElement( "img" );
img.src = src;
return img;
};
if ( $.Browser.vendor == $.BROWSERS.IE && $.Browser.version < 7 ) {
$.makeTransparentImage = function( src ){
var img = $.makeNeutralElement( "img" ),
element = null;
element = $.makeNeutralElement("span");
element.style.display = "inline-block";
img.onload = function() {
element.style.width = element.style.width || img.width + "px";
element.style.height = element.style.height || img.height + "px";
img.onload = null;
img = null; // to prevent memory leaks in IE
};
img.src = src;
element.style.filter =
"progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" +
src +
"', sizingMethod='scale')";
return element;
};
}
return $.makeTransparentImage( src );
}
|
javascript
|
function( src ) {
$.makeTransparentImage = function( src ){
var img = $.makeNeutralElement( "img" );
img.src = src;
return img;
};
if ( $.Browser.vendor == $.BROWSERS.IE && $.Browser.version < 7 ) {
$.makeTransparentImage = function( src ){
var img = $.makeNeutralElement( "img" ),
element = null;
element = $.makeNeutralElement("span");
element.style.display = "inline-block";
img.onload = function() {
element.style.width = element.style.width || img.width + "px";
element.style.height = element.style.height || img.height + "px";
img.onload = null;
img = null; // to prevent memory leaks in IE
};
img.src = src;
element.style.filter =
"progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" +
src +
"', sizingMethod='scale')";
return element;
};
}
return $.makeTransparentImage( src );
}
|
[
"function",
"(",
"src",
")",
"{",
"$",
".",
"makeTransparentImage",
"=",
"function",
"(",
"src",
")",
"{",
"var",
"img",
"=",
"$",
".",
"makeNeutralElement",
"(",
"\"img\"",
")",
";",
"img",
".",
"src",
"=",
"src",
";",
"return",
"img",
";",
"}",
";",
"if",
"(",
"$",
".",
"Browser",
".",
"vendor",
"==",
"$",
".",
"BROWSERS",
".",
"IE",
"&&",
"$",
".",
"Browser",
".",
"version",
"<",
"7",
")",
"{",
"$",
".",
"makeTransparentImage",
"=",
"function",
"(",
"src",
")",
"{",
"var",
"img",
"=",
"$",
".",
"makeNeutralElement",
"(",
"\"img\"",
")",
",",
"element",
"=",
"null",
";",
"element",
"=",
"$",
".",
"makeNeutralElement",
"(",
"\"span\"",
")",
";",
"element",
".",
"style",
".",
"display",
"=",
"\"inline-block\"",
";",
"img",
".",
"onload",
"=",
"function",
"(",
")",
"{",
"element",
".",
"style",
".",
"width",
"=",
"element",
".",
"style",
".",
"width",
"||",
"img",
".",
"width",
"+",
"\"px\"",
";",
"element",
".",
"style",
".",
"height",
"=",
"element",
".",
"style",
".",
"height",
"||",
"img",
".",
"height",
"+",
"\"px\"",
";",
"img",
".",
"onload",
"=",
"null",
";",
"img",
"=",
"null",
";",
"// to prevent memory leaks in IE",
"}",
";",
"img",
".",
"src",
"=",
"src",
";",
"element",
".",
"style",
".",
"filter",
"=",
"\"progid:DXImageTransform.Microsoft.AlphaImageLoader(src='\"",
"+",
"src",
"+",
"\"', sizingMethod='scale')\"",
";",
"return",
"element",
";",
"}",
";",
"}",
"return",
"$",
".",
"makeTransparentImage",
"(",
"src",
")",
";",
"}"
] |
Ensures an image is loaded correctly to support alpha transparency.
Generally only IE has issues doing this correctly for formats like
png.
@function
@param {String} src
@returns {Element}
|
[
"Ensures",
"an",
"image",
"is",
"loaded",
"correctly",
"to",
"support",
"alpha",
"transparency",
".",
"Generally",
"only",
"IE",
"has",
"issues",
"doing",
"this",
"correctly",
"for",
"formats",
"like",
"png",
"."
] |
e7108f23602575fc6eb152d4b82a8b44b2ca698e
|
https://github.com/openseadragon/openseadragon/blob/e7108f23602575fc6eb152d4b82a8b44b2ca698e/src/openseadragon.js#L1807-L1846
|
|
10,796
|
openseadragon/openseadragon
|
src/openseadragon.js
|
function( element, opacity, usesAlpha ) {
var ieOpacity,
ieFilter;
element = $.getElement( element );
if ( usesAlpha && !$.Browser.alpha ) {
opacity = Math.round( opacity );
}
if ( $.Browser.opacity ) {
element.style.opacity = opacity < 1 ? opacity : "";
} else {
if ( opacity < 1 ) {
ieOpacity = Math.round( 100 * opacity );
ieFilter = "alpha(opacity=" + ieOpacity + ")";
element.style.filter = ieFilter;
} else {
element.style.filter = "";
}
}
}
|
javascript
|
function( element, opacity, usesAlpha ) {
var ieOpacity,
ieFilter;
element = $.getElement( element );
if ( usesAlpha && !$.Browser.alpha ) {
opacity = Math.round( opacity );
}
if ( $.Browser.opacity ) {
element.style.opacity = opacity < 1 ? opacity : "";
} else {
if ( opacity < 1 ) {
ieOpacity = Math.round( 100 * opacity );
ieFilter = "alpha(opacity=" + ieOpacity + ")";
element.style.filter = ieFilter;
} else {
element.style.filter = "";
}
}
}
|
[
"function",
"(",
"element",
",",
"opacity",
",",
"usesAlpha",
")",
"{",
"var",
"ieOpacity",
",",
"ieFilter",
";",
"element",
"=",
"$",
".",
"getElement",
"(",
"element",
")",
";",
"if",
"(",
"usesAlpha",
"&&",
"!",
"$",
".",
"Browser",
".",
"alpha",
")",
"{",
"opacity",
"=",
"Math",
".",
"round",
"(",
"opacity",
")",
";",
"}",
"if",
"(",
"$",
".",
"Browser",
".",
"opacity",
")",
"{",
"element",
".",
"style",
".",
"opacity",
"=",
"opacity",
"<",
"1",
"?",
"opacity",
":",
"\"\"",
";",
"}",
"else",
"{",
"if",
"(",
"opacity",
"<",
"1",
")",
"{",
"ieOpacity",
"=",
"Math",
".",
"round",
"(",
"100",
"*",
"opacity",
")",
";",
"ieFilter",
"=",
"\"alpha(opacity=\"",
"+",
"ieOpacity",
"+",
"\")\"",
";",
"element",
".",
"style",
".",
"filter",
"=",
"ieFilter",
";",
"}",
"else",
"{",
"element",
".",
"style",
".",
"filter",
"=",
"\"\"",
";",
"}",
"}",
"}"
] |
Sets the opacity of the specified element.
@function
@param {Element|String} element
@param {Number} opacity
@param {Boolean} [usesAlpha]
|
[
"Sets",
"the",
"opacity",
"of",
"the",
"specified",
"element",
"."
] |
e7108f23602575fc6eb152d4b82a8b44b2ca698e
|
https://github.com/openseadragon/openseadragon/blob/e7108f23602575fc6eb152d4b82a8b44b2ca698e/src/openseadragon.js#L1856-L1878
|
|
10,797
|
openseadragon/openseadragon
|
src/openseadragon.js
|
function( element ) {
element = $.getElement( element );
if ( typeof element.style.touchAction !== 'undefined' ) {
element.style.touchAction = 'none';
} else if ( typeof element.style.msTouchAction !== 'undefined' ) {
element.style.msTouchAction = 'none';
}
}
|
javascript
|
function( element ) {
element = $.getElement( element );
if ( typeof element.style.touchAction !== 'undefined' ) {
element.style.touchAction = 'none';
} else if ( typeof element.style.msTouchAction !== 'undefined' ) {
element.style.msTouchAction = 'none';
}
}
|
[
"function",
"(",
"element",
")",
"{",
"element",
"=",
"$",
".",
"getElement",
"(",
"element",
")",
";",
"if",
"(",
"typeof",
"element",
".",
"style",
".",
"touchAction",
"!==",
"'undefined'",
")",
"{",
"element",
".",
"style",
".",
"touchAction",
"=",
"'none'",
";",
"}",
"else",
"if",
"(",
"typeof",
"element",
".",
"style",
".",
"msTouchAction",
"!==",
"'undefined'",
")",
"{",
"element",
".",
"style",
".",
"msTouchAction",
"=",
"'none'",
";",
"}",
"}"
] |
Sets the specified element's touch-action style attribute to 'none'.
@function
@param {Element|String} element
|
[
"Sets",
"the",
"specified",
"element",
"s",
"touch",
"-",
"action",
"style",
"attribute",
"to",
"none",
"."
] |
e7108f23602575fc6eb152d4b82a8b44b2ca698e
|
https://github.com/openseadragon/openseadragon/blob/e7108f23602575fc6eb152d4b82a8b44b2ca698e/src/openseadragon.js#L1886-L1893
|
|
10,798
|
openseadragon/openseadragon
|
src/openseadragon.js
|
function( element, className ) {
element = $.getElement( element );
if (!element.className) {
element.className = className;
} else if ( ( ' ' + element.className + ' ' ).
indexOf( ' ' + className + ' ' ) === -1 ) {
element.className += ' ' + className;
}
}
|
javascript
|
function( element, className ) {
element = $.getElement( element );
if (!element.className) {
element.className = className;
} else if ( ( ' ' + element.className + ' ' ).
indexOf( ' ' + className + ' ' ) === -1 ) {
element.className += ' ' + className;
}
}
|
[
"function",
"(",
"element",
",",
"className",
")",
"{",
"element",
"=",
"$",
".",
"getElement",
"(",
"element",
")",
";",
"if",
"(",
"!",
"element",
".",
"className",
")",
"{",
"element",
".",
"className",
"=",
"className",
";",
"}",
"else",
"if",
"(",
"(",
"' '",
"+",
"element",
".",
"className",
"+",
"' '",
")",
".",
"indexOf",
"(",
"' '",
"+",
"className",
"+",
"' '",
")",
"===",
"-",
"1",
")",
"{",
"element",
".",
"className",
"+=",
"' '",
"+",
"className",
";",
"}",
"}"
] |
Add the specified CSS class to the element if not present.
@function
@param {Element|String} element
@param {String} className
|
[
"Add",
"the",
"specified",
"CSS",
"class",
"to",
"the",
"element",
"if",
"not",
"present",
"."
] |
e7108f23602575fc6eb152d4b82a8b44b2ca698e
|
https://github.com/openseadragon/openseadragon/blob/e7108f23602575fc6eb152d4b82a8b44b2ca698e/src/openseadragon.js#L1902-L1911
|
|
10,799
|
openseadragon/openseadragon
|
src/openseadragon.js
|
function( array, searchElement, fromIndex ) {
if ( Array.prototype.indexOf ) {
this.indexOf = function( array, searchElement, fromIndex ) {
return array.indexOf( searchElement, fromIndex );
};
} else {
this.indexOf = function( array, searchElement, fromIndex ) {
var i,
pivot = ( fromIndex ) ? fromIndex : 0,
length;
if ( !array ) {
throw new TypeError( );
}
length = array.length;
if ( length === 0 || pivot >= length ) {
return -1;
}
if ( pivot < 0 ) {
pivot = length - Math.abs( pivot );
}
for ( i = pivot; i < length; i++ ) {
if ( array[i] === searchElement ) {
return i;
}
}
return -1;
};
}
return this.indexOf( array, searchElement, fromIndex );
}
|
javascript
|
function( array, searchElement, fromIndex ) {
if ( Array.prototype.indexOf ) {
this.indexOf = function( array, searchElement, fromIndex ) {
return array.indexOf( searchElement, fromIndex );
};
} else {
this.indexOf = function( array, searchElement, fromIndex ) {
var i,
pivot = ( fromIndex ) ? fromIndex : 0,
length;
if ( !array ) {
throw new TypeError( );
}
length = array.length;
if ( length === 0 || pivot >= length ) {
return -1;
}
if ( pivot < 0 ) {
pivot = length - Math.abs( pivot );
}
for ( i = pivot; i < length; i++ ) {
if ( array[i] === searchElement ) {
return i;
}
}
return -1;
};
}
return this.indexOf( array, searchElement, fromIndex );
}
|
[
"function",
"(",
"array",
",",
"searchElement",
",",
"fromIndex",
")",
"{",
"if",
"(",
"Array",
".",
"prototype",
".",
"indexOf",
")",
"{",
"this",
".",
"indexOf",
"=",
"function",
"(",
"array",
",",
"searchElement",
",",
"fromIndex",
")",
"{",
"return",
"array",
".",
"indexOf",
"(",
"searchElement",
",",
"fromIndex",
")",
";",
"}",
";",
"}",
"else",
"{",
"this",
".",
"indexOf",
"=",
"function",
"(",
"array",
",",
"searchElement",
",",
"fromIndex",
")",
"{",
"var",
"i",
",",
"pivot",
"=",
"(",
"fromIndex",
")",
"?",
"fromIndex",
":",
"0",
",",
"length",
";",
"if",
"(",
"!",
"array",
")",
"{",
"throw",
"new",
"TypeError",
"(",
")",
";",
"}",
"length",
"=",
"array",
".",
"length",
";",
"if",
"(",
"length",
"===",
"0",
"||",
"pivot",
">=",
"length",
")",
"{",
"return",
"-",
"1",
";",
"}",
"if",
"(",
"pivot",
"<",
"0",
")",
"{",
"pivot",
"=",
"length",
"-",
"Math",
".",
"abs",
"(",
"pivot",
")",
";",
"}",
"for",
"(",
"i",
"=",
"pivot",
";",
"i",
"<",
"length",
";",
"i",
"++",
")",
"{",
"if",
"(",
"array",
"[",
"i",
"]",
"===",
"searchElement",
")",
"{",
"return",
"i",
";",
"}",
"}",
"return",
"-",
"1",
";",
"}",
";",
"}",
"return",
"this",
".",
"indexOf",
"(",
"array",
",",
"searchElement",
",",
"fromIndex",
")",
";",
"}"
] |
Find the first index at which an element is found in an array or -1
if not present.
Code taken and adapted from
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/indexOf#Compatibility
@function
@param {Array} array The array from which to find the element
@param {Object} searchElement The element to find
@param {Number} [fromIndex=0] Index to start research.
@returns {Number} The index of the element in the array.
|
[
"Find",
"the",
"first",
"index",
"at",
"which",
"an",
"element",
"is",
"found",
"in",
"an",
"array",
"or",
"-",
"1",
"if",
"not",
"present",
"."
] |
e7108f23602575fc6eb152d4b82a8b44b2ca698e
|
https://github.com/openseadragon/openseadragon/blob/e7108f23602575fc6eb152d4b82a8b44b2ca698e/src/openseadragon.js#L1926-L1958
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.