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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
21,700 | titon/toolkit | dist/toolkit.js | function() {
this.fireEvent('showing');
var show = false;
this.count++;
if (this.count === 1) {
this.element.reveal();
show = true;
}
this.showLoader();
this.fireEvent('shown', [show]);
} | javascript | function() {
this.fireEvent('showing');
var show = false;
this.count++;
if (this.count === 1) {
this.element.reveal();
show = true;
}
this.showLoader();
this.fireEvent('shown', [show]);
} | [
"function",
"(",
")",
"{",
"this",
".",
"fireEvent",
"(",
"'showing'",
")",
";",
"var",
"show",
"=",
"false",
";",
"this",
".",
"count",
"++",
";",
"if",
"(",
"this",
".",
"count",
"===",
"1",
")",
"{",
"this",
".",
"element",
".",
"reveal",
"(",
")",
";",
"show",
"=",
"true",
";",
"}",
"this",
".",
"showLoader",
"(",
")",
";",
"this",
".",
"fireEvent",
"(",
"'shown'",
",",
"[",
"show",
"]",
")",
";",
"}"
] | Show the blackout and increase open count. | [
"Show",
"the",
"blackout",
"and",
"increase",
"open",
"count",
"."
] | f0ed36d14cc6d72a7bdbc09da4b5bf7d3d664f0c | https://github.com/titon/toolkit/blob/f0ed36d14cc6d72a7bdbc09da4b5bf7d3d664f0c/dist/toolkit.js#L1489-L1504 | |
21,701 | titon/toolkit | dist/toolkit.js | function() {
var self = $(this),
start,
target;
/**
* There's a major bug in Android devices where `touchend` events do not fire
* without calling `preventDefault()` in `touchstart` or `touchmove`.
* Because of this, we have to hack-ily implement functionality into `touchmove`.
* We also can't use `touchcancel` as that fires prematurely and unbinds our move event.
* More information on these bugs can be found here:
*
* https://code.google.com/p/android/issues/detail?id=19827
* https://code.google.com/p/chromium/issues/detail?id=260732
*
* Using `touchcancel` is also rather unpredictable, as described here:
*
* http://alxgbsn.co.uk/2011/12/23/different-ways-to-trigger-touchcancel-in-mobile-browsers/
*/
function move(e) {
var to = coords(e);
// Trigger `preventDefault()` if `x` is larger than `y` (scrolling horizontally).
// If we `preventDefault()` while scrolling vertically, the window will not scroll.
if (abs(start.x - to.x) > abs(start.y - to.y)) {
e.preventDefault();
}
}
/**
* When `touchend` or `touchcancel` is triggered, clean up the swipe state.
* Also unbind `touchmove` events until another swipe occurs.
*/
function cleanup() {
start = target = null;
swiping = false;
self.off(moveEvent, move);
}
// Initialize the state when a touch occurs
self.on(startEvent, function(e) {
// Calling `preventDefault()` on start will disable clicking of elements (links, inputs, etc)
// So only do it on an `img` element so it cannot be dragged
if (!isTouch && e.target.tagName.toLowerCase() === 'img') {
e.preventDefault();
}
// Exit early if another swipe is occurring
if (swiping) {
return;
}
start = coords(e);
target = e.target;
swiping = true;
// Non-touch devices don't make use of the move event
if (isTouch) {
self.on(moveEvent, move);
}
});
// Trigger the swipe event when the touch finishes
self.on(stopEvent, function(e) {
swipe(start, coords(e), self, target);
cleanup();
});
// Reset the state when the touch is cancelled
self.on('touchcancel', cleanup);
} | javascript | function() {
var self = $(this),
start,
target;
/**
* There's a major bug in Android devices where `touchend` events do not fire
* without calling `preventDefault()` in `touchstart` or `touchmove`.
* Because of this, we have to hack-ily implement functionality into `touchmove`.
* We also can't use `touchcancel` as that fires prematurely and unbinds our move event.
* More information on these bugs can be found here:
*
* https://code.google.com/p/android/issues/detail?id=19827
* https://code.google.com/p/chromium/issues/detail?id=260732
*
* Using `touchcancel` is also rather unpredictable, as described here:
*
* http://alxgbsn.co.uk/2011/12/23/different-ways-to-trigger-touchcancel-in-mobile-browsers/
*/
function move(e) {
var to = coords(e);
// Trigger `preventDefault()` if `x` is larger than `y` (scrolling horizontally).
// If we `preventDefault()` while scrolling vertically, the window will not scroll.
if (abs(start.x - to.x) > abs(start.y - to.y)) {
e.preventDefault();
}
}
/**
* When `touchend` or `touchcancel` is triggered, clean up the swipe state.
* Also unbind `touchmove` events until another swipe occurs.
*/
function cleanup() {
start = target = null;
swiping = false;
self.off(moveEvent, move);
}
// Initialize the state when a touch occurs
self.on(startEvent, function(e) {
// Calling `preventDefault()` on start will disable clicking of elements (links, inputs, etc)
// So only do it on an `img` element so it cannot be dragged
if (!isTouch && e.target.tagName.toLowerCase() === 'img') {
e.preventDefault();
}
// Exit early if another swipe is occurring
if (swiping) {
return;
}
start = coords(e);
target = e.target;
swiping = true;
// Non-touch devices don't make use of the move event
if (isTouch) {
self.on(moveEvent, move);
}
});
// Trigger the swipe event when the touch finishes
self.on(stopEvent, function(e) {
swipe(start, coords(e), self, target);
cleanup();
});
// Reset the state when the touch is cancelled
self.on('touchcancel', cleanup);
} | [
"function",
"(",
")",
"{",
"var",
"self",
"=",
"$",
"(",
"this",
")",
",",
"start",
",",
"target",
";",
"/**\n * There's a major bug in Android devices where `touchend` events do not fire\n * without calling `preventDefault()` in `touchstart` or `touchmove`.\n * Because of this, we have to hack-ily implement functionality into `touchmove`.\n * We also can't use `touchcancel` as that fires prematurely and unbinds our move event.\n * More information on these bugs can be found here:\n *\n * https://code.google.com/p/android/issues/detail?id=19827\n * https://code.google.com/p/chromium/issues/detail?id=260732\n *\n * Using `touchcancel` is also rather unpredictable, as described here:\n *\n * http://alxgbsn.co.uk/2011/12/23/different-ways-to-trigger-touchcancel-in-mobile-browsers/\n */",
"function",
"move",
"(",
"e",
")",
"{",
"var",
"to",
"=",
"coords",
"(",
"e",
")",
";",
"// Trigger `preventDefault()` if `x` is larger than `y` (scrolling horizontally).",
"// If we `preventDefault()` while scrolling vertically, the window will not scroll.",
"if",
"(",
"abs",
"(",
"start",
".",
"x",
"-",
"to",
".",
"x",
")",
">",
"abs",
"(",
"start",
".",
"y",
"-",
"to",
".",
"y",
")",
")",
"{",
"e",
".",
"preventDefault",
"(",
")",
";",
"}",
"}",
"/**\n * When `touchend` or `touchcancel` is triggered, clean up the swipe state.\n * Also unbind `touchmove` events until another swipe occurs.\n */",
"function",
"cleanup",
"(",
")",
"{",
"start",
"=",
"target",
"=",
"null",
";",
"swiping",
"=",
"false",
";",
"self",
".",
"off",
"(",
"moveEvent",
",",
"move",
")",
";",
"}",
"// Initialize the state when a touch occurs",
"self",
".",
"on",
"(",
"startEvent",
",",
"function",
"(",
"e",
")",
"{",
"// Calling `preventDefault()` on start will disable clicking of elements (links, inputs, etc)",
"// So only do it on an `img` element so it cannot be dragged",
"if",
"(",
"!",
"isTouch",
"&&",
"e",
".",
"target",
".",
"tagName",
".",
"toLowerCase",
"(",
")",
"===",
"'img'",
")",
"{",
"e",
".",
"preventDefault",
"(",
")",
";",
"}",
"// Exit early if another swipe is occurring",
"if",
"(",
"swiping",
")",
"{",
"return",
";",
"}",
"start",
"=",
"coords",
"(",
"e",
")",
";",
"target",
"=",
"e",
".",
"target",
";",
"swiping",
"=",
"true",
";",
"// Non-touch devices don't make use of the move event",
"if",
"(",
"isTouch",
")",
"{",
"self",
".",
"on",
"(",
"moveEvent",
",",
"move",
")",
";",
"}",
"}",
")",
";",
"// Trigger the swipe event when the touch finishes",
"self",
".",
"on",
"(",
"stopEvent",
",",
"function",
"(",
"e",
")",
"{",
"swipe",
"(",
"start",
",",
"coords",
"(",
"e",
")",
",",
"self",
",",
"target",
")",
";",
"cleanup",
"(",
")",
";",
"}",
")",
";",
"// Reset the state when the touch is cancelled",
"self",
".",
"on",
"(",
"'touchcancel'",
",",
"cleanup",
")",
";",
"}"
] | Maximum distance to travel in the opposite direction | [
"Maximum",
"distance",
"to",
"travel",
"in",
"the",
"opposite",
"direction"
] | f0ed36d14cc6d72a7bdbc09da4b5bf7d3d664f0c | https://github.com/titon/toolkit/blob/f0ed36d14cc6d72a7bdbc09da4b5bf7d3d664f0c/dist/toolkit.js#L1607-L1679 | |
21,702 | titon/toolkit | dist/toolkit.js | cleanup | function cleanup() {
start = target = null;
swiping = false;
self.off(moveEvent, move);
} | javascript | function cleanup() {
start = target = null;
swiping = false;
self.off(moveEvent, move);
} | [
"function",
"cleanup",
"(",
")",
"{",
"start",
"=",
"target",
"=",
"null",
";",
"swiping",
"=",
"false",
";",
"self",
".",
"off",
"(",
"moveEvent",
",",
"move",
")",
";",
"}"
] | When `touchend` or `touchcancel` is triggered, clean up the swipe state.
Also unbind `touchmove` events until another swipe occurs. | [
"When",
"touchend",
"or",
"touchcancel",
"is",
"triggered",
"clean",
"up",
"the",
"swipe",
"state",
".",
"Also",
"unbind",
"touchmove",
"events",
"until",
"another",
"swipe",
"occurs",
"."
] | f0ed36d14cc6d72a7bdbc09da4b5bf7d3d664f0c | https://github.com/titon/toolkit/blob/f0ed36d14cc6d72a7bdbc09da4b5bf7d3d664f0c/dist/toolkit.js#L1640-L1645 |
21,703 | titon/toolkit | dist/toolkit.js | function() {
var options = this.options;
return this.wrapper = this.render(options.wrapperTemplate)
.addClass(Toolkit.buildTemplate(options.wrapperClass))
.attr('id', this.id('wrapper'))
.appendTo('body');
} | javascript | function() {
var options = this.options;
return this.wrapper = this.render(options.wrapperTemplate)
.addClass(Toolkit.buildTemplate(options.wrapperClass))
.attr('id', this.id('wrapper'))
.appendTo('body');
} | [
"function",
"(",
")",
"{",
"var",
"options",
"=",
"this",
".",
"options",
";",
"return",
"this",
".",
"wrapper",
"=",
"this",
".",
"render",
"(",
"options",
".",
"wrapperTemplate",
")",
".",
"addClass",
"(",
"Toolkit",
".",
"buildTemplate",
"(",
"options",
".",
"wrapperClass",
")",
")",
".",
"attr",
"(",
"'id'",
",",
"this",
".",
"id",
"(",
"'wrapper'",
")",
")",
".",
"appendTo",
"(",
"'body'",
")",
";",
"}"
] | Create the elements wrapper.
@return {jQuery} | [
"Create",
"the",
"elements",
"wrapper",
"."
] | f0ed36d14cc6d72a7bdbc09da4b5bf7d3d664f0c | https://github.com/titon/toolkit/blob/f0ed36d14cc6d72a7bdbc09da4b5bf7d3d664f0c/dist/toolkit.js#L2387-L2394 | |
21,704 | titon/toolkit | dist/toolkit.js | function(node, callback) {
var elements = this.elements,
el,
id = $(node).cache('toolkit.cid', function() {
return Math.random().toString(32).substr(2);
});
if (elements[id]) {
el = elements[id];
} else {
el = elements[id] = this.createElement(node);
if ($.type(callback) === 'function') {
callback.call(this, el);
}
}
return this.element = el;
} | javascript | function(node, callback) {
var elements = this.elements,
el,
id = $(node).cache('toolkit.cid', function() {
return Math.random().toString(32).substr(2);
});
if (elements[id]) {
el = elements[id];
} else {
el = elements[id] = this.createElement(node);
if ($.type(callback) === 'function') {
callback.call(this, el);
}
}
return this.element = el;
} | [
"function",
"(",
"node",
",",
"callback",
")",
"{",
"var",
"elements",
"=",
"this",
".",
"elements",
",",
"el",
",",
"id",
"=",
"$",
"(",
"node",
")",
".",
"cache",
"(",
"'toolkit.cid'",
",",
"function",
"(",
")",
"{",
"return",
"Math",
".",
"random",
"(",
")",
".",
"toString",
"(",
"32",
")",
".",
"substr",
"(",
"2",
")",
";",
"}",
")",
";",
"if",
"(",
"elements",
"[",
"id",
"]",
")",
"{",
"el",
"=",
"elements",
"[",
"id",
"]",
";",
"}",
"else",
"{",
"el",
"=",
"elements",
"[",
"id",
"]",
"=",
"this",
".",
"createElement",
"(",
"node",
")",
";",
"if",
"(",
"$",
".",
"type",
"(",
"callback",
")",
"===",
"'function'",
")",
"{",
"callback",
".",
"call",
"(",
"this",
",",
"el",
")",
";",
"}",
"}",
"return",
"this",
".",
"element",
"=",
"el",
";",
"}"
] | Attempt to find and return an element by a unique composite ID.
Each element is unique per node. If the element does not exist, create it.
@param {jQuery} node
@param {Function} [callback] - Callback to trigger once an element is created
@returns {jQuery} | [
"Attempt",
"to",
"find",
"and",
"return",
"an",
"element",
"by",
"a",
"unique",
"composite",
"ID",
".",
"Each",
"element",
"is",
"unique",
"per",
"node",
".",
"If",
"the",
"element",
"does",
"not",
"exist",
"create",
"it",
"."
] | f0ed36d14cc6d72a7bdbc09da4b5bf7d3d664f0c | https://github.com/titon/toolkit/blob/f0ed36d14cc6d72a7bdbc09da4b5bf7d3d664f0c/dist/toolkit.js#L2413-L2431 | |
21,705 | titon/toolkit | dist/toolkit.js | function(e) {
var node = $(e.currentTarget),
element,
isNode = (this.node && this.node.is(node)),
cid = node.data('toolkit.cid');
// Set the current element based on the nodes composite ID
if (cid && this.elements[cid]) {
element = this.elements[cid];
} else {
element = this.element;
}
if (element && element.is(':shown')) {
// Touch devices should pass through on second click
if (Toolkit.isTouch) {
if (!isNode || this.node.prop('tagName').toLowerCase() !== 'a') {
e.preventDefault();
}
// Non-touch devices
} else {
e.preventDefault();
}
if (isNode) {
// Second click should close it
if (this.options.mode === 'click') {
this.hide();
}
// Exit if the same node so it doesn't re-open
return;
}
} else {
e.preventDefault();
}
this.show(node);
} | javascript | function(e) {
var node = $(e.currentTarget),
element,
isNode = (this.node && this.node.is(node)),
cid = node.data('toolkit.cid');
// Set the current element based on the nodes composite ID
if (cid && this.elements[cid]) {
element = this.elements[cid];
} else {
element = this.element;
}
if (element && element.is(':shown')) {
// Touch devices should pass through on second click
if (Toolkit.isTouch) {
if (!isNode || this.node.prop('tagName').toLowerCase() !== 'a') {
e.preventDefault();
}
// Non-touch devices
} else {
e.preventDefault();
}
if (isNode) {
// Second click should close it
if (this.options.mode === 'click') {
this.hide();
}
// Exit if the same node so it doesn't re-open
return;
}
} else {
e.preventDefault();
}
this.show(node);
} | [
"function",
"(",
"e",
")",
"{",
"var",
"node",
"=",
"$",
"(",
"e",
".",
"currentTarget",
")",
",",
"element",
",",
"isNode",
"=",
"(",
"this",
".",
"node",
"&&",
"this",
".",
"node",
".",
"is",
"(",
"node",
")",
")",
",",
"cid",
"=",
"node",
".",
"data",
"(",
"'toolkit.cid'",
")",
";",
"// Set the current element based on the nodes composite ID",
"if",
"(",
"cid",
"&&",
"this",
".",
"elements",
"[",
"cid",
"]",
")",
"{",
"element",
"=",
"this",
".",
"elements",
"[",
"cid",
"]",
";",
"}",
"else",
"{",
"element",
"=",
"this",
".",
"element",
";",
"}",
"if",
"(",
"element",
"&&",
"element",
".",
"is",
"(",
"':shown'",
")",
")",
"{",
"// Touch devices should pass through on second click",
"if",
"(",
"Toolkit",
".",
"isTouch",
")",
"{",
"if",
"(",
"!",
"isNode",
"||",
"this",
".",
"node",
".",
"prop",
"(",
"'tagName'",
")",
".",
"toLowerCase",
"(",
")",
"!==",
"'a'",
")",
"{",
"e",
".",
"preventDefault",
"(",
")",
";",
"}",
"// Non-touch devices",
"}",
"else",
"{",
"e",
".",
"preventDefault",
"(",
")",
";",
"}",
"if",
"(",
"isNode",
")",
"{",
"// Second click should close it",
"if",
"(",
"this",
".",
"options",
".",
"mode",
"===",
"'click'",
")",
"{",
"this",
".",
"hide",
"(",
")",
";",
"}",
"// Exit if the same node so it doesn't re-open",
"return",
";",
"}",
"}",
"else",
"{",
"e",
".",
"preventDefault",
"(",
")",
";",
"}",
"this",
".",
"show",
"(",
"node",
")",
";",
"}"
] | Event handler for toggling an element through click or hover events.
@param {jQuery.Event} e
@private | [
"Event",
"handler",
"for",
"toggling",
"an",
"element",
"through",
"click",
"or",
"hover",
"events",
"."
] | f0ed36d14cc6d72a7bdbc09da4b5bf7d3d664f0c | https://github.com/titon/toolkit/blob/f0ed36d14cc6d72a7bdbc09da4b5bf7d3d664f0c/dist/toolkit.js#L2461-L2502 | |
21,706 | titon/toolkit | dist/toolkit.js | function(node) {
var target = this.readValue(node, this.options.getTarget);
if (!target || target.substr(0, 1) !== '#') {
throw new Error('Drop menu ' + target + ' does not exist');
}
return $(target);
} | javascript | function(node) {
var target = this.readValue(node, this.options.getTarget);
if (!target || target.substr(0, 1) !== '#') {
throw new Error('Drop menu ' + target + ' does not exist');
}
return $(target);
} | [
"function",
"(",
"node",
")",
"{",
"var",
"target",
"=",
"this",
".",
"readValue",
"(",
"node",
",",
"this",
".",
"options",
".",
"getTarget",
")",
";",
"if",
"(",
"!",
"target",
"||",
"target",
".",
"substr",
"(",
"0",
",",
"1",
")",
"!==",
"'#'",
")",
"{",
"throw",
"new",
"Error",
"(",
"'Drop menu '",
"+",
"target",
"+",
"' does not exist'",
")",
";",
"}",
"return",
"$",
"(",
"target",
")",
";",
"}"
] | Find the menu for the current node.
@param {jQuery} node | [
"Find",
"the",
"menu",
"for",
"the",
"current",
"node",
"."
] | f0ed36d14cc6d72a7bdbc09da4b5bf7d3d664f0c | https://github.com/titon/toolkit/blob/f0ed36d14cc6d72a7bdbc09da4b5bf7d3d664f0c/dist/toolkit.js#L2620-L2628 | |
21,707 | titon/toolkit | dist/toolkit.js | function() {
var element = this.element,
node = this.node;
// Clickout check
if (!element && !node) {
return;
}
this.fireEvent('hiding', [element, node]);
element.conceal();
node
.aria('toggled', false)
.removeClass('is-active');
this.fireEvent('hidden', [element, node]);
} | javascript | function() {
var element = this.element,
node = this.node;
// Clickout check
if (!element && !node) {
return;
}
this.fireEvent('hiding', [element, node]);
element.conceal();
node
.aria('toggled', false)
.removeClass('is-active');
this.fireEvent('hidden', [element, node]);
} | [
"function",
"(",
")",
"{",
"var",
"element",
"=",
"this",
".",
"element",
",",
"node",
"=",
"this",
".",
"node",
";",
"// Clickout check",
"if",
"(",
"!",
"element",
"&&",
"!",
"node",
")",
"{",
"return",
";",
"}",
"this",
".",
"fireEvent",
"(",
"'hiding'",
",",
"[",
"element",
",",
"node",
"]",
")",
";",
"element",
".",
"conceal",
"(",
")",
";",
"node",
".",
"aria",
"(",
"'toggled'",
",",
"false",
")",
".",
"removeClass",
"(",
"'is-active'",
")",
";",
"this",
".",
"fireEvent",
"(",
"'hidden'",
",",
"[",
"element",
",",
"node",
"]",
")",
";",
"}"
] | Hide the opened menu and reset the nodes active state. | [
"Hide",
"the",
"opened",
"menu",
"and",
"reset",
"the",
"nodes",
"active",
"state",
"."
] | f0ed36d14cc6d72a7bdbc09da4b5bf7d3d664f0c | https://github.com/titon/toolkit/blob/f0ed36d14cc6d72a7bdbc09da4b5bf7d3d664f0c/dist/toolkit.js#L2633-L2651 | |
21,708 | titon/toolkit | dist/toolkit.js | function(node) {
this.node = node = $(node);
var element = this.loadElement(node);
this.fireEvent('showing', [element, node]);
element.reveal();
node
.aria('toggled', true)
.addClass('is-active');
this.fireEvent('shown', [element, node]);
} | javascript | function(node) {
this.node = node = $(node);
var element = this.loadElement(node);
this.fireEvent('showing', [element, node]);
element.reveal();
node
.aria('toggled', true)
.addClass('is-active');
this.fireEvent('shown', [element, node]);
} | [
"function",
"(",
"node",
")",
"{",
"this",
".",
"node",
"=",
"node",
"=",
"$",
"(",
"node",
")",
";",
"var",
"element",
"=",
"this",
".",
"loadElement",
"(",
"node",
")",
";",
"this",
".",
"fireEvent",
"(",
"'showing'",
",",
"[",
"element",
",",
"node",
"]",
")",
";",
"element",
".",
"reveal",
"(",
")",
";",
"node",
".",
"aria",
"(",
"'toggled'",
",",
"true",
")",
".",
"addClass",
"(",
"'is-active'",
")",
";",
"this",
".",
"fireEvent",
"(",
"'shown'",
",",
"[",
"element",
",",
"node",
"]",
")",
";",
"}"
] | Open the target menu and apply active state to the node.
@param {jQuery} node | [
"Open",
"the",
"target",
"menu",
"and",
"apply",
"active",
"state",
"to",
"the",
"node",
"."
] | f0ed36d14cc6d72a7bdbc09da4b5bf7d3d664f0c | https://github.com/titon/toolkit/blob/f0ed36d14cc6d72a7bdbc09da4b5bf7d3d664f0c/dist/toolkit.js#L2658-L2672 | |
21,709 | titon/toolkit | dist/toolkit.js | function(e) {
e.preventDefault();
// Hide previous drops
this.hide();
// Toggle the menu
var node = $(e.currentTarget),
menu = this.loadElement(node);
if (!menu.is(':shown')) {
this.show(node);
} else {
this.hide();
}
} | javascript | function(e) {
e.preventDefault();
// Hide previous drops
this.hide();
// Toggle the menu
var node = $(e.currentTarget),
menu = this.loadElement(node);
if (!menu.is(':shown')) {
this.show(node);
} else {
this.hide();
}
} | [
"function",
"(",
"e",
")",
"{",
"e",
".",
"preventDefault",
"(",
")",
";",
"// Hide previous drops",
"this",
".",
"hide",
"(",
")",
";",
"// Toggle the menu",
"var",
"node",
"=",
"$",
"(",
"e",
".",
"currentTarget",
")",
",",
"menu",
"=",
"this",
".",
"loadElement",
"(",
"node",
")",
";",
"if",
"(",
"!",
"menu",
".",
"is",
"(",
"':shown'",
")",
")",
"{",
"this",
".",
"show",
"(",
"node",
")",
";",
"}",
"else",
"{",
"this",
".",
"hide",
"(",
")",
";",
"}",
"}"
] | When a node is clicked, grab the target from the attribute.
Validate the target element, then either display or hide.
@param {jQuery.Event} e
@private | [
"When",
"a",
"node",
"is",
"clicked",
"grab",
"the",
"target",
"from",
"the",
"attribute",
".",
"Validate",
"the",
"target",
"element",
"then",
"either",
"display",
"or",
"hide",
"."
] | f0ed36d14cc6d72a7bdbc09da4b5bf7d3d664f0c | https://github.com/titon/toolkit/blob/f0ed36d14cc6d72a7bdbc09da4b5bf7d3d664f0c/dist/toolkit.js#L2681-L2697 | |
21,710 | titon/toolkit | dist/toolkit.js | function(nodes, url, options) {
if (Toolkit.isTouch) {
return; // Flyouts shouldn't be usable on touch devices
}
this.nodes = $(nodes);
options = this.setOptions(options);
this.createWrapper();
if (options.mode === 'click') {
this.addEvents([
['click', 'document', 'onShowToggle', '{selector}'],
['resize', 'window', $.debounce(this.onHide.bind(this))]
]);
} else {
this.addEvents([
['mouseenter', 'document', 'onShowToggle', '{selector}'],
['mouseenter', 'document', 'onEnter', '{selector}'],
['mouseleave', 'document', 'onLeave', '{selector}']
]);
}
this.initialize();
// Load data from the URL
if (url) {
$.getJSON(url, function(response) {
this.load(response);
}.bind(this));
}
} | javascript | function(nodes, url, options) {
if (Toolkit.isTouch) {
return; // Flyouts shouldn't be usable on touch devices
}
this.nodes = $(nodes);
options = this.setOptions(options);
this.createWrapper();
if (options.mode === 'click') {
this.addEvents([
['click', 'document', 'onShowToggle', '{selector}'],
['resize', 'window', $.debounce(this.onHide.bind(this))]
]);
} else {
this.addEvents([
['mouseenter', 'document', 'onShowToggle', '{selector}'],
['mouseenter', 'document', 'onEnter', '{selector}'],
['mouseleave', 'document', 'onLeave', '{selector}']
]);
}
this.initialize();
// Load data from the URL
if (url) {
$.getJSON(url, function(response) {
this.load(response);
}.bind(this));
}
} | [
"function",
"(",
"nodes",
",",
"url",
",",
"options",
")",
"{",
"if",
"(",
"Toolkit",
".",
"isTouch",
")",
"{",
"return",
";",
"// Flyouts shouldn't be usable on touch devices",
"}",
"this",
".",
"nodes",
"=",
"$",
"(",
"nodes",
")",
";",
"options",
"=",
"this",
".",
"setOptions",
"(",
"options",
")",
";",
"this",
".",
"createWrapper",
"(",
")",
";",
"if",
"(",
"options",
".",
"mode",
"===",
"'click'",
")",
"{",
"this",
".",
"addEvents",
"(",
"[",
"[",
"'click'",
",",
"'document'",
",",
"'onShowToggle'",
",",
"'{selector}'",
"]",
",",
"[",
"'resize'",
",",
"'window'",
",",
"$",
".",
"debounce",
"(",
"this",
".",
"onHide",
".",
"bind",
"(",
"this",
")",
")",
"]",
"]",
")",
";",
"}",
"else",
"{",
"this",
".",
"addEvents",
"(",
"[",
"[",
"'mouseenter'",
",",
"'document'",
",",
"'onShowToggle'",
",",
"'{selector}'",
"]",
",",
"[",
"'mouseenter'",
",",
"'document'",
",",
"'onEnter'",
",",
"'{selector}'",
"]",
",",
"[",
"'mouseleave'",
",",
"'document'",
",",
"'onLeave'",
",",
"'{selector}'",
"]",
"]",
")",
";",
"}",
"this",
".",
"initialize",
"(",
")",
";",
"// Load data from the URL",
"if",
"(",
"url",
")",
"{",
"$",
".",
"getJSON",
"(",
"url",
",",
"function",
"(",
"response",
")",
"{",
"this",
".",
"load",
"(",
"response",
")",
";",
"}",
".",
"bind",
"(",
"this",
")",
")",
";",
"}",
"}"
] | Initialize the flyout. A URL is required during construction.
@param {jQuery} nodes
@param {String} url
@param {Object} [options] | [
"Initialize",
"the",
"flyout",
".",
"A",
"URL",
"is",
"required",
"during",
"construction",
"."
] | f0ed36d14cc6d72a7bdbc09da4b5bf7d3d664f0c | https://github.com/titon/toolkit/blob/f0ed36d14cc6d72a7bdbc09da4b5bf7d3d664f0c/dist/toolkit.js#L2731-L2761 | |
21,711 | titon/toolkit | dist/toolkit.js | function(data, depth) {
depth = depth || 0;
// If root, store the data
if (!depth) {
this.data = data;
}
// Store the data indexed by URL
if (data.url) {
this.dataMap[data.url] = data;
}
if (data.children) {
for (var i = 0, l = data.children.length; i < l; i++) {
this.load(data.children[i], depth + 1);
}
}
} | javascript | function(data, depth) {
depth = depth || 0;
// If root, store the data
if (!depth) {
this.data = data;
}
// Store the data indexed by URL
if (data.url) {
this.dataMap[data.url] = data;
}
if (data.children) {
for (var i = 0, l = data.children.length; i < l; i++) {
this.load(data.children[i], depth + 1);
}
}
} | [
"function",
"(",
"data",
",",
"depth",
")",
"{",
"depth",
"=",
"depth",
"||",
"0",
";",
"// If root, store the data",
"if",
"(",
"!",
"depth",
")",
"{",
"this",
".",
"data",
"=",
"data",
";",
"}",
"// Store the data indexed by URL",
"if",
"(",
"data",
".",
"url",
")",
"{",
"this",
".",
"dataMap",
"[",
"data",
".",
"url",
"]",
"=",
"data",
";",
"}",
"if",
"(",
"data",
".",
"children",
")",
"{",
"for",
"(",
"var",
"i",
"=",
"0",
",",
"l",
"=",
"data",
".",
"children",
".",
"length",
";",
"i",
"<",
"l",
";",
"i",
"++",
")",
"{",
"this",
".",
"load",
"(",
"data",
".",
"children",
"[",
"i",
"]",
",",
"depth",
"+",
"1",
")",
";",
"}",
"}",
"}"
] | Load the data into the class and save a mapping of it.
@param {Object} data
@param {Number} [depth] | [
"Load",
"the",
"data",
"into",
"the",
"class",
"and",
"save",
"a",
"mapping",
"of",
"it",
"."
] | f0ed36d14cc6d72a7bdbc09da4b5bf7d3d664f0c | https://github.com/titon/toolkit/blob/f0ed36d14cc6d72a7bdbc09da4b5bf7d3d664f0c/dist/toolkit.js#L2800-L2818 | |
21,712 | titon/toolkit | dist/toolkit.js | function() {
var options = this.options,
node = this.node,
element = this.loadElement(node);
// Only position if the menu has children
if (!element.children().length) {
return;
}
this.fireEvent('showing');
var height = element.outerHeight(),
coords = node.offset(),
x = coords.left + options.xOffset,
y = coords.top + options.yOffset + node.outerHeight(),
windowScroll = $(window).height(),
dir = 'left';
// If menu goes below half page, position it above
if (y > (windowScroll / 2)) {
y = coords.top - options.yOffset - height;
}
// Change position for RTL
if (Toolkit.isRTL) {
x = $(window).width() - coords.left - node.outerWidth();
dir = 'right';
}
element
.css('top', y)
.css(dir, x)
.reveal();
this.fireEvent('shown');
} | javascript | function() {
var options = this.options,
node = this.node,
element = this.loadElement(node);
// Only position if the menu has children
if (!element.children().length) {
return;
}
this.fireEvent('showing');
var height = element.outerHeight(),
coords = node.offset(),
x = coords.left + options.xOffset,
y = coords.top + options.yOffset + node.outerHeight(),
windowScroll = $(window).height(),
dir = 'left';
// If menu goes below half page, position it above
if (y > (windowScroll / 2)) {
y = coords.top - options.yOffset - height;
}
// Change position for RTL
if (Toolkit.isRTL) {
x = $(window).width() - coords.left - node.outerWidth();
dir = 'right';
}
element
.css('top', y)
.css(dir, x)
.reveal();
this.fireEvent('shown');
} | [
"function",
"(",
")",
"{",
"var",
"options",
"=",
"this",
".",
"options",
",",
"node",
"=",
"this",
".",
"node",
",",
"element",
"=",
"this",
".",
"loadElement",
"(",
"node",
")",
";",
"// Only position if the menu has children",
"if",
"(",
"!",
"element",
".",
"children",
"(",
")",
".",
"length",
")",
"{",
"return",
";",
"}",
"this",
".",
"fireEvent",
"(",
"'showing'",
")",
";",
"var",
"height",
"=",
"element",
".",
"outerHeight",
"(",
")",
",",
"coords",
"=",
"node",
".",
"offset",
"(",
")",
",",
"x",
"=",
"coords",
".",
"left",
"+",
"options",
".",
"xOffset",
",",
"y",
"=",
"coords",
".",
"top",
"+",
"options",
".",
"yOffset",
"+",
"node",
".",
"outerHeight",
"(",
")",
",",
"windowScroll",
"=",
"$",
"(",
"window",
")",
".",
"height",
"(",
")",
",",
"dir",
"=",
"'left'",
";",
"// If menu goes below half page, position it above",
"if",
"(",
"y",
">",
"(",
"windowScroll",
"/",
"2",
")",
")",
"{",
"y",
"=",
"coords",
".",
"top",
"-",
"options",
".",
"yOffset",
"-",
"height",
";",
"}",
"// Change position for RTL",
"if",
"(",
"Toolkit",
".",
"isRTL",
")",
"{",
"x",
"=",
"$",
"(",
"window",
")",
".",
"width",
"(",
")",
"-",
"coords",
".",
"left",
"-",
"node",
".",
"outerWidth",
"(",
")",
";",
"dir",
"=",
"'right'",
";",
"}",
"element",
".",
"css",
"(",
"'top'",
",",
"y",
")",
".",
"css",
"(",
"dir",
",",
"x",
")",
".",
"reveal",
"(",
")",
";",
"this",
".",
"fireEvent",
"(",
"'shown'",
")",
";",
"}"
] | Position the menu below the target node. | [
"Position",
"the",
"menu",
"below",
"the",
"target",
"node",
"."
] | f0ed36d14cc6d72a7bdbc09da4b5bf7d3d664f0c | https://github.com/titon/toolkit/blob/f0ed36d14cc6d72a7bdbc09da4b5bf7d3d664f0c/dist/toolkit.js#L2823-L2859 | |
21,713 | titon/toolkit | dist/toolkit.js | function(node) {
node = $(node);
var target = this.readValue(node, this.options.getUrl) || node.attr('href');
// When jumping from one node to another
// Immediately hide the other menu and start the timer for the current one
if (this.url && target !== this.url) {
this.hide();
this.startTimer('show', this.options.showDelay);
}
// Set the state
this.url = target;
this.node = node.addClass('is-active');
// Load the menu
this.loadElement(node, function(flyout) {
flyout.addClass('is-root');
if (this.dataMap[target]) {
this._buildMenu(flyout, this.dataMap[target]);
}
});
// Display immediately if click
if (this.options.mode === 'click') {
this.position();
}
} | javascript | function(node) {
node = $(node);
var target = this.readValue(node, this.options.getUrl) || node.attr('href');
// When jumping from one node to another
// Immediately hide the other menu and start the timer for the current one
if (this.url && target !== this.url) {
this.hide();
this.startTimer('show', this.options.showDelay);
}
// Set the state
this.url = target;
this.node = node.addClass('is-active');
// Load the menu
this.loadElement(node, function(flyout) {
flyout.addClass('is-root');
if (this.dataMap[target]) {
this._buildMenu(flyout, this.dataMap[target]);
}
});
// Display immediately if click
if (this.options.mode === 'click') {
this.position();
}
} | [
"function",
"(",
"node",
")",
"{",
"node",
"=",
"$",
"(",
"node",
")",
";",
"var",
"target",
"=",
"this",
".",
"readValue",
"(",
"node",
",",
"this",
".",
"options",
".",
"getUrl",
")",
"||",
"node",
".",
"attr",
"(",
"'href'",
")",
";",
"// When jumping from one node to another",
"// Immediately hide the other menu and start the timer for the current one",
"if",
"(",
"this",
".",
"url",
"&&",
"target",
"!==",
"this",
".",
"url",
")",
"{",
"this",
".",
"hide",
"(",
")",
";",
"this",
".",
"startTimer",
"(",
"'show'",
",",
"this",
".",
"options",
".",
"showDelay",
")",
";",
"}",
"// Set the state",
"this",
".",
"url",
"=",
"target",
";",
"this",
".",
"node",
"=",
"node",
".",
"addClass",
"(",
"'is-active'",
")",
";",
"// Load the menu",
"this",
".",
"loadElement",
"(",
"node",
",",
"function",
"(",
"flyout",
")",
"{",
"flyout",
".",
"addClass",
"(",
"'is-root'",
")",
";",
"if",
"(",
"this",
".",
"dataMap",
"[",
"target",
"]",
")",
"{",
"this",
".",
"_buildMenu",
"(",
"flyout",
",",
"this",
".",
"dataMap",
"[",
"target",
"]",
")",
";",
"}",
"}",
")",
";",
"// Display immediately if click",
"if",
"(",
"this",
".",
"options",
".",
"mode",
"===",
"'click'",
")",
"{",
"this",
".",
"position",
"(",
")",
";",
"}",
"}"
] | Show the menu below the node.
@param {jQuery} node | [
"Show",
"the",
"menu",
"below",
"the",
"node",
"."
] | f0ed36d14cc6d72a7bdbc09da4b5bf7d3d664f0c | https://github.com/titon/toolkit/blob/f0ed36d14cc6d72a7bdbc09da4b5bf7d3d664f0c/dist/toolkit.js#L2866-L2895 | |
21,714 | titon/toolkit | dist/toolkit.js | function(key, delay, args) {
this.clearTimer(key);
var func;
if (key === 'show') {
func = this.position;
} else {
func = this.hide;
}
if (func) {
this.timers[key] = setTimeout(function() {
func.apply(this, args || []);
}.bind(this), delay);
}
} | javascript | function(key, delay, args) {
this.clearTimer(key);
var func;
if (key === 'show') {
func = this.position;
} else {
func = this.hide;
}
if (func) {
this.timers[key] = setTimeout(function() {
func.apply(this, args || []);
}.bind(this), delay);
}
} | [
"function",
"(",
"key",
",",
"delay",
",",
"args",
")",
"{",
"this",
".",
"clearTimer",
"(",
"key",
")",
";",
"var",
"func",
";",
"if",
"(",
"key",
"===",
"'show'",
")",
"{",
"func",
"=",
"this",
".",
"position",
";",
"}",
"else",
"{",
"func",
"=",
"this",
".",
"hide",
";",
"}",
"if",
"(",
"func",
")",
"{",
"this",
".",
"timers",
"[",
"key",
"]",
"=",
"setTimeout",
"(",
"function",
"(",
")",
"{",
"func",
".",
"apply",
"(",
"this",
",",
"args",
"||",
"[",
"]",
")",
";",
"}",
".",
"bind",
"(",
"this",
")",
",",
"delay",
")",
";",
"}",
"}"
] | Add a timer that should trigger a function after a delay.
@param {String} key
@param {Number} delay
@param {Array} [args] | [
"Add",
"a",
"timer",
"that",
"should",
"trigger",
"a",
"function",
"after",
"a",
"delay",
"."
] | f0ed36d14cc6d72a7bdbc09da4b5bf7d3d664f0c | https://github.com/titon/toolkit/blob/f0ed36d14cc6d72a7bdbc09da4b5bf7d3d664f0c/dist/toolkit.js#L2904-L2920 | |
21,715 | titon/toolkit | dist/toolkit.js | function(parent) {
parent = $(parent);
parent.removeClass('is-open');
parent.children(this.ns('menu'))
.removeAttr('style')
.aria({
expanded: false,
hidden: false
})
.conceal();
this.fireEvent('hideChild', [parent]);
} | javascript | function(parent) {
parent = $(parent);
parent.removeClass('is-open');
parent.children(this.ns('menu'))
.removeAttr('style')
.aria({
expanded: false,
hidden: false
})
.conceal();
this.fireEvent('hideChild', [parent]);
} | [
"function",
"(",
"parent",
")",
"{",
"parent",
"=",
"$",
"(",
"parent",
")",
";",
"parent",
".",
"removeClass",
"(",
"'is-open'",
")",
";",
"parent",
".",
"children",
"(",
"this",
".",
"ns",
"(",
"'menu'",
")",
")",
".",
"removeAttr",
"(",
"'style'",
")",
".",
"aria",
"(",
"{",
"expanded",
":",
"false",
",",
"hidden",
":",
"false",
"}",
")",
".",
"conceal",
"(",
")",
";",
"this",
".",
"fireEvent",
"(",
"'hideChild'",
",",
"[",
"parent",
"]",
")",
";",
"}"
] | Event handler to hide the child menu after exiting parent li.
@private
@param {jQuery} parent | [
"Event",
"handler",
"to",
"hide",
"the",
"child",
"menu",
"after",
"exiting",
"parent",
"li",
"."
] | f0ed36d14cc6d72a7bdbc09da4b5bf7d3d664f0c | https://github.com/titon/toolkit/blob/f0ed36d14cc6d72a7bdbc09da4b5bf7d3d664f0c/dist/toolkit.js#L3046-L3058 | |
21,716 | titon/toolkit | dist/toolkit.js | function(parent) {
var menu = parent.children(this.ns('menu'));
if (!menu) {
return;
}
menu.aria({
expanded: true,
hidden: true
});
// Alter width because of columns
var children = menu.children();
menu.css('width', (children.outerWidth() * children.length) + 'px');
// Get sizes after menu positioning
var win = $(window),
winHeight = win.height() + win.scrollTop(),
parentOffset = parent.offset(),
parentHeight = parent.outerHeight(),
oppositeClass = 'push-opposite';
// Display menu horizontally on opposite side if it spills out of viewport
if (Toolkit.isRTL) {
if ((parentOffset.left - menu.outerWidth()) < 0) {
menu.addClass(oppositeClass);
} else {
menu.removeClass(oppositeClass);
}
} else {
if ((parentOffset.left + parent.outerWidth() + menu.outerWidth()) >= win.width()) {
menu.addClass(oppositeClass);
} else {
menu.removeClass(oppositeClass);
}
}
// Reverse menu vertically if below half way fold
if (parentOffset.top > (winHeight / 2)) {
menu.css('top', '-' + (menu.outerHeight() - parentHeight) + 'px');
} else {
menu.css('top', 0);
}
parent.addClass('is-open');
menu.reveal();
this.fireEvent('showChild', [parent]);
} | javascript | function(parent) {
var menu = parent.children(this.ns('menu'));
if (!menu) {
return;
}
menu.aria({
expanded: true,
hidden: true
});
// Alter width because of columns
var children = menu.children();
menu.css('width', (children.outerWidth() * children.length) + 'px');
// Get sizes after menu positioning
var win = $(window),
winHeight = win.height() + win.scrollTop(),
parentOffset = parent.offset(),
parentHeight = parent.outerHeight(),
oppositeClass = 'push-opposite';
// Display menu horizontally on opposite side if it spills out of viewport
if (Toolkit.isRTL) {
if ((parentOffset.left - menu.outerWidth()) < 0) {
menu.addClass(oppositeClass);
} else {
menu.removeClass(oppositeClass);
}
} else {
if ((parentOffset.left + parent.outerWidth() + menu.outerWidth()) >= win.width()) {
menu.addClass(oppositeClass);
} else {
menu.removeClass(oppositeClass);
}
}
// Reverse menu vertically if below half way fold
if (parentOffset.top > (winHeight / 2)) {
menu.css('top', '-' + (menu.outerHeight() - parentHeight) + 'px');
} else {
menu.css('top', 0);
}
parent.addClass('is-open');
menu.reveal();
this.fireEvent('showChild', [parent]);
} | [
"function",
"(",
"parent",
")",
"{",
"var",
"menu",
"=",
"parent",
".",
"children",
"(",
"this",
".",
"ns",
"(",
"'menu'",
")",
")",
";",
"if",
"(",
"!",
"menu",
")",
"{",
"return",
";",
"}",
"menu",
".",
"aria",
"(",
"{",
"expanded",
":",
"true",
",",
"hidden",
":",
"true",
"}",
")",
";",
"// Alter width because of columns",
"var",
"children",
"=",
"menu",
".",
"children",
"(",
")",
";",
"menu",
".",
"css",
"(",
"'width'",
",",
"(",
"children",
".",
"outerWidth",
"(",
")",
"*",
"children",
".",
"length",
")",
"+",
"'px'",
")",
";",
"// Get sizes after menu positioning",
"var",
"win",
"=",
"$",
"(",
"window",
")",
",",
"winHeight",
"=",
"win",
".",
"height",
"(",
")",
"+",
"win",
".",
"scrollTop",
"(",
")",
",",
"parentOffset",
"=",
"parent",
".",
"offset",
"(",
")",
",",
"parentHeight",
"=",
"parent",
".",
"outerHeight",
"(",
")",
",",
"oppositeClass",
"=",
"'push-opposite'",
";",
"// Display menu horizontally on opposite side if it spills out of viewport",
"if",
"(",
"Toolkit",
".",
"isRTL",
")",
"{",
"if",
"(",
"(",
"parentOffset",
".",
"left",
"-",
"menu",
".",
"outerWidth",
"(",
")",
")",
"<",
"0",
")",
"{",
"menu",
".",
"addClass",
"(",
"oppositeClass",
")",
";",
"}",
"else",
"{",
"menu",
".",
"removeClass",
"(",
"oppositeClass",
")",
";",
"}",
"}",
"else",
"{",
"if",
"(",
"(",
"parentOffset",
".",
"left",
"+",
"parent",
".",
"outerWidth",
"(",
")",
"+",
"menu",
".",
"outerWidth",
"(",
")",
")",
">=",
"win",
".",
"width",
"(",
")",
")",
"{",
"menu",
".",
"addClass",
"(",
"oppositeClass",
")",
";",
"}",
"else",
"{",
"menu",
".",
"removeClass",
"(",
"oppositeClass",
")",
";",
"}",
"}",
"// Reverse menu vertically if below half way fold",
"if",
"(",
"parentOffset",
".",
"top",
">",
"(",
"winHeight",
"/",
"2",
")",
")",
"{",
"menu",
".",
"css",
"(",
"'top'",
",",
"'-'",
"+",
"(",
"menu",
".",
"outerHeight",
"(",
")",
"-",
"parentHeight",
")",
"+",
"'px'",
")",
";",
"}",
"else",
"{",
"menu",
".",
"css",
"(",
"'top'",
",",
"0",
")",
";",
"}",
"parent",
".",
"addClass",
"(",
"'is-open'",
")",
";",
"menu",
".",
"reveal",
"(",
")",
";",
"this",
".",
"fireEvent",
"(",
"'showChild'",
",",
"[",
"parent",
"]",
")",
";",
"}"
] | Event handler to position the child menu dependent on the position in the page.
@private
@param {jQuery} parent | [
"Event",
"handler",
"to",
"position",
"the",
"child",
"menu",
"dependent",
"on",
"the",
"position",
"in",
"the",
"page",
"."
] | f0ed36d14cc6d72a7bdbc09da4b5bf7d3d664f0c | https://github.com/titon/toolkit/blob/f0ed36d14cc6d72a7bdbc09da4b5bf7d3d664f0c/dist/toolkit.js#L3076-L3126 | |
21,717 | titon/toolkit | dist/toolkit.js | function(element, options) {
element = this.setElement(element);
options = this.setOptions(options, element);
if (options.checkbox) {
element.find(options.checkbox).inputCheckbox(options);
}
if (options.radio) {
element.find(options.radio).inputRadio(options);
}
if (options.select) {
element.find(options.select).inputSelect(options);
}
this.initialize();
} | javascript | function(element, options) {
element = this.setElement(element);
options = this.setOptions(options, element);
if (options.checkbox) {
element.find(options.checkbox).inputCheckbox(options);
}
if (options.radio) {
element.find(options.radio).inputRadio(options);
}
if (options.select) {
element.find(options.select).inputSelect(options);
}
this.initialize();
} | [
"function",
"(",
"element",
",",
"options",
")",
"{",
"element",
"=",
"this",
".",
"setElement",
"(",
"element",
")",
";",
"options",
"=",
"this",
".",
"setOptions",
"(",
"options",
",",
"element",
")",
";",
"if",
"(",
"options",
".",
"checkbox",
")",
"{",
"element",
".",
"find",
"(",
"options",
".",
"checkbox",
")",
".",
"inputCheckbox",
"(",
"options",
")",
";",
"}",
"if",
"(",
"options",
".",
"radio",
")",
"{",
"element",
".",
"find",
"(",
"options",
".",
"radio",
")",
".",
"inputRadio",
"(",
"options",
")",
";",
"}",
"if",
"(",
"options",
".",
"select",
")",
"{",
"element",
".",
"find",
"(",
"options",
".",
"select",
")",
".",
"inputSelect",
"(",
"options",
")",
";",
"}",
"this",
".",
"initialize",
"(",
")",
";",
"}"
] | Initialize the input.
@param {jQuery} element
@param {Object} [options] | [
"Initialize",
"the",
"input",
"."
] | f0ed36d14cc6d72a7bdbc09da4b5bf7d3d664f0c | https://github.com/titon/toolkit/blob/f0ed36d14cc6d72a7bdbc09da4b5bf7d3d664f0c/dist/toolkit.js#L3167-L3184 | |
21,718 | titon/toolkit | dist/toolkit.js | function() {
var options = this.options,
element = this.element;
if (this.name === 'Input') {
if (options.checkbox) {
element.find(options.checkbox).each(function() {
$(this).toolkit('inputCheckbox', 'destroy');
});
}
if (options.radio) {
element.find(options.radio).each(function() {
$(this).toolkit('inputRadio', 'destroy');
});
}
if (options.select) {
element.find(options.select).each(function() {
$(this).toolkit('inputSelect', 'destroy');
});
}
// Check for the wrapper as some inputs may be initialized but not used.
// Multi-selects using native controls for example.
} else if (this.wrapper) {
this.wrapper.replaceWith(element);
element.removeAttr('style');
}
} | javascript | function() {
var options = this.options,
element = this.element;
if (this.name === 'Input') {
if (options.checkbox) {
element.find(options.checkbox).each(function() {
$(this).toolkit('inputCheckbox', 'destroy');
});
}
if (options.radio) {
element.find(options.radio).each(function() {
$(this).toolkit('inputRadio', 'destroy');
});
}
if (options.select) {
element.find(options.select).each(function() {
$(this).toolkit('inputSelect', 'destroy');
});
}
// Check for the wrapper as some inputs may be initialized but not used.
// Multi-selects using native controls for example.
} else if (this.wrapper) {
this.wrapper.replaceWith(element);
element.removeAttr('style');
}
} | [
"function",
"(",
")",
"{",
"var",
"options",
"=",
"this",
".",
"options",
",",
"element",
"=",
"this",
".",
"element",
";",
"if",
"(",
"this",
".",
"name",
"===",
"'Input'",
")",
"{",
"if",
"(",
"options",
".",
"checkbox",
")",
"{",
"element",
".",
"find",
"(",
"options",
".",
"checkbox",
")",
".",
"each",
"(",
"function",
"(",
")",
"{",
"$",
"(",
"this",
")",
".",
"toolkit",
"(",
"'inputCheckbox'",
",",
"'destroy'",
")",
";",
"}",
")",
";",
"}",
"if",
"(",
"options",
".",
"radio",
")",
"{",
"element",
".",
"find",
"(",
"options",
".",
"radio",
")",
".",
"each",
"(",
"function",
"(",
")",
"{",
"$",
"(",
"this",
")",
".",
"toolkit",
"(",
"'inputRadio'",
",",
"'destroy'",
")",
";",
"}",
")",
";",
"}",
"if",
"(",
"options",
".",
"select",
")",
"{",
"element",
".",
"find",
"(",
"options",
".",
"select",
")",
".",
"each",
"(",
"function",
"(",
")",
"{",
"$",
"(",
"this",
")",
".",
"toolkit",
"(",
"'inputSelect'",
",",
"'destroy'",
")",
";",
"}",
")",
";",
"}",
"// Check for the wrapper as some inputs may be initialized but not used.",
"// Multi-selects using native controls for example.",
"}",
"else",
"if",
"(",
"this",
".",
"wrapper",
")",
"{",
"this",
".",
"wrapper",
".",
"replaceWith",
"(",
"element",
")",
";",
"element",
".",
"removeAttr",
"(",
"'style'",
")",
";",
"}",
"}"
] | Remove the wrapper before destroying. | [
"Remove",
"the",
"wrapper",
"before",
"destroying",
"."
] | f0ed36d14cc6d72a7bdbc09da4b5bf7d3d664f0c | https://github.com/titon/toolkit/blob/f0ed36d14cc6d72a7bdbc09da4b5bf7d3d664f0c/dist/toolkit.js#L3189-L3218 | |
21,719 | titon/toolkit | dist/toolkit.js | function(from, to) {
var classes = ($(from).attr('class') || '').replace(this.options.filterClasses, '').trim();
if (classes) {
$(to).addClass(classes);
}
} | javascript | function(from, to) {
var classes = ($(from).attr('class') || '').replace(this.options.filterClasses, '').trim();
if (classes) {
$(to).addClass(classes);
}
} | [
"function",
"(",
"from",
",",
"to",
")",
"{",
"var",
"classes",
"=",
"(",
"$",
"(",
"from",
")",
".",
"attr",
"(",
"'class'",
")",
"||",
"''",
")",
".",
"replace",
"(",
"this",
".",
"options",
".",
"filterClasses",
",",
"''",
")",
".",
"trim",
"(",
")",
";",
"if",
"(",
"classes",
")",
"{",
"$",
"(",
"to",
")",
".",
"addClass",
"(",
"classes",
")",
";",
"}",
"}"
] | Copy classes from one element to another, but do not copy `filterClasses` classes.
@param {jQuery} from
@param {jQuery} to | [
"Copy",
"classes",
"from",
"one",
"element",
"to",
"another",
"but",
"do",
"not",
"copy",
"filterClasses",
"classes",
"."
] | f0ed36d14cc6d72a7bdbc09da4b5bf7d3d664f0c | https://github.com/titon/toolkit/blob/f0ed36d14cc6d72a7bdbc09da4b5bf7d3d664f0c/dist/toolkit.js#L3226-L3232 | |
21,720 | titon/toolkit | dist/toolkit.js | function() {
var input = this.element,
wrapper = this.render(this.options.template)
.insertBefore(input)
.append(input);
if (this.options.copyClasses) {
this.copyClasses(input, wrapper);
}
return wrapper;
} | javascript | function() {
var input = this.element,
wrapper = this.render(this.options.template)
.insertBefore(input)
.append(input);
if (this.options.copyClasses) {
this.copyClasses(input, wrapper);
}
return wrapper;
} | [
"function",
"(",
")",
"{",
"var",
"input",
"=",
"this",
".",
"element",
",",
"wrapper",
"=",
"this",
".",
"render",
"(",
"this",
".",
"options",
".",
"template",
")",
".",
"insertBefore",
"(",
"input",
")",
".",
"append",
"(",
"input",
")",
";",
"if",
"(",
"this",
".",
"options",
".",
"copyClasses",
")",
"{",
"this",
".",
"copyClasses",
"(",
"input",
",",
"wrapper",
")",
";",
"}",
"return",
"wrapper",
";",
"}"
] | Build the element to wrap custom inputs with.
Copy over the original class names.
@returns {jQuery} | [
"Build",
"the",
"element",
"to",
"wrap",
"custom",
"inputs",
"with",
".",
"Copy",
"over",
"the",
"original",
"class",
"names",
"."
] | f0ed36d14cc6d72a7bdbc09da4b5bf7d3d664f0c | https://github.com/titon/toolkit/blob/f0ed36d14cc6d72a7bdbc09da4b5bf7d3d664f0c/dist/toolkit.js#L3240-L3251 | |
21,721 | titon/toolkit | dist/toolkit.js | function(checkbox, options) {
this.element = checkbox = $(checkbox);
options = this.setOptions(options, checkbox);
this.wrapper = this._buildWrapper();
// Create custom input
this.input = this.render(options.checkboxTemplate)
.attr('for', checkbox.attr('id'))
.insertAfter(checkbox);
// Initialize events
this.initialize();
} | javascript | function(checkbox, options) {
this.element = checkbox = $(checkbox);
options = this.setOptions(options, checkbox);
this.wrapper = this._buildWrapper();
// Create custom input
this.input = this.render(options.checkboxTemplate)
.attr('for', checkbox.attr('id'))
.insertAfter(checkbox);
// Initialize events
this.initialize();
} | [
"function",
"(",
"checkbox",
",",
"options",
")",
"{",
"this",
".",
"element",
"=",
"checkbox",
"=",
"$",
"(",
"checkbox",
")",
";",
"options",
"=",
"this",
".",
"setOptions",
"(",
"options",
",",
"checkbox",
")",
";",
"this",
".",
"wrapper",
"=",
"this",
".",
"_buildWrapper",
"(",
")",
";",
"// Create custom input",
"this",
".",
"input",
"=",
"this",
".",
"render",
"(",
"options",
".",
"checkboxTemplate",
")",
".",
"attr",
"(",
"'for'",
",",
"checkbox",
".",
"attr",
"(",
"'id'",
")",
")",
".",
"insertAfter",
"(",
"checkbox",
")",
";",
"// Initialize events",
"this",
".",
"initialize",
"(",
")",
";",
"}"
] | Initialize the checkbox.
@param {jQuery} checkbox
@param {Object} [options] | [
"Initialize",
"the",
"checkbox",
"."
] | f0ed36d14cc6d72a7bdbc09da4b5bf7d3d664f0c | https://github.com/titon/toolkit/blob/f0ed36d14cc6d72a7bdbc09da4b5bf7d3d664f0c/dist/toolkit.js#L3278-L3290 | |
21,722 | titon/toolkit | dist/toolkit.js | function(radio, options) {
this.element = radio = $(radio);
options = this.setOptions(options, radio);
this.wrapper = this._buildWrapper();
// Create custom input
this.input = this.render(options.radioTemplate)
.attr('for', radio.attr('id'))
.insertAfter(radio);
// Initialize events
this.initialize();
} | javascript | function(radio, options) {
this.element = radio = $(radio);
options = this.setOptions(options, radio);
this.wrapper = this._buildWrapper();
// Create custom input
this.input = this.render(options.radioTemplate)
.attr('for', radio.attr('id'))
.insertAfter(radio);
// Initialize events
this.initialize();
} | [
"function",
"(",
"radio",
",",
"options",
")",
"{",
"this",
".",
"element",
"=",
"radio",
"=",
"$",
"(",
"radio",
")",
";",
"options",
"=",
"this",
".",
"setOptions",
"(",
"options",
",",
"radio",
")",
";",
"this",
".",
"wrapper",
"=",
"this",
".",
"_buildWrapper",
"(",
")",
";",
"// Create custom input",
"this",
".",
"input",
"=",
"this",
".",
"render",
"(",
"options",
".",
"radioTemplate",
")",
".",
"attr",
"(",
"'for'",
",",
"radio",
".",
"attr",
"(",
"'id'",
")",
")",
".",
"insertAfter",
"(",
"radio",
")",
";",
"// Initialize events",
"this",
".",
"initialize",
"(",
")",
";",
"}"
] | Initialize the radio.
@param {jQuery} radio
@param {Object} [options] | [
"Initialize",
"the",
"radio",
"."
] | f0ed36d14cc6d72a7bdbc09da4b5bf7d3d664f0c | https://github.com/titon/toolkit/blob/f0ed36d14cc6d72a7bdbc09da4b5bf7d3d664f0c/dist/toolkit.js#L3312-L3324 | |
21,723 | titon/toolkit | dist/toolkit.js | function(select, options) {
this.element = select = $(select);
options = this.setOptions(options, select);
this.multiple = select.prop('multiple');
// Multiple selects must use native controls
if (this.multiple && options.native) {
return;
}
// Wrapping element
this.wrapper = this._buildWrapper();
// Button element to open the drop menu
this.input = this._buildButton();
// Initialize events
this.addEvent('change', 'element', 'onChange');
if (!options.native) {
this.addEvents([
['blur', 'element', 'hide'],
['clickout', 'dropdown', 'hide'],
['click', 'input', 'onToggle']
]);
if (!this.multiple) {
this.addEvent('keydown', 'window', 'onCycle');
}
// Build custom dropdown when not in native
this.dropdown = this._buildDropdown();
// Cant hide/invisible the real select or we lose focus/blur
// So place it below .custom-input
this.element.css('z-index', 1);
}
this.initialize();
// Trigger change immediately to update the label
this.element.change();
} | javascript | function(select, options) {
this.element = select = $(select);
options = this.setOptions(options, select);
this.multiple = select.prop('multiple');
// Multiple selects must use native controls
if (this.multiple && options.native) {
return;
}
// Wrapping element
this.wrapper = this._buildWrapper();
// Button element to open the drop menu
this.input = this._buildButton();
// Initialize events
this.addEvent('change', 'element', 'onChange');
if (!options.native) {
this.addEvents([
['blur', 'element', 'hide'],
['clickout', 'dropdown', 'hide'],
['click', 'input', 'onToggle']
]);
if (!this.multiple) {
this.addEvent('keydown', 'window', 'onCycle');
}
// Build custom dropdown when not in native
this.dropdown = this._buildDropdown();
// Cant hide/invisible the real select or we lose focus/blur
// So place it below .custom-input
this.element.css('z-index', 1);
}
this.initialize();
// Trigger change immediately to update the label
this.element.change();
} | [
"function",
"(",
"select",
",",
"options",
")",
"{",
"this",
".",
"element",
"=",
"select",
"=",
"$",
"(",
"select",
")",
";",
"options",
"=",
"this",
".",
"setOptions",
"(",
"options",
",",
"select",
")",
";",
"this",
".",
"multiple",
"=",
"select",
".",
"prop",
"(",
"'multiple'",
")",
";",
"// Multiple selects must use native controls",
"if",
"(",
"this",
".",
"multiple",
"&&",
"options",
".",
"native",
")",
"{",
"return",
";",
"}",
"// Wrapping element",
"this",
".",
"wrapper",
"=",
"this",
".",
"_buildWrapper",
"(",
")",
";",
"// Button element to open the drop menu",
"this",
".",
"input",
"=",
"this",
".",
"_buildButton",
"(",
")",
";",
"// Initialize events",
"this",
".",
"addEvent",
"(",
"'change'",
",",
"'element'",
",",
"'onChange'",
")",
";",
"if",
"(",
"!",
"options",
".",
"native",
")",
"{",
"this",
".",
"addEvents",
"(",
"[",
"[",
"'blur'",
",",
"'element'",
",",
"'hide'",
"]",
",",
"[",
"'clickout'",
",",
"'dropdown'",
",",
"'hide'",
"]",
",",
"[",
"'click'",
",",
"'input'",
",",
"'onToggle'",
"]",
"]",
")",
";",
"if",
"(",
"!",
"this",
".",
"multiple",
")",
"{",
"this",
".",
"addEvent",
"(",
"'keydown'",
",",
"'window'",
",",
"'onCycle'",
")",
";",
"}",
"// Build custom dropdown when not in native",
"this",
".",
"dropdown",
"=",
"this",
".",
"_buildDropdown",
"(",
")",
";",
"// Cant hide/invisible the real select or we lose focus/blur",
"// So place it below .custom-input",
"this",
".",
"element",
".",
"css",
"(",
"'z-index'",
",",
"1",
")",
";",
"}",
"this",
".",
"initialize",
"(",
")",
";",
"// Trigger change immediately to update the label",
"this",
".",
"element",
".",
"change",
"(",
")",
";",
"}"
] | Initialize the select.
@param {jQuery} select
@param {Object} [options] | [
"Initialize",
"the",
"select",
"."
] | f0ed36d14cc6d72a7bdbc09da4b5bf7d3d664f0c | https://github.com/titon/toolkit/blob/f0ed36d14cc6d72a7bdbc09da4b5bf7d3d664f0c/dist/toolkit.js#L3364-L3406 | |
21,724 | titon/toolkit | dist/toolkit.js | function() {
var options = this.options,
button = this.render(options.selectTemplate)
.find(this.ns('arrow', 'select')).html(this.render(options.arrowTemplate)).end()
.find(this.ns('label', 'select')).html(Toolkit.messages.loading).end()
.css('min-width', this.element.width())
.insertAfter(this.element);
// Update the height of the native select input
this.element.css('min-height', button.outerHeight());
return button;
} | javascript | function() {
var options = this.options,
button = this.render(options.selectTemplate)
.find(this.ns('arrow', 'select')).html(this.render(options.arrowTemplate)).end()
.find(this.ns('label', 'select')).html(Toolkit.messages.loading).end()
.css('min-width', this.element.width())
.insertAfter(this.element);
// Update the height of the native select input
this.element.css('min-height', button.outerHeight());
return button;
} | [
"function",
"(",
")",
"{",
"var",
"options",
"=",
"this",
".",
"options",
",",
"button",
"=",
"this",
".",
"render",
"(",
"options",
".",
"selectTemplate",
")",
".",
"find",
"(",
"this",
".",
"ns",
"(",
"'arrow'",
",",
"'select'",
")",
")",
".",
"html",
"(",
"this",
".",
"render",
"(",
"options",
".",
"arrowTemplate",
")",
")",
".",
"end",
"(",
")",
".",
"find",
"(",
"this",
".",
"ns",
"(",
"'label'",
",",
"'select'",
")",
")",
".",
"html",
"(",
"Toolkit",
".",
"messages",
".",
"loading",
")",
".",
"end",
"(",
")",
".",
"css",
"(",
"'min-width'",
",",
"this",
".",
"element",
".",
"width",
"(",
")",
")",
".",
"insertAfter",
"(",
"this",
".",
"element",
")",
";",
"// Update the height of the native select input",
"this",
".",
"element",
".",
"css",
"(",
"'min-height'",
",",
"button",
".",
"outerHeight",
"(",
")",
")",
";",
"return",
"button",
";",
"}"
] | Build the element to represent the select button with label and arrow.
@returns {jQuery} | [
"Build",
"the",
"element",
"to",
"represent",
"the",
"select",
"button",
"with",
"label",
"and",
"arrow",
"."
] | f0ed36d14cc6d72a7bdbc09da4b5bf7d3d664f0c | https://github.com/titon/toolkit/blob/f0ed36d14cc6d72a7bdbc09da4b5bf7d3d664f0c/dist/toolkit.js#L3449-L3461 | |
21,725 | titon/toolkit | dist/toolkit.js | function() {
var select = this.element,
options = this.options,
buildOption = this._buildOption.bind(this),
renderTemplate = this.render.bind(this),
dropdown = renderTemplate(options.optionsTemplate).attr('role', 'listbox').aria('multiselectable', this.multiple),
list = $('<ul/>'),
index = 0,
self = this;
// Must be set for `_buildOption()`
this.dropdown = dropdown;
select.children().each(function() {
var optgroup = $(this);
if (optgroup.prop('tagName').toLowerCase() === 'optgroup') {
if (index === 0) {
options.hideFirst = false;
}
list.append(
renderTemplate(options.headingTemplate).text(optgroup.attr('label'))
);
optgroup.children().each(function() {
var option = $(this);
if (optgroup.prop('disabled')) {
option.prop('disabled', true);
}
if (option.prop('selected')) {
self.index = index;
}
list.append( buildOption(option, index) );
index++;
});
} else {
if (optgroup.prop('selected')) {
self.index = index;
}
list.append( buildOption(optgroup, index) );
index++;
}
});
if (options.hideSelected && !options.multiple) {
dropdown.addClass('hide-selected');
}
if (options.hideFirst) {
dropdown.addClass('hide-first');
}
if (this.multiple) {
dropdown.addClass('is-multiple');
}
this.wrapper.append(dropdown.append(list));
return dropdown;
} | javascript | function() {
var select = this.element,
options = this.options,
buildOption = this._buildOption.bind(this),
renderTemplate = this.render.bind(this),
dropdown = renderTemplate(options.optionsTemplate).attr('role', 'listbox').aria('multiselectable', this.multiple),
list = $('<ul/>'),
index = 0,
self = this;
// Must be set for `_buildOption()`
this.dropdown = dropdown;
select.children().each(function() {
var optgroup = $(this);
if (optgroup.prop('tagName').toLowerCase() === 'optgroup') {
if (index === 0) {
options.hideFirst = false;
}
list.append(
renderTemplate(options.headingTemplate).text(optgroup.attr('label'))
);
optgroup.children().each(function() {
var option = $(this);
if (optgroup.prop('disabled')) {
option.prop('disabled', true);
}
if (option.prop('selected')) {
self.index = index;
}
list.append( buildOption(option, index) );
index++;
});
} else {
if (optgroup.prop('selected')) {
self.index = index;
}
list.append( buildOption(optgroup, index) );
index++;
}
});
if (options.hideSelected && !options.multiple) {
dropdown.addClass('hide-selected');
}
if (options.hideFirst) {
dropdown.addClass('hide-first');
}
if (this.multiple) {
dropdown.addClass('is-multiple');
}
this.wrapper.append(dropdown.append(list));
return dropdown;
} | [
"function",
"(",
")",
"{",
"var",
"select",
"=",
"this",
".",
"element",
",",
"options",
"=",
"this",
".",
"options",
",",
"buildOption",
"=",
"this",
".",
"_buildOption",
".",
"bind",
"(",
"this",
")",
",",
"renderTemplate",
"=",
"this",
".",
"render",
".",
"bind",
"(",
"this",
")",
",",
"dropdown",
"=",
"renderTemplate",
"(",
"options",
".",
"optionsTemplate",
")",
".",
"attr",
"(",
"'role'",
",",
"'listbox'",
")",
".",
"aria",
"(",
"'multiselectable'",
",",
"this",
".",
"multiple",
")",
",",
"list",
"=",
"$",
"(",
"'<ul/>'",
")",
",",
"index",
"=",
"0",
",",
"self",
"=",
"this",
";",
"// Must be set for `_buildOption()`",
"this",
".",
"dropdown",
"=",
"dropdown",
";",
"select",
".",
"children",
"(",
")",
".",
"each",
"(",
"function",
"(",
")",
"{",
"var",
"optgroup",
"=",
"$",
"(",
"this",
")",
";",
"if",
"(",
"optgroup",
".",
"prop",
"(",
"'tagName'",
")",
".",
"toLowerCase",
"(",
")",
"===",
"'optgroup'",
")",
"{",
"if",
"(",
"index",
"===",
"0",
")",
"{",
"options",
".",
"hideFirst",
"=",
"false",
";",
"}",
"list",
".",
"append",
"(",
"renderTemplate",
"(",
"options",
".",
"headingTemplate",
")",
".",
"text",
"(",
"optgroup",
".",
"attr",
"(",
"'label'",
")",
")",
")",
";",
"optgroup",
".",
"children",
"(",
")",
".",
"each",
"(",
"function",
"(",
")",
"{",
"var",
"option",
"=",
"$",
"(",
"this",
")",
";",
"if",
"(",
"optgroup",
".",
"prop",
"(",
"'disabled'",
")",
")",
"{",
"option",
".",
"prop",
"(",
"'disabled'",
",",
"true",
")",
";",
"}",
"if",
"(",
"option",
".",
"prop",
"(",
"'selected'",
")",
")",
"{",
"self",
".",
"index",
"=",
"index",
";",
"}",
"list",
".",
"append",
"(",
"buildOption",
"(",
"option",
",",
"index",
")",
")",
";",
"index",
"++",
";",
"}",
")",
";",
"}",
"else",
"{",
"if",
"(",
"optgroup",
".",
"prop",
"(",
"'selected'",
")",
")",
"{",
"self",
".",
"index",
"=",
"index",
";",
"}",
"list",
".",
"append",
"(",
"buildOption",
"(",
"optgroup",
",",
"index",
")",
")",
";",
"index",
"++",
";",
"}",
"}",
")",
";",
"if",
"(",
"options",
".",
"hideSelected",
"&&",
"!",
"options",
".",
"multiple",
")",
"{",
"dropdown",
".",
"addClass",
"(",
"'hide-selected'",
")",
";",
"}",
"if",
"(",
"options",
".",
"hideFirst",
")",
"{",
"dropdown",
".",
"addClass",
"(",
"'hide-first'",
")",
";",
"}",
"if",
"(",
"this",
".",
"multiple",
")",
"{",
"dropdown",
".",
"addClass",
"(",
"'is-multiple'",
")",
";",
"}",
"this",
".",
"wrapper",
".",
"append",
"(",
"dropdown",
".",
"append",
"(",
"list",
")",
")",
";",
"return",
"dropdown",
";",
"}"
] | Build the custom dropdown to hold a list of option items.
@returns {jQuery} | [
"Build",
"the",
"custom",
"dropdown",
"to",
"hold",
"a",
"list",
"of",
"option",
"items",
"."
] | f0ed36d14cc6d72a7bdbc09da4b5bf7d3d664f0c | https://github.com/titon/toolkit/blob/f0ed36d14cc6d72a7bdbc09da4b5bf7d3d664f0c/dist/toolkit.js#L3468-L3532 | |
21,726 | titon/toolkit | dist/toolkit.js | function(option, index) {
var select = this.element,
dropdown = this.dropdown,
options = this.options,
selected = option.prop('selected'),
activeClass = 'is-active';
// Create elements
var li = $('<li/>'),
content = option.text(),
description;
if (selected) {
li.addClass(activeClass);
}
if (description = this.readValue(option, options.getDescription)) {
content += this.render(options.descTemplate).html(description).toString();
}
var a = $('<a/>', {
html: content,
href: 'javascript:;',
role: 'option'
}).aria('selected', selected);
if (this.options.copyClasses) {
this.copyClasses(option, li);
}
li.append(a);
// Attach no events for disabled options
if (option.prop('disabled')) {
li.addClass('is-disabled');
a.aria('disabled', true);
return li;
}
// Set events
if (this.multiple) {
a.click(function() {
var self = $(this),
selected = false;
if (option.prop('selected')) {
self.parent().removeClass(activeClass);
} else {
selected = true;
self.parent().addClass(activeClass);
}
option.prop('selected', selected);
self.aria('selected', selected);
select.change();
});
} else {
var self = this;
a.click(function() {
dropdown
.find('li').removeClass(activeClass).end()
.find('a').aria('selected', false);
$(this)
.aria('selected', true)
.parent()
.addClass(activeClass);
self.hide();
self.index = index;
select.val(option.val());
select.change();
});
}
return li;
} | javascript | function(option, index) {
var select = this.element,
dropdown = this.dropdown,
options = this.options,
selected = option.prop('selected'),
activeClass = 'is-active';
// Create elements
var li = $('<li/>'),
content = option.text(),
description;
if (selected) {
li.addClass(activeClass);
}
if (description = this.readValue(option, options.getDescription)) {
content += this.render(options.descTemplate).html(description).toString();
}
var a = $('<a/>', {
html: content,
href: 'javascript:;',
role: 'option'
}).aria('selected', selected);
if (this.options.copyClasses) {
this.copyClasses(option, li);
}
li.append(a);
// Attach no events for disabled options
if (option.prop('disabled')) {
li.addClass('is-disabled');
a.aria('disabled', true);
return li;
}
// Set events
if (this.multiple) {
a.click(function() {
var self = $(this),
selected = false;
if (option.prop('selected')) {
self.parent().removeClass(activeClass);
} else {
selected = true;
self.parent().addClass(activeClass);
}
option.prop('selected', selected);
self.aria('selected', selected);
select.change();
});
} else {
var self = this;
a.click(function() {
dropdown
.find('li').removeClass(activeClass).end()
.find('a').aria('selected', false);
$(this)
.aria('selected', true)
.parent()
.addClass(activeClass);
self.hide();
self.index = index;
select.val(option.val());
select.change();
});
}
return li;
} | [
"function",
"(",
"option",
",",
"index",
")",
"{",
"var",
"select",
"=",
"this",
".",
"element",
",",
"dropdown",
"=",
"this",
".",
"dropdown",
",",
"options",
"=",
"this",
".",
"options",
",",
"selected",
"=",
"option",
".",
"prop",
"(",
"'selected'",
")",
",",
"activeClass",
"=",
"'is-active'",
";",
"// Create elements",
"var",
"li",
"=",
"$",
"(",
"'<li/>'",
")",
",",
"content",
"=",
"option",
".",
"text",
"(",
")",
",",
"description",
";",
"if",
"(",
"selected",
")",
"{",
"li",
".",
"addClass",
"(",
"activeClass",
")",
";",
"}",
"if",
"(",
"description",
"=",
"this",
".",
"readValue",
"(",
"option",
",",
"options",
".",
"getDescription",
")",
")",
"{",
"content",
"+=",
"this",
".",
"render",
"(",
"options",
".",
"descTemplate",
")",
".",
"html",
"(",
"description",
")",
".",
"toString",
"(",
")",
";",
"}",
"var",
"a",
"=",
"$",
"(",
"'<a/>'",
",",
"{",
"html",
":",
"content",
",",
"href",
":",
"'javascript:;'",
",",
"role",
":",
"'option'",
"}",
")",
".",
"aria",
"(",
"'selected'",
",",
"selected",
")",
";",
"if",
"(",
"this",
".",
"options",
".",
"copyClasses",
")",
"{",
"this",
".",
"copyClasses",
"(",
"option",
",",
"li",
")",
";",
"}",
"li",
".",
"append",
"(",
"a",
")",
";",
"// Attach no events for disabled options",
"if",
"(",
"option",
".",
"prop",
"(",
"'disabled'",
")",
")",
"{",
"li",
".",
"addClass",
"(",
"'is-disabled'",
")",
";",
"a",
".",
"aria",
"(",
"'disabled'",
",",
"true",
")",
";",
"return",
"li",
";",
"}",
"// Set events",
"if",
"(",
"this",
".",
"multiple",
")",
"{",
"a",
".",
"click",
"(",
"function",
"(",
")",
"{",
"var",
"self",
"=",
"$",
"(",
"this",
")",
",",
"selected",
"=",
"false",
";",
"if",
"(",
"option",
".",
"prop",
"(",
"'selected'",
")",
")",
"{",
"self",
".",
"parent",
"(",
")",
".",
"removeClass",
"(",
"activeClass",
")",
";",
"}",
"else",
"{",
"selected",
"=",
"true",
";",
"self",
".",
"parent",
"(",
")",
".",
"addClass",
"(",
"activeClass",
")",
";",
"}",
"option",
".",
"prop",
"(",
"'selected'",
",",
"selected",
")",
";",
"self",
".",
"aria",
"(",
"'selected'",
",",
"selected",
")",
";",
"select",
".",
"change",
"(",
")",
";",
"}",
")",
";",
"}",
"else",
"{",
"var",
"self",
"=",
"this",
";",
"a",
".",
"click",
"(",
"function",
"(",
")",
"{",
"dropdown",
".",
"find",
"(",
"'li'",
")",
".",
"removeClass",
"(",
"activeClass",
")",
".",
"end",
"(",
")",
".",
"find",
"(",
"'a'",
")",
".",
"aria",
"(",
"'selected'",
",",
"false",
")",
";",
"$",
"(",
"this",
")",
".",
"aria",
"(",
"'selected'",
",",
"true",
")",
".",
"parent",
"(",
")",
".",
"addClass",
"(",
"activeClass",
")",
";",
"self",
".",
"hide",
"(",
")",
";",
"self",
".",
"index",
"=",
"index",
";",
"select",
".",
"val",
"(",
"option",
".",
"val",
"(",
")",
")",
";",
"select",
".",
"change",
"(",
")",
";",
"}",
")",
";",
"}",
"return",
"li",
";",
"}"
] | Build the list item to represent the select option.
@param {jQuery} option
@param {Number} index
@returns {jQuery} | [
"Build",
"the",
"list",
"item",
"to",
"represent",
"the",
"select",
"option",
"."
] | f0ed36d14cc6d72a7bdbc09da4b5bf7d3d664f0c | https://github.com/titon/toolkit/blob/f0ed36d14cc6d72a7bdbc09da4b5bf7d3d664f0c/dist/toolkit.js#L3541-L3623 | |
21,727 | titon/toolkit | dist/toolkit.js | function(index, step, options) {
var hideFirst = this.options.hideFirst;
index += step;
while (($.type(options[index]) === 'undefined') || options[index].disabled || (index === 0 && hideFirst)) {
index += step;
if (index >= options.length) {
index = 0;
} else if (index < 0) {
index = options.length - 1;
}
}
return index;
} | javascript | function(index, step, options) {
var hideFirst = this.options.hideFirst;
index += step;
while (($.type(options[index]) === 'undefined') || options[index].disabled || (index === 0 && hideFirst)) {
index += step;
if (index >= options.length) {
index = 0;
} else if (index < 0) {
index = options.length - 1;
}
}
return index;
} | [
"function",
"(",
"index",
",",
"step",
",",
"options",
")",
"{",
"var",
"hideFirst",
"=",
"this",
".",
"options",
".",
"hideFirst",
";",
"index",
"+=",
"step",
";",
"while",
"(",
"(",
"$",
".",
"type",
"(",
"options",
"[",
"index",
"]",
")",
"===",
"'undefined'",
")",
"||",
"options",
"[",
"index",
"]",
".",
"disabled",
"||",
"(",
"index",
"===",
"0",
"&&",
"hideFirst",
")",
")",
"{",
"index",
"+=",
"step",
";",
"if",
"(",
"index",
">=",
"options",
".",
"length",
")",
"{",
"index",
"=",
"0",
";",
"}",
"else",
"if",
"(",
"index",
"<",
"0",
")",
"{",
"index",
"=",
"options",
".",
"length",
"-",
"1",
";",
"}",
"}",
"return",
"index",
";",
"}"
] | Loop through the options and determine the index to
Skip over missing options, disabled options, or hidden options.
@private
@param {Number} index
@param {Number} step
@param {jQuery} options
@returns {Number} | [
"Loop",
"through",
"the",
"options",
"and",
"determine",
"the",
"index",
"to",
"Skip",
"over",
"missing",
"options",
"disabled",
"options",
"or",
"hidden",
"options",
"."
] | f0ed36d14cc6d72a7bdbc09da4b5bf7d3d664f0c | https://github.com/titon/toolkit/blob/f0ed36d14cc6d72a7bdbc09da4b5bf7d3d664f0c/dist/toolkit.js#L3635-L3651 | |
21,728 | titon/toolkit | dist/toolkit.js | function(e) {
var select = $(e.target),
options = select.find('option'),
opts = this.options,
selected = [],
label = [],
self = this;
// Fetch label from selected option
options.each(function() {
if (this.selected) {
selected.push( this );
label.push( self.readValue(this, opts.getOptionLabel) || this.textContent );
}
});
// Reformat label if needed
if (this.multiple) {
var title = this.readValue(select, opts.getDefaultLabel),
format = opts.multipleFormat,
count = label.length;
// Use default title if nothing selected
if (!label.length && title) {
label = title;
// Display a counter for label
} else if (format === 'count') {
label = opts.countMessage
.replace('{count}', count)
.replace('{total}', options.length);
// Display options as a list for label
} else if (format === 'list') {
var limit = opts.listLimit;
label = label.splice(0, limit).join(', ');
if (limit < count) {
label += ' ...';
}
}
} else {
label = label.join(', ');
}
// Set the label
select.parent()
.find(this.ns('label', 'select'))
.text(label);
this.fireEvent('change', [select.val(), selected]);
} | javascript | function(e) {
var select = $(e.target),
options = select.find('option'),
opts = this.options,
selected = [],
label = [],
self = this;
// Fetch label from selected option
options.each(function() {
if (this.selected) {
selected.push( this );
label.push( self.readValue(this, opts.getOptionLabel) || this.textContent );
}
});
// Reformat label if needed
if (this.multiple) {
var title = this.readValue(select, opts.getDefaultLabel),
format = opts.multipleFormat,
count = label.length;
// Use default title if nothing selected
if (!label.length && title) {
label = title;
// Display a counter for label
} else if (format === 'count') {
label = opts.countMessage
.replace('{count}', count)
.replace('{total}', options.length);
// Display options as a list for label
} else if (format === 'list') {
var limit = opts.listLimit;
label = label.splice(0, limit).join(', ');
if (limit < count) {
label += ' ...';
}
}
} else {
label = label.join(', ');
}
// Set the label
select.parent()
.find(this.ns('label', 'select'))
.text(label);
this.fireEvent('change', [select.val(), selected]);
} | [
"function",
"(",
"e",
")",
"{",
"var",
"select",
"=",
"$",
"(",
"e",
".",
"target",
")",
",",
"options",
"=",
"select",
".",
"find",
"(",
"'option'",
")",
",",
"opts",
"=",
"this",
".",
"options",
",",
"selected",
"=",
"[",
"]",
",",
"label",
"=",
"[",
"]",
",",
"self",
"=",
"this",
";",
"// Fetch label from selected option",
"options",
".",
"each",
"(",
"function",
"(",
")",
"{",
"if",
"(",
"this",
".",
"selected",
")",
"{",
"selected",
".",
"push",
"(",
"this",
")",
";",
"label",
".",
"push",
"(",
"self",
".",
"readValue",
"(",
"this",
",",
"opts",
".",
"getOptionLabel",
")",
"||",
"this",
".",
"textContent",
")",
";",
"}",
"}",
")",
";",
"// Reformat label if needed",
"if",
"(",
"this",
".",
"multiple",
")",
"{",
"var",
"title",
"=",
"this",
".",
"readValue",
"(",
"select",
",",
"opts",
".",
"getDefaultLabel",
")",
",",
"format",
"=",
"opts",
".",
"multipleFormat",
",",
"count",
"=",
"label",
".",
"length",
";",
"// Use default title if nothing selected",
"if",
"(",
"!",
"label",
".",
"length",
"&&",
"title",
")",
"{",
"label",
"=",
"title",
";",
"// Display a counter for label",
"}",
"else",
"if",
"(",
"format",
"===",
"'count'",
")",
"{",
"label",
"=",
"opts",
".",
"countMessage",
".",
"replace",
"(",
"'{count}'",
",",
"count",
")",
".",
"replace",
"(",
"'{total}'",
",",
"options",
".",
"length",
")",
";",
"// Display options as a list for label",
"}",
"else",
"if",
"(",
"format",
"===",
"'list'",
")",
"{",
"var",
"limit",
"=",
"opts",
".",
"listLimit",
";",
"label",
"=",
"label",
".",
"splice",
"(",
"0",
",",
"limit",
")",
".",
"join",
"(",
"', '",
")",
";",
"if",
"(",
"limit",
"<",
"count",
")",
"{",
"label",
"+=",
"' ...'",
";",
"}",
"}",
"}",
"else",
"{",
"label",
"=",
"label",
".",
"join",
"(",
"', '",
")",
";",
"}",
"// Set the label",
"select",
".",
"parent",
"(",
")",
".",
"find",
"(",
"this",
".",
"ns",
"(",
"'label'",
",",
"'select'",
")",
")",
".",
"text",
"(",
"label",
")",
";",
"this",
".",
"fireEvent",
"(",
"'change'",
",",
"[",
"select",
".",
"val",
"(",
")",
",",
"selected",
"]",
")",
";",
"}"
] | Event handler for select option changing.
@private
@param {jQuery.Event} e | [
"Event",
"handler",
"for",
"select",
"option",
"changing",
"."
] | f0ed36d14cc6d72a7bdbc09da4b5bf7d3d664f0c | https://github.com/titon/toolkit/blob/f0ed36d14cc6d72a7bdbc09da4b5bf7d3d664f0c/dist/toolkit.js#L3659-L3711 | |
21,729 | titon/toolkit | dist/toolkit.js | function(e) {
if (!this.dropdown.is(':shown')) {
return;
}
if ($.inArray(e.keyCode, [38, 40, 13, 27]) >= 0) {
e.preventDefault();
} else {
return;
}
var options = this.element.find('option'),
items = this.dropdown.find('a'),
activeClass = 'is-active',
index = this.index;
switch (e.keyCode) {
case 13: // enter
case 27: // esc
this.hide();
return;
case 38: // up
index = this._loop(index, -1, options);
break;
case 40: // down
index = this._loop(index, 1, options);
break;
}
options.prop('selected', false);
options[index].selected = true;
items.parent().removeClass(activeClass);
items.eq(index).parent().addClass(activeClass);
this.index = index;
this.element.change();
} | javascript | function(e) {
if (!this.dropdown.is(':shown')) {
return;
}
if ($.inArray(e.keyCode, [38, 40, 13, 27]) >= 0) {
e.preventDefault();
} else {
return;
}
var options = this.element.find('option'),
items = this.dropdown.find('a'),
activeClass = 'is-active',
index = this.index;
switch (e.keyCode) {
case 13: // enter
case 27: // esc
this.hide();
return;
case 38: // up
index = this._loop(index, -1, options);
break;
case 40: // down
index = this._loop(index, 1, options);
break;
}
options.prop('selected', false);
options[index].selected = true;
items.parent().removeClass(activeClass);
items.eq(index).parent().addClass(activeClass);
this.index = index;
this.element.change();
} | [
"function",
"(",
"e",
")",
"{",
"if",
"(",
"!",
"this",
".",
"dropdown",
".",
"is",
"(",
"':shown'",
")",
")",
"{",
"return",
";",
"}",
"if",
"(",
"$",
".",
"inArray",
"(",
"e",
".",
"keyCode",
",",
"[",
"38",
",",
"40",
",",
"13",
",",
"27",
"]",
")",
">=",
"0",
")",
"{",
"e",
".",
"preventDefault",
"(",
")",
";",
"}",
"else",
"{",
"return",
";",
"}",
"var",
"options",
"=",
"this",
".",
"element",
".",
"find",
"(",
"'option'",
")",
",",
"items",
"=",
"this",
".",
"dropdown",
".",
"find",
"(",
"'a'",
")",
",",
"activeClass",
"=",
"'is-active'",
",",
"index",
"=",
"this",
".",
"index",
";",
"switch",
"(",
"e",
".",
"keyCode",
")",
"{",
"case",
"13",
":",
"// enter",
"case",
"27",
":",
"// esc",
"this",
".",
"hide",
"(",
")",
";",
"return",
";",
"case",
"38",
":",
"// up",
"index",
"=",
"this",
".",
"_loop",
"(",
"index",
",",
"-",
"1",
",",
"options",
")",
";",
"break",
";",
"case",
"40",
":",
"// down",
"index",
"=",
"this",
".",
"_loop",
"(",
"index",
",",
"1",
",",
"options",
")",
";",
"break",
";",
"}",
"options",
".",
"prop",
"(",
"'selected'",
",",
"false",
")",
";",
"options",
"[",
"index",
"]",
".",
"selected",
"=",
"true",
";",
"items",
".",
"parent",
"(",
")",
".",
"removeClass",
"(",
"activeClass",
")",
";",
"items",
".",
"eq",
"(",
"index",
")",
".",
"parent",
"(",
")",
".",
"addClass",
"(",
"activeClass",
")",
";",
"this",
".",
"index",
"=",
"index",
";",
"this",
".",
"element",
".",
"change",
"(",
")",
";",
"}"
] | Event handler for cycling through options with up and down keys.
@private
@param {jQuery.Event} e | [
"Event",
"handler",
"for",
"cycling",
"through",
"options",
"with",
"up",
"and",
"down",
"keys",
"."
] | f0ed36d14cc6d72a7bdbc09da4b5bf7d3d664f0c | https://github.com/titon/toolkit/blob/f0ed36d14cc6d72a7bdbc09da4b5bf7d3d664f0c/dist/toolkit.js#L3719-L3756 | |
21,730 | titon/toolkit | dist/toolkit.js | function(container, options) {
container = $(container);
options = this.setOptions(options, container);
this.items = container.find(this.options.lazyClass);
if (container.css('overflow') === 'auto') {
this.container = container;
}
var callback = $.throttle(this.load.bind(this), options.throttle);
// Set events
this.addEvents([
['scroll', 'container', callback],
['resize', 'window', callback],
['ready', 'document', 'onReady']
]);
this.initialize();
} | javascript | function(container, options) {
container = $(container);
options = this.setOptions(options, container);
this.items = container.find(this.options.lazyClass);
if (container.css('overflow') === 'auto') {
this.container = container;
}
var callback = $.throttle(this.load.bind(this), options.throttle);
// Set events
this.addEvents([
['scroll', 'container', callback],
['resize', 'window', callback],
['ready', 'document', 'onReady']
]);
this.initialize();
} | [
"function",
"(",
"container",
",",
"options",
")",
"{",
"container",
"=",
"$",
"(",
"container",
")",
";",
"options",
"=",
"this",
".",
"setOptions",
"(",
"options",
",",
"container",
")",
";",
"this",
".",
"items",
"=",
"container",
".",
"find",
"(",
"this",
".",
"options",
".",
"lazyClass",
")",
";",
"if",
"(",
"container",
".",
"css",
"(",
"'overflow'",
")",
"===",
"'auto'",
")",
"{",
"this",
".",
"container",
"=",
"container",
";",
"}",
"var",
"callback",
"=",
"$",
".",
"throttle",
"(",
"this",
".",
"load",
".",
"bind",
"(",
"this",
")",
",",
"options",
".",
"throttle",
")",
";",
"// Set events",
"this",
".",
"addEvents",
"(",
"[",
"[",
"'scroll'",
",",
"'container'",
",",
"callback",
"]",
",",
"[",
"'resize'",
",",
"'window'",
",",
"callback",
"]",
",",
"[",
"'ready'",
",",
"'document'",
",",
"'onReady'",
"]",
"]",
")",
";",
"this",
".",
"initialize",
"(",
")",
";",
"}"
] | Initialize the lazy load.
@param {jQuery} container
@param {Object} [options] | [
"Initialize",
"the",
"lazy",
"load",
"."
] | f0ed36d14cc6d72a7bdbc09da4b5bf7d3d664f0c | https://github.com/titon/toolkit/blob/f0ed36d14cc6d72a7bdbc09da4b5bf7d3d664f0c/dist/toolkit.js#L3831-L3851 | |
21,731 | titon/toolkit | dist/toolkit.js | function() {
if (this.loaded >= this.items.length) {
this.shutdown();
return;
}
this.fireEvent('loading');
this.items.each(function(index, item) {
if (item && this.inViewport(item)) {
this.show(item, index);
}
}.bind(this));
this.fireEvent('loaded');
} | javascript | function() {
if (this.loaded >= this.items.length) {
this.shutdown();
return;
}
this.fireEvent('loading');
this.items.each(function(index, item) {
if (item && this.inViewport(item)) {
this.show(item, index);
}
}.bind(this));
this.fireEvent('loaded');
} | [
"function",
"(",
")",
"{",
"if",
"(",
"this",
".",
"loaded",
">=",
"this",
".",
"items",
".",
"length",
")",
"{",
"this",
".",
"shutdown",
"(",
")",
";",
"return",
";",
"}",
"this",
".",
"fireEvent",
"(",
"'loading'",
")",
";",
"this",
".",
"items",
".",
"each",
"(",
"function",
"(",
"index",
",",
"item",
")",
"{",
"if",
"(",
"item",
"&&",
"this",
".",
"inViewport",
"(",
"item",
")",
")",
"{",
"this",
".",
"show",
"(",
"item",
",",
"index",
")",
";",
"}",
"}",
".",
"bind",
"(",
"this",
")",
")",
";",
"this",
".",
"fireEvent",
"(",
"'loaded'",
")",
";",
"}"
] | Loop over the lazy loaded items and verify they are within the viewport. | [
"Loop",
"over",
"the",
"lazy",
"loaded",
"items",
"and",
"verify",
"they",
"are",
"within",
"the",
"viewport",
"."
] | f0ed36d14cc6d72a7bdbc09da4b5bf7d3d664f0c | https://github.com/titon/toolkit/blob/f0ed36d14cc6d72a7bdbc09da4b5bf7d3d664f0c/dist/toolkit.js#L3906-L3921 | |
21,732 | titon/toolkit | dist/toolkit.js | function(node, index) {
node = $(node);
this.fireEvent('showing', [node]);
// Set the item being loaded for so that events can be fired
this.element = node.removeClass(this.options.lazyClass.substr(1));
// Replace src attributes on images
node.find('img').each(function() {
var image = $(this), src;
if (Toolkit.isRetina) {
src = image.data('src-retina');
}
if (!src) {
src = image.data('src');
}
if (src) {
image.attr('src', src);
}
});
// Replace item with null since removing from the array causes it to break
this.items.splice(index, 1, null);
this.loaded++;
this.fireEvent('shown', [node]);
} | javascript | function(node, index) {
node = $(node);
this.fireEvent('showing', [node]);
// Set the item being loaded for so that events can be fired
this.element = node.removeClass(this.options.lazyClass.substr(1));
// Replace src attributes on images
node.find('img').each(function() {
var image = $(this), src;
if (Toolkit.isRetina) {
src = image.data('src-retina');
}
if (!src) {
src = image.data('src');
}
if (src) {
image.attr('src', src);
}
});
// Replace item with null since removing from the array causes it to break
this.items.splice(index, 1, null);
this.loaded++;
this.fireEvent('shown', [node]);
} | [
"function",
"(",
"node",
",",
"index",
")",
"{",
"node",
"=",
"$",
"(",
"node",
")",
";",
"this",
".",
"fireEvent",
"(",
"'showing'",
",",
"[",
"node",
"]",
")",
";",
"// Set the item being loaded for so that events can be fired",
"this",
".",
"element",
"=",
"node",
".",
"removeClass",
"(",
"this",
".",
"options",
".",
"lazyClass",
".",
"substr",
"(",
"1",
")",
")",
";",
"// Replace src attributes on images",
"node",
".",
"find",
"(",
"'img'",
")",
".",
"each",
"(",
"function",
"(",
")",
"{",
"var",
"image",
"=",
"$",
"(",
"this",
")",
",",
"src",
";",
"if",
"(",
"Toolkit",
".",
"isRetina",
")",
"{",
"src",
"=",
"image",
".",
"data",
"(",
"'src-retina'",
")",
";",
"}",
"if",
"(",
"!",
"src",
")",
"{",
"src",
"=",
"image",
".",
"data",
"(",
"'src'",
")",
";",
"}",
"if",
"(",
"src",
")",
"{",
"image",
".",
"attr",
"(",
"'src'",
",",
"src",
")",
";",
"}",
"}",
")",
";",
"// Replace item with null since removing from the array causes it to break",
"this",
".",
"items",
".",
"splice",
"(",
"index",
",",
"1",
",",
"null",
")",
";",
"this",
".",
"loaded",
"++",
";",
"this",
".",
"fireEvent",
"(",
"'shown'",
",",
"[",
"node",
"]",
")",
";",
"}"
] | Show the item by removing the lazy load class.
@param {jQuery} node
@param {Number} index | [
"Show",
"the",
"item",
"by",
"removing",
"the",
"lazy",
"load",
"class",
"."
] | f0ed36d14cc6d72a7bdbc09da4b5bf7d3d664f0c | https://github.com/titon/toolkit/blob/f0ed36d14cc6d72a7bdbc09da4b5bf7d3d664f0c/dist/toolkit.js#L3944-L3974 | |
21,733 | titon/toolkit | dist/toolkit.js | function(element, options) {
element = this.setElement(element);
options = this.setOptions(options, element);
// Add class and set relative positioning
if (!element.is('body')) {
element.addClass('is-maskable');
var position = element.css('position');
if (!position || position === 'static') {
element.css('position', 'relative');
}
}
// Find a mask or create it
var mask = element.find('> ' + this.ns());
if (!mask.length) {
mask = this.render(options.template);
}
this.setMask(mask);
if (options.selector) {
this.addEvent('click', 'document', 'toggle', options.selector);
}
this.initialize();
} | javascript | function(element, options) {
element = this.setElement(element);
options = this.setOptions(options, element);
// Add class and set relative positioning
if (!element.is('body')) {
element.addClass('is-maskable');
var position = element.css('position');
if (!position || position === 'static') {
element.css('position', 'relative');
}
}
// Find a mask or create it
var mask = element.find('> ' + this.ns());
if (!mask.length) {
mask = this.render(options.template);
}
this.setMask(mask);
if (options.selector) {
this.addEvent('click', 'document', 'toggle', options.selector);
}
this.initialize();
} | [
"function",
"(",
"element",
",",
"options",
")",
"{",
"element",
"=",
"this",
".",
"setElement",
"(",
"element",
")",
";",
"options",
"=",
"this",
".",
"setOptions",
"(",
"options",
",",
"element",
")",
";",
"// Add class and set relative positioning",
"if",
"(",
"!",
"element",
".",
"is",
"(",
"'body'",
")",
")",
"{",
"element",
".",
"addClass",
"(",
"'is-maskable'",
")",
";",
"var",
"position",
"=",
"element",
".",
"css",
"(",
"'position'",
")",
";",
"if",
"(",
"!",
"position",
"||",
"position",
"===",
"'static'",
")",
"{",
"element",
".",
"css",
"(",
"'position'",
",",
"'relative'",
")",
";",
"}",
"}",
"// Find a mask or create it",
"var",
"mask",
"=",
"element",
".",
"find",
"(",
"'> '",
"+",
"this",
".",
"ns",
"(",
")",
")",
";",
"if",
"(",
"!",
"mask",
".",
"length",
")",
"{",
"mask",
"=",
"this",
".",
"render",
"(",
"options",
".",
"template",
")",
";",
"}",
"this",
".",
"setMask",
"(",
"mask",
")",
";",
"if",
"(",
"options",
".",
"selector",
")",
"{",
"this",
".",
"addEvent",
"(",
"'click'",
",",
"'document'",
",",
"'toggle'",
",",
"options",
".",
"selector",
")",
";",
"}",
"this",
".",
"initialize",
"(",
")",
";",
"}"
] | Initialize the mask.
@param {jQuery} element
@param {Object} [options] | [
"Initialize",
"the",
"mask",
"."
] | f0ed36d14cc6d72a7bdbc09da4b5bf7d3d664f0c | https://github.com/titon/toolkit/blob/f0ed36d14cc6d72a7bdbc09da4b5bf7d3d664f0c/dist/toolkit.js#L4029-L4058 | |
21,734 | titon/toolkit | dist/toolkit.js | function(mask) {
var options = this.options,
message;
// Prepare mask
mask.addClass('hide').appendTo(this.element);
if (this.element.is('body')) {
mask.css('position', 'fixed');
}
if (options.revealOnClick) {
mask.click(this.hide.bind(this));
}
this.mask = mask;
// Create message if it does not exist
message = mask.find(this.ns('message'));
if (!message.length && options.messageContent) {
message = this.render(options.messageTemplate)
.html(options.messageContent)
.appendTo(mask);
}
this.message = message;
} | javascript | function(mask) {
var options = this.options,
message;
// Prepare mask
mask.addClass('hide').appendTo(this.element);
if (this.element.is('body')) {
mask.css('position', 'fixed');
}
if (options.revealOnClick) {
mask.click(this.hide.bind(this));
}
this.mask = mask;
// Create message if it does not exist
message = mask.find(this.ns('message'));
if (!message.length && options.messageContent) {
message = this.render(options.messageTemplate)
.html(options.messageContent)
.appendTo(mask);
}
this.message = message;
} | [
"function",
"(",
"mask",
")",
"{",
"var",
"options",
"=",
"this",
".",
"options",
",",
"message",
";",
"// Prepare mask",
"mask",
".",
"addClass",
"(",
"'hide'",
")",
".",
"appendTo",
"(",
"this",
".",
"element",
")",
";",
"if",
"(",
"this",
".",
"element",
".",
"is",
"(",
"'body'",
")",
")",
"{",
"mask",
".",
"css",
"(",
"'position'",
",",
"'fixed'",
")",
";",
"}",
"if",
"(",
"options",
".",
"revealOnClick",
")",
"{",
"mask",
".",
"click",
"(",
"this",
".",
"hide",
".",
"bind",
"(",
"this",
")",
")",
";",
"}",
"this",
".",
"mask",
"=",
"mask",
";",
"// Create message if it does not exist",
"message",
"=",
"mask",
".",
"find",
"(",
"this",
".",
"ns",
"(",
"'message'",
")",
")",
";",
"if",
"(",
"!",
"message",
".",
"length",
"&&",
"options",
".",
"messageContent",
")",
"{",
"message",
"=",
"this",
".",
"render",
"(",
"options",
".",
"messageTemplate",
")",
".",
"html",
"(",
"options",
".",
"messageContent",
")",
".",
"appendTo",
"(",
"mask",
")",
";",
"}",
"this",
".",
"message",
"=",
"message",
";",
"}"
] | Set the element to use as a mask and append it to the target element.
Apply optional classes, events, and styles dependent on implementation.
@param {jQuery} mask | [
"Set",
"the",
"element",
"to",
"use",
"as",
"a",
"mask",
"and",
"append",
"it",
"to",
"the",
"target",
"element",
".",
"Apply",
"optional",
"classes",
"events",
"and",
"styles",
"dependent",
"on",
"implementation",
"."
] | f0ed36d14cc6d72a7bdbc09da4b5bf7d3d664f0c | https://github.com/titon/toolkit/blob/f0ed36d14cc6d72a7bdbc09da4b5bf7d3d664f0c/dist/toolkit.js#L4089-L4116 | |
21,735 | titon/toolkit | dist/toolkit.js | function(nodes, options) {
this.nodes = $(nodes);
options = this.setOptions(options);
this.element = this.createElement()
.attr('role', 'dialog')
.aria('labelledby', this.id('title'))
.aria('describedby', this.id('content'));
// Enable fullscreen
if (options.fullScreen) {
this.element.addClass('is-fullscreen');
}
// Setup blackout
if (options.blackout) {
this.blackout = Blackout.instance();
}
// Initialize events
this.addEvents([
['keydown', 'window', 'onKeydown'],
['click', 'document', 'onShow', '{selector}'],
['click', 'element', 'hide', this.ns('close')],
['click', 'element', 'onSubmit', this.ns('submit')]
]);
if (options.clickout) {
this.addEvent('click', 'element', 'onHide');
}
this.initialize();
} | javascript | function(nodes, options) {
this.nodes = $(nodes);
options = this.setOptions(options);
this.element = this.createElement()
.attr('role', 'dialog')
.aria('labelledby', this.id('title'))
.aria('describedby', this.id('content'));
// Enable fullscreen
if (options.fullScreen) {
this.element.addClass('is-fullscreen');
}
// Setup blackout
if (options.blackout) {
this.blackout = Blackout.instance();
}
// Initialize events
this.addEvents([
['keydown', 'window', 'onKeydown'],
['click', 'document', 'onShow', '{selector}'],
['click', 'element', 'hide', this.ns('close')],
['click', 'element', 'onSubmit', this.ns('submit')]
]);
if (options.clickout) {
this.addEvent('click', 'element', 'onHide');
}
this.initialize();
} | [
"function",
"(",
"nodes",
",",
"options",
")",
"{",
"this",
".",
"nodes",
"=",
"$",
"(",
"nodes",
")",
";",
"options",
"=",
"this",
".",
"setOptions",
"(",
"options",
")",
";",
"this",
".",
"element",
"=",
"this",
".",
"createElement",
"(",
")",
".",
"attr",
"(",
"'role'",
",",
"'dialog'",
")",
".",
"aria",
"(",
"'labelledby'",
",",
"this",
".",
"id",
"(",
"'title'",
")",
")",
".",
"aria",
"(",
"'describedby'",
",",
"this",
".",
"id",
"(",
"'content'",
")",
")",
";",
"// Enable fullscreen",
"if",
"(",
"options",
".",
"fullScreen",
")",
"{",
"this",
".",
"element",
".",
"addClass",
"(",
"'is-fullscreen'",
")",
";",
"}",
"// Setup blackout",
"if",
"(",
"options",
".",
"blackout",
")",
"{",
"this",
".",
"blackout",
"=",
"Blackout",
".",
"instance",
"(",
")",
";",
"}",
"// Initialize events",
"this",
".",
"addEvents",
"(",
"[",
"[",
"'keydown'",
",",
"'window'",
",",
"'onKeydown'",
"]",
",",
"[",
"'click'",
",",
"'document'",
",",
"'onShow'",
",",
"'{selector}'",
"]",
",",
"[",
"'click'",
",",
"'element'",
",",
"'hide'",
",",
"this",
".",
"ns",
"(",
"'close'",
")",
"]",
",",
"[",
"'click'",
",",
"'element'",
",",
"'onSubmit'",
",",
"this",
".",
"ns",
"(",
"'submit'",
")",
"]",
"]",
")",
";",
"if",
"(",
"options",
".",
"clickout",
")",
"{",
"this",
".",
"addEvent",
"(",
"'click'",
",",
"'element'",
",",
"'onHide'",
")",
";",
"}",
"this",
".",
"initialize",
"(",
")",
";",
"}"
] | Initialize the modal.
@param {jQuery} nodes
@param {Object} [options] | [
"Initialize",
"the",
"modal",
"."
] | f0ed36d14cc6d72a7bdbc09da4b5bf7d3d664f0c | https://github.com/titon/toolkit/blob/f0ed36d14cc6d72a7bdbc09da4b5bf7d3d664f0c/dist/toolkit.js#L4543-L4574 | |
21,736 | titon/toolkit | dist/toolkit.js | function(content) {
// AJAX is currently loading
if (content === true) {
return;
}
// Hide blackout loading message
if (this.blackout) {
this.blackout.hideLoader();
}
this.fireEvent('showing');
var body = this.element.find(this.ns('content'));
body.html(content);
this.fireEvent('load', [content]);
// Reveal modal
this.element.reveal();
// Resize modal
if (this.options.fullScreen) {
body.css('min-height', $(window).height());
}
this.fireEvent('shown');
} | javascript | function(content) {
// AJAX is currently loading
if (content === true) {
return;
}
// Hide blackout loading message
if (this.blackout) {
this.blackout.hideLoader();
}
this.fireEvent('showing');
var body = this.element.find(this.ns('content'));
body.html(content);
this.fireEvent('load', [content]);
// Reveal modal
this.element.reveal();
// Resize modal
if (this.options.fullScreen) {
body.css('min-height', $(window).height());
}
this.fireEvent('shown');
} | [
"function",
"(",
"content",
")",
"{",
"// AJAX is currently loading",
"if",
"(",
"content",
"===",
"true",
")",
"{",
"return",
";",
"}",
"// Hide blackout loading message",
"if",
"(",
"this",
".",
"blackout",
")",
"{",
"this",
".",
"blackout",
".",
"hideLoader",
"(",
")",
";",
"}",
"this",
".",
"fireEvent",
"(",
"'showing'",
")",
";",
"var",
"body",
"=",
"this",
".",
"element",
".",
"find",
"(",
"this",
".",
"ns",
"(",
"'content'",
")",
")",
";",
"body",
".",
"html",
"(",
"content",
")",
";",
"this",
".",
"fireEvent",
"(",
"'load'",
",",
"[",
"content",
"]",
")",
";",
"// Reveal modal",
"this",
".",
"element",
".",
"reveal",
"(",
")",
";",
"// Resize modal",
"if",
"(",
"this",
".",
"options",
".",
"fullScreen",
")",
"{",
"body",
".",
"css",
"(",
"'min-height'",
",",
"$",
"(",
"window",
")",
".",
"height",
"(",
")",
")",
";",
"}",
"this",
".",
"fireEvent",
"(",
"'shown'",
")",
";",
"}"
] | Position the modal in the center of the screen.
@param {String|jQuery} content | [
"Position",
"the",
"modal",
"in",
"the",
"center",
"of",
"the",
"screen",
"."
] | f0ed36d14cc6d72a7bdbc09da4b5bf7d3d664f0c | https://github.com/titon/toolkit/blob/f0ed36d14cc6d72a7bdbc09da4b5bf7d3d664f0c/dist/toolkit.js#L4600-L4627 | |
21,737 | titon/toolkit | dist/toolkit.js | function(node, content) {
if (node) {
this.node = node = $(node);
if (!content) {
content = this.readValue(node, this.readOption(node, 'getContent')) || node.attr('href');
}
}
// Show blackout if the element is hidden
// If it is visible, the blackout count will break
if (this.blackout && !this.element.is(':shown')) {
this.blackout.show();
}
// Restrict scrolling
if (this.options.stopScroll) {
$('body').addClass('no-scroll');
}
this.loadContent(content);
} | javascript | function(node, content) {
if (node) {
this.node = node = $(node);
if (!content) {
content = this.readValue(node, this.readOption(node, 'getContent')) || node.attr('href');
}
}
// Show blackout if the element is hidden
// If it is visible, the blackout count will break
if (this.blackout && !this.element.is(':shown')) {
this.blackout.show();
}
// Restrict scrolling
if (this.options.stopScroll) {
$('body').addClass('no-scroll');
}
this.loadContent(content);
} | [
"function",
"(",
"node",
",",
"content",
")",
"{",
"if",
"(",
"node",
")",
"{",
"this",
".",
"node",
"=",
"node",
"=",
"$",
"(",
"node",
")",
";",
"if",
"(",
"!",
"content",
")",
"{",
"content",
"=",
"this",
".",
"readValue",
"(",
"node",
",",
"this",
".",
"readOption",
"(",
"node",
",",
"'getContent'",
")",
")",
"||",
"node",
".",
"attr",
"(",
"'href'",
")",
";",
"}",
"}",
"// Show blackout if the element is hidden",
"// If it is visible, the blackout count will break",
"if",
"(",
"this",
".",
"blackout",
"&&",
"!",
"this",
".",
"element",
".",
"is",
"(",
"':shown'",
")",
")",
"{",
"this",
".",
"blackout",
".",
"show",
"(",
")",
";",
"}",
"// Restrict scrolling",
"if",
"(",
"this",
".",
"options",
".",
"stopScroll",
")",
"{",
"$",
"(",
"'body'",
")",
".",
"addClass",
"(",
"'no-scroll'",
")",
";",
"}",
"this",
".",
"loadContent",
"(",
"content",
")",
";",
"}"
] | Show the modal with the specified content.
@param {jQuery} node
@param {String} [content] | [
"Show",
"the",
"modal",
"with",
"the",
"specified",
"content",
"."
] | f0ed36d14cc6d72a7bdbc09da4b5bf7d3d664f0c | https://github.com/titon/toolkit/blob/f0ed36d14cc6d72a7bdbc09da4b5bf7d3d664f0c/dist/toolkit.js#L4635-L4656 | |
21,738 | titon/toolkit | dist/toolkit.js | function() {
var form = this.element.find('form:first');
if (!form) {
return;
}
this.fireEvent('submit', [form]);
var options = {
url: form.attr('action'),
type: (form.attr('method') || 'post').toUpperCase()
};
if (window.FormData) {
options.processData = false;
options.contentType = false;
options.data = new FormData(form[0]);
} else {
options.data = form.serialize();
}
this.requestData(options);
} | javascript | function() {
var form = this.element.find('form:first');
if (!form) {
return;
}
this.fireEvent('submit', [form]);
var options = {
url: form.attr('action'),
type: (form.attr('method') || 'post').toUpperCase()
};
if (window.FormData) {
options.processData = false;
options.contentType = false;
options.data = new FormData(form[0]);
} else {
options.data = form.serialize();
}
this.requestData(options);
} | [
"function",
"(",
")",
"{",
"var",
"form",
"=",
"this",
".",
"element",
".",
"find",
"(",
"'form:first'",
")",
";",
"if",
"(",
"!",
"form",
")",
"{",
"return",
";",
"}",
"this",
".",
"fireEvent",
"(",
"'submit'",
",",
"[",
"form",
"]",
")",
";",
"var",
"options",
"=",
"{",
"url",
":",
"form",
".",
"attr",
"(",
"'action'",
")",
",",
"type",
":",
"(",
"form",
".",
"attr",
"(",
"'method'",
")",
"||",
"'post'",
")",
".",
"toUpperCase",
"(",
")",
"}",
";",
"if",
"(",
"window",
".",
"FormData",
")",
"{",
"options",
".",
"processData",
"=",
"false",
";",
"options",
".",
"contentType",
"=",
"false",
";",
"options",
".",
"data",
"=",
"new",
"FormData",
"(",
"form",
"[",
"0",
"]",
")",
";",
"}",
"else",
"{",
"options",
".",
"data",
"=",
"form",
".",
"serialize",
"(",
")",
";",
"}",
"this",
".",
"requestData",
"(",
"options",
")",
";",
"}"
] | Submit the form found within the modal. | [
"Submit",
"the",
"form",
"found",
"within",
"the",
"modal",
"."
] | f0ed36d14cc6d72a7bdbc09da4b5bf7d3d664f0c | https://github.com/titon/toolkit/blob/f0ed36d14cc6d72a7bdbc09da4b5bf7d3d664f0c/dist/toolkit.js#L4661-L4684 | |
21,739 | titon/toolkit | dist/toolkit.js | function(element, options) {
element = this.setElement(element).attr('role', 'complementary').conceal();
options = this.setOptions(options, element);
var animation = options.animation;
// Touch devices cannot use squish
if (Toolkit.isTouch && animation === 'squish') {
options.animation = animation = 'push';
}
// Cannot have multiple non-overlayed or non-squished sidebars open
if (animation !== 'on-top' && animation !== 'squish') {
options.hideOthers = true;
}
// Setup container
this.container = element.parent().addClass(animation);
this.primary = element.siblings('[data-offcanvas-content]').attr('role', 'main');
this.secondary = element.siblings('[data-offcanvas-sidebar]');
// Determine the side
this.side = element.data('offcanvas-sidebar') || 'left';
this.opposite = (this.side === 'left') ? 'right' : 'left';
// Initialize events
this.addEvents([
['ready', 'document', 'onReady'],
['resize', 'window', 'onResize']
]);
if (options.swipe) {
if (this.side === 'left') {
this.addEvents([
['swipeleft', 'element', 'hide'],
['swiperight', 'container', 'onSwipe']
]);
} else {
this.addEvents([
['swipeleft', 'container', 'onSwipe'],
['swiperight', 'element', 'hide']
]);
}
}
if (options.selector) {
this.addEvent('click', 'document', 'toggle', options.selector);
}
this.initialize();
} | javascript | function(element, options) {
element = this.setElement(element).attr('role', 'complementary').conceal();
options = this.setOptions(options, element);
var animation = options.animation;
// Touch devices cannot use squish
if (Toolkit.isTouch && animation === 'squish') {
options.animation = animation = 'push';
}
// Cannot have multiple non-overlayed or non-squished sidebars open
if (animation !== 'on-top' && animation !== 'squish') {
options.hideOthers = true;
}
// Setup container
this.container = element.parent().addClass(animation);
this.primary = element.siblings('[data-offcanvas-content]').attr('role', 'main');
this.secondary = element.siblings('[data-offcanvas-sidebar]');
// Determine the side
this.side = element.data('offcanvas-sidebar') || 'left';
this.opposite = (this.side === 'left') ? 'right' : 'left';
// Initialize events
this.addEvents([
['ready', 'document', 'onReady'],
['resize', 'window', 'onResize']
]);
if (options.swipe) {
if (this.side === 'left') {
this.addEvents([
['swipeleft', 'element', 'hide'],
['swiperight', 'container', 'onSwipe']
]);
} else {
this.addEvents([
['swipeleft', 'container', 'onSwipe'],
['swiperight', 'element', 'hide']
]);
}
}
if (options.selector) {
this.addEvent('click', 'document', 'toggle', options.selector);
}
this.initialize();
} | [
"function",
"(",
"element",
",",
"options",
")",
"{",
"element",
"=",
"this",
".",
"setElement",
"(",
"element",
")",
".",
"attr",
"(",
"'role'",
",",
"'complementary'",
")",
".",
"conceal",
"(",
")",
";",
"options",
"=",
"this",
".",
"setOptions",
"(",
"options",
",",
"element",
")",
";",
"var",
"animation",
"=",
"options",
".",
"animation",
";",
"// Touch devices cannot use squish",
"if",
"(",
"Toolkit",
".",
"isTouch",
"&&",
"animation",
"===",
"'squish'",
")",
"{",
"options",
".",
"animation",
"=",
"animation",
"=",
"'push'",
";",
"}",
"// Cannot have multiple non-overlayed or non-squished sidebars open",
"if",
"(",
"animation",
"!==",
"'on-top'",
"&&",
"animation",
"!==",
"'squish'",
")",
"{",
"options",
".",
"hideOthers",
"=",
"true",
";",
"}",
"// Setup container",
"this",
".",
"container",
"=",
"element",
".",
"parent",
"(",
")",
".",
"addClass",
"(",
"animation",
")",
";",
"this",
".",
"primary",
"=",
"element",
".",
"siblings",
"(",
"'[data-offcanvas-content]'",
")",
".",
"attr",
"(",
"'role'",
",",
"'main'",
")",
";",
"this",
".",
"secondary",
"=",
"element",
".",
"siblings",
"(",
"'[data-offcanvas-sidebar]'",
")",
";",
"// Determine the side",
"this",
".",
"side",
"=",
"element",
".",
"data",
"(",
"'offcanvas-sidebar'",
")",
"||",
"'left'",
";",
"this",
".",
"opposite",
"=",
"(",
"this",
".",
"side",
"===",
"'left'",
")",
"?",
"'right'",
":",
"'left'",
";",
"// Initialize events",
"this",
".",
"addEvents",
"(",
"[",
"[",
"'ready'",
",",
"'document'",
",",
"'onReady'",
"]",
",",
"[",
"'resize'",
",",
"'window'",
",",
"'onResize'",
"]",
"]",
")",
";",
"if",
"(",
"options",
".",
"swipe",
")",
"{",
"if",
"(",
"this",
".",
"side",
"===",
"'left'",
")",
"{",
"this",
".",
"addEvents",
"(",
"[",
"[",
"'swipeleft'",
",",
"'element'",
",",
"'hide'",
"]",
",",
"[",
"'swiperight'",
",",
"'container'",
",",
"'onSwipe'",
"]",
"]",
")",
";",
"}",
"else",
"{",
"this",
".",
"addEvents",
"(",
"[",
"[",
"'swipeleft'",
",",
"'container'",
",",
"'onSwipe'",
"]",
",",
"[",
"'swiperight'",
",",
"'element'",
",",
"'hide'",
"]",
"]",
")",
";",
"}",
"}",
"if",
"(",
"options",
".",
"selector",
")",
"{",
"this",
".",
"addEvent",
"(",
"'click'",
",",
"'document'",
",",
"'toggle'",
",",
"options",
".",
"selector",
")",
";",
"}",
"this",
".",
"initialize",
"(",
")",
";",
"}"
] | Initialize off canvas.
@param {jQuery} element
@param {Object} [options] | [
"Initialize",
"off",
"canvas",
"."
] | f0ed36d14cc6d72a7bdbc09da4b5bf7d3d664f0c | https://github.com/titon/toolkit/blob/f0ed36d14cc6d72a7bdbc09da4b5bf7d3d664f0c/dist/toolkit.js#L4786-L4836 | |
21,740 | titon/toolkit | dist/toolkit.js | function() {
this.fireEvent('hiding');
this.container.removeClass('move-' + this.opposite);
this.element
.conceal()
.removeClass('is-expanded')
.aria('expanded', false);
if (this.options.stopScroll) {
$('body').removeClass('no-scroll');
}
this.fireEvent('hidden');
} | javascript | function() {
this.fireEvent('hiding');
this.container.removeClass('move-' + this.opposite);
this.element
.conceal()
.removeClass('is-expanded')
.aria('expanded', false);
if (this.options.stopScroll) {
$('body').removeClass('no-scroll');
}
this.fireEvent('hidden');
} | [
"function",
"(",
")",
"{",
"this",
".",
"fireEvent",
"(",
"'hiding'",
")",
";",
"this",
".",
"container",
".",
"removeClass",
"(",
"'move-'",
"+",
"this",
".",
"opposite",
")",
";",
"this",
".",
"element",
".",
"conceal",
"(",
")",
".",
"removeClass",
"(",
"'is-expanded'",
")",
".",
"aria",
"(",
"'expanded'",
",",
"false",
")",
";",
"if",
"(",
"this",
".",
"options",
".",
"stopScroll",
")",
"{",
"$",
"(",
"'body'",
")",
".",
"removeClass",
"(",
"'no-scroll'",
")",
";",
"}",
"this",
".",
"fireEvent",
"(",
"'hidden'",
")",
";",
"}"
] | Hide the sidebar and reset the container. | [
"Hide",
"the",
"sidebar",
"and",
"reset",
"the",
"container",
"."
] | f0ed36d14cc6d72a7bdbc09da4b5bf7d3d664f0c | https://github.com/titon/toolkit/blob/f0ed36d14cc6d72a7bdbc09da4b5bf7d3d664f0c/dist/toolkit.js#L4848-L4863 | |
21,741 | titon/toolkit | dist/toolkit.js | function() {
var options = this.options;
if (options.hideOthers) {
this.secondary.each(function() {
var sidebar = $(this);
if (sidebar.hasClass('is-expanded')) {
sidebar.toolkit('offCanvas', 'hide');
}
});
}
this.fireEvent('showing');
this.container.addClass('move-' + this.opposite);
this.element
.reveal()
.addClass('is-expanded')
.aria('expanded', true);
if (options.stopScroll) {
$('body').addClass('no-scroll');
}
this.fireEvent('shown');
} | javascript | function() {
var options = this.options;
if (options.hideOthers) {
this.secondary.each(function() {
var sidebar = $(this);
if (sidebar.hasClass('is-expanded')) {
sidebar.toolkit('offCanvas', 'hide');
}
});
}
this.fireEvent('showing');
this.container.addClass('move-' + this.opposite);
this.element
.reveal()
.addClass('is-expanded')
.aria('expanded', true);
if (options.stopScroll) {
$('body').addClass('no-scroll');
}
this.fireEvent('shown');
} | [
"function",
"(",
")",
"{",
"var",
"options",
"=",
"this",
".",
"options",
";",
"if",
"(",
"options",
".",
"hideOthers",
")",
"{",
"this",
".",
"secondary",
".",
"each",
"(",
"function",
"(",
")",
"{",
"var",
"sidebar",
"=",
"$",
"(",
"this",
")",
";",
"if",
"(",
"sidebar",
".",
"hasClass",
"(",
"'is-expanded'",
")",
")",
"{",
"sidebar",
".",
"toolkit",
"(",
"'offCanvas'",
",",
"'hide'",
")",
";",
"}",
"}",
")",
";",
"}",
"this",
".",
"fireEvent",
"(",
"'showing'",
")",
";",
"this",
".",
"container",
".",
"addClass",
"(",
"'move-'",
"+",
"this",
".",
"opposite",
")",
";",
"this",
".",
"element",
".",
"reveal",
"(",
")",
".",
"addClass",
"(",
"'is-expanded'",
")",
".",
"aria",
"(",
"'expanded'",
",",
"true",
")",
";",
"if",
"(",
"options",
".",
"stopScroll",
")",
"{",
"$",
"(",
"'body'",
")",
".",
"addClass",
"(",
"'no-scroll'",
")",
";",
"}",
"this",
".",
"fireEvent",
"(",
"'shown'",
")",
";",
"}"
] | Show the sidebar and squish the container to make room for the sidebar.
If hideOthers is true, hide other open sidebars. | [
"Show",
"the",
"sidebar",
"and",
"squish",
"the",
"container",
"to",
"make",
"room",
"for",
"the",
"sidebar",
".",
"If",
"hideOthers",
"is",
"true",
"hide",
"other",
"open",
"sidebars",
"."
] | f0ed36d14cc6d72a7bdbc09da4b5bf7d3d664f0c | https://github.com/titon/toolkit/blob/f0ed36d14cc6d72a7bdbc09da4b5bf7d3d664f0c/dist/toolkit.js#L4869-L4896 | |
21,742 | titon/toolkit | dist/toolkit.js | function() {
if (!this.options.openOnLoad || this._loaded) {
return;
}
var sidebar = this.element,
inner = this.primary,
transClass = 'no-transition';
sidebar.addClass(transClass);
inner.addClass(transClass);
this.show();
// Transitions will still occur unless we place in a timeout
setTimeout(function() {
sidebar.removeClass(transClass);
inner.removeClass(transClass);
}, 15); // IE needs a minimum of 15
this._loaded = true;
} | javascript | function() {
if (!this.options.openOnLoad || this._loaded) {
return;
}
var sidebar = this.element,
inner = this.primary,
transClass = 'no-transition';
sidebar.addClass(transClass);
inner.addClass(transClass);
this.show();
// Transitions will still occur unless we place in a timeout
setTimeout(function() {
sidebar.removeClass(transClass);
inner.removeClass(transClass);
}, 15); // IE needs a minimum of 15
this._loaded = true;
} | [
"function",
"(",
")",
"{",
"if",
"(",
"!",
"this",
".",
"options",
".",
"openOnLoad",
"||",
"this",
".",
"_loaded",
")",
"{",
"return",
";",
"}",
"var",
"sidebar",
"=",
"this",
".",
"element",
",",
"inner",
"=",
"this",
".",
"primary",
",",
"transClass",
"=",
"'no-transition'",
";",
"sidebar",
".",
"addClass",
"(",
"transClass",
")",
";",
"inner",
".",
"addClass",
"(",
"transClass",
")",
";",
"this",
".",
"show",
"(",
")",
";",
"// Transitions will still occur unless we place in a timeout",
"setTimeout",
"(",
"function",
"(",
")",
"{",
"sidebar",
".",
"removeClass",
"(",
"transClass",
")",
";",
"inner",
".",
"removeClass",
"(",
"transClass",
")",
";",
"}",
",",
"15",
")",
";",
"// IE needs a minimum of 15",
"this",
".",
"_loaded",
"=",
"true",
";",
"}"
] | On page load, immediately display the sidebar.
Remove transitions from the sidebar and container so there is no page jumping.
Also disable `hideOthers` so multiple sidebars can be displayed on load.
@private | [
"On",
"page",
"load",
"immediately",
"display",
"the",
"sidebar",
".",
"Remove",
"transitions",
"from",
"the",
"sidebar",
"and",
"container",
"so",
"there",
"is",
"no",
"page",
"jumping",
".",
"Also",
"disable",
"hideOthers",
"so",
"multiple",
"sidebars",
"can",
"be",
"displayed",
"on",
"load",
"."
] | f0ed36d14cc6d72a7bdbc09da4b5bf7d3d664f0c | https://github.com/titon/toolkit/blob/f0ed36d14cc6d72a7bdbc09da4b5bf7d3d664f0c/dist/toolkit.js#L4916-L4937 | |
21,743 | titon/toolkit | dist/toolkit.js | function(e) {
e.preventDefault();
var target = $(e.target),
selector = '[data-offcanvas-sidebar]';
if (target.is(selector) || target.parents(selector).length) {
return;
}
this.show();
} | javascript | function(e) {
e.preventDefault();
var target = $(e.target),
selector = '[data-offcanvas-sidebar]';
if (target.is(selector) || target.parents(selector).length) {
return;
}
this.show();
} | [
"function",
"(",
"e",
")",
"{",
"e",
".",
"preventDefault",
"(",
")",
";",
"var",
"target",
"=",
"$",
"(",
"e",
".",
"target",
")",
",",
"selector",
"=",
"'[data-offcanvas-sidebar]'",
";",
"if",
"(",
"target",
".",
"is",
"(",
"selector",
")",
"||",
"target",
".",
"parents",
"(",
"selector",
")",
".",
"length",
")",
"{",
"return",
";",
"}",
"this",
".",
"show",
"(",
")",
";",
"}"
] | When swiping on the container, don't trigger a show if we are trying to hide a sidebar.
@private
@param {jQuery.Event} e | [
"When",
"swiping",
"on",
"the",
"container",
"don",
"t",
"trigger",
"a",
"show",
"if",
"we",
"are",
"trying",
"to",
"hide",
"a",
"sidebar",
"."
] | f0ed36d14cc6d72a7bdbc09da4b5bf7d3d664f0c | https://github.com/titon/toolkit/blob/f0ed36d14cc6d72a7bdbc09da4b5bf7d3d664f0c/dist/toolkit.js#L4954-L4965 | |
21,744 | titon/toolkit | dist/toolkit.js | function(element, options) {
element = this.setElement(element);
options = this.setOptions(options, element);
// Setup classes and ARIA
element
.attr('role', 'complementary')
.addClass(options.animation);
// Determine before calculations
var initialTop = element[0].style.top; // jQuery sometimes returns auto
this.initialTop = (initialTop === 'auto') ? 0 : parseInt(initialTop, 10);
this.elementTop = element.offset().top;
// Initialize events
var throttle = options.throttle;
this.addEvents([
['scroll', 'window', $.throttle(this.onScroll.bind(this), throttle)],
['resize', 'window', $.throttle(this.onResize.bind(this), throttle)],
['ready', 'document', 'onResize']
]);
this.initialize();
} | javascript | function(element, options) {
element = this.setElement(element);
options = this.setOptions(options, element);
// Setup classes and ARIA
element
.attr('role', 'complementary')
.addClass(options.animation);
// Determine before calculations
var initialTop = element[0].style.top; // jQuery sometimes returns auto
this.initialTop = (initialTop === 'auto') ? 0 : parseInt(initialTop, 10);
this.elementTop = element.offset().top;
// Initialize events
var throttle = options.throttle;
this.addEvents([
['scroll', 'window', $.throttle(this.onScroll.bind(this), throttle)],
['resize', 'window', $.throttle(this.onResize.bind(this), throttle)],
['ready', 'document', 'onResize']
]);
this.initialize();
} | [
"function",
"(",
"element",
",",
"options",
")",
"{",
"element",
"=",
"this",
".",
"setElement",
"(",
"element",
")",
";",
"options",
"=",
"this",
".",
"setOptions",
"(",
"options",
",",
"element",
")",
";",
"// Setup classes and ARIA",
"element",
".",
"attr",
"(",
"'role'",
",",
"'complementary'",
")",
".",
"addClass",
"(",
"options",
".",
"animation",
")",
";",
"// Determine before calculations",
"var",
"initialTop",
"=",
"element",
"[",
"0",
"]",
".",
"style",
".",
"top",
";",
"// jQuery sometimes returns auto",
"this",
".",
"initialTop",
"=",
"(",
"initialTop",
"===",
"'auto'",
")",
"?",
"0",
":",
"parseInt",
"(",
"initialTop",
",",
"10",
")",
";",
"this",
".",
"elementTop",
"=",
"element",
".",
"offset",
"(",
")",
".",
"top",
";",
"// Initialize events",
"var",
"throttle",
"=",
"options",
".",
"throttle",
";",
"this",
".",
"addEvents",
"(",
"[",
"[",
"'scroll'",
",",
"'window'",
",",
"$",
".",
"throttle",
"(",
"this",
".",
"onScroll",
".",
"bind",
"(",
"this",
")",
",",
"throttle",
")",
"]",
",",
"[",
"'resize'",
",",
"'window'",
",",
"$",
".",
"throttle",
"(",
"this",
".",
"onResize",
".",
"bind",
"(",
"this",
")",
",",
"throttle",
")",
"]",
",",
"[",
"'ready'",
",",
"'document'",
",",
"'onResize'",
"]",
"]",
")",
";",
"this",
".",
"initialize",
"(",
")",
";",
"}"
] | Initialize the pin.
@param {jQuery} element
@param {Object} [options] | [
"Initialize",
"the",
"pin",
"."
] | f0ed36d14cc6d72a7bdbc09da4b5bf7d3d664f0c | https://github.com/titon/toolkit/blob/f0ed36d14cc6d72a7bdbc09da4b5bf7d3d664f0c/dist/toolkit.js#L5014-L5039 | |
21,745 | titon/toolkit | dist/toolkit.js | function() {
var win = $(window),
options = this.options,
element = this.element,
parent = options.context ? element.parents(options.context) : element.parent();
this.viewport = {
width: win.width(),
height: win.height()
};
this.elementHeight = element.outerHeight(true); // Include margin
this.parentHeight = parent.height(); // Exclude padding
this.parentTop = parent.offset().top;
// Disable pin if element is larger than the viewport
if (options.lock && this.elementHeight >= this.viewport.height) {
this.active = false;
// Enable pin if the parent is larger than the child
} else {
this.active = (element.is(':visible') && this.parentHeight > this.elementHeight);
}
} | javascript | function() {
var win = $(window),
options = this.options,
element = this.element,
parent = options.context ? element.parents(options.context) : element.parent();
this.viewport = {
width: win.width(),
height: win.height()
};
this.elementHeight = element.outerHeight(true); // Include margin
this.parentHeight = parent.height(); // Exclude padding
this.parentTop = parent.offset().top;
// Disable pin if element is larger than the viewport
if (options.lock && this.elementHeight >= this.viewport.height) {
this.active = false;
// Enable pin if the parent is larger than the child
} else {
this.active = (element.is(':visible') && this.parentHeight > this.elementHeight);
}
} | [
"function",
"(",
")",
"{",
"var",
"win",
"=",
"$",
"(",
"window",
")",
",",
"options",
"=",
"this",
".",
"options",
",",
"element",
"=",
"this",
".",
"element",
",",
"parent",
"=",
"options",
".",
"context",
"?",
"element",
".",
"parents",
"(",
"options",
".",
"context",
")",
":",
"element",
".",
"parent",
"(",
")",
";",
"this",
".",
"viewport",
"=",
"{",
"width",
":",
"win",
".",
"width",
"(",
")",
",",
"height",
":",
"win",
".",
"height",
"(",
")",
"}",
";",
"this",
".",
"elementHeight",
"=",
"element",
".",
"outerHeight",
"(",
"true",
")",
";",
"// Include margin",
"this",
".",
"parentHeight",
"=",
"parent",
".",
"height",
"(",
")",
";",
"// Exclude padding",
"this",
".",
"parentTop",
"=",
"parent",
".",
"offset",
"(",
")",
".",
"top",
";",
"// Disable pin if element is larger than the viewport",
"if",
"(",
"options",
".",
"lock",
"&&",
"this",
".",
"elementHeight",
">=",
"this",
".",
"viewport",
".",
"height",
")",
"{",
"this",
".",
"active",
"=",
"false",
";",
"// Enable pin if the parent is larger than the child",
"}",
"else",
"{",
"this",
".",
"active",
"=",
"(",
"element",
".",
"is",
"(",
"':visible'",
")",
"&&",
"this",
".",
"parentHeight",
">",
"this",
".",
"elementHeight",
")",
";",
"}",
"}"
] | Calculate the dimensions and offsets of the interacting elements. | [
"Calculate",
"the",
"dimensions",
"and",
"offsets",
"of",
"the",
"interacting",
"elements",
"."
] | f0ed36d14cc6d72a7bdbc09da4b5bf7d3d664f0c | https://github.com/titon/toolkit/blob/f0ed36d14cc6d72a7bdbc09da4b5bf7d3d664f0c/dist/toolkit.js#L5054-L5077 | |
21,746 | titon/toolkit | dist/toolkit.js | function() {
var options = this.options;
if (options.calculate) {
this.calculate();
}
if (!this.active) {
return;
}
var eHeight = this.elementHeight,
eTop = this.elementTop,
pHeight = this.parentHeight,
pTop = this.parentTop,
cssTop = this.initialTop,
scrollTop = $(window).scrollTop(),
pos = {},
x = options.xOffset,
y = 0;
// Scroll is above the parent, remove pin inline styles
if (scrollTop < pTop || scrollTop === 0) {
if (this.pinned) {
this.unpin();
}
return;
}
// Don't extend out the bottom
var elementMaxPos = scrollTop + eHeight,
parentMaxHeight = pHeight + pTop;
// Swap positioning of the fixed menu once it reaches the parent borders
if (options.fixed) {
if (elementMaxPos >= parentMaxHeight) {
y = 'auto';
pos.position = 'absolute';
pos.bottom = 0;
} else if (scrollTop >= eTop) {
y = options.yOffset;
pos.position = 'fixed';
pos.bottom = 'auto';
}
// Stop positioning absolute menu once it exits the parent
} else {
pos.position = 'absolute';
if (elementMaxPos >= parentMaxHeight) {
y += (pHeight - eHeight);
} else {
y += (scrollTop - pTop) + options.yOffset;
}
// Don't go lower than default top
if (cssTop && y < cssTop) {
y = cssTop;
}
}
pos[options.location] = x;
pos.top = y;
this.element
.css(pos)
.addClass('is-pinned');
this.pinned = true;
this.fireEvent('pinned');
} | javascript | function() {
var options = this.options;
if (options.calculate) {
this.calculate();
}
if (!this.active) {
return;
}
var eHeight = this.elementHeight,
eTop = this.elementTop,
pHeight = this.parentHeight,
pTop = this.parentTop,
cssTop = this.initialTop,
scrollTop = $(window).scrollTop(),
pos = {},
x = options.xOffset,
y = 0;
// Scroll is above the parent, remove pin inline styles
if (scrollTop < pTop || scrollTop === 0) {
if (this.pinned) {
this.unpin();
}
return;
}
// Don't extend out the bottom
var elementMaxPos = scrollTop + eHeight,
parentMaxHeight = pHeight + pTop;
// Swap positioning of the fixed menu once it reaches the parent borders
if (options.fixed) {
if (elementMaxPos >= parentMaxHeight) {
y = 'auto';
pos.position = 'absolute';
pos.bottom = 0;
} else if (scrollTop >= eTop) {
y = options.yOffset;
pos.position = 'fixed';
pos.bottom = 'auto';
}
// Stop positioning absolute menu once it exits the parent
} else {
pos.position = 'absolute';
if (elementMaxPos >= parentMaxHeight) {
y += (pHeight - eHeight);
} else {
y += (scrollTop - pTop) + options.yOffset;
}
// Don't go lower than default top
if (cssTop && y < cssTop) {
y = cssTop;
}
}
pos[options.location] = x;
pos.top = y;
this.element
.css(pos)
.addClass('is-pinned');
this.pinned = true;
this.fireEvent('pinned');
} | [
"function",
"(",
")",
"{",
"var",
"options",
"=",
"this",
".",
"options",
";",
"if",
"(",
"options",
".",
"calculate",
")",
"{",
"this",
".",
"calculate",
"(",
")",
";",
"}",
"if",
"(",
"!",
"this",
".",
"active",
")",
"{",
"return",
";",
"}",
"var",
"eHeight",
"=",
"this",
".",
"elementHeight",
",",
"eTop",
"=",
"this",
".",
"elementTop",
",",
"pHeight",
"=",
"this",
".",
"parentHeight",
",",
"pTop",
"=",
"this",
".",
"parentTop",
",",
"cssTop",
"=",
"this",
".",
"initialTop",
",",
"scrollTop",
"=",
"$",
"(",
"window",
")",
".",
"scrollTop",
"(",
")",
",",
"pos",
"=",
"{",
"}",
",",
"x",
"=",
"options",
".",
"xOffset",
",",
"y",
"=",
"0",
";",
"// Scroll is above the parent, remove pin inline styles",
"if",
"(",
"scrollTop",
"<",
"pTop",
"||",
"scrollTop",
"===",
"0",
")",
"{",
"if",
"(",
"this",
".",
"pinned",
")",
"{",
"this",
".",
"unpin",
"(",
")",
";",
"}",
"return",
";",
"}",
"// Don't extend out the bottom",
"var",
"elementMaxPos",
"=",
"scrollTop",
"+",
"eHeight",
",",
"parentMaxHeight",
"=",
"pHeight",
"+",
"pTop",
";",
"// Swap positioning of the fixed menu once it reaches the parent borders",
"if",
"(",
"options",
".",
"fixed",
")",
"{",
"if",
"(",
"elementMaxPos",
">=",
"parentMaxHeight",
")",
"{",
"y",
"=",
"'auto'",
";",
"pos",
".",
"position",
"=",
"'absolute'",
";",
"pos",
".",
"bottom",
"=",
"0",
";",
"}",
"else",
"if",
"(",
"scrollTop",
">=",
"eTop",
")",
"{",
"y",
"=",
"options",
".",
"yOffset",
";",
"pos",
".",
"position",
"=",
"'fixed'",
";",
"pos",
".",
"bottom",
"=",
"'auto'",
";",
"}",
"// Stop positioning absolute menu once it exits the parent",
"}",
"else",
"{",
"pos",
".",
"position",
"=",
"'absolute'",
";",
"if",
"(",
"elementMaxPos",
">=",
"parentMaxHeight",
")",
"{",
"y",
"+=",
"(",
"pHeight",
"-",
"eHeight",
")",
";",
"}",
"else",
"{",
"y",
"+=",
"(",
"scrollTop",
"-",
"pTop",
")",
"+",
"options",
".",
"yOffset",
";",
"}",
"// Don't go lower than default top",
"if",
"(",
"cssTop",
"&&",
"y",
"<",
"cssTop",
")",
"{",
"y",
"=",
"cssTop",
";",
"}",
"}",
"pos",
"[",
"options",
".",
"location",
"]",
"=",
"x",
";",
"pos",
".",
"top",
"=",
"y",
";",
"this",
".",
"element",
".",
"css",
"(",
"pos",
")",
".",
"addClass",
"(",
"'is-pinned'",
")",
";",
"this",
".",
"pinned",
"=",
"true",
";",
"this",
".",
"fireEvent",
"(",
"'pinned'",
")",
";",
"}"
] | Pin the element along the vertical axis while staying contained within the parent. | [
"Pin",
"the",
"element",
"along",
"the",
"vertical",
"axis",
"while",
"staying",
"contained",
"within",
"the",
"parent",
"."
] | f0ed36d14cc6d72a7bdbc09da4b5bf7d3d664f0c | https://github.com/titon/toolkit/blob/f0ed36d14cc6d72a7bdbc09da4b5bf7d3d664f0c/dist/toolkit.js#L5082-L5158 | |
21,747 | titon/toolkit | dist/toolkit.js | function(nodes, options) {
this.nodes = $(nodes);
options = this.setOptions(options);
this.createWrapper();
// Remove title attributes
if (options.getTitle === 'title') {
options.getTitle = 'data-' + this.keyName + '-title';
this.nodes.each(function(i, node) {
$(node).attr(options.getTitle, $(node).attr('title')).removeAttr('title');
});
}
// Initialize events
this.addEvents([
['{mode}', 'document', 'onShowToggle', '{selector}'],
['resize', 'window', $.debounce(this.onHide.bind(this))]
]);
if (options.mode === 'click') {
this.addEvent('clickout', 'document', 'hide');
} else {
this.addEvent('mouseleave', 'document', 'hide', '{selector}');
}
this.initialize();
} | javascript | function(nodes, options) {
this.nodes = $(nodes);
options = this.setOptions(options);
this.createWrapper();
// Remove title attributes
if (options.getTitle === 'title') {
options.getTitle = 'data-' + this.keyName + '-title';
this.nodes.each(function(i, node) {
$(node).attr(options.getTitle, $(node).attr('title')).removeAttr('title');
});
}
// Initialize events
this.addEvents([
['{mode}', 'document', 'onShowToggle', '{selector}'],
['resize', 'window', $.debounce(this.onHide.bind(this))]
]);
if (options.mode === 'click') {
this.addEvent('clickout', 'document', 'hide');
} else {
this.addEvent('mouseleave', 'document', 'hide', '{selector}');
}
this.initialize();
} | [
"function",
"(",
"nodes",
",",
"options",
")",
"{",
"this",
".",
"nodes",
"=",
"$",
"(",
"nodes",
")",
";",
"options",
"=",
"this",
".",
"setOptions",
"(",
"options",
")",
";",
"this",
".",
"createWrapper",
"(",
")",
";",
"// Remove title attributes",
"if",
"(",
"options",
".",
"getTitle",
"===",
"'title'",
")",
"{",
"options",
".",
"getTitle",
"=",
"'data-'",
"+",
"this",
".",
"keyName",
"+",
"'-title'",
";",
"this",
".",
"nodes",
".",
"each",
"(",
"function",
"(",
"i",
",",
"node",
")",
"{",
"$",
"(",
"node",
")",
".",
"attr",
"(",
"options",
".",
"getTitle",
",",
"$",
"(",
"node",
")",
".",
"attr",
"(",
"'title'",
")",
")",
".",
"removeAttr",
"(",
"'title'",
")",
";",
"}",
")",
";",
"}",
"// Initialize events",
"this",
".",
"addEvents",
"(",
"[",
"[",
"'{mode}'",
",",
"'document'",
",",
"'onShowToggle'",
",",
"'{selector}'",
"]",
",",
"[",
"'resize'",
",",
"'window'",
",",
"$",
".",
"debounce",
"(",
"this",
".",
"onHide",
".",
"bind",
"(",
"this",
")",
")",
"]",
"]",
")",
";",
"if",
"(",
"options",
".",
"mode",
"===",
"'click'",
")",
"{",
"this",
".",
"addEvent",
"(",
"'clickout'",
",",
"'document'",
",",
"'hide'",
")",
";",
"}",
"else",
"{",
"this",
".",
"addEvent",
"(",
"'mouseleave'",
",",
"'document'",
",",
"'hide'",
",",
"'{selector}'",
")",
";",
"}",
"this",
".",
"initialize",
"(",
")",
";",
"}"
] | Initialize the tooltip.
@param {jQuery} nodes
@param {Object} [options] | [
"Initialize",
"the",
"tooltip",
"."
] | f0ed36d14cc6d72a7bdbc09da4b5bf7d3d664f0c | https://github.com/titon/toolkit/blob/f0ed36d14cc6d72a7bdbc09da4b5bf7d3d664f0c/dist/toolkit.js#L5329-L5356 | |
21,748 | titon/toolkit | dist/toolkit.js | function(node, content) {
this.node = node = $(node).addClass('is-active');
// Load the new element
this.loadElement(node, function(tooltip) {
tooltip
.addClass(this.readOption(node, 'position'))
.attr('role', 'tooltip');
});
// Load the content
this.loadContent(content || this.readValue(node, this.readOption(node, 'getContent')));
} | javascript | function(node, content) {
this.node = node = $(node).addClass('is-active');
// Load the new element
this.loadElement(node, function(tooltip) {
tooltip
.addClass(this.readOption(node, 'position'))
.attr('role', 'tooltip');
});
// Load the content
this.loadContent(content || this.readValue(node, this.readOption(node, 'getContent')));
} | [
"function",
"(",
"node",
",",
"content",
")",
"{",
"this",
".",
"node",
"=",
"node",
"=",
"$",
"(",
"node",
")",
".",
"addClass",
"(",
"'is-active'",
")",
";",
"// Load the new element",
"this",
".",
"loadElement",
"(",
"node",
",",
"function",
"(",
"tooltip",
")",
"{",
"tooltip",
".",
"addClass",
"(",
"this",
".",
"readOption",
"(",
"node",
",",
"'position'",
")",
")",
".",
"attr",
"(",
"'role'",
",",
"'tooltip'",
")",
";",
"}",
")",
";",
"// Load the content",
"this",
".",
"loadContent",
"(",
"content",
"||",
"this",
".",
"readValue",
"(",
"node",
",",
"this",
".",
"readOption",
"(",
"node",
",",
"'getContent'",
")",
")",
")",
";",
"}"
] | Show the tooltip and determine whether to grab the content from an AJAX call,
a DOM node, or plain text. The content can also be passed as an argument.
@param {jQuery} node
@param {String|jQuery} [content] | [
"Show",
"the",
"tooltip",
"and",
"determine",
"whether",
"to",
"grab",
"the",
"content",
"from",
"an",
"AJAX",
"call",
"a",
"DOM",
"node",
"or",
"plain",
"text",
".",
"The",
"content",
"can",
"also",
"be",
"passed",
"as",
"an",
"argument",
"."
] | f0ed36d14cc6d72a7bdbc09da4b5bf7d3d664f0c | https://github.com/titon/toolkit/blob/f0ed36d14cc6d72a7bdbc09da4b5bf7d3d664f0c/dist/toolkit.js#L5434-L5446 | |
21,749 | titon/toolkit | dist/toolkit.js | function(e) {
e.preventDefault();
var options = this.options;
this.element.reveal().positionTo(options.position, e, {
left: options.xOffset,
top: options.yOffset
}, true);
} | javascript | function(e) {
e.preventDefault();
var options = this.options;
this.element.reveal().positionTo(options.position, e, {
left: options.xOffset,
top: options.yOffset
}, true);
} | [
"function",
"(",
"e",
")",
"{",
"e",
".",
"preventDefault",
"(",
")",
";",
"var",
"options",
"=",
"this",
".",
"options",
";",
"this",
".",
"element",
".",
"reveal",
"(",
")",
".",
"positionTo",
"(",
"options",
".",
"position",
",",
"e",
",",
"{",
"left",
":",
"options",
".",
"xOffset",
",",
"top",
":",
"options",
".",
"yOffset",
"}",
",",
"true",
")",
";",
"}"
] | Event handler for positioning the tooltip by the mouse.
@private
@param {jQuery.Event} e | [
"Event",
"handler",
"for",
"positioning",
"the",
"tooltip",
"by",
"the",
"mouse",
"."
] | f0ed36d14cc6d72a7bdbc09da4b5bf7d3d664f0c | https://github.com/titon/toolkit/blob/f0ed36d14cc6d72a7bdbc09da4b5bf7d3d664f0c/dist/toolkit.js#L5454-L5463 | |
21,750 | titon/toolkit | dist/toolkit.js | function(nodes, options) {
options = options || {};
options.mode = 'click'; // Click only
options.follow = false; // Disable mouse follow
Tooltip.prototype.constructor.call(this, nodes, options);
} | javascript | function(nodes, options) {
options = options || {};
options.mode = 'click'; // Click only
options.follow = false; // Disable mouse follow
Tooltip.prototype.constructor.call(this, nodes, options);
} | [
"function",
"(",
"nodes",
",",
"options",
")",
"{",
"options",
"=",
"options",
"||",
"{",
"}",
";",
"options",
".",
"mode",
"=",
"'click'",
";",
"// Click only",
"options",
".",
"follow",
"=",
"false",
";",
"// Disable mouse follow",
"Tooltip",
".",
"prototype",
".",
"constructor",
".",
"call",
"(",
"this",
",",
"nodes",
",",
"options",
")",
";",
"}"
] | Initialize the popover.
@param {jQuery} nodes
@param {Object} [options] | [
"Initialize",
"the",
"popover",
"."
] | f0ed36d14cc6d72a7bdbc09da4b5bf7d3d664f0c | https://github.com/titon/toolkit/blob/f0ed36d14cc6d72a7bdbc09da4b5bf7d3d664f0c/dist/toolkit.js#L5531-L5537 | |
21,751 | titon/toolkit | dist/toolkit.js | function(element, options) {
var sections, tabs, self = this;
element = this.setElement(element);
options = this.setOptions(options, element);
// Determine cookie name
if (!options.cookie) {
options.cookie = element.attr('id');
}
// Find all the sections and set ARIA attributes
this.sections = sections = element.find(this.ns('section')).each(function(index, section) {
section = $(section);
section
.attr('role', 'tabpanel')
.attr('id', section.attr('id') || self.id('section', index))
.aria('labelledby', self.id('tab', index))
.conceal();
});
// Find the nav and set ARIA attributes
this.nav = element.find(this.ns('nav'))
.attr('role', 'tablist');
// Find the tabs within the nav and set ARIA attributes
this.tabs = tabs = this.nav.find('a').each(function(index) {
$(this)
.data('tab-index', index)
.attr({
role: 'tab',
id: self.id('tab', index)
})
.aria({
controls: sections.eq(index).attr('id'),
selected: false,
expanded: false
})
.removeClass('is-active');
});
// Initialize events
this.addEvent('{mode}', 'element', 'onShow', this.ns('nav') + ' a');
if (options.mode !== 'click' && options.preventDefault) {
this.addEvent('click', 'element', function(e) {
e.preventDefault();
}, this.ns('nav') + ' a');
}
this.initialize();
// Trigger default tab to display
var index = null;
if (options.persistState) {
if (options.cookie && $.cookie) {
index = $.cookie('toolkit.tab.' + options.cookie);
}
if (index === null && options.loadFragment && location.hash) {
index = tabs.filter(function() {
return ($(this).attr('href') === location.hash);
}).eq(0).data('tab-index');
}
}
if (!tabs[index]) {
index = options.defaultIndex;
}
this.jump(index);
} | javascript | function(element, options) {
var sections, tabs, self = this;
element = this.setElement(element);
options = this.setOptions(options, element);
// Determine cookie name
if (!options.cookie) {
options.cookie = element.attr('id');
}
// Find all the sections and set ARIA attributes
this.sections = sections = element.find(this.ns('section')).each(function(index, section) {
section = $(section);
section
.attr('role', 'tabpanel')
.attr('id', section.attr('id') || self.id('section', index))
.aria('labelledby', self.id('tab', index))
.conceal();
});
// Find the nav and set ARIA attributes
this.nav = element.find(this.ns('nav'))
.attr('role', 'tablist');
// Find the tabs within the nav and set ARIA attributes
this.tabs = tabs = this.nav.find('a').each(function(index) {
$(this)
.data('tab-index', index)
.attr({
role: 'tab',
id: self.id('tab', index)
})
.aria({
controls: sections.eq(index).attr('id'),
selected: false,
expanded: false
})
.removeClass('is-active');
});
// Initialize events
this.addEvent('{mode}', 'element', 'onShow', this.ns('nav') + ' a');
if (options.mode !== 'click' && options.preventDefault) {
this.addEvent('click', 'element', function(e) {
e.preventDefault();
}, this.ns('nav') + ' a');
}
this.initialize();
// Trigger default tab to display
var index = null;
if (options.persistState) {
if (options.cookie && $.cookie) {
index = $.cookie('toolkit.tab.' + options.cookie);
}
if (index === null && options.loadFragment && location.hash) {
index = tabs.filter(function() {
return ($(this).attr('href') === location.hash);
}).eq(0).data('tab-index');
}
}
if (!tabs[index]) {
index = options.defaultIndex;
}
this.jump(index);
} | [
"function",
"(",
"element",
",",
"options",
")",
"{",
"var",
"sections",
",",
"tabs",
",",
"self",
"=",
"this",
";",
"element",
"=",
"this",
".",
"setElement",
"(",
"element",
")",
";",
"options",
"=",
"this",
".",
"setOptions",
"(",
"options",
",",
"element",
")",
";",
"// Determine cookie name",
"if",
"(",
"!",
"options",
".",
"cookie",
")",
"{",
"options",
".",
"cookie",
"=",
"element",
".",
"attr",
"(",
"'id'",
")",
";",
"}",
"// Find all the sections and set ARIA attributes",
"this",
".",
"sections",
"=",
"sections",
"=",
"element",
".",
"find",
"(",
"this",
".",
"ns",
"(",
"'section'",
")",
")",
".",
"each",
"(",
"function",
"(",
"index",
",",
"section",
")",
"{",
"section",
"=",
"$",
"(",
"section",
")",
";",
"section",
".",
"attr",
"(",
"'role'",
",",
"'tabpanel'",
")",
".",
"attr",
"(",
"'id'",
",",
"section",
".",
"attr",
"(",
"'id'",
")",
"||",
"self",
".",
"id",
"(",
"'section'",
",",
"index",
")",
")",
".",
"aria",
"(",
"'labelledby'",
",",
"self",
".",
"id",
"(",
"'tab'",
",",
"index",
")",
")",
".",
"conceal",
"(",
")",
";",
"}",
")",
";",
"// Find the nav and set ARIA attributes",
"this",
".",
"nav",
"=",
"element",
".",
"find",
"(",
"this",
".",
"ns",
"(",
"'nav'",
")",
")",
".",
"attr",
"(",
"'role'",
",",
"'tablist'",
")",
";",
"// Find the tabs within the nav and set ARIA attributes",
"this",
".",
"tabs",
"=",
"tabs",
"=",
"this",
".",
"nav",
".",
"find",
"(",
"'a'",
")",
".",
"each",
"(",
"function",
"(",
"index",
")",
"{",
"$",
"(",
"this",
")",
".",
"data",
"(",
"'tab-index'",
",",
"index",
")",
".",
"attr",
"(",
"{",
"role",
":",
"'tab'",
",",
"id",
":",
"self",
".",
"id",
"(",
"'tab'",
",",
"index",
")",
"}",
")",
".",
"aria",
"(",
"{",
"controls",
":",
"sections",
".",
"eq",
"(",
"index",
")",
".",
"attr",
"(",
"'id'",
")",
",",
"selected",
":",
"false",
",",
"expanded",
":",
"false",
"}",
")",
".",
"removeClass",
"(",
"'is-active'",
")",
";",
"}",
")",
";",
"// Initialize events",
"this",
".",
"addEvent",
"(",
"'{mode}'",
",",
"'element'",
",",
"'onShow'",
",",
"this",
".",
"ns",
"(",
"'nav'",
")",
"+",
"' a'",
")",
";",
"if",
"(",
"options",
".",
"mode",
"!==",
"'click'",
"&&",
"options",
".",
"preventDefault",
")",
"{",
"this",
".",
"addEvent",
"(",
"'click'",
",",
"'element'",
",",
"function",
"(",
"e",
")",
"{",
"e",
".",
"preventDefault",
"(",
")",
";",
"}",
",",
"this",
".",
"ns",
"(",
"'nav'",
")",
"+",
"' a'",
")",
";",
"}",
"this",
".",
"initialize",
"(",
")",
";",
"// Trigger default tab to display",
"var",
"index",
"=",
"null",
";",
"if",
"(",
"options",
".",
"persistState",
")",
"{",
"if",
"(",
"options",
".",
"cookie",
"&&",
"$",
".",
"cookie",
")",
"{",
"index",
"=",
"$",
".",
"cookie",
"(",
"'toolkit.tab.'",
"+",
"options",
".",
"cookie",
")",
";",
"}",
"if",
"(",
"index",
"===",
"null",
"&&",
"options",
".",
"loadFragment",
"&&",
"location",
".",
"hash",
")",
"{",
"index",
"=",
"tabs",
".",
"filter",
"(",
"function",
"(",
")",
"{",
"return",
"(",
"$",
"(",
"this",
")",
".",
"attr",
"(",
"'href'",
")",
"===",
"location",
".",
"hash",
")",
";",
"}",
")",
".",
"eq",
"(",
"0",
")",
".",
"data",
"(",
"'tab-index'",
")",
";",
"}",
"}",
"if",
"(",
"!",
"tabs",
"[",
"index",
"]",
")",
"{",
"index",
"=",
"options",
".",
"defaultIndex",
";",
"}",
"this",
".",
"jump",
"(",
"index",
")",
";",
"}"
] | Initialize the tab.
@param {jQuery} element
@param {Object} [options] | [
"Initialize",
"the",
"tab",
"."
] | f0ed36d14cc6d72a7bdbc09da4b5bf7d3d664f0c | https://github.com/titon/toolkit/blob/f0ed36d14cc6d72a7bdbc09da4b5bf7d3d664f0c/dist/toolkit.js#L6221-L6293 | |
21,752 | titon/toolkit | dist/toolkit.js | function(tab) {
tab = $(tab);
var index = tab.data('tab-index'),
section = this.sections.eq(index),
options = this.options,
url = this.readValue(tab, this.readOption(tab, 'getUrl'));
this.fireEvent('showing', [this.index]);
// Load content for AJAX requests
if (url.substr(0, 10) !== 'javascript' && url.substr(0, 1) !== '#') {
this.loadContent(url, { section: section });
}
// Toggle tabs
this.tabs
.aria('toggled', false)
.removeClass('is-active');
// Toggle sections
if (index === this.index && options.collapsible) {
if (section.is(':shown')) {
section.conceal();
} else {
tab.aria('toggled', true).addClass('is-active');
section.reveal();
}
} else {
this.hide();
tab.aria('toggled', true).addClass('is-active');
section.reveal();
}
// Persist the state using a cookie
if (options.persistState && $.cookie) {
$.cookie('toolkit.tab.' + options.cookie, index, {
expires: options.cookieDuration
});
}
this.index = index;
this.node = tab;
this.fireEvent('shown', [index]);
} | javascript | function(tab) {
tab = $(tab);
var index = tab.data('tab-index'),
section = this.sections.eq(index),
options = this.options,
url = this.readValue(tab, this.readOption(tab, 'getUrl'));
this.fireEvent('showing', [this.index]);
// Load content for AJAX requests
if (url.substr(0, 10) !== 'javascript' && url.substr(0, 1) !== '#') {
this.loadContent(url, { section: section });
}
// Toggle tabs
this.tabs
.aria('toggled', false)
.removeClass('is-active');
// Toggle sections
if (index === this.index && options.collapsible) {
if (section.is(':shown')) {
section.conceal();
} else {
tab.aria('toggled', true).addClass('is-active');
section.reveal();
}
} else {
this.hide();
tab.aria('toggled', true).addClass('is-active');
section.reveal();
}
// Persist the state using a cookie
if (options.persistState && $.cookie) {
$.cookie('toolkit.tab.' + options.cookie, index, {
expires: options.cookieDuration
});
}
this.index = index;
this.node = tab;
this.fireEvent('shown', [index]);
} | [
"function",
"(",
"tab",
")",
"{",
"tab",
"=",
"$",
"(",
"tab",
")",
";",
"var",
"index",
"=",
"tab",
".",
"data",
"(",
"'tab-index'",
")",
",",
"section",
"=",
"this",
".",
"sections",
".",
"eq",
"(",
"index",
")",
",",
"options",
"=",
"this",
".",
"options",
",",
"url",
"=",
"this",
".",
"readValue",
"(",
"tab",
",",
"this",
".",
"readOption",
"(",
"tab",
",",
"'getUrl'",
")",
")",
";",
"this",
".",
"fireEvent",
"(",
"'showing'",
",",
"[",
"this",
".",
"index",
"]",
")",
";",
"// Load content for AJAX requests",
"if",
"(",
"url",
".",
"substr",
"(",
"0",
",",
"10",
")",
"!==",
"'javascript'",
"&&",
"url",
".",
"substr",
"(",
"0",
",",
"1",
")",
"!==",
"'#'",
")",
"{",
"this",
".",
"loadContent",
"(",
"url",
",",
"{",
"section",
":",
"section",
"}",
")",
";",
"}",
"// Toggle tabs",
"this",
".",
"tabs",
".",
"aria",
"(",
"'toggled'",
",",
"false",
")",
".",
"removeClass",
"(",
"'is-active'",
")",
";",
"// Toggle sections",
"if",
"(",
"index",
"===",
"this",
".",
"index",
"&&",
"options",
".",
"collapsible",
")",
"{",
"if",
"(",
"section",
".",
"is",
"(",
"':shown'",
")",
")",
"{",
"section",
".",
"conceal",
"(",
")",
";",
"}",
"else",
"{",
"tab",
".",
"aria",
"(",
"'toggled'",
",",
"true",
")",
".",
"addClass",
"(",
"'is-active'",
")",
";",
"section",
".",
"reveal",
"(",
")",
";",
"}",
"}",
"else",
"{",
"this",
".",
"hide",
"(",
")",
";",
"tab",
".",
"aria",
"(",
"'toggled'",
",",
"true",
")",
".",
"addClass",
"(",
"'is-active'",
")",
";",
"section",
".",
"reveal",
"(",
")",
";",
"}",
"// Persist the state using a cookie",
"if",
"(",
"options",
".",
"persistState",
"&&",
"$",
".",
"cookie",
")",
"{",
"$",
".",
"cookie",
"(",
"'toolkit.tab.'",
"+",
"options",
".",
"cookie",
",",
"index",
",",
"{",
"expires",
":",
"options",
".",
"cookieDuration",
"}",
")",
";",
"}",
"this",
".",
"index",
"=",
"index",
";",
"this",
".",
"node",
"=",
"tab",
";",
"this",
".",
"fireEvent",
"(",
"'shown'",
",",
"[",
"index",
"]",
")",
";",
"}"
] | Show the content based on the tab. Can either pass an integer as the index in the collection,
or pass an element object for a tab in the collection.
@param {jQuery} tab | [
"Show",
"the",
"content",
"based",
"on",
"the",
"tab",
".",
"Can",
"either",
"pass",
"an",
"integer",
"as",
"the",
"index",
"in",
"the",
"collection",
"or",
"pass",
"an",
"element",
"object",
"for",
"a",
"tab",
"in",
"the",
"collection",
"."
] | f0ed36d14cc6d72a7bdbc09da4b5bf7d3d664f0c | https://github.com/titon/toolkit/blob/f0ed36d14cc6d72a7bdbc09da4b5bf7d3d664f0c/dist/toolkit.js#L6328-L6375 | |
21,753 | titon/toolkit | dist/toolkit.js | function(e) {
if (this.options.preventDefault || e.currentTarget.getAttribute('href').substr(0, 1) !== '#') {
e.preventDefault();
}
this.show(e.currentTarget);
} | javascript | function(e) {
if (this.options.preventDefault || e.currentTarget.getAttribute('href').substr(0, 1) !== '#') {
e.preventDefault();
}
this.show(e.currentTarget);
} | [
"function",
"(",
"e",
")",
"{",
"if",
"(",
"this",
".",
"options",
".",
"preventDefault",
"||",
"e",
".",
"currentTarget",
".",
"getAttribute",
"(",
"'href'",
")",
".",
"substr",
"(",
"0",
",",
"1",
")",
"!==",
"'#'",
")",
"{",
"e",
".",
"preventDefault",
"(",
")",
";",
"}",
"this",
".",
"show",
"(",
"e",
".",
"currentTarget",
")",
";",
"}"
] | Event callback for tab element click.
@private
@param {jQuery.Event} e | [
"Event",
"callback",
"for",
"tab",
"element",
"click",
"."
] | f0ed36d14cc6d72a7bdbc09da4b5bf7d3d664f0c | https://github.com/titon/toolkit/blob/f0ed36d14cc6d72a7bdbc09da4b5bf7d3d664f0c/dist/toolkit.js#L6420-L6426 | |
21,754 | titon/toolkit | dist/toolkit.js | function(element, options) {
this.nodes = element = $(element); // Set to nodes so instances are unset during destroy()
options = this.setOptions(options, element);
// Create the toasts wrapper
this.createWrapper()
.addClass(options.position)
.attr('role', 'log')
.aria({
relevant: 'additions',
hidden: 'false'
});
this.initialize();
} | javascript | function(element, options) {
this.nodes = element = $(element); // Set to nodes so instances are unset during destroy()
options = this.setOptions(options, element);
// Create the toasts wrapper
this.createWrapper()
.addClass(options.position)
.attr('role', 'log')
.aria({
relevant: 'additions',
hidden: 'false'
});
this.initialize();
} | [
"function",
"(",
"element",
",",
"options",
")",
"{",
"this",
".",
"nodes",
"=",
"element",
"=",
"$",
"(",
"element",
")",
";",
"// Set to nodes so instances are unset during destroy()",
"options",
"=",
"this",
".",
"setOptions",
"(",
"options",
",",
"element",
")",
";",
"// Create the toasts wrapper",
"this",
".",
"createWrapper",
"(",
")",
".",
"addClass",
"(",
"options",
".",
"position",
")",
".",
"attr",
"(",
"'role'",
",",
"'log'",
")",
".",
"aria",
"(",
"{",
"relevant",
":",
"'additions'",
",",
"hidden",
":",
"'false'",
"}",
")",
";",
"this",
".",
"initialize",
"(",
")",
";",
"}"
] | Initialize the toast.
@param {jQuery} element
@param {Object} [options] | [
"Initialize",
"the",
"toast",
"."
] | f0ed36d14cc6d72a7bdbc09da4b5bf7d3d664f0c | https://github.com/titon/toolkit/blob/f0ed36d14cc6d72a7bdbc09da4b5bf7d3d664f0c/dist/toolkit.js#L6454-L6468 | |
21,755 | titon/toolkit | dist/toolkit.js | function(content, options) {
options = $.extend({}, this.options, options || {});
var self = this,
toast = this.render(options.template)
.addClass(options.animation)
.attr('role', 'note')
.html(content)
.conceal()
.prependTo(this.wrapper);
this.fireEvent('create', [toast]);
// Set a timeout to trigger show transition
setTimeout(function() {
self.show(toast);
}, 15); // IE needs a minimum of 15
// Set a timeout to remove the toast
if (options.duration) {
setTimeout(function() {
self.hide(toast);
}, options.duration + 15);
}
} | javascript | function(content, options) {
options = $.extend({}, this.options, options || {});
var self = this,
toast = this.render(options.template)
.addClass(options.animation)
.attr('role', 'note')
.html(content)
.conceal()
.prependTo(this.wrapper);
this.fireEvent('create', [toast]);
// Set a timeout to trigger show transition
setTimeout(function() {
self.show(toast);
}, 15); // IE needs a minimum of 15
// Set a timeout to remove the toast
if (options.duration) {
setTimeout(function() {
self.hide(toast);
}, options.duration + 15);
}
} | [
"function",
"(",
"content",
",",
"options",
")",
"{",
"options",
"=",
"$",
".",
"extend",
"(",
"{",
"}",
",",
"this",
".",
"options",
",",
"options",
"||",
"{",
"}",
")",
";",
"var",
"self",
"=",
"this",
",",
"toast",
"=",
"this",
".",
"render",
"(",
"options",
".",
"template",
")",
".",
"addClass",
"(",
"options",
".",
"animation",
")",
".",
"attr",
"(",
"'role'",
",",
"'note'",
")",
".",
"html",
"(",
"content",
")",
".",
"conceal",
"(",
")",
".",
"prependTo",
"(",
"this",
".",
"wrapper",
")",
";",
"this",
".",
"fireEvent",
"(",
"'create'",
",",
"[",
"toast",
"]",
")",
";",
"// Set a timeout to trigger show transition",
"setTimeout",
"(",
"function",
"(",
")",
"{",
"self",
".",
"show",
"(",
"toast",
")",
";",
"}",
",",
"15",
")",
";",
"// IE needs a minimum of 15",
"// Set a timeout to remove the toast",
"if",
"(",
"options",
".",
"duration",
")",
"{",
"setTimeout",
"(",
"function",
"(",
")",
"{",
"self",
".",
"hide",
"(",
"toast",
")",
";",
"}",
",",
"options",
".",
"duration",
"+",
"15",
")",
";",
"}",
"}"
] | Create a toast element, insert content into it, and append it to the container.
@param {*} content
@param {Object} [options] | [
"Create",
"a",
"toast",
"element",
"insert",
"content",
"into",
"it",
"and",
"append",
"it",
"to",
"the",
"container",
"."
] | f0ed36d14cc6d72a7bdbc09da4b5bf7d3d664f0c | https://github.com/titon/toolkit/blob/f0ed36d14cc6d72a7bdbc09da4b5bf7d3d664f0c/dist/toolkit.js#L6476-L6500 | |
21,756 | titon/toolkit | dist/toolkit.js | function(element) {
element = $(element);
// Pass the element since it gets removed
this.fireEvent('hiding', [element]);
element.transitionend(function() {
element.remove();
this.fireEvent('hidden');
}.bind(this)).conceal();
} | javascript | function(element) {
element = $(element);
// Pass the element since it gets removed
this.fireEvent('hiding', [element]);
element.transitionend(function() {
element.remove();
this.fireEvent('hidden');
}.bind(this)).conceal();
} | [
"function",
"(",
"element",
")",
"{",
"element",
"=",
"$",
"(",
"element",
")",
";",
"// Pass the element since it gets removed",
"this",
".",
"fireEvent",
"(",
"'hiding'",
",",
"[",
"element",
"]",
")",
";",
"element",
".",
"transitionend",
"(",
"function",
"(",
")",
"{",
"element",
".",
"remove",
"(",
")",
";",
"this",
".",
"fireEvent",
"(",
"'hidden'",
")",
";",
"}",
".",
"bind",
"(",
"this",
")",
")",
".",
"conceal",
"(",
")",
";",
"}"
] | Hide the toast after the duration is up.
Also remove the element from the DOM once the transition is complete.
@param {jQuery} element | [
"Hide",
"the",
"toast",
"after",
"the",
"duration",
"is",
"up",
".",
"Also",
"remove",
"the",
"element",
"from",
"the",
"DOM",
"once",
"the",
"transition",
"is",
"complete",
"."
] | f0ed36d14cc6d72a7bdbc09da4b5bf7d3d664f0c | https://github.com/titon/toolkit/blob/f0ed36d14cc6d72a7bdbc09da4b5bf7d3d664f0c/dist/toolkit.js#L6508-L6518 | |
21,757 | titon/toolkit | dist/toolkit.js | function(input, options) {
input = $(input);
if (input.prop('tagName').toLowerCase() !== 'input') {
throw new Error('TypeAhead must be initialized on an input field');
}
var self = this;
options = this.setOptions(options, input);
this.element = this.createElement()
.attr('role', 'listbox')
.aria('multiselectable', false);
// The input field to listen against
this.input = input;
// Use default callbacks
$.each({ sorter: 'sort', matcher: 'match', builder: 'build' }, function(key, fn) {
if (options[key] === false) {
return;
}
var callback;
if (options[key] === null || $.type(options[key]) !== 'function') {
callback = self[fn];
} else {
callback = options[key];
}
options[key] = callback.bind(self);
});
// Prefetch source data from URL
if (options.prefetch && $.type(options.source) === 'string') {
var url = options.source;
$.getJSON(url, options.query, function(items) {
self.cache[url] = items;
});
}
// Enable shadow inputs
if (options.shadow) {
this.wrapper = this.render(this.options.shadowTemplate);
this.shadow = this.input.clone()
.addClass('is-shadow')
.removeAttr('id')
.prop('readonly', true)
.aria('readonly', true);
this.input
.addClass('not-shadow')
.replaceWith(this.wrapper);
this.wrapper
.append(this.shadow)
.append(this.input);
}
// Set ARIA after shadow so that attributes are not inherited
input
.attr({
autocomplete: 'off',
autocapitalize: 'off',
autocorrect: 'off',
spellcheck: 'false',
role: 'combobox'
})
.aria({
autocomplete: 'list',
owns: this.element.attr('id'),
expanded: false
});
// Initialize events
this.addEvents([
['keyup', 'input', 'onLookup'],
['keydown', 'input', 'onCycle'],
['clickout', 'element', 'hide'],
['resize', 'window', $.debounce(this.onHide.bind(this))]
]);
this.initialize();
} | javascript | function(input, options) {
input = $(input);
if (input.prop('tagName').toLowerCase() !== 'input') {
throw new Error('TypeAhead must be initialized on an input field');
}
var self = this;
options = this.setOptions(options, input);
this.element = this.createElement()
.attr('role', 'listbox')
.aria('multiselectable', false);
// The input field to listen against
this.input = input;
// Use default callbacks
$.each({ sorter: 'sort', matcher: 'match', builder: 'build' }, function(key, fn) {
if (options[key] === false) {
return;
}
var callback;
if (options[key] === null || $.type(options[key]) !== 'function') {
callback = self[fn];
} else {
callback = options[key];
}
options[key] = callback.bind(self);
});
// Prefetch source data from URL
if (options.prefetch && $.type(options.source) === 'string') {
var url = options.source;
$.getJSON(url, options.query, function(items) {
self.cache[url] = items;
});
}
// Enable shadow inputs
if (options.shadow) {
this.wrapper = this.render(this.options.shadowTemplate);
this.shadow = this.input.clone()
.addClass('is-shadow')
.removeAttr('id')
.prop('readonly', true)
.aria('readonly', true);
this.input
.addClass('not-shadow')
.replaceWith(this.wrapper);
this.wrapper
.append(this.shadow)
.append(this.input);
}
// Set ARIA after shadow so that attributes are not inherited
input
.attr({
autocomplete: 'off',
autocapitalize: 'off',
autocorrect: 'off',
spellcheck: 'false',
role: 'combobox'
})
.aria({
autocomplete: 'list',
owns: this.element.attr('id'),
expanded: false
});
// Initialize events
this.addEvents([
['keyup', 'input', 'onLookup'],
['keydown', 'input', 'onCycle'],
['clickout', 'element', 'hide'],
['resize', 'window', $.debounce(this.onHide.bind(this))]
]);
this.initialize();
} | [
"function",
"(",
"input",
",",
"options",
")",
"{",
"input",
"=",
"$",
"(",
"input",
")",
";",
"if",
"(",
"input",
".",
"prop",
"(",
"'tagName'",
")",
".",
"toLowerCase",
"(",
")",
"!==",
"'input'",
")",
"{",
"throw",
"new",
"Error",
"(",
"'TypeAhead must be initialized on an input field'",
")",
";",
"}",
"var",
"self",
"=",
"this",
";",
"options",
"=",
"this",
".",
"setOptions",
"(",
"options",
",",
"input",
")",
";",
"this",
".",
"element",
"=",
"this",
".",
"createElement",
"(",
")",
".",
"attr",
"(",
"'role'",
",",
"'listbox'",
")",
".",
"aria",
"(",
"'multiselectable'",
",",
"false",
")",
";",
"// The input field to listen against",
"this",
".",
"input",
"=",
"input",
";",
"// Use default callbacks",
"$",
".",
"each",
"(",
"{",
"sorter",
":",
"'sort'",
",",
"matcher",
":",
"'match'",
",",
"builder",
":",
"'build'",
"}",
",",
"function",
"(",
"key",
",",
"fn",
")",
"{",
"if",
"(",
"options",
"[",
"key",
"]",
"===",
"false",
")",
"{",
"return",
";",
"}",
"var",
"callback",
";",
"if",
"(",
"options",
"[",
"key",
"]",
"===",
"null",
"||",
"$",
".",
"type",
"(",
"options",
"[",
"key",
"]",
")",
"!==",
"'function'",
")",
"{",
"callback",
"=",
"self",
"[",
"fn",
"]",
";",
"}",
"else",
"{",
"callback",
"=",
"options",
"[",
"key",
"]",
";",
"}",
"options",
"[",
"key",
"]",
"=",
"callback",
".",
"bind",
"(",
"self",
")",
";",
"}",
")",
";",
"// Prefetch source data from URL",
"if",
"(",
"options",
".",
"prefetch",
"&&",
"$",
".",
"type",
"(",
"options",
".",
"source",
")",
"===",
"'string'",
")",
"{",
"var",
"url",
"=",
"options",
".",
"source",
";",
"$",
".",
"getJSON",
"(",
"url",
",",
"options",
".",
"query",
",",
"function",
"(",
"items",
")",
"{",
"self",
".",
"cache",
"[",
"url",
"]",
"=",
"items",
";",
"}",
")",
";",
"}",
"// Enable shadow inputs",
"if",
"(",
"options",
".",
"shadow",
")",
"{",
"this",
".",
"wrapper",
"=",
"this",
".",
"render",
"(",
"this",
".",
"options",
".",
"shadowTemplate",
")",
";",
"this",
".",
"shadow",
"=",
"this",
".",
"input",
".",
"clone",
"(",
")",
".",
"addClass",
"(",
"'is-shadow'",
")",
".",
"removeAttr",
"(",
"'id'",
")",
".",
"prop",
"(",
"'readonly'",
",",
"true",
")",
".",
"aria",
"(",
"'readonly'",
",",
"true",
")",
";",
"this",
".",
"input",
".",
"addClass",
"(",
"'not-shadow'",
")",
".",
"replaceWith",
"(",
"this",
".",
"wrapper",
")",
";",
"this",
".",
"wrapper",
".",
"append",
"(",
"this",
".",
"shadow",
")",
".",
"append",
"(",
"this",
".",
"input",
")",
";",
"}",
"// Set ARIA after shadow so that attributes are not inherited",
"input",
".",
"attr",
"(",
"{",
"autocomplete",
":",
"'off'",
",",
"autocapitalize",
":",
"'off'",
",",
"autocorrect",
":",
"'off'",
",",
"spellcheck",
":",
"'false'",
",",
"role",
":",
"'combobox'",
"}",
")",
".",
"aria",
"(",
"{",
"autocomplete",
":",
"'list'",
",",
"owns",
":",
"this",
".",
"element",
".",
"attr",
"(",
"'id'",
")",
",",
"expanded",
":",
"false",
"}",
")",
";",
"// Initialize events",
"this",
".",
"addEvents",
"(",
"[",
"[",
"'keyup'",
",",
"'input'",
",",
"'onLookup'",
"]",
",",
"[",
"'keydown'",
",",
"'input'",
",",
"'onCycle'",
"]",
",",
"[",
"'clickout'",
",",
"'element'",
",",
"'hide'",
"]",
",",
"[",
"'resize'",
",",
"'window'",
",",
"$",
".",
"debounce",
"(",
"this",
".",
"onHide",
".",
"bind",
"(",
"this",
")",
")",
"]",
"]",
")",
";",
"this",
".",
"initialize",
"(",
")",
";",
"}"
] | Initialize the type ahead.
@param {jQuery} input
@param {Object} [options] | [
"Initialize",
"the",
"type",
"ahead",
"."
] | f0ed36d14cc6d72a7bdbc09da4b5bf7d3d664f0c | https://github.com/titon/toolkit/blob/f0ed36d14cc6d72a7bdbc09da4b5bf7d3d664f0c/dist/toolkit.js#L6582-L6668 | |
21,758 | titon/toolkit | dist/toolkit.js | function(item) {
var a = $('<a/>', {
href: 'javascript:;',
role: 'option',
'aria-selected': 'false'
});
a.append( this.render(this.options.titleTemplate).html(this.highlight(item.title)) );
if (item.description) {
a.append( this.render(this.options.descTemplate).html(item.description) );
}
return a;
} | javascript | function(item) {
var a = $('<a/>', {
href: 'javascript:;',
role: 'option',
'aria-selected': 'false'
});
a.append( this.render(this.options.titleTemplate).html(this.highlight(item.title)) );
if (item.description) {
a.append( this.render(this.options.descTemplate).html(item.description) );
}
return a;
} | [
"function",
"(",
"item",
")",
"{",
"var",
"a",
"=",
"$",
"(",
"'<a/>'",
",",
"{",
"href",
":",
"'javascript:;'",
",",
"role",
":",
"'option'",
",",
"'aria-selected'",
":",
"'false'",
"}",
")",
";",
"a",
".",
"append",
"(",
"this",
".",
"render",
"(",
"this",
".",
"options",
".",
"titleTemplate",
")",
".",
"html",
"(",
"this",
".",
"highlight",
"(",
"item",
".",
"title",
")",
")",
")",
";",
"if",
"(",
"item",
".",
"description",
")",
"{",
"a",
".",
"append",
"(",
"this",
".",
"render",
"(",
"this",
".",
"options",
".",
"descTemplate",
")",
".",
"html",
"(",
"item",
".",
"description",
")",
")",
";",
"}",
"return",
"a",
";",
"}"
] | Build the anchor link that will be used in the list.
@param {Object} item
@returns {jQuery} | [
"Build",
"the",
"anchor",
"link",
"that",
"will",
"be",
"used",
"in",
"the",
"list",
"."
] | f0ed36d14cc6d72a7bdbc09da4b5bf7d3d664f0c | https://github.com/titon/toolkit/blob/f0ed36d14cc6d72a7bdbc09da4b5bf7d3d664f0c/dist/toolkit.js#L6686-L6700 | |
21,759 | titon/toolkit | dist/toolkit.js | function() {
this.fireEvent('hiding');
if (this.shadow) {
this.shadow.val('');
}
this.input.aria('expanded', false);
this.element.conceal();
this.fireEvent('hidden');
} | javascript | function() {
this.fireEvent('hiding');
if (this.shadow) {
this.shadow.val('');
}
this.input.aria('expanded', false);
this.element.conceal();
this.fireEvent('hidden');
} | [
"function",
"(",
")",
"{",
"this",
".",
"fireEvent",
"(",
"'hiding'",
")",
";",
"if",
"(",
"this",
".",
"shadow",
")",
"{",
"this",
".",
"shadow",
".",
"val",
"(",
"''",
")",
";",
"}",
"this",
".",
"input",
".",
"aria",
"(",
"'expanded'",
",",
"false",
")",
";",
"this",
".",
"element",
".",
"conceal",
"(",
")",
";",
"this",
".",
"fireEvent",
"(",
"'hidden'",
")",
";",
"}"
] | Hide the list and reset shadow. | [
"Hide",
"the",
"list",
"and",
"reset",
"shadow",
"."
] | f0ed36d14cc6d72a7bdbc09da4b5bf7d3d664f0c | https://github.com/titon/toolkit/blob/f0ed36d14cc6d72a7bdbc09da4b5bf7d3d664f0c/dist/toolkit.js#L6705-L6716 | |
21,760 | titon/toolkit | dist/toolkit.js | function(item) {
var terms = this.term.replace(/[\-\[\]\{\}()*+?.,\\^$|#]/g, '\\$&').split(' '),
options = this.options,
callback = function(match) {
return this.render(options.highlightTemplate).html(match).toString();
}.bind(this);
for (var i = 0, t; t = terms[i]; i++) {
item = item.replace(new RegExp(t, 'ig'), callback);
}
return item;
} | javascript | function(item) {
var terms = this.term.replace(/[\-\[\]\{\}()*+?.,\\^$|#]/g, '\\$&').split(' '),
options = this.options,
callback = function(match) {
return this.render(options.highlightTemplate).html(match).toString();
}.bind(this);
for (var i = 0, t; t = terms[i]; i++) {
item = item.replace(new RegExp(t, 'ig'), callback);
}
return item;
} | [
"function",
"(",
"item",
")",
"{",
"var",
"terms",
"=",
"this",
".",
"term",
".",
"replace",
"(",
"/",
"[\\-\\[\\]\\{\\}()*+?.,\\\\^$|#]",
"/",
"g",
",",
"'\\\\$&'",
")",
".",
"split",
"(",
"' '",
")",
",",
"options",
"=",
"this",
".",
"options",
",",
"callback",
"=",
"function",
"(",
"match",
")",
"{",
"return",
"this",
".",
"render",
"(",
"options",
".",
"highlightTemplate",
")",
".",
"html",
"(",
"match",
")",
".",
"toString",
"(",
")",
";",
"}",
".",
"bind",
"(",
"this",
")",
";",
"for",
"(",
"var",
"i",
"=",
"0",
",",
"t",
";",
"t",
"=",
"terms",
"[",
"i",
"]",
";",
"i",
"++",
")",
"{",
"item",
"=",
"item",
".",
"replace",
"(",
"new",
"RegExp",
"(",
"t",
",",
"'ig'",
")",
",",
"callback",
")",
";",
"}",
"return",
"item",
";",
"}"
] | Highlight the current term within the item string.
Split multi-word terms to highlight separately.
@param {String} item
@returns {String} | [
"Highlight",
"the",
"current",
"term",
"within",
"the",
"item",
"string",
".",
"Split",
"multi",
"-",
"word",
"terms",
"to",
"highlight",
"separately",
"."
] | f0ed36d14cc6d72a7bdbc09da4b5bf7d3d664f0c | https://github.com/titon/toolkit/blob/f0ed36d14cc6d72a7bdbc09da4b5bf7d3d664f0c/dist/toolkit.js#L6725-L6737 | |
21,761 | titon/toolkit | dist/toolkit.js | function() {
if (!this.items.length) {
this.hide();
return;
}
this.fireEvent('showing');
var iPos = this.input.offset();
this.element
.css('top', iPos.top + this.input.outerHeight())
.css(Toolkit.isRTL ? 'right' : 'left', iPos.left)
.reveal();
this.input.aria('expanded', true);
this.fireEvent('shown');
} | javascript | function() {
if (!this.items.length) {
this.hide();
return;
}
this.fireEvent('showing');
var iPos = this.input.offset();
this.element
.css('top', iPos.top + this.input.outerHeight())
.css(Toolkit.isRTL ? 'right' : 'left', iPos.left)
.reveal();
this.input.aria('expanded', true);
this.fireEvent('shown');
} | [
"function",
"(",
")",
"{",
"if",
"(",
"!",
"this",
".",
"items",
".",
"length",
")",
"{",
"this",
".",
"hide",
"(",
")",
";",
"return",
";",
"}",
"this",
".",
"fireEvent",
"(",
"'showing'",
")",
";",
"var",
"iPos",
"=",
"this",
".",
"input",
".",
"offset",
"(",
")",
";",
"this",
".",
"element",
".",
"css",
"(",
"'top'",
",",
"iPos",
".",
"top",
"+",
"this",
".",
"input",
".",
"outerHeight",
"(",
")",
")",
".",
"css",
"(",
"Toolkit",
".",
"isRTL",
"?",
"'right'",
":",
"'left'",
",",
"iPos",
".",
"left",
")",
".",
"reveal",
"(",
")",
";",
"this",
".",
"input",
".",
"aria",
"(",
"'expanded'",
",",
"true",
")",
";",
"this",
".",
"fireEvent",
"(",
"'shown'",
")",
";",
"}"
] | Position the menu below the input. | [
"Position",
"the",
"menu",
"below",
"the",
"input",
"."
] | f0ed36d14cc6d72a7bdbc09da4b5bf7d3d664f0c | https://github.com/titon/toolkit/blob/f0ed36d14cc6d72a7bdbc09da4b5bf7d3d664f0c/dist/toolkit.js#L6764-L6782 | |
21,762 | titon/toolkit | dist/toolkit.js | function(index, event) {
this.index = index;
var rows = this.element.find('li');
rows
.removeClass('is-active')
.find('a')
.aria('selected', false);
// Select
if (index >= 0) {
if (this.items[index]) {
var item = this.items[index];
rows.eq(index)
.addClass('is-active')
.find('a')
.aria('selected', true);
this.input.val(item.title);
this.fireEvent(event || 'select', [item, index]);
}
// Reset
} else {
this.input.val(this.term);
this.fireEvent('reset');
}
} | javascript | function(index, event) {
this.index = index;
var rows = this.element.find('li');
rows
.removeClass('is-active')
.find('a')
.aria('selected', false);
// Select
if (index >= 0) {
if (this.items[index]) {
var item = this.items[index];
rows.eq(index)
.addClass('is-active')
.find('a')
.aria('selected', true);
this.input.val(item.title);
this.fireEvent(event || 'select', [item, index]);
}
// Reset
} else {
this.input.val(this.term);
this.fireEvent('reset');
}
} | [
"function",
"(",
"index",
",",
"event",
")",
"{",
"this",
".",
"index",
"=",
"index",
";",
"var",
"rows",
"=",
"this",
".",
"element",
".",
"find",
"(",
"'li'",
")",
";",
"rows",
".",
"removeClass",
"(",
"'is-active'",
")",
".",
"find",
"(",
"'a'",
")",
".",
"aria",
"(",
"'selected'",
",",
"false",
")",
";",
"// Select",
"if",
"(",
"index",
">=",
"0",
")",
"{",
"if",
"(",
"this",
".",
"items",
"[",
"index",
"]",
")",
"{",
"var",
"item",
"=",
"this",
".",
"items",
"[",
"index",
"]",
";",
"rows",
".",
"eq",
"(",
"index",
")",
".",
"addClass",
"(",
"'is-active'",
")",
".",
"find",
"(",
"'a'",
")",
".",
"aria",
"(",
"'selected'",
",",
"true",
")",
";",
"this",
".",
"input",
".",
"val",
"(",
"item",
".",
"title",
")",
";",
"this",
".",
"fireEvent",
"(",
"event",
"||",
"'select'",
",",
"[",
"item",
",",
"index",
"]",
")",
";",
"}",
"// Reset",
"}",
"else",
"{",
"this",
".",
"input",
".",
"val",
"(",
"this",
".",
"term",
")",
";",
"this",
".",
"fireEvent",
"(",
"'reset'",
")",
";",
"}",
"}"
] | Select an item in the list.
@param {Number} index
@param {String} [event] | [
"Select",
"an",
"item",
"in",
"the",
"list",
"."
] | f0ed36d14cc6d72a7bdbc09da4b5bf7d3d664f0c | https://github.com/titon/toolkit/blob/f0ed36d14cc6d72a7bdbc09da4b5bf7d3d664f0c/dist/toolkit.js#L6798-L6829 | |
21,763 | titon/toolkit | dist/toolkit.js | function(items) {
return items.sort(function(a, b) {
return a.title.localeCompare(b.title);
});
} | javascript | function(items) {
return items.sort(function(a, b) {
return a.title.localeCompare(b.title);
});
} | [
"function",
"(",
"items",
")",
"{",
"return",
"items",
".",
"sort",
"(",
"function",
"(",
"a",
",",
"b",
")",
"{",
"return",
"a",
".",
"title",
".",
"localeCompare",
"(",
"b",
".",
"title",
")",
";",
"}",
")",
";",
"}"
] | Sort the items.
@param {Array} items
@returns {Array} | [
"Sort",
"the",
"items",
"."
] | f0ed36d14cc6d72a7bdbc09da4b5bf7d3d664f0c | https://github.com/titon/toolkit/blob/f0ed36d14cc6d72a7bdbc09da4b5bf7d3d664f0c/dist/toolkit.js#L6837-L6841 | |
21,764 | titon/toolkit | dist/toolkit.js | function(items) {
if (!this.term.length || !items.length) {
this.hide();
return;
}
var options = this.options,
term = this.term,
categories = { _empty_: [] },
item,
list = $('<ul/>');
// Reset
this.items = [];
this.index = -1;
// Sort and match the list of items
if ($.type(options.sorter) === 'function') {
items = options.sorter(items);
}
if ($.type(options.matcher) === 'function') {
items = items.filter(function(item) {
return options.matcher(item, term);
});
}
// Group the items into categories
for (var i = 0; item = items[i]; i++) {
if (item.category) {
if (!categories[item.category]) {
categories[item.category] = [];
}
categories[item.category].push(item);
} else {
categories._empty_.push(item);
}
}
// Loop through the items and build the markup
var results = [],
count = 0;
$.each(categories, function(category, items) {
var elements = [];
if (category !== '_empty_') {
results.push(null);
elements.push(
this.render(options.headingTemplate).append( $('<span/>', { text: category }) )
);
}
for (var i = 0, a; item = items[i]; i++) {
if (count >= options.itemLimit) {
break;
}
a = options.builder(item);
a.on({
mouseover: this.rewind.bind(this),
click: $.proxy(this.onSelect, this, results.length)
});
elements.push( $('<li/>').append(a) );
results.push(item);
count++;
}
list.append(elements);
}.bind(this));
// Append list
this.element.empty().append(list);
// Set the current result set to the items list
// This will be used for index cycling
this.items = results;
// Cache the result set to the term
// Filter out null categories so that we can re-use the cache
this.cache[term.toLowerCase()] = results.filter(function(item) {
return (item !== null);
});
this.fireEvent('load');
// Apply the shadow text
this._shadow();
// Position the list
this.position();
} | javascript | function(items) {
if (!this.term.length || !items.length) {
this.hide();
return;
}
var options = this.options,
term = this.term,
categories = { _empty_: [] },
item,
list = $('<ul/>');
// Reset
this.items = [];
this.index = -1;
// Sort and match the list of items
if ($.type(options.sorter) === 'function') {
items = options.sorter(items);
}
if ($.type(options.matcher) === 'function') {
items = items.filter(function(item) {
return options.matcher(item, term);
});
}
// Group the items into categories
for (var i = 0; item = items[i]; i++) {
if (item.category) {
if (!categories[item.category]) {
categories[item.category] = [];
}
categories[item.category].push(item);
} else {
categories._empty_.push(item);
}
}
// Loop through the items and build the markup
var results = [],
count = 0;
$.each(categories, function(category, items) {
var elements = [];
if (category !== '_empty_') {
results.push(null);
elements.push(
this.render(options.headingTemplate).append( $('<span/>', { text: category }) )
);
}
for (var i = 0, a; item = items[i]; i++) {
if (count >= options.itemLimit) {
break;
}
a = options.builder(item);
a.on({
mouseover: this.rewind.bind(this),
click: $.proxy(this.onSelect, this, results.length)
});
elements.push( $('<li/>').append(a) );
results.push(item);
count++;
}
list.append(elements);
}.bind(this));
// Append list
this.element.empty().append(list);
// Set the current result set to the items list
// This will be used for index cycling
this.items = results;
// Cache the result set to the term
// Filter out null categories so that we can re-use the cache
this.cache[term.toLowerCase()] = results.filter(function(item) {
return (item !== null);
});
this.fireEvent('load');
// Apply the shadow text
this._shadow();
// Position the list
this.position();
} | [
"function",
"(",
"items",
")",
"{",
"if",
"(",
"!",
"this",
".",
"term",
".",
"length",
"||",
"!",
"items",
".",
"length",
")",
"{",
"this",
".",
"hide",
"(",
")",
";",
"return",
";",
"}",
"var",
"options",
"=",
"this",
".",
"options",
",",
"term",
"=",
"this",
".",
"term",
",",
"categories",
"=",
"{",
"_empty_",
":",
"[",
"]",
"}",
",",
"item",
",",
"list",
"=",
"$",
"(",
"'<ul/>'",
")",
";",
"// Reset",
"this",
".",
"items",
"=",
"[",
"]",
";",
"this",
".",
"index",
"=",
"-",
"1",
";",
"// Sort and match the list of items",
"if",
"(",
"$",
".",
"type",
"(",
"options",
".",
"sorter",
")",
"===",
"'function'",
")",
"{",
"items",
"=",
"options",
".",
"sorter",
"(",
"items",
")",
";",
"}",
"if",
"(",
"$",
".",
"type",
"(",
"options",
".",
"matcher",
")",
"===",
"'function'",
")",
"{",
"items",
"=",
"items",
".",
"filter",
"(",
"function",
"(",
"item",
")",
"{",
"return",
"options",
".",
"matcher",
"(",
"item",
",",
"term",
")",
";",
"}",
")",
";",
"}",
"// Group the items into categories",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"item",
"=",
"items",
"[",
"i",
"]",
";",
"i",
"++",
")",
"{",
"if",
"(",
"item",
".",
"category",
")",
"{",
"if",
"(",
"!",
"categories",
"[",
"item",
".",
"category",
"]",
")",
"{",
"categories",
"[",
"item",
".",
"category",
"]",
"=",
"[",
"]",
";",
"}",
"categories",
"[",
"item",
".",
"category",
"]",
".",
"push",
"(",
"item",
")",
";",
"}",
"else",
"{",
"categories",
".",
"_empty_",
".",
"push",
"(",
"item",
")",
";",
"}",
"}",
"// Loop through the items and build the markup",
"var",
"results",
"=",
"[",
"]",
",",
"count",
"=",
"0",
";",
"$",
".",
"each",
"(",
"categories",
",",
"function",
"(",
"category",
",",
"items",
")",
"{",
"var",
"elements",
"=",
"[",
"]",
";",
"if",
"(",
"category",
"!==",
"'_empty_'",
")",
"{",
"results",
".",
"push",
"(",
"null",
")",
";",
"elements",
".",
"push",
"(",
"this",
".",
"render",
"(",
"options",
".",
"headingTemplate",
")",
".",
"append",
"(",
"$",
"(",
"'<span/>'",
",",
"{",
"text",
":",
"category",
"}",
")",
")",
")",
";",
"}",
"for",
"(",
"var",
"i",
"=",
"0",
",",
"a",
";",
"item",
"=",
"items",
"[",
"i",
"]",
";",
"i",
"++",
")",
"{",
"if",
"(",
"count",
">=",
"options",
".",
"itemLimit",
")",
"{",
"break",
";",
"}",
"a",
"=",
"options",
".",
"builder",
"(",
"item",
")",
";",
"a",
".",
"on",
"(",
"{",
"mouseover",
":",
"this",
".",
"rewind",
".",
"bind",
"(",
"this",
")",
",",
"click",
":",
"$",
".",
"proxy",
"(",
"this",
".",
"onSelect",
",",
"this",
",",
"results",
".",
"length",
")",
"}",
")",
";",
"elements",
".",
"push",
"(",
"$",
"(",
"'<li/>'",
")",
".",
"append",
"(",
"a",
")",
")",
";",
"results",
".",
"push",
"(",
"item",
")",
";",
"count",
"++",
";",
"}",
"list",
".",
"append",
"(",
"elements",
")",
";",
"}",
".",
"bind",
"(",
"this",
")",
")",
";",
"// Append list",
"this",
".",
"element",
".",
"empty",
"(",
")",
".",
"append",
"(",
"list",
")",
";",
"// Set the current result set to the items list",
"// This will be used for index cycling",
"this",
".",
"items",
"=",
"results",
";",
"// Cache the result set to the term",
"// Filter out null categories so that we can re-use the cache",
"this",
".",
"cache",
"[",
"term",
".",
"toLowerCase",
"(",
")",
"]",
"=",
"results",
".",
"filter",
"(",
"function",
"(",
"item",
")",
"{",
"return",
"(",
"item",
"!==",
"null",
")",
";",
"}",
")",
";",
"this",
".",
"fireEvent",
"(",
"'load'",
")",
";",
"// Apply the shadow text",
"this",
".",
"_shadow",
"(",
")",
";",
"// Position the list",
"this",
".",
"position",
"(",
")",
";",
"}"
] | Process the list of items be generating new elements and positioning below the input.
@param {Array} items | [
"Process",
"the",
"list",
"of",
"items",
"be",
"generating",
"new",
"elements",
"and",
"positioning",
"below",
"the",
"input",
"."
] | f0ed36d14cc6d72a7bdbc09da4b5bf7d3d664f0c | https://github.com/titon/toolkit/blob/f0ed36d14cc6d72a7bdbc09da4b5bf7d3d664f0c/dist/toolkit.js#L6848-L6942 | |
21,765 | titon/toolkit | dist/toolkit.js | function() {
if (!this.shadow) {
return;
}
var term = this.input.val(),
termLower = term.toLowerCase(),
value = '';
if (this.cache[termLower] && this.cache[termLower][0]) {
var title = this.cache[termLower][0].title;
if (title.toLowerCase().indexOf(termLower) === 0) {
value = term + title.substr(term.length, (title.length - term.length));
}
}
this.shadow.val(value);
} | javascript | function() {
if (!this.shadow) {
return;
}
var term = this.input.val(),
termLower = term.toLowerCase(),
value = '';
if (this.cache[termLower] && this.cache[termLower][0]) {
var title = this.cache[termLower][0].title;
if (title.toLowerCase().indexOf(termLower) === 0) {
value = term + title.substr(term.length, (title.length - term.length));
}
}
this.shadow.val(value);
} | [
"function",
"(",
")",
"{",
"if",
"(",
"!",
"this",
".",
"shadow",
")",
"{",
"return",
";",
"}",
"var",
"term",
"=",
"this",
".",
"input",
".",
"val",
"(",
")",
",",
"termLower",
"=",
"term",
".",
"toLowerCase",
"(",
")",
",",
"value",
"=",
"''",
";",
"if",
"(",
"this",
".",
"cache",
"[",
"termLower",
"]",
"&&",
"this",
".",
"cache",
"[",
"termLower",
"]",
"[",
"0",
"]",
")",
"{",
"var",
"title",
"=",
"this",
".",
"cache",
"[",
"termLower",
"]",
"[",
"0",
"]",
".",
"title",
";",
"if",
"(",
"title",
".",
"toLowerCase",
"(",
")",
".",
"indexOf",
"(",
"termLower",
")",
"===",
"0",
")",
"{",
"value",
"=",
"term",
"+",
"title",
".",
"substr",
"(",
"term",
".",
"length",
",",
"(",
"title",
".",
"length",
"-",
"term",
".",
"length",
")",
")",
";",
"}",
"}",
"this",
".",
"shadow",
".",
"val",
"(",
"value",
")",
";",
"}"
] | Monitor the current input term to determine the shadow text.
Shadow text will reference the term cache.
@private | [
"Monitor",
"the",
"current",
"input",
"term",
"to",
"determine",
"the",
"shadow",
"text",
".",
"Shadow",
"text",
"will",
"reference",
"the",
"term",
"cache",
"."
] | f0ed36d14cc6d72a7bdbc09da4b5bf7d3d664f0c | https://github.com/titon/toolkit/blob/f0ed36d14cc6d72a7bdbc09da4b5bf7d3d664f0c/dist/toolkit.js#L6950-L6968 | |
21,766 | titon/toolkit | dist/toolkit.js | function(e) {
var items = this.items,
length = Math.min(this.options.itemLimit, Math.max(0, items.length)),
event = 'cycle';
if (!length || !this.element.is(':shown')) {
return;
}
switch (e.keyCode) {
// Cycle upwards (up)
case 38:
this.index -= (items[this.index - 1] ? 1 : 2); // category check
if (this.index < 0) {
this.index = length;
}
break;
// Cycle downwards (down)
case 40:
this.index += (items[this.index + 1] ? 1 : 2); // category check
if (this.index >= length) {
this.index = -1;
}
break;
// Select first (tab)
case 9:
e.preventDefault();
var i = 0;
while (!this.items[i]) {
i++;
}
event = 'select';
this.index = i;
this.hide();
break;
// Select current index (enter)
case 13:
e.preventDefault();
event = 'select';
this.hide();
break;
// Reset (esc)
case 27:
this.index = -1;
this.hide();
break;
// Cancel others
default:
return;
}
if (this.shadow) {
this.shadow.val('');
}
// Select the item
this.select(this.index, event);
} | javascript | function(e) {
var items = this.items,
length = Math.min(this.options.itemLimit, Math.max(0, items.length)),
event = 'cycle';
if (!length || !this.element.is(':shown')) {
return;
}
switch (e.keyCode) {
// Cycle upwards (up)
case 38:
this.index -= (items[this.index - 1] ? 1 : 2); // category check
if (this.index < 0) {
this.index = length;
}
break;
// Cycle downwards (down)
case 40:
this.index += (items[this.index + 1] ? 1 : 2); // category check
if (this.index >= length) {
this.index = -1;
}
break;
// Select first (tab)
case 9:
e.preventDefault();
var i = 0;
while (!this.items[i]) {
i++;
}
event = 'select';
this.index = i;
this.hide();
break;
// Select current index (enter)
case 13:
e.preventDefault();
event = 'select';
this.hide();
break;
// Reset (esc)
case 27:
this.index = -1;
this.hide();
break;
// Cancel others
default:
return;
}
if (this.shadow) {
this.shadow.val('');
}
// Select the item
this.select(this.index, event);
} | [
"function",
"(",
"e",
")",
"{",
"var",
"items",
"=",
"this",
".",
"items",
",",
"length",
"=",
"Math",
".",
"min",
"(",
"this",
".",
"options",
".",
"itemLimit",
",",
"Math",
".",
"max",
"(",
"0",
",",
"items",
".",
"length",
")",
")",
",",
"event",
"=",
"'cycle'",
";",
"if",
"(",
"!",
"length",
"||",
"!",
"this",
".",
"element",
".",
"is",
"(",
"':shown'",
")",
")",
"{",
"return",
";",
"}",
"switch",
"(",
"e",
".",
"keyCode",
")",
"{",
"// Cycle upwards (up)",
"case",
"38",
":",
"this",
".",
"index",
"-=",
"(",
"items",
"[",
"this",
".",
"index",
"-",
"1",
"]",
"?",
"1",
":",
"2",
")",
";",
"// category check",
"if",
"(",
"this",
".",
"index",
"<",
"0",
")",
"{",
"this",
".",
"index",
"=",
"length",
";",
"}",
"break",
";",
"// Cycle downwards (down)",
"case",
"40",
":",
"this",
".",
"index",
"+=",
"(",
"items",
"[",
"this",
".",
"index",
"+",
"1",
"]",
"?",
"1",
":",
"2",
")",
";",
"// category check",
"if",
"(",
"this",
".",
"index",
">=",
"length",
")",
"{",
"this",
".",
"index",
"=",
"-",
"1",
";",
"}",
"break",
";",
"// Select first (tab)",
"case",
"9",
":",
"e",
".",
"preventDefault",
"(",
")",
";",
"var",
"i",
"=",
"0",
";",
"while",
"(",
"!",
"this",
".",
"items",
"[",
"i",
"]",
")",
"{",
"i",
"++",
";",
"}",
"event",
"=",
"'select'",
";",
"this",
".",
"index",
"=",
"i",
";",
"this",
".",
"hide",
"(",
")",
";",
"break",
";",
"// Select current index (enter)",
"case",
"13",
":",
"e",
".",
"preventDefault",
"(",
")",
";",
"event",
"=",
"'select'",
";",
"this",
".",
"hide",
"(",
")",
";",
"break",
";",
"// Reset (esc)",
"case",
"27",
":",
"this",
".",
"index",
"=",
"-",
"1",
";",
"this",
".",
"hide",
"(",
")",
";",
"break",
";",
"// Cancel others",
"default",
":",
"return",
";",
"}",
"if",
"(",
"this",
".",
"shadow",
")",
"{",
"this",
".",
"shadow",
".",
"val",
"(",
"''",
")",
";",
"}",
"// Select the item",
"this",
".",
"select",
"(",
"this",
".",
"index",
",",
"event",
")",
";",
"}"
] | Cycle through the items in the list when an arrow key, esc or enter is released.
@private
@param {jQuery.Event} e | [
"Cycle",
"through",
"the",
"items",
"in",
"the",
"list",
"when",
"an",
"arrow",
"key",
"esc",
"or",
"enter",
"is",
"released",
"."
] | f0ed36d14cc6d72a7bdbc09da4b5bf7d3d664f0c | https://github.com/titon/toolkit/blob/f0ed36d14cc6d72a7bdbc09da4b5bf7d3d664f0c/dist/toolkit.js#L6976-L7044 | |
21,767 | titon/toolkit | dist/toolkit.js | function() {
var term = this.term,
options = this.options,
sourceType = $.type(options.source);
// Check the cache first
if (this.cache[term.toLowerCase()]) {
this.source(this.cache[term.toLowerCase()]);
// Use the response of an AJAX request
} else if (sourceType === 'string') {
var url = options.source,
cache = this.cache[url];
if (cache) {
this.source(cache);
} else {
var query = options.query;
query.term = term;
$.getJSON(url, query, this.source.bind(this));
}
// Use a literal array list
} else if (sourceType === 'array') {
this.source(options.source);
// Use the return of a function
} else if (sourceType === 'function') {
var response = options.source.call(this);
if (response) {
this.source(response);
}
} else {
throw new Error('Invalid TypeAhead source type');
}
} | javascript | function() {
var term = this.term,
options = this.options,
sourceType = $.type(options.source);
// Check the cache first
if (this.cache[term.toLowerCase()]) {
this.source(this.cache[term.toLowerCase()]);
// Use the response of an AJAX request
} else if (sourceType === 'string') {
var url = options.source,
cache = this.cache[url];
if (cache) {
this.source(cache);
} else {
var query = options.query;
query.term = term;
$.getJSON(url, query, this.source.bind(this));
}
// Use a literal array list
} else if (sourceType === 'array') {
this.source(options.source);
// Use the return of a function
} else if (sourceType === 'function') {
var response = options.source.call(this);
if (response) {
this.source(response);
}
} else {
throw new Error('Invalid TypeAhead source type');
}
} | [
"function",
"(",
")",
"{",
"var",
"term",
"=",
"this",
".",
"term",
",",
"options",
"=",
"this",
".",
"options",
",",
"sourceType",
"=",
"$",
".",
"type",
"(",
"options",
".",
"source",
")",
";",
"// Check the cache first",
"if",
"(",
"this",
".",
"cache",
"[",
"term",
".",
"toLowerCase",
"(",
")",
"]",
")",
"{",
"this",
".",
"source",
"(",
"this",
".",
"cache",
"[",
"term",
".",
"toLowerCase",
"(",
")",
"]",
")",
";",
"// Use the response of an AJAX request",
"}",
"else",
"if",
"(",
"sourceType",
"===",
"'string'",
")",
"{",
"var",
"url",
"=",
"options",
".",
"source",
",",
"cache",
"=",
"this",
".",
"cache",
"[",
"url",
"]",
";",
"if",
"(",
"cache",
")",
"{",
"this",
".",
"source",
"(",
"cache",
")",
";",
"}",
"else",
"{",
"var",
"query",
"=",
"options",
".",
"query",
";",
"query",
".",
"term",
"=",
"term",
";",
"$",
".",
"getJSON",
"(",
"url",
",",
"query",
",",
"this",
".",
"source",
".",
"bind",
"(",
"this",
")",
")",
";",
"}",
"// Use a literal array list",
"}",
"else",
"if",
"(",
"sourceType",
"===",
"'array'",
")",
"{",
"this",
".",
"source",
"(",
"options",
".",
"source",
")",
";",
"// Use the return of a function",
"}",
"else",
"if",
"(",
"sourceType",
"===",
"'function'",
")",
"{",
"var",
"response",
"=",
"options",
".",
"source",
".",
"call",
"(",
"this",
")",
";",
"if",
"(",
"response",
")",
"{",
"this",
".",
"source",
"(",
"response",
")",
";",
"}",
"}",
"else",
"{",
"throw",
"new",
"Error",
"(",
"'Invalid TypeAhead source type'",
")",
";",
"}",
"}"
] | Event handler called for a lookup. | [
"Event",
"handler",
"called",
"for",
"a",
"lookup",
"."
] | f0ed36d14cc6d72a7bdbc09da4b5bf7d3d664f0c | https://github.com/titon/toolkit/blob/f0ed36d14cc6d72a7bdbc09da4b5bf7d3d664f0c/dist/toolkit.js#L7049-L7086 | |
21,768 | titon/toolkit | dist/toolkit.js | function(e) {
if ($.inArray(e.keyCode, [38, 40, 27, 9, 13]) >= 0) {
return; // Handle with onCycle()
}
clearTimeout(this.timer);
var term = this.input.val().trim();
if (term.length < this.options.minLength) {
this.fireEvent('reset');
this.hide();
} else {
this._shadow();
this.lookup(term);
}
} | javascript | function(e) {
if ($.inArray(e.keyCode, [38, 40, 27, 9, 13]) >= 0) {
return; // Handle with onCycle()
}
clearTimeout(this.timer);
var term = this.input.val().trim();
if (term.length < this.options.minLength) {
this.fireEvent('reset');
this.hide();
} else {
this._shadow();
this.lookup(term);
}
} | [
"function",
"(",
"e",
")",
"{",
"if",
"(",
"$",
".",
"inArray",
"(",
"e",
".",
"keyCode",
",",
"[",
"38",
",",
"40",
",",
"27",
",",
"9",
",",
"13",
"]",
")",
">=",
"0",
")",
"{",
"return",
";",
"// Handle with onCycle()",
"}",
"clearTimeout",
"(",
"this",
".",
"timer",
")",
";",
"var",
"term",
"=",
"this",
".",
"input",
".",
"val",
"(",
")",
".",
"trim",
"(",
")",
";",
"if",
"(",
"term",
".",
"length",
"<",
"this",
".",
"options",
".",
"minLength",
")",
"{",
"this",
".",
"fireEvent",
"(",
"'reset'",
")",
";",
"this",
".",
"hide",
"(",
")",
";",
"}",
"else",
"{",
"this",
".",
"_shadow",
"(",
")",
";",
"this",
".",
"lookup",
"(",
"term",
")",
";",
"}",
"}"
] | Lookup items based on the current input value.
@private
@param {jQuery.Event} e | [
"Lookup",
"items",
"based",
"on",
"the",
"current",
"input",
"value",
"."
] | f0ed36d14cc6d72a7bdbc09da4b5bf7d3d664f0c | https://github.com/titon/toolkit/blob/f0ed36d14cc6d72a7bdbc09da4b5bf7d3d664f0c/dist/toolkit.js#L7094-L7111 | |
21,769 | w8r/avl | src/utils.js | height | function height(node) {
return node ? (1 + Math.max(height(node.left), height(node.right))) : 0;
} | javascript | function height(node) {
return node ? (1 + Math.max(height(node.left), height(node.right))) : 0;
} | [
"function",
"height",
"(",
"node",
")",
"{",
"return",
"node",
"?",
"(",
"1",
"+",
"Math",
".",
"max",
"(",
"height",
"(",
"node",
".",
"left",
")",
",",
"height",
"(",
"node",
".",
"right",
")",
")",
")",
":",
"0",
";",
"}"
] | The function Compute the 'height' of a tree.
Height is the number of nodes along the longest path
from the root node down to the farthest leaf node.
@param {Node} node
@return {Number} | [
"The",
"function",
"Compute",
"the",
"height",
"of",
"a",
"tree",
".",
"Height",
"is",
"the",
"number",
"of",
"nodes",
"along",
"the",
"longest",
"path",
"from",
"the",
"root",
"node",
"down",
"to",
"the",
"farthest",
"leaf",
"node",
"."
] | 601107b38287449aeb01bb7e6da712ac3d0f0c2f | https://github.com/w8r/avl/blob/601107b38287449aeb01bb7e6da712ac3d0f0c2f/src/utils.js#L60-L62 |
21,770 | w8r/avl | src/index.js | rotateLeft | function rotateLeft (node) {
var rightNode = node.right;
node.right = rightNode.left;
if (rightNode.left) rightNode.left.parent = node;
rightNode.parent = node.parent;
if (rightNode.parent) {
if (rightNode.parent.left === node) {
rightNode.parent.left = rightNode;
} else {
rightNode.parent.right = rightNode;
}
}
node.parent = rightNode;
rightNode.left = node;
node.balanceFactor += 1;
if (rightNode.balanceFactor < 0) {
node.balanceFactor -= rightNode.balanceFactor;
}
rightNode.balanceFactor += 1;
if (node.balanceFactor > 0) {
rightNode.balanceFactor += node.balanceFactor;
}
return rightNode;
} | javascript | function rotateLeft (node) {
var rightNode = node.right;
node.right = rightNode.left;
if (rightNode.left) rightNode.left.parent = node;
rightNode.parent = node.parent;
if (rightNode.parent) {
if (rightNode.parent.left === node) {
rightNode.parent.left = rightNode;
} else {
rightNode.parent.right = rightNode;
}
}
node.parent = rightNode;
rightNode.left = node;
node.balanceFactor += 1;
if (rightNode.balanceFactor < 0) {
node.balanceFactor -= rightNode.balanceFactor;
}
rightNode.balanceFactor += 1;
if (node.balanceFactor > 0) {
rightNode.balanceFactor += node.balanceFactor;
}
return rightNode;
} | [
"function",
"rotateLeft",
"(",
"node",
")",
"{",
"var",
"rightNode",
"=",
"node",
".",
"right",
";",
"node",
".",
"right",
"=",
"rightNode",
".",
"left",
";",
"if",
"(",
"rightNode",
".",
"left",
")",
"rightNode",
".",
"left",
".",
"parent",
"=",
"node",
";",
"rightNode",
".",
"parent",
"=",
"node",
".",
"parent",
";",
"if",
"(",
"rightNode",
".",
"parent",
")",
"{",
"if",
"(",
"rightNode",
".",
"parent",
".",
"left",
"===",
"node",
")",
"{",
"rightNode",
".",
"parent",
".",
"left",
"=",
"rightNode",
";",
"}",
"else",
"{",
"rightNode",
".",
"parent",
".",
"right",
"=",
"rightNode",
";",
"}",
"}",
"node",
".",
"parent",
"=",
"rightNode",
";",
"rightNode",
".",
"left",
"=",
"node",
";",
"node",
".",
"balanceFactor",
"+=",
"1",
";",
"if",
"(",
"rightNode",
".",
"balanceFactor",
"<",
"0",
")",
"{",
"node",
".",
"balanceFactor",
"-=",
"rightNode",
".",
"balanceFactor",
";",
"}",
"rightNode",
".",
"balanceFactor",
"+=",
"1",
";",
"if",
"(",
"node",
".",
"balanceFactor",
">",
"0",
")",
"{",
"rightNode",
".",
"balanceFactor",
"+=",
"node",
".",
"balanceFactor",
";",
"}",
"return",
"rightNode",
";",
"}"
] | Single left rotation
@param {Node} node
@return {Node} | [
"Single",
"left",
"rotation"
] | 601107b38287449aeb01bb7e6da712ac3d0f0c2f | https://github.com/w8r/avl/blob/601107b38287449aeb01bb7e6da712ac3d0f0c2f/src/index.js#L41-L69 |
21,771 | Orbs/jspm-git | git.js | function(repo, version, hash, meta, outDir) {
var url, tempRepoDir, packageJSONData, self = this;
if (meta.vPrefix) {
version = 'v' + version;
}
// Automatically track and cleanup files at exit
temp.track();
url = createGitUrl(self.options.baseurl, repo, self.options.reposuffix, self.auth);
return createTempDir().then(function(tempDir) {
tempRepoDir = tempDir;
return exportGitRepo(tempRepoDir, version, url, self.execOpt, self.options.shallowclone);
}).then(function() {
return readPackageJSON(tempRepoDir);
}).then(function(data) {
packageJSONData = data;
return moveRepoToOutDir(tempRepoDir, outDir);
}).then(function() {
return packageJSONData;
});
} | javascript | function(repo, version, hash, meta, outDir) {
var url, tempRepoDir, packageJSONData, self = this;
if (meta.vPrefix) {
version = 'v' + version;
}
// Automatically track and cleanup files at exit
temp.track();
url = createGitUrl(self.options.baseurl, repo, self.options.reposuffix, self.auth);
return createTempDir().then(function(tempDir) {
tempRepoDir = tempDir;
return exportGitRepo(tempRepoDir, version, url, self.execOpt, self.options.shallowclone);
}).then(function() {
return readPackageJSON(tempRepoDir);
}).then(function(data) {
packageJSONData = data;
return moveRepoToOutDir(tempRepoDir, outDir);
}).then(function() {
return packageJSONData;
});
} | [
"function",
"(",
"repo",
",",
"version",
",",
"hash",
",",
"meta",
",",
"outDir",
")",
"{",
"var",
"url",
",",
"tempRepoDir",
",",
"packageJSONData",
",",
"self",
"=",
"this",
";",
"if",
"(",
"meta",
".",
"vPrefix",
")",
"{",
"version",
"=",
"'v'",
"+",
"version",
";",
"}",
"// Automatically track and cleanup files at exit",
"temp",
".",
"track",
"(",
")",
";",
"url",
"=",
"createGitUrl",
"(",
"self",
".",
"options",
".",
"baseurl",
",",
"repo",
",",
"self",
".",
"options",
".",
"reposuffix",
",",
"self",
".",
"auth",
")",
";",
"return",
"createTempDir",
"(",
")",
".",
"then",
"(",
"function",
"(",
"tempDir",
")",
"{",
"tempRepoDir",
"=",
"tempDir",
";",
"return",
"exportGitRepo",
"(",
"tempRepoDir",
",",
"version",
",",
"url",
",",
"self",
".",
"execOpt",
",",
"self",
".",
"options",
".",
"shallowclone",
")",
";",
"}",
")",
".",
"then",
"(",
"function",
"(",
")",
"{",
"return",
"readPackageJSON",
"(",
"tempRepoDir",
")",
";",
"}",
")",
".",
"then",
"(",
"function",
"(",
"data",
")",
"{",
"packageJSONData",
"=",
"data",
";",
"return",
"moveRepoToOutDir",
"(",
"tempRepoDir",
",",
"outDir",
")",
";",
"}",
")",
".",
"then",
"(",
"function",
"(",
")",
"{",
"return",
"packageJSONData",
";",
"}",
")",
";",
"}"
] | always an exact version assumed that this is run after getVersions so the repo exists | [
"always",
"an",
"exact",
"version",
"assumed",
"that",
"this",
"is",
"run",
"after",
"getVersions",
"so",
"the",
"repo",
"exists"
] | 92c8c81835af17970f989dd9083ed2105c24ed69 | https://github.com/Orbs/jspm-git/blob/92c8c81835af17970f989dd9083ed2105c24ed69/git.js#L450-L474 | |
21,772 | Orbs/jspm-git | git.js | function(pjson, dir) {
var main = pjson.main || '';
var libDir = pjson.directories && (pjson.directories.dist || pjson.directories.lib) || '.';
// convert to windows-style paths if necessary
main = path.normalize(main);
libDir = path.normalize(libDir);
if (main.indexOf('!') !== -1) {
return;
}
function checkMain(main, libDir) {
if (!main) {
return Promise.resolve(false);
}
if (main.substr(main.length - 3, 3) === '.js') {
main = main.substr(0, main.length - 3);
}
return new Promise(function(resolve) {
fs.exists(path.resolve(dir, libDir || '.', main) + '.js', function(exists) {
resolve(exists);
});
});
}
return checkMain(main, libDir)
.then(function(hasMain) {
if (hasMain) {
return;
}
return asp(fs.readFile)(path.resolve(dir, 'bower.json'))
.then(function(bowerJson) {
try {
bowerJson = JSON.parse(bowerJson);
} catch(e) {
return;
}
main = bowerJson.main || '';
if (main instanceof Array) {
main = main[0];
}
return checkMain(main);
}, function() {})
.then(function(hasBowerMain) {
if (!hasBowerMain) {
return;
}
pjson.main = main;
});
});
} | javascript | function(pjson, dir) {
var main = pjson.main || '';
var libDir = pjson.directories && (pjson.directories.dist || pjson.directories.lib) || '.';
// convert to windows-style paths if necessary
main = path.normalize(main);
libDir = path.normalize(libDir);
if (main.indexOf('!') !== -1) {
return;
}
function checkMain(main, libDir) {
if (!main) {
return Promise.resolve(false);
}
if (main.substr(main.length - 3, 3) === '.js') {
main = main.substr(0, main.length - 3);
}
return new Promise(function(resolve) {
fs.exists(path.resolve(dir, libDir || '.', main) + '.js', function(exists) {
resolve(exists);
});
});
}
return checkMain(main, libDir)
.then(function(hasMain) {
if (hasMain) {
return;
}
return asp(fs.readFile)(path.resolve(dir, 'bower.json'))
.then(function(bowerJson) {
try {
bowerJson = JSON.parse(bowerJson);
} catch(e) {
return;
}
main = bowerJson.main || '';
if (main instanceof Array) {
main = main[0];
}
return checkMain(main);
}, function() {})
.then(function(hasBowerMain) {
if (!hasBowerMain) {
return;
}
pjson.main = main;
});
});
} | [
"function",
"(",
"pjson",
",",
"dir",
")",
"{",
"var",
"main",
"=",
"pjson",
".",
"main",
"||",
"''",
";",
"var",
"libDir",
"=",
"pjson",
".",
"directories",
"&&",
"(",
"pjson",
".",
"directories",
".",
"dist",
"||",
"pjson",
".",
"directories",
".",
"lib",
")",
"||",
"'.'",
";",
"// convert to windows-style paths if necessary",
"main",
"=",
"path",
".",
"normalize",
"(",
"main",
")",
";",
"libDir",
"=",
"path",
".",
"normalize",
"(",
"libDir",
")",
";",
"if",
"(",
"main",
".",
"indexOf",
"(",
"'!'",
")",
"!==",
"-",
"1",
")",
"{",
"return",
";",
"}",
"function",
"checkMain",
"(",
"main",
",",
"libDir",
")",
"{",
"if",
"(",
"!",
"main",
")",
"{",
"return",
"Promise",
".",
"resolve",
"(",
"false",
")",
";",
"}",
"if",
"(",
"main",
".",
"substr",
"(",
"main",
".",
"length",
"-",
"3",
",",
"3",
")",
"===",
"'.js'",
")",
"{",
"main",
"=",
"main",
".",
"substr",
"(",
"0",
",",
"main",
".",
"length",
"-",
"3",
")",
";",
"}",
"return",
"new",
"Promise",
"(",
"function",
"(",
"resolve",
")",
"{",
"fs",
".",
"exists",
"(",
"path",
".",
"resolve",
"(",
"dir",
",",
"libDir",
"||",
"'.'",
",",
"main",
")",
"+",
"'.js'",
",",
"function",
"(",
"exists",
")",
"{",
"resolve",
"(",
"exists",
")",
";",
"}",
")",
";",
"}",
")",
";",
"}",
"return",
"checkMain",
"(",
"main",
",",
"libDir",
")",
".",
"then",
"(",
"function",
"(",
"hasMain",
")",
"{",
"if",
"(",
"hasMain",
")",
"{",
"return",
";",
"}",
"return",
"asp",
"(",
"fs",
".",
"readFile",
")",
"(",
"path",
".",
"resolve",
"(",
"dir",
",",
"'bower.json'",
")",
")",
".",
"then",
"(",
"function",
"(",
"bowerJson",
")",
"{",
"try",
"{",
"bowerJson",
"=",
"JSON",
".",
"parse",
"(",
"bowerJson",
")",
";",
"}",
"catch",
"(",
"e",
")",
"{",
"return",
";",
"}",
"main",
"=",
"bowerJson",
".",
"main",
"||",
"''",
";",
"if",
"(",
"main",
"instanceof",
"Array",
")",
"{",
"main",
"=",
"main",
"[",
"0",
"]",
";",
"}",
"return",
"checkMain",
"(",
"main",
")",
";",
"}",
",",
"function",
"(",
")",
"{",
"}",
")",
".",
"then",
"(",
"function",
"(",
"hasBowerMain",
")",
"{",
"if",
"(",
"!",
"hasBowerMain",
")",
"{",
"return",
";",
"}",
"pjson",
".",
"main",
"=",
"main",
";",
"}",
")",
";",
"}",
")",
";",
"}"
] | check if the main entry point exists. If not, try the bower.json main. | [
"check",
"if",
"the",
"main",
"entry",
"point",
"exists",
".",
"If",
"not",
"try",
"the",
"bower",
".",
"json",
"main",
"."
] | 92c8c81835af17970f989dd9083ed2105c24ed69 | https://github.com/Orbs/jspm-git/blob/92c8c81835af17970f989dd9083ed2105c24ed69/git.js#L477-L534 | |
21,773 | opentok/accelerator-screen-sharing-js | src/opentok-screen-sharing.js | function () {
var createPublisher = function (publisherDiv) {
var innerDeferred = $.Deferred();
var getContainer = function () {
if (publisherDiv) { return publisherDiv; }
if (typeof _this.screenSharingContainer === 'function') {
return document.querySelector(_this.screenSharingContainer('publisher', 'screen'));
} else {
return _this.screenSharingContainer;
}
}
var container = getContainer();
var properties =
_this.localScreenProperties ||
_this.localScreenProperties ||
_defaultScreenProperties;
_this.publisher = OT.initPublisher(container, properties, function (error) {
if (error) {
_triggerEvent('screenSharingError', error);
innerDeferred.reject(_.extend(_.omit(error, 'messsage'), {
message: 'Error starting the screen sharing',
}));
} else {
_this.publisher.on('mediaStopped', function () {
end();
});
innerDeferred.resolve();
}
});
return innerDeferred.promise();
};
var outerDeferred = $.Deferred();
if (_this.annotation && _this.externalWindow) {
_log(_logEventData.enableAnnotations, _logEventData.variationSuccess);
_accPack.setupExternalAnnotation()
.then(function (annotationWindow) {
_this.annotationWindow = annotationWindow || null;
var annotationElements = annotationWindow.createContainerElements();
createPublisher(annotationElements.publisher)
.then(function () {
outerDeferred.resolve(annotationElements.annotation);
});
});
} else {
createPublisher()
.then(function () {
outerDeferred.resolve();
});
}
return outerDeferred.promise();
} | javascript | function () {
var createPublisher = function (publisherDiv) {
var innerDeferred = $.Deferred();
var getContainer = function () {
if (publisherDiv) { return publisherDiv; }
if (typeof _this.screenSharingContainer === 'function') {
return document.querySelector(_this.screenSharingContainer('publisher', 'screen'));
} else {
return _this.screenSharingContainer;
}
}
var container = getContainer();
var properties =
_this.localScreenProperties ||
_this.localScreenProperties ||
_defaultScreenProperties;
_this.publisher = OT.initPublisher(container, properties, function (error) {
if (error) {
_triggerEvent('screenSharingError', error);
innerDeferred.reject(_.extend(_.omit(error, 'messsage'), {
message: 'Error starting the screen sharing',
}));
} else {
_this.publisher.on('mediaStopped', function () {
end();
});
innerDeferred.resolve();
}
});
return innerDeferred.promise();
};
var outerDeferred = $.Deferred();
if (_this.annotation && _this.externalWindow) {
_log(_logEventData.enableAnnotations, _logEventData.variationSuccess);
_accPack.setupExternalAnnotation()
.then(function (annotationWindow) {
_this.annotationWindow = annotationWindow || null;
var annotationElements = annotationWindow.createContainerElements();
createPublisher(annotationElements.publisher)
.then(function () {
outerDeferred.resolve(annotationElements.annotation);
});
});
} else {
createPublisher()
.then(function () {
outerDeferred.resolve();
});
}
return outerDeferred.promise();
} | [
"function",
"(",
")",
"{",
"var",
"createPublisher",
"=",
"function",
"(",
"publisherDiv",
")",
"{",
"var",
"innerDeferred",
"=",
"$",
".",
"Deferred",
"(",
")",
";",
"var",
"getContainer",
"=",
"function",
"(",
")",
"{",
"if",
"(",
"publisherDiv",
")",
"{",
"return",
"publisherDiv",
";",
"}",
"if",
"(",
"typeof",
"_this",
".",
"screenSharingContainer",
"===",
"'function'",
")",
"{",
"return",
"document",
".",
"querySelector",
"(",
"_this",
".",
"screenSharingContainer",
"(",
"'publisher'",
",",
"'screen'",
")",
")",
";",
"}",
"else",
"{",
"return",
"_this",
".",
"screenSharingContainer",
";",
"}",
"}",
"var",
"container",
"=",
"getContainer",
"(",
")",
";",
"var",
"properties",
"=",
"_this",
".",
"localScreenProperties",
"||",
"_this",
".",
"localScreenProperties",
"||",
"_defaultScreenProperties",
";",
"_this",
".",
"publisher",
"=",
"OT",
".",
"initPublisher",
"(",
"container",
",",
"properties",
",",
"function",
"(",
"error",
")",
"{",
"if",
"(",
"error",
")",
"{",
"_triggerEvent",
"(",
"'screenSharingError'",
",",
"error",
")",
";",
"innerDeferred",
".",
"reject",
"(",
"_",
".",
"extend",
"(",
"_",
".",
"omit",
"(",
"error",
",",
"'messsage'",
")",
",",
"{",
"message",
":",
"'Error starting the screen sharing'",
",",
"}",
")",
")",
";",
"}",
"else",
"{",
"_this",
".",
"publisher",
".",
"on",
"(",
"'mediaStopped'",
",",
"function",
"(",
")",
"{",
"end",
"(",
")",
";",
"}",
")",
";",
"innerDeferred",
".",
"resolve",
"(",
")",
";",
"}",
"}",
")",
";",
"return",
"innerDeferred",
".",
"promise",
"(",
")",
";",
"}",
";",
"var",
"outerDeferred",
"=",
"$",
".",
"Deferred",
"(",
")",
";",
"if",
"(",
"_this",
".",
"annotation",
"&&",
"_this",
".",
"externalWindow",
")",
"{",
"_log",
"(",
"_logEventData",
".",
"enableAnnotations",
",",
"_logEventData",
".",
"variationSuccess",
")",
";",
"_accPack",
".",
"setupExternalAnnotation",
"(",
")",
".",
"then",
"(",
"function",
"(",
"annotationWindow",
")",
"{",
"_this",
".",
"annotationWindow",
"=",
"annotationWindow",
"||",
"null",
";",
"var",
"annotationElements",
"=",
"annotationWindow",
".",
"createContainerElements",
"(",
")",
";",
"createPublisher",
"(",
"annotationElements",
".",
"publisher",
")",
".",
"then",
"(",
"function",
"(",
")",
"{",
"outerDeferred",
".",
"resolve",
"(",
"annotationElements",
".",
"annotation",
")",
";",
"}",
")",
";",
"}",
")",
";",
"}",
"else",
"{",
"createPublisher",
"(",
")",
".",
"then",
"(",
"function",
"(",
")",
"{",
"outerDeferred",
".",
"resolve",
"(",
")",
";",
"}",
")",
";",
"}",
"return",
"outerDeferred",
".",
"promise",
"(",
")",
";",
"}"
] | Create a publisher for the screen. If we're using annotation, we first need
to create the annotion window and get a reference to its annotation container
element so that we can pass it to the initPublisher function.
@returns {promise} < Resolve: [Object] Container element for annotation in external window > | [
"Create",
"a",
"publisher",
"for",
"the",
"screen",
".",
"If",
"we",
"re",
"using",
"annotation",
"we",
"first",
"need",
"to",
"create",
"the",
"annotion",
"window",
"and",
"get",
"a",
"reference",
"to",
"its",
"annotation",
"container",
"element",
"so",
"that",
"we",
"can",
"pass",
"it",
"to",
"the",
"initPublisher",
"function",
"."
] | cfa1b55525ed193ea1dd5caa4ba5c0eb4a902bf7 | https://github.com/opentok/accelerator-screen-sharing-js/blob/cfa1b55525ed193ea1dd5caa4ba5c0eb4a902bf7/src/opentok-screen-sharing.js#L160-L223 | |
21,774 | opentok/accelerator-screen-sharing-js | src/opentok-screen-sharing.js | function (annotationContainer) {
_session.publish(_this.publisher, function (error) {
if (error) {
// Let's write our own error message
var customError = _.omit(error, 'message');
if (error.code === 1500 && navigator.userAgent.indexOf('Firefox') !== -1) {
$('#dialog-form-ff').toggle();
} else {
var errorMessage;
if (error.code === 1010) {
errorMessage = 'Check your network connection';
} else {
errorMessage = 'Error sharing the screen';
}
customError.message = errorMessage;
_triggerEvent('screenSharingError', customError);
_log(_logEventData.actionStart, _logEventData.variationError);
}
} else {
if (_this.annotation && _this.externalWindow) {
_accPack.linkAnnotation(_this.publisher, annotationContainer, _this.annotationWindow);
_log(_logEventData.actionInitialize, _logEventData.variationSuccess);
}
_active = true;
_triggerEvent('startScreenSharing', _this.publisher);
_log(_logEventData.actionStart, _logEventData.variationSuccess);
}
});
} | javascript | function (annotationContainer) {
_session.publish(_this.publisher, function (error) {
if (error) {
// Let's write our own error message
var customError = _.omit(error, 'message');
if (error.code === 1500 && navigator.userAgent.indexOf('Firefox') !== -1) {
$('#dialog-form-ff').toggle();
} else {
var errorMessage;
if (error.code === 1010) {
errorMessage = 'Check your network connection';
} else {
errorMessage = 'Error sharing the screen';
}
customError.message = errorMessage;
_triggerEvent('screenSharingError', customError);
_log(_logEventData.actionStart, _logEventData.variationError);
}
} else {
if (_this.annotation && _this.externalWindow) {
_accPack.linkAnnotation(_this.publisher, annotationContainer, _this.annotationWindow);
_log(_logEventData.actionInitialize, _logEventData.variationSuccess);
}
_active = true;
_triggerEvent('startScreenSharing', _this.publisher);
_log(_logEventData.actionStart, _logEventData.variationSuccess);
}
});
} | [
"function",
"(",
"annotationContainer",
")",
"{",
"_session",
".",
"publish",
"(",
"_this",
".",
"publisher",
",",
"function",
"(",
"error",
")",
"{",
"if",
"(",
"error",
")",
"{",
"// Let's write our own error message",
"var",
"customError",
"=",
"_",
".",
"omit",
"(",
"error",
",",
"'message'",
")",
";",
"if",
"(",
"error",
".",
"code",
"===",
"1500",
"&&",
"navigator",
".",
"userAgent",
".",
"indexOf",
"(",
"'Firefox'",
")",
"!==",
"-",
"1",
")",
"{",
"$",
"(",
"'#dialog-form-ff'",
")",
".",
"toggle",
"(",
")",
";",
"}",
"else",
"{",
"var",
"errorMessage",
";",
"if",
"(",
"error",
".",
"code",
"===",
"1010",
")",
"{",
"errorMessage",
"=",
"'Check your network connection'",
";",
"}",
"else",
"{",
"errorMessage",
"=",
"'Error sharing the screen'",
";",
"}",
"customError",
".",
"message",
"=",
"errorMessage",
";",
"_triggerEvent",
"(",
"'screenSharingError'",
",",
"customError",
")",
";",
"_log",
"(",
"_logEventData",
".",
"actionStart",
",",
"_logEventData",
".",
"variationError",
")",
";",
"}",
"}",
"else",
"{",
"if",
"(",
"_this",
".",
"annotation",
"&&",
"_this",
".",
"externalWindow",
")",
"{",
"_accPack",
".",
"linkAnnotation",
"(",
"_this",
".",
"publisher",
",",
"annotationContainer",
",",
"_this",
".",
"annotationWindow",
")",
";",
"_log",
"(",
"_logEventData",
".",
"actionInitialize",
",",
"_logEventData",
".",
"variationSuccess",
")",
";",
"}",
"_active",
"=",
"true",
";",
"_triggerEvent",
"(",
"'startScreenSharing'",
",",
"_this",
".",
"publisher",
")",
";",
"_log",
"(",
"_logEventData",
".",
"actionStart",
",",
"_logEventData",
".",
"variationSuccess",
")",
";",
"}",
"}",
")",
";",
"}"
] | Start publishing the screen
@param annotationContainer | [
"Start",
"publishing",
"the",
"screen"
] | cfa1b55525ed193ea1dd5caa4ba5c0eb4a902bf7 | https://github.com/opentok/accelerator-screen-sharing-js/blob/cfa1b55525ed193ea1dd5caa4ba5c0eb4a902bf7/src/opentok-screen-sharing.js#L230-L265 | |
21,775 | rain1017/quick-pomelo | template/app.js | function(){
if(Object.keys(app.getServers()).length === 0){
quick.logger.shutdown(shutdown);
}
else{
setTimeout(tryShutdown, 200);
}
} | javascript | function(){
if(Object.keys(app.getServers()).length === 0){
quick.logger.shutdown(shutdown);
}
else{
setTimeout(tryShutdown, 200);
}
} | [
"function",
"(",
")",
"{",
"if",
"(",
"Object",
".",
"keys",
"(",
"app",
".",
"getServers",
"(",
")",
")",
".",
"length",
"===",
"0",
")",
"{",
"quick",
".",
"logger",
".",
"shutdown",
"(",
"shutdown",
")",
";",
"}",
"else",
"{",
"setTimeout",
"(",
"tryShutdown",
",",
"200",
")",
";",
"}",
"}"
] | Wait for all server stop | [
"Wait",
"for",
"all",
"server",
"stop"
] | 3d2c83d81ab190e99a3ab8f64385aa29f44c5383 | https://github.com/rain1017/quick-pomelo/blob/3d2c83d81ab190e99a3ab8f64385aa29f44c5383/template/app.js#L82-L89 | |
21,776 | MariusRumpf/node-lifx | lib/lifx/light.js | Light | function Light(constr) {
this.client = constr.client;
this.id = constr.id; // Used to target the light
this.address = constr.address;
this.port = constr.port;
this.label = null;
this.status = 'on';
this.seenOnDiscovery = constr.seenOnDiscovery;
} | javascript | function Light(constr) {
this.client = constr.client;
this.id = constr.id; // Used to target the light
this.address = constr.address;
this.port = constr.port;
this.label = null;
this.status = 'on';
this.seenOnDiscovery = constr.seenOnDiscovery;
} | [
"function",
"Light",
"(",
"constr",
")",
"{",
"this",
".",
"client",
"=",
"constr",
".",
"client",
";",
"this",
".",
"id",
"=",
"constr",
".",
"id",
";",
"// Used to target the light",
"this",
".",
"address",
"=",
"constr",
".",
"address",
";",
"this",
".",
"port",
"=",
"constr",
".",
"port",
";",
"this",
".",
"label",
"=",
"null",
";",
"this",
".",
"status",
"=",
"'on'",
";",
"this",
".",
"seenOnDiscovery",
"=",
"constr",
".",
"seenOnDiscovery",
";",
"}"
] | A representation of a light bulb
@class
@param {Obj} constr constructor object
@param {Lifx/Client} constr.client the client the light belongs to
@param {String} constr.id the id used to target the light
@param {String} constr.address ip address of the light
@param {Number} constr.port port of the light
@param {Number} constr.seenOnDiscovery on which discovery the light was last seen | [
"A",
"representation",
"of",
"a",
"light",
"bulb"
] | c5bb37309895f7e8aa86eda69c4ed8a72f6fedf1 | https://github.com/MariusRumpf/node-lifx/blob/c5bb37309895f7e8aa86eda69c4ed8a72f6fedf1/lib/lifx/light.js#L18-L27 |
21,777 | MariusRumpf/node-lifx | lib/lifx/client.js | Client | function Client() {
EventEmitter.call(this);
this.debug = false;
this.socket = dgram.createSocket('udp4');
this.isSocketBound = false;
this.devices = {};
this.port = null;
this.messagesQueue = [];
this.sendTimer = null;
this.discoveryTimer = null;
this.discoveryPacketSequence = 0;
this.messageHandlers = [{
type: 'stateService',
callback: this.processDiscoveryPacket.bind(this)
}, {
type: 'stateLabel',
callback: this.processLabelPacket.bind(this)
}, {
type: 'stateLight',
callback: this.processLabelPacket.bind(this)
}];
this.sequenceNumber = 0;
this.lightOfflineTolerance = 3;
this.messageHandlerTimeout = 45000; // 45 sec
this.resendPacketDelay = 150;
this.resendMaxTimes = 5;
this.source = utils.getRandomHexString(8);
this.broadcastAddress = '255.255.255.255';
} | javascript | function Client() {
EventEmitter.call(this);
this.debug = false;
this.socket = dgram.createSocket('udp4');
this.isSocketBound = false;
this.devices = {};
this.port = null;
this.messagesQueue = [];
this.sendTimer = null;
this.discoveryTimer = null;
this.discoveryPacketSequence = 0;
this.messageHandlers = [{
type: 'stateService',
callback: this.processDiscoveryPacket.bind(this)
}, {
type: 'stateLabel',
callback: this.processLabelPacket.bind(this)
}, {
type: 'stateLight',
callback: this.processLabelPacket.bind(this)
}];
this.sequenceNumber = 0;
this.lightOfflineTolerance = 3;
this.messageHandlerTimeout = 45000; // 45 sec
this.resendPacketDelay = 150;
this.resendMaxTimes = 5;
this.source = utils.getRandomHexString(8);
this.broadcastAddress = '255.255.255.255';
} | [
"function",
"Client",
"(",
")",
"{",
"EventEmitter",
".",
"call",
"(",
"this",
")",
";",
"this",
".",
"debug",
"=",
"false",
";",
"this",
".",
"socket",
"=",
"dgram",
".",
"createSocket",
"(",
"'udp4'",
")",
";",
"this",
".",
"isSocketBound",
"=",
"false",
";",
"this",
".",
"devices",
"=",
"{",
"}",
";",
"this",
".",
"port",
"=",
"null",
";",
"this",
".",
"messagesQueue",
"=",
"[",
"]",
";",
"this",
".",
"sendTimer",
"=",
"null",
";",
"this",
".",
"discoveryTimer",
"=",
"null",
";",
"this",
".",
"discoveryPacketSequence",
"=",
"0",
";",
"this",
".",
"messageHandlers",
"=",
"[",
"{",
"type",
":",
"'stateService'",
",",
"callback",
":",
"this",
".",
"processDiscoveryPacket",
".",
"bind",
"(",
"this",
")",
"}",
",",
"{",
"type",
":",
"'stateLabel'",
",",
"callback",
":",
"this",
".",
"processLabelPacket",
".",
"bind",
"(",
"this",
")",
"}",
",",
"{",
"type",
":",
"'stateLight'",
",",
"callback",
":",
"this",
".",
"processLabelPacket",
".",
"bind",
"(",
"this",
")",
"}",
"]",
";",
"this",
".",
"sequenceNumber",
"=",
"0",
";",
"this",
".",
"lightOfflineTolerance",
"=",
"3",
";",
"this",
".",
"messageHandlerTimeout",
"=",
"45000",
";",
"// 45 sec",
"this",
".",
"resendPacketDelay",
"=",
"150",
";",
"this",
".",
"resendMaxTimes",
"=",
"5",
";",
"this",
".",
"source",
"=",
"utils",
".",
"getRandomHexString",
"(",
"8",
")",
";",
"this",
".",
"broadcastAddress",
"=",
"'255.255.255.255'",
";",
"}"
] | Creates a lifx client
@extends EventEmitter | [
"Creates",
"a",
"lifx",
"client"
] | c5bb37309895f7e8aa86eda69c4ed8a72f6fedf1 | https://github.com/MariusRumpf/node-lifx/blob/c5bb37309895f7e8aa86eda69c4ed8a72f6fedf1/lib/lifx/client.js#L16-L45 |
21,778 | samclarke/robots-parser | Robots.js | trimLine | function trimLine(line) {
if (!line) {
return null;
}
if (Array.isArray(line)) {
return line.map(trimLine);
}
return String(line).trim();
} | javascript | function trimLine(line) {
if (!line) {
return null;
}
if (Array.isArray(line)) {
return line.map(trimLine);
}
return String(line).trim();
} | [
"function",
"trimLine",
"(",
"line",
")",
"{",
"if",
"(",
"!",
"line",
")",
"{",
"return",
"null",
";",
"}",
"if",
"(",
"Array",
".",
"isArray",
"(",
"line",
")",
")",
"{",
"return",
"line",
".",
"map",
"(",
"trimLine",
")",
";",
"}",
"return",
"String",
"(",
"line",
")",
".",
"trim",
"(",
")",
";",
"}"
] | Trims the white space from the start and end of the line.
If the line is an array it will strip the white space from
the start and end of each element of the array.
@param {string|Array} line
@return {string|Array}
@private | [
"Trims",
"the",
"white",
"space",
"from",
"the",
"start",
"and",
"end",
"of",
"the",
"line",
"."
] | 888df9e4d820c36d57191ad7ca6b37218051ea65 | https://github.com/samclarke/robots-parser/blob/888df9e4d820c36d57191ad7ca6b37218051ea65/Robots.js#L13-L23 |
21,779 | samclarke/robots-parser | Robots.js | removeComments | function removeComments(line) {
var commentStartIndex = line.indexOf('#');
if (commentStartIndex > -1) {
return line.substr(0, commentStartIndex);
}
return line;
} | javascript | function removeComments(line) {
var commentStartIndex = line.indexOf('#');
if (commentStartIndex > -1) {
return line.substr(0, commentStartIndex);
}
return line;
} | [
"function",
"removeComments",
"(",
"line",
")",
"{",
"var",
"commentStartIndex",
"=",
"line",
".",
"indexOf",
"(",
"'#'",
")",
";",
"if",
"(",
"commentStartIndex",
">",
"-",
"1",
")",
"{",
"return",
"line",
".",
"substr",
"(",
"0",
",",
"commentStartIndex",
")",
";",
"}",
"return",
"line",
";",
"}"
] | Remove comments from lines
@param {string} line
@return {string}
@private | [
"Remove",
"comments",
"from",
"lines"
] | 888df9e4d820c36d57191ad7ca6b37218051ea65 | https://github.com/samclarke/robots-parser/blob/888df9e4d820c36d57191ad7ca6b37218051ea65/Robots.js#L32-L39 |
21,780 | samclarke/robots-parser | Robots.js | formatUserAgent | function formatUserAgent(userAgent) {
var formattedUserAgent = userAgent.toLowerCase();
// Strip the version number from robot/1.0 user agents
var idx = formattedUserAgent.indexOf('/');
if (idx > -1) {
formattedUserAgent = formattedUserAgent.substr(0, idx);
}
return formattedUserAgent.trim();
} | javascript | function formatUserAgent(userAgent) {
var formattedUserAgent = userAgent.toLowerCase();
// Strip the version number from robot/1.0 user agents
var idx = formattedUserAgent.indexOf('/');
if (idx > -1) {
formattedUserAgent = formattedUserAgent.substr(0, idx);
}
return formattedUserAgent.trim();
} | [
"function",
"formatUserAgent",
"(",
"userAgent",
")",
"{",
"var",
"formattedUserAgent",
"=",
"userAgent",
".",
"toLowerCase",
"(",
")",
";",
"// Strip the version number from robot/1.0 user agents",
"var",
"idx",
"=",
"formattedUserAgent",
".",
"indexOf",
"(",
"'/'",
")",
";",
"if",
"(",
"idx",
">",
"-",
"1",
")",
"{",
"formattedUserAgent",
"=",
"formattedUserAgent",
".",
"substr",
"(",
"0",
",",
"idx",
")",
";",
"}",
"return",
"formattedUserAgent",
".",
"trim",
"(",
")",
";",
"}"
] | Normalises the user-agent string by converting it to
lower case and removing any version numbers.
@param {string} userAgent
@return {string}
@private | [
"Normalises",
"the",
"user",
"-",
"agent",
"string",
"by",
"converting",
"it",
"to",
"lower",
"case",
"and",
"removing",
"any",
"version",
"numbers",
"."
] | 888df9e4d820c36d57191ad7ca6b37218051ea65 | https://github.com/samclarke/robots-parser/blob/888df9e4d820c36d57191ad7ca6b37218051ea65/Robots.js#L66-L76 |
21,781 | samclarke/robots-parser | Robots.js | parsePattern | function parsePattern(pattern) {
var regexSpecialChars = /[\-\[\]\/\{\}\(\)\+\?\.\\\^\$\|]/g;
// Treat consecutive wildcards as one (#12)
var wildCardPattern = /\*+/g;
var endOfLinePattern = /\\\$$/;
pattern = normaliseEncoding(pattern)
if (pattern.indexOf('*') < 0 && pattern.indexOf('$') < 0) {
return pattern;
}
pattern = pattern
.replace(regexSpecialChars, '\\$&')
.replace(wildCardPattern, '(?:.*)')
.replace(endOfLinePattern, '$');
return new RegExp(pattern);
} | javascript | function parsePattern(pattern) {
var regexSpecialChars = /[\-\[\]\/\{\}\(\)\+\?\.\\\^\$\|]/g;
// Treat consecutive wildcards as one (#12)
var wildCardPattern = /\*+/g;
var endOfLinePattern = /\\\$$/;
pattern = normaliseEncoding(pattern)
if (pattern.indexOf('*') < 0 && pattern.indexOf('$') < 0) {
return pattern;
}
pattern = pattern
.replace(regexSpecialChars, '\\$&')
.replace(wildCardPattern, '(?:.*)')
.replace(endOfLinePattern, '$');
return new RegExp(pattern);
} | [
"function",
"parsePattern",
"(",
"pattern",
")",
"{",
"var",
"regexSpecialChars",
"=",
"/",
"[\\-\\[\\]\\/\\{\\}\\(\\)\\+\\?\\.\\\\\\^\\$\\|]",
"/",
"g",
";",
"// Treat consecutive wildcards as one (#12)",
"var",
"wildCardPattern",
"=",
"/",
"\\*+",
"/",
"g",
";",
"var",
"endOfLinePattern",
"=",
"/",
"\\\\\\$$",
"/",
";",
"pattern",
"=",
"normaliseEncoding",
"(",
"pattern",
")",
"if",
"(",
"pattern",
".",
"indexOf",
"(",
"'*'",
")",
"<",
"0",
"&&",
"pattern",
".",
"indexOf",
"(",
"'$'",
")",
"<",
"0",
")",
"{",
"return",
"pattern",
";",
"}",
"pattern",
"=",
"pattern",
".",
"replace",
"(",
"regexSpecialChars",
",",
"'\\\\$&'",
")",
".",
"replace",
"(",
"wildCardPattern",
",",
"'(?:.*)'",
")",
".",
"replace",
"(",
"endOfLinePattern",
",",
"'$'",
")",
";",
"return",
"new",
"RegExp",
"(",
"pattern",
")",
";",
"}"
] | Converts the pattern into a regexp if it is a wildcard
pattern.
Returns a string if the pattern isn't a wildcard pattern
@param {string} pattern
@return {string|RegExp}
@private | [
"Converts",
"the",
"pattern",
"into",
"a",
"regexp",
"if",
"it",
"is",
"a",
"wildcard",
"pattern",
"."
] | 888df9e4d820c36d57191ad7ca6b37218051ea65 | https://github.com/samclarke/robots-parser/blob/888df9e4d820c36d57191ad7ca6b37218051ea65/Robots.js#L119-L137 |
21,782 | samclarke/robots-parser | Robots.js | findRule | function findRule(path, rules) {
var matchingRule = null;
for (var i=0; i < rules.length; i++) {
var rule = rules[i];
if (typeof rule.pattern === 'string') {
if (path.indexOf(rule.pattern) !== 0) {
continue;
}
// The longest matching rule takes precedence
if (!matchingRule || rule.pattern.length > matchingRule.pattern.length) {
matchingRule = rule;
}
// The first matching pattern takes precedence
// over all other rules including other patterns
} else if (rule.pattern.test(path)) {
return rule;
}
}
return matchingRule;
} | javascript | function findRule(path, rules) {
var matchingRule = null;
for (var i=0; i < rules.length; i++) {
var rule = rules[i];
if (typeof rule.pattern === 'string') {
if (path.indexOf(rule.pattern) !== 0) {
continue;
}
// The longest matching rule takes precedence
if (!matchingRule || rule.pattern.length > matchingRule.pattern.length) {
matchingRule = rule;
}
// The first matching pattern takes precedence
// over all other rules including other patterns
} else if (rule.pattern.test(path)) {
return rule;
}
}
return matchingRule;
} | [
"function",
"findRule",
"(",
"path",
",",
"rules",
")",
"{",
"var",
"matchingRule",
"=",
"null",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"rules",
".",
"length",
";",
"i",
"++",
")",
"{",
"var",
"rule",
"=",
"rules",
"[",
"i",
"]",
";",
"if",
"(",
"typeof",
"rule",
".",
"pattern",
"===",
"'string'",
")",
"{",
"if",
"(",
"path",
".",
"indexOf",
"(",
"rule",
".",
"pattern",
")",
"!==",
"0",
")",
"{",
"continue",
";",
"}",
"// The longest matching rule takes precedence",
"if",
"(",
"!",
"matchingRule",
"||",
"rule",
".",
"pattern",
".",
"length",
">",
"matchingRule",
".",
"pattern",
".",
"length",
")",
"{",
"matchingRule",
"=",
"rule",
";",
"}",
"// The first matching pattern takes precedence",
"// over all other rules including other patterns",
"}",
"else",
"if",
"(",
"rule",
".",
"pattern",
".",
"test",
"(",
"path",
")",
")",
"{",
"return",
"rule",
";",
"}",
"}",
"return",
"matchingRule",
";",
"}"
] | Returns if a pattern is allowed by the specified rules.
@param {string} path
@param {Array.<Object>} rules
@return {Object?}
@private | [
"Returns",
"if",
"a",
"pattern",
"is",
"allowed",
"by",
"the",
"specified",
"rules",
"."
] | 888df9e4d820c36d57191ad7ca6b37218051ea65 | https://github.com/samclarke/robots-parser/blob/888df9e4d820c36d57191ad7ca6b37218051ea65/Robots.js#L199-L222 |
21,783 | SpoonX/aurelia-orm | dist/aurelia-orm.js | asJson | function asJson(entity, shallow) {
let json;
try {
json = JSON.stringify(asObject(entity, shallow));
} catch (error) {
json = '';
}
return json;
} | javascript | function asJson(entity, shallow) {
let json;
try {
json = JSON.stringify(asObject(entity, shallow));
} catch (error) {
json = '';
}
return json;
} | [
"function",
"asJson",
"(",
"entity",
",",
"shallow",
")",
"{",
"let",
"json",
";",
"try",
"{",
"json",
"=",
"JSON",
".",
"stringify",
"(",
"asObject",
"(",
"entity",
",",
"shallow",
")",
")",
";",
"}",
"catch",
"(",
"error",
")",
"{",
"json",
"=",
"''",
";",
"}",
"return",
"json",
";",
"}"
] | Entity representation as json
@param {Entity} entity
@param {boolean} [shallow]
@return {string} | [
"Entity",
"representation",
"as",
"json"
] | d6b5dece74e1f44038de917c38fadb57d6655c18 | https://github.com/SpoonX/aurelia-orm/blob/d6b5dece74e1f44038de917c38fadb57d6655c18/dist/aurelia-orm.js#L1112-L1122 |
21,784 | SpoonX/aurelia-orm | dist/aurelia-orm.js | getFlat | function getFlat(entity, json) {
let flat = {
entity : asObject(entity, true),
collections: getCollectionsCompact(entity)
};
if (json) {
flat = JSON.stringify(flat);
}
return flat;
} | javascript | function getFlat(entity, json) {
let flat = {
entity : asObject(entity, true),
collections: getCollectionsCompact(entity)
};
if (json) {
flat = JSON.stringify(flat);
}
return flat;
} | [
"function",
"getFlat",
"(",
"entity",
",",
"json",
")",
"{",
"let",
"flat",
"=",
"{",
"entity",
":",
"asObject",
"(",
"entity",
",",
"true",
")",
",",
"collections",
":",
"getCollectionsCompact",
"(",
"entity",
")",
"}",
";",
"if",
"(",
"json",
")",
"{",
"flat",
"=",
"JSON",
".",
"stringify",
"(",
"flat",
")",
";",
"}",
"return",
"flat",
";",
"}"
] | Get a flat, plain representation of the entity and its associations.
@param {Entity} entity
@param {boolean} [json]
@return {{}} {entity, collections} | [
"Get",
"a",
"flat",
"plain",
"representation",
"of",
"the",
"entity",
"and",
"its",
"associations",
"."
] | d6b5dece74e1f44038de917c38fadb57d6655c18 | https://github.com/SpoonX/aurelia-orm/blob/d6b5dece74e1f44038de917c38fadb57d6655c18/dist/aurelia-orm.js#L1184-L1195 |
21,785 | SpoonX/aurelia-orm | dist/aurelia-orm.js | getPropertyForAssociation | function getPropertyForAssociation(forEntity, entity) {
let associations = forEntity.getMeta().fetch('associations');
return Object.keys(associations).filter(key => {
return associations[key].entity === entity.getResource();
})[0];
} | javascript | function getPropertyForAssociation(forEntity, entity) {
let associations = forEntity.getMeta().fetch('associations');
return Object.keys(associations).filter(key => {
return associations[key].entity === entity.getResource();
})[0];
} | [
"function",
"getPropertyForAssociation",
"(",
"forEntity",
",",
"entity",
")",
"{",
"let",
"associations",
"=",
"forEntity",
".",
"getMeta",
"(",
")",
".",
"fetch",
"(",
"'associations'",
")",
";",
"return",
"Object",
".",
"keys",
"(",
"associations",
")",
".",
"filter",
"(",
"key",
"=>",
"{",
"return",
"associations",
"[",
"key",
"]",
".",
"entity",
"===",
"entity",
".",
"getResource",
"(",
")",
";",
"}",
")",
"[",
"0",
"]",
";",
"}"
] | Get the property of the association on this entity.
@param {Entity} forEntity
@param {Entity} entity
@return {string} | [
"Get",
"the",
"property",
"of",
"the",
"association",
"on",
"this",
"entity",
"."
] | d6b5dece74e1f44038de917c38fadb57d6655c18 | https://github.com/SpoonX/aurelia-orm/blob/d6b5dece74e1f44038de917c38fadb57d6655c18/dist/aurelia-orm.js#L1205-L1211 |
21,786 | hoodiehq/hoodie-client | lib/events.js | trigger | function trigger (state, eventName) {
var args = [].slice.call(arguments, 1)
state.emitter.emit.apply(state.emitter, args)
return this
} | javascript | function trigger (state, eventName) {
var args = [].slice.call(arguments, 1)
state.emitter.emit.apply(state.emitter, args)
return this
} | [
"function",
"trigger",
"(",
"state",
",",
"eventName",
")",
"{",
"var",
"args",
"=",
"[",
"]",
".",
"slice",
".",
"call",
"(",
"arguments",
",",
"1",
")",
"state",
".",
"emitter",
".",
"emit",
".",
"apply",
"(",
"state",
".",
"emitter",
",",
"args",
")",
"return",
"this",
"}"
] | trigger a specified event
@param {String} eventName Name of event
@param {...*} [options] Options | [
"trigger",
"a",
"specified",
"event"
] | e9ceb07e01da0d0a0136fd28b413a8e4fac5ea2b | https://github.com/hoodiehq/hoodie-client/blob/e9ceb07e01da0d0a0136fd28b413a8e4fac5ea2b/lib/events.js#L54-L60 |
21,787 | jhermsmeier/node-vcf | lib/vcard.js | function( key ) {
if( this.data[ key ] == null ) {
return this.data[ key ]
}
if( Array.isArray( this.data[ key ] ) ) {
return this.data[ key ].map( function( prop ) {
return prop.clone()
})
} else {
return this.data[ key ].clone()
}
} | javascript | function( key ) {
if( this.data[ key ] == null ) {
return this.data[ key ]
}
if( Array.isArray( this.data[ key ] ) ) {
return this.data[ key ].map( function( prop ) {
return prop.clone()
})
} else {
return this.data[ key ].clone()
}
} | [
"function",
"(",
"key",
")",
"{",
"if",
"(",
"this",
".",
"data",
"[",
"key",
"]",
"==",
"null",
")",
"{",
"return",
"this",
".",
"data",
"[",
"key",
"]",
"}",
"if",
"(",
"Array",
".",
"isArray",
"(",
"this",
".",
"data",
"[",
"key",
"]",
")",
")",
"{",
"return",
"this",
".",
"data",
"[",
"key",
"]",
".",
"map",
"(",
"function",
"(",
"prop",
")",
"{",
"return",
"prop",
".",
"clone",
"(",
")",
"}",
")",
"}",
"else",
"{",
"return",
"this",
".",
"data",
"[",
"key",
"]",
".",
"clone",
"(",
")",
"}",
"}"
] | Get a vCard property
@param {String} key
@return {Object|Array} | [
"Get",
"a",
"vCard",
"property"
] | e0a984fb294fb2b76f0e6bba009357f15195b92d | https://github.com/jhermsmeier/node-vcf/blob/e0a984fb294fb2b76f0e6bba009357f15195b92d/lib/vcard.js#L179-L193 | |
21,788 | jhermsmeier/node-vcf | lib/vcard.js | function( key, value, params ) {
var prop = new vCard.Property( key, value, params )
this.addProperty( prop )
return this
} | javascript | function( key, value, params ) {
var prop = new vCard.Property( key, value, params )
this.addProperty( prop )
return this
} | [
"function",
"(",
"key",
",",
"value",
",",
"params",
")",
"{",
"var",
"prop",
"=",
"new",
"vCard",
".",
"Property",
"(",
"key",
",",
"value",
",",
"params",
")",
"this",
".",
"addProperty",
"(",
"prop",
")",
"return",
"this",
"}"
] | Add a vCard property
@param {String} key
@param {String} value
@param {Object} params | [
"Add",
"a",
"vCard",
"property"
] | e0a984fb294fb2b76f0e6bba009357f15195b92d | https://github.com/jhermsmeier/node-vcf/blob/e0a984fb294fb2b76f0e6bba009357f15195b92d/lib/vcard.js#L211-L215 | |
21,789 | jhermsmeier/node-vcf | lib/vcard.js | function( prop ) {
var key = prop._field
if( Array.isArray( this.data[ key ] ) ) {
this.data[ key ].push( prop )
} else if( this.data[ key ] != null ) {
this.data[ key ] = [ this.data[ key ], prop ]
} else {
this.data[ key ] = prop
}
return this
} | javascript | function( prop ) {
var key = prop._field
if( Array.isArray( this.data[ key ] ) ) {
this.data[ key ].push( prop )
} else if( this.data[ key ] != null ) {
this.data[ key ] = [ this.data[ key ], prop ]
} else {
this.data[ key ] = prop
}
return this
} | [
"function",
"(",
"prop",
")",
"{",
"var",
"key",
"=",
"prop",
".",
"_field",
"if",
"(",
"Array",
".",
"isArray",
"(",
"this",
".",
"data",
"[",
"key",
"]",
")",
")",
"{",
"this",
".",
"data",
"[",
"key",
"]",
".",
"push",
"(",
"prop",
")",
"}",
"else",
"if",
"(",
"this",
".",
"data",
"[",
"key",
"]",
"!=",
"null",
")",
"{",
"this",
".",
"data",
"[",
"key",
"]",
"=",
"[",
"this",
".",
"data",
"[",
"key",
"]",
",",
"prop",
"]",
"}",
"else",
"{",
"this",
".",
"data",
"[",
"key",
"]",
"=",
"prop",
"}",
"return",
"this",
"}"
] | Add a vCard property from an already
constructed vCard.Property
@param {vCard.Property} prop | [
"Add",
"a",
"vCard",
"property",
"from",
"an",
"already",
"constructed",
"vCard",
".",
"Property"
] | e0a984fb294fb2b76f0e6bba009357f15195b92d | https://github.com/jhermsmeier/node-vcf/blob/e0a984fb294fb2b76f0e6bba009357f15195b92d/lib/vcard.js#L232-L246 | |
21,790 | jhermsmeier/node-vcf | lib/vcard.js | function( value ) {
// Normalize & split
var lines = vCard.normalize( value )
.split( /\r?\n/g )
// Keep begin and end markers
// for eventual error messages
var begin = lines[0]
var version = lines[1]
var end = lines[ lines.length - 1 ]
if( !/BEGIN:VCARD/i.test( begin ) )
throw new SyntaxError( 'Invalid vCard: Expected "BEGIN:VCARD" but found "'+ begin +'"' )
if( !/END:VCARD/i.test( end ) )
throw new SyntaxError( 'Invalid vCard: Expected "END:VCARD" but found "'+ end +'"' )
// TODO: For version 2.1, the VERSION can be anywhere between BEGIN & END
if( !/VERSION:\d\.\d/i.test( version ) )
throw new SyntaxError( 'Invalid vCard: Expected "VERSION:\\d.\\d" but found "'+ version +'"' )
this.version = version.substring( 8, 11 )
if( !vCard.isSupported( this.version ) )
throw new Error( 'Unsupported version "' + this.version + '"' )
this.data = vCard.parseLines( lines )
return this
} | javascript | function( value ) {
// Normalize & split
var lines = vCard.normalize( value )
.split( /\r?\n/g )
// Keep begin and end markers
// for eventual error messages
var begin = lines[0]
var version = lines[1]
var end = lines[ lines.length - 1 ]
if( !/BEGIN:VCARD/i.test( begin ) )
throw new SyntaxError( 'Invalid vCard: Expected "BEGIN:VCARD" but found "'+ begin +'"' )
if( !/END:VCARD/i.test( end ) )
throw new SyntaxError( 'Invalid vCard: Expected "END:VCARD" but found "'+ end +'"' )
// TODO: For version 2.1, the VERSION can be anywhere between BEGIN & END
if( !/VERSION:\d\.\d/i.test( version ) )
throw new SyntaxError( 'Invalid vCard: Expected "VERSION:\\d.\\d" but found "'+ version +'"' )
this.version = version.substring( 8, 11 )
if( !vCard.isSupported( this.version ) )
throw new Error( 'Unsupported version "' + this.version + '"' )
this.data = vCard.parseLines( lines )
return this
} | [
"function",
"(",
"value",
")",
"{",
"// Normalize & split",
"var",
"lines",
"=",
"vCard",
".",
"normalize",
"(",
"value",
")",
".",
"split",
"(",
"/",
"\\r?\\n",
"/",
"g",
")",
"// Keep begin and end markers",
"// for eventual error messages",
"var",
"begin",
"=",
"lines",
"[",
"0",
"]",
"var",
"version",
"=",
"lines",
"[",
"1",
"]",
"var",
"end",
"=",
"lines",
"[",
"lines",
".",
"length",
"-",
"1",
"]",
"if",
"(",
"!",
"/",
"BEGIN:VCARD",
"/",
"i",
".",
"test",
"(",
"begin",
")",
")",
"throw",
"new",
"SyntaxError",
"(",
"'Invalid vCard: Expected \"BEGIN:VCARD\" but found \"'",
"+",
"begin",
"+",
"'\"'",
")",
"if",
"(",
"!",
"/",
"END:VCARD",
"/",
"i",
".",
"test",
"(",
"end",
")",
")",
"throw",
"new",
"SyntaxError",
"(",
"'Invalid vCard: Expected \"END:VCARD\" but found \"'",
"+",
"end",
"+",
"'\"'",
")",
"// TODO: For version 2.1, the VERSION can be anywhere between BEGIN & END",
"if",
"(",
"!",
"/",
"VERSION:\\d\\.\\d",
"/",
"i",
".",
"test",
"(",
"version",
")",
")",
"throw",
"new",
"SyntaxError",
"(",
"'Invalid vCard: Expected \"VERSION:\\\\d.\\\\d\" but found \"'",
"+",
"version",
"+",
"'\"'",
")",
"this",
".",
"version",
"=",
"version",
".",
"substring",
"(",
"8",
",",
"11",
")",
"if",
"(",
"!",
"vCard",
".",
"isSupported",
"(",
"this",
".",
"version",
")",
")",
"throw",
"new",
"Error",
"(",
"'Unsupported version \"'",
"+",
"this",
".",
"version",
"+",
"'\"'",
")",
"this",
".",
"data",
"=",
"vCard",
".",
"parseLines",
"(",
"lines",
")",
"return",
"this",
"}"
] | Parse a vcf formatted vCard
@param {String} value
@return {vCard} | [
"Parse",
"a",
"vcf",
"formatted",
"vCard"
] | e0a984fb294fb2b76f0e6bba009357f15195b92d | https://github.com/jhermsmeier/node-vcf/blob/e0a984fb294fb2b76f0e6bba009357f15195b92d/lib/vcard.js#L253-L284 | |
21,791 | jhermsmeier/node-vcf | lib/vcard.js | function( version ) {
version = version || '4.0'
var keys = Object.keys( this.data )
var data = [ [ 'version', {}, 'text', version ] ]
var prop = null
for( var i = 0; i < keys.length; i++ ) {
if( keys[i] === 'version' ) continue;
prop = this.data[ keys[i] ]
if( Array.isArray( prop ) ) {
for( var k = 0; k < prop.length; k++ ) {
data.push( prop[k].toJSON() )
}
} else {
data.push( prop.toJSON() )
}
}
return [ 'vcard', data ]
} | javascript | function( version ) {
version = version || '4.0'
var keys = Object.keys( this.data )
var data = [ [ 'version', {}, 'text', version ] ]
var prop = null
for( var i = 0; i < keys.length; i++ ) {
if( keys[i] === 'version' ) continue;
prop = this.data[ keys[i] ]
if( Array.isArray( prop ) ) {
for( var k = 0; k < prop.length; k++ ) {
data.push( prop[k].toJSON() )
}
} else {
data.push( prop.toJSON() )
}
}
return [ 'vcard', data ]
} | [
"function",
"(",
"version",
")",
"{",
"version",
"=",
"version",
"||",
"'4.0'",
"var",
"keys",
"=",
"Object",
".",
"keys",
"(",
"this",
".",
"data",
")",
"var",
"data",
"=",
"[",
"[",
"'version'",
",",
"{",
"}",
",",
"'text'",
",",
"version",
"]",
"]",
"var",
"prop",
"=",
"null",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"keys",
".",
"length",
";",
"i",
"++",
")",
"{",
"if",
"(",
"keys",
"[",
"i",
"]",
"===",
"'version'",
")",
"continue",
";",
"prop",
"=",
"this",
".",
"data",
"[",
"keys",
"[",
"i",
"]",
"]",
"if",
"(",
"Array",
".",
"isArray",
"(",
"prop",
")",
")",
"{",
"for",
"(",
"var",
"k",
"=",
"0",
";",
"k",
"<",
"prop",
".",
"length",
";",
"k",
"++",
")",
"{",
"data",
".",
"push",
"(",
"prop",
"[",
"k",
"]",
".",
"toJSON",
"(",
")",
")",
"}",
"}",
"else",
"{",
"data",
".",
"push",
"(",
"prop",
".",
"toJSON",
"(",
")",
")",
"}",
"}",
"return",
"[",
"'vcard'",
",",
"data",
"]",
"}"
] | Format the card as jCard
@param {String} version='4.0'
@return {Array} jCard | [
"Format",
"the",
"card",
"as",
"jCard"
] | e0a984fb294fb2b76f0e6bba009357f15195b92d | https://github.com/jhermsmeier/node-vcf/blob/e0a984fb294fb2b76f0e6bba009357f15195b92d/lib/vcard.js#L302-L324 | |
21,792 | jhermsmeier/node-vcf | lib/property.js | function( type ) {
type = ( type + '' ).toLowerCase()
return Array.isArray( this.type ) ?
this.type.indexOf( type ) >= 0 :
this.type === type
} | javascript | function( type ) {
type = ( type + '' ).toLowerCase()
return Array.isArray( this.type ) ?
this.type.indexOf( type ) >= 0 :
this.type === type
} | [
"function",
"(",
"type",
")",
"{",
"type",
"=",
"(",
"type",
"+",
"''",
")",
".",
"toLowerCase",
"(",
")",
"return",
"Array",
".",
"isArray",
"(",
"this",
".",
"type",
")",
"?",
"this",
".",
"type",
".",
"indexOf",
"(",
"type",
")",
">=",
"0",
":",
"this",
".",
"type",
"===",
"type",
"}"
] | Check whether the property is of a given type
@param {String} type
@return {Boolean} | [
"Check",
"whether",
"the",
"property",
"is",
"of",
"a",
"given",
"type"
] | e0a984fb294fb2b76f0e6bba009357f15195b92d | https://github.com/jhermsmeier/node-vcf/blob/e0a984fb294fb2b76f0e6bba009357f15195b92d/lib/property.js#L70-L75 | |
21,793 | jhermsmeier/node-vcf | lib/property.js | function( version ) {
var propName = (this.group ? this.group + '.' : '') + capitalDashCase( this._field )
var keys = Object.keys( this )
var params = []
for( var i = 0; i < keys.length; i++ ) {
if (keys[i] === 'group') continue
params.push( capitalDashCase( keys[i] ) + '=' + this[ keys[i] ] )
}
return propName +
( params.length ? ';' + params.join( ';' ) : params ) + ':' +
( Array.isArray( this._data ) ? this._data.join( ';' ) : this._data )
} | javascript | function( version ) {
var propName = (this.group ? this.group + '.' : '') + capitalDashCase( this._field )
var keys = Object.keys( this )
var params = []
for( var i = 0; i < keys.length; i++ ) {
if (keys[i] === 'group') continue
params.push( capitalDashCase( keys[i] ) + '=' + this[ keys[i] ] )
}
return propName +
( params.length ? ';' + params.join( ';' ) : params ) + ':' +
( Array.isArray( this._data ) ? this._data.join( ';' ) : this._data )
} | [
"function",
"(",
"version",
")",
"{",
"var",
"propName",
"=",
"(",
"this",
".",
"group",
"?",
"this",
".",
"group",
"+",
"'.'",
":",
"''",
")",
"+",
"capitalDashCase",
"(",
"this",
".",
"_field",
")",
"var",
"keys",
"=",
"Object",
".",
"keys",
"(",
"this",
")",
"var",
"params",
"=",
"[",
"]",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"keys",
".",
"length",
";",
"i",
"++",
")",
"{",
"if",
"(",
"keys",
"[",
"i",
"]",
"===",
"'group'",
")",
"continue",
"params",
".",
"push",
"(",
"capitalDashCase",
"(",
"keys",
"[",
"i",
"]",
")",
"+",
"'='",
"+",
"this",
"[",
"keys",
"[",
"i",
"]",
"]",
")",
"}",
"return",
"propName",
"+",
"(",
"params",
".",
"length",
"?",
"';'",
"+",
"params",
".",
"join",
"(",
"';'",
")",
":",
"params",
")",
"+",
"':'",
"+",
"(",
"Array",
".",
"isArray",
"(",
"this",
".",
"_data",
")",
"?",
"this",
".",
"_data",
".",
"join",
"(",
"';'",
")",
":",
"this",
".",
"_data",
")",
"}"
] | Format the property as vcf with given version
@param {String} version
@return {String} | [
"Format",
"the",
"property",
"as",
"vcf",
"with",
"given",
"version"
] | e0a984fb294fb2b76f0e6bba009357f15195b92d | https://github.com/jhermsmeier/node-vcf/blob/e0a984fb294fb2b76f0e6bba009357f15195b92d/lib/property.js#L99-L114 | |
21,794 | jhermsmeier/node-vcf | lib/property.js | function() {
var params = Object.assign({},this)
if( params.value === 'text' ) {
params.value = void 0
delete params.value
}
var data = [ this._field, params, this.value || 'text' ]
switch( this._field ) {
default: data.push( this._data ); break
case 'adr':
case 'n':
data.push( this._data.split( ';' ) )
}
return data
} | javascript | function() {
var params = Object.assign({},this)
if( params.value === 'text' ) {
params.value = void 0
delete params.value
}
var data = [ this._field, params, this.value || 'text' ]
switch( this._field ) {
default: data.push( this._data ); break
case 'adr':
case 'n':
data.push( this._data.split( ';' ) )
}
return data
} | [
"function",
"(",
")",
"{",
"var",
"params",
"=",
"Object",
".",
"assign",
"(",
"{",
"}",
",",
"this",
")",
"if",
"(",
"params",
".",
"value",
"===",
"'text'",
")",
"{",
"params",
".",
"value",
"=",
"void",
"0",
"delete",
"params",
".",
"value",
"}",
"var",
"data",
"=",
"[",
"this",
".",
"_field",
",",
"params",
",",
"this",
".",
"value",
"||",
"'text'",
"]",
"switch",
"(",
"this",
".",
"_field",
")",
"{",
"default",
":",
"data",
".",
"push",
"(",
"this",
".",
"_data",
")",
";",
"break",
"case",
"'adr'",
":",
"case",
"'n'",
":",
"data",
".",
"push",
"(",
"this",
".",
"_data",
".",
"split",
"(",
"';'",
")",
")",
"}",
"return",
"data",
"}"
] | Format the property as jCard data
@return {Array} | [
"Format",
"the",
"property",
"as",
"jCard",
"data"
] | e0a984fb294fb2b76f0e6bba009357f15195b92d | https://github.com/jhermsmeier/node-vcf/blob/e0a984fb294fb2b76f0e6bba009357f15195b92d/lib/property.js#L128-L148 | |
21,795 | waterlock/waterlock | lib/utils.js | function(req, res, user) {
var jsonWebTokens = waterlock.config.jsonWebTokens || {};
var expiryUnit = (jsonWebTokens.expiry && jsonWebTokens.expiry.unit) || 'days';
var expiryLength = (jsonWebTokens.expiry && jsonWebTokens.expiry.length) || 7;
var expires = moment().add(expiryLength, expiryUnit).valueOf();
var issued = Date.now();
user = user || req.session.user;
var token = jwt.encode({
iss: user.id + '|' + req.remoteAddress,
sub: jsonWebTokens.subject,
aud: jsonWebTokens.audience,
exp: expires,
nbf: issued,
iat: issued,
jti: uuid.v1()
}, jsonWebTokens.secret);
return {
token: token,
expires: expires
};
} | javascript | function(req, res, user) {
var jsonWebTokens = waterlock.config.jsonWebTokens || {};
var expiryUnit = (jsonWebTokens.expiry && jsonWebTokens.expiry.unit) || 'days';
var expiryLength = (jsonWebTokens.expiry && jsonWebTokens.expiry.length) || 7;
var expires = moment().add(expiryLength, expiryUnit).valueOf();
var issued = Date.now();
user = user || req.session.user;
var token = jwt.encode({
iss: user.id + '|' + req.remoteAddress,
sub: jsonWebTokens.subject,
aud: jsonWebTokens.audience,
exp: expires,
nbf: issued,
iat: issued,
jti: uuid.v1()
}, jsonWebTokens.secret);
return {
token: token,
expires: expires
};
} | [
"function",
"(",
"req",
",",
"res",
",",
"user",
")",
"{",
"var",
"jsonWebTokens",
"=",
"waterlock",
".",
"config",
".",
"jsonWebTokens",
"||",
"{",
"}",
";",
"var",
"expiryUnit",
"=",
"(",
"jsonWebTokens",
".",
"expiry",
"&&",
"jsonWebTokens",
".",
"expiry",
".",
"unit",
")",
"||",
"'days'",
";",
"var",
"expiryLength",
"=",
"(",
"jsonWebTokens",
".",
"expiry",
"&&",
"jsonWebTokens",
".",
"expiry",
".",
"length",
")",
"||",
"7",
";",
"var",
"expires",
"=",
"moment",
"(",
")",
".",
"add",
"(",
"expiryLength",
",",
"expiryUnit",
")",
".",
"valueOf",
"(",
")",
";",
"var",
"issued",
"=",
"Date",
".",
"now",
"(",
")",
";",
"user",
"=",
"user",
"||",
"req",
".",
"session",
".",
"user",
";",
"var",
"token",
"=",
"jwt",
".",
"encode",
"(",
"{",
"iss",
":",
"user",
".",
"id",
"+",
"'|'",
"+",
"req",
".",
"remoteAddress",
",",
"sub",
":",
"jsonWebTokens",
".",
"subject",
",",
"aud",
":",
"jsonWebTokens",
".",
"audience",
",",
"exp",
":",
"expires",
",",
"nbf",
":",
"issued",
",",
"iat",
":",
"issued",
",",
"jti",
":",
"uuid",
".",
"v1",
"(",
")",
"}",
",",
"jsonWebTokens",
".",
"secret",
")",
";",
"return",
"{",
"token",
":",
"token",
",",
"expires",
":",
"expires",
"}",
";",
"}"
] | Creates a new JWT token
@param {Integer} req
@param {Object} res
@param {Object} user the user model
@return {Object} the created jwt token.
@api public | [
"Creates",
"a",
"new",
"JWT",
"token"
] | 088c7f9c641f626e6ebe9de4eec68f7eddf8d094 | https://github.com/waterlock/waterlock/blob/088c7f9c641f626e6ebe9de4eec68f7eddf8d094/lib/utils.js#L73-L95 | |
21,796 | waterlock/waterlock | lib/utils.js | function(req){
var token = null;
if (req.headers && req.headers.authorization) {
var parts = req.headers.authorization.split(' ');
if (parts.length === 2){
var scheme = parts[0];
var credentials = parts[1];
if (/^Bearer$/i.test(scheme)){
token = credentials;
}
}
}else{
token = this.allParams(req).access_token;
}
return token;
} | javascript | function(req){
var token = null;
if (req.headers && req.headers.authorization) {
var parts = req.headers.authorization.split(' ');
if (parts.length === 2){
var scheme = parts[0];
var credentials = parts[1];
if (/^Bearer$/i.test(scheme)){
token = credentials;
}
}
}else{
token = this.allParams(req).access_token;
}
return token;
} | [
"function",
"(",
"req",
")",
"{",
"var",
"token",
"=",
"null",
";",
"if",
"(",
"req",
".",
"headers",
"&&",
"req",
".",
"headers",
".",
"authorization",
")",
"{",
"var",
"parts",
"=",
"req",
".",
"headers",
".",
"authorization",
".",
"split",
"(",
"' '",
")",
";",
"if",
"(",
"parts",
".",
"length",
"===",
"2",
")",
"{",
"var",
"scheme",
"=",
"parts",
"[",
"0",
"]",
";",
"var",
"credentials",
"=",
"parts",
"[",
"1",
"]",
";",
"if",
"(",
"/",
"^Bearer$",
"/",
"i",
".",
"test",
"(",
"scheme",
")",
")",
"{",
"token",
"=",
"credentials",
";",
"}",
"}",
"}",
"else",
"{",
"token",
"=",
"this",
".",
"allParams",
"(",
"req",
")",
".",
"access_token",
";",
"}",
"return",
"token",
";",
"}"
] | Return access token from request
@param {Object} req the express request object
@return {String} token
@api public | [
"Return",
"access",
"token",
"from",
"request"
] | 088c7f9c641f626e6ebe9de4eec68f7eddf8d094 | https://github.com/waterlock/waterlock/blob/088c7f9c641f626e6ebe9de4eec68f7eddf8d094/lib/utils.js#L104-L120 | |
21,797 | waterlock/waterlock | lib/validator.js | function(token, cb){
try{
// decode the token
var _token = waterlock.jwt.decode(token, waterlock.config.jsonWebTokens.secret);
// set the time of the request
var _reqTime = Date.now();
// If token is expired
if(_token.exp <= _reqTime){
waterlock.logger.debug('access token rejected, reason: EXPIRED');
return cb('Your token is expired.');
}
// If token is early
if(_reqTime <= _token.nbf){
waterlock.logger.debug('access token rejected, reason: TOKEN EARLY');
return cb('This token is early.');
}
// If audience doesn't match
if(waterlock.config.jsonWebTokens.audience !== _token.aud){
waterlock.logger.debug('access token rejected, reason: AUDIENCE');
return cb('This token cannot be accepted for this domain.');
}
this.findUserFromToken(_token, cb);
} catch(err){
cb(err);
}
} | javascript | function(token, cb){
try{
// decode the token
var _token = waterlock.jwt.decode(token, waterlock.config.jsonWebTokens.secret);
// set the time of the request
var _reqTime = Date.now();
// If token is expired
if(_token.exp <= _reqTime){
waterlock.logger.debug('access token rejected, reason: EXPIRED');
return cb('Your token is expired.');
}
// If token is early
if(_reqTime <= _token.nbf){
waterlock.logger.debug('access token rejected, reason: TOKEN EARLY');
return cb('This token is early.');
}
// If audience doesn't match
if(waterlock.config.jsonWebTokens.audience !== _token.aud){
waterlock.logger.debug('access token rejected, reason: AUDIENCE');
return cb('This token cannot be accepted for this domain.');
}
this.findUserFromToken(_token, cb);
} catch(err){
cb(err);
}
} | [
"function",
"(",
"token",
",",
"cb",
")",
"{",
"try",
"{",
"// decode the token",
"var",
"_token",
"=",
"waterlock",
".",
"jwt",
".",
"decode",
"(",
"token",
",",
"waterlock",
".",
"config",
".",
"jsonWebTokens",
".",
"secret",
")",
";",
"// set the time of the request",
"var",
"_reqTime",
"=",
"Date",
".",
"now",
"(",
")",
";",
"// If token is expired",
"if",
"(",
"_token",
".",
"exp",
"<=",
"_reqTime",
")",
"{",
"waterlock",
".",
"logger",
".",
"debug",
"(",
"'access token rejected, reason: EXPIRED'",
")",
";",
"return",
"cb",
"(",
"'Your token is expired.'",
")",
";",
"}",
"// If token is early",
"if",
"(",
"_reqTime",
"<=",
"_token",
".",
"nbf",
")",
"{",
"waterlock",
".",
"logger",
".",
"debug",
"(",
"'access token rejected, reason: TOKEN EARLY'",
")",
";",
"return",
"cb",
"(",
"'This token is early.'",
")",
";",
"}",
"// If audience doesn't match",
"if",
"(",
"waterlock",
".",
"config",
".",
"jsonWebTokens",
".",
"audience",
"!==",
"_token",
".",
"aud",
")",
"{",
"waterlock",
".",
"logger",
".",
"debug",
"(",
"'access token rejected, reason: AUDIENCE'",
")",
";",
"return",
"cb",
"(",
"'This token cannot be accepted for this domain.'",
")",
";",
"}",
"this",
".",
"findUserFromToken",
"(",
"_token",
",",
"cb",
")",
";",
"}",
"catch",
"(",
"err",
")",
"{",
"cb",
"(",
"err",
")",
";",
"}",
"}"
] | Validates a token
@param {String} token the token to be validated
@param {Function} cb called when error has occured or token is validated | [
"Validates",
"a",
"token"
] | 088c7f9c641f626e6ebe9de4eec68f7eddf8d094 | https://github.com/waterlock/waterlock/blob/088c7f9c641f626e6ebe9de4eec68f7eddf8d094/lib/validator.js#L20-L51 | |
21,798 | waterlock/waterlock | lib/validator.js | function(token, cb){
// deserialize the token iss
var _iss = token.iss.split('|');
waterlock.User.findOne(_iss[0]).exec(function(err, user){
if(err){
waterlock.logger.debug(err);
}
cb(err, user);
});
} | javascript | function(token, cb){
// deserialize the token iss
var _iss = token.iss.split('|');
waterlock.User.findOne(_iss[0]).exec(function(err, user){
if(err){
waterlock.logger.debug(err);
}
cb(err, user);
});
} | [
"function",
"(",
"token",
",",
"cb",
")",
"{",
"// deserialize the token iss",
"var",
"_iss",
"=",
"token",
".",
"iss",
".",
"split",
"(",
"'|'",
")",
";",
"waterlock",
".",
"User",
".",
"findOne",
"(",
"_iss",
"[",
"0",
"]",
")",
".",
"exec",
"(",
"function",
"(",
"err",
",",
"user",
")",
"{",
"if",
"(",
"err",
")",
"{",
"waterlock",
".",
"logger",
".",
"debug",
"(",
"err",
")",
";",
"}",
"cb",
"(",
"err",
",",
"user",
")",
";",
"}",
")",
";",
"}"
] | Find the user the give token is issued to
@param {Object} token The parsed token
@param {Function} cb Callback to be called when a user is
found or an error has occured | [
"Find",
"the",
"user",
"the",
"give",
"token",
"is",
"issued",
"to"
] | 088c7f9c641f626e6ebe9de4eec68f7eddf8d094 | https://github.com/waterlock/waterlock/blob/088c7f9c641f626e6ebe9de4eec68f7eddf8d094/lib/validator.js#L60-L71 | |
21,799 | waterlock/waterlock | lib/validator.js | function(req, user){
req.session.authenticated = true;
req.session.user = user;
} | javascript | function(req, user){
req.session.authenticated = true;
req.session.user = user;
} | [
"function",
"(",
"req",
",",
"user",
")",
"{",
"req",
".",
"session",
".",
"authenticated",
"=",
"true",
";",
"req",
".",
"session",
".",
"user",
"=",
"user",
";",
"}"
] | Attaches a user object to the Express req session
@param {Express request} req the Express request object
@param {Waterline DAO} user the waterline user object | [
"Attaches",
"a",
"user",
"object",
"to",
"the",
"Express",
"req",
"session"
] | 088c7f9c641f626e6ebe9de4eec68f7eddf8d094 | https://github.com/waterlock/waterlock/blob/088c7f9c641f626e6ebe9de4eec68f7eddf8d094/lib/validator.js#L120-L123 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.