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 |
---|---|---|---|---|---|---|---|---|---|---|---|
massgov/mayflower
|
patternlab/styleguide/public/styleguide/js/patternlab-viewer.js
|
function() {
var obj;
// not that the modal viewer is no longer active
DataSaver.updateValue('modalActive', 'false');
modalViewer.active = false;
//Add active class to modal
$('#sg-modal-container').removeClass('active');
// remove the active class from all of the checkbox items
$('.sg-checkbox').removeClass('active');
// hide the modal
modalViewer.hide();
// update the wording
$('#sg-t-patterninfo').html("Show Pattern Info");
// tell the styleguide to close
obj = JSON.stringify({ 'event': 'patternLab.patternModalClose' });
document.getElementById('sg-viewport').contentWindow.postMessage(obj, modalViewer.targetOrigin);
}
|
javascript
|
function() {
var obj;
// not that the modal viewer is no longer active
DataSaver.updateValue('modalActive', 'false');
modalViewer.active = false;
//Add active class to modal
$('#sg-modal-container').removeClass('active');
// remove the active class from all of the checkbox items
$('.sg-checkbox').removeClass('active');
// hide the modal
modalViewer.hide();
// update the wording
$('#sg-t-patterninfo').html("Show Pattern Info");
// tell the styleguide to close
obj = JSON.stringify({ 'event': 'patternLab.patternModalClose' });
document.getElementById('sg-viewport').contentWindow.postMessage(obj, modalViewer.targetOrigin);
}
|
[
"function",
"(",
")",
"{",
"var",
"obj",
";",
"DataSaver",
".",
"updateValue",
"(",
"'modalActive'",
",",
"'false'",
")",
";",
"modalViewer",
".",
"active",
"=",
"false",
";",
"$",
"(",
"'#sg-modal-container'",
")",
".",
"removeClass",
"(",
"'active'",
")",
";",
"$",
"(",
"'.sg-checkbox'",
")",
".",
"removeClass",
"(",
"'active'",
")",
";",
"modalViewer",
".",
"hide",
"(",
")",
";",
"$",
"(",
"'#sg-t-patterninfo'",
")",
".",
"html",
"(",
"\"Show Pattern Info\"",
")",
";",
"obj",
"=",
"JSON",
".",
"stringify",
"(",
"{",
"'event'",
":",
"'patternLab.patternModalClose'",
"}",
")",
";",
"document",
".",
"getElementById",
"(",
"'sg-viewport'",
")",
".",
"contentWindow",
".",
"postMessage",
"(",
"obj",
",",
"modalViewer",
".",
"targetOrigin",
")",
";",
"}"
] |
close the modal window
|
[
"close",
"the",
"modal",
"window"
] |
6ae90009c5d611f9fdbcc208f9bd5f1e22926094
|
https://github.com/massgov/mayflower/blob/6ae90009c5d611f9fdbcc208f9bd5f1e22926094/patternlab/styleguide/public/styleguide/js/patternlab-viewer.js#L515-L539
|
train
|
|
massgov/mayflower
|
patternlab/styleguide/public/styleguide/js/patternlab-viewer.js
|
function(patternData, iframePassback, switchText) {
// if this is a styleguide view close the modal
if (iframePassback) {
modalViewer.hide();
}
// gather the data that will fill the modal window
panelsViewer.gatherPanels(patternData, iframePassback, switchText);
}
|
javascript
|
function(patternData, iframePassback, switchText) {
// if this is a styleguide view close the modal
if (iframePassback) {
modalViewer.hide();
}
// gather the data that will fill the modal window
panelsViewer.gatherPanels(patternData, iframePassback, switchText);
}
|
[
"function",
"(",
"patternData",
",",
"iframePassback",
",",
"switchText",
")",
"{",
"if",
"(",
"iframePassback",
")",
"{",
"modalViewer",
".",
"hide",
"(",
")",
";",
"}",
"panelsViewer",
".",
"gatherPanels",
"(",
"patternData",
",",
"iframePassback",
",",
"switchText",
")",
";",
"}"
] |
refresh the modal if a new pattern is loaded and the modal is active
@param {Object} the patternData sent back from the query
@param {Boolean} if the refresh is of a view-all view and the content should be sent back
@param {Boolean} if the text in the dropdown should be switched
|
[
"refresh",
"the",
"modal",
"if",
"a",
"new",
"pattern",
"is",
"loaded",
"and",
"the",
"modal",
"is",
"active"
] |
6ae90009c5d611f9fdbcc208f9bd5f1e22926094
|
https://github.com/massgov/mayflower/blob/6ae90009c5d611f9fdbcc208f9bd5f1e22926094/patternlab/styleguide/public/styleguide/js/patternlab-viewer.js#L584-L594
|
train
|
|
massgov/mayflower
|
patternlab/styleguide/public/styleguide/js/patternlab-viewer.js
|
function(pos) {
// remove active class
els = document.querySelectorAll('#sg-annotations > .sg-annotations-list > li');
for (i = 0; i < els.length; ++i) {
els[i].classList.remove('active');
}
// add active class to called element and scroll to it
for (i = 0; i < els.length; ++i) {
if ((i+1) == pos) {
els[i].classList.add('active');
$('.sg-pattern-extra-info').animate({scrollTop: els[i].offsetTop - 10}, 600);
}
}
}
|
javascript
|
function(pos) {
// remove active class
els = document.querySelectorAll('#sg-annotations > .sg-annotations-list > li');
for (i = 0; i < els.length; ++i) {
els[i].classList.remove('active');
}
// add active class to called element and scroll to it
for (i = 0; i < els.length; ++i) {
if ((i+1) == pos) {
els[i].classList.add('active');
$('.sg-pattern-extra-info').animate({scrollTop: els[i].offsetTop - 10}, 600);
}
}
}
|
[
"function",
"(",
"pos",
")",
"{",
"els",
"=",
"document",
".",
"querySelectorAll",
"(",
"'#sg-annotations > .sg-annotations-list > li'",
")",
";",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"els",
".",
"length",
";",
"++",
"i",
")",
"{",
"els",
"[",
"i",
"]",
".",
"classList",
".",
"remove",
"(",
"'active'",
")",
";",
"}",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"els",
".",
"length",
";",
"++",
"i",
")",
"{",
"if",
"(",
"(",
"i",
"+",
"1",
")",
"==",
"pos",
")",
"{",
"els",
"[",
"i",
"]",
".",
"classList",
".",
"add",
"(",
"'active'",
")",
";",
"$",
"(",
"'.sg-pattern-extra-info'",
")",
".",
"animate",
"(",
"{",
"scrollTop",
":",
"els",
"[",
"i",
"]",
".",
"offsetTop",
"-",
"10",
"}",
",",
"600",
")",
";",
"}",
"}",
"}"
] |
slides the modal window to a particular annotation
@param {Integer} the number for the element that should be highlighted
|
[
"slides",
"the",
"modal",
"window",
"to",
"a",
"particular",
"annotation"
] |
6ae90009c5d611f9fdbcc208f9bd5f1e22926094
|
https://github.com/massgov/mayflower/blob/6ae90009c5d611f9fdbcc208f9bd5f1e22926094/patternlab/styleguide/public/styleguide/js/patternlab-viewer.js#L609-L625
|
train
|
|
massgov/mayflower
|
patternlab/styleguide/public/styleguide/js/patternlab-viewer.js
|
function(switchText) {
// note that the modal is active and set switchText
if ((switchText === undefined) || (switchText)) {
switchText = true;
DataSaver.updateValue('modalActive', 'true');
modalViewer.active = true;
}
// send a message to the pattern
var obj = JSON.stringify({ 'event': 'patternLab.patternQuery', 'switchText': switchText });
document.getElementById('sg-viewport').contentWindow.postMessage(obj, modalViewer.targetOrigin);
}
|
javascript
|
function(switchText) {
// note that the modal is active and set switchText
if ((switchText === undefined) || (switchText)) {
switchText = true;
DataSaver.updateValue('modalActive', 'true');
modalViewer.active = true;
}
// send a message to the pattern
var obj = JSON.stringify({ 'event': 'patternLab.patternQuery', 'switchText': switchText });
document.getElementById('sg-viewport').contentWindow.postMessage(obj, modalViewer.targetOrigin);
}
|
[
"function",
"(",
"switchText",
")",
"{",
"if",
"(",
"(",
"switchText",
"===",
"undefined",
")",
"||",
"(",
"switchText",
")",
")",
"{",
"switchText",
"=",
"true",
";",
"DataSaver",
".",
"updateValue",
"(",
"'modalActive'",
",",
"'true'",
")",
";",
"modalViewer",
".",
"active",
"=",
"true",
";",
"}",
"var",
"obj",
"=",
"JSON",
".",
"stringify",
"(",
"{",
"'event'",
":",
"'patternLab.patternQuery'",
",",
"'switchText'",
":",
"switchText",
"}",
")",
";",
"document",
".",
"getElementById",
"(",
"'sg-viewport'",
")",
".",
"contentWindow",
".",
"postMessage",
"(",
"obj",
",",
"modalViewer",
".",
"targetOrigin",
")",
";",
"}"
] |
ask the pattern for info so we can open the modal window and populate it
@param {Boolean} if the dropdown text should be changed
|
[
"ask",
"the",
"pattern",
"for",
"info",
"so",
"we",
"can",
"open",
"the",
"modal",
"window",
"and",
"populate",
"it"
] |
6ae90009c5d611f9fdbcc208f9bd5f1e22926094
|
https://github.com/massgov/mayflower/blob/6ae90009c5d611f9fdbcc208f9bd5f1e22926094/patternlab/styleguide/public/styleguide/js/patternlab-viewer.js#L638-L651
|
train
|
|
massgov/mayflower
|
patternlab/styleguide/public/styleguide/js/patternlab-viewer.js
|
function(templateRendered, patternPartial) {
var els = templateRendered.querySelectorAll('#sg-'+patternPartial+'-tabs li');
for (var i = 0; i < els.length; ++i) {
els[i].onclick = function(e) {
e.preventDefault();
var patternPartial = this.getAttribute('data-patternpartial');
var panelID = this.getAttribute('data-panelid');
panelsUtil.show(patternPartial, panelID);
};
}
return templateRendered;
}
|
javascript
|
function(templateRendered, patternPartial) {
var els = templateRendered.querySelectorAll('#sg-'+patternPartial+'-tabs li');
for (var i = 0; i < els.length; ++i) {
els[i].onclick = function(e) {
e.preventDefault();
var patternPartial = this.getAttribute('data-patternpartial');
var panelID = this.getAttribute('data-panelid');
panelsUtil.show(patternPartial, panelID);
};
}
return templateRendered;
}
|
[
"function",
"(",
"templateRendered",
",",
"patternPartial",
")",
"{",
"var",
"els",
"=",
"templateRendered",
".",
"querySelectorAll",
"(",
"'#sg-'",
"+",
"patternPartial",
"+",
"'-tabs li'",
")",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"els",
".",
"length",
";",
"++",
"i",
")",
"{",
"els",
"[",
"i",
"]",
".",
"onclick",
"=",
"function",
"(",
"e",
")",
"{",
"e",
".",
"preventDefault",
"(",
")",
";",
"var",
"patternPartial",
"=",
"this",
".",
"getAttribute",
"(",
"'data-patternpartial'",
")",
";",
"var",
"panelID",
"=",
"this",
".",
"getAttribute",
"(",
"'data-panelid'",
")",
";",
"panelsUtil",
".",
"show",
"(",
"patternPartial",
",",
"panelID",
")",
";",
"}",
";",
"}",
"return",
"templateRendered",
";",
"}"
] |
Add click events to the template that was rendered
@param {String} the rendered template for the modal
@param {String} the pattern partial for the modal
|
[
"Add",
"click",
"events",
"to",
"the",
"template",
"that",
"was",
"rendered"
] |
6ae90009c5d611f9fdbcc208f9bd5f1e22926094
|
https://github.com/massgov/mayflower/blob/6ae90009c5d611f9fdbcc208f9bd5f1e22926094/patternlab/styleguide/public/styleguide/js/patternlab-viewer.js#L718-L732
|
train
|
|
massgov/mayflower
|
patternlab/styleguide/public/styleguide/js/patternlab-viewer.js
|
function(panels, patternData, iframePassback, switchText) {
// count how many panels have rendered content
var panelContentCount = 0;
for (var i = 0; i < panels.length; ++i) {
if (panels[i].content !== undefined) {
panelContentCount++;
}
}
// see if the count of panels with content matches number of panels
if (panelContentCount === Panels.count()) {
panelsViewer.renderPanels(panels, patternData, iframePassback, switchText);
}
}
|
javascript
|
function(panels, patternData, iframePassback, switchText) {
// count how many panels have rendered content
var panelContentCount = 0;
for (var i = 0; i < panels.length; ++i) {
if (panels[i].content !== undefined) {
panelContentCount++;
}
}
// see if the count of panels with content matches number of panels
if (panelContentCount === Panels.count()) {
panelsViewer.renderPanels(panels, patternData, iframePassback, switchText);
}
}
|
[
"function",
"(",
"panels",
",",
"patternData",
",",
"iframePassback",
",",
"switchText",
")",
"{",
"var",
"panelContentCount",
"=",
"0",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"panels",
".",
"length",
";",
"++",
"i",
")",
"{",
"if",
"(",
"panels",
"[",
"i",
"]",
".",
"content",
"!==",
"undefined",
")",
"{",
"panelContentCount",
"++",
";",
"}",
"}",
"if",
"(",
"panelContentCount",
"===",
"Panels",
".",
"count",
"(",
")",
")",
"{",
"panelsViewer",
".",
"renderPanels",
"(",
"panels",
",",
"patternData",
",",
"iframePassback",
",",
"switchText",
")",
";",
"}",
"}"
] |
Check to see if all of the panels have been collected before rendering
@param {String} the collected panels
@param {String} the data from the pattern
@param {Boolean} if this is going to be passed back to the styleguide
|
[
"Check",
"to",
"see",
"if",
"all",
"of",
"the",
"panels",
"have",
"been",
"collected",
"before",
"rendering"
] |
6ae90009c5d611f9fdbcc208f9bd5f1e22926094
|
https://github.com/massgov/mayflower/blob/6ae90009c5d611f9fdbcc208f9bd5f1e22926094/patternlab/styleguide/public/styleguide/js/patternlab-viewer.js#L888-L903
|
train
|
|
massgov/mayflower
|
patternlab/styleguide/public/styleguide/js/patternlab-viewer.js
|
sizeiframe
|
function sizeiframe(size,animate) {
var theSize;
if(size>maxViewportWidth) { //If the entered size is larger than the max allowed viewport size, cap value at max vp size
theSize = maxViewportWidth;
} else if(size<minViewportWidth) { //If the entered size is less than the minimum allowed viewport size, cap value at min vp size
theSize = minViewportWidth;
} else {
theSize = size;
}
//Conditionally remove CSS animation class from viewport
if(animate===false) {
$('#sg-gen-container,#sg-viewport').removeClass("vp-animate"); //If aninate is set to false, remove animate class from viewport
} else {
$('#sg-gen-container,#sg-viewport').addClass("vp-animate");
}
$('#sg-gen-container').width(theSize+viewportResizeHandleWidth); //Resize viewport wrapper to desired size + size of drag resize handler
$sgViewport.width(theSize); //Resize viewport to desired size
var targetOrigin = (window.location.protocol === "file:") ? "*" : window.location.protocol+"//"+window.location.host;
var obj = JSON.stringify({ "event": "patternLab.resize", "resize": "true" });
document.getElementById('sg-viewport').contentWindow.postMessage(obj,targetOrigin);
updateSizeReading(theSize); //Update values in toolbar
saveSize(theSize); //Save current viewport to cookie
}
|
javascript
|
function sizeiframe(size,animate) {
var theSize;
if(size>maxViewportWidth) { //If the entered size is larger than the max allowed viewport size, cap value at max vp size
theSize = maxViewportWidth;
} else if(size<minViewportWidth) { //If the entered size is less than the minimum allowed viewport size, cap value at min vp size
theSize = minViewportWidth;
} else {
theSize = size;
}
//Conditionally remove CSS animation class from viewport
if(animate===false) {
$('#sg-gen-container,#sg-viewport').removeClass("vp-animate"); //If aninate is set to false, remove animate class from viewport
} else {
$('#sg-gen-container,#sg-viewport').addClass("vp-animate");
}
$('#sg-gen-container').width(theSize+viewportResizeHandleWidth); //Resize viewport wrapper to desired size + size of drag resize handler
$sgViewport.width(theSize); //Resize viewport to desired size
var targetOrigin = (window.location.protocol === "file:") ? "*" : window.location.protocol+"//"+window.location.host;
var obj = JSON.stringify({ "event": "patternLab.resize", "resize": "true" });
document.getElementById('sg-viewport').contentWindow.postMessage(obj,targetOrigin);
updateSizeReading(theSize); //Update values in toolbar
saveSize(theSize); //Save current viewport to cookie
}
|
[
"function",
"sizeiframe",
"(",
"size",
",",
"animate",
")",
"{",
"var",
"theSize",
";",
"if",
"(",
"size",
">",
"maxViewportWidth",
")",
"{",
"theSize",
"=",
"maxViewportWidth",
";",
"}",
"else",
"if",
"(",
"size",
"<",
"minViewportWidth",
")",
"{",
"theSize",
"=",
"minViewportWidth",
";",
"}",
"else",
"{",
"theSize",
"=",
"size",
";",
"}",
"if",
"(",
"animate",
"===",
"false",
")",
"{",
"$",
"(",
"'#sg-gen-container,#sg-viewport'",
")",
".",
"removeClass",
"(",
"\"vp-animate\"",
")",
";",
"}",
"else",
"{",
"$",
"(",
"'#sg-gen-container,#sg-viewport'",
")",
".",
"addClass",
"(",
"\"vp-animate\"",
")",
";",
"}",
"$",
"(",
"'#sg-gen-container'",
")",
".",
"width",
"(",
"theSize",
"+",
"viewportResizeHandleWidth",
")",
";",
"$sgViewport",
".",
"width",
"(",
"theSize",
")",
";",
"var",
"targetOrigin",
"=",
"(",
"window",
".",
"location",
".",
"protocol",
"===",
"\"file:\"",
")",
"?",
"\"*\"",
":",
"window",
".",
"location",
".",
"protocol",
"+",
"\"//\"",
"+",
"window",
".",
"location",
".",
"host",
";",
"var",
"obj",
"=",
"JSON",
".",
"stringify",
"(",
"{",
"\"event\"",
":",
"\"patternLab.resize\"",
",",
"\"resize\"",
":",
"\"true\"",
"}",
")",
";",
"document",
".",
"getElementById",
"(",
"'sg-viewport'",
")",
".",
"contentWindow",
".",
"postMessage",
"(",
"obj",
",",
"targetOrigin",
")",
";",
"updateSizeReading",
"(",
"theSize",
")",
";",
"saveSize",
"(",
"theSize",
")",
";",
"}"
] |
Resize the viewport 'size' is the target size of the viewport 'animate' is a boolean for switching the CSS animation on or off. 'animate' is true by default, but can be set to false for things like nudging and dragging
|
[
"Resize",
"the",
"viewport",
"size",
"is",
"the",
"target",
"size",
"of",
"the",
"viewport",
"animate",
"is",
"a",
"boolean",
"for",
"switching",
"the",
"CSS",
"animation",
"on",
"or",
"off",
".",
"animate",
"is",
"true",
"by",
"default",
"but",
"can",
"be",
"set",
"to",
"false",
"for",
"things",
"like",
"nudging",
"and",
"dragging"
] |
6ae90009c5d611f9fdbcc208f9bd5f1e22926094
|
https://github.com/massgov/mayflower/blob/6ae90009c5d611f9fdbcc208f9bd5f1e22926094/patternlab/styleguide/public/styleguide/js/patternlab-viewer.js#L1658-L1685
|
train
|
mongodb-js/collection-sample
|
lib/reservoir-sampler.js
|
reservoirStream
|
function reservoirStream(collection, size, opts) {
opts = _defaults(opts || {}, {
chunkSize: RESERVOIR_CHUNK_SIZE,
promoteValues: true
});
var reservoir = new Reservoir(size);
var stream = es.through(
function write(data) {
// fill reservoir with ids
reservoir.pushSome(data);
},
function end() {
// split the reservoir of ids into smaller chunks
var chunks = _chunk(reservoir, opts.chunkSize);
// create cursors for chunks
var cursors = chunks.map(function(ids) {
var cursor = collection.find({ _id: { $in: ids }}, { promoteValues: opts.promoteValues, raw: opts.raw });
if (opts.fields) {
cursor.project(opts.fields);
}
if (opts.maxTimeMS) {
cursor.maxTimeMS(opts.maxTimeMS);
}
return cursor.stream();
});
// merge all cursors (order arbitrary) and emit docs
es.merge(cursors).pipe(es.through(function(doc) {
stream.emit('data', doc);
})).on('end', function() {
stream.emit('end');
});
}
);
return stream;
}
|
javascript
|
function reservoirStream(collection, size, opts) {
opts = _defaults(opts || {}, {
chunkSize: RESERVOIR_CHUNK_SIZE,
promoteValues: true
});
var reservoir = new Reservoir(size);
var stream = es.through(
function write(data) {
// fill reservoir with ids
reservoir.pushSome(data);
},
function end() {
// split the reservoir of ids into smaller chunks
var chunks = _chunk(reservoir, opts.chunkSize);
// create cursors for chunks
var cursors = chunks.map(function(ids) {
var cursor = collection.find({ _id: { $in: ids }}, { promoteValues: opts.promoteValues, raw: opts.raw });
if (opts.fields) {
cursor.project(opts.fields);
}
if (opts.maxTimeMS) {
cursor.maxTimeMS(opts.maxTimeMS);
}
return cursor.stream();
});
// merge all cursors (order arbitrary) and emit docs
es.merge(cursors).pipe(es.through(function(doc) {
stream.emit('data', doc);
})).on('end', function() {
stream.emit('end');
});
}
);
return stream;
}
|
[
"function",
"reservoirStream",
"(",
"collection",
",",
"size",
",",
"opts",
")",
"{",
"opts",
"=",
"_defaults",
"(",
"opts",
"||",
"{",
"}",
",",
"{",
"chunkSize",
":",
"RESERVOIR_CHUNK_SIZE",
",",
"promoteValues",
":",
"true",
"}",
")",
";",
"var",
"reservoir",
"=",
"new",
"Reservoir",
"(",
"size",
")",
";",
"var",
"stream",
"=",
"es",
".",
"through",
"(",
"function",
"write",
"(",
"data",
")",
"{",
"reservoir",
".",
"pushSome",
"(",
"data",
")",
";",
"}",
",",
"function",
"end",
"(",
")",
"{",
"var",
"chunks",
"=",
"_chunk",
"(",
"reservoir",
",",
"opts",
".",
"chunkSize",
")",
";",
"var",
"cursors",
"=",
"chunks",
".",
"map",
"(",
"function",
"(",
"ids",
")",
"{",
"var",
"cursor",
"=",
"collection",
".",
"find",
"(",
"{",
"_id",
":",
"{",
"$in",
":",
"ids",
"}",
"}",
",",
"{",
"promoteValues",
":",
"opts",
".",
"promoteValues",
",",
"raw",
":",
"opts",
".",
"raw",
"}",
")",
";",
"if",
"(",
"opts",
".",
"fields",
")",
"{",
"cursor",
".",
"project",
"(",
"opts",
".",
"fields",
")",
";",
"}",
"if",
"(",
"opts",
".",
"maxTimeMS",
")",
"{",
"cursor",
".",
"maxTimeMS",
"(",
"opts",
".",
"maxTimeMS",
")",
";",
"}",
"return",
"cursor",
".",
"stream",
"(",
")",
";",
"}",
")",
";",
"es",
".",
"merge",
"(",
"cursors",
")",
".",
"pipe",
"(",
"es",
".",
"through",
"(",
"function",
"(",
"doc",
")",
"{",
"stream",
".",
"emit",
"(",
"'data'",
",",
"doc",
")",
";",
"}",
")",
")",
".",
"on",
"(",
"'end'",
",",
"function",
"(",
")",
"{",
"stream",
".",
"emit",
"(",
"'end'",
")",
";",
"}",
")",
";",
"}",
")",
";",
"return",
"stream",
";",
"}"
] |
Does reservoir sampling and fetches the resulting documents from the
collection.
The query runs with a limit of `RESERVOIR_SAMPLE_LIMIT`. The reservoir
then samples `size` _ids from the query result. These _ids get grouped
into chunks of at most `RESERVOIR_CHUNK_SIZE`. For each chunk, a cursor
is opened to fetch the actual documents. The cursor streams are combined
and all the resulting documents are emitted downstream.
@param {mongodb.Collection} collection The collection to sample from.
@param {Number} size How many documents should be returned.
@param {Object} opts
@option {Object} query to refine possible samples [default: `{}`].
@option {Number} size of the sample to capture [default: `5`].
@option {Object} fields to return for each document [default: `null`].
@option {Boolean} return document results as raw BSON buffers [default: `false`].
@option {Number} chunkSize For chunked $in queries [default: `1000`].
@return {stream.Readable}
@api private
|
[
"Does",
"reservoir",
"sampling",
"and",
"fetches",
"the",
"resulting",
"documents",
"from",
"the",
"collection",
"."
] |
54299d76c82e119dd75b7c5e42a17229eebe8129
|
https://github.com/mongodb-js/collection-sample/blob/54299d76c82e119dd75b7c5e42a17229eebe8129/lib/reservoir-sampler.js#L34-L69
|
train
|
mongodb-js/collection-sample
|
lib/raw-transform.js
|
transform
|
function transform(chunk, encoding, cb) {
// only transform for raw bytes
if (raw) {
var response = BSON.deserialize(chunk);
response.cursor.firstBatch.forEach(function(doc) {
this.push(BSON.serialize(doc));
}.bind(this));
return cb();
}
// otherwise go back to the main stream
return cb(null, chunk);
}
|
javascript
|
function transform(chunk, encoding, cb) {
// only transform for raw bytes
if (raw) {
var response = BSON.deserialize(chunk);
response.cursor.firstBatch.forEach(function(doc) {
this.push(BSON.serialize(doc));
}.bind(this));
return cb();
}
// otherwise go back to the main stream
return cb(null, chunk);
}
|
[
"function",
"transform",
"(",
"chunk",
",",
"encoding",
",",
"cb",
")",
"{",
"if",
"(",
"raw",
")",
"{",
"var",
"response",
"=",
"BSON",
".",
"deserialize",
"(",
"chunk",
")",
";",
"response",
".",
"cursor",
".",
"firstBatch",
".",
"forEach",
"(",
"function",
"(",
"doc",
")",
"{",
"this",
".",
"push",
"(",
"BSON",
".",
"serialize",
"(",
"doc",
")",
")",
";",
"}",
".",
"bind",
"(",
"this",
")",
")",
";",
"return",
"cb",
"(",
")",
";",
"}",
"return",
"cb",
"(",
"null",
",",
"chunk",
")",
";",
"}"
] |
split up incoming raw bytes and return documents one by one; NODE-1906 this is only necessary for native sampler
|
[
"split",
"up",
"incoming",
"raw",
"bytes",
"and",
"return",
"documents",
"one",
"by",
"one",
";",
"NODE",
"-",
"1906",
"this",
"is",
"only",
"necessary",
"for",
"native",
"sampler"
] |
54299d76c82e119dd75b7c5e42a17229eebe8129
|
https://github.com/mongodb-js/collection-sample/blob/54299d76c82e119dd75b7c5e42a17229eebe8129/lib/raw-transform.js#L7-L18
|
train
|
rasmusbe/gulp-wp-pot
|
index.js
|
gulpWPpot
|
function gulpWPpot (options) {
if (options !== undefined && !isObject(options)) {
throw new PluginError('gulp-wp-pot', 'Require a argument of type object.');
}
const files = [];
const stream = through.obj(function (file, enc, cb) {
if (file.isStream()) {
this.emit('error', new PluginError('gulp-wp-pot', 'Streams are not supported.'));
}
files.push(file.path);
cb();
}, function (cb) {
if (!options) {
options = {};
}
options.src = files;
options.writeFile = false;
try {
const potContents = wpPot(options);
const potFile = new Vinyl({
contents: Buffer.from(potContents),
path: '.'
});
this.push(potFile);
this.emit('end');
cb();
} catch (error) {
this.emit('error', new PluginError('gulp-wp-pot', error));
}
});
return stream;
}
|
javascript
|
function gulpWPpot (options) {
if (options !== undefined && !isObject(options)) {
throw new PluginError('gulp-wp-pot', 'Require a argument of type object.');
}
const files = [];
const stream = through.obj(function (file, enc, cb) {
if (file.isStream()) {
this.emit('error', new PluginError('gulp-wp-pot', 'Streams are not supported.'));
}
files.push(file.path);
cb();
}, function (cb) {
if (!options) {
options = {};
}
options.src = files;
options.writeFile = false;
try {
const potContents = wpPot(options);
const potFile = new Vinyl({
contents: Buffer.from(potContents),
path: '.'
});
this.push(potFile);
this.emit('end');
cb();
} catch (error) {
this.emit('error', new PluginError('gulp-wp-pot', error));
}
});
return stream;
}
|
[
"function",
"gulpWPpot",
"(",
"options",
")",
"{",
"if",
"(",
"options",
"!==",
"undefined",
"&&",
"!",
"isObject",
"(",
"options",
")",
")",
"{",
"throw",
"new",
"PluginError",
"(",
"'gulp-wp-pot'",
",",
"'Require a argument of type object.'",
")",
";",
"}",
"const",
"files",
"=",
"[",
"]",
";",
"const",
"stream",
"=",
"through",
".",
"obj",
"(",
"function",
"(",
"file",
",",
"enc",
",",
"cb",
")",
"{",
"if",
"(",
"file",
".",
"isStream",
"(",
")",
")",
"{",
"this",
".",
"emit",
"(",
"'error'",
",",
"new",
"PluginError",
"(",
"'gulp-wp-pot'",
",",
"'Streams are not supported.'",
")",
")",
";",
"}",
"files",
".",
"push",
"(",
"file",
".",
"path",
")",
";",
"cb",
"(",
")",
";",
"}",
",",
"function",
"(",
"cb",
")",
"{",
"if",
"(",
"!",
"options",
")",
"{",
"options",
"=",
"{",
"}",
";",
"}",
"options",
".",
"src",
"=",
"files",
";",
"options",
".",
"writeFile",
"=",
"false",
";",
"try",
"{",
"const",
"potContents",
"=",
"wpPot",
"(",
"options",
")",
";",
"const",
"potFile",
"=",
"new",
"Vinyl",
"(",
"{",
"contents",
":",
"Buffer",
".",
"from",
"(",
"potContents",
")",
",",
"path",
":",
"'.'",
"}",
")",
";",
"this",
".",
"push",
"(",
"potFile",
")",
";",
"this",
".",
"emit",
"(",
"'end'",
")",
";",
"cb",
"(",
")",
";",
"}",
"catch",
"(",
"error",
")",
"{",
"this",
".",
"emit",
"(",
"'error'",
",",
"new",
"PluginError",
"(",
"'gulp-wp-pot'",
",",
"error",
")",
")",
";",
"}",
"}",
")",
";",
"return",
"stream",
";",
"}"
] |
Run the wp pot generator.
@param {object} options
@return {object}
|
[
"Run",
"the",
"wp",
"pot",
"generator",
"."
] |
7896dac159b1e63fd89bc16be20ab13ea1524aa9
|
https://github.com/rasmusbe/gulp-wp-pot/blob/7896dac159b1e63fd89bc16be20ab13ea1524aa9/index.js#L28-L67
|
train
|
gr2m/moment-parseformat
|
lib/parseformat.js
|
replaceEndian
|
function replaceEndian (options, matchedPart, first, separator, second, third) {
var parts
var hasSingleDigit = Math.min(first.length, second.length, third.length) === 1
var hasQuadDigit = Math.max(first.length, second.length, third.length) === 4
var preferredOrder = typeof options.preferredOrder === 'string' ? options.preferredOrder : options.preferredOrder[separator]
first = parseInt(first, 10)
second = parseInt(second, 10)
third = parseInt(third, 10)
parts = [first, second, third]
preferredOrder = preferredOrder.toUpperCase()
// If first is a year, order will always be Year-Month-Day
if (first > 31) {
parts[0] = hasQuadDigit ? 'YYYY' : 'YY'
parts[1] = hasSingleDigit ? 'M' : 'MM'
parts[2] = hasSingleDigit ? 'D' : 'DD'
return parts.join(separator)
}
// Second will never be the year. And if it is a day,
// the order will always be Month-Day-Year
if (second > 12) {
parts[0] = hasSingleDigit ? 'M' : 'MM'
parts[1] = hasSingleDigit ? 'D' : 'DD'
parts[2] = hasQuadDigit ? 'YYYY' : 'YY'
return parts.join(separator)
}
// if third is a year ...
if (third > 31) {
parts[2] = hasQuadDigit ? 'YYYY' : 'YY'
// ... try to find day in first and second.
// If found, the remaining part is the month.
if (preferredOrder[0] === 'M' && first < 13) {
parts[0] = hasSingleDigit ? 'M' : 'MM'
parts[1] = hasSingleDigit ? 'D' : 'DD'
return parts.join(separator)
}
parts[0] = hasSingleDigit ? 'D' : 'DD'
parts[1] = hasSingleDigit ? 'M' : 'MM'
return parts.join(separator)
}
// if we had no luck until here, we use the preferred order
parts[preferredOrder.indexOf('D')] = hasSingleDigit ? 'D' : 'DD'
parts[preferredOrder.indexOf('M')] = hasSingleDigit ? 'M' : 'MM'
parts[preferredOrder.indexOf('Y')] = hasQuadDigit ? 'YYYY' : 'YY'
return parts.join(separator)
}
|
javascript
|
function replaceEndian (options, matchedPart, first, separator, second, third) {
var parts
var hasSingleDigit = Math.min(first.length, second.length, third.length) === 1
var hasQuadDigit = Math.max(first.length, second.length, third.length) === 4
var preferredOrder = typeof options.preferredOrder === 'string' ? options.preferredOrder : options.preferredOrder[separator]
first = parseInt(first, 10)
second = parseInt(second, 10)
third = parseInt(third, 10)
parts = [first, second, third]
preferredOrder = preferredOrder.toUpperCase()
// If first is a year, order will always be Year-Month-Day
if (first > 31) {
parts[0] = hasQuadDigit ? 'YYYY' : 'YY'
parts[1] = hasSingleDigit ? 'M' : 'MM'
parts[2] = hasSingleDigit ? 'D' : 'DD'
return parts.join(separator)
}
// Second will never be the year. And if it is a day,
// the order will always be Month-Day-Year
if (second > 12) {
parts[0] = hasSingleDigit ? 'M' : 'MM'
parts[1] = hasSingleDigit ? 'D' : 'DD'
parts[2] = hasQuadDigit ? 'YYYY' : 'YY'
return parts.join(separator)
}
// if third is a year ...
if (third > 31) {
parts[2] = hasQuadDigit ? 'YYYY' : 'YY'
// ... try to find day in first and second.
// If found, the remaining part is the month.
if (preferredOrder[0] === 'M' && first < 13) {
parts[0] = hasSingleDigit ? 'M' : 'MM'
parts[1] = hasSingleDigit ? 'D' : 'DD'
return parts.join(separator)
}
parts[0] = hasSingleDigit ? 'D' : 'DD'
parts[1] = hasSingleDigit ? 'M' : 'MM'
return parts.join(separator)
}
// if we had no luck until here, we use the preferred order
parts[preferredOrder.indexOf('D')] = hasSingleDigit ? 'D' : 'DD'
parts[preferredOrder.indexOf('M')] = hasSingleDigit ? 'M' : 'MM'
parts[preferredOrder.indexOf('Y')] = hasQuadDigit ? 'YYYY' : 'YY'
return parts.join(separator)
}
|
[
"function",
"replaceEndian",
"(",
"options",
",",
"matchedPart",
",",
"first",
",",
"separator",
",",
"second",
",",
"third",
")",
"{",
"var",
"parts",
"var",
"hasSingleDigit",
"=",
"Math",
".",
"min",
"(",
"first",
".",
"length",
",",
"second",
".",
"length",
",",
"third",
".",
"length",
")",
"===",
"1",
"var",
"hasQuadDigit",
"=",
"Math",
".",
"max",
"(",
"first",
".",
"length",
",",
"second",
".",
"length",
",",
"third",
".",
"length",
")",
"===",
"4",
"var",
"preferredOrder",
"=",
"typeof",
"options",
".",
"preferredOrder",
"===",
"'string'",
"?",
"options",
".",
"preferredOrder",
":",
"options",
".",
"preferredOrder",
"[",
"separator",
"]",
"first",
"=",
"parseInt",
"(",
"first",
",",
"10",
")",
"second",
"=",
"parseInt",
"(",
"second",
",",
"10",
")",
"third",
"=",
"parseInt",
"(",
"third",
",",
"10",
")",
"parts",
"=",
"[",
"first",
",",
"second",
",",
"third",
"]",
"preferredOrder",
"=",
"preferredOrder",
".",
"toUpperCase",
"(",
")",
"if",
"(",
"first",
">",
"31",
")",
"{",
"parts",
"[",
"0",
"]",
"=",
"hasQuadDigit",
"?",
"'YYYY'",
":",
"'YY'",
"parts",
"[",
"1",
"]",
"=",
"hasSingleDigit",
"?",
"'M'",
":",
"'MM'",
"parts",
"[",
"2",
"]",
"=",
"hasSingleDigit",
"?",
"'D'",
":",
"'DD'",
"return",
"parts",
".",
"join",
"(",
"separator",
")",
"}",
"if",
"(",
"second",
">",
"12",
")",
"{",
"parts",
"[",
"0",
"]",
"=",
"hasSingleDigit",
"?",
"'M'",
":",
"'MM'",
"parts",
"[",
"1",
"]",
"=",
"hasSingleDigit",
"?",
"'D'",
":",
"'DD'",
"parts",
"[",
"2",
"]",
"=",
"hasQuadDigit",
"?",
"'YYYY'",
":",
"'YY'",
"return",
"parts",
".",
"join",
"(",
"separator",
")",
"}",
"if",
"(",
"third",
">",
"31",
")",
"{",
"parts",
"[",
"2",
"]",
"=",
"hasQuadDigit",
"?",
"'YYYY'",
":",
"'YY'",
"if",
"(",
"preferredOrder",
"[",
"0",
"]",
"===",
"'M'",
"&&",
"first",
"<",
"13",
")",
"{",
"parts",
"[",
"0",
"]",
"=",
"hasSingleDigit",
"?",
"'M'",
":",
"'MM'",
"parts",
"[",
"1",
"]",
"=",
"hasSingleDigit",
"?",
"'D'",
":",
"'DD'",
"return",
"parts",
".",
"join",
"(",
"separator",
")",
"}",
"parts",
"[",
"0",
"]",
"=",
"hasSingleDigit",
"?",
"'D'",
":",
"'DD'",
"parts",
"[",
"1",
"]",
"=",
"hasSingleDigit",
"?",
"'M'",
":",
"'MM'",
"return",
"parts",
".",
"join",
"(",
"separator",
")",
"}",
"parts",
"[",
"preferredOrder",
".",
"indexOf",
"(",
"'D'",
")",
"]",
"=",
"hasSingleDigit",
"?",
"'D'",
":",
"'DD'",
"parts",
"[",
"preferredOrder",
".",
"indexOf",
"(",
"'M'",
")",
"]",
"=",
"hasSingleDigit",
"?",
"'M'",
":",
"'MM'",
"parts",
"[",
"preferredOrder",
".",
"indexOf",
"(",
"'Y'",
")",
"]",
"=",
"hasQuadDigit",
"?",
"'YYYY'",
":",
"'YY'",
"return",
"parts",
".",
"join",
"(",
"separator",
")",
"}"
] |
if we can't find an endian based on the separator, but there still is a short date with day, month & year, we try to make a smart decision to identify the order
|
[
"if",
"we",
"can",
"t",
"find",
"an",
"endian",
"based",
"on",
"the",
"separator",
"but",
"there",
"still",
"is",
"a",
"short",
"date",
"with",
"day",
"month",
"&",
"year",
"we",
"try",
"to",
"make",
"a",
"smart",
"decision",
"to",
"identify",
"the",
"order"
] |
c465304a6b5c2771ac5cf51f2ad5dad78a3450d9
|
https://github.com/gr2m/moment-parseformat/blob/c465304a6b5c2771ac5cf51f2ad5dad78a3450d9/lib/parseformat.js#L194-L245
|
train
|
ringcentral/ringcentral-js-widgets
|
packages/ringcentral-widgets/components/CircleButton/index.js
|
CircleButton
|
function CircleButton(props) {
let icon;
if (props.icon) {
const Icon = props.icon;
icon = (
<Icon
className={classnames(styles.icon, props.iconClassName)}
width={props.iconWidth}
height={props.iconHeight}
x={props.iconX}
y={props.iconY}
/>
);
}
const circleClass = classnames(
styles.circle,
!props.showBorder && styles.noBorder,
);
const onClick = props.disabled ? null : props.onClick;
return (
<svg
data-sign={props.dataSign}
xmlns="http://www.w3.org/2000/svg"
className={classnames(styles.btnSvg, props.className)}
viewBox="0 0 500 500"
onClick={(e) => {
if ((e.target && e.target.tagName !== 'svg') && onClick) {
onClick(e);
}
}}
width={props.width}
height={props.height}
x={props.x}
y={props.y}
>
{props.title ? <title>{props.title}</title> : null}
<g
className={styles.btnSvgGroup}
>
<circle
className={circleClass}
cx="250"
cy="250"
r="245"
/>
{icon}
{
props.showRipple
? <circle
className={styles.ripple}
cx="250"
cy="250"
r="245"
/>
: null
}
</g>
</svg>
);
}
|
javascript
|
function CircleButton(props) {
let icon;
if (props.icon) {
const Icon = props.icon;
icon = (
<Icon
className={classnames(styles.icon, props.iconClassName)}
width={props.iconWidth}
height={props.iconHeight}
x={props.iconX}
y={props.iconY}
/>
);
}
const circleClass = classnames(
styles.circle,
!props.showBorder && styles.noBorder,
);
const onClick = props.disabled ? null : props.onClick;
return (
<svg
data-sign={props.dataSign}
xmlns="http://www.w3.org/2000/svg"
className={classnames(styles.btnSvg, props.className)}
viewBox="0 0 500 500"
onClick={(e) => {
if ((e.target && e.target.tagName !== 'svg') && onClick) {
onClick(e);
}
}}
width={props.width}
height={props.height}
x={props.x}
y={props.y}
>
{props.title ? <title>{props.title}</title> : null}
<g
className={styles.btnSvgGroup}
>
<circle
className={circleClass}
cx="250"
cy="250"
r="245"
/>
{icon}
{
props.showRipple
? <circle
className={styles.ripple}
cx="250"
cy="250"
r="245"
/>
: null
}
</g>
</svg>
);
}
|
[
"function",
"CircleButton",
"(",
"props",
")",
"{",
"let",
"icon",
";",
"if",
"(",
"props",
".",
"icon",
")",
"{",
"const",
"Icon",
"=",
"props",
".",
"icon",
";",
"icon",
"=",
"(",
"<",
"Icon",
"className",
"=",
"{",
"classnames",
"(",
"styles",
".",
"icon",
",",
"props",
".",
"iconClassName",
")",
"}",
"width",
"=",
"{",
"props",
".",
"iconWidth",
"}",
"height",
"=",
"{",
"props",
".",
"iconHeight",
"}",
"x",
"=",
"{",
"props",
".",
"iconX",
"}",
"y",
"=",
"{",
"props",
".",
"iconY",
"}",
"/",
">",
")",
";",
"}",
"const",
"circleClass",
"=",
"classnames",
"(",
"styles",
".",
"circle",
",",
"!",
"props",
".",
"showBorder",
"&&",
"styles",
".",
"noBorder",
",",
")",
";",
"const",
"onClick",
"=",
"props",
".",
"disabled",
"?",
"null",
":",
"props",
".",
"onClick",
";",
"return",
"(",
"<",
"svg",
"data-sign",
"=",
"{",
"props",
".",
"dataSign",
"}",
"xmlns",
"=",
"\"http://www.w3.org/2000/svg\"",
"className",
"=",
"{",
"classnames",
"(",
"styles",
".",
"btnSvg",
",",
"props",
".",
"className",
")",
"}",
"viewBox",
"=",
"\"0 0 500 500\"",
"onClick",
"=",
"{",
"(",
"e",
")",
"=>",
"{",
"if",
"(",
"(",
"e",
".",
"target",
"&&",
"e",
".",
"target",
".",
"tagName",
"!==",
"'svg'",
")",
"&&",
"onClick",
")",
"{",
"onClick",
"(",
"e",
")",
";",
"}",
"}",
"}",
"width",
"=",
"{",
"props",
".",
"width",
"}",
"height",
"=",
"{",
"props",
".",
"height",
"}",
"x",
"=",
"{",
"props",
".",
"x",
"}",
"y",
"=",
"{",
"props",
".",
"y",
"}",
">",
" ",
"{",
"props",
".",
"title",
"?",
"<",
"title",
">",
"{",
"props",
".",
"title",
"}",
"<",
"/",
"title",
">",
":",
"null",
"}",
" ",
"<",
"g",
"className",
"=",
"{",
"styles",
".",
"btnSvgGroup",
"}",
">",
" ",
"<",
"circle",
"className",
"=",
"{",
"circleClass",
"}",
"cx",
"=",
"\"250\"",
"cy",
"=",
"\"250\"",
"r",
"=",
"\"245\"",
"/",
">",
" ",
"{",
"icon",
"}",
" ",
"{",
"props",
".",
"showRipple",
"?",
"<",
"circle",
"className",
"=",
"{",
"styles",
".",
"ripple",
"}",
"cx",
"=",
"\"250\"",
"cy",
"=",
"\"250\"",
"r",
"=",
"\"245\"",
"/",
">",
":",
"null",
"}",
" ",
"<",
"/",
"g",
">",
" ",
"<",
"/",
"svg",
">",
")",
";",
"}"
] |
Circle Button with SVG
|
[
"Circle",
"Button",
"with",
"SVG"
] |
31bbd5860ad523f65b6debcc5f27edd23100164d
|
https://github.com/ringcentral/ringcentral-js-widgets/blob/31bbd5860ad523f65b6debcc5f27edd23100164d/packages/ringcentral-widgets/components/CircleButton/index.js#L9-L68
|
train
|
ringcentral/ringcentral-js-widgets
|
packages/ringcentral-widgets/components/RecentActivityPanel/index.js
|
RecentActivityPanel
|
function RecentActivityPanel(props) {
const { title, expanded, onPanelToggle } = props;
const toggleButton = {
label: <ToggleIcon expanded={expanded} />,
onClick: onPanelToggle,
placement: 'right'
};
if (!props.currentContact) {
return null;
}
const containerClass = classnames(styles.container, props.className);
return (
<div className={containerClass}>
<div className={styles.header} onClick={onPanelToggle}>
<Header buttons={[toggleButton]} className={styles.header}>{title}</Header>
</div>
<RecentActivityView {...props} />
</div>
);
}
|
javascript
|
function RecentActivityPanel(props) {
const { title, expanded, onPanelToggle } = props;
const toggleButton = {
label: <ToggleIcon expanded={expanded} />,
onClick: onPanelToggle,
placement: 'right'
};
if (!props.currentContact) {
return null;
}
const containerClass = classnames(styles.container, props.className);
return (
<div className={containerClass}>
<div className={styles.header} onClick={onPanelToggle}>
<Header buttons={[toggleButton]} className={styles.header}>{title}</Header>
</div>
<RecentActivityView {...props} />
</div>
);
}
|
[
"function",
"RecentActivityPanel",
"(",
"props",
")",
"{",
"const",
"{",
"title",
",",
"expanded",
",",
"onPanelToggle",
"}",
"=",
"props",
";",
"const",
"toggleButton",
"=",
"{",
"label",
":",
"<",
"ToggleIcon",
"expanded",
"=",
"{",
"expanded",
"}",
"/",
">",
",",
"onClick",
":",
"onPanelToggle",
",",
"placement",
":",
"'right'",
"}",
";",
"if",
"(",
"!",
"props",
".",
"currentContact",
")",
"{",
"return",
"null",
";",
"}",
"const",
"containerClass",
"=",
"classnames",
"(",
"styles",
".",
"container",
",",
"props",
".",
"className",
")",
";",
"return",
"(",
"<",
"div",
"className",
"=",
"{",
"containerClass",
"}",
">",
" ",
"<",
"div",
"className",
"=",
"{",
"styles",
".",
"header",
"}",
"onClick",
"=",
"{",
"onPanelToggle",
"}",
">",
" ",
"<",
"Header",
"buttons",
"=",
"{",
"[",
"toggleButton",
"]",
"}",
"className",
"=",
"{",
"styles",
".",
"header",
"}",
">",
"{",
"title",
"}",
"<",
"/",
"Header",
">",
" ",
"<",
"/",
"div",
">",
" ",
"<",
"RecentActivityView",
"{",
"...",
"props",
"}",
"/",
">",
" ",
"<",
"/",
"div",
">",
")",
";",
"}"
] |
RecentActivityPanel component provides a animated slide-out panel.
|
[
"RecentActivityPanel",
"component",
"provides",
"a",
"animated",
"slide",
"-",
"out",
"panel",
"."
] |
31bbd5860ad523f65b6debcc5f27edd23100164d
|
https://github.com/ringcentral/ringcentral-js-widgets/blob/31bbd5860ad523f65b6debcc5f27edd23100164d/packages/ringcentral-widgets/components/RecentActivityPanel/index.js#L23-L42
|
train
|
ax5ui/ax5core
|
dist/ax5core.js
|
hasProperty
|
function hasProperty(obj, propName) {
return obj != null && (typeof obj === 'undefined' ? 'undefined' : _typeof(obj)) === 'object' && propName in obj;
}
|
javascript
|
function hasProperty(obj, propName) {
return obj != null && (typeof obj === 'undefined' ? 'undefined' : _typeof(obj)) === 'object' && propName in obj;
}
|
[
"function",
"hasProperty",
"(",
"obj",
",",
"propName",
")",
"{",
"return",
"obj",
"!=",
"null",
"&&",
"(",
"typeof",
"obj",
"===",
"'undefined'",
"?",
"'undefined'",
":",
"_typeof",
"(",
"obj",
")",
")",
"===",
"'object'",
"&&",
"propName",
"in",
"obj",
";",
"}"
] |
Null safe way of checking whether or not an object,
including its prototype, has a given property
|
[
"Null",
"safe",
"way",
"of",
"checking",
"whether",
"or",
"not",
"an",
"object",
"including",
"its",
"prototype",
"has",
"a",
"given",
"property"
] |
f1f029f85a42d16c439ed6eff5d41c7ccd88dec5
|
https://github.com/ax5ui/ax5core/blob/f1f029f85a42d16c439ed6eff5d41c7ccd88dec5/dist/ax5core.js#L3275-L3277
|
train
|
podio/podio-js
|
lib/push.js
|
function (options) {
// Initialize the Faye client if it hasn't been initialized
if (_.isUndefined(this._fayeClient)) {
var pushUrl = new URI(this.apiURL).subdomain('push').path('faye').toString();
this._fayeClient = new Faye.Client(pushUrl);
// We don't support websockets
this._fayeClient.disable('websocket');
// Add extensions to Faye client
this._fayeClient.addExtension({
'outgoing': function(message, callback) {
message.ext = message.ext || {};
message.ext = {
private_pub_signature: options.signature,
private_pub_timestamp: options.timestamp
};
callback(message);
}
});
}
return this._fayeClient;
}
|
javascript
|
function (options) {
// Initialize the Faye client if it hasn't been initialized
if (_.isUndefined(this._fayeClient)) {
var pushUrl = new URI(this.apiURL).subdomain('push').path('faye').toString();
this._fayeClient = new Faye.Client(pushUrl);
// We don't support websockets
this._fayeClient.disable('websocket');
// Add extensions to Faye client
this._fayeClient.addExtension({
'outgoing': function(message, callback) {
message.ext = message.ext || {};
message.ext = {
private_pub_signature: options.signature,
private_pub_timestamp: options.timestamp
};
callback(message);
}
});
}
return this._fayeClient;
}
|
[
"function",
"(",
"options",
")",
"{",
"if",
"(",
"_",
".",
"isUndefined",
"(",
"this",
".",
"_fayeClient",
")",
")",
"{",
"var",
"pushUrl",
"=",
"new",
"URI",
"(",
"this",
".",
"apiURL",
")",
".",
"subdomain",
"(",
"'push'",
")",
".",
"path",
"(",
"'faye'",
")",
".",
"toString",
"(",
")",
";",
"this",
".",
"_fayeClient",
"=",
"new",
"Faye",
".",
"Client",
"(",
"pushUrl",
")",
";",
"this",
".",
"_fayeClient",
".",
"disable",
"(",
"'websocket'",
")",
";",
"this",
".",
"_fayeClient",
".",
"addExtension",
"(",
"{",
"'outgoing'",
":",
"function",
"(",
"message",
",",
"callback",
")",
"{",
"message",
".",
"ext",
"=",
"message",
".",
"ext",
"||",
"{",
"}",
";",
"message",
".",
"ext",
"=",
"{",
"private_pub_signature",
":",
"options",
".",
"signature",
",",
"private_pub_timestamp",
":",
"options",
".",
"timestamp",
"}",
";",
"callback",
"(",
"message",
")",
";",
"}",
"}",
")",
";",
"}",
"return",
"this",
".",
"_fayeClient",
";",
"}"
] |
Returns a reference to the Faye client and initializes it if needed
|
[
"Returns",
"a",
"reference",
"to",
"the",
"Faye",
"client",
"and",
"initializes",
"it",
"if",
"needed"
] |
0c7a8935ffad860af31202565d328ea79a90ebb6
|
https://github.com/podio/podio-js/blob/0c7a8935ffad860af31202565d328ea79a90ebb6/lib/push.js#L11-L37
|
train
|
|
restify/plugins
|
lib/plugins/oauth2TokenParser.js
|
oauth2TokenParser
|
function oauth2TokenParser(options) {
function parseOauth2Token(req, res, next) {
req.oauth2 = { accessToken: null};
var tokenFromHeader = parseHeader(req);
if (tokenFromHeader) {
req.oauth2.accessToken = tokenFromHeader;
}
var tokenFromBody = null;
if (typeof req.body === 'object') {
tokenFromBody = req.body.access_token;
}
// more than one method to transmit the token in each request
// is not allowed - return 400
if (tokenFromBody && tokenFromHeader) {
return next(new errors.makeErrFromCode(400,
'multiple tokens disallowed'));
}
if (tokenFromBody && req.contentType().toLowerCase()
=== 'application/x-www-form-urlencoded') {
req.oauth2.accessToken = tokenFromBody;
}
return (next());
}
return (parseOauth2Token);
}
|
javascript
|
function oauth2TokenParser(options) {
function parseOauth2Token(req, res, next) {
req.oauth2 = { accessToken: null};
var tokenFromHeader = parseHeader(req);
if (tokenFromHeader) {
req.oauth2.accessToken = tokenFromHeader;
}
var tokenFromBody = null;
if (typeof req.body === 'object') {
tokenFromBody = req.body.access_token;
}
// more than one method to transmit the token in each request
// is not allowed - return 400
if (tokenFromBody && tokenFromHeader) {
return next(new errors.makeErrFromCode(400,
'multiple tokens disallowed'));
}
if (tokenFromBody && req.contentType().toLowerCase()
=== 'application/x-www-form-urlencoded') {
req.oauth2.accessToken = tokenFromBody;
}
return (next());
}
return (parseOauth2Token);
}
|
[
"function",
"oauth2TokenParser",
"(",
"options",
")",
"{",
"function",
"parseOauth2Token",
"(",
"req",
",",
"res",
",",
"next",
")",
"{",
"req",
".",
"oauth2",
"=",
"{",
"accessToken",
":",
"null",
"}",
";",
"var",
"tokenFromHeader",
"=",
"parseHeader",
"(",
"req",
")",
";",
"if",
"(",
"tokenFromHeader",
")",
"{",
"req",
".",
"oauth2",
".",
"accessToken",
"=",
"tokenFromHeader",
";",
"}",
"var",
"tokenFromBody",
"=",
"null",
";",
"if",
"(",
"typeof",
"req",
".",
"body",
"===",
"'object'",
")",
"{",
"tokenFromBody",
"=",
"req",
".",
"body",
".",
"access_token",
";",
"}",
"if",
"(",
"tokenFromBody",
"&&",
"tokenFromHeader",
")",
"{",
"return",
"next",
"(",
"new",
"errors",
".",
"makeErrFromCode",
"(",
"400",
",",
"'multiple tokens disallowed'",
")",
")",
";",
"}",
"if",
"(",
"tokenFromBody",
"&&",
"req",
".",
"contentType",
"(",
")",
".",
"toLowerCase",
"(",
")",
"===",
"'application/x-www-form-urlencoded'",
")",
"{",
"req",
".",
"oauth2",
".",
"accessToken",
"=",
"tokenFromBody",
";",
"}",
"return",
"(",
"next",
"(",
")",
")",
";",
"}",
"return",
"(",
"parseOauth2Token",
")",
";",
"}"
] |
Returns a plugin that will parse the client's request for an OAUTH2
access token
Subsequent handlers will see `req.oauth2`, which looks like:
{
oauth2: {
accessToken: 'mF_9.B5f-4.1JqM&p=q'
}
}
@public
@function oauth2TokenParser
@throws {InvalidArgumentError}
@param {Object} options an options object
@returns {Function}
|
[
"Returns",
"a",
"plugin",
"that",
"will",
"parse",
"the",
"client",
"s",
"request",
"for",
"an",
"OAUTH2",
"access",
"token"
] |
32c0c1e64dae2698abd8f4c0307d4fb405c1b6f2
|
https://github.com/restify/plugins/blob/32c0c1e64dae2698abd8f4c0307d4fb405c1b6f2/lib/plugins/oauth2TokenParser.js#L67-L101
|
train
|
restify/plugins
|
lib/plugins/accept.js
|
acceptParser
|
function acceptParser(accepts) {
var acceptable = accepts;
if (!Array.isArray(acceptable)) {
acceptable = [acceptable];
}
assert.arrayOfString(acceptable, 'acceptable');
acceptable = acceptable.filter(function (a) {
return (a);
}).map(function (a) {
return ((a.indexOf('/') === -1) ? mime.lookup(a) : a);
}).filter(function (a) {
return (a);
});
var e = new NotAcceptableError('Server accepts: ' + acceptable.join());
function parseAccept(req, res, next) {
if (req.accepts(acceptable)) {
next();
return;
}
res.json(e);
next(false);
}
return (parseAccept);
}
|
javascript
|
function acceptParser(accepts) {
var acceptable = accepts;
if (!Array.isArray(acceptable)) {
acceptable = [acceptable];
}
assert.arrayOfString(acceptable, 'acceptable');
acceptable = acceptable.filter(function (a) {
return (a);
}).map(function (a) {
return ((a.indexOf('/') === -1) ? mime.lookup(a) : a);
}).filter(function (a) {
return (a);
});
var e = new NotAcceptableError('Server accepts: ' + acceptable.join());
function parseAccept(req, res, next) {
if (req.accepts(acceptable)) {
next();
return;
}
res.json(e);
next(false);
}
return (parseAccept);
}
|
[
"function",
"acceptParser",
"(",
"accepts",
")",
"{",
"var",
"acceptable",
"=",
"accepts",
";",
"if",
"(",
"!",
"Array",
".",
"isArray",
"(",
"acceptable",
")",
")",
"{",
"acceptable",
"=",
"[",
"acceptable",
"]",
";",
"}",
"assert",
".",
"arrayOfString",
"(",
"acceptable",
",",
"'acceptable'",
")",
";",
"acceptable",
"=",
"acceptable",
".",
"filter",
"(",
"function",
"(",
"a",
")",
"{",
"return",
"(",
"a",
")",
";",
"}",
")",
".",
"map",
"(",
"function",
"(",
"a",
")",
"{",
"return",
"(",
"(",
"a",
".",
"indexOf",
"(",
"'/'",
")",
"===",
"-",
"1",
")",
"?",
"mime",
".",
"lookup",
"(",
"a",
")",
":",
"a",
")",
";",
"}",
")",
".",
"filter",
"(",
"function",
"(",
"a",
")",
"{",
"return",
"(",
"a",
")",
";",
"}",
")",
";",
"var",
"e",
"=",
"new",
"NotAcceptableError",
"(",
"'Server accepts: '",
"+",
"acceptable",
".",
"join",
"(",
")",
")",
";",
"function",
"parseAccept",
"(",
"req",
",",
"res",
",",
"next",
")",
"{",
"if",
"(",
"req",
".",
"accepts",
"(",
"acceptable",
")",
")",
"{",
"next",
"(",
")",
";",
"return",
";",
"}",
"res",
".",
"json",
"(",
"e",
")",
";",
"next",
"(",
"false",
")",
";",
"}",
"return",
"(",
"parseAccept",
")",
";",
"}"
] |
Returns a plugin that will check the client's Accept header can be handled
by this server.
Note you can get the set of types allowed from a restify server by doing
`server.acceptable`.
@public
@function acceptParser
@throws {NotAcceptableError}
@param {String} accepts array of accept types.
@returns {Function} restify handler.
|
[
"Returns",
"a",
"plugin",
"that",
"will",
"check",
"the",
"client",
"s",
"Accept",
"header",
"can",
"be",
"handled",
"by",
"this",
"server",
"."
] |
32c0c1e64dae2698abd8f4c0307d4fb405c1b6f2
|
https://github.com/restify/plugins/blob/32c0c1e64dae2698abd8f4c0307d4fb405c1b6f2/lib/plugins/accept.js#L24-L53
|
train
|
restify/plugins
|
lib/plugins/authorization.js
|
authorizationParser
|
function authorizationParser(options) {
function parseAuthorization(req, res, next) {
req.authorization = {};
req.username = 'anonymous';
if (!req.headers.authorization) {
return (next());
}
var pieces = req.headers.authorization.split(' ', 2);
if (!pieces || pieces.length !== 2) {
var e = new InvalidHeaderError('BasicAuth content ' +
'is invalid.');
return (next(e));
}
req.authorization.scheme = pieces[0];
req.authorization.credentials = pieces[1];
try {
switch (pieces[0].toLowerCase()) {
case 'basic':
req.authorization.basic = parseBasic(pieces[1]);
req.username = req.authorization.basic.username;
break;
case 'signature':
req.authorization.signature =
parseSignature(req, options);
req.username =
req.authorization.signature.keyId;
break;
default:
break;
}
} catch (e2) {
return (next(e2));
}
return (next());
}
return (parseAuthorization);
}
|
javascript
|
function authorizationParser(options) {
function parseAuthorization(req, res, next) {
req.authorization = {};
req.username = 'anonymous';
if (!req.headers.authorization) {
return (next());
}
var pieces = req.headers.authorization.split(' ', 2);
if (!pieces || pieces.length !== 2) {
var e = new InvalidHeaderError('BasicAuth content ' +
'is invalid.');
return (next(e));
}
req.authorization.scheme = pieces[0];
req.authorization.credentials = pieces[1];
try {
switch (pieces[0].toLowerCase()) {
case 'basic':
req.authorization.basic = parseBasic(pieces[1]);
req.username = req.authorization.basic.username;
break;
case 'signature':
req.authorization.signature =
parseSignature(req, options);
req.username =
req.authorization.signature.keyId;
break;
default:
break;
}
} catch (e2) {
return (next(e2));
}
return (next());
}
return (parseAuthorization);
}
|
[
"function",
"authorizationParser",
"(",
"options",
")",
"{",
"function",
"parseAuthorization",
"(",
"req",
",",
"res",
",",
"next",
")",
"{",
"req",
".",
"authorization",
"=",
"{",
"}",
";",
"req",
".",
"username",
"=",
"'anonymous'",
";",
"if",
"(",
"!",
"req",
".",
"headers",
".",
"authorization",
")",
"{",
"return",
"(",
"next",
"(",
")",
")",
";",
"}",
"var",
"pieces",
"=",
"req",
".",
"headers",
".",
"authorization",
".",
"split",
"(",
"' '",
",",
"2",
")",
";",
"if",
"(",
"!",
"pieces",
"||",
"pieces",
".",
"length",
"!==",
"2",
")",
"{",
"var",
"e",
"=",
"new",
"InvalidHeaderError",
"(",
"'BasicAuth content '",
"+",
"'is invalid.'",
")",
";",
"return",
"(",
"next",
"(",
"e",
")",
")",
";",
"}",
"req",
".",
"authorization",
".",
"scheme",
"=",
"pieces",
"[",
"0",
"]",
";",
"req",
".",
"authorization",
".",
"credentials",
"=",
"pieces",
"[",
"1",
"]",
";",
"try",
"{",
"switch",
"(",
"pieces",
"[",
"0",
"]",
".",
"toLowerCase",
"(",
")",
")",
"{",
"case",
"'basic'",
":",
"req",
".",
"authorization",
".",
"basic",
"=",
"parseBasic",
"(",
"pieces",
"[",
"1",
"]",
")",
";",
"req",
".",
"username",
"=",
"req",
".",
"authorization",
".",
"basic",
".",
"username",
";",
"break",
";",
"case",
"'signature'",
":",
"req",
".",
"authorization",
".",
"signature",
"=",
"parseSignature",
"(",
"req",
",",
"options",
")",
";",
"req",
".",
"username",
"=",
"req",
".",
"authorization",
".",
"signature",
".",
"keyId",
";",
"break",
";",
"default",
":",
"break",
";",
"}",
"}",
"catch",
"(",
"e2",
")",
"{",
"return",
"(",
"next",
"(",
"e2",
")",
")",
";",
"}",
"return",
"(",
"next",
"(",
")",
")",
";",
"}",
"return",
"(",
"parseAuthorization",
")",
";",
"}"
] |
Returns a plugin that will parse the client's Authorization header.
Subsequent handlers will see `req.authorization`, which looks like:
{
scheme: <Basic|Signature|...>,
credentials: <Undecoded value of header>,
basic: {
username: $user
password: $password
}
}
`req.username` will also be set, and defaults to 'anonymous'.
@public
@function authorizationParser
@throws {InvalidArgumentError}
@param {Object} options an options object
@returns {Function}
|
[
"Returns",
"a",
"plugin",
"that",
"will",
"parse",
"the",
"client",
"s",
"Authorization",
"header",
"."
] |
32c0c1e64dae2698abd8f4c0307d4fb405c1b6f2
|
https://github.com/restify/plugins/blob/32c0c1e64dae2698abd8f4c0307d4fb405c1b6f2/lib/plugins/authorization.js#L103-L149
|
train
|
restify/plugins
|
lib/pre/reqIdHeaders.js
|
createReqIdHeaders
|
function createReqIdHeaders(opts) {
assert.object(opts, 'opts');
assert.arrayOfString(opts.headers, 'opts.headers');
var headers = opts.headers.concat(DEFAULT_HEADERS);
return function reqIdHeaders(req, res, next) {
for (var i = 0; i < headers.length; i++) {
var val = req.header(headers[i]);
if (val) {
req.id(val);
break;
}
}
return next();
};
}
|
javascript
|
function createReqIdHeaders(opts) {
assert.object(opts, 'opts');
assert.arrayOfString(opts.headers, 'opts.headers');
var headers = opts.headers.concat(DEFAULT_HEADERS);
return function reqIdHeaders(req, res, next) {
for (var i = 0; i < headers.length; i++) {
var val = req.header(headers[i]);
if (val) {
req.id(val);
break;
}
}
return next();
};
}
|
[
"function",
"createReqIdHeaders",
"(",
"opts",
")",
"{",
"assert",
".",
"object",
"(",
"opts",
",",
"'opts'",
")",
";",
"assert",
".",
"arrayOfString",
"(",
"opts",
".",
"headers",
",",
"'opts.headers'",
")",
";",
"var",
"headers",
"=",
"opts",
".",
"headers",
".",
"concat",
"(",
"DEFAULT_HEADERS",
")",
";",
"return",
"function",
"reqIdHeaders",
"(",
"req",
",",
"res",
",",
"next",
")",
"{",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"headers",
".",
"length",
";",
"i",
"++",
")",
"{",
"var",
"val",
"=",
"req",
".",
"header",
"(",
"headers",
"[",
"i",
"]",
")",
";",
"if",
"(",
"val",
")",
"{",
"req",
".",
"id",
"(",
"val",
")",
";",
"break",
";",
"}",
"}",
"return",
"next",
"(",
")",
";",
"}",
";",
"}"
] |
Automatically reuse incoming request header as the request id.
@public
@function createReqIdHeaders
@param {Object} opts an options object
@param {Array} opts.headers array of headers from where to pull existing
request id headers
@returns {Function}
|
[
"Automatically",
"reuse",
"incoming",
"request",
"header",
"as",
"the",
"request",
"id",
"."
] |
32c0c1e64dae2698abd8f4c0307d4fb405c1b6f2
|
https://github.com/restify/plugins/blob/32c0c1e64dae2698abd8f4c0307d4fb405c1b6f2/lib/pre/reqIdHeaders.js#L17-L37
|
train
|
restify/plugins
|
lib/plugins/query.js
|
queryParser
|
function queryParser(options) {
var opts = options || {};
assert.object(opts, 'opts');
function parseQueryString(req, res, next) {
if (!req.getQuery()) {
req.query = {};
return next();
}
req.query = qs.parse(req.getQuery(), opts);
if (opts.mapParams === true) {
Object.keys(req.query).forEach(function (k) {
if (req.params[k] && !opts.overrideParams) {
return;
}
req.params[k] = req.query[k];
});
}
return next();
}
return parseQueryString;
}
|
javascript
|
function queryParser(options) {
var opts = options || {};
assert.object(opts, 'opts');
function parseQueryString(req, res, next) {
if (!req.getQuery()) {
req.query = {};
return next();
}
req.query = qs.parse(req.getQuery(), opts);
if (opts.mapParams === true) {
Object.keys(req.query).forEach(function (k) {
if (req.params[k] && !opts.overrideParams) {
return;
}
req.params[k] = req.query[k];
});
}
return next();
}
return parseQueryString;
}
|
[
"function",
"queryParser",
"(",
"options",
")",
"{",
"var",
"opts",
"=",
"options",
"||",
"{",
"}",
";",
"assert",
".",
"object",
"(",
"opts",
",",
"'opts'",
")",
";",
"function",
"parseQueryString",
"(",
"req",
",",
"res",
",",
"next",
")",
"{",
"if",
"(",
"!",
"req",
".",
"getQuery",
"(",
")",
")",
"{",
"req",
".",
"query",
"=",
"{",
"}",
";",
"return",
"next",
"(",
")",
";",
"}",
"req",
".",
"query",
"=",
"qs",
".",
"parse",
"(",
"req",
".",
"getQuery",
"(",
")",
",",
"opts",
")",
";",
"if",
"(",
"opts",
".",
"mapParams",
"===",
"true",
")",
"{",
"Object",
".",
"keys",
"(",
"req",
".",
"query",
")",
".",
"forEach",
"(",
"function",
"(",
"k",
")",
"{",
"if",
"(",
"req",
".",
"params",
"[",
"k",
"]",
"&&",
"!",
"opts",
".",
"overrideParams",
")",
"{",
"return",
";",
"}",
"req",
".",
"params",
"[",
"k",
"]",
"=",
"req",
".",
"query",
"[",
"k",
"]",
";",
"}",
")",
";",
"}",
"return",
"next",
"(",
")",
";",
"}",
"return",
"parseQueryString",
";",
"}"
] |
Returns a plugin that will parse the query string, and merge the results
into req.query.
Unless options.mapParams is false, they will also be mapped into req.params.
@public
@function queryParser
@param {Object} options an options object
@returns {Function}
|
[
"Returns",
"a",
"plugin",
"that",
"will",
"parse",
"the",
"query",
"string",
"and",
"merge",
"the",
"results",
"into",
"req",
".",
"query",
"."
] |
32c0c1e64dae2698abd8f4c0307d4fb405c1b6f2
|
https://github.com/restify/plugins/blob/32c0c1e64dae2698abd8f4c0307d4fb405c1b6f2/lib/plugins/query.js#L19-L46
|
train
|
jshttp/range-parser
|
index.js
|
rangeParser
|
function rangeParser (size, str, options) {
if (typeof str !== 'string') {
throw new TypeError('argument str must be a string')
}
var index = str.indexOf('=')
if (index === -1) {
return -2
}
// split the range string
var arr = str.slice(index + 1).split(',')
var ranges = []
// add ranges type
ranges.type = str.slice(0, index)
// parse all ranges
for (var i = 0; i < arr.length; i++) {
var range = arr[i].split('-')
var start = parseInt(range[0], 10)
var end = parseInt(range[1], 10)
// -nnn
if (isNaN(start)) {
start = size - end
end = size - 1
// nnn-
} else if (isNaN(end)) {
end = size - 1
}
// limit last-byte-pos to current length
if (end > size - 1) {
end = size - 1
}
// invalid or unsatisifiable
if (isNaN(start) || isNaN(end) || start > end || start < 0) {
continue
}
// add range
ranges.push({
start: start,
end: end
})
}
if (ranges.length < 1) {
// unsatisifiable
return -1
}
return options && options.combine
? combineRanges(ranges)
: ranges
}
|
javascript
|
function rangeParser (size, str, options) {
if (typeof str !== 'string') {
throw new TypeError('argument str must be a string')
}
var index = str.indexOf('=')
if (index === -1) {
return -2
}
// split the range string
var arr = str.slice(index + 1).split(',')
var ranges = []
// add ranges type
ranges.type = str.slice(0, index)
// parse all ranges
for (var i = 0; i < arr.length; i++) {
var range = arr[i].split('-')
var start = parseInt(range[0], 10)
var end = parseInt(range[1], 10)
// -nnn
if (isNaN(start)) {
start = size - end
end = size - 1
// nnn-
} else if (isNaN(end)) {
end = size - 1
}
// limit last-byte-pos to current length
if (end > size - 1) {
end = size - 1
}
// invalid or unsatisifiable
if (isNaN(start) || isNaN(end) || start > end || start < 0) {
continue
}
// add range
ranges.push({
start: start,
end: end
})
}
if (ranges.length < 1) {
// unsatisifiable
return -1
}
return options && options.combine
? combineRanges(ranges)
: ranges
}
|
[
"function",
"rangeParser",
"(",
"size",
",",
"str",
",",
"options",
")",
"{",
"if",
"(",
"typeof",
"str",
"!==",
"'string'",
")",
"{",
"throw",
"new",
"TypeError",
"(",
"'argument str must be a string'",
")",
"}",
"var",
"index",
"=",
"str",
".",
"indexOf",
"(",
"'='",
")",
"if",
"(",
"index",
"===",
"-",
"1",
")",
"{",
"return",
"-",
"2",
"}",
"var",
"arr",
"=",
"str",
".",
"slice",
"(",
"index",
"+",
"1",
")",
".",
"split",
"(",
"','",
")",
"var",
"ranges",
"=",
"[",
"]",
"ranges",
".",
"type",
"=",
"str",
".",
"slice",
"(",
"0",
",",
"index",
")",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"arr",
".",
"length",
";",
"i",
"++",
")",
"{",
"var",
"range",
"=",
"arr",
"[",
"i",
"]",
".",
"split",
"(",
"'-'",
")",
"var",
"start",
"=",
"parseInt",
"(",
"range",
"[",
"0",
"]",
",",
"10",
")",
"var",
"end",
"=",
"parseInt",
"(",
"range",
"[",
"1",
"]",
",",
"10",
")",
"if",
"(",
"isNaN",
"(",
"start",
")",
")",
"{",
"start",
"=",
"size",
"-",
"end",
"end",
"=",
"size",
"-",
"1",
"}",
"else",
"if",
"(",
"isNaN",
"(",
"end",
")",
")",
"{",
"end",
"=",
"size",
"-",
"1",
"}",
"if",
"(",
"end",
">",
"size",
"-",
"1",
")",
"{",
"end",
"=",
"size",
"-",
"1",
"}",
"if",
"(",
"isNaN",
"(",
"start",
")",
"||",
"isNaN",
"(",
"end",
")",
"||",
"start",
">",
"end",
"||",
"start",
"<",
"0",
")",
"{",
"continue",
"}",
"ranges",
".",
"push",
"(",
"{",
"start",
":",
"start",
",",
"end",
":",
"end",
"}",
")",
"}",
"if",
"(",
"ranges",
".",
"length",
"<",
"1",
")",
"{",
"return",
"-",
"1",
"}",
"return",
"options",
"&&",
"options",
".",
"combine",
"?",
"combineRanges",
"(",
"ranges",
")",
":",
"ranges",
"}"
] |
Parse "Range" header `str` relative to the given file `size`.
@param {Number} size
@param {String} str
@param {Object} [options]
@return {Array}
@public
|
[
"Parse",
"Range",
"header",
"str",
"relative",
"to",
"the",
"given",
"file",
"size",
"."
] |
9817a4dd666ac9f3905ddb92296e623bee91d04b
|
https://github.com/jshttp/range-parser/blob/9817a4dd666ac9f3905ddb92296e623bee91d04b/index.js#L27-L85
|
train
|
jshttp/range-parser
|
index.js
|
combineRanges
|
function combineRanges (ranges) {
var ordered = ranges.map(mapWithIndex).sort(sortByRangeStart)
for (var j = 0, i = 1; i < ordered.length; i++) {
var range = ordered[i]
var current = ordered[j]
if (range.start > current.end + 1) {
// next range
ordered[++j] = range
} else if (range.end > current.end) {
// extend range
current.end = range.end
current.index = Math.min(current.index, range.index)
}
}
// trim ordered array
ordered.length = j + 1
// generate combined range
var combined = ordered.sort(sortByRangeIndex).map(mapWithoutIndex)
// copy ranges type
combined.type = ranges.type
return combined
}
|
javascript
|
function combineRanges (ranges) {
var ordered = ranges.map(mapWithIndex).sort(sortByRangeStart)
for (var j = 0, i = 1; i < ordered.length; i++) {
var range = ordered[i]
var current = ordered[j]
if (range.start > current.end + 1) {
// next range
ordered[++j] = range
} else if (range.end > current.end) {
// extend range
current.end = range.end
current.index = Math.min(current.index, range.index)
}
}
// trim ordered array
ordered.length = j + 1
// generate combined range
var combined = ordered.sort(sortByRangeIndex).map(mapWithoutIndex)
// copy ranges type
combined.type = ranges.type
return combined
}
|
[
"function",
"combineRanges",
"(",
"ranges",
")",
"{",
"var",
"ordered",
"=",
"ranges",
".",
"map",
"(",
"mapWithIndex",
")",
".",
"sort",
"(",
"sortByRangeStart",
")",
"for",
"(",
"var",
"j",
"=",
"0",
",",
"i",
"=",
"1",
";",
"i",
"<",
"ordered",
".",
"length",
";",
"i",
"++",
")",
"{",
"var",
"range",
"=",
"ordered",
"[",
"i",
"]",
"var",
"current",
"=",
"ordered",
"[",
"j",
"]",
"if",
"(",
"range",
".",
"start",
">",
"current",
".",
"end",
"+",
"1",
")",
"{",
"ordered",
"[",
"++",
"j",
"]",
"=",
"range",
"}",
"else",
"if",
"(",
"range",
".",
"end",
">",
"current",
".",
"end",
")",
"{",
"current",
".",
"end",
"=",
"range",
".",
"end",
"current",
".",
"index",
"=",
"Math",
".",
"min",
"(",
"current",
".",
"index",
",",
"range",
".",
"index",
")",
"}",
"}",
"ordered",
".",
"length",
"=",
"j",
"+",
"1",
"var",
"combined",
"=",
"ordered",
".",
"sort",
"(",
"sortByRangeIndex",
")",
".",
"map",
"(",
"mapWithoutIndex",
")",
"combined",
".",
"type",
"=",
"ranges",
".",
"type",
"return",
"combined",
"}"
] |
Combine overlapping & adjacent ranges.
@private
|
[
"Combine",
"overlapping",
"&",
"adjacent",
"ranges",
"."
] |
9817a4dd666ac9f3905ddb92296e623bee91d04b
|
https://github.com/jshttp/range-parser/blob/9817a4dd666ac9f3905ddb92296e623bee91d04b/index.js#L92-L119
|
train
|
jshttp/range-parser
|
index.js
|
mapWithIndex
|
function mapWithIndex (range, index) {
return {
start: range.start,
end: range.end,
index: index
}
}
|
javascript
|
function mapWithIndex (range, index) {
return {
start: range.start,
end: range.end,
index: index
}
}
|
[
"function",
"mapWithIndex",
"(",
"range",
",",
"index",
")",
"{",
"return",
"{",
"start",
":",
"range",
".",
"start",
",",
"end",
":",
"range",
".",
"end",
",",
"index",
":",
"index",
"}",
"}"
] |
Map function to add index value to ranges.
@private
|
[
"Map",
"function",
"to",
"add",
"index",
"value",
"to",
"ranges",
"."
] |
9817a4dd666ac9f3905ddb92296e623bee91d04b
|
https://github.com/jshttp/range-parser/blob/9817a4dd666ac9f3905ddb92296e623bee91d04b/index.js#L126-L132
|
train
|
kintone/plugin-packer
|
src/sourcelist.js
|
sourceList
|
function sourceList(manifest) {
const sourceTypes = [
["desktop", "js"],
["desktop", "css"],
["mobile", "js"],
["config", "js"],
["config", "css"]
];
const list = sourceTypes
.map(t => manifest[t[0]] && manifest[t[0]][t[1]])
.filter(i => !!i)
.reduce((a, b) => a.concat(b), [])
.filter(file => !/^https?:\/\//.test(file));
if (manifest.config && manifest.config.html) {
list.push(manifest.config.html);
}
list.push("manifest.json", manifest.icon);
// Make the file list unique
return [...new Set(list)];
}
|
javascript
|
function sourceList(manifest) {
const sourceTypes = [
["desktop", "js"],
["desktop", "css"],
["mobile", "js"],
["config", "js"],
["config", "css"]
];
const list = sourceTypes
.map(t => manifest[t[0]] && manifest[t[0]][t[1]])
.filter(i => !!i)
.reduce((a, b) => a.concat(b), [])
.filter(file => !/^https?:\/\//.test(file));
if (manifest.config && manifest.config.html) {
list.push(manifest.config.html);
}
list.push("manifest.json", manifest.icon);
// Make the file list unique
return [...new Set(list)];
}
|
[
"function",
"sourceList",
"(",
"manifest",
")",
"{",
"const",
"sourceTypes",
"=",
"[",
"[",
"\"desktop\"",
",",
"\"js\"",
"]",
",",
"[",
"\"desktop\"",
",",
"\"css\"",
"]",
",",
"[",
"\"mobile\"",
",",
"\"js\"",
"]",
",",
"[",
"\"config\"",
",",
"\"js\"",
"]",
",",
"[",
"\"config\"",
",",
"\"css\"",
"]",
"]",
";",
"const",
"list",
"=",
"sourceTypes",
".",
"map",
"(",
"t",
"=>",
"manifest",
"[",
"t",
"[",
"0",
"]",
"]",
"&&",
"manifest",
"[",
"t",
"[",
"0",
"]",
"]",
"[",
"t",
"[",
"1",
"]",
"]",
")",
".",
"filter",
"(",
"i",
"=>",
"!",
"!",
"i",
")",
".",
"reduce",
"(",
"(",
"a",
",",
"b",
")",
"=>",
"a",
".",
"concat",
"(",
"b",
")",
",",
"[",
"]",
")",
".",
"filter",
"(",
"file",
"=>",
"!",
"/",
"^https?:\\/\\/",
"/",
".",
"test",
"(",
"file",
")",
")",
";",
"if",
"(",
"manifest",
".",
"config",
"&&",
"manifest",
".",
"config",
".",
"html",
")",
"{",
"list",
".",
"push",
"(",
"manifest",
".",
"config",
".",
"html",
")",
";",
"}",
"list",
".",
"push",
"(",
"\"manifest.json\"",
",",
"manifest",
".",
"icon",
")",
";",
"return",
"[",
"...",
"new",
"Set",
"(",
"list",
")",
"]",
";",
"}"
] |
Create content file list from manifest.json
@param {!Object} manifest
@return {!Array<string>}
|
[
"Create",
"content",
"file",
"list",
"from",
"manifest",
".",
"json"
] |
585e081ad8f1ddefe8f1b6e6b41eebfd20a7a2bb
|
https://github.com/kintone/plugin-packer/blob/585e081ad8f1ddefe8f1b6e6b41eebfd20a7a2bb/src/sourcelist.js#L9-L28
|
train
|
kintone/plugin-packer
|
src/create-contents-zip.js
|
createContentsZip
|
function createContentsZip(pluginDir, manifest) {
return new Promise((res, rej) => {
const output = new streamBuffers.WritableStreamBuffer();
const zipFile = new ZipFile();
let size = null;
output.on("finish", () => {
debug(`plugin.zip: ${size} bytes`);
res(output.getContents());
});
zipFile.outputStream.pipe(output);
sourceList(manifest).forEach(src => {
zipFile.addFile(path.join(pluginDir, src), src);
});
zipFile.end(finalSize => {
size = finalSize;
});
});
}
|
javascript
|
function createContentsZip(pluginDir, manifest) {
return new Promise((res, rej) => {
const output = new streamBuffers.WritableStreamBuffer();
const zipFile = new ZipFile();
let size = null;
output.on("finish", () => {
debug(`plugin.zip: ${size} bytes`);
res(output.getContents());
});
zipFile.outputStream.pipe(output);
sourceList(manifest).forEach(src => {
zipFile.addFile(path.join(pluginDir, src), src);
});
zipFile.end(finalSize => {
size = finalSize;
});
});
}
|
[
"function",
"createContentsZip",
"(",
"pluginDir",
",",
"manifest",
")",
"{",
"return",
"new",
"Promise",
"(",
"(",
"res",
",",
"rej",
")",
"=>",
"{",
"const",
"output",
"=",
"new",
"streamBuffers",
".",
"WritableStreamBuffer",
"(",
")",
";",
"const",
"zipFile",
"=",
"new",
"ZipFile",
"(",
")",
";",
"let",
"size",
"=",
"null",
";",
"output",
".",
"on",
"(",
"\"finish\"",
",",
"(",
")",
"=>",
"{",
"debug",
"(",
"`",
"${",
"size",
"}",
"`",
")",
";",
"res",
"(",
"output",
".",
"getContents",
"(",
")",
")",
";",
"}",
")",
";",
"zipFile",
".",
"outputStream",
".",
"pipe",
"(",
"output",
")",
";",
"sourceList",
"(",
"manifest",
")",
".",
"forEach",
"(",
"src",
"=>",
"{",
"zipFile",
".",
"addFile",
"(",
"path",
".",
"join",
"(",
"pluginDir",
",",
"src",
")",
",",
"src",
")",
";",
"}",
")",
";",
"zipFile",
".",
"end",
"(",
"finalSize",
"=>",
"{",
"size",
"=",
"finalSize",
";",
"}",
")",
";",
"}",
")",
";",
"}"
] |
Create a zipped contents
@param {string} pluginDir
@param {!Object} manifest
@return {!Promise<!Buffer>}
|
[
"Create",
"a",
"zipped",
"contents"
] |
585e081ad8f1ddefe8f1b6e6b41eebfd20a7a2bb
|
https://github.com/kintone/plugin-packer/blob/585e081ad8f1ddefe8f1b6e6b41eebfd20a7a2bb/src/create-contents-zip.js#L18-L35
|
train
|
kintone/plugin-packer
|
site/dom.js
|
fileMapToBuffer
|
function fileMapToBuffer(fileMap) {
return Promise.all(
Array.from(fileMap.entries()).map(([path, file]) =>
readArrayBuffer(file).then(buffer => ({ buffer, path }))
)
)
.then(results => {
const zipFile = new yazl.ZipFile();
results.forEach(result => {
zipFile.addBuffer(Buffer.from(result.buffer), result.path);
});
zipFile.end();
return zipFile;
})
.then(
zipFile =>
new Promise(resolve => {
const output = new streamBuffers.WritableStreamBuffer();
output.on("finish", () => {
resolve(output.getContents());
});
zipFile.outputStream.pipe(output);
})
);
}
|
javascript
|
function fileMapToBuffer(fileMap) {
return Promise.all(
Array.from(fileMap.entries()).map(([path, file]) =>
readArrayBuffer(file).then(buffer => ({ buffer, path }))
)
)
.then(results => {
const zipFile = new yazl.ZipFile();
results.forEach(result => {
zipFile.addBuffer(Buffer.from(result.buffer), result.path);
});
zipFile.end();
return zipFile;
})
.then(
zipFile =>
new Promise(resolve => {
const output = new streamBuffers.WritableStreamBuffer();
output.on("finish", () => {
resolve(output.getContents());
});
zipFile.outputStream.pipe(output);
})
);
}
|
[
"function",
"fileMapToBuffer",
"(",
"fileMap",
")",
"{",
"return",
"Promise",
".",
"all",
"(",
"Array",
".",
"from",
"(",
"fileMap",
".",
"entries",
"(",
")",
")",
".",
"map",
"(",
"(",
"[",
"path",
",",
"file",
"]",
")",
"=>",
"readArrayBuffer",
"(",
"file",
")",
".",
"then",
"(",
"buffer",
"=>",
"(",
"{",
"buffer",
",",
"path",
"}",
")",
")",
")",
")",
".",
"then",
"(",
"results",
"=>",
"{",
"const",
"zipFile",
"=",
"new",
"yazl",
".",
"ZipFile",
"(",
")",
";",
"results",
".",
"forEach",
"(",
"result",
"=>",
"{",
"zipFile",
".",
"addBuffer",
"(",
"Buffer",
".",
"from",
"(",
"result",
".",
"buffer",
")",
",",
"result",
".",
"path",
")",
";",
"}",
")",
";",
"zipFile",
".",
"end",
"(",
")",
";",
"return",
"zipFile",
";",
"}",
")",
".",
"then",
"(",
"zipFile",
"=>",
"new",
"Promise",
"(",
"resolve",
"=>",
"{",
"const",
"output",
"=",
"new",
"streamBuffers",
".",
"WritableStreamBuffer",
"(",
")",
";",
"output",
".",
"on",
"(",
"\"finish\"",
",",
"(",
")",
"=>",
"{",
"resolve",
"(",
"output",
".",
"getContents",
"(",
")",
")",
";",
"}",
")",
";",
"zipFile",
".",
"outputStream",
".",
"pipe",
"(",
"output",
")",
";",
"}",
")",
")",
";",
"}"
] |
Create a buffer of the zip file
@typedef {{file: File, fullPath: string}} FileEntry
@param {Map<string, File>} fileMap
@return {Promise<Buffer>}
|
[
"Create",
"a",
"buffer",
"of",
"the",
"zip",
"file"
] |
585e081ad8f1ddefe8f1b6e6b41eebfd20a7a2bb
|
https://github.com/kintone/plugin-packer/blob/585e081ad8f1ddefe8f1b6e6b41eebfd20a7a2bb/site/dom.js#L169-L193
|
train
|
kintone/plugin-packer
|
src/index.js
|
zip
|
function zip(contentsZip, publicKey, signature) {
debug(`zip(): start`);
return new Promise((res, rej) => {
const output = new streamBuffers.WritableStreamBuffer();
const zipFile = new ZipFile();
output.on("finish", () => {
debug(`zip(): output finish event`);
res(output.getContents());
});
zipFile.outputStream.pipe(output);
zipFile.addBuffer(contentsZip, "contents.zip");
zipFile.addBuffer(publicKey, "PUBKEY");
zipFile.addBuffer(signature, "SIGNATURE");
zipFile.end(finalSize => {
debug(`zip(): ZipFile end event: finalSize ${finalSize} bytes`);
});
});
}
|
javascript
|
function zip(contentsZip, publicKey, signature) {
debug(`zip(): start`);
return new Promise((res, rej) => {
const output = new streamBuffers.WritableStreamBuffer();
const zipFile = new ZipFile();
output.on("finish", () => {
debug(`zip(): output finish event`);
res(output.getContents());
});
zipFile.outputStream.pipe(output);
zipFile.addBuffer(contentsZip, "contents.zip");
zipFile.addBuffer(publicKey, "PUBKEY");
zipFile.addBuffer(signature, "SIGNATURE");
zipFile.end(finalSize => {
debug(`zip(): ZipFile end event: finalSize ${finalSize} bytes`);
});
});
}
|
[
"function",
"zip",
"(",
"contentsZip",
",",
"publicKey",
",",
"signature",
")",
"{",
"debug",
"(",
"`",
"`",
")",
";",
"return",
"new",
"Promise",
"(",
"(",
"res",
",",
"rej",
")",
"=>",
"{",
"const",
"output",
"=",
"new",
"streamBuffers",
".",
"WritableStreamBuffer",
"(",
")",
";",
"const",
"zipFile",
"=",
"new",
"ZipFile",
"(",
")",
";",
"output",
".",
"on",
"(",
"\"finish\"",
",",
"(",
")",
"=>",
"{",
"debug",
"(",
"`",
"`",
")",
";",
"res",
"(",
"output",
".",
"getContents",
"(",
")",
")",
";",
"}",
")",
";",
"zipFile",
".",
"outputStream",
".",
"pipe",
"(",
"output",
")",
";",
"zipFile",
".",
"addBuffer",
"(",
"contentsZip",
",",
"\"contents.zip\"",
")",
";",
"zipFile",
".",
"addBuffer",
"(",
"publicKey",
",",
"\"PUBKEY\"",
")",
";",
"zipFile",
".",
"addBuffer",
"(",
"signature",
",",
"\"SIGNATURE\"",
")",
";",
"zipFile",
".",
"end",
"(",
"finalSize",
"=>",
"{",
"debug",
"(",
"`",
"${",
"finalSize",
"}",
"`",
")",
";",
"}",
")",
";",
"}",
")",
";",
"}"
] |
Create plugin.zip
@param {!Buffer} contentsZip
@param {!Buffer} publicKey
@param {!Buffer} signature
@return {!Promise<!Buffer>}
|
[
"Create",
"plugin",
".",
"zip"
] |
585e081ad8f1ddefe8f1b6e6b41eebfd20a7a2bb
|
https://github.com/kintone/plugin-packer/blob/585e081ad8f1ddefe8f1b6e6b41eebfd20a7a2bb/src/index.js#L49-L66
|
train
|
kintone/plugin-packer
|
src/zip.js
|
rezip
|
function rezip(contentsZip) {
return preprocessToRezip(contentsZip).then(
({ zipFile, entries, manifestJson, manifestPath }) => {
validateManifest(entries, manifestJson, manifestPath);
return rezipContents(zipFile, entries, manifestJson, manifestPath);
}
);
}
|
javascript
|
function rezip(contentsZip) {
return preprocessToRezip(contentsZip).then(
({ zipFile, entries, manifestJson, manifestPath }) => {
validateManifest(entries, manifestJson, manifestPath);
return rezipContents(zipFile, entries, manifestJson, manifestPath);
}
);
}
|
[
"function",
"rezip",
"(",
"contentsZip",
")",
"{",
"return",
"preprocessToRezip",
"(",
"contentsZip",
")",
".",
"then",
"(",
"(",
"{",
"zipFile",
",",
"entries",
",",
"manifestJson",
",",
"manifestPath",
"}",
")",
"=>",
"{",
"validateManifest",
"(",
"entries",
",",
"manifestJson",
",",
"manifestPath",
")",
";",
"return",
"rezipContents",
"(",
"zipFile",
",",
"entries",
",",
"manifestJson",
",",
"manifestPath",
")",
";",
"}",
")",
";",
"}"
] |
Extract, validate and rezip contents.zip
@param {!Buffer} contentsZip The zipped plugin contents directory.
@return {!Promise<!Buffer>}
|
[
"Extract",
"validate",
"and",
"rezip",
"contents",
".",
"zip"
] |
585e081ad8f1ddefe8f1b6e6b41eebfd20a7a2bb
|
https://github.com/kintone/plugin-packer/blob/585e081ad8f1ddefe8f1b6e6b41eebfd20a7a2bb/src/zip.js#L19-L26
|
train
|
kintone/plugin-packer
|
src/zip.js
|
validateContentsZip
|
function validateContentsZip(contentsZip) {
return preprocessToRezip(contentsZip).then(
({ entries, manifestJson, manifestPath }) =>
validateManifest(entries, manifestJson, manifestPath)
);
}
|
javascript
|
function validateContentsZip(contentsZip) {
return preprocessToRezip(contentsZip).then(
({ entries, manifestJson, manifestPath }) =>
validateManifest(entries, manifestJson, manifestPath)
);
}
|
[
"function",
"validateContentsZip",
"(",
"contentsZip",
")",
"{",
"return",
"preprocessToRezip",
"(",
"contentsZip",
")",
".",
"then",
"(",
"(",
"{",
"entries",
",",
"manifestJson",
",",
"manifestPath",
"}",
")",
"=>",
"validateManifest",
"(",
"entries",
",",
"manifestJson",
",",
"manifestPath",
")",
")",
";",
"}"
] |
Validate a buffer of contents.zip
@param {!Buffer} contentsZip
@return {!Promise<*>}
|
[
"Validate",
"a",
"buffer",
"of",
"contents",
".",
"zip"
] |
585e081ad8f1ddefe8f1b6e6b41eebfd20a7a2bb
|
https://github.com/kintone/plugin-packer/blob/585e081ad8f1ddefe8f1b6e6b41eebfd20a7a2bb/src/zip.js#L33-L38
|
train
|
kintone/plugin-packer
|
src/zip.js
|
preprocessToRezip
|
function preprocessToRezip(contentsZip) {
return zipEntriesFromBuffer(contentsZip).then(result => {
const manifestList = Array.from(result.entries.keys()).filter(
file => path.basename(file) === "manifest.json"
);
if (manifestList.length === 0) {
throw new Error("The zip file has no manifest.json");
} else if (manifestList.length > 1) {
throw new Error("The zip file has many manifest.json files");
}
result.manifestPath = manifestList[0];
const manifestEntry = result.entries.get(result.manifestPath);
return getManifestJsonFromEntry(result.zipFile, manifestEntry).then(json =>
Object.assign(result, { manifestJson: json })
);
});
}
|
javascript
|
function preprocessToRezip(contentsZip) {
return zipEntriesFromBuffer(contentsZip).then(result => {
const manifestList = Array.from(result.entries.keys()).filter(
file => path.basename(file) === "manifest.json"
);
if (manifestList.length === 0) {
throw new Error("The zip file has no manifest.json");
} else if (manifestList.length > 1) {
throw new Error("The zip file has many manifest.json files");
}
result.manifestPath = manifestList[0];
const manifestEntry = result.entries.get(result.manifestPath);
return getManifestJsonFromEntry(result.zipFile, manifestEntry).then(json =>
Object.assign(result, { manifestJson: json })
);
});
}
|
[
"function",
"preprocessToRezip",
"(",
"contentsZip",
")",
"{",
"return",
"zipEntriesFromBuffer",
"(",
"contentsZip",
")",
".",
"then",
"(",
"result",
"=>",
"{",
"const",
"manifestList",
"=",
"Array",
".",
"from",
"(",
"result",
".",
"entries",
".",
"keys",
"(",
")",
")",
".",
"filter",
"(",
"file",
"=>",
"path",
".",
"basename",
"(",
"file",
")",
"===",
"\"manifest.json\"",
")",
";",
"if",
"(",
"manifestList",
".",
"length",
"===",
"0",
")",
"{",
"throw",
"new",
"Error",
"(",
"\"The zip file has no manifest.json\"",
")",
";",
"}",
"else",
"if",
"(",
"manifestList",
".",
"length",
">",
"1",
")",
"{",
"throw",
"new",
"Error",
"(",
"\"The zip file has many manifest.json files\"",
")",
";",
"}",
"result",
".",
"manifestPath",
"=",
"manifestList",
"[",
"0",
"]",
";",
"const",
"manifestEntry",
"=",
"result",
".",
"entries",
".",
"get",
"(",
"result",
".",
"manifestPath",
")",
";",
"return",
"getManifestJsonFromEntry",
"(",
"result",
".",
"zipFile",
",",
"manifestEntry",
")",
".",
"then",
"(",
"json",
"=>",
"Object",
".",
"assign",
"(",
"result",
",",
"{",
"manifestJson",
":",
"json",
"}",
")",
")",
";",
"}",
")",
";",
"}"
] |
Create an intermediate representation for contents.zip
@typedef {{zipFile: !yauzl.ZipFile,entries: !Map<string, !yauzl.ZipEntry>, manifestJson: Object, manifestPath: string}} PreprocessedContentsZip
@param {!Buffer} contentsZip
@return {Promise<PreprocessedContentsZip>}
|
[
"Create",
"an",
"intermediate",
"representation",
"for",
"contents",
".",
"zip"
] |
585e081ad8f1ddefe8f1b6e6b41eebfd20a7a2bb
|
https://github.com/kintone/plugin-packer/blob/585e081ad8f1ddefe8f1b6e6b41eebfd20a7a2bb/src/zip.js#L46-L62
|
train
|
kintone/plugin-packer
|
src/cli.js
|
validateRelativePath
|
function validateRelativePath(pluginDir) {
return str => {
try {
const stat = fs.statSync(path.join(pluginDir, str));
return stat.isFile();
} catch (e) {
return false;
}
};
}
|
javascript
|
function validateRelativePath(pluginDir) {
return str => {
try {
const stat = fs.statSync(path.join(pluginDir, str));
return stat.isFile();
} catch (e) {
return false;
}
};
}
|
[
"function",
"validateRelativePath",
"(",
"pluginDir",
")",
"{",
"return",
"str",
"=>",
"{",
"try",
"{",
"const",
"stat",
"=",
"fs",
".",
"statSync",
"(",
"path",
".",
"join",
"(",
"pluginDir",
",",
"str",
")",
")",
";",
"return",
"stat",
".",
"isFile",
"(",
")",
";",
"}",
"catch",
"(",
"e",
")",
"{",
"return",
"false",
";",
"}",
"}",
";",
"}"
] |
Return validator for `relative-path` format
@param {string} pluginDir
@return {function(string): boolean}
|
[
"Return",
"validator",
"for",
"relative",
"-",
"path",
"format"
] |
585e081ad8f1ddefe8f1b6e6b41eebfd20a7a2bb
|
https://github.com/kintone/plugin-packer/blob/585e081ad8f1ddefe8f1b6e6b41eebfd20a7a2bb/src/cli.js#L163-L172
|
train
|
kintone/plugin-packer
|
src/cli.js
|
validateMaxFileSize
|
function validateMaxFileSize(pluginDir) {
return (maxBytes, filePath) => {
try {
const stat = fs.statSync(path.join(pluginDir, filePath));
return stat.size <= maxBytes;
} catch (e) {
return false;
}
};
}
|
javascript
|
function validateMaxFileSize(pluginDir) {
return (maxBytes, filePath) => {
try {
const stat = fs.statSync(path.join(pluginDir, filePath));
return stat.size <= maxBytes;
} catch (e) {
return false;
}
};
}
|
[
"function",
"validateMaxFileSize",
"(",
"pluginDir",
")",
"{",
"return",
"(",
"maxBytes",
",",
"filePath",
")",
"=>",
"{",
"try",
"{",
"const",
"stat",
"=",
"fs",
".",
"statSync",
"(",
"path",
".",
"join",
"(",
"pluginDir",
",",
"filePath",
")",
")",
";",
"return",
"stat",
".",
"size",
"<=",
"maxBytes",
";",
"}",
"catch",
"(",
"e",
")",
"{",
"return",
"false",
";",
"}",
"}",
";",
"}"
] |
Return validator for `maxFileSize` keyword
@param {string} pluginDir
@return {function(number, string): boolean}
|
[
"Return",
"validator",
"for",
"maxFileSize",
"keyword"
] |
585e081ad8f1ddefe8f1b6e6b41eebfd20a7a2bb
|
https://github.com/kintone/plugin-packer/blob/585e081ad8f1ddefe8f1b6e6b41eebfd20a7a2bb/src/cli.js#L180-L189
|
train
|
kintone/plugin-packer
|
src/hex2a.js
|
hex2a
|
function hex2a(hex) {
return Array.from(hex)
.map(s => {
if (s >= "0" && s <= "9") {
return String.fromCharCode(s.charCodeAt(0) + N_TO_A);
} else if (s >= "a" && s <= "f") {
return String.fromCharCode(s.charCodeAt(0) + A_TO_K);
}
throw new Error(`invalid char: ${s}`);
})
.join("");
}
|
javascript
|
function hex2a(hex) {
return Array.from(hex)
.map(s => {
if (s >= "0" && s <= "9") {
return String.fromCharCode(s.charCodeAt(0) + N_TO_A);
} else if (s >= "a" && s <= "f") {
return String.fromCharCode(s.charCodeAt(0) + A_TO_K);
}
throw new Error(`invalid char: ${s}`);
})
.join("");
}
|
[
"function",
"hex2a",
"(",
"hex",
")",
"{",
"return",
"Array",
".",
"from",
"(",
"hex",
")",
".",
"map",
"(",
"s",
"=>",
"{",
"if",
"(",
"s",
">=",
"\"0\"",
"&&",
"s",
"<=",
"\"9\"",
")",
"{",
"return",
"String",
".",
"fromCharCode",
"(",
"s",
".",
"charCodeAt",
"(",
"0",
")",
"+",
"N_TO_A",
")",
";",
"}",
"else",
"if",
"(",
"s",
">=",
"\"a\"",
"&&",
"s",
"<=",
"\"f\"",
")",
"{",
"return",
"String",
".",
"fromCharCode",
"(",
"s",
".",
"charCodeAt",
"(",
"0",
")",
"+",
"A_TO_K",
")",
";",
"}",
"throw",
"new",
"Error",
"(",
"`",
"${",
"s",
"}",
"`",
")",
";",
"}",
")",
".",
"join",
"(",
"\"\"",
")",
";",
"}"
] |
`tr '0-9a-f' 'a-p'` in JS
@param {string} hex like '8a7f7d'
@return {string}
|
[
"tr",
"0",
"-",
"9a",
"-",
"f",
"a",
"-",
"p",
"in",
"JS"
] |
585e081ad8f1ddefe8f1b6e6b41eebfd20a7a2bb
|
https://github.com/kintone/plugin-packer/blob/585e081ad8f1ddefe8f1b6e6b41eebfd20a7a2bb/src/hex2a.js#L12-L23
|
train
|
xenophilicibex/react-kronos
|
src/styles.js
|
index
|
function index(options) {
return {
kronos: {
position: 'relative',
display: 'flex',
color: 'hsl(0, 0%, 50%)',
'& *': {
fontFamily: options.font,
boxSizing: 'border-box',
userSelect: 'none',
},
},
input: {
border: '1px solid transparent',
borderRadius: options.corners,
borderColor: color(options.color)
.alpha(0.2)
.rgbString(),
fontSize: 16,
padding: '3px 6px',
background: 'white',
'&.outside-range': {
color: 'white',
background: '#d0021b',
},
'&:hover': {
cursor: options.inputDisabled ? 'not-allowed' : 'default',
},
'&:focus': {
outline: 'none',
borderColor: color(options.color)
.alpha(0.5)
.rgbString(),
},
},
}
}
|
javascript
|
function index(options) {
return {
kronos: {
position: 'relative',
display: 'flex',
color: 'hsl(0, 0%, 50%)',
'& *': {
fontFamily: options.font,
boxSizing: 'border-box',
userSelect: 'none',
},
},
input: {
border: '1px solid transparent',
borderRadius: options.corners,
borderColor: color(options.color)
.alpha(0.2)
.rgbString(),
fontSize: 16,
padding: '3px 6px',
background: 'white',
'&.outside-range': {
color: 'white',
background: '#d0021b',
},
'&:hover': {
cursor: options.inputDisabled ? 'not-allowed' : 'default',
},
'&:focus': {
outline: 'none',
borderColor: color(options.color)
.alpha(0.5)
.rgbString(),
},
},
}
}
|
[
"function",
"index",
"(",
"options",
")",
"{",
"return",
"{",
"kronos",
":",
"{",
"position",
":",
"'relative'",
",",
"display",
":",
"'flex'",
",",
"color",
":",
"'hsl(0, 0%, 50%)'",
",",
"'& *'",
":",
"{",
"fontFamily",
":",
"options",
".",
"font",
",",
"boxSizing",
":",
"'border-box'",
",",
"userSelect",
":",
"'none'",
",",
"}",
",",
"}",
",",
"input",
":",
"{",
"border",
":",
"'1px solid transparent'",
",",
"borderRadius",
":",
"options",
".",
"corners",
",",
"borderColor",
":",
"color",
"(",
"options",
".",
"color",
")",
".",
"alpha",
"(",
"0.2",
")",
".",
"rgbString",
"(",
")",
",",
"fontSize",
":",
"16",
",",
"padding",
":",
"'3px 6px'",
",",
"background",
":",
"'white'",
",",
"'&.outside-range'",
":",
"{",
"color",
":",
"'white'",
",",
"background",
":",
"'#d0021b'",
",",
"}",
",",
"'&:hover'",
":",
"{",
"cursor",
":",
"options",
".",
"inputDisabled",
"?",
"'not-allowed'",
":",
"'default'",
",",
"}",
",",
"'&:focus'",
":",
"{",
"outline",
":",
"'none'",
",",
"borderColor",
":",
"color",
"(",
"options",
".",
"color",
")",
".",
"alpha",
"(",
"0.5",
")",
".",
"rgbString",
"(",
")",
",",
"}",
",",
"}",
",",
"}",
"}"
] |
Styles for each page
|
[
"Styles",
"for",
"each",
"page"
] |
4883ebb347fb85359d6a8bb0f47c5f29fec4a645
|
https://github.com/xenophilicibex/react-kronos/blob/4883ebb347fb85359d6a8bb0f47c5f29fec4a645/src/styles.js#L70-L106
|
train
|
basisjs/basisjs
|
src/basis/data/object.js
|
function(name, source){
var oldSource = this.sources[name];
if (name in this.fields.sources == false)
{
/** @cut */ basis.dev.warn('basis.data.object.Merge#setSource: can\'t set source with name `' + name + '` as not specified by fields configuration');
return;
}
// ignore set source for self fields
if (name == '-')
return;
// create context for name if not exists yet
if (name in this.sourcesContext_ == false)
this.sourcesContext_[name] = {
host: this,
name: name,
adapter: null
};
// resolve object from value
source = resolveObject(this.sourcesContext_[name], resolveSetSource, source, 'adapter', this);
// main part
if (oldSource !== source)
{
var listenHandler = this.listen['source:' + name];
// remove handler from old source if present
if (oldSource)
{
if (listenHandler)
oldSource.removeHandler(listenHandler, this);
oldSource.removeHandler(MERGE_SOURCE_HANDLER, this.sourcesContext_[name]);
}
// set new source value
this.sources[name] = source;
// add handler to new source
if (source)
{
source.addHandler(MERGE_SOURCE_HANDLER, this.sourcesContext_[name]);
if (listenHandler)
source.addHandler(listenHandler, this);
// apply new source data
var newData = this.fields.sources[name](source.data);
// reset properties missed in new source if source is defaultSource
if (this.fields.defaultSource == name)
for (var key in this.data)
if (!this.fields.fieldSource.hasOwnProperty(key) && !newData.hasOwnProperty(key))
newData[key] = undefined;
this.update(newData);
}
this.emit_sourceChanged(name, oldSource);
}
}
|
javascript
|
function(name, source){
var oldSource = this.sources[name];
if (name in this.fields.sources == false)
{
/** @cut */ basis.dev.warn('basis.data.object.Merge#setSource: can\'t set source with name `' + name + '` as not specified by fields configuration');
return;
}
// ignore set source for self fields
if (name == '-')
return;
// create context for name if not exists yet
if (name in this.sourcesContext_ == false)
this.sourcesContext_[name] = {
host: this,
name: name,
adapter: null
};
// resolve object from value
source = resolveObject(this.sourcesContext_[name], resolveSetSource, source, 'adapter', this);
// main part
if (oldSource !== source)
{
var listenHandler = this.listen['source:' + name];
// remove handler from old source if present
if (oldSource)
{
if (listenHandler)
oldSource.removeHandler(listenHandler, this);
oldSource.removeHandler(MERGE_SOURCE_HANDLER, this.sourcesContext_[name]);
}
// set new source value
this.sources[name] = source;
// add handler to new source
if (source)
{
source.addHandler(MERGE_SOURCE_HANDLER, this.sourcesContext_[name]);
if (listenHandler)
source.addHandler(listenHandler, this);
// apply new source data
var newData = this.fields.sources[name](source.data);
// reset properties missed in new source if source is defaultSource
if (this.fields.defaultSource == name)
for (var key in this.data)
if (!this.fields.fieldSource.hasOwnProperty(key) && !newData.hasOwnProperty(key))
newData[key] = undefined;
this.update(newData);
}
this.emit_sourceChanged(name, oldSource);
}
}
|
[
"function",
"(",
"name",
",",
"source",
")",
"{",
"var",
"oldSource",
"=",
"this",
".",
"sources",
"[",
"name",
"]",
";",
"if",
"(",
"name",
"in",
"this",
".",
"fields",
".",
"sources",
"==",
"false",
")",
"{",
"basis",
".",
"dev",
".",
"warn",
"(",
"'basis.data.object.Merge#setSource: can\\'t set source with name `'",
"+",
"\\'",
"+",
"name",
")",
";",
"'` as not specified by fields configuration'",
"}",
"return",
";",
"if",
"(",
"name",
"==",
"'-'",
")",
"return",
";",
"if",
"(",
"name",
"in",
"this",
".",
"sourcesContext_",
"==",
"false",
")",
"this",
".",
"sourcesContext_",
"[",
"name",
"]",
"=",
"{",
"host",
":",
"this",
",",
"name",
":",
"name",
",",
"adapter",
":",
"null",
"}",
";",
"source",
"=",
"resolveObject",
"(",
"this",
".",
"sourcesContext_",
"[",
"name",
"]",
",",
"resolveSetSource",
",",
"source",
",",
"'adapter'",
",",
"this",
")",
";",
"}"
] |
Set new value for some source name.
@param {string} name Source name.
@param {DataObject} source Value for source name.
|
[
"Set",
"new",
"value",
"for",
"some",
"source",
"name",
"."
] |
8571903014b207a09d45ad2d1bfba277bf21289b
|
https://github.com/basisjs/basisjs/blob/8571903014b207a09d45ad2d1bfba277bf21289b/src/basis/data/object.js#L396-L459
|
train
|
|
basisjs/basisjs
|
src/basis/cssom.js
|
compatibleStyleSheetInsertRule
|
function compatibleStyleSheetInsertRule(rule, index){
// fetch selector and style from rule description
var m = rule.match(/^([^{]+)\{(.*)\}\s*$/);
if (m)
{
var selectors = m[1].trim().split(/\s*,\s*/);
for (var i = 0; i < selectors.length; i++)
this.addRule(selectors[i], m[2] || null, index++);
return index - 1;
}
/** @cut */ throw new Error('Syntax error in CSS rule to be added');
}
|
javascript
|
function compatibleStyleSheetInsertRule(rule, index){
// fetch selector and style from rule description
var m = rule.match(/^([^{]+)\{(.*)\}\s*$/);
if (m)
{
var selectors = m[1].trim().split(/\s*,\s*/);
for (var i = 0; i < selectors.length; i++)
this.addRule(selectors[i], m[2] || null, index++);
return index - 1;
}
/** @cut */ throw new Error('Syntax error in CSS rule to be added');
}
|
[
"function",
"compatibleStyleSheetInsertRule",
"(",
"rule",
",",
"index",
")",
"{",
"var",
"m",
"=",
"rule",
".",
"match",
"(",
"/",
"^([^{]+)\\{(.*)\\}\\s*$",
"/",
")",
";",
"if",
"(",
"m",
")",
"{",
"var",
"selectors",
"=",
"m",
"[",
"1",
"]",
".",
"trim",
"(",
")",
".",
"split",
"(",
"/",
"\\s*,\\s*",
"/",
")",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"selectors",
".",
"length",
";",
"i",
"++",
")",
"this",
".",
"addRule",
"(",
"selectors",
"[",
"i",
"]",
",",
"m",
"[",
"2",
"]",
"||",
"null",
",",
"index",
"++",
")",
";",
"return",
"index",
"-",
"1",
";",
"}",
"throw",
"new",
"Error",
"(",
"'Syntax error in CSS rule to be added'",
")",
";",
"}"
] |
working with stylesheets
|
[
"working",
"with",
"stylesheets"
] |
8571903014b207a09d45ad2d1bfba277bf21289b
|
https://github.com/basisjs/basisjs/blob/8571903014b207a09d45ad2d1bfba277bf21289b/src/basis/cssom.js#L77-L89
|
train
|
basisjs/basisjs
|
src/basis/cssom.js
|
getStyleSheet
|
function getStyleSheet(id, createIfNotExists){
if (!id)
id = 'DefaultGenericStyleSheet';
if (!cssStyleSheets[id])
if (createIfNotExists)
cssStyleSheets[id] = new StyleSheet(addStyleSheet());
return cssStyleSheets[id];
}
|
javascript
|
function getStyleSheet(id, createIfNotExists){
if (!id)
id = 'DefaultGenericStyleSheet';
if (!cssStyleSheets[id])
if (createIfNotExists)
cssStyleSheets[id] = new StyleSheet(addStyleSheet());
return cssStyleSheets[id];
}
|
[
"function",
"getStyleSheet",
"(",
"id",
",",
"createIfNotExists",
")",
"{",
"if",
"(",
"!",
"id",
")",
"id",
"=",
"'DefaultGenericStyleSheet'",
";",
"if",
"(",
"!",
"cssStyleSheets",
"[",
"id",
"]",
")",
"if",
"(",
"createIfNotExists",
")",
"cssStyleSheets",
"[",
"id",
"]",
"=",
"new",
"StyleSheet",
"(",
"addStyleSheet",
"(",
")",
")",
";",
"return",
"cssStyleSheets",
"[",
"id",
"]",
";",
"}"
] |
Returns generic stylesheet by it's id.
@param {string=} id
@param {boolean=} createIfNotExists
@return {basis.cssom.StyleSheet}
|
[
"Returns",
"generic",
"stylesheet",
"by",
"it",
"s",
"id",
"."
] |
8571903014b207a09d45ad2d1bfba277bf21289b
|
https://github.com/basisjs/basisjs/blob/8571903014b207a09d45ad2d1bfba277bf21289b/src/basis/cssom.js#L132-L141
|
train
|
basisjs/basisjs
|
src/basis/cssom.js
|
setStyleProperty
|
function setStyleProperty(node, property, value){
var mapping = styleMapping[property];
var key = mapping ? mapping.key : camelize(property.replace(/^-ms-/, 'ms-'));
if (!key)
return;
if (mapping && mapping.getter)
value = mapping.getter(value);
var imp = !!IMPORTANT_REGEXP.test(value);
var style = node.style;
if (imp || isPropertyImportant(style, property))
{
value = value.replace(IMPORTANT_REGEXP, '');
if (style.setProperty)
{
// W3C scheme
// if property exists and important, remove it
if (!imp)
// Can't use removeProperty() because it wont remove !important rules in Chrome.
style.setProperty(property, '');
// set new value for property
style.setProperty(property, value, (imp ? IMPORTANT : ''));
}
else
{
// IE8- scheme
var newValue = key + ': ' + value + (imp ? ' !' + IMPORTANT : '') + ';';
var rxText = style[key] ? property + '\\s*:\\s*' + style[key] + '(\\s*!' + IMPORTANT + ')?\\s*;?' : '^';
try {
style.cssText = style.cssText.replace(new RegExp(rxText, 'i'), newValue);
} catch(e) {
/** @cut */ basis.dev.warn('basis.cssom.setStyleProperty: Can\'t set wrong value `' + value + '` for ' + key + ' property');
}
}
}
else
{
if (SET_STYLE_EXCEPTION_BUG)
{
// IE6-8 throw exception when assign wrong value to style, but standart
// says just ignore this assignments
// try/catch is speedless, therefore wrap this statement only for ie
// it makes code safe and more compatible
try {
node.style[key] = value;
} catch(e) {
/** @cut */ basis.dev.warn('basis.cssom.setStyleProperty: Can\'t set wrong value `' + value + '` for ' + key + ' property');
}
}
else
node.style[key] = value;
return node.style[key];
}
}
|
javascript
|
function setStyleProperty(node, property, value){
var mapping = styleMapping[property];
var key = mapping ? mapping.key : camelize(property.replace(/^-ms-/, 'ms-'));
if (!key)
return;
if (mapping && mapping.getter)
value = mapping.getter(value);
var imp = !!IMPORTANT_REGEXP.test(value);
var style = node.style;
if (imp || isPropertyImportant(style, property))
{
value = value.replace(IMPORTANT_REGEXP, '');
if (style.setProperty)
{
// W3C scheme
// if property exists and important, remove it
if (!imp)
// Can't use removeProperty() because it wont remove !important rules in Chrome.
style.setProperty(property, '');
// set new value for property
style.setProperty(property, value, (imp ? IMPORTANT : ''));
}
else
{
// IE8- scheme
var newValue = key + ': ' + value + (imp ? ' !' + IMPORTANT : '') + ';';
var rxText = style[key] ? property + '\\s*:\\s*' + style[key] + '(\\s*!' + IMPORTANT + ')?\\s*;?' : '^';
try {
style.cssText = style.cssText.replace(new RegExp(rxText, 'i'), newValue);
} catch(e) {
/** @cut */ basis.dev.warn('basis.cssom.setStyleProperty: Can\'t set wrong value `' + value + '` for ' + key + ' property');
}
}
}
else
{
if (SET_STYLE_EXCEPTION_BUG)
{
// IE6-8 throw exception when assign wrong value to style, but standart
// says just ignore this assignments
// try/catch is speedless, therefore wrap this statement only for ie
// it makes code safe and more compatible
try {
node.style[key] = value;
} catch(e) {
/** @cut */ basis.dev.warn('basis.cssom.setStyleProperty: Can\'t set wrong value `' + value + '` for ' + key + ' property');
}
}
else
node.style[key] = value;
return node.style[key];
}
}
|
[
"function",
"setStyleProperty",
"(",
"node",
",",
"property",
",",
"value",
")",
"{",
"var",
"mapping",
"=",
"styleMapping",
"[",
"property",
"]",
";",
"var",
"key",
"=",
"mapping",
"?",
"mapping",
".",
"key",
":",
"camelize",
"(",
"property",
".",
"replace",
"(",
"/",
"^-ms-",
"/",
",",
"'ms-'",
")",
")",
";",
"if",
"(",
"!",
"key",
")",
"return",
";",
"if",
"(",
"mapping",
"&&",
"mapping",
".",
"getter",
")",
"value",
"=",
"mapping",
".",
"getter",
"(",
"value",
")",
";",
"var",
"imp",
"=",
"!",
"!",
"IMPORTANT_REGEXP",
".",
"test",
"(",
"value",
")",
";",
"var",
"style",
"=",
"node",
".",
"style",
";",
"if",
"(",
"imp",
"||",
"isPropertyImportant",
"(",
"style",
",",
"property",
")",
")",
"{",
"value",
"=",
"value",
".",
"replace",
"(",
"IMPORTANT_REGEXP",
",",
"''",
")",
";",
"if",
"(",
"style",
".",
"setProperty",
")",
"{",
"if",
"(",
"!",
"imp",
")",
"style",
".",
"setProperty",
"(",
"property",
",",
"''",
")",
";",
"style",
".",
"setProperty",
"(",
"property",
",",
"value",
",",
"(",
"imp",
"?",
"IMPORTANT",
":",
"''",
")",
")",
";",
"}",
"else",
"{",
"var",
"newValue",
"=",
"key",
"+",
"': '",
"+",
"value",
"+",
"(",
"imp",
"?",
"' !'",
"+",
"IMPORTANT",
":",
"''",
")",
"+",
"';'",
";",
"var",
"rxText",
"=",
"style",
"[",
"key",
"]",
"?",
"property",
"+",
"'\\\\s*:\\\\s*'",
"+",
"\\\\",
"+",
"\\\\",
"+",
"style",
"[",
"key",
"]",
"+",
"'(\\\\s*!'",
":",
"\\\\",
";",
"IMPORTANT",
"}",
"}",
"else",
"')?\\\\s*;?'",
"}"
] |
Apply new style property value for node.
@param {Element} node Node which style to be changed.
@param {string} property Name of property.
@param {string} value Value of property.
@return {*} Returns style property value after assignment.
|
[
"Apply",
"new",
"style",
"property",
"value",
"for",
"node",
"."
] |
8571903014b207a09d45ad2d1bfba277bf21289b
|
https://github.com/basisjs/basisjs/blob/8571903014b207a09d45ad2d1bfba277bf21289b/src/basis/cssom.js#L187-L248
|
train
|
basisjs/basisjs
|
src/basis/cssom.js
|
setStyle
|
function setStyle(node, style){
for (var key in style)
setStyleProperty(node, key, style[key]);
return node;
}
|
javascript
|
function setStyle(node, style){
for (var key in style)
setStyleProperty(node, key, style[key]);
return node;
}
|
[
"function",
"setStyle",
"(",
"node",
",",
"style",
")",
"{",
"for",
"(",
"var",
"key",
"in",
"style",
")",
"setStyleProperty",
"(",
"node",
",",
"key",
",",
"style",
"[",
"key",
"]",
")",
";",
"return",
"node",
";",
"}"
] |
Apply new style properties for node.
@param {Element} node Node which style to be changed.
@param {object} style Object contains new values for node style properties.
@return {Element}
|
[
"Apply",
"new",
"style",
"properties",
"for",
"node",
"."
] |
8571903014b207a09d45ad2d1bfba277bf21289b
|
https://github.com/basisjs/basisjs/blob/8571903014b207a09d45ad2d1bfba277bf21289b/src/basis/cssom.js#L256-L261
|
train
|
basisjs/basisjs
|
src/basis/ui/scrolltable.js
|
function(){
var headerElement = this.header.element;
var footerElement = this.footer ? this.footer.element : null;
//
// Sync header html
//
var headerOuterHTML = domUtils.outerHTML(headerElement);
if (this.shadowHeaderHTML_ != headerOuterHTML)
{
this.shadowHeaderHTML_ = headerOuterHTML;
replaceTemplateNode(this, 'shadowHeader', headerElement.cloneNode(true));
}
//
// Sync footer html
//
if (footerElement)
{
var footerOuterHTML = domUtils.outerHTML(footerElement);
if (this.shadowFooterHtml_ != footerOuterHTML)
{
this.shadowFooterHtml_ = footerOuterHTML;
replaceTemplateNode(this, 'shadowFooter', footerElement.cloneNode(true));
}
}
//
// Sync column width
//
for (var i = 0, column, columnWidth; column = this.columnWidthSync_[i]; i++)
{
columnWidth = column.measure.offsetWidth + 'px';
cssom.setStyleProperty(column.header.firstChild, 'width', columnWidth);
if (footerElement)
cssom.setStyleProperty(column.footer.firstChild, 'width', columnWidth);
}
//
// Calc metrics boxes
//
var tableWidth = this.tmpl.boundElement.offsetWidth || 0;
var headerHeight = headerElement.offsetHeight || 0;
var footerHeight = (footerElement && footerElement.offsetHeight) || 0;
//
// Update style properties
//
this.tmpl.headerExpandCell.style.left = tableWidth + 'px';
this.tmpl.footerExpandCell.style.left = tableWidth + 'px';
this.tmpl.tableElement.style.margin = '-' + headerHeight + 'px 0 -' + footerHeight + 'px';
if (this.fitToContainer)
this.element.style.paddingBottom = (headerHeight + footerHeight) + 'px';
// reset timer
// it should be at the end of relayout to prevent relayout call while relayout
this.timer_ = basis.clearImmediate(this.timer_);
}
|
javascript
|
function(){
var headerElement = this.header.element;
var footerElement = this.footer ? this.footer.element : null;
//
// Sync header html
//
var headerOuterHTML = domUtils.outerHTML(headerElement);
if (this.shadowHeaderHTML_ != headerOuterHTML)
{
this.shadowHeaderHTML_ = headerOuterHTML;
replaceTemplateNode(this, 'shadowHeader', headerElement.cloneNode(true));
}
//
// Sync footer html
//
if (footerElement)
{
var footerOuterHTML = domUtils.outerHTML(footerElement);
if (this.shadowFooterHtml_ != footerOuterHTML)
{
this.shadowFooterHtml_ = footerOuterHTML;
replaceTemplateNode(this, 'shadowFooter', footerElement.cloneNode(true));
}
}
//
// Sync column width
//
for (var i = 0, column, columnWidth; column = this.columnWidthSync_[i]; i++)
{
columnWidth = column.measure.offsetWidth + 'px';
cssom.setStyleProperty(column.header.firstChild, 'width', columnWidth);
if (footerElement)
cssom.setStyleProperty(column.footer.firstChild, 'width', columnWidth);
}
//
// Calc metrics boxes
//
var tableWidth = this.tmpl.boundElement.offsetWidth || 0;
var headerHeight = headerElement.offsetHeight || 0;
var footerHeight = (footerElement && footerElement.offsetHeight) || 0;
//
// Update style properties
//
this.tmpl.headerExpandCell.style.left = tableWidth + 'px';
this.tmpl.footerExpandCell.style.left = tableWidth + 'px';
this.tmpl.tableElement.style.margin = '-' + headerHeight + 'px 0 -' + footerHeight + 'px';
if (this.fitToContainer)
this.element.style.paddingBottom = (headerHeight + footerHeight) + 'px';
// reset timer
// it should be at the end of relayout to prevent relayout call while relayout
this.timer_ = basis.clearImmediate(this.timer_);
}
|
[
"function",
"(",
")",
"{",
"var",
"headerElement",
"=",
"this",
".",
"header",
".",
"element",
";",
"var",
"footerElement",
"=",
"this",
".",
"footer",
"?",
"this",
".",
"footer",
".",
"element",
":",
"null",
";",
"var",
"headerOuterHTML",
"=",
"domUtils",
".",
"outerHTML",
"(",
"headerElement",
")",
";",
"if",
"(",
"this",
".",
"shadowHeaderHTML_",
"!=",
"headerOuterHTML",
")",
"{",
"this",
".",
"shadowHeaderHTML_",
"=",
"headerOuterHTML",
";",
"replaceTemplateNode",
"(",
"this",
",",
"'shadowHeader'",
",",
"headerElement",
".",
"cloneNode",
"(",
"true",
")",
")",
";",
"}",
"if",
"(",
"footerElement",
")",
"{",
"var",
"footerOuterHTML",
"=",
"domUtils",
".",
"outerHTML",
"(",
"footerElement",
")",
";",
"if",
"(",
"this",
".",
"shadowFooterHtml_",
"!=",
"footerOuterHTML",
")",
"{",
"this",
".",
"shadowFooterHtml_",
"=",
"footerOuterHTML",
";",
"replaceTemplateNode",
"(",
"this",
",",
"'shadowFooter'",
",",
"footerElement",
".",
"cloneNode",
"(",
"true",
")",
")",
";",
"}",
"}",
"for",
"(",
"var",
"i",
"=",
"0",
",",
"column",
",",
"columnWidth",
";",
"column",
"=",
"this",
".",
"columnWidthSync_",
"[",
"i",
"]",
";",
"i",
"++",
")",
"{",
"columnWidth",
"=",
"column",
".",
"measure",
".",
"offsetWidth",
"+",
"'px'",
";",
"cssom",
".",
"setStyleProperty",
"(",
"column",
".",
"header",
".",
"firstChild",
",",
"'width'",
",",
"columnWidth",
")",
";",
"if",
"(",
"footerElement",
")",
"cssom",
".",
"setStyleProperty",
"(",
"column",
".",
"footer",
".",
"firstChild",
",",
"'width'",
",",
"columnWidth",
")",
";",
"}",
"var",
"tableWidth",
"=",
"this",
".",
"tmpl",
".",
"boundElement",
".",
"offsetWidth",
"||",
"0",
";",
"var",
"headerHeight",
"=",
"headerElement",
".",
"offsetHeight",
"||",
"0",
";",
"var",
"footerHeight",
"=",
"(",
"footerElement",
"&&",
"footerElement",
".",
"offsetHeight",
")",
"||",
"0",
";",
"this",
".",
"tmpl",
".",
"headerExpandCell",
".",
"style",
".",
"left",
"=",
"tableWidth",
"+",
"'px'",
";",
"this",
".",
"tmpl",
".",
"footerExpandCell",
".",
"style",
".",
"left",
"=",
"tableWidth",
"+",
"'px'",
";",
"this",
".",
"tmpl",
".",
"tableElement",
".",
"style",
".",
"margin",
"=",
"'-'",
"+",
"headerHeight",
"+",
"'px 0 -'",
"+",
"footerHeight",
"+",
"'px'",
";",
"if",
"(",
"this",
".",
"fitToContainer",
")",
"this",
".",
"element",
".",
"style",
".",
"paddingBottom",
"=",
"(",
"headerHeight",
"+",
"footerHeight",
")",
"+",
"'px'",
";",
"this",
".",
"timer_",
"=",
"basis",
".",
"clearImmediate",
"(",
"this",
".",
"timer_",
")",
";",
"}"
] |
Make relayout of table. Should never be used in common cases. Call requestRelayout instead.
|
[
"Make",
"relayout",
"of",
"table",
".",
"Should",
"never",
"be",
"used",
"in",
"common",
"cases",
".",
"Call",
"requestRelayout",
"instead",
"."
] |
8571903014b207a09d45ad2d1bfba277bf21289b
|
https://github.com/basisjs/basisjs/blob/8571903014b207a09d45ad2d1bfba277bf21289b/src/basis/ui/scrolltable.js#L182-L240
|
train
|
|
basisjs/basisjs
|
src/basis/template/declaration/utils.js
|
getLocation
|
function getLocation(template, loc){
if (loc)
return (template.sourceUrl || '') + ':' + loc.start.line + ':' + (loc.start.column + 1);
}
|
javascript
|
function getLocation(template, loc){
if (loc)
return (template.sourceUrl || '') + ':' + loc.start.line + ':' + (loc.start.column + 1);
}
|
[
"function",
"getLocation",
"(",
"template",
",",
"loc",
")",
"{",
"if",
"(",
"loc",
")",
"return",
"(",
"template",
".",
"sourceUrl",
"||",
"''",
")",
"+",
"':'",
"+",
"loc",
".",
"start",
".",
"line",
"+",
"':'",
"+",
"(",
"loc",
".",
"start",
".",
"column",
"+",
"1",
")",
";",
"}"
] |
location and debug
|
[
"location",
"and",
"debug"
] |
8571903014b207a09d45ad2d1bfba277bf21289b
|
https://github.com/basisjs/basisjs/blob/8571903014b207a09d45ad2d1bfba277bf21289b/src/basis/template/declaration/utils.js#L80-L83
|
train
|
basisjs/basisjs
|
src/basis/dom.js
|
handleInsert
|
function handleInsert(node, newNode, refChild){
return newNode != null
? node.insertBefore(isNode(newNode) ? newNode : createText(newNode), refChild || null)
: null;
}
|
javascript
|
function handleInsert(node, newNode, refChild){
return newNode != null
? node.insertBefore(isNode(newNode) ? newNode : createText(newNode), refChild || null)
: null;
}
|
[
"function",
"handleInsert",
"(",
"node",
",",
"newNode",
",",
"refChild",
")",
"{",
"return",
"newNode",
"!=",
"null",
"?",
"node",
".",
"insertBefore",
"(",
"isNode",
"(",
"newNode",
")",
"?",
"newNode",
":",
"createText",
"(",
"newNode",
")",
",",
"refChild",
"||",
"null",
")",
":",
"null",
";",
"}"
] |
Insert newNode into node. If newNode is instance of Node, it insert without change; otherwise it converts to TextNode.
@param {Node} node Target node
@param {Node|*} newNode Inserting node or object.
@param {Node=} refChild Child of node.
@return {Node}
|
[
"Insert",
"newNode",
"into",
"node",
".",
"If",
"newNode",
"is",
"instance",
"of",
"Node",
"it",
"insert",
"without",
"change",
";",
"otherwise",
"it",
"converts",
"to",
"TextNode",
"."
] |
8571903014b207a09d45ad2d1bfba277bf21289b
|
https://github.com/basisjs/basisjs/blob/8571903014b207a09d45ad2d1bfba277bf21289b/src/basis/dom.js#L178-L182
|
train
|
basisjs/basisjs
|
src/basis/dom.js
|
function(filter, result){
var node;
if (!result)
result = [];
this.reset();
while (node = this.next(filter))
result.push(node);
return result;
}
|
javascript
|
function(filter, result){
var node;
if (!result)
result = [];
this.reset();
while (node = this.next(filter))
result.push(node);
return result;
}
|
[
"function",
"(",
"filter",
",",
"result",
")",
"{",
"var",
"node",
";",
"if",
"(",
"!",
"result",
")",
"result",
"=",
"[",
"]",
";",
"this",
".",
"reset",
"(",
")",
";",
"while",
"(",
"node",
"=",
"this",
".",
"next",
"(",
"filter",
")",
")",
"result",
".",
"push",
"(",
"node",
")",
";",
"return",
"result",
";",
"}"
] |
Returns all nodes.
@param {function(object):boolean} filter Override internal filter
@return {Node|object}
|
[
"Returns",
"all",
"nodes",
"."
] |
8571903014b207a09d45ad2d1bfba277bf21289b
|
https://github.com/basisjs/basisjs/blob/8571903014b207a09d45ad2d1bfba277bf21289b/src/basis/dom.js#L283-L295
|
train
|
|
basisjs/basisjs
|
src/basis/dom.js
|
function(filter){
filter = filter || this.filter;
var cursor = this.cursor_ || this.root_;
do
{
var node = cursor[this.a]; // next child
while (!node)
{
if (cursor === this.root_)
return this.cursor_ = null;
node = cursor[this.b]; // next sibling
if (!node)
cursor = cursor[PARENT_NODE];
}
}
while (!filter(cursor = node));
return this.cursor_ = cursor;
}
|
javascript
|
function(filter){
filter = filter || this.filter;
var cursor = this.cursor_ || this.root_;
do
{
var node = cursor[this.a]; // next child
while (!node)
{
if (cursor === this.root_)
return this.cursor_ = null;
node = cursor[this.b]; // next sibling
if (!node)
cursor = cursor[PARENT_NODE];
}
}
while (!filter(cursor = node));
return this.cursor_ = cursor;
}
|
[
"function",
"(",
"filter",
")",
"{",
"filter",
"=",
"filter",
"||",
"this",
".",
"filter",
";",
"var",
"cursor",
"=",
"this",
".",
"cursor_",
"||",
"this",
".",
"root_",
";",
"do",
"{",
"var",
"node",
"=",
"cursor",
"[",
"this",
".",
"a",
"]",
";",
"while",
"(",
"!",
"node",
")",
"{",
"if",
"(",
"cursor",
"===",
"this",
".",
"root_",
")",
"return",
"this",
".",
"cursor_",
"=",
"null",
";",
"node",
"=",
"cursor",
"[",
"this",
".",
"b",
"]",
";",
"if",
"(",
"!",
"node",
")",
"cursor",
"=",
"cursor",
"[",
"PARENT_NODE",
"]",
";",
"}",
"}",
"while",
"(",
"!",
"filter",
"(",
"cursor",
"=",
"node",
")",
")",
";",
"return",
"this",
".",
"cursor_",
"=",
"cursor",
";",
"}"
] |
Returns next node from cursor.
@param {function(object):boolean} filter Override internal filter
@return {Node|object}
|
[
"Returns",
"next",
"node",
"from",
"cursor",
"."
] |
8571903014b207a09d45ad2d1bfba277bf21289b
|
https://github.com/basisjs/basisjs/blob/8571903014b207a09d45ad2d1bfba277bf21289b/src/basis/dom.js#L302-L324
|
train
|
|
basisjs/basisjs
|
src/basis/dom.js
|
function(filter){
filter = filter || this.filter;
var cursor = this.cursor_;
var prevSibling = this.c; // previous sibling
var prevChild = this.d; // previous child
do
{
var node = cursor ? cursor[prevSibling] : this.root_[prevChild];
if (node)
{
while (node[prevChild])
node = node[prevChild];
cursor = node;
}
else
if (cursor)
cursor = cursor[PARENT_NODE];
if (!cursor || cursor === this.root_)
{
cursor = null;
break;
}
}
while (!filter(cursor));
return this.cursor_ = cursor;
}
|
javascript
|
function(filter){
filter = filter || this.filter;
var cursor = this.cursor_;
var prevSibling = this.c; // previous sibling
var prevChild = this.d; // previous child
do
{
var node = cursor ? cursor[prevSibling] : this.root_[prevChild];
if (node)
{
while (node[prevChild])
node = node[prevChild];
cursor = node;
}
else
if (cursor)
cursor = cursor[PARENT_NODE];
if (!cursor || cursor === this.root_)
{
cursor = null;
break;
}
}
while (!filter(cursor));
return this.cursor_ = cursor;
}
|
[
"function",
"(",
"filter",
")",
"{",
"filter",
"=",
"filter",
"||",
"this",
".",
"filter",
";",
"var",
"cursor",
"=",
"this",
".",
"cursor_",
";",
"var",
"prevSibling",
"=",
"this",
".",
"c",
";",
"var",
"prevChild",
"=",
"this",
".",
"d",
";",
"do",
"{",
"var",
"node",
"=",
"cursor",
"?",
"cursor",
"[",
"prevSibling",
"]",
":",
"this",
".",
"root_",
"[",
"prevChild",
"]",
";",
"if",
"(",
"node",
")",
"{",
"while",
"(",
"node",
"[",
"prevChild",
"]",
")",
"node",
"=",
"node",
"[",
"prevChild",
"]",
";",
"cursor",
"=",
"node",
";",
"}",
"else",
"if",
"(",
"cursor",
")",
"cursor",
"=",
"cursor",
"[",
"PARENT_NODE",
"]",
";",
"if",
"(",
"!",
"cursor",
"||",
"cursor",
"===",
"this",
".",
"root_",
")",
"{",
"cursor",
"=",
"null",
";",
"break",
";",
"}",
"}",
"while",
"(",
"!",
"filter",
"(",
"cursor",
")",
")",
";",
"return",
"this",
".",
"cursor_",
"=",
"cursor",
";",
"}"
] |
Returns previous node from cursor.
@param {function(object):boolean} filter Override internal filter
@return {Node|object}
|
[
"Returns",
"previous",
"node",
"from",
"cursor",
"."
] |
8571903014b207a09d45ad2d1bfba277bf21289b
|
https://github.com/basisjs/basisjs/blob/8571903014b207a09d45ad2d1bfba277bf21289b/src/basis/dom.js#L331-L360
|
train
|
|
basisjs/basisjs
|
src/basis/dom.js
|
tag
|
function tag(node, tagName){
var element = get(node) || document;
if (tagName == '*' && element.all)
return arrayFrom(element.all);
else
return arrayFrom(element.getElementsByTagName(tagName || '*'));
}
|
javascript
|
function tag(node, tagName){
var element = get(node) || document;
if (tagName == '*' && element.all)
return arrayFrom(element.all);
else
return arrayFrom(element.getElementsByTagName(tagName || '*'));
}
|
[
"function",
"tag",
"(",
"node",
",",
"tagName",
")",
"{",
"var",
"element",
"=",
"get",
"(",
"node",
")",
"||",
"document",
";",
"if",
"(",
"tagName",
"==",
"'*'",
"&&",
"element",
".",
"all",
")",
"return",
"arrayFrom",
"(",
"element",
".",
"all",
")",
";",
"else",
"return",
"arrayFrom",
"(",
"element",
".",
"getElementsByTagName",
"(",
"tagName",
"||",
"'*'",
")",
")",
";",
"}"
] |
Returns all descendant elements tagName name for node.
@param {string|Node} node Context element.
@param {string} tagName Tag name.
@return {Array.<Element>}
|
[
"Returns",
"all",
"descendant",
"elements",
"tagName",
"name",
"for",
"node",
"."
] |
8571903014b207a09d45ad2d1bfba277bf21289b
|
https://github.com/basisjs/basisjs/blob/8571903014b207a09d45ad2d1bfba277bf21289b/src/basis/dom.js#L419-L426
|
train
|
basisjs/basisjs
|
src/basis/dom.js
|
axis
|
function axis(root, axis, filter){
var result = [];
var walker;
var cursor;
filter = typeof filter == 'string' ? getter(filter) : filter || basis.fn.$true;
if (axis & (AXIS_SELF | AXIS_ANCESTOR_OR_SELF | AXIS_DESCENDANT_OR_SELF))
if (filter(root))
result.push(root);
switch (axis)
{
case AXIS_ANCESTOR:
case AXIS_ANCESTOR_OR_SELF:
cursor = root;
while ((cursor = cursor[PARENT_NODE]) && cursor !== root.document)
if (filter(cursor))
result.push(cursor);
break;
case AXIS_CHILD:
cursor = root[FIRST_CHILD];
while (cursor)
{
if (filter(cursor))
result.push(cursor);
cursor = cursor[NEXT_SIBLING];
}
break;
case AXIS_DESCENDANT:
case AXIS_DESCENDANT_OR_SELF:
if (root[FIRST_CHILD])
{
walker = new TreeWalker(root);
walker.nodes(filter, result);
}
break;
case AXIS_FOLLOWING:
walker = new TreeWalker(root, filter);
walker.cursor_ = root[NEXT_SIBLING] || root[PARENT_NODE];
while (cursor = walker.next())
result.push(cursor);
break;
case AXIS_FOLLOWING_SIBLING:
cursor = root;
while (cursor = cursor[NEXT_SIBLING])
if (filter(cursor))
result.push(cursor);
break;
case AXIS_PARENT:
if (filter(root[PARENT_NODE]))
result.push(root[PARENT_NODE]);
break;
case AXIS_PRECEDING:
walker = new TreeWalker(root, filter, TreeWalker.BACKWARD);
walker.cursor_ = root[PREVIOUS_SIBLING] || root[PARENT_NODE];
while (cursor = walker.next())
result.push(cursor);
break;
case AXIS_PRECEDING_SIBLING:
cursor = root;
while (cursor = cursor[PREVIOUS_SIBLING])
if (filter(cursor))
result.push(cursor);
break;
}
return result;
}
|
javascript
|
function axis(root, axis, filter){
var result = [];
var walker;
var cursor;
filter = typeof filter == 'string' ? getter(filter) : filter || basis.fn.$true;
if (axis & (AXIS_SELF | AXIS_ANCESTOR_OR_SELF | AXIS_DESCENDANT_OR_SELF))
if (filter(root))
result.push(root);
switch (axis)
{
case AXIS_ANCESTOR:
case AXIS_ANCESTOR_OR_SELF:
cursor = root;
while ((cursor = cursor[PARENT_NODE]) && cursor !== root.document)
if (filter(cursor))
result.push(cursor);
break;
case AXIS_CHILD:
cursor = root[FIRST_CHILD];
while (cursor)
{
if (filter(cursor))
result.push(cursor);
cursor = cursor[NEXT_SIBLING];
}
break;
case AXIS_DESCENDANT:
case AXIS_DESCENDANT_OR_SELF:
if (root[FIRST_CHILD])
{
walker = new TreeWalker(root);
walker.nodes(filter, result);
}
break;
case AXIS_FOLLOWING:
walker = new TreeWalker(root, filter);
walker.cursor_ = root[NEXT_SIBLING] || root[PARENT_NODE];
while (cursor = walker.next())
result.push(cursor);
break;
case AXIS_FOLLOWING_SIBLING:
cursor = root;
while (cursor = cursor[NEXT_SIBLING])
if (filter(cursor))
result.push(cursor);
break;
case AXIS_PARENT:
if (filter(root[PARENT_NODE]))
result.push(root[PARENT_NODE]);
break;
case AXIS_PRECEDING:
walker = new TreeWalker(root, filter, TreeWalker.BACKWARD);
walker.cursor_ = root[PREVIOUS_SIBLING] || root[PARENT_NODE];
while (cursor = walker.next())
result.push(cursor);
break;
case AXIS_PRECEDING_SIBLING:
cursor = root;
while (cursor = cursor[PREVIOUS_SIBLING])
if (filter(cursor))
result.push(cursor);
break;
}
return result;
}
|
[
"function",
"axis",
"(",
"root",
",",
"axis",
",",
"filter",
")",
"{",
"var",
"result",
"=",
"[",
"]",
";",
"var",
"walker",
";",
"var",
"cursor",
";",
"filter",
"=",
"typeof",
"filter",
"==",
"'string'",
"?",
"getter",
"(",
"filter",
")",
":",
"filter",
"||",
"basis",
".",
"fn",
".",
"$true",
";",
"if",
"(",
"axis",
"&",
"(",
"AXIS_SELF",
"|",
"AXIS_ANCESTOR_OR_SELF",
"|",
"AXIS_DESCENDANT_OR_SELF",
")",
")",
"if",
"(",
"filter",
"(",
"root",
")",
")",
"result",
".",
"push",
"(",
"root",
")",
";",
"switch",
"(",
"axis",
")",
"{",
"case",
"AXIS_ANCESTOR",
":",
"case",
"AXIS_ANCESTOR_OR_SELF",
":",
"cursor",
"=",
"root",
";",
"while",
"(",
"(",
"cursor",
"=",
"cursor",
"[",
"PARENT_NODE",
"]",
")",
"&&",
"cursor",
"!==",
"root",
".",
"document",
")",
"if",
"(",
"filter",
"(",
"cursor",
")",
")",
"result",
".",
"push",
"(",
"cursor",
")",
";",
"break",
";",
"case",
"AXIS_CHILD",
":",
"cursor",
"=",
"root",
"[",
"FIRST_CHILD",
"]",
";",
"while",
"(",
"cursor",
")",
"{",
"if",
"(",
"filter",
"(",
"cursor",
")",
")",
"result",
".",
"push",
"(",
"cursor",
")",
";",
"cursor",
"=",
"cursor",
"[",
"NEXT_SIBLING",
"]",
";",
"}",
"break",
";",
"case",
"AXIS_DESCENDANT",
":",
"case",
"AXIS_DESCENDANT_OR_SELF",
":",
"if",
"(",
"root",
"[",
"FIRST_CHILD",
"]",
")",
"{",
"walker",
"=",
"new",
"TreeWalker",
"(",
"root",
")",
";",
"walker",
".",
"nodes",
"(",
"filter",
",",
"result",
")",
";",
"}",
"break",
";",
"case",
"AXIS_FOLLOWING",
":",
"walker",
"=",
"new",
"TreeWalker",
"(",
"root",
",",
"filter",
")",
";",
"walker",
".",
"cursor_",
"=",
"root",
"[",
"NEXT_SIBLING",
"]",
"||",
"root",
"[",
"PARENT_NODE",
"]",
";",
"while",
"(",
"cursor",
"=",
"walker",
".",
"next",
"(",
")",
")",
"result",
".",
"push",
"(",
"cursor",
")",
";",
"break",
";",
"case",
"AXIS_FOLLOWING_SIBLING",
":",
"cursor",
"=",
"root",
";",
"while",
"(",
"cursor",
"=",
"cursor",
"[",
"NEXT_SIBLING",
"]",
")",
"if",
"(",
"filter",
"(",
"cursor",
")",
")",
"result",
".",
"push",
"(",
"cursor",
")",
";",
"break",
";",
"case",
"AXIS_PARENT",
":",
"if",
"(",
"filter",
"(",
"root",
"[",
"PARENT_NODE",
"]",
")",
")",
"result",
".",
"push",
"(",
"root",
"[",
"PARENT_NODE",
"]",
")",
";",
"break",
";",
"case",
"AXIS_PRECEDING",
":",
"walker",
"=",
"new",
"TreeWalker",
"(",
"root",
",",
"filter",
",",
"TreeWalker",
".",
"BACKWARD",
")",
";",
"walker",
".",
"cursor_",
"=",
"root",
"[",
"PREVIOUS_SIBLING",
"]",
"||",
"root",
"[",
"PARENT_NODE",
"]",
";",
"while",
"(",
"cursor",
"=",
"walker",
".",
"next",
"(",
")",
")",
"result",
".",
"push",
"(",
"cursor",
")",
";",
"break",
";",
"case",
"AXIS_PRECEDING_SIBLING",
":",
"cursor",
"=",
"root",
";",
"while",
"(",
"cursor",
"=",
"cursor",
"[",
"PREVIOUS_SIBLING",
"]",
")",
"if",
"(",
"filter",
"(",
"cursor",
")",
")",
"result",
".",
"push",
"(",
"cursor",
")",
";",
"break",
";",
"}",
"return",
"result",
";",
"}"
] |
Navigation
Returns nodes axis in XPath like way.
@param {Node} root Relative point for axis.
@param {number} axis Axis constant.
@param {function(node:Node):boolean} filter Filter function. If it's returns true node will be in result list.
@return {Array.<Node>}
|
[
"Navigation",
"Returns",
"nodes",
"axis",
"in",
"XPath",
"like",
"way",
"."
] |
8571903014b207a09d45ad2d1bfba277bf21289b
|
https://github.com/basisjs/basisjs/blob/8571903014b207a09d45ad2d1bfba277bf21289b/src/basis/dom.js#L439-L514
|
train
|
basisjs/basisjs
|
src/basis/dom.js
|
findAncestor
|
function findAncestor(node, matchFunction, bound){
while (node && node !== bound)
{
if (matchFunction(node))
break;
node = node.parentNode;
}
return node || null;
}
|
javascript
|
function findAncestor(node, matchFunction, bound){
while (node && node !== bound)
{
if (matchFunction(node))
break;
node = node.parentNode;
}
return node || null;
}
|
[
"function",
"findAncestor",
"(",
"node",
",",
"matchFunction",
",",
"bound",
")",
"{",
"while",
"(",
"node",
"&&",
"node",
"!==",
"bound",
")",
"{",
"if",
"(",
"matchFunction",
"(",
"node",
")",
")",
"break",
";",
"node",
"=",
"node",
".",
"parentNode",
";",
"}",
"return",
"node",
"||",
"null",
";",
"}"
] |
Returns ancestor that matchFunction returns true for.
@param {Node} node Start node for traversal.
@param {function(node:Node):boolean} matchFunction Checking function.
@param {Node=} bound Don't traversal after bound node.
@return {Node} First ancestor node that pass matchFunction.
|
[
"Returns",
"ancestor",
"that",
"matchFunction",
"returns",
"true",
"for",
"."
] |
8571903014b207a09d45ad2d1bfba277bf21289b
|
https://github.com/basisjs/basisjs/blob/8571903014b207a09d45ad2d1bfba277bf21289b/src/basis/dom.js#L523-L533
|
train
|
basisjs/basisjs
|
src/basis/dom.js
|
createFragment
|
function createFragment(){
var result = document.createDocumentFragment();
var len = arguments.length;
var array = createFragment.array = [];
for (var i = 0; i < len; i++)
array.push(handleInsert(result, arguments[i]));
return result;
}
|
javascript
|
function createFragment(){
var result = document.createDocumentFragment();
var len = arguments.length;
var array = createFragment.array = [];
for (var i = 0; i < len; i++)
array.push(handleInsert(result, arguments[i]));
return result;
}
|
[
"function",
"createFragment",
"(",
")",
"{",
"var",
"result",
"=",
"document",
".",
"createDocumentFragment",
"(",
")",
";",
"var",
"len",
"=",
"arguments",
".",
"length",
";",
"var",
"array",
"=",
"createFragment",
".",
"array",
"=",
"[",
"]",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"len",
";",
"i",
"++",
")",
"array",
".",
"push",
"(",
"handleInsert",
"(",
"result",
",",
"arguments",
"[",
"i",
"]",
")",
")",
";",
"return",
"result",
";",
"}"
] |
Returns new DocumentFragmentNode with arguments as childs.
@param {...Node|string} nodes
@return {DocumentFragment} The new DocumentFragment
|
[
"Returns",
"new",
"DocumentFragmentNode",
"with",
"arguments",
"as",
"childs",
"."
] |
8571903014b207a09d45ad2d1bfba277bf21289b
|
https://github.com/basisjs/basisjs/blob/8571903014b207a09d45ad2d1bfba277bf21289b/src/basis/dom.js#L553-L562
|
train
|
basisjs/basisjs
|
src/basis/dom.js
|
createElement
|
function createElement(config){
var isConfig = config != undefined && typeof config != 'string';
var description = (isConfig ? config.description : config) || '';
var elementName = 'div'; // modern browsers become case sensetive for tag names for xhtml
var element;
// fetch tag name
var m = description.match(/^([a-z0-9_\-]+)(.*)$/i);
if (m)
{
elementName = m[1];
description = m[2];
}
// create an element
if (description != '')
{
// extract properties
var classNames = [];
var attributes = {};
var entryName;
while (m = DESCRIPTION_PART_REGEXP.exec(description))
{
if (m[8])
{
throw new Error(
'Create element error in basis.dom.createElement()' +
'\n\nDescription:\n> ' + description +
'\n\nProblem place:\n> ' + description.substr(0, m.index) + '-->' + description.substr(m.index) + '<--'
);
}
entryName = m[1] || m[2] || m[3];
if (m[1]) // id
attributes.id = entryName;
else
if (m[2]) // class
classNames.push(entryName);
else
{ // attribute
if (entryName != 'class')
attributes[entryName] = m[4] ? m[5] || m[6] || m[7] || '' : entryName;
}
}
// create element
if (IS_ATTRIBUTE_BUG_NAME && attributes.name && /^(input|textarea|select)$/i.test(elementName))
elementName = '<' + elementName + ' name=' + attributes.name + '>';
}
// create element
element = document.createElement(elementName);
// set attributes
if (attributes)
{
if (attributes.style && IS_ATTRIBUTE_BUG_STYLE)
element.style.cssText = attributes.style;
for (var attrName in attributes)
element.setAttribute(attrName, attributes[attrName], 0);
}
// set css classes
if (classNames && classNames.length)
element.className = classNames.join(' ');
// append child nodes
if (arguments.length > 1)
handleInsert(element, createFragment.apply(0, basis.array.flatten(arrayFrom(arguments, 1))));
// attach event handlers
if (isConfig)
{
if (config.css)
{
if (!cssom)
cssom = require('basis.cssom');
cssom.setStyle(element, config.css);
}
for (var event in config)
if (typeof config[event] == 'function')
eventUtils.addHandler(element, event, config[event], element);
}
// return an element
return element;
}
|
javascript
|
function createElement(config){
var isConfig = config != undefined && typeof config != 'string';
var description = (isConfig ? config.description : config) || '';
var elementName = 'div'; // modern browsers become case sensetive for tag names for xhtml
var element;
// fetch tag name
var m = description.match(/^([a-z0-9_\-]+)(.*)$/i);
if (m)
{
elementName = m[1];
description = m[2];
}
// create an element
if (description != '')
{
// extract properties
var classNames = [];
var attributes = {};
var entryName;
while (m = DESCRIPTION_PART_REGEXP.exec(description))
{
if (m[8])
{
throw new Error(
'Create element error in basis.dom.createElement()' +
'\n\nDescription:\n> ' + description +
'\n\nProblem place:\n> ' + description.substr(0, m.index) + '-->' + description.substr(m.index) + '<--'
);
}
entryName = m[1] || m[2] || m[3];
if (m[1]) // id
attributes.id = entryName;
else
if (m[2]) // class
classNames.push(entryName);
else
{ // attribute
if (entryName != 'class')
attributes[entryName] = m[4] ? m[5] || m[6] || m[7] || '' : entryName;
}
}
// create element
if (IS_ATTRIBUTE_BUG_NAME && attributes.name && /^(input|textarea|select)$/i.test(elementName))
elementName = '<' + elementName + ' name=' + attributes.name + '>';
}
// create element
element = document.createElement(elementName);
// set attributes
if (attributes)
{
if (attributes.style && IS_ATTRIBUTE_BUG_STYLE)
element.style.cssText = attributes.style;
for (var attrName in attributes)
element.setAttribute(attrName, attributes[attrName], 0);
}
// set css classes
if (classNames && classNames.length)
element.className = classNames.join(' ');
// append child nodes
if (arguments.length > 1)
handleInsert(element, createFragment.apply(0, basis.array.flatten(arrayFrom(arguments, 1))));
// attach event handlers
if (isConfig)
{
if (config.css)
{
if (!cssom)
cssom = require('basis.cssom');
cssom.setStyle(element, config.css);
}
for (var event in config)
if (typeof config[event] == 'function')
eventUtils.addHandler(element, event, config[event], element);
}
// return an element
return element;
}
|
[
"function",
"createElement",
"(",
"config",
")",
"{",
"var",
"isConfig",
"=",
"config",
"!=",
"undefined",
"&&",
"typeof",
"config",
"!=",
"'string'",
";",
"var",
"description",
"=",
"(",
"isConfig",
"?",
"config",
".",
"description",
":",
"config",
")",
"||",
"''",
";",
"var",
"elementName",
"=",
"'div'",
";",
"var",
"element",
";",
"var",
"m",
"=",
"description",
".",
"match",
"(",
"/",
"^([a-z0-9_\\-]+)(.*)$",
"/",
"i",
")",
";",
"if",
"(",
"m",
")",
"{",
"elementName",
"=",
"m",
"[",
"1",
"]",
";",
"description",
"=",
"m",
"[",
"2",
"]",
";",
"}",
"if",
"(",
"description",
"!=",
"''",
")",
"{",
"var",
"classNames",
"=",
"[",
"]",
";",
"var",
"attributes",
"=",
"{",
"}",
";",
"var",
"entryName",
";",
"while",
"(",
"m",
"=",
"DESCRIPTION_PART_REGEXP",
".",
"exec",
"(",
"description",
")",
")",
"{",
"if",
"(",
"m",
"[",
"8",
"]",
")",
"{",
"throw",
"new",
"Error",
"(",
"'Create element error in basis.dom.createElement()'",
"+",
"'\\n\\nDescription:\\n> '",
"+",
"\\n",
"+",
"\\n",
"+",
"\\n",
"+",
"description",
"+",
"'\\n\\nProblem place:\\n> '",
"+",
"\\n",
")",
";",
"}",
"\\n",
"\\n",
"}",
"description",
".",
"substr",
"(",
"0",
",",
"m",
".",
"index",
")",
"}",
"'",
"description",
".",
"substr",
"(",
"m",
".",
"index",
")",
"'<--'",
"entryName",
"=",
"m",
"[",
"1",
"]",
"||",
"m",
"[",
"2",
"]",
"||",
"m",
"[",
"3",
"]",
";",
"if",
"(",
"m",
"[",
"1",
"]",
")",
"attributes",
".",
"id",
"=",
"entryName",
";",
"else",
"if",
"(",
"m",
"[",
"2",
"]",
")",
"classNames",
".",
"push",
"(",
"entryName",
")",
";",
"else",
"{",
"if",
"(",
"entryName",
"!=",
"'class'",
")",
"attributes",
"[",
"entryName",
"]",
"=",
"m",
"[",
"4",
"]",
"?",
"m",
"[",
"5",
"]",
"||",
"m",
"[",
"6",
"]",
"||",
"m",
"[",
"7",
"]",
"||",
"''",
":",
"entryName",
";",
"}",
"if",
"(",
"IS_ATTRIBUTE_BUG_NAME",
"&&",
"attributes",
".",
"name",
"&&",
"/",
"^(input|textarea|select)$",
"/",
"i",
".",
"test",
"(",
"elementName",
")",
")",
"elementName",
"=",
"'<'",
"+",
"elementName",
"+",
"' name='",
"+",
"attributes",
".",
"name",
"+",
"'>'",
";",
"}"
] |
Creates a new Element with arguments as childs.
@param {string|object} config CSS-selector like definition or object for extended Element creation.
@param {...Node|object} children Child nodes
@return {!Element} The new Element.
|
[
"Creates",
"a",
"new",
"Element",
"with",
"arguments",
"as",
"childs",
"."
] |
8571903014b207a09d45ad2d1bfba277bf21289b
|
https://github.com/basisjs/basisjs/blob/8571903014b207a09d45ad2d1bfba277bf21289b/src/basis/dom.js#L598-L690
|
train
|
basisjs/basisjs
|
src/basis/dom.js
|
insert
|
function insert(node, source, insertPoint, refChild){
node = get(node) || node; // TODO: remove
switch (insertPoint) {
case undefined: // insertPoint omitted
case INSERT_END:
refChild = null;
break;
case INSERT_BEGIN:
refChild = node[FIRST_CHILD];
break;
case INSERT_BEFORE:
break;
case INSERT_AFTER:
refChild = refChild[NEXT_SIBLING];
break;
default:
insertPoint = Number(insertPoint);
refChild = insertPoint >= 0 && insertPoint < node.childNodes.length ? node.childNodes[insertPoint] : null;
}
var isDOMLikeObject = !isNode(node);
var result;
if (!source || !Array.isArray(source))
result = isDOMLikeObject ? source && node.insertBefore(source, refChild) : handleInsert(node, source, refChild);
else
{
if (isDOMLikeObject)
{
result = [];
for (var i = 0, len = source.length; i < len; i++)
result[i] = node.insertBefore(source[i], refChild);
}
else
{
node.insertBefore(createFragment.apply(0, source), refChild);
result = createFragment.array;
}
}
return result;
}
|
javascript
|
function insert(node, source, insertPoint, refChild){
node = get(node) || node; // TODO: remove
switch (insertPoint) {
case undefined: // insertPoint omitted
case INSERT_END:
refChild = null;
break;
case INSERT_BEGIN:
refChild = node[FIRST_CHILD];
break;
case INSERT_BEFORE:
break;
case INSERT_AFTER:
refChild = refChild[NEXT_SIBLING];
break;
default:
insertPoint = Number(insertPoint);
refChild = insertPoint >= 0 && insertPoint < node.childNodes.length ? node.childNodes[insertPoint] : null;
}
var isDOMLikeObject = !isNode(node);
var result;
if (!source || !Array.isArray(source))
result = isDOMLikeObject ? source && node.insertBefore(source, refChild) : handleInsert(node, source, refChild);
else
{
if (isDOMLikeObject)
{
result = [];
for (var i = 0, len = source.length; i < len; i++)
result[i] = node.insertBefore(source[i], refChild);
}
else
{
node.insertBefore(createFragment.apply(0, source), refChild);
result = createFragment.array;
}
}
return result;
}
|
[
"function",
"insert",
"(",
"node",
",",
"source",
",",
"insertPoint",
",",
"refChild",
")",
"{",
"node",
"=",
"get",
"(",
"node",
")",
"||",
"node",
";",
"switch",
"(",
"insertPoint",
")",
"{",
"case",
"undefined",
":",
"case",
"INSERT_END",
":",
"refChild",
"=",
"null",
";",
"break",
";",
"case",
"INSERT_BEGIN",
":",
"refChild",
"=",
"node",
"[",
"FIRST_CHILD",
"]",
";",
"break",
";",
"case",
"INSERT_BEFORE",
":",
"break",
";",
"case",
"INSERT_AFTER",
":",
"refChild",
"=",
"refChild",
"[",
"NEXT_SIBLING",
"]",
";",
"break",
";",
"default",
":",
"insertPoint",
"=",
"Number",
"(",
"insertPoint",
")",
";",
"refChild",
"=",
"insertPoint",
">=",
"0",
"&&",
"insertPoint",
"<",
"node",
".",
"childNodes",
".",
"length",
"?",
"node",
".",
"childNodes",
"[",
"insertPoint",
"]",
":",
"null",
";",
"}",
"var",
"isDOMLikeObject",
"=",
"!",
"isNode",
"(",
"node",
")",
";",
"var",
"result",
";",
"if",
"(",
"!",
"source",
"||",
"!",
"Array",
".",
"isArray",
"(",
"source",
")",
")",
"result",
"=",
"isDOMLikeObject",
"?",
"source",
"&&",
"node",
".",
"insertBefore",
"(",
"source",
",",
"refChild",
")",
":",
"handleInsert",
"(",
"node",
",",
"source",
",",
"refChild",
")",
";",
"else",
"{",
"if",
"(",
"isDOMLikeObject",
")",
"{",
"result",
"=",
"[",
"]",
";",
"for",
"(",
"var",
"i",
"=",
"0",
",",
"len",
"=",
"source",
".",
"length",
";",
"i",
"<",
"len",
";",
"i",
"++",
")",
"result",
"[",
"i",
"]",
"=",
"node",
".",
"insertBefore",
"(",
"source",
"[",
"i",
"]",
",",
"refChild",
")",
";",
"}",
"else",
"{",
"node",
".",
"insertBefore",
"(",
"createFragment",
".",
"apply",
"(",
"0",
",",
"source",
")",
",",
"refChild",
")",
";",
"result",
"=",
"createFragment",
".",
"array",
";",
"}",
"}",
"return",
"result",
";",
"}"
] |
DOM manipulations
Insert source into specified insertPoint position of node.
@param {Node|object} node Destination node.
@param {Node|Array.<Node>|object|Array.<object>} source One or more nodes to be inserted.
@param {string|number=} insertPoint Number as value means position in nodes childNodes.
Also it might be one of special value: INSERT_BEGIN, INSERT_BEFORE, INSERT_AFTER, INSERT_END.
@param {Node|object=} refChild Pointer to Child node of node, using for INSERT_BEFORE & INSERT_AFTER
@return {Node|Array.<Node>} Inserted nodes (may different of source members).
|
[
"DOM",
"manipulations",
"Insert",
"source",
"into",
"specified",
"insertPoint",
"position",
"of",
"node",
"."
] |
8571903014b207a09d45ad2d1bfba277bf21289b
|
https://github.com/basisjs/basisjs/blob/8571903014b207a09d45ad2d1bfba277bf21289b/src/basis/dom.js#L705-L747
|
train
|
basisjs/basisjs
|
src/basis/dom.js
|
replace
|
function replace(oldNode, newNode){
return oldNode[PARENT_NODE] ? oldNode[PARENT_NODE].replaceChild(newNode, oldNode) : oldNode;
}
|
javascript
|
function replace(oldNode, newNode){
return oldNode[PARENT_NODE] ? oldNode[PARENT_NODE].replaceChild(newNode, oldNode) : oldNode;
}
|
[
"function",
"replace",
"(",
"oldNode",
",",
"newNode",
")",
"{",
"return",
"oldNode",
"[",
"PARENT_NODE",
"]",
"?",
"oldNode",
"[",
"PARENT_NODE",
"]",
".",
"replaceChild",
"(",
"newNode",
",",
"oldNode",
")",
":",
"oldNode",
";",
"}"
] |
Replace oldNode for newNode and returns oldNode.
@param {Node} oldNode
@param {Node} newNode
@return {Node}
|
[
"Replace",
"oldNode",
"for",
"newNode",
"and",
"returns",
"oldNode",
"."
] |
8571903014b207a09d45ad2d1bfba277bf21289b
|
https://github.com/basisjs/basisjs/blob/8571903014b207a09d45ad2d1bfba277bf21289b/src/basis/dom.js#L764-L766
|
train
|
basisjs/basisjs
|
src/basis/dom.js
|
swap
|
function swap(nodeA, nodeB){
if (nodeA === nodeB || comparePosition(nodeA, nodeB) & (POSITION_CONTAINED_BY | POSITION_CONTAINS | POSITION_DISCONNECTED))
return false;
replace(nodeA, testElement);
replace(nodeB, nodeA);
replace(testElement, nodeB);
return true;
}
|
javascript
|
function swap(nodeA, nodeB){
if (nodeA === nodeB || comparePosition(nodeA, nodeB) & (POSITION_CONTAINED_BY | POSITION_CONTAINS | POSITION_DISCONNECTED))
return false;
replace(nodeA, testElement);
replace(nodeB, nodeA);
replace(testElement, nodeB);
return true;
}
|
[
"function",
"swap",
"(",
"nodeA",
",",
"nodeB",
")",
"{",
"if",
"(",
"nodeA",
"===",
"nodeB",
"||",
"comparePosition",
"(",
"nodeA",
",",
"nodeB",
")",
"&",
"(",
"POSITION_CONTAINED_BY",
"|",
"POSITION_CONTAINS",
"|",
"POSITION_DISCONNECTED",
")",
")",
"return",
"false",
";",
"replace",
"(",
"nodeA",
",",
"testElement",
")",
";",
"replace",
"(",
"nodeB",
",",
"nodeA",
")",
";",
"replace",
"(",
"testElement",
",",
"nodeB",
")",
";",
"return",
"true",
";",
"}"
] |
Change placing of nodes and returns the result of operation.
@param {Node} nodeA
@param {Node} nodeB
@return {boolean}
|
[
"Change",
"placing",
"of",
"nodes",
"and",
"returns",
"the",
"result",
"of",
"operation",
"."
] |
8571903014b207a09d45ad2d1bfba277bf21289b
|
https://github.com/basisjs/basisjs/blob/8571903014b207a09d45ad2d1bfba277bf21289b/src/basis/dom.js#L774-L783
|
train
|
basisjs/basisjs
|
src/basis/dom.js
|
clone
|
function clone(node, noChildren){
var result = node.cloneNode(!noChildren);
if (result.attachEvent) // clear event handlers for IE
axis(result, AXIS_DESCENDANT_OR_SELF).forEach(eventUtils.clearHandlers);
return result;
}
|
javascript
|
function clone(node, noChildren){
var result = node.cloneNode(!noChildren);
if (result.attachEvent) // clear event handlers for IE
axis(result, AXIS_DESCENDANT_OR_SELF).forEach(eventUtils.clearHandlers);
return result;
}
|
[
"function",
"clone",
"(",
"node",
",",
"noChildren",
")",
"{",
"var",
"result",
"=",
"node",
".",
"cloneNode",
"(",
"!",
"noChildren",
")",
";",
"if",
"(",
"result",
".",
"attachEvent",
")",
"axis",
"(",
"result",
",",
"AXIS_DESCENDANT_OR_SELF",
")",
".",
"forEach",
"(",
"eventUtils",
".",
"clearHandlers",
")",
";",
"return",
"result",
";",
"}"
] |
Clone node.
@param {Node} node
@param {boolean} noChildren If true than clone only node with no children.
@return {Node}
|
[
"Clone",
"node",
"."
] |
8571903014b207a09d45ad2d1bfba277bf21289b
|
https://github.com/basisjs/basisjs/blob/8571903014b207a09d45ad2d1bfba277bf21289b/src/basis/dom.js#L791-L796
|
train
|
basisjs/basisjs
|
src/basis/dom.js
|
clear
|
function clear(node){
node = get(node);
while (node[LAST_CHILD])
node.removeChild(node[LAST_CHILD]);
return node;
}
|
javascript
|
function clear(node){
node = get(node);
while (node[LAST_CHILD])
node.removeChild(node[LAST_CHILD]);
return node;
}
|
[
"function",
"clear",
"(",
"node",
")",
"{",
"node",
"=",
"get",
"(",
"node",
")",
";",
"while",
"(",
"node",
"[",
"LAST_CHILD",
"]",
")",
"node",
".",
"removeChild",
"(",
"node",
"[",
"LAST_CHILD",
"]",
")",
";",
"return",
"node",
";",
"}"
] |
Removes all child nodes of node and returns this node.
@param {Node} node
@return {Node}
|
[
"Removes",
"all",
"child",
"nodes",
"of",
"node",
"and",
"returns",
"this",
"node",
"."
] |
8571903014b207a09d45ad2d1bfba277bf21289b
|
https://github.com/basisjs/basisjs/blob/8571903014b207a09d45ad2d1bfba277bf21289b/src/basis/dom.js#L803-L810
|
train
|
basisjs/basisjs
|
src/basis/dom.js
|
focus
|
function focus(node, select){
// try catch block here because browsers throw unexpected exeption in some cases
try {
node = get(node);
node.focus();
if (select && node.select) // && typeof node.select == 'function'
// temporary removed because IE returns 'object' for DOM object methods, instead of 'function'
node.select();
} catch(e) {}
}
|
javascript
|
function focus(node, select){
// try catch block here because browsers throw unexpected exeption in some cases
try {
node = get(node);
node.focus();
if (select && node.select) // && typeof node.select == 'function'
// temporary removed because IE returns 'object' for DOM object methods, instead of 'function'
node.select();
} catch(e) {}
}
|
[
"function",
"focus",
"(",
"node",
",",
"select",
")",
"{",
"try",
"{",
"node",
"=",
"get",
"(",
"node",
")",
";",
"node",
".",
"focus",
"(",
")",
";",
"if",
"(",
"select",
"&&",
"node",
".",
"select",
")",
"node",
".",
"select",
"(",
")",
";",
"}",
"catch",
"(",
"e",
")",
"{",
"}",
"}"
] |
Input selection stuff
Set focus for node.
@param {Element} node
@param {boolean=} select Call select() method of node.
|
[
"Input",
"selection",
"stuff",
"Set",
"focus",
"for",
"node",
"."
] |
8571903014b207a09d45ad2d1bfba277bf21289b
|
https://github.com/basisjs/basisjs/blob/8571903014b207a09d45ad2d1bfba277bf21289b/src/basis/dom.js#L890-L899
|
train
|
basisjs/basisjs
|
src/basis/utils/utf16.js
|
toBytes
|
function toBytes(input){
var output = [];
var len = input.length;
for (var i = 0; i < len; i++)
{
var c = input.charCodeAt(i);
output.push(c & 0xFF, c >> 8);
}
return output;
}
|
javascript
|
function toBytes(input){
var output = [];
var len = input.length;
for (var i = 0; i < len; i++)
{
var c = input.charCodeAt(i);
output.push(c & 0xFF, c >> 8);
}
return output;
}
|
[
"function",
"toBytes",
"(",
"input",
")",
"{",
"var",
"output",
"=",
"[",
"]",
";",
"var",
"len",
"=",
"input",
".",
"length",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"len",
";",
"i",
"++",
")",
"{",
"var",
"c",
"=",
"input",
".",
"charCodeAt",
"(",
"i",
")",
";",
"output",
".",
"push",
"(",
"c",
"&",
"0xFF",
",",
"c",
">>",
"8",
")",
";",
"}",
"return",
"output",
";",
"}"
] |
utf16 string -> utf16 bytes array
|
[
"utf16",
"string",
"-",
">",
"utf16",
"bytes",
"array"
] |
8571903014b207a09d45ad2d1bfba277bf21289b
|
https://github.com/basisjs/basisjs/blob/8571903014b207a09d45ad2d1bfba277bf21289b/src/basis/utils/utf16.js#L11-L22
|
train
|
basisjs/basisjs
|
src/basis/utils/utf16.js
|
fromBytes
|
function fromBytes(input){
var output = '';
var len = input.length;
var i = 0;
var b1;
var b2;
while (i < len)
{
b1 = input[i++] || 0;
b2 = input[i++] || 0;
output += String.fromCharCode((b2 << 8) | b1);
}
return output;
}
|
javascript
|
function fromBytes(input){
var output = '';
var len = input.length;
var i = 0;
var b1;
var b2;
while (i < len)
{
b1 = input[i++] || 0;
b2 = input[i++] || 0;
output += String.fromCharCode((b2 << 8) | b1);
}
return output;
}
|
[
"function",
"fromBytes",
"(",
"input",
")",
"{",
"var",
"output",
"=",
"''",
";",
"var",
"len",
"=",
"input",
".",
"length",
";",
"var",
"i",
"=",
"0",
";",
"var",
"b1",
";",
"var",
"b2",
";",
"while",
"(",
"i",
"<",
"len",
")",
"{",
"b1",
"=",
"input",
"[",
"i",
"++",
"]",
"||",
"0",
";",
"b2",
"=",
"input",
"[",
"i",
"++",
"]",
"||",
"0",
";",
"output",
"+=",
"String",
".",
"fromCharCode",
"(",
"(",
"b2",
"<<",
"8",
")",
"|",
"b1",
")",
";",
"}",
"return",
"output",
";",
"}"
] |
utf16 bytes array -> utf16 string
|
[
"utf16",
"bytes",
"array",
"-",
">",
"utf16",
"string"
] |
8571903014b207a09d45ad2d1bfba277bf21289b
|
https://github.com/basisjs/basisjs/blob/8571903014b207a09d45ad2d1bfba277bf21289b/src/basis/utils/utf16.js#L25-L39
|
train
|
basisjs/basisjs
|
src/basis/utils/utf16.js
|
toUTF8
|
function toUTF8(input){
var output = '';
var len = input.length;
for (var i = 0; i < len; i++)
{
var c = input.charCodeAt(i);
if (c < 128)
output += chars[c];
else
if (c < 2048)
output += chars[(c >> 6) | 192] +
chars[(c & 63) | 128];
else
output += chars[(c >> 12) | 224] +
chars[((c >> 6) & 63) | 128] +
chars[(c & 63) | 128];
}
return output;
}
|
javascript
|
function toUTF8(input){
var output = '';
var len = input.length;
for (var i = 0; i < len; i++)
{
var c = input.charCodeAt(i);
if (c < 128)
output += chars[c];
else
if (c < 2048)
output += chars[(c >> 6) | 192] +
chars[(c & 63) | 128];
else
output += chars[(c >> 12) | 224] +
chars[((c >> 6) & 63) | 128] +
chars[(c & 63) | 128];
}
return output;
}
|
[
"function",
"toUTF8",
"(",
"input",
")",
"{",
"var",
"output",
"=",
"''",
";",
"var",
"len",
"=",
"input",
".",
"length",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"len",
";",
"i",
"++",
")",
"{",
"var",
"c",
"=",
"input",
".",
"charCodeAt",
"(",
"i",
")",
";",
"if",
"(",
"c",
"<",
"128",
")",
"output",
"+=",
"chars",
"[",
"c",
"]",
";",
"else",
"if",
"(",
"c",
"<",
"2048",
")",
"output",
"+=",
"chars",
"[",
"(",
"c",
">>",
"6",
")",
"|",
"192",
"]",
"+",
"chars",
"[",
"(",
"c",
"&",
"63",
")",
"|",
"128",
"]",
";",
"else",
"output",
"+=",
"chars",
"[",
"(",
"c",
">>",
"12",
")",
"|",
"224",
"]",
"+",
"chars",
"[",
"(",
"(",
"c",
">>",
"6",
")",
"&",
"63",
")",
"|",
"128",
"]",
"+",
"chars",
"[",
"(",
"c",
"&",
"63",
")",
"|",
"128",
"]",
";",
"}",
"return",
"output",
";",
"}"
] |
utf16 string -> utf8 string
|
[
"utf16",
"string",
"-",
">",
"utf8",
"string"
] |
8571903014b207a09d45ad2d1bfba277bf21289b
|
https://github.com/basisjs/basisjs/blob/8571903014b207a09d45ad2d1bfba277bf21289b/src/basis/utils/utf16.js#L42-L62
|
train
|
basisjs/basisjs
|
src/basis/utils/utf16.js
|
toUTF8Bytes
|
function toUTF8Bytes(input){
// utf16 -> utf8
input = toUTF8(input);
// string -> array of bytes
var len = input.length;
var output = new Array(len);
for (var i = 0; i < len; i++)
output[i] = input.charCodeAt(i);
return output;
}
|
javascript
|
function toUTF8Bytes(input){
// utf16 -> utf8
input = toUTF8(input);
// string -> array of bytes
var len = input.length;
var output = new Array(len);
for (var i = 0; i < len; i++)
output[i] = input.charCodeAt(i);
return output;
}
|
[
"function",
"toUTF8Bytes",
"(",
"input",
")",
"{",
"input",
"=",
"toUTF8",
"(",
"input",
")",
";",
"var",
"len",
"=",
"input",
".",
"length",
";",
"var",
"output",
"=",
"new",
"Array",
"(",
"len",
")",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"len",
";",
"i",
"++",
")",
"output",
"[",
"i",
"]",
"=",
"input",
".",
"charCodeAt",
"(",
"i",
")",
";",
"return",
"output",
";",
"}"
] |
utf16 string -> utf8 bytes array
|
[
"utf16",
"string",
"-",
">",
"utf8",
"bytes",
"array"
] |
8571903014b207a09d45ad2d1bfba277bf21289b
|
https://github.com/basisjs/basisjs/blob/8571903014b207a09d45ad2d1bfba277bf21289b/src/basis/utils/utf16.js#L65-L77
|
train
|
basisjs/basisjs
|
src/basis/utils/utf16.js
|
fromUTF8
|
function fromUTF8(input){
var output = '';
var len = input.length;
var i = 0;
var c1;
var c2;
var c3;
while (i < len)
{
c1 = input.charCodeAt(i++);
if (c1 < 128)
output += chars[c1];
else
{
c2 = input.charCodeAt(i++);
if (c1 & 32)
{
c3 = input.charCodeAt(i++);
output += String.fromCharCode(((c1 & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
}
else
output += String.fromCharCode(((c1 & 31) << 6) | (c2 & 63));
}
}
return output;
}
|
javascript
|
function fromUTF8(input){
var output = '';
var len = input.length;
var i = 0;
var c1;
var c2;
var c3;
while (i < len)
{
c1 = input.charCodeAt(i++);
if (c1 < 128)
output += chars[c1];
else
{
c2 = input.charCodeAt(i++);
if (c1 & 32)
{
c3 = input.charCodeAt(i++);
output += String.fromCharCode(((c1 & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
}
else
output += String.fromCharCode(((c1 & 31) << 6) | (c2 & 63));
}
}
return output;
}
|
[
"function",
"fromUTF8",
"(",
"input",
")",
"{",
"var",
"output",
"=",
"''",
";",
"var",
"len",
"=",
"input",
".",
"length",
";",
"var",
"i",
"=",
"0",
";",
"var",
"c1",
";",
"var",
"c2",
";",
"var",
"c3",
";",
"while",
"(",
"i",
"<",
"len",
")",
"{",
"c1",
"=",
"input",
".",
"charCodeAt",
"(",
"i",
"++",
")",
";",
"if",
"(",
"c1",
"<",
"128",
")",
"output",
"+=",
"chars",
"[",
"c1",
"]",
";",
"else",
"{",
"c2",
"=",
"input",
".",
"charCodeAt",
"(",
"i",
"++",
")",
";",
"if",
"(",
"c1",
"&",
"32",
")",
"{",
"c3",
"=",
"input",
".",
"charCodeAt",
"(",
"i",
"++",
")",
";",
"output",
"+=",
"String",
".",
"fromCharCode",
"(",
"(",
"(",
"c1",
"&",
"15",
")",
"<<",
"12",
")",
"|",
"(",
"(",
"c2",
"&",
"63",
")",
"<<",
"6",
")",
"|",
"(",
"c3",
"&",
"63",
")",
")",
";",
"}",
"else",
"output",
"+=",
"String",
".",
"fromCharCode",
"(",
"(",
"(",
"c1",
"&",
"31",
")",
"<<",
"6",
")",
"|",
"(",
"c2",
"&",
"63",
")",
")",
";",
"}",
"}",
"return",
"output",
";",
"}"
] |
utf8 string -> utf16 string
|
[
"utf8",
"string",
"-",
">",
"utf16",
"string"
] |
8571903014b207a09d45ad2d1bfba277bf21289b
|
https://github.com/basisjs/basisjs/blob/8571903014b207a09d45ad2d1bfba277bf21289b/src/basis/utils/utf16.js#L80-L106
|
train
|
basisjs/basisjs
|
src/basis/ui.js
|
extendBinding
|
function extendBinding(binding, extension){
/** @cut */ var info = basis.dev.getInfo(extension, 'map');
binding.bindingId = bindingSeed++;
for (var key in extension)
{
var def = null;
var value = extension[key];
// NOTE: check for Node, because first extendBinding invoke before Node class declared
if ((Node && value instanceof Node) || basis.resource.isResource(value))
{
def = {
events: 'satelliteChanged',
getter: (function(key, satellite){
var resource = typeof satellite == 'function' ? satellite : null;
var init = function(node){
init = false;
if (resource)
{
satellite = resource();
if (satellite instanceof Node == false)
return;
resource = null;
}
node.setSatellite(key, satellite);
/** @cut */ if (node.satellite[key] !== satellite)
/** @cut */ basis.dev.warn('basis.ui.binding: implicit satellite `' + key + '` attach to owner failed');
};
return function(node){
if (init)
init(node);
return resource || (node.satellite[key] ? node.satellite[key].element : null);
};
})(key, value)
};
}
else
{
if (value)
{
if (typeof value == 'string')
value = BINDING_PRESET.process(key, value);
else
// if value has bindingBridge means that it can update itself
if (value.bindingBridge)
value = basis.fn.$const(value);
if (typeof value != 'object')
{
def = {
getter: typeof value == 'function' ? value : basis.getter(value)
};
}
else
if (Array.isArray(value))
{
def = {
events: value[0],
getter: basis.getter(value[1])
};
}
else
{
def = {
events: value.events,
getter: basis.getter(value.getter)
};
}
}
}
/** @cut */ if (def && info && info.hasOwnProperty(key))
/** @cut */ def.loc = info[key];
binding[key] = def;
}
}
|
javascript
|
function extendBinding(binding, extension){
/** @cut */ var info = basis.dev.getInfo(extension, 'map');
binding.bindingId = bindingSeed++;
for (var key in extension)
{
var def = null;
var value = extension[key];
// NOTE: check for Node, because first extendBinding invoke before Node class declared
if ((Node && value instanceof Node) || basis.resource.isResource(value))
{
def = {
events: 'satelliteChanged',
getter: (function(key, satellite){
var resource = typeof satellite == 'function' ? satellite : null;
var init = function(node){
init = false;
if (resource)
{
satellite = resource();
if (satellite instanceof Node == false)
return;
resource = null;
}
node.setSatellite(key, satellite);
/** @cut */ if (node.satellite[key] !== satellite)
/** @cut */ basis.dev.warn('basis.ui.binding: implicit satellite `' + key + '` attach to owner failed');
};
return function(node){
if (init)
init(node);
return resource || (node.satellite[key] ? node.satellite[key].element : null);
};
})(key, value)
};
}
else
{
if (value)
{
if (typeof value == 'string')
value = BINDING_PRESET.process(key, value);
else
// if value has bindingBridge means that it can update itself
if (value.bindingBridge)
value = basis.fn.$const(value);
if (typeof value != 'object')
{
def = {
getter: typeof value == 'function' ? value : basis.getter(value)
};
}
else
if (Array.isArray(value))
{
def = {
events: value[0],
getter: basis.getter(value[1])
};
}
else
{
def = {
events: value.events,
getter: basis.getter(value.getter)
};
}
}
}
/** @cut */ if (def && info && info.hasOwnProperty(key))
/** @cut */ def.loc = info[key];
binding[key] = def;
}
}
|
[
"function",
"extendBinding",
"(",
"binding",
",",
"extension",
")",
"{",
"var",
"info",
"=",
"basis",
".",
"dev",
".",
"getInfo",
"(",
"extension",
",",
"'map'",
")",
";",
"binding",
".",
"bindingId",
"=",
"bindingSeed",
"++",
";",
"for",
"(",
"var",
"key",
"in",
"extension",
")",
"{",
"var",
"def",
"=",
"null",
";",
"var",
"value",
"=",
"extension",
"[",
"key",
"]",
";",
"if",
"(",
"(",
"Node",
"&&",
"value",
"instanceof",
"Node",
")",
"||",
"basis",
".",
"resource",
".",
"isResource",
"(",
"value",
")",
")",
"{",
"def",
"=",
"{",
"events",
":",
"'satelliteChanged'",
",",
"getter",
":",
"(",
"function",
"(",
"key",
",",
"satellite",
")",
"{",
"var",
"resource",
"=",
"typeof",
"satellite",
"==",
"'function'",
"?",
"satellite",
":",
"null",
";",
"var",
"init",
"=",
"function",
"(",
"node",
")",
"{",
"init",
"=",
"false",
";",
"if",
"(",
"resource",
")",
"{",
"satellite",
"=",
"resource",
"(",
")",
";",
"if",
"(",
"satellite",
"instanceof",
"Node",
"==",
"false",
")",
"return",
";",
"resource",
"=",
"null",
";",
"}",
"node",
".",
"setSatellite",
"(",
"key",
",",
"satellite",
")",
";",
"if",
"(",
"node",
".",
"satellite",
"[",
"key",
"]",
"!==",
"satellite",
")",
"basis",
".",
"dev",
".",
"warn",
"(",
"'basis.ui.binding: implicit satellite `'",
"+",
"key",
"+",
"'` attach to owner failed'",
")",
";",
"}",
";",
"return",
"function",
"(",
"node",
")",
"{",
"if",
"(",
"init",
")",
"init",
"(",
"node",
")",
";",
"return",
"resource",
"||",
"(",
"node",
".",
"satellite",
"[",
"key",
"]",
"?",
"node",
".",
"satellite",
"[",
"key",
"]",
".",
"element",
":",
"null",
")",
";",
"}",
";",
"}",
")",
"(",
"key",
",",
"value",
")",
"}",
";",
"}",
"else",
"{",
"if",
"(",
"value",
")",
"{",
"if",
"(",
"typeof",
"value",
"==",
"'string'",
")",
"value",
"=",
"BINDING_PRESET",
".",
"process",
"(",
"key",
",",
"value",
")",
";",
"else",
"if",
"(",
"value",
".",
"bindingBridge",
")",
"value",
"=",
"basis",
".",
"fn",
".",
"$const",
"(",
"value",
")",
";",
"if",
"(",
"typeof",
"value",
"!=",
"'object'",
")",
"{",
"def",
"=",
"{",
"getter",
":",
"typeof",
"value",
"==",
"'function'",
"?",
"value",
":",
"basis",
".",
"getter",
"(",
"value",
")",
"}",
";",
"}",
"else",
"if",
"(",
"Array",
".",
"isArray",
"(",
"value",
")",
")",
"{",
"def",
"=",
"{",
"events",
":",
"value",
"[",
"0",
"]",
",",
"getter",
":",
"basis",
".",
"getter",
"(",
"value",
"[",
"1",
"]",
")",
"}",
";",
"}",
"else",
"{",
"def",
"=",
"{",
"events",
":",
"value",
".",
"events",
",",
"getter",
":",
"basis",
".",
"getter",
"(",
"value",
".",
"getter",
")",
"}",
";",
"}",
"}",
"}",
"if",
"(",
"def",
"&&",
"info",
"&&",
"info",
".",
"hasOwnProperty",
"(",
"key",
")",
")",
"def",
".",
"loc",
"=",
"info",
"[",
"key",
"]",
";",
"binding",
"[",
"key",
"]",
"=",
"def",
";",
"}",
"}"
] |
Function that extends list of binding by extension.
@param {object} binding
@param {object} extension
|
[
"Function",
"that",
"extends",
"list",
"of",
"binding",
"by",
"extension",
"."
] |
8571903014b207a09d45ad2d1bfba277bf21289b
|
https://github.com/basisjs/basisjs/blob/8571903014b207a09d45ad2d1bfba277bf21289b/src/basis/ui.js#L62-L144
|
train
|
basisjs/basisjs
|
src/basis/ui.js
|
function(actionName, event){
var action = this.action[actionName];
if (action)
action.call(this, event);
/** @cut */ if (!action)
/** @cut */ basis.dev.warn('template call `' + actionName + '` action, but it isn\'t defined in action list');
}
|
javascript
|
function(actionName, event){
var action = this.action[actionName];
if (action)
action.call(this, event);
/** @cut */ if (!action)
/** @cut */ basis.dev.warn('template call `' + actionName + '` action, but it isn\'t defined in action list');
}
|
[
"function",
"(",
"actionName",
",",
"event",
")",
"{",
"var",
"action",
"=",
"this",
".",
"action",
"[",
"actionName",
"]",
";",
"if",
"(",
"action",
")",
"action",
".",
"call",
"(",
"this",
",",
"event",
")",
";",
"if",
"(",
"!",
"action",
")",
"basis",
".",
"dev",
".",
"warn",
"(",
"'template call `'",
"+",
"actionName",
"+",
"'` action, but it isn\\'t defined in action list'",
")",
";",
"}"
] |
Handler on template actions.
@param {string} actionName
@param {object} event
|
[
"Handler",
"on",
"template",
"actions",
"."
] |
8571903014b207a09d45ad2d1bfba277bf21289b
|
https://github.com/basisjs/basisjs/blob/8571903014b207a09d45ad2d1bfba277bf21289b/src/basis/ui.js#L610-L618
|
train
|
|
basisjs/basisjs
|
src/basis/ui.js
|
function(select){
var focusElement = this.tmpl ? this.tmpl.focus || this.element : null;
if (focusElement)
{
if (focusTimer)
focusTimer = basis.clearImmediate(focusTimer);
focusTimer = basis.setImmediate(function(){
try {
focusElement.focus();
if (select)
focusElement.select();
} catch(e) {}
});
}
}
|
javascript
|
function(select){
var focusElement = this.tmpl ? this.tmpl.focus || this.element : null;
if (focusElement)
{
if (focusTimer)
focusTimer = basis.clearImmediate(focusTimer);
focusTimer = basis.setImmediate(function(){
try {
focusElement.focus();
if (select)
focusElement.select();
} catch(e) {}
});
}
}
|
[
"function",
"(",
"select",
")",
"{",
"var",
"focusElement",
"=",
"this",
".",
"tmpl",
"?",
"this",
".",
"tmpl",
".",
"focus",
"||",
"this",
".",
"element",
":",
"null",
";",
"if",
"(",
"focusElement",
")",
"{",
"if",
"(",
"focusTimer",
")",
"focusTimer",
"=",
"basis",
".",
"clearImmediate",
"(",
"focusTimer",
")",
";",
"focusTimer",
"=",
"basis",
".",
"setImmediate",
"(",
"function",
"(",
")",
"{",
"try",
"{",
"focusElement",
".",
"focus",
"(",
")",
";",
"if",
"(",
"select",
")",
"focusElement",
".",
"select",
"(",
")",
";",
"}",
"catch",
"(",
"e",
")",
"{",
"}",
"}",
")",
";",
"}",
"}"
] |
Set focus on element in template, if possible.
@param {boolean=} select
|
[
"Set",
"focus",
"on",
"element",
"in",
"template",
"if",
"possible",
"."
] |
8571903014b207a09d45ad2d1bfba277bf21289b
|
https://github.com/basisjs/basisjs/blob/8571903014b207a09d45ad2d1bfba277bf21289b/src/basis/ui.js#L624-L640
|
train
|
|
basisjs/basisjs
|
src/basis/ui.js
|
function(){
var focusElement = this.tmpl ? this.tmpl.focus || this.element : null;
if (focusElement)
try {
focusElement.blur();
} catch(e) {}
}
|
javascript
|
function(){
var focusElement = this.tmpl ? this.tmpl.focus || this.element : null;
if (focusElement)
try {
focusElement.blur();
} catch(e) {}
}
|
[
"function",
"(",
")",
"{",
"var",
"focusElement",
"=",
"this",
".",
"tmpl",
"?",
"this",
".",
"tmpl",
".",
"focus",
"||",
"this",
".",
"element",
":",
"null",
";",
"if",
"(",
"focusElement",
")",
"try",
"{",
"focusElement",
".",
"blur",
"(",
")",
";",
"}",
"catch",
"(",
"e",
")",
"{",
"}",
"}"
] |
Remove focus from element.
|
[
"Remove",
"focus",
"from",
"element",
"."
] |
8571903014b207a09d45ad2d1bfba277bf21289b
|
https://github.com/basisjs/basisjs/blob/8571903014b207a09d45ad2d1bfba277bf21289b/src/basis/ui.js#L645-L652
|
train
|
|
basisjs/basisjs
|
src/basis/ui.js
|
function(super_){
return {
// methods
insertBefore: function(newChild, refChild){
/** @cut */ if (this.noChildNodesElement_)
/** @cut */ {
/** @cut */ delete this.noChildNodesElement_;
/** @cut */ basis.dev.warn('basis.ui: Template has no childNodesElement container, but insertBefore method called; probably it\'s a bug');
/** @cut */ }
// inherit
newChild = super_.insertBefore.call(this, newChild, refChild);
var target = newChild.groupNode || this;
var container = target.childNodesElement || this.childNodesElement;
var nextSibling = newChild.nextSibling;
var insertPoint = nextSibling && nextSibling.element.parentNode == container ? nextSibling.element : null;
var childElement = newChild.element;
var refNode = insertPoint || container.insertPoint || null; // NOTE: null at the end for IE
if (childElement.parentNode !== container || childElement.nextSibling !== refNode) // prevent dom update
container.insertBefore(childElement, refNode);
return newChild;
},
removeChild: function(oldChild){
// inherit
super_.removeChild.call(this, oldChild);
// remove from dom
var element = oldChild.element;
var parent = element.parentNode;
if (parent)
parent.removeChild(element);
return oldChild;
},
clear: function(alive){
// if not alive mode node element will be removed on node destroy
if (alive)
{
var node = this.firstChild;
while (node)
{
var element = node.element;
var parent = element.parentNode;
if (parent)
parent.removeChild(element);
node = node.nextSibling;
}
}
// inherit
super_.clear.call(this, alive);
},
setChildNodes: function(childNodes, keepAlive){
/** @cut */ if (this.noChildNodesElement_)
/** @cut */ {
/** @cut */ delete this.noChildNodesElement_;
/** @cut */ basis.dev.warn('basis.ui: Template has no childNodesElement container, but setChildNodes method called; probably it\'s a bug');
/** @cut */ }
// reallocate childNodesElement to new DocumentFragment
var domFragment = document.createDocumentFragment();
var target = this.grouping || this;
var container = target.childNodesElement;
// set child nodes element points to DOM fragment
target.childNodesElement = domFragment;
// call inherit method
// NOTE: make sure that dispatching childNodesModified event handlers are not sensetive
// for child node positions at real DOM (html document), because all new child nodes
// will be inserted into temporary DocumentFragment that will be inserted into html document
// later (after inherited method call)
super_.setChildNodes.call(this, childNodes, keepAlive);
// flush dom fragment nodes into container
container.insertBefore(domFragment, container.insertPoint || null); // NOTE: null at the end for IE
// restore childNodesElement
target.childNodesElement = container;
}
};
}
|
javascript
|
function(super_){
return {
// methods
insertBefore: function(newChild, refChild){
/** @cut */ if (this.noChildNodesElement_)
/** @cut */ {
/** @cut */ delete this.noChildNodesElement_;
/** @cut */ basis.dev.warn('basis.ui: Template has no childNodesElement container, but insertBefore method called; probably it\'s a bug');
/** @cut */ }
// inherit
newChild = super_.insertBefore.call(this, newChild, refChild);
var target = newChild.groupNode || this;
var container = target.childNodesElement || this.childNodesElement;
var nextSibling = newChild.nextSibling;
var insertPoint = nextSibling && nextSibling.element.parentNode == container ? nextSibling.element : null;
var childElement = newChild.element;
var refNode = insertPoint || container.insertPoint || null; // NOTE: null at the end for IE
if (childElement.parentNode !== container || childElement.nextSibling !== refNode) // prevent dom update
container.insertBefore(childElement, refNode);
return newChild;
},
removeChild: function(oldChild){
// inherit
super_.removeChild.call(this, oldChild);
// remove from dom
var element = oldChild.element;
var parent = element.parentNode;
if (parent)
parent.removeChild(element);
return oldChild;
},
clear: function(alive){
// if not alive mode node element will be removed on node destroy
if (alive)
{
var node = this.firstChild;
while (node)
{
var element = node.element;
var parent = element.parentNode;
if (parent)
parent.removeChild(element);
node = node.nextSibling;
}
}
// inherit
super_.clear.call(this, alive);
},
setChildNodes: function(childNodes, keepAlive){
/** @cut */ if (this.noChildNodesElement_)
/** @cut */ {
/** @cut */ delete this.noChildNodesElement_;
/** @cut */ basis.dev.warn('basis.ui: Template has no childNodesElement container, but setChildNodes method called; probably it\'s a bug');
/** @cut */ }
// reallocate childNodesElement to new DocumentFragment
var domFragment = document.createDocumentFragment();
var target = this.grouping || this;
var container = target.childNodesElement;
// set child nodes element points to DOM fragment
target.childNodesElement = domFragment;
// call inherit method
// NOTE: make sure that dispatching childNodesModified event handlers are not sensetive
// for child node positions at real DOM (html document), because all new child nodes
// will be inserted into temporary DocumentFragment that will be inserted into html document
// later (after inherited method call)
super_.setChildNodes.call(this, childNodes, keepAlive);
// flush dom fragment nodes into container
container.insertBefore(domFragment, container.insertPoint || null); // NOTE: null at the end for IE
// restore childNodesElement
target.childNodesElement = container;
}
};
}
|
[
"function",
"(",
"super_",
")",
"{",
"return",
"{",
"insertBefore",
":",
"function",
"(",
"newChild",
",",
"refChild",
")",
"{",
"if",
"(",
"this",
".",
"noChildNodesElement_",
")",
"{",
"delete",
"this",
".",
"noChildNodesElement_",
";",
"basis",
".",
"dev",
".",
"warn",
"(",
"'basis.ui: Template has no childNodesElement container, but insertBefore method called; probably it\\'s a bug'",
")",
";",
"}",
"\\'",
"newChild",
"=",
"super_",
".",
"insertBefore",
".",
"call",
"(",
"this",
",",
"newChild",
",",
"refChild",
")",
";",
"var",
"target",
"=",
"newChild",
".",
"groupNode",
"||",
"this",
";",
"var",
"container",
"=",
"target",
".",
"childNodesElement",
"||",
"this",
".",
"childNodesElement",
";",
"var",
"nextSibling",
"=",
"newChild",
".",
"nextSibling",
";",
"var",
"insertPoint",
"=",
"nextSibling",
"&&",
"nextSibling",
".",
"element",
".",
"parentNode",
"==",
"container",
"?",
"nextSibling",
".",
"element",
":",
"null",
";",
"var",
"childElement",
"=",
"newChild",
".",
"element",
";",
"var",
"refNode",
"=",
"insertPoint",
"||",
"container",
".",
"insertPoint",
"||",
"null",
";",
"if",
"(",
"childElement",
".",
"parentNode",
"!==",
"container",
"||",
"childElement",
".",
"nextSibling",
"!==",
"refNode",
")",
"container",
".",
"insertBefore",
"(",
"childElement",
",",
"refNode",
")",
";",
"}",
",",
"return",
"newChild",
";",
",",
"removeChild",
":",
"function",
"(",
"oldChild",
")",
"{",
"super_",
".",
"removeChild",
".",
"call",
"(",
"this",
",",
"oldChild",
")",
";",
"var",
"element",
"=",
"oldChild",
".",
"element",
";",
"var",
"parent",
"=",
"element",
".",
"parentNode",
";",
"if",
"(",
"parent",
")",
"parent",
".",
"removeChild",
"(",
"element",
")",
";",
"return",
"oldChild",
";",
"}",
",",
"clear",
":",
"function",
"(",
"alive",
")",
"{",
"if",
"(",
"alive",
")",
"{",
"var",
"node",
"=",
"this",
".",
"firstChild",
";",
"while",
"(",
"node",
")",
"{",
"var",
"element",
"=",
"node",
".",
"element",
";",
"var",
"parent",
"=",
"element",
".",
"parentNode",
";",
"if",
"(",
"parent",
")",
"parent",
".",
"removeChild",
"(",
"element",
")",
";",
"node",
"=",
"node",
".",
"nextSibling",
";",
"}",
"}",
"super_",
".",
"clear",
".",
"call",
"(",
"this",
",",
"alive",
")",
";",
"}",
"}",
";",
"}"
] |
Template mixin for containers classes
@mixin
|
[
"Template",
"mixin",
"for",
"containers",
"classes"
] |
8571903014b207a09d45ad2d1bfba277bf21289b
|
https://github.com/basisjs/basisjs/blob/8571903014b207a09d45ad2d1bfba277bf21289b/src/basis/ui.js#L696-L785
|
train
|
|
basisjs/basisjs
|
src/basis/tracker.js
|
track
|
function track(event){
try {
// TODO look up for event.data.transformer before setting data
tracker.set(event);
} catch(e) {
/** @cut */ basis.dev.error(namespace + '.track(): Error during tracking event processing', event, e);
}
}
|
javascript
|
function track(event){
try {
// TODO look up for event.data.transformer before setting data
tracker.set(event);
} catch(e) {
/** @cut */ basis.dev.error(namespace + '.track(): Error during tracking event processing', event, e);
}
}
|
[
"function",
"track",
"(",
"event",
")",
"{",
"try",
"{",
"tracker",
".",
"set",
"(",
"event",
")",
";",
"}",
"catch",
"(",
"e",
")",
"{",
"basis",
".",
"dev",
".",
"error",
"(",
"namespace",
"+",
"'.track(): Error during tracking event processing'",
",",
"event",
",",
"e",
")",
";",
"}",
"}"
] |
Maps an event name to a list of tracking objects
@param {TrackingDataObject} event a tracking object
@private
@return
|
[
"Maps",
"an",
"event",
"name",
"to",
"a",
"list",
"of",
"tracking",
"objects"
] |
8571903014b207a09d45ad2d1bfba277bf21289b
|
https://github.com/basisjs/basisjs/blob/8571903014b207a09d45ad2d1bfba277bf21289b/src/basis/tracker.js#L58-L65
|
train
|
basisjs/basisjs
|
src/basis/tracker.js
|
getCssSelectorFromPath
|
function getCssSelectorFromPath(path, selector){
return parsePath(path).map(function(role){
if (!role.role)
return '';
var start = escapeQuotes(role.role);
var end = (role.subrole ? '/' + escapeQuotes(role.subrole) : '') + '"]';
if (role.roleId)
{
if (selector && role.roleId == '*')
start = '[role-marker^="' + start + '("][role-marker$=")';
else
start = '[role-marker="' + start + '(' + escapeQuotes(role.roleId) + ')';
}
else
{
start = '[role-marker="' + start;
}
return start + end;
}).join(' ');
}
|
javascript
|
function getCssSelectorFromPath(path, selector){
return parsePath(path).map(function(role){
if (!role.role)
return '';
var start = escapeQuotes(role.role);
var end = (role.subrole ? '/' + escapeQuotes(role.subrole) : '') + '"]';
if (role.roleId)
{
if (selector && role.roleId == '*')
start = '[role-marker^="' + start + '("][role-marker$=")';
else
start = '[role-marker="' + start + '(' + escapeQuotes(role.roleId) + ')';
}
else
{
start = '[role-marker="' + start;
}
return start + end;
}).join(' ');
}
|
[
"function",
"getCssSelectorFromPath",
"(",
"path",
",",
"selector",
")",
"{",
"return",
"parsePath",
"(",
"path",
")",
".",
"map",
"(",
"function",
"(",
"role",
")",
"{",
"if",
"(",
"!",
"role",
".",
"role",
")",
"return",
"''",
";",
"var",
"start",
"=",
"escapeQuotes",
"(",
"role",
".",
"role",
")",
";",
"var",
"end",
"=",
"(",
"role",
".",
"subrole",
"?",
"'/'",
"+",
"escapeQuotes",
"(",
"role",
".",
"subrole",
")",
":",
"''",
")",
"+",
"'\"]'",
";",
"if",
"(",
"role",
".",
"roleId",
")",
"{",
"if",
"(",
"selector",
"&&",
"role",
".",
"roleId",
"==",
"'*'",
")",
"start",
"=",
"'[role-marker^=\"'",
"+",
"start",
"+",
"'(\"][role-marker$=\")'",
";",
"else",
"start",
"=",
"'[role-marker=\"'",
"+",
"start",
"+",
"'('",
"+",
"escapeQuotes",
"(",
"role",
".",
"roleId",
")",
"+",
"')'",
";",
"}",
"else",
"{",
"start",
"=",
"'[role-marker=\"'",
"+",
"start",
";",
"}",
"return",
"start",
"+",
"end",
";",
"}",
")",
".",
"join",
"(",
"' '",
")",
";",
"}"
] |
`show` event
Transforms given path to a css selector
@param {string} path
@param {string} selector
@private
@return {string}
|
[
"show",
"event",
"Transforms",
"given",
"path",
"to",
"a",
"css",
"selector"
] |
8571903014b207a09d45ad2d1bfba277bf21289b
|
https://github.com/basisjs/basisjs/blob/8571903014b207a09d45ad2d1bfba277bf21289b/src/basis/tracker.js#L139-L161
|
train
|
basisjs/basisjs
|
src/basis/tracker.js
|
checkShow
|
function checkShow(){
/**
* Checks visibility of an element on a page in a browser
* @param {HTMLElement} element some DOM node
* @private
* @return {boolean}
*/
function isVisible(element){
if (getComputedStyle(element, 'visibility') != 'visible')
return false;
var box = getBoundingRect(element);
if (!box.width || !box.height)
return false;
return true;
}
var list = getSelectorList(SHOW_EVENT);
for (var i = 0; i < list.length; i++)
{
var selector = list[i];
var elements = document.querySelectorAll(getCssSelectorFromPath(selector.selector, true));
var visibleElement = basis.array.search(basis.array(elements), true, isVisible);
var visible = Boolean(visibleElement);
var state;
if (!hasOwnProperty.call(list.visible, selector.selectorStr))
state = list.visible[selector.selectorStr] = false;
else
state = list.visible[selector.selectorStr];
list.visible[selector.selectorStr] = visible;
if (state == false && visible)
track({
type: 'ui',
path: stringifyPath(getPathByNode(visibleElement)),
selector: selector.selectorStr,
event: SHOW_EVENT,
data: selector.data
});
}
}
|
javascript
|
function checkShow(){
/**
* Checks visibility of an element on a page in a browser
* @param {HTMLElement} element some DOM node
* @private
* @return {boolean}
*/
function isVisible(element){
if (getComputedStyle(element, 'visibility') != 'visible')
return false;
var box = getBoundingRect(element);
if (!box.width || !box.height)
return false;
return true;
}
var list = getSelectorList(SHOW_EVENT);
for (var i = 0; i < list.length; i++)
{
var selector = list[i];
var elements = document.querySelectorAll(getCssSelectorFromPath(selector.selector, true));
var visibleElement = basis.array.search(basis.array(elements), true, isVisible);
var visible = Boolean(visibleElement);
var state;
if (!hasOwnProperty.call(list.visible, selector.selectorStr))
state = list.visible[selector.selectorStr] = false;
else
state = list.visible[selector.selectorStr];
list.visible[selector.selectorStr] = visible;
if (state == false && visible)
track({
type: 'ui',
path: stringifyPath(getPathByNode(visibleElement)),
selector: selector.selectorStr,
event: SHOW_EVENT,
data: selector.data
});
}
}
|
[
"function",
"checkShow",
"(",
")",
"{",
"function",
"isVisible",
"(",
"element",
")",
"{",
"if",
"(",
"getComputedStyle",
"(",
"element",
",",
"'visibility'",
")",
"!=",
"'visible'",
")",
"return",
"false",
";",
"var",
"box",
"=",
"getBoundingRect",
"(",
"element",
")",
";",
"if",
"(",
"!",
"box",
".",
"width",
"||",
"!",
"box",
".",
"height",
")",
"return",
"false",
";",
"return",
"true",
";",
"}",
"var",
"list",
"=",
"getSelectorList",
"(",
"SHOW_EVENT",
")",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"list",
".",
"length",
";",
"i",
"++",
")",
"{",
"var",
"selector",
"=",
"list",
"[",
"i",
"]",
";",
"var",
"elements",
"=",
"document",
".",
"querySelectorAll",
"(",
"getCssSelectorFromPath",
"(",
"selector",
".",
"selector",
",",
"true",
")",
")",
";",
"var",
"visibleElement",
"=",
"basis",
".",
"array",
".",
"search",
"(",
"basis",
".",
"array",
"(",
"elements",
")",
",",
"true",
",",
"isVisible",
")",
";",
"var",
"visible",
"=",
"Boolean",
"(",
"visibleElement",
")",
";",
"var",
"state",
";",
"if",
"(",
"!",
"hasOwnProperty",
".",
"call",
"(",
"list",
".",
"visible",
",",
"selector",
".",
"selectorStr",
")",
")",
"state",
"=",
"list",
".",
"visible",
"[",
"selector",
".",
"selectorStr",
"]",
"=",
"false",
";",
"else",
"state",
"=",
"list",
".",
"visible",
"[",
"selector",
".",
"selectorStr",
"]",
";",
"list",
".",
"visible",
"[",
"selector",
".",
"selectorStr",
"]",
"=",
"visible",
";",
"if",
"(",
"state",
"==",
"false",
"&&",
"visible",
")",
"track",
"(",
"{",
"type",
":",
"'ui'",
",",
"path",
":",
"stringifyPath",
"(",
"getPathByNode",
"(",
"visibleElement",
")",
")",
",",
"selector",
":",
"selector",
".",
"selectorStr",
",",
"event",
":",
"SHOW_EVENT",
",",
"data",
":",
"selector",
".",
"data",
"}",
")",
";",
"}",
"}"
] |
Tracks visibilty changes for nodes marked with show event in custom tracking maps
@private
@return
|
[
"Tracks",
"visibilty",
"changes",
"for",
"nodes",
"marked",
"with",
"show",
"event",
"in",
"custom",
"tracking",
"maps"
] |
8571903014b207a09d45ad2d1bfba277bf21289b
|
https://github.com/basisjs/basisjs/blob/8571903014b207a09d45ad2d1bfba277bf21289b/src/basis/tracker.js#L168-L213
|
train
|
basisjs/basisjs
|
src/basis/tracker.js
|
isVisible
|
function isVisible(element){
if (getComputedStyle(element, 'visibility') != 'visible')
return false;
var box = getBoundingRect(element);
if (!box.width || !box.height)
return false;
return true;
}
|
javascript
|
function isVisible(element){
if (getComputedStyle(element, 'visibility') != 'visible')
return false;
var box = getBoundingRect(element);
if (!box.width || !box.height)
return false;
return true;
}
|
[
"function",
"isVisible",
"(",
"element",
")",
"{",
"if",
"(",
"getComputedStyle",
"(",
"element",
",",
"'visibility'",
")",
"!=",
"'visible'",
")",
"return",
"false",
";",
"var",
"box",
"=",
"getBoundingRect",
"(",
"element",
")",
";",
"if",
"(",
"!",
"box",
".",
"width",
"||",
"!",
"box",
".",
"height",
")",
"return",
"false",
";",
"return",
"true",
";",
"}"
] |
Checks visibility of an element on a page in a browser
@param {HTMLElement} element some DOM node
@private
@return {boolean}
|
[
"Checks",
"visibility",
"of",
"an",
"element",
"on",
"a",
"page",
"in",
"a",
"browser"
] |
8571903014b207a09d45ad2d1bfba277bf21289b
|
https://github.com/basisjs/basisjs/blob/8571903014b207a09d45ad2d1bfba277bf21289b/src/basis/tracker.js#L175-L185
|
train
|
basisjs/basisjs
|
src/basis/tracker.js
|
getSelectorList
|
function getSelectorList(eventName){
if (hasOwnProperty.call(eventMap, eventName))
return eventMap[eventName];
var selectorList = eventMap[eventName] = [];
var inputTimeout = null;
switch (eventName) {
case SHOW_EVENT:
selectorList.visible = {};
setInterval(checkShow, VISIBLE_CHECK_INTERVAL);
break;
default:
eventUtils.addGlobalHandler(eventName, function(event){
var path = event.path.reduce(function(res, node){
var role = node.getAttribute ? node.getAttribute('role-marker') : null;
if (role)
res.unshift(parseRole(role));
return res;
}, []);
// if there is at least one `role-marker` attribute in the DOM [x]path for the clicked (or hovered or `event`ed) element
// then lets search a matching selector in our loaded track map
if (path.length)
selectorList.forEach(function(item){
var result = handleEventFor(path, item, event);
if (result)
if (result.debounce)
{
clearTimeout(inputTimeout);
inputTimeout = setTimeout(function(){
track(result.dataToTrack);
}, INPUT_DEBOUNCE_TIMEOUT);
}
else
{
track(result.dataToTrack);
}
});
});
}
return selectorList;
}
|
javascript
|
function getSelectorList(eventName){
if (hasOwnProperty.call(eventMap, eventName))
return eventMap[eventName];
var selectorList = eventMap[eventName] = [];
var inputTimeout = null;
switch (eventName) {
case SHOW_EVENT:
selectorList.visible = {};
setInterval(checkShow, VISIBLE_CHECK_INTERVAL);
break;
default:
eventUtils.addGlobalHandler(eventName, function(event){
var path = event.path.reduce(function(res, node){
var role = node.getAttribute ? node.getAttribute('role-marker') : null;
if (role)
res.unshift(parseRole(role));
return res;
}, []);
// if there is at least one `role-marker` attribute in the DOM [x]path for the clicked (or hovered or `event`ed) element
// then lets search a matching selector in our loaded track map
if (path.length)
selectorList.forEach(function(item){
var result = handleEventFor(path, item, event);
if (result)
if (result.debounce)
{
clearTimeout(inputTimeout);
inputTimeout = setTimeout(function(){
track(result.dataToTrack);
}, INPUT_DEBOUNCE_TIMEOUT);
}
else
{
track(result.dataToTrack);
}
});
});
}
return selectorList;
}
|
[
"function",
"getSelectorList",
"(",
"eventName",
")",
"{",
"if",
"(",
"hasOwnProperty",
".",
"call",
"(",
"eventMap",
",",
"eventName",
")",
")",
"return",
"eventMap",
"[",
"eventName",
"]",
";",
"var",
"selectorList",
"=",
"eventMap",
"[",
"eventName",
"]",
"=",
"[",
"]",
";",
"var",
"inputTimeout",
"=",
"null",
";",
"switch",
"(",
"eventName",
")",
"{",
"case",
"SHOW_EVENT",
":",
"selectorList",
".",
"visible",
"=",
"{",
"}",
";",
"setInterval",
"(",
"checkShow",
",",
"VISIBLE_CHECK_INTERVAL",
")",
";",
"break",
";",
"default",
":",
"eventUtils",
".",
"addGlobalHandler",
"(",
"eventName",
",",
"function",
"(",
"event",
")",
"{",
"var",
"path",
"=",
"event",
".",
"path",
".",
"reduce",
"(",
"function",
"(",
"res",
",",
"node",
")",
"{",
"var",
"role",
"=",
"node",
".",
"getAttribute",
"?",
"node",
".",
"getAttribute",
"(",
"'role-marker'",
")",
":",
"null",
";",
"if",
"(",
"role",
")",
"res",
".",
"unshift",
"(",
"parseRole",
"(",
"role",
")",
")",
";",
"return",
"res",
";",
"}",
",",
"[",
"]",
")",
";",
"if",
"(",
"path",
".",
"length",
")",
"selectorList",
".",
"forEach",
"(",
"function",
"(",
"item",
")",
"{",
"var",
"result",
"=",
"handleEventFor",
"(",
"path",
",",
"item",
",",
"event",
")",
";",
"if",
"(",
"result",
")",
"if",
"(",
"result",
".",
"debounce",
")",
"{",
"clearTimeout",
"(",
"inputTimeout",
")",
";",
"inputTimeout",
"=",
"setTimeout",
"(",
"function",
"(",
")",
"{",
"track",
"(",
"result",
".",
"dataToTrack",
")",
";",
"}",
",",
"INPUT_DEBOUNCE_TIMEOUT",
")",
";",
"}",
"else",
"{",
"track",
"(",
"result",
".",
"dataToTrack",
")",
";",
"}",
"}",
")",
";",
"}",
")",
";",
"}",
"return",
"selectorList",
";",
"}"
] |
Fills up the eventMap, also adds a handler for each browser event, mentioned in custom tracking maps
@param {string} eventName browser event.type or SHOW_EVENT
@private
@return {Array}
|
[
"Fills",
"up",
"the",
"eventMap",
"also",
"adds",
"a",
"handler",
"for",
"each",
"browser",
"event",
"mentioned",
"in",
"custom",
"tracking",
"maps"
] |
8571903014b207a09d45ad2d1bfba277bf21289b
|
https://github.com/basisjs/basisjs/blob/8571903014b207a09d45ad2d1bfba277bf21289b/src/basis/tracker.js#L333-L377
|
train
|
basisjs/basisjs
|
src/basis/tracker.js
|
getEventList
|
function getEventList(selector){
var selectorStr = stringifyPath(selector);
if (hasOwnProperty.call(selectorMap, selectorStr))
return selectorMap[selectorStr];
var eventList = selectorMap[selectorStr] = [];
eventList.selectorStr = selectorStr;
eventList.selector = selector;
return eventList;
}
|
javascript
|
function getEventList(selector){
var selectorStr = stringifyPath(selector);
if (hasOwnProperty.call(selectorMap, selectorStr))
return selectorMap[selectorStr];
var eventList = selectorMap[selectorStr] = [];
eventList.selectorStr = selectorStr;
eventList.selector = selector;
return eventList;
}
|
[
"function",
"getEventList",
"(",
"selector",
")",
"{",
"var",
"selectorStr",
"=",
"stringifyPath",
"(",
"selector",
")",
";",
"if",
"(",
"hasOwnProperty",
".",
"call",
"(",
"selectorMap",
",",
"selectorStr",
")",
")",
"return",
"selectorMap",
"[",
"selectorStr",
"]",
";",
"var",
"eventList",
"=",
"selectorMap",
"[",
"selectorStr",
"]",
"=",
"[",
"]",
";",
"eventList",
".",
"selectorStr",
"=",
"selectorStr",
";",
"eventList",
".",
"selector",
"=",
"selector",
";",
"return",
"eventList",
";",
"}"
] |
if there is no such selector in the `selectorMap`, creates empty array
@param {string} selector
@private
@return {Array}
|
[
"if",
"there",
"is",
"no",
"such",
"selector",
"in",
"the",
"selectorMap",
"creates",
"empty",
"array"
] |
8571903014b207a09d45ad2d1bfba277bf21289b
|
https://github.com/basisjs/basisjs/blob/8571903014b207a09d45ad2d1bfba277bf21289b/src/basis/tracker.js#L385-L397
|
train
|
basisjs/basisjs
|
src/basis/tracker.js
|
stringifyRole
|
function stringifyRole(role){
if (typeof role == 'string')
return role;
if (!role)
return '';
return [
role.role || '',
role.roleId ? '(' + role.roleId + ')' : '',
role.subrole ? '/' + role.subrole : ''
].join('');
}
|
javascript
|
function stringifyRole(role){
if (typeof role == 'string')
return role;
if (!role)
return '';
return [
role.role || '',
role.roleId ? '(' + role.roleId + ')' : '',
role.subrole ? '/' + role.subrole : ''
].join('');
}
|
[
"function",
"stringifyRole",
"(",
"role",
")",
"{",
"if",
"(",
"typeof",
"role",
"==",
"'string'",
")",
"return",
"role",
";",
"if",
"(",
"!",
"role",
")",
"return",
"''",
";",
"return",
"[",
"role",
".",
"role",
"||",
"''",
",",
"role",
".",
"roleId",
"?",
"'('",
"+",
"role",
".",
"roleId",
"+",
"')'",
":",
"''",
",",
"role",
".",
"subrole",
"?",
"'/'",
"+",
"role",
".",
"subrole",
":",
"''",
"]",
".",
"join",
"(",
"''",
")",
";",
"}"
] |
Inverse to parseRole function.
Is used in devpanel.
@param {string|RoleObject} role
@return {string}
|
[
"Inverse",
"to",
"parseRole",
"function",
".",
"Is",
"used",
"in",
"devpanel",
"."
] |
8571903014b207a09d45ad2d1bfba277bf21289b
|
https://github.com/basisjs/basisjs/blob/8571903014b207a09d45ad2d1bfba277bf21289b/src/basis/tracker.js#L478-L490
|
train
|
basisjs/basisjs
|
src/basis/tracker.js
|
parsePath
|
function parsePath(value){
if (!Array.isArray(value))
value = String(value || '').trim().split(/\s+/);
return value.map(function(part){
if (typeof part == 'string')
return parseRole(part);
return part || {
role: '',
roleId: '',
subrole: ''
};
});
}
|
javascript
|
function parsePath(value){
if (!Array.isArray(value))
value = String(value || '').trim().split(/\s+/);
return value.map(function(part){
if (typeof part == 'string')
return parseRole(part);
return part || {
role: '',
roleId: '',
subrole: ''
};
});
}
|
[
"function",
"parsePath",
"(",
"value",
")",
"{",
"if",
"(",
"!",
"Array",
".",
"isArray",
"(",
"value",
")",
")",
"value",
"=",
"String",
"(",
"value",
"||",
"''",
")",
".",
"trim",
"(",
")",
".",
"split",
"(",
"/",
"\\s+",
"/",
")",
";",
"return",
"value",
".",
"map",
"(",
"function",
"(",
"part",
")",
"{",
"if",
"(",
"typeof",
"part",
"==",
"'string'",
")",
"return",
"parseRole",
"(",
"part",
")",
";",
"return",
"part",
"||",
"{",
"role",
":",
"''",
",",
"roleId",
":",
"''",
",",
"subrole",
":",
"''",
"}",
";",
"}",
")",
";",
"}"
] |
Parses a string or a list to a list of role objects.
Private except for tests.
@param {string|Array.<string>} value
@return {Array.<RoleObject>}
|
[
"Parses",
"a",
"string",
"or",
"a",
"list",
"to",
"a",
"list",
"of",
"role",
"objects",
".",
"Private",
"except",
"for",
"tests",
"."
] |
8571903014b207a09d45ad2d1bfba277bf21289b
|
https://github.com/basisjs/basisjs/blob/8571903014b207a09d45ad2d1bfba277bf21289b/src/basis/tracker.js#L498-L512
|
train
|
basisjs/basisjs
|
src/basis/tracker.js
|
isPathMatchSelector
|
function isPathMatchSelector(path, selector){
function isMatch(path, selector){
path = typeof path == 'string' ? parseRole(path) : path || '';
selector = typeof selector == 'string' ? parseRole(selector) : selector || '';
return selector.role == path.role &&
(selector.roleId == '*' || selector.roleId == path.roleId) &&
selector.subrole == path.subrole;
}
var pathIndex = path.length;
var selectorIndex = selector.length;
if (!selectorIndex)
return true;
if (!isMatch(path[--pathIndex], selector[--selectorIndex]))
return false;
while (pathIndex > 0 && selectorIndex > 0)
if (!isMatch(path[--pathIndex], selector[--selectorIndex]))
selectorIndex++;
return selectorIndex === 0;
}
|
javascript
|
function isPathMatchSelector(path, selector){
function isMatch(path, selector){
path = typeof path == 'string' ? parseRole(path) : path || '';
selector = typeof selector == 'string' ? parseRole(selector) : selector || '';
return selector.role == path.role &&
(selector.roleId == '*' || selector.roleId == path.roleId) &&
selector.subrole == path.subrole;
}
var pathIndex = path.length;
var selectorIndex = selector.length;
if (!selectorIndex)
return true;
if (!isMatch(path[--pathIndex], selector[--selectorIndex]))
return false;
while (pathIndex > 0 && selectorIndex > 0)
if (!isMatch(path[--pathIndex], selector[--selectorIndex]))
selectorIndex++;
return selectorIndex === 0;
}
|
[
"function",
"isPathMatchSelector",
"(",
"path",
",",
"selector",
")",
"{",
"function",
"isMatch",
"(",
"path",
",",
"selector",
")",
"{",
"path",
"=",
"typeof",
"path",
"==",
"'string'",
"?",
"parseRole",
"(",
"path",
")",
":",
"path",
"||",
"''",
";",
"selector",
"=",
"typeof",
"selector",
"==",
"'string'",
"?",
"parseRole",
"(",
"selector",
")",
":",
"selector",
"||",
"''",
";",
"return",
"selector",
".",
"role",
"==",
"path",
".",
"role",
"&&",
"(",
"selector",
".",
"roleId",
"==",
"'*'",
"||",
"selector",
".",
"roleId",
"==",
"path",
".",
"roleId",
")",
"&&",
"selector",
".",
"subrole",
"==",
"path",
".",
"subrole",
";",
"}",
"var",
"pathIndex",
"=",
"path",
".",
"length",
";",
"var",
"selectorIndex",
"=",
"selector",
".",
"length",
";",
"if",
"(",
"!",
"selectorIndex",
")",
"return",
"true",
";",
"if",
"(",
"!",
"isMatch",
"(",
"path",
"[",
"--",
"pathIndex",
"]",
",",
"selector",
"[",
"--",
"selectorIndex",
"]",
")",
")",
"return",
"false",
";",
"while",
"(",
"pathIndex",
">",
"0",
"&&",
"selectorIndex",
">",
"0",
")",
"if",
"(",
"!",
"isMatch",
"(",
"path",
"[",
"--",
"pathIndex",
"]",
",",
"selector",
"[",
"--",
"selectorIndex",
"]",
")",
")",
"selectorIndex",
"++",
";",
"return",
"selectorIndex",
"===",
"0",
";",
"}"
] |
private except for tests
@param {Array.<RoleObject>} path
@param {string|RoleObject} selector
@return {boolean}
|
[
"private",
"except",
"for",
"tests"
] |
8571903014b207a09d45ad2d1bfba277bf21289b
|
https://github.com/basisjs/basisjs/blob/8571903014b207a09d45ad2d1bfba277bf21289b/src/basis/tracker.js#L533-L557
|
train
|
basisjs/basisjs
|
src/basis/tracker.js
|
getInfo
|
function getInfo(path){
var result = [];
if (typeof path == 'string')
path = parsePath(path);
for (var key in selectorMap)
if (isPathMatchSelector(path, selectorMap[key].selector))
result.push.apply(result, selectorMap[key].map(function(item){
return basis.object.extend({
selector: selectorMap[key].selector,
selectorStr: selectorMap[key].selectorStr
}, item);
}));
return result.length ? result : false;
}
|
javascript
|
function getInfo(path){
var result = [];
if (typeof path == 'string')
path = parsePath(path);
for (var key in selectorMap)
if (isPathMatchSelector(path, selectorMap[key].selector))
result.push.apply(result, selectorMap[key].map(function(item){
return basis.object.extend({
selector: selectorMap[key].selector,
selectorStr: selectorMap[key].selectorStr
}, item);
}));
return result.length ? result : false;
}
|
[
"function",
"getInfo",
"(",
"path",
")",
"{",
"var",
"result",
"=",
"[",
"]",
";",
"if",
"(",
"typeof",
"path",
"==",
"'string'",
")",
"path",
"=",
"parsePath",
"(",
"path",
")",
";",
"for",
"(",
"var",
"key",
"in",
"selectorMap",
")",
"if",
"(",
"isPathMatchSelector",
"(",
"path",
",",
"selectorMap",
"[",
"key",
"]",
".",
"selector",
")",
")",
"result",
".",
"push",
".",
"apply",
"(",
"result",
",",
"selectorMap",
"[",
"key",
"]",
".",
"map",
"(",
"function",
"(",
"item",
")",
"{",
"return",
"basis",
".",
"object",
".",
"extend",
"(",
"{",
"selector",
":",
"selectorMap",
"[",
"key",
"]",
".",
"selector",
",",
"selectorStr",
":",
"selectorMap",
"[",
"key",
"]",
".",
"selectorStr",
"}",
",",
"item",
")",
";",
"}",
")",
")",
";",
"return",
"result",
".",
"length",
"?",
"result",
":",
"false",
";",
"}"
] |
Relies on `selectorMap`
Is used in devpanel.
@param {string|Array.<RoleObject>} path
@return {Array.<Object>|boolean} here Object is a tracking data object
|
[
"Relies",
"on",
"selectorMap",
"Is",
"used",
"in",
"devpanel",
"."
] |
8571903014b207a09d45ad2d1bfba277bf21289b
|
https://github.com/basisjs/basisjs/blob/8571903014b207a09d45ad2d1bfba277bf21289b/src/basis/tracker.js#L565-L581
|
train
|
basisjs/basisjs
|
src/basis/tracker.js
|
getPathByNode
|
function getPathByNode(node){
var cursor = node;
var path = [];
var role;
while (cursor && cursor !== document)
{
if (role = cursor.getAttribute('role-marker'))
path.unshift(parseRole(role));
cursor = cursor.parentNode;
}
return path;
}
|
javascript
|
function getPathByNode(node){
var cursor = node;
var path = [];
var role;
while (cursor && cursor !== document)
{
if (role = cursor.getAttribute('role-marker'))
path.unshift(parseRole(role));
cursor = cursor.parentNode;
}
return path;
}
|
[
"function",
"getPathByNode",
"(",
"node",
")",
"{",
"var",
"cursor",
"=",
"node",
";",
"var",
"path",
"=",
"[",
"]",
";",
"var",
"role",
";",
"while",
"(",
"cursor",
"&&",
"cursor",
"!==",
"document",
")",
"{",
"if",
"(",
"role",
"=",
"cursor",
".",
"getAttribute",
"(",
"'role-marker'",
")",
")",
"path",
".",
"unshift",
"(",
"parseRole",
"(",
"role",
")",
")",
";",
"cursor",
"=",
"cursor",
".",
"parentNode",
";",
"}",
"return",
"path",
";",
"}"
] |
Works similar to `parsePath` but for DOM nodes, not for strings
Is used in devpanel.
@param {HTMLElement} node
@return {Array.<RoleObject>}
|
[
"Works",
"similar",
"to",
"parsePath",
"but",
"for",
"DOM",
"nodes",
"not",
"for",
"strings",
"Is",
"used",
"in",
"devpanel",
"."
] |
8571903014b207a09d45ad2d1bfba277bf21289b
|
https://github.com/basisjs/basisjs/blob/8571903014b207a09d45ad2d1bfba277bf21289b/src/basis/tracker.js#L589-L602
|
train
|
basisjs/basisjs
|
src/basis/tracker.js
|
loadMap
|
function loadMap(map){
if (!map)
{
/** @cut */ basis.dev.warn(namespace + '.loadMap(): Wrong value for map');
return;
}
for (var key in map)
{
var eventsMap = map[key];
if (!eventsMap)
{
/** @cut */ basis.dev.warn(namespace + '.loadMap(): Value of map should be an object for path: ' + key);
continue;
}
var selector = parsePath(key);
for (var events in eventsMap)
{
var data = eventsMap[events];
events.trim().split(/\s+/).forEach(function(eventName){
registrateSelector(selector, eventName, data);
});
}
}
}
|
javascript
|
function loadMap(map){
if (!map)
{
/** @cut */ basis.dev.warn(namespace + '.loadMap(): Wrong value for map');
return;
}
for (var key in map)
{
var eventsMap = map[key];
if (!eventsMap)
{
/** @cut */ basis.dev.warn(namespace + '.loadMap(): Value of map should be an object for path: ' + key);
continue;
}
var selector = parsePath(key);
for (var events in eventsMap)
{
var data = eventsMap[events];
events.trim().split(/\s+/).forEach(function(eventName){
registrateSelector(selector, eventName, data);
});
}
}
}
|
[
"function",
"loadMap",
"(",
"map",
")",
"{",
"if",
"(",
"!",
"map",
")",
"{",
"basis",
".",
"dev",
".",
"warn",
"(",
"namespace",
"+",
"'.loadMap(): Wrong value for map'",
")",
";",
"return",
";",
"}",
"for",
"(",
"var",
"key",
"in",
"map",
")",
"{",
"var",
"eventsMap",
"=",
"map",
"[",
"key",
"]",
";",
"if",
"(",
"!",
"eventsMap",
")",
"{",
"basis",
".",
"dev",
".",
"warn",
"(",
"namespace",
"+",
"'.loadMap(): Value of map should be an object for path: '",
"+",
"key",
")",
";",
"continue",
";",
"}",
"var",
"selector",
"=",
"parsePath",
"(",
"key",
")",
";",
"for",
"(",
"var",
"events",
"in",
"eventsMap",
")",
"{",
"var",
"data",
"=",
"eventsMap",
"[",
"events",
"]",
";",
"events",
".",
"trim",
"(",
")",
".",
"split",
"(",
"/",
"\\s+",
"/",
")",
".",
"forEach",
"(",
"function",
"(",
"eventName",
")",
"{",
"registrateSelector",
"(",
"selector",
",",
"eventName",
",",
"data",
")",
";",
"}",
")",
";",
"}",
"}",
"}"
] |
main API
Registers all selectors from a given map
@param {Object} map
@return
|
[
"main",
"API",
"Registers",
"all",
"selectors",
"from",
"a",
"given",
"map"
] |
8571903014b207a09d45ad2d1bfba277bf21289b
|
https://github.com/basisjs/basisjs/blob/8571903014b207a09d45ad2d1bfba277bf21289b/src/basis/tracker.js#L613-L640
|
train
|
basisjs/basisjs
|
src/basis/tracker.js
|
addDispatcher
|
function addDispatcher(dispatcher, events, transformer){
if (!dispatcher || typeof dispatcher.addHandler != 'function')
{
/** @cut */ basis.dev.warn(namespace + '.addDispatcher(): First argument should have `addHandler` method');
return;
}
if (typeof events == 'string')
events = events.split(/\s+/);
if (!Array.isArray(events))
{
/** @cut */ basis.dev.warn(namespace + '.addDispatcher(): Second argument should be a list of events');
return;
}
if (typeof transformer != 'function')
{
/** @cut */ basis.dev.warn(namespace + '.addDispatcher(): Third argument should be a function');
return;
}
dispatcher.addHandler({
'*': function(event){
if (events.indexOf(event.type) != -1)
{
var eventName = event.type;
var selectorList = getSelectorList(eventName);
selectorList.forEach(function(item){
var data = transformer(event, item);
if (data)
track(data);
});
}
}
});
return true;
}
|
javascript
|
function addDispatcher(dispatcher, events, transformer){
if (!dispatcher || typeof dispatcher.addHandler != 'function')
{
/** @cut */ basis.dev.warn(namespace + '.addDispatcher(): First argument should have `addHandler` method');
return;
}
if (typeof events == 'string')
events = events.split(/\s+/);
if (!Array.isArray(events))
{
/** @cut */ basis.dev.warn(namespace + '.addDispatcher(): Second argument should be a list of events');
return;
}
if (typeof transformer != 'function')
{
/** @cut */ basis.dev.warn(namespace + '.addDispatcher(): Third argument should be a function');
return;
}
dispatcher.addHandler({
'*': function(event){
if (events.indexOf(event.type) != -1)
{
var eventName = event.type;
var selectorList = getSelectorList(eventName);
selectorList.forEach(function(item){
var data = transformer(event, item);
if (data)
track(data);
});
}
}
});
return true;
}
|
[
"function",
"addDispatcher",
"(",
"dispatcher",
",",
"events",
",",
"transformer",
")",
"{",
"if",
"(",
"!",
"dispatcher",
"||",
"typeof",
"dispatcher",
".",
"addHandler",
"!=",
"'function'",
")",
"{",
"basis",
".",
"dev",
".",
"warn",
"(",
"namespace",
"+",
"'.addDispatcher(): First argument should have `addHandler` method'",
")",
";",
"return",
";",
"}",
"if",
"(",
"typeof",
"events",
"==",
"'string'",
")",
"events",
"=",
"events",
".",
"split",
"(",
"/",
"\\s+",
"/",
")",
";",
"if",
"(",
"!",
"Array",
".",
"isArray",
"(",
"events",
")",
")",
"{",
"basis",
".",
"dev",
".",
"warn",
"(",
"namespace",
"+",
"'.addDispatcher(): Second argument should be a list of events'",
")",
";",
"return",
";",
"}",
"if",
"(",
"typeof",
"transformer",
"!=",
"'function'",
")",
"{",
"basis",
".",
"dev",
".",
"warn",
"(",
"namespace",
"+",
"'.addDispatcher(): Third argument should be a function'",
")",
";",
"return",
";",
"}",
"dispatcher",
".",
"addHandler",
"(",
"{",
"'*'",
":",
"function",
"(",
"event",
")",
"{",
"if",
"(",
"events",
".",
"indexOf",
"(",
"event",
".",
"type",
")",
"!=",
"-",
"1",
")",
"{",
"var",
"eventName",
"=",
"event",
".",
"type",
";",
"var",
"selectorList",
"=",
"getSelectorList",
"(",
"eventName",
")",
";",
"selectorList",
".",
"forEach",
"(",
"function",
"(",
"item",
")",
"{",
"var",
"data",
"=",
"transformer",
"(",
"event",
",",
"item",
")",
";",
"if",
"(",
"data",
")",
"track",
"(",
"data",
")",
";",
"}",
")",
";",
"}",
"}",
"}",
")",
";",
"return",
"true",
";",
"}"
] |
A way to add custom data to a tracking data object
@param {{ addHandler: function(object) }} dispatcher basis.net.transportDispatcher or another basis.event.Emitter or any object with addHandler function
@param {string|Array} events list of events recognizable by `dispatcher`
@param {function(event, item):object} transformer function should return a tracking data object
@return {undefined|boolean}
|
[
"A",
"way",
"to",
"add",
"custom",
"data",
"to",
"a",
"tracking",
"data",
"object"
] |
8571903014b207a09d45ad2d1bfba277bf21289b
|
https://github.com/basisjs/basisjs/blob/8571903014b207a09d45ad2d1bfba277bf21289b/src/basis/tracker.js#L649-L689
|
train
|
basisjs/basisjs
|
src/basis/utils/utf8.js
|
fromBytes
|
function fromBytes(input){
var len = input.length;
var output = '';
for (var i = 0; i < len; i++)
output += chars[input[i]];
return output;
}
|
javascript
|
function fromBytes(input){
var len = input.length;
var output = '';
for (var i = 0; i < len; i++)
output += chars[input[i]];
return output;
}
|
[
"function",
"fromBytes",
"(",
"input",
")",
"{",
"var",
"len",
"=",
"input",
".",
"length",
";",
"var",
"output",
"=",
"''",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"len",
";",
"i",
"++",
")",
"output",
"+=",
"chars",
"[",
"input",
"[",
"i",
"]",
"]",
";",
"return",
"output",
";",
"}"
] |
utf8 bytes array
|
[
"utf8",
"bytes",
"array"
] |
8571903014b207a09d45ad2d1bfba277bf21289b
|
https://github.com/basisjs/basisjs/blob/8571903014b207a09d45ad2d1bfba277bf21289b/src/basis/utils/utf8.js#L23-L31
|
train
|
basisjs/basisjs
|
src/basis/entity.js
|
getDelta
|
function getDelta(inserted, deleted){
var delta = {};
var result;
if (inserted && inserted.length)
result = delta.inserted = inserted;
if (deleted && deleted.length)
result = delta.deleted = deleted;
if (result)
return delta;
}
|
javascript
|
function getDelta(inserted, deleted){
var delta = {};
var result;
if (inserted && inserted.length)
result = delta.inserted = inserted;
if (deleted && deleted.length)
result = delta.deleted = deleted;
if (result)
return delta;
}
|
[
"function",
"getDelta",
"(",
"inserted",
",",
"deleted",
")",
"{",
"var",
"delta",
"=",
"{",
"}",
";",
"var",
"result",
";",
"if",
"(",
"inserted",
"&&",
"inserted",
".",
"length",
")",
"result",
"=",
"delta",
".",
"inserted",
"=",
"inserted",
";",
"if",
"(",
"deleted",
"&&",
"deleted",
".",
"length",
")",
"result",
"=",
"delta",
".",
"deleted",
"=",
"deleted",
";",
"if",
"(",
"result",
")",
"return",
"delta",
";",
"}"
] |
EntitySets
Returns delta object
@return {object|undefined}
|
[
"EntitySets",
"Returns",
"delta",
"object"
] |
8571903014b207a09d45ad2d1bfba277bf21289b
|
https://github.com/basisjs/basisjs/blob/8571903014b207a09d45ad2d1bfba277bf21289b/src/basis/entity.js#L220-L232
|
train
|
basisjs/basisjs
|
src/basis/data/dataset/Subtract.js
|
function(minuend, subtrahend){
var delta;
var operandsChanged = false;
var oldMinuend = this.minuend;
var oldSubtrahend = this.subtrahend;
minuend = resolveDataset(this, this.setMinuend, minuend, 'minuendRA_');
subtrahend = resolveDataset(this, this.setSubtrahend, subtrahend, 'subtrahendRA_');
// set new minuend if changed
if (oldMinuend !== minuend)
{
operandsChanged = true;
this.minuend = minuend;
var listenHandler = this.listen.minuend;
if (listenHandler)
{
if (oldMinuend)
oldMinuend.removeHandler(listenHandler, this);
if (minuend)
minuend.addHandler(listenHandler, this);
}
this.emit_minuendChanged(oldMinuend);
}
// set new subtrahend if changed
if (oldSubtrahend !== subtrahend)
{
operandsChanged = true;
this.subtrahend = subtrahend;
var listenHandler = this.listen.subtrahend;
if (listenHandler)
{
if (oldSubtrahend)
oldSubtrahend.removeHandler(listenHandler, this);
if (subtrahend)
subtrahend.addHandler(listenHandler, this);
}
this.emit_subtrahendChanged(oldSubtrahend);
}
if (!operandsChanged)
return false;
/** @cut */ basis.dev.setInfo(this, 'sourceInfo', {
/** @cut */ type: 'Subtract',
/** @cut */ source: [minuend, subtrahend]
/** @cut */ });
// apply changes
if (!minuend || !subtrahend)
{
if (this.itemCount)
this.emit_itemsChanged(delta = {
deleted: this.getItems()
});
}
else
{
var deleted = [];
var inserted = [];
for (var key in this.items_)
if (!minuend.items_[key] || subtrahend.items_[key])
deleted.push(this.items_[key]);
for (var key in minuend.items_)
if (!this.items_[key] && !subtrahend.items_[key])
inserted.push(minuend.items_[key]);
if (delta = getDelta(inserted, deleted))
this.emit_itemsChanged(delta);
}
return delta;
}
|
javascript
|
function(minuend, subtrahend){
var delta;
var operandsChanged = false;
var oldMinuend = this.minuend;
var oldSubtrahend = this.subtrahend;
minuend = resolveDataset(this, this.setMinuend, minuend, 'minuendRA_');
subtrahend = resolveDataset(this, this.setSubtrahend, subtrahend, 'subtrahendRA_');
// set new minuend if changed
if (oldMinuend !== minuend)
{
operandsChanged = true;
this.minuend = minuend;
var listenHandler = this.listen.minuend;
if (listenHandler)
{
if (oldMinuend)
oldMinuend.removeHandler(listenHandler, this);
if (minuend)
minuend.addHandler(listenHandler, this);
}
this.emit_minuendChanged(oldMinuend);
}
// set new subtrahend if changed
if (oldSubtrahend !== subtrahend)
{
operandsChanged = true;
this.subtrahend = subtrahend;
var listenHandler = this.listen.subtrahend;
if (listenHandler)
{
if (oldSubtrahend)
oldSubtrahend.removeHandler(listenHandler, this);
if (subtrahend)
subtrahend.addHandler(listenHandler, this);
}
this.emit_subtrahendChanged(oldSubtrahend);
}
if (!operandsChanged)
return false;
/** @cut */ basis.dev.setInfo(this, 'sourceInfo', {
/** @cut */ type: 'Subtract',
/** @cut */ source: [minuend, subtrahend]
/** @cut */ });
// apply changes
if (!minuend || !subtrahend)
{
if (this.itemCount)
this.emit_itemsChanged(delta = {
deleted: this.getItems()
});
}
else
{
var deleted = [];
var inserted = [];
for (var key in this.items_)
if (!minuend.items_[key] || subtrahend.items_[key])
deleted.push(this.items_[key]);
for (var key in minuend.items_)
if (!this.items_[key] && !subtrahend.items_[key])
inserted.push(minuend.items_[key]);
if (delta = getDelta(inserted, deleted))
this.emit_itemsChanged(delta);
}
return delta;
}
|
[
"function",
"(",
"minuend",
",",
"subtrahend",
")",
"{",
"var",
"delta",
";",
"var",
"operandsChanged",
"=",
"false",
";",
"var",
"oldMinuend",
"=",
"this",
".",
"minuend",
";",
"var",
"oldSubtrahend",
"=",
"this",
".",
"subtrahend",
";",
"minuend",
"=",
"resolveDataset",
"(",
"this",
",",
"this",
".",
"setMinuend",
",",
"minuend",
",",
"'minuendRA_'",
")",
";",
"subtrahend",
"=",
"resolveDataset",
"(",
"this",
",",
"this",
".",
"setSubtrahend",
",",
"subtrahend",
",",
"'subtrahendRA_'",
")",
";",
"if",
"(",
"oldMinuend",
"!==",
"minuend",
")",
"{",
"operandsChanged",
"=",
"true",
";",
"this",
".",
"minuend",
"=",
"minuend",
";",
"var",
"listenHandler",
"=",
"this",
".",
"listen",
".",
"minuend",
";",
"if",
"(",
"listenHandler",
")",
"{",
"if",
"(",
"oldMinuend",
")",
"oldMinuend",
".",
"removeHandler",
"(",
"listenHandler",
",",
"this",
")",
";",
"if",
"(",
"minuend",
")",
"minuend",
".",
"addHandler",
"(",
"listenHandler",
",",
"this",
")",
";",
"}",
"this",
".",
"emit_minuendChanged",
"(",
"oldMinuend",
")",
";",
"}",
"if",
"(",
"oldSubtrahend",
"!==",
"subtrahend",
")",
"{",
"operandsChanged",
"=",
"true",
";",
"this",
".",
"subtrahend",
"=",
"subtrahend",
";",
"var",
"listenHandler",
"=",
"this",
".",
"listen",
".",
"subtrahend",
";",
"if",
"(",
"listenHandler",
")",
"{",
"if",
"(",
"oldSubtrahend",
")",
"oldSubtrahend",
".",
"removeHandler",
"(",
"listenHandler",
",",
"this",
")",
";",
"if",
"(",
"subtrahend",
")",
"subtrahend",
".",
"addHandler",
"(",
"listenHandler",
",",
"this",
")",
";",
"}",
"this",
".",
"emit_subtrahendChanged",
"(",
"oldSubtrahend",
")",
";",
"}",
"if",
"(",
"!",
"operandsChanged",
")",
"return",
"false",
";",
"basis",
".",
"dev",
".",
"setInfo",
"(",
"this",
",",
"'sourceInfo'",
",",
"{",
"type",
":",
"'Subtract'",
",",
"source",
":",
"[",
"minuend",
",",
"subtrahend",
"]",
"}",
")",
";",
"if",
"(",
"!",
"minuend",
"||",
"!",
"subtrahend",
")",
"{",
"if",
"(",
"this",
".",
"itemCount",
")",
"this",
".",
"emit_itemsChanged",
"(",
"delta",
"=",
"{",
"deleted",
":",
"this",
".",
"getItems",
"(",
")",
"}",
")",
";",
"}",
"else",
"{",
"var",
"deleted",
"=",
"[",
"]",
";",
"var",
"inserted",
"=",
"[",
"]",
";",
"for",
"(",
"var",
"key",
"in",
"this",
".",
"items_",
")",
"if",
"(",
"!",
"minuend",
".",
"items_",
"[",
"key",
"]",
"||",
"subtrahend",
".",
"items_",
"[",
"key",
"]",
")",
"deleted",
".",
"push",
"(",
"this",
".",
"items_",
"[",
"key",
"]",
")",
";",
"for",
"(",
"var",
"key",
"in",
"minuend",
".",
"items_",
")",
"if",
"(",
"!",
"this",
".",
"items_",
"[",
"key",
"]",
"&&",
"!",
"subtrahend",
".",
"items_",
"[",
"key",
"]",
")",
"inserted",
".",
"push",
"(",
"minuend",
".",
"items_",
"[",
"key",
"]",
")",
";",
"if",
"(",
"delta",
"=",
"getDelta",
"(",
"inserted",
",",
"deleted",
")",
")",
"this",
".",
"emit_itemsChanged",
"(",
"delta",
")",
";",
"}",
"return",
"delta",
";",
"}"
] |
Set new minuend & subtrahend.
@param {basis.data.ReadOnlyDataset=} minuend
@param {basis.data.ReadOnlyDataset=} subtrahend
@return {object|boolean} Delta if changes happend
|
[
"Set",
"new",
"minuend",
"&",
"subtrahend",
"."
] |
8571903014b207a09d45ad2d1bfba277bf21289b
|
https://github.com/basisjs/basisjs/blob/8571903014b207a09d45ad2d1bfba277bf21289b/src/basis/data/dataset/Subtract.js#L140-L221
|
train
|
|
basisjs/basisjs
|
src/basis/template.js
|
resolveResource
|
function resolveResource(ref, baseURI){
// ref ~ "#123"
if (/^#\d+$/.test(ref))
return templateList[ref.substr(1)];
// ref ~ "id:foo"
if (/^id:/.test(ref))
return resolveSourceByDocumentId(ref.substr(3));
// ref ~ "foo.bar.baz"
if (/^[a-z0-9\.]+$/i.test(ref) && !/\.tmpl$/.test(ref))
return getSourceByPath(ref);
// ref ~ "./path/to/file.tmpl"
return basis.resource(basis.resource.resolveURI(ref, baseURI, '<b:include src=\"{url}\"/>'));
}
|
javascript
|
function resolveResource(ref, baseURI){
// ref ~ "#123"
if (/^#\d+$/.test(ref))
return templateList[ref.substr(1)];
// ref ~ "id:foo"
if (/^id:/.test(ref))
return resolveSourceByDocumentId(ref.substr(3));
// ref ~ "foo.bar.baz"
if (/^[a-z0-9\.]+$/i.test(ref) && !/\.tmpl$/.test(ref))
return getSourceByPath(ref);
// ref ~ "./path/to/file.tmpl"
return basis.resource(basis.resource.resolveURI(ref, baseURI, '<b:include src=\"{url}\"/>'));
}
|
[
"function",
"resolveResource",
"(",
"ref",
",",
"baseURI",
")",
"{",
"if",
"(",
"/",
"^#\\d+$",
"/",
".",
"test",
"(",
"ref",
")",
")",
"return",
"templateList",
"[",
"ref",
".",
"substr",
"(",
"1",
")",
"]",
";",
"if",
"(",
"/",
"^id:",
"/",
".",
"test",
"(",
"ref",
")",
")",
"return",
"resolveSourceByDocumentId",
"(",
"ref",
".",
"substr",
"(",
"3",
")",
")",
";",
"if",
"(",
"/",
"^[a-z0-9\\.]+$",
"/",
"i",
".",
"test",
"(",
"ref",
")",
"&&",
"!",
"/",
"\\.tmpl$",
"/",
".",
"test",
"(",
"ref",
")",
")",
"return",
"getSourceByPath",
"(",
"ref",
")",
";",
"return",
"basis",
".",
"resource",
"(",
"basis",
".",
"resource",
".",
"resolveURI",
"(",
"ref",
",",
"baseURI",
",",
"'<b:include src=\\\"{url}\\\"/>'",
")",
")",
";",
"}"
] |
Resolve source by given reference.
@param {string} ref
@param {string=} baseURI
|
[
"Resolve",
"source",
"by",
"given",
"reference",
"."
] |
8571903014b207a09d45ad2d1bfba277bf21289b
|
https://github.com/basisjs/basisjs/blob/8571903014b207a09d45ad2d1bfba277bf21289b/src/basis/template.js#L80-L95
|
train
|
basisjs/basisjs
|
src/basis/template.js
|
templateSourceUpdate
|
function templateSourceUpdate(){
if (this.destroyBuilder)
buildTemplate.call(this);
var cursor = this;
while (cursor = cursor.attaches_)
cursor.handler.call(cursor.context);
}
|
javascript
|
function templateSourceUpdate(){
if (this.destroyBuilder)
buildTemplate.call(this);
var cursor = this;
while (cursor = cursor.attaches_)
cursor.handler.call(cursor.context);
}
|
[
"function",
"templateSourceUpdate",
"(",
")",
"{",
"if",
"(",
"this",
".",
"destroyBuilder",
")",
"buildTemplate",
".",
"call",
"(",
"this",
")",
";",
"var",
"cursor",
"=",
"this",
";",
"while",
"(",
"cursor",
"=",
"cursor",
".",
"attaches_",
")",
"cursor",
".",
"handler",
".",
"call",
"(",
"cursor",
".",
"context",
")",
";",
"}"
] |
Template
Function calls when bb-value template source is changing
|
[
"Template",
"Function",
"calls",
"when",
"bb",
"-",
"value",
"template",
"source",
"is",
"changing"
] |
8571903014b207a09d45ad2d1bfba277bf21289b
|
https://github.com/basisjs/basisjs/blob/8571903014b207a09d45ad2d1bfba277bf21289b/src/basis/template.js#L105-L112
|
train
|
basisjs/basisjs
|
src/basis/template.js
|
buildTemplate
|
function buildTemplate(){
// build new declaration
var declaration = getDeclFromSource(this.source, this.baseURI, false, {
isolate: this.getIsolatePrefix()
});
// make functions and assign to template
var destroyBuilder = this.destroyBuilder;
var instances = {};
var funcs = this.builder(declaration.tokens, instances);
this.createInstance = funcs.createInstance;
this.clearInstance = funcs.destroyInstance;
this.destroyBuilder = funcs.destroy;
store.add(this.templateId, this, instances);
// for debug purposes only
/** @cut */ this.instances_ = instances;
/** @cut */ this.decl_ = declaration;
// process dependencies
var newDeps = declaration.deps;
var oldDeps = this.deps_;
this.deps_ = newDeps;
// detach old deps
if (oldDeps)
for (var i = 0, dep; dep = oldDeps[i]; i++)
dep.bindingBridge.detach(dep, templateSourceUpdate, this);
// attach new deps
if (newDeps)
for (var i = 0, dep; dep = newDeps[i]; i++)
dep.bindingBridge.attach(dep, templateSourceUpdate, this);
// apply resources
// start use new resource list and than stop use old resource list,
// in this order FOUC is less possible
var newResources = declaration.resources;
var oldResources = this.resources;
this.resources = newResources;
if (newResources)
for (var i = 0, item; item = newResources[i]; i++)
{
var resource = basis.resource(item.url).fetch();
if (typeof resource.startUse == 'function')
resource.startUse();
}
if (oldResources)
for (var i = 0, item; item = oldResources[i]; i++)
{
var resource = basis.resource(item.url).fetch();
if (typeof resource.stopUse == 'function')
resource.stopUse();
}
// destroy old instances if any
if (destroyBuilder)
destroyBuilder(true);
}
|
javascript
|
function buildTemplate(){
// build new declaration
var declaration = getDeclFromSource(this.source, this.baseURI, false, {
isolate: this.getIsolatePrefix()
});
// make functions and assign to template
var destroyBuilder = this.destroyBuilder;
var instances = {};
var funcs = this.builder(declaration.tokens, instances);
this.createInstance = funcs.createInstance;
this.clearInstance = funcs.destroyInstance;
this.destroyBuilder = funcs.destroy;
store.add(this.templateId, this, instances);
// for debug purposes only
/** @cut */ this.instances_ = instances;
/** @cut */ this.decl_ = declaration;
// process dependencies
var newDeps = declaration.deps;
var oldDeps = this.deps_;
this.deps_ = newDeps;
// detach old deps
if (oldDeps)
for (var i = 0, dep; dep = oldDeps[i]; i++)
dep.bindingBridge.detach(dep, templateSourceUpdate, this);
// attach new deps
if (newDeps)
for (var i = 0, dep; dep = newDeps[i]; i++)
dep.bindingBridge.attach(dep, templateSourceUpdate, this);
// apply resources
// start use new resource list and than stop use old resource list,
// in this order FOUC is less possible
var newResources = declaration.resources;
var oldResources = this.resources;
this.resources = newResources;
if (newResources)
for (var i = 0, item; item = newResources[i]; i++)
{
var resource = basis.resource(item.url).fetch();
if (typeof resource.startUse == 'function')
resource.startUse();
}
if (oldResources)
for (var i = 0, item; item = oldResources[i]; i++)
{
var resource = basis.resource(item.url).fetch();
if (typeof resource.stopUse == 'function')
resource.stopUse();
}
// destroy old instances if any
if (destroyBuilder)
destroyBuilder(true);
}
|
[
"function",
"buildTemplate",
"(",
")",
"{",
"var",
"declaration",
"=",
"getDeclFromSource",
"(",
"this",
".",
"source",
",",
"this",
".",
"baseURI",
",",
"false",
",",
"{",
"isolate",
":",
"this",
".",
"getIsolatePrefix",
"(",
")",
"}",
")",
";",
"var",
"destroyBuilder",
"=",
"this",
".",
"destroyBuilder",
";",
"var",
"instances",
"=",
"{",
"}",
";",
"var",
"funcs",
"=",
"this",
".",
"builder",
"(",
"declaration",
".",
"tokens",
",",
"instances",
")",
";",
"this",
".",
"createInstance",
"=",
"funcs",
".",
"createInstance",
";",
"this",
".",
"clearInstance",
"=",
"funcs",
".",
"destroyInstance",
";",
"this",
".",
"destroyBuilder",
"=",
"funcs",
".",
"destroy",
";",
"store",
".",
"add",
"(",
"this",
".",
"templateId",
",",
"this",
",",
"instances",
")",
";",
"this",
".",
"instances_",
"=",
"instances",
";",
"this",
".",
"decl_",
"=",
"declaration",
";",
"var",
"newDeps",
"=",
"declaration",
".",
"deps",
";",
"var",
"oldDeps",
"=",
"this",
".",
"deps_",
";",
"this",
".",
"deps_",
"=",
"newDeps",
";",
"if",
"(",
"oldDeps",
")",
"for",
"(",
"var",
"i",
"=",
"0",
",",
"dep",
";",
"dep",
"=",
"oldDeps",
"[",
"i",
"]",
";",
"i",
"++",
")",
"dep",
".",
"bindingBridge",
".",
"detach",
"(",
"dep",
",",
"templateSourceUpdate",
",",
"this",
")",
";",
"if",
"(",
"newDeps",
")",
"for",
"(",
"var",
"i",
"=",
"0",
",",
"dep",
";",
"dep",
"=",
"newDeps",
"[",
"i",
"]",
";",
"i",
"++",
")",
"dep",
".",
"bindingBridge",
".",
"attach",
"(",
"dep",
",",
"templateSourceUpdate",
",",
"this",
")",
";",
"var",
"newResources",
"=",
"declaration",
".",
"resources",
";",
"var",
"oldResources",
"=",
"this",
".",
"resources",
";",
"this",
".",
"resources",
"=",
"newResources",
";",
"if",
"(",
"newResources",
")",
"for",
"(",
"var",
"i",
"=",
"0",
",",
"item",
";",
"item",
"=",
"newResources",
"[",
"i",
"]",
";",
"i",
"++",
")",
"{",
"var",
"resource",
"=",
"basis",
".",
"resource",
"(",
"item",
".",
"url",
")",
".",
"fetch",
"(",
")",
";",
"if",
"(",
"typeof",
"resource",
".",
"startUse",
"==",
"'function'",
")",
"resource",
".",
"startUse",
"(",
")",
";",
"}",
"if",
"(",
"oldResources",
")",
"for",
"(",
"var",
"i",
"=",
"0",
",",
"item",
";",
"item",
"=",
"oldResources",
"[",
"i",
"]",
";",
"i",
"++",
")",
"{",
"var",
"resource",
"=",
"basis",
".",
"resource",
"(",
"item",
".",
"url",
")",
".",
"fetch",
"(",
")",
";",
"if",
"(",
"typeof",
"resource",
".",
"stopUse",
"==",
"'function'",
")",
"resource",
".",
"stopUse",
"(",
")",
";",
"}",
"if",
"(",
"destroyBuilder",
")",
"destroyBuilder",
"(",
"true",
")",
";",
"}"
] |
Internal function to build declaration by template source,
attach it to template and setup synchronization.
|
[
"Internal",
"function",
"to",
"build",
"declaration",
"by",
"template",
"source",
"attach",
"it",
"to",
"template",
"and",
"setup",
"synchronization",
"."
] |
8571903014b207a09d45ad2d1bfba277bf21289b
|
https://github.com/basisjs/basisjs/blob/8571903014b207a09d45ad2d1bfba277bf21289b/src/basis/template.js#L118-L182
|
train
|
basisjs/basisjs
|
src/basis/template.js
|
function(object, actionCallback, updateCallback, bindings, bindingInterface){
buildTemplate.call(this);
return this.createInstance(object, actionCallback, updateCallback, bindings, bindingInterface);
}
|
javascript
|
function(object, actionCallback, updateCallback, bindings, bindingInterface){
buildTemplate.call(this);
return this.createInstance(object, actionCallback, updateCallback, bindings, bindingInterface);
}
|
[
"function",
"(",
"object",
",",
"actionCallback",
",",
"updateCallback",
",",
"bindings",
",",
"bindingInterface",
")",
"{",
"buildTemplate",
".",
"call",
"(",
"this",
")",
";",
"return",
"this",
".",
"createInstance",
"(",
"object",
",",
"actionCallback",
",",
"updateCallback",
",",
"bindings",
",",
"bindingInterface",
")",
";",
"}"
] |
Create DOM structure and return object with references for it's nodes.
@param {object=} object Object which templateAction method will be called on events.
@param {function=} actionCallback
@param {function=} updateCallback
@param {object=} bindings
@param {object=} bindingInterface Object like { attach: function(object, handler, context), detach: function(object, handler, context) }
@return {object}
|
[
"Create",
"DOM",
"structure",
"and",
"return",
"object",
"with",
"references",
"for",
"it",
"s",
"nodes",
"."
] |
8571903014b207a09d45ad2d1bfba277bf21289b
|
https://github.com/basisjs/basisjs/blob/8571903014b207a09d45ad2d1bfba277bf21289b/src/basis/template.js#L310-L313
|
train
|
|
basisjs/basisjs
|
src/basis/template.js
|
function(source){
var oldSource = this.source;
if (oldSource != source)
{
if (typeof source == 'string')
{
var m = source.match(/^([a-z]+):/);
if (m)
{
source = source.substr(m[0].length);
switch (m[1])
{
case 'id':
// source from script element
source = resolveSourceByDocumentId(source);
break;
case 'path':
source = getSourceByPath(source);
break;
default:
/** @cut */ basis.dev.warn(namespace + '.Template.setSource: Unknown prefix ' + m[1] + ' for template source was ingnored.');
}
}
}
if (oldSource && oldSource.bindingBridge)
{
this.url = '';
this.baseURI = '';
oldSource.bindingBridge.detach(oldSource, templateSourceUpdate, this);
}
if (source && source.bindingBridge)
{
if (source.url)
{
this.url = source.url;
this.baseURI = path.dirname(source.url) + '/';
}
source.bindingBridge.attach(source, templateSourceUpdate, this);
}
this.source = source;
templateSourceUpdate.call(this);
}
}
|
javascript
|
function(source){
var oldSource = this.source;
if (oldSource != source)
{
if (typeof source == 'string')
{
var m = source.match(/^([a-z]+):/);
if (m)
{
source = source.substr(m[0].length);
switch (m[1])
{
case 'id':
// source from script element
source = resolveSourceByDocumentId(source);
break;
case 'path':
source = getSourceByPath(source);
break;
default:
/** @cut */ basis.dev.warn(namespace + '.Template.setSource: Unknown prefix ' + m[1] + ' for template source was ingnored.');
}
}
}
if (oldSource && oldSource.bindingBridge)
{
this.url = '';
this.baseURI = '';
oldSource.bindingBridge.detach(oldSource, templateSourceUpdate, this);
}
if (source && source.bindingBridge)
{
if (source.url)
{
this.url = source.url;
this.baseURI = path.dirname(source.url) + '/';
}
source.bindingBridge.attach(source, templateSourceUpdate, this);
}
this.source = source;
templateSourceUpdate.call(this);
}
}
|
[
"function",
"(",
"source",
")",
"{",
"var",
"oldSource",
"=",
"this",
".",
"source",
";",
"if",
"(",
"oldSource",
"!=",
"source",
")",
"{",
"if",
"(",
"typeof",
"source",
"==",
"'string'",
")",
"{",
"var",
"m",
"=",
"source",
".",
"match",
"(",
"/",
"^([a-z]+):",
"/",
")",
";",
"if",
"(",
"m",
")",
"{",
"source",
"=",
"source",
".",
"substr",
"(",
"m",
"[",
"0",
"]",
".",
"length",
")",
";",
"switch",
"(",
"m",
"[",
"1",
"]",
")",
"{",
"case",
"'id'",
":",
"source",
"=",
"resolveSourceByDocumentId",
"(",
"source",
")",
";",
"break",
";",
"case",
"'path'",
":",
"source",
"=",
"getSourceByPath",
"(",
"source",
")",
";",
"break",
";",
"default",
":",
"basis",
".",
"dev",
".",
"warn",
"(",
"namespace",
"+",
"'.Template.setSource: Unknown prefix '",
"+",
"m",
"[",
"1",
"]",
"+",
"' for template source was ingnored.'",
")",
";",
"}",
"}",
"}",
"if",
"(",
"oldSource",
"&&",
"oldSource",
".",
"bindingBridge",
")",
"{",
"this",
".",
"url",
"=",
"''",
";",
"this",
".",
"baseURI",
"=",
"''",
";",
"oldSource",
".",
"bindingBridge",
".",
"detach",
"(",
"oldSource",
",",
"templateSourceUpdate",
",",
"this",
")",
";",
"}",
"if",
"(",
"source",
"&&",
"source",
".",
"bindingBridge",
")",
"{",
"if",
"(",
"source",
".",
"url",
")",
"{",
"this",
".",
"url",
"=",
"source",
".",
"url",
";",
"this",
".",
"baseURI",
"=",
"path",
".",
"dirname",
"(",
"source",
".",
"url",
")",
"+",
"'/'",
";",
"}",
"source",
".",
"bindingBridge",
".",
"attach",
"(",
"source",
",",
"templateSourceUpdate",
",",
"this",
")",
";",
"}",
"this",
".",
"source",
"=",
"source",
";",
"templateSourceUpdate",
".",
"call",
"(",
"this",
")",
";",
"}",
"}"
] |
Set new content source for template.
@param {string|bb-value} source New content source for template.
|
[
"Set",
"new",
"content",
"source",
"for",
"template",
"."
] |
8571903014b207a09d45ad2d1bfba277bf21289b
|
https://github.com/basisjs/basisjs/blob/8571903014b207a09d45ad2d1bfba277bf21289b/src/basis/template.js#L335-L383
|
train
|
|
basisjs/basisjs
|
src/basis/template.js
|
function(config){
this.ruleRet_ = [];
this.templates_ = [];
this.rule = config.rule;
var events = config.events;
if (events && events.length)
{
this.ruleEvents = {};
for (var i = 0, eventName; eventName = events[i]; i++)
this.ruleEvents[eventName] = true;
}
cleaner.add(this);
}
|
javascript
|
function(config){
this.ruleRet_ = [];
this.templates_ = [];
this.rule = config.rule;
var events = config.events;
if (events && events.length)
{
this.ruleEvents = {};
for (var i = 0, eventName; eventName = events[i]; i++)
this.ruleEvents[eventName] = true;
}
cleaner.add(this);
}
|
[
"function",
"(",
"config",
")",
"{",
"this",
".",
"ruleRet_",
"=",
"[",
"]",
";",
"this",
".",
"templates_",
"=",
"[",
"]",
";",
"this",
".",
"rule",
"=",
"config",
".",
"rule",
";",
"var",
"events",
"=",
"config",
".",
"events",
";",
"if",
"(",
"events",
"&&",
"events",
".",
"length",
")",
"{",
"this",
".",
"ruleEvents",
"=",
"{",
"}",
";",
"for",
"(",
"var",
"i",
"=",
"0",
",",
"eventName",
";",
"eventName",
"=",
"events",
"[",
"i",
"]",
";",
"i",
"++",
")",
"this",
".",
"ruleEvents",
"[",
"eventName",
"]",
"=",
"true",
";",
"}",
"cleaner",
".",
"add",
"(",
"this",
")",
";",
"}"
] |
return empty string as template source
|
[
"return",
"empty",
"string",
"as",
"template",
"source"
] |
8571903014b207a09d45ad2d1bfba277bf21289b
|
https://github.com/basisjs/basisjs/blob/8571903014b207a09d45ad2d1bfba277bf21289b/src/basis/template.js#L455-L469
|
train
|
|
basisjs/basisjs
|
src/basis/template.js
|
switcher
|
function switcher(events, rule){
if (!rule)
{
rule = events;
events = null;
}
if (typeof events == 'string')
events = events.split(/\s+/);
return new TemplateSwitchConfig({
rule: rule,
events: events
});
}
|
javascript
|
function switcher(events, rule){
if (!rule)
{
rule = events;
events = null;
}
if (typeof events == 'string')
events = events.split(/\s+/);
return new TemplateSwitchConfig({
rule: rule,
events: events
});
}
|
[
"function",
"switcher",
"(",
"events",
",",
"rule",
")",
"{",
"if",
"(",
"!",
"rule",
")",
"{",
"rule",
"=",
"events",
";",
"events",
"=",
"null",
";",
"}",
"if",
"(",
"typeof",
"events",
"==",
"'string'",
")",
"events",
"=",
"events",
".",
"split",
"(",
"/",
"\\s+",
"/",
")",
";",
"return",
"new",
"TemplateSwitchConfig",
"(",
"{",
"rule",
":",
"rule",
",",
"events",
":",
"events",
"}",
")",
";",
"}"
] |
Helper to create TemplateSwitchConfig instance
@param {string|string[]} events
@param {function()} rule
|
[
"Helper",
"to",
"create",
"TemplateSwitchConfig",
"instance"
] |
8571903014b207a09d45ad2d1bfba277bf21289b
|
https://github.com/basisjs/basisjs/blob/8571903014b207a09d45ad2d1bfba277bf21289b/src/basis/template.js#L495-L509
|
train
|
basisjs/basisjs
|
src/basis/event.js
|
createDispatcher
|
function createDispatcher(eventName){
var eventFunction = events[eventName];
if (!eventFunction)
{
eventFunction = function(){
var cursor = this;
var args;
var fn;
while (cursor = cursor.handler)
{
// callback call
fn = cursor.callbacks[eventName];
if (typeof fn == 'function')
{
if (!args)
{
// it should be better for browser optimizations
// (instead of [this].concat(slice.call(arguments)))
args = [this];
for (var i = 0; i < arguments.length; i++)
args.push(arguments[i]);
}
fn.apply(cursor.context || this, args);
}
// any event callback call
fn = cursor.callbacks['*'];
if (typeof fn == 'function')
{
if (!args)
{
// it should be better for browser optimizations
// (instead of [this].concat(slice.call(arguments)))
args = [this];
for (var i = 0; i < arguments.length; i++)
args.push(arguments[i]);
}
fn.call(cursor.context || this, {
sender: this,
type: eventName,
args: args
});
}
}
// feature available in development mode only
/** @cut */ if (this.debug_emit)
/** @cut */ {
/** @cut */ args = []; // avoid optimization warnings about arguments
/** @cut */ for (var i = 0; i < arguments.length; i++)
/** @cut */ args.push(arguments[i]);
/** @cut */ this.debug_emit({
/** @cut */ sender: this,
/** @cut */ type: eventName,
/** @cut */ args: args
/** @cut */ });
/** @cut */ }
};
// function wrapper for more verbose in development mode
/** @cut */ eventFunction = new Function(
/** @cut */ 'return {"' + namespace + '.events.' + eventName + '":\n\n ' +
/** @cut */
/** @cut */ 'function(' + basis.array(arguments, 1).join(', ') + '){' +
/** @cut */ eventFunction.toString()
/** @cut */ .replace(/\beventName\b/g, '"' + eventName + '"')
/** @cut */ .replace(/^function[^(]*\(\)[^{]*\{|\}$/g, '') +
/** @cut */ '}' +
/** @cut */
/** @cut */ '\n\n}["' + namespace + '.events.' + eventName + '"];'
/** @cut */ )();
events[eventName] = eventFunction;
}
return eventFunction;
}
|
javascript
|
function createDispatcher(eventName){
var eventFunction = events[eventName];
if (!eventFunction)
{
eventFunction = function(){
var cursor = this;
var args;
var fn;
while (cursor = cursor.handler)
{
// callback call
fn = cursor.callbacks[eventName];
if (typeof fn == 'function')
{
if (!args)
{
// it should be better for browser optimizations
// (instead of [this].concat(slice.call(arguments)))
args = [this];
for (var i = 0; i < arguments.length; i++)
args.push(arguments[i]);
}
fn.apply(cursor.context || this, args);
}
// any event callback call
fn = cursor.callbacks['*'];
if (typeof fn == 'function')
{
if (!args)
{
// it should be better for browser optimizations
// (instead of [this].concat(slice.call(arguments)))
args = [this];
for (var i = 0; i < arguments.length; i++)
args.push(arguments[i]);
}
fn.call(cursor.context || this, {
sender: this,
type: eventName,
args: args
});
}
}
// feature available in development mode only
/** @cut */ if (this.debug_emit)
/** @cut */ {
/** @cut */ args = []; // avoid optimization warnings about arguments
/** @cut */ for (var i = 0; i < arguments.length; i++)
/** @cut */ args.push(arguments[i]);
/** @cut */ this.debug_emit({
/** @cut */ sender: this,
/** @cut */ type: eventName,
/** @cut */ args: args
/** @cut */ });
/** @cut */ }
};
// function wrapper for more verbose in development mode
/** @cut */ eventFunction = new Function(
/** @cut */ 'return {"' + namespace + '.events.' + eventName + '":\n\n ' +
/** @cut */
/** @cut */ 'function(' + basis.array(arguments, 1).join(', ') + '){' +
/** @cut */ eventFunction.toString()
/** @cut */ .replace(/\beventName\b/g, '"' + eventName + '"')
/** @cut */ .replace(/^function[^(]*\(\)[^{]*\{|\}$/g, '') +
/** @cut */ '}' +
/** @cut */
/** @cut */ '\n\n}["' + namespace + '.events.' + eventName + '"];'
/** @cut */ )();
events[eventName] = eventFunction;
}
return eventFunction;
}
|
[
"function",
"createDispatcher",
"(",
"eventName",
")",
"{",
"var",
"eventFunction",
"=",
"events",
"[",
"eventName",
"]",
";",
"if",
"(",
"!",
"eventFunction",
")",
"{",
"eventFunction",
"=",
"function",
"(",
")",
"{",
"var",
"cursor",
"=",
"this",
";",
"var",
"args",
";",
"var",
"fn",
";",
"while",
"(",
"cursor",
"=",
"cursor",
".",
"handler",
")",
"{",
"fn",
"=",
"cursor",
".",
"callbacks",
"[",
"eventName",
"]",
";",
"if",
"(",
"typeof",
"fn",
"==",
"'function'",
")",
"{",
"if",
"(",
"!",
"args",
")",
"{",
"args",
"=",
"[",
"this",
"]",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"arguments",
".",
"length",
";",
"i",
"++",
")",
"args",
".",
"push",
"(",
"arguments",
"[",
"i",
"]",
")",
";",
"}",
"fn",
".",
"apply",
"(",
"cursor",
".",
"context",
"||",
"this",
",",
"args",
")",
";",
"}",
"fn",
"=",
"cursor",
".",
"callbacks",
"[",
"'*'",
"]",
";",
"if",
"(",
"typeof",
"fn",
"==",
"'function'",
")",
"{",
"if",
"(",
"!",
"args",
")",
"{",
"args",
"=",
"[",
"this",
"]",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"arguments",
".",
"length",
";",
"i",
"++",
")",
"args",
".",
"push",
"(",
"arguments",
"[",
"i",
"]",
")",
";",
"}",
"fn",
".",
"call",
"(",
"cursor",
".",
"context",
"||",
"this",
",",
"{",
"sender",
":",
"this",
",",
"type",
":",
"eventName",
",",
"args",
":",
"args",
"}",
")",
";",
"}",
"}",
"if",
"(",
"this",
".",
"debug_emit",
")",
"{",
"args",
"=",
"[",
"]",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"arguments",
".",
"length",
";",
"i",
"++",
")",
"args",
".",
"push",
"(",
"arguments",
"[",
"i",
"]",
")",
";",
"this",
".",
"debug_emit",
"(",
"{",
"sender",
":",
"this",
",",
"type",
":",
"eventName",
",",
"args",
":",
"args",
"}",
")",
";",
"}",
"}",
";",
"eventFunction",
"=",
"new",
"Function",
"(",
"'return {\"'",
"+",
"namespace",
"+",
"'.events.'",
"+",
"eventName",
"+",
"'\":\\n\\n '",
"+",
"\\n",
"+",
"\\n",
"+",
"'function('",
"+",
"basis",
".",
"array",
"(",
"arguments",
",",
"1",
")",
".",
"join",
"(",
"', '",
")",
"+",
"'){'",
"+",
"eventFunction",
".",
"toString",
"(",
")",
".",
"replace",
"(",
"/",
"\\beventName\\b",
"/",
"g",
",",
"'\"'",
"+",
"eventName",
"+",
"'\"'",
")",
".",
"replace",
"(",
"/",
"^function[^(]*\\(\\)[^{]*\\{|\\}$",
"/",
"g",
",",
"''",
")",
"+",
"'}'",
"+",
"'\\n\\n}[\"'",
"+",
"\\n",
"+",
"\\n",
")",
"namespace",
";",
"'.events.'",
"}",
"eventName",
"}"
] |
Creates new type of event or returns existing one, if it was created before.
@param {string} eventName
@return {function(..eventArgs)}
|
[
"Creates",
"new",
"type",
"of",
"event",
"or",
"returns",
"existing",
"one",
"if",
"it",
"was",
"created",
"before",
"."
] |
8571903014b207a09d45ad2d1bfba277bf21289b
|
https://github.com/basisjs/basisjs/blob/8571903014b207a09d45ad2d1bfba277bf21289b/src/basis/event.js#L34-L114
|
train
|
basisjs/basisjs
|
src/basis/event.js
|
function(callbacks, context){
/** @cut */ if (!callbacks)
/** @cut */ basis.dev.warn(namespace + '.Emitter#addHandler: callbacks is not an object (', callbacks, ')');
context = context || this;
// warn about duplicates
/** @cut */ var cursor = this;
/** @cut */ while (cursor = cursor.handler)
/** @cut */ {
/** @cut */ if (cursor.callbacks === callbacks && cursor.context === context)
/** @cut */ {
/** @cut */ basis.dev.warn(namespace + '.Emitter#addHandler: add duplicate event callbacks', callbacks, 'to Emitter instance:', this);
/** @cut */ break;
/** @cut */ }
/** @cut */ }
// add handler
this.handler = {
callbacks: callbacks,
context: context,
handler: this.handler
};
}
|
javascript
|
function(callbacks, context){
/** @cut */ if (!callbacks)
/** @cut */ basis.dev.warn(namespace + '.Emitter#addHandler: callbacks is not an object (', callbacks, ')');
context = context || this;
// warn about duplicates
/** @cut */ var cursor = this;
/** @cut */ while (cursor = cursor.handler)
/** @cut */ {
/** @cut */ if (cursor.callbacks === callbacks && cursor.context === context)
/** @cut */ {
/** @cut */ basis.dev.warn(namespace + '.Emitter#addHandler: add duplicate event callbacks', callbacks, 'to Emitter instance:', this);
/** @cut */ break;
/** @cut */ }
/** @cut */ }
// add handler
this.handler = {
callbacks: callbacks,
context: context,
handler: this.handler
};
}
|
[
"function",
"(",
"callbacks",
",",
"context",
")",
"{",
"if",
"(",
"!",
"callbacks",
")",
"basis",
".",
"dev",
".",
"warn",
"(",
"namespace",
"+",
"'.Emitter#addHandler: callbacks is not an object ('",
",",
"callbacks",
",",
"')'",
")",
";",
"context",
"=",
"context",
"||",
"this",
";",
"var",
"cursor",
"=",
"this",
";",
"while",
"(",
"cursor",
"=",
"cursor",
".",
"handler",
")",
"{",
"if",
"(",
"cursor",
".",
"callbacks",
"===",
"callbacks",
"&&",
"cursor",
".",
"context",
"===",
"context",
")",
"{",
"basis",
".",
"dev",
".",
"warn",
"(",
"namespace",
"+",
"'.Emitter#addHandler: add duplicate event callbacks'",
",",
"callbacks",
",",
"'to Emitter instance:'",
",",
"this",
")",
";",
"break",
";",
"}",
"}",
"this",
".",
"handler",
"=",
"{",
"callbacks",
":",
"callbacks",
",",
"context",
":",
"context",
",",
"handler",
":",
"this",
".",
"handler",
"}",
";",
"}"
] |
Adds new event handler to object.
@param {object} callbacks Callback set.
@param {object=} context Context object.
|
[
"Adds",
"new",
"event",
"handler",
"to",
"object",
"."
] |
8571903014b207a09d45ad2d1bfba277bf21289b
|
https://github.com/basisjs/basisjs/blob/8571903014b207a09d45ad2d1bfba277bf21289b/src/basis/event.js#L238-L261
|
train
|
|
basisjs/basisjs
|
src/basis/router.js
|
checkUrl
|
function checkUrl(){
var newPath = location.hash.substr(1) || '';
if (newPath != currentPath)
{
// check for recursion
if (preventRecursion(newPath))
return;
// save current path
currentPath = newPath;
var routesToLeave = [];
var routesToEnter = [];
var routesToMatch = [];
allRoutes.forEach(function(route){
var flags = route.processLocation_(newPath);
if (flags & ROUTE_LEAVE)
routesToLeave.push(route);
if (flags & ROUTE_ENTER)
routesToEnter.push(route);
if (flags & ROUTE_MATCH)
routesToMatch.push(route);
});
for (var i = 0; i < routesToLeave.length; i++)
routeLeave(routesToLeave[i]);
for (var i = 0; i < routesToEnter.length; i++)
routeEnter(routesToEnter[i]);
for (var i = 0; i < routesToMatch.length; i++)
routeMatch(routesToMatch[i]);
/** @cut */ flushLog(namespace + ': hash changed to "' + newPath + '"');
}
else
{
allRoutes.forEach(function(route){
if (route.value)
{
routeEnter(route, true);
routeMatch(route, true);
}
});
/** @cut */ flushLog(namespace + ': checkUrl()');
}
}
|
javascript
|
function checkUrl(){
var newPath = location.hash.substr(1) || '';
if (newPath != currentPath)
{
// check for recursion
if (preventRecursion(newPath))
return;
// save current path
currentPath = newPath;
var routesToLeave = [];
var routesToEnter = [];
var routesToMatch = [];
allRoutes.forEach(function(route){
var flags = route.processLocation_(newPath);
if (flags & ROUTE_LEAVE)
routesToLeave.push(route);
if (flags & ROUTE_ENTER)
routesToEnter.push(route);
if (flags & ROUTE_MATCH)
routesToMatch.push(route);
});
for (var i = 0; i < routesToLeave.length; i++)
routeLeave(routesToLeave[i]);
for (var i = 0; i < routesToEnter.length; i++)
routeEnter(routesToEnter[i]);
for (var i = 0; i < routesToMatch.length; i++)
routeMatch(routesToMatch[i]);
/** @cut */ flushLog(namespace + ': hash changed to "' + newPath + '"');
}
else
{
allRoutes.forEach(function(route){
if (route.value)
{
routeEnter(route, true);
routeMatch(route, true);
}
});
/** @cut */ flushLog(namespace + ': checkUrl()');
}
}
|
[
"function",
"checkUrl",
"(",
")",
"{",
"var",
"newPath",
"=",
"location",
".",
"hash",
".",
"substr",
"(",
"1",
")",
"||",
"''",
";",
"if",
"(",
"newPath",
"!=",
"currentPath",
")",
"{",
"if",
"(",
"preventRecursion",
"(",
"newPath",
")",
")",
"return",
";",
"currentPath",
"=",
"newPath",
";",
"var",
"routesToLeave",
"=",
"[",
"]",
";",
"var",
"routesToEnter",
"=",
"[",
"]",
";",
"var",
"routesToMatch",
"=",
"[",
"]",
";",
"allRoutes",
".",
"forEach",
"(",
"function",
"(",
"route",
")",
"{",
"var",
"flags",
"=",
"route",
".",
"processLocation_",
"(",
"newPath",
")",
";",
"if",
"(",
"flags",
"&",
"ROUTE_LEAVE",
")",
"routesToLeave",
".",
"push",
"(",
"route",
")",
";",
"if",
"(",
"flags",
"&",
"ROUTE_ENTER",
")",
"routesToEnter",
".",
"push",
"(",
"route",
")",
";",
"if",
"(",
"flags",
"&",
"ROUTE_MATCH",
")",
"routesToMatch",
".",
"push",
"(",
"route",
")",
";",
"}",
")",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"routesToLeave",
".",
"length",
";",
"i",
"++",
")",
"routeLeave",
"(",
"routesToLeave",
"[",
"i",
"]",
")",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"routesToEnter",
".",
"length",
";",
"i",
"++",
")",
"routeEnter",
"(",
"routesToEnter",
"[",
"i",
"]",
")",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"routesToMatch",
".",
"length",
";",
"i",
"++",
")",
"routeMatch",
"(",
"routesToMatch",
"[",
"i",
"]",
")",
";",
"flushLog",
"(",
"namespace",
"+",
"': hash changed to \"'",
"+",
"newPath",
"+",
"'\"'",
")",
";",
"}",
"else",
"{",
"allRoutes",
".",
"forEach",
"(",
"function",
"(",
"route",
")",
"{",
"if",
"(",
"route",
".",
"value",
")",
"{",
"routeEnter",
"(",
"route",
",",
"true",
")",
";",
"routeMatch",
"(",
"route",
",",
"true",
")",
";",
"}",
"}",
")",
";",
"flushLog",
"(",
"namespace",
"+",
"': checkUrl()'",
")",
";",
"}",
"}"
] |
Process current location
|
[
"Process",
"current",
"location"
] |
8571903014b207a09d45ad2d1bfba277bf21289b
|
https://github.com/basisjs/basisjs/blob/8571903014b207a09d45ad2d1bfba277bf21289b/src/basis/router.js#L601-L651
|
train
|
basisjs/basisjs
|
src/basis/router.js
|
get
|
function get(params){
var path = params.path;
var config = params.config;
if (path instanceof Route)
return path;
var route;
// If there is no config specified - it should be a plain route, so we try to reuse it
if (!config)
route = plainRoutesByPath[path];
if (!route && params.autocreate)
{
var parseInfo = Object.prototype.toString.call(path) == '[object RegExp]'
? { path: path, regexp: path, ast: null, params: [] }
: parsePath(path);
route = createRoute(parseInfo, config);
allRoutes.push(route);
if (route instanceof ParametrizedRoute == false)
plainRoutesByPath[path] = route;
if (typeof currentPath == 'string')
{
var flags = route.processLocation_(currentPath);
if (flags & ROUTE_ENTER)
routeEnter(route);
if (flags & ROUTE_MATCH)
routeMatch(route);
}
}
return route;
}
|
javascript
|
function get(params){
var path = params.path;
var config = params.config;
if (path instanceof Route)
return path;
var route;
// If there is no config specified - it should be a plain route, so we try to reuse it
if (!config)
route = plainRoutesByPath[path];
if (!route && params.autocreate)
{
var parseInfo = Object.prototype.toString.call(path) == '[object RegExp]'
? { path: path, regexp: path, ast: null, params: [] }
: parsePath(path);
route = createRoute(parseInfo, config);
allRoutes.push(route);
if (route instanceof ParametrizedRoute == false)
plainRoutesByPath[path] = route;
if (typeof currentPath == 'string')
{
var flags = route.processLocation_(currentPath);
if (flags & ROUTE_ENTER)
routeEnter(route);
if (flags & ROUTE_MATCH)
routeMatch(route);
}
}
return route;
}
|
[
"function",
"get",
"(",
"params",
")",
"{",
"var",
"path",
"=",
"params",
".",
"path",
";",
"var",
"config",
"=",
"params",
".",
"config",
";",
"if",
"(",
"path",
"instanceof",
"Route",
")",
"return",
"path",
";",
"var",
"route",
";",
"if",
"(",
"!",
"config",
")",
"route",
"=",
"plainRoutesByPath",
"[",
"path",
"]",
";",
"if",
"(",
"!",
"route",
"&&",
"params",
".",
"autocreate",
")",
"{",
"var",
"parseInfo",
"=",
"Object",
".",
"prototype",
".",
"toString",
".",
"call",
"(",
"path",
")",
"==",
"'[object RegExp]'",
"?",
"{",
"path",
":",
"path",
",",
"regexp",
":",
"path",
",",
"ast",
":",
"null",
",",
"params",
":",
"[",
"]",
"}",
":",
"parsePath",
"(",
"path",
")",
";",
"route",
"=",
"createRoute",
"(",
"parseInfo",
",",
"config",
")",
";",
"allRoutes",
".",
"push",
"(",
"route",
")",
";",
"if",
"(",
"route",
"instanceof",
"ParametrizedRoute",
"==",
"false",
")",
"plainRoutesByPath",
"[",
"path",
"]",
"=",
"route",
";",
"if",
"(",
"typeof",
"currentPath",
"==",
"'string'",
")",
"{",
"var",
"flags",
"=",
"route",
".",
"processLocation_",
"(",
"currentPath",
")",
";",
"if",
"(",
"flags",
"&",
"ROUTE_ENTER",
")",
"routeEnter",
"(",
"route",
")",
";",
"if",
"(",
"flags",
"&",
"ROUTE_MATCH",
")",
"routeMatch",
"(",
"route",
")",
";",
"}",
"}",
"return",
"route",
";",
"}"
] |
Returns route descriptor
|
[
"Returns",
"route",
"descriptor"
] |
8571903014b207a09d45ad2d1bfba277bf21289b
|
https://github.com/basisjs/basisjs/blob/8571903014b207a09d45ad2d1bfba277bf21289b/src/basis/router.js#L663-L698
|
train
|
basisjs/basisjs
|
src/basis/router.js
|
add
|
function add(path, callback, context){
var route = get({
path: path,
autocreate: true
});
route.callbacks_.push({
cb_: callback,
context: context,
callback: typeof callback != 'function' ? callback || {} : {
match: callback
}
});
initSchedule.add(route);
return route;
}
|
javascript
|
function add(path, callback, context){
var route = get({
path: path,
autocreate: true
});
route.callbacks_.push({
cb_: callback,
context: context,
callback: typeof callback != 'function' ? callback || {} : {
match: callback
}
});
initSchedule.add(route);
return route;
}
|
[
"function",
"add",
"(",
"path",
",",
"callback",
",",
"context",
")",
"{",
"var",
"route",
"=",
"get",
"(",
"{",
"path",
":",
"path",
",",
"autocreate",
":",
"true",
"}",
")",
";",
"route",
".",
"callbacks_",
".",
"push",
"(",
"{",
"cb_",
":",
"callback",
",",
"context",
":",
"context",
",",
"callback",
":",
"typeof",
"callback",
"!=",
"'function'",
"?",
"callback",
"||",
"{",
"}",
":",
"{",
"match",
":",
"callback",
"}",
"}",
")",
";",
"initSchedule",
".",
"add",
"(",
"route",
")",
";",
"return",
"route",
";",
"}"
] |
Add path to be handled
|
[
"Add",
"path",
"to",
"be",
"handled"
] |
8571903014b207a09d45ad2d1bfba277bf21289b
|
https://github.com/basisjs/basisjs/blob/8571903014b207a09d45ad2d1bfba277bf21289b/src/basis/router.js#L703-L720
|
train
|
basisjs/basisjs
|
src/basis/router.js
|
remove
|
function remove(route, callback, context){
var route = get({
path: route
});
if (!route)
return;
for (var i = 0, cb; cb = route.callbacks_[i]; i++)
{
if (cb.cb_ === callback && cb.context === context)
{
route.callbacks_.splice(i, 1);
if (route.value && callback && callback.leave)
{
callback.leave.call(context);
/** @cut */ if (module.exports.debug)
/** @cut */ basis.dev.info(
/** @cut */ namespace + ': add handler for route `' + path + '`\n',
/** @cut */ { type: 'leave', path: route.path, cb: callback.leave, route: route }
/** @cut */ );
}
if (!route.callbacks_.length)
{
// check no attaches to route
if ((!route.handler || !route.handler.handler) && !route.matched.handler)
{
basis.array.remove(allRoutes, route);
if (!(route instanceof ParametrizedRoute))
delete plainRoutesByPath[route.path];
}
}
return;
}
}
/** @cut */ basis.dev.warn(namespace + ': no callback removed', { callback: callback, context: context });
}
|
javascript
|
function remove(route, callback, context){
var route = get({
path: route
});
if (!route)
return;
for (var i = 0, cb; cb = route.callbacks_[i]; i++)
{
if (cb.cb_ === callback && cb.context === context)
{
route.callbacks_.splice(i, 1);
if (route.value && callback && callback.leave)
{
callback.leave.call(context);
/** @cut */ if (module.exports.debug)
/** @cut */ basis.dev.info(
/** @cut */ namespace + ': add handler for route `' + path + '`\n',
/** @cut */ { type: 'leave', path: route.path, cb: callback.leave, route: route }
/** @cut */ );
}
if (!route.callbacks_.length)
{
// check no attaches to route
if ((!route.handler || !route.handler.handler) && !route.matched.handler)
{
basis.array.remove(allRoutes, route);
if (!(route instanceof ParametrizedRoute))
delete plainRoutesByPath[route.path];
}
}
return;
}
}
/** @cut */ basis.dev.warn(namespace + ': no callback removed', { callback: callback, context: context });
}
|
[
"function",
"remove",
"(",
"route",
",",
"callback",
",",
"context",
")",
"{",
"var",
"route",
"=",
"get",
"(",
"{",
"path",
":",
"route",
"}",
")",
";",
"if",
"(",
"!",
"route",
")",
"return",
";",
"for",
"(",
"var",
"i",
"=",
"0",
",",
"cb",
";",
"cb",
"=",
"route",
".",
"callbacks_",
"[",
"i",
"]",
";",
"i",
"++",
")",
"{",
"if",
"(",
"cb",
".",
"cb_",
"===",
"callback",
"&&",
"cb",
".",
"context",
"===",
"context",
")",
"{",
"route",
".",
"callbacks_",
".",
"splice",
"(",
"i",
",",
"1",
")",
";",
"if",
"(",
"route",
".",
"value",
"&&",
"callback",
"&&",
"callback",
".",
"leave",
")",
"{",
"callback",
".",
"leave",
".",
"call",
"(",
"context",
")",
";",
"if",
"(",
"module",
".",
"exports",
".",
"debug",
")",
"basis",
".",
"dev",
".",
"info",
"(",
"namespace",
"+",
"': add handler for route `'",
"+",
"path",
"+",
"'`\\n'",
",",
"\\n",
")",
";",
"}",
"{",
"type",
":",
"'leave'",
",",
"path",
":",
"route",
".",
"path",
",",
"cb",
":",
"callback",
".",
"leave",
",",
"route",
":",
"route",
"}",
"if",
"(",
"!",
"route",
".",
"callbacks_",
".",
"length",
")",
"{",
"if",
"(",
"(",
"!",
"route",
".",
"handler",
"||",
"!",
"route",
".",
"handler",
".",
"handler",
")",
"&&",
"!",
"route",
".",
"matched",
".",
"handler",
")",
"{",
"basis",
".",
"array",
".",
"remove",
"(",
"allRoutes",
",",
"route",
")",
";",
"if",
"(",
"!",
"(",
"route",
"instanceof",
"ParametrizedRoute",
")",
")",
"delete",
"plainRoutesByPath",
"[",
"route",
".",
"path",
"]",
";",
"}",
"}",
"}",
"}",
"return",
";",
"}"
] |
Remove handler for path
|
[
"Remove",
"handler",
"for",
"path"
] |
8571903014b207a09d45ad2d1bfba277bf21289b
|
https://github.com/basisjs/basisjs/blob/8571903014b207a09d45ad2d1bfba277bf21289b/src/basis/router.js#L725-L766
|
train
|
basisjs/basisjs
|
src/basis/router.js
|
navigate
|
function navigate(path, replace){
if (replace)
location.replace(location.pathname + '#' + path);
else
location.hash = path;
if (started)
checkUrl();
}
|
javascript
|
function navigate(path, replace){
if (replace)
location.replace(location.pathname + '#' + path);
else
location.hash = path;
if (started)
checkUrl();
}
|
[
"function",
"navigate",
"(",
"path",
",",
"replace",
")",
"{",
"if",
"(",
"replace",
")",
"location",
".",
"replace",
"(",
"location",
".",
"pathname",
"+",
"'#'",
"+",
"path",
")",
";",
"else",
"location",
".",
"hash",
"=",
"path",
";",
"if",
"(",
"started",
")",
"checkUrl",
"(",
")",
";",
"}"
] |
Navigate to specified path
|
[
"Navigate",
"to",
"specified",
"path"
] |
8571903014b207a09d45ad2d1bfba277bf21289b
|
https://github.com/basisjs/basisjs/blob/8571903014b207a09d45ad2d1bfba277bf21289b/src/basis/router.js#L771-L779
|
train
|
basisjs/basisjs
|
src/basis/data/dataset/Merge.js
|
function(rule){
rule = basis.getter(rule || UNION);
if (this.rule !== rule)
{
var oldRule = this.rule;
this.rule = rule;
this.emit_ruleChanged(oldRule);
return this.applyRule();
}
}
|
javascript
|
function(rule){
rule = basis.getter(rule || UNION);
if (this.rule !== rule)
{
var oldRule = this.rule;
this.rule = rule;
this.emit_ruleChanged(oldRule);
return this.applyRule();
}
}
|
[
"function",
"(",
"rule",
")",
"{",
"rule",
"=",
"basis",
".",
"getter",
"(",
"rule",
"||",
"UNION",
")",
";",
"if",
"(",
"this",
".",
"rule",
"!==",
"rule",
")",
"{",
"var",
"oldRule",
"=",
"this",
".",
"rule",
";",
"this",
".",
"rule",
"=",
"rule",
";",
"this",
".",
"emit_ruleChanged",
"(",
"oldRule",
")",
";",
"return",
"this",
".",
"applyRule",
"(",
")",
";",
"}",
"}"
] |
Set new merge rule for dataset. Some types are available in basis.data.Dataset.Merge
@param {function(count:number, sourceCount:number):boolean|string} rule New rule.
@return {Object} Delta of member changes.
|
[
"Set",
"new",
"merge",
"rule",
"for",
"dataset",
".",
"Some",
"types",
"are",
"available",
"in",
"basis",
".",
"data",
".",
"Dataset",
".",
"Merge"
] |
8571903014b207a09d45ad2d1bfba277bf21289b
|
https://github.com/basisjs/basisjs/blob/8571903014b207a09d45ad2d1bfba277bf21289b/src/basis/data/dataset/Merge.js#L210-L222
|
train
|
|
basisjs/basisjs
|
src/basis/data/dataset/Merge.js
|
function(scope){
var memberMap = this.members_;
var rule = this.rule;
var sourceCount = this.sources.length;
var inserted = [];
var deleted = [];
var memberCounter;
var isMember;
var delta;
if (!scope)
scope = memberMap;
for (var objectId in scope)
{
memberCounter = memberMap[objectId];
isMember = sourceCount && memberCounter.count && rule(memberCounter.count, sourceCount);
if (isMember != memberCounter.isMember)
{
if (isMember)
{
// not in items -> insert
memberCounter.isMember = true;
inserted.push(memberCounter.object);
}
else
{
// already in items -> delete
memberCounter.isMember = false;
deleted.push(memberCounter.object);
}
}
if (memberCounter.count == 0)
delete memberMap[objectId];
}
// fire event if delta found
if (delta = getDelta(inserted, deleted))
this.emit_itemsChanged(delta);
return delta;
}
|
javascript
|
function(scope){
var memberMap = this.members_;
var rule = this.rule;
var sourceCount = this.sources.length;
var inserted = [];
var deleted = [];
var memberCounter;
var isMember;
var delta;
if (!scope)
scope = memberMap;
for (var objectId in scope)
{
memberCounter = memberMap[objectId];
isMember = sourceCount && memberCounter.count && rule(memberCounter.count, sourceCount);
if (isMember != memberCounter.isMember)
{
if (isMember)
{
// not in items -> insert
memberCounter.isMember = true;
inserted.push(memberCounter.object);
}
else
{
// already in items -> delete
memberCounter.isMember = false;
deleted.push(memberCounter.object);
}
}
if (memberCounter.count == 0)
delete memberMap[objectId];
}
// fire event if delta found
if (delta = getDelta(inserted, deleted))
this.emit_itemsChanged(delta);
return delta;
}
|
[
"function",
"(",
"scope",
")",
"{",
"var",
"memberMap",
"=",
"this",
".",
"members_",
";",
"var",
"rule",
"=",
"this",
".",
"rule",
";",
"var",
"sourceCount",
"=",
"this",
".",
"sources",
".",
"length",
";",
"var",
"inserted",
"=",
"[",
"]",
";",
"var",
"deleted",
"=",
"[",
"]",
";",
"var",
"memberCounter",
";",
"var",
"isMember",
";",
"var",
"delta",
";",
"if",
"(",
"!",
"scope",
")",
"scope",
"=",
"memberMap",
";",
"for",
"(",
"var",
"objectId",
"in",
"scope",
")",
"{",
"memberCounter",
"=",
"memberMap",
"[",
"objectId",
"]",
";",
"isMember",
"=",
"sourceCount",
"&&",
"memberCounter",
".",
"count",
"&&",
"rule",
"(",
"memberCounter",
".",
"count",
",",
"sourceCount",
")",
";",
"if",
"(",
"isMember",
"!=",
"memberCounter",
".",
"isMember",
")",
"{",
"if",
"(",
"isMember",
")",
"{",
"memberCounter",
".",
"isMember",
"=",
"true",
";",
"inserted",
".",
"push",
"(",
"memberCounter",
".",
"object",
")",
";",
"}",
"else",
"{",
"memberCounter",
".",
"isMember",
"=",
"false",
";",
"deleted",
".",
"push",
"(",
"memberCounter",
".",
"object",
")",
";",
"}",
"}",
"if",
"(",
"memberCounter",
".",
"count",
"==",
"0",
")",
"delete",
"memberMap",
"[",
"objectId",
"]",
";",
"}",
"if",
"(",
"delta",
"=",
"getDelta",
"(",
"inserted",
",",
"deleted",
")",
")",
"this",
".",
"emit_itemsChanged",
"(",
"delta",
")",
";",
"return",
"delta",
";",
"}"
] |
Check all members are they match to rule or not.
@param {Object=} scope Key map that will be checked. If not passed than all members
will be checked.
@return {Object} Delta of member changes.
|
[
"Check",
"all",
"members",
"are",
"they",
"match",
"to",
"rule",
"or",
"not",
"."
] |
8571903014b207a09d45ad2d1bfba277bf21289b
|
https://github.com/basisjs/basisjs/blob/8571903014b207a09d45ad2d1bfba277bf21289b/src/basis/data/dataset/Merge.js#L230-L273
|
train
|
|
basisjs/basisjs
|
src/basis/data/dataset/Merge.js
|
function(source){
// this -> sourceInfo
var merge = this.owner;
var sourcesMap_ = merge.sourcesMap_;
var dataset = resolveDataset(this, merge.updateDataset_, source, 'adapter', merge);
var inserted;
var deleted;
var delta;
if (this.dataset === dataset)
return;
if (dataset)
{
var count = (sourcesMap_[dataset.basisObjectId] || 0) + 1;
sourcesMap_[dataset.basisObjectId] = count;
if (count == 1)
{
merge.addDataset_(dataset);
inserted = [dataset];
}
}
if (this.dataset)
{
var count = (sourcesMap_[this.dataset.basisObjectId] || 0) - 1;
sourcesMap_[this.dataset.basisObjectId] = count;
if (count == 0)
{
merge.removeDataset_(this.dataset);
deleted = [this.dataset];
}
}
this.dataset = dataset;
// build delta and fire event
merge.applyRule();
// fire sources changes event
if (delta = getDelta(inserted, deleted))
{
var setSourcesTransaction = merge.sourceDelta_;
if (setSourcesTransaction)
{
if (delta.inserted)
delta.inserted.forEach(function(item){
if (!arrayRemove(this.deleted, item))
arrayAdd(this.inserted, item);
}, setSourcesTransaction);
if (delta.deleted)
delta.deleted.forEach(function(item){
if (!arrayRemove(this.inserted, item))
arrayAdd(this.deleted, item);
}, setSourcesTransaction);
}
else
{
merge.emit_sourcesChanged(delta);
}
}
return delta;
}
|
javascript
|
function(source){
// this -> sourceInfo
var merge = this.owner;
var sourcesMap_ = merge.sourcesMap_;
var dataset = resolveDataset(this, merge.updateDataset_, source, 'adapter', merge);
var inserted;
var deleted;
var delta;
if (this.dataset === dataset)
return;
if (dataset)
{
var count = (sourcesMap_[dataset.basisObjectId] || 0) + 1;
sourcesMap_[dataset.basisObjectId] = count;
if (count == 1)
{
merge.addDataset_(dataset);
inserted = [dataset];
}
}
if (this.dataset)
{
var count = (sourcesMap_[this.dataset.basisObjectId] || 0) - 1;
sourcesMap_[this.dataset.basisObjectId] = count;
if (count == 0)
{
merge.removeDataset_(this.dataset);
deleted = [this.dataset];
}
}
this.dataset = dataset;
// build delta and fire event
merge.applyRule();
// fire sources changes event
if (delta = getDelta(inserted, deleted))
{
var setSourcesTransaction = merge.sourceDelta_;
if (setSourcesTransaction)
{
if (delta.inserted)
delta.inserted.forEach(function(item){
if (!arrayRemove(this.deleted, item))
arrayAdd(this.inserted, item);
}, setSourcesTransaction);
if (delta.deleted)
delta.deleted.forEach(function(item){
if (!arrayRemove(this.inserted, item))
arrayAdd(this.deleted, item);
}, setSourcesTransaction);
}
else
{
merge.emit_sourcesChanged(delta);
}
}
return delta;
}
|
[
"function",
"(",
"source",
")",
"{",
"var",
"merge",
"=",
"this",
".",
"owner",
";",
"var",
"sourcesMap_",
"=",
"merge",
".",
"sourcesMap_",
";",
"var",
"dataset",
"=",
"resolveDataset",
"(",
"this",
",",
"merge",
".",
"updateDataset_",
",",
"source",
",",
"'adapter'",
",",
"merge",
")",
";",
"var",
"inserted",
";",
"var",
"deleted",
";",
"var",
"delta",
";",
"if",
"(",
"this",
".",
"dataset",
"===",
"dataset",
")",
"return",
";",
"if",
"(",
"dataset",
")",
"{",
"var",
"count",
"=",
"(",
"sourcesMap_",
"[",
"dataset",
".",
"basisObjectId",
"]",
"||",
"0",
")",
"+",
"1",
";",
"sourcesMap_",
"[",
"dataset",
".",
"basisObjectId",
"]",
"=",
"count",
";",
"if",
"(",
"count",
"==",
"1",
")",
"{",
"merge",
".",
"addDataset_",
"(",
"dataset",
")",
";",
"inserted",
"=",
"[",
"dataset",
"]",
";",
"}",
"}",
"if",
"(",
"this",
".",
"dataset",
")",
"{",
"var",
"count",
"=",
"(",
"sourcesMap_",
"[",
"this",
".",
"dataset",
".",
"basisObjectId",
"]",
"||",
"0",
")",
"-",
"1",
";",
"sourcesMap_",
"[",
"this",
".",
"dataset",
".",
"basisObjectId",
"]",
"=",
"count",
";",
"if",
"(",
"count",
"==",
"0",
")",
"{",
"merge",
".",
"removeDataset_",
"(",
"this",
".",
"dataset",
")",
";",
"deleted",
"=",
"[",
"this",
".",
"dataset",
"]",
";",
"}",
"}",
"this",
".",
"dataset",
"=",
"dataset",
";",
"merge",
".",
"applyRule",
"(",
")",
";",
"if",
"(",
"delta",
"=",
"getDelta",
"(",
"inserted",
",",
"deleted",
")",
")",
"{",
"var",
"setSourcesTransaction",
"=",
"merge",
".",
"sourceDelta_",
";",
"if",
"(",
"setSourcesTransaction",
")",
"{",
"if",
"(",
"delta",
".",
"inserted",
")",
"delta",
".",
"inserted",
".",
"forEach",
"(",
"function",
"(",
"item",
")",
"{",
"if",
"(",
"!",
"arrayRemove",
"(",
"this",
".",
"deleted",
",",
"item",
")",
")",
"arrayAdd",
"(",
"this",
".",
"inserted",
",",
"item",
")",
";",
"}",
",",
"setSourcesTransaction",
")",
";",
"if",
"(",
"delta",
".",
"deleted",
")",
"delta",
".",
"deleted",
".",
"forEach",
"(",
"function",
"(",
"item",
")",
"{",
"if",
"(",
"!",
"arrayRemove",
"(",
"this",
".",
"inserted",
",",
"item",
")",
")",
"arrayAdd",
"(",
"this",
".",
"deleted",
",",
"item",
")",
";",
"}",
",",
"setSourcesTransaction",
")",
";",
"}",
"else",
"{",
"merge",
".",
"emit_sourcesChanged",
"(",
"delta",
")",
";",
"}",
"}",
"return",
"delta",
";",
"}"
] |
Update dataset value by source.
@param {*} source
@private
|
[
"Update",
"dataset",
"value",
"by",
"source",
"."
] |
8571903014b207a09d45ad2d1bfba277bf21289b
|
https://github.com/basisjs/basisjs/blob/8571903014b207a09d45ad2d1bfba277bf21289b/src/basis/data/dataset/Merge.js#L333-L397
|
train
|
|
basisjs/basisjs
|
src/basis/data/dataset/Merge.js
|
function(source){
if (!source || (typeof source != 'object' && typeof source != 'function'))
{
/** @cut */ basis.dev.warn(this.constructor.className + '.addSource: value should be a dataset instance or to be able to resolve in dataset');
return;
}
if (this.hasSource(source))
{
/** @cut */ basis.dev.warn(this.constructor.className + '.addSource: value is already in source list');
return;
}
var sourceInfo = {
owner: this,
source: source,
adapter: null,
dataset: null
};
this.sourceValues_.push(sourceInfo);
this.updateDataset_.call(sourceInfo, source);
if (this.listen.sourceValue && source instanceof Emitter)
source.addHandler(this.listen.sourceValue, this);
}
|
javascript
|
function(source){
if (!source || (typeof source != 'object' && typeof source != 'function'))
{
/** @cut */ basis.dev.warn(this.constructor.className + '.addSource: value should be a dataset instance or to be able to resolve in dataset');
return;
}
if (this.hasSource(source))
{
/** @cut */ basis.dev.warn(this.constructor.className + '.addSource: value is already in source list');
return;
}
var sourceInfo = {
owner: this,
source: source,
adapter: null,
dataset: null
};
this.sourceValues_.push(sourceInfo);
this.updateDataset_.call(sourceInfo, source);
if (this.listen.sourceValue && source instanceof Emitter)
source.addHandler(this.listen.sourceValue, this);
}
|
[
"function",
"(",
"source",
")",
"{",
"if",
"(",
"!",
"source",
"||",
"(",
"typeof",
"source",
"!=",
"'object'",
"&&",
"typeof",
"source",
"!=",
"'function'",
")",
")",
"{",
"basis",
".",
"dev",
".",
"warn",
"(",
"this",
".",
"constructor",
".",
"className",
"+",
"'.addSource: value should be a dataset instance or to be able to resolve in dataset'",
")",
";",
"return",
";",
"}",
"if",
"(",
"this",
".",
"hasSource",
"(",
"source",
")",
")",
"{",
"basis",
".",
"dev",
".",
"warn",
"(",
"this",
".",
"constructor",
".",
"className",
"+",
"'.addSource: value is already in source list'",
")",
";",
"return",
";",
"}",
"var",
"sourceInfo",
"=",
"{",
"owner",
":",
"this",
",",
"source",
":",
"source",
",",
"adapter",
":",
"null",
",",
"dataset",
":",
"null",
"}",
";",
"this",
".",
"sourceValues_",
".",
"push",
"(",
"sourceInfo",
")",
";",
"this",
".",
"updateDataset_",
".",
"call",
"(",
"sourceInfo",
",",
"source",
")",
";",
"if",
"(",
"this",
".",
"listen",
".",
"sourceValue",
"&&",
"source",
"instanceof",
"Emitter",
")",
"source",
".",
"addHandler",
"(",
"this",
".",
"listen",
".",
"sourceValue",
",",
"this",
")",
";",
"}"
] |
Add source from sources list.
@param {basis.data.ReadOnlyDataset|object|function()} source
@return {boolean} Returns true if new source added.
|
[
"Add",
"source",
"from",
"sources",
"list",
"."
] |
8571903014b207a09d45ad2d1bfba277bf21289b
|
https://github.com/basisjs/basisjs/blob/8571903014b207a09d45ad2d1bfba277bf21289b/src/basis/data/dataset/Merge.js#L414-L439
|
train
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.