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 |
---|---|---|---|---|---|---|---|---|---|---|---|
basisjs/basisjs
|
src/basis/data/dataset/Merge.js
|
function(sources){
var exists = this.sourceValues_.map(function(sourceInfo){
return sourceInfo.source;
});
var inserted = [];
var deleted = [];
var delta;
if (!sources)
sources = [];
this.sourceDelta_ = {
inserted: inserted,
deleted: deleted
};
for (var i = 0; i < sources.length; i++)
{
var source = sources[i];
if (!arrayRemove(exists, source))
this.addSource(source);
}
exists.forEach(this.removeSource, this);
this.sourceDelta_ = null;
if (delta = getDelta(inserted, deleted))
this.emit_sourcesChanged(delta);
return delta;
}
|
javascript
|
function(sources){
var exists = this.sourceValues_.map(function(sourceInfo){
return sourceInfo.source;
});
var inserted = [];
var deleted = [];
var delta;
if (!sources)
sources = [];
this.sourceDelta_ = {
inserted: inserted,
deleted: deleted
};
for (var i = 0; i < sources.length; i++)
{
var source = sources[i];
if (!arrayRemove(exists, source))
this.addSource(source);
}
exists.forEach(this.removeSource, this);
this.sourceDelta_ = null;
if (delta = getDelta(inserted, deleted))
this.emit_sourcesChanged(delta);
return delta;
}
|
[
"function",
"(",
"sources",
")",
"{",
"var",
"exists",
"=",
"this",
".",
"sourceValues_",
".",
"map",
"(",
"function",
"(",
"sourceInfo",
")",
"{",
"return",
"sourceInfo",
".",
"source",
";",
"}",
")",
";",
"var",
"inserted",
"=",
"[",
"]",
";",
"var",
"deleted",
"=",
"[",
"]",
";",
"var",
"delta",
";",
"if",
"(",
"!",
"sources",
")",
"sources",
"=",
"[",
"]",
";",
"this",
".",
"sourceDelta_",
"=",
"{",
"inserted",
":",
"inserted",
",",
"deleted",
":",
"deleted",
"}",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"sources",
".",
"length",
";",
"i",
"++",
")",
"{",
"var",
"source",
"=",
"sources",
"[",
"i",
"]",
";",
"if",
"(",
"!",
"arrayRemove",
"(",
"exists",
",",
"source",
")",
")",
"this",
".",
"addSource",
"(",
"source",
")",
";",
"}",
"exists",
".",
"forEach",
"(",
"this",
".",
"removeSource",
",",
"this",
")",
";",
"this",
".",
"sourceDelta_",
"=",
"null",
";",
"if",
"(",
"delta",
"=",
"getDelta",
"(",
"inserted",
",",
"deleted",
")",
")",
"this",
".",
"emit_sourcesChanged",
"(",
"delta",
")",
";",
"return",
"delta",
";",
"}"
] |
Synchonize sources list according new list.
@param {Array.<basis.data.ReadOnlyDataset>} sources
|
[
"Synchonize",
"sources",
"list",
"according",
"new",
"list",
"."
] |
8571903014b207a09d45ad2d1bfba277bf21289b
|
https://github.com/basisjs/basisjs/blob/8571903014b207a09d45ad2d1bfba277bf21289b/src/basis/data/dataset/Merge.js#L478-L508
|
train
|
|
basisjs/basisjs
|
src/basis.js
|
values
|
function values(object){
var result = [];
for (var key in object)
result.push(object[key]);
return result;
}
|
javascript
|
function values(object){
var result = [];
for (var key in object)
result.push(object[key]);
return result;
}
|
[
"function",
"values",
"(",
"object",
")",
"{",
"var",
"result",
"=",
"[",
"]",
";",
"for",
"(",
"var",
"key",
"in",
"object",
")",
"result",
".",
"push",
"(",
"object",
"[",
"key",
"]",
")",
";",
"return",
"result",
";",
"}"
] |
Returns all property values of object.
@param {object} object Any object can has properties.
@return {Array.<object>}
|
[
"Returns",
"all",
"property",
"values",
"of",
"object",
"."
] |
8571903014b207a09d45ad2d1bfba277bf21289b
|
https://github.com/basisjs/basisjs/blob/8571903014b207a09d45ad2d1bfba277bf21289b/src/basis.js#L169-L176
|
train
|
basisjs/basisjs
|
src/basis.js
|
slice
|
function slice(source, keys){
var result = {};
if (!keys)
return extend(result, source);
for (var i = 0, key; key = keys[i++];)
if (key in source)
result[key] = source[key];
return result;
}
|
javascript
|
function slice(source, keys){
var result = {};
if (!keys)
return extend(result, source);
for (var i = 0, key; key = keys[i++];)
if (key in source)
result[key] = source[key];
return result;
}
|
[
"function",
"slice",
"(",
"source",
",",
"keys",
")",
"{",
"var",
"result",
"=",
"{",
"}",
";",
"if",
"(",
"!",
"keys",
")",
"return",
"extend",
"(",
"result",
",",
"source",
")",
";",
"for",
"(",
"var",
"i",
"=",
"0",
",",
"key",
";",
"key",
"=",
"keys",
"[",
"i",
"++",
"]",
";",
")",
"if",
"(",
"key",
"in",
"source",
")",
"result",
"[",
"key",
"]",
"=",
"source",
"[",
"key",
"]",
";",
"return",
"result",
";",
"}"
] |
Creates a slice of source object.
@param {object} source Any object can has properties.
@param {Array.<string>} keys Desired key set.
@return {object} New object with desired keys from source object.
|
[
"Creates",
"a",
"slice",
"of",
"source",
"object",
"."
] |
8571903014b207a09d45ad2d1bfba277bf21289b
|
https://github.com/basisjs/basisjs/blob/8571903014b207a09d45ad2d1bfba277bf21289b/src/basis.js#L184-L195
|
train
|
basisjs/basisjs
|
src/basis.js
|
splice
|
function splice(source, keys){
var result = {};
if (!keys)
return extend(result, source);
for (var i = 0, key; key = keys[i++];)
if (key in source)
{
result[key] = source[key];
delete source[key];
}
return result;
}
|
javascript
|
function splice(source, keys){
var result = {};
if (!keys)
return extend(result, source);
for (var i = 0, key; key = keys[i++];)
if (key in source)
{
result[key] = source[key];
delete source[key];
}
return result;
}
|
[
"function",
"splice",
"(",
"source",
",",
"keys",
")",
"{",
"var",
"result",
"=",
"{",
"}",
";",
"if",
"(",
"!",
"keys",
")",
"return",
"extend",
"(",
"result",
",",
"source",
")",
";",
"for",
"(",
"var",
"i",
"=",
"0",
",",
"key",
";",
"key",
"=",
"keys",
"[",
"i",
"++",
"]",
";",
")",
"if",
"(",
"key",
"in",
"source",
")",
"{",
"result",
"[",
"key",
"]",
"=",
"source",
"[",
"key",
"]",
";",
"delete",
"source",
"[",
"key",
"]",
";",
"}",
"return",
"result",
";",
"}"
] |
Creates a slice of source object and delete keys from source.
@param {object} source Any object can has properties.
@param {Array.<string>} keys Desired key set.
@return {object} New object with desired keys from source object.
TODO: fix case when keys is not passed; it returns copy of source,
but doesn't delete anything (source should become empty object)
|
[
"Creates",
"a",
"slice",
"of",
"source",
"object",
"and",
"delete",
"keys",
"from",
"source",
"."
] |
8571903014b207a09d45ad2d1bfba277bf21289b
|
https://github.com/basisjs/basisjs/blob/8571903014b207a09d45ad2d1bfba277bf21289b/src/basis.js#L205-L219
|
train
|
basisjs/basisjs
|
src/basis.js
|
merge
|
function merge(/* obj1 .. objN */){
var result = {};
for (var i = 0; i < arguments.length; i++)
extend(result, arguments[i]);
return result;
}
|
javascript
|
function merge(/* obj1 .. objN */){
var result = {};
for (var i = 0; i < arguments.length; i++)
extend(result, arguments[i]);
return result;
}
|
[
"function",
"merge",
"(",
")",
"{",
"var",
"result",
"=",
"{",
"}",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"arguments",
".",
"length",
";",
"i",
"++",
")",
"extend",
"(",
"result",
",",
"arguments",
"[",
"i",
"]",
")",
";",
"return",
"result",
";",
"}"
] |
Merge several objects into new object and returns it.
@param {...*} args
@return {object}
|
[
"Merge",
"several",
"objects",
"into",
"new",
"object",
"and",
"returns",
"it",
"."
] |
8571903014b207a09d45ad2d1bfba277bf21289b
|
https://github.com/basisjs/basisjs/blob/8571903014b207a09d45ad2d1bfba277bf21289b/src/basis.js#L226-L233
|
train
|
basisjs/basisjs
|
src/basis.js
|
iterate
|
function iterate(object, callback, thisObject){
var result = [];
for (var key in object)
result.push(callback.call(thisObject, key, object[key]));
return result;
}
|
javascript
|
function iterate(object, callback, thisObject){
var result = [];
for (var key in object)
result.push(callback.call(thisObject, key, object[key]));
return result;
}
|
[
"function",
"iterate",
"(",
"object",
",",
"callback",
",",
"thisObject",
")",
"{",
"var",
"result",
"=",
"[",
"]",
";",
"for",
"(",
"var",
"key",
"in",
"object",
")",
"result",
".",
"push",
"(",
"callback",
".",
"call",
"(",
"thisObject",
",",
"key",
",",
"object",
"[",
"key",
"]",
")",
")",
";",
"return",
"result",
";",
"}"
] |
Returns list of callback call result for every object's key-value pair.
@param {object} object Any object can has properties.
@param {function(key, value)} callback
@param {*=} thisObject
@return {Array.<*>}
|
[
"Returns",
"list",
"of",
"callback",
"call",
"result",
"for",
"every",
"object",
"s",
"key",
"-",
"value",
"pair",
"."
] |
8571903014b207a09d45ad2d1bfba277bf21289b
|
https://github.com/basisjs/basisjs/blob/8571903014b207a09d45ad2d1bfba277bf21289b/src/basis.js#L242-L249
|
train
|
basisjs/basisjs
|
src/basis.js
|
factory
|
function factory(fn){
if (typeof fn != 'function')
fn = getter(fn);
var result = function(value){
return fn(value);
};
/** @cut */ result = devInfoResolver.patchFactory(result);
result.factory = FACTORY;
return result;
}
|
javascript
|
function factory(fn){
if (typeof fn != 'function')
fn = getter(fn);
var result = function(value){
return fn(value);
};
/** @cut */ result = devInfoResolver.patchFactory(result);
result.factory = FACTORY;
return result;
}
|
[
"function",
"factory",
"(",
"fn",
")",
"{",
"if",
"(",
"typeof",
"fn",
"!=",
"'function'",
")",
"fn",
"=",
"getter",
"(",
"fn",
")",
";",
"var",
"result",
"=",
"function",
"(",
"value",
")",
"{",
"return",
"fn",
"(",
"value",
")",
";",
"}",
";",
"result",
"=",
"devInfoResolver",
".",
"patchFactory",
"(",
"result",
")",
";",
"result",
".",
"factory",
"=",
"FACTORY",
";",
"return",
"result",
";",
"}"
] |
Make factory function from getter.
@param {function(value)|string} fn Base for getter.
@return {function(value)} Factory function.
|
[
"Make",
"factory",
"function",
"from",
"getter",
"."
] |
8571903014b207a09d45ad2d1bfba277bf21289b
|
https://github.com/basisjs/basisjs/blob/8571903014b207a09d45ad2d1bfba277bf21289b/src/basis.js#L566-L577
|
train
|
basisjs/basisjs
|
src/basis.js
|
publicCallback
|
function publicCallback(fn, permanent){
var name = 'basisjsCallback' + genUID();
global[name] = permanent ? fn : function(){
try {
// IE8 and lower can't delete from global
delete global[name];
} catch(e) {
global[name] = undefined;
}
return fn.apply(this, arguments);
};
return name;
}
|
javascript
|
function publicCallback(fn, permanent){
var name = 'basisjsCallback' + genUID();
global[name] = permanent ? fn : function(){
try {
// IE8 and lower can't delete from global
delete global[name];
} catch(e) {
global[name] = undefined;
}
return fn.apply(this, arguments);
};
return name;
}
|
[
"function",
"publicCallback",
"(",
"fn",
",",
"permanent",
")",
"{",
"var",
"name",
"=",
"'basisjsCallback'",
"+",
"genUID",
"(",
")",
";",
"global",
"[",
"name",
"]",
"=",
"permanent",
"?",
"fn",
":",
"function",
"(",
")",
"{",
"try",
"{",
"delete",
"global",
"[",
"name",
"]",
";",
"}",
"catch",
"(",
"e",
")",
"{",
"global",
"[",
"name",
"]",
"=",
"undefined",
";",
"}",
"return",
"fn",
".",
"apply",
"(",
"this",
",",
"arguments",
")",
";",
"}",
";",
"return",
"name",
";",
"}"
] |
Generates name for function and registrates it in global scope.
@param {function()} fn Function that should available in global scope.
@param {boolean} permanent If false callback will be removed after fiest invoke.
@return {string} Function name in global scope.
|
[
"Generates",
"name",
"for",
"function",
"and",
"registrates",
"it",
"in",
"global",
"scope",
"."
] |
8571903014b207a09d45ad2d1bfba277bf21289b
|
https://github.com/basisjs/basisjs/blob/8571903014b207a09d45ad2d1bfba277bf21289b/src/basis.js#L594-L609
|
train
|
basisjs/basisjs
|
src/basis.js
|
devVerboseName
|
function devVerboseName(name, args, fn){
/** @cut */ return new Function(keys(args), 'return {"' + name + '": ' + fn + '\n}["' + name + '"]').apply(null, values(args));
/** @cut */ }
|
javascript
|
function devVerboseName(name, args, fn){
/** @cut */ return new Function(keys(args), 'return {"' + name + '": ' + fn + '\n}["' + name + '"]').apply(null, values(args));
/** @cut */ }
|
[
"function",
"devVerboseName",
"(",
"name",
",",
"args",
",",
"fn",
")",
"{",
"return",
"new",
"Function",
"(",
"keys",
"(",
"args",
")",
",",
"'return {\"'",
"+",
"name",
"+",
"'\": '",
"+",
"fn",
"+",
"'\\n}[\"'",
"+",
"\\n",
"+",
"name",
")",
".",
"'\"]'",
"apply",
";",
"}"
] |
dev mode only
@cut
|
[
"dev",
"mode",
"only"
] |
8571903014b207a09d45ad2d1bfba277bf21289b
|
https://github.com/basisjs/basisjs/blob/8571903014b207a09d45ad2d1bfba277bf21289b/src/basis.js#L614-L616
|
train
|
basisjs/basisjs
|
src/basis.js
|
function(path){
path = (path || '')
.replace(PROTOCOL_RX, '/')
.replace(ORIGIN_RX, '/') // but cut off origin
.replace(SEARCH_HASH_RX, ''); // cut off query search and hash
// use link element as path resolver
var result = [];
var parts = path.split('/'); // split
// process path parts
for (var i = 0; i < parts.length; i++)
{
if (parts[i] == '..')
{
if (result.length > 1 || result[0])
result.pop();
}
else
{
if ((parts[i] || !i) && parts[i] != '.')
result.push(parts[i]);
}
}
return result.join('/') ||
(path[0] === '/' ? '/' : '');
}
|
javascript
|
function(path){
path = (path || '')
.replace(PROTOCOL_RX, '/')
.replace(ORIGIN_RX, '/') // but cut off origin
.replace(SEARCH_HASH_RX, ''); // cut off query search and hash
// use link element as path resolver
var result = [];
var parts = path.split('/'); // split
// process path parts
for (var i = 0; i < parts.length; i++)
{
if (parts[i] == '..')
{
if (result.length > 1 || result[0])
result.pop();
}
else
{
if ((parts[i] || !i) && parts[i] != '.')
result.push(parts[i]);
}
}
return result.join('/') ||
(path[0] === '/' ? '/' : '');
}
|
[
"function",
"(",
"path",
")",
"{",
"path",
"=",
"(",
"path",
"||",
"''",
")",
".",
"replace",
"(",
"PROTOCOL_RX",
",",
"'/'",
")",
".",
"replace",
"(",
"ORIGIN_RX",
",",
"'/'",
")",
".",
"replace",
"(",
"SEARCH_HASH_RX",
",",
"''",
")",
";",
"var",
"result",
"=",
"[",
"]",
";",
"var",
"parts",
"=",
"path",
".",
"split",
"(",
"'/'",
")",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"parts",
".",
"length",
";",
"i",
"++",
")",
"{",
"if",
"(",
"parts",
"[",
"i",
"]",
"==",
"'..'",
")",
"{",
"if",
"(",
"result",
".",
"length",
">",
"1",
"||",
"result",
"[",
"0",
"]",
")",
"result",
".",
"pop",
"(",
")",
";",
"}",
"else",
"{",
"if",
"(",
"(",
"parts",
"[",
"i",
"]",
"||",
"!",
"i",
")",
"&&",
"parts",
"[",
"i",
"]",
"!=",
"'.'",
")",
"result",
".",
"push",
"(",
"parts",
"[",
"i",
"]",
")",
";",
"}",
"}",
"return",
"result",
".",
"join",
"(",
"'/'",
")",
"||",
"(",
"path",
"[",
"0",
"]",
"===",
"'/'",
"?",
"'/'",
":",
"''",
")",
";",
"}"
] |
Normalize a string path, taking care of '..' and '.' parts.
When multiple slashes are found, they're replaced by a single one;
when the path contains a trailing slash, it is preserved.
Origin is not includes in result path.
@example
basis.path.normalize('/foo/bar//baz/asdf/quux/..');
// returns '/foo/bar/baz/asdf'
basis.path.normalize('http://example.com:8080/foo//..//bar/');
// returns '/bar'
basis.path.normalize('//localhost/foo/./..//bar/');
// returns '/bar'
@param {string} path
@return {string}
|
[
"Normalize",
"a",
"string",
"path",
"taking",
"care",
"of",
"..",
"and",
".",
"parts",
".",
"When",
"multiple",
"slashes",
"are",
"found",
"they",
"re",
"replaced",
"by",
"a",
"single",
"one",
";",
"when",
"the",
"path",
"contains",
"a",
"trailing",
"slash",
"it",
"is",
"preserved",
"."
] |
8571903014b207a09d45ad2d1bfba277bf21289b
|
https://github.com/basisjs/basisjs/blob/8571903014b207a09d45ad2d1bfba277bf21289b/src/basis.js#L1044-L1071
|
train
|
|
basisjs/basisjs
|
src/basis.js
|
function(path, ext){
var filename = utils.normalize(path).match(/[^\\\/]*$/);
filename = filename ? filename[0] : '';
if (ext == utils.extname(filename))
filename = filename.substring(0, filename.length - ext.length);
return filename;
}
|
javascript
|
function(path, ext){
var filename = utils.normalize(path).match(/[^\\\/]*$/);
filename = filename ? filename[0] : '';
if (ext == utils.extname(filename))
filename = filename.substring(0, filename.length - ext.length);
return filename;
}
|
[
"function",
"(",
"path",
",",
"ext",
")",
"{",
"var",
"filename",
"=",
"utils",
".",
"normalize",
"(",
"path",
")",
".",
"match",
"(",
"/",
"[^\\\\\\/]*$",
"/",
")",
";",
"filename",
"=",
"filename",
"?",
"filename",
"[",
"0",
"]",
":",
"''",
";",
"if",
"(",
"ext",
"==",
"utils",
".",
"extname",
"(",
"filename",
")",
")",
"filename",
"=",
"filename",
".",
"substring",
"(",
"0",
",",
"filename",
".",
"length",
"-",
"ext",
".",
"length",
")",
";",
"return",
"filename",
";",
"}"
] |
Return the last portion of a path. Similar to node.js path.basename
or the Unix basename command.
@example
basis.path.basename('/foo/bar/baz.html'); // returns 'baz.html'
basis.path.basename('/foo/bar/baz.html', '.html'); // returns 'baz'
@param {string} path
@param {string=} ext
@return {string}
|
[
"Return",
"the",
"last",
"portion",
"of",
"a",
"path",
".",
"Similar",
"to",
"node",
".",
"js",
"path",
".",
"basename",
"or",
"the",
"Unix",
"basename",
"command",
"."
] |
8571903014b207a09d45ad2d1bfba277bf21289b
|
https://github.com/basisjs/basisjs/blob/8571903014b207a09d45ad2d1bfba277bf21289b/src/basis.js#L1120-L1128
|
train
|
|
basisjs/basisjs
|
src/basis.js
|
function(){
var args = arrayFrom(arguments).reverse();
var path = [];
var absoluteFound = false;
for (var i = 0; !absoluteFound && i < args.length; i++)
if (typeof args[i] == 'string')
{
path.unshift(args[i]);
absoluteFound = ABSOLUTE_RX.test(args[i]);
}
if (!absoluteFound)
path.unshift(baseURI == '/' ? '' : baseURI);
else if (path.length && path[0] == '/')
path[0] = '';
return utils.normalize(path.join('/'));
}
|
javascript
|
function(){
var args = arrayFrom(arguments).reverse();
var path = [];
var absoluteFound = false;
for (var i = 0; !absoluteFound && i < args.length; i++)
if (typeof args[i] == 'string')
{
path.unshift(args[i]);
absoluteFound = ABSOLUTE_RX.test(args[i]);
}
if (!absoluteFound)
path.unshift(baseURI == '/' ? '' : baseURI);
else if (path.length && path[0] == '/')
path[0] = '';
return utils.normalize(path.join('/'));
}
|
[
"function",
"(",
")",
"{",
"var",
"args",
"=",
"arrayFrom",
"(",
"arguments",
")",
".",
"reverse",
"(",
")",
";",
"var",
"path",
"=",
"[",
"]",
";",
"var",
"absoluteFound",
"=",
"false",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"!",
"absoluteFound",
"&&",
"i",
"<",
"args",
".",
"length",
";",
"i",
"++",
")",
"if",
"(",
"typeof",
"args",
"[",
"i",
"]",
"==",
"'string'",
")",
"{",
"path",
".",
"unshift",
"(",
"args",
"[",
"i",
"]",
")",
";",
"absoluteFound",
"=",
"ABSOLUTE_RX",
".",
"test",
"(",
"args",
"[",
"i",
"]",
")",
";",
"}",
"if",
"(",
"!",
"absoluteFound",
")",
"path",
".",
"unshift",
"(",
"baseURI",
"==",
"'/'",
"?",
"''",
":",
"baseURI",
")",
";",
"else",
"if",
"(",
"path",
".",
"length",
"&&",
"path",
"[",
"0",
"]",
"==",
"'/'",
")",
"path",
"[",
"0",
"]",
"=",
"''",
";",
"return",
"utils",
".",
"normalize",
"(",
"path",
".",
"join",
"(",
"'/'",
")",
")",
";",
"}"
] |
Resolves to to an absolute path.
If to isn't already absolute from arguments are prepended in right
to left order, until an absolute path is found. If after using all
from paths still no absolute path is found, the current location is
used as well. The resulting path is normalized, and trailing slashes
are removed unless the path gets resolved to the root directory.
Non-string arguments are ignored.
@example
basis.path.resolve('/foo/bar', './baz');
// returns '/foo/bar/baz'
basis.path.resolve('/foo/bar', '/demo/file/');
// returns '/demo/file'
basis.path.resolve('foo', 'bar/baz/', '../gif/image.gif');
// if current location is /demo, it returns '/demo/foo/bar/gif/image.gif'
@param {...string=} paths
@return {string}
|
[
"Resolves",
"to",
"to",
"an",
"absolute",
"path",
"."
] |
8571903014b207a09d45ad2d1bfba277bf21289b
|
https://github.com/basisjs/basisjs/blob/8571903014b207a09d45ad2d1bfba277bf21289b/src/basis.js#L1153-L1171
|
train
|
|
basisjs/basisjs
|
src/basis.js
|
function(from, to){
// it makes function useful with array iterate methods, i.e.
// ['foo', 'bar'].map(basis.path.relative)
if (typeof to != 'string')
{
to = from;
from = baseURI;
}
from = utils.normalize(from);
to = utils.normalize(to);
if (from[0] == '/' && to[0] != '/')
return from;
if (to[0] == '/' && from[0] != '/')
return to;
var base = from.replace(/^\/$/, '').split(/\//);
var path = to.replace(/^\/$/, '').split(/\//);
var result = [];
var i = 0;
while (path[i] == base[i] && typeof base[i] == 'string')
i++;
for (var j = base.length - i; j > 0; j--)
result.push('..');
return result.concat(path.slice(i).filter(Boolean)).join('/');
}
|
javascript
|
function(from, to){
// it makes function useful with array iterate methods, i.e.
// ['foo', 'bar'].map(basis.path.relative)
if (typeof to != 'string')
{
to = from;
from = baseURI;
}
from = utils.normalize(from);
to = utils.normalize(to);
if (from[0] == '/' && to[0] != '/')
return from;
if (to[0] == '/' && from[0] != '/')
return to;
var base = from.replace(/^\/$/, '').split(/\//);
var path = to.replace(/^\/$/, '').split(/\//);
var result = [];
var i = 0;
while (path[i] == base[i] && typeof base[i] == 'string')
i++;
for (var j = base.length - i; j > 0; j--)
result.push('..');
return result.concat(path.slice(i).filter(Boolean)).join('/');
}
|
[
"function",
"(",
"from",
",",
"to",
")",
"{",
"if",
"(",
"typeof",
"to",
"!=",
"'string'",
")",
"{",
"to",
"=",
"from",
";",
"from",
"=",
"baseURI",
";",
"}",
"from",
"=",
"utils",
".",
"normalize",
"(",
"from",
")",
";",
"to",
"=",
"utils",
".",
"normalize",
"(",
"to",
")",
";",
"if",
"(",
"from",
"[",
"0",
"]",
"==",
"'/'",
"&&",
"to",
"[",
"0",
"]",
"!=",
"'/'",
")",
"return",
"from",
";",
"if",
"(",
"to",
"[",
"0",
"]",
"==",
"'/'",
"&&",
"from",
"[",
"0",
"]",
"!=",
"'/'",
")",
"return",
"to",
";",
"var",
"base",
"=",
"from",
".",
"replace",
"(",
"/",
"^\\/$",
"/",
",",
"''",
")",
".",
"split",
"(",
"/",
"\\/",
"/",
")",
";",
"var",
"path",
"=",
"to",
".",
"replace",
"(",
"/",
"^\\/$",
"/",
",",
"''",
")",
".",
"split",
"(",
"/",
"\\/",
"/",
")",
";",
"var",
"result",
"=",
"[",
"]",
";",
"var",
"i",
"=",
"0",
";",
"while",
"(",
"path",
"[",
"i",
"]",
"==",
"base",
"[",
"i",
"]",
"&&",
"typeof",
"base",
"[",
"i",
"]",
"==",
"'string'",
")",
"i",
"++",
";",
"for",
"(",
"var",
"j",
"=",
"base",
".",
"length",
"-",
"i",
";",
"j",
">",
"0",
";",
"j",
"--",
")",
"result",
".",
"push",
"(",
"'..'",
")",
";",
"return",
"result",
".",
"concat",
"(",
"path",
".",
"slice",
"(",
"i",
")",
".",
"filter",
"(",
"Boolean",
")",
")",
".",
"join",
"(",
"'/'",
")",
";",
"}"
] |
Solve the relative path from from to to.
At times we have two absolute paths, and we need to derive the
relative path from one to the other. This is actually the reverse
transform of {basis.path.resolve}, which means we see that:
basis.path.resolve(from, basis.path.relative(from, to)) == basis.path.resolve(to)
If `to` argument omitted than resolve `from` relative to current baseURI.
Function also could be used with Array#map method as well. In this case
every array member resolves to current baseURI.
@example
basis.path.relative('/data/orandea/test/aaa', '/data/orandea/impl/bbb');
// returns '../../impl/bbb'
['foo', '/a/b/bar', 'a/b/baz'].map(basis.path.relative);
// if baseURI is '/a/b' it produces
// ['../../foo', 'bar', '../../a/b/baz']
@param {string} from
@param {string=} to
@return {string}
|
[
"Solve",
"the",
"relative",
"path",
"from",
"from",
"to",
"to",
"."
] |
8571903014b207a09d45ad2d1bfba277bf21289b
|
https://github.com/basisjs/basisjs/blob/8571903014b207a09d45ad2d1bfba277bf21289b/src/basis.js#L1199-L1228
|
train
|
|
basisjs/basisjs
|
src/basis.js
|
fetchConfig
|
function fetchConfig(){
var config = __config;
if (!config)
{
if (NODE_ENV)
{
// node.js env
basisFilename = process.basisjsFilename || __filename.replace(/\\/g, '/');
/** @cut */ if (process.basisjsConfig)
/** @cut */ {
/** @cut */ config = process.basisjsConfig;
/** @cut */ if (typeof config == 'string')
/** @cut */ {
/** @cut */ try {
/** @cut */ config = Function('return{' + config + '}')();
/** @cut */ } catch(e) {
/** @cut */ /** @cut */ consoleMethods.error('basis-config: basis.js config parse fault: ' + e);
/** @cut */ }
/** @cut */ }
/** @cut */ }
}
else
{
// browser env
var scripts = document.scripts;
for (var i = 0, scriptEl; scriptEl = scripts[i]; i++)
{
var configAttrValue = scriptEl.hasAttribute('basis-config')
? scriptEl.getAttribute('basis-config')
: scriptEl.getAttribute('data-basis-config');
scriptEl.removeAttribute('basis-config');
scriptEl.removeAttribute('data-basis-config');
if (configAttrValue !== null)
{
basisFilename = pathUtils.normalize(scriptEl.src);
try {
config = Function('return{' + configAttrValue + '}')();
} catch(e) {
/** @cut */ consoleMethods.error('basis-config: basis.js config parse fault: ' + e);
}
break;
}
}
if (!basisFilename)
{
basisFilename = pathUtils.normalize(scripts[0].src);
/** @cut */ consoleMethods.warn('basis-config: no `basis-config` marker on any script tag is found. All paths will be resolved relative to `src` from the first `script` tag.');
}
}
}
return processConfig(config);
}
|
javascript
|
function fetchConfig(){
var config = __config;
if (!config)
{
if (NODE_ENV)
{
// node.js env
basisFilename = process.basisjsFilename || __filename.replace(/\\/g, '/');
/** @cut */ if (process.basisjsConfig)
/** @cut */ {
/** @cut */ config = process.basisjsConfig;
/** @cut */ if (typeof config == 'string')
/** @cut */ {
/** @cut */ try {
/** @cut */ config = Function('return{' + config + '}')();
/** @cut */ } catch(e) {
/** @cut */ /** @cut */ consoleMethods.error('basis-config: basis.js config parse fault: ' + e);
/** @cut */ }
/** @cut */ }
/** @cut */ }
}
else
{
// browser env
var scripts = document.scripts;
for (var i = 0, scriptEl; scriptEl = scripts[i]; i++)
{
var configAttrValue = scriptEl.hasAttribute('basis-config')
? scriptEl.getAttribute('basis-config')
: scriptEl.getAttribute('data-basis-config');
scriptEl.removeAttribute('basis-config');
scriptEl.removeAttribute('data-basis-config');
if (configAttrValue !== null)
{
basisFilename = pathUtils.normalize(scriptEl.src);
try {
config = Function('return{' + configAttrValue + '}')();
} catch(e) {
/** @cut */ consoleMethods.error('basis-config: basis.js config parse fault: ' + e);
}
break;
}
}
if (!basisFilename)
{
basisFilename = pathUtils.normalize(scripts[0].src);
/** @cut */ consoleMethods.warn('basis-config: no `basis-config` marker on any script tag is found. All paths will be resolved relative to `src` from the first `script` tag.');
}
}
}
return processConfig(config);
}
|
[
"function",
"fetchConfig",
"(",
")",
"{",
"var",
"config",
"=",
"__config",
";",
"if",
"(",
"!",
"config",
")",
"{",
"if",
"(",
"NODE_ENV",
")",
"{",
"basisFilename",
"=",
"process",
".",
"basisjsFilename",
"||",
"__filename",
".",
"replace",
"(",
"/",
"\\\\",
"/",
"g",
",",
"'/'",
")",
";",
"if",
"(",
"process",
".",
"basisjsConfig",
")",
"{",
"config",
"=",
"process",
".",
"basisjsConfig",
";",
"if",
"(",
"typeof",
"config",
"==",
"'string'",
")",
"{",
"try",
"{",
"config",
"=",
"Function",
"(",
"'return{'",
"+",
"config",
"+",
"'}'",
")",
"(",
")",
";",
"}",
"catch",
"(",
"e",
")",
"{",
"consoleMethods",
".",
"error",
"(",
"'basis-config: basis.js config parse fault: '",
"+",
"e",
")",
";",
"}",
"}",
"}",
"}",
"else",
"{",
"var",
"scripts",
"=",
"document",
".",
"scripts",
";",
"for",
"(",
"var",
"i",
"=",
"0",
",",
"scriptEl",
";",
"scriptEl",
"=",
"scripts",
"[",
"i",
"]",
";",
"i",
"++",
")",
"{",
"var",
"configAttrValue",
"=",
"scriptEl",
".",
"hasAttribute",
"(",
"'basis-config'",
")",
"?",
"scriptEl",
".",
"getAttribute",
"(",
"'basis-config'",
")",
":",
"scriptEl",
".",
"getAttribute",
"(",
"'data-basis-config'",
")",
";",
"scriptEl",
".",
"removeAttribute",
"(",
"'basis-config'",
")",
";",
"scriptEl",
".",
"removeAttribute",
"(",
"'data-basis-config'",
")",
";",
"if",
"(",
"configAttrValue",
"!==",
"null",
")",
"{",
"basisFilename",
"=",
"pathUtils",
".",
"normalize",
"(",
"scriptEl",
".",
"src",
")",
";",
"try",
"{",
"config",
"=",
"Function",
"(",
"'return{'",
"+",
"configAttrValue",
"+",
"'}'",
")",
"(",
")",
";",
"}",
"catch",
"(",
"e",
")",
"{",
"consoleMethods",
".",
"error",
"(",
"'basis-config: basis.js config parse fault: '",
"+",
"e",
")",
";",
"}",
"break",
";",
"}",
"}",
"if",
"(",
"!",
"basisFilename",
")",
"{",
"basisFilename",
"=",
"pathUtils",
".",
"normalize",
"(",
"scripts",
"[",
"0",
"]",
".",
"src",
")",
";",
"consoleMethods",
".",
"warn",
"(",
"'basis-config: no `basis-config` marker on any script tag is found. All paths will be resolved relative to `src` from the first `script` tag.'",
")",
";",
"}",
"}",
"}",
"return",
"processConfig",
"(",
"config",
")",
";",
"}"
] |
Fetch basis.js options from script's `basis-config` or `data-basis-config` attribute.
|
[
"Fetch",
"basis",
".",
"js",
"options",
"from",
"script",
"s",
"basis",
"-",
"config",
"or",
"data",
"-",
"basis",
"-",
"config",
"attribute",
"."
] |
8571903014b207a09d45ad2d1bfba277bf21289b
|
https://github.com/basisjs/basisjs/blob/8571903014b207a09d45ad2d1bfba277bf21289b/src/basis.js#L1249-L1308
|
train
|
basisjs/basisjs
|
src/basis.js
|
processConfig
|
function processConfig(config){
// make a copy of config
config = slice(config);
// extend by default settings
complete(config, {
implicitExt: NODE_ENV ? true : false // true, false, 'warn'
});
// warn about extProto in basis-config, this option was removed in 1.3.0
/** @cut */ if ('extProto' in config)
/** @cut */ consoleMethods.warn('basis-config: `extProto` option in basis-config is not support anymore');
// warn about path in basis-config, this option was deprecated in 1.3.0
/** @cut */ if ('path' in config)
/** @cut */ consoleMethods.warn('basis-config: `path` option in basis-config is deprecated, use `modules` instead');
// build modules list
var autoload = [];
var modules = merge(config.path, config.modules, {
basis: basisFilename
});
// reset modules
config.modules = {};
// process autoload
if (config.autoload)
{
// [path/to/][name][.rest.ext] -> {
// name: name,
// filename: path + name + rest
// }
var m = String(config.autoload).match(/^((?:[^\/]*\/)*)([a-z$_][a-z0-9$_]*)((?:\.[a-z$_][a-z0-9$_]*)*)$/i);
if (m)
{
modules[m[2]] = {
autoload: true,
filename: m[1] + m[2] + (m[3] || '.js')
};
}
else
{
/** @cut */ consoleMethods.warn('basis-config: wrong `autoload` value (setting ignored): ' + config.autoload);
}
delete config.autoload;
}
// process modules
for (var name in modules)
{
// name: {
// autoload: boolean,
// path: 'path/to',
// filename: 'module.js'
// }
//
// or
//
// name: 'filename'
var module = modules[name];
// if value is string, convert to config
if (typeof module == 'string')
// value is filename
module = {
// if path ends with `/` add `[name].js` to the end
filename: module.replace(/\/$/, '/' + name + '.js')
};
// get and resolve path and filename
var filename = module.filename;
var path = module.path;
// if no path but filename
// let filename equals to 'path/to/file[.ext]', then
// path = 'path/to/file'
// filename = '../file[.ext]'
if (filename && !path)
{
filename = pathUtils.resolve(filename);
path = filename.substr(0, filename.length - pathUtils.extname(filename).length);
filename = '../' + pathUtils.basename(filename);
}
// path should be absolute
// at this point path is defined in any case
path = pathUtils.resolve(path);
// if no filename but path
// let path equals to 'path/to/file[.ext]', then
// path = 'path/to'
// filename = 'file[.ext]'
if (!filename && path)
{
filename = pathUtils.basename(path);
path = pathUtils.dirname(path);
}
// if filename has no extension, adds `.js`
if (!pathUtils.extname(filename))
filename += '.js';
// resolve filename
filename = pathUtils.resolve(path, filename);
// store results
config.modules[name] = {
path: path,
filename: filename
};
// store autoload modules
if (module.autoload)
{
config.autoload = autoload;
autoload.push(name);
}
}
return config;
}
|
javascript
|
function processConfig(config){
// make a copy of config
config = slice(config);
// extend by default settings
complete(config, {
implicitExt: NODE_ENV ? true : false // true, false, 'warn'
});
// warn about extProto in basis-config, this option was removed in 1.3.0
/** @cut */ if ('extProto' in config)
/** @cut */ consoleMethods.warn('basis-config: `extProto` option in basis-config is not support anymore');
// warn about path in basis-config, this option was deprecated in 1.3.0
/** @cut */ if ('path' in config)
/** @cut */ consoleMethods.warn('basis-config: `path` option in basis-config is deprecated, use `modules` instead');
// build modules list
var autoload = [];
var modules = merge(config.path, config.modules, {
basis: basisFilename
});
// reset modules
config.modules = {};
// process autoload
if (config.autoload)
{
// [path/to/][name][.rest.ext] -> {
// name: name,
// filename: path + name + rest
// }
var m = String(config.autoload).match(/^((?:[^\/]*\/)*)([a-z$_][a-z0-9$_]*)((?:\.[a-z$_][a-z0-9$_]*)*)$/i);
if (m)
{
modules[m[2]] = {
autoload: true,
filename: m[1] + m[2] + (m[3] || '.js')
};
}
else
{
/** @cut */ consoleMethods.warn('basis-config: wrong `autoload` value (setting ignored): ' + config.autoload);
}
delete config.autoload;
}
// process modules
for (var name in modules)
{
// name: {
// autoload: boolean,
// path: 'path/to',
// filename: 'module.js'
// }
//
// or
//
// name: 'filename'
var module = modules[name];
// if value is string, convert to config
if (typeof module == 'string')
// value is filename
module = {
// if path ends with `/` add `[name].js` to the end
filename: module.replace(/\/$/, '/' + name + '.js')
};
// get and resolve path and filename
var filename = module.filename;
var path = module.path;
// if no path but filename
// let filename equals to 'path/to/file[.ext]', then
// path = 'path/to/file'
// filename = '../file[.ext]'
if (filename && !path)
{
filename = pathUtils.resolve(filename);
path = filename.substr(0, filename.length - pathUtils.extname(filename).length);
filename = '../' + pathUtils.basename(filename);
}
// path should be absolute
// at this point path is defined in any case
path = pathUtils.resolve(path);
// if no filename but path
// let path equals to 'path/to/file[.ext]', then
// path = 'path/to'
// filename = 'file[.ext]'
if (!filename && path)
{
filename = pathUtils.basename(path);
path = pathUtils.dirname(path);
}
// if filename has no extension, adds `.js`
if (!pathUtils.extname(filename))
filename += '.js';
// resolve filename
filename = pathUtils.resolve(path, filename);
// store results
config.modules[name] = {
path: path,
filename: filename
};
// store autoload modules
if (module.autoload)
{
config.autoload = autoload;
autoload.push(name);
}
}
return config;
}
|
[
"function",
"processConfig",
"(",
"config",
")",
"{",
"config",
"=",
"slice",
"(",
"config",
")",
";",
"complete",
"(",
"config",
",",
"{",
"implicitExt",
":",
"NODE_ENV",
"?",
"true",
":",
"false",
"}",
")",
";",
"if",
"(",
"'extProto'",
"in",
"config",
")",
"consoleMethods",
".",
"warn",
"(",
"'basis-config: `extProto` option in basis-config is not support anymore'",
")",
";",
"if",
"(",
"'path'",
"in",
"config",
")",
"consoleMethods",
".",
"warn",
"(",
"'basis-config: `path` option in basis-config is deprecated, use `modules` instead'",
")",
";",
"var",
"autoload",
"=",
"[",
"]",
";",
"var",
"modules",
"=",
"merge",
"(",
"config",
".",
"path",
",",
"config",
".",
"modules",
",",
"{",
"basis",
":",
"basisFilename",
"}",
")",
";",
"config",
".",
"modules",
"=",
"{",
"}",
";",
"if",
"(",
"config",
".",
"autoload",
")",
"{",
"var",
"m",
"=",
"String",
"(",
"config",
".",
"autoload",
")",
".",
"match",
"(",
"/",
"^((?:[^\\/]*\\/)*)([a-z$_][a-z0-9$_]*)((?:\\.[a-z$_][a-z0-9$_]*)*)$",
"/",
"i",
")",
";",
"if",
"(",
"m",
")",
"{",
"modules",
"[",
"m",
"[",
"2",
"]",
"]",
"=",
"{",
"autoload",
":",
"true",
",",
"filename",
":",
"m",
"[",
"1",
"]",
"+",
"m",
"[",
"2",
"]",
"+",
"(",
"m",
"[",
"3",
"]",
"||",
"'.js'",
")",
"}",
";",
"}",
"else",
"{",
"consoleMethods",
".",
"warn",
"(",
"'basis-config: wrong `autoload` value (setting ignored): '",
"+",
"config",
".",
"autoload",
")",
";",
"}",
"delete",
"config",
".",
"autoload",
";",
"}",
"for",
"(",
"var",
"name",
"in",
"modules",
")",
"{",
"var",
"module",
"=",
"modules",
"[",
"name",
"]",
";",
"if",
"(",
"typeof",
"module",
"==",
"'string'",
")",
"module",
"=",
"{",
"filename",
":",
"module",
".",
"replace",
"(",
"/",
"\\/$",
"/",
",",
"'/'",
"+",
"name",
"+",
"'.js'",
")",
"}",
";",
"var",
"filename",
"=",
"module",
".",
"filename",
";",
"var",
"path",
"=",
"module",
".",
"path",
";",
"if",
"(",
"filename",
"&&",
"!",
"path",
")",
"{",
"filename",
"=",
"pathUtils",
".",
"resolve",
"(",
"filename",
")",
";",
"path",
"=",
"filename",
".",
"substr",
"(",
"0",
",",
"filename",
".",
"length",
"-",
"pathUtils",
".",
"extname",
"(",
"filename",
")",
".",
"length",
")",
";",
"filename",
"=",
"'../'",
"+",
"pathUtils",
".",
"basename",
"(",
"filename",
")",
";",
"}",
"path",
"=",
"pathUtils",
".",
"resolve",
"(",
"path",
")",
";",
"if",
"(",
"!",
"filename",
"&&",
"path",
")",
"{",
"filename",
"=",
"pathUtils",
".",
"basename",
"(",
"path",
")",
";",
"path",
"=",
"pathUtils",
".",
"dirname",
"(",
"path",
")",
";",
"}",
"if",
"(",
"!",
"pathUtils",
".",
"extname",
"(",
"filename",
")",
")",
"filename",
"+=",
"'.js'",
";",
"filename",
"=",
"pathUtils",
".",
"resolve",
"(",
"path",
",",
"filename",
")",
";",
"config",
".",
"modules",
"[",
"name",
"]",
"=",
"{",
"path",
":",
"path",
",",
"filename",
":",
"filename",
"}",
";",
"if",
"(",
"module",
".",
"autoload",
")",
"{",
"config",
".",
"autoload",
"=",
"autoload",
";",
"autoload",
".",
"push",
"(",
"name",
")",
";",
"}",
"}",
"return",
"config",
";",
"}"
] |
Process config object and returns adopted config.
Special options:
- autoload: namespace that must be loaded right after core loaded
- path: dictionary of paths for root namespaces
- modules: dictionary of modules with options
Other options copy into basis.config as is.
|
[
"Process",
"config",
"object",
"and",
"returns",
"adopted",
"config",
"."
] |
8571903014b207a09d45ad2d1bfba277bf21289b
|
https://github.com/basisjs/basisjs/blob/8571903014b207a09d45ad2d1bfba277bf21289b/src/basis.js#L1320-L1444
|
train
|
basisjs/basisjs
|
src/basis.js
|
createClass
|
function createClass(SuperClass){
var classId = classSeed++;
if (typeof SuperClass != 'function')
SuperClass = BaseClass;
/** @cut */ var className = '';
/** @cut */ for (var i = 1, extension; extension = arguments[i]; i++)
/** @cut */ if (typeof extension != 'function' && extension.className)
/** @cut */ className = extension.className;
/** @cut */ if (!className)
/** @cut */ className = SuperClass.className + '._Class' + classId;
// temp class constructor with no init call
var NewClassProto = function(){};
// verbose name in dev
/** @cut */ NewClassProto = devVerboseName(className, {}, NewClassProto);
NewClassProto.prototype = SuperClass.prototype;
var newProto = new NewClassProto;
var newClassProps = {
/** @cut */ className: className,
basisClassId_: classId,
superClass_: SuperClass,
extendConstructor_: !!SuperClass.extendConstructor_,
// class methods
isSubclassOf: isSubclassOf,
subclass: function(){
return createClass.apply(null, [NewClass].concat(arrayFrom(arguments)));
},
extend: extendClass,
factory: function(config){
return factory(function(extra){
return new NewClass(merge(config, extra));
});
},
// auto extend creates a subclass
__extend__: function(value){
if (value && value !== SELF && (typeof value == 'object' || (typeof value == 'function' && !isClass(value))))
return BaseClass.create.call(null, NewClass, value);
else
return value;
},
// new class prototype
prototype: newProto
};
// extend NewClass prototype
for (var i = 1, extension; extension = arguments[i]; i++)
newClassProps.extend(extension);
/** @cut */if (newProto.init !== BaseClass.prototype.init && !/^function[^(]*\(\)/.test(newProto.init) && newClassProps.extendConstructor_) consoleMethods.warn('probably wrong extendConstructor_ value for ' + newClassProps.className);
// new class constructor
var NewClass = newClassProps.extendConstructor_
// constructor with instance extension
? function(extend){
// mark object
this.basisObjectId = instanceSeed.id++;
// extend and override instance properties
var prop;
for (var key in extend)
{
prop = this[key];
this[key] = prop && prop.__extend__
? prop.__extend__(extend[key])
: extend[key];
}
// call constructor
this.init();
// post init
this.postInit();
}
// simple constructor
: function(){
// mark object
this.basisObjectId = instanceSeed.id++;
// call constructor
this.init.apply(this, arguments);
// post init
this.postInit();
};
// verbose name in dev
// NOTE: this code makes Chrome and Firefox show class name in console
/** @cut */ NewClass = devVerboseName(className, { instanceSeed: instanceSeed }, NewClass);
// add constructor property to prototype
newProto.constructor = NewClass;
for (var key in newProto)
if (newProto[key] === SELF)
newProto[key] = NewClass;
//else
// newProto[key] = newProto[key];
// extend constructor with properties
extend(NewClass, newClassProps);
// for class introspection
/** @cut */ classes.push(NewClass);
// return new class
return NewClass;
}
|
javascript
|
function createClass(SuperClass){
var classId = classSeed++;
if (typeof SuperClass != 'function')
SuperClass = BaseClass;
/** @cut */ var className = '';
/** @cut */ for (var i = 1, extension; extension = arguments[i]; i++)
/** @cut */ if (typeof extension != 'function' && extension.className)
/** @cut */ className = extension.className;
/** @cut */ if (!className)
/** @cut */ className = SuperClass.className + '._Class' + classId;
// temp class constructor with no init call
var NewClassProto = function(){};
// verbose name in dev
/** @cut */ NewClassProto = devVerboseName(className, {}, NewClassProto);
NewClassProto.prototype = SuperClass.prototype;
var newProto = new NewClassProto;
var newClassProps = {
/** @cut */ className: className,
basisClassId_: classId,
superClass_: SuperClass,
extendConstructor_: !!SuperClass.extendConstructor_,
// class methods
isSubclassOf: isSubclassOf,
subclass: function(){
return createClass.apply(null, [NewClass].concat(arrayFrom(arguments)));
},
extend: extendClass,
factory: function(config){
return factory(function(extra){
return new NewClass(merge(config, extra));
});
},
// auto extend creates a subclass
__extend__: function(value){
if (value && value !== SELF && (typeof value == 'object' || (typeof value == 'function' && !isClass(value))))
return BaseClass.create.call(null, NewClass, value);
else
return value;
},
// new class prototype
prototype: newProto
};
// extend NewClass prototype
for (var i = 1, extension; extension = arguments[i]; i++)
newClassProps.extend(extension);
/** @cut */if (newProto.init !== BaseClass.prototype.init && !/^function[^(]*\(\)/.test(newProto.init) && newClassProps.extendConstructor_) consoleMethods.warn('probably wrong extendConstructor_ value for ' + newClassProps.className);
// new class constructor
var NewClass = newClassProps.extendConstructor_
// constructor with instance extension
? function(extend){
// mark object
this.basisObjectId = instanceSeed.id++;
// extend and override instance properties
var prop;
for (var key in extend)
{
prop = this[key];
this[key] = prop && prop.__extend__
? prop.__extend__(extend[key])
: extend[key];
}
// call constructor
this.init();
// post init
this.postInit();
}
// simple constructor
: function(){
// mark object
this.basisObjectId = instanceSeed.id++;
// call constructor
this.init.apply(this, arguments);
// post init
this.postInit();
};
// verbose name in dev
// NOTE: this code makes Chrome and Firefox show class name in console
/** @cut */ NewClass = devVerboseName(className, { instanceSeed: instanceSeed }, NewClass);
// add constructor property to prototype
newProto.constructor = NewClass;
for (var key in newProto)
if (newProto[key] === SELF)
newProto[key] = NewClass;
//else
// newProto[key] = newProto[key];
// extend constructor with properties
extend(NewClass, newClassProps);
// for class introspection
/** @cut */ classes.push(NewClass);
// return new class
return NewClass;
}
|
[
"function",
"createClass",
"(",
"SuperClass",
")",
"{",
"var",
"classId",
"=",
"classSeed",
"++",
";",
"if",
"(",
"typeof",
"SuperClass",
"!=",
"'function'",
")",
"SuperClass",
"=",
"BaseClass",
";",
"var",
"className",
"=",
"''",
";",
"for",
"(",
"var",
"i",
"=",
"1",
",",
"extension",
";",
"extension",
"=",
"arguments",
"[",
"i",
"]",
";",
"i",
"++",
")",
"if",
"(",
"typeof",
"extension",
"!=",
"'function'",
"&&",
"extension",
".",
"className",
")",
"className",
"=",
"extension",
".",
"className",
";",
"if",
"(",
"!",
"className",
")",
"className",
"=",
"SuperClass",
".",
"className",
"+",
"'._Class'",
"+",
"classId",
";",
"var",
"NewClassProto",
"=",
"function",
"(",
")",
"{",
"}",
";",
"NewClassProto",
"=",
"devVerboseName",
"(",
"className",
",",
"{",
"}",
",",
"NewClassProto",
")",
";",
"NewClassProto",
".",
"prototype",
"=",
"SuperClass",
".",
"prototype",
";",
"var",
"newProto",
"=",
"new",
"NewClassProto",
";",
"var",
"newClassProps",
"=",
"{",
"className",
":",
"className",
",",
"basisClassId_",
":",
"classId",
",",
"superClass_",
":",
"SuperClass",
",",
"extendConstructor_",
":",
"!",
"!",
"SuperClass",
".",
"extendConstructor_",
",",
"isSubclassOf",
":",
"isSubclassOf",
",",
"subclass",
":",
"function",
"(",
")",
"{",
"return",
"createClass",
".",
"apply",
"(",
"null",
",",
"[",
"NewClass",
"]",
".",
"concat",
"(",
"arrayFrom",
"(",
"arguments",
")",
")",
")",
";",
"}",
",",
"extend",
":",
"extendClass",
",",
"factory",
":",
"function",
"(",
"config",
")",
"{",
"return",
"factory",
"(",
"function",
"(",
"extra",
")",
"{",
"return",
"new",
"NewClass",
"(",
"merge",
"(",
"config",
",",
"extra",
")",
")",
";",
"}",
")",
";",
"}",
",",
"__extend__",
":",
"function",
"(",
"value",
")",
"{",
"if",
"(",
"value",
"&&",
"value",
"!==",
"SELF",
"&&",
"(",
"typeof",
"value",
"==",
"'object'",
"||",
"(",
"typeof",
"value",
"==",
"'function'",
"&&",
"!",
"isClass",
"(",
"value",
")",
")",
")",
")",
"return",
"BaseClass",
".",
"create",
".",
"call",
"(",
"null",
",",
"NewClass",
",",
"value",
")",
";",
"else",
"return",
"value",
";",
"}",
",",
"prototype",
":",
"newProto",
"}",
";",
"for",
"(",
"var",
"i",
"=",
"1",
",",
"extension",
";",
"extension",
"=",
"arguments",
"[",
"i",
"]",
";",
"i",
"++",
")",
"newClassProps",
".",
"extend",
"(",
"extension",
")",
";",
"if",
"(",
"newProto",
".",
"init",
"!==",
"BaseClass",
".",
"prototype",
".",
"init",
"&&",
"!",
"/",
"^function[^(]*\\(\\)",
"/",
".",
"test",
"(",
"newProto",
".",
"init",
")",
"&&",
"newClassProps",
".",
"extendConstructor_",
")",
"consoleMethods",
".",
"warn",
"(",
"'probably wrong extendConstructor_ value for '",
"+",
"newClassProps",
".",
"className",
")",
";",
"var",
"NewClass",
"=",
"newClassProps",
".",
"extendConstructor_",
"?",
"function",
"(",
"extend",
")",
"{",
"this",
".",
"basisObjectId",
"=",
"instanceSeed",
".",
"id",
"++",
";",
"var",
"prop",
";",
"for",
"(",
"var",
"key",
"in",
"extend",
")",
"{",
"prop",
"=",
"this",
"[",
"key",
"]",
";",
"this",
"[",
"key",
"]",
"=",
"prop",
"&&",
"prop",
".",
"__extend__",
"?",
"prop",
".",
"__extend__",
"(",
"extend",
"[",
"key",
"]",
")",
":",
"extend",
"[",
"key",
"]",
";",
"}",
"this",
".",
"init",
"(",
")",
";",
"this",
".",
"postInit",
"(",
")",
";",
"}",
":",
"function",
"(",
")",
"{",
"this",
".",
"basisObjectId",
"=",
"instanceSeed",
".",
"id",
"++",
";",
"this",
".",
"init",
".",
"apply",
"(",
"this",
",",
"arguments",
")",
";",
"this",
".",
"postInit",
"(",
")",
";",
"}",
";",
"NewClass",
"=",
"devVerboseName",
"(",
"className",
",",
"{",
"instanceSeed",
":",
"instanceSeed",
"}",
",",
"NewClass",
")",
";",
"newProto",
".",
"constructor",
"=",
"NewClass",
";",
"for",
"(",
"var",
"key",
"in",
"newProto",
")",
"if",
"(",
"newProto",
"[",
"key",
"]",
"===",
"SELF",
")",
"newProto",
"[",
"key",
"]",
"=",
"NewClass",
";",
"extend",
"(",
"NewClass",
",",
"newClassProps",
")",
";",
"classes",
".",
"push",
"(",
"NewClass",
")",
";",
"return",
"NewClass",
";",
"}"
] |
Class constructor.
@param {function()} SuperClass Class that new one inherits of.
@param {...(object|function())} extensions Objects that extends new class prototype.
@return {function()} A new class.
|
[
"Class",
"constructor",
"."
] |
8571903014b207a09d45ad2d1bfba277bf21289b
|
https://github.com/basisjs/basisjs/blob/8571903014b207a09d45ad2d1bfba277bf21289b/src/basis.js#L1541-L1659
|
train
|
basisjs/basisjs
|
src/basis.js
|
function(value){
if (value && value !== SELF && (typeof value == 'object' || (typeof value == 'function' && !isClass(value))))
return BaseClass.create.call(null, NewClass, value);
else
return value;
}
|
javascript
|
function(value){
if (value && value !== SELF && (typeof value == 'object' || (typeof value == 'function' && !isClass(value))))
return BaseClass.create.call(null, NewClass, value);
else
return value;
}
|
[
"function",
"(",
"value",
")",
"{",
"if",
"(",
"value",
"&&",
"value",
"!==",
"SELF",
"&&",
"(",
"typeof",
"value",
"==",
"'object'",
"||",
"(",
"typeof",
"value",
"==",
"'function'",
"&&",
"!",
"isClass",
"(",
"value",
")",
")",
")",
")",
"return",
"BaseClass",
".",
"create",
".",
"call",
"(",
"null",
",",
"NewClass",
",",
"value",
")",
";",
"else",
"return",
"value",
";",
"}"
] |
auto extend creates a subclass
|
[
"auto",
"extend",
"creates",
"a",
"subclass"
] |
8571903014b207a09d45ad2d1bfba277bf21289b
|
https://github.com/basisjs/basisjs/blob/8571903014b207a09d45ad2d1bfba277bf21289b/src/basis.js#L1585-L1590
|
train
|
|
basisjs/basisjs
|
src/basis.js
|
extendClass
|
function extendClass(source){
var proto = this.prototype;
if (typeof source == 'function' && !isClass(source))
source = source(this.superClass_.prototype, slice(proto));
if (source.prototype)
source = source.prototype;
for (var key in source)
{
var value = source[key];
var protoValue = proto[key];
if (key == 'className' || key == 'extendConstructor_')
this[key] = value;
else
{
if (protoValue && protoValue.__extend__)
proto[key] = protoValue.__extend__(value);
else
{
proto[key] = value;
///** @cut */ if (value && !value.__extend__ && (value.constructor == Object || value.constructor == Array)){ consoleMethods.warn('!' + key); }
}
}
}
// for browsers that doesn't enum toString
if (TOSTRING_BUG && source[key = 'toString'] !== toString)
proto[key] = source[key];
return this;
}
|
javascript
|
function extendClass(source){
var proto = this.prototype;
if (typeof source == 'function' && !isClass(source))
source = source(this.superClass_.prototype, slice(proto));
if (source.prototype)
source = source.prototype;
for (var key in source)
{
var value = source[key];
var protoValue = proto[key];
if (key == 'className' || key == 'extendConstructor_')
this[key] = value;
else
{
if (protoValue && protoValue.__extend__)
proto[key] = protoValue.__extend__(value);
else
{
proto[key] = value;
///** @cut */ if (value && !value.__extend__ && (value.constructor == Object || value.constructor == Array)){ consoleMethods.warn('!' + key); }
}
}
}
// for browsers that doesn't enum toString
if (TOSTRING_BUG && source[key = 'toString'] !== toString)
proto[key] = source[key];
return this;
}
|
[
"function",
"extendClass",
"(",
"source",
")",
"{",
"var",
"proto",
"=",
"this",
".",
"prototype",
";",
"if",
"(",
"typeof",
"source",
"==",
"'function'",
"&&",
"!",
"isClass",
"(",
"source",
")",
")",
"source",
"=",
"source",
"(",
"this",
".",
"superClass_",
".",
"prototype",
",",
"slice",
"(",
"proto",
")",
")",
";",
"if",
"(",
"source",
".",
"prototype",
")",
"source",
"=",
"source",
".",
"prototype",
";",
"for",
"(",
"var",
"key",
"in",
"source",
")",
"{",
"var",
"value",
"=",
"source",
"[",
"key",
"]",
";",
"var",
"protoValue",
"=",
"proto",
"[",
"key",
"]",
";",
"if",
"(",
"key",
"==",
"'className'",
"||",
"key",
"==",
"'extendConstructor_'",
")",
"this",
"[",
"key",
"]",
"=",
"value",
";",
"else",
"{",
"if",
"(",
"protoValue",
"&&",
"protoValue",
".",
"__extend__",
")",
"proto",
"[",
"key",
"]",
"=",
"protoValue",
".",
"__extend__",
"(",
"value",
")",
";",
"else",
"{",
"proto",
"[",
"key",
"]",
"=",
"value",
";",
"}",
"}",
"}",
"if",
"(",
"TOSTRING_BUG",
"&&",
"source",
"[",
"key",
"=",
"'toString'",
"]",
"!==",
"toString",
")",
"proto",
"[",
"key",
"]",
"=",
"source",
"[",
"key",
"]",
";",
"return",
"this",
";",
"}"
] |
Extend class prototype
@param {Object} source If source has a prototype, it will be used to extend current prototype.
@return {function()} Returns `this`.
|
[
"Extend",
"class",
"prototype"
] |
8571903014b207a09d45ad2d1bfba277bf21289b
|
https://github.com/basisjs/basisjs/blob/8571903014b207a09d45ad2d1bfba277bf21289b/src/basis.js#L1666-L1699
|
train
|
basisjs/basisjs
|
src/basis.js
|
function(){
var value = this.get();
var cursor = this;
while (cursor = cursor.handler)
cursor.fn.call(cursor.context, value);
}
|
javascript
|
function(){
var value = this.get();
var cursor = this;
while (cursor = cursor.handler)
cursor.fn.call(cursor.context, value);
}
|
[
"function",
"(",
")",
"{",
"var",
"value",
"=",
"this",
".",
"get",
"(",
")",
";",
"var",
"cursor",
"=",
"this",
";",
"while",
"(",
"cursor",
"=",
"cursor",
".",
"handler",
")",
"cursor",
".",
"fn",
".",
"call",
"(",
"cursor",
".",
"context",
",",
"value",
")",
";",
"}"
] |
Call every attached callbacks with current token value.
|
[
"Call",
"every",
"attached",
"callbacks",
"with",
"current",
"token",
"value",
"."
] |
8571903014b207a09d45ad2d1bfba277bf21289b
|
https://github.com/basisjs/basisjs/blob/8571903014b207a09d45ad2d1bfba277bf21289b/src/basis.js#L1963-L1969
|
train
|
|
basisjs/basisjs
|
src/basis.js
|
function(){
var token = this.deferredToken;
if (!token)
{
token = this.deferredToken = new DeferredToken(this.get());
this.attach(token.set, token);
}
return token;
}
|
javascript
|
function(){
var token = this.deferredToken;
if (!token)
{
token = this.deferredToken = new DeferredToken(this.get());
this.attach(token.set, token);
}
return token;
}
|
[
"function",
"(",
")",
"{",
"var",
"token",
"=",
"this",
".",
"deferredToken",
";",
"if",
"(",
"!",
"token",
")",
"{",
"token",
"=",
"this",
".",
"deferredToken",
"=",
"new",
"DeferredToken",
"(",
"this",
".",
"get",
"(",
")",
")",
";",
"this",
".",
"attach",
"(",
"token",
".",
"set",
",",
"token",
")",
";",
"}",
"return",
"token",
";",
"}"
] |
Returns deferred token based on this token. Every token can has
only one it's own deferred token.
@return {basis.DeferredToken}
|
[
"Returns",
"deferred",
"token",
"based",
"on",
"this",
"token",
".",
"Every",
"token",
"can",
"has",
"only",
"one",
"it",
"s",
"own",
"deferred",
"token",
"."
] |
8571903014b207a09d45ad2d1bfba277bf21289b
|
https://github.com/basisjs/basisjs/blob/8571903014b207a09d45ad2d1bfba277bf21289b/src/basis.js#L1976-L1986
|
train
|
|
basisjs/basisjs
|
src/basis.js
|
function(fn){
var token = new Token();
var setter = function(value){
this.set(fn.call(this, value));
};
if (typeof fn != 'function')
fn = getter(fn);
setter.call(token, this.get());
this.attach(setter, token, token.destroy);
token.attach($undef, this, function(){
this.detach(setter, token);
});
/** @cut */ devInfoResolver.setInfo(token, 'sourceInfo', {
/** @cut */ type: 'Token#as',
/** @cut */ source: this,
/** @cut */ transform: fn
/** @cut */ });
return token;
}
|
javascript
|
function(fn){
var token = new Token();
var setter = function(value){
this.set(fn.call(this, value));
};
if (typeof fn != 'function')
fn = getter(fn);
setter.call(token, this.get());
this.attach(setter, token, token.destroy);
token.attach($undef, this, function(){
this.detach(setter, token);
});
/** @cut */ devInfoResolver.setInfo(token, 'sourceInfo', {
/** @cut */ type: 'Token#as',
/** @cut */ source: this,
/** @cut */ transform: fn
/** @cut */ });
return token;
}
|
[
"function",
"(",
"fn",
")",
"{",
"var",
"token",
"=",
"new",
"Token",
"(",
")",
";",
"var",
"setter",
"=",
"function",
"(",
"value",
")",
"{",
"this",
".",
"set",
"(",
"fn",
".",
"call",
"(",
"this",
",",
"value",
")",
")",
";",
"}",
";",
"if",
"(",
"typeof",
"fn",
"!=",
"'function'",
")",
"fn",
"=",
"getter",
"(",
"fn",
")",
";",
"setter",
".",
"call",
"(",
"token",
",",
"this",
".",
"get",
"(",
")",
")",
";",
"this",
".",
"attach",
"(",
"setter",
",",
"token",
",",
"token",
".",
"destroy",
")",
";",
"token",
".",
"attach",
"(",
"$undef",
",",
"this",
",",
"function",
"(",
")",
"{",
"this",
".",
"detach",
"(",
"setter",
",",
"token",
")",
";",
"}",
")",
";",
"devInfoResolver",
".",
"setInfo",
"(",
"token",
",",
"'sourceInfo'",
",",
"{",
"type",
":",
"'Token#as'",
",",
"source",
":",
"this",
",",
"transform",
":",
"fn",
"}",
")",
";",
"return",
"token",
";",
"}"
] |
Creates new token from token that contains modified through fn value.
@param {function(value):value} fn
@return {*}
|
[
"Creates",
"new",
"token",
"from",
"token",
"that",
"contains",
"modified",
"through",
"fn",
"value",
"."
] |
8571903014b207a09d45ad2d1bfba277bf21289b
|
https://github.com/basisjs/basisjs/blob/8571903014b207a09d45ad2d1bfba277bf21289b/src/basis.js#L1993-L2016
|
train
|
|
basisjs/basisjs
|
src/basis.js
|
function(){
if (this.deferredToken)
{
this.deferredToken.destroy();
this.deferredToken = null;
}
this.attach = $undef;
this.detach = $undef;
var cursor = this;
while (cursor = cursor.handler)
if (cursor.destroy)
cursor.destroy.call(cursor.context);
this.handler = null;
this.value = null;
}
|
javascript
|
function(){
if (this.deferredToken)
{
this.deferredToken.destroy();
this.deferredToken = null;
}
this.attach = $undef;
this.detach = $undef;
var cursor = this;
while (cursor = cursor.handler)
if (cursor.destroy)
cursor.destroy.call(cursor.context);
this.handler = null;
this.value = null;
}
|
[
"function",
"(",
")",
"{",
"if",
"(",
"this",
".",
"deferredToken",
")",
"{",
"this",
".",
"deferredToken",
".",
"destroy",
"(",
")",
";",
"this",
".",
"deferredToken",
"=",
"null",
";",
"}",
"this",
".",
"attach",
"=",
"$undef",
";",
"this",
".",
"detach",
"=",
"$undef",
";",
"var",
"cursor",
"=",
"this",
";",
"while",
"(",
"cursor",
"=",
"cursor",
".",
"handler",
")",
"if",
"(",
"cursor",
".",
"destroy",
")",
"cursor",
".",
"destroy",
".",
"call",
"(",
"cursor",
".",
"context",
")",
";",
"this",
".",
"handler",
"=",
"null",
";",
"this",
".",
"value",
"=",
"null",
";",
"}"
] |
Actually it's not require invoke destroy method for token, garbage
collector have no problems to free token's memory when all references
to token are removed.
@destructor
|
[
"Actually",
"it",
"s",
"not",
"require",
"invoke",
"destroy",
"method",
"for",
"token",
"garbage",
"collector",
"have",
"no",
"problems",
"to",
"free",
"token",
"s",
"memory",
"when",
"all",
"references",
"to",
"token",
"are",
"removed",
"."
] |
8571903014b207a09d45ad2d1bfba277bf21289b
|
https://github.com/basisjs/basisjs/blob/8571903014b207a09d45ad2d1bfba277bf21289b/src/basis.js#L2024-L2041
|
train
|
|
basisjs/basisjs
|
src/basis.js
|
function(searchElement, offset){
offset = parseInt(offset, 10) || 0;
if (offset < 0)
return -1;
for (; offset < this.length; offset++)
if (this[offset] === searchElement)
return offset;
return -1;
}
|
javascript
|
function(searchElement, offset){
offset = parseInt(offset, 10) || 0;
if (offset < 0)
return -1;
for (; offset < this.length; offset++)
if (this[offset] === searchElement)
return offset;
return -1;
}
|
[
"function",
"(",
"searchElement",
",",
"offset",
")",
"{",
"offset",
"=",
"parseInt",
"(",
"offset",
",",
"10",
")",
"||",
"0",
";",
"if",
"(",
"offset",
"<",
"0",
")",
"return",
"-",
"1",
";",
"for",
"(",
";",
"offset",
"<",
"this",
".",
"length",
";",
"offset",
"++",
")",
"if",
"(",
"this",
"[",
"offset",
"]",
"===",
"searchElement",
")",
"return",
"offset",
";",
"return",
"-",
"1",
";",
"}"
] |
JavaScript 1.6
|
[
"JavaScript",
"1",
".",
"6"
] |
8571903014b207a09d45ad2d1bfba277bf21289b
|
https://github.com/basisjs/basisjs/blob/8571903014b207a09d45ad2d1bfba277bf21289b/src/basis.js#L2882-L2890
|
train
|
|
basisjs/basisjs
|
src/basis.js
|
function(callback, initialValue){
var len = this.length;
var argsLen = arguments.length;
// no value to return if no initial value and an empty array
if (len == 0 && argsLen == 1)
throw new TypeError();
var result;
var inited = 0;
if (argsLen > 1)
{
result = initialValue;
inited = 1;
}
for (var i = 0; i < len; i++)
if (i in this)
if (inited++)
result = callback.call(null, result, this[i], i, this);
else
result = this[i];
return result;
}
|
javascript
|
function(callback, initialValue){
var len = this.length;
var argsLen = arguments.length;
// no value to return if no initial value and an empty array
if (len == 0 && argsLen == 1)
throw new TypeError();
var result;
var inited = 0;
if (argsLen > 1)
{
result = initialValue;
inited = 1;
}
for (var i = 0; i < len; i++)
if (i in this)
if (inited++)
result = callback.call(null, result, this[i], i, this);
else
result = this[i];
return result;
}
|
[
"function",
"(",
"callback",
",",
"initialValue",
")",
"{",
"var",
"len",
"=",
"this",
".",
"length",
";",
"var",
"argsLen",
"=",
"arguments",
".",
"length",
";",
"if",
"(",
"len",
"==",
"0",
"&&",
"argsLen",
"==",
"1",
")",
"throw",
"new",
"TypeError",
"(",
")",
";",
"var",
"result",
";",
"var",
"inited",
"=",
"0",
";",
"if",
"(",
"argsLen",
">",
"1",
")",
"{",
"result",
"=",
"initialValue",
";",
"inited",
"=",
"1",
";",
"}",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"len",
";",
"i",
"++",
")",
"if",
"(",
"i",
"in",
"this",
")",
"if",
"(",
"inited",
"++",
")",
"result",
"=",
"callback",
".",
"call",
"(",
"null",
",",
"result",
",",
"this",
"[",
"i",
"]",
",",
"i",
",",
"this",
")",
";",
"else",
"result",
"=",
"this",
"[",
"i",
"]",
";",
"return",
"result",
";",
"}"
] |
JavaScript 1.8
|
[
"JavaScript",
"1",
".",
"8"
] |
8571903014b207a09d45ad2d1bfba277bf21289b
|
https://github.com/basisjs/basisjs/blob/8571903014b207a09d45ad2d1bfba277bf21289b/src/basis.js#L2935-L2960
|
train
|
|
basisjs/basisjs
|
src/devpanel/view/file-graph/view/graph/index.js
|
function(){
return {
bindDragNDrop: function(node, handlers){
if (handlers)
{
var events = Viva.Graph.Utils.dragndrop(node.ui.element);
['onStart', 'onDrag', 'onStop'].forEach(function(name){
if (typeof handlers[name] === 'function')
events[name](handlers[name]);
});
node.events = events;
}
else if (node.events)
{ // TODO: i'm not sure if this is required in JS world...
node.events.release();
node.events = null;
}
}
};
}
|
javascript
|
function(){
return {
bindDragNDrop: function(node, handlers){
if (handlers)
{
var events = Viva.Graph.Utils.dragndrop(node.ui.element);
['onStart', 'onDrag', 'onStop'].forEach(function(name){
if (typeof handlers[name] === 'function')
events[name](handlers[name]);
});
node.events = events;
}
else if (node.events)
{ // TODO: i'm not sure if this is required in JS world...
node.events.release();
node.events = null;
}
}
};
}
|
[
"function",
"(",
")",
"{",
"return",
"{",
"bindDragNDrop",
":",
"function",
"(",
"node",
",",
"handlers",
")",
"{",
"if",
"(",
"handlers",
")",
"{",
"var",
"events",
"=",
"Viva",
".",
"Graph",
".",
"Utils",
".",
"dragndrop",
"(",
"node",
".",
"ui",
".",
"element",
")",
";",
"[",
"'onStart'",
",",
"'onDrag'",
",",
"'onStop'",
"]",
".",
"forEach",
"(",
"function",
"(",
"name",
")",
"{",
"if",
"(",
"typeof",
"handlers",
"[",
"name",
"]",
"===",
"'function'",
")",
"events",
"[",
"name",
"]",
"(",
"handlers",
"[",
"name",
"]",
")",
";",
"}",
")",
";",
"node",
".",
"events",
"=",
"events",
";",
"}",
"else",
"if",
"(",
"node",
".",
"events",
")",
"{",
"node",
".",
"events",
".",
"release",
"(",
")",
";",
"node",
".",
"events",
"=",
"null",
";",
"}",
"}",
"}",
";",
"}"
] |
Default input manager listens to DOM events to process nodes drag-n-drop
|
[
"Default",
"input",
"manager",
"listens",
"to",
"DOM",
"events",
"to",
"process",
"nodes",
"drag",
"-",
"n",
"-",
"drop"
] |
8571903014b207a09d45ad2d1bfba277bf21289b
|
https://github.com/basisjs/basisjs/blob/8571903014b207a09d45ad2d1bfba277bf21289b/src/devpanel/view/file-graph/view/graph/index.js#L189-L210
|
train
|
|
basisjs/basisjs
|
src/basis/data/dataset/MapFilter.js
|
function(rule){
rule = basis.getter(rule || $true);
if (this.rule !== rule)
{
var oldRule = this.rule;
this.rule = rule;
this.emit_ruleChanged(oldRule);
/** @cut */ basis.dev.patchInfo(this, 'sourceInfo', {
/** @cut */ transform: this.rule
/** @cut */ });
return this.applyRule();
}
}
|
javascript
|
function(rule){
rule = basis.getter(rule || $true);
if (this.rule !== rule)
{
var oldRule = this.rule;
this.rule = rule;
this.emit_ruleChanged(oldRule);
/** @cut */ basis.dev.patchInfo(this, 'sourceInfo', {
/** @cut */ transform: this.rule
/** @cut */ });
return this.applyRule();
}
}
|
[
"function",
"(",
"rule",
")",
"{",
"rule",
"=",
"basis",
".",
"getter",
"(",
"rule",
"||",
"$true",
")",
";",
"if",
"(",
"this",
".",
"rule",
"!==",
"rule",
")",
"{",
"var",
"oldRule",
"=",
"this",
".",
"rule",
";",
"this",
".",
"rule",
"=",
"rule",
";",
"this",
".",
"emit_ruleChanged",
"(",
"oldRule",
")",
";",
"basis",
".",
"dev",
".",
"patchInfo",
"(",
"this",
",",
"'sourceInfo'",
",",
"{",
"transform",
":",
"this",
".",
"rule",
"}",
")",
";",
"return",
"this",
".",
"applyRule",
"(",
")",
";",
"}",
"}"
] |
Set new filter function.
@param {function(item:basis.data.Object):*|string} rule
@return {Object} Delta of member changes.
|
[
"Set",
"new",
"filter",
"function",
"."
] |
8571903014b207a09d45ad2d1bfba277bf21289b
|
https://github.com/basisjs/basisjs/blob/8571903014b207a09d45ad2d1bfba277bf21289b/src/basis/data/dataset/MapFilter.js#L278-L294
|
train
|
|
basisjs/basisjs
|
src/basis/data/dataset/MapFilter.js
|
function(){
var sourceMap = this.sourceMap_;
var memberMap = this.members_;
var curMember;
var newMember;
var curMemberId;
var newMemberId;
var sourceObject;
var sourceObjectInfo;
var inserted = [];
var deleted = [];
var delta;
for (var sourceObjectId in sourceMap)
{
sourceObjectInfo = sourceMap[sourceObjectId];
sourceObject = sourceObjectInfo.sourceObject;
curMember = sourceObjectInfo.member;
newMember = this.map ? this.map(sourceObject) : sourceObject;
if (newMember instanceof DataObject == false || this.filter(newMember))
newMember = null;
if (!isEqual(curMember, newMember))
{
sourceObjectInfo.member = newMember;
// if here is ref for member already
if (curMember)
{
curMemberId = curMember.basisObjectId;
// call callback on member ref add
if (this.removeMemberRef)
this.removeMemberRef(curMember, sourceObject);
// decrease ref count
memberMap[curMemberId]--;
}
// if new member exists, update map
if (newMember)
{
newMemberId = newMember.basisObjectId;
// call callback on member ref add
if (this.addMemberRef)
this.addMemberRef(newMember, sourceObject);
if (newMemberId in memberMap)
{
// member is already in map -> increase ref count
memberMap[newMemberId]++;
}
else
{
// add to map
memberMap[newMemberId] = 1;
// add to delta
inserted.push(newMember);
}
}
}
}
// get deleted delta
for (curMemberId in this.items_)
if (memberMap[curMemberId] == 0)
{
delete memberMap[curMemberId];
deleted.push(this.items_[curMemberId]);
}
// if any changes, fire event
if (delta = getDelta(inserted, deleted))
this.emit_itemsChanged(delta);
return delta;
}
|
javascript
|
function(){
var sourceMap = this.sourceMap_;
var memberMap = this.members_;
var curMember;
var newMember;
var curMemberId;
var newMemberId;
var sourceObject;
var sourceObjectInfo;
var inserted = [];
var deleted = [];
var delta;
for (var sourceObjectId in sourceMap)
{
sourceObjectInfo = sourceMap[sourceObjectId];
sourceObject = sourceObjectInfo.sourceObject;
curMember = sourceObjectInfo.member;
newMember = this.map ? this.map(sourceObject) : sourceObject;
if (newMember instanceof DataObject == false || this.filter(newMember))
newMember = null;
if (!isEqual(curMember, newMember))
{
sourceObjectInfo.member = newMember;
// if here is ref for member already
if (curMember)
{
curMemberId = curMember.basisObjectId;
// call callback on member ref add
if (this.removeMemberRef)
this.removeMemberRef(curMember, sourceObject);
// decrease ref count
memberMap[curMemberId]--;
}
// if new member exists, update map
if (newMember)
{
newMemberId = newMember.basisObjectId;
// call callback on member ref add
if (this.addMemberRef)
this.addMemberRef(newMember, sourceObject);
if (newMemberId in memberMap)
{
// member is already in map -> increase ref count
memberMap[newMemberId]++;
}
else
{
// add to map
memberMap[newMemberId] = 1;
// add to delta
inserted.push(newMember);
}
}
}
}
// get deleted delta
for (curMemberId in this.items_)
if (memberMap[curMemberId] == 0)
{
delete memberMap[curMemberId];
deleted.push(this.items_[curMemberId]);
}
// if any changes, fire event
if (delta = getDelta(inserted, deleted))
this.emit_itemsChanged(delta);
return delta;
}
|
[
"function",
"(",
")",
"{",
"var",
"sourceMap",
"=",
"this",
".",
"sourceMap_",
";",
"var",
"memberMap",
"=",
"this",
".",
"members_",
";",
"var",
"curMember",
";",
"var",
"newMember",
";",
"var",
"curMemberId",
";",
"var",
"newMemberId",
";",
"var",
"sourceObject",
";",
"var",
"sourceObjectInfo",
";",
"var",
"inserted",
"=",
"[",
"]",
";",
"var",
"deleted",
"=",
"[",
"]",
";",
"var",
"delta",
";",
"for",
"(",
"var",
"sourceObjectId",
"in",
"sourceMap",
")",
"{",
"sourceObjectInfo",
"=",
"sourceMap",
"[",
"sourceObjectId",
"]",
";",
"sourceObject",
"=",
"sourceObjectInfo",
".",
"sourceObject",
";",
"curMember",
"=",
"sourceObjectInfo",
".",
"member",
";",
"newMember",
"=",
"this",
".",
"map",
"?",
"this",
".",
"map",
"(",
"sourceObject",
")",
":",
"sourceObject",
";",
"if",
"(",
"newMember",
"instanceof",
"DataObject",
"==",
"false",
"||",
"this",
".",
"filter",
"(",
"newMember",
")",
")",
"newMember",
"=",
"null",
";",
"if",
"(",
"!",
"isEqual",
"(",
"curMember",
",",
"newMember",
")",
")",
"{",
"sourceObjectInfo",
".",
"member",
"=",
"newMember",
";",
"if",
"(",
"curMember",
")",
"{",
"curMemberId",
"=",
"curMember",
".",
"basisObjectId",
";",
"if",
"(",
"this",
".",
"removeMemberRef",
")",
"this",
".",
"removeMemberRef",
"(",
"curMember",
",",
"sourceObject",
")",
";",
"memberMap",
"[",
"curMemberId",
"]",
"--",
";",
"}",
"if",
"(",
"newMember",
")",
"{",
"newMemberId",
"=",
"newMember",
".",
"basisObjectId",
";",
"if",
"(",
"this",
".",
"addMemberRef",
")",
"this",
".",
"addMemberRef",
"(",
"newMember",
",",
"sourceObject",
")",
";",
"if",
"(",
"newMemberId",
"in",
"memberMap",
")",
"{",
"memberMap",
"[",
"newMemberId",
"]",
"++",
";",
"}",
"else",
"{",
"memberMap",
"[",
"newMemberId",
"]",
"=",
"1",
";",
"inserted",
".",
"push",
"(",
"newMember",
")",
";",
"}",
"}",
"}",
"}",
"for",
"(",
"curMemberId",
"in",
"this",
".",
"items_",
")",
"if",
"(",
"memberMap",
"[",
"curMemberId",
"]",
"==",
"0",
")",
"{",
"delete",
"memberMap",
"[",
"curMemberId",
"]",
";",
"deleted",
".",
"push",
"(",
"this",
".",
"items_",
"[",
"curMemberId",
"]",
")",
";",
"}",
"if",
"(",
"delta",
"=",
"getDelta",
"(",
"inserted",
",",
"deleted",
")",
")",
"this",
".",
"emit_itemsChanged",
"(",
"delta",
")",
";",
"return",
"delta",
";",
"}"
] |
Apply transform for all source objects and rebuild member set.
@return {Object} Delta of member changes.
|
[
"Apply",
"transform",
"for",
"all",
"source",
"objects",
"and",
"rebuild",
"member",
"set",
"."
] |
8571903014b207a09d45ad2d1bfba277bf21289b
|
https://github.com/basisjs/basisjs/blob/8571903014b207a09d45ad2d1bfba277bf21289b/src/basis/data/dataset/MapFilter.js#L300-L380
|
train
|
|
basisjs/basisjs
|
src/basis/data/dataset/Slice.js
|
function(offset, limit){
var oldOffset = this.offset;
var oldLimit = this.limit;
var delta = false;
if (oldOffset != offset || oldLimit != limit)
{
this.offset = offset;
this.limit = limit;
delta = this.applyRule();
this.emit_rangeChanged(oldOffset, oldLimit);
}
return delta;
}
|
javascript
|
function(offset, limit){
var oldOffset = this.offset;
var oldLimit = this.limit;
var delta = false;
if (oldOffset != offset || oldLimit != limit)
{
this.offset = offset;
this.limit = limit;
delta = this.applyRule();
this.emit_rangeChanged(oldOffset, oldLimit);
}
return delta;
}
|
[
"function",
"(",
"offset",
",",
"limit",
")",
"{",
"var",
"oldOffset",
"=",
"this",
".",
"offset",
";",
"var",
"oldLimit",
"=",
"this",
".",
"limit",
";",
"var",
"delta",
"=",
"false",
";",
"if",
"(",
"oldOffset",
"!=",
"offset",
"||",
"oldLimit",
"!=",
"limit",
")",
"{",
"this",
".",
"offset",
"=",
"offset",
";",
"this",
".",
"limit",
"=",
"limit",
";",
"delta",
"=",
"this",
".",
"applyRule",
"(",
")",
";",
"this",
".",
"emit_rangeChanged",
"(",
"oldOffset",
",",
"oldLimit",
")",
";",
"}",
"return",
"delta",
";",
"}"
] |
Set new range for dataset.
@param {number} offset Start of range.
@param {number} limit Length of range.
@return {object|boolean} Delta of member changes.
|
[
"Set",
"new",
"range",
"for",
"dataset",
"."
] |
8571903014b207a09d45ad2d1bfba277bf21289b
|
https://github.com/basisjs/basisjs/blob/8571903014b207a09d45ad2d1bfba277bf21289b/src/basis/data/dataset/Slice.js#L266-L282
|
train
|
|
basisjs/basisjs
|
src/basis/data/dataset/Slice.js
|
function(rule, orderDesc){
rule = basis.getter(rule || $true);
orderDesc = !!orderDesc;
if (this.rule != rule || this.orderDesc != orderDesc)
{
var oldRule = this.rule;
var oldOrderDesc = this.orderDesc;
// rebuild index only if rule changing
if (this.rule != rule)
{
var index = this.index_;
for (var i = 0; i < index.length; i++)
index[i].value = nanToUndefined(rule(index[i].object));
index.sort(sliceIndexSort);
this.rule = rule;
}
// set new values
this.orderDesc = orderDesc;
this.rule = rule;
this.emit_ruleChanged(oldRule, oldOrderDesc);
return this.applyRule();
}
}
|
javascript
|
function(rule, orderDesc){
rule = basis.getter(rule || $true);
orderDesc = !!orderDesc;
if (this.rule != rule || this.orderDesc != orderDesc)
{
var oldRule = this.rule;
var oldOrderDesc = this.orderDesc;
// rebuild index only if rule changing
if (this.rule != rule)
{
var index = this.index_;
for (var i = 0; i < index.length; i++)
index[i].value = nanToUndefined(rule(index[i].object));
index.sort(sliceIndexSort);
this.rule = rule;
}
// set new values
this.orderDesc = orderDesc;
this.rule = rule;
this.emit_ruleChanged(oldRule, oldOrderDesc);
return this.applyRule();
}
}
|
[
"function",
"(",
"rule",
",",
"orderDesc",
")",
"{",
"rule",
"=",
"basis",
".",
"getter",
"(",
"rule",
"||",
"$true",
")",
";",
"orderDesc",
"=",
"!",
"!",
"orderDesc",
";",
"if",
"(",
"this",
".",
"rule",
"!=",
"rule",
"||",
"this",
".",
"orderDesc",
"!=",
"orderDesc",
")",
"{",
"var",
"oldRule",
"=",
"this",
".",
"rule",
";",
"var",
"oldOrderDesc",
"=",
"this",
".",
"orderDesc",
";",
"if",
"(",
"this",
".",
"rule",
"!=",
"rule",
")",
"{",
"var",
"index",
"=",
"this",
".",
"index_",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"index",
".",
"length",
";",
"i",
"++",
")",
"index",
"[",
"i",
"]",
".",
"value",
"=",
"nanToUndefined",
"(",
"rule",
"(",
"index",
"[",
"i",
"]",
".",
"object",
")",
")",
";",
"index",
".",
"sort",
"(",
"sliceIndexSort",
")",
";",
"this",
".",
"rule",
"=",
"rule",
";",
"}",
"this",
".",
"orderDesc",
"=",
"orderDesc",
";",
"this",
".",
"rule",
"=",
"rule",
";",
"this",
".",
"emit_ruleChanged",
"(",
"oldRule",
",",
"oldOrderDesc",
")",
";",
"return",
"this",
".",
"applyRule",
"(",
")",
";",
"}",
"}"
] |
Set new rule and order.
@param {function(item:basis.data.Object):*|string} rule
@param {boolean} orderDesc
@return {object} Delta of member changes.
|
[
"Set",
"new",
"rule",
"and",
"order",
"."
] |
8571903014b207a09d45ad2d1bfba277bf21289b
|
https://github.com/basisjs/basisjs/blob/8571903014b207a09d45ad2d1bfba277bf21289b/src/basis/data/dataset/Slice.js#L308-L337
|
train
|
|
basisjs/basisjs
|
src/basis/data/dataset/Slice.js
|
function(){
var start = this.offset;
var end = start + this.limit;
if (this.orderDesc)
{
start = this.index_.length - end;
end = start + this.limit;
}
var curSet = objectSlice(this.members_);
var newSet = this.index_.slice(Math.max(0, start), Math.max(0, end));
var inserted = [];
var delta;
for (var i = 0, item; item = newSet[i]; i++)
{
var objectId = item.object.basisObjectId;
if (curSet[objectId])
delete curSet[objectId];
else
{
inserted.push(item.object);
this.members_[objectId] = item.object;
}
}
for (var objectId in curSet)
delete this.members_[objectId];
// update left tokens
if (this.left_)
for (var offset in this.left_)
{
var item = this.index_[this.orderDesc ? end + Number(offset) - 1 : start - Number(offset)];
this.left_[offset].set(item ? item.object : null);
}
// update right tokens
if (this.right_)
for (var offset in this.right_)
{
var item = this.index_[this.orderDesc ? start - Number(offset) : end + Number(offset) - 1];
this.right_[offset].set(item ? item.object : null);
}
// emit event if any delta
if (delta = getDelta(inserted, values(curSet)))
this.emit_itemsChanged(delta);
return delta;
}
|
javascript
|
function(){
var start = this.offset;
var end = start + this.limit;
if (this.orderDesc)
{
start = this.index_.length - end;
end = start + this.limit;
}
var curSet = objectSlice(this.members_);
var newSet = this.index_.slice(Math.max(0, start), Math.max(0, end));
var inserted = [];
var delta;
for (var i = 0, item; item = newSet[i]; i++)
{
var objectId = item.object.basisObjectId;
if (curSet[objectId])
delete curSet[objectId];
else
{
inserted.push(item.object);
this.members_[objectId] = item.object;
}
}
for (var objectId in curSet)
delete this.members_[objectId];
// update left tokens
if (this.left_)
for (var offset in this.left_)
{
var item = this.index_[this.orderDesc ? end + Number(offset) - 1 : start - Number(offset)];
this.left_[offset].set(item ? item.object : null);
}
// update right tokens
if (this.right_)
for (var offset in this.right_)
{
var item = this.index_[this.orderDesc ? start - Number(offset) : end + Number(offset) - 1];
this.right_[offset].set(item ? item.object : null);
}
// emit event if any delta
if (delta = getDelta(inserted, values(curSet)))
this.emit_itemsChanged(delta);
return delta;
}
|
[
"function",
"(",
")",
"{",
"var",
"start",
"=",
"this",
".",
"offset",
";",
"var",
"end",
"=",
"start",
"+",
"this",
".",
"limit",
";",
"if",
"(",
"this",
".",
"orderDesc",
")",
"{",
"start",
"=",
"this",
".",
"index_",
".",
"length",
"-",
"end",
";",
"end",
"=",
"start",
"+",
"this",
".",
"limit",
";",
"}",
"var",
"curSet",
"=",
"objectSlice",
"(",
"this",
".",
"members_",
")",
";",
"var",
"newSet",
"=",
"this",
".",
"index_",
".",
"slice",
"(",
"Math",
".",
"max",
"(",
"0",
",",
"start",
")",
",",
"Math",
".",
"max",
"(",
"0",
",",
"end",
")",
")",
";",
"var",
"inserted",
"=",
"[",
"]",
";",
"var",
"delta",
";",
"for",
"(",
"var",
"i",
"=",
"0",
",",
"item",
";",
"item",
"=",
"newSet",
"[",
"i",
"]",
";",
"i",
"++",
")",
"{",
"var",
"objectId",
"=",
"item",
".",
"object",
".",
"basisObjectId",
";",
"if",
"(",
"curSet",
"[",
"objectId",
"]",
")",
"delete",
"curSet",
"[",
"objectId",
"]",
";",
"else",
"{",
"inserted",
".",
"push",
"(",
"item",
".",
"object",
")",
";",
"this",
".",
"members_",
"[",
"objectId",
"]",
"=",
"item",
".",
"object",
";",
"}",
"}",
"for",
"(",
"var",
"objectId",
"in",
"curSet",
")",
"delete",
"this",
".",
"members_",
"[",
"objectId",
"]",
";",
"if",
"(",
"this",
".",
"left_",
")",
"for",
"(",
"var",
"offset",
"in",
"this",
".",
"left_",
")",
"{",
"var",
"item",
"=",
"this",
".",
"index_",
"[",
"this",
".",
"orderDesc",
"?",
"end",
"+",
"Number",
"(",
"offset",
")",
"-",
"1",
":",
"start",
"-",
"Number",
"(",
"offset",
")",
"]",
";",
"this",
".",
"left_",
"[",
"offset",
"]",
".",
"set",
"(",
"item",
"?",
"item",
".",
"object",
":",
"null",
")",
";",
"}",
"if",
"(",
"this",
".",
"right_",
")",
"for",
"(",
"var",
"offset",
"in",
"this",
".",
"right_",
")",
"{",
"var",
"item",
"=",
"this",
".",
"index_",
"[",
"this",
".",
"orderDesc",
"?",
"start",
"-",
"Number",
"(",
"offset",
")",
":",
"end",
"+",
"Number",
"(",
"offset",
")",
"-",
"1",
"]",
";",
"this",
".",
"right_",
"[",
"offset",
"]",
".",
"set",
"(",
"item",
"?",
"item",
".",
"object",
":",
"null",
")",
";",
"}",
"if",
"(",
"delta",
"=",
"getDelta",
"(",
"inserted",
",",
"values",
"(",
"curSet",
")",
")",
")",
"this",
".",
"emit_itemsChanged",
"(",
"delta",
")",
";",
"return",
"delta",
";",
"}"
] |
Recompute slice.
@return {Object} Delta of member changes.
|
[
"Recompute",
"slice",
"."
] |
8571903014b207a09d45ad2d1bfba277bf21289b
|
https://github.com/basisjs/basisjs/blob/8571903014b207a09d45ad2d1bfba277bf21289b/src/basis/data/dataset/Slice.js#L343-L395
|
train
|
|
basisjs/basisjs
|
src/basis/dom/wrapper.js
|
function(){
// this -> {
// owner: owner,
// name: satelliteName,
// config: satelliteConfig,
// instance: satelliteInstance or null,
// instanceRA_: ResolveAdapter or null,
// existsRA_: ResolveAdapter or null
// factoryType: 'value' or 'class'
// factory: class or any
// }
var name = this.name;
var config = this.config;
var owner = this.owner;
var exists = ('existsIf' in config == false) || config.existsIf(owner);
if (resolveValue(this, SATELLITE_UPDATE, exists, 'existsRA_'))
{
var satellite = this.instance || config.instance;
if (!satellite || this.factoryType == 'value')
{
if (!this.factoryType)
{
var instanceValue = config.getInstance;
var instanceClass = config.instanceClass;
if (typeof instanceValue == 'function')
{
instanceValue = instanceValue.call(owner, owner);
if (Class.isClass(instanceValue))
instanceClass = processInstanceClass(instanceValue);
}
this.factoryType = instanceClass ? 'class' : 'value';
this.factory = instanceClass || instanceValue;
}
if (this.factoryType == 'class')
{
var satelliteConfig = {
destroy: warnOnAutoSatelliteDestoy // auto-create satellite marker, lock destroy method invocation
};
if (config.delegate)
{
satelliteConfig.autoDelegate = false;
satelliteConfig.delegate = config.delegate(owner);
}
if (config.dataSource)
satelliteConfig.dataSource = config.dataSource(owner);
if (config.config)
basis.object.complete(satelliteConfig, typeof config.config == 'function'
? config.config(owner)
: config.config
);
this.instance = new this.factory(satelliteConfig);
owner.setSatellite(name, this.instance, true);
/** @cut */ var loc = basis.dev.getInfo(config, 'loc');
/** @cut */ if (loc)
/** @cut */ basis.dev.setInfo(this.instance, 'loc', loc);
return;
}
// factoryType == 'value'
satellite = resolveAbstractNode(this, SATELLITE_UPDATE, this.factory, 'instanceRA_');
}
if (this.instance !== satellite)
{
this.instance = satellite || null;
owner.setSatellite(name, this.instance, true);
}
if (satellite && satellite.owner === owner)
{
if (config.delegate)
satellite.setDelegate(config.delegate(owner));
if (config.dataSource)
satellite.setDataSource(config.dataSource(owner));
}
}
else
{
var satellite = this.instance;
if (satellite)
{
if (config.instance)
{
if (config.delegate)
satellite.setDelegate();
if (config.dataSource)
satellite.setDataSource();
}
this.instance = null;
owner.setSatellite(name, null, true);
}
}
}
|
javascript
|
function(){
// this -> {
// owner: owner,
// name: satelliteName,
// config: satelliteConfig,
// instance: satelliteInstance or null,
// instanceRA_: ResolveAdapter or null,
// existsRA_: ResolveAdapter or null
// factoryType: 'value' or 'class'
// factory: class or any
// }
var name = this.name;
var config = this.config;
var owner = this.owner;
var exists = ('existsIf' in config == false) || config.existsIf(owner);
if (resolveValue(this, SATELLITE_UPDATE, exists, 'existsRA_'))
{
var satellite = this.instance || config.instance;
if (!satellite || this.factoryType == 'value')
{
if (!this.factoryType)
{
var instanceValue = config.getInstance;
var instanceClass = config.instanceClass;
if (typeof instanceValue == 'function')
{
instanceValue = instanceValue.call(owner, owner);
if (Class.isClass(instanceValue))
instanceClass = processInstanceClass(instanceValue);
}
this.factoryType = instanceClass ? 'class' : 'value';
this.factory = instanceClass || instanceValue;
}
if (this.factoryType == 'class')
{
var satelliteConfig = {
destroy: warnOnAutoSatelliteDestoy // auto-create satellite marker, lock destroy method invocation
};
if (config.delegate)
{
satelliteConfig.autoDelegate = false;
satelliteConfig.delegate = config.delegate(owner);
}
if (config.dataSource)
satelliteConfig.dataSource = config.dataSource(owner);
if (config.config)
basis.object.complete(satelliteConfig, typeof config.config == 'function'
? config.config(owner)
: config.config
);
this.instance = new this.factory(satelliteConfig);
owner.setSatellite(name, this.instance, true);
/** @cut */ var loc = basis.dev.getInfo(config, 'loc');
/** @cut */ if (loc)
/** @cut */ basis.dev.setInfo(this.instance, 'loc', loc);
return;
}
// factoryType == 'value'
satellite = resolveAbstractNode(this, SATELLITE_UPDATE, this.factory, 'instanceRA_');
}
if (this.instance !== satellite)
{
this.instance = satellite || null;
owner.setSatellite(name, this.instance, true);
}
if (satellite && satellite.owner === owner)
{
if (config.delegate)
satellite.setDelegate(config.delegate(owner));
if (config.dataSource)
satellite.setDataSource(config.dataSource(owner));
}
}
else
{
var satellite = this.instance;
if (satellite)
{
if (config.instance)
{
if (config.delegate)
satellite.setDelegate();
if (config.dataSource)
satellite.setDataSource();
}
this.instance = null;
owner.setSatellite(name, null, true);
}
}
}
|
[
"function",
"(",
")",
"{",
"var",
"name",
"=",
"this",
".",
"name",
";",
"var",
"config",
"=",
"this",
".",
"config",
";",
"var",
"owner",
"=",
"this",
".",
"owner",
";",
"var",
"exists",
"=",
"(",
"'existsIf'",
"in",
"config",
"==",
"false",
")",
"||",
"config",
".",
"existsIf",
"(",
"owner",
")",
";",
"if",
"(",
"resolveValue",
"(",
"this",
",",
"SATELLITE_UPDATE",
",",
"exists",
",",
"'existsRA_'",
")",
")",
"{",
"var",
"satellite",
"=",
"this",
".",
"instance",
"||",
"config",
".",
"instance",
";",
"if",
"(",
"!",
"satellite",
"||",
"this",
".",
"factoryType",
"==",
"'value'",
")",
"{",
"if",
"(",
"!",
"this",
".",
"factoryType",
")",
"{",
"var",
"instanceValue",
"=",
"config",
".",
"getInstance",
";",
"var",
"instanceClass",
"=",
"config",
".",
"instanceClass",
";",
"if",
"(",
"typeof",
"instanceValue",
"==",
"'function'",
")",
"{",
"instanceValue",
"=",
"instanceValue",
".",
"call",
"(",
"owner",
",",
"owner",
")",
";",
"if",
"(",
"Class",
".",
"isClass",
"(",
"instanceValue",
")",
")",
"instanceClass",
"=",
"processInstanceClass",
"(",
"instanceValue",
")",
";",
"}",
"this",
".",
"factoryType",
"=",
"instanceClass",
"?",
"'class'",
":",
"'value'",
";",
"this",
".",
"factory",
"=",
"instanceClass",
"||",
"instanceValue",
";",
"}",
"if",
"(",
"this",
".",
"factoryType",
"==",
"'class'",
")",
"{",
"var",
"satelliteConfig",
"=",
"{",
"destroy",
":",
"warnOnAutoSatelliteDestoy",
"}",
";",
"if",
"(",
"config",
".",
"delegate",
")",
"{",
"satelliteConfig",
".",
"autoDelegate",
"=",
"false",
";",
"satelliteConfig",
".",
"delegate",
"=",
"config",
".",
"delegate",
"(",
"owner",
")",
";",
"}",
"if",
"(",
"config",
".",
"dataSource",
")",
"satelliteConfig",
".",
"dataSource",
"=",
"config",
".",
"dataSource",
"(",
"owner",
")",
";",
"if",
"(",
"config",
".",
"config",
")",
"basis",
".",
"object",
".",
"complete",
"(",
"satelliteConfig",
",",
"typeof",
"config",
".",
"config",
"==",
"'function'",
"?",
"config",
".",
"config",
"(",
"owner",
")",
":",
"config",
".",
"config",
")",
";",
"this",
".",
"instance",
"=",
"new",
"this",
".",
"factory",
"(",
"satelliteConfig",
")",
";",
"owner",
".",
"setSatellite",
"(",
"name",
",",
"this",
".",
"instance",
",",
"true",
")",
";",
"var",
"loc",
"=",
"basis",
".",
"dev",
".",
"getInfo",
"(",
"config",
",",
"'loc'",
")",
";",
"if",
"(",
"loc",
")",
"basis",
".",
"dev",
".",
"setInfo",
"(",
"this",
".",
"instance",
",",
"'loc'",
",",
"loc",
")",
";",
"return",
";",
"}",
"satellite",
"=",
"resolveAbstractNode",
"(",
"this",
",",
"SATELLITE_UPDATE",
",",
"this",
".",
"factory",
",",
"'instanceRA_'",
")",
";",
"}",
"if",
"(",
"this",
".",
"instance",
"!==",
"satellite",
")",
"{",
"this",
".",
"instance",
"=",
"satellite",
"||",
"null",
";",
"owner",
".",
"setSatellite",
"(",
"name",
",",
"this",
".",
"instance",
",",
"true",
")",
";",
"}",
"if",
"(",
"satellite",
"&&",
"satellite",
".",
"owner",
"===",
"owner",
")",
"{",
"if",
"(",
"config",
".",
"delegate",
")",
"satellite",
".",
"setDelegate",
"(",
"config",
".",
"delegate",
"(",
"owner",
")",
")",
";",
"if",
"(",
"config",
".",
"dataSource",
")",
"satellite",
".",
"setDataSource",
"(",
"config",
".",
"dataSource",
"(",
"owner",
")",
")",
";",
"}",
"}",
"else",
"{",
"var",
"satellite",
"=",
"this",
".",
"instance",
";",
"if",
"(",
"satellite",
")",
"{",
"if",
"(",
"config",
".",
"instance",
")",
"{",
"if",
"(",
"config",
".",
"delegate",
")",
"satellite",
".",
"setDelegate",
"(",
")",
";",
"if",
"(",
"config",
".",
"dataSource",
")",
"satellite",
".",
"setDataSource",
"(",
")",
";",
"}",
"this",
".",
"instance",
"=",
"null",
";",
"owner",
".",
"setSatellite",
"(",
"name",
",",
"null",
",",
"true",
")",
";",
"}",
"}",
"}"
] |
satellite update handler
|
[
"satellite",
"update",
"handler"
] |
8571903014b207a09d45ad2d1bfba277bf21289b
|
https://github.com/basisjs/basisjs/blob/8571903014b207a09d45ad2d1bfba277bf21289b/src/basis/dom/wrapper.js#L502-L609
|
train
|
|
basisjs/basisjs
|
src/basis/dom/wrapper.js
|
function(name, satellite, autoSet){
var oldSatellite = this.satellite[name] || null;
var auto = this.satellite[AUTO];
var autoConfig = auto && auto[name];
var preserveAuto = autoSet && autoConfig;
if (preserveAuto)
{
satellite = autoConfig.instance;
if (satellite && autoConfig.config.instance)
delete autoConfig.config.instance.setOwner;
}
else
{
satellite = processSatelliteConfig(satellite);
if (satellite && satellite.owner === this && auto && satellite.ownerSatelliteName && auto[satellite.ownerSatelliteName])
{
/** @cut */ basis.dev.warn(namespace + ': auto-create satellite can\'t change name inside owner');
return;
}
// if setSatellite was called not on auto-satellite update
if (autoConfig)
{
// remove old auto-config
delete auto[name];
if (autoConfig.config.instance)
autoConfig.config.instance.removeHandler(AUTO_SATELLITE_INSTANCE_HANDLER, autoConfig);
if (autoConfig.config.handler)
this.removeHandler(autoConfig.config.handler, autoConfig);
}
}
if (oldSatellite !== satellite)
{
var satelliteListen = this.listen.satellite;
var satellitePersonalListen = this.listen['satellite:' + name];
var destroySatellite;
if (oldSatellite)
{
// unlink old satellite
delete this.satellite[name];
var oldSatelliteName = oldSatellite.ownerSatelliteName;
if (oldSatelliteName != null)
{
oldSatellite.ownerSatelliteName = null;
oldSatellite.emit_ownerSatelliteNameChanged(oldSatelliteName);
}
if (autoConfig && oldSatellite.destroy === warnOnAutoSatelliteDestoy)
{
destroySatellite = oldSatellite;
}
else
{
// regular satellite
if (satelliteListen)
oldSatellite.removeHandler(satelliteListen, this);
if (satellitePersonalListen)
oldSatellite.removeHandler(satellitePersonalListen, this);
oldSatellite.setOwner(null);
}
if (preserveAuto && !satellite && autoConfig.config.instance)
autoConfig.config.instance.setOwner = warnOnAutoSatelliteOwnerChange;
}
if (satellite)
{
// check value is auto-config
if (satellite instanceof AbstractNode == false)
{
// auto-create satellite
var autoConfig = {
owner: this,
name: name,
config: satellite,
factoryType: null,
factory: null,
instance: null,
instanceRA_: null,
existsRA_: null
};
// auto-create satellite
if (satellite.handler)
this.addHandler(satellite.handler, autoConfig);
if (satellite.instance)
{
satellite.instance.addHandler(AUTO_SATELLITE_INSTANCE_HANDLER, autoConfig);
satellite.instance.setOwner = warnOnAutoSatelliteOwnerChange;
}
// create auto
if (!auto)
{
if (this.satellite === NULL_SATELLITE)
this.satellite = {};
auto = this.satellite[AUTO] = {};
}
auto[name] = autoConfig;
SATELLITE_UPDATE.call(autoConfig, this);
if (!autoConfig.instance && oldSatellite)
this.emit_satelliteChanged(name, oldSatellite);
if (destroySatellite)
{
// auto create satellite must be destroyed
delete destroySatellite.destroy;
destroySatellite.destroy();
}
return;
}
// link new satellite
if (satellite.owner !== this)
{
if (autoConfig && autoConfig.config.delegate)
{
// ignore autoDelegate if satellite is auto-satellite and config has delegate setting
var autoDelegate = satellite.autoDelegate;
satellite.autoDelegate = false;
satellite.setOwner(this);
satellite.autoDelegate = autoDelegate;
}
else
satellite.setOwner(this);
// reset satellite if owner was not set
if (satellite.owner !== this)
{
this.setSatellite(name, null);
return;
}
if (satelliteListen)
satellite.addHandler(satelliteListen, this);
if (satellitePersonalListen)
satellite.addHandler(satellitePersonalListen, this);
}
else
{
// move satellite inside owner
if (satellite.ownerSatelliteName)
{
delete this.satellite[satellite.ownerSatelliteName];
this.emit_satelliteChanged(satellite.ownerSatelliteName, satellite);
}
}
if (this.satellite == NULL_SATELLITE)
this.satellite = {};
this.satellite[name] = satellite;
var oldSatelliteName = satellite.ownerSatelliteName;
if (oldSatelliteName != name)
{
satellite.ownerSatelliteName = name;
satellite.emit_ownerSatelliteNameChanged(oldSatelliteName);
}
}
this.emit_satelliteChanged(name, oldSatellite);
if (destroySatellite)
{
// auto create satellite must be destroyed
delete destroySatellite.destroy;
destroySatellite.destroy();
}
}
}
|
javascript
|
function(name, satellite, autoSet){
var oldSatellite = this.satellite[name] || null;
var auto = this.satellite[AUTO];
var autoConfig = auto && auto[name];
var preserveAuto = autoSet && autoConfig;
if (preserveAuto)
{
satellite = autoConfig.instance;
if (satellite && autoConfig.config.instance)
delete autoConfig.config.instance.setOwner;
}
else
{
satellite = processSatelliteConfig(satellite);
if (satellite && satellite.owner === this && auto && satellite.ownerSatelliteName && auto[satellite.ownerSatelliteName])
{
/** @cut */ basis.dev.warn(namespace + ': auto-create satellite can\'t change name inside owner');
return;
}
// if setSatellite was called not on auto-satellite update
if (autoConfig)
{
// remove old auto-config
delete auto[name];
if (autoConfig.config.instance)
autoConfig.config.instance.removeHandler(AUTO_SATELLITE_INSTANCE_HANDLER, autoConfig);
if (autoConfig.config.handler)
this.removeHandler(autoConfig.config.handler, autoConfig);
}
}
if (oldSatellite !== satellite)
{
var satelliteListen = this.listen.satellite;
var satellitePersonalListen = this.listen['satellite:' + name];
var destroySatellite;
if (oldSatellite)
{
// unlink old satellite
delete this.satellite[name];
var oldSatelliteName = oldSatellite.ownerSatelliteName;
if (oldSatelliteName != null)
{
oldSatellite.ownerSatelliteName = null;
oldSatellite.emit_ownerSatelliteNameChanged(oldSatelliteName);
}
if (autoConfig && oldSatellite.destroy === warnOnAutoSatelliteDestoy)
{
destroySatellite = oldSatellite;
}
else
{
// regular satellite
if (satelliteListen)
oldSatellite.removeHandler(satelliteListen, this);
if (satellitePersonalListen)
oldSatellite.removeHandler(satellitePersonalListen, this);
oldSatellite.setOwner(null);
}
if (preserveAuto && !satellite && autoConfig.config.instance)
autoConfig.config.instance.setOwner = warnOnAutoSatelliteOwnerChange;
}
if (satellite)
{
// check value is auto-config
if (satellite instanceof AbstractNode == false)
{
// auto-create satellite
var autoConfig = {
owner: this,
name: name,
config: satellite,
factoryType: null,
factory: null,
instance: null,
instanceRA_: null,
existsRA_: null
};
// auto-create satellite
if (satellite.handler)
this.addHandler(satellite.handler, autoConfig);
if (satellite.instance)
{
satellite.instance.addHandler(AUTO_SATELLITE_INSTANCE_HANDLER, autoConfig);
satellite.instance.setOwner = warnOnAutoSatelliteOwnerChange;
}
// create auto
if (!auto)
{
if (this.satellite === NULL_SATELLITE)
this.satellite = {};
auto = this.satellite[AUTO] = {};
}
auto[name] = autoConfig;
SATELLITE_UPDATE.call(autoConfig, this);
if (!autoConfig.instance && oldSatellite)
this.emit_satelliteChanged(name, oldSatellite);
if (destroySatellite)
{
// auto create satellite must be destroyed
delete destroySatellite.destroy;
destroySatellite.destroy();
}
return;
}
// link new satellite
if (satellite.owner !== this)
{
if (autoConfig && autoConfig.config.delegate)
{
// ignore autoDelegate if satellite is auto-satellite and config has delegate setting
var autoDelegate = satellite.autoDelegate;
satellite.autoDelegate = false;
satellite.setOwner(this);
satellite.autoDelegate = autoDelegate;
}
else
satellite.setOwner(this);
// reset satellite if owner was not set
if (satellite.owner !== this)
{
this.setSatellite(name, null);
return;
}
if (satelliteListen)
satellite.addHandler(satelliteListen, this);
if (satellitePersonalListen)
satellite.addHandler(satellitePersonalListen, this);
}
else
{
// move satellite inside owner
if (satellite.ownerSatelliteName)
{
delete this.satellite[satellite.ownerSatelliteName];
this.emit_satelliteChanged(satellite.ownerSatelliteName, satellite);
}
}
if (this.satellite == NULL_SATELLITE)
this.satellite = {};
this.satellite[name] = satellite;
var oldSatelliteName = satellite.ownerSatelliteName;
if (oldSatelliteName != name)
{
satellite.ownerSatelliteName = name;
satellite.emit_ownerSatelliteNameChanged(oldSatelliteName);
}
}
this.emit_satelliteChanged(name, oldSatellite);
if (destroySatellite)
{
// auto create satellite must be destroyed
delete destroySatellite.destroy;
destroySatellite.destroy();
}
}
}
|
[
"function",
"(",
"name",
",",
"satellite",
",",
"autoSet",
")",
"{",
"var",
"oldSatellite",
"=",
"this",
".",
"satellite",
"[",
"name",
"]",
"||",
"null",
";",
"var",
"auto",
"=",
"this",
".",
"satellite",
"[",
"AUTO",
"]",
";",
"var",
"autoConfig",
"=",
"auto",
"&&",
"auto",
"[",
"name",
"]",
";",
"var",
"preserveAuto",
"=",
"autoSet",
"&&",
"autoConfig",
";",
"if",
"(",
"preserveAuto",
")",
"{",
"satellite",
"=",
"autoConfig",
".",
"instance",
";",
"if",
"(",
"satellite",
"&&",
"autoConfig",
".",
"config",
".",
"instance",
")",
"delete",
"autoConfig",
".",
"config",
".",
"instance",
".",
"setOwner",
";",
"}",
"else",
"{",
"satellite",
"=",
"processSatelliteConfig",
"(",
"satellite",
")",
";",
"if",
"(",
"satellite",
"&&",
"satellite",
".",
"owner",
"===",
"this",
"&&",
"auto",
"&&",
"satellite",
".",
"ownerSatelliteName",
"&&",
"auto",
"[",
"satellite",
".",
"ownerSatelliteName",
"]",
")",
"{",
"basis",
".",
"dev",
".",
"warn",
"(",
"namespace",
"+",
"': auto-create satellite can\\'t change name inside owner'",
")",
";",
"\\'",
"}",
"return",
";",
"}",
"if",
"(",
"autoConfig",
")",
"{",
"delete",
"auto",
"[",
"name",
"]",
";",
"if",
"(",
"autoConfig",
".",
"config",
".",
"instance",
")",
"autoConfig",
".",
"config",
".",
"instance",
".",
"removeHandler",
"(",
"AUTO_SATELLITE_INSTANCE_HANDLER",
",",
"autoConfig",
")",
";",
"if",
"(",
"autoConfig",
".",
"config",
".",
"handler",
")",
"this",
".",
"removeHandler",
"(",
"autoConfig",
".",
"config",
".",
"handler",
",",
"autoConfig",
")",
";",
"}",
"}"
] |
Set replace satellite with defined name for new one.
@param {string} name Satellite name.
@param {basis.data.Object} satellite New satellite node.
@param {boolean} autoSet Method invoked by auto-create
|
[
"Set",
"replace",
"satellite",
"with",
"defined",
"name",
"for",
"new",
"one",
"."
] |
8571903014b207a09d45ad2d1bfba277bf21289b
|
https://github.com/basisjs/basisjs/blob/8571903014b207a09d45ad2d1bfba277bf21289b/src/basis/dom/wrapper.js#L1136-L1316
|
train
|
|
basisjs/basisjs
|
src/basis/dom/wrapper.js
|
function(newNode, refNode){
var nodes = this.nodes;
var pos = refNode ? nodes.indexOf(refNode) : -1;
if (pos == -1)
{
nodes.push(newNode);
this.last = newNode;
}
else
nodes.splice(pos, 0, newNode);
this.first = nodes[0];
newNode.groupNode = this;
this.emit_childNodesModified({ inserted: [newNode] });
}
|
javascript
|
function(newNode, refNode){
var nodes = this.nodes;
var pos = refNode ? nodes.indexOf(refNode) : -1;
if (pos == -1)
{
nodes.push(newNode);
this.last = newNode;
}
else
nodes.splice(pos, 0, newNode);
this.first = nodes[0];
newNode.groupNode = this;
this.emit_childNodesModified({ inserted: [newNode] });
}
|
[
"function",
"(",
"newNode",
",",
"refNode",
")",
"{",
"var",
"nodes",
"=",
"this",
".",
"nodes",
";",
"var",
"pos",
"=",
"refNode",
"?",
"nodes",
".",
"indexOf",
"(",
"refNode",
")",
":",
"-",
"1",
";",
"if",
"(",
"pos",
"==",
"-",
"1",
")",
"{",
"nodes",
".",
"push",
"(",
"newNode",
")",
";",
"this",
".",
"last",
"=",
"newNode",
";",
"}",
"else",
"nodes",
".",
"splice",
"(",
"pos",
",",
"0",
",",
"newNode",
")",
";",
"this",
".",
"first",
"=",
"nodes",
"[",
"0",
"]",
";",
"newNode",
".",
"groupNode",
"=",
"this",
";",
"this",
".",
"emit_childNodesModified",
"(",
"{",
"inserted",
":",
"[",
"newNode",
"]",
"}",
")",
";",
"}"
] |
Works like insertBefore, but don't update newNode references.
@param {basis.dom.wrapper.AbstractNode} newNode
@param {basis.dom.wrapper.AbstractNode} refNode
|
[
"Works",
"like",
"insertBefore",
"but",
"don",
"t",
"update",
"newNode",
"references",
"."
] |
8571903014b207a09d45ad2d1bfba277bf21289b
|
https://github.com/basisjs/basisjs/blob/8571903014b207a09d45ad2d1bfba277bf21289b/src/basis/dom/wrapper.js#L1463-L1480
|
train
|
|
basisjs/basisjs
|
src/basis/dom/wrapper.js
|
function(oldNode){
var nodes = this.nodes;
if (arrayRemove(nodes, oldNode))
{
this.first = nodes[0] || null;
this.last = nodes[nodes.length - 1] || null;
oldNode.groupNode = null;
this.emit_childNodesModified({ deleted: [oldNode] });
}
if (!this.first && this.autoDestroyIfEmpty)
this.destroy();
}
|
javascript
|
function(oldNode){
var nodes = this.nodes;
if (arrayRemove(nodes, oldNode))
{
this.first = nodes[0] || null;
this.last = nodes[nodes.length - 1] || null;
oldNode.groupNode = null;
this.emit_childNodesModified({ deleted: [oldNode] });
}
if (!this.first && this.autoDestroyIfEmpty)
this.destroy();
}
|
[
"function",
"(",
"oldNode",
")",
"{",
"var",
"nodes",
"=",
"this",
".",
"nodes",
";",
"if",
"(",
"arrayRemove",
"(",
"nodes",
",",
"oldNode",
")",
")",
"{",
"this",
".",
"first",
"=",
"nodes",
"[",
"0",
"]",
"||",
"null",
";",
"this",
".",
"last",
"=",
"nodes",
"[",
"nodes",
".",
"length",
"-",
"1",
"]",
"||",
"null",
";",
"oldNode",
".",
"groupNode",
"=",
"null",
";",
"this",
".",
"emit_childNodesModified",
"(",
"{",
"deleted",
":",
"[",
"oldNode",
"]",
"}",
")",
";",
"}",
"if",
"(",
"!",
"this",
".",
"first",
"&&",
"this",
".",
"autoDestroyIfEmpty",
")",
"this",
".",
"destroy",
"(",
")",
";",
"}"
] |
Works like removeChild, but don't update oldNode references.
@param {basis.dom.wrapper.AbstractNode} oldNode
|
[
"Works",
"like",
"removeChild",
"but",
"don",
"t",
"update",
"oldNode",
"references",
"."
] |
8571903014b207a09d45ad2d1bfba277bf21289b
|
https://github.com/basisjs/basisjs/blob/8571903014b207a09d45ad2d1bfba277bf21289b/src/basis/dom/wrapper.js#L1486-L1499
|
train
|
|
basisjs/basisjs
|
src/basis/dom/wrapper.js
|
function(matchFunction){
if (this.matchFunction != matchFunction)
{
var oldMatchFunction = this.matchFunction;
this.matchFunction = matchFunction;
for (var node = this.lastChild; node; node = node.previousSibling)
node.match(matchFunction);
this.emit_matchFunctionChanged(oldMatchFunction);
}
}
|
javascript
|
function(matchFunction){
if (this.matchFunction != matchFunction)
{
var oldMatchFunction = this.matchFunction;
this.matchFunction = matchFunction;
for (var node = this.lastChild; node; node = node.previousSibling)
node.match(matchFunction);
this.emit_matchFunctionChanged(oldMatchFunction);
}
}
|
[
"function",
"(",
"matchFunction",
")",
"{",
"if",
"(",
"this",
".",
"matchFunction",
"!=",
"matchFunction",
")",
"{",
"var",
"oldMatchFunction",
"=",
"this",
".",
"matchFunction",
";",
"this",
".",
"matchFunction",
"=",
"matchFunction",
";",
"for",
"(",
"var",
"node",
"=",
"this",
".",
"lastChild",
";",
"node",
";",
"node",
"=",
"node",
".",
"previousSibling",
")",
"node",
".",
"match",
"(",
"matchFunction",
")",
";",
"this",
".",
"emit_matchFunctionChanged",
"(",
"oldMatchFunction",
")",
";",
"}",
"}"
] |
Set match function for child nodes.
@param {function(node):boolean} matchFunction
|
[
"Set",
"match",
"function",
"for",
"child",
"nodes",
"."
] |
8571903014b207a09d45ad2d1bfba277bf21289b
|
https://github.com/basisjs/basisjs/blob/8571903014b207a09d45ad2d1bfba277bf21289b/src/basis/dom/wrapper.js#L2539-L2550
|
train
|
|
basisjs/basisjs
|
src/basis/dom/wrapper.js
|
function(selection, silent){
var oldSelection = this.selection;
if (selection instanceof Selection === false)
selection = selection ? new Selection(selection) : null;
if (oldSelection !== selection)
{
// change context selection for child nodes
updateNodeContextSelection(this, oldSelection || this.contextSelection, selection || this.contextSelection, false, true);
if (this.listen.selection)
{
if (oldSelection)
oldSelection.removeHandler(this.listen.selection, this);
if (selection)
selection.addHandler(this.listen.selection, this);
}
// update selection
this.selection = selection;
if (!silent)
this.emit_selectionChanged(oldSelection);
return true;
}
}
|
javascript
|
function(selection, silent){
var oldSelection = this.selection;
if (selection instanceof Selection === false)
selection = selection ? new Selection(selection) : null;
if (oldSelection !== selection)
{
// change context selection for child nodes
updateNodeContextSelection(this, oldSelection || this.contextSelection, selection || this.contextSelection, false, true);
if (this.listen.selection)
{
if (oldSelection)
oldSelection.removeHandler(this.listen.selection, this);
if (selection)
selection.addHandler(this.listen.selection, this);
}
// update selection
this.selection = selection;
if (!silent)
this.emit_selectionChanged(oldSelection);
return true;
}
}
|
[
"function",
"(",
"selection",
",",
"silent",
")",
"{",
"var",
"oldSelection",
"=",
"this",
".",
"selection",
";",
"if",
"(",
"selection",
"instanceof",
"Selection",
"===",
"false",
")",
"selection",
"=",
"selection",
"?",
"new",
"Selection",
"(",
"selection",
")",
":",
"null",
";",
"if",
"(",
"oldSelection",
"!==",
"selection",
")",
"{",
"updateNodeContextSelection",
"(",
"this",
",",
"oldSelection",
"||",
"this",
".",
"contextSelection",
",",
"selection",
"||",
"this",
".",
"contextSelection",
",",
"false",
",",
"true",
")",
";",
"if",
"(",
"this",
".",
"listen",
".",
"selection",
")",
"{",
"if",
"(",
"oldSelection",
")",
"oldSelection",
".",
"removeHandler",
"(",
"this",
".",
"listen",
".",
"selection",
",",
"this",
")",
";",
"if",
"(",
"selection",
")",
"selection",
".",
"addHandler",
"(",
"this",
".",
"listen",
".",
"selection",
",",
"this",
")",
";",
"}",
"this",
".",
"selection",
"=",
"selection",
";",
"if",
"(",
"!",
"silent",
")",
"this",
".",
"emit_selectionChanged",
"(",
"oldSelection",
")",
";",
"return",
"true",
";",
"}",
"}"
] |
Changes selection property of node.
@param {basis.dom.wrapper.Selection=} selection New selection value for node.
@return {boolean} Returns true if selection was changed.
|
[
"Changes",
"selection",
"property",
"of",
"node",
"."
] |
8571903014b207a09d45ad2d1bfba277bf21289b
|
https://github.com/basisjs/basisjs/blob/8571903014b207a09d45ad2d1bfba277bf21289b/src/basis/dom/wrapper.js#L2754-L2780
|
train
|
|
basisjs/basisjs
|
src/basis/dom/wrapper.js
|
function(selected, multiple){
var selection = this.contextSelection;
selected = !!resolveValue(this, this.setSelected, selected, 'selectedRA_');
// special case, when node selected and has selection context check only
// resolve adapter influence on selected if exists, and restore selection
// influence when no resolve adapter
if (this.selected && selection)
{
if (this.selectedRA_)
{
if (selection.has(this))
{
this.selected = false;
selection.remove(this);
this.selected = true;
}
}
else
{
if (!selection.has(this))
selection.add(this);
}
}
if (selected !== this.selected)
{
if (this.selectedRA_) // when resolveValue using ignore selection
{
this.selected = selected;
if (selected)
this.emit_select();
else
this.emit_unselect();
}
else
{
if (selected) // this.selected = false -> true
{
if (selection)
{
if (multiple)
selection.add(this);
else
selection.set(this);
}
else
{
this.selected = true;
this.emit_select();
}
}
else // this.selected = true -> false
{
if (selection)
{
selection.remove(this);
}
else
{
this.selected = false;
this.emit_unselect();
}
}
}
return true;
}
else
{
if (!this.selectedRA_ && selected && selection) // this.selected = true -> true
{
if (multiple)
selection.remove(this);
else
selection.set(this);
}
}
return false;
}
|
javascript
|
function(selected, multiple){
var selection = this.contextSelection;
selected = !!resolveValue(this, this.setSelected, selected, 'selectedRA_');
// special case, when node selected and has selection context check only
// resolve adapter influence on selected if exists, and restore selection
// influence when no resolve adapter
if (this.selected && selection)
{
if (this.selectedRA_)
{
if (selection.has(this))
{
this.selected = false;
selection.remove(this);
this.selected = true;
}
}
else
{
if (!selection.has(this))
selection.add(this);
}
}
if (selected !== this.selected)
{
if (this.selectedRA_) // when resolveValue using ignore selection
{
this.selected = selected;
if (selected)
this.emit_select();
else
this.emit_unselect();
}
else
{
if (selected) // this.selected = false -> true
{
if (selection)
{
if (multiple)
selection.add(this);
else
selection.set(this);
}
else
{
this.selected = true;
this.emit_select();
}
}
else // this.selected = true -> false
{
if (selection)
{
selection.remove(this);
}
else
{
this.selected = false;
this.emit_unselect();
}
}
}
return true;
}
else
{
if (!this.selectedRA_ && selected && selection) // this.selected = true -> true
{
if (multiple)
selection.remove(this);
else
selection.set(this);
}
}
return false;
}
|
[
"function",
"(",
"selected",
",",
"multiple",
")",
"{",
"var",
"selection",
"=",
"this",
".",
"contextSelection",
";",
"selected",
"=",
"!",
"!",
"resolveValue",
"(",
"this",
",",
"this",
".",
"setSelected",
",",
"selected",
",",
"'selectedRA_'",
")",
";",
"if",
"(",
"this",
".",
"selected",
"&&",
"selection",
")",
"{",
"if",
"(",
"this",
".",
"selectedRA_",
")",
"{",
"if",
"(",
"selection",
".",
"has",
"(",
"this",
")",
")",
"{",
"this",
".",
"selected",
"=",
"false",
";",
"selection",
".",
"remove",
"(",
"this",
")",
";",
"this",
".",
"selected",
"=",
"true",
";",
"}",
"}",
"else",
"{",
"if",
"(",
"!",
"selection",
".",
"has",
"(",
"this",
")",
")",
"selection",
".",
"add",
"(",
"this",
")",
";",
"}",
"}",
"if",
"(",
"selected",
"!==",
"this",
".",
"selected",
")",
"{",
"if",
"(",
"this",
".",
"selectedRA_",
")",
"{",
"this",
".",
"selected",
"=",
"selected",
";",
"if",
"(",
"selected",
")",
"this",
".",
"emit_select",
"(",
")",
";",
"else",
"this",
".",
"emit_unselect",
"(",
")",
";",
"}",
"else",
"{",
"if",
"(",
"selected",
")",
"{",
"if",
"(",
"selection",
")",
"{",
"if",
"(",
"multiple",
")",
"selection",
".",
"add",
"(",
"this",
")",
";",
"else",
"selection",
".",
"set",
"(",
"this",
")",
";",
"}",
"else",
"{",
"this",
".",
"selected",
"=",
"true",
";",
"this",
".",
"emit_select",
"(",
")",
";",
"}",
"}",
"else",
"{",
"if",
"(",
"selection",
")",
"{",
"selection",
".",
"remove",
"(",
"this",
")",
";",
"}",
"else",
"{",
"this",
".",
"selected",
"=",
"false",
";",
"this",
".",
"emit_unselect",
"(",
")",
";",
"}",
"}",
"}",
"return",
"true",
";",
"}",
"else",
"{",
"if",
"(",
"!",
"this",
".",
"selectedRA_",
"&&",
"selected",
"&&",
"selection",
")",
"{",
"if",
"(",
"multiple",
")",
"selection",
".",
"remove",
"(",
"this",
")",
";",
"else",
"selection",
".",
"set",
"(",
"this",
")",
";",
"}",
"}",
"return",
"false",
";",
"}"
] |
Set new value for selected property.
@param {boolean} selected Should be node selected or not.
@param {boolean} multiple Apply new state in multiple select mode or not.
@return {boolean} Returns true if selected property was changed.
|
[
"Set",
"new",
"value",
"for",
"selected",
"property",
"."
] |
8571903014b207a09d45ad2d1bfba277bf21289b
|
https://github.com/basisjs/basisjs/blob/8571903014b207a09d45ad2d1bfba277bf21289b/src/basis/dom/wrapper.js#L2788-L2869
|
train
|
|
basisjs/basisjs
|
src/basis/dom/wrapper.js
|
function(disabled){
disabled = !!resolveValue(this, this.setDisabled, disabled, 'disabledRA_');
if (this.disabled !== disabled)
{
this.disabled = disabled;
if (!this.contextDisabled)
if (disabled)
this.emit_disable();
else
this.emit_enable();
return true;
}
return false;
}
|
javascript
|
function(disabled){
disabled = !!resolveValue(this, this.setDisabled, disabled, 'disabledRA_');
if (this.disabled !== disabled)
{
this.disabled = disabled;
if (!this.contextDisabled)
if (disabled)
this.emit_disable();
else
this.emit_enable();
return true;
}
return false;
}
|
[
"function",
"(",
"disabled",
")",
"{",
"disabled",
"=",
"!",
"!",
"resolveValue",
"(",
"this",
",",
"this",
".",
"setDisabled",
",",
"disabled",
",",
"'disabledRA_'",
")",
";",
"if",
"(",
"this",
".",
"disabled",
"!==",
"disabled",
")",
"{",
"this",
".",
"disabled",
"=",
"disabled",
";",
"if",
"(",
"!",
"this",
".",
"contextDisabled",
")",
"if",
"(",
"disabled",
")",
"this",
".",
"emit_disable",
"(",
")",
";",
"else",
"this",
".",
"emit_enable",
"(",
")",
";",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
] |
Set new value for disabled property.
@param {boolean} disabled Should be node disabled or not.
@return {boolean} Returns true if disabled property was changed.
|
[
"Set",
"new",
"value",
"for",
"disabled",
"property",
"."
] |
8571903014b207a09d45ad2d1bfba277bf21289b
|
https://github.com/basisjs/basisjs/blob/8571903014b207a09d45ad2d1bfba277bf21289b/src/basis/dom/wrapper.js#L2905-L2922
|
train
|
|
basisjs/basisjs
|
src/basis/data/AbstractData.js
|
function(isActive){
var proxyToken = this.activeRA_ && this.activeRA_.proxyToken;
if (isActive === PROXY)
{
if (!proxyToken)
{
proxyToken = new basis.Token(this.subscriberCount > 0);
this.addHandler(ABSTRACTDATA_ACTIVE_SYNC_HANDLER, proxyToken);
}
isActive = proxyToken;
}
else
{
if (proxyToken && isActive !== proxyToken)
{
this.removeHandler(ABSTRACTDATA_ACTIVE_SYNC_HANDLER, proxyToken);
proxyToken = null;
}
}
isActive = !!resolveValue(this, this.setActive, isActive, 'activeRA_');
if (proxyToken && this.activeRA_)
this.activeRA_.proxyToken = proxyToken;
if (this.active != isActive)
{
this.active = isActive;
this.emit_activeChanged();
if (isActive)
SUBSCRIPTION.subscribe(this, this.subscribeTo);
else
SUBSCRIPTION.unsubscribe(this, this.subscribeTo);
return true;
}
return false;
}
|
javascript
|
function(isActive){
var proxyToken = this.activeRA_ && this.activeRA_.proxyToken;
if (isActive === PROXY)
{
if (!proxyToken)
{
proxyToken = new basis.Token(this.subscriberCount > 0);
this.addHandler(ABSTRACTDATA_ACTIVE_SYNC_HANDLER, proxyToken);
}
isActive = proxyToken;
}
else
{
if (proxyToken && isActive !== proxyToken)
{
this.removeHandler(ABSTRACTDATA_ACTIVE_SYNC_HANDLER, proxyToken);
proxyToken = null;
}
}
isActive = !!resolveValue(this, this.setActive, isActive, 'activeRA_');
if (proxyToken && this.activeRA_)
this.activeRA_.proxyToken = proxyToken;
if (this.active != isActive)
{
this.active = isActive;
this.emit_activeChanged();
if (isActive)
SUBSCRIPTION.subscribe(this, this.subscribeTo);
else
SUBSCRIPTION.unsubscribe(this, this.subscribeTo);
return true;
}
return false;
}
|
[
"function",
"(",
"isActive",
")",
"{",
"var",
"proxyToken",
"=",
"this",
".",
"activeRA_",
"&&",
"this",
".",
"activeRA_",
".",
"proxyToken",
";",
"if",
"(",
"isActive",
"===",
"PROXY",
")",
"{",
"if",
"(",
"!",
"proxyToken",
")",
"{",
"proxyToken",
"=",
"new",
"basis",
".",
"Token",
"(",
"this",
".",
"subscriberCount",
">",
"0",
")",
";",
"this",
".",
"addHandler",
"(",
"ABSTRACTDATA_ACTIVE_SYNC_HANDLER",
",",
"proxyToken",
")",
";",
"}",
"isActive",
"=",
"proxyToken",
";",
"}",
"else",
"{",
"if",
"(",
"proxyToken",
"&&",
"isActive",
"!==",
"proxyToken",
")",
"{",
"this",
".",
"removeHandler",
"(",
"ABSTRACTDATA_ACTIVE_SYNC_HANDLER",
",",
"proxyToken",
")",
";",
"proxyToken",
"=",
"null",
";",
"}",
"}",
"isActive",
"=",
"!",
"!",
"resolveValue",
"(",
"this",
",",
"this",
".",
"setActive",
",",
"isActive",
",",
"'activeRA_'",
")",
";",
"if",
"(",
"proxyToken",
"&&",
"this",
".",
"activeRA_",
")",
"this",
".",
"activeRA_",
".",
"proxyToken",
"=",
"proxyToken",
";",
"if",
"(",
"this",
".",
"active",
"!=",
"isActive",
")",
"{",
"this",
".",
"active",
"=",
"isActive",
";",
"this",
".",
"emit_activeChanged",
"(",
")",
";",
"if",
"(",
"isActive",
")",
"SUBSCRIPTION",
".",
"subscribe",
"(",
"this",
",",
"this",
".",
"subscribeTo",
")",
";",
"else",
"SUBSCRIPTION",
".",
"unsubscribe",
"(",
"this",
",",
"this",
".",
"subscribeTo",
")",
";",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
] |
Set new value for isActiveSubscriber property.
@param {boolean} isActive New value for {basis.data.Object#active} property.
@return {boolean} Returns true if {basis.data.Object#active} was changed.
|
[
"Set",
"new",
"value",
"for",
"isActiveSubscriber",
"property",
"."
] |
8571903014b207a09d45ad2d1bfba277bf21289b
|
https://github.com/basisjs/basisjs/blob/8571903014b207a09d45ad2d1bfba277bf21289b/src/basis/data/AbstractData.js#L235-L276
|
train
|
|
basisjs/basisjs
|
src/basis/data/AbstractData.js
|
function(subscriptionType){
var curSubscriptionType = this.subscribeTo;
var newSubscriptionType = subscriptionType & SUBSCRIPTION.ALL;
var delta = curSubscriptionType ^ newSubscriptionType;
if (delta)
{
this.subscribeTo = newSubscriptionType;
if (this.active)
SUBSCRIPTION.changeSubscription(this, curSubscriptionType, newSubscriptionType);
return true;
}
return false;
}
|
javascript
|
function(subscriptionType){
var curSubscriptionType = this.subscribeTo;
var newSubscriptionType = subscriptionType & SUBSCRIPTION.ALL;
var delta = curSubscriptionType ^ newSubscriptionType;
if (delta)
{
this.subscribeTo = newSubscriptionType;
if (this.active)
SUBSCRIPTION.changeSubscription(this, curSubscriptionType, newSubscriptionType);
return true;
}
return false;
}
|
[
"function",
"(",
"subscriptionType",
")",
"{",
"var",
"curSubscriptionType",
"=",
"this",
".",
"subscribeTo",
";",
"var",
"newSubscriptionType",
"=",
"subscriptionType",
"&",
"SUBSCRIPTION",
".",
"ALL",
";",
"var",
"delta",
"=",
"curSubscriptionType",
"^",
"newSubscriptionType",
";",
"if",
"(",
"delta",
")",
"{",
"this",
".",
"subscribeTo",
"=",
"newSubscriptionType",
";",
"if",
"(",
"this",
".",
"active",
")",
"SUBSCRIPTION",
".",
"changeSubscription",
"(",
"this",
",",
"curSubscriptionType",
",",
"newSubscriptionType",
")",
";",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
] |
Set new value for subscriptionType property.
@param {number} subscriptionType New value for {basis.data.Object#subscribeTo} property.
@return {boolean} Returns true if {basis.data.Object#subscribeTo} was changed.
|
[
"Set",
"new",
"value",
"for",
"subscriptionType",
"property",
"."
] |
8571903014b207a09d45ad2d1bfba277bf21289b
|
https://github.com/basisjs/basisjs/blob/8571903014b207a09d45ad2d1bfba277bf21289b/src/basis/data/AbstractData.js#L283-L299
|
train
|
|
basisjs/basisjs
|
src/basis/data/AbstractData.js
|
function(syncAction){
var oldAction = this.syncAction;
if (typeof syncAction != 'function')
syncAction = null;
this.syncAction = syncAction;
if (syncAction)
{
if (!oldAction)
this.addHandler(this.syncEvents);
if (this.isSyncRequired())
callSyncAction(this);
}
else
{
if (oldAction)
this.removeHandler(this.syncEvents);
}
}
|
javascript
|
function(syncAction){
var oldAction = this.syncAction;
if (typeof syncAction != 'function')
syncAction = null;
this.syncAction = syncAction;
if (syncAction)
{
if (!oldAction)
this.addHandler(this.syncEvents);
if (this.isSyncRequired())
callSyncAction(this);
}
else
{
if (oldAction)
this.removeHandler(this.syncEvents);
}
}
|
[
"function",
"(",
"syncAction",
")",
"{",
"var",
"oldAction",
"=",
"this",
".",
"syncAction",
";",
"if",
"(",
"typeof",
"syncAction",
"!=",
"'function'",
")",
"syncAction",
"=",
"null",
";",
"this",
".",
"syncAction",
"=",
"syncAction",
";",
"if",
"(",
"syncAction",
")",
"{",
"if",
"(",
"!",
"oldAction",
")",
"this",
".",
"addHandler",
"(",
"this",
".",
"syncEvents",
")",
";",
"if",
"(",
"this",
".",
"isSyncRequired",
"(",
")",
")",
"callSyncAction",
"(",
"this",
")",
";",
"}",
"else",
"{",
"if",
"(",
"oldAction",
")",
"this",
".",
"removeHandler",
"(",
"this",
".",
"syncEvents",
")",
";",
"}",
"}"
] |
Change sync actions function.
@param {function|null} syncAction
|
[
"Change",
"sync",
"actions",
"function",
"."
] |
8571903014b207a09d45ad2d1bfba277bf21289b
|
https://github.com/basisjs/basisjs/blob/8571903014b207a09d45ad2d1bfba277bf21289b/src/basis/data/AbstractData.js#L313-L333
|
train
|
|
basisjs/basisjs
|
src/basis/data/resolve.js
|
createResolveFunction
|
function createResolveFunction(Class){
return function resolve(context, fn, source, property, factoryContext){
var oldAdapter = context[property] || null;
var newAdapter = null;
if (fn !== resolveAdapterProxy && typeof source == 'function')
source = source.call(factoryContext || context, factoryContext || context);
if (source && source.bindingBridge)
{
if (!oldAdapter || oldAdapter.source !== source)
newAdapter = new BBResolveAdapter(context, fn, source, DEFAULT_CHANGE_ADAPTER_HANDLER);
else
newAdapter = oldAdapter;
source = resolve(newAdapter, resolveAdapterProxy, source.bindingBridge.get(source), 'next');
}
if (source instanceof Class == false)
source = null;
if (property && oldAdapter !== newAdapter)
{
var cursor = oldAdapter;
// drop old adapter chain
while (cursor)
{
var adapter = cursor;
adapter.detach();
cursor = adapter.next;
adapter.next = null;
}
if (newAdapter)
newAdapter.attach(DEFAULT_DESTROY_ADAPTER_HANDLER);
context[property] = newAdapter;
}
return source;
};
}
|
javascript
|
function createResolveFunction(Class){
return function resolve(context, fn, source, property, factoryContext){
var oldAdapter = context[property] || null;
var newAdapter = null;
if (fn !== resolveAdapterProxy && typeof source == 'function')
source = source.call(factoryContext || context, factoryContext || context);
if (source && source.bindingBridge)
{
if (!oldAdapter || oldAdapter.source !== source)
newAdapter = new BBResolveAdapter(context, fn, source, DEFAULT_CHANGE_ADAPTER_HANDLER);
else
newAdapter = oldAdapter;
source = resolve(newAdapter, resolveAdapterProxy, source.bindingBridge.get(source), 'next');
}
if (source instanceof Class == false)
source = null;
if (property && oldAdapter !== newAdapter)
{
var cursor = oldAdapter;
// drop old adapter chain
while (cursor)
{
var adapter = cursor;
adapter.detach();
cursor = adapter.next;
adapter.next = null;
}
if (newAdapter)
newAdapter.attach(DEFAULT_DESTROY_ADAPTER_HANDLER);
context[property] = newAdapter;
}
return source;
};
}
|
[
"function",
"createResolveFunction",
"(",
"Class",
")",
"{",
"return",
"function",
"resolve",
"(",
"context",
",",
"fn",
",",
"source",
",",
"property",
",",
"factoryContext",
")",
"{",
"var",
"oldAdapter",
"=",
"context",
"[",
"property",
"]",
"||",
"null",
";",
"var",
"newAdapter",
"=",
"null",
";",
"if",
"(",
"fn",
"!==",
"resolveAdapterProxy",
"&&",
"typeof",
"source",
"==",
"'function'",
")",
"source",
"=",
"source",
".",
"call",
"(",
"factoryContext",
"||",
"context",
",",
"factoryContext",
"||",
"context",
")",
";",
"if",
"(",
"source",
"&&",
"source",
".",
"bindingBridge",
")",
"{",
"if",
"(",
"!",
"oldAdapter",
"||",
"oldAdapter",
".",
"source",
"!==",
"source",
")",
"newAdapter",
"=",
"new",
"BBResolveAdapter",
"(",
"context",
",",
"fn",
",",
"source",
",",
"DEFAULT_CHANGE_ADAPTER_HANDLER",
")",
";",
"else",
"newAdapter",
"=",
"oldAdapter",
";",
"source",
"=",
"resolve",
"(",
"newAdapter",
",",
"resolveAdapterProxy",
",",
"source",
".",
"bindingBridge",
".",
"get",
"(",
"source",
")",
",",
"'next'",
")",
";",
"}",
"if",
"(",
"source",
"instanceof",
"Class",
"==",
"false",
")",
"source",
"=",
"null",
";",
"if",
"(",
"property",
"&&",
"oldAdapter",
"!==",
"newAdapter",
")",
"{",
"var",
"cursor",
"=",
"oldAdapter",
";",
"while",
"(",
"cursor",
")",
"{",
"var",
"adapter",
"=",
"cursor",
";",
"adapter",
".",
"detach",
"(",
")",
";",
"cursor",
"=",
"adapter",
".",
"next",
";",
"adapter",
".",
"next",
"=",
"null",
";",
"}",
"if",
"(",
"newAdapter",
")",
"newAdapter",
".",
"attach",
"(",
"DEFAULT_DESTROY_ADAPTER_HANDLER",
")",
";",
"context",
"[",
"property",
"]",
"=",
"newAdapter",
";",
"}",
"return",
"source",
";",
"}",
";",
"}"
] |
Class instance resolve function factory
|
[
"Class",
"instance",
"resolve",
"function",
"factory"
] |
8571903014b207a09d45ad2d1bfba277bf21289b
|
https://github.com/basisjs/basisjs/blob/8571903014b207a09d45ad2d1bfba277bf21289b/src/basis/data/resolve.js#L63-L105
|
train
|
basisjs/basisjs
|
src/basis/data/resolve.js
|
resolveValue
|
function resolveValue(context, fn, source, property, factoryContext){
var oldAdapter = context[property] || null;
var newAdapter = null;
// as functions could be a value, invoke only functions with factory property
// i.e. source -> function(){ /* factory code */ }).factory === FACTORY
// apply only for top-level resolveValue() invocation
if (source && fn !== resolveAdapterProxy && basis.fn.isFactory(source))
source = source.call(factoryContext || context, factoryContext || context);
if (source && source.bindingBridge)
{
if (!oldAdapter || oldAdapter.source !== source)
newAdapter = new BBResolveAdapter(context, fn, source, DEFAULT_CHANGE_ADAPTER_HANDLER);
else
newAdapter = oldAdapter;
source = resolveValue(newAdapter, resolveAdapterProxy, source.bindingBridge.get(source), 'next');
}
if (property && oldAdapter !== newAdapter)
{
var cursor = oldAdapter;
// drop old adapter chain
while (cursor)
{
var adapter = cursor;
adapter.detach();
cursor = adapter.next;
adapter.next = null;
}
if (newAdapter)
newAdapter.attach(RESOLVEVALUE_DESTROY_ADAPTER_HANDLER);
context[property] = newAdapter;
}
return source;
}
|
javascript
|
function resolveValue(context, fn, source, property, factoryContext){
var oldAdapter = context[property] || null;
var newAdapter = null;
// as functions could be a value, invoke only functions with factory property
// i.e. source -> function(){ /* factory code */ }).factory === FACTORY
// apply only for top-level resolveValue() invocation
if (source && fn !== resolveAdapterProxy && basis.fn.isFactory(source))
source = source.call(factoryContext || context, factoryContext || context);
if (source && source.bindingBridge)
{
if (!oldAdapter || oldAdapter.source !== source)
newAdapter = new BBResolveAdapter(context, fn, source, DEFAULT_CHANGE_ADAPTER_HANDLER);
else
newAdapter = oldAdapter;
source = resolveValue(newAdapter, resolveAdapterProxy, source.bindingBridge.get(source), 'next');
}
if (property && oldAdapter !== newAdapter)
{
var cursor = oldAdapter;
// drop old adapter chain
while (cursor)
{
var adapter = cursor;
adapter.detach();
cursor = adapter.next;
adapter.next = null;
}
if (newAdapter)
newAdapter.attach(RESOLVEVALUE_DESTROY_ADAPTER_HANDLER);
context[property] = newAdapter;
}
return source;
}
|
[
"function",
"resolveValue",
"(",
"context",
",",
"fn",
",",
"source",
",",
"property",
",",
"factoryContext",
")",
"{",
"var",
"oldAdapter",
"=",
"context",
"[",
"property",
"]",
"||",
"null",
";",
"var",
"newAdapter",
"=",
"null",
";",
"if",
"(",
"source",
"&&",
"fn",
"!==",
"resolveAdapterProxy",
"&&",
"basis",
".",
"fn",
".",
"isFactory",
"(",
"source",
")",
")",
"source",
"=",
"source",
".",
"call",
"(",
"factoryContext",
"||",
"context",
",",
"factoryContext",
"||",
"context",
")",
";",
"if",
"(",
"source",
"&&",
"source",
".",
"bindingBridge",
")",
"{",
"if",
"(",
"!",
"oldAdapter",
"||",
"oldAdapter",
".",
"source",
"!==",
"source",
")",
"newAdapter",
"=",
"new",
"BBResolveAdapter",
"(",
"context",
",",
"fn",
",",
"source",
",",
"DEFAULT_CHANGE_ADAPTER_HANDLER",
")",
";",
"else",
"newAdapter",
"=",
"oldAdapter",
";",
"source",
"=",
"resolveValue",
"(",
"newAdapter",
",",
"resolveAdapterProxy",
",",
"source",
".",
"bindingBridge",
".",
"get",
"(",
"source",
")",
",",
"'next'",
")",
";",
"}",
"if",
"(",
"property",
"&&",
"oldAdapter",
"!==",
"newAdapter",
")",
"{",
"var",
"cursor",
"=",
"oldAdapter",
";",
"while",
"(",
"cursor",
")",
"{",
"var",
"adapter",
"=",
"cursor",
";",
"adapter",
".",
"detach",
"(",
")",
";",
"cursor",
"=",
"adapter",
".",
"next",
";",
"adapter",
".",
"next",
"=",
"null",
";",
"}",
"if",
"(",
"newAdapter",
")",
"newAdapter",
".",
"attach",
"(",
"RESOLVEVALUE_DESTROY_ADAPTER_HANDLER",
")",
";",
"context",
"[",
"property",
"]",
"=",
"newAdapter",
";",
"}",
"return",
"source",
";",
"}"
] |
Resolve value from source.
|
[
"Resolve",
"value",
"from",
"source",
"."
] |
8571903014b207a09d45ad2d1bfba277bf21289b
|
https://github.com/basisjs/basisjs/blob/8571903014b207a09d45ad2d1bfba277bf21289b/src/basis/data/resolve.js#L110-L150
|
train
|
basisjs/basisjs
|
src/basis/data/dataset/Extract.js
|
function(){
var insertedMap = {};
var deletedMap = {};
var delta;
for (var key in this.sourceMap_)
{
var sourceObjectInfo = this.sourceMap_[key];
var sourceObject = sourceObjectInfo.source;
if (sourceObject instanceof DataObject)
{
var newValue = this.rule(sourceObject) || null;
var oldValue = sourceObjectInfo.value;
if (isEqual(newValue, oldValue))
continue;
if (newValue instanceof DataObject || newValue instanceof ReadOnlyDataset)
{
var inserted = addToExtract(this, newValue, sourceObject);
for (var i = 0; i < inserted.length; i++)
{
var item = inserted[i];
var id = item.basisObjectId;
if (deletedMap[id])
delete deletedMap[id];
else
insertedMap[id] = item;
}
}
if (oldValue)
{
var deleted = removeFromExtract(this, oldValue, sourceObject);
for (var i = 0; i < deleted.length; i++)
{
var item = deleted[i];
var id = item.basisObjectId;
if (insertedMap[id])
delete insertedMap[id];
else
deletedMap[id] = item;
}
}
// update value
sourceObjectInfo.value = newValue;
}
}
if (delta = getDelta(values(insertedMap), values(deletedMap)))
this.emit_itemsChanged(delta);
return delta;
}
|
javascript
|
function(){
var insertedMap = {};
var deletedMap = {};
var delta;
for (var key in this.sourceMap_)
{
var sourceObjectInfo = this.sourceMap_[key];
var sourceObject = sourceObjectInfo.source;
if (sourceObject instanceof DataObject)
{
var newValue = this.rule(sourceObject) || null;
var oldValue = sourceObjectInfo.value;
if (isEqual(newValue, oldValue))
continue;
if (newValue instanceof DataObject || newValue instanceof ReadOnlyDataset)
{
var inserted = addToExtract(this, newValue, sourceObject);
for (var i = 0; i < inserted.length; i++)
{
var item = inserted[i];
var id = item.basisObjectId;
if (deletedMap[id])
delete deletedMap[id];
else
insertedMap[id] = item;
}
}
if (oldValue)
{
var deleted = removeFromExtract(this, oldValue, sourceObject);
for (var i = 0; i < deleted.length; i++)
{
var item = deleted[i];
var id = item.basisObjectId;
if (insertedMap[id])
delete insertedMap[id];
else
deletedMap[id] = item;
}
}
// update value
sourceObjectInfo.value = newValue;
}
}
if (delta = getDelta(values(insertedMap), values(deletedMap)))
this.emit_itemsChanged(delta);
return delta;
}
|
[
"function",
"(",
")",
"{",
"var",
"insertedMap",
"=",
"{",
"}",
";",
"var",
"deletedMap",
"=",
"{",
"}",
";",
"var",
"delta",
";",
"for",
"(",
"var",
"key",
"in",
"this",
".",
"sourceMap_",
")",
"{",
"var",
"sourceObjectInfo",
"=",
"this",
".",
"sourceMap_",
"[",
"key",
"]",
";",
"var",
"sourceObject",
"=",
"sourceObjectInfo",
".",
"source",
";",
"if",
"(",
"sourceObject",
"instanceof",
"DataObject",
")",
"{",
"var",
"newValue",
"=",
"this",
".",
"rule",
"(",
"sourceObject",
")",
"||",
"null",
";",
"var",
"oldValue",
"=",
"sourceObjectInfo",
".",
"value",
";",
"if",
"(",
"isEqual",
"(",
"newValue",
",",
"oldValue",
")",
")",
"continue",
";",
"if",
"(",
"newValue",
"instanceof",
"DataObject",
"||",
"newValue",
"instanceof",
"ReadOnlyDataset",
")",
"{",
"var",
"inserted",
"=",
"addToExtract",
"(",
"this",
",",
"newValue",
",",
"sourceObject",
")",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"inserted",
".",
"length",
";",
"i",
"++",
")",
"{",
"var",
"item",
"=",
"inserted",
"[",
"i",
"]",
";",
"var",
"id",
"=",
"item",
".",
"basisObjectId",
";",
"if",
"(",
"deletedMap",
"[",
"id",
"]",
")",
"delete",
"deletedMap",
"[",
"id",
"]",
";",
"else",
"insertedMap",
"[",
"id",
"]",
"=",
"item",
";",
"}",
"}",
"if",
"(",
"oldValue",
")",
"{",
"var",
"deleted",
"=",
"removeFromExtract",
"(",
"this",
",",
"oldValue",
",",
"sourceObject",
")",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"deleted",
".",
"length",
";",
"i",
"++",
")",
"{",
"var",
"item",
"=",
"deleted",
"[",
"i",
"]",
";",
"var",
"id",
"=",
"item",
".",
"basisObjectId",
";",
"if",
"(",
"insertedMap",
"[",
"id",
"]",
")",
"delete",
"insertedMap",
"[",
"id",
"]",
";",
"else",
"deletedMap",
"[",
"id",
"]",
"=",
"item",
";",
"}",
"}",
"sourceObjectInfo",
".",
"value",
"=",
"newValue",
";",
"}",
"}",
"if",
"(",
"delta",
"=",
"getDelta",
"(",
"values",
"(",
"insertedMap",
")",
",",
"values",
"(",
"deletedMap",
")",
")",
")",
"this",
".",
"emit_itemsChanged",
"(",
"delta",
")",
";",
"return",
"delta",
";",
"}"
] |
Re-apply rule to members.
@return {Object} Delta of member changes.
|
[
"Re",
"-",
"apply",
"rule",
"to",
"members",
"."
] |
8571903014b207a09d45ad2d1bfba277bf21289b
|
https://github.com/basisjs/basisjs/blob/8571903014b207a09d45ad2d1bfba277bf21289b/src/basis/data/dataset/Extract.js#L307-L363
|
train
|
|
basisjs/basisjs
|
src/basis/net/action.js
|
createAction
|
function createAction(config){
// make a copy of config with defaults
config = basis.object.extend({
prepare: nothingToDo,
request: nothingToDo
}, config);
// if body is function take in account special action context
if (typeof config.body == 'function')
{
var bodyFn = config.body;
config.body = function(){
return bodyFn.apply(this.context, this.args);
};
}
// splice properties
var fn = basis.object.splice(config, ['prepare', 'request']);
var callback = basis.object.merge(
DEFAULT_CALLBACK,
basis.object.splice(config, ['start', 'success', 'failure', 'abort', 'complete'])
);
// lazy transport
var getTransport = basis.fn.lazyInit(function(){
var transport = resolveTransport(config);
transport.addHandler(CALLBACK_HANDLER, callback);
return transport;
});
return function action(){
// this - instance of AbstractData
if (this.state != STATE_PROCESSING)
{
if (fn.prepare.apply(this, arguments))
{
/** @cut */ basis.dev.info('Prepare handler returns trulthy result. Operation aborted. Context: ', this);
return Promise.reject('Prepare handler returns trulthy result. Operation aborted. Context: ', this);
}
var request;
var requestData = basis.object.complete({
origin: this,
bodyContext: {
context: this,
args: basis.array(arguments)
}
}, fn.request.apply(this, arguments));
// if body is function take in account special action context
if (typeof requestData.body == 'function')
{
var bodyFn = requestData.body;
requestData.body = function(){
return bodyFn.apply(this.context, this.args);
};
}
// do a request
if (request = getTransport().request(requestData))
return new Promise(function(fulfill, reject){
request.addHandler(PROMISE_REQUEST_HANDLER, {
request: request,
fulfill: fulfill,
reject: reject
});
});
return Promise.reject('Request is not performed');
}
else
{
/** @cut */ basis.dev.warn('Context in processing state. Operation aborted. Context: ', this);
return Promise.reject('Context in processing state, request is not performed');
}
};
}
|
javascript
|
function createAction(config){
// make a copy of config with defaults
config = basis.object.extend({
prepare: nothingToDo,
request: nothingToDo
}, config);
// if body is function take in account special action context
if (typeof config.body == 'function')
{
var bodyFn = config.body;
config.body = function(){
return bodyFn.apply(this.context, this.args);
};
}
// splice properties
var fn = basis.object.splice(config, ['prepare', 'request']);
var callback = basis.object.merge(
DEFAULT_CALLBACK,
basis.object.splice(config, ['start', 'success', 'failure', 'abort', 'complete'])
);
// lazy transport
var getTransport = basis.fn.lazyInit(function(){
var transport = resolveTransport(config);
transport.addHandler(CALLBACK_HANDLER, callback);
return transport;
});
return function action(){
// this - instance of AbstractData
if (this.state != STATE_PROCESSING)
{
if (fn.prepare.apply(this, arguments))
{
/** @cut */ basis.dev.info('Prepare handler returns trulthy result. Operation aborted. Context: ', this);
return Promise.reject('Prepare handler returns trulthy result. Operation aborted. Context: ', this);
}
var request;
var requestData = basis.object.complete({
origin: this,
bodyContext: {
context: this,
args: basis.array(arguments)
}
}, fn.request.apply(this, arguments));
// if body is function take in account special action context
if (typeof requestData.body == 'function')
{
var bodyFn = requestData.body;
requestData.body = function(){
return bodyFn.apply(this.context, this.args);
};
}
// do a request
if (request = getTransport().request(requestData))
return new Promise(function(fulfill, reject){
request.addHandler(PROMISE_REQUEST_HANDLER, {
request: request,
fulfill: fulfill,
reject: reject
});
});
return Promise.reject('Request is not performed');
}
else
{
/** @cut */ basis.dev.warn('Context in processing state. Operation aborted. Context: ', this);
return Promise.reject('Context in processing state, request is not performed');
}
};
}
|
[
"function",
"createAction",
"(",
"config",
")",
"{",
"config",
"=",
"basis",
".",
"object",
".",
"extend",
"(",
"{",
"prepare",
":",
"nothingToDo",
",",
"request",
":",
"nothingToDo",
"}",
",",
"config",
")",
";",
"if",
"(",
"typeof",
"config",
".",
"body",
"==",
"'function'",
")",
"{",
"var",
"bodyFn",
"=",
"config",
".",
"body",
";",
"config",
".",
"body",
"=",
"function",
"(",
")",
"{",
"return",
"bodyFn",
".",
"apply",
"(",
"this",
".",
"context",
",",
"this",
".",
"args",
")",
";",
"}",
";",
"}",
"var",
"fn",
"=",
"basis",
".",
"object",
".",
"splice",
"(",
"config",
",",
"[",
"'prepare'",
",",
"'request'",
"]",
")",
";",
"var",
"callback",
"=",
"basis",
".",
"object",
".",
"merge",
"(",
"DEFAULT_CALLBACK",
",",
"basis",
".",
"object",
".",
"splice",
"(",
"config",
",",
"[",
"'start'",
",",
"'success'",
",",
"'failure'",
",",
"'abort'",
",",
"'complete'",
"]",
")",
")",
";",
"var",
"getTransport",
"=",
"basis",
".",
"fn",
".",
"lazyInit",
"(",
"function",
"(",
")",
"{",
"var",
"transport",
"=",
"resolveTransport",
"(",
"config",
")",
";",
"transport",
".",
"addHandler",
"(",
"CALLBACK_HANDLER",
",",
"callback",
")",
";",
"return",
"transport",
";",
"}",
")",
";",
"return",
"function",
"action",
"(",
")",
"{",
"if",
"(",
"this",
".",
"state",
"!=",
"STATE_PROCESSING",
")",
"{",
"if",
"(",
"fn",
".",
"prepare",
".",
"apply",
"(",
"this",
",",
"arguments",
")",
")",
"{",
"basis",
".",
"dev",
".",
"info",
"(",
"'Prepare handler returns trulthy result. Operation aborted. Context: '",
",",
"this",
")",
";",
"return",
"Promise",
".",
"reject",
"(",
"'Prepare handler returns trulthy result. Operation aborted. Context: '",
",",
"this",
")",
";",
"}",
"var",
"request",
";",
"var",
"requestData",
"=",
"basis",
".",
"object",
".",
"complete",
"(",
"{",
"origin",
":",
"this",
",",
"bodyContext",
":",
"{",
"context",
":",
"this",
",",
"args",
":",
"basis",
".",
"array",
"(",
"arguments",
")",
"}",
"}",
",",
"fn",
".",
"request",
".",
"apply",
"(",
"this",
",",
"arguments",
")",
")",
";",
"if",
"(",
"typeof",
"requestData",
".",
"body",
"==",
"'function'",
")",
"{",
"var",
"bodyFn",
"=",
"requestData",
".",
"body",
";",
"requestData",
".",
"body",
"=",
"function",
"(",
")",
"{",
"return",
"bodyFn",
".",
"apply",
"(",
"this",
".",
"context",
",",
"this",
".",
"args",
")",
";",
"}",
";",
"}",
"if",
"(",
"request",
"=",
"getTransport",
"(",
")",
".",
"request",
"(",
"requestData",
")",
")",
"return",
"new",
"Promise",
"(",
"function",
"(",
"fulfill",
",",
"reject",
")",
"{",
"request",
".",
"addHandler",
"(",
"PROMISE_REQUEST_HANDLER",
",",
"{",
"request",
":",
"request",
",",
"fulfill",
":",
"fulfill",
",",
"reject",
":",
"reject",
"}",
")",
";",
"}",
")",
";",
"return",
"Promise",
".",
"reject",
"(",
"'Request is not performed'",
")",
";",
"}",
"else",
"{",
"basis",
".",
"dev",
".",
"warn",
"(",
"'Context in processing state. Operation aborted. Context: '",
",",
"this",
")",
";",
"return",
"Promise",
".",
"reject",
"(",
"'Context in processing state, request is not performed'",
")",
";",
"}",
"}",
";",
"}"
] |
Creates a function that init service transport if necessary and make a request.
@function
|
[
"Creates",
"a",
"function",
"that",
"init",
"service",
"transport",
"if",
"necessary",
"and",
"make",
"a",
"request",
"."
] |
8571903014b207a09d45ad2d1bfba277bf21289b
|
https://github.com/basisjs/basisjs/blob/8571903014b207a09d45ad2d1bfba277bf21289b/src/basis/net/action.js#L111-L189
|
train
|
basisjs/basisjs
|
demo/apps/todomvc/basis/js/app.js
|
function(){
// set up router
router.route(/^\/(active|completed)$/).param(0).as(function(subset){
Todo.selected.set(Todo[subset || 'all']);
});
// return app root node
return new Node({
template: resource('./app/template/layout.tmpl'),
binding: {
// nested views
form: resource('./module/form/index.js'),
list: resource('./module/list/index.js'),
stat: resource('./module/stat/index.js')
}
});
}
|
javascript
|
function(){
// set up router
router.route(/^\/(active|completed)$/).param(0).as(function(subset){
Todo.selected.set(Todo[subset || 'all']);
});
// return app root node
return new Node({
template: resource('./app/template/layout.tmpl'),
binding: {
// nested views
form: resource('./module/form/index.js'),
list: resource('./module/list/index.js'),
stat: resource('./module/stat/index.js')
}
});
}
|
[
"function",
"(",
")",
"{",
"router",
".",
"route",
"(",
"/",
"^\\/(active|completed)$",
"/",
")",
".",
"param",
"(",
"0",
")",
".",
"as",
"(",
"function",
"(",
"subset",
")",
"{",
"Todo",
".",
"selected",
".",
"set",
"(",
"Todo",
"[",
"subset",
"||",
"'all'",
"]",
")",
";",
"}",
")",
";",
"return",
"new",
"Node",
"(",
"{",
"template",
":",
"resource",
"(",
"'./app/template/layout.tmpl'",
")",
",",
"binding",
":",
"{",
"form",
":",
"resource",
"(",
"'./module/form/index.js'",
")",
",",
"list",
":",
"resource",
"(",
"'./module/list/index.js'",
")",
",",
"stat",
":",
"resource",
"(",
"'./module/stat/index.js'",
")",
"}",
"}",
")",
";",
"}"
] |
init method invoke on document ready
|
[
"init",
"method",
"invoke",
"on",
"document",
"ready"
] |
8571903014b207a09d45ad2d1bfba277bf21289b
|
https://github.com/basisjs/basisjs/blob/8571903014b207a09d45ad2d1bfba277bf21289b/demo/apps/todomvc/basis/js/app.js#L11-L27
|
train
|
|
basisjs/basisjs
|
src/basis/template/html.js
|
legacyAttrClass
|
function legacyAttrClass(domRef, oldClass, newValue, anim){
var newClass = newValue || '';
if (newClass != oldClass)
{
var className = domRef.className;
var classNameIsObject = typeof className != 'string';
var classList;
if (classNameIsObject)
className = className.baseVal;
classList = className.split(WHITESPACE);
if (oldClass)
basis.array.remove(classList, oldClass);
if (newClass)
{
classList.push(newClass);
if (anim)
{
basis.array.add(classList, newClass + '-anim');
basis.nextTick(function(){
var classList = (classNameIsObject ? domRef.className.baseVal : domRef.className).split(WHITESPACE);
basis.array.remove(classList, newClass + '-anim');
if (classNameIsObject)
domRef.className.baseVal = classList.join(' ');
else
domRef.className = classList.join(' ');
});
}
}
if (classNameIsObject)
domRef.className.baseVal = classList.join(' ');
else
domRef.className = classList.join(' ');
}
return newClass;
}
|
javascript
|
function legacyAttrClass(domRef, oldClass, newValue, anim){
var newClass = newValue || '';
if (newClass != oldClass)
{
var className = domRef.className;
var classNameIsObject = typeof className != 'string';
var classList;
if (classNameIsObject)
className = className.baseVal;
classList = className.split(WHITESPACE);
if (oldClass)
basis.array.remove(classList, oldClass);
if (newClass)
{
classList.push(newClass);
if (anim)
{
basis.array.add(classList, newClass + '-anim');
basis.nextTick(function(){
var classList = (classNameIsObject ? domRef.className.baseVal : domRef.className).split(WHITESPACE);
basis.array.remove(classList, newClass + '-anim');
if (classNameIsObject)
domRef.className.baseVal = classList.join(' ');
else
domRef.className = classList.join(' ');
});
}
}
if (classNameIsObject)
domRef.className.baseVal = classList.join(' ');
else
domRef.className = classList.join(' ');
}
return newClass;
}
|
[
"function",
"legacyAttrClass",
"(",
"domRef",
",",
"oldClass",
",",
"newValue",
",",
"anim",
")",
"{",
"var",
"newClass",
"=",
"newValue",
"||",
"''",
";",
"if",
"(",
"newClass",
"!=",
"oldClass",
")",
"{",
"var",
"className",
"=",
"domRef",
".",
"className",
";",
"var",
"classNameIsObject",
"=",
"typeof",
"className",
"!=",
"'string'",
";",
"var",
"classList",
";",
"if",
"(",
"classNameIsObject",
")",
"className",
"=",
"className",
".",
"baseVal",
";",
"classList",
"=",
"className",
".",
"split",
"(",
"WHITESPACE",
")",
";",
"if",
"(",
"oldClass",
")",
"basis",
".",
"array",
".",
"remove",
"(",
"classList",
",",
"oldClass",
")",
";",
"if",
"(",
"newClass",
")",
"{",
"classList",
".",
"push",
"(",
"newClass",
")",
";",
"if",
"(",
"anim",
")",
"{",
"basis",
".",
"array",
".",
"add",
"(",
"classList",
",",
"newClass",
"+",
"'-anim'",
")",
";",
"basis",
".",
"nextTick",
"(",
"function",
"(",
")",
"{",
"var",
"classList",
"=",
"(",
"classNameIsObject",
"?",
"domRef",
".",
"className",
".",
"baseVal",
":",
"domRef",
".",
"className",
")",
".",
"split",
"(",
"WHITESPACE",
")",
";",
"basis",
".",
"array",
".",
"remove",
"(",
"classList",
",",
"newClass",
"+",
"'-anim'",
")",
";",
"if",
"(",
"classNameIsObject",
")",
"domRef",
".",
"className",
".",
"baseVal",
"=",
"classList",
".",
"join",
"(",
"' '",
")",
";",
"else",
"domRef",
".",
"className",
"=",
"classList",
".",
"join",
"(",
"' '",
")",
";",
"}",
")",
";",
"}",
"}",
"if",
"(",
"classNameIsObject",
")",
"domRef",
".",
"className",
".",
"baseVal",
"=",
"classList",
".",
"join",
"(",
"' '",
")",
";",
"else",
"domRef",
".",
"className",
"=",
"classList",
".",
"join",
"(",
"' '",
")",
";",
"}",
"return",
"newClass",
";",
"}"
] |
old browsers have no support for classList at all IE11 and lower doesn't support classList for SVG
|
[
"old",
"browsers",
"have",
"no",
"support",
"for",
"classList",
"at",
"all",
"IE11",
"and",
"lower",
"doesn",
"t",
"support",
"classList",
"for",
"SVG"
] |
8571903014b207a09d45ad2d1bfba277bf21289b
|
https://github.com/basisjs/basisjs/blob/8571903014b207a09d45ad2d1bfba277bf21289b/src/basis/template/html.js#L264-L308
|
train
|
basisjs/basisjs
|
src/basis/net/ajax.js
|
setRequestHeaders
|
function setRequestHeaders(xhr, requestData){
var headers = {};
if (IS_METHOD_WITH_BODY.test(requestData.method))
{
// when send a FormData instance, browsers serialize it and
// set correct content-type header with boundary
if (!FormData || requestData.body instanceof FormData == false)
headers['Content-Type'] = requestData.contentType + (requestData.encoding ? '\x3Bcharset=' + requestData.encoding : '');
}
else
{
if (ua.test('ie')) // disable IE caching
{
// new Date(0).toGMTString() is not correct here;
// IE returns date string with no leading zero and IIS may parse
// date wrong and response with code 400
headers['If-Modified-Since'] = 'Thu, 01 Jan 1970 00:00:00 GMT';
}
}
headers = basis.object.merge(headers, requestData.headers);
objectIterate(requestData.headers, function(name, value){
if (name.trim().toLowerCase() == 'content-type')
{
/** @cut */ basis.dev.warn('basis.net.ajax: `Content-Type` header found in request data, use contentType and encoding properties instead');
headers['Content-Type'] = value;
}
else
headers[name] = value;
});
objectIterate(headers, function(key, value){
if (value != null && typeof value != 'function')
xhr.setRequestHeader(key, value);
else
delete headers[key];
});
return headers;
}
|
javascript
|
function setRequestHeaders(xhr, requestData){
var headers = {};
if (IS_METHOD_WITH_BODY.test(requestData.method))
{
// when send a FormData instance, browsers serialize it and
// set correct content-type header with boundary
if (!FormData || requestData.body instanceof FormData == false)
headers['Content-Type'] = requestData.contentType + (requestData.encoding ? '\x3Bcharset=' + requestData.encoding : '');
}
else
{
if (ua.test('ie')) // disable IE caching
{
// new Date(0).toGMTString() is not correct here;
// IE returns date string with no leading zero and IIS may parse
// date wrong and response with code 400
headers['If-Modified-Since'] = 'Thu, 01 Jan 1970 00:00:00 GMT';
}
}
headers = basis.object.merge(headers, requestData.headers);
objectIterate(requestData.headers, function(name, value){
if (name.trim().toLowerCase() == 'content-type')
{
/** @cut */ basis.dev.warn('basis.net.ajax: `Content-Type` header found in request data, use contentType and encoding properties instead');
headers['Content-Type'] = value;
}
else
headers[name] = value;
});
objectIterate(headers, function(key, value){
if (value != null && typeof value != 'function')
xhr.setRequestHeader(key, value);
else
delete headers[key];
});
return headers;
}
|
[
"function",
"setRequestHeaders",
"(",
"xhr",
",",
"requestData",
")",
"{",
"var",
"headers",
"=",
"{",
"}",
";",
"if",
"(",
"IS_METHOD_WITH_BODY",
".",
"test",
"(",
"requestData",
".",
"method",
")",
")",
"{",
"if",
"(",
"!",
"FormData",
"||",
"requestData",
".",
"body",
"instanceof",
"FormData",
"==",
"false",
")",
"headers",
"[",
"'Content-Type'",
"]",
"=",
"requestData",
".",
"contentType",
"+",
"(",
"requestData",
".",
"encoding",
"?",
"'\\x3Bcharset='",
"+",
"\\x3B",
":",
"requestData",
".",
"encoding",
")",
";",
"}",
"else",
"''",
"{",
"if",
"(",
"ua",
".",
"test",
"(",
"'ie'",
")",
")",
"{",
"headers",
"[",
"'If-Modified-Since'",
"]",
"=",
"'Thu, 01 Jan 1970 00:00:00 GMT'",
";",
"}",
"}",
"headers",
"=",
"basis",
".",
"object",
".",
"merge",
"(",
"headers",
",",
"requestData",
".",
"headers",
")",
";",
"objectIterate",
"(",
"requestData",
".",
"headers",
",",
"function",
"(",
"name",
",",
"value",
")",
"{",
"if",
"(",
"name",
".",
"trim",
"(",
")",
".",
"toLowerCase",
"(",
")",
"==",
"'content-type'",
")",
"{",
"basis",
".",
"dev",
".",
"warn",
"(",
"'basis.net.ajax: `Content-Type` header found in request data, use contentType and encoding properties instead'",
")",
";",
"headers",
"[",
"'Content-Type'",
"]",
"=",
"value",
";",
"}",
"else",
"headers",
"[",
"name",
"]",
"=",
"value",
";",
"}",
")",
";",
"objectIterate",
"(",
"headers",
",",
"function",
"(",
"key",
",",
"value",
")",
"{",
"if",
"(",
"value",
"!=",
"null",
"&&",
"typeof",
"value",
"!=",
"'function'",
")",
"xhr",
".",
"setRequestHeader",
"(",
"key",
",",
"value",
")",
";",
"else",
"delete",
"headers",
"[",
"key",
"]",
";",
"}",
")",
";",
"}"
] |
Sets transport request headers
@private
|
[
"Sets",
"transport",
"request",
"headers"
] |
8571903014b207a09d45ad2d1bfba277bf21289b
|
https://github.com/basisjs/basisjs/blob/8571903014b207a09d45ad2d1bfba277bf21289b/src/basis/net/ajax.js#L86-L127
|
train
|
basisjs/basisjs
|
src/basis/xml.js
|
XML2Object
|
function XML2Object(node, mapping){ // require for refactoring
var nodeType = node.nodeType;
var attributes = node.attributes;
var firstChild = node.firstChild;
if (!firstChild)
{
var firstAttr = attributes && attributes[0];
if (nodeType == ELEMENT_NODE)
{
if (!firstAttr)
return '';
// test for <node xsi:nil="true"/>
if (attributes.length == 1 &&
(firstAttr.baseName || firstAttr.localName) == XSI_NIL_LOCALPART &&
firstAttr.namespaceURI == XSI_NAMESPACE)
return null;
}
else
{
if (!firstAttr)
return null;
}
}
else
{
// single child node and not an element -> return child nodeValue
if (firstChild.nodeType != ELEMENT_NODE && firstChild === node.lastChild)
return firstChild.nodeValue;
else
if (firstChild !== node.lastChild && firstChild.nodeType == TEXT_NODE)
{
var isSeparatedTextNode = true;
var result = '';
var cursor = firstChild;
do
{
if (cursor.nodeType !== TEXT_NODE)
{
isSeparatedTextNode = false;
break;
}
result += cursor.nodeValue;
}
while (cursor = cursor.nextSibling);
if (isSeparatedTextNode)
return result;
}
}
var result = {};
var nodes = [];
var childNodesCount = 0;
var value;
var cursor;
var object;
var name;
var isElement;
var map;
if (cursor = firstChild)
{
do
{
childNodesCount = nodes.push(cursor);
}
while (cursor = cursor.nextSibling);
}
if (attributes)
for (var i = 0, attr; attr = attributes[i]; i++)
nodes.push(attr);
if (!mapping)
mapping = {};
for (var i = 0, child; child = nodes[i]; i++)
{
name = child.nodeName;
isElement = i < childNodesCount;
map = mapping[name];
// fetch value
if (isElement)
{
value = XML2Object(child, mapping);
}
else
{
if (name == 'xmlns')
continue;
value = child.nodeValue;
}
// mapping keys
while (map)
{
if (map.storeName)
value[map.storeName] = name;
if (map.rename)
{
name = map.rename;
map = mapping[name];
}
else
{
if (map.format)
value = map.format(value);
if (!result[name] && map.forceArray)
value = [value];
break;
}
}
// store result
if (name in result)
{
if ((object = result[name]) && object.push)
object.push(value);
else
result[name] = [object, value];
}
else
result[name] = value;
}
return result;
}
|
javascript
|
function XML2Object(node, mapping){ // require for refactoring
var nodeType = node.nodeType;
var attributes = node.attributes;
var firstChild = node.firstChild;
if (!firstChild)
{
var firstAttr = attributes && attributes[0];
if (nodeType == ELEMENT_NODE)
{
if (!firstAttr)
return '';
// test for <node xsi:nil="true"/>
if (attributes.length == 1 &&
(firstAttr.baseName || firstAttr.localName) == XSI_NIL_LOCALPART &&
firstAttr.namespaceURI == XSI_NAMESPACE)
return null;
}
else
{
if (!firstAttr)
return null;
}
}
else
{
// single child node and not an element -> return child nodeValue
if (firstChild.nodeType != ELEMENT_NODE && firstChild === node.lastChild)
return firstChild.nodeValue;
else
if (firstChild !== node.lastChild && firstChild.nodeType == TEXT_NODE)
{
var isSeparatedTextNode = true;
var result = '';
var cursor = firstChild;
do
{
if (cursor.nodeType !== TEXT_NODE)
{
isSeparatedTextNode = false;
break;
}
result += cursor.nodeValue;
}
while (cursor = cursor.nextSibling);
if (isSeparatedTextNode)
return result;
}
}
var result = {};
var nodes = [];
var childNodesCount = 0;
var value;
var cursor;
var object;
var name;
var isElement;
var map;
if (cursor = firstChild)
{
do
{
childNodesCount = nodes.push(cursor);
}
while (cursor = cursor.nextSibling);
}
if (attributes)
for (var i = 0, attr; attr = attributes[i]; i++)
nodes.push(attr);
if (!mapping)
mapping = {};
for (var i = 0, child; child = nodes[i]; i++)
{
name = child.nodeName;
isElement = i < childNodesCount;
map = mapping[name];
// fetch value
if (isElement)
{
value = XML2Object(child, mapping);
}
else
{
if (name == 'xmlns')
continue;
value = child.nodeValue;
}
// mapping keys
while (map)
{
if (map.storeName)
value[map.storeName] = name;
if (map.rename)
{
name = map.rename;
map = mapping[name];
}
else
{
if (map.format)
value = map.format(value);
if (!result[name] && map.forceArray)
value = [value];
break;
}
}
// store result
if (name in result)
{
if ((object = result[name]) && object.push)
object.push(value);
else
result[name] = [object, value];
}
else
result[name] = value;
}
return result;
}
|
[
"function",
"XML2Object",
"(",
"node",
",",
"mapping",
")",
"{",
"var",
"nodeType",
"=",
"node",
".",
"nodeType",
";",
"var",
"attributes",
"=",
"node",
".",
"attributes",
";",
"var",
"firstChild",
"=",
"node",
".",
"firstChild",
";",
"if",
"(",
"!",
"firstChild",
")",
"{",
"var",
"firstAttr",
"=",
"attributes",
"&&",
"attributes",
"[",
"0",
"]",
";",
"if",
"(",
"nodeType",
"==",
"ELEMENT_NODE",
")",
"{",
"if",
"(",
"!",
"firstAttr",
")",
"return",
"''",
";",
"if",
"(",
"attributes",
".",
"length",
"==",
"1",
"&&",
"(",
"firstAttr",
".",
"baseName",
"||",
"firstAttr",
".",
"localName",
")",
"==",
"XSI_NIL_LOCALPART",
"&&",
"firstAttr",
".",
"namespaceURI",
"==",
"XSI_NAMESPACE",
")",
"return",
"null",
";",
"}",
"else",
"{",
"if",
"(",
"!",
"firstAttr",
")",
"return",
"null",
";",
"}",
"}",
"else",
"{",
"if",
"(",
"firstChild",
".",
"nodeType",
"!=",
"ELEMENT_NODE",
"&&",
"firstChild",
"===",
"node",
".",
"lastChild",
")",
"return",
"firstChild",
".",
"nodeValue",
";",
"else",
"if",
"(",
"firstChild",
"!==",
"node",
".",
"lastChild",
"&&",
"firstChild",
".",
"nodeType",
"==",
"TEXT_NODE",
")",
"{",
"var",
"isSeparatedTextNode",
"=",
"true",
";",
"var",
"result",
"=",
"''",
";",
"var",
"cursor",
"=",
"firstChild",
";",
"do",
"{",
"if",
"(",
"cursor",
".",
"nodeType",
"!==",
"TEXT_NODE",
")",
"{",
"isSeparatedTextNode",
"=",
"false",
";",
"break",
";",
"}",
"result",
"+=",
"cursor",
".",
"nodeValue",
";",
"}",
"while",
"(",
"cursor",
"=",
"cursor",
".",
"nextSibling",
")",
";",
"if",
"(",
"isSeparatedTextNode",
")",
"return",
"result",
";",
"}",
"}",
"var",
"result",
"=",
"{",
"}",
";",
"var",
"nodes",
"=",
"[",
"]",
";",
"var",
"childNodesCount",
"=",
"0",
";",
"var",
"value",
";",
"var",
"cursor",
";",
"var",
"object",
";",
"var",
"name",
";",
"var",
"isElement",
";",
"var",
"map",
";",
"if",
"(",
"cursor",
"=",
"firstChild",
")",
"{",
"do",
"{",
"childNodesCount",
"=",
"nodes",
".",
"push",
"(",
"cursor",
")",
";",
"}",
"while",
"(",
"cursor",
"=",
"cursor",
".",
"nextSibling",
")",
";",
"}",
"if",
"(",
"attributes",
")",
"for",
"(",
"var",
"i",
"=",
"0",
",",
"attr",
";",
"attr",
"=",
"attributes",
"[",
"i",
"]",
";",
"i",
"++",
")",
"nodes",
".",
"push",
"(",
"attr",
")",
";",
"if",
"(",
"!",
"mapping",
")",
"mapping",
"=",
"{",
"}",
";",
"for",
"(",
"var",
"i",
"=",
"0",
",",
"child",
";",
"child",
"=",
"nodes",
"[",
"i",
"]",
";",
"i",
"++",
")",
"{",
"name",
"=",
"child",
".",
"nodeName",
";",
"isElement",
"=",
"i",
"<",
"childNodesCount",
";",
"map",
"=",
"mapping",
"[",
"name",
"]",
";",
"if",
"(",
"isElement",
")",
"{",
"value",
"=",
"XML2Object",
"(",
"child",
",",
"mapping",
")",
";",
"}",
"else",
"{",
"if",
"(",
"name",
"==",
"'xmlns'",
")",
"continue",
";",
"value",
"=",
"child",
".",
"nodeValue",
";",
"}",
"while",
"(",
"map",
")",
"{",
"if",
"(",
"map",
".",
"storeName",
")",
"value",
"[",
"map",
".",
"storeName",
"]",
"=",
"name",
";",
"if",
"(",
"map",
".",
"rename",
")",
"{",
"name",
"=",
"map",
".",
"rename",
";",
"map",
"=",
"mapping",
"[",
"name",
"]",
";",
"}",
"else",
"{",
"if",
"(",
"map",
".",
"format",
")",
"value",
"=",
"map",
".",
"format",
"(",
"value",
")",
";",
"if",
"(",
"!",
"result",
"[",
"name",
"]",
"&&",
"map",
".",
"forceArray",
")",
"value",
"=",
"[",
"value",
"]",
";",
"break",
";",
"}",
"}",
"if",
"(",
"name",
"in",
"result",
")",
"{",
"if",
"(",
"(",
"object",
"=",
"result",
"[",
"name",
"]",
")",
"&&",
"object",
".",
"push",
")",
"object",
".",
"push",
"(",
"value",
")",
";",
"else",
"result",
"[",
"name",
"]",
"=",
"[",
"object",
",",
"value",
"]",
";",
"}",
"else",
"result",
"[",
"name",
"]",
"=",
"value",
";",
"}",
"return",
"result",
";",
"}"
] |
XML -> Object
Converting xml tree to javascript object representation.
@function
@param {Node} node
@param {object} mapping
@return {object}
|
[
"XML",
"-",
">",
"Object",
"Converting",
"xml",
"tree",
"to",
"javascript",
"object",
"representation",
"."
] |
8571903014b207a09d45ad2d1bfba277bf21289b
|
https://github.com/basisjs/basisjs/blob/8571903014b207a09d45ad2d1bfba277bf21289b/src/basis/xml.js#L167-L300
|
train
|
basisjs/basisjs
|
src/basis/xml.js
|
isPrimitiveObject
|
function isPrimitiveObject(value){
return typeof value == 'string' || typeof value == 'number' ||
typeof value == 'function' || typeof value == 'boolean' ||
value.constructor === Date || value.constructor === RegExp;
}
|
javascript
|
function isPrimitiveObject(value){
return typeof value == 'string' || typeof value == 'number' ||
typeof value == 'function' || typeof value == 'boolean' ||
value.constructor === Date || value.constructor === RegExp;
}
|
[
"function",
"isPrimitiveObject",
"(",
"value",
")",
"{",
"return",
"typeof",
"value",
"==",
"'string'",
"||",
"typeof",
"value",
"==",
"'number'",
"||",
"typeof",
"value",
"==",
"'function'",
"||",
"typeof",
"value",
"==",
"'boolean'",
"||",
"value",
".",
"constructor",
"===",
"Date",
"||",
"value",
".",
"constructor",
"===",
"RegExp",
";",
"}"
] |
Object -> XML
|
[
"Object",
"-",
">",
"XML"
] |
8571903014b207a09d45ad2d1bfba277bf21289b
|
https://github.com/basisjs/basisjs/blob/8571903014b207a09d45ad2d1bfba277bf21289b/src/basis/xml.js#L306-L310
|
train
|
basisjs/basisjs
|
src/basis/xml.js
|
XML2String
|
function XML2String(node){
// modern browsers feature
if (typeof XMLSerializer != 'undefined')
return new XMLSerializer().serializeToString(node);
// old IE feature
if (typeof node.xml == 'string')
return node.xml;
// other browsers
if (node.nodeType == domUtils.DOCUMENT_NODE)
node = node.documentElement;
return domUtils.outerHTML(node);
}
|
javascript
|
function XML2String(node){
// modern browsers feature
if (typeof XMLSerializer != 'undefined')
return new XMLSerializer().serializeToString(node);
// old IE feature
if (typeof node.xml == 'string')
return node.xml;
// other browsers
if (node.nodeType == domUtils.DOCUMENT_NODE)
node = node.documentElement;
return domUtils.outerHTML(node);
}
|
[
"function",
"XML2String",
"(",
"node",
")",
"{",
"if",
"(",
"typeof",
"XMLSerializer",
"!=",
"'undefined'",
")",
"return",
"new",
"XMLSerializer",
"(",
")",
".",
"serializeToString",
"(",
"node",
")",
";",
"if",
"(",
"typeof",
"node",
".",
"xml",
"==",
"'string'",
")",
"return",
"node",
".",
"xml",
";",
"if",
"(",
"node",
".",
"nodeType",
"==",
"domUtils",
".",
"DOCUMENT_NODE",
")",
"node",
"=",
"node",
".",
"documentElement",
";",
"return",
"domUtils",
".",
"outerHTML",
"(",
"node",
")",
";",
"}"
] |
XML -> string
|
[
"XML",
"-",
">",
"string"
] |
8571903014b207a09d45ad2d1bfba277bf21289b
|
https://github.com/basisjs/basisjs/blob/8571903014b207a09d45ad2d1bfba277bf21289b/src/basis/xml.js#L396-L410
|
train
|
basisjs/basisjs
|
src/basis/dom/event.js
|
kill
|
function kill(event, node){
node = getNode(node);
if (node)
addHandler(node, event, kill);
else
{
cancelDefault(event);
cancelBubble(event);
}
}
|
javascript
|
function kill(event, node){
node = getNode(node);
if (node)
addHandler(node, event, kill);
else
{
cancelDefault(event);
cancelBubble(event);
}
}
|
[
"function",
"kill",
"(",
"event",
",",
"node",
")",
"{",
"node",
"=",
"getNode",
"(",
"node",
")",
";",
"if",
"(",
"node",
")",
"addHandler",
"(",
"node",
",",
"event",
",",
"kill",
")",
";",
"else",
"{",
"cancelDefault",
"(",
"event",
")",
";",
"cancelBubble",
"(",
"event",
")",
";",
"}",
"}"
] |
Stops event bubbling and prevent default actions for event.
@param {Event|string} event
@param {Node=} node
|
[
"Stops",
"event",
"bubbling",
"and",
"prevent",
"default",
"actions",
"for",
"event",
"."
] |
8571903014b207a09d45ad2d1bfba277bf21289b
|
https://github.com/basisjs/basisjs/blob/8571903014b207a09d45ad2d1bfba277bf21289b/src/basis/dom/event.js#L300-L310
|
train
|
basisjs/basisjs
|
src/basis/dom/event.js
|
mouseButton
|
function mouseButton(event, button){
if (typeof event.which == 'number')
// DOM scheme
return event.which == button.VALUE;
else
// IE6-8
return !!(event.button & button.BIT);
}
|
javascript
|
function mouseButton(event, button){
if (typeof event.which == 'number')
// DOM scheme
return event.which == button.VALUE;
else
// IE6-8
return !!(event.button & button.BIT);
}
|
[
"function",
"mouseButton",
"(",
"event",
",",
"button",
")",
"{",
"if",
"(",
"typeof",
"event",
".",
"which",
"==",
"'number'",
")",
"return",
"event",
".",
"which",
"==",
"button",
".",
"VALUE",
";",
"else",
"return",
"!",
"!",
"(",
"event",
".",
"button",
"&",
"button",
".",
"BIT",
")",
";",
"}"
] |
Checks if pressed mouse button equal to desire mouse button.
@param {Event} event
@param {object} button One of MOUSE constant
@return {boolean}
|
[
"Checks",
"if",
"pressed",
"mouse",
"button",
"equal",
"to",
"desire",
"mouse",
"button",
"."
] |
8571903014b207a09d45ad2d1bfba277bf21289b
|
https://github.com/basisjs/basisjs/blob/8571903014b207a09d45ad2d1bfba277bf21289b/src/basis/dom/event.js#L336-L343
|
train
|
basisjs/basisjs
|
src/basis/dom/event.js
|
mouseX
|
function mouseX(event){
if ('pageX' in event)
return event.pageX;
else
return 'clientX' in event
? event.clientX +
(document.compatMode == 'CSS1Compat' ? document.documentElement.scrollLeft : document.body.scrollLeft)
: 0;
}
|
javascript
|
function mouseX(event){
if ('pageX' in event)
return event.pageX;
else
return 'clientX' in event
? event.clientX +
(document.compatMode == 'CSS1Compat' ? document.documentElement.scrollLeft : document.body.scrollLeft)
: 0;
}
|
[
"function",
"mouseX",
"(",
"event",
")",
"{",
"if",
"(",
"'pageX'",
"in",
"event",
")",
"return",
"event",
".",
"pageX",
";",
"else",
"return",
"'clientX'",
"in",
"event",
"?",
"event",
".",
"clientX",
"+",
"(",
"document",
".",
"compatMode",
"==",
"'CSS1Compat'",
"?",
"document",
".",
"documentElement",
".",
"scrollLeft",
":",
"document",
".",
"body",
".",
"scrollLeft",
")",
":",
"0",
";",
"}"
] |
Returns mouse click horizontal page coordinate.
@param {Event} event
@return {number}
|
[
"Returns",
"mouse",
"click",
"horizontal",
"page",
"coordinate",
"."
] |
8571903014b207a09d45ad2d1bfba277bf21289b
|
https://github.com/basisjs/basisjs/blob/8571903014b207a09d45ad2d1bfba277bf21289b/src/basis/dom/event.js#L350-L358
|
train
|
basisjs/basisjs
|
src/basis/dom/event.js
|
mouseY
|
function mouseY(event){
if ('pageY' in event)
return event.pageY;
else
return 'clientY' in event
? event.clientY +
(document.compatMode == 'CSS1Compat' ? document.documentElement.scrollTop : document.body.scrollTop)
: 0;
}
|
javascript
|
function mouseY(event){
if ('pageY' in event)
return event.pageY;
else
return 'clientY' in event
? event.clientY +
(document.compatMode == 'CSS1Compat' ? document.documentElement.scrollTop : document.body.scrollTop)
: 0;
}
|
[
"function",
"mouseY",
"(",
"event",
")",
"{",
"if",
"(",
"'pageY'",
"in",
"event",
")",
"return",
"event",
".",
"pageY",
";",
"else",
"return",
"'clientY'",
"in",
"event",
"?",
"event",
".",
"clientY",
"+",
"(",
"document",
".",
"compatMode",
"==",
"'CSS1Compat'",
"?",
"document",
".",
"documentElement",
".",
"scrollTop",
":",
"document",
".",
"body",
".",
"scrollTop",
")",
":",
"0",
";",
"}"
] |
Returns mouse click vertical page coordinate.
@param {Event} event
@return {number}
|
[
"Returns",
"mouse",
"click",
"vertical",
"page",
"coordinate",
"."
] |
8571903014b207a09d45ad2d1bfba277bf21289b
|
https://github.com/basisjs/basisjs/blob/8571903014b207a09d45ad2d1bfba277bf21289b/src/basis/dom/event.js#L365-L373
|
train
|
basisjs/basisjs
|
src/basis/dom/event.js
|
wheelDelta
|
function wheelDelta(event){
var delta = 0;
if ('deltaY' in event)
delta = -event.deltaY; // safari & gecko
else
if ('wheelDelta' in event)
delta = event.wheelDelta; // IE, webkit, opera
else
if (event.type == 'DOMMouseScroll')
delta = -event.detail; // old gecko
return delta && (delta / Math.abs(delta));
}
|
javascript
|
function wheelDelta(event){
var delta = 0;
if ('deltaY' in event)
delta = -event.deltaY; // safari & gecko
else
if ('wheelDelta' in event)
delta = event.wheelDelta; // IE, webkit, opera
else
if (event.type == 'DOMMouseScroll')
delta = -event.detail; // old gecko
return delta && (delta / Math.abs(delta));
}
|
[
"function",
"wheelDelta",
"(",
"event",
")",
"{",
"var",
"delta",
"=",
"0",
";",
"if",
"(",
"'deltaY'",
"in",
"event",
")",
"delta",
"=",
"-",
"event",
".",
"deltaY",
";",
"else",
"if",
"(",
"'wheelDelta'",
"in",
"event",
")",
"delta",
"=",
"event",
".",
"wheelDelta",
";",
"else",
"if",
"(",
"event",
".",
"type",
"==",
"'DOMMouseScroll'",
")",
"delta",
"=",
"-",
"event",
".",
"detail",
";",
"return",
"delta",
"&&",
"(",
"delta",
"/",
"Math",
".",
"abs",
"(",
"delta",
")",
")",
";",
"}"
] |
Returns mouse wheel delta.
@param {Event} event
@return {number} -1, 0, 1
|
[
"Returns",
"mouse",
"wheel",
"delta",
"."
] |
8571903014b207a09d45ad2d1bfba277bf21289b
|
https://github.com/basisjs/basisjs/blob/8571903014b207a09d45ad2d1bfba277bf21289b/src/basis/dom/event.js#L400-L413
|
train
|
basisjs/basisjs
|
src/basis/dom/event.js
|
observeGlobalEvents
|
function observeGlobalEvents(event){
var handlers = arrayFrom(globalHandlers[event.type]);
var captureHandler = captureHandlers[event.type];
var wrappedEvent = new Event(event);
startFrame(event);
if (captureHandler)
{
captureHandler.handler.call(captureHandler.thisObject, wrappedEvent);
}
else
{
if (handlers)
{
for (var i = handlers.length; i-- > 0;)
{
var handlerObject = handlers[i];
handlerObject.handler.call(handlerObject.thisObject, wrappedEvent);
}
}
}
finishFrame(event);
}
|
javascript
|
function observeGlobalEvents(event){
var handlers = arrayFrom(globalHandlers[event.type]);
var captureHandler = captureHandlers[event.type];
var wrappedEvent = new Event(event);
startFrame(event);
if (captureHandler)
{
captureHandler.handler.call(captureHandler.thisObject, wrappedEvent);
}
else
{
if (handlers)
{
for (var i = handlers.length; i-- > 0;)
{
var handlerObject = handlers[i];
handlerObject.handler.call(handlerObject.thisObject, wrappedEvent);
}
}
}
finishFrame(event);
}
|
[
"function",
"observeGlobalEvents",
"(",
"event",
")",
"{",
"var",
"handlers",
"=",
"arrayFrom",
"(",
"globalHandlers",
"[",
"event",
".",
"type",
"]",
")",
";",
"var",
"captureHandler",
"=",
"captureHandlers",
"[",
"event",
".",
"type",
"]",
";",
"var",
"wrappedEvent",
"=",
"new",
"Event",
"(",
"event",
")",
";",
"startFrame",
"(",
"event",
")",
";",
"if",
"(",
"captureHandler",
")",
"{",
"captureHandler",
".",
"handler",
".",
"call",
"(",
"captureHandler",
".",
"thisObject",
",",
"wrappedEvent",
")",
";",
"}",
"else",
"{",
"if",
"(",
"handlers",
")",
"{",
"for",
"(",
"var",
"i",
"=",
"handlers",
".",
"length",
";",
"i",
"--",
">",
"0",
";",
")",
"{",
"var",
"handlerObject",
"=",
"handlers",
"[",
"i",
"]",
";",
"handlerObject",
".",
"handler",
".",
"call",
"(",
"handlerObject",
".",
"thisObject",
",",
"wrappedEvent",
")",
";",
"}",
"}",
"}",
"finishFrame",
"(",
"event",
")",
";",
"}"
] |
Observe handlers for event
@private
@param {Event} event
|
[
"Observe",
"handlers",
"for",
"event"
] |
8571903014b207a09d45ad2d1bfba277bf21289b
|
https://github.com/basisjs/basisjs/blob/8571903014b207a09d45ad2d1bfba277bf21289b/src/basis/dom/event.js#L462-L486
|
train
|
basisjs/basisjs
|
src/basis/dom/event.js
|
addGlobalHandler
|
function addGlobalHandler(eventType, handler, thisObject){
var handlers = globalHandlers[eventType];
if (handlers)
{
// search for similar handler, returns if found (prevent for handler dublicates)
for (var i = 0, item; item = handlers[i]; i++)
if (item.handler === handler && item.thisObject === thisObject)
return;
}
else
{
if (noCaptureScheme)
// nothing to do, but it will provide observeGlobalEvents calls if other one doesn't
addHandler(document, eventType, $null);
else
document.addEventListener(eventType, observeGlobalEvents, true);
handlers = globalHandlers[eventType] = [];
}
// add new handler
handlers.push({
handler: handler,
thisObject: thisObject
});
}
|
javascript
|
function addGlobalHandler(eventType, handler, thisObject){
var handlers = globalHandlers[eventType];
if (handlers)
{
// search for similar handler, returns if found (prevent for handler dublicates)
for (var i = 0, item; item = handlers[i]; i++)
if (item.handler === handler && item.thisObject === thisObject)
return;
}
else
{
if (noCaptureScheme)
// nothing to do, but it will provide observeGlobalEvents calls if other one doesn't
addHandler(document, eventType, $null);
else
document.addEventListener(eventType, observeGlobalEvents, true);
handlers = globalHandlers[eventType] = [];
}
// add new handler
handlers.push({
handler: handler,
thisObject: thisObject
});
}
|
[
"function",
"addGlobalHandler",
"(",
"eventType",
",",
"handler",
",",
"thisObject",
")",
"{",
"var",
"handlers",
"=",
"globalHandlers",
"[",
"eventType",
"]",
";",
"if",
"(",
"handlers",
")",
"{",
"for",
"(",
"var",
"i",
"=",
"0",
",",
"item",
";",
"item",
"=",
"handlers",
"[",
"i",
"]",
";",
"i",
"++",
")",
"if",
"(",
"item",
".",
"handler",
"===",
"handler",
"&&",
"item",
".",
"thisObject",
"===",
"thisObject",
")",
"return",
";",
"}",
"else",
"{",
"if",
"(",
"noCaptureScheme",
")",
"addHandler",
"(",
"document",
",",
"eventType",
",",
"$null",
")",
";",
"else",
"document",
".",
"addEventListener",
"(",
"eventType",
",",
"observeGlobalEvents",
",",
"true",
")",
";",
"handlers",
"=",
"globalHandlers",
"[",
"eventType",
"]",
"=",
"[",
"]",
";",
"}",
"handlers",
".",
"push",
"(",
"{",
"handler",
":",
"handler",
",",
"thisObject",
":",
"thisObject",
"}",
")",
";",
"}"
] |
Adds global handler for some event type.
@param {string} eventType
@param {function(event)} handler
@param {object=} thisObject Context for handler
|
[
"Adds",
"global",
"handler",
"for",
"some",
"event",
"type",
"."
] |
8571903014b207a09d45ad2d1bfba277bf21289b
|
https://github.com/basisjs/basisjs/blob/8571903014b207a09d45ad2d1bfba277bf21289b/src/basis/dom/event.js#L525-L550
|
train
|
basisjs/basisjs
|
src/basis/dom/event.js
|
removeGlobalHandler
|
function removeGlobalHandler(eventType, handler, thisObject){
var handlers = globalHandlers[eventType];
if (handlers)
{
for (var i = 0, item; item = handlers[i]; i++)
{
if (item.handler === handler && item.thisObject === thisObject)
{
handlers.splice(i, 1);
if (!handlers.length)
{
delete globalHandlers[eventType];
if (noCaptureScheme)
removeHandler(document, eventType, $null);
else
document.removeEventListener(eventType, observeGlobalEvents, true);
}
return;
}
}
}
}
|
javascript
|
function removeGlobalHandler(eventType, handler, thisObject){
var handlers = globalHandlers[eventType];
if (handlers)
{
for (var i = 0, item; item = handlers[i]; i++)
{
if (item.handler === handler && item.thisObject === thisObject)
{
handlers.splice(i, 1);
if (!handlers.length)
{
delete globalHandlers[eventType];
if (noCaptureScheme)
removeHandler(document, eventType, $null);
else
document.removeEventListener(eventType, observeGlobalEvents, true);
}
return;
}
}
}
}
|
[
"function",
"removeGlobalHandler",
"(",
"eventType",
",",
"handler",
",",
"thisObject",
")",
"{",
"var",
"handlers",
"=",
"globalHandlers",
"[",
"eventType",
"]",
";",
"if",
"(",
"handlers",
")",
"{",
"for",
"(",
"var",
"i",
"=",
"0",
",",
"item",
";",
"item",
"=",
"handlers",
"[",
"i",
"]",
";",
"i",
"++",
")",
"{",
"if",
"(",
"item",
".",
"handler",
"===",
"handler",
"&&",
"item",
".",
"thisObject",
"===",
"thisObject",
")",
"{",
"handlers",
".",
"splice",
"(",
"i",
",",
"1",
")",
";",
"if",
"(",
"!",
"handlers",
".",
"length",
")",
"{",
"delete",
"globalHandlers",
"[",
"eventType",
"]",
";",
"if",
"(",
"noCaptureScheme",
")",
"removeHandler",
"(",
"document",
",",
"eventType",
",",
"$null",
")",
";",
"else",
"document",
".",
"removeEventListener",
"(",
"eventType",
",",
"observeGlobalEvents",
",",
"true",
")",
";",
"}",
"return",
";",
"}",
"}",
"}",
"}"
] |
Removes global handler for eventType storage.
@param {string} eventType
@param {function(event)} handler
@param {object=} thisObject Context for handler
|
[
"Removes",
"global",
"handler",
"for",
"eventType",
"storage",
"."
] |
8571903014b207a09d45ad2d1bfba277bf21289b
|
https://github.com/basisjs/basisjs/blob/8571903014b207a09d45ad2d1bfba277bf21289b/src/basis/dom/event.js#L558-L581
|
train
|
basisjs/basisjs
|
src/basis/dom/event.js
|
addHandler
|
function addHandler(node, eventType, handler, thisObject){
node = getNode(node);
if (!node)
throw 'basis.event.addHandler: can\'t attach event listener to undefined';
if (typeof handler != 'function')
throw 'basis.event.addHandler: handler is not a function';
var handlers = node === global ? globalEvents : node[EVENT_HOLDER];
if (!handlers)
handlers = node[EVENT_HOLDER] = {};
var eventTypeHandlers = handlers[eventType];
var handlerObject = {
handler: handler,
thisObject: thisObject
};
if (!eventTypeHandlers)
{
eventTypeHandlers = handlers[eventType] = [handlerObject];
eventTypeHandlers.fireEvent = function(event){ // closure
// simulate capture phase for old browsers
event = wrap(event);
if (noCaptureScheme && event && globalHandlers[eventType])
{
if (typeof event.returnValue == 'undefined')
{
observeGlobalEvents(event);
if (event.cancelBubble === true)
return;
if (typeof event.returnValue == 'undefined')
event.returnValue = true;
}
}
startFrame(event);
// call eventType handlers
for (var i = 0, wrappedEvent = new Event(event), item; item = eventTypeHandlers[i++];)
item.handler.call(item.thisObject, wrappedEvent);
finishFrame(event);
};
if (W3CSUPPORT)
// W3C DOM event model
node.addEventListener(eventType, eventTypeHandlers.fireEvent, false);
else
// old IE event model
node.attachEvent('on' + eventType, eventTypeHandlers.fireEvent);
}
else
{
// check for duplicates, exit if found
for (var i = 0, item; item = eventTypeHandlers[i]; i++)
if (item.handler === handler && item.thisObject === thisObject)
return;
// add only unique handlers
eventTypeHandlers.push(handlerObject);
}
}
|
javascript
|
function addHandler(node, eventType, handler, thisObject){
node = getNode(node);
if (!node)
throw 'basis.event.addHandler: can\'t attach event listener to undefined';
if (typeof handler != 'function')
throw 'basis.event.addHandler: handler is not a function';
var handlers = node === global ? globalEvents : node[EVENT_HOLDER];
if (!handlers)
handlers = node[EVENT_HOLDER] = {};
var eventTypeHandlers = handlers[eventType];
var handlerObject = {
handler: handler,
thisObject: thisObject
};
if (!eventTypeHandlers)
{
eventTypeHandlers = handlers[eventType] = [handlerObject];
eventTypeHandlers.fireEvent = function(event){ // closure
// simulate capture phase for old browsers
event = wrap(event);
if (noCaptureScheme && event && globalHandlers[eventType])
{
if (typeof event.returnValue == 'undefined')
{
observeGlobalEvents(event);
if (event.cancelBubble === true)
return;
if (typeof event.returnValue == 'undefined')
event.returnValue = true;
}
}
startFrame(event);
// call eventType handlers
for (var i = 0, wrappedEvent = new Event(event), item; item = eventTypeHandlers[i++];)
item.handler.call(item.thisObject, wrappedEvent);
finishFrame(event);
};
if (W3CSUPPORT)
// W3C DOM event model
node.addEventListener(eventType, eventTypeHandlers.fireEvent, false);
else
// old IE event model
node.attachEvent('on' + eventType, eventTypeHandlers.fireEvent);
}
else
{
// check for duplicates, exit if found
for (var i = 0, item; item = eventTypeHandlers[i]; i++)
if (item.handler === handler && item.thisObject === thisObject)
return;
// add only unique handlers
eventTypeHandlers.push(handlerObject);
}
}
|
[
"function",
"addHandler",
"(",
"node",
",",
"eventType",
",",
"handler",
",",
"thisObject",
")",
"{",
"node",
"=",
"getNode",
"(",
"node",
")",
";",
"if",
"(",
"!",
"node",
")",
"throw",
"'basis.event.addHandler: can\\'t attach event listener to undefined'",
";",
"\\'",
"if",
"(",
"typeof",
"handler",
"!=",
"'function'",
")",
"throw",
"'basis.event.addHandler: handler is not a function'",
";",
"var",
"handlers",
"=",
"node",
"===",
"global",
"?",
"globalEvents",
":",
"node",
"[",
"EVENT_HOLDER",
"]",
";",
"if",
"(",
"!",
"handlers",
")",
"handlers",
"=",
"node",
"[",
"EVENT_HOLDER",
"]",
"=",
"{",
"}",
";",
"var",
"eventTypeHandlers",
"=",
"handlers",
"[",
"eventType",
"]",
";",
"var",
"handlerObject",
"=",
"{",
"handler",
":",
"handler",
",",
"thisObject",
":",
"thisObject",
"}",
";",
"}"
] |
common event handlers
Adds handler for node for eventType events.
@param {Node|Window|string} node
@param {string} eventType
@param {function(event)} handler
@param {object=} thisObject Context for handler
|
[
"common",
"event",
"handlers",
"Adds",
"handler",
"for",
"node",
"for",
"eventType",
"events",
"."
] |
8571903014b207a09d45ad2d1bfba277bf21289b
|
https://github.com/basisjs/basisjs/blob/8571903014b207a09d45ad2d1bfba277bf21289b/src/basis/dom/event.js#L594-L658
|
train
|
basisjs/basisjs
|
src/basis/dom/event.js
|
addHandlers
|
function addHandlers(node, handlers, thisObject){
node = getNode(node);
for (var eventType in handlers)
addHandler(node, eventType, handlers[eventType], thisObject);
}
|
javascript
|
function addHandlers(node, handlers, thisObject){
node = getNode(node);
for (var eventType in handlers)
addHandler(node, eventType, handlers[eventType], thisObject);
}
|
[
"function",
"addHandlers",
"(",
"node",
",",
"handlers",
",",
"thisObject",
")",
"{",
"node",
"=",
"getNode",
"(",
"node",
")",
";",
"for",
"(",
"var",
"eventType",
"in",
"handlers",
")",
"addHandler",
"(",
"node",
",",
"eventType",
",",
"handlers",
"[",
"eventType",
"]",
",",
"thisObject",
")",
";",
"}"
] |
Adds multiple handlers for node.
@param {Node|Window|string} node
@param {object} handlers
@param {object=} thisObject Context for handlers
|
[
"Adds",
"multiple",
"handlers",
"for",
"node",
"."
] |
8571903014b207a09d45ad2d1bfba277bf21289b
|
https://github.com/basisjs/basisjs/blob/8571903014b207a09d45ad2d1bfba277bf21289b/src/basis/dom/event.js#L666-L671
|
train
|
basisjs/basisjs
|
src/basis/dom/event.js
|
removeHandler
|
function removeHandler(node, eventType, handler, thisObject){
node = getNode(node);
var handlers = node === global ? globalEvents : node[EVENT_HOLDER];
if (handlers)
{
var eventTypeHandlers = handlers[eventType];
if (eventTypeHandlers)
{
for (var i = 0, item; item = eventTypeHandlers[i]; i++)
{
if (item.handler === handler && item.thisObject === thisObject)
{
// delete event handler
eventTypeHandlers.splice(i, 1);
// if there is no more handler for this event, clear it
if (!eventTypeHandlers.length)
clearHandlers(node, eventType);
return;
}
}
}
}
}
|
javascript
|
function removeHandler(node, eventType, handler, thisObject){
node = getNode(node);
var handlers = node === global ? globalEvents : node[EVENT_HOLDER];
if (handlers)
{
var eventTypeHandlers = handlers[eventType];
if (eventTypeHandlers)
{
for (var i = 0, item; item = eventTypeHandlers[i]; i++)
{
if (item.handler === handler && item.thisObject === thisObject)
{
// delete event handler
eventTypeHandlers.splice(i, 1);
// if there is no more handler for this event, clear it
if (!eventTypeHandlers.length)
clearHandlers(node, eventType);
return;
}
}
}
}
}
|
[
"function",
"removeHandler",
"(",
"node",
",",
"eventType",
",",
"handler",
",",
"thisObject",
")",
"{",
"node",
"=",
"getNode",
"(",
"node",
")",
";",
"var",
"handlers",
"=",
"node",
"===",
"global",
"?",
"globalEvents",
":",
"node",
"[",
"EVENT_HOLDER",
"]",
";",
"if",
"(",
"handlers",
")",
"{",
"var",
"eventTypeHandlers",
"=",
"handlers",
"[",
"eventType",
"]",
";",
"if",
"(",
"eventTypeHandlers",
")",
"{",
"for",
"(",
"var",
"i",
"=",
"0",
",",
"item",
";",
"item",
"=",
"eventTypeHandlers",
"[",
"i",
"]",
";",
"i",
"++",
")",
"{",
"if",
"(",
"item",
".",
"handler",
"===",
"handler",
"&&",
"item",
".",
"thisObject",
"===",
"thisObject",
")",
"{",
"eventTypeHandlers",
".",
"splice",
"(",
"i",
",",
"1",
")",
";",
"if",
"(",
"!",
"eventTypeHandlers",
".",
"length",
")",
"clearHandlers",
"(",
"node",
",",
"eventType",
")",
";",
"return",
";",
"}",
"}",
"}",
"}",
"}"
] |
Removes handler from node's handler holder.
@param {Node|Window|string} node
@param {string} eventType
@param {object} handler
@param {object=} thisObject Context for handlers
|
[
"Removes",
"handler",
"from",
"node",
"s",
"handler",
"holder",
"."
] |
8571903014b207a09d45ad2d1bfba277bf21289b
|
https://github.com/basisjs/basisjs/blob/8571903014b207a09d45ad2d1bfba277bf21289b/src/basis/dom/event.js#L680-L705
|
train
|
basisjs/basisjs
|
src/basis/dom/event.js
|
clearHandlers
|
function clearHandlers(node, eventType){
node = getNode(node);
var handlers = node === global ? globalEvents : node[EVENT_HOLDER];
if (handlers)
{
if (typeof eventType != 'string')
{
// no eventType - delete handlers for all events
for (eventType in handlers)
clearHandlers(node, eventType);
}
else
{
// delete eventType handlers
var eventTypeHandlers = handlers[eventType];
if (eventTypeHandlers)
{
if (node.removeEventListener)
node.removeEventListener(eventType, eventTypeHandlers.fireEvent, false);
else
node.detachEvent('on' + eventType, eventTypeHandlers.fireEvent);
delete handlers[eventType];
}
}
}
}
|
javascript
|
function clearHandlers(node, eventType){
node = getNode(node);
var handlers = node === global ? globalEvents : node[EVENT_HOLDER];
if (handlers)
{
if (typeof eventType != 'string')
{
// no eventType - delete handlers for all events
for (eventType in handlers)
clearHandlers(node, eventType);
}
else
{
// delete eventType handlers
var eventTypeHandlers = handlers[eventType];
if (eventTypeHandlers)
{
if (node.removeEventListener)
node.removeEventListener(eventType, eventTypeHandlers.fireEvent, false);
else
node.detachEvent('on' + eventType, eventTypeHandlers.fireEvent);
delete handlers[eventType];
}
}
}
}
|
[
"function",
"clearHandlers",
"(",
"node",
",",
"eventType",
")",
"{",
"node",
"=",
"getNode",
"(",
"node",
")",
";",
"var",
"handlers",
"=",
"node",
"===",
"global",
"?",
"globalEvents",
":",
"node",
"[",
"EVENT_HOLDER",
"]",
";",
"if",
"(",
"handlers",
")",
"{",
"if",
"(",
"typeof",
"eventType",
"!=",
"'string'",
")",
"{",
"for",
"(",
"eventType",
"in",
"handlers",
")",
"clearHandlers",
"(",
"node",
",",
"eventType",
")",
";",
"}",
"else",
"{",
"var",
"eventTypeHandlers",
"=",
"handlers",
"[",
"eventType",
"]",
";",
"if",
"(",
"eventTypeHandlers",
")",
"{",
"if",
"(",
"node",
".",
"removeEventListener",
")",
"node",
".",
"removeEventListener",
"(",
"eventType",
",",
"eventTypeHandlers",
".",
"fireEvent",
",",
"false",
")",
";",
"else",
"node",
".",
"detachEvent",
"(",
"'on'",
"+",
"eventType",
",",
"eventTypeHandlers",
".",
"fireEvent",
")",
";",
"delete",
"handlers",
"[",
"eventType",
"]",
";",
"}",
"}",
"}",
"}"
] |
Removes all node's handlers for eventType. If eventType omited, all handlers for all eventTypes will be deleted.
@param {Node|string} node
@param {string} eventType
|
[
"Removes",
"all",
"node",
"s",
"handlers",
"for",
"eventType",
".",
"If",
"eventType",
"omited",
"all",
"handlers",
"for",
"all",
"eventTypes",
"will",
"be",
"deleted",
"."
] |
8571903014b207a09d45ad2d1bfba277bf21289b
|
https://github.com/basisjs/basisjs/blob/8571903014b207a09d45ad2d1bfba277bf21289b/src/basis/dom/event.js#L712-L739
|
train
|
basisjs/basisjs
|
src/basis/dom/event.js
|
onUnload
|
function onUnload(handler, thisObject){
// deprecated in 1.4
/** @cut */ basis.dev.warn('basis.dom.event.onUnload() is deprecated, use basis.teardown() instead');
basis.teardown(handler, thisObject);
}
|
javascript
|
function onUnload(handler, thisObject){
// deprecated in 1.4
/** @cut */ basis.dev.warn('basis.dom.event.onUnload() is deprecated, use basis.teardown() instead');
basis.teardown(handler, thisObject);
}
|
[
"function",
"onUnload",
"(",
"handler",
",",
"thisObject",
")",
"{",
"basis",
".",
"dev",
".",
"warn",
"(",
"'basis.dom.event.onUnload() is deprecated, use basis.teardown() instead'",
")",
";",
"basis",
".",
"teardown",
"(",
"handler",
",",
"thisObject",
")",
";",
"}"
] |
on document load event dispatcher
Attach unload handlers for page
@param {function(event)} handler
@param {object=} thisObject Context for handler
|
[
"on",
"document",
"load",
"event",
"dispatcher",
"Attach",
"unload",
"handlers",
"for",
"page"
] |
8571903014b207a09d45ad2d1bfba277bf21289b
|
https://github.com/basisjs/basisjs/blob/8571903014b207a09d45ad2d1bfba277bf21289b/src/basis/dom/event.js#L768-L772
|
train
|
basisjs/basisjs
|
src/basis/utils/highlight.js
|
highlight
|
function highlight(text, lang, options){
function makeSafe(str){
return str
.replace(/\r\n|\n\r|\r/g, '\n')
.replace(/&/g, '&')
.replace(/</g, '<');
}
function normalize(text){
text = text
// cut first empty lines
.replace(/^(?:\s*[\n]+)+?([ \t]*)/, '$1')
.trimRight();
// fix empty strings
text = text.replace(/\n[ \t]+\n/g, '\n\n');
// normalize text offset
var minOffset = 1000;
var lines = text.split(/\n+/);
var startLine = Number(text.match(/^function/) != null); // fix for function.toString()
for (var i = startLine; i < lines.length; i++)
{
var m = lines[i].match(/^\s*/);
if (m[0].length < minOffset)
minOffset = m[0].length;
if (minOffset == 0)
break;
}
if (minOffset > 0)
text = text.replace(new RegExp('(^|\\n) {' + minOffset + '}', 'g'), '$1');
return text;
}
function defaultWrapper(line, idx){
return (
'<div class="line ' + (idx % 2 ? 'odd' : 'even') + lineClass + '">' +
'<span class="lineContent">' +
(!options.noLineNumber
? '<input class="lineNumber" value="' + lead(idx + 1, numberWidth) + '" type="none" unselectable="on" readonly="readonly" tabindex="-1" />' +
'<span class="over"></span>'
: ''
) +
line + '\r\n' +
'</span>' +
'</div>'
);
}
// MAIN PART
if (!options)
options = {};
// prepare text
var rangeStart = -1;
var rangeEnd = -1;
var rangeName = '';
if (options.range)
{
var left = makeSafe(text.substr(0, options.range[0]));
var range = makeSafe(text.substring(options.range[0], options.range[1]));
var right = makeSafe(text.substr(options.range[1]));
rangeStart = left.length;
rangeEnd = rangeStart + range.length;
rangeName = options.range[2] || 'range';
text = left + range + right;
}
else
{
text = makeSafe(text);
}
if (!options.keepFormat)
text = normalize(text || '');
var parser = LANG_PARSER[lang] || LANG_PARSER.text;
var html = parser(text, rangeStart, rangeEnd, rangeName);
var lines = html.split('\n');
var numberWidth = String(lines.length).length;
var lineClass = (options.noLineNumber ? '' : ' hasLineNumber');
var offsetRx = new RegExp('^(<span class="' + rangeName + '">)?([ \\t]+)');
lines = lines
.map(function(line){
return line.replace(offsetRx, function(m, rangeSpan, spaces){
return (rangeSpan || '') + repeat('\xA0', spaces.replace(/\t/g, ' ').length);
});
})
.map(options.wrapper || defaultWrapper);
return options.lines ? lines : lines.join('');
}
|
javascript
|
function highlight(text, lang, options){
function makeSafe(str){
return str
.replace(/\r\n|\n\r|\r/g, '\n')
.replace(/&/g, '&')
.replace(/</g, '<');
}
function normalize(text){
text = text
// cut first empty lines
.replace(/^(?:\s*[\n]+)+?([ \t]*)/, '$1')
.trimRight();
// fix empty strings
text = text.replace(/\n[ \t]+\n/g, '\n\n');
// normalize text offset
var minOffset = 1000;
var lines = text.split(/\n+/);
var startLine = Number(text.match(/^function/) != null); // fix for function.toString()
for (var i = startLine; i < lines.length; i++)
{
var m = lines[i].match(/^\s*/);
if (m[0].length < minOffset)
minOffset = m[0].length;
if (minOffset == 0)
break;
}
if (minOffset > 0)
text = text.replace(new RegExp('(^|\\n) {' + minOffset + '}', 'g'), '$1');
return text;
}
function defaultWrapper(line, idx){
return (
'<div class="line ' + (idx % 2 ? 'odd' : 'even') + lineClass + '">' +
'<span class="lineContent">' +
(!options.noLineNumber
? '<input class="lineNumber" value="' + lead(idx + 1, numberWidth) + '" type="none" unselectable="on" readonly="readonly" tabindex="-1" />' +
'<span class="over"></span>'
: ''
) +
line + '\r\n' +
'</span>' +
'</div>'
);
}
// MAIN PART
if (!options)
options = {};
// prepare text
var rangeStart = -1;
var rangeEnd = -1;
var rangeName = '';
if (options.range)
{
var left = makeSafe(text.substr(0, options.range[0]));
var range = makeSafe(text.substring(options.range[0], options.range[1]));
var right = makeSafe(text.substr(options.range[1]));
rangeStart = left.length;
rangeEnd = rangeStart + range.length;
rangeName = options.range[2] || 'range';
text = left + range + right;
}
else
{
text = makeSafe(text);
}
if (!options.keepFormat)
text = normalize(text || '');
var parser = LANG_PARSER[lang] || LANG_PARSER.text;
var html = parser(text, rangeStart, rangeEnd, rangeName);
var lines = html.split('\n');
var numberWidth = String(lines.length).length;
var lineClass = (options.noLineNumber ? '' : ' hasLineNumber');
var offsetRx = new RegExp('^(<span class="' + rangeName + '">)?([ \\t]+)');
lines = lines
.map(function(line){
return line.replace(offsetRx, function(m, rangeSpan, spaces){
return (rangeSpan || '') + repeat('\xA0', spaces.replace(/\t/g, ' ').length);
});
})
.map(options.wrapper || defaultWrapper);
return options.lines ? lines : lines.join('');
}
|
[
"function",
"highlight",
"(",
"text",
",",
"lang",
",",
"options",
")",
"{",
"function",
"makeSafe",
"(",
"str",
")",
"{",
"return",
"str",
".",
"replace",
"(",
"/",
"\\r\\n|\\n\\r|\\r",
"/",
"g",
",",
"'\\n'",
")",
".",
"\\n",
"replace",
".",
"(",
"/",
"&",
"/",
"g",
",",
"'&'",
")",
"replace",
";",
"}",
"(",
"/",
"<",
"/",
"g",
",",
"'<'",
")",
"function",
"normalize",
"(",
"text",
")",
"{",
"text",
"=",
"text",
".",
"replace",
"(",
"/",
"^(?:\\s*[\\n]+)+?([ \\t]*)",
"/",
",",
"'$1'",
")",
".",
"trimRight",
"(",
")",
";",
"text",
"=",
"text",
".",
"replace",
"(",
"/",
"\\n[ \\t]+\\n",
"/",
"g",
",",
"'\\n\\n'",
")",
";",
"\\n",
"\\n",
"var",
"minOffset",
"=",
"1000",
";",
"var",
"lines",
"=",
"text",
".",
"split",
"(",
"/",
"\\n+",
"/",
")",
";",
"var",
"startLine",
"=",
"Number",
"(",
"text",
".",
"match",
"(",
"/",
"^function",
"/",
")",
"!=",
"null",
")",
";",
"for",
"(",
"var",
"i",
"=",
"startLine",
";",
"i",
"<",
"lines",
".",
"length",
";",
"i",
"++",
")",
"{",
"var",
"m",
"=",
"lines",
"[",
"i",
"]",
".",
"match",
"(",
"/",
"^\\s*",
"/",
")",
";",
"if",
"(",
"m",
"[",
"0",
"]",
".",
"length",
"<",
"minOffset",
")",
"minOffset",
"=",
"m",
"[",
"0",
"]",
".",
"length",
";",
"if",
"(",
"minOffset",
"==",
"0",
")",
"break",
";",
"}",
"}",
"if",
"(",
"minOffset",
">",
"0",
")",
"text",
"=",
"text",
".",
"replace",
"(",
"new",
"RegExp",
"(",
"'(^|\\\\n) {'",
"+",
"\\\\",
"+",
"minOffset",
",",
"'}'",
")",
",",
"'g'",
")",
";",
"'$1'",
"return",
"text",
";",
"function",
"defaultWrapper",
"(",
"line",
",",
"idx",
")",
"{",
"return",
"(",
"'<div class=\"line '",
"+",
"(",
"idx",
"%",
"2",
"?",
"'odd'",
":",
"'even'",
")",
"+",
"lineClass",
"+",
"'\">'",
"+",
"'<span class=\"lineContent\">'",
"+",
"(",
"!",
"options",
".",
"noLineNumber",
"?",
"'<input class=\"lineNumber\" value=\"'",
"+",
"lead",
"(",
"idx",
"+",
"1",
",",
"numberWidth",
")",
"+",
"'\" type=\"none\" unselectable=\"on\" readonly=\"readonly\" tabindex=\"-1\" />'",
"+",
"'<span class=\"over\"></span>'",
":",
"''",
")",
"+",
"line",
"+",
"'\\r\\n'",
"+",
"\\r",
"+",
"\\n",
")",
";",
"}",
"'</span>'",
"'</div>'",
"if",
"(",
"!",
"options",
")",
"options",
"=",
"{",
"}",
";",
"var",
"rangeStart",
"=",
"-",
"1",
";",
"var",
"rangeEnd",
"=",
"-",
"1",
";",
"var",
"rangeName",
"=",
"''",
";",
"if",
"(",
"options",
".",
"range",
")",
"{",
"var",
"left",
"=",
"makeSafe",
"(",
"text",
".",
"substr",
"(",
"0",
",",
"options",
".",
"range",
"[",
"0",
"]",
")",
")",
";",
"var",
"range",
"=",
"makeSafe",
"(",
"text",
".",
"substring",
"(",
"options",
".",
"range",
"[",
"0",
"]",
",",
"options",
".",
"range",
"[",
"1",
"]",
")",
")",
";",
"var",
"right",
"=",
"makeSafe",
"(",
"text",
".",
"substr",
"(",
"options",
".",
"range",
"[",
"1",
"]",
")",
")",
";",
"rangeStart",
"=",
"left",
".",
"length",
";",
"rangeEnd",
"=",
"rangeStart",
"+",
"range",
".",
"length",
";",
"rangeName",
"=",
"options",
".",
"range",
"[",
"2",
"]",
"||",
"'range'",
";",
"text",
"=",
"left",
"+",
"range",
"+",
"right",
";",
"}",
"else",
"{",
"text",
"=",
"makeSafe",
"(",
"text",
")",
";",
"}",
"if",
"(",
"!",
"options",
".",
"keepFormat",
")",
"text",
"=",
"normalize",
"(",
"text",
"||",
"''",
")",
";",
"var",
"parser",
"=",
"LANG_PARSER",
"[",
"lang",
"]",
"||",
"LANG_PARSER",
".",
"text",
";",
"var",
"html",
"=",
"parser",
"(",
"text",
",",
"rangeStart",
",",
"rangeEnd",
",",
"rangeName",
")",
";",
"}"
] |
Function that produce html code from text.
@param {string} text
@param {string=} lang
@param {object=} options
@return {string}
|
[
"Function",
"that",
"produce",
"html",
"code",
"from",
"text",
"."
] |
8571903014b207a09d45ad2d1bfba277bf21289b
|
https://github.com/basisjs/basisjs/blob/8571903014b207a09d45ad2d1bfba277bf21289b/src/basis/utils/highlight.js#L370-L470
|
train
|
basisjs/basisjs
|
src/basis/data.js
|
function(value){
var oldValue = this.value;
var newValue = this.proxy ? this.proxy(value) : value;
var changed = newValue !== oldValue;
if (changed)
{
if (this.setNullOnEmitterDestroy)
{
if (oldValue instanceof Emitter)
oldValue.removeHandler(VALUE_EMMITER_DESTROY_HANDLER, this);
if (newValue instanceof Emitter)
newValue.addHandler(VALUE_EMMITER_DESTROY_HANDLER, this);
}
this.value = newValue;
if (!this.locked)
this.emit_change(oldValue);
}
return changed;
}
|
javascript
|
function(value){
var oldValue = this.value;
var newValue = this.proxy ? this.proxy(value) : value;
var changed = newValue !== oldValue;
if (changed)
{
if (this.setNullOnEmitterDestroy)
{
if (oldValue instanceof Emitter)
oldValue.removeHandler(VALUE_EMMITER_DESTROY_HANDLER, this);
if (newValue instanceof Emitter)
newValue.addHandler(VALUE_EMMITER_DESTROY_HANDLER, this);
}
this.value = newValue;
if (!this.locked)
this.emit_change(oldValue);
}
return changed;
}
|
[
"function",
"(",
"value",
")",
"{",
"var",
"oldValue",
"=",
"this",
".",
"value",
";",
"var",
"newValue",
"=",
"this",
".",
"proxy",
"?",
"this",
".",
"proxy",
"(",
"value",
")",
":",
"value",
";",
"var",
"changed",
"=",
"newValue",
"!==",
"oldValue",
";",
"if",
"(",
"changed",
")",
"{",
"if",
"(",
"this",
".",
"setNullOnEmitterDestroy",
")",
"{",
"if",
"(",
"oldValue",
"instanceof",
"Emitter",
")",
"oldValue",
".",
"removeHandler",
"(",
"VALUE_EMMITER_DESTROY_HANDLER",
",",
"this",
")",
";",
"if",
"(",
"newValue",
"instanceof",
"Emitter",
")",
"newValue",
".",
"addHandler",
"(",
"VALUE_EMMITER_DESTROY_HANDLER",
",",
"this",
")",
";",
"}",
"this",
".",
"value",
"=",
"newValue",
";",
"if",
"(",
"!",
"this",
".",
"locked",
")",
"this",
".",
"emit_change",
"(",
"oldValue",
")",
";",
"}",
"return",
"changed",
";",
"}"
] |
Sets new value but only if value is not equivalent to current
property's value. Change event emit if value was changed.
@param {*} value New value for property.
@return {boolean} Returns true if value was changed.
|
[
"Sets",
"new",
"value",
"but",
"only",
"if",
"value",
"is",
"not",
"equivalent",
"to",
"current",
"property",
"s",
"value",
".",
"Change",
"event",
"emit",
"if",
"value",
"was",
"changed",
"."
] |
8571903014b207a09d45ad2d1bfba277bf21289b
|
https://github.com/basisjs/basisjs/blob/8571903014b207a09d45ad2d1bfba277bf21289b/src/basis/data.js#L257-L279
|
train
|
|
basisjs/basisjs
|
src/basis/data.js
|
function(){
if (this.locked)
{
this.locked--;
if (!this.locked)
{
var lockedValue = this.lockedValue_;
this.lockedValue_ = null;
if (this.value !== lockedValue)
this.emit_change(lockedValue);
}
}
}
|
javascript
|
function(){
if (this.locked)
{
this.locked--;
if (!this.locked)
{
var lockedValue = this.lockedValue_;
this.lockedValue_ = null;
if (this.value !== lockedValue)
this.emit_change(lockedValue);
}
}
}
|
[
"function",
"(",
")",
"{",
"if",
"(",
"this",
".",
"locked",
")",
"{",
"this",
".",
"locked",
"--",
";",
"if",
"(",
"!",
"this",
".",
"locked",
")",
"{",
"var",
"lockedValue",
"=",
"this",
".",
"lockedValue_",
";",
"this",
".",
"lockedValue_",
"=",
"null",
";",
"if",
"(",
"this",
".",
"value",
"!==",
"lockedValue",
")",
"this",
".",
"emit_change",
"(",
"lockedValue",
")",
";",
"}",
"}",
"}"
] |
Unlocks value for change event fire. If value changed during object
was locked, than change event fires.
|
[
"Unlocks",
"value",
"for",
"change",
"event",
"fire",
".",
"If",
"value",
"changed",
"during",
"object",
"was",
"locked",
"than",
"change",
"event",
"fires",
"."
] |
8571903014b207a09d45ad2d1bfba277bf21289b
|
https://github.com/basisjs/basisjs/blob/8571903014b207a09d45ad2d1bfba277bf21289b/src/basis/data.js#L310-L325
|
train
|
|
basisjs/basisjs
|
src/basis/data.js
|
function(fn){
// obsolete in 1.4
/** @cut */ if (arguments.length > 1)
/** @cut */ basis.dev.warn('basis.data.Value#as() doesn\'t accept deferred flag as second parameter anymore. Use value.as(fn).deferred() instead.');
if (!fn || fn === $self)
return this;
if (typeof fn == 'string')
fn = basis.getter(fn);
if (this.links_)
{
// try to find value with the same function
var cursor = this;
var fnId = fn[GETTER_ID] || String(fn);
while (cursor = cursor.links_)
{
var context = cursor.context;
if (context instanceof ReadOnlyValue &&
context.proxy &&
(context.proxy[GETTER_ID] || String(context.proxy)) == fnId) // compare functions by id
{
/** @cut */ context = devWrap(context);
return context;
}
}
}
// create transform value
var result = new ReadOnlyValue({
proxy: fn,
value: this.value
});
/** @cut */ basis.dev.setInfo(result, 'sourceInfo', {
/** @cut */ type: 'Value#as',
/** @cut */ source: this,
/** @cut */ sourceTarget: this.value,
/** @cut */ transform: fn
/** @cut */ });
/** @cut */ if (fn.retarget)
/** @cut */ {
/** @cut */ result.proxy = function(value){
/** @cut */ value = fn(value);
/** @cut */ basis.dev.patchInfo(result, 'sourceInfo', {
/** @cut */ sourceTarget: value
/** @cut */ });
/** @cut */ return value;
/** @cut */ };
/** @cut */ result.proxy[GETTER_ID] = fn[GETTER_ID]; // set the same GETTER_ID for correct search in links_
/** @cut */ }
this.link(result, valueSyncAs, true, result.destroy);
return result;
}
|
javascript
|
function(fn){
// obsolete in 1.4
/** @cut */ if (arguments.length > 1)
/** @cut */ basis.dev.warn('basis.data.Value#as() doesn\'t accept deferred flag as second parameter anymore. Use value.as(fn).deferred() instead.');
if (!fn || fn === $self)
return this;
if (typeof fn == 'string')
fn = basis.getter(fn);
if (this.links_)
{
// try to find value with the same function
var cursor = this;
var fnId = fn[GETTER_ID] || String(fn);
while (cursor = cursor.links_)
{
var context = cursor.context;
if (context instanceof ReadOnlyValue &&
context.proxy &&
(context.proxy[GETTER_ID] || String(context.proxy)) == fnId) // compare functions by id
{
/** @cut */ context = devWrap(context);
return context;
}
}
}
// create transform value
var result = new ReadOnlyValue({
proxy: fn,
value: this.value
});
/** @cut */ basis.dev.setInfo(result, 'sourceInfo', {
/** @cut */ type: 'Value#as',
/** @cut */ source: this,
/** @cut */ sourceTarget: this.value,
/** @cut */ transform: fn
/** @cut */ });
/** @cut */ if (fn.retarget)
/** @cut */ {
/** @cut */ result.proxy = function(value){
/** @cut */ value = fn(value);
/** @cut */ basis.dev.patchInfo(result, 'sourceInfo', {
/** @cut */ sourceTarget: value
/** @cut */ });
/** @cut */ return value;
/** @cut */ };
/** @cut */ result.proxy[GETTER_ID] = fn[GETTER_ID]; // set the same GETTER_ID for correct search in links_
/** @cut */ }
this.link(result, valueSyncAs, true, result.destroy);
return result;
}
|
[
"function",
"(",
"fn",
")",
"{",
"if",
"(",
"arguments",
".",
"length",
">",
"1",
")",
"basis",
".",
"dev",
".",
"warn",
"(",
"'basis.data.Value#as() doesn\\'t accept deferred flag as second parameter anymore. Use value.as(fn).deferred() instead.'",
")",
";",
"\\'",
"if",
"(",
"!",
"fn",
"||",
"fn",
"===",
"$self",
")",
"return",
"this",
";",
"if",
"(",
"typeof",
"fn",
"==",
"'string'",
")",
"fn",
"=",
"basis",
".",
"getter",
"(",
"fn",
")",
";",
"if",
"(",
"this",
".",
"links_",
")",
"{",
"var",
"cursor",
"=",
"this",
";",
"var",
"fnId",
"=",
"fn",
"[",
"GETTER_ID",
"]",
"||",
"String",
"(",
"fn",
")",
";",
"while",
"(",
"cursor",
"=",
"cursor",
".",
"links_",
")",
"{",
"var",
"context",
"=",
"cursor",
".",
"context",
";",
"if",
"(",
"context",
"instanceof",
"ReadOnlyValue",
"&&",
"context",
".",
"proxy",
"&&",
"(",
"context",
".",
"proxy",
"[",
"GETTER_ID",
"]",
"||",
"String",
"(",
"context",
".",
"proxy",
")",
")",
"==",
"fnId",
")",
"{",
"context",
"=",
"devWrap",
"(",
"context",
")",
";",
"return",
"context",
";",
"}",
"}",
"}",
"var",
"result",
"=",
"new",
"ReadOnlyValue",
"(",
"{",
"proxy",
":",
"fn",
",",
"value",
":",
"this",
".",
"value",
"}",
")",
";",
"basis",
".",
"dev",
".",
"setInfo",
"(",
"result",
",",
"'sourceInfo'",
",",
"{",
"type",
":",
"'Value#as'",
",",
"source",
":",
"this",
",",
"sourceTarget",
":",
"this",
".",
"value",
",",
"transform",
":",
"fn",
"}",
")",
";",
"if",
"(",
"fn",
".",
"retarget",
")",
"{",
"result",
".",
"proxy",
"=",
"function",
"(",
"value",
")",
"{",
"value",
"=",
"fn",
"(",
"value",
")",
";",
"basis",
".",
"dev",
".",
"patchInfo",
"(",
"result",
",",
"'sourceInfo'",
",",
"{",
"sourceTarget",
":",
"value",
"}",
")",
";",
"return",
"value",
";",
"}",
";",
"result",
".",
"proxy",
"[",
"GETTER_ID",
"]",
"=",
"fn",
"[",
"GETTER_ID",
"]",
";",
"}",
"this",
".",
"link",
"(",
"result",
",",
"valueSyncAs",
",",
"true",
",",
"result",
".",
"destroy",
")",
";",
"}"
] |
Returns Value instance which value equals to transformed via fn function.
@param {function(value)} fn
@return {basis.data.Value}
|
[
"Returns",
"Value",
"instance",
"which",
"value",
"equals",
"to",
"transformed",
"via",
"fn",
"function",
"."
] |
8571903014b207a09d45ad2d1bfba277bf21289b
|
https://github.com/basisjs/basisjs/blob/8571903014b207a09d45ad2d1bfba277bf21289b/src/basis/data.js#L481-L540
|
train
|
|
basisjs/basisjs
|
src/basis/data.js
|
isConnected
|
function isConnected(a, b){
while (b && b !== a && b !== b.delegate)
b = b.delegate;
return b === a;
}
|
javascript
|
function isConnected(a, b){
while (b && b !== a && b !== b.delegate)
b = b.delegate;
return b === a;
}
|
[
"function",
"isConnected",
"(",
"a",
",",
"b",
")",
"{",
"while",
"(",
"b",
"&&",
"b",
"!==",
"a",
"&&",
"b",
"!==",
"b",
".",
"delegate",
")",
"b",
"=",
"b",
".",
"delegate",
";",
"return",
"b",
"===",
"a",
";",
"}"
] |
Returns true if object is connected to another object through delegate chain.
@param {basis.data.Object} a
@param {basis.data.Object} b
@return {boolean} Whether objects are connected.
|
[
"Returns",
"true",
"if",
"object",
"is",
"connected",
"to",
"another",
"object",
"through",
"delegate",
"chain",
"."
] |
8571903014b207a09d45ad2d1bfba277bf21289b
|
https://github.com/basisjs/basisjs/blob/8571903014b207a09d45ad2d1bfba277bf21289b/src/basis/data.js#L1139-L1144
|
train
|
basisjs/basisjs
|
src/basis/data.js
|
applyDelegateChanges
|
function applyDelegateChanges(object, oldRoot, oldTarget){
var delegate = object.delegate;
if (delegate)
{
object.root = delegate.root;
object.target = delegate.target;
object.data = delegate.data;
object.state = delegate.state;
}
// fire event if root changed
if (!isEqual(object.root, oldRoot))
{
var rootListenHandler = object.listen.root;
if (rootListenHandler)
{
if (oldRoot && !isEqual(oldRoot, object))
oldRoot.removeHandler(rootListenHandler, object);
if (object.root && !isEqual(object.root, object))
object.root.addHandler(rootListenHandler, object);
}
object.emit_rootChanged(oldRoot);
}
// fire event if target changed
if (!isEqual(object.target, oldTarget))
{
var targetListenHandler = object.listen.target;
if (targetListenHandler)
{
if (oldTarget && !isEqual(oldTarget, object))
oldTarget.removeHandler(targetListenHandler, object);
if (object.target && !isEqual(object.target, object))
object.target.addHandler(targetListenHandler, object);
}
object.emit_targetChanged(oldTarget);
}
var cursor = object.delegates_;
while (cursor)
{
if (cursor.delegate)
applyDelegateChanges(cursor.delegate, oldRoot, oldTarget);
cursor = cursor.next;
}
}
|
javascript
|
function applyDelegateChanges(object, oldRoot, oldTarget){
var delegate = object.delegate;
if (delegate)
{
object.root = delegate.root;
object.target = delegate.target;
object.data = delegate.data;
object.state = delegate.state;
}
// fire event if root changed
if (!isEqual(object.root, oldRoot))
{
var rootListenHandler = object.listen.root;
if (rootListenHandler)
{
if (oldRoot && !isEqual(oldRoot, object))
oldRoot.removeHandler(rootListenHandler, object);
if (object.root && !isEqual(object.root, object))
object.root.addHandler(rootListenHandler, object);
}
object.emit_rootChanged(oldRoot);
}
// fire event if target changed
if (!isEqual(object.target, oldTarget))
{
var targetListenHandler = object.listen.target;
if (targetListenHandler)
{
if (oldTarget && !isEqual(oldTarget, object))
oldTarget.removeHandler(targetListenHandler, object);
if (object.target && !isEqual(object.target, object))
object.target.addHandler(targetListenHandler, object);
}
object.emit_targetChanged(oldTarget);
}
var cursor = object.delegates_;
while (cursor)
{
if (cursor.delegate)
applyDelegateChanges(cursor.delegate, oldRoot, oldTarget);
cursor = cursor.next;
}
}
|
[
"function",
"applyDelegateChanges",
"(",
"object",
",",
"oldRoot",
",",
"oldTarget",
")",
"{",
"var",
"delegate",
"=",
"object",
".",
"delegate",
";",
"if",
"(",
"delegate",
")",
"{",
"object",
".",
"root",
"=",
"delegate",
".",
"root",
";",
"object",
".",
"target",
"=",
"delegate",
".",
"target",
";",
"object",
".",
"data",
"=",
"delegate",
".",
"data",
";",
"object",
".",
"state",
"=",
"delegate",
".",
"state",
";",
"}",
"if",
"(",
"!",
"isEqual",
"(",
"object",
".",
"root",
",",
"oldRoot",
")",
")",
"{",
"var",
"rootListenHandler",
"=",
"object",
".",
"listen",
".",
"root",
";",
"if",
"(",
"rootListenHandler",
")",
"{",
"if",
"(",
"oldRoot",
"&&",
"!",
"isEqual",
"(",
"oldRoot",
",",
"object",
")",
")",
"oldRoot",
".",
"removeHandler",
"(",
"rootListenHandler",
",",
"object",
")",
";",
"if",
"(",
"object",
".",
"root",
"&&",
"!",
"isEqual",
"(",
"object",
".",
"root",
",",
"object",
")",
")",
"object",
".",
"root",
".",
"addHandler",
"(",
"rootListenHandler",
",",
"object",
")",
";",
"}",
"object",
".",
"emit_rootChanged",
"(",
"oldRoot",
")",
";",
"}",
"if",
"(",
"!",
"isEqual",
"(",
"object",
".",
"target",
",",
"oldTarget",
")",
")",
"{",
"var",
"targetListenHandler",
"=",
"object",
".",
"listen",
".",
"target",
";",
"if",
"(",
"targetListenHandler",
")",
"{",
"if",
"(",
"oldTarget",
"&&",
"!",
"isEqual",
"(",
"oldTarget",
",",
"object",
")",
")",
"oldTarget",
".",
"removeHandler",
"(",
"targetListenHandler",
",",
"object",
")",
";",
"if",
"(",
"object",
".",
"target",
"&&",
"!",
"isEqual",
"(",
"object",
".",
"target",
",",
"object",
")",
")",
"object",
".",
"target",
".",
"addHandler",
"(",
"targetListenHandler",
",",
"object",
")",
";",
"}",
"object",
".",
"emit_targetChanged",
"(",
"oldTarget",
")",
";",
"}",
"var",
"cursor",
"=",
"object",
".",
"delegates_",
";",
"while",
"(",
"cursor",
")",
"{",
"if",
"(",
"cursor",
".",
"delegate",
")",
"applyDelegateChanges",
"(",
"cursor",
".",
"delegate",
",",
"oldRoot",
",",
"oldTarget",
")",
";",
"cursor",
"=",
"cursor",
".",
"next",
";",
"}",
"}"
] |
Apply changes for all delegate graph
|
[
"Apply",
"changes",
"for",
"all",
"delegate",
"graph"
] |
8571903014b207a09d45ad2d1bfba277bf21289b
|
https://github.com/basisjs/basisjs/blob/8571903014b207a09d45ad2d1bfba277bf21289b/src/basis/data.js#L1149-L1201
|
train
|
basisjs/basisjs
|
src/basis/data.js
|
function(data){
if (this.delegate)
return this.root.update(data);
if (data)
{
var delta = {};
var changed = false;
for (var prop in data)
if (this.data[prop] !== data[prop])
{
changed = true;
delta[prop] = this.data[prop];
this.data[prop] = data[prop];
}
if (changed)
{
this.emit_update(delta);
return delta;
}
}
return false;
}
|
javascript
|
function(data){
if (this.delegate)
return this.root.update(data);
if (data)
{
var delta = {};
var changed = false;
for (var prop in data)
if (this.data[prop] !== data[prop])
{
changed = true;
delta[prop] = this.data[prop];
this.data[prop] = data[prop];
}
if (changed)
{
this.emit_update(delta);
return delta;
}
}
return false;
}
|
[
"function",
"(",
"data",
")",
"{",
"if",
"(",
"this",
".",
"delegate",
")",
"return",
"this",
".",
"root",
".",
"update",
"(",
"data",
")",
";",
"if",
"(",
"data",
")",
"{",
"var",
"delta",
"=",
"{",
"}",
";",
"var",
"changed",
"=",
"false",
";",
"for",
"(",
"var",
"prop",
"in",
"data",
")",
"if",
"(",
"this",
".",
"data",
"[",
"prop",
"]",
"!==",
"data",
"[",
"prop",
"]",
")",
"{",
"changed",
"=",
"true",
";",
"delta",
"[",
"prop",
"]",
"=",
"this",
".",
"data",
"[",
"prop",
"]",
";",
"this",
".",
"data",
"[",
"prop",
"]",
"=",
"data",
"[",
"prop",
"]",
";",
"}",
"if",
"(",
"changed",
")",
"{",
"this",
".",
"emit_update",
"(",
"delta",
")",
";",
"return",
"delta",
";",
"}",
"}",
"return",
"false",
";",
"}"
] |
Handle changing object data. Fires update event only if something was changed.
@param {Object} data New values for object data holder (this.data).
@return {Object|boolean} Delta if object data (this.data) was updated or false otherwise.
|
[
"Handle",
"changing",
"object",
"data",
".",
"Fires",
"update",
"event",
"only",
"if",
"something",
"was",
"changed",
"."
] |
8571903014b207a09d45ad2d1bfba277bf21289b
|
https://github.com/basisjs/basisjs/blob/8571903014b207a09d45ad2d1bfba277bf21289b/src/basis/data.js#L1563-L1588
|
train
|
|
basisjs/basisjs
|
src/basis/data.js
|
getDatasetDelta
|
function getDatasetDelta(a, b){
if (!a || !a.itemCount)
{
if (b && b.itemCount)
return {
inserted: b.getItems()
};
}
else
{
if (!b || !b.itemCount)
{
if (a.itemCount)
return {
deleted: a.getItems()
};
}
else
{
var inserted = [];
var deleted = [];
for (var key in a.items_)
{
var item = a.items_[key];
if (item.basisObjectId in b.items_ == false)
deleted.push(item);
}
for (var key in b.items_)
{
var item = b.items_[key];
if (item.basisObjectId in a.items_ == false)
inserted.push(item);
}
return getDelta(inserted, deleted);
}
}
}
|
javascript
|
function getDatasetDelta(a, b){
if (!a || !a.itemCount)
{
if (b && b.itemCount)
return {
inserted: b.getItems()
};
}
else
{
if (!b || !b.itemCount)
{
if (a.itemCount)
return {
deleted: a.getItems()
};
}
else
{
var inserted = [];
var deleted = [];
for (var key in a.items_)
{
var item = a.items_[key];
if (item.basisObjectId in b.items_ == false)
deleted.push(item);
}
for (var key in b.items_)
{
var item = b.items_[key];
if (item.basisObjectId in a.items_ == false)
inserted.push(item);
}
return getDelta(inserted, deleted);
}
}
}
|
[
"function",
"getDatasetDelta",
"(",
"a",
",",
"b",
")",
"{",
"if",
"(",
"!",
"a",
"||",
"!",
"a",
".",
"itemCount",
")",
"{",
"if",
"(",
"b",
"&&",
"b",
".",
"itemCount",
")",
"return",
"{",
"inserted",
":",
"b",
".",
"getItems",
"(",
")",
"}",
";",
"}",
"else",
"{",
"if",
"(",
"!",
"b",
"||",
"!",
"b",
".",
"itemCount",
")",
"{",
"if",
"(",
"a",
".",
"itemCount",
")",
"return",
"{",
"deleted",
":",
"a",
".",
"getItems",
"(",
")",
"}",
";",
"}",
"else",
"{",
"var",
"inserted",
"=",
"[",
"]",
";",
"var",
"deleted",
"=",
"[",
"]",
";",
"for",
"(",
"var",
"key",
"in",
"a",
".",
"items_",
")",
"{",
"var",
"item",
"=",
"a",
".",
"items_",
"[",
"key",
"]",
";",
"if",
"(",
"item",
".",
"basisObjectId",
"in",
"b",
".",
"items_",
"==",
"false",
")",
"deleted",
".",
"push",
"(",
"item",
")",
";",
"}",
"for",
"(",
"var",
"key",
"in",
"b",
".",
"items_",
")",
"{",
"var",
"item",
"=",
"b",
".",
"items_",
"[",
"key",
"]",
";",
"if",
"(",
"item",
".",
"basisObjectId",
"in",
"a",
".",
"items_",
"==",
"false",
")",
"inserted",
".",
"push",
"(",
"item",
")",
";",
"}",
"return",
"getDelta",
"(",
"inserted",
",",
"deleted",
")",
";",
"}",
"}",
"}"
] |
Returns delta betwwen dataset, that could be used for event
@return {object|undefined}
|
[
"Returns",
"delta",
"betwwen",
"dataset",
"that",
"could",
"be",
"used",
"for",
"event"
] |
8571903014b207a09d45ad2d1bfba277bf21289b
|
https://github.com/basisjs/basisjs/blob/8571903014b207a09d45ad2d1bfba277bf21289b/src/basis/data.js#L1741-L1780
|
train
|
basisjs/basisjs
|
src/basis/data.js
|
function(count){
var result = [];
if (count)
for (var objectId in this.items_)
if (result.push(this.items_[objectId]) >= count)
break;
return result;
}
|
javascript
|
function(count){
var result = [];
if (count)
for (var objectId in this.items_)
if (result.push(this.items_[objectId]) >= count)
break;
return result;
}
|
[
"function",
"(",
"count",
")",
"{",
"var",
"result",
"=",
"[",
"]",
";",
"if",
"(",
"count",
")",
"for",
"(",
"var",
"objectId",
"in",
"this",
".",
"items_",
")",
"if",
"(",
"result",
".",
"push",
"(",
"this",
".",
"items_",
"[",
"objectId",
"]",
")",
">=",
"count",
")",
"break",
";",
"return",
"result",
";",
"}"
] |
Returns some N items from dataset if exists.
@param {number} count Max length of resulting array.
@return {Array.<basis.data.Object>}
|
[
"Returns",
"some",
"N",
"items",
"from",
"dataset",
"if",
"exists",
"."
] |
8571903014b207a09d45ad2d1bfba277bf21289b
|
https://github.com/basisjs/basisjs/blob/8571903014b207a09d45ad2d1bfba277bf21289b/src/basis/data.js#L2072-L2081
|
train
|
|
basisjs/basisjs
|
src/basis/data.js
|
function(fn){
var items = this.getItems();
for (var i = 0; i < items.length; i++)
fn(items[i]);
}
|
javascript
|
function(fn){
var items = this.getItems();
for (var i = 0; i < items.length; i++)
fn(items[i]);
}
|
[
"function",
"(",
"fn",
")",
"{",
"var",
"items",
"=",
"this",
".",
"getItems",
"(",
")",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"items",
".",
"length",
";",
"i",
"++",
")",
"fn",
"(",
"items",
"[",
"i",
"]",
")",
";",
"}"
] |
Call fn for every item in dataset.
@param {function(item)} fn
|
[
"Call",
"fn",
"for",
"every",
"item",
"in",
"dataset",
"."
] |
8571903014b207a09d45ad2d1bfba277bf21289b
|
https://github.com/basisjs/basisjs/blob/8571903014b207a09d45ad2d1bfba277bf21289b/src/basis/data.js#L2087-L2092
|
train
|
|
basisjs/basisjs
|
src/basis/data.js
|
function(items){
var delta = this.set(items) || {};
var deleted = delta.deleted;
Dataset.setAccumulateState(true);
if (deleted)
for (var i = 0, object; object = deleted[i]; i++)
object.destroy();
Dataset.setAccumulateState(false);
return delta.inserted;
}
|
javascript
|
function(items){
var delta = this.set(items) || {};
var deleted = delta.deleted;
Dataset.setAccumulateState(true);
if (deleted)
for (var i = 0, object; object = deleted[i]; i++)
object.destroy();
Dataset.setAccumulateState(false);
return delta.inserted;
}
|
[
"function",
"(",
"items",
")",
"{",
"var",
"delta",
"=",
"this",
".",
"set",
"(",
"items",
")",
"||",
"{",
"}",
";",
"var",
"deleted",
"=",
"delta",
".",
"deleted",
";",
"Dataset",
".",
"setAccumulateState",
"(",
"true",
")",
";",
"if",
"(",
"deleted",
")",
"for",
"(",
"var",
"i",
"=",
"0",
",",
"object",
";",
"object",
"=",
"deleted",
"[",
"i",
"]",
";",
"i",
"++",
")",
"object",
".",
"destroy",
"(",
")",
";",
"Dataset",
".",
"setAccumulateState",
"(",
"false",
")",
";",
"return",
"delta",
".",
"inserted",
";",
"}"
] |
Set new item set and destroy deleted items.
@param {Array.<basis.data.Object>} items
@return {Array.<basis.data.Object>|undefined} Returns array of inserted items or undefined if nothing inserted.
|
[
"Set",
"new",
"item",
"set",
"and",
"destroy",
"deleted",
"items",
"."
] |
8571903014b207a09d45ad2d1bfba277bf21289b
|
https://github.com/basisjs/basisjs/blob/8571903014b207a09d45ad2d1bfba277bf21289b/src/basis/data.js#L2323-L2334
|
train
|
|
basisjs/basisjs
|
src/basis/data.js
|
function(){
Dataset.flushChanges(this);
var deleted = this.getItems();
var listenHandler = this.listen.item;
var delta;
if (deleted.length)
{
if (listenHandler)
for (var i = 0; i < deleted.length; i++)
deleted[i].removeHandler(listenHandler, this);
this.emit_itemsChanged(delta = {
deleted: deleted
});
this.members_ = {};
}
return delta;
}
|
javascript
|
function(){
Dataset.flushChanges(this);
var deleted = this.getItems();
var listenHandler = this.listen.item;
var delta;
if (deleted.length)
{
if (listenHandler)
for (var i = 0; i < deleted.length; i++)
deleted[i].removeHandler(listenHandler, this);
this.emit_itemsChanged(delta = {
deleted: deleted
});
this.members_ = {};
}
return delta;
}
|
[
"function",
"(",
")",
"{",
"Dataset",
".",
"flushChanges",
"(",
"this",
")",
";",
"var",
"deleted",
"=",
"this",
".",
"getItems",
"(",
")",
";",
"var",
"listenHandler",
"=",
"this",
".",
"listen",
".",
"item",
";",
"var",
"delta",
";",
"if",
"(",
"deleted",
".",
"length",
")",
"{",
"if",
"(",
"listenHandler",
")",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"deleted",
".",
"length",
";",
"i",
"++",
")",
"deleted",
"[",
"i",
"]",
".",
"removeHandler",
"(",
"listenHandler",
",",
"this",
")",
";",
"this",
".",
"emit_itemsChanged",
"(",
"delta",
"=",
"{",
"deleted",
":",
"deleted",
"}",
")",
";",
"this",
".",
"members_",
"=",
"{",
"}",
";",
"}",
"return",
"delta",
";",
"}"
] |
Removes all items from dataset.
|
[
"Removes",
"all",
"items",
"from",
"dataset",
"."
] |
8571903014b207a09d45ad2d1bfba277bf21289b
|
https://github.com/basisjs/basisjs/blob/8571903014b207a09d45ad2d1bfba277bf21289b/src/basis/data.js#L2339-L2360
|
train
|
|
basisjs/basisjs
|
src/basis/l10n.js
|
resolveToken
|
function resolveToken(path){
if (path.charAt(0) == '#')
{
// return index by absolute index
return tokenIndex[parseInt(path.substr(1), 36)];
}
else
{
var parts = path.match(/^(.+?)@(.+)$/);
if (parts)
return resolveDictionary(basis.path.resolve(parts[2])).token(parts[1]);
/** @cut */ basis.dev.warn('basis.l10n.token accepts token references in format `token.path@path/to/dict.l10n` only');
}
}
|
javascript
|
function resolveToken(path){
if (path.charAt(0) == '#')
{
// return index by absolute index
return tokenIndex[parseInt(path.substr(1), 36)];
}
else
{
var parts = path.match(/^(.+?)@(.+)$/);
if (parts)
return resolveDictionary(basis.path.resolve(parts[2])).token(parts[1]);
/** @cut */ basis.dev.warn('basis.l10n.token accepts token references in format `token.path@path/to/dict.l10n` only');
}
}
|
[
"function",
"resolveToken",
"(",
"path",
")",
"{",
"if",
"(",
"path",
".",
"charAt",
"(",
"0",
")",
"==",
"'#'",
")",
"{",
"return",
"tokenIndex",
"[",
"parseInt",
"(",
"path",
".",
"substr",
"(",
"1",
")",
",",
"36",
")",
"]",
";",
"}",
"else",
"{",
"var",
"parts",
"=",
"path",
".",
"match",
"(",
"/",
"^(.+?)@(.+)$",
"/",
")",
";",
"if",
"(",
"parts",
")",
"return",
"resolveDictionary",
"(",
"basis",
".",
"path",
".",
"resolve",
"(",
"parts",
"[",
"2",
"]",
")",
")",
".",
"token",
"(",
"parts",
"[",
"1",
"]",
")",
";",
"basis",
".",
"dev",
".",
"warn",
"(",
"'basis.l10n.token accepts token references in format `token.path@path/to/dict.l10n` only'",
")",
";",
"}",
"}"
] |
Returns token for path. Path also may be index reference, that used in production.
@example
basis.l10n.token('token.path@path/to/dict'); // token by name and dictionary location
basis.l10n.token('#123'); // get token by base 36 index, use in production
@name basis.l10n.token
@param {string} path
@return {basis.l10n.Token}
|
[
"Returns",
"token",
"for",
"path",
".",
"Path",
"also",
"may",
"be",
"index",
"reference",
"that",
"used",
"in",
"production",
"."
] |
8571903014b207a09d45ad2d1bfba277bf21289b
|
https://github.com/basisjs/basisjs/blob/8571903014b207a09d45ad2d1bfba277bf21289b/src/basis/l10n.js#L449-L464
|
train
|
basisjs/basisjs
|
src/basis/l10n.js
|
function(){
for (var tokenName in this.tokens)
{
var token = this.tokens[tokenName];
var descriptor = this.getDescriptor(tokenName) || NULL_DESCRIPTOR;
var savedType = token.getType();
token.descriptor = descriptor;
if (token.value !== descriptor.value)
{
// on value change apply will be ivoked and new type applied
basisTokenPrototypeSet.call(token, descriptor.value);
}
else
{
// apply changes if type has been changed
if (token.getType() != savedType)
token.apply();
}
}
}
|
javascript
|
function(){
for (var tokenName in this.tokens)
{
var token = this.tokens[tokenName];
var descriptor = this.getDescriptor(tokenName) || NULL_DESCRIPTOR;
var savedType = token.getType();
token.descriptor = descriptor;
if (token.value !== descriptor.value)
{
// on value change apply will be ivoked and new type applied
basisTokenPrototypeSet.call(token, descriptor.value);
}
else
{
// apply changes if type has been changed
if (token.getType() != savedType)
token.apply();
}
}
}
|
[
"function",
"(",
")",
"{",
"for",
"(",
"var",
"tokenName",
"in",
"this",
".",
"tokens",
")",
"{",
"var",
"token",
"=",
"this",
".",
"tokens",
"[",
"tokenName",
"]",
";",
"var",
"descriptor",
"=",
"this",
".",
"getDescriptor",
"(",
"tokenName",
")",
"||",
"NULL_DESCRIPTOR",
";",
"var",
"savedType",
"=",
"token",
".",
"getType",
"(",
")",
";",
"token",
".",
"descriptor",
"=",
"descriptor",
";",
"if",
"(",
"token",
".",
"value",
"!==",
"descriptor",
".",
"value",
")",
"{",
"basisTokenPrototypeSet",
".",
"call",
"(",
"token",
",",
"descriptor",
".",
"value",
")",
";",
"}",
"else",
"{",
"if",
"(",
"token",
".",
"getType",
"(",
")",
"!=",
"savedType",
")",
"token",
".",
"apply",
"(",
")",
";",
"}",
"}",
"}"
] |
Sync token values according to current culture and it's fallback.
|
[
"Sync",
"token",
"values",
"according",
"to",
"current",
"culture",
"and",
"it",
"s",
"fallback",
"."
] |
8571903014b207a09d45ad2d1bfba277bf21289b
|
https://github.com/basisjs/basisjs/blob/8571903014b207a09d45ad2d1bfba277bf21289b/src/basis/l10n.js#L692-L713
|
train
|
|
basisjs/basisjs
|
src/basis/l10n.js
|
internalResolveDictionary
|
function internalResolveDictionary(source, noFetch) {
var dictionary;
if (typeof source == 'string')
{
var location = source;
var extname = basis.path.extname(location);
if (extname != '.l10n')
location = location.replace(new RegExp(extname + '([#?]|$)'), '.l10n$1');
source = basis.resource(location);
}
if (basis.resource.isResource(source))
dictionary = dictionaryByUrl[source.url];
return dictionary || new Dictionary(source, noFetch);
}
|
javascript
|
function internalResolveDictionary(source, noFetch) {
var dictionary;
if (typeof source == 'string')
{
var location = source;
var extname = basis.path.extname(location);
if (extname != '.l10n')
location = location.replace(new RegExp(extname + '([#?]|$)'), '.l10n$1');
source = basis.resource(location);
}
if (basis.resource.isResource(source))
dictionary = dictionaryByUrl[source.url];
return dictionary || new Dictionary(source, noFetch);
}
|
[
"function",
"internalResolveDictionary",
"(",
"source",
",",
"noFetch",
")",
"{",
"var",
"dictionary",
";",
"if",
"(",
"typeof",
"source",
"==",
"'string'",
")",
"{",
"var",
"location",
"=",
"source",
";",
"var",
"extname",
"=",
"basis",
".",
"path",
".",
"extname",
"(",
"location",
")",
";",
"if",
"(",
"extname",
"!=",
"'.l10n'",
")",
"location",
"=",
"location",
".",
"replace",
"(",
"new",
"RegExp",
"(",
"extname",
"+",
"'([#?]|$)'",
")",
",",
"'.l10n$1'",
")",
";",
"source",
"=",
"basis",
".",
"resource",
"(",
"location",
")",
";",
"}",
"if",
"(",
"basis",
".",
"resource",
".",
"isResource",
"(",
"source",
")",
")",
"dictionary",
"=",
"dictionaryByUrl",
"[",
"source",
".",
"url",
"]",
";",
"return",
"dictionary",
"||",
"new",
"Dictionary",
"(",
"source",
",",
"noFetch",
")",
";",
"}"
] |
Currently for internal use only, with additional argument
|
[
"Currently",
"for",
"internal",
"use",
"only",
"with",
"additional",
"argument"
] |
8571903014b207a09d45ad2d1bfba277bf21289b
|
https://github.com/basisjs/basisjs/blob/8571903014b207a09d45ad2d1bfba277bf21289b/src/basis/l10n.js#L823-L841
|
train
|
basisjs/basisjs
|
src/basis/l10n.js
|
resolveCulture
|
function resolveCulture(name, pluralForm){
if (name && !cultures[name])
cultures[name] = new Culture(name, pluralForm);
return cultures[name || currentCulture];
}
|
javascript
|
function resolveCulture(name, pluralForm){
if (name && !cultures[name])
cultures[name] = new Culture(name, pluralForm);
return cultures[name || currentCulture];
}
|
[
"function",
"resolveCulture",
"(",
"name",
",",
"pluralForm",
")",
"{",
"if",
"(",
"name",
"&&",
"!",
"cultures",
"[",
"name",
"]",
")",
"cultures",
"[",
"name",
"]",
"=",
"new",
"Culture",
"(",
"name",
",",
"pluralForm",
")",
";",
"return",
"cultures",
"[",
"name",
"||",
"currentCulture",
"]",
";",
"}"
] |
Returns culture instance by name. Creates new one if not exists yet.
@param {string} name Culture name
@param {object} pluralForm
@return {basis.l10n.Culture}
|
[
"Returns",
"culture",
"instance",
"by",
"name",
".",
"Creates",
"new",
"one",
"if",
"not",
"exists",
"yet",
"."
] |
8571903014b207a09d45ad2d1bfba277bf21289b
|
https://github.com/basisjs/basisjs/blob/8571903014b207a09d45ad2d1bfba277bf21289b/src/basis/l10n.js#L1004-L1009
|
train
|
basisjs/basisjs
|
src/basis/l10n.js
|
setCulture
|
function setCulture(culture){
if (!culture)
return;
if (currentCulture != culture)
{
if (cultureList.indexOf(culture) == -1)
{
/** @cut */ basis.dev.warn('basis.l10n.setCulture: culture `' + culture + '` not in the list, the culture doesn\'t changed');
return;
}
currentCulture = culture;
for (var i = 0, dictionary; dictionary = dictionaries[i]; i++)
dictionary.syncValues();
basisTokenPrototypeSet.call(resolveCulture, culture);
}
}
|
javascript
|
function setCulture(culture){
if (!culture)
return;
if (currentCulture != culture)
{
if (cultureList.indexOf(culture) == -1)
{
/** @cut */ basis.dev.warn('basis.l10n.setCulture: culture `' + culture + '` not in the list, the culture doesn\'t changed');
return;
}
currentCulture = culture;
for (var i = 0, dictionary; dictionary = dictionaries[i]; i++)
dictionary.syncValues();
basisTokenPrototypeSet.call(resolveCulture, culture);
}
}
|
[
"function",
"setCulture",
"(",
"culture",
")",
"{",
"if",
"(",
"!",
"culture",
")",
"return",
";",
"if",
"(",
"currentCulture",
"!=",
"culture",
")",
"{",
"if",
"(",
"cultureList",
".",
"indexOf",
"(",
"culture",
")",
"==",
"-",
"1",
")",
"{",
"basis",
".",
"dev",
".",
"warn",
"(",
"'basis.l10n.setCulture: culture `'",
"+",
"culture",
"+",
"'` not in the list, the culture doesn\\'t changed'",
")",
";",
"\\'",
"}",
"return",
";",
"currentCulture",
"=",
"culture",
";",
"for",
"(",
"var",
"i",
"=",
"0",
",",
"dictionary",
";",
"dictionary",
"=",
"dictionaries",
"[",
"i",
"]",
";",
"i",
"++",
")",
"dictionary",
".",
"syncValues",
"(",
")",
";",
"}",
"}"
] |
Set new culture.
@param {string} culture Culture name.
|
[
"Set",
"new",
"culture",
"."
] |
8571903014b207a09d45ad2d1bfba277bf21289b
|
https://github.com/basisjs/basisjs/blob/8571903014b207a09d45ad2d1bfba277bf21289b/src/basis/l10n.js#L1028-L1047
|
train
|
basisjs/basisjs
|
src/basis/l10n.js
|
onCultureChange
|
function onCultureChange(fn, context, fire){
resolveCulture.attach(fn, context);
if (fire)
fn.call(context, currentCulture);
}
|
javascript
|
function onCultureChange(fn, context, fire){
resolveCulture.attach(fn, context);
if (fire)
fn.call(context, currentCulture);
}
|
[
"function",
"onCultureChange",
"(",
"fn",
",",
"context",
",",
"fire",
")",
"{",
"resolveCulture",
".",
"attach",
"(",
"fn",
",",
"context",
")",
";",
"if",
"(",
"fire",
")",
"fn",
".",
"call",
"(",
"context",
",",
"currentCulture",
")",
";",
"}"
] |
Add callback on culture change.
@param {function(culture)} fn Callback
@param {context=} context Context for callback
@param {boolean=} fire If true callback will be invoked with current
culture name right after callback attachment.
|
[
"Add",
"callback",
"on",
"culture",
"change",
"."
] |
8571903014b207a09d45ad2d1bfba277bf21289b
|
https://github.com/basisjs/basisjs/blob/8571903014b207a09d45ad2d1bfba277bf21289b/src/basis/l10n.js#L1134-L1139
|
train
|
AltspaceVR/AltspaceSDK
|
dist/altspace.js
|
init
|
function init(_scene, _camera, _params) {
if (!_scene || !(_scene instanceof THREE.Scene)) {
throw new TypeError('Requires THREE.Scene argument');
}
if (!_camera || !(_camera instanceof THREE.Camera)) {
throw new TypeError('Requires THREE.Camera argument');
}
scene = _scene;
camera = _camera;
var p = _params || {};
domElem = p.renderer && p.renderer.domElement || window;
domElem.addEventListener('mousedown', mouseDown, false);
domElem.addEventListener('mouseup', mouseUp, false);
domElem.addEventListener('mousemove', mouseMove, false);
}
|
javascript
|
function init(_scene, _camera, _params) {
if (!_scene || !(_scene instanceof THREE.Scene)) {
throw new TypeError('Requires THREE.Scene argument');
}
if (!_camera || !(_camera instanceof THREE.Camera)) {
throw new TypeError('Requires THREE.Camera argument');
}
scene = _scene;
camera = _camera;
var p = _params || {};
domElem = p.renderer && p.renderer.domElement || window;
domElem.addEventListener('mousedown', mouseDown, false);
domElem.addEventListener('mouseup', mouseUp, false);
domElem.addEventListener('mousemove', mouseMove, false);
}
|
[
"function",
"init",
"(",
"_scene",
",",
"_camera",
",",
"_params",
")",
"{",
"if",
"(",
"!",
"_scene",
"||",
"!",
"(",
"_scene",
"instanceof",
"THREE",
".",
"Scene",
")",
")",
"{",
"throw",
"new",
"TypeError",
"(",
"'Requires THREE.Scene argument'",
")",
";",
"}",
"if",
"(",
"!",
"_camera",
"||",
"!",
"(",
"_camera",
"instanceof",
"THREE",
".",
"Camera",
")",
")",
"{",
"throw",
"new",
"TypeError",
"(",
"'Requires THREE.Camera argument'",
")",
";",
"}",
"scene",
"=",
"_scene",
";",
"camera",
"=",
"_camera",
";",
"var",
"p",
"=",
"_params",
"||",
"{",
"}",
";",
"domElem",
"=",
"p",
".",
"renderer",
"&&",
"p",
".",
"renderer",
".",
"domElement",
"||",
"window",
";",
"domElem",
".",
"addEventListener",
"(",
"'mousedown'",
",",
"mouseDown",
",",
"false",
")",
";",
"domElem",
".",
"addEventListener",
"(",
"'mouseup'",
",",
"mouseUp",
",",
"false",
")",
";",
"domElem",
".",
"addEventListener",
"(",
"'mousemove'",
",",
"mouseMove",
",",
"false",
")",
";",
"}"
] |
Initializes the cursor module
@static
@method init
@param {THREE.Scene} scene
@param {THREE.Camera} camera - Camera used for raycasting.
@param {Object} [options] - An options object
@param {THREE.WebGLRenderer} [options.renderer] - If supplied, applies cursor movement to render target
instead of entire client
@memberof module:altspace/utilities/shims/cursor
|
[
"Initializes",
"the",
"cursor",
"module"
] |
3e39b6ebeed500c98f16f4cf2b0db053ec0953cd
|
https://github.com/AltspaceVR/AltspaceSDK/blob/3e39b6ebeed500c98f16f4cf2b0db053ec0953cd/dist/altspace.js#L3443-L3459
|
train
|
AltspaceVR/AltspaceSDK
|
dist/altspace.js
|
Simulation
|
function Simulation(config)
{
if ( config === void 0 ) config = {auto: true};
this._scene = null;
this._renderer = null;
this._camera = null;
var usingAFrame = window.AFRAME && document.querySelector('a-scene');
if(usingAFrame)
{
var ascene = document.querySelector('a-scene');
this._scene = ascene.object3D;
this._renderer = ascene.renderer;
var acamera = document.querySelector('a-camera');
if(acamera)
{ this._camera = acamera.object3D; }
}
else if (window.altspace && altspace.inClient)
{
this._scene = new THREE.Scene();
this._renderer = altspace.getThreeJSRenderer();
this._camera = new THREE.PerspectiveCamera(); // TODO: change from shim to symbolic
}
else {
this._setupWebGL();
}
if(config.auto && !usingAFrame)
{ this.loop(); }
}
|
javascript
|
function Simulation(config)
{
if ( config === void 0 ) config = {auto: true};
this._scene = null;
this._renderer = null;
this._camera = null;
var usingAFrame = window.AFRAME && document.querySelector('a-scene');
if(usingAFrame)
{
var ascene = document.querySelector('a-scene');
this._scene = ascene.object3D;
this._renderer = ascene.renderer;
var acamera = document.querySelector('a-camera');
if(acamera)
{ this._camera = acamera.object3D; }
}
else if (window.altspace && altspace.inClient)
{
this._scene = new THREE.Scene();
this._renderer = altspace.getThreeJSRenderer();
this._camera = new THREE.PerspectiveCamera(); // TODO: change from shim to symbolic
}
else {
this._setupWebGL();
}
if(config.auto && !usingAFrame)
{ this.loop(); }
}
|
[
"function",
"Simulation",
"(",
"config",
")",
"{",
"if",
"(",
"config",
"===",
"void",
"0",
")",
"config",
"=",
"{",
"auto",
":",
"true",
"}",
";",
"this",
".",
"_scene",
"=",
"null",
";",
"this",
".",
"_renderer",
"=",
"null",
";",
"this",
".",
"_camera",
"=",
"null",
";",
"var",
"usingAFrame",
"=",
"window",
".",
"AFRAME",
"&&",
"document",
".",
"querySelector",
"(",
"'a-scene'",
")",
";",
"if",
"(",
"usingAFrame",
")",
"{",
"var",
"ascene",
"=",
"document",
".",
"querySelector",
"(",
"'a-scene'",
")",
";",
"this",
".",
"_scene",
"=",
"ascene",
".",
"object3D",
";",
"this",
".",
"_renderer",
"=",
"ascene",
".",
"renderer",
";",
"var",
"acamera",
"=",
"document",
".",
"querySelector",
"(",
"'a-camera'",
")",
";",
"if",
"(",
"acamera",
")",
"{",
"this",
".",
"_camera",
"=",
"acamera",
".",
"object3D",
";",
"}",
"}",
"else",
"if",
"(",
"window",
".",
"altspace",
"&&",
"altspace",
".",
"inClient",
")",
"{",
"this",
".",
"_scene",
"=",
"new",
"THREE",
".",
"Scene",
"(",
")",
";",
"this",
".",
"_renderer",
"=",
"altspace",
".",
"getThreeJSRenderer",
"(",
")",
";",
"this",
".",
"_camera",
"=",
"new",
"THREE",
".",
"PerspectiveCamera",
"(",
")",
";",
"}",
"else",
"{",
"this",
".",
"_setupWebGL",
"(",
")",
";",
"}",
"if",
"(",
"config",
".",
"auto",
"&&",
"!",
"usingAFrame",
")",
"{",
"this",
".",
"loop",
"(",
")",
";",
"}",
"}"
] |
Simulation is a helper class that lets you quickly setup a three.js app with support for AltspaceVR. It creates a basic scene for you and starts the render and behavior loop.
If all of your application logic is in behaviors, you do not need to create any additional requestAnimationFrame loops.
It also automatically uses the WebGL renderer when running in a
desktop browser and emulates cursor events with mouse clicks.
@class Simulation
@param {Object} [config] Optional parameters.
@param {Boolean} [config.auto=true] Automatically start the render loop.
@memberof module:altspace/utilities
|
[
"Simulation",
"is",
"a",
"helper",
"class",
"that",
"lets",
"you",
"quickly",
"setup",
"a",
"three",
".",
"js",
"app",
"with",
"support",
"for",
"AltspaceVR",
".",
"It",
"creates",
"a",
"basic",
"scene",
"for",
"you",
"and",
"starts",
"the",
"render",
"and",
"behavior",
"loop",
"."
] |
3e39b6ebeed500c98f16f4cf2b0db053ec0953cd
|
https://github.com/AltspaceVR/AltspaceSDK/blob/3e39b6ebeed500c98f16f4cf2b0db053ec0953cd/dist/altspace.js#L3556-L3588
|
train
|
AltspaceVR/AltspaceSDK
|
dist/altspace.js
|
init$1
|
function init$1(params){
var p = params || {};
TRACE = p.TRACE || false;
if (p.crossOrigin) { crossOrigin = p.crossOrigin; }
if (p.baseUrl) { baseUrl = p.baseUrl; }
if (baseUrl.slice(-1) !== '/') { baseUrl += '/'; }
loader = new altspace.utilities.shims.OBJMTLLoader();
loader.crossOrigin = crossOrigin;
if (TRACE) { console.log('MultiLoader initialized with params', params); }
}
|
javascript
|
function init$1(params){
var p = params || {};
TRACE = p.TRACE || false;
if (p.crossOrigin) { crossOrigin = p.crossOrigin; }
if (p.baseUrl) { baseUrl = p.baseUrl; }
if (baseUrl.slice(-1) !== '/') { baseUrl += '/'; }
loader = new altspace.utilities.shims.OBJMTLLoader();
loader.crossOrigin = crossOrigin;
if (TRACE) { console.log('MultiLoader initialized with params', params); }
}
|
[
"function",
"init$1",
"(",
"params",
")",
"{",
"var",
"p",
"=",
"params",
"||",
"{",
"}",
";",
"TRACE",
"=",
"p",
".",
"TRACE",
"||",
"false",
";",
"if",
"(",
"p",
".",
"crossOrigin",
")",
"{",
"crossOrigin",
"=",
"p",
".",
"crossOrigin",
";",
"}",
"if",
"(",
"p",
".",
"baseUrl",
")",
"{",
"baseUrl",
"=",
"p",
".",
"baseUrl",
";",
"}",
"if",
"(",
"baseUrl",
".",
"slice",
"(",
"-",
"1",
")",
"!==",
"'/'",
")",
"{",
"baseUrl",
"+=",
"'/'",
";",
"}",
"loader",
"=",
"new",
"altspace",
".",
"utilities",
".",
"shims",
".",
"OBJMTLLoader",
"(",
")",
";",
"loader",
".",
"crossOrigin",
"=",
"crossOrigin",
";",
"if",
"(",
"TRACE",
")",
"{",
"console",
".",
"log",
"(",
"'MultiLoader initialized with params'",
",",
"params",
")",
";",
"}",
"}"
] |
end of LoadRequest
|
[
"end",
"of",
"LoadRequest"
] |
3e39b6ebeed500c98f16f4cf2b0db053ec0953cd
|
https://github.com/AltspaceVR/AltspaceSDK/blob/3e39b6ebeed500c98f16f4cf2b0db053ec0953cd/dist/altspace.js#L3683-L3693
|
train
|
AltspaceVR/AltspaceSDK
|
dist/altspace.js
|
ensureInVR
|
function ensureInVR() {
if (inTile || !inVR) //inTile && inAltspace
{
var css = document.createElement("style");
css.type = "text/css";
css.innerHTML = "@import url(https://fonts.googleapis.com/css?family=Open+Sans:800);.altspace-info{text-align:center;font-family:'Open Sans',sans-serif;line-height:.5}.altspace-vr-notice{color:rgba(0,0,0,.7);font-size:5vw}.altspace-pen-name{font-size:7vw}";
document.head.appendChild(css);
document.body.style.background = Please.make_color({ seed: getPenId() });
var info = document.createElement("div");
info.className = "altspace-info";
document.body.appendChild(info);
var nameEl = document.createElement("span");
nameEl.className = "altspace-pen-name";
nameEl.innerHTML = '<p>' + name.toUpperCase() + '</p>';
info.appendChild(nameEl);
if (inTile) {
var errorMsg = 'VR mode does not support preview tiles. Stopping code execution.';
console.log('ERROR: ' + errorMsg);
throw new Error(errorMsg);
}
if (!inVR) {
var launchEl = document.createElement("span");
launchEl.className = "altspace-vr-notice";
launchEl.innerHTML = '<p>View</p>';
info.insertBefore(launchEl, nameEl);
var notice = document.createElement("span");
notice.className = "altspace-vr-notice";
notice.innerHTML = '<p>in <a href="http://altvr.com"> AltspaceVR </a></p>';
info.appendChild(notice);
var errorMsg = 'Not in VR mode. Stopping code execution.';
if (inTile) {
console.log('ERROR: ' + errorMsg);//thrown error message not displayed in console when inTile, log it
}
throw new Error(errorMsg);
}
return;
}
}
|
javascript
|
function ensureInVR() {
if (inTile || !inVR) //inTile && inAltspace
{
var css = document.createElement("style");
css.type = "text/css";
css.innerHTML = "@import url(https://fonts.googleapis.com/css?family=Open+Sans:800);.altspace-info{text-align:center;font-family:'Open Sans',sans-serif;line-height:.5}.altspace-vr-notice{color:rgba(0,0,0,.7);font-size:5vw}.altspace-pen-name{font-size:7vw}";
document.head.appendChild(css);
document.body.style.background = Please.make_color({ seed: getPenId() });
var info = document.createElement("div");
info.className = "altspace-info";
document.body.appendChild(info);
var nameEl = document.createElement("span");
nameEl.className = "altspace-pen-name";
nameEl.innerHTML = '<p>' + name.toUpperCase() + '</p>';
info.appendChild(nameEl);
if (inTile) {
var errorMsg = 'VR mode does not support preview tiles. Stopping code execution.';
console.log('ERROR: ' + errorMsg);
throw new Error(errorMsg);
}
if (!inVR) {
var launchEl = document.createElement("span");
launchEl.className = "altspace-vr-notice";
launchEl.innerHTML = '<p>View</p>';
info.insertBefore(launchEl, nameEl);
var notice = document.createElement("span");
notice.className = "altspace-vr-notice";
notice.innerHTML = '<p>in <a href="http://altvr.com"> AltspaceVR </a></p>';
info.appendChild(notice);
var errorMsg = 'Not in VR mode. Stopping code execution.';
if (inTile) {
console.log('ERROR: ' + errorMsg);//thrown error message not displayed in console when inTile, log it
}
throw new Error(errorMsg);
}
return;
}
}
|
[
"function",
"ensureInVR",
"(",
")",
"{",
"if",
"(",
"inTile",
"||",
"!",
"inVR",
")",
"{",
"var",
"css",
"=",
"document",
".",
"createElement",
"(",
"\"style\"",
")",
";",
"css",
".",
"type",
"=",
"\"text/css\"",
";",
"css",
".",
"innerHTML",
"=",
"\"@import url(https://fonts.googleapis.com/css?family=Open+Sans:800);.altspace-info{text-align:center;font-family:'Open Sans',sans-serif;line-height:.5}.altspace-vr-notice{color:rgba(0,0,0,.7);font-size:5vw}.altspace-pen-name{font-size:7vw}\"",
";",
"document",
".",
"head",
".",
"appendChild",
"(",
"css",
")",
";",
"document",
".",
"body",
".",
"style",
".",
"background",
"=",
"Please",
".",
"make_color",
"(",
"{",
"seed",
":",
"getPenId",
"(",
")",
"}",
")",
";",
"var",
"info",
"=",
"document",
".",
"createElement",
"(",
"\"div\"",
")",
";",
"info",
".",
"className",
"=",
"\"altspace-info\"",
";",
"document",
".",
"body",
".",
"appendChild",
"(",
"info",
")",
";",
"var",
"nameEl",
"=",
"document",
".",
"createElement",
"(",
"\"span\"",
")",
";",
"nameEl",
".",
"className",
"=",
"\"altspace-pen-name\"",
";",
"nameEl",
".",
"innerHTML",
"=",
"'<p>'",
"+",
"name",
".",
"toUpperCase",
"(",
")",
"+",
"'</p>'",
";",
"info",
".",
"appendChild",
"(",
"nameEl",
")",
";",
"if",
"(",
"inTile",
")",
"{",
"var",
"errorMsg",
"=",
"'VR mode does not support preview tiles. Stopping code execution.'",
";",
"console",
".",
"log",
"(",
"'ERROR: '",
"+",
"errorMsg",
")",
";",
"throw",
"new",
"Error",
"(",
"errorMsg",
")",
";",
"}",
"if",
"(",
"!",
"inVR",
")",
"{",
"var",
"launchEl",
"=",
"document",
".",
"createElement",
"(",
"\"span\"",
")",
";",
"launchEl",
".",
"className",
"=",
"\"altspace-vr-notice\"",
";",
"launchEl",
".",
"innerHTML",
"=",
"'<p>View</p>'",
";",
"info",
".",
"insertBefore",
"(",
"launchEl",
",",
"nameEl",
")",
";",
"var",
"notice",
"=",
"document",
".",
"createElement",
"(",
"\"span\"",
")",
";",
"notice",
".",
"className",
"=",
"\"altspace-vr-notice\"",
";",
"notice",
".",
"innerHTML",
"=",
"'<p>in <a href=\"http://altvr.com\"> AltspaceVR </a></p>'",
";",
"info",
".",
"appendChild",
"(",
"notice",
")",
";",
"var",
"errorMsg",
"=",
"'Not in VR mode. Stopping code execution.'",
";",
"if",
"(",
"inTile",
")",
"{",
"console",
".",
"log",
"(",
"'ERROR: '",
"+",
"errorMsg",
")",
";",
"}",
"throw",
"new",
"Error",
"(",
"errorMsg",
")",
";",
"}",
"return",
";",
"}",
"}"
] |
Will stop code exection and post a message informing the user to
open the example in VR
@method ensureInVR
@memberof module:altspace/utilities/codePen
|
[
"Will",
"stop",
"code",
"exection",
"and",
"post",
"a",
"message",
"informing",
"the",
"user",
"to",
"open",
"the",
"example",
"in",
"VR"
] |
3e39b6ebeed500c98f16f4cf2b0db053ec0953cd
|
https://github.com/AltspaceVR/AltspaceSDK/blob/3e39b6ebeed500c98f16f4cf2b0db053ec0953cd/dist/altspace.js#L3770-L3817
|
train
|
AltspaceVR/AltspaceSDK
|
dist/altspace.js
|
getPenId
|
function getPenId() {
var url = getParsedUrl();
var splitPath = url.path.split('/');
var id = splitPath[splitPath.length - 1];
return id;
}
|
javascript
|
function getPenId() {
var url = getParsedUrl();
var splitPath = url.path.split('/');
var id = splitPath[splitPath.length - 1];
return id;
}
|
[
"function",
"getPenId",
"(",
")",
"{",
"var",
"url",
"=",
"getParsedUrl",
"(",
")",
";",
"var",
"splitPath",
"=",
"url",
".",
"path",
".",
"split",
"(",
"'/'",
")",
";",
"var",
"id",
"=",
"splitPath",
"[",
"splitPath",
".",
"length",
"-",
"1",
"]",
";",
"return",
"id",
";",
"}"
] |
Returns the pen ID, useful for setting the sync instanceId.
@method getPenId
@return {String}
@memberof module:altspace/utilities/codePen
|
[
"Returns",
"the",
"pen",
"ID",
"useful",
"for",
"setting",
"the",
"sync",
"instanceId",
"."
] |
3e39b6ebeed500c98f16f4cf2b0db053ec0953cd
|
https://github.com/AltspaceVR/AltspaceSDK/blob/3e39b6ebeed500c98f16f4cf2b0db053ec0953cd/dist/altspace.js#L3842-L3847
|
train
|
AltspaceVR/AltspaceSDK
|
dist/altspace.js
|
getAuthorId
|
function getAuthorId() {
var url = getParsedUrl();
var splitPath = url.path.split('/');
var isTeam = splitPath[1] == 'team';
var id = isTeam ? 'team-' + splitPath[2] : splitPath[1];
return id;
}
|
javascript
|
function getAuthorId() {
var url = getParsedUrl();
var splitPath = url.path.split('/');
var isTeam = splitPath[1] == 'team';
var id = isTeam ? 'team-' + splitPath[2] : splitPath[1];
return id;
}
|
[
"function",
"getAuthorId",
"(",
")",
"{",
"var",
"url",
"=",
"getParsedUrl",
"(",
")",
";",
"var",
"splitPath",
"=",
"url",
".",
"path",
".",
"split",
"(",
"'/'",
")",
";",
"var",
"isTeam",
"=",
"splitPath",
"[",
"1",
"]",
"==",
"'team'",
";",
"var",
"id",
"=",
"isTeam",
"?",
"'team-'",
"+",
"splitPath",
"[",
"2",
"]",
":",
"splitPath",
"[",
"1",
"]",
";",
"return",
"id",
";",
"}"
] |
Returns the pen author ID, useful for setting the sync authorId.
@method getAuthorId
@return {String}
@memberof module:altspace/utilities/codePen
|
[
"Returns",
"the",
"pen",
"author",
"ID",
"useful",
"for",
"setting",
"the",
"sync",
"authorId",
"."
] |
3e39b6ebeed500c98f16f4cf2b0db053ec0953cd
|
https://github.com/AltspaceVR/AltspaceSDK/blob/3e39b6ebeed500c98f16f4cf2b0db053ec0953cd/dist/altspace.js#L3855-L3861
|
train
|
AltspaceVR/AltspaceSDK
|
dist/altspace.js
|
isEqual
|
function isEqual(a, b)
{
// objects are directly equal
if(a === b){
return true;
}
// recurse for each pair of array items
else if( Array.isArray(a) && Array.isArray(b) && a.length === b.length ){
return a.every( function (v,i) { return isEqual(a[i], b[i]); } );
}
// recurse for every key/val pair in objects
else if( a instanceof Object && b instanceof Object
&& isEqual(Object.keys(a).sort(), Object.keys(b).sort()) )
{
for(var k in a){
if( !isEqual(a[k], b[k]) )
{ return false; }
}
return true;
}
else {
return false;
}
}
|
javascript
|
function isEqual(a, b)
{
// objects are directly equal
if(a === b){
return true;
}
// recurse for each pair of array items
else if( Array.isArray(a) && Array.isArray(b) && a.length === b.length ){
return a.every( function (v,i) { return isEqual(a[i], b[i]); } );
}
// recurse for every key/val pair in objects
else if( a instanceof Object && b instanceof Object
&& isEqual(Object.keys(a).sort(), Object.keys(b).sort()) )
{
for(var k in a){
if( !isEqual(a[k], b[k]) )
{ return false; }
}
return true;
}
else {
return false;
}
}
|
[
"function",
"isEqual",
"(",
"a",
",",
"b",
")",
"{",
"if",
"(",
"a",
"===",
"b",
")",
"{",
"return",
"true",
";",
"}",
"else",
"if",
"(",
"Array",
".",
"isArray",
"(",
"a",
")",
"&&",
"Array",
".",
"isArray",
"(",
"b",
")",
"&&",
"a",
".",
"length",
"===",
"b",
".",
"length",
")",
"{",
"return",
"a",
".",
"every",
"(",
"function",
"(",
"v",
",",
"i",
")",
"{",
"return",
"isEqual",
"(",
"a",
"[",
"i",
"]",
",",
"b",
"[",
"i",
"]",
")",
";",
"}",
")",
";",
"}",
"else",
"if",
"(",
"a",
"instanceof",
"Object",
"&&",
"b",
"instanceof",
"Object",
"&&",
"isEqual",
"(",
"Object",
".",
"keys",
"(",
"a",
")",
".",
"sort",
"(",
")",
",",
"Object",
".",
"keys",
"(",
"b",
")",
".",
"sort",
"(",
")",
")",
")",
"{",
"for",
"(",
"var",
"k",
"in",
"a",
")",
"{",
"if",
"(",
"!",
"isEqual",
"(",
"a",
"[",
"k",
"]",
",",
"b",
"[",
"k",
"]",
")",
")",
"{",
"return",
"false",
";",
"}",
"}",
"return",
"true",
";",
"}",
"else",
"{",
"return",
"false",
";",
"}",
"}"
] |
deep object comparison
|
[
"deep",
"object",
"comparison"
] |
3e39b6ebeed500c98f16f4cf2b0db053ec0953cd
|
https://github.com/AltspaceVR/AltspaceSDK/blob/3e39b6ebeed500c98f16f4cf2b0db053ec0953cd/dist/altspace.js#L5674-L5697
|
train
|
AltspaceVR/AltspaceSDK
|
examples/js/libs/ColladaLoader.js
|
flattenSkeleton
|
function flattenSkeleton(skeleton) {
var list = [];
var walk = function(parentid, node, list) {
var bone = {};
bone.name = node.sid;
bone.parent = parentid;
bone.matrix = node.matrix;
var data = [ new THREE.Vector3(),new THREE.Quaternion(),new THREE.Vector3() ];
bone.matrix.decompose(data[0], data[1], data[2]);
bone.pos = [ data[0].x,data[0].y,data[0].z ];
bone.scl = [ data[2].x,data[2].y,data[2].z ];
bone.rotq = [ data[1].x,data[1].y,data[1].z,data[1].w ];
list.push(bone);
for (var i in node.nodes) {
walk(node.sid, node.nodes[i], list);
}
};
walk(-1, skeleton, list);
return list;
}
|
javascript
|
function flattenSkeleton(skeleton) {
var list = [];
var walk = function(parentid, node, list) {
var bone = {};
bone.name = node.sid;
bone.parent = parentid;
bone.matrix = node.matrix;
var data = [ new THREE.Vector3(),new THREE.Quaternion(),new THREE.Vector3() ];
bone.matrix.decompose(data[0], data[1], data[2]);
bone.pos = [ data[0].x,data[0].y,data[0].z ];
bone.scl = [ data[2].x,data[2].y,data[2].z ];
bone.rotq = [ data[1].x,data[1].y,data[1].z,data[1].w ];
list.push(bone);
for (var i in node.nodes) {
walk(node.sid, node.nodes[i], list);
}
};
walk(-1, skeleton, list);
return list;
}
|
[
"function",
"flattenSkeleton",
"(",
"skeleton",
")",
"{",
"var",
"list",
"=",
"[",
"]",
";",
"var",
"walk",
"=",
"function",
"(",
"parentid",
",",
"node",
",",
"list",
")",
"{",
"var",
"bone",
"=",
"{",
"}",
";",
"bone",
".",
"name",
"=",
"node",
".",
"sid",
";",
"bone",
".",
"parent",
"=",
"parentid",
";",
"bone",
".",
"matrix",
"=",
"node",
".",
"matrix",
";",
"var",
"data",
"=",
"[",
"new",
"THREE",
".",
"Vector3",
"(",
")",
",",
"new",
"THREE",
".",
"Quaternion",
"(",
")",
",",
"new",
"THREE",
".",
"Vector3",
"(",
")",
"]",
";",
"bone",
".",
"matrix",
".",
"decompose",
"(",
"data",
"[",
"0",
"]",
",",
"data",
"[",
"1",
"]",
",",
"data",
"[",
"2",
"]",
")",
";",
"bone",
".",
"pos",
"=",
"[",
"data",
"[",
"0",
"]",
".",
"x",
",",
"data",
"[",
"0",
"]",
".",
"y",
",",
"data",
"[",
"0",
"]",
".",
"z",
"]",
";",
"bone",
".",
"scl",
"=",
"[",
"data",
"[",
"2",
"]",
".",
"x",
",",
"data",
"[",
"2",
"]",
".",
"y",
",",
"data",
"[",
"2",
"]",
".",
"z",
"]",
";",
"bone",
".",
"rotq",
"=",
"[",
"data",
"[",
"1",
"]",
".",
"x",
",",
"data",
"[",
"1",
"]",
".",
"y",
",",
"data",
"[",
"1",
"]",
".",
"z",
",",
"data",
"[",
"1",
"]",
".",
"w",
"]",
";",
"list",
".",
"push",
"(",
"bone",
")",
";",
"for",
"(",
"var",
"i",
"in",
"node",
".",
"nodes",
")",
"{",
"walk",
"(",
"node",
".",
"sid",
",",
"node",
".",
"nodes",
"[",
"i",
"]",
",",
"list",
")",
";",
"}",
"}",
";",
"walk",
"(",
"-",
"1",
",",
"skeleton",
",",
"list",
")",
";",
"return",
"list",
";",
"}"
] |
Walk the Collada tree and flatten the bones into a list, extract the position, quat and scale from the matrix
|
[
"Walk",
"the",
"Collada",
"tree",
"and",
"flatten",
"the",
"bones",
"into",
"a",
"list",
"extract",
"the",
"position",
"quat",
"and",
"scale",
"from",
"the",
"matrix"
] |
3e39b6ebeed500c98f16f4cf2b0db053ec0953cd
|
https://github.com/AltspaceVR/AltspaceSDK/blob/3e39b6ebeed500c98f16f4cf2b0db053ec0953cd/examples/js/libs/ColladaLoader.js#L605-L634
|
train
|
AltspaceVR/AltspaceSDK
|
examples/js/libs/ColladaLoader.js
|
skinToBindPose
|
function skinToBindPose(geometry,skeleton,skinController) {
var bones = [];
setupSkeleton( skeleton, bones, -1 );
setupSkinningMatrices( bones, skinController.skin );
var v = new THREE.Vector3();
var skinned = [];
for (var i = 0; i < geometry.vertices.length; i ++) {
skinned.push(new THREE.Vector3());
}
for ( i = 0; i < bones.length; i ++ ) {
if ( bones[ i ].type != 'JOINT' ) continue;
for ( var j = 0; j < bones[ i ].weights.length; j ++ ) {
var w = bones[ i ].weights[ j ];
var vidx = w.index;
var weight = w.weight;
var o = geometry.vertices[vidx];
var s = skinned[vidx];
v.x = o.x;
v.y = o.y;
v.z = o.z;
v.applyMatrix4( bones[i].skinningMatrix );
s.x += (v.x * weight);
s.y += (v.y * weight);
s.z += (v.z * weight);
}
}
for (var i = 0; i < geometry.vertices.length; i ++) {
geometry.vertices[i] = skinned[i];
}
}
|
javascript
|
function skinToBindPose(geometry,skeleton,skinController) {
var bones = [];
setupSkeleton( skeleton, bones, -1 );
setupSkinningMatrices( bones, skinController.skin );
var v = new THREE.Vector3();
var skinned = [];
for (var i = 0; i < geometry.vertices.length; i ++) {
skinned.push(new THREE.Vector3());
}
for ( i = 0; i < bones.length; i ++ ) {
if ( bones[ i ].type != 'JOINT' ) continue;
for ( var j = 0; j < bones[ i ].weights.length; j ++ ) {
var w = bones[ i ].weights[ j ];
var vidx = w.index;
var weight = w.weight;
var o = geometry.vertices[vidx];
var s = skinned[vidx];
v.x = o.x;
v.y = o.y;
v.z = o.z;
v.applyMatrix4( bones[i].skinningMatrix );
s.x += (v.x * weight);
s.y += (v.y * weight);
s.z += (v.z * weight);
}
}
for (var i = 0; i < geometry.vertices.length; i ++) {
geometry.vertices[i] = skinned[i];
}
}
|
[
"function",
"skinToBindPose",
"(",
"geometry",
",",
"skeleton",
",",
"skinController",
")",
"{",
"var",
"bones",
"=",
"[",
"]",
";",
"setupSkeleton",
"(",
"skeleton",
",",
"bones",
",",
"-",
"1",
")",
";",
"setupSkinningMatrices",
"(",
"bones",
",",
"skinController",
".",
"skin",
")",
";",
"var",
"v",
"=",
"new",
"THREE",
".",
"Vector3",
"(",
")",
";",
"var",
"skinned",
"=",
"[",
"]",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"geometry",
".",
"vertices",
".",
"length",
";",
"i",
"++",
")",
"{",
"skinned",
".",
"push",
"(",
"new",
"THREE",
".",
"Vector3",
"(",
")",
")",
";",
"}",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"bones",
".",
"length",
";",
"i",
"++",
")",
"{",
"if",
"(",
"bones",
"[",
"i",
"]",
".",
"type",
"!=",
"'JOINT'",
")",
"continue",
";",
"for",
"(",
"var",
"j",
"=",
"0",
";",
"j",
"<",
"bones",
"[",
"i",
"]",
".",
"weights",
".",
"length",
";",
"j",
"++",
")",
"{",
"var",
"w",
"=",
"bones",
"[",
"i",
"]",
".",
"weights",
"[",
"j",
"]",
";",
"var",
"vidx",
"=",
"w",
".",
"index",
";",
"var",
"weight",
"=",
"w",
".",
"weight",
";",
"var",
"o",
"=",
"geometry",
".",
"vertices",
"[",
"vidx",
"]",
";",
"var",
"s",
"=",
"skinned",
"[",
"vidx",
"]",
";",
"v",
".",
"x",
"=",
"o",
".",
"x",
";",
"v",
".",
"y",
"=",
"o",
".",
"y",
";",
"v",
".",
"z",
"=",
"o",
".",
"z",
";",
"v",
".",
"applyMatrix4",
"(",
"bones",
"[",
"i",
"]",
".",
"skinningMatrix",
")",
";",
"s",
".",
"x",
"+=",
"(",
"v",
".",
"x",
"*",
"weight",
")",
";",
"s",
".",
"y",
"+=",
"(",
"v",
".",
"y",
"*",
"weight",
")",
";",
"s",
".",
"z",
"+=",
"(",
"v",
".",
"z",
"*",
"weight",
")",
";",
"}",
"}",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"geometry",
".",
"vertices",
".",
"length",
";",
"i",
"++",
")",
"{",
"geometry",
".",
"vertices",
"[",
"i",
"]",
"=",
"skinned",
"[",
"i",
"]",
";",
"}",
"}"
] |
Move the vertices into the pose that is proper for the start of the animation
|
[
"Move",
"the",
"vertices",
"into",
"the",
"pose",
"that",
"is",
"proper",
"for",
"the",
"start",
"of",
"the",
"animation"
] |
3e39b6ebeed500c98f16f4cf2b0db053ec0953cd
|
https://github.com/AltspaceVR/AltspaceSDK/blob/3e39b6ebeed500c98f16f4cf2b0db053ec0953cd/examples/js/libs/ColladaLoader.js#L637-L683
|
train
|
AltspaceVR/AltspaceSDK
|
examples/js/libs/ColladaLoader.js
|
getNextKeyWith
|
function getNextKeyWith( keys, fullSid, ndx ) {
for ( ; ndx < keys.length; ndx ++ ) {
var key = keys[ ndx ];
if ( key.hasTarget( fullSid ) ) {
return key;
}
}
return null;
}
|
javascript
|
function getNextKeyWith( keys, fullSid, ndx ) {
for ( ; ndx < keys.length; ndx ++ ) {
var key = keys[ ndx ];
if ( key.hasTarget( fullSid ) ) {
return key;
}
}
return null;
}
|
[
"function",
"getNextKeyWith",
"(",
"keys",
",",
"fullSid",
",",
"ndx",
")",
"{",
"for",
"(",
";",
"ndx",
"<",
"keys",
".",
"length",
";",
"ndx",
"++",
")",
"{",
"var",
"key",
"=",
"keys",
"[",
"ndx",
"]",
";",
"if",
"(",
"key",
".",
"hasTarget",
"(",
"fullSid",
")",
")",
"{",
"return",
"key",
";",
"}",
"}",
"return",
"null",
";",
"}"
] |
Get next key with given sid
|
[
"Get",
"next",
"key",
"with",
"given",
"sid"
] |
3e39b6ebeed500c98f16f4cf2b0db053ec0953cd
|
https://github.com/AltspaceVR/AltspaceSDK/blob/3e39b6ebeed500c98f16f4cf2b0db053ec0953cd/examples/js/libs/ColladaLoader.js#L1682-L1698
|
train
|
AltspaceVR/AltspaceSDK
|
examples/js/libs/ColladaLoader.js
|
getPrevKeyWith
|
function getPrevKeyWith( keys, fullSid, ndx ) {
ndx = ndx >= 0 ? ndx : ndx + keys.length;
for ( ; ndx >= 0; ndx -- ) {
var key = keys[ ndx ];
if ( key.hasTarget( fullSid ) ) {
return key;
}
}
return null;
}
|
javascript
|
function getPrevKeyWith( keys, fullSid, ndx ) {
ndx = ndx >= 0 ? ndx : ndx + keys.length;
for ( ; ndx >= 0; ndx -- ) {
var key = keys[ ndx ];
if ( key.hasTarget( fullSid ) ) {
return key;
}
}
return null;
}
|
[
"function",
"getPrevKeyWith",
"(",
"keys",
",",
"fullSid",
",",
"ndx",
")",
"{",
"ndx",
"=",
"ndx",
">=",
"0",
"?",
"ndx",
":",
"ndx",
"+",
"keys",
".",
"length",
";",
"for",
"(",
";",
"ndx",
">=",
"0",
";",
"ndx",
"--",
")",
"{",
"var",
"key",
"=",
"keys",
"[",
"ndx",
"]",
";",
"if",
"(",
"key",
".",
"hasTarget",
"(",
"fullSid",
")",
")",
"{",
"return",
"key",
";",
"}",
"}",
"return",
"null",
";",
"}"
] |
Get previous key with given sid
|
[
"Get",
"previous",
"key",
"with",
"given",
"sid"
] |
3e39b6ebeed500c98f16f4cf2b0db053ec0953cd
|
https://github.com/AltspaceVR/AltspaceSDK/blob/3e39b6ebeed500c98f16f4cf2b0db053ec0953cd/examples/js/libs/ColladaLoader.js#L1702-L1720
|
train
|
AltspaceVR/AltspaceSDK
|
examples/js/libs/ColladaLoader.js
|
setUpConversion
|
function setUpConversion() {
if ( options.convertUpAxis !== true || colladaUp === options.upAxis ) {
upConversion = null;
} else {
switch ( colladaUp ) {
case 'X':
upConversion = options.upAxis === 'Y' ? 'XtoY' : 'XtoZ';
break;
case 'Y':
upConversion = options.upAxis === 'X' ? 'YtoX' : 'YtoZ';
break;
case 'Z':
upConversion = options.upAxis === 'X' ? 'ZtoX' : 'ZtoY';
break;
}
}
}
|
javascript
|
function setUpConversion() {
if ( options.convertUpAxis !== true || colladaUp === options.upAxis ) {
upConversion = null;
} else {
switch ( colladaUp ) {
case 'X':
upConversion = options.upAxis === 'Y' ? 'XtoY' : 'XtoZ';
break;
case 'Y':
upConversion = options.upAxis === 'X' ? 'YtoX' : 'YtoZ';
break;
case 'Z':
upConversion = options.upAxis === 'X' ? 'ZtoX' : 'ZtoY';
break;
}
}
}
|
[
"function",
"setUpConversion",
"(",
")",
"{",
"if",
"(",
"options",
".",
"convertUpAxis",
"!==",
"true",
"||",
"colladaUp",
"===",
"options",
".",
"upAxis",
")",
"{",
"upConversion",
"=",
"null",
";",
"}",
"else",
"{",
"switch",
"(",
"colladaUp",
")",
"{",
"case",
"'X'",
":",
"upConversion",
"=",
"options",
".",
"upAxis",
"===",
"'Y'",
"?",
"'XtoY'",
":",
"'XtoZ'",
";",
"break",
";",
"case",
"'Y'",
":",
"upConversion",
"=",
"options",
".",
"upAxis",
"===",
"'X'",
"?",
"'YtoX'",
":",
"'YtoZ'",
";",
"break",
";",
"case",
"'Z'",
":",
"upConversion",
"=",
"options",
".",
"upAxis",
"===",
"'X'",
"?",
"'ZtoX'",
":",
"'ZtoY'",
";",
"break",
";",
"}",
"}",
"}"
] |
Up axis conversion
|
[
"Up",
"axis",
"conversion"
] |
3e39b6ebeed500c98f16f4cf2b0db053ec0953cd
|
https://github.com/AltspaceVR/AltspaceSDK/blob/3e39b6ebeed500c98f16f4cf2b0db053ec0953cd/examples/js/libs/ColladaLoader.js#L5263-L5292
|
train
|
AltspaceVR/AltspaceSDK
|
examples/js/libs/GLTFLoader.js
|
replaceTHREEShaderAttributes
|
function replaceTHREEShaderAttributes( shaderText, technique ) {
// Expected technique attributes
var attributes = {};
for ( var attributeId in technique.attributes ) {
var pname = technique.attributes[ attributeId ];
var param = technique.parameters[ pname ];
var atype = param.type;
var semantic = param.semantic;
attributes[ attributeId ] = {
type: atype,
semantic: semantic
};
}
// Figure out which attributes to change in technique
var shaderParams = technique.parameters;
var shaderAttributes = technique.attributes;
var params = {};
for ( var attributeId in attributes ) {
var pname = shaderAttributes[ attributeId ];
var shaderParam = shaderParams[ pname ];
var semantic = shaderParam.semantic;
if ( semantic ) {
params[ attributeId ] = shaderParam;
}
}
for ( var pname in params ) {
var param = params[ pname ];
var semantic = param.semantic;
var regEx = new RegExp( "\\b" + pname + "\\b", "g" );
switch ( semantic ) {
case "POSITION":
shaderText = shaderText.replace( regEx, 'position' );
break;
case "NORMAL":
shaderText = shaderText.replace( regEx, 'normal' );
break;
case 'TEXCOORD_0':
case 'TEXCOORD0':
case 'TEXCOORD':
shaderText = shaderText.replace( regEx, 'uv' );
break;
case 'COLOR_0':
case 'COLOR0':
case 'COLOR':
shaderText = shaderText.replace( regEx, 'color' );
break;
case "WEIGHT":
shaderText = shaderText.replace( regEx, 'skinWeight' );
break;
case "JOINT":
shaderText = shaderText.replace( regEx, 'skinIndex' );
break;
}
}
return shaderText;
}
|
javascript
|
function replaceTHREEShaderAttributes( shaderText, technique ) {
// Expected technique attributes
var attributes = {};
for ( var attributeId in technique.attributes ) {
var pname = technique.attributes[ attributeId ];
var param = technique.parameters[ pname ];
var atype = param.type;
var semantic = param.semantic;
attributes[ attributeId ] = {
type: atype,
semantic: semantic
};
}
// Figure out which attributes to change in technique
var shaderParams = technique.parameters;
var shaderAttributes = technique.attributes;
var params = {};
for ( var attributeId in attributes ) {
var pname = shaderAttributes[ attributeId ];
var shaderParam = shaderParams[ pname ];
var semantic = shaderParam.semantic;
if ( semantic ) {
params[ attributeId ] = shaderParam;
}
}
for ( var pname in params ) {
var param = params[ pname ];
var semantic = param.semantic;
var regEx = new RegExp( "\\b" + pname + "\\b", "g" );
switch ( semantic ) {
case "POSITION":
shaderText = shaderText.replace( regEx, 'position' );
break;
case "NORMAL":
shaderText = shaderText.replace( regEx, 'normal' );
break;
case 'TEXCOORD_0':
case 'TEXCOORD0':
case 'TEXCOORD':
shaderText = shaderText.replace( regEx, 'uv' );
break;
case 'COLOR_0':
case 'COLOR0':
case 'COLOR':
shaderText = shaderText.replace( regEx, 'color' );
break;
case "WEIGHT":
shaderText = shaderText.replace( regEx, 'skinWeight' );
break;
case "JOINT":
shaderText = shaderText.replace( regEx, 'skinIndex' );
break;
}
}
return shaderText;
}
|
[
"function",
"replaceTHREEShaderAttributes",
"(",
"shaderText",
",",
"technique",
")",
"{",
"var",
"attributes",
"=",
"{",
"}",
";",
"for",
"(",
"var",
"attributeId",
"in",
"technique",
".",
"attributes",
")",
"{",
"var",
"pname",
"=",
"technique",
".",
"attributes",
"[",
"attributeId",
"]",
";",
"var",
"param",
"=",
"technique",
".",
"parameters",
"[",
"pname",
"]",
";",
"var",
"atype",
"=",
"param",
".",
"type",
";",
"var",
"semantic",
"=",
"param",
".",
"semantic",
";",
"attributes",
"[",
"attributeId",
"]",
"=",
"{",
"type",
":",
"atype",
",",
"semantic",
":",
"semantic",
"}",
";",
"}",
"var",
"shaderParams",
"=",
"technique",
".",
"parameters",
";",
"var",
"shaderAttributes",
"=",
"technique",
".",
"attributes",
";",
"var",
"params",
"=",
"{",
"}",
";",
"for",
"(",
"var",
"attributeId",
"in",
"attributes",
")",
"{",
"var",
"pname",
"=",
"shaderAttributes",
"[",
"attributeId",
"]",
";",
"var",
"shaderParam",
"=",
"shaderParams",
"[",
"pname",
"]",
";",
"var",
"semantic",
"=",
"shaderParam",
".",
"semantic",
";",
"if",
"(",
"semantic",
")",
"{",
"params",
"[",
"attributeId",
"]",
"=",
"shaderParam",
";",
"}",
"}",
"for",
"(",
"var",
"pname",
"in",
"params",
")",
"{",
"var",
"param",
"=",
"params",
"[",
"pname",
"]",
";",
"var",
"semantic",
"=",
"param",
".",
"semantic",
";",
"var",
"regEx",
"=",
"new",
"RegExp",
"(",
"\"\\\\b\"",
"+",
"\\\\",
"+",
"pname",
",",
"\"\\\\b\"",
")",
";",
"\\\\",
"}",
"\"g\"",
"}"
] |
Three.js seems too dependent on attribute names so globally replace those in the shader code
|
[
"Three",
".",
"js",
"seems",
"too",
"dependent",
"on",
"attribute",
"names",
"so",
"globally",
"replace",
"those",
"in",
"the",
"shader",
"code"
] |
3e39b6ebeed500c98f16f4cf2b0db053ec0953cd
|
https://github.com/AltspaceVR/AltspaceSDK/blob/3e39b6ebeed500c98f16f4cf2b0db053ec0953cd/examples/js/libs/GLTFLoader.js#L654-L742
|
train
|
AltspaceVR/AltspaceSDK
|
src/utilities/behaviors/SteamVRInput.js
|
getController
|
function getController(hand, config) {
const findGamepad = (resolve, reject) => {
const gamepad = altspace.getGamepads().find((g) => g.mapping === 'steamvr' && g.hand === hand);
if (gamepad) {
if(config.logging) console.log("SteamVR input device found", gamepad);
resolve(gamepad);
} else {
if(config.logging) console.log("SteamVR input device not found trying again in 500ms...");
setTimeout(findGamepad, 500, resolve, reject);
}
};
return new Promise(findGamepad);
}
|
javascript
|
function getController(hand, config) {
const findGamepad = (resolve, reject) => {
const gamepad = altspace.getGamepads().find((g) => g.mapping === 'steamvr' && g.hand === hand);
if (gamepad) {
if(config.logging) console.log("SteamVR input device found", gamepad);
resolve(gamepad);
} else {
if(config.logging) console.log("SteamVR input device not found trying again in 500ms...");
setTimeout(findGamepad, 500, resolve, reject);
}
};
return new Promise(findGamepad);
}
|
[
"function",
"getController",
"(",
"hand",
",",
"config",
")",
"{",
"const",
"findGamepad",
"=",
"(",
"resolve",
",",
"reject",
")",
"=>",
"{",
"const",
"gamepad",
"=",
"altspace",
".",
"getGamepads",
"(",
")",
".",
"find",
"(",
"(",
"g",
")",
"=>",
"g",
".",
"mapping",
"===",
"'steamvr'",
"&&",
"g",
".",
"hand",
"===",
"hand",
")",
";",
"if",
"(",
"gamepad",
")",
"{",
"if",
"(",
"config",
".",
"logging",
")",
"console",
".",
"log",
"(",
"\"SteamVR input device found\"",
",",
"gamepad",
")",
";",
"resolve",
"(",
"gamepad",
")",
";",
"}",
"else",
"{",
"if",
"(",
"config",
".",
"logging",
")",
"console",
".",
"log",
"(",
"\"SteamVR input device not found trying again in 500ms...\"",
")",
";",
"setTimeout",
"(",
"findGamepad",
",",
"500",
",",
"resolve",
",",
"reject",
")",
";",
"}",
"}",
";",
"return",
"new",
"Promise",
"(",
"findGamepad",
")",
";",
"}"
] |
Returns a Promise that resovles static when a steamvr controller is found
|
[
"Returns",
"a",
"Promise",
"that",
"resovles",
"static",
"when",
"a",
"steamvr",
"controller",
"is",
"found"
] |
3e39b6ebeed500c98f16f4cf2b0db053ec0953cd
|
https://github.com/AltspaceVR/AltspaceSDK/blob/3e39b6ebeed500c98f16f4cf2b0db053ec0953cd/src/utilities/behaviors/SteamVRInput.js#L6-L19
|
train
|
tschaub/grunt-gh-pages
|
lib/git.js
|
spawn
|
function spawn(exe, args, cwd) {
const deferred = Q.defer();
const child = cp.spawn(exe, args, {cwd: cwd || process.cwd()});
const buffer = [];
child.stderr.on('data', chunk => {
buffer.push(chunk.toString());
});
child.stdout.on('data', chunk => {
deferred.notify(chunk);
});
child.on('close', code => {
if (code) {
const msg = buffer.join('') || `Process failed: ${code}`;
deferred.reject(new ProcessError(code, msg));
} else {
deferred.resolve(code);
}
});
return deferred.promise;
}
|
javascript
|
function spawn(exe, args, cwd) {
const deferred = Q.defer();
const child = cp.spawn(exe, args, {cwd: cwd || process.cwd()});
const buffer = [];
child.stderr.on('data', chunk => {
buffer.push(chunk.toString());
});
child.stdout.on('data', chunk => {
deferred.notify(chunk);
});
child.on('close', code => {
if (code) {
const msg = buffer.join('') || `Process failed: ${code}`;
deferred.reject(new ProcessError(code, msg));
} else {
deferred.resolve(code);
}
});
return deferred.promise;
}
|
[
"function",
"spawn",
"(",
"exe",
",",
"args",
",",
"cwd",
")",
"{",
"const",
"deferred",
"=",
"Q",
".",
"defer",
"(",
")",
";",
"const",
"child",
"=",
"cp",
".",
"spawn",
"(",
"exe",
",",
"args",
",",
"{",
"cwd",
":",
"cwd",
"||",
"process",
".",
"cwd",
"(",
")",
"}",
")",
";",
"const",
"buffer",
"=",
"[",
"]",
";",
"child",
".",
"stderr",
".",
"on",
"(",
"'data'",
",",
"chunk",
"=>",
"{",
"buffer",
".",
"push",
"(",
"chunk",
".",
"toString",
"(",
")",
")",
";",
"}",
")",
";",
"child",
".",
"stdout",
".",
"on",
"(",
"'data'",
",",
"chunk",
"=>",
"{",
"deferred",
".",
"notify",
"(",
"chunk",
")",
";",
"}",
")",
";",
"child",
".",
"on",
"(",
"'close'",
",",
"code",
"=>",
"{",
"if",
"(",
"code",
")",
"{",
"const",
"msg",
"=",
"buffer",
".",
"join",
"(",
"''",
")",
"||",
"`",
"${",
"code",
"}",
"`",
";",
"deferred",
".",
"reject",
"(",
"new",
"ProcessError",
"(",
"code",
",",
"msg",
")",
")",
";",
"}",
"else",
"{",
"deferred",
".",
"resolve",
"(",
"code",
")",
";",
"}",
"}",
")",
";",
"return",
"deferred",
".",
"promise",
";",
"}"
] |
Util function for handling spawned processes as promises.
@param {string} exe Executable.
@param {Array.<string>} args Arguments.
@param {string} cwd Working directory.
@return {Promise} A promise.
|
[
"Util",
"function",
"for",
"handling",
"spawned",
"processes",
"as",
"promises",
"."
] |
84effda4864e87b8bfc63e418e1c8a8bf3751309
|
https://github.com/tschaub/grunt-gh-pages/blob/84effda4864e87b8bfc63e418e1c8a8bf3751309/lib/git.js#L52-L71
|
train
|
tschaub/grunt-gh-pages
|
lib/util.js
|
makeDir
|
function makeDir(path, callback) {
fs.mkdir(path, err => {
if (err) {
// check if directory exists
fs.stat(path, (err2, stat) => {
if (err2 || !stat.isDirectory()) {
callback(err);
} else {
callback();
}
});
} else {
callback();
}
});
}
|
javascript
|
function makeDir(path, callback) {
fs.mkdir(path, err => {
if (err) {
// check if directory exists
fs.stat(path, (err2, stat) => {
if (err2 || !stat.isDirectory()) {
callback(err);
} else {
callback();
}
});
} else {
callback();
}
});
}
|
[
"function",
"makeDir",
"(",
"path",
",",
"callback",
")",
"{",
"fs",
".",
"mkdir",
"(",
"path",
",",
"err",
"=>",
"{",
"if",
"(",
"err",
")",
"{",
"fs",
".",
"stat",
"(",
"path",
",",
"(",
"err2",
",",
"stat",
")",
"=>",
"{",
"if",
"(",
"err2",
"||",
"!",
"stat",
".",
"isDirectory",
"(",
")",
")",
"{",
"callback",
"(",
"err",
")",
";",
"}",
"else",
"{",
"callback",
"(",
")",
";",
"}",
"}",
")",
";",
"}",
"else",
"{",
"callback",
"(",
")",
";",
"}",
"}",
")",
";",
"}"
] |
Make directory, ignoring errors if directory already exists.
@param {string} path Directory path.
@param {function(Error)} callback Callback.
|
[
"Make",
"directory",
"ignoring",
"errors",
"if",
"directory",
"already",
"exists",
"."
] |
84effda4864e87b8bfc63e418e1c8a8bf3751309
|
https://github.com/tschaub/grunt-gh-pages/blob/84effda4864e87b8bfc63e418e1c8a8bf3751309/lib/util.js#L104-L119
|
train
|
ProseMirror/prosemirror-history
|
src/history.js
|
mustPreserveItems
|
function mustPreserveItems(state) {
let plugins = state.plugins
if (cachedPreserveItemsPlugins != plugins) {
cachedPreserveItems = false
cachedPreserveItemsPlugins = plugins
for (let i = 0; i < plugins.length; i++) if (plugins[i].spec.historyPreserveItems) {
cachedPreserveItems = true
break
}
}
return cachedPreserveItems
}
|
javascript
|
function mustPreserveItems(state) {
let plugins = state.plugins
if (cachedPreserveItemsPlugins != plugins) {
cachedPreserveItems = false
cachedPreserveItemsPlugins = plugins
for (let i = 0; i < plugins.length; i++) if (plugins[i].spec.historyPreserveItems) {
cachedPreserveItems = true
break
}
}
return cachedPreserveItems
}
|
[
"function",
"mustPreserveItems",
"(",
"state",
")",
"{",
"let",
"plugins",
"=",
"state",
".",
"plugins",
"if",
"(",
"cachedPreserveItemsPlugins",
"!=",
"plugins",
")",
"{",
"cachedPreserveItems",
"=",
"false",
"cachedPreserveItemsPlugins",
"=",
"plugins",
"for",
"(",
"let",
"i",
"=",
"0",
";",
"i",
"<",
"plugins",
".",
"length",
";",
"i",
"++",
")",
"if",
"(",
"plugins",
"[",
"i",
"]",
".",
"spec",
".",
"historyPreserveItems",
")",
"{",
"cachedPreserveItems",
"=",
"true",
"break",
"}",
"}",
"return",
"cachedPreserveItems",
"}"
] |
Check whether any plugin in the given state has a `historyPreserveItems` property in its spec, in which case we must preserve steps exactly as they came in, so that they can be rebased.
|
[
"Check",
"whether",
"any",
"plugin",
"in",
"the",
"given",
"state",
"has",
"a",
"historyPreserveItems",
"property",
"in",
"its",
"spec",
"in",
"which",
"case",
"we",
"must",
"preserve",
"steps",
"exactly",
"as",
"they",
"came",
"in",
"so",
"that",
"they",
"can",
"be",
"rebased",
"."
] |
e1f3590f8f9b5bf1e6925dcadb0a6c2c8e715e5f
|
https://github.com/ProseMirror/prosemirror-history/blob/e1f3590f8f9b5bf1e6925dcadb0a6c2c8e715e5f/src/history.js#L344-L355
|
train
|
wecodemore/grunt-githooks
|
lib/githooks.js
|
Hook
|
function Hook(hookName, taskNames, options) {
/**
* The name of the hook
* @property hookName
* @type {String}
*/
this.hookName = hookName;
/**
* The name of the tasks that should be run by the hook, space separated
* @property taskNames
* @type {String}
*/
this.taskNames = taskNames;
/**
* Options for the creation of the hook
* @property options
* @type {Object}
*/
this.options = options || {};
this.markerRegExp = new RegExp(this.options.startMarker.replace(/\//g, '\\/') +
'[\\s\\S]*' + // Not .* because it needs to match \n
this.options.endMarker.replace(/\//g, '\\/'), 'm');
}
|
javascript
|
function Hook(hookName, taskNames, options) {
/**
* The name of the hook
* @property hookName
* @type {String}
*/
this.hookName = hookName;
/**
* The name of the tasks that should be run by the hook, space separated
* @property taskNames
* @type {String}
*/
this.taskNames = taskNames;
/**
* Options for the creation of the hook
* @property options
* @type {Object}
*/
this.options = options || {};
this.markerRegExp = new RegExp(this.options.startMarker.replace(/\//g, '\\/') +
'[\\s\\S]*' + // Not .* because it needs to match \n
this.options.endMarker.replace(/\//g, '\\/'), 'm');
}
|
[
"function",
"Hook",
"(",
"hookName",
",",
"taskNames",
",",
"options",
")",
"{",
"this",
".",
"hookName",
"=",
"hookName",
";",
"this",
".",
"taskNames",
"=",
"taskNames",
";",
"this",
".",
"options",
"=",
"options",
"||",
"{",
"}",
";",
"this",
".",
"markerRegExp",
"=",
"new",
"RegExp",
"(",
"this",
".",
"options",
".",
"startMarker",
".",
"replace",
"(",
"/",
"\\/",
"/",
"g",
",",
"'\\\\/'",
")",
"+",
"\\\\",
"+",
"'[\\\\s\\\\S]*'",
",",
"\\\\",
")",
";",
"}"
] |
Class to help manage a hook
@class Hook
@module githooks
@constructor
|
[
"Class",
"to",
"help",
"manage",
"a",
"hook"
] |
8a026d6b9529c7923e734960813d1f54315a8e47
|
https://github.com/wecodemore/grunt-githooks/blob/8a026d6b9529c7923e734960813d1f54315a8e47/lib/githooks.js#L14-L40
|
train
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.