repo
stringlengths 5
67
| path
stringlengths 4
116
| func_name
stringlengths 0
58
| original_string
stringlengths 52
373k
| language
stringclasses 1
value | code
stringlengths 52
373k
| code_tokens
list | docstring
stringlengths 4
11.8k
| docstring_tokens
list | sha
stringlengths 40
40
| url
stringlengths 86
226
| partition
stringclasses 1
value |
---|---|---|---|---|---|---|---|---|---|---|---|
ember-cli/loader.js
|
benchmarks/scenarios/ember.js
|
function (selector) {
var target = _emberViewsSystemJquery.default(selector);
_emberMetalDebug.assert('You tried to replace in (' + selector + ') but that isn\'t in the DOM', target.length > 0);
_emberMetalDebug.assert('You cannot replace an existing Ember.View.', !target.is('.ember-view') && !target.parents().is('.ember-view'));
this.renderer.replaceIn(this, target[0]);
return this;
}
|
javascript
|
function (selector) {
var target = _emberViewsSystemJquery.default(selector);
_emberMetalDebug.assert('You tried to replace in (' + selector + ') but that isn\'t in the DOM', target.length > 0);
_emberMetalDebug.assert('You cannot replace an existing Ember.View.', !target.is('.ember-view') && !target.parents().is('.ember-view'));
this.renderer.replaceIn(this, target[0]);
return this;
}
|
[
"function",
"(",
"selector",
")",
"{",
"var",
"target",
"=",
"_emberViewsSystemJquery",
".",
"default",
"(",
"selector",
")",
";",
"_emberMetalDebug",
".",
"assert",
"(",
"'You tried to replace in ('",
"+",
"selector",
"+",
"') but that isn\\'t in the DOM'",
",",
"\\'",
")",
";",
"target",
".",
"length",
">",
"0",
"_emberMetalDebug",
".",
"assert",
"(",
"'You cannot replace an existing Ember.View.'",
",",
"!",
"target",
".",
"is",
"(",
"'.ember-view'",
")",
"&&",
"!",
"target",
".",
"parents",
"(",
")",
".",
"is",
"(",
"'.ember-view'",
")",
")",
";",
"this",
".",
"renderer",
".",
"replaceIn",
"(",
"this",
",",
"target",
"[",
"0",
"]",
")",
";",
"}"
] |
Replaces the content of the specified parent element with this view's
element. If the view does not have an HTML representation yet,
the element will be generated automatically.
Note that this method just schedules the view to be appended; the DOM
element will not be appended to the given element until all bindings have
finished synchronizing
@method replaceIn
@param {String|DOMElement|jQuery} target A selector, element, HTML string, or jQuery object
@return {Ember.View} received
@private
|
[
"Replaces",
"the",
"content",
"of",
"the",
"specified",
"parent",
"element",
"with",
"this",
"view",
"s",
"element",
".",
"If",
"the",
"view",
"does",
"not",
"have",
"an",
"HTML",
"representation",
"yet",
"the",
"element",
"will",
"be",
"generated",
"automatically",
".",
"Note",
"that",
"this",
"method",
"just",
"schedules",
"the",
"view",
"to",
"be",
"appended",
";",
"the",
"DOM",
"element",
"will",
"not",
"be",
"appended",
"to",
"the",
"given",
"element",
"until",
"all",
"bindings",
"have",
"finished",
"synchronizing"
] |
4fe5b3dfd5e1a30d706d289bb4e5fdbd5a799101
|
https://github.com/ember-cli/loader.js/blob/4fe5b3dfd5e1a30d706d289bb4e5fdbd5a799101/benchmarks/scenarios/ember.js#L45390-L45399
|
train
|
|
ember-cli/loader.js
|
benchmarks/scenarios/ember.js
|
normalizeComponentAttributes
|
function normalizeComponentAttributes(component, isAngleBracket, attrs) {
var normalized = {};
var attributeBindings = component.attributeBindings;
var streamBasePath = component.isComponent ? '' : 'view.';
var i, l;
if (attrs.id && _emberHtmlbarsHooksGetValue.default(attrs.id)) {
// Do not allow binding to the `id`
normalized.id = _emberHtmlbarsHooksGetValue.default(attrs.id);
component.elementId = normalized.id;
} else {
normalized.id = component.elementId;
}
if (attributeBindings) {
for (i = 0, l = attributeBindings.length; i < l; i++) {
var attr = attributeBindings[i];
var colonIndex = attr.indexOf(':');
var attrName, expression;
if (colonIndex !== -1) {
var attrProperty = attr.substring(0, colonIndex);
attrName = attr.substring(colonIndex + 1);
expression = ['get', '' + streamBasePath + attrProperty];
} else if (attrs[attr]) {
// TODO: For compatibility with 1.x, we probably need to `set`
// the component's attribute here if it is a CP, but we also
// probably want to suspend observers and allow the
// willUpdateAttrs logic to trigger observers at the correct time.
attrName = attr;
expression = ['value', attrs[attr]];
} else {
attrName = attr;
expression = ['get', '' + streamBasePath + attr];
}
_emberMetalDebug.assert('You cannot use class as an attributeBinding, use classNameBindings instead.', attrName !== 'class');
normalized[attrName] = expression;
}
}
if (isAngleBracket) {
for (var prop in attrs) {
var val = attrs[prop];
if (!val) {
continue;
}
if (typeof val === 'string' || val.isConcat) {
normalized[prop] = ['value', val];
}
}
}
if (attrs.tagName) {
component.tagName = attrs.tagName;
}
var normalizedClass = normalizeClass(component, attrs, streamBasePath);
if (normalizedClass) {
normalized.class = normalizedClass;
}
if (_emberMetalProperty_get.get(component, 'isVisible') === false) {
var hiddenStyle = ['subexpr', '-html-safe', ['display: none;'], []];
var existingStyle = normalized.style;
if (existingStyle) {
normalized.style = ['subexpr', 'concat', [existingStyle, ' ', hiddenStyle], []];
} else {
normalized.style = hiddenStyle;
}
}
return normalized;
}
|
javascript
|
function normalizeComponentAttributes(component, isAngleBracket, attrs) {
var normalized = {};
var attributeBindings = component.attributeBindings;
var streamBasePath = component.isComponent ? '' : 'view.';
var i, l;
if (attrs.id && _emberHtmlbarsHooksGetValue.default(attrs.id)) {
// Do not allow binding to the `id`
normalized.id = _emberHtmlbarsHooksGetValue.default(attrs.id);
component.elementId = normalized.id;
} else {
normalized.id = component.elementId;
}
if (attributeBindings) {
for (i = 0, l = attributeBindings.length; i < l; i++) {
var attr = attributeBindings[i];
var colonIndex = attr.indexOf(':');
var attrName, expression;
if (colonIndex !== -1) {
var attrProperty = attr.substring(0, colonIndex);
attrName = attr.substring(colonIndex + 1);
expression = ['get', '' + streamBasePath + attrProperty];
} else if (attrs[attr]) {
// TODO: For compatibility with 1.x, we probably need to `set`
// the component's attribute here if it is a CP, but we also
// probably want to suspend observers and allow the
// willUpdateAttrs logic to trigger observers at the correct time.
attrName = attr;
expression = ['value', attrs[attr]];
} else {
attrName = attr;
expression = ['get', '' + streamBasePath + attr];
}
_emberMetalDebug.assert('You cannot use class as an attributeBinding, use classNameBindings instead.', attrName !== 'class');
normalized[attrName] = expression;
}
}
if (isAngleBracket) {
for (var prop in attrs) {
var val = attrs[prop];
if (!val) {
continue;
}
if (typeof val === 'string' || val.isConcat) {
normalized[prop] = ['value', val];
}
}
}
if (attrs.tagName) {
component.tagName = attrs.tagName;
}
var normalizedClass = normalizeClass(component, attrs, streamBasePath);
if (normalizedClass) {
normalized.class = normalizedClass;
}
if (_emberMetalProperty_get.get(component, 'isVisible') === false) {
var hiddenStyle = ['subexpr', '-html-safe', ['display: none;'], []];
var existingStyle = normalized.style;
if (existingStyle) {
normalized.style = ['subexpr', 'concat', [existingStyle, ' ', hiddenStyle], []];
} else {
normalized.style = hiddenStyle;
}
}
return normalized;
}
|
[
"function",
"normalizeComponentAttributes",
"(",
"component",
",",
"isAngleBracket",
",",
"attrs",
")",
"{",
"var",
"normalized",
"=",
"{",
"}",
";",
"var",
"attributeBindings",
"=",
"component",
".",
"attributeBindings",
";",
"var",
"streamBasePath",
"=",
"component",
".",
"isComponent",
"?",
"''",
":",
"'view.'",
";",
"var",
"i",
",",
"l",
";",
"if",
"(",
"attrs",
".",
"id",
"&&",
"_emberHtmlbarsHooksGetValue",
".",
"default",
"(",
"attrs",
".",
"id",
")",
")",
"{",
"normalized",
".",
"id",
"=",
"_emberHtmlbarsHooksGetValue",
".",
"default",
"(",
"attrs",
".",
"id",
")",
";",
"component",
".",
"elementId",
"=",
"normalized",
".",
"id",
";",
"}",
"else",
"{",
"normalized",
".",
"id",
"=",
"component",
".",
"elementId",
";",
"}",
"if",
"(",
"attributeBindings",
")",
"{",
"for",
"(",
"i",
"=",
"0",
",",
"l",
"=",
"attributeBindings",
".",
"length",
";",
"i",
"<",
"l",
";",
"i",
"++",
")",
"{",
"var",
"attr",
"=",
"attributeBindings",
"[",
"i",
"]",
";",
"var",
"colonIndex",
"=",
"attr",
".",
"indexOf",
"(",
"':'",
")",
";",
"var",
"attrName",
",",
"expression",
";",
"if",
"(",
"colonIndex",
"!==",
"-",
"1",
")",
"{",
"var",
"attrProperty",
"=",
"attr",
".",
"substring",
"(",
"0",
",",
"colonIndex",
")",
";",
"attrName",
"=",
"attr",
".",
"substring",
"(",
"colonIndex",
"+",
"1",
")",
";",
"expression",
"=",
"[",
"'get'",
",",
"''",
"+",
"streamBasePath",
"+",
"attrProperty",
"]",
";",
"}",
"else",
"if",
"(",
"attrs",
"[",
"attr",
"]",
")",
"{",
"attrName",
"=",
"attr",
";",
"expression",
"=",
"[",
"'value'",
",",
"attrs",
"[",
"attr",
"]",
"]",
";",
"}",
"else",
"{",
"attrName",
"=",
"attr",
";",
"expression",
"=",
"[",
"'get'",
",",
"''",
"+",
"streamBasePath",
"+",
"attr",
"]",
";",
"}",
"_emberMetalDebug",
".",
"assert",
"(",
"'You cannot use class as an attributeBinding, use classNameBindings instead.'",
",",
"attrName",
"!==",
"'class'",
")",
";",
"normalized",
"[",
"attrName",
"]",
"=",
"expression",
";",
"}",
"}",
"if",
"(",
"isAngleBracket",
")",
"{",
"for",
"(",
"var",
"prop",
"in",
"attrs",
")",
"{",
"var",
"val",
"=",
"attrs",
"[",
"prop",
"]",
";",
"if",
"(",
"!",
"val",
")",
"{",
"continue",
";",
"}",
"if",
"(",
"typeof",
"val",
"===",
"'string'",
"||",
"val",
".",
"isConcat",
")",
"{",
"normalized",
"[",
"prop",
"]",
"=",
"[",
"'value'",
",",
"val",
"]",
";",
"}",
"}",
"}",
"if",
"(",
"attrs",
".",
"tagName",
")",
"{",
"component",
".",
"tagName",
"=",
"attrs",
".",
"tagName",
";",
"}",
"var",
"normalizedClass",
"=",
"normalizeClass",
"(",
"component",
",",
"attrs",
",",
"streamBasePath",
")",
";",
"if",
"(",
"normalizedClass",
")",
"{",
"normalized",
".",
"class",
"=",
"normalizedClass",
";",
"}",
"if",
"(",
"_emberMetalProperty_get",
".",
"get",
"(",
"component",
",",
"'isVisible'",
")",
"===",
"false",
")",
"{",
"var",
"hiddenStyle",
"=",
"[",
"'subexpr'",
",",
"'-html-safe'",
",",
"[",
"'display: none;'",
"]",
",",
"[",
"]",
"]",
";",
"var",
"existingStyle",
"=",
"normalized",
".",
"style",
";",
"if",
"(",
"existingStyle",
")",
"{",
"normalized",
".",
"style",
"=",
"[",
"'subexpr'",
",",
"'concat'",
",",
"[",
"existingStyle",
",",
"' '",
",",
"hiddenStyle",
"]",
",",
"[",
"]",
"]",
";",
"}",
"else",
"{",
"normalized",
".",
"style",
"=",
"hiddenStyle",
";",
"}",
"}",
"return",
"normalized",
";",
"}"
] |
Takes a component and builds a normalized set of attribute bindings consumable by HTMLBars' `attribute` hook.
|
[
"Takes",
"a",
"component",
"and",
"builds",
"a",
"normalized",
"set",
"of",
"attribute",
"bindings",
"consumable",
"by",
"HTMLBars",
"attribute",
"hook",
"."
] |
4fe5b3dfd5e1a30d706d289bb4e5fdbd5a799101
|
https://github.com/ember-cli/loader.js/blob/4fe5b3dfd5e1a30d706d289bb4e5fdbd5a799101/benchmarks/scenarios/ember.js#L46417-L46494
|
train
|
ember-cli/loader.js
|
benchmarks/scenarios/ember.js
|
function (addedEvents, rootElement) {
var event;
var events = this._finalEvents = _emberMetalAssign.default({}, _emberMetalProperty_get.get(this, 'events'), addedEvents);
if (!_emberMetalIs_none.default(rootElement)) {
_emberMetalProperty_set.set(this, 'rootElement', rootElement);
}
rootElement = _emberViewsSystemJquery.default(_emberMetalProperty_get.get(this, 'rootElement'));
_emberMetalDebug.assert('You cannot use the same root element (' + (rootElement.selector || rootElement[0].tagName) + ') multiple times in an Ember.Application', !rootElement.is(ROOT_ELEMENT_SELECTOR));
_emberMetalDebug.assert('You cannot make a new Ember.Application using a root element that is a descendent of an existing Ember.Application', !rootElement.closest(ROOT_ELEMENT_SELECTOR).length);
_emberMetalDebug.assert('You cannot make a new Ember.Application using a root element that is an ancestor of an existing Ember.Application', !rootElement.find(ROOT_ELEMENT_SELECTOR).length);
rootElement.addClass(ROOT_ELEMENT_CLASS);
_emberMetalDebug.assert('Unable to add \'' + ROOT_ELEMENT_CLASS + '\' class to rootElement. Make sure you set rootElement to the body or an element in the body.', rootElement.is(ROOT_ELEMENT_SELECTOR));
for (event in events) {
if (events.hasOwnProperty(event)) {
this.setupHandler(rootElement, event, events[event]);
}
}
}
|
javascript
|
function (addedEvents, rootElement) {
var event;
var events = this._finalEvents = _emberMetalAssign.default({}, _emberMetalProperty_get.get(this, 'events'), addedEvents);
if (!_emberMetalIs_none.default(rootElement)) {
_emberMetalProperty_set.set(this, 'rootElement', rootElement);
}
rootElement = _emberViewsSystemJquery.default(_emberMetalProperty_get.get(this, 'rootElement'));
_emberMetalDebug.assert('You cannot use the same root element (' + (rootElement.selector || rootElement[0].tagName) + ') multiple times in an Ember.Application', !rootElement.is(ROOT_ELEMENT_SELECTOR));
_emberMetalDebug.assert('You cannot make a new Ember.Application using a root element that is a descendent of an existing Ember.Application', !rootElement.closest(ROOT_ELEMENT_SELECTOR).length);
_emberMetalDebug.assert('You cannot make a new Ember.Application using a root element that is an ancestor of an existing Ember.Application', !rootElement.find(ROOT_ELEMENT_SELECTOR).length);
rootElement.addClass(ROOT_ELEMENT_CLASS);
_emberMetalDebug.assert('Unable to add \'' + ROOT_ELEMENT_CLASS + '\' class to rootElement. Make sure you set rootElement to the body or an element in the body.', rootElement.is(ROOT_ELEMENT_SELECTOR));
for (event in events) {
if (events.hasOwnProperty(event)) {
this.setupHandler(rootElement, event, events[event]);
}
}
}
|
[
"function",
"(",
"addedEvents",
",",
"rootElement",
")",
"{",
"var",
"event",
";",
"var",
"events",
"=",
"this",
".",
"_finalEvents",
"=",
"_emberMetalAssign",
".",
"default",
"(",
"{",
"}",
",",
"_emberMetalProperty_get",
".",
"get",
"(",
"this",
",",
"'events'",
")",
",",
"addedEvents",
")",
";",
"if",
"(",
"!",
"_emberMetalIs_none",
".",
"default",
"(",
"rootElement",
")",
")",
"{",
"_emberMetalProperty_set",
".",
"set",
"(",
"this",
",",
"'rootElement'",
",",
"rootElement",
")",
";",
"}",
"rootElement",
"=",
"_emberViewsSystemJquery",
".",
"default",
"(",
"_emberMetalProperty_get",
".",
"get",
"(",
"this",
",",
"'rootElement'",
")",
")",
";",
"_emberMetalDebug",
".",
"assert",
"(",
"'You cannot use the same root element ('",
"+",
"(",
"rootElement",
".",
"selector",
"||",
"rootElement",
"[",
"0",
"]",
".",
"tagName",
")",
"+",
"') multiple times in an Ember.Application'",
",",
"!",
"rootElement",
".",
"is",
"(",
"ROOT_ELEMENT_SELECTOR",
")",
")",
";",
"_emberMetalDebug",
".",
"assert",
"(",
"'You cannot make a new Ember.Application using a root element that is a descendent of an existing Ember.Application'",
",",
"!",
"rootElement",
".",
"closest",
"(",
"ROOT_ELEMENT_SELECTOR",
")",
".",
"length",
")",
";",
"_emberMetalDebug",
".",
"assert",
"(",
"'You cannot make a new Ember.Application using a root element that is an ancestor of an existing Ember.Application'",
",",
"!",
"rootElement",
".",
"find",
"(",
"ROOT_ELEMENT_SELECTOR",
")",
".",
"length",
")",
";",
"rootElement",
".",
"addClass",
"(",
"ROOT_ELEMENT_CLASS",
")",
";",
"_emberMetalDebug",
".",
"assert",
"(",
"'Unable to add \\''",
"+",
"\\'",
"+",
"ROOT_ELEMENT_CLASS",
",",
"'\\' class to rootElement. Make sure you set rootElement to the body or an element in the body.'",
")",
";",
"\\'",
"}"
] |
Sets up event listeners for standard browser events.
This will be called after the browser sends a `DOMContentReady` event. By
default, it will set up all of the listeners on the document body. If you
would like to register the listeners on a different element, set the event
dispatcher's `root` property.
@private
@method setup
@param addedEvents {Object}
|
[
"Sets",
"up",
"event",
"listeners",
"for",
"standard",
"browser",
"events",
".",
"This",
"will",
"be",
"called",
"after",
"the",
"browser",
"sends",
"a",
"DOMContentReady",
"event",
".",
"By",
"default",
"it",
"will",
"set",
"up",
"all",
"of",
"the",
"listeners",
"on",
"the",
"document",
"body",
".",
"If",
"you",
"would",
"like",
"to",
"register",
"the",
"listeners",
"on",
"a",
"different",
"element",
"set",
"the",
"event",
"dispatcher",
"s",
"root",
"property",
"."
] |
4fe5b3dfd5e1a30d706d289bb4e5fdbd5a799101
|
https://github.com/ember-cli/loader.js/blob/4fe5b3dfd5e1a30d706d289bb4e5fdbd5a799101/benchmarks/scenarios/ember.js#L46700-L46723
|
train
|
|
ember-cli/loader.js
|
benchmarks/scenarios/ember.js
|
function (rootElement, event, eventName) {
var self = this;
var owner = _containerOwner.getOwner(this);
var viewRegistry = owner && owner.lookup('-view-registry:main') || _emberViewsViewsView.default.views;
if (eventName === null) {
return;
}
rootElement.on(event + '.ember', '.ember-view', function (evt, triggeringManager) {
var view = viewRegistry[this.id];
var result = true;
var manager = self.canDispatchToEventManager ? self._findNearestEventManager(view, eventName) : null;
if (manager && manager !== triggeringManager) {
result = self._dispatchEvent(manager, evt, eventName, view);
} else if (view) {
result = self._bubbleEvent(view, evt, eventName);
}
return result;
});
rootElement.on(event + '.ember', '[data-ember-action]', function (evt) {
var actionId = _emberViewsSystemJquery.default(evt.currentTarget).attr('data-ember-action');
var actions = _emberViewsSystemAction_manager.default.registeredActions[actionId];
// We have to check for actions here since in some cases, jQuery will trigger
// an event on `removeChild` (i.e. focusout) after we've already torn down the
// action handlers for the view.
if (!actions) {
return;
}
for (var index = 0, _length = actions.length; index < _length; index++) {
var action = actions[index];
if (action && action.eventName === eventName) {
return action.handler(evt);
}
}
});
}
|
javascript
|
function (rootElement, event, eventName) {
var self = this;
var owner = _containerOwner.getOwner(this);
var viewRegistry = owner && owner.lookup('-view-registry:main') || _emberViewsViewsView.default.views;
if (eventName === null) {
return;
}
rootElement.on(event + '.ember', '.ember-view', function (evt, triggeringManager) {
var view = viewRegistry[this.id];
var result = true;
var manager = self.canDispatchToEventManager ? self._findNearestEventManager(view, eventName) : null;
if (manager && manager !== triggeringManager) {
result = self._dispatchEvent(manager, evt, eventName, view);
} else if (view) {
result = self._bubbleEvent(view, evt, eventName);
}
return result;
});
rootElement.on(event + '.ember', '[data-ember-action]', function (evt) {
var actionId = _emberViewsSystemJquery.default(evt.currentTarget).attr('data-ember-action');
var actions = _emberViewsSystemAction_manager.default.registeredActions[actionId];
// We have to check for actions here since in some cases, jQuery will trigger
// an event on `removeChild` (i.e. focusout) after we've already torn down the
// action handlers for the view.
if (!actions) {
return;
}
for (var index = 0, _length = actions.length; index < _length; index++) {
var action = actions[index];
if (action && action.eventName === eventName) {
return action.handler(evt);
}
}
});
}
|
[
"function",
"(",
"rootElement",
",",
"event",
",",
"eventName",
")",
"{",
"var",
"self",
"=",
"this",
";",
"var",
"owner",
"=",
"_containerOwner",
".",
"getOwner",
"(",
"this",
")",
";",
"var",
"viewRegistry",
"=",
"owner",
"&&",
"owner",
".",
"lookup",
"(",
"'-view-registry:main'",
")",
"||",
"_emberViewsViewsView",
".",
"default",
".",
"views",
";",
"if",
"(",
"eventName",
"===",
"null",
")",
"{",
"return",
";",
"}",
"rootElement",
".",
"on",
"(",
"event",
"+",
"'.ember'",
",",
"'.ember-view'",
",",
"function",
"(",
"evt",
",",
"triggeringManager",
")",
"{",
"var",
"view",
"=",
"viewRegistry",
"[",
"this",
".",
"id",
"]",
";",
"var",
"result",
"=",
"true",
";",
"var",
"manager",
"=",
"self",
".",
"canDispatchToEventManager",
"?",
"self",
".",
"_findNearestEventManager",
"(",
"view",
",",
"eventName",
")",
":",
"null",
";",
"if",
"(",
"manager",
"&&",
"manager",
"!==",
"triggeringManager",
")",
"{",
"result",
"=",
"self",
".",
"_dispatchEvent",
"(",
"manager",
",",
"evt",
",",
"eventName",
",",
"view",
")",
";",
"}",
"else",
"if",
"(",
"view",
")",
"{",
"result",
"=",
"self",
".",
"_bubbleEvent",
"(",
"view",
",",
"evt",
",",
"eventName",
")",
";",
"}",
"return",
"result",
";",
"}",
")",
";",
"rootElement",
".",
"on",
"(",
"event",
"+",
"'.ember'",
",",
"'[data-ember-action]'",
",",
"function",
"(",
"evt",
")",
"{",
"var",
"actionId",
"=",
"_emberViewsSystemJquery",
".",
"default",
"(",
"evt",
".",
"currentTarget",
")",
".",
"attr",
"(",
"'data-ember-action'",
")",
";",
"var",
"actions",
"=",
"_emberViewsSystemAction_manager",
".",
"default",
".",
"registeredActions",
"[",
"actionId",
"]",
";",
"if",
"(",
"!",
"actions",
")",
"{",
"return",
";",
"}",
"for",
"(",
"var",
"index",
"=",
"0",
",",
"_length",
"=",
"actions",
".",
"length",
";",
"index",
"<",
"_length",
";",
"index",
"++",
")",
"{",
"var",
"action",
"=",
"actions",
"[",
"index",
"]",
";",
"if",
"(",
"action",
"&&",
"action",
".",
"eventName",
"===",
"eventName",
")",
"{",
"return",
"action",
".",
"handler",
"(",
"evt",
")",
";",
"}",
"}",
"}",
")",
";",
"}"
] |
Registers an event listener on the rootElement. If the given event is
triggered, the provided event handler will be triggered on the target view.
If the target view does not implement the event handler, or if the handler
returns `false`, the parent view will be called. The event will continue to
bubble to each successive parent view until it reaches the top.
@private
@method setupHandler
@param {Element} rootElement
@param {String} event the browser-originated event to listen to
@param {String} eventName the name of the method to call on the view
|
[
"Registers",
"an",
"event",
"listener",
"on",
"the",
"rootElement",
".",
"If",
"the",
"given",
"event",
"is",
"triggered",
"the",
"provided",
"event",
"handler",
"will",
"be",
"triggered",
"on",
"the",
"target",
"view",
".",
"If",
"the",
"target",
"view",
"does",
"not",
"implement",
"the",
"event",
"handler",
"or",
"if",
"the",
"handler",
"returns",
"false",
"the",
"parent",
"view",
"will",
"be",
"called",
".",
"The",
"event",
"will",
"continue",
"to",
"bubble",
"to",
"each",
"successive",
"parent",
"view",
"until",
"it",
"reaches",
"the",
"top",
"."
] |
4fe5b3dfd5e1a30d706d289bb4e5fdbd5a799101
|
https://github.com/ember-cli/loader.js/blob/4fe5b3dfd5e1a30d706d289bb4e5fdbd5a799101/benchmarks/scenarios/ember.js#L46737-L46781
|
train
|
|
ember-cli/loader.js
|
benchmarks/scenarios/ember.js
|
function () {
this._super.apply(this, arguments);
var name = arguments[0];
var method = this[name];
if (method) {
var length = arguments.length;
var args = new Array(length - 1);
for (var i = 1; i < length; i++) {
args[i - 1] = arguments[i];
}
return method.apply(this, args);
}
}
|
javascript
|
function () {
this._super.apply(this, arguments);
var name = arguments[0];
var method = this[name];
if (method) {
var length = arguments.length;
var args = new Array(length - 1);
for (var i = 1; i < length; i++) {
args[i - 1] = arguments[i];
}
return method.apply(this, args);
}
}
|
[
"function",
"(",
")",
"{",
"this",
".",
"_super",
".",
"apply",
"(",
"this",
",",
"arguments",
")",
";",
"var",
"name",
"=",
"arguments",
"[",
"0",
"]",
";",
"var",
"method",
"=",
"this",
"[",
"name",
"]",
";",
"if",
"(",
"method",
")",
"{",
"var",
"length",
"=",
"arguments",
".",
"length",
";",
"var",
"args",
"=",
"new",
"Array",
"(",
"length",
"-",
"1",
")",
";",
"for",
"(",
"var",
"i",
"=",
"1",
";",
"i",
"<",
"length",
";",
"i",
"++",
")",
"{",
"args",
"[",
"i",
"-",
"1",
"]",
"=",
"arguments",
"[",
"i",
"]",
";",
"}",
"return",
"method",
".",
"apply",
"(",
"this",
",",
"args",
")",
";",
"}",
"}"
] |
Override the default event firing from `Ember.Evented` to
also call methods with the given name.
@method trigger
@param name {String}
@private
|
[
"Override",
"the",
"default",
"event",
"firing",
"from",
"Ember",
".",
"Evented",
"to",
"also",
"call",
"methods",
"with",
"the",
"given",
"name",
"."
] |
4fe5b3dfd5e1a30d706d289bb4e5fdbd5a799101
|
https://github.com/ember-cli/loader.js/blob/4fe5b3dfd5e1a30d706d289bb4e5fdbd5a799101/benchmarks/scenarios/ember.js#L47121-L47133
|
train
|
|
ember-cli/loader.js
|
benchmarks/scenarios/ember.js
|
function (view, eventName, event) {
if (view.has(eventName)) {
// Handler should be able to re-dispatch events, so we don't
// preventDefault or stopPropagation.
return _emberMetalInstrumentation.flaggedInstrument('interaction.' + eventName, { event: event, view: view }, function () {
return _emberMetalRun_loop.default.join(view, view.trigger, eventName, event);
});
} else {
return true; // continue event propagation
}
}
|
javascript
|
function (view, eventName, event) {
if (view.has(eventName)) {
// Handler should be able to re-dispatch events, so we don't
// preventDefault or stopPropagation.
return _emberMetalInstrumentation.flaggedInstrument('interaction.' + eventName, { event: event, view: view }, function () {
return _emberMetalRun_loop.default.join(view, view.trigger, eventName, event);
});
} else {
return true; // continue event propagation
}
}
|
[
"function",
"(",
"view",
",",
"eventName",
",",
"event",
")",
"{",
"if",
"(",
"view",
".",
"has",
"(",
"eventName",
")",
")",
"{",
"return",
"_emberMetalInstrumentation",
".",
"flaggedInstrument",
"(",
"'interaction.'",
"+",
"eventName",
",",
"{",
"event",
":",
"event",
",",
"view",
":",
"view",
"}",
",",
"function",
"(",
")",
"{",
"return",
"_emberMetalRun_loop",
".",
"default",
".",
"join",
"(",
"view",
",",
"view",
".",
"trigger",
",",
"eventName",
",",
"event",
")",
";",
"}",
")",
";",
"}",
"else",
"{",
"return",
"true",
";",
"}",
"}"
] |
Handle events from `Ember.EventDispatcher`
|
[
"Handle",
"events",
"from",
"Ember",
".",
"EventDispatcher"
] |
4fe5b3dfd5e1a30d706d289bb4e5fdbd5a799101
|
https://github.com/ember-cli/loader.js/blob/4fe5b3dfd5e1a30d706d289bb4e5fdbd5a799101/benchmarks/scenarios/ember.js#L47294-L47304
|
train
|
|
ember-cli/loader.js
|
benchmarks/scenarios/ember.js
|
function (parsedPath) {
return View._classStringForValue(parsedPath.path, parsedPath.stream.value(), parsedPath.className, parsedPath.falsyClassName);
}
|
javascript
|
function (parsedPath) {
return View._classStringForValue(parsedPath.path, parsedPath.stream.value(), parsedPath.className, parsedPath.falsyClassName);
}
|
[
"function",
"(",
"parsedPath",
")",
"{",
"return",
"View",
".",
"_classStringForValue",
"(",
"parsedPath",
".",
"path",
",",
"parsedPath",
".",
"stream",
".",
"value",
"(",
")",
",",
"parsedPath",
".",
"className",
",",
"parsedPath",
".",
"falsyClassName",
")",
";",
"}"
] |
Given a property name, returns a dasherized version of that
property name if the property evaluates to a non-falsy value.
For example, if the view has property `isUrgent` that evaluates to true,
passing `isUrgent` to this method will return `"is-urgent"`.
@method _classStringForProperty
@param property
@private
|
[
"Given",
"a",
"property",
"name",
"returns",
"a",
"dasherized",
"version",
"of",
"that",
"property",
"name",
"if",
"the",
"property",
"evaluates",
"to",
"a",
"non",
"-",
"falsy",
"value",
".",
"For",
"example",
"if",
"the",
"view",
"has",
"property",
"isUrgent",
"that",
"evaluates",
"to",
"true",
"passing",
"isUrgent",
"to",
"this",
"method",
"will",
"return",
"is",
"-",
"urgent",
"."
] |
4fe5b3dfd5e1a30d706d289bb4e5fdbd5a799101
|
https://github.com/ember-cli/loader.js/blob/4fe5b3dfd5e1a30d706d289bb4e5fdbd5a799101/benchmarks/scenarios/ember.js#L48225-L48227
|
train
|
|
ember-cli/loader.js
|
benchmarks/scenarios/ember.js
|
wrap
|
function wrap(template) {
if (template === null) {
return null;
}
return {
meta: template.meta,
arity: template.arity,
raw: template,
render: function (self, env, options, blockArguments) {
var scope = env.hooks.createFreshScope();
var contextualElement = options && options.contextualElement;
var renderOptions = new _htmlbarsRuntimeRender.RenderOptions(null, self, blockArguments, contextualElement);
return _htmlbarsRuntimeRender.default(template, env, scope, renderOptions);
}
};
}
|
javascript
|
function wrap(template) {
if (template === null) {
return null;
}
return {
meta: template.meta,
arity: template.arity,
raw: template,
render: function (self, env, options, blockArguments) {
var scope = env.hooks.createFreshScope();
var contextualElement = options && options.contextualElement;
var renderOptions = new _htmlbarsRuntimeRender.RenderOptions(null, self, blockArguments, contextualElement);
return _htmlbarsRuntimeRender.default(template, env, scope, renderOptions);
}
};
}
|
[
"function",
"wrap",
"(",
"template",
")",
"{",
"if",
"(",
"template",
"===",
"null",
")",
"{",
"return",
"null",
";",
"}",
"return",
"{",
"meta",
":",
"template",
".",
"meta",
",",
"arity",
":",
"template",
".",
"arity",
",",
"raw",
":",
"template",
",",
"render",
":",
"function",
"(",
"self",
",",
"env",
",",
"options",
",",
"blockArguments",
")",
"{",
"var",
"scope",
"=",
"env",
".",
"hooks",
".",
"createFreshScope",
"(",
")",
";",
"var",
"contextualElement",
"=",
"options",
"&&",
"options",
".",
"contextualElement",
";",
"var",
"renderOptions",
"=",
"new",
"_htmlbarsRuntimeRender",
".",
"RenderOptions",
"(",
"null",
",",
"self",
",",
"blockArguments",
",",
"contextualElement",
")",
";",
"return",
"_htmlbarsRuntimeRender",
".",
"default",
"(",
"template",
",",
"env",
",",
"scope",
",",
"renderOptions",
")",
";",
"}",
"}",
";",
"}"
] |
HTMLBars delegates the runtime behavior of a template to
hooks provided by the host environment. These hooks explain
the lexical environment of a Handlebars template, the internal
representation of references, and the interaction between an
HTMLBars template and the DOM it is managing.
While HTMLBars host hooks have access to all of this internal
machinery, templates and helpers have access to the abstraction
provided by the host hooks.
## The Lexical Environment
The default lexical environment of an HTMLBars template includes:
Any local variables, provided by *block arguments*
The current value of `self`
## Simple Nesting
Let's look at a simple template with a nested block:
```hbs
<h1>{{title}}</h1>
{{#if author}}
<p class="byline">{{author}}</p>
{{/if}}
```
In this case, the lexical environment at the top-level of the
template does not change inside of the `if` block. This is
achieved via an implementation of `if` that looks like this:
```js
registerHelper('if', function(params) {
if (!!params[0]) {
return this.yield();
}
});
```
A call to `this.yield` invokes the child template using the
current lexical environment.
## Block Arguments
It is possible for nested blocks to introduce new local
variables:
```hbs
{{#count-calls as |i|}}
<h1>{{title}}</h1>
<p>Called {{i}} times</p>
{{/count}}
```
In this example, the child block inherits its surrounding
lexical environment, but augments it with a single new
variable binding.
The implementation of `count-calls` supplies the value of
`i`, but does not otherwise alter the environment:
```js
var count = 0;
registerHelper('count-calls', function() {
return this.yield([ ++count ]);
});
```
|
[
"HTMLBars",
"delegates",
"the",
"runtime",
"behavior",
"of",
"a",
"template",
"to",
"hooks",
"provided",
"by",
"the",
"host",
"environment",
".",
"These",
"hooks",
"explain",
"the",
"lexical",
"environment",
"of",
"a",
"Handlebars",
"template",
"the",
"internal",
"representation",
"of",
"references",
"and",
"the",
"interaction",
"between",
"an",
"HTMLBars",
"template",
"and",
"the",
"DOM",
"it",
"is",
"managing",
"."
] |
4fe5b3dfd5e1a30d706d289bb4e5fdbd5a799101
|
https://github.com/ember-cli/loader.js/blob/4fe5b3dfd5e1a30d706d289bb4e5fdbd5a799101/benchmarks/scenarios/ember.js#L48486-L48504
|
train
|
ember-cli/loader.js
|
benchmarks/scenarios/ember.js
|
advanceToKey
|
function advanceToKey(key) {
var seek = currentMorph;
while (seek.key !== key) {
candidates[seek.key] = seek;
seek = seek.nextMorph;
}
currentMorph = seek.nextMorph;
return seek;
}
|
javascript
|
function advanceToKey(key) {
var seek = currentMorph;
while (seek.key !== key) {
candidates[seek.key] = seek;
seek = seek.nextMorph;
}
currentMorph = seek.nextMorph;
return seek;
}
|
[
"function",
"advanceToKey",
"(",
"key",
")",
"{",
"var",
"seek",
"=",
"currentMorph",
";",
"while",
"(",
"seek",
".",
"key",
"!==",
"key",
")",
"{",
"candidates",
"[",
"seek",
".",
"key",
"]",
"=",
"seek",
";",
"seek",
"=",
"seek",
".",
"nextMorph",
";",
"}",
"currentMorph",
"=",
"seek",
".",
"nextMorph",
";",
"return",
"seek",
";",
"}"
] |
Advances the currentMorph pointer to the morph in the previously-rendered list that matches the yielded key. While doing so, it marks any morphs that it advances past as candidates for deletion. Assuming those morphs are not yielded in later, they will be removed in the prune step during cleanup. Note that this helper function assumes that the morph being seeked to is guaranteed to exist in the previous MorphList; if this is called and the morph does not exist, it will result in an infinite loop
|
[
"Advances",
"the",
"currentMorph",
"pointer",
"to",
"the",
"morph",
"in",
"the",
"previously",
"-",
"rendered",
"list",
"that",
"matches",
"the",
"yielded",
"key",
".",
"While",
"doing",
"so",
"it",
"marks",
"any",
"morphs",
"that",
"it",
"advances",
"past",
"as",
"candidates",
"for",
"deletion",
".",
"Assuming",
"those",
"morphs",
"are",
"not",
"yielded",
"in",
"later",
"they",
"will",
"be",
"removed",
"in",
"the",
"prune",
"step",
"during",
"cleanup",
".",
"Note",
"that",
"this",
"helper",
"function",
"assumes",
"that",
"the",
"morph",
"being",
"seeked",
"to",
"is",
"guaranteed",
"to",
"exist",
"in",
"the",
"previous",
"MorphList",
";",
"if",
"this",
"is",
"called",
"and",
"the",
"morph",
"does",
"not",
"exist",
"it",
"will",
"result",
"in",
"an",
"infinite",
"loop"
] |
4fe5b3dfd5e1a30d706d289bb4e5fdbd5a799101
|
https://github.com/ember-cli/loader.js/blob/4fe5b3dfd5e1a30d706d289bb4e5fdbd5a799101/benchmarks/scenarios/ember.js#L48594-L48604
|
train
|
ember-cli/loader.js
|
benchmarks/scenarios/ember.js
|
Morph
|
function Morph(domHelper, contextualElement) {
this.domHelper = domHelper;
// context if content if current content is detached
this.contextualElement = contextualElement;
// inclusive range of morph
// these should be nodeType 1, 3, or 8
this.firstNode = null;
this.lastNode = null;
// flag to force text to setContent to be treated as html
this.parseTextAsHTML = false;
// morph list graph
this.parentMorphList = null;
this.previousMorph = null;
this.nextMorph = null;
}
|
javascript
|
function Morph(domHelper, contextualElement) {
this.domHelper = domHelper;
// context if content if current content is detached
this.contextualElement = contextualElement;
// inclusive range of morph
// these should be nodeType 1, 3, or 8
this.firstNode = null;
this.lastNode = null;
// flag to force text to setContent to be treated as html
this.parseTextAsHTML = false;
// morph list graph
this.parentMorphList = null;
this.previousMorph = null;
this.nextMorph = null;
}
|
[
"function",
"Morph",
"(",
"domHelper",
",",
"contextualElement",
")",
"{",
"this",
".",
"domHelper",
"=",
"domHelper",
";",
"this",
".",
"contextualElement",
"=",
"contextualElement",
";",
"this",
".",
"firstNode",
"=",
"null",
";",
"this",
".",
"lastNode",
"=",
"null",
";",
"this",
".",
"parseTextAsHTML",
"=",
"false",
";",
"this",
".",
"parentMorphList",
"=",
"null",
";",
"this",
".",
"previousMorph",
"=",
"null",
";",
"this",
".",
"nextMorph",
"=",
"null",
";",
"}"
] |
constructor just initializes the fields use one of the static initializers to create a valid morph.
|
[
"constructor",
"just",
"initializes",
"the",
"fields",
"use",
"one",
"of",
"the",
"static",
"initializers",
"to",
"create",
"a",
"valid",
"morph",
"."
] |
4fe5b3dfd5e1a30d706d289bb4e5fdbd5a799101
|
https://github.com/ember-cli/loader.js/blob/4fe5b3dfd5e1a30d706d289bb4e5fdbd5a799101/benchmarks/scenarios/ember.js#L51201-L51217
|
train
|
ember-cli/loader.js
|
benchmarks/scenarios/ember.js
|
ReferenceIterator
|
function ReferenceIterator(iterable) {
_classCallCheck(this, ReferenceIterator);
this.iterator = null;
var artifacts = new IterationArtifacts(iterable);
this.artifacts = artifacts;
}
|
javascript
|
function ReferenceIterator(iterable) {
_classCallCheck(this, ReferenceIterator);
this.iterator = null;
var artifacts = new IterationArtifacts(iterable);
this.artifacts = artifacts;
}
|
[
"function",
"ReferenceIterator",
"(",
"iterable",
")",
"{",
"_classCallCheck",
"(",
"this",
",",
"ReferenceIterator",
")",
";",
"this",
".",
"iterator",
"=",
"null",
";",
"var",
"artifacts",
"=",
"new",
"IterationArtifacts",
"(",
"iterable",
")",
";",
"this",
".",
"artifacts",
"=",
"artifacts",
";",
"}"
] |
if anyone needs to construct this object with something other than an iterable, let @wycats know.
|
[
"if",
"anyone",
"needs",
"to",
"construct",
"this",
"object",
"with",
"something",
"other",
"than",
"an",
"iterable",
"let"
] |
4fe5b3dfd5e1a30d706d289bb4e5fdbd5a799101
|
https://github.com/ember-cli/loader.js/blob/4fe5b3dfd5e1a30d706d289bb4e5fdbd5a799101/benchmarks/scenarios/ember.js#L51675-L51681
|
train
|
ember-cli/loader.js
|
benchmarks/scenarios/ember.js
|
function (ch) {
// DEBUG "Processing `" + ch + "`:"
var nextStates = this.nextStates,
child,
charSpec,
chars;
// DEBUG " " + debugState(this)
var returned = [];
for (var i = 0, l = nextStates.length; i < l; i++) {
child = nextStates[i];
charSpec = child.charSpec;
if (typeof (chars = charSpec.validChars) !== 'undefined') {
if (chars.indexOf(ch) !== -1) {
returned.push(child);
}
} else if (typeof (chars = charSpec.invalidChars) !== 'undefined') {
if (chars.indexOf(ch) === -1) {
returned.push(child);
}
}
}
return returned;
}
|
javascript
|
function (ch) {
// DEBUG "Processing `" + ch + "`:"
var nextStates = this.nextStates,
child,
charSpec,
chars;
// DEBUG " " + debugState(this)
var returned = [];
for (var i = 0, l = nextStates.length; i < l; i++) {
child = nextStates[i];
charSpec = child.charSpec;
if (typeof (chars = charSpec.validChars) !== 'undefined') {
if (chars.indexOf(ch) !== -1) {
returned.push(child);
}
} else if (typeof (chars = charSpec.invalidChars) !== 'undefined') {
if (chars.indexOf(ch) === -1) {
returned.push(child);
}
}
}
return returned;
}
|
[
"function",
"(",
"ch",
")",
"{",
"var",
"nextStates",
"=",
"this",
".",
"nextStates",
",",
"child",
",",
"charSpec",
",",
"chars",
";",
"var",
"returned",
"=",
"[",
"]",
";",
"for",
"(",
"var",
"i",
"=",
"0",
",",
"l",
"=",
"nextStates",
".",
"length",
";",
"i",
"<",
"l",
";",
"i",
"++",
")",
"{",
"child",
"=",
"nextStates",
"[",
"i",
"]",
";",
"charSpec",
"=",
"child",
".",
"charSpec",
";",
"if",
"(",
"typeof",
"(",
"chars",
"=",
"charSpec",
".",
"validChars",
")",
"!==",
"'undefined'",
")",
"{",
"if",
"(",
"chars",
".",
"indexOf",
"(",
"ch",
")",
"!==",
"-",
"1",
")",
"{",
"returned",
".",
"push",
"(",
"child",
")",
";",
"}",
"}",
"else",
"if",
"(",
"typeof",
"(",
"chars",
"=",
"charSpec",
".",
"invalidChars",
")",
"!==",
"'undefined'",
")",
"{",
"if",
"(",
"chars",
".",
"indexOf",
"(",
"ch",
")",
"===",
"-",
"1",
")",
"{",
"returned",
".",
"push",
"(",
"child",
")",
";",
"}",
"}",
"}",
"return",
"returned",
";",
"}"
] |
Find a list of child states matching the next character
|
[
"Find",
"a",
"list",
"of",
"child",
"states",
"matching",
"the",
"next",
"character"
] |
4fe5b3dfd5e1a30d706d289bb4e5fdbd5a799101
|
https://github.com/ember-cli/loader.js/blob/4fe5b3dfd5e1a30d706d289bb4e5fdbd5a799101/benchmarks/scenarios/ember.js#L61012-L61039
|
train
|
|
ember-cli/loader.js
|
benchmarks/scenarios/ember.js
|
function (handlerName) {
var partitionedArgs = _routerUtils.extractQueryParams(_routerUtils.slice.call(arguments, 1)),
suppliedParams = partitionedArgs[0],
queryParams = partitionedArgs[1];
// Construct a TransitionIntent with the provided params
// and apply it to the present state of the router.
var intent = new _routerTransitionIntentNamedTransitionIntent.default({ name: handlerName, contexts: suppliedParams });
var state = intent.applyToState(this.state, this.recognizer, this.getHandler);
var params = {};
for (var i = 0, len = state.handlerInfos.length; i < len; ++i) {
var handlerInfo = state.handlerInfos[i];
var handlerParams = handlerInfo.serialize();
_routerUtils.merge(params, handlerParams);
}
params.queryParams = queryParams;
return this.recognizer.generate(handlerName, params);
}
|
javascript
|
function (handlerName) {
var partitionedArgs = _routerUtils.extractQueryParams(_routerUtils.slice.call(arguments, 1)),
suppliedParams = partitionedArgs[0],
queryParams = partitionedArgs[1];
// Construct a TransitionIntent with the provided params
// and apply it to the present state of the router.
var intent = new _routerTransitionIntentNamedTransitionIntent.default({ name: handlerName, contexts: suppliedParams });
var state = intent.applyToState(this.state, this.recognizer, this.getHandler);
var params = {};
for (var i = 0, len = state.handlerInfos.length; i < len; ++i) {
var handlerInfo = state.handlerInfos[i];
var handlerParams = handlerInfo.serialize();
_routerUtils.merge(params, handlerParams);
}
params.queryParams = queryParams;
return this.recognizer.generate(handlerName, params);
}
|
[
"function",
"(",
"handlerName",
")",
"{",
"var",
"partitionedArgs",
"=",
"_routerUtils",
".",
"extractQueryParams",
"(",
"_routerUtils",
".",
"slice",
".",
"call",
"(",
"arguments",
",",
"1",
")",
")",
",",
"suppliedParams",
"=",
"partitionedArgs",
"[",
"0",
"]",
",",
"queryParams",
"=",
"partitionedArgs",
"[",
"1",
"]",
";",
"var",
"intent",
"=",
"new",
"_routerTransitionIntentNamedTransitionIntent",
".",
"default",
"(",
"{",
"name",
":",
"handlerName",
",",
"contexts",
":",
"suppliedParams",
"}",
")",
";",
"var",
"state",
"=",
"intent",
".",
"applyToState",
"(",
"this",
".",
"state",
",",
"this",
".",
"recognizer",
",",
"this",
".",
"getHandler",
")",
";",
"var",
"params",
"=",
"{",
"}",
";",
"for",
"(",
"var",
"i",
"=",
"0",
",",
"len",
"=",
"state",
".",
"handlerInfos",
".",
"length",
";",
"i",
"<",
"len",
";",
"++",
"i",
")",
"{",
"var",
"handlerInfo",
"=",
"state",
".",
"handlerInfos",
"[",
"i",
"]",
";",
"var",
"handlerParams",
"=",
"handlerInfo",
".",
"serialize",
"(",
")",
";",
"_routerUtils",
".",
"merge",
"(",
"params",
",",
"handlerParams",
")",
";",
"}",
"params",
".",
"queryParams",
"=",
"queryParams",
";",
"return",
"this",
".",
"recognizer",
".",
"generate",
"(",
"handlerName",
",",
"params",
")",
";",
"}"
] |
Take a named route and context objects and generate a
URL.
@param {String} name the name of the route to generate
a URL for
@param {...Object} objects a list of objects to serialize
@return {String} a URL
|
[
"Take",
"a",
"named",
"route",
"and",
"context",
"objects",
"and",
"generate",
"a",
"URL",
"."
] |
4fe5b3dfd5e1a30d706d289bb4e5fdbd5a799101
|
https://github.com/ember-cli/loader.js/blob/4fe5b3dfd5e1a30d706d289bb4e5fdbd5a799101/benchmarks/scenarios/ember.js#L61957-L61977
|
train
|
|
ember-cli/loader.js
|
benchmarks/scenarios/ember.js
|
function () {
if (this.isAborted) {
return this;
}
_routerUtils.log(this.router, this.sequence, this.targetName + ": transition was aborted");
this.intent.preTransitionState = this.router.state;
this.isAborted = true;
this.isActive = false;
this.router.activeTransition = null;
return this;
}
|
javascript
|
function () {
if (this.isAborted) {
return this;
}
_routerUtils.log(this.router, this.sequence, this.targetName + ": transition was aborted");
this.intent.preTransitionState = this.router.state;
this.isAborted = true;
this.isActive = false;
this.router.activeTransition = null;
return this;
}
|
[
"function",
"(",
")",
"{",
"if",
"(",
"this",
".",
"isAborted",
")",
"{",
"return",
"this",
";",
"}",
"_routerUtils",
".",
"log",
"(",
"this",
".",
"router",
",",
"this",
".",
"sequence",
",",
"this",
".",
"targetName",
"+",
"\": transition was aborted\"",
")",
";",
"this",
".",
"intent",
".",
"preTransitionState",
"=",
"this",
".",
"router",
".",
"state",
";",
"this",
".",
"isAborted",
"=",
"true",
";",
"this",
".",
"isActive",
"=",
"false",
";",
"this",
".",
"router",
".",
"activeTransition",
"=",
"null",
";",
"return",
"this",
";",
"}"
] |
Aborts the Transition. Note you can also implicitly abort a transition
by initiating another transition while a previous one is underway.
@method abort
@return {Transition} this transition
@public
|
[
"Aborts",
"the",
"Transition",
".",
"Note",
"you",
"can",
"also",
"implicitly",
"abort",
"a",
"transition",
"by",
"initiating",
"another",
"transition",
"while",
"a",
"previous",
"one",
"is",
"underway",
"."
] |
4fe5b3dfd5e1a30d706d289bb4e5fdbd5a799101
|
https://github.com/ember-cli/loader.js/blob/4fe5b3dfd5e1a30d706d289bb4e5fdbd5a799101/benchmarks/scenarios/ember.js#L63069-L63079
|
train
|
|
ember-cli/loader.js
|
benchmarks/scenarios/ember.js
|
race
|
function race(entries, label) {
/*jshint validthis:true */
var Constructor = this;
var promise = new Constructor(_rsvpInternal.noop, label);
if (!_rsvpUtils.isArray(entries)) {
_rsvpInternal.reject(promise, new TypeError('You must pass an array to race.'));
return promise;
}
var length = entries.length;
function onFulfillment(value) {
_rsvpInternal.resolve(promise, value);
}
function onRejection(reason) {
_rsvpInternal.reject(promise, reason);
}
for (var i = 0; promise._state === _rsvpInternal.PENDING && i < length; i++) {
_rsvpInternal.subscribe(Constructor.resolve(entries[i]), undefined, onFulfillment, onRejection);
}
return promise;
}
|
javascript
|
function race(entries, label) {
/*jshint validthis:true */
var Constructor = this;
var promise = new Constructor(_rsvpInternal.noop, label);
if (!_rsvpUtils.isArray(entries)) {
_rsvpInternal.reject(promise, new TypeError('You must pass an array to race.'));
return promise;
}
var length = entries.length;
function onFulfillment(value) {
_rsvpInternal.resolve(promise, value);
}
function onRejection(reason) {
_rsvpInternal.reject(promise, reason);
}
for (var i = 0; promise._state === _rsvpInternal.PENDING && i < length; i++) {
_rsvpInternal.subscribe(Constructor.resolve(entries[i]), undefined, onFulfillment, onRejection);
}
return promise;
}
|
[
"function",
"race",
"(",
"entries",
",",
"label",
")",
"{",
"var",
"Constructor",
"=",
"this",
";",
"var",
"promise",
"=",
"new",
"Constructor",
"(",
"_rsvpInternal",
".",
"noop",
",",
"label",
")",
";",
"if",
"(",
"!",
"_rsvpUtils",
".",
"isArray",
"(",
"entries",
")",
")",
"{",
"_rsvpInternal",
".",
"reject",
"(",
"promise",
",",
"new",
"TypeError",
"(",
"'You must pass an array to race.'",
")",
")",
";",
"return",
"promise",
";",
"}",
"var",
"length",
"=",
"entries",
".",
"length",
";",
"function",
"onFulfillment",
"(",
"value",
")",
"{",
"_rsvpInternal",
".",
"resolve",
"(",
"promise",
",",
"value",
")",
";",
"}",
"function",
"onRejection",
"(",
"reason",
")",
"{",
"_rsvpInternal",
".",
"reject",
"(",
"promise",
",",
"reason",
")",
";",
"}",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"promise",
".",
"_state",
"===",
"_rsvpInternal",
".",
"PENDING",
"&&",
"i",
"<",
"length",
";",
"i",
"++",
")",
"{",
"_rsvpInternal",
".",
"subscribe",
"(",
"Constructor",
".",
"resolve",
"(",
"entries",
"[",
"i",
"]",
")",
",",
"undefined",
",",
"onFulfillment",
",",
"onRejection",
")",
";",
"}",
"return",
"promise",
";",
"}"
] |
`RSVP.Promise.race` returns a new promise which is settled in the same way as the
first passed promise to settle.
Example:
```javascript
var promise1 = new RSVP.Promise(function(resolve, reject){
setTimeout(function(){
resolve('promise 1');
}, 200);
});
var promise2 = new RSVP.Promise(function(resolve, reject){
setTimeout(function(){
resolve('promise 2');
}, 100);
});
RSVP.Promise.race([promise1, promise2]).then(function(result){
result === 'promise 2' because it was resolved before promise1
was resolved.
});
```
`RSVP.Promise.race` is deterministic in that only the state of the first
settled promise matters. For example, even if other promises given to the
`promises` array argument are resolved, but the first settled promise has
become rejected before the other promises became fulfilled, the returned
promise will become rejected:
```javascript
var promise1 = new RSVP.Promise(function(resolve, reject){
setTimeout(function(){
resolve('promise 1');
}, 200);
});
var promise2 = new RSVP.Promise(function(resolve, reject){
setTimeout(function(){
reject(new Error('promise 2'));
}, 100);
});
RSVP.Promise.race([promise1, promise2]).then(function(result){
Code here never runs
}, function(reason){
reason.message === 'promise 2' because promise 2 became rejected before
promise 1 became fulfilled
});
```
An example real-world use case is implementing timeouts:
```javascript
RSVP.Promise.race([ajax('foo.json'), timeout(5000)])
```
@method race
@static
@param {Array} entries array of promises to observe
@param {String} label optional string for describing the promise returned.
Useful for tooling.
@return {Promise} a promise which settles in the same way as the first passed
promise to settle.
|
[
"RSVP",
".",
"Promise",
".",
"race",
"returns",
"a",
"new",
"promise",
"which",
"is",
"settled",
"in",
"the",
"same",
"way",
"as",
"the",
"first",
"passed",
"promise",
"to",
"settle",
"."
] |
4fe5b3dfd5e1a30d706d289bb4e5fdbd5a799101
|
https://github.com/ember-cli/loader.js/blob/4fe5b3dfd5e1a30d706d289bb4e5fdbd5a799101/benchmarks/scenarios/ember.js#L65258-L65284
|
train
|
sindresorhus/gulp-changed
|
index.js
|
fsOperationFailed
|
function fsOperationFailed(stream, sourceFile, err) {
if (err.code !== 'ENOENT') {
stream.emit('error', new PluginError('gulp-changed', err, {
fileName: sourceFile.path
}));
}
stream.push(sourceFile);
}
|
javascript
|
function fsOperationFailed(stream, sourceFile, err) {
if (err.code !== 'ENOENT') {
stream.emit('error', new PluginError('gulp-changed', err, {
fileName: sourceFile.path
}));
}
stream.push(sourceFile);
}
|
[
"function",
"fsOperationFailed",
"(",
"stream",
",",
"sourceFile",
",",
"err",
")",
"{",
"if",
"(",
"err",
".",
"code",
"!==",
"'ENOENT'",
")",
"{",
"stream",
".",
"emit",
"(",
"'error'",
",",
"new",
"PluginError",
"(",
"'gulp-changed'",
",",
"err",
",",
"{",
"fileName",
":",
"sourceFile",
".",
"path",
"}",
")",
")",
";",
"}",
"stream",
".",
"push",
"(",
"sourceFile",
")",
";",
"}"
] |
Ignore missing file error
|
[
"Ignore",
"missing",
"file",
"error"
] |
df7582f848aba597b9e821dbb8507ddd208178d7
|
https://github.com/sindresorhus/gulp-changed/blob/df7582f848aba597b9e821dbb8507ddd208178d7/index.js#L13-L21
|
train
|
sindresorhus/gulp-changed
|
index.js
|
compareLastModifiedTime
|
function compareLastModifiedTime(stream, sourceFile, targetPath) {
return stat(targetPath)
.then(targetStat => {
if (sourceFile.stat && sourceFile.stat.mtime > targetStat.mtime) {
stream.push(sourceFile);
}
});
}
|
javascript
|
function compareLastModifiedTime(stream, sourceFile, targetPath) {
return stat(targetPath)
.then(targetStat => {
if (sourceFile.stat && sourceFile.stat.mtime > targetStat.mtime) {
stream.push(sourceFile);
}
});
}
|
[
"function",
"compareLastModifiedTime",
"(",
"stream",
",",
"sourceFile",
",",
"targetPath",
")",
"{",
"return",
"stat",
"(",
"targetPath",
")",
".",
"then",
"(",
"targetStat",
"=>",
"{",
"if",
"(",
"sourceFile",
".",
"stat",
"&&",
"sourceFile",
".",
"stat",
".",
"mtime",
">",
"targetStat",
".",
"mtime",
")",
"{",
"stream",
".",
"push",
"(",
"sourceFile",
")",
";",
"}",
"}",
")",
";",
"}"
] |
Only push through files changed more recently than the destination files
|
[
"Only",
"push",
"through",
"files",
"changed",
"more",
"recently",
"than",
"the",
"destination",
"files"
] |
df7582f848aba597b9e821dbb8507ddd208178d7
|
https://github.com/sindresorhus/gulp-changed/blob/df7582f848aba597b9e821dbb8507ddd208178d7/index.js#L24-L31
|
train
|
sindresorhus/gulp-changed
|
index.js
|
compareContents
|
function compareContents(stream, sourceFile, targetPath) {
return readFile(targetPath)
.then(targetData => {
if (sourceFile.isNull() || !sourceFile.contents.equals(targetData)) {
stream.push(sourceFile);
}
});
}
|
javascript
|
function compareContents(stream, sourceFile, targetPath) {
return readFile(targetPath)
.then(targetData => {
if (sourceFile.isNull() || !sourceFile.contents.equals(targetData)) {
stream.push(sourceFile);
}
});
}
|
[
"function",
"compareContents",
"(",
"stream",
",",
"sourceFile",
",",
"targetPath",
")",
"{",
"return",
"readFile",
"(",
"targetPath",
")",
".",
"then",
"(",
"targetData",
"=>",
"{",
"if",
"(",
"sourceFile",
".",
"isNull",
"(",
")",
"||",
"!",
"sourceFile",
".",
"contents",
".",
"equals",
"(",
"targetData",
")",
")",
"{",
"stream",
".",
"push",
"(",
"sourceFile",
")",
";",
"}",
"}",
")",
";",
"}"
] |
Only push through files with different contents than the destination files
|
[
"Only",
"push",
"through",
"files",
"with",
"different",
"contents",
"than",
"the",
"destination",
"files"
] |
df7582f848aba597b9e821dbb8507ddd208178d7
|
https://github.com/sindresorhus/gulp-changed/blob/df7582f848aba597b9e821dbb8507ddd208178d7/index.js#L34-L41
|
train
|
ghybs/Leaflet.MarkerCluster.LayerSupport
|
src/layersupport.js
|
function (layers) {
var layersArray = this._toArray(layers),
separated = this._checkInGetSeparated(layersArray),
groups = separated.groups,
i, group, id;
// Batch add all single layers.
this._originalAddLayers(separated.singles);
// Add Layer Groups to the map so that they are registered there and
// the map fires 'layeradd' events for them as well.
for (i = 0; i < groups.length; i++) {
group = groups[i];
id = L.stamp(group);
this._proxyLayerGroups[id] = group;
delete this._proxyLayerGroupsNeedRemoving[id];
if (this._map) {
this._map._originalAddLayer(group);
}
}
}
|
javascript
|
function (layers) {
var layersArray = this._toArray(layers),
separated = this._checkInGetSeparated(layersArray),
groups = separated.groups,
i, group, id;
// Batch add all single layers.
this._originalAddLayers(separated.singles);
// Add Layer Groups to the map so that they are registered there and
// the map fires 'layeradd' events for them as well.
for (i = 0; i < groups.length; i++) {
group = groups[i];
id = L.stamp(group);
this._proxyLayerGroups[id] = group;
delete this._proxyLayerGroupsNeedRemoving[id];
if (this._map) {
this._map._originalAddLayer(group);
}
}
}
|
[
"function",
"(",
"layers",
")",
"{",
"var",
"layersArray",
"=",
"this",
".",
"_toArray",
"(",
"layers",
")",
",",
"separated",
"=",
"this",
".",
"_checkInGetSeparated",
"(",
"layersArray",
")",
",",
"groups",
"=",
"separated",
".",
"groups",
",",
"i",
",",
"group",
",",
"id",
";",
"this",
".",
"_originalAddLayers",
"(",
"separated",
".",
"singles",
")",
";",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"groups",
".",
"length",
";",
"i",
"++",
")",
"{",
"group",
"=",
"groups",
"[",
"i",
"]",
";",
"id",
"=",
"L",
".",
"stamp",
"(",
"group",
")",
";",
"this",
".",
"_proxyLayerGroups",
"[",
"id",
"]",
"=",
"group",
";",
"delete",
"this",
".",
"_proxyLayerGroupsNeedRemoving",
"[",
"id",
"]",
";",
"if",
"(",
"this",
".",
"_map",
")",
"{",
"this",
".",
"_map",
".",
"_originalAddLayer",
"(",
"group",
")",
";",
"}",
"}",
"}"
] |
Checks in and adds an array of layers to this group.
Layer Groups are also added to the map to fire their event.
@param layers (L.Layer|L.Layer[]) single and/or group layers to be added.
@returns {L.MarkerClusterGroup.LayerSupport} this.
|
[
"Checks",
"in",
"and",
"adds",
"an",
"array",
"of",
"layers",
"to",
"this",
"group",
".",
"Layer",
"Groups",
"are",
"also",
"added",
"to",
"the",
"map",
"to",
"fire",
"their",
"event",
"."
] |
649b3a94fad3e7fe6bc5870e2cca74b07604a934
|
https://github.com/ghybs/Leaflet.MarkerCluster.LayerSupport/blob/649b3a94fad3e7fe6bc5870e2cca74b07604a934/src/layersupport.js#L92-L112
|
train
|
|
ghybs/Leaflet.MarkerCluster.LayerSupport
|
src/layersupport.js
|
function (layers) {
var layersArray = this._toArray(layers),
separated = this._separateSingleFromGroupLayers(layersArray, {
groups: [],
singles: []
}),
groups = separated.groups,
singles = separated.singles,
i = 0,
group, id;
// Batch remove single layers from MCG.
this._originalRemoveLayers(singles);
// Remove Layer Groups from the map so that they are un-registered
// there and the map fires 'layerremove' events for them as well.
for (; i < groups.length; i++) {
group = groups[i];
id = L.stamp(group);
delete this._proxyLayerGroups[id];
if (this._map) {
this._map._originalRemoveLayer(group);
} else {
this._proxyLayerGroupsNeedRemoving[id] = group;
}
}
return this;
}
|
javascript
|
function (layers) {
var layersArray = this._toArray(layers),
separated = this._separateSingleFromGroupLayers(layersArray, {
groups: [],
singles: []
}),
groups = separated.groups,
singles = separated.singles,
i = 0,
group, id;
// Batch remove single layers from MCG.
this._originalRemoveLayers(singles);
// Remove Layer Groups from the map so that they are un-registered
// there and the map fires 'layerremove' events for them as well.
for (; i < groups.length; i++) {
group = groups[i];
id = L.stamp(group);
delete this._proxyLayerGroups[id];
if (this._map) {
this._map._originalRemoveLayer(group);
} else {
this._proxyLayerGroupsNeedRemoving[id] = group;
}
}
return this;
}
|
[
"function",
"(",
"layers",
")",
"{",
"var",
"layersArray",
"=",
"this",
".",
"_toArray",
"(",
"layers",
")",
",",
"separated",
"=",
"this",
".",
"_separateSingleFromGroupLayers",
"(",
"layersArray",
",",
"{",
"groups",
":",
"[",
"]",
",",
"singles",
":",
"[",
"]",
"}",
")",
",",
"groups",
"=",
"separated",
".",
"groups",
",",
"singles",
"=",
"separated",
".",
"singles",
",",
"i",
"=",
"0",
",",
"group",
",",
"id",
";",
"this",
".",
"_originalRemoveLayers",
"(",
"singles",
")",
";",
"for",
"(",
";",
"i",
"<",
"groups",
".",
"length",
";",
"i",
"++",
")",
"{",
"group",
"=",
"groups",
"[",
"i",
"]",
";",
"id",
"=",
"L",
".",
"stamp",
"(",
"group",
")",
";",
"delete",
"this",
".",
"_proxyLayerGroups",
"[",
"id",
"]",
";",
"if",
"(",
"this",
".",
"_map",
")",
"{",
"this",
".",
"_map",
".",
"_originalRemoveLayer",
"(",
"group",
")",
";",
"}",
"else",
"{",
"this",
".",
"_proxyLayerGroupsNeedRemoving",
"[",
"id",
"]",
"=",
"group",
";",
"}",
"}",
"return",
"this",
";",
"}"
] |
Removes layers from this group but without check out.
Layer Groups are also removed from the map to fire their event.
@param layers (L.Layer|L.Layer[]) single and/or group layers to be removed.
@returns {L.MarkerClusterGroup.LayerSupport} this.
|
[
"Removes",
"layers",
"from",
"this",
"group",
"but",
"without",
"check",
"out",
".",
"Layer",
"Groups",
"are",
"also",
"removed",
"from",
"the",
"map",
"to",
"fire",
"their",
"event",
"."
] |
649b3a94fad3e7fe6bc5870e2cca74b07604a934
|
https://github.com/ghybs/Leaflet.MarkerCluster.LayerSupport/blob/649b3a94fad3e7fe6bc5870e2cca74b07604a934/src/layersupport.js#L126-L154
|
train
|
|
ghybs/Leaflet.MarkerCluster.LayerSupport
|
src/layersupport.js
|
function (layer, operationType) {
var duration = this.options.singleAddRemoveBufferDuration,
fn;
if (duration > 0) {
this._singleAddRemoveBuffer.push({
type: operationType,
layer: layer
});
if (!this._singleAddRemoveBufferTimeout) {
fn = L.bind(this._processSingleAddRemoveBuffer, this);
this._singleAddRemoveBufferTimeout = setTimeout(fn, duration);
}
} else { // If duration <= 0, process synchronously.
this[operationType](layer);
}
}
|
javascript
|
function (layer, operationType) {
var duration = this.options.singleAddRemoveBufferDuration,
fn;
if (duration > 0) {
this._singleAddRemoveBuffer.push({
type: operationType,
layer: layer
});
if (!this._singleAddRemoveBufferTimeout) {
fn = L.bind(this._processSingleAddRemoveBuffer, this);
this._singleAddRemoveBufferTimeout = setTimeout(fn, duration);
}
} else { // If duration <= 0, process synchronously.
this[operationType](layer);
}
}
|
[
"function",
"(",
"layer",
",",
"operationType",
")",
"{",
"var",
"duration",
"=",
"this",
".",
"options",
".",
"singleAddRemoveBufferDuration",
",",
"fn",
";",
"if",
"(",
"duration",
">",
"0",
")",
"{",
"this",
".",
"_singleAddRemoveBuffer",
".",
"push",
"(",
"{",
"type",
":",
"operationType",
",",
"layer",
":",
"layer",
"}",
")",
";",
"if",
"(",
"!",
"this",
".",
"_singleAddRemoveBufferTimeout",
")",
"{",
"fn",
"=",
"L",
".",
"bind",
"(",
"this",
".",
"_processSingleAddRemoveBuffer",
",",
"this",
")",
";",
"this",
".",
"_singleAddRemoveBufferTimeout",
"=",
"setTimeout",
"(",
"fn",
",",
"duration",
")",
";",
"}",
"}",
"else",
"{",
"this",
"[",
"operationType",
"]",
"(",
"layer",
")",
";",
"}",
"}"
] |
Do not restore the original map methods when removing the group from it. Leaving them as-is does not harm, whereas restoring the original ones may kill the functionality of potential other LayerSupport groups on the same map. Therefore we do not need to override onRemove.
|
[
"Do",
"not",
"restore",
"the",
"original",
"map",
"methods",
"when",
"removing",
"the",
"group",
"from",
"it",
".",
"Leaving",
"them",
"as",
"-",
"is",
"does",
"not",
"harm",
"whereas",
"restoring",
"the",
"original",
"ones",
"may",
"kill",
"the",
"functionality",
"of",
"potential",
"other",
"LayerSupport",
"groups",
"on",
"the",
"same",
"map",
".",
"Therefore",
"we",
"do",
"not",
"need",
"to",
"override",
"onRemove",
"."
] |
649b3a94fad3e7fe6bc5870e2cca74b07604a934
|
https://github.com/ghybs/Leaflet.MarkerCluster.LayerSupport/blob/649b3a94fad3e7fe6bc5870e2cca74b07604a934/src/layersupport.js#L210-L228
|
train
|
|
ghybs/Leaflet.MarkerCluster.LayerSupport
|
src/layersupport.js
|
function (layerGroup) {
if (layerGroup._proxyMcgLayerSupportGroup === undefined ||
layerGroup._proxyMcgLayerSupportGroup !== this) {
return;
}
delete layerGroup._proxyMcgLayerSupportGroup;
layerGroup.addLayer = layerGroup._originalAddLayer;
layerGroup.removeLayer = layerGroup._originalRemoveLayer;
layerGroup.onAdd = layerGroup._originalOnAdd;
layerGroup.onRemove = layerGroup._originalOnRemove;
var id = L.stamp(layerGroup);
delete this._proxyLayerGroups[id];
delete this._proxyLayerGroupsNeedRemoving[id];
this._removeFromOwnMap(layerGroup);
}
|
javascript
|
function (layerGroup) {
if (layerGroup._proxyMcgLayerSupportGroup === undefined ||
layerGroup._proxyMcgLayerSupportGroup !== this) {
return;
}
delete layerGroup._proxyMcgLayerSupportGroup;
layerGroup.addLayer = layerGroup._originalAddLayer;
layerGroup.removeLayer = layerGroup._originalRemoveLayer;
layerGroup.onAdd = layerGroup._originalOnAdd;
layerGroup.onRemove = layerGroup._originalOnRemove;
var id = L.stamp(layerGroup);
delete this._proxyLayerGroups[id];
delete this._proxyLayerGroupsNeedRemoving[id];
this._removeFromOwnMap(layerGroup);
}
|
[
"function",
"(",
"layerGroup",
")",
"{",
"if",
"(",
"layerGroup",
".",
"_proxyMcgLayerSupportGroup",
"===",
"undefined",
"||",
"layerGroup",
".",
"_proxyMcgLayerSupportGroup",
"!==",
"this",
")",
"{",
"return",
";",
"}",
"delete",
"layerGroup",
".",
"_proxyMcgLayerSupportGroup",
";",
"layerGroup",
".",
"addLayer",
"=",
"layerGroup",
".",
"_originalAddLayer",
";",
"layerGroup",
".",
"removeLayer",
"=",
"layerGroup",
".",
"_originalRemoveLayer",
";",
"layerGroup",
".",
"onAdd",
"=",
"layerGroup",
".",
"_originalOnAdd",
";",
"layerGroup",
".",
"onRemove",
"=",
"layerGroup",
".",
"_originalOnRemove",
";",
"var",
"id",
"=",
"L",
".",
"stamp",
"(",
"layerGroup",
")",
";",
"delete",
"this",
".",
"_proxyLayerGroups",
"[",
"id",
"]",
";",
"delete",
"this",
".",
"_proxyLayerGroupsNeedRemoving",
"[",
"id",
"]",
";",
"this",
".",
"_removeFromOwnMap",
"(",
"layerGroup",
")",
";",
"}"
] |
Restore the normal LayerGroup behaviour. Removal and check out of contained markers must be taken care of externally.
|
[
"Restore",
"the",
"normal",
"LayerGroup",
"behaviour",
".",
"Removal",
"and",
"check",
"out",
"of",
"contained",
"markers",
"must",
"be",
"taken",
"care",
"of",
"externally",
"."
] |
649b3a94fad3e7fe6bc5870e2cca74b07604a934
|
https://github.com/ghybs/Leaflet.MarkerCluster.LayerSupport/blob/649b3a94fad3e7fe6bc5870e2cca74b07604a934/src/layersupport.js#L347-L365
|
train
|
|
ghybs/Leaflet.MarkerCluster.LayerSupport
|
src/layersupport.js
|
function (map) {
var layers = this._layers,
toBeReAdded = [],
layer;
for (var id in layers) {
layer = layers[id];
if (layer._map) {
toBeReAdded.push(layer);
map._originalRemoveLayer(layer);
}
}
return toBeReAdded;
}
|
javascript
|
function (map) {
var layers = this._layers,
toBeReAdded = [],
layer;
for (var id in layers) {
layer = layers[id];
if (layer._map) {
toBeReAdded.push(layer);
map._originalRemoveLayer(layer);
}
}
return toBeReAdded;
}
|
[
"function",
"(",
"map",
")",
"{",
"var",
"layers",
"=",
"this",
".",
"_layers",
",",
"toBeReAdded",
"=",
"[",
"]",
",",
"layer",
";",
"for",
"(",
"var",
"id",
"in",
"layers",
")",
"{",
"layer",
"=",
"layers",
"[",
"id",
"]",
";",
"if",
"(",
"layer",
".",
"_map",
")",
"{",
"toBeReAdded",
".",
"push",
"(",
"layer",
")",
";",
"map",
".",
"_originalRemoveLayer",
"(",
"layer",
")",
";",
"}",
"}",
"return",
"toBeReAdded",
";",
"}"
] |
In case checked in layers have been added to map whereas map is not redirected.
|
[
"In",
"case",
"checked",
"in",
"layers",
"have",
"been",
"added",
"to",
"map",
"whereas",
"map",
"is",
"not",
"redirected",
"."
] |
649b3a94fad3e7fe6bc5870e2cca74b07604a934
|
https://github.com/ghybs/Leaflet.MarkerCluster.LayerSupport/blob/649b3a94fad3e7fe6bc5870e2cca74b07604a934/src/layersupport.js#L393-L407
|
train
|
|
ghybs/Leaflet.MarkerCluster.LayerSupport
|
src/layersupport.js
|
function (layer) {
var id = this.getLayerId(layer);
this._layers[id] = layer;
if (this._map) {
this._proxyMcgLayerSupportGroup.addLayer(layer);
} else {
this._proxyMcgLayerSupportGroup.checkIn(layer);
}
return this;
}
|
javascript
|
function (layer) {
var id = this.getLayerId(layer);
this._layers[id] = layer;
if (this._map) {
this._proxyMcgLayerSupportGroup.addLayer(layer);
} else {
this._proxyMcgLayerSupportGroup.checkIn(layer);
}
return this;
}
|
[
"function",
"(",
"layer",
")",
"{",
"var",
"id",
"=",
"this",
".",
"getLayerId",
"(",
"layer",
")",
";",
"this",
".",
"_layers",
"[",
"id",
"]",
"=",
"layer",
";",
"if",
"(",
"this",
".",
"_map",
")",
"{",
"this",
".",
"_proxyMcgLayerSupportGroup",
".",
"addLayer",
"(",
"layer",
")",
";",
"}",
"else",
"{",
"this",
".",
"_proxyMcgLayerSupportGroup",
".",
"checkIn",
"(",
"layer",
")",
";",
"}",
"return",
"this",
";",
"}"
] |
Re-implement to redirect addLayer to Layer Support group instead of map.
|
[
"Re",
"-",
"implement",
"to",
"redirect",
"addLayer",
"to",
"Layer",
"Support",
"group",
"instead",
"of",
"map",
"."
] |
649b3a94fad3e7fe6bc5870e2cca74b07604a934
|
https://github.com/ghybs/Leaflet.MarkerCluster.LayerSupport/blob/649b3a94fad3e7fe6bc5870e2cca74b07604a934/src/layersupport.js#L489-L501
|
train
|
|
ghybs/Leaflet.MarkerCluster.LayerSupport
|
src/layersupport.js
|
function (layer) {
var id = layer in this._layers ? layer : this.getLayerId(layer);
this._proxyMcgLayerSupportGroup.removeLayer(layer);
delete this._layers[id];
return this;
}
|
javascript
|
function (layer) {
var id = layer in this._layers ? layer : this.getLayerId(layer);
this._proxyMcgLayerSupportGroup.removeLayer(layer);
delete this._layers[id];
return this;
}
|
[
"function",
"(",
"layer",
")",
"{",
"var",
"id",
"=",
"layer",
"in",
"this",
".",
"_layers",
"?",
"layer",
":",
"this",
".",
"getLayerId",
"(",
"layer",
")",
";",
"this",
".",
"_proxyMcgLayerSupportGroup",
".",
"removeLayer",
"(",
"layer",
")",
";",
"delete",
"this",
".",
"_layers",
"[",
"id",
"]",
";",
"return",
"this",
";",
"}"
] |
Re-implement to redirect removeLayer to Layer Support group instead of map.
|
[
"Re",
"-",
"implement",
"to",
"redirect",
"removeLayer",
"to",
"Layer",
"Support",
"group",
"instead",
"of",
"map",
"."
] |
649b3a94fad3e7fe6bc5870e2cca74b07604a934
|
https://github.com/ghybs/Leaflet.MarkerCluster.LayerSupport/blob/649b3a94fad3e7fe6bc5870e2cca74b07604a934/src/layersupport.js#L504-L513
|
train
|
|
jeromeetienne/better.js
|
www/long-stack-traces/lib/long-stack-traces.js
|
wrapRegistrationFunction
|
function wrapRegistrationFunction(object, property, callbackArg) {
if (typeof object[property] !== "function") {
console.error("(long-stack-traces) Object", object, "does not contain function", property);
return;
}
if (!has.call(object, property)) {
console.warn("(long-stack-traces) Object", object, "does not directly contain function", property);
}
// TODO: better source position detection
var sourcePosition = (object.constructor.name || Object.prototype.toString.call(object)) + "." + property;
// capture the original registration function
var fn = object[property];
// overwrite it with a wrapped registration function that modifies the supplied callback argument
object[property] = function() {
// replace the callback argument with a wrapped version that captured the current stack trace
arguments[callbackArg] = makeWrappedCallback(arguments[callbackArg], sourcePosition);
// call the original registration function with the modified arguments
return fn.apply(this, arguments);
}
// check that the registration function was indeed overwritten
if (object[property] === fn)
console.warn("(long-stack-traces) Couldn't replace ", property, "on", object);
}
|
javascript
|
function wrapRegistrationFunction(object, property, callbackArg) {
if (typeof object[property] !== "function") {
console.error("(long-stack-traces) Object", object, "does not contain function", property);
return;
}
if (!has.call(object, property)) {
console.warn("(long-stack-traces) Object", object, "does not directly contain function", property);
}
// TODO: better source position detection
var sourcePosition = (object.constructor.name || Object.prototype.toString.call(object)) + "." + property;
// capture the original registration function
var fn = object[property];
// overwrite it with a wrapped registration function that modifies the supplied callback argument
object[property] = function() {
// replace the callback argument with a wrapped version that captured the current stack trace
arguments[callbackArg] = makeWrappedCallback(arguments[callbackArg], sourcePosition);
// call the original registration function with the modified arguments
return fn.apply(this, arguments);
}
// check that the registration function was indeed overwritten
if (object[property] === fn)
console.warn("(long-stack-traces) Couldn't replace ", property, "on", object);
}
|
[
"function",
"wrapRegistrationFunction",
"(",
"object",
",",
"property",
",",
"callbackArg",
")",
"{",
"if",
"(",
"typeof",
"object",
"[",
"property",
"]",
"!==",
"\"function\"",
")",
"{",
"console",
".",
"error",
"(",
"\"(long-stack-traces) Object\"",
",",
"object",
",",
"\"does not contain function\"",
",",
"property",
")",
";",
"return",
";",
"}",
"if",
"(",
"!",
"has",
".",
"call",
"(",
"object",
",",
"property",
")",
")",
"{",
"console",
".",
"warn",
"(",
"\"(long-stack-traces) Object\"",
",",
"object",
",",
"\"does not directly contain function\"",
",",
"property",
")",
";",
"}",
"var",
"sourcePosition",
"=",
"(",
"object",
".",
"constructor",
".",
"name",
"||",
"Object",
".",
"prototype",
".",
"toString",
".",
"call",
"(",
"object",
")",
")",
"+",
"\".\"",
"+",
"property",
";",
"var",
"fn",
"=",
"object",
"[",
"property",
"]",
";",
"object",
"[",
"property",
"]",
"=",
"function",
"(",
")",
"{",
"arguments",
"[",
"callbackArg",
"]",
"=",
"makeWrappedCallback",
"(",
"arguments",
"[",
"callbackArg",
"]",
",",
"sourcePosition",
")",
";",
"return",
"fn",
".",
"apply",
"(",
"this",
",",
"arguments",
")",
";",
"}",
"if",
"(",
"object",
"[",
"property",
"]",
"===",
"fn",
")",
"console",
".",
"warn",
"(",
"\"(long-stack-traces) Couldn't replace \"",
",",
"property",
",",
"\"on\"",
",",
"object",
")",
";",
"}"
] |
Takes an object, a property name for the callback function to wrap, and an argument position and overwrites the function with a wrapper that captures the stack at the time of callback registration
|
[
"Takes",
"an",
"object",
"a",
"property",
"name",
"for",
"the",
"callback",
"function",
"to",
"wrap",
"and",
"an",
"argument",
"position",
"and",
"overwrites",
"the",
"function",
"with",
"a",
"wrapper",
"that",
"captures",
"the",
"stack",
"at",
"the",
"time",
"of",
"callback",
"registration"
] |
248114fc31978b3c197fe227734d7da7381d4c4a
|
https://github.com/jeromeetienne/better.js/blob/248114fc31978b3c197fe227734d7da7381d4c4a/www/long-stack-traces/lib/long-stack-traces.js#L38-L63
|
train
|
jeromeetienne/better.js
|
www/long-stack-traces/lib/long-stack-traces.js
|
makeWrappedCallback
|
function makeWrappedCallback(callback, frameLocation) {
// add a fake stack frame. we can't get a real one since we aren't inside the original function
var traceError = new Error();
traceError.__location = frameLocation;
traceError.__previous = currentTraceError;
return function() {
// if (currentTraceError) {
// FIXME: This shouldn't normally happen, but it often does. Do we actually need a stack instead?
// console.warn("(long-stack-traces) Internal Error: currentTrace already set.");
// }
// restore the trace
currentTraceError = traceError;
try {
return callback.apply(this, arguments);
} catch (e) {
console.error("Uncaught " + e.stack);
if (LST.rethrow)
throw ""; // TODO: throw the original error, or undefined?
} finally {
// clear the trace so we can check that none is set above.
// TODO: could we remove this for slightly better performace?
currentTraceError = null;
}
}
}
|
javascript
|
function makeWrappedCallback(callback, frameLocation) {
// add a fake stack frame. we can't get a real one since we aren't inside the original function
var traceError = new Error();
traceError.__location = frameLocation;
traceError.__previous = currentTraceError;
return function() {
// if (currentTraceError) {
// FIXME: This shouldn't normally happen, but it often does. Do we actually need a stack instead?
// console.warn("(long-stack-traces) Internal Error: currentTrace already set.");
// }
// restore the trace
currentTraceError = traceError;
try {
return callback.apply(this, arguments);
} catch (e) {
console.error("Uncaught " + e.stack);
if (LST.rethrow)
throw ""; // TODO: throw the original error, or undefined?
} finally {
// clear the trace so we can check that none is set above.
// TODO: could we remove this for slightly better performace?
currentTraceError = null;
}
}
}
|
[
"function",
"makeWrappedCallback",
"(",
"callback",
",",
"frameLocation",
")",
"{",
"var",
"traceError",
"=",
"new",
"Error",
"(",
")",
";",
"traceError",
".",
"__location",
"=",
"frameLocation",
";",
"traceError",
".",
"__previous",
"=",
"currentTraceError",
";",
"return",
"function",
"(",
")",
"{",
"currentTraceError",
"=",
"traceError",
";",
"try",
"{",
"return",
"callback",
".",
"apply",
"(",
"this",
",",
"arguments",
")",
";",
"}",
"catch",
"(",
"e",
")",
"{",
"console",
".",
"error",
"(",
"\"Uncaught \"",
"+",
"e",
".",
"stack",
")",
";",
"if",
"(",
"LST",
".",
"rethrow",
")",
"throw",
"\"\"",
";",
"}",
"finally",
"{",
"currentTraceError",
"=",
"null",
";",
"}",
"}",
"}"
] |
Takes a callback function and name, and captures a stack trace, returning a new callback that restores the stack frame This function adds a single function call overhead during callback registration vs. inlining it in wrapRegistationFunction
|
[
"Takes",
"a",
"callback",
"function",
"and",
"name",
"and",
"captures",
"a",
"stack",
"trace",
"returning",
"a",
"new",
"callback",
"that",
"restores",
"the",
"stack",
"frame",
"This",
"function",
"adds",
"a",
"single",
"function",
"call",
"overhead",
"during",
"callback",
"registration",
"vs",
".",
"inlining",
"it",
"in",
"wrapRegistationFunction"
] |
248114fc31978b3c197fe227734d7da7381d4c4a
|
https://github.com/jeromeetienne/better.js/blob/248114fc31978b3c197fe227734d7da7381d4c4a/www/long-stack-traces/lib/long-stack-traces.js#L67-L91
|
train
|
jeromeetienne/better.js
|
src/stacktrace.js
|
_parserFirefox
|
function _parserFirefox(error){
// start parse the error stack string
var lines = error.stack.split("\n").slice(0, -1);
var stacktrace = [];
lines.forEach(function(line){
var matches = line.match(/^(.*)@(.+):(\d+)$/);
stacktrace.push(new Stacktrace.Frame({
fct : matches[1] === '' ? '<anonymous>' : matches[1],
url : matches[2],
line : parseInt(matches[3], 10),
column : 1
}));
});
return stacktrace;
}
|
javascript
|
function _parserFirefox(error){
// start parse the error stack string
var lines = error.stack.split("\n").slice(0, -1);
var stacktrace = [];
lines.forEach(function(line){
var matches = line.match(/^(.*)@(.+):(\d+)$/);
stacktrace.push(new Stacktrace.Frame({
fct : matches[1] === '' ? '<anonymous>' : matches[1],
url : matches[2],
line : parseInt(matches[3], 10),
column : 1
}));
});
return stacktrace;
}
|
[
"function",
"_parserFirefox",
"(",
"error",
")",
"{",
"var",
"lines",
"=",
"error",
".",
"stack",
".",
"split",
"(",
"\"\\n\"",
")",
".",
"\\n",
"slice",
";",
"(",
"0",
",",
"-",
"1",
")",
"var",
"stacktrace",
"=",
"[",
"]",
";",
"lines",
".",
"forEach",
"(",
"function",
"(",
"line",
")",
"{",
"var",
"matches",
"=",
"line",
".",
"match",
"(",
"/",
"^(.*)@(.+):(\\d+)$",
"/",
")",
";",
"stacktrace",
".",
"push",
"(",
"new",
"Stacktrace",
".",
"Frame",
"(",
"{",
"fct",
":",
"matches",
"[",
"1",
"]",
"===",
"''",
"?",
"'<anonymous>'",
":",
"matches",
"[",
"1",
"]",
",",
"url",
":",
"matches",
"[",
"2",
"]",
",",
"line",
":",
"parseInt",
"(",
"matches",
"[",
"3",
"]",
",",
"10",
")",
",",
"column",
":",
"1",
"}",
")",
")",
";",
"}",
")",
";",
"}"
] |
parse the stacktrace from firefox
|
[
"parse",
"the",
"stacktrace",
"from",
"firefox"
] |
248114fc31978b3c197fe227734d7da7381d4c4a
|
https://github.com/jeromeetienne/better.js/blob/248114fc31978b3c197fe227734d7da7381d4c4a/src/stacktrace.js#L108-L122
|
train
|
jeromeetienne/better.js
|
src/stacktrace.js
|
_parserPhantomJS
|
function _parserPhantomJS(error){
// start parse the error stack string
var lines = error.stack.split("\n").slice(1);
var stacktrace = [];
lines.forEach(function(line){
if( line.match(/\(native\)$/) ){
var matches = line.match(/^\s*at (.+) \(native\)/);
stacktrace.push(new Stacktrace.Frame({
fct : matches[1],
url : 'native',
line : 1,
column : 1
}));
}else if( line.match(/\)$/) ){
var matches = line.match(/^\s*at (.+) \((.+):(\d+)\)/);
stacktrace.push(new Stacktrace.Frame({
fct : matches[1],
url : matches[2],
line : parseInt(matches[3], 10),
column : 1
}));
}else{
var matches = line.match(/^\s*at (.+):(\d+)/);
stacktrace.push(new Stacktrace.Frame({
url : matches[1],
fct : '<anonymous>',
line : parseInt(matches[2], 10),
column : 1
}));
}
});
return stacktrace;
}
|
javascript
|
function _parserPhantomJS(error){
// start parse the error stack string
var lines = error.stack.split("\n").slice(1);
var stacktrace = [];
lines.forEach(function(line){
if( line.match(/\(native\)$/) ){
var matches = line.match(/^\s*at (.+) \(native\)/);
stacktrace.push(new Stacktrace.Frame({
fct : matches[1],
url : 'native',
line : 1,
column : 1
}));
}else if( line.match(/\)$/) ){
var matches = line.match(/^\s*at (.+) \((.+):(\d+)\)/);
stacktrace.push(new Stacktrace.Frame({
fct : matches[1],
url : matches[2],
line : parseInt(matches[3], 10),
column : 1
}));
}else{
var matches = line.match(/^\s*at (.+):(\d+)/);
stacktrace.push(new Stacktrace.Frame({
url : matches[1],
fct : '<anonymous>',
line : parseInt(matches[2], 10),
column : 1
}));
}
});
return stacktrace;
}
|
[
"function",
"_parserPhantomJS",
"(",
"error",
")",
"{",
"var",
"lines",
"=",
"error",
".",
"stack",
".",
"split",
"(",
"\"\\n\"",
")",
".",
"\\n",
"slice",
";",
"(",
"1",
")",
"var",
"stacktrace",
"=",
"[",
"]",
";",
"lines",
".",
"forEach",
"(",
"function",
"(",
"line",
")",
"{",
"if",
"(",
"line",
".",
"match",
"(",
"/",
"\\(native\\)$",
"/",
")",
")",
"{",
"var",
"matches",
"=",
"line",
".",
"match",
"(",
"/",
"^\\s*at (.+) \\(native\\)",
"/",
")",
";",
"stacktrace",
".",
"push",
"(",
"new",
"Stacktrace",
".",
"Frame",
"(",
"{",
"fct",
":",
"matches",
"[",
"1",
"]",
",",
"url",
":",
"'native'",
",",
"line",
":",
"1",
",",
"column",
":",
"1",
"}",
")",
")",
";",
"}",
"else",
"if",
"(",
"line",
".",
"match",
"(",
"/",
"\\)$",
"/",
")",
")",
"{",
"var",
"matches",
"=",
"line",
".",
"match",
"(",
"/",
"^\\s*at (.+) \\((.+):(\\d+)\\)",
"/",
")",
";",
"stacktrace",
".",
"push",
"(",
"new",
"Stacktrace",
".",
"Frame",
"(",
"{",
"fct",
":",
"matches",
"[",
"1",
"]",
",",
"url",
":",
"matches",
"[",
"2",
"]",
",",
"line",
":",
"parseInt",
"(",
"matches",
"[",
"3",
"]",
",",
"10",
")",
",",
"column",
":",
"1",
"}",
")",
")",
";",
"}",
"else",
"{",
"var",
"matches",
"=",
"line",
".",
"match",
"(",
"/",
"^\\s*at (.+):(\\d+)",
"/",
")",
";",
"stacktrace",
".",
"push",
"(",
"new",
"Stacktrace",
".",
"Frame",
"(",
"{",
"url",
":",
"matches",
"[",
"1",
"]",
",",
"fct",
":",
"'<anonymous>'",
",",
"line",
":",
"parseInt",
"(",
"matches",
"[",
"2",
"]",
",",
"10",
")",
",",
"column",
":",
"1",
"}",
")",
")",
";",
"}",
"}",
")",
";",
"}"
] |
parse the stacktrace from phantomJS
|
[
"parse",
"the",
"stacktrace",
"from",
"phantomJS"
] |
248114fc31978b3c197fe227734d7da7381d4c4a
|
https://github.com/jeromeetienne/better.js/blob/248114fc31978b3c197fe227734d7da7381d4c4a/src/stacktrace.js#L127-L159
|
train
|
jeromeetienne/better.js
|
src/strongtyping.js
|
typeToString
|
function typeToString(allowedType){
if( allowedType === Number ) return 'Number'
if( allowedType === String ) return 'String'
if( allowedType === Object ) return 'Object'
if( allowedType === undefined ) return 'undefined'
return allowedType.toString()
}
|
javascript
|
function typeToString(allowedType){
if( allowedType === Number ) return 'Number'
if( allowedType === String ) return 'String'
if( allowedType === Object ) return 'Object'
if( allowedType === undefined ) return 'undefined'
return allowedType.toString()
}
|
[
"function",
"typeToString",
"(",
"allowedType",
")",
"{",
"if",
"(",
"allowedType",
"===",
"Number",
")",
"return",
"'Number'",
"if",
"(",
"allowedType",
"===",
"String",
")",
"return",
"'String'",
"if",
"(",
"allowedType",
"===",
"Object",
")",
"return",
"'Object'",
"if",
"(",
"allowedType",
"===",
"undefined",
")",
"return",
"'undefined'",
"return",
"allowedType",
".",
"toString",
"(",
")",
"}"
] |
convert one allowed type to a string
@param {any} allowedType - the allowed type
@return {String} - the string for this type
|
[
"convert",
"one",
"allowed",
"type",
"to",
"a",
"string"
] |
248114fc31978b3c197fe227734d7da7381d4c4a
|
https://github.com/jeromeetienne/better.js/blob/248114fc31978b3c197fe227734d7da7381d4c4a/src/strongtyping.js#L217-L223
|
train
|
videojs/font
|
lib/grunt.js
|
merge
|
function merge(target, source) {
// Check if font name is changed
if (source['font-name']) {
target['font-name'] = source['font-name'];
}
// Check if root dir is changed
if (source['root-dir']) {
target['root-dir'] = source['root-dir'];
}
// Check for icon changes
if (source.icons) {
for (let icon of source['icons']) {
let index = iconsIndex.indexOf(icon.name);
// Icon is replaced
if (index !== -1) {
target.icons[index] = icon;
}
// New icon is added
else {
target.icons.push(icon);
iconsIndex.push(icon.name);
}
}
}
return target;
}
|
javascript
|
function merge(target, source) {
// Check if font name is changed
if (source['font-name']) {
target['font-name'] = source['font-name'];
}
// Check if root dir is changed
if (source['root-dir']) {
target['root-dir'] = source['root-dir'];
}
// Check for icon changes
if (source.icons) {
for (let icon of source['icons']) {
let index = iconsIndex.indexOf(icon.name);
// Icon is replaced
if (index !== -1) {
target.icons[index] = icon;
}
// New icon is added
else {
target.icons.push(icon);
iconsIndex.push(icon.name);
}
}
}
return target;
}
|
[
"function",
"merge",
"(",
"target",
",",
"source",
")",
"{",
"if",
"(",
"source",
"[",
"'font-name'",
"]",
")",
"{",
"target",
"[",
"'font-name'",
"]",
"=",
"source",
"[",
"'font-name'",
"]",
";",
"}",
"if",
"(",
"source",
"[",
"'root-dir'",
"]",
")",
"{",
"target",
"[",
"'root-dir'",
"]",
"=",
"source",
"[",
"'root-dir'",
"]",
";",
"}",
"if",
"(",
"source",
".",
"icons",
")",
"{",
"for",
"(",
"let",
"icon",
"of",
"source",
"[",
"'icons'",
"]",
")",
"{",
"let",
"index",
"=",
"iconsIndex",
".",
"indexOf",
"(",
"icon",
".",
"name",
")",
";",
"if",
"(",
"index",
"!==",
"-",
"1",
")",
"{",
"target",
".",
"icons",
"[",
"index",
"]",
"=",
"icon",
";",
"}",
"else",
"{",
"target",
".",
"icons",
".",
"push",
"(",
"icon",
")",
";",
"iconsIndex",
".",
"push",
"(",
"icon",
".",
"name",
")",
";",
"}",
"}",
"}",
"return",
"target",
";",
"}"
] |
Merge a `source` object to a `target` recursively
|
[
"Merge",
"a",
"source",
"object",
"to",
"a",
"target",
"recursively"
] |
ec42c81be03f8a41f22f457eff10833e824c33b9
|
https://github.com/videojs/font/blob/ec42c81be03f8a41f22f457eff10833e824c33b9/lib/grunt.js#L8-L37
|
train
|
krampstudio/grunt-jsdoc
|
tasks/lib/exec.js
|
function(grunt, script, sources, params) {
var flag;
var cmd = script;
var args =[];
// Compute JSDoc options
for (flag in params) {
if (params.hasOwnProperty(flag)) {
if (params[flag] !== false) {
args.push('--' + flag);
}
if (typeof params[flag] === 'string') {
args.push(params[flag]);
}
}
}
if (!Array.isArray(sources)) {
sources = [sources];
}
args = args.concat(sources);
grunt.log.debug('Running : ' + cmd + ' ' + args.join(' '));
return spawn(cmd, args);
}
|
javascript
|
function(grunt, script, sources, params) {
var flag;
var cmd = script;
var args =[];
// Compute JSDoc options
for (flag in params) {
if (params.hasOwnProperty(flag)) {
if (params[flag] !== false) {
args.push('--' + flag);
}
if (typeof params[flag] === 'string') {
args.push(params[flag]);
}
}
}
if (!Array.isArray(sources)) {
sources = [sources];
}
args = args.concat(sources);
grunt.log.debug('Running : ' + cmd + ' ' + args.join(' '));
return spawn(cmd, args);
}
|
[
"function",
"(",
"grunt",
",",
"script",
",",
"sources",
",",
"params",
")",
"{",
"var",
"flag",
";",
"var",
"cmd",
"=",
"script",
";",
"var",
"args",
"=",
"[",
"]",
";",
"for",
"(",
"flag",
"in",
"params",
")",
"{",
"if",
"(",
"params",
".",
"hasOwnProperty",
"(",
"flag",
")",
")",
"{",
"if",
"(",
"params",
"[",
"flag",
"]",
"!==",
"false",
")",
"{",
"args",
".",
"push",
"(",
"'--'",
"+",
"flag",
")",
";",
"}",
"if",
"(",
"typeof",
"params",
"[",
"flag",
"]",
"===",
"'string'",
")",
"{",
"args",
".",
"push",
"(",
"params",
"[",
"flag",
"]",
")",
";",
"}",
"}",
"}",
"if",
"(",
"!",
"Array",
".",
"isArray",
"(",
"sources",
")",
")",
"{",
"sources",
"=",
"[",
"sources",
"]",
";",
"}",
"args",
"=",
"args",
".",
"concat",
"(",
"sources",
")",
";",
"grunt",
".",
"log",
".",
"debug",
"(",
"'Running : '",
"+",
"cmd",
"+",
"' '",
"+",
"args",
".",
"join",
"(",
"' '",
")",
")",
";",
"return",
"spawn",
"(",
"cmd",
",",
"args",
")",
";",
"}"
] |
Build and execute a child process using the spawn function
@param {Object} grunt - the grunt context
@param {String} script - the script to run
@param {Array} sources - the list of sources files
@param {Object} params - the list of cli flags
@return {ChildProcess} from the spawn
|
[
"Build",
"and",
"execute",
"a",
"child",
"process",
"using",
"the",
"spawn",
"function"
] |
7b4c6eb9db6ae207b18f1fdf37bc71d8c98c76da
|
https://github.com/krampstudio/grunt-jsdoc/blob/7b4c6eb9db6ae207b18f1fdf37bc71d8c98c76da/tasks/lib/exec.js#L17-L44
|
train
|
|
krampstudio/grunt-jsdoc
|
tasks/lib/exec.js
|
function(grunt) {
var i, binPath, paths;
var nodePath = process.env.NODE_PATH || '';
//check first the base path into the cwd
paths = [
__dirname + '/../../node_modules/.bin/jsdoc',
__dirname + '/../../node_modules/jsdoc/jsdoc.js',
__dirname + '/../../../jsdoc/jsdoc.js'
];
//fall back on global if not found at the usual location
nodePath.split(path.delimiter).forEach(function(p) {
if (!/\/$/.test(p)) {
p += '/';
}
paths.push(p + '/jsdoc/jsdoc.js');
});
for (i in paths) {
binPath = path.resolve(paths[i]);
if (grunt.file.exists(binPath) && grunt.file.isFile(binPath)) {
return binPath;
}
}
return;
}
|
javascript
|
function(grunt) {
var i, binPath, paths;
var nodePath = process.env.NODE_PATH || '';
//check first the base path into the cwd
paths = [
__dirname + '/../../node_modules/.bin/jsdoc',
__dirname + '/../../node_modules/jsdoc/jsdoc.js',
__dirname + '/../../../jsdoc/jsdoc.js'
];
//fall back on global if not found at the usual location
nodePath.split(path.delimiter).forEach(function(p) {
if (!/\/$/.test(p)) {
p += '/';
}
paths.push(p + '/jsdoc/jsdoc.js');
});
for (i in paths) {
binPath = path.resolve(paths[i]);
if (grunt.file.exists(binPath) && grunt.file.isFile(binPath)) {
return binPath;
}
}
return;
}
|
[
"function",
"(",
"grunt",
")",
"{",
"var",
"i",
",",
"binPath",
",",
"paths",
";",
"var",
"nodePath",
"=",
"process",
".",
"env",
".",
"NODE_PATH",
"||",
"''",
";",
"paths",
"=",
"[",
"__dirname",
"+",
"'/../../node_modules/.bin/jsdoc'",
",",
"__dirname",
"+",
"'/../../node_modules/jsdoc/jsdoc.js'",
",",
"__dirname",
"+",
"'/../../../jsdoc/jsdoc.js'",
"]",
";",
"nodePath",
".",
"split",
"(",
"path",
".",
"delimiter",
")",
".",
"forEach",
"(",
"function",
"(",
"p",
")",
"{",
"if",
"(",
"!",
"/",
"\\/$",
"/",
".",
"test",
"(",
"p",
")",
")",
"{",
"p",
"+=",
"'/'",
";",
"}",
"paths",
".",
"push",
"(",
"p",
"+",
"'/jsdoc/jsdoc.js'",
")",
";",
"}",
")",
";",
"for",
"(",
"i",
"in",
"paths",
")",
"{",
"binPath",
"=",
"path",
".",
"resolve",
"(",
"paths",
"[",
"i",
"]",
")",
";",
"if",
"(",
"grunt",
".",
"file",
".",
"exists",
"(",
"binPath",
")",
"&&",
"grunt",
".",
"file",
".",
"isFile",
"(",
"binPath",
")",
")",
"{",
"return",
"binPath",
";",
"}",
"}",
"return",
";",
"}"
] |
Lookup file or path into node modules
@param {Object} grunt - the grunt context
@returns {String} the first matching resolved path or nothing if not found
|
[
"Lookup",
"file",
"or",
"path",
"into",
"node",
"modules"
] |
7b4c6eb9db6ae207b18f1fdf37bc71d8c98c76da
|
https://github.com/krampstudio/grunt-jsdoc/blob/7b4c6eb9db6ae207b18f1fdf37bc71d8c98c76da/tasks/lib/exec.js#L51-L78
|
train
|
|
qlik-oss/leonardo-ui
|
docs/build.js
|
compileTemplates
|
function compileTemplates() {
const mainHtml = fs.readFileSync(path.resolve(docsDir, 'src/template.html'), {
encoding: 'utf8',
});
const mainTemplate = Handlebars.compile(mainHtml);
function createPage(fileName, tab, content) {
const html = mainTemplate({
tabs: [{
title: 'Get started',
url: 'get-started.html',
selected: tab === 'get-started',
}, {
title: 'Components',
url: 'components.html',
selected: tab === 'components',
}],
content,
luiVersion: LUI_VERSION,
});
fileUtil.writeFile(path.resolve(docsDir, 'dist', fileName), html);
}
function createIndexPage() {
const content = fs.readFileSync(path.resolve(docsDir, 'src/pages/index.html'), {
encoding: 'utf8',
});
const template = Handlebars.compile(content);
const html = template();
return createPage('index.html', 'index', html);
}
function createGetStartedPage() {
const content = fs.readFileSync(path.resolve(docsDir, 'src/pages/get-started.html'), {
encoding: 'utf8',
});
const template = Handlebars.compile(content);
const html = template({
luiVersion: LUI_VERSION,
});
return createPage('get-started.html', 'get-started', html);
}
function createComponentPage(templateName, template, tab, content) {
return createPage(templateName, tab, template({
content,
sections: sections.map(section => ({
name: section.name,
pages: section.pages.map(page => ({
name: page.name,
template: page.template,
selected: page.template === templateName,
})),
})),
}));
}
function createComponentPages() {
const componentHtml = fs.readFileSync(path.resolve(docsDir, 'src/component-template.html'), {
encoding: 'utf8',
});
const componentTemplate = Handlebars.compile(componentHtml);
sections.forEach((section) => {
section.pages.forEach((page) => {
const file = `src/pages/${page.template}`;
const fileContent = fs.readFileSync(path.resolve(docsDir, file), {
encoding: 'utf8',
});
const template = Handlebars.compile(fileContent);
const html = template();
createComponentPage(page.template, componentTemplate, 'components', html);
});
});
const file = 'src/pages/components.html';
const fileContent = fs.readFileSync(path.resolve(docsDir, file), {
encoding: 'utf8',
});
createComponentPage('components.html', componentTemplate, 'components', fileContent);
}
createIndexPage();
createGetStartedPage();
createComponentPages();
}
|
javascript
|
function compileTemplates() {
const mainHtml = fs.readFileSync(path.resolve(docsDir, 'src/template.html'), {
encoding: 'utf8',
});
const mainTemplate = Handlebars.compile(mainHtml);
function createPage(fileName, tab, content) {
const html = mainTemplate({
tabs: [{
title: 'Get started',
url: 'get-started.html',
selected: tab === 'get-started',
}, {
title: 'Components',
url: 'components.html',
selected: tab === 'components',
}],
content,
luiVersion: LUI_VERSION,
});
fileUtil.writeFile(path.resolve(docsDir, 'dist', fileName), html);
}
function createIndexPage() {
const content = fs.readFileSync(path.resolve(docsDir, 'src/pages/index.html'), {
encoding: 'utf8',
});
const template = Handlebars.compile(content);
const html = template();
return createPage('index.html', 'index', html);
}
function createGetStartedPage() {
const content = fs.readFileSync(path.resolve(docsDir, 'src/pages/get-started.html'), {
encoding: 'utf8',
});
const template = Handlebars.compile(content);
const html = template({
luiVersion: LUI_VERSION,
});
return createPage('get-started.html', 'get-started', html);
}
function createComponentPage(templateName, template, tab, content) {
return createPage(templateName, tab, template({
content,
sections: sections.map(section => ({
name: section.name,
pages: section.pages.map(page => ({
name: page.name,
template: page.template,
selected: page.template === templateName,
})),
})),
}));
}
function createComponentPages() {
const componentHtml = fs.readFileSync(path.resolve(docsDir, 'src/component-template.html'), {
encoding: 'utf8',
});
const componentTemplate = Handlebars.compile(componentHtml);
sections.forEach((section) => {
section.pages.forEach((page) => {
const file = `src/pages/${page.template}`;
const fileContent = fs.readFileSync(path.resolve(docsDir, file), {
encoding: 'utf8',
});
const template = Handlebars.compile(fileContent);
const html = template();
createComponentPage(page.template, componentTemplate, 'components', html);
});
});
const file = 'src/pages/components.html';
const fileContent = fs.readFileSync(path.resolve(docsDir, file), {
encoding: 'utf8',
});
createComponentPage('components.html', componentTemplate, 'components', fileContent);
}
createIndexPage();
createGetStartedPage();
createComponentPages();
}
|
[
"function",
"compileTemplates",
"(",
")",
"{",
"const",
"mainHtml",
"=",
"fs",
".",
"readFileSync",
"(",
"path",
".",
"resolve",
"(",
"docsDir",
",",
"'src/template.html'",
")",
",",
"{",
"encoding",
":",
"'utf8'",
",",
"}",
")",
";",
"const",
"mainTemplate",
"=",
"Handlebars",
".",
"compile",
"(",
"mainHtml",
")",
";",
"function",
"createPage",
"(",
"fileName",
",",
"tab",
",",
"content",
")",
"{",
"const",
"html",
"=",
"mainTemplate",
"(",
"{",
"tabs",
":",
"[",
"{",
"title",
":",
"'Get started'",
",",
"url",
":",
"'get-started.html'",
",",
"selected",
":",
"tab",
"===",
"'get-started'",
",",
"}",
",",
"{",
"title",
":",
"'Components'",
",",
"url",
":",
"'components.html'",
",",
"selected",
":",
"tab",
"===",
"'components'",
",",
"}",
"]",
",",
"content",
",",
"luiVersion",
":",
"LUI_VERSION",
",",
"}",
")",
";",
"fileUtil",
".",
"writeFile",
"(",
"path",
".",
"resolve",
"(",
"docsDir",
",",
"'dist'",
",",
"fileName",
")",
",",
"html",
")",
";",
"}",
"function",
"createIndexPage",
"(",
")",
"{",
"const",
"content",
"=",
"fs",
".",
"readFileSync",
"(",
"path",
".",
"resolve",
"(",
"docsDir",
",",
"'src/pages/index.html'",
")",
",",
"{",
"encoding",
":",
"'utf8'",
",",
"}",
")",
";",
"const",
"template",
"=",
"Handlebars",
".",
"compile",
"(",
"content",
")",
";",
"const",
"html",
"=",
"template",
"(",
")",
";",
"return",
"createPage",
"(",
"'index.html'",
",",
"'index'",
",",
"html",
")",
";",
"}",
"function",
"createGetStartedPage",
"(",
")",
"{",
"const",
"content",
"=",
"fs",
".",
"readFileSync",
"(",
"path",
".",
"resolve",
"(",
"docsDir",
",",
"'src/pages/get-started.html'",
")",
",",
"{",
"encoding",
":",
"'utf8'",
",",
"}",
")",
";",
"const",
"template",
"=",
"Handlebars",
".",
"compile",
"(",
"content",
")",
";",
"const",
"html",
"=",
"template",
"(",
"{",
"luiVersion",
":",
"LUI_VERSION",
",",
"}",
")",
";",
"return",
"createPage",
"(",
"'get-started.html'",
",",
"'get-started'",
",",
"html",
")",
";",
"}",
"function",
"createComponentPage",
"(",
"templateName",
",",
"template",
",",
"tab",
",",
"content",
")",
"{",
"return",
"createPage",
"(",
"templateName",
",",
"tab",
",",
"template",
"(",
"{",
"content",
",",
"sections",
":",
"sections",
".",
"map",
"(",
"section",
"=>",
"(",
"{",
"name",
":",
"section",
".",
"name",
",",
"pages",
":",
"section",
".",
"pages",
".",
"map",
"(",
"page",
"=>",
"(",
"{",
"name",
":",
"page",
".",
"name",
",",
"template",
":",
"page",
".",
"template",
",",
"selected",
":",
"page",
".",
"template",
"===",
"templateName",
",",
"}",
")",
")",
",",
"}",
")",
")",
",",
"}",
")",
")",
";",
"}",
"function",
"createComponentPages",
"(",
")",
"{",
"const",
"componentHtml",
"=",
"fs",
".",
"readFileSync",
"(",
"path",
".",
"resolve",
"(",
"docsDir",
",",
"'src/component-template.html'",
")",
",",
"{",
"encoding",
":",
"'utf8'",
",",
"}",
")",
";",
"const",
"componentTemplate",
"=",
"Handlebars",
".",
"compile",
"(",
"componentHtml",
")",
";",
"sections",
".",
"forEach",
"(",
"(",
"section",
")",
"=>",
"{",
"section",
".",
"pages",
".",
"forEach",
"(",
"(",
"page",
")",
"=>",
"{",
"const",
"file",
"=",
"`",
"${",
"page",
".",
"template",
"}",
"`",
";",
"const",
"fileContent",
"=",
"fs",
".",
"readFileSync",
"(",
"path",
".",
"resolve",
"(",
"docsDir",
",",
"file",
")",
",",
"{",
"encoding",
":",
"'utf8'",
",",
"}",
")",
";",
"const",
"template",
"=",
"Handlebars",
".",
"compile",
"(",
"fileContent",
")",
";",
"const",
"html",
"=",
"template",
"(",
")",
";",
"createComponentPage",
"(",
"page",
".",
"template",
",",
"componentTemplate",
",",
"'components'",
",",
"html",
")",
";",
"}",
")",
";",
"}",
")",
";",
"const",
"file",
"=",
"'src/pages/components.html'",
";",
"const",
"fileContent",
"=",
"fs",
".",
"readFileSync",
"(",
"path",
".",
"resolve",
"(",
"docsDir",
",",
"file",
")",
",",
"{",
"encoding",
":",
"'utf8'",
",",
"}",
")",
";",
"createComponentPage",
"(",
"'components.html'",
",",
"componentTemplate",
",",
"'components'",
",",
"fileContent",
")",
";",
"}",
"createIndexPage",
"(",
")",
";",
"createGetStartedPage",
"(",
")",
";",
"createComponentPages",
"(",
")",
";",
"}"
] |
Compile Handlebars templates
|
[
"Compile",
"Handlebars",
"templates"
] |
b02bd30a9b951fb4fe949ff374327c2698afdb74
|
https://github.com/qlik-oss/leonardo-ui/blob/b02bd30a9b951fb4fe949ff374327c2698afdb74/docs/build.js#L156-L243
|
train
|
qlik-oss/leonardo-ui
|
docs/build.js
|
copyResources
|
function copyResources() {
// Source code deps
fileUtil.copyFile(path.resolve(docsDir, '../dist/leonardo-ui.js'), path.resolve(docsDir, 'dist/leonardo-ui/leonardo-ui.js'));
fileUtil.copyFile(path.resolve(docsDir, '../dist/leonardo-ui.js.map'), path.resolve(docsDir, 'dist/leonardo-ui/leonardo-ui.js.map'));
fileUtil.copyFile(path.resolve(docsDir, '../dist/leonardo-ui.css'), path.resolve(docsDir, 'dist/leonardo-ui/leonardo-ui.css'));
fileUtil.copyFile(path.resolve(docsDir, '../dist/leonardo-ui.css.map'), path.resolve(docsDir, 'dist/leonardo-ui/leonardo-ui.css.map'));
fileUtil.copyFile(path.resolve(docsDir, '../dist/lui-icons.ttf'), path.resolve(docsDir, 'dist/leonardo-ui/lui-icons.ttf'));
fileUtil.copyFile(path.resolve(docsDir, '../dist/lui-icons.woff'), path.resolve(docsDir, 'dist/leonardo-ui/lui-icons.woff'));
// Doc files
glob.sync(`${path.resolve(docsDir, 'src/img')}/**.*`).forEach((file) => {
const folder = path.resolve(docsDir, 'src/img/').replace(/\\/g, '/'); // Because glob uses forward slashes on all paths
const fileName = file.replace(folder, '');
fileUtil.copyFile(file, path.resolve(docsDir, `dist/resources/${fileName}`));
});
}
|
javascript
|
function copyResources() {
// Source code deps
fileUtil.copyFile(path.resolve(docsDir, '../dist/leonardo-ui.js'), path.resolve(docsDir, 'dist/leonardo-ui/leonardo-ui.js'));
fileUtil.copyFile(path.resolve(docsDir, '../dist/leonardo-ui.js.map'), path.resolve(docsDir, 'dist/leonardo-ui/leonardo-ui.js.map'));
fileUtil.copyFile(path.resolve(docsDir, '../dist/leonardo-ui.css'), path.resolve(docsDir, 'dist/leonardo-ui/leonardo-ui.css'));
fileUtil.copyFile(path.resolve(docsDir, '../dist/leonardo-ui.css.map'), path.resolve(docsDir, 'dist/leonardo-ui/leonardo-ui.css.map'));
fileUtil.copyFile(path.resolve(docsDir, '../dist/lui-icons.ttf'), path.resolve(docsDir, 'dist/leonardo-ui/lui-icons.ttf'));
fileUtil.copyFile(path.resolve(docsDir, '../dist/lui-icons.woff'), path.resolve(docsDir, 'dist/leonardo-ui/lui-icons.woff'));
// Doc files
glob.sync(`${path.resolve(docsDir, 'src/img')}/**.*`).forEach((file) => {
const folder = path.resolve(docsDir, 'src/img/').replace(/\\/g, '/'); // Because glob uses forward slashes on all paths
const fileName = file.replace(folder, '');
fileUtil.copyFile(file, path.resolve(docsDir, `dist/resources/${fileName}`));
});
}
|
[
"function",
"copyResources",
"(",
")",
"{",
"fileUtil",
".",
"copyFile",
"(",
"path",
".",
"resolve",
"(",
"docsDir",
",",
"'../dist/leonardo-ui.js'",
")",
",",
"path",
".",
"resolve",
"(",
"docsDir",
",",
"'dist/leonardo-ui/leonardo-ui.js'",
")",
")",
";",
"fileUtil",
".",
"copyFile",
"(",
"path",
".",
"resolve",
"(",
"docsDir",
",",
"'../dist/leonardo-ui.js.map'",
")",
",",
"path",
".",
"resolve",
"(",
"docsDir",
",",
"'dist/leonardo-ui/leonardo-ui.js.map'",
")",
")",
";",
"fileUtil",
".",
"copyFile",
"(",
"path",
".",
"resolve",
"(",
"docsDir",
",",
"'../dist/leonardo-ui.css'",
")",
",",
"path",
".",
"resolve",
"(",
"docsDir",
",",
"'dist/leonardo-ui/leonardo-ui.css'",
")",
")",
";",
"fileUtil",
".",
"copyFile",
"(",
"path",
".",
"resolve",
"(",
"docsDir",
",",
"'../dist/leonardo-ui.css.map'",
")",
",",
"path",
".",
"resolve",
"(",
"docsDir",
",",
"'dist/leonardo-ui/leonardo-ui.css.map'",
")",
")",
";",
"fileUtil",
".",
"copyFile",
"(",
"path",
".",
"resolve",
"(",
"docsDir",
",",
"'../dist/lui-icons.ttf'",
")",
",",
"path",
".",
"resolve",
"(",
"docsDir",
",",
"'dist/leonardo-ui/lui-icons.ttf'",
")",
")",
";",
"fileUtil",
".",
"copyFile",
"(",
"path",
".",
"resolve",
"(",
"docsDir",
",",
"'../dist/lui-icons.woff'",
")",
",",
"path",
".",
"resolve",
"(",
"docsDir",
",",
"'dist/leonardo-ui/lui-icons.woff'",
")",
")",
";",
"glob",
".",
"sync",
"(",
"`",
"${",
"path",
".",
"resolve",
"(",
"docsDir",
",",
"'src/img'",
")",
"}",
"`",
")",
".",
"forEach",
"(",
"(",
"file",
")",
"=>",
"{",
"const",
"folder",
"=",
"path",
".",
"resolve",
"(",
"docsDir",
",",
"'src/img/'",
")",
".",
"replace",
"(",
"/",
"\\\\",
"/",
"g",
",",
"'/'",
")",
";",
"const",
"fileName",
"=",
"file",
".",
"replace",
"(",
"folder",
",",
"''",
")",
";",
"fileUtil",
".",
"copyFile",
"(",
"file",
",",
"path",
".",
"resolve",
"(",
"docsDir",
",",
"`",
"${",
"fileName",
"}",
"`",
")",
")",
";",
"}",
")",
";",
"}"
] |
Copy external libraries and images
|
[
"Copy",
"external",
"libraries",
"and",
"images"
] |
b02bd30a9b951fb4fe949ff374327c2698afdb74
|
https://github.com/qlik-oss/leonardo-ui/blob/b02bd30a9b951fb4fe949ff374327c2698afdb74/docs/build.js#L246-L261
|
train
|
systemjs/builder
|
lib/utils.js
|
getCanonicalNamePlain
|
function getCanonicalNamePlain(loader, normalized, isPlugin) {
// now just reverse apply paths rules to get canonical name
var pathMatch;
// first check exact path matches
for (var p in loader.paths) {
if (loader.paths[p].indexOf('*') != -1)
continue;
var curPath = normalizePath(loader, loader.paths[p], isPlugin);
// always stop on first exact match
if (normalized === curPath)
return p;
// support trailing / in paths rules
else if (curPath[curPath.length - 1] == '/' &&
normalized.substr(0, curPath.length - 1) == curPath.substr(0, curPath.length - 1) &&
(normalized.length < curPath.length || normalized[curPath.length - 1] == curPath[curPath.length - 1])) {
// first case is that canonicalize('src') = 'app' for 'app/': 'src/'
return normalized.length < curPath.length ? p.substr(0, p.length - 1) : p + normalized.substr(curPath.length);
}
}
// then wildcard matches
var pathMatchLength = 0;
var curMatchLength;
if (!pathMatch)
for (var p in loader.paths) {
if (loader.paths[p].indexOf('*') == -1)
continue;
// normalize the output path
var curPath = normalizePath(loader, loader.paths[p], true);
// do reverse match
var wIndex = curPath.indexOf('*');
if (normalized.substr(0, wIndex) === curPath.substr(0, wIndex)
&& normalized.substr(normalized.length - curPath.length + wIndex + 1) === curPath.substr(wIndex + 1)) {
curMatchLength = curPath.split('/').length;
if (curMatchLength >= pathMatchLength) {
pathMatch = p.replace('*', normalized.substr(wIndex, normalized.length - curPath.length + 1));
pathMatchLength = curMatchLength;
}
}
}
// when no path was matched, act like the standard rule is *: baseURL/*
if (!pathMatch) {
if (normalized.substr(0, loader.baseURL.length) == loader.baseURL)
pathMatch = normalized.substr(loader.baseURL.length);
else if (normalized.match(absURLRegEx))
throw new Error('Unable to calculate canonical name to bundle ' + normalized + '. Ensure that this module sits within the baseURL or a wildcard path config.');
else
pathMatch = normalized;
}
return pathMatch;
}
|
javascript
|
function getCanonicalNamePlain(loader, normalized, isPlugin) {
// now just reverse apply paths rules to get canonical name
var pathMatch;
// first check exact path matches
for (var p in loader.paths) {
if (loader.paths[p].indexOf('*') != -1)
continue;
var curPath = normalizePath(loader, loader.paths[p], isPlugin);
// always stop on first exact match
if (normalized === curPath)
return p;
// support trailing / in paths rules
else if (curPath[curPath.length - 1] == '/' &&
normalized.substr(0, curPath.length - 1) == curPath.substr(0, curPath.length - 1) &&
(normalized.length < curPath.length || normalized[curPath.length - 1] == curPath[curPath.length - 1])) {
// first case is that canonicalize('src') = 'app' for 'app/': 'src/'
return normalized.length < curPath.length ? p.substr(0, p.length - 1) : p + normalized.substr(curPath.length);
}
}
// then wildcard matches
var pathMatchLength = 0;
var curMatchLength;
if (!pathMatch)
for (var p in loader.paths) {
if (loader.paths[p].indexOf('*') == -1)
continue;
// normalize the output path
var curPath = normalizePath(loader, loader.paths[p], true);
// do reverse match
var wIndex = curPath.indexOf('*');
if (normalized.substr(0, wIndex) === curPath.substr(0, wIndex)
&& normalized.substr(normalized.length - curPath.length + wIndex + 1) === curPath.substr(wIndex + 1)) {
curMatchLength = curPath.split('/').length;
if (curMatchLength >= pathMatchLength) {
pathMatch = p.replace('*', normalized.substr(wIndex, normalized.length - curPath.length + 1));
pathMatchLength = curMatchLength;
}
}
}
// when no path was matched, act like the standard rule is *: baseURL/*
if (!pathMatch) {
if (normalized.substr(0, loader.baseURL.length) == loader.baseURL)
pathMatch = normalized.substr(loader.baseURL.length);
else if (normalized.match(absURLRegEx))
throw new Error('Unable to calculate canonical name to bundle ' + normalized + '. Ensure that this module sits within the baseURL or a wildcard path config.');
else
pathMatch = normalized;
}
return pathMatch;
}
|
[
"function",
"getCanonicalNamePlain",
"(",
"loader",
",",
"normalized",
",",
"isPlugin",
")",
"{",
"var",
"pathMatch",
";",
"for",
"(",
"var",
"p",
"in",
"loader",
".",
"paths",
")",
"{",
"if",
"(",
"loader",
".",
"paths",
"[",
"p",
"]",
".",
"indexOf",
"(",
"'*'",
")",
"!=",
"-",
"1",
")",
"continue",
";",
"var",
"curPath",
"=",
"normalizePath",
"(",
"loader",
",",
"loader",
".",
"paths",
"[",
"p",
"]",
",",
"isPlugin",
")",
";",
"if",
"(",
"normalized",
"===",
"curPath",
")",
"return",
"p",
";",
"else",
"if",
"(",
"curPath",
"[",
"curPath",
".",
"length",
"-",
"1",
"]",
"==",
"'/'",
"&&",
"normalized",
".",
"substr",
"(",
"0",
",",
"curPath",
".",
"length",
"-",
"1",
")",
"==",
"curPath",
".",
"substr",
"(",
"0",
",",
"curPath",
".",
"length",
"-",
"1",
")",
"&&",
"(",
"normalized",
".",
"length",
"<",
"curPath",
".",
"length",
"||",
"normalized",
"[",
"curPath",
".",
"length",
"-",
"1",
"]",
"==",
"curPath",
"[",
"curPath",
".",
"length",
"-",
"1",
"]",
")",
")",
"{",
"return",
"normalized",
".",
"length",
"<",
"curPath",
".",
"length",
"?",
"p",
".",
"substr",
"(",
"0",
",",
"p",
".",
"length",
"-",
"1",
")",
":",
"p",
"+",
"normalized",
".",
"substr",
"(",
"curPath",
".",
"length",
")",
";",
"}",
"}",
"var",
"pathMatchLength",
"=",
"0",
";",
"var",
"curMatchLength",
";",
"if",
"(",
"!",
"pathMatch",
")",
"for",
"(",
"var",
"p",
"in",
"loader",
".",
"paths",
")",
"{",
"if",
"(",
"loader",
".",
"paths",
"[",
"p",
"]",
".",
"indexOf",
"(",
"'*'",
")",
"==",
"-",
"1",
")",
"continue",
";",
"var",
"curPath",
"=",
"normalizePath",
"(",
"loader",
",",
"loader",
".",
"paths",
"[",
"p",
"]",
",",
"true",
")",
";",
"var",
"wIndex",
"=",
"curPath",
".",
"indexOf",
"(",
"'*'",
")",
";",
"if",
"(",
"normalized",
".",
"substr",
"(",
"0",
",",
"wIndex",
")",
"===",
"curPath",
".",
"substr",
"(",
"0",
",",
"wIndex",
")",
"&&",
"normalized",
".",
"substr",
"(",
"normalized",
".",
"length",
"-",
"curPath",
".",
"length",
"+",
"wIndex",
"+",
"1",
")",
"===",
"curPath",
".",
"substr",
"(",
"wIndex",
"+",
"1",
")",
")",
"{",
"curMatchLength",
"=",
"curPath",
".",
"split",
"(",
"'/'",
")",
".",
"length",
";",
"if",
"(",
"curMatchLength",
">=",
"pathMatchLength",
")",
"{",
"pathMatch",
"=",
"p",
".",
"replace",
"(",
"'*'",
",",
"normalized",
".",
"substr",
"(",
"wIndex",
",",
"normalized",
".",
"length",
"-",
"curPath",
".",
"length",
"+",
"1",
")",
")",
";",
"pathMatchLength",
"=",
"curMatchLength",
";",
"}",
"}",
"}",
"if",
"(",
"!",
"pathMatch",
")",
"{",
"if",
"(",
"normalized",
".",
"substr",
"(",
"0",
",",
"loader",
".",
"baseURL",
".",
"length",
")",
"==",
"loader",
".",
"baseURL",
")",
"pathMatch",
"=",
"normalized",
".",
"substr",
"(",
"loader",
".",
"baseURL",
".",
"length",
")",
";",
"else",
"if",
"(",
"normalized",
".",
"match",
"(",
"absURLRegEx",
")",
")",
"throw",
"new",
"Error",
"(",
"'Unable to calculate canonical name to bundle '",
"+",
"normalized",
"+",
"'. Ensure that this module sits within the baseURL or a wildcard path config.'",
")",
";",
"else",
"pathMatch",
"=",
"normalized",
";",
"}",
"return",
"pathMatch",
";",
"}"
] |
syntax-free getCanonicalName just reverse-applies paths and defulatJSExtension to determine the canonical
|
[
"syntax",
"-",
"free",
"getCanonicalName",
"just",
"reverse",
"-",
"applies",
"paths",
"and",
"defulatJSExtension",
"to",
"determine",
"the",
"canonical"
] |
e874ec6a0bdea904016bc2831f5185f38fe6c539
|
https://github.com/systemjs/builder/blob/e874ec6a0bdea904016bc2831f5185f38fe6c539/lib/utils.js#L175-L233
|
train
|
systemjs/builder
|
lib/utils.js
|
createPkgConfigPathObj
|
function createPkgConfigPathObj(path) {
var lastWildcard = path.lastIndexOf('*');
var length = Math.max(lastWildcard + 1, path.lastIndexOf('/'));
return {
length: length,
regEx: new RegExp('^(' + path.substr(0, length).replace(/[.+?^${}()|[\]\\]/g, '\\$&').replace(/\*/g, '[^\\/]+') + ')(\\/|$)'),
wildcard: lastWildcard != -1
};
}
|
javascript
|
function createPkgConfigPathObj(path) {
var lastWildcard = path.lastIndexOf('*');
var length = Math.max(lastWildcard + 1, path.lastIndexOf('/'));
return {
length: length,
regEx: new RegExp('^(' + path.substr(0, length).replace(/[.+?^${}()|[\]\\]/g, '\\$&').replace(/\*/g, '[^\\/]+') + ')(\\/|$)'),
wildcard: lastWildcard != -1
};
}
|
[
"function",
"createPkgConfigPathObj",
"(",
"path",
")",
"{",
"var",
"lastWildcard",
"=",
"path",
".",
"lastIndexOf",
"(",
"'*'",
")",
";",
"var",
"length",
"=",
"Math",
".",
"max",
"(",
"lastWildcard",
"+",
"1",
",",
"path",
".",
"lastIndexOf",
"(",
"'/'",
")",
")",
";",
"return",
"{",
"length",
":",
"length",
",",
"regEx",
":",
"new",
"RegExp",
"(",
"'^('",
"+",
"path",
".",
"substr",
"(",
"0",
",",
"length",
")",
".",
"replace",
"(",
"/",
"[.+?^${}()|[\\]\\\\]",
"/",
"g",
",",
"'\\\\$&'",
")",
".",
"\\\\",
"replace",
"+",
"(",
"/",
"\\*",
"/",
"g",
",",
"'[^\\\\/]+'",
")",
")",
",",
"\\\\",
"}",
";",
"}"
] |
data object for quick checks against package paths
|
[
"data",
"object",
"for",
"quick",
"checks",
"against",
"package",
"paths"
] |
e874ec6a0bdea904016bc2831f5185f38fe6c539
|
https://github.com/systemjs/builder/blob/e874ec6a0bdea904016bc2831f5185f38fe6c539/lib/utils.js#L242-L250
|
train
|
systemjs/builder
|
lib/trace.js
|
booleanEnvTrace
|
function booleanEnvTrace(condition) {
var conditionObj = parseCondition(condition);
if (conditionObj.negate)
return traceCondition(conditionalComplement(condition), false);
else
return traceCondition(condition, true);
}
|
javascript
|
function booleanEnvTrace(condition) {
var conditionObj = parseCondition(condition);
if (conditionObj.negate)
return traceCondition(conditionalComplement(condition), false);
else
return traceCondition(condition, true);
}
|
[
"function",
"booleanEnvTrace",
"(",
"condition",
")",
"{",
"var",
"conditionObj",
"=",
"parseCondition",
"(",
"condition",
")",
";",
"if",
"(",
"conditionObj",
".",
"negate",
")",
"return",
"traceCondition",
"(",
"conditionalComplement",
"(",
"condition",
")",
",",
"false",
")",
";",
"else",
"return",
"traceCondition",
"(",
"condition",
",",
"true",
")",
";",
"}"
] |
whether or not to include condition branch given our conditionalEnv
|
[
"whether",
"or",
"not",
"to",
"include",
"condition",
"branch",
"given",
"our",
"conditionalEnv"
] |
e874ec6a0bdea904016bc2831f5185f38fe6c539
|
https://github.com/systemjs/builder/blob/e874ec6a0bdea904016bc2831f5185f38fe6c539/lib/trace.js#L870-L877
|
train
|
systemjs/builder
|
compilers/json.js
|
optimizePackageConfig
|
function optimizePackageConfig(json) {
if (json.systemjs)
json = json.systemjs;
// remove non SystemJS package config properties
var loaderConfigProperties = ['baseDir', 'defaultExtension', 'format', 'meta', 'map', 'main'];
for (var p in json)
if (loaderConfigProperties.indexOf(p) == -1)
delete json[p];
if (json.map && !json.map['@env']) {
Object.keys(json.map).forEach(function(target) {
var mapped = json.map[target];
if (typeof mapped == 'string' && mapped.substr(0, 6) == '@node/')
delete json.map[target];
if (typeof mapped == 'object') {
Object.keys(mapped).forEach(function(condition) {
if (condition == 'node')
delete mapped[condition];
});
if (!hasProperties(mapped))
delete json.map[target];
}
});
if (!hasProperties(json.map))
delete json.map;
}
return json;
}
|
javascript
|
function optimizePackageConfig(json) {
if (json.systemjs)
json = json.systemjs;
// remove non SystemJS package config properties
var loaderConfigProperties = ['baseDir', 'defaultExtension', 'format', 'meta', 'map', 'main'];
for (var p in json)
if (loaderConfigProperties.indexOf(p) == -1)
delete json[p];
if (json.map && !json.map['@env']) {
Object.keys(json.map).forEach(function(target) {
var mapped = json.map[target];
if (typeof mapped == 'string' && mapped.substr(0, 6) == '@node/')
delete json.map[target];
if (typeof mapped == 'object') {
Object.keys(mapped).forEach(function(condition) {
if (condition == 'node')
delete mapped[condition];
});
if (!hasProperties(mapped))
delete json.map[target];
}
});
if (!hasProperties(json.map))
delete json.map;
}
return json;
}
|
[
"function",
"optimizePackageConfig",
"(",
"json",
")",
"{",
"if",
"(",
"json",
".",
"systemjs",
")",
"json",
"=",
"json",
".",
"systemjs",
";",
"var",
"loaderConfigProperties",
"=",
"[",
"'baseDir'",
",",
"'defaultExtension'",
",",
"'format'",
",",
"'meta'",
",",
"'map'",
",",
"'main'",
"]",
";",
"for",
"(",
"var",
"p",
"in",
"json",
")",
"if",
"(",
"loaderConfigProperties",
".",
"indexOf",
"(",
"p",
")",
"==",
"-",
"1",
")",
"delete",
"json",
"[",
"p",
"]",
";",
"if",
"(",
"json",
".",
"map",
"&&",
"!",
"json",
".",
"map",
"[",
"'@env'",
"]",
")",
"{",
"Object",
".",
"keys",
"(",
"json",
".",
"map",
")",
".",
"forEach",
"(",
"function",
"(",
"target",
")",
"{",
"var",
"mapped",
"=",
"json",
".",
"map",
"[",
"target",
"]",
";",
"if",
"(",
"typeof",
"mapped",
"==",
"'string'",
"&&",
"mapped",
".",
"substr",
"(",
"0",
",",
"6",
")",
"==",
"'@node/'",
")",
"delete",
"json",
".",
"map",
"[",
"target",
"]",
";",
"if",
"(",
"typeof",
"mapped",
"==",
"'object'",
")",
"{",
"Object",
".",
"keys",
"(",
"mapped",
")",
".",
"forEach",
"(",
"function",
"(",
"condition",
")",
"{",
"if",
"(",
"condition",
"==",
"'node'",
")",
"delete",
"mapped",
"[",
"condition",
"]",
";",
"}",
")",
";",
"if",
"(",
"!",
"hasProperties",
"(",
"mapped",
")",
")",
"delete",
"json",
".",
"map",
"[",
"target",
"]",
";",
"}",
"}",
")",
";",
"if",
"(",
"!",
"hasProperties",
"(",
"json",
".",
"map",
")",
")",
"delete",
"json",
".",
"map",
";",
"}",
"return",
"json",
";",
"}"
] |
because bundles are for the browser only if this is a package config file json we are compiling then we can optimize out the node-only configurations to make it smaller
|
[
"because",
"bundles",
"are",
"for",
"the",
"browser",
"only",
"if",
"this",
"is",
"a",
"package",
"config",
"file",
"json",
"we",
"are",
"compiling",
"then",
"we",
"can",
"optimize",
"out",
"the",
"node",
"-",
"only",
"configurations",
"to",
"make",
"it",
"smaller"
] |
e874ec6a0bdea904016bc2831f5185f38fe6c539
|
https://github.com/systemjs/builder/blob/e874ec6a0bdea904016bc2831f5185f38fe6c539/compilers/json.js#L28-L60
|
train
|
systemjs/builder
|
lib/compile.js
|
getCompileHash
|
function getCompileHash(load, compileOpts) {
return createHash('md5')
.update(JSON.stringify({
source: load.source,
metadata: load.metadata,
path: compileOpts.sourceMaps && load.path,
normalize: compileOpts.normalize,
anonymous: compileOpts.anonymous,
systemGlobal: compileOpts.systemGlobal,
static: compileOpts.static,
encodeNames: compileOpts.encodeNames,
sourceMaps: compileOpts.sourceMaps,
lowResSourceMaps: compileOpts.lowResSourceMaps
}))
.digest('hex');
}
|
javascript
|
function getCompileHash(load, compileOpts) {
return createHash('md5')
.update(JSON.stringify({
source: load.source,
metadata: load.metadata,
path: compileOpts.sourceMaps && load.path,
normalize: compileOpts.normalize,
anonymous: compileOpts.anonymous,
systemGlobal: compileOpts.systemGlobal,
static: compileOpts.static,
encodeNames: compileOpts.encodeNames,
sourceMaps: compileOpts.sourceMaps,
lowResSourceMaps: compileOpts.lowResSourceMaps
}))
.digest('hex');
}
|
[
"function",
"getCompileHash",
"(",
"load",
",",
"compileOpts",
")",
"{",
"return",
"createHash",
"(",
"'md5'",
")",
".",
"update",
"(",
"JSON",
".",
"stringify",
"(",
"{",
"source",
":",
"load",
".",
"source",
",",
"metadata",
":",
"load",
".",
"metadata",
",",
"path",
":",
"compileOpts",
".",
"sourceMaps",
"&&",
"load",
".",
"path",
",",
"normalize",
":",
"compileOpts",
".",
"normalize",
",",
"anonymous",
":",
"compileOpts",
".",
"anonymous",
",",
"systemGlobal",
":",
"compileOpts",
".",
"systemGlobal",
",",
"static",
":",
"compileOpts",
".",
"static",
",",
"encodeNames",
":",
"compileOpts",
".",
"encodeNames",
",",
"sourceMaps",
":",
"compileOpts",
".",
"sourceMaps",
",",
"lowResSourceMaps",
":",
"compileOpts",
".",
"lowResSourceMaps",
"}",
")",
")",
".",
"digest",
"(",
"'hex'",
")",
";",
"}"
] |
create a compile hash based on path + source + metadata + compileOpts one implication here is that plugins shouldn't rely on System.x checks as these will not be cache-invalidated but within the bundle hook is fine
|
[
"create",
"a",
"compile",
"hash",
"based",
"on",
"path",
"+",
"source",
"+",
"metadata",
"+",
"compileOpts",
"one",
"implication",
"here",
"is",
"that",
"plugins",
"shouldn",
"t",
"rely",
"on",
"System",
".",
"x",
"checks",
"as",
"these",
"will",
"not",
"be",
"cache",
"-",
"invalidated",
"but",
"within",
"the",
"bundle",
"hook",
"is",
"fine"
] |
e874ec6a0bdea904016bc2831f5185f38fe6c539
|
https://github.com/systemjs/builder/blob/e874ec6a0bdea904016bc2831f5185f38fe6c539/lib/compile.js#L26-L42
|
train
|
systemjs/builder
|
lib/compile.js
|
remapLoadRecord
|
function remapLoadRecord(load, mapFunction) {
load = extend({}, load);
load.name = mapFunction(load.name, load.name);
var depMap = {};
Object.keys(load.depMap).forEach(function(dep) {
depMap[dep] = mapFunction(load.depMap[dep], dep);
});
load.depMap = depMap;
return load;
}
|
javascript
|
function remapLoadRecord(load, mapFunction) {
load = extend({}, load);
load.name = mapFunction(load.name, load.name);
var depMap = {};
Object.keys(load.depMap).forEach(function(dep) {
depMap[dep] = mapFunction(load.depMap[dep], dep);
});
load.depMap = depMap;
return load;
}
|
[
"function",
"remapLoadRecord",
"(",
"load",
",",
"mapFunction",
")",
"{",
"load",
"=",
"extend",
"(",
"{",
"}",
",",
"load",
")",
";",
"load",
".",
"name",
"=",
"mapFunction",
"(",
"load",
".",
"name",
",",
"load",
".",
"name",
")",
";",
"var",
"depMap",
"=",
"{",
"}",
";",
"Object",
".",
"keys",
"(",
"load",
".",
"depMap",
")",
".",
"forEach",
"(",
"function",
"(",
"dep",
")",
"{",
"depMap",
"[",
"dep",
"]",
"=",
"mapFunction",
"(",
"load",
".",
"depMap",
"[",
"dep",
"]",
",",
"dep",
")",
";",
"}",
")",
";",
"load",
".",
"depMap",
"=",
"depMap",
";",
"return",
"load",
";",
"}"
] |
create a new load record with any necessary final mappings
|
[
"create",
"a",
"new",
"load",
"record",
"with",
"any",
"necessary",
"final",
"mappings"
] |
e874ec6a0bdea904016bc2831f5185f38fe6c539
|
https://github.com/systemjs/builder/blob/e874ec6a0bdea904016bc2831f5185f38fe6c539/lib/compile.js#L86-L95
|
train
|
handsontable/ngHandsontable
|
dist/ngHandsontable.js
|
function(element, htSettings) {
var container = document.createElement('div'),
hot;
container.className = this.containerClassName;
if (htSettings.hotId) {
container.id = htSettings.hotId;
}
element[0].appendChild(container);
hot = new Handsontable(container, htSettings);
if (htSettings.hotId) {
hotRegisterer.registerInstance(htSettings.hotId, hot);
}
return hot;
}
|
javascript
|
function(element, htSettings) {
var container = document.createElement('div'),
hot;
container.className = this.containerClassName;
if (htSettings.hotId) {
container.id = htSettings.hotId;
}
element[0].appendChild(container);
hot = new Handsontable(container, htSettings);
if (htSettings.hotId) {
hotRegisterer.registerInstance(htSettings.hotId, hot);
}
return hot;
}
|
[
"function",
"(",
"element",
",",
"htSettings",
")",
"{",
"var",
"container",
"=",
"document",
".",
"createElement",
"(",
"'div'",
")",
",",
"hot",
";",
"container",
".",
"className",
"=",
"this",
".",
"containerClassName",
";",
"if",
"(",
"htSettings",
".",
"hotId",
")",
"{",
"container",
".",
"id",
"=",
"htSettings",
".",
"hotId",
";",
"}",
"element",
"[",
"0",
"]",
".",
"appendChild",
"(",
"container",
")",
";",
"hot",
"=",
"new",
"Handsontable",
"(",
"container",
",",
"htSettings",
")",
";",
"if",
"(",
"htSettings",
".",
"hotId",
")",
"{",
"hotRegisterer",
".",
"registerInstance",
"(",
"htSettings",
".",
"hotId",
",",
"hot",
")",
";",
"}",
"return",
"hot",
";",
"}"
] |
Append handsontable container div and initialize handsontable instance inside element.
@param {qLite} element
@param {Object} htSettings
|
[
"Append",
"handsontable",
"container",
"div",
"and",
"initialize",
"handsontable",
"instance",
"inside",
"element",
"."
] |
c23f42ac1b937794ac93ded0a6392b55bbe4c16b
|
https://github.com/handsontable/ngHandsontable/blob/c23f42ac1b937794ac93ded0a6392b55bbe4c16b/dist/ngHandsontable.js#L130-L147
|
train
|
|
handsontable/ngHandsontable
|
dist/ngHandsontable.js
|
function(settings, scope) {
var
scopeOptions = angular.extend({}, scope),
htOptions, i, length;
settings = settings || {};
angular.extend(scopeOptions, scope.settings || {});
htOptions = this.getAvailableSettings();
for (i = 0, length = htOptions.length; i < length; i++) {
if (typeof scopeOptions[htOptions[i]] !== 'undefined') {
settings[htOptions[i]] = scopeOptions[htOptions[i]];
}
}
return settings;
}
|
javascript
|
function(settings, scope) {
var
scopeOptions = angular.extend({}, scope),
htOptions, i, length;
settings = settings || {};
angular.extend(scopeOptions, scope.settings || {});
htOptions = this.getAvailableSettings();
for (i = 0, length = htOptions.length; i < length; i++) {
if (typeof scopeOptions[htOptions[i]] !== 'undefined') {
settings[htOptions[i]] = scopeOptions[htOptions[i]];
}
}
return settings;
}
|
[
"function",
"(",
"settings",
",",
"scope",
")",
"{",
"var",
"scopeOptions",
"=",
"angular",
".",
"extend",
"(",
"{",
"}",
",",
"scope",
")",
",",
"htOptions",
",",
"i",
",",
"length",
";",
"settings",
"=",
"settings",
"||",
"{",
"}",
";",
"angular",
".",
"extend",
"(",
"scopeOptions",
",",
"scope",
".",
"settings",
"||",
"{",
"}",
")",
";",
"htOptions",
"=",
"this",
".",
"getAvailableSettings",
"(",
")",
";",
"for",
"(",
"i",
"=",
"0",
",",
"length",
"=",
"htOptions",
".",
"length",
";",
"i",
"<",
"length",
";",
"i",
"++",
")",
"{",
"if",
"(",
"typeof",
"scopeOptions",
"[",
"htOptions",
"[",
"i",
"]",
"]",
"!==",
"'undefined'",
")",
"{",
"settings",
"[",
"htOptions",
"[",
"i",
"]",
"]",
"=",
"scopeOptions",
"[",
"htOptions",
"[",
"i",
"]",
"]",
";",
"}",
"}",
"return",
"settings",
";",
"}"
] |
Merge original handsontable settings with setting defined in scope.
@param {Object} settings
@param {Object} scope
@returns {Object}
|
[
"Merge",
"original",
"handsontable",
"settings",
"with",
"setting",
"defined",
"in",
"scope",
"."
] |
c23f42ac1b937794ac93ded0a6392b55bbe4c16b
|
https://github.com/handsontable/ngHandsontable/blob/c23f42ac1b937794ac93ded0a6392b55bbe4c16b/dist/ngHandsontable.js#L179-L195
|
train
|
|
handsontable/ngHandsontable
|
dist/ngHandsontable.js
|
function(settings, scope) {
var
scopeOptions = angular.extend({}, scope),
htHooks, i, length, attribute;
settings = settings || {};
angular.extend(scopeOptions, scope.settings || {});
htHooks = this.getAvailableHooks();
for (i = 0, length = htHooks.length; i < length; i++) {
attribute = 'on' + ucFirst(htHooks[i]);
if (typeof scopeOptions[htHooks[i]] === 'function' || typeof scopeOptions[attribute] === 'function') {
settings[htHooks[i]] = scopeOptions[htHooks[i]] || scopeOptions[attribute];
}
}
return settings;
}
|
javascript
|
function(settings, scope) {
var
scopeOptions = angular.extend({}, scope),
htHooks, i, length, attribute;
settings = settings || {};
angular.extend(scopeOptions, scope.settings || {});
htHooks = this.getAvailableHooks();
for (i = 0, length = htHooks.length; i < length; i++) {
attribute = 'on' + ucFirst(htHooks[i]);
if (typeof scopeOptions[htHooks[i]] === 'function' || typeof scopeOptions[attribute] === 'function') {
settings[htHooks[i]] = scopeOptions[htHooks[i]] || scopeOptions[attribute];
}
}
return settings;
}
|
[
"function",
"(",
"settings",
",",
"scope",
")",
"{",
"var",
"scopeOptions",
"=",
"angular",
".",
"extend",
"(",
"{",
"}",
",",
"scope",
")",
",",
"htHooks",
",",
"i",
",",
"length",
",",
"attribute",
";",
"settings",
"=",
"settings",
"||",
"{",
"}",
";",
"angular",
".",
"extend",
"(",
"scopeOptions",
",",
"scope",
".",
"settings",
"||",
"{",
"}",
")",
";",
"htHooks",
"=",
"this",
".",
"getAvailableHooks",
"(",
")",
";",
"for",
"(",
"i",
"=",
"0",
",",
"length",
"=",
"htHooks",
".",
"length",
";",
"i",
"<",
"length",
";",
"i",
"++",
")",
"{",
"attribute",
"=",
"'on'",
"+",
"ucFirst",
"(",
"htHooks",
"[",
"i",
"]",
")",
";",
"if",
"(",
"typeof",
"scopeOptions",
"[",
"htHooks",
"[",
"i",
"]",
"]",
"===",
"'function'",
"||",
"typeof",
"scopeOptions",
"[",
"attribute",
"]",
"===",
"'function'",
")",
"{",
"settings",
"[",
"htHooks",
"[",
"i",
"]",
"]",
"=",
"scopeOptions",
"[",
"htHooks",
"[",
"i",
"]",
"]",
"||",
"scopeOptions",
"[",
"attribute",
"]",
";",
"}",
"}",
"return",
"settings",
";",
"}"
] |
Merge original handsontable hooks with hooks defined in scope.
@param {Object} settings
@param {Object} scope
@returns {Object}
|
[
"Merge",
"original",
"handsontable",
"hooks",
"with",
"hooks",
"defined",
"in",
"scope",
"."
] |
c23f42ac1b937794ac93ded0a6392b55bbe4c16b
|
https://github.com/handsontable/ngHandsontable/blob/c23f42ac1b937794ac93ded0a6392b55bbe4c16b/dist/ngHandsontable.js#L204-L222
|
train
|
|
handsontable/ngHandsontable
|
dist/ngHandsontable.js
|
function(scopeDefinition, attrs) {
for (var i in scopeDefinition) {
if (scopeDefinition.hasOwnProperty(i) && attrs[i] === void 0 &&
attrs[scopeDefinition[i].substr(1, scopeDefinition[i].length)] === void 0) {
delete scopeDefinition[i];
}
}
return scopeDefinition;
}
|
javascript
|
function(scopeDefinition, attrs) {
for (var i in scopeDefinition) {
if (scopeDefinition.hasOwnProperty(i) && attrs[i] === void 0 &&
attrs[scopeDefinition[i].substr(1, scopeDefinition[i].length)] === void 0) {
delete scopeDefinition[i];
}
}
return scopeDefinition;
}
|
[
"function",
"(",
"scopeDefinition",
",",
"attrs",
")",
"{",
"for",
"(",
"var",
"i",
"in",
"scopeDefinition",
")",
"{",
"if",
"(",
"scopeDefinition",
".",
"hasOwnProperty",
"(",
"i",
")",
"&&",
"attrs",
"[",
"i",
"]",
"===",
"void",
"0",
"&&",
"attrs",
"[",
"scopeDefinition",
"[",
"i",
"]",
".",
"substr",
"(",
"1",
",",
"scopeDefinition",
"[",
"i",
"]",
".",
"length",
")",
"]",
"===",
"void",
"0",
")",
"{",
"delete",
"scopeDefinition",
"[",
"i",
"]",
";",
"}",
"}",
"return",
"scopeDefinition",
";",
"}"
] |
Trim scope definition according to attrs object from directive.
@param {Object} scopeDefinition
@param {Object} attrs
@returns {Object}
|
[
"Trim",
"scope",
"definition",
"according",
"to",
"attrs",
"object",
"from",
"directive",
"."
] |
c23f42ac1b937794ac93ded0a6392b55bbe4c16b
|
https://github.com/handsontable/ngHandsontable/blob/c23f42ac1b937794ac93ded0a6392b55bbe4c16b/dist/ngHandsontable.js#L231-L240
|
train
|
|
handsontable/ngHandsontable
|
dist/ngHandsontable.js
|
function() {
var scopeDefinition = {};
this.applyAvailableSettingsScopeDef(scopeDefinition);
this.applyAvailableHooksScopeDef(scopeDefinition);
scopeDefinition.datarows = '=';
scopeDefinition.dataschema = '=';
scopeDefinition.observeDomVisibility = '=';
//scopeDefinition.settings = '=';
return scopeDefinition;
}
|
javascript
|
function() {
var scopeDefinition = {};
this.applyAvailableSettingsScopeDef(scopeDefinition);
this.applyAvailableHooksScopeDef(scopeDefinition);
scopeDefinition.datarows = '=';
scopeDefinition.dataschema = '=';
scopeDefinition.observeDomVisibility = '=';
//scopeDefinition.settings = '=';
return scopeDefinition;
}
|
[
"function",
"(",
")",
"{",
"var",
"scopeDefinition",
"=",
"{",
"}",
";",
"this",
".",
"applyAvailableSettingsScopeDef",
"(",
"scopeDefinition",
")",
";",
"this",
".",
"applyAvailableHooksScopeDef",
"(",
"scopeDefinition",
")",
";",
"scopeDefinition",
".",
"datarows",
"=",
"'='",
";",
"scopeDefinition",
".",
"dataschema",
"=",
"'='",
";",
"scopeDefinition",
".",
"observeDomVisibility",
"=",
"'='",
";",
"return",
"scopeDefinition",
";",
"}"
] |
Get isolate scope definition for main handsontable directive.
@return {Object}
|
[
"Get",
"isolate",
"scope",
"definition",
"for",
"main",
"handsontable",
"directive",
"."
] |
c23f42ac1b937794ac93ded0a6392b55bbe4c16b
|
https://github.com/handsontable/ngHandsontable/blob/c23f42ac1b937794ac93ded0a6392b55bbe4c16b/dist/ngHandsontable.js#L247-L259
|
train
|
|
handsontable/ngHandsontable
|
dist/ngHandsontable.js
|
function(scopeDefinition) {
var options, i, length;
options = this.getAvailableSettings();
for (i = 0, length = options.length; i < length; i++) {
scopeDefinition[options[i]] = '=';
}
return scopeDefinition;
}
|
javascript
|
function(scopeDefinition) {
var options, i, length;
options = this.getAvailableSettings();
for (i = 0, length = options.length; i < length; i++) {
scopeDefinition[options[i]] = '=';
}
return scopeDefinition;
}
|
[
"function",
"(",
"scopeDefinition",
")",
"{",
"var",
"options",
",",
"i",
",",
"length",
";",
"options",
"=",
"this",
".",
"getAvailableSettings",
"(",
")",
";",
"for",
"(",
"i",
"=",
"0",
",",
"length",
"=",
"options",
".",
"length",
";",
"i",
"<",
"length",
";",
"i",
"++",
")",
"{",
"scopeDefinition",
"[",
"options",
"[",
"i",
"]",
"]",
"=",
"'='",
";",
"}",
"return",
"scopeDefinition",
";",
"}"
] |
Apply all available handsontable settings into object which represents scope definition.
@param {Object} [scopeDefinition]
@returns {Object}
|
[
"Apply",
"all",
"available",
"handsontable",
"settings",
"into",
"object",
"which",
"represents",
"scope",
"definition",
"."
] |
c23f42ac1b937794ac93ded0a6392b55bbe4c16b
|
https://github.com/handsontable/ngHandsontable/blob/c23f42ac1b937794ac93ded0a6392b55bbe4c16b/dist/ngHandsontable.js#L281-L291
|
train
|
|
handsontable/ngHandsontable
|
dist/ngHandsontable.js
|
function(scopeDefinition) {
var options, i, length;
options = this.getAvailableHooks();
for (i = 0, length = options.length; i < length; i++) {
scopeDefinition[options[i]] = '=on' + ucFirst(options[i]);
}
return scopeDefinition;
}
|
javascript
|
function(scopeDefinition) {
var options, i, length;
options = this.getAvailableHooks();
for (i = 0, length = options.length; i < length; i++) {
scopeDefinition[options[i]] = '=on' + ucFirst(options[i]);
}
return scopeDefinition;
}
|
[
"function",
"(",
"scopeDefinition",
")",
"{",
"var",
"options",
",",
"i",
",",
"length",
";",
"options",
"=",
"this",
".",
"getAvailableHooks",
"(",
")",
";",
"for",
"(",
"i",
"=",
"0",
",",
"length",
"=",
"options",
".",
"length",
";",
"i",
"<",
"length",
";",
"i",
"++",
")",
"{",
"scopeDefinition",
"[",
"options",
"[",
"i",
"]",
"]",
"=",
"'=on'",
"+",
"ucFirst",
"(",
"options",
"[",
"i",
"]",
")",
";",
"}",
"return",
"scopeDefinition",
";",
"}"
] |
Apply all available handsontable hooks into object which represents scope definition.
@param {Object} [scopeDefinition]
@returns {Object}
|
[
"Apply",
"all",
"available",
"handsontable",
"hooks",
"into",
"object",
"which",
"represents",
"scope",
"definition",
"."
] |
c23f42ac1b937794ac93ded0a6392b55bbe4c16b
|
https://github.com/handsontable/ngHandsontable/blob/c23f42ac1b937794ac93ded0a6392b55bbe4c16b/dist/ngHandsontable.js#L299-L309
|
train
|
|
handsontable/ngHandsontable
|
dist/ngHandsontable.js
|
function(hyphenateStyle) {
var settings = Object.keys(Handsontable.DefaultSettings.prototype);
if (settings.indexOf('contextMenuCopyPaste') === -1) {
settings.push('contextMenuCopyPaste');
}
if (settings.indexOf('handsontable') === -1) {
settings.push('handsontable');
}
if (settings.indexOf('settings') >= 0) {
settings.splice(settings.indexOf('settings'), 1);
}
if (hyphenateStyle) {
settings = settings.map(hyphenate);
}
return settings;
}
|
javascript
|
function(hyphenateStyle) {
var settings = Object.keys(Handsontable.DefaultSettings.prototype);
if (settings.indexOf('contextMenuCopyPaste') === -1) {
settings.push('contextMenuCopyPaste');
}
if (settings.indexOf('handsontable') === -1) {
settings.push('handsontable');
}
if (settings.indexOf('settings') >= 0) {
settings.splice(settings.indexOf('settings'), 1);
}
if (hyphenateStyle) {
settings = settings.map(hyphenate);
}
return settings;
}
|
[
"function",
"(",
"hyphenateStyle",
")",
"{",
"var",
"settings",
"=",
"Object",
".",
"keys",
"(",
"Handsontable",
".",
"DefaultSettings",
".",
"prototype",
")",
";",
"if",
"(",
"settings",
".",
"indexOf",
"(",
"'contextMenuCopyPaste'",
")",
"===",
"-",
"1",
")",
"{",
"settings",
".",
"push",
"(",
"'contextMenuCopyPaste'",
")",
";",
"}",
"if",
"(",
"settings",
".",
"indexOf",
"(",
"'handsontable'",
")",
"===",
"-",
"1",
")",
"{",
"settings",
".",
"push",
"(",
"'handsontable'",
")",
";",
"}",
"if",
"(",
"settings",
".",
"indexOf",
"(",
"'settings'",
")",
">=",
"0",
")",
"{",
"settings",
".",
"splice",
"(",
"settings",
".",
"indexOf",
"(",
"'settings'",
")",
",",
"1",
")",
";",
"}",
"if",
"(",
"hyphenateStyle",
")",
"{",
"settings",
"=",
"settings",
".",
"map",
"(",
"hyphenate",
")",
";",
"}",
"return",
"settings",
";",
"}"
] |
Get all available settings from handsontable, returns settings by default in camelCase mode.
@param {Boolean} [hyphenateStyle=undefined] If `true` then returns options in hyphenate mode (eq. row-header)
@returns {Array}
|
[
"Get",
"all",
"available",
"settings",
"from",
"handsontable",
"returns",
"settings",
"by",
"default",
"in",
"camelCase",
"mode",
"."
] |
c23f42ac1b937794ac93ded0a6392b55bbe4c16b
|
https://github.com/handsontable/ngHandsontable/blob/c23f42ac1b937794ac93ded0a6392b55bbe4c16b/dist/ngHandsontable.js#L317-L334
|
train
|
|
handsontable/ngHandsontable
|
dist/ngHandsontable.js
|
function(hyphenateStyle) {
var settings = Handsontable.hooks.getRegistered();
if (hyphenateStyle) {
settings = settings.map(function(hook) {
return 'on-' + hyphenate(hook);
});
}
return settings;
}
|
javascript
|
function(hyphenateStyle) {
var settings = Handsontable.hooks.getRegistered();
if (hyphenateStyle) {
settings = settings.map(function(hook) {
return 'on-' + hyphenate(hook);
});
}
return settings;
}
|
[
"function",
"(",
"hyphenateStyle",
")",
"{",
"var",
"settings",
"=",
"Handsontable",
".",
"hooks",
".",
"getRegistered",
"(",
")",
";",
"if",
"(",
"hyphenateStyle",
")",
"{",
"settings",
"=",
"settings",
".",
"map",
"(",
"function",
"(",
"hook",
")",
"{",
"return",
"'on-'",
"+",
"hyphenate",
"(",
"hook",
")",
";",
"}",
")",
";",
"}",
"return",
"settings",
";",
"}"
] |
Get all available hooks from handsontable, returns hooks by default in camelCase mode.
@param {Boolean} [hyphenateStyle=undefined] If `true` then returns hooks in hyphenate mode (eq. on-after-init)
@returns {Array}
|
[
"Get",
"all",
"available",
"hooks",
"from",
"handsontable",
"returns",
"hooks",
"by",
"default",
"in",
"camelCase",
"mode",
"."
] |
c23f42ac1b937794ac93ded0a6392b55bbe4c16b
|
https://github.com/handsontable/ngHandsontable/blob/c23f42ac1b937794ac93ded0a6392b55bbe4c16b/dist/ngHandsontable.js#L342-L352
|
train
|
|
QuickBlox/quickblox-javascript-sdk
|
samples/video_conferencing/js/video/ui_helpers.js
|
autoClosePopups
|
function autoClosePopups(clear) {
if (clear) {
clearTimeout(modalTimerID);
modalTimerID = undefined;
} else {
modalTimerID = setTimeout(function() {
bootbox.hideAll();
}, 30000);
}
}
|
javascript
|
function autoClosePopups(clear) {
if (clear) {
clearTimeout(modalTimerID);
modalTimerID = undefined;
} else {
modalTimerID = setTimeout(function() {
bootbox.hideAll();
}, 30000);
}
}
|
[
"function",
"autoClosePopups",
"(",
"clear",
")",
"{",
"if",
"(",
"clear",
")",
"{",
"clearTimeout",
"(",
"modalTimerID",
")",
";",
"modalTimerID",
"=",
"undefined",
";",
"}",
"else",
"{",
"modalTimerID",
"=",
"setTimeout",
"(",
"function",
"(",
")",
"{",
"bootbox",
".",
"hideAll",
"(",
")",
";",
"}",
",",
"30000",
")",
";",
"}",
"}"
] |
modal's timer
|
[
"modal",
"s",
"timer"
] |
23edee3c5904cff3d723907a928ddf20dab8ffa5
|
https://github.com/QuickBlox/quickblox-javascript-sdk/blob/23edee3c5904cff3d723907a928ddf20dab8ffa5/samples/video_conferencing/js/video/ui_helpers.js#L368-L377
|
train
|
QuickBlox/quickblox-javascript-sdk
|
samples/cordova/text_chat/www/js/ui_helpers.js
|
buildUserHtml
|
function buildUserHtml(userLogin, userId, isNew) {
var userHtml = "<a href='#' id='" + userId;
if(isNew){
userHtml += "_new'";
}else{
userHtml += "'";
}
userHtml += " class='col-md-12 col-sm-12 col-xs-12 users_form' onclick='";
userHtml += "clickToAdd";
userHtml += "(\"";
userHtml += userId;
if(isNew){
userHtml += "_new";
}
userHtml += "\")'>";
userHtml += userLogin;
userHtml +="</a>";
return userHtml;
}
|
javascript
|
function buildUserHtml(userLogin, userId, isNew) {
var userHtml = "<a href='#' id='" + userId;
if(isNew){
userHtml += "_new'";
}else{
userHtml += "'";
}
userHtml += " class='col-md-12 col-sm-12 col-xs-12 users_form' onclick='";
userHtml += "clickToAdd";
userHtml += "(\"";
userHtml += userId;
if(isNew){
userHtml += "_new";
}
userHtml += "\")'>";
userHtml += userLogin;
userHtml +="</a>";
return userHtml;
}
|
[
"function",
"buildUserHtml",
"(",
"userLogin",
",",
"userId",
",",
"isNew",
")",
"{",
"var",
"userHtml",
"=",
"\"<a href='#' id='\"",
"+",
"userId",
";",
"if",
"(",
"isNew",
")",
"{",
"userHtml",
"+=",
"\"_new'\"",
";",
"}",
"else",
"{",
"userHtml",
"+=",
"\"'\"",
";",
"}",
"userHtml",
"+=",
"\" class='col-md-12 col-sm-12 col-xs-12 users_form' onclick='\"",
";",
"userHtml",
"+=",
"\"clickToAdd\"",
";",
"userHtml",
"+=",
"\"(\\\"\"",
";",
"\\\"",
"userHtml",
"+=",
"userId",
";",
"if",
"(",
"isNew",
")",
"{",
"userHtml",
"+=",
"\"_new\"",
";",
"}",
"userHtml",
"+=",
"\"\\\")'>\"",
";",
"\\\"",
"userHtml",
"+=",
"userLogin",
";",
"}"
] |
build html for users list
|
[
"build",
"html",
"for",
"users",
"list"
] |
23edee3c5904cff3d723907a928ddf20dab8ffa5
|
https://github.com/QuickBlox/quickblox-javascript-sdk/blob/23edee3c5904cff3d723907a928ddf20dab8ffa5/samples/cordova/text_chat/www/js/ui_helpers.js#L76-L95
|
train
|
QuickBlox/quickblox-javascript-sdk
|
samples/cordova/video_chat/platforms/ios/cordova/lib/prepare.js
|
cleanLaunchStoryboardImages
|
function cleanLaunchStoryboardImages(projectRoot, projectConfig, locations) {
var splashScreens = projectConfig.getSplashScreens('ios');
var platformProjDir = locations.xcodeCordovaProj;
var launchStoryboardImagesDir = getLaunchStoryboardImagesDir(projectRoot, platformProjDir);
if (launchStoryboardImagesDir) {
var resourceMap = mapLaunchStoryboardResources(splashScreens, launchStoryboardImagesDir);
var contentsJSON = getLaunchStoryboardContentsJSON(splashScreens, launchStoryboardImagesDir);
Object.keys(resourceMap).forEach(function (targetPath) {
resourceMap[targetPath] = null;
});
events.emit('verbose', 'Cleaning storyboard image set at ' + launchStoryboardImagesDir);
// Source paths are removed from the map, so updatePaths() will delete the target files.
FileUpdater.updatePaths(
resourceMap, { rootDir: projectRoot, all: true }, logFileOp);
// delete filename from contents.json
contentsJSON.images.forEach(function(image) {
image.filename = undefined;
});
events.emit('verbose', 'Updating Storyboard image set contents.json');
fs.writeFileSync(path.join(launchStoryboardImagesDir, 'contents.json'),
JSON.stringify(contentsJSON, null, 2));
}
}
|
javascript
|
function cleanLaunchStoryboardImages(projectRoot, projectConfig, locations) {
var splashScreens = projectConfig.getSplashScreens('ios');
var platformProjDir = locations.xcodeCordovaProj;
var launchStoryboardImagesDir = getLaunchStoryboardImagesDir(projectRoot, platformProjDir);
if (launchStoryboardImagesDir) {
var resourceMap = mapLaunchStoryboardResources(splashScreens, launchStoryboardImagesDir);
var contentsJSON = getLaunchStoryboardContentsJSON(splashScreens, launchStoryboardImagesDir);
Object.keys(resourceMap).forEach(function (targetPath) {
resourceMap[targetPath] = null;
});
events.emit('verbose', 'Cleaning storyboard image set at ' + launchStoryboardImagesDir);
// Source paths are removed from the map, so updatePaths() will delete the target files.
FileUpdater.updatePaths(
resourceMap, { rootDir: projectRoot, all: true }, logFileOp);
// delete filename from contents.json
contentsJSON.images.forEach(function(image) {
image.filename = undefined;
});
events.emit('verbose', 'Updating Storyboard image set contents.json');
fs.writeFileSync(path.join(launchStoryboardImagesDir, 'contents.json'),
JSON.stringify(contentsJSON, null, 2));
}
}
|
[
"function",
"cleanLaunchStoryboardImages",
"(",
"projectRoot",
",",
"projectConfig",
",",
"locations",
")",
"{",
"var",
"splashScreens",
"=",
"projectConfig",
".",
"getSplashScreens",
"(",
"'ios'",
")",
";",
"var",
"platformProjDir",
"=",
"locations",
".",
"xcodeCordovaProj",
";",
"var",
"launchStoryboardImagesDir",
"=",
"getLaunchStoryboardImagesDir",
"(",
"projectRoot",
",",
"platformProjDir",
")",
";",
"if",
"(",
"launchStoryboardImagesDir",
")",
"{",
"var",
"resourceMap",
"=",
"mapLaunchStoryboardResources",
"(",
"splashScreens",
",",
"launchStoryboardImagesDir",
")",
";",
"var",
"contentsJSON",
"=",
"getLaunchStoryboardContentsJSON",
"(",
"splashScreens",
",",
"launchStoryboardImagesDir",
")",
";",
"Object",
".",
"keys",
"(",
"resourceMap",
")",
".",
"forEach",
"(",
"function",
"(",
"targetPath",
")",
"{",
"resourceMap",
"[",
"targetPath",
"]",
"=",
"null",
";",
"}",
")",
";",
"events",
".",
"emit",
"(",
"'verbose'",
",",
"'Cleaning storyboard image set at '",
"+",
"launchStoryboardImagesDir",
")",
";",
"FileUpdater",
".",
"updatePaths",
"(",
"resourceMap",
",",
"{",
"rootDir",
":",
"projectRoot",
",",
"all",
":",
"true",
"}",
",",
"logFileOp",
")",
";",
"contentsJSON",
".",
"images",
".",
"forEach",
"(",
"function",
"(",
"image",
")",
"{",
"image",
".",
"filename",
"=",
"undefined",
";",
"}",
")",
";",
"events",
".",
"emit",
"(",
"'verbose'",
",",
"'Updating Storyboard image set contents.json'",
")",
";",
"fs",
".",
"writeFileSync",
"(",
"path",
".",
"join",
"(",
"launchStoryboardImagesDir",
",",
"'contents.json'",
")",
",",
"JSON",
".",
"stringify",
"(",
"contentsJSON",
",",
"null",
",",
"2",
")",
")",
";",
"}",
"}"
] |
Removes the images from the launch storyboard's image set and updates the image set's contents.json
file appropriately.
@param {string} projectRoot Path to the project root
@param {Object} projectConfig The project's config.xml
@param {Object} locations A dictionary containing useful location paths
|
[
"Removes",
"the",
"images",
"from",
"the",
"launch",
"storyboard",
"s",
"image",
"set",
"and",
"updates",
"the",
"image",
"set",
"s",
"contents",
".",
"json",
"file",
"appropriately",
"."
] |
23edee3c5904cff3d723907a928ddf20dab8ffa5
|
https://github.com/QuickBlox/quickblox-javascript-sdk/blob/23edee3c5904cff3d723907a928ddf20dab8ffa5/samples/cordova/video_chat/platforms/ios/cordova/lib/prepare.js#L713-L739
|
train
|
QuickBlox/quickblox-javascript-sdk
|
src/modules/chat/qbChat.js
|
function(callback, isInitialConnect) {
Utils.QBLog('[QBChat]', 'Status.CONNECTED at ' + chatUtils.getLocalTime());
var self = this,
xmppClient = Utils.getEnv().browser ? self.connection : self.Client,
presence = Utils.getEnv().browser ? $pres() : chatUtils.createStanza(XMPP.Stanza, null, 'presence');
if (config.streamManagement.enable && config.chatProtocol.active === 2) {
self.streamManagement.enable(self.connection, null);
self.streamManagement.sentMessageCallback = self._sentMessageCallback;
}
self.helpers.setUserCurrentJid(self.helpers.userCurrentJid(xmppClient));
self.isConnected = true;
self._isConnecting = false;
self._enableCarbons();
if (isInitialConnect) {
self.roster.get(function(contacts) {
xmppClient.send(presence);
self.roster.contacts = contacts;
callback(self.roster.contacts);
});
} else {
var rooms = Object.keys(self.muc.joinedRooms);
xmppClient.send(presence);
Utils.QBLog('[QBChat]', 'Re-joining ' + rooms.length + " rooms...");
for (var i = 0, len = rooms.length; i < len; i++) {
self.muc.join(rooms[i]);
}
if (typeof self.onReconnectListener === 'function') {
Utils.safeCallbackCall(self.onReconnectListener);
}
}
}
|
javascript
|
function(callback, isInitialConnect) {
Utils.QBLog('[QBChat]', 'Status.CONNECTED at ' + chatUtils.getLocalTime());
var self = this,
xmppClient = Utils.getEnv().browser ? self.connection : self.Client,
presence = Utils.getEnv().browser ? $pres() : chatUtils.createStanza(XMPP.Stanza, null, 'presence');
if (config.streamManagement.enable && config.chatProtocol.active === 2) {
self.streamManagement.enable(self.connection, null);
self.streamManagement.sentMessageCallback = self._sentMessageCallback;
}
self.helpers.setUserCurrentJid(self.helpers.userCurrentJid(xmppClient));
self.isConnected = true;
self._isConnecting = false;
self._enableCarbons();
if (isInitialConnect) {
self.roster.get(function(contacts) {
xmppClient.send(presence);
self.roster.contacts = contacts;
callback(self.roster.contacts);
});
} else {
var rooms = Object.keys(self.muc.joinedRooms);
xmppClient.send(presence);
Utils.QBLog('[QBChat]', 'Re-joining ' + rooms.length + " rooms...");
for (var i = 0, len = rooms.length; i < len; i++) {
self.muc.join(rooms[i]);
}
if (typeof self.onReconnectListener === 'function') {
Utils.safeCallbackCall(self.onReconnectListener);
}
}
}
|
[
"function",
"(",
"callback",
",",
"isInitialConnect",
")",
"{",
"Utils",
".",
"QBLog",
"(",
"'[QBChat]'",
",",
"'Status.CONNECTED at '",
"+",
"chatUtils",
".",
"getLocalTime",
"(",
")",
")",
";",
"var",
"self",
"=",
"this",
",",
"xmppClient",
"=",
"Utils",
".",
"getEnv",
"(",
")",
".",
"browser",
"?",
"self",
".",
"connection",
":",
"self",
".",
"Client",
",",
"presence",
"=",
"Utils",
".",
"getEnv",
"(",
")",
".",
"browser",
"?",
"$pres",
"(",
")",
":",
"chatUtils",
".",
"createStanza",
"(",
"XMPP",
".",
"Stanza",
",",
"null",
",",
"'presence'",
")",
";",
"if",
"(",
"config",
".",
"streamManagement",
".",
"enable",
"&&",
"config",
".",
"chatProtocol",
".",
"active",
"===",
"2",
")",
"{",
"self",
".",
"streamManagement",
".",
"enable",
"(",
"self",
".",
"connection",
",",
"null",
")",
";",
"self",
".",
"streamManagement",
".",
"sentMessageCallback",
"=",
"self",
".",
"_sentMessageCallback",
";",
"}",
"self",
".",
"helpers",
".",
"setUserCurrentJid",
"(",
"self",
".",
"helpers",
".",
"userCurrentJid",
"(",
"xmppClient",
")",
")",
";",
"self",
".",
"isConnected",
"=",
"true",
";",
"self",
".",
"_isConnecting",
"=",
"false",
";",
"self",
".",
"_enableCarbons",
"(",
")",
";",
"if",
"(",
"isInitialConnect",
")",
"{",
"self",
".",
"roster",
".",
"get",
"(",
"function",
"(",
"contacts",
")",
"{",
"xmppClient",
".",
"send",
"(",
"presence",
")",
";",
"self",
".",
"roster",
".",
"contacts",
"=",
"contacts",
";",
"callback",
"(",
"self",
".",
"roster",
".",
"contacts",
")",
";",
"}",
")",
";",
"}",
"else",
"{",
"var",
"rooms",
"=",
"Object",
".",
"keys",
"(",
"self",
".",
"muc",
".",
"joinedRooms",
")",
";",
"xmppClient",
".",
"send",
"(",
"presence",
")",
";",
"Utils",
".",
"QBLog",
"(",
"'[QBChat]'",
",",
"'Re-joining '",
"+",
"rooms",
".",
"length",
"+",
"\" rooms...\"",
")",
";",
"for",
"(",
"var",
"i",
"=",
"0",
",",
"len",
"=",
"rooms",
".",
"length",
";",
"i",
"<",
"len",
";",
"i",
"++",
")",
"{",
"self",
".",
"muc",
".",
"join",
"(",
"rooms",
"[",
"i",
"]",
")",
";",
"}",
"if",
"(",
"typeof",
"self",
".",
"onReconnectListener",
"===",
"'function'",
")",
"{",
"Utils",
".",
"safeCallbackCall",
"(",
"self",
".",
"onReconnectListener",
")",
";",
"}",
"}",
"}"
] |
Actions after the connection is established
- enable stream management (the configuration setting);
- save user's JID;
- enable carbons;
- get and storage the user's roster (if the initial connect);
- recover the joined rooms and fire 'onReconnectListener' (if the reconnect);
- send initial presence to the chat server.
|
[
"Actions",
"after",
"the",
"connection",
"is",
"established"
] |
23edee3c5904cff3d723907a928ddf20dab8ffa5
|
https://github.com/QuickBlox/quickblox-javascript-sdk/blob/23edee3c5904cff3d723907a928ddf20dab8ffa5/src/modules/chat/qbChat.js#L872-L913
|
train
|
|
QuickBlox/quickblox-javascript-sdk
|
src/modules/chat/qbChat.js
|
function(listWithUpdates, callback) {
/**
* Callback for QB.chat.privacylist.update().
* @param {Object} error - The error object
* @param {Object} response - The privacy list object
* @callback updatePrivacylistCallback
* */
var self = this;
self.getList(listWithUpdates.name, function(error, existentList) {
if (error) {
callback(error, null);
} else {
var updatedList = {};
updatedList.items = Utils.MergeArrayOfObjects(existentList.items, listWithUpdates.items);
updatedList.name = listWithUpdates.name;
self.create(updatedList, function(err, result) {
if (error) {
callback(err, null);
}else{
callback(null, result);
}
});
}
});
}
|
javascript
|
function(listWithUpdates, callback) {
/**
* Callback for QB.chat.privacylist.update().
* @param {Object} error - The error object
* @param {Object} response - The privacy list object
* @callback updatePrivacylistCallback
* */
var self = this;
self.getList(listWithUpdates.name, function(error, existentList) {
if (error) {
callback(error, null);
} else {
var updatedList = {};
updatedList.items = Utils.MergeArrayOfObjects(existentList.items, listWithUpdates.items);
updatedList.name = listWithUpdates.name;
self.create(updatedList, function(err, result) {
if (error) {
callback(err, null);
}else{
callback(null, result);
}
});
}
});
}
|
[
"function",
"(",
"listWithUpdates",
",",
"callback",
")",
"{",
"var",
"self",
"=",
"this",
";",
"self",
".",
"getList",
"(",
"listWithUpdates",
".",
"name",
",",
"function",
"(",
"error",
",",
"existentList",
")",
"{",
"if",
"(",
"error",
")",
"{",
"callback",
"(",
"error",
",",
"null",
")",
";",
"}",
"else",
"{",
"var",
"updatedList",
"=",
"{",
"}",
";",
"updatedList",
".",
"items",
"=",
"Utils",
".",
"MergeArrayOfObjects",
"(",
"existentList",
".",
"items",
",",
"listWithUpdates",
".",
"items",
")",
";",
"updatedList",
".",
"name",
"=",
"listWithUpdates",
".",
"name",
";",
"self",
".",
"create",
"(",
"updatedList",
",",
"function",
"(",
"err",
",",
"result",
")",
"{",
"if",
"(",
"error",
")",
"{",
"callback",
"(",
"err",
",",
"null",
")",
";",
"}",
"else",
"{",
"callback",
"(",
"null",
",",
"result",
")",
";",
"}",
"}",
")",
";",
"}",
"}",
")",
";",
"}"
] |
Update the privacy list.
@memberof QB.chat.privacylist
@param {String} name - The name of the list.
@param {updatePrivacylistCallback} callback - The callback function.
|
[
"Update",
"the",
"privacy",
"list",
"."
] |
23edee3c5904cff3d723907a928ddf20dab8ffa5
|
https://github.com/QuickBlox/quickblox-javascript-sdk/blob/23edee3c5904cff3d723907a928ddf20dab8ffa5/src/modules/chat/qbChat.js#L2008-L2035
|
train
|
|
QuickBlox/quickblox-javascript-sdk
|
src/modules/chat/qbChat.js
|
function(jid_or_user_id) {
var jid;
if (typeof jid_or_user_id === 'string') {
jid = jid_or_user_id;
} else if (typeof jid_or_user_id === 'number') {
jid = jid_or_user_id + '-' + config.creds.appId + '@' + config.endpoints.chat;
} else {
throw new Error('The method "jidOrUserId" may take jid or id');
}
return jid;
}
|
javascript
|
function(jid_or_user_id) {
var jid;
if (typeof jid_or_user_id === 'string') {
jid = jid_or_user_id;
} else if (typeof jid_or_user_id === 'number') {
jid = jid_or_user_id + '-' + config.creds.appId + '@' + config.endpoints.chat;
} else {
throw new Error('The method "jidOrUserId" may take jid or id');
}
return jid;
}
|
[
"function",
"(",
"jid_or_user_id",
")",
"{",
"var",
"jid",
";",
"if",
"(",
"typeof",
"jid_or_user_id",
"===",
"'string'",
")",
"{",
"jid",
"=",
"jid_or_user_id",
";",
"}",
"else",
"if",
"(",
"typeof",
"jid_or_user_id",
"===",
"'number'",
")",
"{",
"jid",
"=",
"jid_or_user_id",
"+",
"'-'",
"+",
"config",
".",
"creds",
".",
"appId",
"+",
"'@'",
"+",
"config",
".",
"endpoints",
".",
"chat",
";",
"}",
"else",
"{",
"throw",
"new",
"Error",
"(",
"'The method \"jidOrUserId\" may take jid or id'",
")",
";",
"}",
"return",
"jid",
";",
"}"
] |
Get unique id.
@memberof QB.chat.helpers
@param {String | Number} jid_or_user_id - Jid or user id.
@returns {String} - jid.
|
[
"Get",
"unique",
"id",
"."
] |
23edee3c5904cff3d723907a928ddf20dab8ffa5
|
https://github.com/QuickBlox/quickblox-javascript-sdk/blob/23edee3c5904cff3d723907a928ddf20dab8ffa5/src/modules/chat/qbChat.js#L2270-L2280
|
train
|
|
QuickBlox/quickblox-javascript-sdk
|
src/modules/chat/qbChat.js
|
function(jid_or_user_id) {
var chatType;
if (typeof jid_or_user_id === 'string') {
chatType = jid_or_user_id.indexOf("muc") > -1 ? 'groupchat' : 'chat';
} else if (typeof jid_or_user_id === 'number') {
chatType = 'chat';
} else {
throw new Error(unsupportedError);
}
return chatType;
}
|
javascript
|
function(jid_or_user_id) {
var chatType;
if (typeof jid_or_user_id === 'string') {
chatType = jid_or_user_id.indexOf("muc") > -1 ? 'groupchat' : 'chat';
} else if (typeof jid_or_user_id === 'number') {
chatType = 'chat';
} else {
throw new Error(unsupportedError);
}
return chatType;
}
|
[
"function",
"(",
"jid_or_user_id",
")",
"{",
"var",
"chatType",
";",
"if",
"(",
"typeof",
"jid_or_user_id",
"===",
"'string'",
")",
"{",
"chatType",
"=",
"jid_or_user_id",
".",
"indexOf",
"(",
"\"muc\"",
")",
">",
"-",
"1",
"?",
"'groupchat'",
":",
"'chat'",
";",
"}",
"else",
"if",
"(",
"typeof",
"jid_or_user_id",
"===",
"'number'",
")",
"{",
"chatType",
"=",
"'chat'",
";",
"}",
"else",
"{",
"throw",
"new",
"Error",
"(",
"unsupportedError",
")",
";",
"}",
"return",
"chatType",
";",
"}"
] |
Get the chat type.
@memberof QB.chat.helpers
@param {String | Number} jid_or_user_id - Jid or user id.
@returns {String} - jid.
|
[
"Get",
"the",
"chat",
"type",
"."
] |
23edee3c5904cff3d723907a928ddf20dab8ffa5
|
https://github.com/QuickBlox/quickblox-javascript-sdk/blob/23edee3c5904cff3d723907a928ddf20dab8ffa5/src/modules/chat/qbChat.js#L2288-L2298
|
train
|
|
QuickBlox/quickblox-javascript-sdk
|
src/modules/chat/qbChat.js
|
function(occupantsIds, UserId) {
var recipient = null;
occupantsIds.forEach(function(item) {
if(item != UserId){
recipient = item;
}
});
return recipient;
}
|
javascript
|
function(occupantsIds, UserId) {
var recipient = null;
occupantsIds.forEach(function(item) {
if(item != UserId){
recipient = item;
}
});
return recipient;
}
|
[
"function",
"(",
"occupantsIds",
",",
"UserId",
")",
"{",
"var",
"recipient",
"=",
"null",
";",
"occupantsIds",
".",
"forEach",
"(",
"function",
"(",
"item",
")",
"{",
"if",
"(",
"item",
"!=",
"UserId",
")",
"{",
"recipient",
"=",
"item",
";",
"}",
"}",
")",
";",
"return",
"recipient",
";",
"}"
] |
Get the recipint id.
@memberof QB.chat.helpers
@param {Array} occupantsIds - Array of user ids.
@param {Number} UserId - Jid or user id.
@returns {Number} recipient - recipient id.
|
[
"Get",
"the",
"recipint",
"id",
"."
] |
23edee3c5904cff3d723907a928ddf20dab8ffa5
|
https://github.com/QuickBlox/quickblox-javascript-sdk/blob/23edee3c5904cff3d723907a928ddf20dab8ffa5/src/modules/chat/qbChat.js#L2307-L2315
|
train
|
|
QuickBlox/quickblox-javascript-sdk
|
src/modules/chat/qbChat.js
|
function(userId, appId) {
if(!appId){
return userId + '-' + config.creds.appId + '@' + config.endpoints.chat;
}
return userId + '-' + appId + '@' + config.endpoints.chat;
}
|
javascript
|
function(userId, appId) {
if(!appId){
return userId + '-' + config.creds.appId + '@' + config.endpoints.chat;
}
return userId + '-' + appId + '@' + config.endpoints.chat;
}
|
[
"function",
"(",
"userId",
",",
"appId",
")",
"{",
"if",
"(",
"!",
"appId",
")",
"{",
"return",
"userId",
"+",
"'-'",
"+",
"config",
".",
"creds",
".",
"appId",
"+",
"'@'",
"+",
"config",
".",
"endpoints",
".",
"chat",
";",
"}",
"return",
"userId",
"+",
"'-'",
"+",
"appId",
"+",
"'@'",
"+",
"config",
".",
"endpoints",
".",
"chat",
";",
"}"
] |
Get the User jid id.
@memberof QB.chat.helpers
@param {Number} UserId - The user id.
@param {Number} appId - The application id.
@returns {String} jid - The user jid.
|
[
"Get",
"the",
"User",
"jid",
"id",
"."
] |
23edee3c5904cff3d723907a928ddf20dab8ffa5
|
https://github.com/QuickBlox/quickblox-javascript-sdk/blob/23edee3c5904cff3d723907a928ddf20dab8ffa5/src/modules/chat/qbChat.js#L2324-L2329
|
train
|
|
QuickBlox/quickblox-javascript-sdk
|
src/modules/chat/qbChat.js
|
function(jid) {
var s = jid.split('/');
if (s.length < 2) return null;
s.splice(0, 1);
return parseInt(s.join('/'));
}
|
javascript
|
function(jid) {
var s = jid.split('/');
if (s.length < 2) return null;
s.splice(0, 1);
return parseInt(s.join('/'));
}
|
[
"function",
"(",
"jid",
")",
"{",
"var",
"s",
"=",
"jid",
".",
"split",
"(",
"'/'",
")",
";",
"if",
"(",
"s",
".",
"length",
"<",
"2",
")",
"return",
"null",
";",
"s",
".",
"splice",
"(",
"0",
",",
"1",
")",
";",
"return",
"parseInt",
"(",
"s",
".",
"join",
"(",
"'/'",
")",
")",
";",
"}"
] |
Get user id from dialog's full jid.
@memberof QB.chat.helpers
@param {String} jid - dialog's full jid.
@returns {String} user_id - User Id.
|
[
"Get",
"user",
"id",
"from",
"dialog",
"s",
"full",
"jid",
"."
] |
23edee3c5904cff3d723907a928ddf20dab8ffa5
|
https://github.com/QuickBlox/quickblox-javascript-sdk/blob/23edee3c5904cff3d723907a928ddf20dab8ffa5/src/modules/chat/qbChat.js#L2389-L2394
|
train
|
|
QuickBlox/quickblox-javascript-sdk
|
src/modules/chat/qbChat.js
|
function(jid) {
var arrayElements = jid.toString().split('/');
if(arrayElements.length === 0){
return null;
}
return arrayElements[arrayElements.length-1];
}
|
javascript
|
function(jid) {
var arrayElements = jid.toString().split('/');
if(arrayElements.length === 0){
return null;
}
return arrayElements[arrayElements.length-1];
}
|
[
"function",
"(",
"jid",
")",
"{",
"var",
"arrayElements",
"=",
"jid",
".",
"toString",
"(",
")",
".",
"split",
"(",
"'/'",
")",
";",
"if",
"(",
"arrayElements",
".",
"length",
"===",
"0",
")",
"{",
"return",
"null",
";",
"}",
"return",
"arrayElements",
"[",
"arrayElements",
".",
"length",
"-",
"1",
"]",
";",
"}"
] |
Get the user id from the room jid.
@memberof QB.chat.helpers
@param {String} jid - resourse jid.
@returns {String} userId - The user id.
|
[
"Get",
"the",
"user",
"id",
"from",
"the",
"room",
"jid",
"."
] |
23edee3c5904cff3d723907a928ddf20dab8ffa5
|
https://github.com/QuickBlox/quickblox-javascript-sdk/blob/23edee3c5904cff3d723907a928ddf20dab8ffa5/src/modules/chat/qbChat.js#L2423-L2429
|
train
|
|
QuickBlox/quickblox-javascript-sdk
|
samples/cordova/video_chat/platforms/ios/cordova/lib/run.js
|
filterSupportedArgs
|
function filterSupportedArgs(args) {
var filtered = [];
var sargs = ['--device', '--emulator', '--nobuild', '--list', '--target', '--debug', '--release'];
var re = new RegExp(sargs.join('|'));
args.forEach(function(element) {
// supported args not found, we add
// we do a regex search because --target can be "--target=XXX"
if (element.search(re) == -1) {
filtered.push(element);
}
}, this);
return filtered;
}
|
javascript
|
function filterSupportedArgs(args) {
var filtered = [];
var sargs = ['--device', '--emulator', '--nobuild', '--list', '--target', '--debug', '--release'];
var re = new RegExp(sargs.join('|'));
args.forEach(function(element) {
// supported args not found, we add
// we do a regex search because --target can be "--target=XXX"
if (element.search(re) == -1) {
filtered.push(element);
}
}, this);
return filtered;
}
|
[
"function",
"filterSupportedArgs",
"(",
"args",
")",
"{",
"var",
"filtered",
"=",
"[",
"]",
";",
"var",
"sargs",
"=",
"[",
"'--device'",
",",
"'--emulator'",
",",
"'--nobuild'",
",",
"'--list'",
",",
"'--target'",
",",
"'--debug'",
",",
"'--release'",
"]",
";",
"var",
"re",
"=",
"new",
"RegExp",
"(",
"sargs",
".",
"join",
"(",
"'|'",
")",
")",
";",
"args",
".",
"forEach",
"(",
"function",
"(",
"element",
")",
"{",
"if",
"(",
"element",
".",
"search",
"(",
"re",
")",
"==",
"-",
"1",
")",
"{",
"filtered",
".",
"push",
"(",
"element",
")",
";",
"}",
"}",
",",
"this",
")",
";",
"return",
"filtered",
";",
"}"
] |
Filters the args array and removes supported args for the 'run' command.
@return {Array} array with unsupported args for the 'run' command
|
[
"Filters",
"the",
"args",
"array",
"and",
"removes",
"supported",
"args",
"for",
"the",
"run",
"command",
"."
] |
23edee3c5904cff3d723907a928ddf20dab8ffa5
|
https://github.com/QuickBlox/quickblox-javascript-sdk/blob/23edee3c5904cff3d723907a928ddf20dab8ffa5/samples/cordova/video_chat/platforms/ios/cordova/lib/run.js#L98-L112
|
train
|
QuickBlox/quickblox-javascript-sdk
|
samples/video_conferencing/js/messages.js
|
clickSendMessage
|
function clickSendMessage() {
var currentText = $('#message_text').val().trim();
if (!currentText.length) {
return;
}
$('#message_text').val('').focus();
sendMessage(currentText, null);
}
|
javascript
|
function clickSendMessage() {
var currentText = $('#message_text').val().trim();
if (!currentText.length) {
return;
}
$('#message_text').val('').focus();
sendMessage(currentText, null);
}
|
[
"function",
"clickSendMessage",
"(",
")",
"{",
"var",
"currentText",
"=",
"$",
"(",
"'#message_text'",
")",
".",
"val",
"(",
")",
".",
"trim",
"(",
")",
";",
"if",
"(",
"!",
"currentText",
".",
"length",
")",
"{",
"return",
";",
"}",
"$",
"(",
"'#message_text'",
")",
".",
"val",
"(",
"''",
")",
".",
"focus",
"(",
")",
";",
"sendMessage",
"(",
"currentText",
",",
"null",
")",
";",
"}"
] |
sending messages after confirmation
|
[
"sending",
"messages",
"after",
"confirmation"
] |
23edee3c5904cff3d723907a928ddf20dab8ffa5
|
https://github.com/QuickBlox/quickblox-javascript-sdk/blob/23edee3c5904cff3d723907a928ddf20dab8ffa5/samples/video_conferencing/js/messages.js#L179-L189
|
train
|
QuickBlox/quickblox-javascript-sdk
|
samples/video_conferencing/js/messages.js
|
showMessage
|
function showMessage(userId, msg, attachmentFileId) {
var userLogin = getUserLoginById(userId);
var messageHtml = buildMessageHTML(msg.body, userLogin, new Date(), attachmentFileId, msg.id);
$('#messages-list').append(messageHtml);
// scroll to bottom
var mydiv = $('#messages-list');
mydiv.scrollTop(mydiv.prop('scrollHeight'));
}
|
javascript
|
function showMessage(userId, msg, attachmentFileId) {
var userLogin = getUserLoginById(userId);
var messageHtml = buildMessageHTML(msg.body, userLogin, new Date(), attachmentFileId, msg.id);
$('#messages-list').append(messageHtml);
// scroll to bottom
var mydiv = $('#messages-list');
mydiv.scrollTop(mydiv.prop('scrollHeight'));
}
|
[
"function",
"showMessage",
"(",
"userId",
",",
"msg",
",",
"attachmentFileId",
")",
"{",
"var",
"userLogin",
"=",
"getUserLoginById",
"(",
"userId",
")",
";",
"var",
"messageHtml",
"=",
"buildMessageHTML",
"(",
"msg",
".",
"body",
",",
"userLogin",
",",
"new",
"Date",
"(",
")",
",",
"attachmentFileId",
",",
"msg",
".",
"id",
")",
";",
"$",
"(",
"'#messages-list'",
")",
".",
"append",
"(",
"messageHtml",
")",
";",
"var",
"mydiv",
"=",
"$",
"(",
"'#messages-list'",
")",
";",
"mydiv",
".",
"scrollTop",
"(",
"mydiv",
".",
"prop",
"(",
"'scrollHeight'",
")",
")",
";",
"}"
] |
show messages in UI
|
[
"show",
"messages",
"in",
"UI"
] |
23edee3c5904cff3d723907a928ddf20dab8ffa5
|
https://github.com/QuickBlox/quickblox-javascript-sdk/blob/23edee3c5904cff3d723907a928ddf20dab8ffa5/samples/video_conferencing/js/messages.js#L255-L264
|
train
|
QuickBlox/quickblox-javascript-sdk
|
samples/video_conferencing/js/messages.js
|
sendTypingStatus
|
function sendTypingStatus() {
if (currentDialog.type == 3) {
QB.chat.sendIsTypingStatus(opponentId);
} else if (currentDialog && currentDialog.xmpp_room_jid) {
QB.chat.sendIsTypingStatus(currentDialog.xmpp_room_jid);
}
}
|
javascript
|
function sendTypingStatus() {
if (currentDialog.type == 3) {
QB.chat.sendIsTypingStatus(opponentId);
} else if (currentDialog && currentDialog.xmpp_room_jid) {
QB.chat.sendIsTypingStatus(currentDialog.xmpp_room_jid);
}
}
|
[
"function",
"sendTypingStatus",
"(",
")",
"{",
"if",
"(",
"currentDialog",
".",
"type",
"==",
"3",
")",
"{",
"QB",
".",
"chat",
".",
"sendIsTypingStatus",
"(",
"opponentId",
")",
";",
"}",
"else",
"if",
"(",
"currentDialog",
"&&",
"currentDialog",
".",
"xmpp_room_jid",
")",
"{",
"QB",
".",
"chat",
".",
"sendIsTypingStatus",
"(",
"currentDialog",
".",
"xmpp_room_jid",
")",
";",
"}",
"}"
] |
send 'is typing' status
|
[
"send",
"is",
"typing",
"status"
] |
23edee3c5904cff3d723907a928ddf20dab8ffa5
|
https://github.com/QuickBlox/quickblox-javascript-sdk/blob/23edee3c5904cff3d723907a928ddf20dab8ffa5/samples/video_conferencing/js/messages.js#L311-L317
|
train
|
QuickBlox/quickblox-javascript-sdk
|
samples/video_conferencing/js/messages.js
|
sendStopTypinStatus
|
function sendStopTypinStatus() {
if (currentDialog.type == 3) {
QB.chat.sendIsStopTypingStatus(opponentId);
} else {
QB.chat.sendIsStopTypingStatus(currentDialog.xmpp_room_jid);
}
}
|
javascript
|
function sendStopTypinStatus() {
if (currentDialog.type == 3) {
QB.chat.sendIsStopTypingStatus(opponentId);
} else {
QB.chat.sendIsStopTypingStatus(currentDialog.xmpp_room_jid);
}
}
|
[
"function",
"sendStopTypinStatus",
"(",
")",
"{",
"if",
"(",
"currentDialog",
".",
"type",
"==",
"3",
")",
"{",
"QB",
".",
"chat",
".",
"sendIsStopTypingStatus",
"(",
"opponentId",
")",
";",
"}",
"else",
"{",
"QB",
".",
"chat",
".",
"sendIsStopTypingStatus",
"(",
"currentDialog",
".",
"xmpp_room_jid",
")",
";",
"}",
"}"
] |
send 'stop typing' status
|
[
"send",
"stop",
"typing",
"status"
] |
23edee3c5904cff3d723907a928ddf20dab8ffa5
|
https://github.com/QuickBlox/quickblox-javascript-sdk/blob/23edee3c5904cff3d723907a928ddf20dab8ffa5/samples/video_conferencing/js/messages.js#L320-L326
|
train
|
QuickBlox/quickblox-javascript-sdk
|
samples/video_conferencing/js/messages.js
|
showUserIsTypingView
|
function showUserIsTypingView(isTyping, userId, dialogId) {
if (isMessageForCurrentDialog(userId, dialogId)) {
if (!isTyping) {
$('#' + userId + '_typing').remove();
} else if (userId != currentUser.id) {
var userLogin = getUserLoginById(userId);
var typingUserHtml = buildTypingUserHtml(userId, userLogin);
$('#messages-list').append(typingUserHtml);
}
// scroll to bottom
var mydiv = $('#messages-list');
mydiv.scrollTop(mydiv.prop('scrollHeight'));
}
}
|
javascript
|
function showUserIsTypingView(isTyping, userId, dialogId) {
if (isMessageForCurrentDialog(userId, dialogId)) {
if (!isTyping) {
$('#' + userId + '_typing').remove();
} else if (userId != currentUser.id) {
var userLogin = getUserLoginById(userId);
var typingUserHtml = buildTypingUserHtml(userId, userLogin);
$('#messages-list').append(typingUserHtml);
}
// scroll to bottom
var mydiv = $('#messages-list');
mydiv.scrollTop(mydiv.prop('scrollHeight'));
}
}
|
[
"function",
"showUserIsTypingView",
"(",
"isTyping",
",",
"userId",
",",
"dialogId",
")",
"{",
"if",
"(",
"isMessageForCurrentDialog",
"(",
"userId",
",",
"dialogId",
")",
")",
"{",
"if",
"(",
"!",
"isTyping",
")",
"{",
"$",
"(",
"'#'",
"+",
"userId",
"+",
"'_typing'",
")",
".",
"remove",
"(",
")",
";",
"}",
"else",
"if",
"(",
"userId",
"!=",
"currentUser",
".",
"id",
")",
"{",
"var",
"userLogin",
"=",
"getUserLoginById",
"(",
"userId",
")",
";",
"var",
"typingUserHtml",
"=",
"buildTypingUserHtml",
"(",
"userId",
",",
"userLogin",
")",
";",
"$",
"(",
"'#messages-list'",
")",
".",
"append",
"(",
"typingUserHtml",
")",
";",
"}",
"var",
"mydiv",
"=",
"$",
"(",
"'#messages-list'",
")",
";",
"mydiv",
".",
"scrollTop",
"(",
"mydiv",
".",
"prop",
"(",
"'scrollHeight'",
")",
")",
";",
"}",
"}"
] |
show or hide typing status to other users
|
[
"show",
"or",
"hide",
"typing",
"status",
"to",
"other",
"users"
] |
23edee3c5904cff3d723907a928ddf20dab8ffa5
|
https://github.com/QuickBlox/quickblox-javascript-sdk/blob/23edee3c5904cff3d723907a928ddf20dab8ffa5/samples/video_conferencing/js/messages.js#L329-L344
|
train
|
QuickBlox/quickblox-javascript-sdk
|
samples/video_conferencing/js/messages.js
|
isMessageForCurrentDialog
|
function isMessageForCurrentDialog(userId, dialogId) {
var result = false;
if (dialogId == currentDialog._id || (dialogId === null && currentDialog.type == 3 && opponentId == userId)) {
result = true;
}
return result;
}
|
javascript
|
function isMessageForCurrentDialog(userId, dialogId) {
var result = false;
if (dialogId == currentDialog._id || (dialogId === null && currentDialog.type == 3 && opponentId == userId)) {
result = true;
}
return result;
}
|
[
"function",
"isMessageForCurrentDialog",
"(",
"userId",
",",
"dialogId",
")",
"{",
"var",
"result",
"=",
"false",
";",
"if",
"(",
"dialogId",
"==",
"currentDialog",
".",
"_id",
"||",
"(",
"dialogId",
"===",
"null",
"&&",
"currentDialog",
".",
"type",
"==",
"3",
"&&",
"opponentId",
"==",
"userId",
")",
")",
"{",
"result",
"=",
"true",
";",
"}",
"return",
"result",
";",
"}"
] |
filter for current dialog
|
[
"filter",
"for",
"current",
"dialog"
] |
23edee3c5904cff3d723907a928ddf20dab8ffa5
|
https://github.com/QuickBlox/quickblox-javascript-sdk/blob/23edee3c5904cff3d723907a928ddf20dab8ffa5/samples/video_conferencing/js/messages.js#L347-L353
|
train
|
QuickBlox/quickblox-javascript-sdk
|
samples/cordova/video_chat/platforms/ios/cordova/lib/check_reqs.js
|
checkTool
|
function checkTool (tool, minVersion, message, toolFriendlyName) {
toolFriendlyName = toolFriendlyName || tool;
// Check whether tool command is available at all
var tool_command = shell.which(tool);
if (!tool_command) {
return Q.reject(toolFriendlyName + ' was not found. ' + (message || ''));
}
// check if tool version is greater than specified one
return versions.get_tool_version(tool).then(function (version) {
version = version.trim();
return versions.compareVersions(version, minVersion) >= 0 ?
Q.resolve(version) :
Q.reject('Cordova needs ' + toolFriendlyName + ' version ' + minVersion +
' or greater, you have version ' + version + '. ' + (message || ''));
});
}
|
javascript
|
function checkTool (tool, minVersion, message, toolFriendlyName) {
toolFriendlyName = toolFriendlyName || tool;
// Check whether tool command is available at all
var tool_command = shell.which(tool);
if (!tool_command) {
return Q.reject(toolFriendlyName + ' was not found. ' + (message || ''));
}
// check if tool version is greater than specified one
return versions.get_tool_version(tool).then(function (version) {
version = version.trim();
return versions.compareVersions(version, minVersion) >= 0 ?
Q.resolve(version) :
Q.reject('Cordova needs ' + toolFriendlyName + ' version ' + minVersion +
' or greater, you have version ' + version + '. ' + (message || ''));
});
}
|
[
"function",
"checkTool",
"(",
"tool",
",",
"minVersion",
",",
"message",
",",
"toolFriendlyName",
")",
"{",
"toolFriendlyName",
"=",
"toolFriendlyName",
"||",
"tool",
";",
"var",
"tool_command",
"=",
"shell",
".",
"which",
"(",
"tool",
")",
";",
"if",
"(",
"!",
"tool_command",
")",
"{",
"return",
"Q",
".",
"reject",
"(",
"toolFriendlyName",
"+",
"' was not found. '",
"+",
"(",
"message",
"||",
"''",
")",
")",
";",
"}",
"return",
"versions",
".",
"get_tool_version",
"(",
"tool",
")",
".",
"then",
"(",
"function",
"(",
"version",
")",
"{",
"version",
"=",
"version",
".",
"trim",
"(",
")",
";",
"return",
"versions",
".",
"compareVersions",
"(",
"version",
",",
"minVersion",
")",
">=",
"0",
"?",
"Q",
".",
"resolve",
"(",
"version",
")",
":",
"Q",
".",
"reject",
"(",
"'Cordova needs '",
"+",
"toolFriendlyName",
"+",
"' version '",
"+",
"minVersion",
"+",
"' or greater, you have version '",
"+",
"version",
"+",
"'. '",
"+",
"(",
"message",
"||",
"''",
")",
")",
";",
"}",
")",
";",
"}"
] |
Checks if specific tool is available.
@param {String} tool Tool name to check. Known tools are 'xcodebuild' and 'ios-deploy'
@param {Number} minVersion Min allowed tool version.
@param {String} message Message that will be used to reject promise.
@param {String} toolFriendlyName Friendly name of the tool, to report to the user. Optional.
@return {Promise} Returns a promise either resolved with tool version or rejected
|
[
"Checks",
"if",
"specific",
"tool",
"is",
"available",
"."
] |
23edee3c5904cff3d723907a928ddf20dab8ffa5
|
https://github.com/QuickBlox/quickblox-javascript-sdk/blob/23edee3c5904cff3d723907a928ddf20dab8ffa5/samples/cordova/video_chat/platforms/ios/cordova/lib/check_reqs.js#L128-L144
|
train
|
QuickBlox/quickblox-javascript-sdk
|
samples/video_conferencing/js/video/soundmeter.js
|
SoundMeter
|
function SoundMeter(context) {
this.context = context;
this.instant = 0.0;
this.slow = 0.0;
this.clip = 0.0;
this.script = context.createScriptProcessor(2048, 1, 1);
var that = this;
this.script.onaudioprocess = function(event) {
var input = event.inputBuffer.getChannelData(0);
var i;
var sum = 0.0;
var clipcount = 0;
for (i = 0; i < input.length; ++i) {
sum += input[i] * input[i];
if (Math.abs(input[i]) > 0.99) {
clipcount += 1;
}
}
that.instant = Math.sqrt(sum / input.length);
that.slow = 0.95 * that.slow + 0.05 * that.instant;
that.clip = clipcount / input.length;
};
}
|
javascript
|
function SoundMeter(context) {
this.context = context;
this.instant = 0.0;
this.slow = 0.0;
this.clip = 0.0;
this.script = context.createScriptProcessor(2048, 1, 1);
var that = this;
this.script.onaudioprocess = function(event) {
var input = event.inputBuffer.getChannelData(0);
var i;
var sum = 0.0;
var clipcount = 0;
for (i = 0; i < input.length; ++i) {
sum += input[i] * input[i];
if (Math.abs(input[i]) > 0.99) {
clipcount += 1;
}
}
that.instant = Math.sqrt(sum / input.length);
that.slow = 0.95 * that.slow + 0.05 * that.instant;
that.clip = clipcount / input.length;
};
}
|
[
"function",
"SoundMeter",
"(",
"context",
")",
"{",
"this",
".",
"context",
"=",
"context",
";",
"this",
".",
"instant",
"=",
"0.0",
";",
"this",
".",
"slow",
"=",
"0.0",
";",
"this",
".",
"clip",
"=",
"0.0",
";",
"this",
".",
"script",
"=",
"context",
".",
"createScriptProcessor",
"(",
"2048",
",",
"1",
",",
"1",
")",
";",
"var",
"that",
"=",
"this",
";",
"this",
".",
"script",
".",
"onaudioprocess",
"=",
"function",
"(",
"event",
")",
"{",
"var",
"input",
"=",
"event",
".",
"inputBuffer",
".",
"getChannelData",
"(",
"0",
")",
";",
"var",
"i",
";",
"var",
"sum",
"=",
"0.0",
";",
"var",
"clipcount",
"=",
"0",
";",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"input",
".",
"length",
";",
"++",
"i",
")",
"{",
"sum",
"+=",
"input",
"[",
"i",
"]",
"*",
"input",
"[",
"i",
"]",
";",
"if",
"(",
"Math",
".",
"abs",
"(",
"input",
"[",
"i",
"]",
")",
">",
"0.99",
")",
"{",
"clipcount",
"+=",
"1",
";",
"}",
"}",
"that",
".",
"instant",
"=",
"Math",
".",
"sqrt",
"(",
"sum",
"/",
"input",
".",
"length",
")",
";",
"that",
".",
"slow",
"=",
"0.95",
"*",
"that",
".",
"slow",
"+",
"0.05",
"*",
"that",
".",
"instant",
";",
"that",
".",
"clip",
"=",
"clipcount",
"/",
"input",
".",
"length",
";",
"}",
";",
"}"
] |
Meter class that generates a number correlated to audio volume. The meter class itself displays nothing, but it makes the instantaneous and time-decaying volumes available for inspection. It also reports on the fraction of samples that were at or near the top of the measurement range.
|
[
"Meter",
"class",
"that",
"generates",
"a",
"number",
"correlated",
"to",
"audio",
"volume",
".",
"The",
"meter",
"class",
"itself",
"displays",
"nothing",
"but",
"it",
"makes",
"the",
"instantaneous",
"and",
"time",
"-",
"decaying",
"volumes",
"available",
"for",
"inspection",
".",
"It",
"also",
"reports",
"on",
"the",
"fraction",
"of",
"samples",
"that",
"were",
"at",
"or",
"near",
"the",
"top",
"of",
"the",
"measurement",
"range",
"."
] |
23edee3c5904cff3d723907a928ddf20dab8ffa5
|
https://github.com/QuickBlox/quickblox-javascript-sdk/blob/23edee3c5904cff3d723907a928ddf20dab8ffa5/samples/video_conferencing/js/video/soundmeter.js#L16-L38
|
train
|
QuickBlox/quickblox-javascript-sdk
|
samples/cordova/video_chat/plugins/cordova-plugin-device/www/device.js
|
Device
|
function Device() {
this.available = false;
this.platform = null;
this.version = null;
this.uuid = null;
this.cordova = null;
this.model = null;
this.manufacturer = null;
this.isVirtual = null;
this.serial = null;
var me = this;
channel.onCordovaReady.subscribe(function() {
me.getInfo(function(info) {
//ignoring info.cordova returning from native, we should use value from cordova.version defined in cordova.js
//TODO: CB-5105 native implementations should not return info.cordova
var buildLabel = cordova.version;
me.available = true;
me.platform = info.platform;
me.version = info.version;
me.uuid = info.uuid;
me.cordova = buildLabel;
me.model = info.model;
me.isVirtual = info.isVirtual;
me.manufacturer = info.manufacturer || 'unknown';
me.serial = info.serial || 'unknown';
channel.onCordovaInfoReady.fire();
},function(e) {
me.available = false;
utils.alert("[ERROR] Error initializing Cordova: " + e);
});
});
}
|
javascript
|
function Device() {
this.available = false;
this.platform = null;
this.version = null;
this.uuid = null;
this.cordova = null;
this.model = null;
this.manufacturer = null;
this.isVirtual = null;
this.serial = null;
var me = this;
channel.onCordovaReady.subscribe(function() {
me.getInfo(function(info) {
//ignoring info.cordova returning from native, we should use value from cordova.version defined in cordova.js
//TODO: CB-5105 native implementations should not return info.cordova
var buildLabel = cordova.version;
me.available = true;
me.platform = info.platform;
me.version = info.version;
me.uuid = info.uuid;
me.cordova = buildLabel;
me.model = info.model;
me.isVirtual = info.isVirtual;
me.manufacturer = info.manufacturer || 'unknown';
me.serial = info.serial || 'unknown';
channel.onCordovaInfoReady.fire();
},function(e) {
me.available = false;
utils.alert("[ERROR] Error initializing Cordova: " + e);
});
});
}
|
[
"function",
"Device",
"(",
")",
"{",
"this",
".",
"available",
"=",
"false",
";",
"this",
".",
"platform",
"=",
"null",
";",
"this",
".",
"version",
"=",
"null",
";",
"this",
".",
"uuid",
"=",
"null",
";",
"this",
".",
"cordova",
"=",
"null",
";",
"this",
".",
"model",
"=",
"null",
";",
"this",
".",
"manufacturer",
"=",
"null",
";",
"this",
".",
"isVirtual",
"=",
"null",
";",
"this",
".",
"serial",
"=",
"null",
";",
"var",
"me",
"=",
"this",
";",
"channel",
".",
"onCordovaReady",
".",
"subscribe",
"(",
"function",
"(",
")",
"{",
"me",
".",
"getInfo",
"(",
"function",
"(",
"info",
")",
"{",
"var",
"buildLabel",
"=",
"cordova",
".",
"version",
";",
"me",
".",
"available",
"=",
"true",
";",
"me",
".",
"platform",
"=",
"info",
".",
"platform",
";",
"me",
".",
"version",
"=",
"info",
".",
"version",
";",
"me",
".",
"uuid",
"=",
"info",
".",
"uuid",
";",
"me",
".",
"cordova",
"=",
"buildLabel",
";",
"me",
".",
"model",
"=",
"info",
".",
"model",
";",
"me",
".",
"isVirtual",
"=",
"info",
".",
"isVirtual",
";",
"me",
".",
"manufacturer",
"=",
"info",
".",
"manufacturer",
"||",
"'unknown'",
";",
"me",
".",
"serial",
"=",
"info",
".",
"serial",
"||",
"'unknown'",
";",
"channel",
".",
"onCordovaInfoReady",
".",
"fire",
"(",
")",
";",
"}",
",",
"function",
"(",
"e",
")",
"{",
"me",
".",
"available",
"=",
"false",
";",
"utils",
".",
"alert",
"(",
"\"[ERROR] Error initializing Cordova: \"",
"+",
"e",
")",
";",
"}",
")",
";",
"}",
")",
";",
"}"
] |
This represents the mobile device, and provides properties for inspecting the model, version, UUID of the
phone, etc.
@constructor
|
[
"This",
"represents",
"the",
"mobile",
"device",
"and",
"provides",
"properties",
"for",
"inspecting",
"the",
"model",
"version",
"UUID",
"of",
"the",
"phone",
"etc",
"."
] |
23edee3c5904cff3d723907a928ddf20dab8ffa5
|
https://github.com/QuickBlox/quickblox-javascript-sdk/blob/23edee3c5904cff3d723907a928ddf20dab8ffa5/samples/cordova/video_chat/plugins/cordova-plugin-device/www/device.js#L37-L70
|
train
|
QuickBlox/quickblox-javascript-sdk
|
src/modules/qbAddressBook.js
|
function(isCompactOrCallback, callback) {
var self = this;
var isCompact, cb;
if(isFunction(isCompactOrCallback)) {
cb = isCompactOrCallback;
} else {
isCompact = isCompactOrCallback;
cb = callback;
}
if(!isFunction(cb)) {
throw new Error('The QB.addressbook.get accept callback function is required.');
}
var ajaxParams = {
'type': 'GET',
'url': Utils.getUrl(config.urls.addressbookRegistered),
'contentType': 'application/json; charset=utf-8'
};
if(isCompact) {
ajaxParams.data = {'compact': 1};
}
this.service.ajax(ajaxParams, function(err, res) {
if (err) {
// Don't ask me why.
// Thanks to backend developers for this
var isFakeErrorEmptyAddressBook = self._isFakeErrorEmptyAddressBook(err);
if(isFakeErrorEmptyAddressBook) {
cb(null, []);
} else {
cb(err, null);
}
} else {
cb(null, res);
}
});
}
|
javascript
|
function(isCompactOrCallback, callback) {
var self = this;
var isCompact, cb;
if(isFunction(isCompactOrCallback)) {
cb = isCompactOrCallback;
} else {
isCompact = isCompactOrCallback;
cb = callback;
}
if(!isFunction(cb)) {
throw new Error('The QB.addressbook.get accept callback function is required.');
}
var ajaxParams = {
'type': 'GET',
'url': Utils.getUrl(config.urls.addressbookRegistered),
'contentType': 'application/json; charset=utf-8'
};
if(isCompact) {
ajaxParams.data = {'compact': 1};
}
this.service.ajax(ajaxParams, function(err, res) {
if (err) {
// Don't ask me why.
// Thanks to backend developers for this
var isFakeErrorEmptyAddressBook = self._isFakeErrorEmptyAddressBook(err);
if(isFakeErrorEmptyAddressBook) {
cb(null, []);
} else {
cb(err, null);
}
} else {
cb(null, res);
}
});
}
|
[
"function",
"(",
"isCompactOrCallback",
",",
"callback",
")",
"{",
"var",
"self",
"=",
"this",
";",
"var",
"isCompact",
",",
"cb",
";",
"if",
"(",
"isFunction",
"(",
"isCompactOrCallback",
")",
")",
"{",
"cb",
"=",
"isCompactOrCallback",
";",
"}",
"else",
"{",
"isCompact",
"=",
"isCompactOrCallback",
";",
"cb",
"=",
"callback",
";",
"}",
"if",
"(",
"!",
"isFunction",
"(",
"cb",
")",
")",
"{",
"throw",
"new",
"Error",
"(",
"'The QB.addressbook.get accept callback function is required.'",
")",
";",
"}",
"var",
"ajaxParams",
"=",
"{",
"'type'",
":",
"'GET'",
",",
"'url'",
":",
"Utils",
".",
"getUrl",
"(",
"config",
".",
"urls",
".",
"addressbookRegistered",
")",
",",
"'contentType'",
":",
"'application/json; charset=utf-8'",
"}",
";",
"if",
"(",
"isCompact",
")",
"{",
"ajaxParams",
".",
"data",
"=",
"{",
"'compact'",
":",
"1",
"}",
";",
"}",
"this",
".",
"service",
".",
"ajax",
"(",
"ajaxParams",
",",
"function",
"(",
"err",
",",
"res",
")",
"{",
"if",
"(",
"err",
")",
"{",
"var",
"isFakeErrorEmptyAddressBook",
"=",
"self",
".",
"_isFakeErrorEmptyAddressBook",
"(",
"err",
")",
";",
"if",
"(",
"isFakeErrorEmptyAddressBook",
")",
"{",
"cb",
"(",
"null",
",",
"[",
"]",
")",
";",
"}",
"else",
"{",
"cb",
"(",
"err",
",",
"null",
")",
";",
"}",
"}",
"else",
"{",
"cb",
"(",
"null",
",",
"res",
")",
";",
"}",
"}",
")",
";",
"}"
] |
Retrieve QuickBlox users that have phone numbers from your address book.
The methods accepts 1 or 2 parameters.
@memberof QB.addressbook
@param {boolean|function} udidOrCallback - You can pass isCompact parameter or callback object. If isCompact is passed then only user's id and phone fields will be returned from server. Otherwise - all standard user's fields will be returned.
@param {function} [callback] - Callback function is useв as 2nd parameter if you pass `isCompact` as 1st parameter.
This callback takes 2 arguments: an error and a response.
|
[
"Retrieve",
"QuickBlox",
"users",
"that",
"have",
"phone",
"numbers",
"from",
"your",
"address",
"book",
".",
"The",
"methods",
"accepts",
"1",
"or",
"2",
"parameters",
"."
] |
23edee3c5904cff3d723907a928ddf20dab8ffa5
|
https://github.com/QuickBlox/quickblox-javascript-sdk/blob/23edee3c5904cff3d723907a928ddf20dab8ffa5/src/modules/qbAddressBook.js#L176-L216
|
train
|
|
QuickBlox/quickblox-javascript-sdk
|
src/modules/webrtc/qbWebRTCSession.js
|
WebRTCSession
|
function WebRTCSession(params) {
this.ID = params.sessionID ? params.sessionID : generateUUID();
this.state = WebRTCSession.State.NEW;
this.initiatorID = parseInt(params.initiatorID);
this.opponentsIDs = params.opIDs;
this.callType = parseInt(params.callType);
this.peerConnections = {};
this.localStream = null;
this.mediaParams = null;
this.signalingProvider = params.signalingProvider;
this.currentUserID = params.currentUserID;
this.bandwidth = params.bandwidth;
/**
* We use this timeout to fix next issue:
* "From Android/iOS make a call to Web and kill the Android/iOS app instantly. Web accept/reject popup will be still visible.
* We need a way to hide it if sach situation happened."
*/
this.answerTimer = null;
this.startCallTime = 0;
this.acceptCallTime = 0;
}
|
javascript
|
function WebRTCSession(params) {
this.ID = params.sessionID ? params.sessionID : generateUUID();
this.state = WebRTCSession.State.NEW;
this.initiatorID = parseInt(params.initiatorID);
this.opponentsIDs = params.opIDs;
this.callType = parseInt(params.callType);
this.peerConnections = {};
this.localStream = null;
this.mediaParams = null;
this.signalingProvider = params.signalingProvider;
this.currentUserID = params.currentUserID;
this.bandwidth = params.bandwidth;
/**
* We use this timeout to fix next issue:
* "From Android/iOS make a call to Web and kill the Android/iOS app instantly. Web accept/reject popup will be still visible.
* We need a way to hide it if sach situation happened."
*/
this.answerTimer = null;
this.startCallTime = 0;
this.acceptCallTime = 0;
}
|
[
"function",
"WebRTCSession",
"(",
"params",
")",
"{",
"this",
".",
"ID",
"=",
"params",
".",
"sessionID",
"?",
"params",
".",
"sessionID",
":",
"generateUUID",
"(",
")",
";",
"this",
".",
"state",
"=",
"WebRTCSession",
".",
"State",
".",
"NEW",
";",
"this",
".",
"initiatorID",
"=",
"parseInt",
"(",
"params",
".",
"initiatorID",
")",
";",
"this",
".",
"opponentsIDs",
"=",
"params",
".",
"opIDs",
";",
"this",
".",
"callType",
"=",
"parseInt",
"(",
"params",
".",
"callType",
")",
";",
"this",
".",
"peerConnections",
"=",
"{",
"}",
";",
"this",
".",
"localStream",
"=",
"null",
";",
"this",
".",
"mediaParams",
"=",
"null",
";",
"this",
".",
"signalingProvider",
"=",
"params",
".",
"signalingProvider",
";",
"this",
".",
"currentUserID",
"=",
"params",
".",
"currentUserID",
";",
"this",
".",
"bandwidth",
"=",
"params",
".",
"bandwidth",
";",
"this",
".",
"answerTimer",
"=",
"null",
";",
"this",
".",
"startCallTime",
"=",
"0",
";",
"this",
".",
"acceptCallTime",
"=",
"0",
";",
"}"
] |
Creates a session
@param {number} An ID if the call's initiator
@param {array} An array with opponents
@param {enum} Type of a call
|
[
"Creates",
"a",
"session"
] |
23edee3c5904cff3d723907a928ddf20dab8ffa5
|
https://github.com/QuickBlox/quickblox-javascript-sdk/blob/23edee3c5904cff3d723907a928ddf20dab8ffa5/src/modules/webrtc/qbWebRTCSession.js#L41-L70
|
train
|
QuickBlox/quickblox-javascript-sdk
|
src/modules/webrtc/qbWebRTCSession.js
|
_prepareExtension
|
function _prepareExtension(extension) {
var ext = {};
try {
if ( ({}).toString.call(extension) === '[object Object]' ) {
ext.userInfo = extension;
ext = JSON.parse( JSON.stringify(ext).replace(/null/g, "\"\"") );
} else {
throw new Error('Invalid type of "extension" object.');
}
} catch (err) {
Helpers.traceWarning(err.message);
}
return ext;
}
|
javascript
|
function _prepareExtension(extension) {
var ext = {};
try {
if ( ({}).toString.call(extension) === '[object Object]' ) {
ext.userInfo = extension;
ext = JSON.parse( JSON.stringify(ext).replace(/null/g, "\"\"") );
} else {
throw new Error('Invalid type of "extension" object.');
}
} catch (err) {
Helpers.traceWarning(err.message);
}
return ext;
}
|
[
"function",
"_prepareExtension",
"(",
"extension",
")",
"{",
"var",
"ext",
"=",
"{",
"}",
";",
"try",
"{",
"if",
"(",
"(",
"{",
"}",
")",
".",
"toString",
".",
"call",
"(",
"extension",
")",
"===",
"'[object Object]'",
")",
"{",
"ext",
".",
"userInfo",
"=",
"extension",
";",
"ext",
"=",
"JSON",
".",
"parse",
"(",
"JSON",
".",
"stringify",
"(",
"ext",
")",
".",
"replace",
"(",
"/",
"null",
"/",
"g",
",",
"\"\\\"\\\"\"",
")",
")",
";",
"}",
"else",
"\\\"",
"}",
"\\\"",
"{",
"throw",
"new",
"Error",
"(",
"'Invalid type of \"extension\" object.'",
")",
";",
"}",
"}"
] |
private _prepareExtension - replace property null to empty string
return object with property or empty if extension didn't set
|
[
"private",
"_prepareExtension",
"-",
"replace",
"property",
"null",
"to",
"empty",
"string",
"return",
"object",
"with",
"property",
"or",
"empty",
"if",
"extension",
"didn",
"t",
"set"
] |
23edee3c5904cff3d723907a928ddf20dab8ffa5
|
https://github.com/QuickBlox/quickblox-javascript-sdk/blob/23edee3c5904cff3d723907a928ddf20dab8ffa5/src/modules/webrtc/qbWebRTCSession.js#L998-L1013
|
train
|
QuickBlox/quickblox-javascript-sdk
|
samples/cordova/text_chat/www/libs/stickerpipe/js/stickerpipe.js
|
defaultImageSrcGenerator
|
function defaultImageSrcGenerator(icon, options) {
return ''.concat(options.base, options.size, '/', icon, options.ext);
}
|
javascript
|
function defaultImageSrcGenerator(icon, options) {
return ''.concat(options.base, options.size, '/', icon, options.ext);
}
|
[
"function",
"defaultImageSrcGenerator",
"(",
"icon",
",",
"options",
")",
"{",
"return",
"''",
".",
"concat",
"(",
"options",
".",
"base",
",",
"options",
".",
"size",
",",
"'/'",
",",
"icon",
",",
"options",
".",
"ext",
")",
";",
"}"
] |
Default callback used to generate emoji src
based on Twitter CDN
@param string the emoji codepoint string
@param string the default size to use, i.e. "36x36"
@param string optional "\uFE0F" variant char, ignored by default
@return string the image source to use
|
[
"Default",
"callback",
"used",
"to",
"generate",
"emoji",
"src",
"based",
"on",
"Twitter",
"CDN"
] |
23edee3c5904cff3d723907a928ddf20dab8ffa5
|
https://github.com/QuickBlox/quickblox-javascript-sdk/blob/23edee3c5904cff3d723907a928ddf20dab8ffa5/samples/cordova/text_chat/www/libs/stickerpipe/js/stickerpipe.js#L2650-L2652
|
train
|
QuickBlox/quickblox-javascript-sdk
|
samples/cordova/text_chat/www/libs/stickerpipe/js/stickerpipe.js
|
grabTheRightIcon
|
function grabTheRightIcon(icon, variant) {
// if variant is present as \uFE0F
return toCodePoint(
variant === '\uFE0F' ?
// the icon should not contain it
icon.slice(0, -1) :
// fix non standard OSX behavior
(icon.length === 3 && icon.charAt(1) === '\uFE0F' ?
icon.charAt(0) + icon.charAt(2) : icon)
);
}
|
javascript
|
function grabTheRightIcon(icon, variant) {
// if variant is present as \uFE0F
return toCodePoint(
variant === '\uFE0F' ?
// the icon should not contain it
icon.slice(0, -1) :
// fix non standard OSX behavior
(icon.length === 3 && icon.charAt(1) === '\uFE0F' ?
icon.charAt(0) + icon.charAt(2) : icon)
);
}
|
[
"function",
"grabTheRightIcon",
"(",
"icon",
",",
"variant",
")",
"{",
"return",
"toCodePoint",
"(",
"variant",
"===",
"'\\uFE0F'",
"?",
"\\uFE0F",
":",
"icon",
".",
"slice",
"(",
"0",
",",
"-",
"1",
")",
")",
";",
"}"
] |
Used to both remove the possible variant
and to convert utf16 into code points
@param string the emoji surrogate pair
@param string the optional variant char, if any
|
[
"Used",
"to",
"both",
"remove",
"the",
"possible",
"variant",
"and",
"to",
"convert",
"utf16",
"into",
"code",
"points"
] |
23edee3c5904cff3d723907a928ddf20dab8ffa5
|
https://github.com/QuickBlox/quickblox-javascript-sdk/blob/23edee3c5904cff3d723907a928ddf20dab8ffa5/samples/cordova/text_chat/www/libs/stickerpipe/js/stickerpipe.js#L2690-L2700
|
train
|
QuickBlox/quickblox-javascript-sdk
|
samples/cordova/text_chat/www/js/messages.js
|
sendMessage
|
function sendMessage(text, attachmentFileId) {
stickerpipe.onUserMessageSent(stickerpipe.isSticker(text));
var msg = {
type: currentDialog.type === 3 ? 'chat' : 'groupchat',
body: text,
extension: {
save_to_history: 1,
},
markable: 1
};
if(attachmentFileId !== null){
msg['extension']['attachments'] = [{id: attachmentFileId, type: 'photo'}];
}
if (currentDialog.type === 3) {
opponentId = QB.chat.helpers.getRecipientId(currentDialog.occupants_ids, currentUser.id);
QB.chat.send(opponentId, msg);
$('.list-group-item.active .list-group-item-text')
.text(stickerpipe.isSticker(msg.body) ? 'Sticker' : msg.body);
if(attachmentFileId === null){
showMessage(currentUser.id, msg);
} else {
showMessage(currentUser.id, msg, attachmentFileId);
}
} else {
QB.chat.send(currentDialog.xmpp_room_jid, msg);
}
// claer timer and send 'stop typing' status
clearTimeout(isTypingTimerId);
isTypingTimeoutCallback();
dialogsMessages.push(msg);
}
|
javascript
|
function sendMessage(text, attachmentFileId) {
stickerpipe.onUserMessageSent(stickerpipe.isSticker(text));
var msg = {
type: currentDialog.type === 3 ? 'chat' : 'groupchat',
body: text,
extension: {
save_to_history: 1,
},
markable: 1
};
if(attachmentFileId !== null){
msg['extension']['attachments'] = [{id: attachmentFileId, type: 'photo'}];
}
if (currentDialog.type === 3) {
opponentId = QB.chat.helpers.getRecipientId(currentDialog.occupants_ids, currentUser.id);
QB.chat.send(opponentId, msg);
$('.list-group-item.active .list-group-item-text')
.text(stickerpipe.isSticker(msg.body) ? 'Sticker' : msg.body);
if(attachmentFileId === null){
showMessage(currentUser.id, msg);
} else {
showMessage(currentUser.id, msg, attachmentFileId);
}
} else {
QB.chat.send(currentDialog.xmpp_room_jid, msg);
}
// claer timer and send 'stop typing' status
clearTimeout(isTypingTimerId);
isTypingTimeoutCallback();
dialogsMessages.push(msg);
}
|
[
"function",
"sendMessage",
"(",
"text",
",",
"attachmentFileId",
")",
"{",
"stickerpipe",
".",
"onUserMessageSent",
"(",
"stickerpipe",
".",
"isSticker",
"(",
"text",
")",
")",
";",
"var",
"msg",
"=",
"{",
"type",
":",
"currentDialog",
".",
"type",
"===",
"3",
"?",
"'chat'",
":",
"'groupchat'",
",",
"body",
":",
"text",
",",
"extension",
":",
"{",
"save_to_history",
":",
"1",
",",
"}",
",",
"markable",
":",
"1",
"}",
";",
"if",
"(",
"attachmentFileId",
"!==",
"null",
")",
"{",
"msg",
"[",
"'extension'",
"]",
"[",
"'attachments'",
"]",
"=",
"[",
"{",
"id",
":",
"attachmentFileId",
",",
"type",
":",
"'photo'",
"}",
"]",
";",
"}",
"if",
"(",
"currentDialog",
".",
"type",
"===",
"3",
")",
"{",
"opponentId",
"=",
"QB",
".",
"chat",
".",
"helpers",
".",
"getRecipientId",
"(",
"currentDialog",
".",
"occupants_ids",
",",
"currentUser",
".",
"id",
")",
";",
"QB",
".",
"chat",
".",
"send",
"(",
"opponentId",
",",
"msg",
")",
";",
"$",
"(",
"'.list-group-item.active .list-group-item-text'",
")",
".",
"text",
"(",
"stickerpipe",
".",
"isSticker",
"(",
"msg",
".",
"body",
")",
"?",
"'Sticker'",
":",
"msg",
".",
"body",
")",
";",
"if",
"(",
"attachmentFileId",
"===",
"null",
")",
"{",
"showMessage",
"(",
"currentUser",
".",
"id",
",",
"msg",
")",
";",
"}",
"else",
"{",
"showMessage",
"(",
"currentUser",
".",
"id",
",",
"msg",
",",
"attachmentFileId",
")",
";",
"}",
"}",
"else",
"{",
"QB",
".",
"chat",
".",
"send",
"(",
"currentDialog",
".",
"xmpp_room_jid",
",",
"msg",
")",
";",
"}",
"clearTimeout",
"(",
"isTypingTimerId",
")",
";",
"isTypingTimeoutCallback",
"(",
")",
";",
"dialogsMessages",
".",
"push",
"(",
"msg",
")",
";",
"}"
] |
send text or attachment
|
[
"send",
"text",
"or",
"attachment"
] |
23edee3c5904cff3d723907a928ddf20dab8ffa5
|
https://github.com/QuickBlox/quickblox-javascript-sdk/blob/23edee3c5904cff3d723907a928ddf20dab8ffa5/samples/cordova/text_chat/www/js/messages.js#L193-L231
|
train
|
QuickBlox/quickblox-javascript-sdk
|
samples/cordova/text_chat/www/js/dialogs.js
|
createNewDialog
|
function createNewDialog() {
var usersIds = [];
var usersNames = [];
$('#users_list .users_form.active').each(function(index) {
usersIds[index] = $(this).attr('id');
usersNames[index] = $(this).text();
});
$("#add_new_dialog").modal("hide");
$('#add_new_dialog .progress').show();
var dialogName;
var dialogOccupants;
var dialogType;
if (usersIds.length > 1) {
if (usersNames.indexOf(currentUser.login) > -1) {
dialogName = usersNames.join(', ');
}else{
dialogName = currentUser.login + ', ' + usersNames.join(', ');
}
dialogOccupants = usersIds;
dialogType = 2;
} else {
dialogOccupants = usersIds;
dialogType = 3;
}
var params = {
type: dialogType,
occupants_ids: dialogOccupants,
name: dialogName
};
// create a dialog
//
console.log("Creating a dialog with params: " + JSON.stringify(params));
QB.chat.dialog.create(params, function(err, createdDialog) {
if (err) {
console.log(err);
} else {
console.log("Dialog " + createdDialog._id + " created with users: " + dialogOccupants);
// save dialog to local storage
var dialogId = createdDialog._id;
dialogs[dialogId] = createdDialog;
currentDialog = createdDialog;
joinToNewDialogAndShow(createdDialog);
notifyOccupants(createdDialog.occupants_ids, createdDialog._id, 1);
triggerDialog(createdDialog._id);
$('a.users_form').removeClass('active');
}
});
}
|
javascript
|
function createNewDialog() {
var usersIds = [];
var usersNames = [];
$('#users_list .users_form.active').each(function(index) {
usersIds[index] = $(this).attr('id');
usersNames[index] = $(this).text();
});
$("#add_new_dialog").modal("hide");
$('#add_new_dialog .progress').show();
var dialogName;
var dialogOccupants;
var dialogType;
if (usersIds.length > 1) {
if (usersNames.indexOf(currentUser.login) > -1) {
dialogName = usersNames.join(', ');
}else{
dialogName = currentUser.login + ', ' + usersNames.join(', ');
}
dialogOccupants = usersIds;
dialogType = 2;
} else {
dialogOccupants = usersIds;
dialogType = 3;
}
var params = {
type: dialogType,
occupants_ids: dialogOccupants,
name: dialogName
};
// create a dialog
//
console.log("Creating a dialog with params: " + JSON.stringify(params));
QB.chat.dialog.create(params, function(err, createdDialog) {
if (err) {
console.log(err);
} else {
console.log("Dialog " + createdDialog._id + " created with users: " + dialogOccupants);
// save dialog to local storage
var dialogId = createdDialog._id;
dialogs[dialogId] = createdDialog;
currentDialog = createdDialog;
joinToNewDialogAndShow(createdDialog);
notifyOccupants(createdDialog.occupants_ids, createdDialog._id, 1);
triggerDialog(createdDialog._id);
$('a.users_form').removeClass('active');
}
});
}
|
[
"function",
"createNewDialog",
"(",
")",
"{",
"var",
"usersIds",
"=",
"[",
"]",
";",
"var",
"usersNames",
"=",
"[",
"]",
";",
"$",
"(",
"'#users_list .users_form.active'",
")",
".",
"each",
"(",
"function",
"(",
"index",
")",
"{",
"usersIds",
"[",
"index",
"]",
"=",
"$",
"(",
"this",
")",
".",
"attr",
"(",
"'id'",
")",
";",
"usersNames",
"[",
"index",
"]",
"=",
"$",
"(",
"this",
")",
".",
"text",
"(",
")",
";",
"}",
")",
";",
"$",
"(",
"\"#add_new_dialog\"",
")",
".",
"modal",
"(",
"\"hide\"",
")",
";",
"$",
"(",
"'#add_new_dialog .progress'",
")",
".",
"show",
"(",
")",
";",
"var",
"dialogName",
";",
"var",
"dialogOccupants",
";",
"var",
"dialogType",
";",
"if",
"(",
"usersIds",
".",
"length",
">",
"1",
")",
"{",
"if",
"(",
"usersNames",
".",
"indexOf",
"(",
"currentUser",
".",
"login",
")",
">",
"-",
"1",
")",
"{",
"dialogName",
"=",
"usersNames",
".",
"join",
"(",
"', '",
")",
";",
"}",
"else",
"{",
"dialogName",
"=",
"currentUser",
".",
"login",
"+",
"', '",
"+",
"usersNames",
".",
"join",
"(",
"', '",
")",
";",
"}",
"dialogOccupants",
"=",
"usersIds",
";",
"dialogType",
"=",
"2",
";",
"}",
"else",
"{",
"dialogOccupants",
"=",
"usersIds",
";",
"dialogType",
"=",
"3",
";",
"}",
"var",
"params",
"=",
"{",
"type",
":",
"dialogType",
",",
"occupants_ids",
":",
"dialogOccupants",
",",
"name",
":",
"dialogName",
"}",
";",
"console",
".",
"log",
"(",
"\"Creating a dialog with params: \"",
"+",
"JSON",
".",
"stringify",
"(",
"params",
")",
")",
";",
"QB",
".",
"chat",
".",
"dialog",
".",
"create",
"(",
"params",
",",
"function",
"(",
"err",
",",
"createdDialog",
")",
"{",
"if",
"(",
"err",
")",
"{",
"console",
".",
"log",
"(",
"err",
")",
";",
"}",
"else",
"{",
"console",
".",
"log",
"(",
"\"Dialog \"",
"+",
"createdDialog",
".",
"_id",
"+",
"\" created with users: \"",
"+",
"dialogOccupants",
")",
";",
"var",
"dialogId",
"=",
"createdDialog",
".",
"_id",
";",
"dialogs",
"[",
"dialogId",
"]",
"=",
"createdDialog",
";",
"currentDialog",
"=",
"createdDialog",
";",
"joinToNewDialogAndShow",
"(",
"createdDialog",
")",
";",
"notifyOccupants",
"(",
"createdDialog",
".",
"occupants_ids",
",",
"createdDialog",
".",
"_id",
",",
"1",
")",
";",
"triggerDialog",
"(",
"createdDialog",
".",
"_id",
")",
";",
"$",
"(",
"'a.users_form'",
")",
".",
"removeClass",
"(",
"'active'",
")",
";",
"}",
"}",
")",
";",
"}"
] |
create new dialog
|
[
"create",
"new",
"dialog"
] |
23edee3c5904cff3d723907a928ddf20dab8ffa5
|
https://github.com/QuickBlox/quickblox-javascript-sdk/blob/23edee3c5904cff3d723907a928ddf20dab8ffa5/samples/cordova/text_chat/www/js/dialogs.js#L214-L274
|
train
|
QuickBlox/quickblox-javascript-sdk
|
samples/cordova/text_chat/www/js/dialogs.js
|
showDialogInfoPopup
|
function showDialogInfoPopup() {
if(Object.keys(currentDialog).length !== 0) {
$('#update_dialog').modal('show');
$('#update_dialog .progress').hide();
setupDialogInfoPopup(currentDialog.occupants_ids, currentDialog.name);
}
}
|
javascript
|
function showDialogInfoPopup() {
if(Object.keys(currentDialog).length !== 0) {
$('#update_dialog').modal('show');
$('#update_dialog .progress').hide();
setupDialogInfoPopup(currentDialog.occupants_ids, currentDialog.name);
}
}
|
[
"function",
"showDialogInfoPopup",
"(",
")",
"{",
"if",
"(",
"Object",
".",
"keys",
"(",
"currentDialog",
")",
".",
"length",
"!==",
"0",
")",
"{",
"$",
"(",
"'#update_dialog'",
")",
".",
"modal",
"(",
"'show'",
")",
";",
"$",
"(",
"'#update_dialog .progress'",
")",
".",
"hide",
"(",
")",
";",
"setupDialogInfoPopup",
"(",
"currentDialog",
".",
"occupants_ids",
",",
"currentDialog",
".",
"name",
")",
";",
"}",
"}"
] |
show modal window with dialog's info
|
[
"show",
"modal",
"window",
"with",
"dialog",
"s",
"info"
] |
23edee3c5904cff3d723907a928ddf20dab8ffa5
|
https://github.com/QuickBlox/quickblox-javascript-sdk/blob/23edee3c5904cff3d723907a928ddf20dab8ffa5/samples/cordova/text_chat/www/js/dialogs.js#L384-L391
|
train
|
QuickBlox/quickblox-javascript-sdk
|
samples/cordova/video_chat/plugins/cordova-custom-config/hooks/applyCustomConfig.js
|
parseAndroidPreferences
|
function parseAndroidPreferences(preferences, configData){
var type = 'preference';
_.each(preferences, function (preference) {
// Extract pre-defined preferences (deprecated)
var target,
prefData;
if(preference.attrib.name.match(/^android-manifest\//)){
// Extract manifest Xpath preferences
var parts = preference.attrib.name.split("/"),
destination = parts.pop();
parts.shift();
prefData = {
parent: parts.join("/") || "./",
type: type,
destination: destination,
data: preference
};
target = "AndroidManifest.xml";
}
if(prefData){
if(!configData[target]) {
configData[target] = [];
}
configData[target].push(prefData);
}
});
}
|
javascript
|
function parseAndroidPreferences(preferences, configData){
var type = 'preference';
_.each(preferences, function (preference) {
// Extract pre-defined preferences (deprecated)
var target,
prefData;
if(preference.attrib.name.match(/^android-manifest\//)){
// Extract manifest Xpath preferences
var parts = preference.attrib.name.split("/"),
destination = parts.pop();
parts.shift();
prefData = {
parent: parts.join("/") || "./",
type: type,
destination: destination,
data: preference
};
target = "AndroidManifest.xml";
}
if(prefData){
if(!configData[target]) {
configData[target] = [];
}
configData[target].push(prefData);
}
});
}
|
[
"function",
"parseAndroidPreferences",
"(",
"preferences",
",",
"configData",
")",
"{",
"var",
"type",
"=",
"'preference'",
";",
"_",
".",
"each",
"(",
"preferences",
",",
"function",
"(",
"preference",
")",
"{",
"var",
"target",
",",
"prefData",
";",
"if",
"(",
"preference",
".",
"attrib",
".",
"name",
".",
"match",
"(",
"/",
"^android-manifest\\/",
"/",
")",
")",
"{",
"var",
"parts",
"=",
"preference",
".",
"attrib",
".",
"name",
".",
"split",
"(",
"\"/\"",
")",
",",
"destination",
"=",
"parts",
".",
"pop",
"(",
")",
";",
"parts",
".",
"shift",
"(",
")",
";",
"prefData",
"=",
"{",
"parent",
":",
"parts",
".",
"join",
"(",
"\"/\"",
")",
"||",
"\"./\"",
",",
"type",
":",
"type",
",",
"destination",
":",
"destination",
",",
"data",
":",
"preference",
"}",
";",
"target",
"=",
"\"AndroidManifest.xml\"",
";",
"}",
"if",
"(",
"prefData",
")",
"{",
"if",
"(",
"!",
"configData",
"[",
"target",
"]",
")",
"{",
"configData",
"[",
"target",
"]",
"=",
"[",
"]",
";",
"}",
"configData",
"[",
"target",
"]",
".",
"push",
"(",
"prefData",
")",
";",
"}",
"}",
")",
";",
"}"
] |
Parses supported Android preferences using the preference mapping into the appropriate XML elements in AndroidManifest.xml
|
[
"Parses",
"supported",
"Android",
"preferences",
"using",
"the",
"preference",
"mapping",
"into",
"the",
"appropriate",
"XML",
"elements",
"in",
"AndroidManifest",
".",
"xml"
] |
23edee3c5904cff3d723907a928ddf20dab8ffa5
|
https://github.com/QuickBlox/quickblox-javascript-sdk/blob/23edee3c5904cff3d723907a928ddf20dab8ffa5/samples/cordova/video_chat/plugins/cordova-custom-config/hooks/applyCustomConfig.js#L257-L287
|
train
|
QuickBlox/quickblox-javascript-sdk
|
samples/cordova/video_chat/plugins/cordova-custom-config/hooks/applyCustomConfig.js
|
updateWp8Manifest
|
function updateWp8Manifest(targetFilePath, configItems) {
var tempManifest = fileUtils.parseElementtreeSync(targetFilePath),
root = tempManifest.getroot();
_.each(configItems, function (item) {
// if parent is not found on the root, child/grandchild nodes are searched
var parentEl = root.find(item.parent) || root.find('*/' + item.parent),
parentSelector,
data = item.data,
childSelector = item.destination,
childEl;
if(!parentEl) {
return;
}
_.each(data.attrib, function (prop, propName) {
childSelector += '[@'+propName+'="'+prop+'"]';
});
childEl = parentEl.find(childSelector);
// if child element doesnt exist, create new element
if(!childEl) {
childEl = new et.Element(item.destination);
parentEl.append(childEl);
}
// copy all config.xml data except for the generated _id property
_.each(data, function (prop, propName) {
if(propName !== '_id') {
childEl[propName] = prop;
}
});
});
fs.writeFileSync(targetFilePath, tempManifest.write({indent: 4}), 'utf-8');
}
|
javascript
|
function updateWp8Manifest(targetFilePath, configItems) {
var tempManifest = fileUtils.parseElementtreeSync(targetFilePath),
root = tempManifest.getroot();
_.each(configItems, function (item) {
// if parent is not found on the root, child/grandchild nodes are searched
var parentEl = root.find(item.parent) || root.find('*/' + item.parent),
parentSelector,
data = item.data,
childSelector = item.destination,
childEl;
if(!parentEl) {
return;
}
_.each(data.attrib, function (prop, propName) {
childSelector += '[@'+propName+'="'+prop+'"]';
});
childEl = parentEl.find(childSelector);
// if child element doesnt exist, create new element
if(!childEl) {
childEl = new et.Element(item.destination);
parentEl.append(childEl);
}
// copy all config.xml data except for the generated _id property
_.each(data, function (prop, propName) {
if(propName !== '_id') {
childEl[propName] = prop;
}
});
});
fs.writeFileSync(targetFilePath, tempManifest.write({indent: 4}), 'utf-8');
}
|
[
"function",
"updateWp8Manifest",
"(",
"targetFilePath",
",",
"configItems",
")",
"{",
"var",
"tempManifest",
"=",
"fileUtils",
".",
"parseElementtreeSync",
"(",
"targetFilePath",
")",
",",
"root",
"=",
"tempManifest",
".",
"getroot",
"(",
")",
";",
"_",
".",
"each",
"(",
"configItems",
",",
"function",
"(",
"item",
")",
"{",
"var",
"parentEl",
"=",
"root",
".",
"find",
"(",
"item",
".",
"parent",
")",
"||",
"root",
".",
"find",
"(",
"'*/'",
"+",
"item",
".",
"parent",
")",
",",
"parentSelector",
",",
"data",
"=",
"item",
".",
"data",
",",
"childSelector",
"=",
"item",
".",
"destination",
",",
"childEl",
";",
"if",
"(",
"!",
"parentEl",
")",
"{",
"return",
";",
"}",
"_",
".",
"each",
"(",
"data",
".",
"attrib",
",",
"function",
"(",
"prop",
",",
"propName",
")",
"{",
"childSelector",
"+=",
"'[@'",
"+",
"propName",
"+",
"'=\"'",
"+",
"prop",
"+",
"'\"]'",
";",
"}",
")",
";",
"childEl",
"=",
"parentEl",
".",
"find",
"(",
"childSelector",
")",
";",
"if",
"(",
"!",
"childEl",
")",
"{",
"childEl",
"=",
"new",
"et",
".",
"Element",
"(",
"item",
".",
"destination",
")",
";",
"parentEl",
".",
"append",
"(",
"childEl",
")",
";",
"}",
"_",
".",
"each",
"(",
"data",
",",
"function",
"(",
"prop",
",",
"propName",
")",
"{",
"if",
"(",
"propName",
"!==",
"'_id'",
")",
"{",
"childEl",
"[",
"propName",
"]",
"=",
"prop",
";",
"}",
"}",
")",
";",
"}",
")",
";",
"fs",
".",
"writeFileSync",
"(",
"targetFilePath",
",",
"tempManifest",
".",
"write",
"(",
"{",
"indent",
":",
"4",
"}",
")",
",",
"'utf-8'",
")",
";",
"}"
] |
Updates target file with data from config.xml
|
[
"Updates",
"target",
"file",
"with",
"data",
"from",
"config",
".",
"xml"
] |
23edee3c5904cff3d723907a928ddf20dab8ffa5
|
https://github.com/QuickBlox/quickblox-javascript-sdk/blob/23edee3c5904cff3d723907a928ddf20dab8ffa5/samples/cordova/video_chat/plugins/cordova-custom-config/hooks/applyCustomConfig.js#L430-L464
|
train
|
QuickBlox/quickblox-javascript-sdk
|
samples/cordova/video_chat/plugins/cordova-custom-config/hooks/applyCustomConfig.js
|
updateIosPbxProj
|
function updateIosPbxProj(xcodeProjectPath, configItems) {
var xcodeProject = xcode.project(xcodeProjectPath);
xcodeProject.parse(function(err){
if(err){
// shell is undefined if android platform has been removed and added with a new package id but ios stayed the same.
var msg = 'An error occurred during parsing of [' + xcodeProjectPath + ']: ' + JSON.stringify(err);
if(typeof shell !== "undefined" && shell !== null){
shell.echo(msg);
} else{
logger.error(msg + ' - Maybe you forgot to remove/add the ios platform?');
}
}else{
_.each(configItems, function (item) {
switch(item.type){
case "XCBuildConfiguration":
var buildConfig = xcodeProject.pbxXCBuildConfigurationSection();
var replaced = updateXCBuildConfiguration(item, buildConfig, "replace");
if(!replaced){
updateXCBuildConfiguration(item, buildConfig, "add");
}
break;
}
});
fs.writeFileSync(xcodeProjectPath, xcodeProject.writeSync(), 'utf-8');
}
});
}
|
javascript
|
function updateIosPbxProj(xcodeProjectPath, configItems) {
var xcodeProject = xcode.project(xcodeProjectPath);
xcodeProject.parse(function(err){
if(err){
// shell is undefined if android platform has been removed and added with a new package id but ios stayed the same.
var msg = 'An error occurred during parsing of [' + xcodeProjectPath + ']: ' + JSON.stringify(err);
if(typeof shell !== "undefined" && shell !== null){
shell.echo(msg);
} else{
logger.error(msg + ' - Maybe you forgot to remove/add the ios platform?');
}
}else{
_.each(configItems, function (item) {
switch(item.type){
case "XCBuildConfiguration":
var buildConfig = xcodeProject.pbxXCBuildConfigurationSection();
var replaced = updateXCBuildConfiguration(item, buildConfig, "replace");
if(!replaced){
updateXCBuildConfiguration(item, buildConfig, "add");
}
break;
}
});
fs.writeFileSync(xcodeProjectPath, xcodeProject.writeSync(), 'utf-8');
}
});
}
|
[
"function",
"updateIosPbxProj",
"(",
"xcodeProjectPath",
",",
"configItems",
")",
"{",
"var",
"xcodeProject",
"=",
"xcode",
".",
"project",
"(",
"xcodeProjectPath",
")",
";",
"xcodeProject",
".",
"parse",
"(",
"function",
"(",
"err",
")",
"{",
"if",
"(",
"err",
")",
"{",
"var",
"msg",
"=",
"'An error occurred during parsing of ['",
"+",
"xcodeProjectPath",
"+",
"']: '",
"+",
"JSON",
".",
"stringify",
"(",
"err",
")",
";",
"if",
"(",
"typeof",
"shell",
"!==",
"\"undefined\"",
"&&",
"shell",
"!==",
"null",
")",
"{",
"shell",
".",
"echo",
"(",
"msg",
")",
";",
"}",
"else",
"{",
"logger",
".",
"error",
"(",
"msg",
"+",
"' - Maybe you forgot to remove/add the ios platform?'",
")",
";",
"}",
"}",
"else",
"{",
"_",
".",
"each",
"(",
"configItems",
",",
"function",
"(",
"item",
")",
"{",
"switch",
"(",
"item",
".",
"type",
")",
"{",
"case",
"\"XCBuildConfiguration\"",
":",
"var",
"buildConfig",
"=",
"xcodeProject",
".",
"pbxXCBuildConfigurationSection",
"(",
")",
";",
"var",
"replaced",
"=",
"updateXCBuildConfiguration",
"(",
"item",
",",
"buildConfig",
",",
"\"replace\"",
")",
";",
"if",
"(",
"!",
"replaced",
")",
"{",
"updateXCBuildConfiguration",
"(",
"item",
",",
"buildConfig",
",",
"\"add\"",
")",
";",
"}",
"break",
";",
"}",
"}",
")",
";",
"fs",
".",
"writeFileSync",
"(",
"xcodeProjectPath",
",",
"xcodeProject",
".",
"writeSync",
"(",
")",
",",
"'utf-8'",
")",
";",
"}",
"}",
")",
";",
"}"
] |
Updates the project.pbxproj file with data from config.xml
@param {String} xcodeProjectPath - path to XCode project file
@param {Array} configItems - config items to update project file with
|
[
"Updates",
"the",
"project",
".",
"pbxproj",
"file",
"with",
"data",
"from",
"config",
".",
"xml"
] |
23edee3c5904cff3d723907a928ddf20dab8ffa5
|
https://github.com/QuickBlox/quickblox-javascript-sdk/blob/23edee3c5904cff3d723907a928ddf20dab8ffa5/samples/cordova/video_chat/plugins/cordova-custom-config/hooks/applyCustomConfig.js#L493-L519
|
train
|
QuickBlox/quickblox-javascript-sdk
|
samples/cordova/video_chat/plugins/cordova-custom-config/hooks/applyCustomConfig.js
|
updateXCBuildConfiguration
|
function updateXCBuildConfiguration(item, buildConfig, mode){
var modified = false;
for(var blockName in buildConfig){
var block = buildConfig[blockName];
if(typeof(block) !== "object" || !(block["buildSettings"])) continue;
var literalMatch = !!block["buildSettings"][item.name],
quotedMatch = !!block["buildSettings"][quoteEscape(item.name)],
match = literalMatch || quotedMatch;
if((match || mode === "add") &&
(!item.buildType || item.buildType.toLowerCase() === block['name'].toLowerCase())){
var name;
if(match){
name = literalMatch ? item.name : quoteEscape(item.name);
}else{
// adding
name = (item.quote && (item.quote === "none" || item.quote === "value")) ? item.name : quoteEscape(item.name);
}
var value = (item.quote && (item.quote === "none" || item.quote === "key")) ? item.value : quoteEscape(item.value);
block["buildSettings"][name] = value;
modified = true;
logger.verbose(mode+" XCBuildConfiguration key={ "+name+" } to value={ "+value+" } for build type='"+block['name']+"' in block='"+blockName+"'");
}
}
return modified;
}
|
javascript
|
function updateXCBuildConfiguration(item, buildConfig, mode){
var modified = false;
for(var blockName in buildConfig){
var block = buildConfig[blockName];
if(typeof(block) !== "object" || !(block["buildSettings"])) continue;
var literalMatch = !!block["buildSettings"][item.name],
quotedMatch = !!block["buildSettings"][quoteEscape(item.name)],
match = literalMatch || quotedMatch;
if((match || mode === "add") &&
(!item.buildType || item.buildType.toLowerCase() === block['name'].toLowerCase())){
var name;
if(match){
name = literalMatch ? item.name : quoteEscape(item.name);
}else{
// adding
name = (item.quote && (item.quote === "none" || item.quote === "value")) ? item.name : quoteEscape(item.name);
}
var value = (item.quote && (item.quote === "none" || item.quote === "key")) ? item.value : quoteEscape(item.value);
block["buildSettings"][name] = value;
modified = true;
logger.verbose(mode+" XCBuildConfiguration key={ "+name+" } to value={ "+value+" } for build type='"+block['name']+"' in block='"+blockName+"'");
}
}
return modified;
}
|
[
"function",
"updateXCBuildConfiguration",
"(",
"item",
",",
"buildConfig",
",",
"mode",
")",
"{",
"var",
"modified",
"=",
"false",
";",
"for",
"(",
"var",
"blockName",
"in",
"buildConfig",
")",
"{",
"var",
"block",
"=",
"buildConfig",
"[",
"blockName",
"]",
";",
"if",
"(",
"typeof",
"(",
"block",
")",
"!==",
"\"object\"",
"||",
"!",
"(",
"block",
"[",
"\"buildSettings\"",
"]",
")",
")",
"continue",
";",
"var",
"literalMatch",
"=",
"!",
"!",
"block",
"[",
"\"buildSettings\"",
"]",
"[",
"item",
".",
"name",
"]",
",",
"quotedMatch",
"=",
"!",
"!",
"block",
"[",
"\"buildSettings\"",
"]",
"[",
"quoteEscape",
"(",
"item",
".",
"name",
")",
"]",
",",
"match",
"=",
"literalMatch",
"||",
"quotedMatch",
";",
"if",
"(",
"(",
"match",
"||",
"mode",
"===",
"\"add\"",
")",
"&&",
"(",
"!",
"item",
".",
"buildType",
"||",
"item",
".",
"buildType",
".",
"toLowerCase",
"(",
")",
"===",
"block",
"[",
"'name'",
"]",
".",
"toLowerCase",
"(",
")",
")",
")",
"{",
"var",
"name",
";",
"if",
"(",
"match",
")",
"{",
"name",
"=",
"literalMatch",
"?",
"item",
".",
"name",
":",
"quoteEscape",
"(",
"item",
".",
"name",
")",
";",
"}",
"else",
"{",
"name",
"=",
"(",
"item",
".",
"quote",
"&&",
"(",
"item",
".",
"quote",
"===",
"\"none\"",
"||",
"item",
".",
"quote",
"===",
"\"value\"",
")",
")",
"?",
"item",
".",
"name",
":",
"quoteEscape",
"(",
"item",
".",
"name",
")",
";",
"}",
"var",
"value",
"=",
"(",
"item",
".",
"quote",
"&&",
"(",
"item",
".",
"quote",
"===",
"\"none\"",
"||",
"item",
".",
"quote",
"===",
"\"key\"",
")",
")",
"?",
"item",
".",
"value",
":",
"quoteEscape",
"(",
"item",
".",
"value",
")",
";",
"block",
"[",
"\"buildSettings\"",
"]",
"[",
"name",
"]",
"=",
"value",
";",
"modified",
"=",
"true",
";",
"logger",
".",
"verbose",
"(",
"mode",
"+",
"\" XCBuildConfiguration key={ \"",
"+",
"name",
"+",
"\" } to value={ \"",
"+",
"value",
"+",
"\" } for build type='\"",
"+",
"block",
"[",
"'name'",
"]",
"+",
"\"' in block='\"",
"+",
"blockName",
"+",
"\"'\"",
")",
";",
"}",
"}",
"return",
"modified",
";",
"}"
] |
Updates an XCode build configuration setting with the given item.
@param {Object} item - configuration item containing setting data
@param {Object} buildConfig - XCode build config object
@param {String} mode - update mode: "replace" to replace only existing keys or "add" to add a new key to every block
@returns {boolean} true if buildConfig was modified
|
[
"Updates",
"an",
"XCode",
"build",
"configuration",
"setting",
"with",
"the",
"given",
"item",
"."
] |
23edee3c5904cff3d723907a928ddf20dab8ffa5
|
https://github.com/QuickBlox/quickblox-javascript-sdk/blob/23edee3c5904cff3d723907a928ddf20dab8ffa5/samples/cordova/video_chat/plugins/cordova-custom-config/hooks/applyCustomConfig.js#L528-L556
|
train
|
QuickBlox/quickblox-javascript-sdk
|
src/modules/qbData.js
|
function(className, params) {
var result = Utils.getUrl(config.urls.data, className + '/' + params.id + '/file');
result += '?field_name=' + params.field_name + '&token=' + this.service.getSession().token;
return result;
}
|
javascript
|
function(className, params) {
var result = Utils.getUrl(config.urls.data, className + '/' + params.id + '/file');
result += '?field_name=' + params.field_name + '&token=' + this.service.getSession().token;
return result;
}
|
[
"function",
"(",
"className",
",",
"params",
")",
"{",
"var",
"result",
"=",
"Utils",
".",
"getUrl",
"(",
"config",
".",
"urls",
".",
"data",
",",
"className",
"+",
"'/'",
"+",
"params",
".",
"id",
"+",
"'/file'",
")",
";",
"result",
"+=",
"'?field_name='",
"+",
"params",
".",
"field_name",
"+",
"'&token='",
"+",
"this",
".",
"service",
".",
"getSession",
"(",
")",
".",
"token",
";",
"return",
"result",
";",
"}"
] |
Return file's URL from file field by ID
@memberof QB.data
@param {string} className - A class name of record
@param {object} params - Object of parameters
@param {string} params.field_name - The file's field name
@param {string} params.id - The record's ID
|
[
"Return",
"file",
"s",
"URL",
"from",
"file",
"field",
"by",
"ID"
] |
23edee3c5904cff3d723907a928ddf20dab8ffa5
|
https://github.com/QuickBlox/quickblox-javascript-sdk/blob/23edee3c5904cff3d723907a928ddf20dab8ffa5/src/modules/qbData.js#L347-L351
|
train
|
|
QuickBlox/quickblox-javascript-sdk
|
src/modules/qbContent.js
|
function(params, callback) {
/**
* Callback for QB.content.createAndUpload(params, callback).
* @callback createAndUploadFileCallback
* @param {object} error - The error object
* @param {object} response - The file object (blob-object-access)
*/
var _this = this,
createParams= {},
file,
name,
type,
size,
fileId;
var clonedParams = JSON.parse(JSON.stringify(params));
clonedParams.file.data = "...";
file = params.file;
name = params.name || file.name;
type = params.type || file.type;
size = params.size || file.size;
createParams.name = name;
createParams.content_type = type;
if (params.public) {
createParams.public = params.public;
}
if (params.tag_list) {
createParams.tag_list = params.tag_list;
}
// Create a file object
this.create(createParams, function(err, createResult){
if (err) {
callback(err, null);
} else {
var uri = parseUri(createResult.blob_object_access.params),
uploadUrl = uri.protocol + "://" + uri.authority + uri.path,
uploadParams = {url: uploadUrl},
data = {};
fileId = createResult.id;
createResult.size = size;
Object.keys(uri.queryKey).forEach(function(val) {
data[val] = decodeURIComponent(uri.queryKey[val]);
});
data.file = file;
uploadParams.data = data;
// Upload the file to Amazon S3
_this.upload(uploadParams, function(err, result) {
if (err) {
callback(err, null);
} else {
// Mark file as uploaded
_this.markUploaded({
id: fileId,
size: size
}, function(err, result){
if (err) {
callback(err, null);
} else {
callback(null, createResult);
}
});
}
});
}
});
}
|
javascript
|
function(params, callback) {
/**
* Callback for QB.content.createAndUpload(params, callback).
* @callback createAndUploadFileCallback
* @param {object} error - The error object
* @param {object} response - The file object (blob-object-access)
*/
var _this = this,
createParams= {},
file,
name,
type,
size,
fileId;
var clonedParams = JSON.parse(JSON.stringify(params));
clonedParams.file.data = "...";
file = params.file;
name = params.name || file.name;
type = params.type || file.type;
size = params.size || file.size;
createParams.name = name;
createParams.content_type = type;
if (params.public) {
createParams.public = params.public;
}
if (params.tag_list) {
createParams.tag_list = params.tag_list;
}
// Create a file object
this.create(createParams, function(err, createResult){
if (err) {
callback(err, null);
} else {
var uri = parseUri(createResult.blob_object_access.params),
uploadUrl = uri.protocol + "://" + uri.authority + uri.path,
uploadParams = {url: uploadUrl},
data = {};
fileId = createResult.id;
createResult.size = size;
Object.keys(uri.queryKey).forEach(function(val) {
data[val] = decodeURIComponent(uri.queryKey[val]);
});
data.file = file;
uploadParams.data = data;
// Upload the file to Amazon S3
_this.upload(uploadParams, function(err, result) {
if (err) {
callback(err, null);
} else {
// Mark file as uploaded
_this.markUploaded({
id: fileId,
size: size
}, function(err, result){
if (err) {
callback(err, null);
} else {
callback(null, createResult);
}
});
}
});
}
});
}
|
[
"function",
"(",
"params",
",",
"callback",
")",
"{",
"var",
"_this",
"=",
"this",
",",
"createParams",
"=",
"{",
"}",
",",
"file",
",",
"name",
",",
"type",
",",
"size",
",",
"fileId",
";",
"var",
"clonedParams",
"=",
"JSON",
".",
"parse",
"(",
"JSON",
".",
"stringify",
"(",
"params",
")",
")",
";",
"clonedParams",
".",
"file",
".",
"data",
"=",
"\"...\"",
";",
"file",
"=",
"params",
".",
"file",
";",
"name",
"=",
"params",
".",
"name",
"||",
"file",
".",
"name",
";",
"type",
"=",
"params",
".",
"type",
"||",
"file",
".",
"type",
";",
"size",
"=",
"params",
".",
"size",
"||",
"file",
".",
"size",
";",
"createParams",
".",
"name",
"=",
"name",
";",
"createParams",
".",
"content_type",
"=",
"type",
";",
"if",
"(",
"params",
".",
"public",
")",
"{",
"createParams",
".",
"public",
"=",
"params",
".",
"public",
";",
"}",
"if",
"(",
"params",
".",
"tag_list",
")",
"{",
"createParams",
".",
"tag_list",
"=",
"params",
".",
"tag_list",
";",
"}",
"this",
".",
"create",
"(",
"createParams",
",",
"function",
"(",
"err",
",",
"createResult",
")",
"{",
"if",
"(",
"err",
")",
"{",
"callback",
"(",
"err",
",",
"null",
")",
";",
"}",
"else",
"{",
"var",
"uri",
"=",
"parseUri",
"(",
"createResult",
".",
"blob_object_access",
".",
"params",
")",
",",
"uploadUrl",
"=",
"uri",
".",
"protocol",
"+",
"\"://\"",
"+",
"uri",
".",
"authority",
"+",
"uri",
".",
"path",
",",
"uploadParams",
"=",
"{",
"url",
":",
"uploadUrl",
"}",
",",
"data",
"=",
"{",
"}",
";",
"fileId",
"=",
"createResult",
".",
"id",
";",
"createResult",
".",
"size",
"=",
"size",
";",
"Object",
".",
"keys",
"(",
"uri",
".",
"queryKey",
")",
".",
"forEach",
"(",
"function",
"(",
"val",
")",
"{",
"data",
"[",
"val",
"]",
"=",
"decodeURIComponent",
"(",
"uri",
".",
"queryKey",
"[",
"val",
"]",
")",
";",
"}",
")",
";",
"data",
".",
"file",
"=",
"file",
";",
"uploadParams",
".",
"data",
"=",
"data",
";",
"_this",
".",
"upload",
"(",
"uploadParams",
",",
"function",
"(",
"err",
",",
"result",
")",
"{",
"if",
"(",
"err",
")",
"{",
"callback",
"(",
"err",
",",
"null",
")",
";",
"}",
"else",
"{",
"_this",
".",
"markUploaded",
"(",
"{",
"id",
":",
"fileId",
",",
"size",
":",
"size",
"}",
",",
"function",
"(",
"err",
",",
"result",
")",
"{",
"if",
"(",
"err",
")",
"{",
"callback",
"(",
"err",
",",
"null",
")",
";",
"}",
"else",
"{",
"callback",
"(",
"null",
",",
"createResult",
")",
";",
"}",
"}",
")",
";",
"}",
"}",
")",
";",
"}",
"}",
")",
";",
"}"
] |
Create file > upload file > mark file as uploaded > return result.
@memberof QB.content
@param {object} params - Object of parameters
@param {object} params.file - File object
@param {string} params.name - The file's name
@param {string} params.type - The file's mime ({@link https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types/Complete_list_of_MIME_types content type})
@param {number} params.size - Size of file, in bytes
@param {boolean} [params.public=false] - The file's visibility. public means it will be possible to access this file without QuickBlox session token provided. Default is 'false'
@param {createAndUploadFileCallback} callback - The createAndUploadFileCallback function
|
[
"Create",
"file",
">",
"upload",
"file",
">",
"mark",
"file",
"as",
"uploaded",
">",
"return",
"result",
"."
] |
23edee3c5904cff3d723907a928ddf20dab8ffa5
|
https://github.com/QuickBlox/quickblox-javascript-sdk/blob/23edee3c5904cff3d723907a928ddf20dab8ffa5/src/modules/qbContent.js#L122-L197
|
train
|
|
QuickBlox/quickblox-javascript-sdk
|
src/modules/qbContent.js
|
function (id, callback) {
/**
* Callback for QB.content.getInfo(id, callback)
* @callback getFileInfoByIdCallback
* @param {object} error - The error object
* @param {object} response - The file object (blob-object-access)
*/
this.service.ajax({url: Utils.getUrl(config.urls.blobs, id)}, function (err, res) {
if (err) {
callback (err, null);
} else {
callback (null, res);
}
});
}
|
javascript
|
function (id, callback) {
/**
* Callback for QB.content.getInfo(id, callback)
* @callback getFileInfoByIdCallback
* @param {object} error - The error object
* @param {object} response - The file object (blob-object-access)
*/
this.service.ajax({url: Utils.getUrl(config.urls.blobs, id)}, function (err, res) {
if (err) {
callback (err, null);
} else {
callback (null, res);
}
});
}
|
[
"function",
"(",
"id",
",",
"callback",
")",
"{",
"this",
".",
"service",
".",
"ajax",
"(",
"{",
"url",
":",
"Utils",
".",
"getUrl",
"(",
"config",
".",
"urls",
".",
"blobs",
",",
"id",
")",
"}",
",",
"function",
"(",
"err",
",",
"res",
")",
"{",
"if",
"(",
"err",
")",
"{",
"callback",
"(",
"err",
",",
"null",
")",
";",
"}",
"else",
"{",
"callback",
"(",
"null",
",",
"res",
")",
";",
"}",
"}",
")",
";",
"}"
] |
Retrieve file object by id (@link https://docsdev.quickblox.com/rest_api/Content_API.html#Retrieve_file read more})
@memberof QB.content
@param {number} id - The id of file to declare as uploaded
@param {getFileInfoByIdCallback} callback - The getFileInfoByIdCallback function return file's object.
|
[
"Retrieve",
"file",
"object",
"by",
"id",
"("
] |
23edee3c5904cff3d723907a928ddf20dab8ffa5
|
https://github.com/QuickBlox/quickblox-javascript-sdk/blob/23edee3c5904cff3d723907a928ddf20dab8ffa5/src/modules/qbContent.js#L270-L284
|
train
|
|
McNull/angular-block-ui
|
dist/angular-block-ui.js
|
blockNavigation
|
function blockNavigation($scope, mainBlockUI, blockUIConfig) {
if (blockUIConfig.blockBrowserNavigation) {
function registerLocationChange() {
$scope.$on('$locationChangeStart', function (event) {
// console.log('$locationChangeStart', mainBlockUI.$_blockLocationChange + ' ' + mainBlockUI.state().blockCount);
if (mainBlockUI.$_blockLocationChange && mainBlockUI.state().blockCount > 0) {
event.preventDefault();
}
});
$scope.$on('$locationChangeSuccess', function () {
mainBlockUI.$_blockLocationChange = blockUIConfig.blockBrowserNavigation;
// console.log('$locationChangeSuccess', mainBlockUI.$_blockLocationChange + ' ' + mainBlockUI.state().blockCount);
});
}
if (moduleLoaded('ngRoute')) {
// After the initial content has been loaded we'll spy on any location
// changes and discard them when needed.
var fn = $scope.$on('$viewContentLoaded', function () {
// Unhook the view loaded and hook a function that will prevent
// location changes while the block is active.
fn();
registerLocationChange();
});
} else {
registerLocationChange();
}
}
}
|
javascript
|
function blockNavigation($scope, mainBlockUI, blockUIConfig) {
if (blockUIConfig.blockBrowserNavigation) {
function registerLocationChange() {
$scope.$on('$locationChangeStart', function (event) {
// console.log('$locationChangeStart', mainBlockUI.$_blockLocationChange + ' ' + mainBlockUI.state().blockCount);
if (mainBlockUI.$_blockLocationChange && mainBlockUI.state().blockCount > 0) {
event.preventDefault();
}
});
$scope.$on('$locationChangeSuccess', function () {
mainBlockUI.$_blockLocationChange = blockUIConfig.blockBrowserNavigation;
// console.log('$locationChangeSuccess', mainBlockUI.$_blockLocationChange + ' ' + mainBlockUI.state().blockCount);
});
}
if (moduleLoaded('ngRoute')) {
// After the initial content has been loaded we'll spy on any location
// changes and discard them when needed.
var fn = $scope.$on('$viewContentLoaded', function () {
// Unhook the view loaded and hook a function that will prevent
// location changes while the block is active.
fn();
registerLocationChange();
});
} else {
registerLocationChange();
}
}
}
|
[
"function",
"blockNavigation",
"(",
"$scope",
",",
"mainBlockUI",
",",
"blockUIConfig",
")",
"{",
"if",
"(",
"blockUIConfig",
".",
"blockBrowserNavigation",
")",
"{",
"function",
"registerLocationChange",
"(",
")",
"{",
"$scope",
".",
"$on",
"(",
"'$locationChangeStart'",
",",
"function",
"(",
"event",
")",
"{",
"if",
"(",
"mainBlockUI",
".",
"$_blockLocationChange",
"&&",
"mainBlockUI",
".",
"state",
"(",
")",
".",
"blockCount",
">",
"0",
")",
"{",
"event",
".",
"preventDefault",
"(",
")",
";",
"}",
"}",
")",
";",
"$scope",
".",
"$on",
"(",
"'$locationChangeSuccess'",
",",
"function",
"(",
")",
"{",
"mainBlockUI",
".",
"$_blockLocationChange",
"=",
"blockUIConfig",
".",
"blockBrowserNavigation",
";",
"}",
")",
";",
"}",
"if",
"(",
"moduleLoaded",
"(",
"'ngRoute'",
")",
")",
"{",
"var",
"fn",
"=",
"$scope",
".",
"$on",
"(",
"'$viewContentLoaded'",
",",
"function",
"(",
")",
"{",
"fn",
"(",
")",
";",
"registerLocationChange",
"(",
")",
";",
"}",
")",
";",
"}",
"else",
"{",
"registerLocationChange",
"(",
")",
";",
"}",
"}",
"}"
] |
Called from block-ui-directive for the 'main' instance.
|
[
"Called",
"from",
"block",
"-",
"ui",
"-",
"directive",
"for",
"the",
"main",
"instance",
"."
] |
0d01eee67a6f8b0fd6beeaf16f950d1870842702
|
https://github.com/McNull/angular-block-ui/blob/0d01eee67a6f8b0fd6beeaf16f950d1870842702/dist/angular-block-ui.js#L104-L146
|
train
|
exceptionless/Exceptionless.JavaScript
|
dist/exceptionless.universal.js
|
unsubscribe
|
function unsubscribe(handler) {
for (var i = handlers.length - 1; i >= 0; --i) {
if (handlers[i] === handler) {
handlers.splice(i, 1);
}
}
if (handlers.length === 0) {
window.onerror = _oldOnerrorHandler;
_onErrorHandlerInstalled = false;
}
}
|
javascript
|
function unsubscribe(handler) {
for (var i = handlers.length - 1; i >= 0; --i) {
if (handlers[i] === handler) {
handlers.splice(i, 1);
}
}
if (handlers.length === 0) {
window.onerror = _oldOnerrorHandler;
_onErrorHandlerInstalled = false;
}
}
|
[
"function",
"unsubscribe",
"(",
"handler",
")",
"{",
"for",
"(",
"var",
"i",
"=",
"handlers",
".",
"length",
"-",
"1",
";",
"i",
">=",
"0",
";",
"--",
"i",
")",
"{",
"if",
"(",
"handlers",
"[",
"i",
"]",
"===",
"handler",
")",
"{",
"handlers",
".",
"splice",
"(",
"i",
",",
"1",
")",
";",
"}",
"}",
"if",
"(",
"handlers",
".",
"length",
"===",
"0",
")",
"{",
"window",
".",
"onerror",
"=",
"_oldOnerrorHandler",
";",
"_onErrorHandlerInstalled",
"=",
"false",
";",
"}",
"}"
] |
Remove a crash handler.
@param {Function} handler
@memberof TraceKit.report
|
[
"Remove",
"a",
"crash",
"handler",
"."
] |
02711d099660a6d51a107b69a6e1c2aa68c9c559
|
https://github.com/exceptionless/Exceptionless.JavaScript/blob/02711d099660a6d51a107b69a6e1c2aa68c9c559/dist/exceptionless.universal.js#L139-L150
|
train
|
exceptionless/Exceptionless.JavaScript
|
dist/exceptionless.universal.js
|
installGlobalHandler
|
function installGlobalHandler() {
if (_onErrorHandlerInstalled === true) {
return;
}
_oldOnerrorHandler = window.onerror;
window.onerror = traceKitWindowOnError;
_onErrorHandlerInstalled = true;
}
|
javascript
|
function installGlobalHandler() {
if (_onErrorHandlerInstalled === true) {
return;
}
_oldOnerrorHandler = window.onerror;
window.onerror = traceKitWindowOnError;
_onErrorHandlerInstalled = true;
}
|
[
"function",
"installGlobalHandler",
"(",
")",
"{",
"if",
"(",
"_onErrorHandlerInstalled",
"===",
"true",
")",
"{",
"return",
";",
"}",
"_oldOnerrorHandler",
"=",
"window",
".",
"onerror",
";",
"window",
".",
"onerror",
"=",
"traceKitWindowOnError",
";",
"_onErrorHandlerInstalled",
"=",
"true",
";",
"}"
] |
Install a global onerror handler
@memberof TraceKit.report
|
[
"Install",
"a",
"global",
"onerror",
"handler"
] |
02711d099660a6d51a107b69a6e1c2aa68c9c559
|
https://github.com/exceptionless/Exceptionless.JavaScript/blob/02711d099660a6d51a107b69a6e1c2aa68c9c559/dist/exceptionless.universal.js#L241-L249
|
train
|
exceptionless/Exceptionless.JavaScript
|
dist/exceptionless.universal.js
|
processLastException
|
function processLastException() {
var _lastExceptionStack = lastExceptionStack,
_lastException = lastException;
lastExceptionStack = null;
lastException = null;
notifyHandlers(_lastExceptionStack, false, _lastException);
}
|
javascript
|
function processLastException() {
var _lastExceptionStack = lastExceptionStack,
_lastException = lastException;
lastExceptionStack = null;
lastException = null;
notifyHandlers(_lastExceptionStack, false, _lastException);
}
|
[
"function",
"processLastException",
"(",
")",
"{",
"var",
"_lastExceptionStack",
"=",
"lastExceptionStack",
",",
"_lastException",
"=",
"lastException",
";",
"lastExceptionStack",
"=",
"null",
";",
"lastException",
"=",
"null",
";",
"notifyHandlers",
"(",
"_lastExceptionStack",
",",
"false",
",",
"_lastException",
")",
";",
"}"
] |
Process the most recent exception
@memberof TraceKit.report
|
[
"Process",
"the",
"most",
"recent",
"exception"
] |
02711d099660a6d51a107b69a6e1c2aa68c9c559
|
https://github.com/exceptionless/Exceptionless.JavaScript/blob/02711d099660a6d51a107b69a6e1c2aa68c9c559/dist/exceptionless.universal.js#L255-L261
|
train
|
exceptionless/Exceptionless.JavaScript
|
dist/exceptionless.universal.js
|
loadSource
|
function loadSource(url) {
if (!TraceKit.remoteFetching) { //Only attempt request if remoteFetching is on.
return '';
}
try {
var getXHR = function() {
try {
return new window.XMLHttpRequest();
} catch (e) {
// explicitly bubble up the exception if not found
return new window.ActiveXObject('Microsoft.XMLHTTP');
}
};
var request = getXHR();
request.open('GET', url, false);
request.send('');
return request.responseText;
} catch (e) {
return '';
}
}
|
javascript
|
function loadSource(url) {
if (!TraceKit.remoteFetching) { //Only attempt request if remoteFetching is on.
return '';
}
try {
var getXHR = function() {
try {
return new window.XMLHttpRequest();
} catch (e) {
// explicitly bubble up the exception if not found
return new window.ActiveXObject('Microsoft.XMLHTTP');
}
};
var request = getXHR();
request.open('GET', url, false);
request.send('');
return request.responseText;
} catch (e) {
return '';
}
}
|
[
"function",
"loadSource",
"(",
"url",
")",
"{",
"if",
"(",
"!",
"TraceKit",
".",
"remoteFetching",
")",
"{",
"return",
"''",
";",
"}",
"try",
"{",
"var",
"getXHR",
"=",
"function",
"(",
")",
"{",
"try",
"{",
"return",
"new",
"window",
".",
"XMLHttpRequest",
"(",
")",
";",
"}",
"catch",
"(",
"e",
")",
"{",
"return",
"new",
"window",
".",
"ActiveXObject",
"(",
"'Microsoft.XMLHTTP'",
")",
";",
"}",
"}",
";",
"var",
"request",
"=",
"getXHR",
"(",
")",
";",
"request",
".",
"open",
"(",
"'GET'",
",",
"url",
",",
"false",
")",
";",
"request",
".",
"send",
"(",
"''",
")",
";",
"return",
"request",
".",
"responseText",
";",
"}",
"catch",
"(",
"e",
")",
"{",
"return",
"''",
";",
"}",
"}"
] |
Attempts to retrieve source code via XMLHttpRequest, which is used
to look up anonymous function names.
@param {string} url URL of source code.
@return {string} Source contents.
@memberof TraceKit.computeStackTrace
|
[
"Attempts",
"to",
"retrieve",
"source",
"code",
"via",
"XMLHttpRequest",
"which",
"is",
"used",
"to",
"look",
"up",
"anonymous",
"function",
"names",
"."
] |
02711d099660a6d51a107b69a6e1c2aa68c9c559
|
https://github.com/exceptionless/Exceptionless.JavaScript/blob/02711d099660a6d51a107b69a6e1c2aa68c9c559/dist/exceptionless.universal.js#L396-L417
|
train
|
exceptionless/Exceptionless.JavaScript
|
dist/exceptionless.universal.js
|
findSourceInUrls
|
function findSourceInUrls(re, urls) {
var source, m;
for (var i = 0, j = urls.length; i < j; ++i) {
if ((source = getSource(urls[i])).length) {
source = source.join('\n');
if ((m = re.exec(source))) {
return {
'url': urls[i],
'line': source.substring(0, m.index).split('\n').length,
'column': m.index - source.lastIndexOf('\n', m.index) - 1
};
}
}
}
return null;
}
|
javascript
|
function findSourceInUrls(re, urls) {
var source, m;
for (var i = 0, j = urls.length; i < j; ++i) {
if ((source = getSource(urls[i])).length) {
source = source.join('\n');
if ((m = re.exec(source))) {
return {
'url': urls[i],
'line': source.substring(0, m.index).split('\n').length,
'column': m.index - source.lastIndexOf('\n', m.index) - 1
};
}
}
}
return null;
}
|
[
"function",
"findSourceInUrls",
"(",
"re",
",",
"urls",
")",
"{",
"var",
"source",
",",
"m",
";",
"for",
"(",
"var",
"i",
"=",
"0",
",",
"j",
"=",
"urls",
".",
"length",
";",
"i",
"<",
"j",
";",
"++",
"i",
")",
"{",
"if",
"(",
"(",
"source",
"=",
"getSource",
"(",
"urls",
"[",
"i",
"]",
")",
")",
".",
"length",
")",
"{",
"source",
"=",
"source",
".",
"join",
"(",
"'\\n'",
")",
";",
"\\n",
"}",
"}",
"if",
"(",
"(",
"m",
"=",
"re",
".",
"exec",
"(",
"source",
")",
")",
")",
"{",
"return",
"{",
"'url'",
":",
"urls",
"[",
"i",
"]",
",",
"'line'",
":",
"source",
".",
"substring",
"(",
"0",
",",
"m",
".",
"index",
")",
".",
"split",
"(",
"'\\n'",
")",
".",
"\\n",
",",
"length",
"}",
";",
"}",
"}"
] |
Determines where a code fragment occurs in the source code.
@param {RegExp} re The function definition.
@param {Array.<string>} urls A list of URLs to search.
@return {?Object.<string, (string|number)>} An object containing
the url, line, and column number of the defined function.
@memberof TraceKit.computeStackTrace
|
[
"Determines",
"where",
"a",
"code",
"fragment",
"occurs",
"in",
"the",
"source",
"code",
"."
] |
02711d099660a6d51a107b69a6e1c2aa68c9c559
|
https://github.com/exceptionless/Exceptionless.JavaScript/blob/02711d099660a6d51a107b69a6e1c2aa68c9c559/dist/exceptionless.universal.js#L558-L575
|
train
|
exceptionless/Exceptionless.JavaScript
|
dist/exceptionless.universal.js
|
findSourceByFunctionBody
|
function findSourceByFunctionBody(func) {
if (_isUndefined(window && window.document)) {
return;
}
var urls = [window.location.href],
scripts = window.document.getElementsByTagName('script'),
body,
code = '' + func,
codeRE = /^function(?:\s+([\w$]+))?\s*\(([\w\s,]*)\)\s*\{\s*(\S[\s\S]*\S)\s*\}\s*$/,
eventRE = /^function on([\w$]+)\s*\(event\)\s*\{\s*(\S[\s\S]*\S)\s*\}\s*$/,
re,
parts,
result;
for (var i = 0; i < scripts.length; ++i) {
var script = scripts[i];
if (script.src) {
urls.push(script.src);
}
}
if (!(parts = codeRE.exec(code))) {
re = new RegExp(escapeRegExp(code).replace(/\s+/g, '\\s+'));
}
// not sure if this is really necessary, but I don’t have a test
// corpus large enough to confirm that and it was in the original.
else {
var name = parts[1] ? '\\s+' + parts[1] : '',
args = parts[2].split(',').join('\\s*,\\s*');
body = escapeRegExp(parts[3]).replace(/;$/, ';?'); // semicolon is inserted if the function ends with a comment.replace(/\s+/g, '\\s+');
re = new RegExp('function' + name + '\\s*\\(\\s*' + args + '\\s*\\)\\s*{\\s*' + body + '\\s*}');
}
// look for a normal function definition
if ((result = findSourceInUrls(re, urls))) {
return result;
}
// look for an old-school event handler function
if ((parts = eventRE.exec(code))) {
var event = parts[1];
body = escapeCodeAsRegExpForMatchingInsideHTML(parts[2]);
// look for a function defined in HTML as an onXXX handler
re = new RegExp('on' + event + '=[\\\'"]\\s*' + body + '\\s*[\\\'"]', 'i');
if ((result = findSourceInUrls(re, urls[0]))) {
return result;
}
// look for ???
re = new RegExp(body);
if ((result = findSourceInUrls(re, urls))) {
return result;
}
}
return null;
}
|
javascript
|
function findSourceByFunctionBody(func) {
if (_isUndefined(window && window.document)) {
return;
}
var urls = [window.location.href],
scripts = window.document.getElementsByTagName('script'),
body,
code = '' + func,
codeRE = /^function(?:\s+([\w$]+))?\s*\(([\w\s,]*)\)\s*\{\s*(\S[\s\S]*\S)\s*\}\s*$/,
eventRE = /^function on([\w$]+)\s*\(event\)\s*\{\s*(\S[\s\S]*\S)\s*\}\s*$/,
re,
parts,
result;
for (var i = 0; i < scripts.length; ++i) {
var script = scripts[i];
if (script.src) {
urls.push(script.src);
}
}
if (!(parts = codeRE.exec(code))) {
re = new RegExp(escapeRegExp(code).replace(/\s+/g, '\\s+'));
}
// not sure if this is really necessary, but I don’t have a test
// corpus large enough to confirm that and it was in the original.
else {
var name = parts[1] ? '\\s+' + parts[1] : '',
args = parts[2].split(',').join('\\s*,\\s*');
body = escapeRegExp(parts[3]).replace(/;$/, ';?'); // semicolon is inserted if the function ends with a comment.replace(/\s+/g, '\\s+');
re = new RegExp('function' + name + '\\s*\\(\\s*' + args + '\\s*\\)\\s*{\\s*' + body + '\\s*}');
}
// look for a normal function definition
if ((result = findSourceInUrls(re, urls))) {
return result;
}
// look for an old-school event handler function
if ((parts = eventRE.exec(code))) {
var event = parts[1];
body = escapeCodeAsRegExpForMatchingInsideHTML(parts[2]);
// look for a function defined in HTML as an onXXX handler
re = new RegExp('on' + event + '=[\\\'"]\\s*' + body + '\\s*[\\\'"]', 'i');
if ((result = findSourceInUrls(re, urls[0]))) {
return result;
}
// look for ???
re = new RegExp(body);
if ((result = findSourceInUrls(re, urls))) {
return result;
}
}
return null;
}
|
[
"function",
"findSourceByFunctionBody",
"(",
"func",
")",
"{",
"if",
"(",
"_isUndefined",
"(",
"window",
"&&",
"window",
".",
"document",
")",
")",
"{",
"return",
";",
"}",
"var",
"urls",
"=",
"[",
"window",
".",
"location",
".",
"href",
"]",
",",
"scripts",
"=",
"window",
".",
"document",
".",
"getElementsByTagName",
"(",
"'script'",
")",
",",
"body",
",",
"code",
"=",
"''",
"+",
"func",
",",
"codeRE",
"=",
"/",
"^function(?:\\s+([\\w$]+))?\\s*\\(([\\w\\s,]*)\\)\\s*\\{\\s*(\\S[\\s\\S]*\\S)\\s*\\}\\s*$",
"/",
",",
"eventRE",
"=",
"/",
"^function on([\\w$]+)\\s*\\(event\\)\\s*\\{\\s*(\\S[\\s\\S]*\\S)\\s*\\}\\s*$",
"/",
",",
"re",
",",
"parts",
",",
"result",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"scripts",
".",
"length",
";",
"++",
"i",
")",
"{",
"var",
"script",
"=",
"scripts",
"[",
"i",
"]",
";",
"if",
"(",
"script",
".",
"src",
")",
"{",
"urls",
".",
"push",
"(",
"script",
".",
"src",
")",
";",
"}",
"}",
"if",
"(",
"!",
"(",
"parts",
"=",
"codeRE",
".",
"exec",
"(",
"code",
")",
")",
")",
"{",
"re",
"=",
"new",
"RegExp",
"(",
"escapeRegExp",
"(",
"code",
")",
".",
"replace",
"(",
"/",
"\\s+",
"/",
"g",
",",
"'\\\\s+'",
")",
")",
";",
"}",
"else",
"\\\\",
"{",
"var",
"name",
"=",
"parts",
"[",
"1",
"]",
"?",
"'\\\\s+'",
"+",
"\\\\",
":",
"parts",
"[",
"1",
"]",
",",
"''",
";",
"args",
"=",
"parts",
"[",
"2",
"]",
".",
"split",
"(",
"','",
")",
".",
"join",
"(",
"'\\\\s*,\\\\s*'",
")",
"\\\\",
"}",
"\\\\",
"body",
"=",
"escapeRegExp",
"(",
"parts",
"[",
"3",
"]",
")",
".",
"replace",
"(",
"/",
";$",
"/",
",",
"';?'",
")",
";",
"}"
] |
Determines where a function was defined within the source code.
@param {(Function|string)} func A function reference or serialized
function definition.
@return {?Object.<string, (string|number)>} An object containing
the url, line, and column number of the defined function.
@memberof TraceKit.computeStackTrace
|
[
"Determines",
"where",
"a",
"function",
"was",
"defined",
"within",
"the",
"source",
"code",
"."
] |
02711d099660a6d51a107b69a6e1c2aa68c9c559
|
https://github.com/exceptionless/Exceptionless.JavaScript/blob/02711d099660a6d51a107b69a6e1c2aa68c9c559/dist/exceptionless.universal.js#L608-L670
|
train
|
exceptionless/Exceptionless.JavaScript
|
dist/exceptionless.universal.js
|
computeStackTraceFromStacktraceProp
|
function computeStackTraceFromStacktraceProp(ex) {
// Access and store the stacktrace property before doing ANYTHING
// else to it because Opera is not very good at providing it
// reliably in other circumstances.
var stacktrace = ex.stacktrace;
if (!stacktrace) {
return;
}
var opera10Regex = / line (\d+).*script (?:in )?(\S+)(?:: in function (\S+))?$/i,
opera11Regex = / line (\d+), column (\d+)\s*(?:in (?:<anonymous function: ([^>]+)>|([^\)]+))\((.*)\))? in (.*):\s*$/i,
lines = stacktrace.split('\n'),
stack = [],
parts;
for (var line = 0; line < lines.length; line += 2) {
var element = null;
if ((parts = opera10Regex.exec(lines[line]))) {
element = {
'url': parts[2],
'line': +parts[1],
'column': null,
'func': parts[3],
'args':[]
};
} else if ((parts = opera11Regex.exec(lines[line]))) {
element = {
'url': parts[6],
'line': +parts[1],
'column': +parts[2],
'func': parts[3] || parts[4],
'args': parts[5] ? parts[5].split(',') : []
};
}
if (element) {
if (!element.func && element.line) {
element.func = guessFunctionName(element.url, element.line);
}
if (element.line) {
try {
element.context = gatherContext(element.url, element.line);
} catch (exc) {}
}
if (!element.context) {
element.context = [lines[line + 1]];
}
stack.push(element);
}
}
if (!stack.length) {
return null;
}
return {
'mode': 'stacktrace',
'name': ex.name,
'message': ex.message,
'stack': stack
};
}
|
javascript
|
function computeStackTraceFromStacktraceProp(ex) {
// Access and store the stacktrace property before doing ANYTHING
// else to it because Opera is not very good at providing it
// reliably in other circumstances.
var stacktrace = ex.stacktrace;
if (!stacktrace) {
return;
}
var opera10Regex = / line (\d+).*script (?:in )?(\S+)(?:: in function (\S+))?$/i,
opera11Regex = / line (\d+), column (\d+)\s*(?:in (?:<anonymous function: ([^>]+)>|([^\)]+))\((.*)\))? in (.*):\s*$/i,
lines = stacktrace.split('\n'),
stack = [],
parts;
for (var line = 0; line < lines.length; line += 2) {
var element = null;
if ((parts = opera10Regex.exec(lines[line]))) {
element = {
'url': parts[2],
'line': +parts[1],
'column': null,
'func': parts[3],
'args':[]
};
} else if ((parts = opera11Regex.exec(lines[line]))) {
element = {
'url': parts[6],
'line': +parts[1],
'column': +parts[2],
'func': parts[3] || parts[4],
'args': parts[5] ? parts[5].split(',') : []
};
}
if (element) {
if (!element.func && element.line) {
element.func = guessFunctionName(element.url, element.line);
}
if (element.line) {
try {
element.context = gatherContext(element.url, element.line);
} catch (exc) {}
}
if (!element.context) {
element.context = [lines[line + 1]];
}
stack.push(element);
}
}
if (!stack.length) {
return null;
}
return {
'mode': 'stacktrace',
'name': ex.name,
'message': ex.message,
'stack': stack
};
}
|
[
"function",
"computeStackTraceFromStacktraceProp",
"(",
"ex",
")",
"{",
"var",
"stacktrace",
"=",
"ex",
".",
"stacktrace",
";",
"if",
"(",
"!",
"stacktrace",
")",
"{",
"return",
";",
"}",
"var",
"opera10Regex",
"=",
"/",
" line (\\d+).*script (?:in )?(\\S+)(?:: in function (\\S+))?$",
"/",
"i",
",",
"opera11Regex",
"=",
"/",
" line (\\d+), column (\\d+)\\s*(?:in (?:<anonymous function: ([^>]+)>|([^\\)]+))\\((.*)\\))? in (.*):\\s*$",
"/",
"i",
",",
"lines",
"=",
"stacktrace",
".",
"split",
"(",
"'\\n'",
")",
",",
"\\n",
",",
"stack",
"=",
"[",
"]",
";",
"parts",
"for",
"(",
"var",
"line",
"=",
"0",
";",
"line",
"<",
"lines",
".",
"length",
";",
"line",
"+=",
"2",
")",
"{",
"var",
"element",
"=",
"null",
";",
"if",
"(",
"(",
"parts",
"=",
"opera10Regex",
".",
"exec",
"(",
"lines",
"[",
"line",
"]",
")",
")",
")",
"{",
"element",
"=",
"{",
"'url'",
":",
"parts",
"[",
"2",
"]",
",",
"'line'",
":",
"+",
"parts",
"[",
"1",
"]",
",",
"'column'",
":",
"null",
",",
"'func'",
":",
"parts",
"[",
"3",
"]",
",",
"'args'",
":",
"[",
"]",
"}",
";",
"}",
"else",
"if",
"(",
"(",
"parts",
"=",
"opera11Regex",
".",
"exec",
"(",
"lines",
"[",
"line",
"]",
")",
")",
")",
"{",
"element",
"=",
"{",
"'url'",
":",
"parts",
"[",
"6",
"]",
",",
"'line'",
":",
"+",
"parts",
"[",
"1",
"]",
",",
"'column'",
":",
"+",
"parts",
"[",
"2",
"]",
",",
"'func'",
":",
"parts",
"[",
"3",
"]",
"||",
"parts",
"[",
"4",
"]",
",",
"'args'",
":",
"parts",
"[",
"5",
"]",
"?",
"parts",
"[",
"5",
"]",
".",
"split",
"(",
"','",
")",
":",
"[",
"]",
"}",
";",
"}",
"if",
"(",
"element",
")",
"{",
"if",
"(",
"!",
"element",
".",
"func",
"&&",
"element",
".",
"line",
")",
"{",
"element",
".",
"func",
"=",
"guessFunctionName",
"(",
"element",
".",
"url",
",",
"element",
".",
"line",
")",
";",
"}",
"if",
"(",
"element",
".",
"line",
")",
"{",
"try",
"{",
"element",
".",
"context",
"=",
"gatherContext",
"(",
"element",
".",
"url",
",",
"element",
".",
"line",
")",
";",
"}",
"catch",
"(",
"exc",
")",
"{",
"}",
"}",
"if",
"(",
"!",
"element",
".",
"context",
")",
"{",
"element",
".",
"context",
"=",
"[",
"lines",
"[",
"line",
"+",
"1",
"]",
"]",
";",
"}",
"stack",
".",
"push",
"(",
"element",
")",
";",
"}",
"}",
"if",
"(",
"!",
"stack",
".",
"length",
")",
"{",
"return",
"null",
";",
"}",
"}"
] |
Computes stack trace information from the stacktrace property.
Opera 10+ uses this property.
@param {Error} ex
@return {?TraceKit.StackTrace} Stack trace information.
@memberof TraceKit.computeStackTrace
|
[
"Computes",
"stack",
"trace",
"information",
"from",
"the",
"stacktrace",
"property",
".",
"Opera",
"10",
"+",
"uses",
"this",
"property",
"."
] |
02711d099660a6d51a107b69a6e1c2aa68c9c559
|
https://github.com/exceptionless/Exceptionless.JavaScript/blob/02711d099660a6d51a107b69a6e1c2aa68c9c559/dist/exceptionless.universal.js#L818-L881
|
train
|
marionettejs/backbone.radio
|
src/backbone.radio.js
|
callHandler
|
function callHandler(callback, context, args) {
switch (args.length) {
case 0: return callback.call(context);
case 1: return callback.call(context, args[0]);
case 2: return callback.call(context, args[0], args[1]);
case 3: return callback.call(context, args[0], args[1], args[2]);
default: return callback.apply(context, args);
}
}
|
javascript
|
function callHandler(callback, context, args) {
switch (args.length) {
case 0: return callback.call(context);
case 1: return callback.call(context, args[0]);
case 2: return callback.call(context, args[0], args[1]);
case 3: return callback.call(context, args[0], args[1], args[2]);
default: return callback.apply(context, args);
}
}
|
[
"function",
"callHandler",
"(",
"callback",
",",
"context",
",",
"args",
")",
"{",
"switch",
"(",
"args",
".",
"length",
")",
"{",
"case",
"0",
":",
"return",
"callback",
".",
"call",
"(",
"context",
")",
";",
"case",
"1",
":",
"return",
"callback",
".",
"call",
"(",
"context",
",",
"args",
"[",
"0",
"]",
")",
";",
"case",
"2",
":",
"return",
"callback",
".",
"call",
"(",
"context",
",",
"args",
"[",
"0",
"]",
",",
"args",
"[",
"1",
"]",
")",
";",
"case",
"3",
":",
"return",
"callback",
".",
"call",
"(",
"context",
",",
"args",
"[",
"0",
"]",
",",
"args",
"[",
"1",
"]",
",",
"args",
"[",
"2",
"]",
")",
";",
"default",
":",
"return",
"callback",
".",
"apply",
"(",
"context",
",",
"args",
")",
";",
"}",
"}"
] |
An optimized way to execute callbacks.
|
[
"An",
"optimized",
"way",
"to",
"execute",
"callbacks",
"."
] |
7a58ade84bedb5551c2e12bdd3434d0fd6b1bdbd
|
https://github.com/marionettejs/backbone.radio/blob/7a58ade84bedb5551c2e12bdd3434d0fd6b1bdbd/src/backbone.radio.js#L74-L82
|
train
|
marionettejs/backbone.radio
|
src/backbone.radio.js
|
removeHandler
|
function removeHandler(store, name, callback, context) {
var event = store[name];
if (
(!callback || (callback === event.callback || callback === event.callback._callback)) &&
(!context || (context === event.context))
) {
delete store[name];
return true;
}
}
|
javascript
|
function removeHandler(store, name, callback, context) {
var event = store[name];
if (
(!callback || (callback === event.callback || callback === event.callback._callback)) &&
(!context || (context === event.context))
) {
delete store[name];
return true;
}
}
|
[
"function",
"removeHandler",
"(",
"store",
",",
"name",
",",
"callback",
",",
"context",
")",
"{",
"var",
"event",
"=",
"store",
"[",
"name",
"]",
";",
"if",
"(",
"(",
"!",
"callback",
"||",
"(",
"callback",
"===",
"event",
".",
"callback",
"||",
"callback",
"===",
"event",
".",
"callback",
".",
"_callback",
")",
")",
"&&",
"(",
"!",
"context",
"||",
"(",
"context",
"===",
"event",
".",
"context",
")",
")",
")",
"{",
"delete",
"store",
"[",
"name",
"]",
";",
"return",
"true",
";",
"}",
"}"
] |
A helper used by `off` methods to the handler from the store
|
[
"A",
"helper",
"used",
"by",
"off",
"methods",
"to",
"the",
"handler",
"from",
"the",
"store"
] |
7a58ade84bedb5551c2e12bdd3434d0fd6b1bdbd
|
https://github.com/marionettejs/backbone.radio/blob/7a58ade84bedb5551c2e12bdd3434d0fd6b1bdbd/src/backbone.radio.js#L85-L94
|
train
|
marionettejs/backbone.radio
|
src/backbone.radio.js
|
_partial
|
function _partial(channelName) {
return _logs[channelName] || (_logs[channelName] = Radio.log.bind(Radio, channelName));
}
|
javascript
|
function _partial(channelName) {
return _logs[channelName] || (_logs[channelName] = Radio.log.bind(Radio, channelName));
}
|
[
"function",
"_partial",
"(",
"channelName",
")",
"{",
"return",
"_logs",
"[",
"channelName",
"]",
"||",
"(",
"_logs",
"[",
"channelName",
"]",
"=",
"Radio",
".",
"log",
".",
"bind",
"(",
"Radio",
",",
"channelName",
")",
")",
";",
"}"
] |
This is to produce an identical function in both tuneIn and tuneOut, so that Backbone.Events unregisters it.
|
[
"This",
"is",
"to",
"produce",
"an",
"identical",
"function",
"in",
"both",
"tuneIn",
"and",
"tuneOut",
"so",
"that",
"Backbone",
".",
"Events",
"unregisters",
"it",
"."
] |
7a58ade84bedb5551c2e12bdd3434d0fd6b1bdbd
|
https://github.com/marionettejs/backbone.radio/blob/7a58ade84bedb5551c2e12bdd3434d0fd6b1bdbd/src/backbone.radio.js#L129-L131
|
train
|
marionettejs/backbone.radio
|
src/backbone.radio.js
|
function(channelName, eventName) {
if (typeof console === 'undefined') { return; }
var args = _.toArray(arguments).slice(2);
console.log('[' + channelName + '] "' + eventName + '"', args);
}
|
javascript
|
function(channelName, eventName) {
if (typeof console === 'undefined') { return; }
var args = _.toArray(arguments).slice(2);
console.log('[' + channelName + '] "' + eventName + '"', args);
}
|
[
"function",
"(",
"channelName",
",",
"eventName",
")",
"{",
"if",
"(",
"typeof",
"console",
"===",
"'undefined'",
")",
"{",
"return",
";",
"}",
"var",
"args",
"=",
"_",
".",
"toArray",
"(",
"arguments",
")",
".",
"slice",
"(",
"2",
")",
";",
"console",
".",
"log",
"(",
"'['",
"+",
"channelName",
"+",
"'] \"'",
"+",
"eventName",
"+",
"'\"'",
",",
"args",
")",
";",
"}"
] |
Log information about the channel and event
|
[
"Log",
"information",
"about",
"the",
"channel",
"and",
"event"
] |
7a58ade84bedb5551c2e12bdd3434d0fd6b1bdbd
|
https://github.com/marionettejs/backbone.radio/blob/7a58ade84bedb5551c2e12bdd3434d0fd6b1bdbd/src/backbone.radio.js#L136-L140
|
train
|
|
marionettejs/backbone.radio
|
src/backbone.radio.js
|
function(channelName) {
var channel = Radio.channel(channelName);
channel._tunedIn = true;
channel.on('all', _partial(channelName));
return this;
}
|
javascript
|
function(channelName) {
var channel = Radio.channel(channelName);
channel._tunedIn = true;
channel.on('all', _partial(channelName));
return this;
}
|
[
"function",
"(",
"channelName",
")",
"{",
"var",
"channel",
"=",
"Radio",
".",
"channel",
"(",
"channelName",
")",
";",
"channel",
".",
"_tunedIn",
"=",
"true",
";",
"channel",
".",
"on",
"(",
"'all'",
",",
"_partial",
"(",
"channelName",
")",
")",
";",
"return",
"this",
";",
"}"
] |
Logs all events on this channel to the console. It sets an internal value on the channel telling it we're listening, then sets a listener on the Backbone.Events
|
[
"Logs",
"all",
"events",
"on",
"this",
"channel",
"to",
"the",
"console",
".",
"It",
"sets",
"an",
"internal",
"value",
"on",
"the",
"channel",
"telling",
"it",
"we",
"re",
"listening",
"then",
"sets",
"a",
"listener",
"on",
"the",
"Backbone",
".",
"Events"
] |
7a58ade84bedb5551c2e12bdd3434d0fd6b1bdbd
|
https://github.com/marionettejs/backbone.radio/blob/7a58ade84bedb5551c2e12bdd3434d0fd6b1bdbd/src/backbone.radio.js#L145-L150
|
train
|
|
marionettejs/backbone.radio
|
src/backbone.radio.js
|
function(channelName) {
var channel = Radio.channel(channelName);
channel._tunedIn = false;
channel.off('all', _partial(channelName));
delete _logs[channelName];
return this;
}
|
javascript
|
function(channelName) {
var channel = Radio.channel(channelName);
channel._tunedIn = false;
channel.off('all', _partial(channelName));
delete _logs[channelName];
return this;
}
|
[
"function",
"(",
"channelName",
")",
"{",
"var",
"channel",
"=",
"Radio",
".",
"channel",
"(",
"channelName",
")",
";",
"channel",
".",
"_tunedIn",
"=",
"false",
";",
"channel",
".",
"off",
"(",
"'all'",
",",
"_partial",
"(",
"channelName",
")",
")",
";",
"delete",
"_logs",
"[",
"channelName",
"]",
";",
"return",
"this",
";",
"}"
] |
Stop logging all of the activities on this channel to the console
|
[
"Stop",
"logging",
"all",
"of",
"the",
"activities",
"on",
"this",
"channel",
"to",
"the",
"console"
] |
7a58ade84bedb5551c2e12bdd3434d0fd6b1bdbd
|
https://github.com/marionettejs/backbone.radio/blob/7a58ade84bedb5551c2e12bdd3434d0fd6b1bdbd/src/backbone.radio.js#L153-L159
|
train
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.