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 |
---|---|---|---|---|---|---|---|---|---|---|---|
hogart/rpg-tools | lib/inventory.js | equipFromInventory | function equipFromInventory (attributes, index, slotName) {
if (index >= attributes.inventory.length) {
throw new InventoryIndexError(index);
}
var item = attributes.inventory[index];
if (!slotName) {
slotName = item.slot;
}
if (!slotName) {
throw new UnequippableItemError(item.name);
}
if (!(slotName in attributes.equipped)) {
throw new SlotNameError(slotName);
}
if (item.slot !== slotName) {
throw new InvalidSlotError(item.slot, slotName);
}
if (!requirements.met(attributes, item.requirements)) {
throw new RequirementsNotMetError();
}
if (attributes.equipped[slotName]) {
unEquip(attributes, slotName);
}
attributes.inventory.splice(index, 1);
attributes.equipped[slotName] = item;
return attributes;
} | javascript | function equipFromInventory (attributes, index, slotName) {
if (index >= attributes.inventory.length) {
throw new InventoryIndexError(index);
}
var item = attributes.inventory[index];
if (!slotName) {
slotName = item.slot;
}
if (!slotName) {
throw new UnequippableItemError(item.name);
}
if (!(slotName in attributes.equipped)) {
throw new SlotNameError(slotName);
}
if (item.slot !== slotName) {
throw new InvalidSlotError(item.slot, slotName);
}
if (!requirements.met(attributes, item.requirements)) {
throw new RequirementsNotMetError();
}
if (attributes.equipped[slotName]) {
unEquip(attributes, slotName);
}
attributes.inventory.splice(index, 1);
attributes.equipped[slotName] = item;
return attributes;
} | [
"function",
"equipFromInventory",
"(",
"attributes",
",",
"index",
",",
"slotName",
")",
"{",
"if",
"(",
"index",
">=",
"attributes",
".",
"inventory",
".",
"length",
")",
"{",
"throw",
"new",
"InventoryIndexError",
"(",
"index",
")",
";",
"}",
"var",
"item",
"=",
"attributes",
".",
"inventory",
"[",
"index",
"]",
";",
"if",
"(",
"!",
"slotName",
")",
"{",
"slotName",
"=",
"item",
".",
"slot",
";",
"}",
"if",
"(",
"!",
"slotName",
")",
"{",
"throw",
"new",
"UnequippableItemError",
"(",
"item",
".",
"name",
")",
";",
"}",
"if",
"(",
"!",
"(",
"slotName",
"in",
"attributes",
".",
"equipped",
")",
")",
"{",
"throw",
"new",
"SlotNameError",
"(",
"slotName",
")",
";",
"}",
"if",
"(",
"item",
".",
"slot",
"!==",
"slotName",
")",
"{",
"throw",
"new",
"InvalidSlotError",
"(",
"item",
".",
"slot",
",",
"slotName",
")",
";",
"}",
"if",
"(",
"!",
"requirements",
".",
"met",
"(",
"attributes",
",",
"item",
".",
"requirements",
")",
")",
"{",
"throw",
"new",
"RequirementsNotMetError",
"(",
")",
";",
"}",
"if",
"(",
"attributes",
".",
"equipped",
"[",
"slotName",
"]",
")",
"{",
"unEquip",
"(",
"attributes",
",",
"slotName",
")",
";",
"}",
"attributes",
".",
"inventory",
".",
"splice",
"(",
"index",
",",
"1",
")",
";",
"attributes",
".",
"equipped",
"[",
"slotName",
"]",
"=",
"item",
";",
"return",
"attributes",
";",
"}"
]
| Equips item which is located in inventory by given index
@param {Attributes} attributes which object should be operated.
@param {number} index inventory slot number
@param {String} slotName where to equip | [
"Equips",
"item",
"which",
"is",
"located",
"in",
"inventory",
"by",
"given",
"index"
]
| 6909e3f3c21c2fd4c9e7d82103a69f11ae7e4375 | https://github.com/hogart/rpg-tools/blob/6909e3f3c21c2fd4c9e7d82103a69f11ae7e4375/lib/inventory.js#L118-L153 | train |
hogart/rpg-tools | lib/inventory.js | isWearable | function isWearable (attributes, index) {
if (index >= attributes.inventory.length) {
throw new InventoryIndexError(index);
}
var item = attributes.inventory[index];
if (!requirements.met(attributes, item.requirements)) {
throw new RequirementsNotMetError();
}
var slotName = item.slot;
if (!slotName) {
throw new UnequippableItemError(item.name);
}
return slotName;
} | javascript | function isWearable (attributes, index) {
if (index >= attributes.inventory.length) {
throw new InventoryIndexError(index);
}
var item = attributes.inventory[index];
if (!requirements.met(attributes, item.requirements)) {
throw new RequirementsNotMetError();
}
var slotName = item.slot;
if (!slotName) {
throw new UnequippableItemError(item.name);
}
return slotName;
} | [
"function",
"isWearable",
"(",
"attributes",
",",
"index",
")",
"{",
"if",
"(",
"index",
">=",
"attributes",
".",
"inventory",
".",
"length",
")",
"{",
"throw",
"new",
"InventoryIndexError",
"(",
"index",
")",
";",
"}",
"var",
"item",
"=",
"attributes",
".",
"inventory",
"[",
"index",
"]",
";",
"if",
"(",
"!",
"requirements",
".",
"met",
"(",
"attributes",
",",
"item",
".",
"requirements",
")",
")",
"{",
"throw",
"new",
"RequirementsNotMetError",
"(",
")",
";",
"}",
"var",
"slotName",
"=",
"item",
".",
"slot",
";",
"if",
"(",
"!",
"slotName",
")",
"{",
"throw",
"new",
"UnequippableItemError",
"(",
"item",
".",
"name",
")",
";",
"}",
"return",
"slotName",
";",
"}"
]
| Given index of item, returns list of possible slots
@param {Attributes} attributes
@param {number} index
@return {String} | [
"Given",
"index",
"of",
"item",
"returns",
"list",
"of",
"possible",
"slots"
]
| 6909e3f3c21c2fd4c9e7d82103a69f11ae7e4375 | https://github.com/hogart/rpg-tools/blob/6909e3f3c21c2fd4c9e7d82103a69f11ae7e4375/lib/inventory.js#L161-L179 | train |
okunishinishi/node-mysqldesc | lib/describing/mysql_describer.js | function (database, callback) {
var s = this,
querier = s._querier;
querier.connect();
async.waterfall([
function (callback) {
querier.showTables(database, function (err, tables) {
callback(err, tables);
});
},
function (tables, callback) {
var tableNames = s._parseTableNames(tables);
async.map(tableNames, function (table, callback) {
querier.descTable(database, table, function (err, data1) {
querier.selectKeyColumnUsage(database, table, function (err, data2) {
callback(err, {
name: table,
columns: s._parseTableData(data1),
relations: s._getRelations(data2, table)
});
});
});
}, callback);
},
function (data, callback) {
var database = {};
data.forEach(function (data) {
database[data.name] = data;
});
callback(null, database);
}
], function (err, result) {
querier.disconnect();
callback(err, result);
});
return s;
} | javascript | function (database, callback) {
var s = this,
querier = s._querier;
querier.connect();
async.waterfall([
function (callback) {
querier.showTables(database, function (err, tables) {
callback(err, tables);
});
},
function (tables, callback) {
var tableNames = s._parseTableNames(tables);
async.map(tableNames, function (table, callback) {
querier.descTable(database, table, function (err, data1) {
querier.selectKeyColumnUsage(database, table, function (err, data2) {
callback(err, {
name: table,
columns: s._parseTableData(data1),
relations: s._getRelations(data2, table)
});
});
});
}, callback);
},
function (data, callback) {
var database = {};
data.forEach(function (data) {
database[data.name] = data;
});
callback(null, database);
}
], function (err, result) {
querier.disconnect();
callback(err, result);
});
return s;
} | [
"function",
"(",
"database",
",",
"callback",
")",
"{",
"var",
"s",
"=",
"this",
",",
"querier",
"=",
"s",
".",
"_querier",
";",
"querier",
".",
"connect",
"(",
")",
";",
"async",
".",
"waterfall",
"(",
"[",
"function",
"(",
"callback",
")",
"{",
"querier",
".",
"showTables",
"(",
"database",
",",
"function",
"(",
"err",
",",
"tables",
")",
"{",
"callback",
"(",
"err",
",",
"tables",
")",
";",
"}",
")",
";",
"}",
",",
"function",
"(",
"tables",
",",
"callback",
")",
"{",
"var",
"tableNames",
"=",
"s",
".",
"_parseTableNames",
"(",
"tables",
")",
";",
"async",
".",
"map",
"(",
"tableNames",
",",
"function",
"(",
"table",
",",
"callback",
")",
"{",
"querier",
".",
"descTable",
"(",
"database",
",",
"table",
",",
"function",
"(",
"err",
",",
"data1",
")",
"{",
"querier",
".",
"selectKeyColumnUsage",
"(",
"database",
",",
"table",
",",
"function",
"(",
"err",
",",
"data2",
")",
"{",
"callback",
"(",
"err",
",",
"{",
"name",
":",
"table",
",",
"columns",
":",
"s",
".",
"_parseTableData",
"(",
"data1",
")",
",",
"relations",
":",
"s",
".",
"_getRelations",
"(",
"data2",
",",
"table",
")",
"}",
")",
";",
"}",
")",
";",
"}",
")",
";",
"}",
",",
"callback",
")",
";",
"}",
",",
"function",
"(",
"data",
",",
"callback",
")",
"{",
"var",
"database",
"=",
"{",
"}",
";",
"data",
".",
"forEach",
"(",
"function",
"(",
"data",
")",
"{",
"database",
"[",
"data",
".",
"name",
"]",
"=",
"data",
";",
"}",
")",
";",
"callback",
"(",
"null",
",",
"database",
")",
";",
"}",
"]",
",",
"function",
"(",
"err",
",",
"result",
")",
"{",
"querier",
".",
"disconnect",
"(",
")",
";",
"callback",
"(",
"err",
",",
"result",
")",
";",
"}",
")",
";",
"return",
"s",
";",
"}"
]
| Describe database.
@param {string} database - Name of database.
@param {function} callback - Callback when done.
@returns {MysqlDescriber} - Returns self. | [
"Describe",
"database",
"."
]
| df88626bce889cb1d4f1879387a77d3a480d676a | https://github.com/okunishinishi/node-mysqldesc/blob/df88626bce889cb1d4f1879387a77d3a480d676a/lib/describing/mysql_describer.js#L30-L66 | train |
|
okunishinishi/node-mysqldesc | lib/describing/mysql_describer.js | function (database, table, callback) {
var s = this,
querier = s._querier;
querier.connect();
querier.descTable(database, table, function (err, data) {
querier.disconnect();
callback(err, s._parseTableData(data || {}));
});
return s;
} | javascript | function (database, table, callback) {
var s = this,
querier = s._querier;
querier.connect();
querier.descTable(database, table, function (err, data) {
querier.disconnect();
callback(err, s._parseTableData(data || {}));
});
return s;
} | [
"function",
"(",
"database",
",",
"table",
",",
"callback",
")",
"{",
"var",
"s",
"=",
"this",
",",
"querier",
"=",
"s",
".",
"_querier",
";",
"querier",
".",
"connect",
"(",
")",
";",
"querier",
".",
"descTable",
"(",
"database",
",",
"table",
",",
"function",
"(",
"err",
",",
"data",
")",
"{",
"querier",
".",
"disconnect",
"(",
")",
";",
"callback",
"(",
"err",
",",
"s",
".",
"_parseTableData",
"(",
"data",
"||",
"{",
"}",
")",
")",
";",
"}",
")",
";",
"return",
"s",
";",
"}"
]
| Describe mysql table.
@param {string} database - Name of database.
@param {string} table - Name of table.
@param {function} callback - Callback when done.
@returns {MysqlDescriber} | [
"Describe",
"mysql",
"table",
"."
]
| df88626bce889cb1d4f1879387a77d3a480d676a | https://github.com/okunishinishi/node-mysqldesc/blob/df88626bce889cb1d4f1879387a77d3a480d676a/lib/describing/mysql_describer.js#L74-L83 | train |
|
okunishinishi/node-mysqldesc | lib/describing/mysql_describer.js | function (database, callback) {
var s = this,
querier = s._querier;
querier.connect();
async.waterfall([
function (callback) {
querier.showTables(database, function (err, tables) {
callback(err, tables);
});
},
function (tables, callback) {
var tableNames = s._parseTableNames(tables);
async.map(tableNames, function (table, callback) {
querier.selectKeyColumnUsage(database, table, function (err, data) {
callback(err, {
name: table,
keyColumnUsage: s._parseTableKeyColumnUsageData(data)
});
});
}, callback);
},
function (data, callback) {
var database = {};
data.forEach(function (data) {
database[data.name] = data.keyColumnUsage;
});
callback(null, database);
}
], function (err, result) {
querier.disconnect();
callback(err, result);
});
return s;
} | javascript | function (database, callback) {
var s = this,
querier = s._querier;
querier.connect();
async.waterfall([
function (callback) {
querier.showTables(database, function (err, tables) {
callback(err, tables);
});
},
function (tables, callback) {
var tableNames = s._parseTableNames(tables);
async.map(tableNames, function (table, callback) {
querier.selectKeyColumnUsage(database, table, function (err, data) {
callback(err, {
name: table,
keyColumnUsage: s._parseTableKeyColumnUsageData(data)
});
});
}, callback);
},
function (data, callback) {
var database = {};
data.forEach(function (data) {
database[data.name] = data.keyColumnUsage;
});
callback(null, database);
}
], function (err, result) {
querier.disconnect();
callback(err, result);
});
return s;
} | [
"function",
"(",
"database",
",",
"callback",
")",
"{",
"var",
"s",
"=",
"this",
",",
"querier",
"=",
"s",
".",
"_querier",
";",
"querier",
".",
"connect",
"(",
")",
";",
"async",
".",
"waterfall",
"(",
"[",
"function",
"(",
"callback",
")",
"{",
"querier",
".",
"showTables",
"(",
"database",
",",
"function",
"(",
"err",
",",
"tables",
")",
"{",
"callback",
"(",
"err",
",",
"tables",
")",
";",
"}",
")",
";",
"}",
",",
"function",
"(",
"tables",
",",
"callback",
")",
"{",
"var",
"tableNames",
"=",
"s",
".",
"_parseTableNames",
"(",
"tables",
")",
";",
"async",
".",
"map",
"(",
"tableNames",
",",
"function",
"(",
"table",
",",
"callback",
")",
"{",
"querier",
".",
"selectKeyColumnUsage",
"(",
"database",
",",
"table",
",",
"function",
"(",
"err",
",",
"data",
")",
"{",
"callback",
"(",
"err",
",",
"{",
"name",
":",
"table",
",",
"keyColumnUsage",
":",
"s",
".",
"_parseTableKeyColumnUsageData",
"(",
"data",
")",
"}",
")",
";",
"}",
")",
";",
"}",
",",
"callback",
")",
";",
"}",
",",
"function",
"(",
"data",
",",
"callback",
")",
"{",
"var",
"database",
"=",
"{",
"}",
";",
"data",
".",
"forEach",
"(",
"function",
"(",
"data",
")",
"{",
"database",
"[",
"data",
".",
"name",
"]",
"=",
"data",
".",
"keyColumnUsage",
";",
"}",
")",
";",
"callback",
"(",
"null",
",",
"database",
")",
";",
"}",
"]",
",",
"function",
"(",
"err",
",",
"result",
")",
"{",
"querier",
".",
"disconnect",
"(",
")",
";",
"callback",
"(",
"err",
",",
"result",
")",
";",
"}",
")",
";",
"return",
"s",
";",
"}"
]
| Describe key column usages in database.
@param {string} database - Name of database.
@param {function} callback - Callback when done.
@returns {MysqlDescriber} | [
"Describe",
"key",
"column",
"usages",
"in",
"database",
"."
]
| df88626bce889cb1d4f1879387a77d3a480d676a | https://github.com/okunishinishi/node-mysqldesc/blob/df88626bce889cb1d4f1879387a77d3a480d676a/lib/describing/mysql_describer.js#L90-L123 | train |
|
okunishinishi/node-mysqldesc | lib/describing/mysql_describer.js | function (database, table, callback) {
var s = this,
querier = s._querier;
querier.connect();
querier.selectKeyColumnUsage(database, table, function (err, data) {
querier.disconnect();
callback(err, s._parseTableKeyColumnUsageData(data));
});
return s;
} | javascript | function (database, table, callback) {
var s = this,
querier = s._querier;
querier.connect();
querier.selectKeyColumnUsage(database, table, function (err, data) {
querier.disconnect();
callback(err, s._parseTableKeyColumnUsageData(data));
});
return s;
} | [
"function",
"(",
"database",
",",
"table",
",",
"callback",
")",
"{",
"var",
"s",
"=",
"this",
",",
"querier",
"=",
"s",
".",
"_querier",
";",
"querier",
".",
"connect",
"(",
")",
";",
"querier",
".",
"selectKeyColumnUsage",
"(",
"database",
",",
"table",
",",
"function",
"(",
"err",
",",
"data",
")",
"{",
"querier",
".",
"disconnect",
"(",
")",
";",
"callback",
"(",
"err",
",",
"s",
".",
"_parseTableKeyColumnUsageData",
"(",
"data",
")",
")",
";",
"}",
")",
";",
"return",
"s",
";",
"}"
]
| Describe key column usage for a table.
@param {string} database - Name of database.
@param {string} table - Name of table.
@param {function} callback - Callback when done.
@returns {MysqlDescriber} | [
"Describe",
"key",
"column",
"usage",
"for",
"a",
"table",
"."
]
| df88626bce889cb1d4f1879387a77d3a480d676a | https://github.com/okunishinishi/node-mysqldesc/blob/df88626bce889cb1d4f1879387a77d3a480d676a/lib/describing/mysql_describer.js#L131-L140 | train |
|
vieron/ui-docs | lib/doc-parser.js | function() {
var block_tpl_content = fs.readFileSync(
path.join(this.opts.templatePath, 'doc-block.hbs'));
this.tpl_block = this.hbs.compile(block_tpl_content.toString());
includeHelper.register(this.hbs, this);
this._postProcessDocFiles();
return this;
} | javascript | function() {
var block_tpl_content = fs.readFileSync(
path.join(this.opts.templatePath, 'doc-block.hbs'));
this.tpl_block = this.hbs.compile(block_tpl_content.toString());
includeHelper.register(this.hbs, this);
this._postProcessDocFiles();
return this;
} | [
"function",
"(",
")",
"{",
"var",
"block_tpl_content",
"=",
"fs",
".",
"readFileSync",
"(",
"path",
".",
"join",
"(",
"this",
".",
"opts",
".",
"templatePath",
",",
"'doc-block.hbs'",
")",
")",
";",
"this",
".",
"tpl_block",
"=",
"this",
".",
"hbs",
".",
"compile",
"(",
"block_tpl_content",
".",
"toString",
"(",
")",
")",
";",
"includeHelper",
".",
"register",
"(",
"this",
".",
"hbs",
",",
"this",
")",
";",
"this",
".",
"_postProcessDocFiles",
"(",
")",
";",
"return",
"this",
";",
"}"
]
| ADDING NEW THINGS TO DOC BLOCKS | [
"ADDING",
"NEW",
"THINGS",
"TO",
"DOC",
"BLOCKS"
]
| 8cf2ed4da9dc676d23170ba3612df7e1d4e15b11 | https://github.com/vieron/ui-docs/blob/8cf2ed4da9dc676d23170ba3612df7e1d4e15b11/lib/doc-parser.js#L264-L273 | train |
|
unshiftio/beacons | image.js | Image | function Image() {
if (!this) return new Image();
this.url = null;
EventEmitter.call(this);
setTimeout(function timeout() {
if (this.onerror) this.on('error', this.onerror);
if (this.onload) this.on('load', this.onload);
}.bind(this));
} | javascript | function Image() {
if (!this) return new Image();
this.url = null;
EventEmitter.call(this);
setTimeout(function timeout() {
if (this.onerror) this.on('error', this.onerror);
if (this.onload) this.on('load', this.onload);
}.bind(this));
} | [
"function",
"Image",
"(",
")",
"{",
"if",
"(",
"!",
"this",
")",
"return",
"new",
"Image",
"(",
")",
";",
"this",
".",
"url",
"=",
"null",
";",
"EventEmitter",
".",
"call",
"(",
"this",
")",
";",
"setTimeout",
"(",
"function",
"timeout",
"(",
")",
"{",
"if",
"(",
"this",
".",
"onerror",
")",
"this",
".",
"on",
"(",
"'error'",
",",
"this",
".",
"onerror",
")",
";",
"if",
"(",
"this",
".",
"onload",
")",
"this",
".",
"on",
"(",
"'load'",
",",
"this",
".",
"onload",
")",
";",
"}",
".",
"bind",
"(",
"this",
")",
")",
";",
"}"
]
| Image instance.
@constructor
@param {String} url URL we want to connect to
@api private
/* istanbul ignore next | [
"Image",
"instance",
"."
]
| baf355d411ec22ebd557a296113ee3f3256ead6e | https://github.com/unshiftio/beacons/blob/baf355d411ec22ebd557a296113ee3f3256ead6e/image.js#L14-L25 | train |
sagely/grunt-zaproxy | tasks/zaproxy.js | function (zaproxy, statusFn, callback) {
var wait = function () {
statusFn(function (err, body) {
if (err) {
callback(err);
return;
}
if (body.status < 100) {
grunt.log.write('.');
setTimeout(function () {
wait(callback);
}, 1000);
} else {
callback(null, body);
}
});
};
wait();
} | javascript | function (zaproxy, statusFn, callback) {
var wait = function () {
statusFn(function (err, body) {
if (err) {
callback(err);
return;
}
if (body.status < 100) {
grunt.log.write('.');
setTimeout(function () {
wait(callback);
}, 1000);
} else {
callback(null, body);
}
});
};
wait();
} | [
"function",
"(",
"zaproxy",
",",
"statusFn",
",",
"callback",
")",
"{",
"var",
"wait",
"=",
"function",
"(",
")",
"{",
"statusFn",
"(",
"function",
"(",
"err",
",",
"body",
")",
"{",
"if",
"(",
"err",
")",
"{",
"callback",
"(",
"err",
")",
";",
"return",
";",
"}",
"if",
"(",
"body",
".",
"status",
"<",
"100",
")",
"{",
"grunt",
".",
"log",
".",
"write",
"(",
"'.'",
")",
";",
"setTimeout",
"(",
"function",
"(",
")",
"{",
"wait",
"(",
"callback",
")",
";",
"}",
",",
"1000",
")",
";",
"}",
"else",
"{",
"callback",
"(",
"null",
",",
"body",
")",
";",
"}",
"}",
")",
";",
"}",
";",
"wait",
"(",
")",
";",
"}"
]
| Wait for a scan to finish. | [
"Wait",
"for",
"a",
"scan",
"to",
"finish",
"."
]
| f93fd5c8f37f3c2ec3bddf7c9d0ad631a088d92d | https://github.com/sagely/grunt-zaproxy/blob/f93fd5c8f37f3c2ec3bddf7c9d0ad631a088d92d/tasks/zaproxy.js#L157-L175 | train |
|
navicore/aglio-theme-bluecase | src/makecases.js | numberType | function numberType(mname, tpe, options) {
const doubles = options.themeDoubles.split(',')
if (doubles && doubles.includes(mname)) {
return 'Double'
} else {
return 'Int'
}
} | javascript | function numberType(mname, tpe, options) {
const doubles = options.themeDoubles.split(',')
if (doubles && doubles.includes(mname)) {
return 'Double'
} else {
return 'Int'
}
} | [
"function",
"numberType",
"(",
"mname",
",",
"tpe",
",",
"options",
")",
"{",
"const",
"doubles",
"=",
"options",
".",
"themeDoubles",
".",
"split",
"(",
"','",
")",
"if",
"(",
"doubles",
"&&",
"doubles",
".",
"includes",
"(",
"mname",
")",
")",
"{",
"return",
"'Double'",
"}",
"else",
"{",
"return",
"'Int'",
"}",
"}"
]
| turn number into scala Double if element name matches cmdline arg list | [
"turn",
"number",
"into",
"scala",
"Double",
"if",
"element",
"name",
"matches",
"cmdline",
"arg",
"list"
]
| eae6c191b3cc8724cbca46ad9853e3270f20baff | https://github.com/navicore/aglio-theme-bluecase/blob/eae6c191b3cc8724cbca46ad9853e3270f20baff/src/makecases.js#L2-L9 | train |
chrisJohn404/ljswitchboard-ljm_device_curator | lib/t7_calibration_operations.js | getCurrentConfigs | function getCurrentConfigs(bundle) {
dbgHWTest('getCurrentConfigs', bundle.calibrationInfoValid);
var defered = q.defer();
bundle.device.sReadMany(bundle.infoToCache)
.then(function(results) {
// bundle.currentDeviceConfigs
results.forEach(function(result) {
bundle.currentDeviceConfigs[result.name] = result;
});
defered.resolve(bundle);
}, function(err) {
bundle.overallResult = false;
bundle.overallMessage = 'Failed to read current device configs.';
bundle.shortMessage = 'Failed';
defered.resolve(bundle);
});
return defered.promise;
} | javascript | function getCurrentConfigs(bundle) {
dbgHWTest('getCurrentConfigs', bundle.calibrationInfoValid);
var defered = q.defer();
bundle.device.sReadMany(bundle.infoToCache)
.then(function(results) {
// bundle.currentDeviceConfigs
results.forEach(function(result) {
bundle.currentDeviceConfigs[result.name] = result;
});
defered.resolve(bundle);
}, function(err) {
bundle.overallResult = false;
bundle.overallMessage = 'Failed to read current device configs.';
bundle.shortMessage = 'Failed';
defered.resolve(bundle);
});
return defered.promise;
} | [
"function",
"getCurrentConfigs",
"(",
"bundle",
")",
"{",
"dbgHWTest",
"(",
"'getCurrentConfigs'",
",",
"bundle",
".",
"calibrationInfoValid",
")",
";",
"var",
"defered",
"=",
"q",
".",
"defer",
"(",
")",
";",
"bundle",
".",
"device",
".",
"sReadMany",
"(",
"bundle",
".",
"infoToCache",
")",
".",
"then",
"(",
"function",
"(",
"results",
")",
"{",
"results",
".",
"forEach",
"(",
"function",
"(",
"result",
")",
"{",
"bundle",
".",
"currentDeviceConfigs",
"[",
"result",
".",
"name",
"]",
"=",
"result",
";",
"}",
")",
";",
"defered",
".",
"resolve",
"(",
"bundle",
")",
";",
"}",
",",
"function",
"(",
"err",
")",
"{",
"bundle",
".",
"overallResult",
"=",
"false",
";",
"bundle",
".",
"overallMessage",
"=",
"'Failed to read current device configs.'",
";",
"bundle",
".",
"shortMessage",
"=",
"'Failed'",
";",
"defered",
".",
"resolve",
"(",
"bundle",
")",
";",
"}",
")",
";",
"return",
"defered",
".",
"promise",
";",
"}"
]
| Read current device configuration & save it to the bundle. | [
"Read",
"current",
"device",
"configuration",
"&",
"save",
"it",
"to",
"the",
"bundle",
"."
]
| 36cb25645dfa0a68e906d5ec43e5514391947257 | https://github.com/chrisJohn404/ljswitchboard-ljm_device_curator/blob/36cb25645dfa0a68e906d5ec43e5514391947257/lib/t7_calibration_operations.js#L1266-L1284 | train |
feedhenry/grunt-fh-build | tasks/fh-build.js | function(bundle_deps) {
var patterns = [
'**',
'!dist/**',
'!plato/**',
'!cov-*/**',
'!test*/**',
'!config/**',
'!output/**',
'!coverage/**',
'!node_modules/**',
'!package.json', // this will be processed
'!Gruntfile.js',
'!Makefile',
'!makefile',
'!npm-debug.log',
'!*.sublime-project',
'!sonar-project.properties',
'!**/*.tar.gz'
];
if (bundle_deps) {
var nodeModulePatterns = _.uniq(getProductionNodeModules().map(formatDirectory));
patterns = patterns.concat(nodeModulePatterns);
}
var fhignore = grunt.config.get('fhignore');
var extras = [];
if (fhignore && _.isArray(fhignore)) {
extras = fhignore.map(function(elem) {
return '!' + elem;
});
}
Array.prototype.push.apply(patterns, extras);
var fhinclude = grunt.config.get('fhinclude');
extras = [];
if(fhinclude && _.isArray(fhinclude)) {
extras = fhinclude;
}
Array.prototype.push.apply(patterns, extras);
grunt.log.debug("Patterns: " + patterns);
return patterns;
} | javascript | function(bundle_deps) {
var patterns = [
'**',
'!dist/**',
'!plato/**',
'!cov-*/**',
'!test*/**',
'!config/**',
'!output/**',
'!coverage/**',
'!node_modules/**',
'!package.json', // this will be processed
'!Gruntfile.js',
'!Makefile',
'!makefile',
'!npm-debug.log',
'!*.sublime-project',
'!sonar-project.properties',
'!**/*.tar.gz'
];
if (bundle_deps) {
var nodeModulePatterns = _.uniq(getProductionNodeModules().map(formatDirectory));
patterns = patterns.concat(nodeModulePatterns);
}
var fhignore = grunt.config.get('fhignore');
var extras = [];
if (fhignore && _.isArray(fhignore)) {
extras = fhignore.map(function(elem) {
return '!' + elem;
});
}
Array.prototype.push.apply(patterns, extras);
var fhinclude = grunt.config.get('fhinclude');
extras = [];
if(fhinclude && _.isArray(fhinclude)) {
extras = fhinclude;
}
Array.prototype.push.apply(patterns, extras);
grunt.log.debug("Patterns: " + patterns);
return patterns;
} | [
"function",
"(",
"bundle_deps",
")",
"{",
"var",
"patterns",
"=",
"[",
"'**'",
",",
"'!dist/**'",
",",
"'!plato/**'",
",",
"'!cov-*/**'",
",",
"'!test*/**'",
",",
"'!config/**'",
",",
"'!output/**'",
",",
"'!coverage/**'",
",",
"'!node_modules/**'",
",",
"'!package.json'",
",",
"'!Gruntfile.js'",
",",
"'!Makefile'",
",",
"'!makefile'",
",",
"'!npm-debug.log'",
",",
"'!*.sublime-project'",
",",
"'!sonar-project.properties'",
",",
"'!**/*.tar.gz'",
"]",
";",
"if",
"(",
"bundle_deps",
")",
"{",
"var",
"nodeModulePatterns",
"=",
"_",
".",
"uniq",
"(",
"getProductionNodeModules",
"(",
")",
".",
"map",
"(",
"formatDirectory",
")",
")",
";",
"patterns",
"=",
"patterns",
".",
"concat",
"(",
"nodeModulePatterns",
")",
";",
"}",
"var",
"fhignore",
"=",
"grunt",
".",
"config",
".",
"get",
"(",
"'fhignore'",
")",
";",
"var",
"extras",
"=",
"[",
"]",
";",
"if",
"(",
"fhignore",
"&&",
"_",
".",
"isArray",
"(",
"fhignore",
")",
")",
"{",
"extras",
"=",
"fhignore",
".",
"map",
"(",
"function",
"(",
"elem",
")",
"{",
"return",
"'!'",
"+",
"elem",
";",
"}",
")",
";",
"}",
"Array",
".",
"prototype",
".",
"push",
".",
"apply",
"(",
"patterns",
",",
"extras",
")",
";",
"var",
"fhinclude",
"=",
"grunt",
".",
"config",
".",
"get",
"(",
"'fhinclude'",
")",
";",
"extras",
"=",
"[",
"]",
";",
"if",
"(",
"fhinclude",
"&&",
"_",
".",
"isArray",
"(",
"fhinclude",
")",
")",
"{",
"extras",
"=",
"fhinclude",
";",
"}",
"Array",
".",
"prototype",
".",
"push",
".",
"apply",
"(",
"patterns",
",",
"extras",
")",
";",
"grunt",
".",
"log",
".",
"debug",
"(",
"\"Patterns: \"",
"+",
"patterns",
")",
";",
"return",
"patterns",
";",
"}"
]
| If grunt config contains an array property called 'fhignore',
its elements will be excluded from the tarball. | [
"If",
"grunt",
"config",
"contains",
"an",
"array",
"property",
"called",
"fhignore",
"its",
"elements",
"will",
"be",
"excluded",
"from",
"the",
"tarball",
"."
]
| 527e8d7806a80e10b479864ba142b4c8192babb6 | https://github.com/feedhenry/grunt-fh-build/blob/527e8d7806a80e10b479864ba142b4c8192babb6/tasks/fh-build.js#L71-L111 | train |
|
lemonde/knex-schema | lib/reset.js | reset | function reset(schemas) {
var resolver = new Resolver(schemas);
// Reduce force sequential execution.
return Promise.reduce(resolver.resolve().reverse(), resetSchema.bind(this), []);
} | javascript | function reset(schemas) {
var resolver = new Resolver(schemas);
// Reduce force sequential execution.
return Promise.reduce(resolver.resolve().reverse(), resetSchema.bind(this), []);
} | [
"function",
"reset",
"(",
"schemas",
")",
"{",
"var",
"resolver",
"=",
"new",
"Resolver",
"(",
"schemas",
")",
";",
"return",
"Promise",
".",
"reduce",
"(",
"resolver",
".",
"resolve",
"(",
")",
".",
"reverse",
"(",
")",
",",
"resetSchema",
".",
"bind",
"(",
"this",
")",
",",
"[",
"]",
")",
";",
"}"
]
| Delete schemas tables data.
@param {[Schemas]} schemas
@return {Promise} | [
"Delete",
"schemas",
"tables",
"data",
"."
]
| 3e0f6cde374d240552eb08e50e123a513fda44ae | https://github.com/lemonde/knex-schema/blob/3e0f6cde374d240552eb08e50e123a513fda44ae/lib/reset.js#L19-L23 | train |
lemonde/knex-schema | lib/reset.js | resetSchema | function resetSchema(result, schema) {
var knex = this.knex;
return knex.schema.hasTable(schema.tableName)
.then(function (exists) {
if (! exists) return result;
return knex(schema.tableName).del()
.then(function () {
return result.concat([schema]);
});
});
} | javascript | function resetSchema(result, schema) {
var knex = this.knex;
return knex.schema.hasTable(schema.tableName)
.then(function (exists) {
if (! exists) return result;
return knex(schema.tableName).del()
.then(function () {
return result.concat([schema]);
});
});
} | [
"function",
"resetSchema",
"(",
"result",
",",
"schema",
")",
"{",
"var",
"knex",
"=",
"this",
".",
"knex",
";",
"return",
"knex",
".",
"schema",
".",
"hasTable",
"(",
"schema",
".",
"tableName",
")",
".",
"then",
"(",
"function",
"(",
"exists",
")",
"{",
"if",
"(",
"!",
"exists",
")",
"return",
"result",
";",
"return",
"knex",
"(",
"schema",
".",
"tableName",
")",
".",
"del",
"(",
")",
".",
"then",
"(",
"function",
"(",
")",
"{",
"return",
"result",
".",
"concat",
"(",
"[",
"schema",
"]",
")",
";",
"}",
")",
";",
"}",
")",
";",
"}"
]
| Delete schema table data.
@param {[Schema]} result - reduce accumulator
@param {Schema} schema
@return {Promise} | [
"Delete",
"schema",
"table",
"data",
"."
]
| 3e0f6cde374d240552eb08e50e123a513fda44ae | https://github.com/lemonde/knex-schema/blob/3e0f6cde374d240552eb08e50e123a513fda44ae/lib/reset.js#L33-L43 | train |
S3bb1/ah-dashboard-plugin | public/dashboard/bower_components/admin-lte/plugins/datatables/extensions/Scroller/js/dataTables.scroller.js | function ()
{
var heights = this.s.heights;
var max = 1000000;
heights.virtual = heights.row * this.s.dt.fnRecordsDisplay();
heights.scroll = heights.virtual;
if ( heights.scroll > max ) {
heights.scroll = max;
}
this.dom.force.style.height = heights.scroll+"px";
} | javascript | function ()
{
var heights = this.s.heights;
var max = 1000000;
heights.virtual = heights.row * this.s.dt.fnRecordsDisplay();
heights.scroll = heights.virtual;
if ( heights.scroll > max ) {
heights.scroll = max;
}
this.dom.force.style.height = heights.scroll+"px";
} | [
"function",
"(",
")",
"{",
"var",
"heights",
"=",
"this",
".",
"s",
".",
"heights",
";",
"var",
"max",
"=",
"1000000",
";",
"heights",
".",
"virtual",
"=",
"heights",
".",
"row",
"*",
"this",
".",
"s",
".",
"dt",
".",
"fnRecordsDisplay",
"(",
")",
";",
"heights",
".",
"scroll",
"=",
"heights",
".",
"virtual",
";",
"if",
"(",
"heights",
".",
"scroll",
">",
"max",
")",
"{",
"heights",
".",
"scroll",
"=",
"max",
";",
"}",
"this",
".",
"dom",
".",
"force",
".",
"style",
".",
"height",
"=",
"heights",
".",
"scroll",
"+",
"\"px\"",
";",
"}"
]
| Force the scrolling container to have height beyond that of just the
table that has been drawn so the user can scroll the whole data set.
Note that if the calculated required scrolling height exceeds a maximum
value (1 million pixels - hard-coded) the forcing element will be set
only to that maximum value and virtual / physical domain transforms will
be used to allow Scroller to display tables of any number of records.
@returns {void}
@private | [
"Force",
"the",
"scrolling",
"container",
"to",
"have",
"height",
"beyond",
"that",
"of",
"just",
"the",
"table",
"that",
"has",
"been",
"drawn",
"so",
"the",
"user",
"can",
"scroll",
"the",
"whole",
"data",
"set",
"."
]
| c283370ec0f99a25db5bb7029a98b4febf8c5251 | https://github.com/S3bb1/ah-dashboard-plugin/blob/c283370ec0f99a25db5bb7029a98b4febf8c5251/public/dashboard/bower_components/admin-lte/plugins/datatables/extensions/Scroller/js/dataTables.scroller.js#L859-L872 | train |
|
S3bb1/ah-dashboard-plugin | public/dashboard/bower_components/admin-lte/plugins/datatables/extensions/Scroller/js/dataTables.scroller.js | function ()
{
var dt = this.s.dt;
var origTable = dt.nTable;
var nTable = origTable.cloneNode( false );
var tbody = $('<tbody/>').appendTo( nTable );
var container = $(
'<div class="'+dt.oClasses.sWrapper+' DTS">'+
'<div class="'+dt.oClasses.sScrollWrapper+'">'+
'<div class="'+dt.oClasses.sScrollBody+'"></div>'+
'</div>'+
'</div>'
);
// Want 3 rows in the sizing table so :first-child and :last-child
// CSS styles don't come into play - take the size of the middle row
$('tbody tr:lt(4)', origTable).clone().appendTo( tbody );
while( $('tr', tbody).length < 3 ) {
tbody.append( '<tr><td> </td></tr>' );
}
$('div.'+dt.oClasses.sScrollBody, container).append( nTable );
var appendTo;
if (dt._bInitComplete) {
appendTo = origTable.parentNode;
} else {
if (!this.s.dt.nHolding) {
this.s.dt.nHolding = $( '<div></div>' ).insertBefore( this.s.dt.nTable );
}
appendTo = this.s.dt.nHolding;
}
container.appendTo( appendTo );
this.s.heights.row = $('tr', tbody).eq(1).outerHeight();
container.remove();
} | javascript | function ()
{
var dt = this.s.dt;
var origTable = dt.nTable;
var nTable = origTable.cloneNode( false );
var tbody = $('<tbody/>').appendTo( nTable );
var container = $(
'<div class="'+dt.oClasses.sWrapper+' DTS">'+
'<div class="'+dt.oClasses.sScrollWrapper+'">'+
'<div class="'+dt.oClasses.sScrollBody+'"></div>'+
'</div>'+
'</div>'
);
// Want 3 rows in the sizing table so :first-child and :last-child
// CSS styles don't come into play - take the size of the middle row
$('tbody tr:lt(4)', origTable).clone().appendTo( tbody );
while( $('tr', tbody).length < 3 ) {
tbody.append( '<tr><td> </td></tr>' );
}
$('div.'+dt.oClasses.sScrollBody, container).append( nTable );
var appendTo;
if (dt._bInitComplete) {
appendTo = origTable.parentNode;
} else {
if (!this.s.dt.nHolding) {
this.s.dt.nHolding = $( '<div></div>' ).insertBefore( this.s.dt.nTable );
}
appendTo = this.s.dt.nHolding;
}
container.appendTo( appendTo );
this.s.heights.row = $('tr', tbody).eq(1).outerHeight();
container.remove();
} | [
"function",
"(",
")",
"{",
"var",
"dt",
"=",
"this",
".",
"s",
".",
"dt",
";",
"var",
"origTable",
"=",
"dt",
".",
"nTable",
";",
"var",
"nTable",
"=",
"origTable",
".",
"cloneNode",
"(",
"false",
")",
";",
"var",
"tbody",
"=",
"$",
"(",
"'<tbody/>'",
")",
".",
"appendTo",
"(",
"nTable",
")",
";",
"var",
"container",
"=",
"$",
"(",
"'<div class=\"'",
"+",
"dt",
".",
"oClasses",
".",
"sWrapper",
"+",
"' DTS\">'",
"+",
"'<div class=\"'",
"+",
"dt",
".",
"oClasses",
".",
"sScrollWrapper",
"+",
"'\">'",
"+",
"'<div class=\"'",
"+",
"dt",
".",
"oClasses",
".",
"sScrollBody",
"+",
"'\"></div>'",
"+",
"'</div>'",
"+",
"'</div>'",
")",
";",
"$",
"(",
"'tbody tr:lt(4)'",
",",
"origTable",
")",
".",
"clone",
"(",
")",
".",
"appendTo",
"(",
"tbody",
")",
";",
"while",
"(",
"$",
"(",
"'tr'",
",",
"tbody",
")",
".",
"length",
"<",
"3",
")",
"{",
"tbody",
".",
"append",
"(",
"'<tr><td> </td></tr>'",
")",
";",
"}",
"$",
"(",
"'div.'",
"+",
"dt",
".",
"oClasses",
".",
"sScrollBody",
",",
"container",
")",
".",
"append",
"(",
"nTable",
")",
";",
"var",
"appendTo",
";",
"if",
"(",
"dt",
".",
"_bInitComplete",
")",
"{",
"appendTo",
"=",
"origTable",
".",
"parentNode",
";",
"}",
"else",
"{",
"if",
"(",
"!",
"this",
".",
"s",
".",
"dt",
".",
"nHolding",
")",
"{",
"this",
".",
"s",
".",
"dt",
".",
"nHolding",
"=",
"$",
"(",
"'<div></div>'",
")",
".",
"insertBefore",
"(",
"this",
".",
"s",
".",
"dt",
".",
"nTable",
")",
";",
"}",
"appendTo",
"=",
"this",
".",
"s",
".",
"dt",
".",
"nHolding",
";",
"}",
"container",
".",
"appendTo",
"(",
"appendTo",
")",
";",
"this",
".",
"s",
".",
"heights",
".",
"row",
"=",
"$",
"(",
"'tr'",
",",
"tbody",
")",
".",
"eq",
"(",
"1",
")",
".",
"outerHeight",
"(",
")",
";",
"container",
".",
"remove",
"(",
")",
";",
"}"
]
| Automatic calculation of table row height. This is just a little tricky here as using
initialisation DataTables has tale the table out of the document, so we need to create
a new table and insert it into the document, calculate the row height and then whip the
table out.
@returns {void}
@private | [
"Automatic",
"calculation",
"of",
"table",
"row",
"height",
".",
"This",
"is",
"just",
"a",
"little",
"tricky",
"here",
"as",
"using",
"initialisation",
"DataTables",
"has",
"tale",
"the",
"table",
"out",
"of",
"the",
"document",
"so",
"we",
"need",
"to",
"create",
"a",
"new",
"table",
"and",
"insert",
"it",
"into",
"the",
"document",
"calculate",
"the",
"row",
"height",
"and",
"then",
"whip",
"the",
"table",
"out",
"."
]
| c283370ec0f99a25db5bb7029a98b4febf8c5251 | https://github.com/S3bb1/ah-dashboard-plugin/blob/c283370ec0f99a25db5bb7029a98b4febf8c5251/public/dashboard/bower_components/admin-lte/plugins/datatables/extensions/Scroller/js/dataTables.scroller.js#L883-L919 | train |
|
S3bb1/ah-dashboard-plugin | public/dashboard/bower_components/admin-lte/plugins/datatables/extensions/Scroller/js/dataTables.scroller.js | function ()
{
if ( !this.s.dt.oFeatures.bInfo )
{
return;
}
var
dt = this.s.dt,
language = dt.oLanguage,
iScrollTop = this.dom.scroller.scrollTop,
iStart = Math.floor( this.fnPixelsToRow(iScrollTop, false, this.s.ani)+1 ),
iMax = dt.fnRecordsTotal(),
iTotal = dt.fnRecordsDisplay(),
iPossibleEnd = Math.ceil( this.fnPixelsToRow(iScrollTop+this.s.heights.viewport, false, this.s.ani) ),
iEnd = iTotal < iPossibleEnd ? iTotal : iPossibleEnd,
sStart = dt.fnFormatNumber( iStart ),
sEnd = dt.fnFormatNumber( iEnd ),
sMax = dt.fnFormatNumber( iMax ),
sTotal = dt.fnFormatNumber( iTotal ),
sOut;
if ( dt.fnRecordsDisplay() === 0 &&
dt.fnRecordsDisplay() == dt.fnRecordsTotal() )
{
/* Empty record set */
sOut = language.sInfoEmpty+ language.sInfoPostFix;
}
else if ( dt.fnRecordsDisplay() === 0 )
{
/* Empty record set after filtering */
sOut = language.sInfoEmpty +' '+
language.sInfoFiltered.replace('_MAX_', sMax)+
language.sInfoPostFix;
}
else if ( dt.fnRecordsDisplay() == dt.fnRecordsTotal() )
{
/* Normal record set */
sOut = language.sInfo.
replace('_START_', sStart).
replace('_END_', sEnd).
replace('_MAX_', sMax).
replace('_TOTAL_', sTotal)+
language.sInfoPostFix;
}
else
{
/* Record set after filtering */
sOut = language.sInfo.
replace('_START_', sStart).
replace('_END_', sEnd).
replace('_MAX_', sMax).
replace('_TOTAL_', sTotal) +' '+
language.sInfoFiltered.replace(
'_MAX_',
dt.fnFormatNumber(dt.fnRecordsTotal())
)+
language.sInfoPostFix;
}
var callback = language.fnInfoCallback;
if ( callback ) {
sOut = callback.call( dt.oInstance,
dt, iStart, iEnd, iMax, iTotal, sOut
);
}
var n = dt.aanFeatures.i;
if ( typeof n != 'undefined' )
{
for ( var i=0, iLen=n.length ; i<iLen ; i++ )
{
$(n[i]).html( sOut );
}
}
} | javascript | function ()
{
if ( !this.s.dt.oFeatures.bInfo )
{
return;
}
var
dt = this.s.dt,
language = dt.oLanguage,
iScrollTop = this.dom.scroller.scrollTop,
iStart = Math.floor( this.fnPixelsToRow(iScrollTop, false, this.s.ani)+1 ),
iMax = dt.fnRecordsTotal(),
iTotal = dt.fnRecordsDisplay(),
iPossibleEnd = Math.ceil( this.fnPixelsToRow(iScrollTop+this.s.heights.viewport, false, this.s.ani) ),
iEnd = iTotal < iPossibleEnd ? iTotal : iPossibleEnd,
sStart = dt.fnFormatNumber( iStart ),
sEnd = dt.fnFormatNumber( iEnd ),
sMax = dt.fnFormatNumber( iMax ),
sTotal = dt.fnFormatNumber( iTotal ),
sOut;
if ( dt.fnRecordsDisplay() === 0 &&
dt.fnRecordsDisplay() == dt.fnRecordsTotal() )
{
/* Empty record set */
sOut = language.sInfoEmpty+ language.sInfoPostFix;
}
else if ( dt.fnRecordsDisplay() === 0 )
{
/* Empty record set after filtering */
sOut = language.sInfoEmpty +' '+
language.sInfoFiltered.replace('_MAX_', sMax)+
language.sInfoPostFix;
}
else if ( dt.fnRecordsDisplay() == dt.fnRecordsTotal() )
{
/* Normal record set */
sOut = language.sInfo.
replace('_START_', sStart).
replace('_END_', sEnd).
replace('_MAX_', sMax).
replace('_TOTAL_', sTotal)+
language.sInfoPostFix;
}
else
{
/* Record set after filtering */
sOut = language.sInfo.
replace('_START_', sStart).
replace('_END_', sEnd).
replace('_MAX_', sMax).
replace('_TOTAL_', sTotal) +' '+
language.sInfoFiltered.replace(
'_MAX_',
dt.fnFormatNumber(dt.fnRecordsTotal())
)+
language.sInfoPostFix;
}
var callback = language.fnInfoCallback;
if ( callback ) {
sOut = callback.call( dt.oInstance,
dt, iStart, iEnd, iMax, iTotal, sOut
);
}
var n = dt.aanFeatures.i;
if ( typeof n != 'undefined' )
{
for ( var i=0, iLen=n.length ; i<iLen ; i++ )
{
$(n[i]).html( sOut );
}
}
} | [
"function",
"(",
")",
"{",
"if",
"(",
"!",
"this",
".",
"s",
".",
"dt",
".",
"oFeatures",
".",
"bInfo",
")",
"{",
"return",
";",
"}",
"var",
"dt",
"=",
"this",
".",
"s",
".",
"dt",
",",
"language",
"=",
"dt",
".",
"oLanguage",
",",
"iScrollTop",
"=",
"this",
".",
"dom",
".",
"scroller",
".",
"scrollTop",
",",
"iStart",
"=",
"Math",
".",
"floor",
"(",
"this",
".",
"fnPixelsToRow",
"(",
"iScrollTop",
",",
"false",
",",
"this",
".",
"s",
".",
"ani",
")",
"+",
"1",
")",
",",
"iMax",
"=",
"dt",
".",
"fnRecordsTotal",
"(",
")",
",",
"iTotal",
"=",
"dt",
".",
"fnRecordsDisplay",
"(",
")",
",",
"iPossibleEnd",
"=",
"Math",
".",
"ceil",
"(",
"this",
".",
"fnPixelsToRow",
"(",
"iScrollTop",
"+",
"this",
".",
"s",
".",
"heights",
".",
"viewport",
",",
"false",
",",
"this",
".",
"s",
".",
"ani",
")",
")",
",",
"iEnd",
"=",
"iTotal",
"<",
"iPossibleEnd",
"?",
"iTotal",
":",
"iPossibleEnd",
",",
"sStart",
"=",
"dt",
".",
"fnFormatNumber",
"(",
"iStart",
")",
",",
"sEnd",
"=",
"dt",
".",
"fnFormatNumber",
"(",
"iEnd",
")",
",",
"sMax",
"=",
"dt",
".",
"fnFormatNumber",
"(",
"iMax",
")",
",",
"sTotal",
"=",
"dt",
".",
"fnFormatNumber",
"(",
"iTotal",
")",
",",
"sOut",
";",
"if",
"(",
"dt",
".",
"fnRecordsDisplay",
"(",
")",
"===",
"0",
"&&",
"dt",
".",
"fnRecordsDisplay",
"(",
")",
"==",
"dt",
".",
"fnRecordsTotal",
"(",
")",
")",
"{",
"sOut",
"=",
"language",
".",
"sInfoEmpty",
"+",
"language",
".",
"sInfoPostFix",
";",
"}",
"else",
"if",
"(",
"dt",
".",
"fnRecordsDisplay",
"(",
")",
"===",
"0",
")",
"{",
"sOut",
"=",
"language",
".",
"sInfoEmpty",
"+",
"' '",
"+",
"language",
".",
"sInfoFiltered",
".",
"replace",
"(",
"'_MAX_'",
",",
"sMax",
")",
"+",
"language",
".",
"sInfoPostFix",
";",
"}",
"else",
"if",
"(",
"dt",
".",
"fnRecordsDisplay",
"(",
")",
"==",
"dt",
".",
"fnRecordsTotal",
"(",
")",
")",
"{",
"sOut",
"=",
"language",
".",
"sInfo",
".",
"replace",
"(",
"'_START_'",
",",
"sStart",
")",
".",
"replace",
"(",
"'_END_'",
",",
"sEnd",
")",
".",
"replace",
"(",
"'_MAX_'",
",",
"sMax",
")",
".",
"replace",
"(",
"'_TOTAL_'",
",",
"sTotal",
")",
"+",
"language",
".",
"sInfoPostFix",
";",
"}",
"else",
"{",
"sOut",
"=",
"language",
".",
"sInfo",
".",
"replace",
"(",
"'_START_'",
",",
"sStart",
")",
".",
"replace",
"(",
"'_END_'",
",",
"sEnd",
")",
".",
"replace",
"(",
"'_MAX_'",
",",
"sMax",
")",
".",
"replace",
"(",
"'_TOTAL_'",
",",
"sTotal",
")",
"+",
"' '",
"+",
"language",
".",
"sInfoFiltered",
".",
"replace",
"(",
"'_MAX_'",
",",
"dt",
".",
"fnFormatNumber",
"(",
"dt",
".",
"fnRecordsTotal",
"(",
")",
")",
")",
"+",
"language",
".",
"sInfoPostFix",
";",
"}",
"var",
"callback",
"=",
"language",
".",
"fnInfoCallback",
";",
"if",
"(",
"callback",
")",
"{",
"sOut",
"=",
"callback",
".",
"call",
"(",
"dt",
".",
"oInstance",
",",
"dt",
",",
"iStart",
",",
"iEnd",
",",
"iMax",
",",
"iTotal",
",",
"sOut",
")",
";",
"}",
"var",
"n",
"=",
"dt",
".",
"aanFeatures",
".",
"i",
";",
"if",
"(",
"typeof",
"n",
"!=",
"'undefined'",
")",
"{",
"for",
"(",
"var",
"i",
"=",
"0",
",",
"iLen",
"=",
"n",
".",
"length",
";",
"i",
"<",
"iLen",
";",
"i",
"++",
")",
"{",
"$",
"(",
"n",
"[",
"i",
"]",
")",
".",
"html",
"(",
"sOut",
")",
";",
"}",
"}",
"}"
]
| Update any information elements that are controlled by the DataTable based on the scrolling
viewport and what rows are visible in it. This function basically acts in the same way as
_fnUpdateInfo in DataTables, and effectively replaces that function.
@returns {void}
@private | [
"Update",
"any",
"information",
"elements",
"that",
"are",
"controlled",
"by",
"the",
"DataTable",
"based",
"on",
"the",
"scrolling",
"viewport",
"and",
"what",
"rows",
"are",
"visible",
"in",
"it",
".",
"This",
"function",
"basically",
"acts",
"in",
"the",
"same",
"way",
"as",
"_fnUpdateInfo",
"in",
"DataTables",
"and",
"effectively",
"replaces",
"that",
"function",
"."
]
| c283370ec0f99a25db5bb7029a98b4febf8c5251 | https://github.com/S3bb1/ah-dashboard-plugin/blob/c283370ec0f99a25db5bb7029a98b4febf8c5251/public/dashboard/bower_components/admin-lte/plugins/datatables/extensions/Scroller/js/dataTables.scroller.js#L929-L1004 | train |
|
mangojuicejs/mangojuice | packages/mangojuice-core/src/classes/Process.js | forEachChildren | function forEachChildren(proc, iterator) {
for (let id in proc.children) {
iterator(proc.children[id]);
}
} | javascript | function forEachChildren(proc, iterator) {
for (let id in proc.children) {
iterator(proc.children[id]);
}
} | [
"function",
"forEachChildren",
"(",
"proc",
",",
"iterator",
")",
"{",
"for",
"(",
"let",
"id",
"in",
"proc",
".",
"children",
")",
"{",
"iterator",
"(",
"proc",
".",
"children",
"[",
"id",
"]",
")",
";",
"}",
"}"
]
| Iterate through all active child processes and run
given iterator for every model.
@param {Process} proc | [
"Iterate",
"through",
"all",
"active",
"child",
"processes",
"and",
"run",
"given",
"iterator",
"for",
"every",
"model",
"."
]
| 15bda5648462c171cc8e2dd0f8f15696655ce11a | https://github.com/mangojuicejs/mangojuice/blob/15bda5648462c171cc8e2dd0f8f15696655ce11a/packages/mangojuice-core/src/classes/Process.js#L48-L52 | train |
mangojuicejs/mangojuice | packages/mangojuice-core/src/classes/Process.js | bindChild | function bindChild(proc, model, key, childCmd) {
const { logicClass, updateMsg, createArgs } = childCmd;
const originalModel = model[key];
let actualModel = originalModel || {};
let currProc = procOf(actualModel);
// Protect update of the model of the same type
if (updateMsg && (!currProc || !(currProc.logic instanceof logicClass))) {
proc.logger.onCatchError(new Error('Child model does not exists or have incorrect type'), proc);
return;
}
// Re-run prepare with new config args if proc already running
// with the same logic class, otherwise destroy the logic
if (currProc) {
if (!updateMsg) {
currProc.destroy();
currProc = null;
actualModel = {};
} else {
runLogicUpdate(currProc, updateMsg);
}
}
// Run new process for given child definition if no proc was
// binded to the model or if it was destroyed
if (!currProc) {
const shouldRehydrate = actualModel && actualModel === originalModel;
currProc = new proc.constructor({
createArgs,
logicClass,
parent: proc,
logger: proc.logger,
contexts: proc.contexts,
internalContext: proc.internalContext
});
model[key] = actualModel;
currProc.bind(actualModel);
currProc.run(shouldRehydrate);
proc.children[currProc.id] = currProc;
}
return currProc;
} | javascript | function bindChild(proc, model, key, childCmd) {
const { logicClass, updateMsg, createArgs } = childCmd;
const originalModel = model[key];
let actualModel = originalModel || {};
let currProc = procOf(actualModel);
// Protect update of the model of the same type
if (updateMsg && (!currProc || !(currProc.logic instanceof logicClass))) {
proc.logger.onCatchError(new Error('Child model does not exists or have incorrect type'), proc);
return;
}
// Re-run prepare with new config args if proc already running
// with the same logic class, otherwise destroy the logic
if (currProc) {
if (!updateMsg) {
currProc.destroy();
currProc = null;
actualModel = {};
} else {
runLogicUpdate(currProc, updateMsg);
}
}
// Run new process for given child definition if no proc was
// binded to the model or if it was destroyed
if (!currProc) {
const shouldRehydrate = actualModel && actualModel === originalModel;
currProc = new proc.constructor({
createArgs,
logicClass,
parent: proc,
logger: proc.logger,
contexts: proc.contexts,
internalContext: proc.internalContext
});
model[key] = actualModel;
currProc.bind(actualModel);
currProc.run(shouldRehydrate);
proc.children[currProc.id] = currProc;
}
return currProc;
} | [
"function",
"bindChild",
"(",
"proc",
",",
"model",
",",
"key",
",",
"childCmd",
")",
"{",
"const",
"{",
"logicClass",
",",
"updateMsg",
",",
"createArgs",
"}",
"=",
"childCmd",
";",
"const",
"originalModel",
"=",
"model",
"[",
"key",
"]",
";",
"let",
"actualModel",
"=",
"originalModel",
"||",
"{",
"}",
";",
"let",
"currProc",
"=",
"procOf",
"(",
"actualModel",
")",
";",
"if",
"(",
"updateMsg",
"&&",
"(",
"!",
"currProc",
"||",
"!",
"(",
"currProc",
".",
"logic",
"instanceof",
"logicClass",
")",
")",
")",
"{",
"proc",
".",
"logger",
".",
"onCatchError",
"(",
"new",
"Error",
"(",
"'Child model does not exists or have incorrect type'",
")",
",",
"proc",
")",
";",
"return",
";",
"}",
"if",
"(",
"currProc",
")",
"{",
"if",
"(",
"!",
"updateMsg",
")",
"{",
"currProc",
".",
"destroy",
"(",
")",
";",
"currProc",
"=",
"null",
";",
"actualModel",
"=",
"{",
"}",
";",
"}",
"else",
"{",
"runLogicUpdate",
"(",
"currProc",
",",
"updateMsg",
")",
";",
"}",
"}",
"if",
"(",
"!",
"currProc",
")",
"{",
"const",
"shouldRehydrate",
"=",
"actualModel",
"&&",
"actualModel",
"===",
"originalModel",
";",
"currProc",
"=",
"new",
"proc",
".",
"constructor",
"(",
"{",
"createArgs",
",",
"logicClass",
",",
"parent",
":",
"proc",
",",
"logger",
":",
"proc",
".",
"logger",
",",
"contexts",
":",
"proc",
".",
"contexts",
",",
"internalContext",
":",
"proc",
".",
"internalContext",
"}",
")",
";",
"model",
"[",
"key",
"]",
"=",
"actualModel",
";",
"currProc",
".",
"bind",
"(",
"actualModel",
")",
";",
"currProc",
".",
"run",
"(",
"shouldRehydrate",
")",
";",
"proc",
".",
"children",
"[",
"currProc",
".",
"id",
"]",
"=",
"currProc",
";",
"}",
"return",
"currProc",
";",
"}"
]
| Create process and bind the process to child model
with given name. If model field is empty then do nothing.
If model already binded to some model do nothing.
Return true if model sucessfully binded to the process.
Othersise returns false
@private
@param {Object} childModel
@param {String} fieldName
@return {Boolean} | [
"Create",
"process",
"and",
"bind",
"the",
"process",
"to",
"child",
"model",
"with",
"given",
"name",
".",
"If",
"model",
"field",
"is",
"empty",
"then",
"do",
"nothing",
".",
"If",
"model",
"already",
"binded",
"to",
"some",
"model",
"do",
"nothing",
".",
"Return",
"true",
"if",
"model",
"sucessfully",
"binded",
"to",
"the",
"process",
".",
"Othersise",
"returns",
"false"
]
| 15bda5648462c171cc8e2dd0f8f15696655ce11a | https://github.com/mangojuicejs/mangojuice/blob/15bda5648462c171cc8e2dd0f8f15696655ce11a/packages/mangojuice-core/src/classes/Process.js#L66-L109 | train |
mangojuicejs/mangojuice | packages/mangojuice-core/src/classes/Process.js | bindComputedFieldCmd | function bindComputedFieldCmd(proc, model, key, computeVal) {
const { logger } = proc;
// Create getter function
const isMemoized = computeVal instanceof MemoizedFieldCmd;
const computeFn = isMemoized ? computeVal.computeFn : computeVal;
const safeComputeValue = () => safeExecFunction(logger, computeFn)
const getter = isMemoized ? memoize(safeComputeValue) : safeComputeValue;
// Register memoized field in the process to be able to reset
// when the model changed
if (isMemoized) {
proc.computedFields[key] = getter;
}
// Set the getter in the model
Object.defineProperty(model, key, {
enumerable: true,
configurable: true,
set: noop,
get: getter
});
} | javascript | function bindComputedFieldCmd(proc, model, key, computeVal) {
const { logger } = proc;
// Create getter function
const isMemoized = computeVal instanceof MemoizedFieldCmd;
const computeFn = isMemoized ? computeVal.computeFn : computeVal;
const safeComputeValue = () => safeExecFunction(logger, computeFn)
const getter = isMemoized ? memoize(safeComputeValue) : safeComputeValue;
// Register memoized field in the process to be able to reset
// when the model changed
if (isMemoized) {
proc.computedFields[key] = getter;
}
// Set the getter in the model
Object.defineProperty(model, key, {
enumerable: true,
configurable: true,
set: noop,
get: getter
});
} | [
"function",
"bindComputedFieldCmd",
"(",
"proc",
",",
"model",
",",
"key",
",",
"computeVal",
")",
"{",
"const",
"{",
"logger",
"}",
"=",
"proc",
";",
"const",
"isMemoized",
"=",
"computeVal",
"instanceof",
"MemoizedFieldCmd",
";",
"const",
"computeFn",
"=",
"isMemoized",
"?",
"computeVal",
".",
"computeFn",
":",
"computeVal",
";",
"const",
"safeComputeValue",
"=",
"(",
")",
"=>",
"safeExecFunction",
"(",
"logger",
",",
"computeFn",
")",
"const",
"getter",
"=",
"isMemoized",
"?",
"memoize",
"(",
"safeComputeValue",
")",
":",
"safeComputeValue",
";",
"if",
"(",
"isMemoized",
")",
"{",
"proc",
".",
"computedFields",
"[",
"key",
"]",
"=",
"getter",
";",
"}",
"Object",
".",
"defineProperty",
"(",
"model",
",",
"key",
",",
"{",
"enumerable",
":",
"true",
",",
"configurable",
":",
"true",
",",
"set",
":",
"noop",
",",
"get",
":",
"getter",
"}",
")",
";",
"}"
]
| Bind field in the model with given computed function or dependency
object.
@private
@param {Process} proc
@param {string} fieldName
@param {function} computeVal | [
"Bind",
"field",
"in",
"the",
"model",
"with",
"given",
"computed",
"function",
"or",
"dependency",
"object",
"."
]
| 15bda5648462c171cc8e2dd0f8f15696655ce11a | https://github.com/mangojuicejs/mangojuice/blob/15bda5648462c171cc8e2dd0f8f15696655ce11a/packages/mangojuice-core/src/classes/Process.js#L120-L142 | train |
mangojuicejs/mangojuice | packages/mangojuice-core/src/classes/Process.js | runLogicCreate | function runLogicCreate(proc, rehydrate) {
const { exec, logic, createArgs, model } = proc;
if (logic.create) {
const commandFactory = () => {
logic.model = !rehydrate ? undefined : model;
const res = logic.create.apply(logic, createArgs);
logic.model = model;
return res;
};
exec(commandFactory);
}
} | javascript | function runLogicCreate(proc, rehydrate) {
const { exec, logic, createArgs, model } = proc;
if (logic.create) {
const commandFactory = () => {
logic.model = !rehydrate ? undefined : model;
const res = logic.create.apply(logic, createArgs);
logic.model = model;
return res;
};
exec(commandFactory);
}
} | [
"function",
"runLogicCreate",
"(",
"proc",
",",
"rehydrate",
")",
"{",
"const",
"{",
"exec",
",",
"logic",
",",
"createArgs",
",",
"model",
"}",
"=",
"proc",
";",
"if",
"(",
"logic",
".",
"create",
")",
"{",
"const",
"commandFactory",
"=",
"(",
")",
"=>",
"{",
"logic",
".",
"model",
"=",
"!",
"rehydrate",
"?",
"undefined",
":",
"model",
";",
"const",
"res",
"=",
"logic",
".",
"create",
".",
"apply",
"(",
"logic",
",",
"createArgs",
")",
";",
"logic",
".",
"model",
"=",
"model",
";",
"return",
"res",
";",
"}",
";",
"exec",
"(",
"commandFactory",
")",
";",
"}",
"}"
]
| Run init command depending on from what state the logic
is runinng. Run `logic.rehydrate` if some model was provided
and `prepare` if model was not provided and we need to create
it from scratch.
@param {Process} proc | [
"Run",
"init",
"command",
"depending",
"on",
"from",
"what",
"state",
"the",
"logic",
"is",
"runinng",
".",
"Run",
"logic",
".",
"rehydrate",
"if",
"some",
"model",
"was",
"provided",
"and",
"prepare",
"if",
"model",
"was",
"not",
"provided",
"and",
"we",
"need",
"to",
"create",
"it",
"from",
"scratch",
"."
]
| 15bda5648462c171cc8e2dd0f8f15696655ce11a | https://github.com/mangojuicejs/mangojuice/blob/15bda5648462c171cc8e2dd0f8f15696655ce11a/packages/mangojuice-core/src/classes/Process.js#L186-L197 | train |
mangojuicejs/mangojuice | packages/mangojuice-core/src/classes/Process.js | runModelObservers | function runModelObservers(proc) {
const observersIterator = (obs) => obs();
maybeForEach(proc.observers, observersIterator);
if (proc.parent) {
maybeForEach(proc.childrenObservers, observersIterator);
}
} | javascript | function runModelObservers(proc) {
const observersIterator = (obs) => obs();
maybeForEach(proc.observers, observersIterator);
if (proc.parent) {
maybeForEach(proc.childrenObservers, observersIterator);
}
} | [
"function",
"runModelObservers",
"(",
"proc",
")",
"{",
"const",
"observersIterator",
"=",
"(",
"obs",
")",
"=>",
"obs",
"(",
")",
";",
"maybeForEach",
"(",
"proc",
".",
"observers",
",",
"observersIterator",
")",
";",
"if",
"(",
"proc",
".",
"parent",
")",
"{",
"maybeForEach",
"(",
"proc",
".",
"childrenObservers",
",",
"observersIterator",
")",
";",
"}",
"}"
]
| Ren all model observers and returns a Promise which will
be resolved when all handlers executed and returned promises
is also resolved
@private
@param {Process} proc
@return {Promise} | [
"Ren",
"all",
"model",
"observers",
"and",
"returns",
"a",
"Promise",
"which",
"will",
"be",
"resolved",
"when",
"all",
"handlers",
"executed",
"and",
"returned",
"promises",
"is",
"also",
"resolved"
]
| 15bda5648462c171cc8e2dd0f8f15696655ce11a | https://github.com/mangojuicejs/mangojuice/blob/15bda5648462c171cc8e2dd0f8f15696655ce11a/packages/mangojuice-core/src/classes/Process.js#L216-L222 | train |
mangojuicejs/mangojuice | packages/mangojuice-core/src/classes/Process.js | execTask | function execTask(proc, taskObj) {
const { tasks, logger, model, sharedModel, config, logic } = proc;
const { task, executor, notifyCmd, successCmd, failCmd,
customArgs, execEvery, customExecId, id: taskId } = taskObj;
// If not in multi-thread mode or just need to cancel a tak –
// cancel all running task with same identifier (command id)
if (taskObj.cancelTask || !execEvery) {
cancelTask(proc, taskId);
if (taskObj.cancelTask) return;
}
// Define next execution id
const execId = customExecId || nextId();
const executions = tasks[taskId] = tasks[taskId] || {};
const cleanup = () => delete executions[execId];
// Do not create any new task if the task with given exec id
// already exists. Usefull for throttle/debounce tasks
if (executions[execId]) {
executions[execId].exec(taskObj);
} else {
const taskCall = executor(proc, taskObj);
executions[execId] = taskCall;
taskCall.exec(taskObj).then(cleanup, cleanup);
}
} | javascript | function execTask(proc, taskObj) {
const { tasks, logger, model, sharedModel, config, logic } = proc;
const { task, executor, notifyCmd, successCmd, failCmd,
customArgs, execEvery, customExecId, id: taskId } = taskObj;
// If not in multi-thread mode or just need to cancel a tak –
// cancel all running task with same identifier (command id)
if (taskObj.cancelTask || !execEvery) {
cancelTask(proc, taskId);
if (taskObj.cancelTask) return;
}
// Define next execution id
const execId = customExecId || nextId();
const executions = tasks[taskId] = tasks[taskId] || {};
const cleanup = () => delete executions[execId];
// Do not create any new task if the task with given exec id
// already exists. Usefull for throttle/debounce tasks
if (executions[execId]) {
executions[execId].exec(taskObj);
} else {
const taskCall = executor(proc, taskObj);
executions[execId] = taskCall;
taskCall.exec(taskObj).then(cleanup, cleanup);
}
} | [
"function",
"execTask",
"(",
"proc",
",",
"taskObj",
")",
"{",
"const",
"{",
"tasks",
",",
"logger",
",",
"model",
",",
"sharedModel",
",",
"config",
",",
"logic",
"}",
"=",
"proc",
";",
"const",
"{",
"task",
",",
"executor",
",",
"notifyCmd",
",",
"successCmd",
",",
"failCmd",
",",
"customArgs",
",",
"execEvery",
",",
"customExecId",
",",
"id",
":",
"taskId",
"}",
"=",
"taskObj",
";",
"if",
"(",
"taskObj",
".",
"cancelTask",
"||",
"!",
"execEvery",
")",
"{",
"cancelTask",
"(",
"proc",
",",
"taskId",
")",
";",
"if",
"(",
"taskObj",
".",
"cancelTask",
")",
"return",
";",
"}",
"const",
"execId",
"=",
"customExecId",
"||",
"nextId",
"(",
")",
";",
"const",
"executions",
"=",
"tasks",
"[",
"taskId",
"]",
"=",
"tasks",
"[",
"taskId",
"]",
"||",
"{",
"}",
";",
"const",
"cleanup",
"=",
"(",
")",
"=>",
"delete",
"executions",
"[",
"execId",
"]",
";",
"if",
"(",
"executions",
"[",
"execId",
"]",
")",
"{",
"executions",
"[",
"execId",
"]",
".",
"exec",
"(",
"taskObj",
")",
";",
"}",
"else",
"{",
"const",
"taskCall",
"=",
"executor",
"(",
"proc",
",",
"taskObj",
")",
";",
"executions",
"[",
"execId",
"]",
"=",
"taskCall",
";",
"taskCall",
".",
"exec",
"(",
"taskObj",
")",
".",
"then",
"(",
"cleanup",
",",
"cleanup",
")",
";",
"}",
"}"
]
| Execute given task object in scope of given Process.
Returns a Promise which will be resolved when task will
be resolved or reject with with a command, which should
be executed next.
@private
@param {Process} proc
@param {Task} taskObj
@return {Promise} | [
"Execute",
"given",
"task",
"object",
"in",
"scope",
"of",
"given",
"Process",
".",
"Returns",
"a",
"Promise",
"which",
"will",
"be",
"resolved",
"when",
"task",
"will",
"be",
"resolved",
"or",
"reject",
"with",
"with",
"a",
"command",
"which",
"should",
"be",
"executed",
"next",
"."
]
| 15bda5648462c171cc8e2dd0f8f15696655ce11a | https://github.com/mangojuicejs/mangojuice/blob/15bda5648462c171cc8e2dd0f8f15696655ce11a/packages/mangojuice-core/src/classes/Process.js#L328-L354 | train |
ply-ct/ply | lib/subst.js | function(template, map, fallback) {
if (!map)
return template;
return template.replace(/\$\{.+?}/g, (match) => {
const path = match.substr(2, match.length - 3).trim();
return get(path, map, fallback);
});
} | javascript | function(template, map, fallback) {
if (!map)
return template;
return template.replace(/\$\{.+?}/g, (match) => {
const path = match.substr(2, match.length - 3).trim();
return get(path, map, fallback);
});
} | [
"function",
"(",
"template",
",",
"map",
",",
"fallback",
")",
"{",
"if",
"(",
"!",
"map",
")",
"return",
"template",
";",
"return",
"template",
".",
"replace",
"(",
"/",
"\\$\\{.+?}",
"/",
"g",
",",
"(",
"match",
")",
"=>",
"{",
"const",
"path",
"=",
"match",
".",
"substr",
"(",
"2",
",",
"match",
".",
"length",
"-",
"3",
")",
".",
"trim",
"(",
")",
";",
"return",
"get",
"(",
"path",
",",
"map",
",",
"fallback",
")",
";",
"}",
")",
";",
"}"
]
| Replaces template expressions with values. | [
"Replaces",
"template",
"expressions",
"with",
"values",
"."
]
| 1d4146829845fedd917f5f0626cd74cc3845d0c8 | https://github.com/ply-ct/ply/blob/1d4146829845fedd917f5f0626cd74cc3845d0c8/lib/subst.js#L11-L18 | train |
|
chrisJohn404/ljswitchboard-ljm_device_curator | lib/t7_flash_operations.js | function(address, innerSize, writeValues)
{
return function (lastResults) {
var innerDeferred = q.defer();
var addresses = [];
var values = [];
var directions = [];
var numFrames;
var numValues;
// Flash memory pointer
directions.push(driver_const.LJM_WRITE);
// Key
if (key === undefined) {
numFrames = 2;
numValues = [1];
} else {
// Write for key
directions.push(driver_const.LJM_WRITE);
addresses.push(driver_const.T7_MA_EXF_KEY);
values.push(key);
numFrames = 3;
numValues = [1, 1];
}
if (isReadOp)
directions.push(driver_const.LJM_READ);
else
directions.push(driver_const.LJM_WRITE);
addresses.push(ptrAddress);
values.push(address);
addresses.push(flashAddress);
if (isReadOp) {
for (var i=0; i<innerSize; i++) {
values.push(null);
}
} else {
values.push.apply(values, writeValues);
}
numValues.push(innerSize);
device.rwMany(
addresses,
directions,
numValues,
values,
// createSafeReject(innerDeferred),
function(err) {
// console.log('tseries_upgrade: calling rwMany', isReadOp, addresses, directions, numValues, values);
// console.log('tseries_upgrade: rwMany Error', err);
// console.log('Throwing Upgrade Error', err);
if(!isReadOp) {
// console.log('Failed to write flash data', addresses, numValues, values, err);
}
var callFunc = createSafeReject(innerDeferred);
callFunc(err);
},
function (newResults) {
if(!isReadOp) {
// console.log('Successfully wrote flash data', addresses, numValues, values);
}
lastResults.push.apply(lastResults, newResults);
innerDeferred.resolve(lastResults);
}
);
return innerDeferred.promise;
};
} | javascript | function(address, innerSize, writeValues)
{
return function (lastResults) {
var innerDeferred = q.defer();
var addresses = [];
var values = [];
var directions = [];
var numFrames;
var numValues;
// Flash memory pointer
directions.push(driver_const.LJM_WRITE);
// Key
if (key === undefined) {
numFrames = 2;
numValues = [1];
} else {
// Write for key
directions.push(driver_const.LJM_WRITE);
addresses.push(driver_const.T7_MA_EXF_KEY);
values.push(key);
numFrames = 3;
numValues = [1, 1];
}
if (isReadOp)
directions.push(driver_const.LJM_READ);
else
directions.push(driver_const.LJM_WRITE);
addresses.push(ptrAddress);
values.push(address);
addresses.push(flashAddress);
if (isReadOp) {
for (var i=0; i<innerSize; i++) {
values.push(null);
}
} else {
values.push.apply(values, writeValues);
}
numValues.push(innerSize);
device.rwMany(
addresses,
directions,
numValues,
values,
// createSafeReject(innerDeferred),
function(err) {
// console.log('tseries_upgrade: calling rwMany', isReadOp, addresses, directions, numValues, values);
// console.log('tseries_upgrade: rwMany Error', err);
// console.log('Throwing Upgrade Error', err);
if(!isReadOp) {
// console.log('Failed to write flash data', addresses, numValues, values, err);
}
var callFunc = createSafeReject(innerDeferred);
callFunc(err);
},
function (newResults) {
if(!isReadOp) {
// console.log('Successfully wrote flash data', addresses, numValues, values);
}
lastResults.push.apply(lastResults, newResults);
innerDeferred.resolve(lastResults);
}
);
return innerDeferred.promise;
};
} | [
"function",
"(",
"address",
",",
"innerSize",
",",
"writeValues",
")",
"{",
"return",
"function",
"(",
"lastResults",
")",
"{",
"var",
"innerDeferred",
"=",
"q",
".",
"defer",
"(",
")",
";",
"var",
"addresses",
"=",
"[",
"]",
";",
"var",
"values",
"=",
"[",
"]",
";",
"var",
"directions",
"=",
"[",
"]",
";",
"var",
"numFrames",
";",
"var",
"numValues",
";",
"directions",
".",
"push",
"(",
"driver_const",
".",
"LJM_WRITE",
")",
";",
"if",
"(",
"key",
"===",
"undefined",
")",
"{",
"numFrames",
"=",
"2",
";",
"numValues",
"=",
"[",
"1",
"]",
";",
"}",
"else",
"{",
"directions",
".",
"push",
"(",
"driver_const",
".",
"LJM_WRITE",
")",
";",
"addresses",
".",
"push",
"(",
"driver_const",
".",
"T7_MA_EXF_KEY",
")",
";",
"values",
".",
"push",
"(",
"key",
")",
";",
"numFrames",
"=",
"3",
";",
"numValues",
"=",
"[",
"1",
",",
"1",
"]",
";",
"}",
"if",
"(",
"isReadOp",
")",
"directions",
".",
"push",
"(",
"driver_const",
".",
"LJM_READ",
")",
";",
"else",
"directions",
".",
"push",
"(",
"driver_const",
".",
"LJM_WRITE",
")",
";",
"addresses",
".",
"push",
"(",
"ptrAddress",
")",
";",
"values",
".",
"push",
"(",
"address",
")",
";",
"addresses",
".",
"push",
"(",
"flashAddress",
")",
";",
"if",
"(",
"isReadOp",
")",
"{",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"innerSize",
";",
"i",
"++",
")",
"{",
"values",
".",
"push",
"(",
"null",
")",
";",
"}",
"}",
"else",
"{",
"values",
".",
"push",
".",
"apply",
"(",
"values",
",",
"writeValues",
")",
";",
"}",
"numValues",
".",
"push",
"(",
"innerSize",
")",
";",
"device",
".",
"rwMany",
"(",
"addresses",
",",
"directions",
",",
"numValues",
",",
"values",
",",
"function",
"(",
"err",
")",
"{",
"if",
"(",
"!",
"isReadOp",
")",
"{",
"}",
"var",
"callFunc",
"=",
"createSafeReject",
"(",
"innerDeferred",
")",
";",
"callFunc",
"(",
"err",
")",
";",
"}",
",",
"function",
"(",
"newResults",
")",
"{",
"if",
"(",
"!",
"isReadOp",
")",
"{",
"}",
"lastResults",
".",
"push",
".",
"apply",
"(",
"lastResults",
",",
"newResults",
")",
";",
"innerDeferred",
".",
"resolve",
"(",
"lastResults",
")",
";",
"}",
")",
";",
"return",
"innerDeferred",
".",
"promise",
";",
"}",
";",
"}"
]
| Creates a closure over a rw excutiong with an address and size | [
"Creates",
"a",
"closure",
"over",
"a",
"rw",
"excutiong",
"with",
"an",
"address",
"and",
"size"
]
| 36cb25645dfa0a68e906d5ec43e5514391947257 | https://github.com/chrisJohn404/ljswitchboard-ljm_device_curator/blob/36cb25645dfa0a68e906d5ec43e5514391947257/lib/t7_flash_operations.js#L104-L176 | train |
|
zettaforge/unity-module-scripts | lib/index.js | function (name, pkgDir) {
if (!isString(name) || !isString(pkgDir) ||
S(name).isEmpty() || S(pkgDir).isEmpty() || !isDirectory.sync(pkgDir)) {
return 1
}
var scope = utils(name, pkgDir)
try {
scope.validateIsUnityRoot()
scope.createModulesDirectoryInAssets()
scope.createModuleDirectory()
scope.copyModuleResources()
} catch (err) {
scope.cleanupOnPostInstallError()
scope.printError(err)
return 1
}
return 0
} | javascript | function (name, pkgDir) {
if (!isString(name) || !isString(pkgDir) ||
S(name).isEmpty() || S(pkgDir).isEmpty() || !isDirectory.sync(pkgDir)) {
return 1
}
var scope = utils(name, pkgDir)
try {
scope.validateIsUnityRoot()
scope.createModulesDirectoryInAssets()
scope.createModuleDirectory()
scope.copyModuleResources()
} catch (err) {
scope.cleanupOnPostInstallError()
scope.printError(err)
return 1
}
return 0
} | [
"function",
"(",
"name",
",",
"pkgDir",
")",
"{",
"if",
"(",
"!",
"isString",
"(",
"name",
")",
"||",
"!",
"isString",
"(",
"pkgDir",
")",
"||",
"S",
"(",
"name",
")",
".",
"isEmpty",
"(",
")",
"||",
"S",
"(",
"pkgDir",
")",
".",
"isEmpty",
"(",
")",
"||",
"!",
"isDirectory",
".",
"sync",
"(",
"pkgDir",
")",
")",
"{",
"return",
"1",
"}",
"var",
"scope",
"=",
"utils",
"(",
"name",
",",
"pkgDir",
")",
"try",
"{",
"scope",
".",
"validateIsUnityRoot",
"(",
")",
"scope",
".",
"createModulesDirectoryInAssets",
"(",
")",
"scope",
".",
"createModuleDirectory",
"(",
")",
"scope",
".",
"copyModuleResources",
"(",
")",
"}",
"catch",
"(",
"err",
")",
"{",
"scope",
".",
"cleanupOnPostInstallError",
"(",
")",
"scope",
".",
"printError",
"(",
"err",
")",
"return",
"1",
"}",
"return",
"0",
"}"
]
| A simple implementation of postinstall that would be suitable for most packages that only contain git-hosted assets. Returns a falsy value if the routine succeeded. | [
"A",
"simple",
"implementation",
"of",
"postinstall",
"that",
"would",
"be",
"suitable",
"for",
"most",
"packages",
"that",
"only",
"contain",
"git",
"-",
"hosted",
"assets",
".",
"Returns",
"a",
"falsy",
"value",
"if",
"the",
"routine",
"succeeded",
"."
]
| e058e258939fc2e8ea0514eb406d49bb3f6140de | https://github.com/zettaforge/unity-module-scripts/blob/e058e258939fc2e8ea0514eb406d49bb3f6140de/lib/index.js#L72-L89 | train |
|
zettaforge/unity-module-scripts | lib/index.js | function (name, pkgDir) {
if (!isString(name) || !isString(pkgDir) ||
S(name).isEmpty() || S(pkgDir).isEmpty() || !isDirectory.sync(pkgDir)) {
return 1
}
var scope = utils(name, pkgDir)
try {
scope.removeModuleDirectory()
} catch (err) {
scope.printError(err)
return 1
}
return 0
} | javascript | function (name, pkgDir) {
if (!isString(name) || !isString(pkgDir) ||
S(name).isEmpty() || S(pkgDir).isEmpty() || !isDirectory.sync(pkgDir)) {
return 1
}
var scope = utils(name, pkgDir)
try {
scope.removeModuleDirectory()
} catch (err) {
scope.printError(err)
return 1
}
return 0
} | [
"function",
"(",
"name",
",",
"pkgDir",
")",
"{",
"if",
"(",
"!",
"isString",
"(",
"name",
")",
"||",
"!",
"isString",
"(",
"pkgDir",
")",
"||",
"S",
"(",
"name",
")",
".",
"isEmpty",
"(",
")",
"||",
"S",
"(",
"pkgDir",
")",
".",
"isEmpty",
"(",
")",
"||",
"!",
"isDirectory",
".",
"sync",
"(",
"pkgDir",
")",
")",
"{",
"return",
"1",
"}",
"var",
"scope",
"=",
"utils",
"(",
"name",
",",
"pkgDir",
")",
"try",
"{",
"scope",
".",
"removeModuleDirectory",
"(",
")",
"}",
"catch",
"(",
"err",
")",
"{",
"scope",
".",
"printError",
"(",
"err",
")",
"return",
"1",
"}",
"return",
"0",
"}"
]
| A simple implementation of postuninstall that would be suitable for most packages that only contain git-hosted assets. Returns a falsy value if the routine succeeded. | [
"A",
"simple",
"implementation",
"of",
"postuninstall",
"that",
"would",
"be",
"suitable",
"for",
"most",
"packages",
"that",
"only",
"contain",
"git",
"-",
"hosted",
"assets",
".",
"Returns",
"a",
"falsy",
"value",
"if",
"the",
"routine",
"succeeded",
"."
]
| e058e258939fc2e8ea0514eb406d49bb3f6140de | https://github.com/zettaforge/unity-module-scripts/blob/e058e258939fc2e8ea0514eb406d49bb3f6140de/lib/index.js#L94-L107 | train |
|
burnnat/grunt-debug | tasks/lib/hooks.js | function(grunt) {
var me = this;
this.hookChild(
grunt.util,
'spawn',
function(original, spawnArgs) {
var options = spawnArgs[0];
var callback = spawnArgs[1];
if (options.cmd === process.argv[0]) {
var module;
for (var i = 0; i < options.args.length; i++) {
if (options.args[i].lastIndexOf('--') != 0) {
module = options.args[i];
break;
}
}
me.addDebugArg(options.args, module);
}
return original.call(this, options, callback);
}
);
} | javascript | function(grunt) {
var me = this;
this.hookChild(
grunt.util,
'spawn',
function(original, spawnArgs) {
var options = spawnArgs[0];
var callback = spawnArgs[1];
if (options.cmd === process.argv[0]) {
var module;
for (var i = 0; i < options.args.length; i++) {
if (options.args[i].lastIndexOf('--') != 0) {
module = options.args[i];
break;
}
}
me.addDebugArg(options.args, module);
}
return original.call(this, options, callback);
}
);
} | [
"function",
"(",
"grunt",
")",
"{",
"var",
"me",
"=",
"this",
";",
"this",
".",
"hookChild",
"(",
"grunt",
".",
"util",
",",
"'spawn'",
",",
"function",
"(",
"original",
",",
"spawnArgs",
")",
"{",
"var",
"options",
"=",
"spawnArgs",
"[",
"0",
"]",
";",
"var",
"callback",
"=",
"spawnArgs",
"[",
"1",
"]",
";",
"if",
"(",
"options",
".",
"cmd",
"===",
"process",
".",
"argv",
"[",
"0",
"]",
")",
"{",
"var",
"module",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"options",
".",
"args",
".",
"length",
";",
"i",
"++",
")",
"{",
"if",
"(",
"options",
".",
"args",
"[",
"i",
"]",
".",
"lastIndexOf",
"(",
"'--'",
")",
"!=",
"0",
")",
"{",
"module",
"=",
"options",
".",
"args",
"[",
"i",
"]",
";",
"break",
";",
"}",
"}",
"me",
".",
"addDebugArg",
"(",
"options",
".",
"args",
",",
"module",
")",
";",
"}",
"return",
"original",
".",
"call",
"(",
"this",
",",
"options",
",",
"callback",
")",
";",
"}",
")",
";",
"}"
]
| Monkey-patch grunt `spawn` function to enable debugging on child processes. | [
"Monkey",
"-",
"patch",
"grunt",
"spawn",
"function",
"to",
"enable",
"debugging",
"on",
"child",
"processes",
"."
]
| 968fefb5c99621752bc8b81d0fe865c1f90b8eb0 | https://github.com/burnnat/grunt-debug/blob/968fefb5c99621752bc8b81d0fe865c1f90b8eb0/tasks/lib/hooks.js#L59-L85 | train |
|
alexcjohnson/world-calendars | dist/calendars/chinese.js | function(year, monthIndex) {
if (year.year) {
year = year.year();
monthIndex = year.month();
}
var intercalaryMonth = this.intercalaryMonth(year);
return !!intercalaryMonth && intercalaryMonth === monthIndex;
} | javascript | function(year, monthIndex) {
if (year.year) {
year = year.year();
monthIndex = year.month();
}
var intercalaryMonth = this.intercalaryMonth(year);
return !!intercalaryMonth && intercalaryMonth === monthIndex;
} | [
"function",
"(",
"year",
",",
"monthIndex",
")",
"{",
"if",
"(",
"year",
".",
"year",
")",
"{",
"year",
"=",
"year",
".",
"year",
"(",
")",
";",
"monthIndex",
"=",
"year",
".",
"month",
"(",
")",
";",
"}",
"var",
"intercalaryMonth",
"=",
"this",
".",
"intercalaryMonth",
"(",
"year",
")",
";",
"return",
"!",
"!",
"intercalaryMonth",
"&&",
"intercalaryMonth",
"===",
"monthIndex",
";",
"}"
]
| Determine whether this date is an intercalary month.
@memberof ChineseCalendar
@param year {CDate|number} The date to examine or the year to examine.
@param [monthIndex] {number} The month index to examine.
@return {boolean} <code>true</code> if this is an intercalary month, <code>false</code> if not.
@throws Error if an invalid year or a different calendar used. | [
"Determine",
"whether",
"this",
"date",
"is",
"an",
"intercalary",
"month",
"."
]
| 810693882512dec1b804456f8d435b962bd6cf31 | https://github.com/alexcjohnson/world-calendars/blob/810693882512dec1b804456f8d435b962bd6cf31/dist/calendars/chinese.js#L278-L287 | train |
|
alexcjohnson/world-calendars | dist/calendars/chinese.js | function(dateString) {
var match = dateString.match(DATE_REGEXP);
var year = this._validateYear(+match[1]);
var month = +match[2];
var isIntercalary = !!match[3];
var monthIndex = this.toMonthIndex(year, month, isIntercalary);
var day = +match[4];
return this.newDate(year, monthIndex, day);
} | javascript | function(dateString) {
var match = dateString.match(DATE_REGEXP);
var year = this._validateYear(+match[1]);
var month = +match[2];
var isIntercalary = !!match[3];
var monthIndex = this.toMonthIndex(year, month, isIntercalary);
var day = +match[4];
return this.newDate(year, monthIndex, day);
} | [
"function",
"(",
"dateString",
")",
"{",
"var",
"match",
"=",
"dateString",
".",
"match",
"(",
"DATE_REGEXP",
")",
";",
"var",
"year",
"=",
"this",
".",
"_validateYear",
"(",
"+",
"match",
"[",
"1",
"]",
")",
";",
"var",
"month",
"=",
"+",
"match",
"[",
"2",
"]",
";",
"var",
"isIntercalary",
"=",
"!",
"!",
"match",
"[",
"3",
"]",
";",
"var",
"monthIndex",
"=",
"this",
".",
"toMonthIndex",
"(",
"year",
",",
"month",
",",
"isIntercalary",
")",
";",
"var",
"day",
"=",
"+",
"match",
"[",
"4",
"]",
";",
"return",
"this",
".",
"newDate",
"(",
"year",
",",
"monthIndex",
",",
"day",
")",
";",
"}"
]
| Create a new date from a string.
@memberof ChineseCalendar
@param dateString {string} String representing a Chinese date
@return {CDate} The new date.
@throws Error if an invalid date. | [
"Create",
"a",
"new",
"date",
"from",
"a",
"string",
"."
]
| 810693882512dec1b804456f8d435b962bd6cf31 | https://github.com/alexcjohnson/world-calendars/blob/810693882512dec1b804456f8d435b962bd6cf31/dist/calendars/chinese.js#L415-L427 | train |
|
bfontaine/ArrayDB | src/arraydb.js | cleanMarks | function cleanMarks( o ) {
delete o[randKey];
for ( prop in o ) {
if ( p.hasOwnProperty( prop )
&& get_type( p[prop] ) == 'object'
&& randKey in p[prop]) {
cleanMarks( p[prop] );
}
}
} | javascript | function cleanMarks( o ) {
delete o[randKey];
for ( prop in o ) {
if ( p.hasOwnProperty( prop )
&& get_type( p[prop] ) == 'object'
&& randKey in p[prop]) {
cleanMarks( p[prop] );
}
}
} | [
"function",
"cleanMarks",
"(",
"o",
")",
"{",
"delete",
"o",
"[",
"randKey",
"]",
";",
"for",
"(",
"prop",
"in",
"o",
")",
"{",
"if",
"(",
"p",
".",
"hasOwnProperty",
"(",
"prop",
")",
"&&",
"get_type",
"(",
"p",
"[",
"prop",
"]",
")",
"==",
"'object'",
"&&",
"randKey",
"in",
"p",
"[",
"prop",
"]",
")",
"{",
"cleanMarks",
"(",
"p",
"[",
"prop",
"]",
")",
";",
"}",
"}",
"}"
]
| clean up marked objects | [
"clean",
"up",
"marked",
"objects"
]
| 011939dda73cfbea112bb803480e849afba14e92 | https://github.com/bfontaine/ArrayDB/blob/011939dda73cfbea112bb803480e849afba14e92/src/arraydb.js#L117-L127 | train |
bfontaine/ArrayDB | src/arraydb.js | match_objects_teardown | function match_objects_teardown( o, p, result ) {
if ( get_type( o ) == 'object' ) { cleanMarks( o ); }
if ( get_type( p ) == 'object' ) { cleanMarks( p ); }
return result;
} | javascript | function match_objects_teardown( o, p, result ) {
if ( get_type( o ) == 'object' ) { cleanMarks( o ); }
if ( get_type( p ) == 'object' ) { cleanMarks( p ); }
return result;
} | [
"function",
"match_objects_teardown",
"(",
"o",
",",
"p",
",",
"result",
")",
"{",
"if",
"(",
"get_type",
"(",
"o",
")",
"==",
"'object'",
")",
"{",
"cleanMarks",
"(",
"o",
")",
";",
"}",
"if",
"(",
"get_type",
"(",
"p",
")",
"==",
"'object'",
")",
"{",
"cleanMarks",
"(",
"p",
")",
";",
"}",
"return",
"result",
";",
"}"
]
| clean up marked objects and return result | [
"clean",
"up",
"marked",
"objects",
"and",
"return",
"result"
]
| 011939dda73cfbea112bb803480e849afba14e92 | https://github.com/bfontaine/ArrayDB/blob/011939dda73cfbea112bb803480e849afba14e92/src/arraydb.js#L130-L134 | train |
bfontaine/ArrayDB | src/arraydb.js | query | function query( q, limit, offset ) {
var i, _l, res,
strict = true,
reverse = false;
if ( this.length === 0 || arguments.length === 0 ) {
return [];
}
if ( typeof q === 'object' && q != null
&& 'query' in q
&& arguments.length === 1 ) {
limit = +q.limit;
offset = +q.offset;
strict = !!q.strict;
reverse = !!q.reverse;
q = q.query;
}
if ( isNaN( limit ) ) {
limit = Infinity;
}
offset = offset || 0;
if ( typeof Array.prototype.filter === 'function' ) {
return this.filter(function( o ) {
return match( o, q, strict ) === !reverse;
}).slice( offset, offset + limit );
}
res = [];
_l = Math.min( this.length, limit + offset );
i = 0;
for ( ; i<_l; i++ ) {
if ( match( this[ i ], q, strict ) === !reverse ) {
if ( offset-- > 0 ) { continue; }
res.push( this[ i ] );
}
}
return res;
} | javascript | function query( q, limit, offset ) {
var i, _l, res,
strict = true,
reverse = false;
if ( this.length === 0 || arguments.length === 0 ) {
return [];
}
if ( typeof q === 'object' && q != null
&& 'query' in q
&& arguments.length === 1 ) {
limit = +q.limit;
offset = +q.offset;
strict = !!q.strict;
reverse = !!q.reverse;
q = q.query;
}
if ( isNaN( limit ) ) {
limit = Infinity;
}
offset = offset || 0;
if ( typeof Array.prototype.filter === 'function' ) {
return this.filter(function( o ) {
return match( o, q, strict ) === !reverse;
}).slice( offset, offset + limit );
}
res = [];
_l = Math.min( this.length, limit + offset );
i = 0;
for ( ; i<_l; i++ ) {
if ( match( this[ i ], q, strict ) === !reverse ) {
if ( offset-- > 0 ) { continue; }
res.push( this[ i ] );
}
}
return res;
} | [
"function",
"query",
"(",
"q",
",",
"limit",
",",
"offset",
")",
"{",
"var",
"i",
",",
"_l",
",",
"res",
",",
"strict",
"=",
"true",
",",
"reverse",
"=",
"false",
";",
"if",
"(",
"this",
".",
"length",
"===",
"0",
"||",
"arguments",
".",
"length",
"===",
"0",
")",
"{",
"return",
"[",
"]",
";",
"}",
"if",
"(",
"typeof",
"q",
"===",
"'object'",
"&&",
"q",
"!=",
"null",
"&&",
"'query'",
"in",
"q",
"&&",
"arguments",
".",
"length",
"===",
"1",
")",
"{",
"limit",
"=",
"+",
"q",
".",
"limit",
";",
"offset",
"=",
"+",
"q",
".",
"offset",
";",
"strict",
"=",
"!",
"!",
"q",
".",
"strict",
";",
"reverse",
"=",
"!",
"!",
"q",
".",
"reverse",
";",
"q",
"=",
"q",
".",
"query",
";",
"}",
"if",
"(",
"isNaN",
"(",
"limit",
")",
")",
"{",
"limit",
"=",
"Infinity",
";",
"}",
"offset",
"=",
"offset",
"||",
"0",
";",
"if",
"(",
"typeof",
"Array",
".",
"prototype",
".",
"filter",
"===",
"'function'",
")",
"{",
"return",
"this",
".",
"filter",
"(",
"function",
"(",
"o",
")",
"{",
"return",
"match",
"(",
"o",
",",
"q",
",",
"strict",
")",
"===",
"!",
"reverse",
";",
"}",
")",
".",
"slice",
"(",
"offset",
",",
"offset",
"+",
"limit",
")",
";",
"}",
"res",
"=",
"[",
"]",
";",
"_l",
"=",
"Math",
".",
"min",
"(",
"this",
".",
"length",
",",
"limit",
"+",
"offset",
")",
";",
"i",
"=",
"0",
";",
"for",
"(",
";",
"i",
"<",
"_l",
";",
"i",
"++",
")",
"{",
"if",
"(",
"match",
"(",
"this",
"[",
"i",
"]",
",",
"q",
",",
"strict",
")",
"===",
"!",
"reverse",
")",
"{",
"if",
"(",
"offset",
"--",
">",
"0",
")",
"{",
"continue",
";",
"}",
"res",
".",
"push",
"(",
"this",
"[",
"i",
"]",
")",
";",
"}",
"}",
"return",
"res",
";",
"}"
]
| Main function. Will be called on an ArrayDB or Array
object.
@q [Object]: the query. If it's the only one argument and it has
a 'query' property, it's used to specify other arguments,
e.g.: {
query: <the query>,
limit: <the limit>,
offset: <the offset>,
strict: <strict mode?>,
reverse: <reversed query?>
}
@limit [Number]: optional. The maximum number of results. Default
to Infinity.
@offset [Number]: optional. Default to 0. | [
"Main",
"function",
".",
"Will",
"be",
"called",
"on",
"an",
"ArrayDB",
"or",
"Array",
"object",
"."
]
| 011939dda73cfbea112bb803480e849afba14e92 | https://github.com/bfontaine/ArrayDB/blob/011939dda73cfbea112bb803480e849afba14e92/src/arraydb.js#L247-L308 | train |
quick-sort/jstock | index.js | wma | function wma(close, n = 5) {
let result = []
let len = close.length
if (len === 0 || n <= 0) {
return result
}
let avg = close[0]
result.push(avg)
let T_m = close[0]
let div = n * (n + 1) / 2
for (let i = 1; i < len; i++) {
if (i < n) {
T_m += close[i]
let sum = 0
let d = 0
for (let j = 0; j <= i; j++) {
sum += close[i - j] * (n - j)
d += (n - j)
}
avg = sum / d
} else {
avg += (n * close[i] - T_m) / div
T_m += close[i] - close[i - n]
}
result.push(avg)
}
return result
} | javascript | function wma(close, n = 5) {
let result = []
let len = close.length
if (len === 0 || n <= 0) {
return result
}
let avg = close[0]
result.push(avg)
let T_m = close[0]
let div = n * (n + 1) / 2
for (let i = 1; i < len; i++) {
if (i < n) {
T_m += close[i]
let sum = 0
let d = 0
for (let j = 0; j <= i; j++) {
sum += close[i - j] * (n - j)
d += (n - j)
}
avg = sum / d
} else {
avg += (n * close[i] - T_m) / div
T_m += close[i] - close[i - n]
}
result.push(avg)
}
return result
} | [
"function",
"wma",
"(",
"close",
",",
"n",
"=",
"5",
")",
"{",
"let",
"result",
"=",
"[",
"]",
"let",
"len",
"=",
"close",
".",
"length",
"if",
"(",
"len",
"===",
"0",
"||",
"n",
"<=",
"0",
")",
"{",
"return",
"result",
"}",
"let",
"avg",
"=",
"close",
"[",
"0",
"]",
"result",
".",
"push",
"(",
"avg",
")",
"let",
"T_m",
"=",
"close",
"[",
"0",
"]",
"let",
"div",
"=",
"n",
"*",
"(",
"n",
"+",
"1",
")",
"/",
"2",
"for",
"(",
"let",
"i",
"=",
"1",
";",
"i",
"<",
"len",
";",
"i",
"++",
")",
"{",
"if",
"(",
"i",
"<",
"n",
")",
"{",
"T_m",
"+=",
"close",
"[",
"i",
"]",
"let",
"sum",
"=",
"0",
"let",
"d",
"=",
"0",
"for",
"(",
"let",
"j",
"=",
"0",
";",
"j",
"<=",
"i",
";",
"j",
"++",
")",
"{",
"sum",
"+=",
"close",
"[",
"i",
"-",
"j",
"]",
"*",
"(",
"n",
"-",
"j",
")",
"d",
"+=",
"(",
"n",
"-",
"j",
")",
"}",
"avg",
"=",
"sum",
"/",
"d",
"}",
"else",
"{",
"avg",
"+=",
"(",
"n",
"*",
"close",
"[",
"i",
"]",
"-",
"T_m",
")",
"/",
"div",
"T_m",
"+=",
"close",
"[",
"i",
"]",
"-",
"close",
"[",
"i",
"-",
"n",
"]",
"}",
"result",
".",
"push",
"(",
"avg",
")",
"}",
"return",
"result",
"}"
]
| Weighted moving average | [
"Weighted",
"moving",
"average"
]
| 52e58c982c72b97bf55e1efc3f2637bf4c209181 | https://github.com/quick-sort/jstock/blob/52e58c982c72b97bf55e1efc3f2637bf4c209181/index.js#L32-L60 | train |
quick-sort/jstock | index.js | ema | function ema(close, n = 5) {
let len = close.length
let result = []
if (len === 0 || n <= 0) {
return result
}
let alpha = 2 / (n + 1)
let avg = close[0]
result.push(avg)
for (let i = 1; i < len; i++) {
avg = alpha * close[i] + (1 - alpha) * avg
result.push(avg)
}
return result
} | javascript | function ema(close, n = 5) {
let len = close.length
let result = []
if (len === 0 || n <= 0) {
return result
}
let alpha = 2 / (n + 1)
let avg = close[0]
result.push(avg)
for (let i = 1; i < len; i++) {
avg = alpha * close[i] + (1 - alpha) * avg
result.push(avg)
}
return result
} | [
"function",
"ema",
"(",
"close",
",",
"n",
"=",
"5",
")",
"{",
"let",
"len",
"=",
"close",
".",
"length",
"let",
"result",
"=",
"[",
"]",
"if",
"(",
"len",
"===",
"0",
"||",
"n",
"<=",
"0",
")",
"{",
"return",
"result",
"}",
"let",
"alpha",
"=",
"2",
"/",
"(",
"n",
"+",
"1",
")",
"let",
"avg",
"=",
"close",
"[",
"0",
"]",
"result",
".",
"push",
"(",
"avg",
")",
"for",
"(",
"let",
"i",
"=",
"1",
";",
"i",
"<",
"len",
";",
"i",
"++",
")",
"{",
"avg",
"=",
"alpha",
"*",
"close",
"[",
"i",
"]",
"+",
"(",
"1",
"-",
"alpha",
")",
"*",
"avg",
"result",
".",
"push",
"(",
"avg",
")",
"}",
"return",
"result",
"}"
]
| Exponential moving average
alpha = 2 / (N + 1) | [
"Exponential",
"moving",
"average"
]
| 52e58c982c72b97bf55e1efc3f2637bf4c209181 | https://github.com/quick-sort/jstock/blob/52e58c982c72b97bf55e1efc3f2637bf4c209181/index.js#L66-L80 | train |
quick-sort/jstock | index.js | kdj | function kdj(close, high, low, n = 5) {
let len = close.length
let k = []
let d = []
let j = []
if (len === 0 || n <= 0) {
return {k, d, j}
}
let ik = 50
let id = 50
let ij = 50
let rsv = (close[0] - low[0]) * 100 / (high[0] - low[0])
ik = 2 * ik / 3 + rsv / 3
id = 2 * id / 3 + ik / 3
ij = 3 * ik - 2 * id
k.push(ik)
d.push(id)
j.push(ij)
let ln = low[0]
let hn = high[0]
for (let i = 1; i < len; i++) {
if (i < n) {
if (ln > low[i]) {
ln = low[i]
}
if (hn < high[i]) {
hn = high[i]
}
} else {
if (ln === low[i - n]) {
ln = low[i]
for (let j = 1; j < n; j++) {
if (low[i - j] < ln) {
ln = low[i - j]
}
}
} else {
if (ln > low[i]) {
ln = low[i]
}
}
if (hn === high[i - n]) {
hn = high[i]
for (let j = 1; j < n; j++) {
if (high[i - j] > hn) {
hn = high[i - j]
}
}
} else {
if (hn < high[i]) {
hn = high[i]
}
}
}
rsv = (close[i] - ln) * 100 / (hn - ln)
ik = 2 * ik / 3 + rsv / 3
id = 2 * id / 3 + ik / 3
ij = 3 * ik - 2 * id
k.push(ik)
d.push(id)
j.push(ij)
}
return {k, d, j}
} | javascript | function kdj(close, high, low, n = 5) {
let len = close.length
let k = []
let d = []
let j = []
if (len === 0 || n <= 0) {
return {k, d, j}
}
let ik = 50
let id = 50
let ij = 50
let rsv = (close[0] - low[0]) * 100 / (high[0] - low[0])
ik = 2 * ik / 3 + rsv / 3
id = 2 * id / 3 + ik / 3
ij = 3 * ik - 2 * id
k.push(ik)
d.push(id)
j.push(ij)
let ln = low[0]
let hn = high[0]
for (let i = 1; i < len; i++) {
if (i < n) {
if (ln > low[i]) {
ln = low[i]
}
if (hn < high[i]) {
hn = high[i]
}
} else {
if (ln === low[i - n]) {
ln = low[i]
for (let j = 1; j < n; j++) {
if (low[i - j] < ln) {
ln = low[i - j]
}
}
} else {
if (ln > low[i]) {
ln = low[i]
}
}
if (hn === high[i - n]) {
hn = high[i]
for (let j = 1; j < n; j++) {
if (high[i - j] > hn) {
hn = high[i - j]
}
}
} else {
if (hn < high[i]) {
hn = high[i]
}
}
}
rsv = (close[i] - ln) * 100 / (hn - ln)
ik = 2 * ik / 3 + rsv / 3
id = 2 * id / 3 + ik / 3
ij = 3 * ik - 2 * id
k.push(ik)
d.push(id)
j.push(ij)
}
return {k, d, j}
} | [
"function",
"kdj",
"(",
"close",
",",
"high",
",",
"low",
",",
"n",
"=",
"5",
")",
"{",
"let",
"len",
"=",
"close",
".",
"length",
"let",
"k",
"=",
"[",
"]",
"let",
"d",
"=",
"[",
"]",
"let",
"j",
"=",
"[",
"]",
"if",
"(",
"len",
"===",
"0",
"||",
"n",
"<=",
"0",
")",
"{",
"return",
"{",
"k",
",",
"d",
",",
"j",
"}",
"}",
"let",
"ik",
"=",
"50",
"let",
"id",
"=",
"50",
"let",
"ij",
"=",
"50",
"let",
"rsv",
"=",
"(",
"close",
"[",
"0",
"]",
"-",
"low",
"[",
"0",
"]",
")",
"*",
"100",
"/",
"(",
"high",
"[",
"0",
"]",
"-",
"low",
"[",
"0",
"]",
")",
"ik",
"=",
"2",
"*",
"ik",
"/",
"3",
"+",
"rsv",
"/",
"3",
"id",
"=",
"2",
"*",
"id",
"/",
"3",
"+",
"ik",
"/",
"3",
"ij",
"=",
"3",
"*",
"ik",
"-",
"2",
"*",
"id",
"k",
".",
"push",
"(",
"ik",
")",
"d",
".",
"push",
"(",
"id",
")",
"j",
".",
"push",
"(",
"ij",
")",
"let",
"ln",
"=",
"low",
"[",
"0",
"]",
"let",
"hn",
"=",
"high",
"[",
"0",
"]",
"for",
"(",
"let",
"i",
"=",
"1",
";",
"i",
"<",
"len",
";",
"i",
"++",
")",
"{",
"if",
"(",
"i",
"<",
"n",
")",
"{",
"if",
"(",
"ln",
">",
"low",
"[",
"i",
"]",
")",
"{",
"ln",
"=",
"low",
"[",
"i",
"]",
"}",
"if",
"(",
"hn",
"<",
"high",
"[",
"i",
"]",
")",
"{",
"hn",
"=",
"high",
"[",
"i",
"]",
"}",
"}",
"else",
"{",
"if",
"(",
"ln",
"===",
"low",
"[",
"i",
"-",
"n",
"]",
")",
"{",
"ln",
"=",
"low",
"[",
"i",
"]",
"for",
"(",
"let",
"j",
"=",
"1",
";",
"j",
"<",
"n",
";",
"j",
"++",
")",
"{",
"if",
"(",
"low",
"[",
"i",
"-",
"j",
"]",
"<",
"ln",
")",
"{",
"ln",
"=",
"low",
"[",
"i",
"-",
"j",
"]",
"}",
"}",
"}",
"else",
"{",
"if",
"(",
"ln",
">",
"low",
"[",
"i",
"]",
")",
"{",
"ln",
"=",
"low",
"[",
"i",
"]",
"}",
"}",
"if",
"(",
"hn",
"===",
"high",
"[",
"i",
"-",
"n",
"]",
")",
"{",
"hn",
"=",
"high",
"[",
"i",
"]",
"for",
"(",
"let",
"j",
"=",
"1",
";",
"j",
"<",
"n",
";",
"j",
"++",
")",
"{",
"if",
"(",
"high",
"[",
"i",
"-",
"j",
"]",
">",
"hn",
")",
"{",
"hn",
"=",
"high",
"[",
"i",
"-",
"j",
"]",
"}",
"}",
"}",
"else",
"{",
"if",
"(",
"hn",
"<",
"high",
"[",
"i",
"]",
")",
"{",
"hn",
"=",
"high",
"[",
"i",
"]",
"}",
"}",
"}",
"rsv",
"=",
"(",
"close",
"[",
"i",
"]",
"-",
"ln",
")",
"*",
"100",
"/",
"(",
"hn",
"-",
"ln",
")",
"ik",
"=",
"2",
"*",
"ik",
"/",
"3",
"+",
"rsv",
"/",
"3",
"id",
"=",
"2",
"*",
"id",
"/",
"3",
"+",
"ik",
"/",
"3",
"ij",
"=",
"3",
"*",
"ik",
"-",
"2",
"*",
"id",
"k",
".",
"push",
"(",
"ik",
")",
"d",
".",
"push",
"(",
"id",
")",
"j",
".",
"push",
"(",
"ij",
")",
"}",
"return",
"{",
"k",
",",
"d",
",",
"j",
"}",
"}"
]
| KDJ
close should have | [
"KDJ",
"close",
"should",
"have"
]
| 52e58c982c72b97bf55e1efc3f2637bf4c209181 | https://github.com/quick-sort/jstock/blob/52e58c982c72b97bf55e1efc3f2637bf4c209181/index.js#L138-L203 | train |
ply-ct/ply | lib/storage.js | function(location, name) {
this.location = location;
this.name = name;
if (typeof localStorage === 'undefined' || localStorage === null) {
if (this.name) {
this.name = require('sanitize-filename')(this.name, {replacement: '_'});
require('mkdirp').sync(this.location);
}
}
else {
this.localStorage = localStorage;
}
this.path = this.location;
if (this.name)
this.path += '/' + this.name;
} | javascript | function(location, name) {
this.location = location;
this.name = name;
if (typeof localStorage === 'undefined' || localStorage === null) {
if (this.name) {
this.name = require('sanitize-filename')(this.name, {replacement: '_'});
require('mkdirp').sync(this.location);
}
}
else {
this.localStorage = localStorage;
}
this.path = this.location;
if (this.name)
this.path += '/' + this.name;
} | [
"function",
"(",
"location",
",",
"name",
")",
"{",
"this",
".",
"location",
"=",
"location",
";",
"this",
".",
"name",
"=",
"name",
";",
"if",
"(",
"typeof",
"localStorage",
"===",
"'undefined'",
"||",
"localStorage",
"===",
"null",
")",
"{",
"if",
"(",
"this",
".",
"name",
")",
"{",
"this",
".",
"name",
"=",
"require",
"(",
"'sanitize-filename'",
")",
"(",
"this",
".",
"name",
",",
"{",
"replacement",
":",
"'_'",
"}",
")",
";",
"require",
"(",
"'mkdirp'",
")",
".",
"sync",
"(",
"this",
".",
"location",
")",
";",
"}",
"}",
"else",
"{",
"this",
".",
"localStorage",
"=",
"localStorage",
";",
"}",
"this",
".",
"path",
"=",
"this",
".",
"location",
";",
"if",
"(",
"this",
".",
"name",
")",
"this",
".",
"path",
"+=",
"'/'",
"+",
"this",
".",
"name",
";",
"}"
]
| Abstracts storage to file system or html5 localStorage. name is optional | [
"Abstracts",
"storage",
"to",
"file",
"system",
"or",
"html5",
"localStorage",
".",
"name",
"is",
"optional"
]
| 1d4146829845fedd917f5f0626cd74cc3845d0c8 | https://github.com/ply-ct/ply/blob/1d4146829845fedd917f5f0626cd74cc3845d0c8/lib/storage.js#L7-L22 | train |
|
jkawamoto/psi | node/dlpa/lib/dlpa.js | flatten | function flatten(matrix) {
const res = [];
// If the given matrix is not a matrix but a scalar.
if (!Array.isArray(matrix)) {
matrix = [
[matrix]
];
}
matrix.forEach((row) => {
// If the given matrix is a vector.
if (!Array.isArray(row)) {
row = [row];
}
row.forEach((elem) => {
res.push(elem.real);
res.push(elem.imag);
});
});
return res;
} | javascript | function flatten(matrix) {
const res = [];
// If the given matrix is not a matrix but a scalar.
if (!Array.isArray(matrix)) {
matrix = [
[matrix]
];
}
matrix.forEach((row) => {
// If the given matrix is a vector.
if (!Array.isArray(row)) {
row = [row];
}
row.forEach((elem) => {
res.push(elem.real);
res.push(elem.imag);
});
});
return res;
} | [
"function",
"flatten",
"(",
"matrix",
")",
"{",
"const",
"res",
"=",
"[",
"]",
";",
"if",
"(",
"!",
"Array",
".",
"isArray",
"(",
"matrix",
")",
")",
"{",
"matrix",
"=",
"[",
"[",
"matrix",
"]",
"]",
";",
"}",
"matrix",
".",
"forEach",
"(",
"(",
"row",
")",
"=>",
"{",
"if",
"(",
"!",
"Array",
".",
"isArray",
"(",
"row",
")",
")",
"{",
"row",
"=",
"[",
"row",
"]",
";",
"}",
"row",
".",
"forEach",
"(",
"(",
"elem",
")",
"=>",
"{",
"res",
".",
"push",
"(",
"elem",
".",
"real",
")",
";",
"res",
".",
"push",
"(",
"elem",
".",
"imag",
")",
";",
"}",
")",
";",
"}",
")",
";",
"return",
"res",
";",
"}"
]
| flatten returns a list which flatten the given matrix. | [
"flatten",
"returns",
"a",
"list",
"which",
"flatten",
"the",
"given",
"matrix",
"."
]
| 94c75c5b6fbd3380b1729ce61ed2fc6538278a1e | https://github.com/jkawamoto/psi/blob/94c75c5b6fbd3380b1729ce61ed2fc6538278a1e/node/dlpa/lib/dlpa.js#L29-L51 | train |
jkawamoto/psi | node/dlpa/lib/dlpa.js | matrix | function matrix(rows, columns, values) {
// console.log(values);
const res = [];
let row = [];
let real;
values.forEach((v, i) => {
if (i % 2 == 0) {
real = v;
} else {
row.push({
real: real,
imag: v
});
if ((i + 1) / 2 % columns == 0) {
res.push(row);
row = [];
}
}
});
return res;
} | javascript | function matrix(rows, columns, values) {
// console.log(values);
const res = [];
let row = [];
let real;
values.forEach((v, i) => {
if (i % 2 == 0) {
real = v;
} else {
row.push({
real: real,
imag: v
});
if ((i + 1) / 2 % columns == 0) {
res.push(row);
row = [];
}
}
});
return res;
} | [
"function",
"matrix",
"(",
"rows",
",",
"columns",
",",
"values",
")",
"{",
"const",
"res",
"=",
"[",
"]",
";",
"let",
"row",
"=",
"[",
"]",
";",
"let",
"real",
";",
"values",
".",
"forEach",
"(",
"(",
"v",
",",
"i",
")",
"=>",
"{",
"if",
"(",
"i",
"%",
"2",
"==",
"0",
")",
"{",
"real",
"=",
"v",
";",
"}",
"else",
"{",
"row",
".",
"push",
"(",
"{",
"real",
":",
"real",
",",
"imag",
":",
"v",
"}",
")",
";",
"if",
"(",
"(",
"i",
"+",
"1",
")",
"/",
"2",
"%",
"columns",
"==",
"0",
")",
"{",
"res",
".",
"push",
"(",
"row",
")",
";",
"row",
"=",
"[",
"]",
";",
"}",
"}",
"}",
")",
";",
"return",
"res",
";",
"}"
]
| matrix returns a matrix of which values are given ones. | [
"matrix",
"returns",
"a",
"matrix",
"of",
"which",
"values",
"are",
"given",
"ones",
"."
]
| 94c75c5b6fbd3380b1729ce61ed2fc6538278a1e | https://github.com/jkawamoto/psi/blob/94c75c5b6fbd3380b1729ce61ed2fc6538278a1e/node/dlpa/lib/dlpa.js#L55-L75 | train |
jkawamoto/psi | node/dlpa/lib/dlpa.js | Client | function Client(config) {
RED.nodes.createNode(this, config);
const port = String(Math.floor(Math.random() * (40000 - 30000 + 1)) + 30000);
// Start a DLPA-Node server.
// Options:
// --listen LISTEN Listening port.
// --host HOST Address of the DLPA server to be connected.
// --port PORT Port number of the DLPA server to be connected.
// --id CLIENT_ID Client ID
// --epsilon EPSILON Epsilon used in the Laplace distribution to add noises.
const proc = spawn("python3", [
"-m", "dlpanode.server",
"--listen", port,
"--host", config.host,
"--port", config.port,
"--id", config.client_id,
"--epsilon", config.epsilon
], {
"cwd": __dirname,
stdio: ["pipe", process.stdout, "pipe"]
});
let exited = false;
proc.on("exit", (code, signal) => {
this.log(`DLPA-Node server is closed: ${signal}`);
exited = true;
})
const logger = readline.createInterface({
input: proc.stderr,
});
logger.on("line", (line) => {
this.log(line)
})
const client = new dlpanode.DLPAClient(
`localhost:${port}`, grpc.credentials.createInsecure());
this.on("input", (msg) => {
// Send a message to the server.
client.encryptNoisySum({
values: flatten(msg.payload).map(v => Math.round((v + MAG) * MAG))
}, (err, response) => {
if (err) {
this.error(err);
}
});
});
// Stop the server.
this.on("close", (done) => {
if (exited) {
done();
return;
}
// Wait the server is closed.
proc.on("exit", () => {
done();
});
// Send a signal.
this.log("DLPA-Node server is closing");
proc.stdin.close();
proc.stdout.close();
logger.close();
proc.kill();
});
} | javascript | function Client(config) {
RED.nodes.createNode(this, config);
const port = String(Math.floor(Math.random() * (40000 - 30000 + 1)) + 30000);
// Start a DLPA-Node server.
// Options:
// --listen LISTEN Listening port.
// --host HOST Address of the DLPA server to be connected.
// --port PORT Port number of the DLPA server to be connected.
// --id CLIENT_ID Client ID
// --epsilon EPSILON Epsilon used in the Laplace distribution to add noises.
const proc = spawn("python3", [
"-m", "dlpanode.server",
"--listen", port,
"--host", config.host,
"--port", config.port,
"--id", config.client_id,
"--epsilon", config.epsilon
], {
"cwd": __dirname,
stdio: ["pipe", process.stdout, "pipe"]
});
let exited = false;
proc.on("exit", (code, signal) => {
this.log(`DLPA-Node server is closed: ${signal}`);
exited = true;
})
const logger = readline.createInterface({
input: proc.stderr,
});
logger.on("line", (line) => {
this.log(line)
})
const client = new dlpanode.DLPAClient(
`localhost:${port}`, grpc.credentials.createInsecure());
this.on("input", (msg) => {
// Send a message to the server.
client.encryptNoisySum({
values: flatten(msg.payload).map(v => Math.round((v + MAG) * MAG))
}, (err, response) => {
if (err) {
this.error(err);
}
});
});
// Stop the server.
this.on("close", (done) => {
if (exited) {
done();
return;
}
// Wait the server is closed.
proc.on("exit", () => {
done();
});
// Send a signal.
this.log("DLPA-Node server is closing");
proc.stdin.close();
proc.stdout.close();
logger.close();
proc.kill();
});
} | [
"function",
"Client",
"(",
"config",
")",
"{",
"RED",
".",
"nodes",
".",
"createNode",
"(",
"this",
",",
"config",
")",
";",
"const",
"port",
"=",
"String",
"(",
"Math",
".",
"floor",
"(",
"Math",
".",
"random",
"(",
")",
"*",
"(",
"40000",
"-",
"30000",
"+",
"1",
")",
")",
"+",
"30000",
")",
";",
"const",
"proc",
"=",
"spawn",
"(",
"\"python3\"",
",",
"[",
"\"-m\"",
",",
"\"dlpanode.server\"",
",",
"\"--listen\"",
",",
"port",
",",
"\"--host\"",
",",
"config",
".",
"host",
",",
"\"--port\"",
",",
"config",
".",
"port",
",",
"\"--id\"",
",",
"config",
".",
"client_id",
",",
"\"--epsilon\"",
",",
"config",
".",
"epsilon",
"]",
",",
"{",
"\"cwd\"",
":",
"__dirname",
",",
"stdio",
":",
"[",
"\"pipe\"",
",",
"process",
".",
"stdout",
",",
"\"pipe\"",
"]",
"}",
")",
";",
"let",
"exited",
"=",
"false",
";",
"proc",
".",
"on",
"(",
"\"exit\"",
",",
"(",
"code",
",",
"signal",
")",
"=>",
"{",
"this",
".",
"log",
"(",
"`",
"${",
"signal",
"}",
"`",
")",
";",
"exited",
"=",
"true",
";",
"}",
")",
"const",
"logger",
"=",
"readline",
".",
"createInterface",
"(",
"{",
"input",
":",
"proc",
".",
"stderr",
",",
"}",
")",
";",
"logger",
".",
"on",
"(",
"\"line\"",
",",
"(",
"line",
")",
"=>",
"{",
"this",
".",
"log",
"(",
"line",
")",
"}",
")",
"const",
"client",
"=",
"new",
"dlpanode",
".",
"DLPAClient",
"(",
"`",
"${",
"port",
"}",
"`",
",",
"grpc",
".",
"credentials",
".",
"createInsecure",
"(",
")",
")",
";",
"this",
".",
"on",
"(",
"\"input\"",
",",
"(",
"msg",
")",
"=>",
"{",
"client",
".",
"encryptNoisySum",
"(",
"{",
"values",
":",
"flatten",
"(",
"msg",
".",
"payload",
")",
".",
"map",
"(",
"v",
"=>",
"Math",
".",
"round",
"(",
"(",
"v",
"+",
"MAG",
")",
"*",
"MAG",
")",
")",
"}",
",",
"(",
"err",
",",
"response",
")",
"=>",
"{",
"if",
"(",
"err",
")",
"{",
"this",
".",
"error",
"(",
"err",
")",
";",
"}",
"}",
")",
";",
"}",
")",
";",
"this",
".",
"on",
"(",
"\"close\"",
",",
"(",
"done",
")",
"=>",
"{",
"if",
"(",
"exited",
")",
"{",
"done",
"(",
")",
";",
"return",
";",
"}",
"proc",
".",
"on",
"(",
"\"exit\"",
",",
"(",
")",
"=>",
"{",
"done",
"(",
")",
";",
"}",
")",
";",
"this",
".",
"log",
"(",
"\"DLPA-Node server is closing\"",
")",
";",
"proc",
".",
"stdin",
".",
"close",
"(",
")",
";",
"proc",
".",
"stdout",
".",
"close",
"(",
")",
";",
"logger",
".",
"close",
"(",
")",
";",
"proc",
".",
"kill",
"(",
")",
";",
"}",
")",
";",
"}"
]
| DLPA Client Node. | [
"DLPA",
"Client",
"Node",
"."
]
| 94c75c5b6fbd3380b1729ce61ed2fc6538278a1e | https://github.com/jkawamoto/psi/blob/94c75c5b6fbd3380b1729ce61ed2fc6538278a1e/node/dlpa/lib/dlpa.js#L84-L156 | train |
jkawamoto/psi | node/dlpa/lib/dlpa.js | Server | function Server(config) {
RED.nodes.createNode(this, config);
// Start a DLPA server.
// Options:
// --port PORT Listening port number.
// --clients CLIENTS The number of clicents.
// --max-workers MAX_WORKERS
// The maximum number of workiers (default: 10).
const proc = spawn("python3", [
"-m", "dlpa.server",
"--port", config.port,
"--clients", config.nclient,
"--key-length", "128",
"--time-span", config.span ? config.span : "300"
], {
cwd: __dirname,
});
let exited = false;
proc.on("exit", (code, signal) => {
this.log(`DLPA server is closed: ${signal}`);
exited = true;
})
const logger = readline.createInterface({
input: proc.stderr
});
logger.on("line", (line) => {
this.log(line);
})
// Wait results which should be outputted into stderr; and then
// post a message based on each output.
const rl = readline.createInterface({
input: proc.stdout
});
rl.on("line", (line) => {
const payload = JSON.parse(line);
this.send({
"topic": config.topic,
"payload": matrix(
parseInt(config.rows, 10),
parseInt(config.columns, 10),
payload.value.map(v => (v / MAG) - MAG))
});
});
// Stop the server.
this.on("close", (done) => {
if (exited) {
done();
return;
}
// Wait the server is closed.
proc.on("exit", () => {
done();
});
// Send a signal.
this.log("DLPA server is closing");
proc.stdin.close();
rl.close();
logger.close();
proc.kill();
});
} | javascript | function Server(config) {
RED.nodes.createNode(this, config);
// Start a DLPA server.
// Options:
// --port PORT Listening port number.
// --clients CLIENTS The number of clicents.
// --max-workers MAX_WORKERS
// The maximum number of workiers (default: 10).
const proc = spawn("python3", [
"-m", "dlpa.server",
"--port", config.port,
"--clients", config.nclient,
"--key-length", "128",
"--time-span", config.span ? config.span : "300"
], {
cwd: __dirname,
});
let exited = false;
proc.on("exit", (code, signal) => {
this.log(`DLPA server is closed: ${signal}`);
exited = true;
})
const logger = readline.createInterface({
input: proc.stderr
});
logger.on("line", (line) => {
this.log(line);
})
// Wait results which should be outputted into stderr; and then
// post a message based on each output.
const rl = readline.createInterface({
input: proc.stdout
});
rl.on("line", (line) => {
const payload = JSON.parse(line);
this.send({
"topic": config.topic,
"payload": matrix(
parseInt(config.rows, 10),
parseInt(config.columns, 10),
payload.value.map(v => (v / MAG) - MAG))
});
});
// Stop the server.
this.on("close", (done) => {
if (exited) {
done();
return;
}
// Wait the server is closed.
proc.on("exit", () => {
done();
});
// Send a signal.
this.log("DLPA server is closing");
proc.stdin.close();
rl.close();
logger.close();
proc.kill();
});
} | [
"function",
"Server",
"(",
"config",
")",
"{",
"RED",
".",
"nodes",
".",
"createNode",
"(",
"this",
",",
"config",
")",
";",
"const",
"proc",
"=",
"spawn",
"(",
"\"python3\"",
",",
"[",
"\"-m\"",
",",
"\"dlpa.server\"",
",",
"\"--port\"",
",",
"config",
".",
"port",
",",
"\"--clients\"",
",",
"config",
".",
"nclient",
",",
"\"--key-length\"",
",",
"\"128\"",
",",
"\"--time-span\"",
",",
"config",
".",
"span",
"?",
"config",
".",
"span",
":",
"\"300\"",
"]",
",",
"{",
"cwd",
":",
"__dirname",
",",
"}",
")",
";",
"let",
"exited",
"=",
"false",
";",
"proc",
".",
"on",
"(",
"\"exit\"",
",",
"(",
"code",
",",
"signal",
")",
"=>",
"{",
"this",
".",
"log",
"(",
"`",
"${",
"signal",
"}",
"`",
")",
";",
"exited",
"=",
"true",
";",
"}",
")",
"const",
"logger",
"=",
"readline",
".",
"createInterface",
"(",
"{",
"input",
":",
"proc",
".",
"stderr",
"}",
")",
";",
"logger",
".",
"on",
"(",
"\"line\"",
",",
"(",
"line",
")",
"=>",
"{",
"this",
".",
"log",
"(",
"line",
")",
";",
"}",
")",
"const",
"rl",
"=",
"readline",
".",
"createInterface",
"(",
"{",
"input",
":",
"proc",
".",
"stdout",
"}",
")",
";",
"rl",
".",
"on",
"(",
"\"line\"",
",",
"(",
"line",
")",
"=>",
"{",
"const",
"payload",
"=",
"JSON",
".",
"parse",
"(",
"line",
")",
";",
"this",
".",
"send",
"(",
"{",
"\"topic\"",
":",
"config",
".",
"topic",
",",
"\"payload\"",
":",
"matrix",
"(",
"parseInt",
"(",
"config",
".",
"rows",
",",
"10",
")",
",",
"parseInt",
"(",
"config",
".",
"columns",
",",
"10",
")",
",",
"payload",
".",
"value",
".",
"map",
"(",
"v",
"=>",
"(",
"v",
"/",
"MAG",
")",
"-",
"MAG",
")",
")",
"}",
")",
";",
"}",
")",
";",
"this",
".",
"on",
"(",
"\"close\"",
",",
"(",
"done",
")",
"=>",
"{",
"if",
"(",
"exited",
")",
"{",
"done",
"(",
")",
";",
"return",
";",
"}",
"proc",
".",
"on",
"(",
"\"exit\"",
",",
"(",
")",
"=>",
"{",
"done",
"(",
")",
";",
"}",
")",
";",
"this",
".",
"log",
"(",
"\"DLPA server is closing\"",
")",
";",
"proc",
".",
"stdin",
".",
"close",
"(",
")",
";",
"rl",
".",
"close",
"(",
")",
";",
"logger",
".",
"close",
"(",
")",
";",
"proc",
".",
"kill",
"(",
")",
";",
"}",
")",
";",
"}"
]
| DLPA Server Node. | [
"DLPA",
"Server",
"Node",
"."
]
| 94c75c5b6fbd3380b1729ce61ed2fc6538278a1e | https://github.com/jkawamoto/psi/blob/94c75c5b6fbd3380b1729ce61ed2fc6538278a1e/node/dlpa/lib/dlpa.js#L163-L230 | train |
sverweij/upem | src/core.js | updateAllDeps | function updateAllDeps (pPackageObject, pOutdatedPackages = {}, pOptions = {}) {
return Object.assign(
{},
pPackageObject,
Object.keys(pPackageObject)
.filter(pPkgKey => pPkgKey.includes('ependencies'))
.reduce(
(pAll, pDepKey) => {
pAll[pDepKey] = updateDeps(pPackageObject[pDepKey], pOutdatedPackages, pOptions)
return pAll
},
{}
)
)
} | javascript | function updateAllDeps (pPackageObject, pOutdatedPackages = {}, pOptions = {}) {
return Object.assign(
{},
pPackageObject,
Object.keys(pPackageObject)
.filter(pPkgKey => pPkgKey.includes('ependencies'))
.reduce(
(pAll, pDepKey) => {
pAll[pDepKey] = updateDeps(pPackageObject[pDepKey], pOutdatedPackages, pOptions)
return pAll
},
{}
)
)
} | [
"function",
"updateAllDeps",
"(",
"pPackageObject",
",",
"pOutdatedPackages",
"=",
"{",
"}",
",",
"pOptions",
"=",
"{",
"}",
")",
"{",
"return",
"Object",
".",
"assign",
"(",
"{",
"}",
",",
"pPackageObject",
",",
"Object",
".",
"keys",
"(",
"pPackageObject",
")",
".",
"filter",
"(",
"pPkgKey",
"=>",
"pPkgKey",
".",
"includes",
"(",
"'ependencies'",
")",
")",
".",
"reduce",
"(",
"(",
"pAll",
",",
"pDepKey",
")",
"=>",
"{",
"pAll",
"[",
"pDepKey",
"]",
"=",
"updateDeps",
"(",
"pPackageObject",
"[",
"pDepKey",
"]",
",",
"pOutdatedPackages",
",",
"pOptions",
")",
"return",
"pAll",
"}",
",",
"{",
"}",
")",
")",
"}"
]
| Updates all dependencies in the passed package.json that match a key in the
passed outdated object to the _latest_ in that object, ignoring the
packages mentioned in the upem.donotup key.
@param {any} pPackageObject - the contents of a package.json in object format
@param {any} pOutdatedObject - the output of npm outdated --json, in object format
@param {string} pSavePrefix - how updated packages get prefixed; either '~',
'^' or '' (the default)
@return {any} - the transformed pPackageObject | [
"Updates",
"all",
"dependencies",
"in",
"the",
"passed",
"package",
".",
"json",
"that",
"match",
"a",
"key",
"in",
"the",
"passed",
"outdated",
"object",
"to",
"the",
"_latest_",
"in",
"that",
"object",
"ignoring",
"the",
"packages",
"mentioned",
"in",
"the",
"upem",
".",
"donotup",
"key",
"."
]
| 6523056076917923f1c9bfb9b96454002145e683 | https://github.com/sverweij/upem/blob/6523056076917923f1c9bfb9b96454002145e683/src/core.js#L42-L56 | train |
nuttyjs/nutty | index.js | function(index)
{
//Check the index value
if(index >= nutty._middlewares.length){ return; }
//Call the middleware
nutty._middlewares[index](args, function(error)
{
//Check for undefined error
if(typeof error === 'undefined'){ var error = null; }
//Check for error
if(error && error instanceof Error)
{
//Throw the error
throw error;
}
//Next middleware on the list
return middlewares_recursive(index + 1);
});
} | javascript | function(index)
{
//Check the index value
if(index >= nutty._middlewares.length){ return; }
//Call the middleware
nutty._middlewares[index](args, function(error)
{
//Check for undefined error
if(typeof error === 'undefined'){ var error = null; }
//Check for error
if(error && error instanceof Error)
{
//Throw the error
throw error;
}
//Next middleware on the list
return middlewares_recursive(index + 1);
});
} | [
"function",
"(",
"index",
")",
"{",
"if",
"(",
"index",
">=",
"nutty",
".",
"_middlewares",
".",
"length",
")",
"{",
"return",
";",
"}",
"nutty",
".",
"_middlewares",
"[",
"index",
"]",
"(",
"args",
",",
"function",
"(",
"error",
")",
"{",
"if",
"(",
"typeof",
"error",
"===",
"'undefined'",
")",
"{",
"var",
"error",
"=",
"null",
";",
"}",
"if",
"(",
"error",
"&&",
"error",
"instanceof",
"Error",
")",
"{",
"throw",
"error",
";",
"}",
"return",
"middlewares_recursive",
"(",
"index",
"+",
"1",
")",
";",
"}",
")",
";",
"}"
]
| Middlewares recursive caller | [
"Middlewares",
"recursive",
"caller"
]
| 1006c57c78d01b7b117af1dec03a64d444632f33 | https://github.com/nuttyjs/nutty/blob/1006c57c78d01b7b117af1dec03a64d444632f33/index.js#L63-L84 | train |
|
ofzza/enTT | dist/entt/extensions.js | getEntityExtensions | function getEntityExtensions(entity) {
// Check if entity passed as instance or class
if (entity instanceof _entt2.default) {
// Return property configuration from instance
return _cache.ConfigurationCache.get(entity).extensions;
} else if (_lodash2.default.isFunction(entity) && entity.prototype instanceof _entt2.default) {
// Return property configuration from class
return _cache.ConfigurationCache.get(new entity()).extensions;
}
} | javascript | function getEntityExtensions(entity) {
// Check if entity passed as instance or class
if (entity instanceof _entt2.default) {
// Return property configuration from instance
return _cache.ConfigurationCache.get(entity).extensions;
} else if (_lodash2.default.isFunction(entity) && entity.prototype instanceof _entt2.default) {
// Return property configuration from class
return _cache.ConfigurationCache.get(new entity()).extensions;
}
} | [
"function",
"getEntityExtensions",
"(",
"entity",
")",
"{",
"if",
"(",
"entity",
"instanceof",
"_entt2",
".",
"default",
")",
"{",
"return",
"_cache",
".",
"ConfigurationCache",
".",
"get",
"(",
"entity",
")",
".",
"extensions",
";",
"}",
"else",
"if",
"(",
"_lodash2",
".",
"default",
".",
"isFunction",
"(",
"entity",
")",
"&&",
"entity",
".",
"prototype",
"instanceof",
"_entt2",
".",
"default",
")",
"{",
"return",
"_cache",
".",
"ConfigurationCache",
".",
"get",
"(",
"new",
"entity",
"(",
")",
")",
".",
"extensions",
";",
"}",
"}"
]
| Retrieves extensions for an Entity instance or class
@static
@param {any} entity Entity instance or EnTT extending class to get extensions for
@returns {any} EnTT Extensions
@memberof Extensions | [
"Retrieves",
"extensions",
"for",
"an",
"Entity",
"instance",
"or",
"class"
]
| fdf27de4142b3c65a3e51dee70e0d7625dff897c | https://github.com/ofzza/enTT/blob/fdf27de4142b3c65a3e51dee70e0d7625dff897c/dist/entt/extensions.js#L50-L59 | train |
yuichi-tanaka/connect-aerospike | lib/connect-aerospike.js | AerospikeStore | function AerospikeStore(options){
var self = this;
options = options || {};
Store.call(self,options);
self.prefix = null == options.prefix ? _default_prefix : options.prefix;
self.ns = null == options.ns ? _default_ns : options.ns;
self.st = null == options.st ? _default_set : options.st;
self.ttl = null == options.ttl ? _default_ttl : options.ttl;
if(!options.hosts || options.hosts.length<=0){
options.hosts = [_default_host];
}
if(options.hosts){
var hosts = options.hosts.map(function(host){
var _val = host.split(':');
var _host = _val[0];
var _port = ~~_val[1] || _default_port;
return { addr:_host,port:_port};
});
var timeout = (typeof options.timeout === 'number' ? options.timeout : _default_timeout);
aerospike.client({
hosts:hosts,
log:{
level: _default_log_level
},
policies:{
timeout: timeout
}
}).connect(function(err,client){
if(err && err.code !== aerospike.status.AEROSPIKE_OK){
console.error('Aerospike server connection Error : %j',err);
}else{
self.client = client;
}
});
}
} | javascript | function AerospikeStore(options){
var self = this;
options = options || {};
Store.call(self,options);
self.prefix = null == options.prefix ? _default_prefix : options.prefix;
self.ns = null == options.ns ? _default_ns : options.ns;
self.st = null == options.st ? _default_set : options.st;
self.ttl = null == options.ttl ? _default_ttl : options.ttl;
if(!options.hosts || options.hosts.length<=0){
options.hosts = [_default_host];
}
if(options.hosts){
var hosts = options.hosts.map(function(host){
var _val = host.split(':');
var _host = _val[0];
var _port = ~~_val[1] || _default_port;
return { addr:_host,port:_port};
});
var timeout = (typeof options.timeout === 'number' ? options.timeout : _default_timeout);
aerospike.client({
hosts:hosts,
log:{
level: _default_log_level
},
policies:{
timeout: timeout
}
}).connect(function(err,client){
if(err && err.code !== aerospike.status.AEROSPIKE_OK){
console.error('Aerospike server connection Error : %j',err);
}else{
self.client = client;
}
});
}
} | [
"function",
"AerospikeStore",
"(",
"options",
")",
"{",
"var",
"self",
"=",
"this",
";",
"options",
"=",
"options",
"||",
"{",
"}",
";",
"Store",
".",
"call",
"(",
"self",
",",
"options",
")",
";",
"self",
".",
"prefix",
"=",
"null",
"==",
"options",
".",
"prefix",
"?",
"_default_prefix",
":",
"options",
".",
"prefix",
";",
"self",
".",
"ns",
"=",
"null",
"==",
"options",
".",
"ns",
"?",
"_default_ns",
":",
"options",
".",
"ns",
";",
"self",
".",
"st",
"=",
"null",
"==",
"options",
".",
"st",
"?",
"_default_set",
":",
"options",
".",
"st",
";",
"self",
".",
"ttl",
"=",
"null",
"==",
"options",
".",
"ttl",
"?",
"_default_ttl",
":",
"options",
".",
"ttl",
";",
"if",
"(",
"!",
"options",
".",
"hosts",
"||",
"options",
".",
"hosts",
".",
"length",
"<=",
"0",
")",
"{",
"options",
".",
"hosts",
"=",
"[",
"_default_host",
"]",
";",
"}",
"if",
"(",
"options",
".",
"hosts",
")",
"{",
"var",
"hosts",
"=",
"options",
".",
"hosts",
".",
"map",
"(",
"function",
"(",
"host",
")",
"{",
"var",
"_val",
"=",
"host",
".",
"split",
"(",
"':'",
")",
";",
"var",
"_host",
"=",
"_val",
"[",
"0",
"]",
";",
"var",
"_port",
"=",
"~",
"~",
"_val",
"[",
"1",
"]",
"||",
"_default_port",
";",
"return",
"{",
"addr",
":",
"_host",
",",
"port",
":",
"_port",
"}",
";",
"}",
")",
";",
"var",
"timeout",
"=",
"(",
"typeof",
"options",
".",
"timeout",
"===",
"'number'",
"?",
"options",
".",
"timeout",
":",
"_default_timeout",
")",
";",
"aerospike",
".",
"client",
"(",
"{",
"hosts",
":",
"hosts",
",",
"log",
":",
"{",
"level",
":",
"_default_log_level",
"}",
",",
"policies",
":",
"{",
"timeout",
":",
"timeout",
"}",
"}",
")",
".",
"connect",
"(",
"function",
"(",
"err",
",",
"client",
")",
"{",
"if",
"(",
"err",
"&&",
"err",
".",
"code",
"!==",
"aerospike",
".",
"status",
".",
"AEROSPIKE_OK",
")",
"{",
"console",
".",
"error",
"(",
"'Aerospike server connection Error : %j'",
",",
"err",
")",
";",
"}",
"else",
"{",
"self",
".",
"client",
"=",
"client",
";",
"}",
"}",
")",
";",
"}",
"}"
]
| Initialize AerospikeStore with the given options
pparam {Object} options
@api public | [
"Initialize",
"AerospikeStore",
"with",
"the",
"given",
"options"
]
| 483a4d7123366b4e67d5de55ad5c57146590e4d5 | https://github.com/yuichi-tanaka/connect-aerospike/blob/483a4d7123366b4e67d5de55ad5c57146590e4d5/lib/connect-aerospike.js#L46-L84 | train |
S3bb1/ah-dashboard-plugin | public/dashboard/bower_components/jQuery-contextMenu/src/jquery.contextMenu.js | function($menu) {
// position to the lower middle of the trigger element
if ($.ui && $.ui.position) {
// .position() is provided as a jQuery UI utility
// (...and it won't work on hidden elements)
$menu.css('display', 'block').position({
my: "center top",
at: "center bottom",
of: this,
offset: "0 5",
collision: "fit"
}).css('display', 'none');
} else {
// determine contextMenu position
var offset = this.offset();
offset.top += this.outerHeight();
offset.left += this.outerWidth() / 2 - $menu.outerWidth() / 2;
$menu.css(offset);
}
} | javascript | function($menu) {
// position to the lower middle of the trigger element
if ($.ui && $.ui.position) {
// .position() is provided as a jQuery UI utility
// (...and it won't work on hidden elements)
$menu.css('display', 'block').position({
my: "center top",
at: "center bottom",
of: this,
offset: "0 5",
collision: "fit"
}).css('display', 'none');
} else {
// determine contextMenu position
var offset = this.offset();
offset.top += this.outerHeight();
offset.left += this.outerWidth() / 2 - $menu.outerWidth() / 2;
$menu.css(offset);
}
} | [
"function",
"(",
"$menu",
")",
"{",
"if",
"(",
"$",
".",
"ui",
"&&",
"$",
".",
"ui",
".",
"position",
")",
"{",
"$menu",
".",
"css",
"(",
"'display'",
",",
"'block'",
")",
".",
"position",
"(",
"{",
"my",
":",
"\"center top\"",
",",
"at",
":",
"\"center bottom\"",
",",
"of",
":",
"this",
",",
"offset",
":",
"\"0 5\"",
",",
"collision",
":",
"\"fit\"",
"}",
")",
".",
"css",
"(",
"'display'",
",",
"'none'",
")",
";",
"}",
"else",
"{",
"var",
"offset",
"=",
"this",
".",
"offset",
"(",
")",
";",
"offset",
".",
"top",
"+=",
"this",
".",
"outerHeight",
"(",
")",
";",
"offset",
".",
"left",
"+=",
"this",
".",
"outerWidth",
"(",
")",
"/",
"2",
"-",
"$menu",
".",
"outerWidth",
"(",
")",
"/",
"2",
";",
"$menu",
".",
"css",
"(",
"offset",
")",
";",
"}",
"}"
]
| determine position to show menu at | [
"determine",
"position",
"to",
"show",
"menu",
"at"
]
| c283370ec0f99a25db5bb7029a98b4febf8c5251 | https://github.com/S3bb1/ah-dashboard-plugin/blob/c283370ec0f99a25db5bb7029a98b4febf8c5251/public/dashboard/bower_components/jQuery-contextMenu/src/jquery.contextMenu.js#L92-L111 | train |
|
S3bb1/ah-dashboard-plugin | public/dashboard/bower_components/jQuery-contextMenu/src/jquery.contextMenu.js | function(e) {
e.preventDefault();
e.stopImmediatePropagation();
$(this).trigger($.Event("contextmenu", { data: e.data, pageX: e.pageX, pageY: e.pageY }));
} | javascript | function(e) {
e.preventDefault();
e.stopImmediatePropagation();
$(this).trigger($.Event("contextmenu", { data: e.data, pageX: e.pageX, pageY: e.pageY }));
} | [
"function",
"(",
"e",
")",
"{",
"e",
".",
"preventDefault",
"(",
")",
";",
"e",
".",
"stopImmediatePropagation",
"(",
")",
";",
"$",
"(",
"this",
")",
".",
"trigger",
"(",
"$",
".",
"Event",
"(",
"\"contextmenu\"",
",",
"{",
"data",
":",
"e",
".",
"data",
",",
"pageX",
":",
"e",
".",
"pageX",
",",
"pageY",
":",
"e",
".",
"pageY",
"}",
")",
")",
";",
"}"
]
| contextMenu left-click trigger | [
"contextMenu",
"left",
"-",
"click",
"trigger"
]
| c283370ec0f99a25db5bb7029a98b4febf8c5251 | https://github.com/S3bb1/ah-dashboard-plugin/blob/c283370ec0f99a25db5bb7029a98b4febf8c5251/public/dashboard/bower_components/jQuery-contextMenu/src/jquery.contextMenu.js#L272-L276 | train |
|
S3bb1/ah-dashboard-plugin | public/dashboard/bower_components/jQuery-contextMenu/src/jquery.contextMenu.js | function(e) {
// show menu
var $this = $(this);
if ($this.data('contextMenuActive') && $currentTrigger && $currentTrigger.length && $currentTrigger.is($this) && !$this.hasClass('context-menu-disabled')) {
e.preventDefault();
e.stopImmediatePropagation();
$currentTrigger = $this;
$this.trigger($.Event("contextmenu", { data: e.data, pageX: e.pageX, pageY: e.pageY }));
}
$this.removeData('contextMenuActive');
} | javascript | function(e) {
// show menu
var $this = $(this);
if ($this.data('contextMenuActive') && $currentTrigger && $currentTrigger.length && $currentTrigger.is($this) && !$this.hasClass('context-menu-disabled')) {
e.preventDefault();
e.stopImmediatePropagation();
$currentTrigger = $this;
$this.trigger($.Event("contextmenu", { data: e.data, pageX: e.pageX, pageY: e.pageY }));
}
$this.removeData('contextMenuActive');
} | [
"function",
"(",
"e",
")",
"{",
"var",
"$this",
"=",
"$",
"(",
"this",
")",
";",
"if",
"(",
"$this",
".",
"data",
"(",
"'contextMenuActive'",
")",
"&&",
"$currentTrigger",
"&&",
"$currentTrigger",
".",
"length",
"&&",
"$currentTrigger",
".",
"is",
"(",
"$this",
")",
"&&",
"!",
"$this",
".",
"hasClass",
"(",
"'context-menu-disabled'",
")",
")",
"{",
"e",
".",
"preventDefault",
"(",
")",
";",
"e",
".",
"stopImmediatePropagation",
"(",
")",
";",
"$currentTrigger",
"=",
"$this",
";",
"$this",
".",
"trigger",
"(",
"$",
".",
"Event",
"(",
"\"contextmenu\"",
",",
"{",
"data",
":",
"e",
".",
"data",
",",
"pageX",
":",
"e",
".",
"pageX",
",",
"pageY",
":",
"e",
".",
"pageY",
"}",
")",
")",
";",
"}",
"$this",
".",
"removeData",
"(",
"'contextMenuActive'",
")",
";",
"}"
]
| contextMenu right-click trigger | [
"contextMenu",
"right",
"-",
"click",
"trigger"
]
| c283370ec0f99a25db5bb7029a98b4febf8c5251 | https://github.com/S3bb1/ah-dashboard-plugin/blob/c283370ec0f99a25db5bb7029a98b4febf8c5251/public/dashboard/bower_components/jQuery-contextMenu/src/jquery.contextMenu.js#L293-L304 | train |
|
S3bb1/ah-dashboard-plugin | public/dashboard/bower_components/jQuery-contextMenu/src/jquery.contextMenu.js | function(e) {
e.stopPropagation();
var opt = $(this).data('contextMenu') || {};
// obtain currently selected menu
if (opt.$selected) {
var $s = opt.$selected;
opt = opt.$selected.parent().data('contextMenu') || {};
opt.$selected = $s;
}
var $children = opt.$menu.children(),
$prev = !opt.$selected || !opt.$selected.prev().length ? $children.last() : opt.$selected.prev(),
$round = $prev;
// skip disabled
while ($prev.hasClass('disabled') || $prev.hasClass('not-selectable')) {
if ($prev.prev().length) {
$prev = $prev.prev();
} else {
$prev = $children.last();
}
if ($prev.is($round)) {
// break endless loop
return;
}
}
// leave current
if (opt.$selected) {
handle.itemMouseleave.call(opt.$selected.get(0), e);
}
// activate next
handle.itemMouseenter.call($prev.get(0), e);
// focus input
var $input = $prev.find('input, textarea, select');
if ($input.length) {
$input.focus();
}
} | javascript | function(e) {
e.stopPropagation();
var opt = $(this).data('contextMenu') || {};
// obtain currently selected menu
if (opt.$selected) {
var $s = opt.$selected;
opt = opt.$selected.parent().data('contextMenu') || {};
opt.$selected = $s;
}
var $children = opt.$menu.children(),
$prev = !opt.$selected || !opt.$selected.prev().length ? $children.last() : opt.$selected.prev(),
$round = $prev;
// skip disabled
while ($prev.hasClass('disabled') || $prev.hasClass('not-selectable')) {
if ($prev.prev().length) {
$prev = $prev.prev();
} else {
$prev = $children.last();
}
if ($prev.is($round)) {
// break endless loop
return;
}
}
// leave current
if (opt.$selected) {
handle.itemMouseleave.call(opt.$selected.get(0), e);
}
// activate next
handle.itemMouseenter.call($prev.get(0), e);
// focus input
var $input = $prev.find('input, textarea, select');
if ($input.length) {
$input.focus();
}
} | [
"function",
"(",
"e",
")",
"{",
"e",
".",
"stopPropagation",
"(",
")",
";",
"var",
"opt",
"=",
"$",
"(",
"this",
")",
".",
"data",
"(",
"'contextMenu'",
")",
"||",
"{",
"}",
";",
"if",
"(",
"opt",
".",
"$selected",
")",
"{",
"var",
"$s",
"=",
"opt",
".",
"$selected",
";",
"opt",
"=",
"opt",
".",
"$selected",
".",
"parent",
"(",
")",
".",
"data",
"(",
"'contextMenu'",
")",
"||",
"{",
"}",
";",
"opt",
".",
"$selected",
"=",
"$s",
";",
"}",
"var",
"$children",
"=",
"opt",
".",
"$menu",
".",
"children",
"(",
")",
",",
"$prev",
"=",
"!",
"opt",
".",
"$selected",
"||",
"!",
"opt",
".",
"$selected",
".",
"prev",
"(",
")",
".",
"length",
"?",
"$children",
".",
"last",
"(",
")",
":",
"opt",
".",
"$selected",
".",
"prev",
"(",
")",
",",
"$round",
"=",
"$prev",
";",
"while",
"(",
"$prev",
".",
"hasClass",
"(",
"'disabled'",
")",
"||",
"$prev",
".",
"hasClass",
"(",
"'not-selectable'",
")",
")",
"{",
"if",
"(",
"$prev",
".",
"prev",
"(",
")",
".",
"length",
")",
"{",
"$prev",
"=",
"$prev",
".",
"prev",
"(",
")",
";",
"}",
"else",
"{",
"$prev",
"=",
"$children",
".",
"last",
"(",
")",
";",
"}",
"if",
"(",
"$prev",
".",
"is",
"(",
"$round",
")",
")",
"{",
"return",
";",
"}",
"}",
"if",
"(",
"opt",
".",
"$selected",
")",
"{",
"handle",
".",
"itemMouseleave",
".",
"call",
"(",
"opt",
".",
"$selected",
".",
"get",
"(",
"0",
")",
",",
"e",
")",
";",
"}",
"handle",
".",
"itemMouseenter",
".",
"call",
"(",
"$prev",
".",
"get",
"(",
"0",
")",
",",
"e",
")",
";",
"var",
"$input",
"=",
"$prev",
".",
"find",
"(",
"'input, textarea, select'",
")",
";",
"if",
"(",
"$input",
".",
"length",
")",
"{",
"$input",
".",
"focus",
"(",
")",
";",
"}",
"}"
]
| select previous possible command in menu | [
"select",
"previous",
"possible",
"command",
"in",
"menu"
]
| c283370ec0f99a25db5bb7029a98b4febf8c5251 | https://github.com/S3bb1/ah-dashboard-plugin/blob/c283370ec0f99a25db5bb7029a98b4febf8c5251/public/dashboard/bower_components/jQuery-contextMenu/src/jquery.contextMenu.js#L558-L599 | train |
|
S3bb1/ah-dashboard-plugin | public/dashboard/bower_components/jQuery-contextMenu/src/jquery.contextMenu.js | function(e) {
var $this = $(this).closest('.context-menu-item'),
data = $this.data(),
opt = data.contextMenu,
root = data.contextMenuRoot;
root.$selected = opt.$selected = $this;
root.isInput = opt.isInput = true;
} | javascript | function(e) {
var $this = $(this).closest('.context-menu-item'),
data = $this.data(),
opt = data.contextMenu,
root = data.contextMenuRoot;
root.$selected = opt.$selected = $this;
root.isInput = opt.isInput = true;
} | [
"function",
"(",
"e",
")",
"{",
"var",
"$this",
"=",
"$",
"(",
"this",
")",
".",
"closest",
"(",
"'.context-menu-item'",
")",
",",
"data",
"=",
"$this",
".",
"data",
"(",
")",
",",
"opt",
"=",
"data",
".",
"contextMenu",
",",
"root",
"=",
"data",
".",
"contextMenuRoot",
";",
"root",
".",
"$selected",
"=",
"opt",
".",
"$selected",
"=",
"$this",
";",
"root",
".",
"isInput",
"=",
"opt",
".",
"isInput",
"=",
"true",
";",
"}"
]
| flag that we're inside an input so the key handler can act accordingly | [
"flag",
"that",
"we",
"re",
"inside",
"an",
"input",
"so",
"the",
"key",
"handler",
"can",
"act",
"accordingly"
]
| c283370ec0f99a25db5bb7029a98b4febf8c5251 | https://github.com/S3bb1/ah-dashboard-plugin/blob/c283370ec0f99a25db5bb7029a98b4febf8c5251/public/dashboard/bower_components/jQuery-contextMenu/src/jquery.contextMenu.js#L645-L653 | train |
|
S3bb1/ah-dashboard-plugin | public/dashboard/bower_components/jQuery-contextMenu/src/jquery.contextMenu.js | function(e) {
var $this = $(this),
data = $this.data(),
opt = data.contextMenu,
root = data.contextMenuRoot,
key = data.contextMenuKey,
callback;
// abort if the key is unknown or disabled or is a menu
if (!opt.items[key] || $this.is('.disabled, .context-menu-submenu, .context-menu-separator, .not-selectable')) {
return;
}
e.preventDefault();
e.stopImmediatePropagation();
if ($.isFunction(root.callbacks[key]) && Object.prototype.hasOwnProperty.call(root.callbacks, key)) {
// item-specific callback
callback = root.callbacks[key];
} else if ($.isFunction(root.callback)) {
// default callback
callback = root.callback;
} else {
// no callback, no action
return;
}
// hide menu if callback doesn't stop that
if (callback.call(root.$trigger, key, root) !== false) {
root.$menu.trigger('contextmenu:hide');
} else if (root.$menu.parent().length) {
op.update.call(root.$trigger, root);
}
} | javascript | function(e) {
var $this = $(this),
data = $this.data(),
opt = data.contextMenu,
root = data.contextMenuRoot,
key = data.contextMenuKey,
callback;
// abort if the key is unknown or disabled or is a menu
if (!opt.items[key] || $this.is('.disabled, .context-menu-submenu, .context-menu-separator, .not-selectable')) {
return;
}
e.preventDefault();
e.stopImmediatePropagation();
if ($.isFunction(root.callbacks[key]) && Object.prototype.hasOwnProperty.call(root.callbacks, key)) {
// item-specific callback
callback = root.callbacks[key];
} else if ($.isFunction(root.callback)) {
// default callback
callback = root.callback;
} else {
// no callback, no action
return;
}
// hide menu if callback doesn't stop that
if (callback.call(root.$trigger, key, root) !== false) {
root.$menu.trigger('contextmenu:hide');
} else if (root.$menu.parent().length) {
op.update.call(root.$trigger, root);
}
} | [
"function",
"(",
"e",
")",
"{",
"var",
"$this",
"=",
"$",
"(",
"this",
")",
",",
"data",
"=",
"$this",
".",
"data",
"(",
")",
",",
"opt",
"=",
"data",
".",
"contextMenu",
",",
"root",
"=",
"data",
".",
"contextMenuRoot",
",",
"key",
"=",
"data",
".",
"contextMenuKey",
",",
"callback",
";",
"if",
"(",
"!",
"opt",
".",
"items",
"[",
"key",
"]",
"||",
"$this",
".",
"is",
"(",
"'.disabled, .context-menu-submenu, .context-menu-separator, .not-selectable'",
")",
")",
"{",
"return",
";",
"}",
"e",
".",
"preventDefault",
"(",
")",
";",
"e",
".",
"stopImmediatePropagation",
"(",
")",
";",
"if",
"(",
"$",
".",
"isFunction",
"(",
"root",
".",
"callbacks",
"[",
"key",
"]",
")",
"&&",
"Object",
".",
"prototype",
".",
"hasOwnProperty",
".",
"call",
"(",
"root",
".",
"callbacks",
",",
"key",
")",
")",
"{",
"callback",
"=",
"root",
".",
"callbacks",
"[",
"key",
"]",
";",
"}",
"else",
"if",
"(",
"$",
".",
"isFunction",
"(",
"root",
".",
"callback",
")",
")",
"{",
"callback",
"=",
"root",
".",
"callback",
";",
"}",
"else",
"{",
"return",
";",
"}",
"if",
"(",
"callback",
".",
"call",
"(",
"root",
".",
"$trigger",
",",
"key",
",",
"root",
")",
"!==",
"false",
")",
"{",
"root",
".",
"$menu",
".",
"trigger",
"(",
"'contextmenu:hide'",
")",
";",
"}",
"else",
"if",
"(",
"root",
".",
"$menu",
".",
"parent",
"(",
")",
".",
"length",
")",
"{",
"op",
".",
"update",
".",
"call",
"(",
"root",
".",
"$trigger",
",",
"root",
")",
";",
"}",
"}"
]
| contextMenu item click | [
"contextMenu",
"item",
"click"
]
| c283370ec0f99a25db5bb7029a98b4febf8c5251 | https://github.com/S3bb1/ah-dashboard-plugin/blob/c283370ec0f99a25db5bb7029a98b4febf8c5251/public/dashboard/bower_components/jQuery-contextMenu/src/jquery.contextMenu.js#L721-L754 | train |
|
theetrain/gulp-resource-hints | lib/index.js | gulpResourceHints | function gulpResourceHints (opt) {
var options = helpers.options(opt)
helpers.reset()
return new Transform({
objectMode: true,
transform: function (file, enc, cb) {
if (file.isNull()) {
helpers.logger(PLUGIN_NAME, 'no file', true)
cb(null, file)
return
}
var fileContents = String(file.contents)
// Gather assets, keep unique values
// Using https://www.npmjs.com/package/list-assets
var assets = new Set(listAssets.html(
fileContents,
{
absolute: true,
protocolRelative: true
}
).map(ob => ob.url))
if (assets.size < 0) {
// Skip file: no static assets
cb(null, file)
return
}
if (!helpers.hasInsertionPoint(file)) {
helpers.logger(PLUGIN_NAME, 'Skipping file: no <head> or token found', true)
cb(null, file)
return
}
// Future feature! Gotta do more stream madness
// if (options.getCSSAssets) {
// for (var k = 0, cssLen = assets.length; k < cssLen; k++) {
// if (assets[k].endsWith('.css') || assets[k].endsWith('.CSS')) {
// assets.push(listAssets.css(
// fileContents
// ))
// }
// }
// }
// Build resource hints based on user-selected assets
var data = ['']
assets.forEach((aVal, aKey, set) => {
Object.keys(options.paths).forEach((key) => {
if (options.paths[key] === '') {
return
}
data.push(helpers.buildResourceHint(key, aVal, options.paths[key]))
})
})
data = data.reduce((a, b) => a + b)
var newFile = helpers.writeDataToFile(file, data, options.pageToken)
if (!newFile) {
helpers.logger(PLUGIN_NAME + ': Could not write data to file. ' + file.relative)
cb(null, file)
return
} else {
file.contents = new Buffer(newFile)
}
cb(null, file)
}
})
} | javascript | function gulpResourceHints (opt) {
var options = helpers.options(opt)
helpers.reset()
return new Transform({
objectMode: true,
transform: function (file, enc, cb) {
if (file.isNull()) {
helpers.logger(PLUGIN_NAME, 'no file', true)
cb(null, file)
return
}
var fileContents = String(file.contents)
// Gather assets, keep unique values
// Using https://www.npmjs.com/package/list-assets
var assets = new Set(listAssets.html(
fileContents,
{
absolute: true,
protocolRelative: true
}
).map(ob => ob.url))
if (assets.size < 0) {
// Skip file: no static assets
cb(null, file)
return
}
if (!helpers.hasInsertionPoint(file)) {
helpers.logger(PLUGIN_NAME, 'Skipping file: no <head> or token found', true)
cb(null, file)
return
}
// Future feature! Gotta do more stream madness
// if (options.getCSSAssets) {
// for (var k = 0, cssLen = assets.length; k < cssLen; k++) {
// if (assets[k].endsWith('.css') || assets[k].endsWith('.CSS')) {
// assets.push(listAssets.css(
// fileContents
// ))
// }
// }
// }
// Build resource hints based on user-selected assets
var data = ['']
assets.forEach((aVal, aKey, set) => {
Object.keys(options.paths).forEach((key) => {
if (options.paths[key] === '') {
return
}
data.push(helpers.buildResourceHint(key, aVal, options.paths[key]))
})
})
data = data.reduce((a, b) => a + b)
var newFile = helpers.writeDataToFile(file, data, options.pageToken)
if (!newFile) {
helpers.logger(PLUGIN_NAME + ': Could not write data to file. ' + file.relative)
cb(null, file)
return
} else {
file.contents = new Buffer(newFile)
}
cb(null, file)
}
})
} | [
"function",
"gulpResourceHints",
"(",
"opt",
")",
"{",
"var",
"options",
"=",
"helpers",
".",
"options",
"(",
"opt",
")",
"helpers",
".",
"reset",
"(",
")",
"return",
"new",
"Transform",
"(",
"{",
"objectMode",
":",
"true",
",",
"transform",
":",
"function",
"(",
"file",
",",
"enc",
",",
"cb",
")",
"{",
"if",
"(",
"file",
".",
"isNull",
"(",
")",
")",
"{",
"helpers",
".",
"logger",
"(",
"PLUGIN_NAME",
",",
"'no file'",
",",
"true",
")",
"cb",
"(",
"null",
",",
"file",
")",
"return",
"}",
"var",
"fileContents",
"=",
"String",
"(",
"file",
".",
"contents",
")",
"var",
"assets",
"=",
"new",
"Set",
"(",
"listAssets",
".",
"html",
"(",
"fileContents",
",",
"{",
"absolute",
":",
"true",
",",
"protocolRelative",
":",
"true",
"}",
")",
".",
"map",
"(",
"ob",
"=>",
"ob",
".",
"url",
")",
")",
"if",
"(",
"assets",
".",
"size",
"<",
"0",
")",
"{",
"cb",
"(",
"null",
",",
"file",
")",
"return",
"}",
"if",
"(",
"!",
"helpers",
".",
"hasInsertionPoint",
"(",
"file",
")",
")",
"{",
"helpers",
".",
"logger",
"(",
"PLUGIN_NAME",
",",
"'Skipping file: no <head> or token found'",
",",
"true",
")",
"cb",
"(",
"null",
",",
"file",
")",
"return",
"}",
"var",
"data",
"=",
"[",
"''",
"]",
"assets",
".",
"forEach",
"(",
"(",
"aVal",
",",
"aKey",
",",
"set",
")",
"=>",
"{",
"Object",
".",
"keys",
"(",
"options",
".",
"paths",
")",
".",
"forEach",
"(",
"(",
"key",
")",
"=>",
"{",
"if",
"(",
"options",
".",
"paths",
"[",
"key",
"]",
"===",
"''",
")",
"{",
"return",
"}",
"data",
".",
"push",
"(",
"helpers",
".",
"buildResourceHint",
"(",
"key",
",",
"aVal",
",",
"options",
".",
"paths",
"[",
"key",
"]",
")",
")",
"}",
")",
"}",
")",
"data",
"=",
"data",
".",
"reduce",
"(",
"(",
"a",
",",
"b",
")",
"=>",
"a",
"+",
"b",
")",
"var",
"newFile",
"=",
"helpers",
".",
"writeDataToFile",
"(",
"file",
",",
"data",
",",
"options",
".",
"pageToken",
")",
"if",
"(",
"!",
"newFile",
")",
"{",
"helpers",
".",
"logger",
"(",
"PLUGIN_NAME",
"+",
"': Could not write data to file. '",
"+",
"file",
".",
"relative",
")",
"cb",
"(",
"null",
",",
"file",
")",
"return",
"}",
"else",
"{",
"file",
".",
"contents",
"=",
"new",
"Buffer",
"(",
"newFile",
")",
"}",
"cb",
"(",
"null",
",",
"file",
")",
"}",
"}",
")",
"}"
]
| Main Function
Read file streams, parse assets, build resource hints
@param {object} opt | [
"Main",
"Function",
"Read",
"file",
"streams",
"parse",
"assets",
"build",
"resource",
"hints"
]
| 12a01e42b35ed07ddef80bddf07e21a69f2138f4 | https://github.com/theetrain/gulp-resource-hints/blob/12a01e42b35ed07ddef80bddf07e21a69f2138f4/lib/index.js#L14-L89 | train |
EvilDevRu/node-redis-dump | lib/node-redis-dump.js | function(key, data, callback) {
'use strict';
/**
* Read scores by values.
*
* @param {Array} values
* @param {Function} callback
*/
var ReadScores = function(values, callback) {
var result = [];
/**
* Get scores recursive.
*/
var GetRecursive = function() {
if (!values.length) {
callback(null, result);
return;
}
var value = values.pop();
this.getClient().zscore(key, value, function(err, score) {
if (err) {
callback(err);
return;
}
result.push(score);
GetRecursive();
});
}.bind(this);
GetRecursive();
}.bind(this);
/**
* Read key.
*
* @param {String} key
* @param {String} type
* @param {Function} rkCallback
*/
var ReadKey = function(key, type, rkCallback) {
var params = [ key ],
command = {
set: 'smembers',
zset: 'zrange',
list: 'lrange',
hash: 'hgetall'
}[ type ] || 'get';
if (command.indexOf('range') !== -1) {
params.push(0);
params.push(-1);
}
params.push(function(err, values) {
if (err) {
rkCallback(err);
return;
}
switch (type) {
case 'zset':
ReadScores(_.clone(values).reverse(), function(err, scores) {
rkCallback(null, _.zip(scores, values));
});
break;
default:
rkCallback(null, values);
break;
}
});
this.getClient()[ command ].apply(this.getClient(), params);
}.bind(this);
switch (this.getExportParams().type) {
// Export as redis type.
case 'redis':
return function(err, type) {
var type2PrintSetCommand = {
string: 'SET',
set: 'SADD',
zset: 'ZADD',
list: 'RPUSH',
hash: 'HSET'
};
if (!data) {
data = '';
}
ReadKey(key, type, function(err, value) {
if (err) {
callback(err);
return;
}
var command = type2PrintSetCommand[ type ];
key = key.trim();
switch (type) {
case 'set':
_.each(value, function(item) {
data += command + ' "' + key + '" "' + item + "\"\n";
});
break;
case 'zset':
_.each(value, function(item) {
data += command + ' "' + key + '" ' + item[0] + ' "' + item[1] + "\"\n";
});
break;
case 'hash':
_.each(_.pairs(value), function(item) {
data += command + ' "' + key + '" "' + item[0] + '" "' + item[1] + "\"\n";
});
break;
default:
data += command + ' "' + key + '" "' + value + "\"\n";
break;
}
callback(null, data);
});
};
// Export as json type.
case 'json':
return function(err, type) {
if (!data) {
data = {};
}
ReadKey(key, type, function(err, value) {
if (err) {
callback(err);
return;
}
switch (type) {
case 'zset':
var withoutScores = [];
_.each(value, function(item) {
withoutScores.push(item[1]);
});
value = withoutScores;
break;
}
data[ key.trim() ] = value;
callback(null, data);
});
};
}
} | javascript | function(key, data, callback) {
'use strict';
/**
* Read scores by values.
*
* @param {Array} values
* @param {Function} callback
*/
var ReadScores = function(values, callback) {
var result = [];
/**
* Get scores recursive.
*/
var GetRecursive = function() {
if (!values.length) {
callback(null, result);
return;
}
var value = values.pop();
this.getClient().zscore(key, value, function(err, score) {
if (err) {
callback(err);
return;
}
result.push(score);
GetRecursive();
});
}.bind(this);
GetRecursive();
}.bind(this);
/**
* Read key.
*
* @param {String} key
* @param {String} type
* @param {Function} rkCallback
*/
var ReadKey = function(key, type, rkCallback) {
var params = [ key ],
command = {
set: 'smembers',
zset: 'zrange',
list: 'lrange',
hash: 'hgetall'
}[ type ] || 'get';
if (command.indexOf('range') !== -1) {
params.push(0);
params.push(-1);
}
params.push(function(err, values) {
if (err) {
rkCallback(err);
return;
}
switch (type) {
case 'zset':
ReadScores(_.clone(values).reverse(), function(err, scores) {
rkCallback(null, _.zip(scores, values));
});
break;
default:
rkCallback(null, values);
break;
}
});
this.getClient()[ command ].apply(this.getClient(), params);
}.bind(this);
switch (this.getExportParams().type) {
// Export as redis type.
case 'redis':
return function(err, type) {
var type2PrintSetCommand = {
string: 'SET',
set: 'SADD',
zset: 'ZADD',
list: 'RPUSH',
hash: 'HSET'
};
if (!data) {
data = '';
}
ReadKey(key, type, function(err, value) {
if (err) {
callback(err);
return;
}
var command = type2PrintSetCommand[ type ];
key = key.trim();
switch (type) {
case 'set':
_.each(value, function(item) {
data += command + ' "' + key + '" "' + item + "\"\n";
});
break;
case 'zset':
_.each(value, function(item) {
data += command + ' "' + key + '" ' + item[0] + ' "' + item[1] + "\"\n";
});
break;
case 'hash':
_.each(_.pairs(value), function(item) {
data += command + ' "' + key + '" "' + item[0] + '" "' + item[1] + "\"\n";
});
break;
default:
data += command + ' "' + key + '" "' + value + "\"\n";
break;
}
callback(null, data);
});
};
// Export as json type.
case 'json':
return function(err, type) {
if (!data) {
data = {};
}
ReadKey(key, type, function(err, value) {
if (err) {
callback(err);
return;
}
switch (type) {
case 'zset':
var withoutScores = [];
_.each(value, function(item) {
withoutScores.push(item[1]);
});
value = withoutScores;
break;
}
data[ key.trim() ] = value;
callback(null, data);
});
};
}
} | [
"function",
"(",
"key",
",",
"data",
",",
"callback",
")",
"{",
"'use strict'",
";",
"var",
"ReadScores",
"=",
"function",
"(",
"values",
",",
"callback",
")",
"{",
"var",
"result",
"=",
"[",
"]",
";",
"var",
"GetRecursive",
"=",
"function",
"(",
")",
"{",
"if",
"(",
"!",
"values",
".",
"length",
")",
"{",
"callback",
"(",
"null",
",",
"result",
")",
";",
"return",
";",
"}",
"var",
"value",
"=",
"values",
".",
"pop",
"(",
")",
";",
"this",
".",
"getClient",
"(",
")",
".",
"zscore",
"(",
"key",
",",
"value",
",",
"function",
"(",
"err",
",",
"score",
")",
"{",
"if",
"(",
"err",
")",
"{",
"callback",
"(",
"err",
")",
";",
"return",
";",
"}",
"result",
".",
"push",
"(",
"score",
")",
";",
"GetRecursive",
"(",
")",
";",
"}",
")",
";",
"}",
".",
"bind",
"(",
"this",
")",
";",
"GetRecursive",
"(",
")",
";",
"}",
".",
"bind",
"(",
"this",
")",
";",
"var",
"ReadKey",
"=",
"function",
"(",
"key",
",",
"type",
",",
"rkCallback",
")",
"{",
"var",
"params",
"=",
"[",
"key",
"]",
",",
"command",
"=",
"{",
"set",
":",
"'smembers'",
",",
"zset",
":",
"'zrange'",
",",
"list",
":",
"'lrange'",
",",
"hash",
":",
"'hgetall'",
"}",
"[",
"type",
"]",
"||",
"'get'",
";",
"if",
"(",
"command",
".",
"indexOf",
"(",
"'range'",
")",
"!==",
"-",
"1",
")",
"{",
"params",
".",
"push",
"(",
"0",
")",
";",
"params",
".",
"push",
"(",
"-",
"1",
")",
";",
"}",
"params",
".",
"push",
"(",
"function",
"(",
"err",
",",
"values",
")",
"{",
"if",
"(",
"err",
")",
"{",
"rkCallback",
"(",
"err",
")",
";",
"return",
";",
"}",
"switch",
"(",
"type",
")",
"{",
"case",
"'zset'",
":",
"ReadScores",
"(",
"_",
".",
"clone",
"(",
"values",
")",
".",
"reverse",
"(",
")",
",",
"function",
"(",
"err",
",",
"scores",
")",
"{",
"rkCallback",
"(",
"null",
",",
"_",
".",
"zip",
"(",
"scores",
",",
"values",
")",
")",
";",
"}",
")",
";",
"break",
";",
"default",
":",
"rkCallback",
"(",
"null",
",",
"values",
")",
";",
"break",
";",
"}",
"}",
")",
";",
"this",
".",
"getClient",
"(",
")",
"[",
"command",
"]",
".",
"apply",
"(",
"this",
".",
"getClient",
"(",
")",
",",
"params",
")",
";",
"}",
".",
"bind",
"(",
"this",
")",
";",
"switch",
"(",
"this",
".",
"getExportParams",
"(",
")",
".",
"type",
")",
"{",
"case",
"'redis'",
":",
"return",
"function",
"(",
"err",
",",
"type",
")",
"{",
"var",
"type2PrintSetCommand",
"=",
"{",
"string",
":",
"'SET'",
",",
"set",
":",
"'SADD'",
",",
"zset",
":",
"'ZADD'",
",",
"list",
":",
"'RPUSH'",
",",
"hash",
":",
"'HSET'",
"}",
";",
"if",
"(",
"!",
"data",
")",
"{",
"data",
"=",
"''",
";",
"}",
"ReadKey",
"(",
"key",
",",
"type",
",",
"function",
"(",
"err",
",",
"value",
")",
"{",
"if",
"(",
"err",
")",
"{",
"callback",
"(",
"err",
")",
";",
"return",
";",
"}",
"var",
"command",
"=",
"type2PrintSetCommand",
"[",
"type",
"]",
";",
"key",
"=",
"key",
".",
"trim",
"(",
")",
";",
"switch",
"(",
"type",
")",
"{",
"case",
"'set'",
":",
"_",
".",
"each",
"(",
"value",
",",
"function",
"(",
"item",
")",
"{",
"data",
"+=",
"command",
"+",
"' \"'",
"+",
"key",
"+",
"'\" \"'",
"+",
"item",
"+",
"\"\\\"\\n\"",
";",
"}",
")",
";",
"\\\"",
"\\n",
"break",
";",
"case",
"'zset'",
":",
"_",
".",
"each",
"(",
"value",
",",
"function",
"(",
"item",
")",
"{",
"data",
"+=",
"command",
"+",
"' \"'",
"+",
"key",
"+",
"'\" '",
"+",
"item",
"[",
"0",
"]",
"+",
"' \"'",
"+",
"item",
"[",
"1",
"]",
"+",
"\"\\\"\\n\"",
";",
"}",
")",
";",
"\\\"",
"}",
"\\n",
"}",
")",
";",
"}",
";",
"break",
";",
"}",
"}"
]
| Read key callback by type. | [
"Read",
"key",
"callback",
"by",
"type",
"."
]
| 27f30b4c5a20f2a001e00d732d3c1d4ef67ddbad | https://github.com/EvilDevRu/node-redis-dump/blob/27f30b4c5a20f2a001e00d732d3c1d4ef67ddbad/lib/node-redis-dump.js#L61-L225 | train |
|
EvilDevRu/node-redis-dump | lib/node-redis-dump.js | function(err, status) {
if (err) {
callback(err);
return;
}
if (status || status === 'OK') {
report.inserted += _.isNumber(status) ? status : 1;
} else {
// Hm...
report.errors += 1;
}
AddRecursive();
} | javascript | function(err, status) {
if (err) {
callback(err);
return;
}
if (status || status === 'OK') {
report.inserted += _.isNumber(status) ? status : 1;
} else {
// Hm...
report.errors += 1;
}
AddRecursive();
} | [
"function",
"(",
"err",
",",
"status",
")",
"{",
"if",
"(",
"err",
")",
"{",
"callback",
"(",
"err",
")",
";",
"return",
";",
"}",
"if",
"(",
"status",
"||",
"status",
"===",
"'OK'",
")",
"{",
"report",
".",
"inserted",
"+=",
"_",
".",
"isNumber",
"(",
"status",
")",
"?",
"status",
":",
"1",
";",
"}",
"else",
"{",
"report",
".",
"errors",
"+=",
"1",
";",
"}",
"AddRecursive",
"(",
")",
";",
"}"
]
| Callback function. | [
"Callback",
"function",
"."
]
| 27f30b4c5a20f2a001e00d732d3c1d4ef67ddbad | https://github.com/EvilDevRu/node-redis-dump/blob/27f30b4c5a20f2a001e00d732d3c1d4ef67ddbad/lib/node-redis-dump.js#L374-L388 | train |
|
arhs/grunt-untar | tasks/untar.js | mustUnzip | function mustUnzip(file, mode){
if (mode){
return mode === 'tgz';
}
var extension = path.extname(file);
return contains(['.tgz', '.gz'], extension);
} | javascript | function mustUnzip(file, mode){
if (mode){
return mode === 'tgz';
}
var extension = path.extname(file);
return contains(['.tgz', '.gz'], extension);
} | [
"function",
"mustUnzip",
"(",
"file",
",",
"mode",
")",
"{",
"if",
"(",
"mode",
")",
"{",
"return",
"mode",
"===",
"'tgz'",
";",
"}",
"var",
"extension",
"=",
"path",
".",
"extname",
"(",
"file",
")",
";",
"return",
"contains",
"(",
"[",
"'.tgz'",
",",
"'.gz'",
"]",
",",
"extension",
")",
";",
"}"
]
| Return true if the processed file must be unzipped.
Check the mode and default to analyzing the file extension.
@param file the processed file
@param [mode] the mode
@returns {Boolean} true if the file must be unzipped | [
"Return",
"true",
"if",
"the",
"processed",
"file",
"must",
"be",
"unzipped",
".",
"Check",
"the",
"mode",
"and",
"default",
"to",
"analyzing",
"the",
"file",
"extension",
"."
]
| 092fd0b1c9d9c864c6a905cfa616b0439df39214 | https://github.com/arhs/grunt-untar/blob/092fd0b1c9d9c864c6a905cfa616b0439df39214/tasks/untar.js#L21-L27 | train |
ofzza/enTT | src/ext/dynamic-properties.js | isDynamicProperty | function isDynamicProperty (propertyConfiguration) {
return propertyConfiguration
// Is defined as dynamic
&& propertyConfiguration.dynamic
// Dynamic option value is a function
&& _.isFunction(propertyConfiguration.dynamic)
// Dynamic option value is not a EnTT class
&& (propertyConfiguration.dynamic !== EnTT);
} | javascript | function isDynamicProperty (propertyConfiguration) {
return propertyConfiguration
// Is defined as dynamic
&& propertyConfiguration.dynamic
// Dynamic option value is a function
&& _.isFunction(propertyConfiguration.dynamic)
// Dynamic option value is not a EnTT class
&& (propertyConfiguration.dynamic !== EnTT);
} | [
"function",
"isDynamicProperty",
"(",
"propertyConfiguration",
")",
"{",
"return",
"propertyConfiguration",
"&&",
"propertyConfiguration",
".",
"dynamic",
"&&",
"_",
".",
"isFunction",
"(",
"propertyConfiguration",
".",
"dynamic",
")",
"&&",
"(",
"propertyConfiguration",
".",
"dynamic",
"!==",
"EnTT",
")",
";",
"}"
]
| Checks if property is defined as a dynamic property
@param {any} propertyConfiguration Property configuration
@returns {bool} If property is defined as a dynamic property | [
"Checks",
"if",
"property",
"is",
"defined",
"as",
"a",
"dynamic",
"property"
]
| fdf27de4142b3c65a3e51dee70e0d7625dff897c | https://github.com/ofzza/enTT/blob/fdf27de4142b3c65a3e51dee70e0d7625dff897c/src/ext/dynamic-properties.js#L114-L122 | train |
alexcjohnson/world-calendars | jquery-src/jquery.calendars.js | function(name, language) {
name = (name || 'gregorian').toLowerCase();
language = language || '';
var cal = this._localCals[name + '-' + language];
if (!cal && this.calendars[name]) {
cal = new this.calendars[name](language);
this._localCals[name + '-' + language] = cal;
}
if (!cal) {
throw (this.local.invalidCalendar || this.regionalOptions[''].invalidCalendar).
replace(/\{0\}/, name);
}
return cal;
} | javascript | function(name, language) {
name = (name || 'gregorian').toLowerCase();
language = language || '';
var cal = this._localCals[name + '-' + language];
if (!cal && this.calendars[name]) {
cal = new this.calendars[name](language);
this._localCals[name + '-' + language] = cal;
}
if (!cal) {
throw (this.local.invalidCalendar || this.regionalOptions[''].invalidCalendar).
replace(/\{0\}/, name);
}
return cal;
} | [
"function",
"(",
"name",
",",
"language",
")",
"{",
"name",
"=",
"(",
"name",
"||",
"'gregorian'",
")",
".",
"toLowerCase",
"(",
")",
";",
"language",
"=",
"language",
"||",
"''",
";",
"var",
"cal",
"=",
"this",
".",
"_localCals",
"[",
"name",
"+",
"'-'",
"+",
"language",
"]",
";",
"if",
"(",
"!",
"cal",
"&&",
"this",
".",
"calendars",
"[",
"name",
"]",
")",
"{",
"cal",
"=",
"new",
"this",
".",
"calendars",
"[",
"name",
"]",
"(",
"language",
")",
";",
"this",
".",
"_localCals",
"[",
"name",
"+",
"'-'",
"+",
"language",
"]",
"=",
"cal",
";",
"}",
"if",
"(",
"!",
"cal",
")",
"{",
"throw",
"(",
"this",
".",
"local",
".",
"invalidCalendar",
"||",
"this",
".",
"regionalOptions",
"[",
"''",
"]",
".",
"invalidCalendar",
")",
".",
"replace",
"(",
"/",
"\\{0\\}",
"/",
",",
"name",
")",
";",
"}",
"return",
"cal",
";",
"}"
]
| Obtain a calendar implementation and localisation.
@memberof Calendars
@param [name='gregorian'] {string} The name of the calendar, e.g. 'gregorian', 'persian', 'islamic'.
@param [language=''] {string} The language code to use for localisation (default is English).
@return {Calendar} The calendar and localisation.
@throws Error if calendar not found. | [
"Obtain",
"a",
"calendar",
"implementation",
"and",
"localisation",
"."
]
| 810693882512dec1b804456f8d435b962bd6cf31 | https://github.com/alexcjohnson/world-calendars/blob/810693882512dec1b804456f8d435b962bd6cf31/jquery-src/jquery.calendars.js#L35-L48 | train |
|
alexcjohnson/world-calendars | jquery-src/jquery.calendars.js | function(year, month, day, calendar, language) {
calendar = (year != null && year.year ? year.calendar() : (typeof calendar === 'string' ?
this.instance(calendar, language) : calendar)) || this.instance();
return calendar.newDate(year, month, day);
} | javascript | function(year, month, day, calendar, language) {
calendar = (year != null && year.year ? year.calendar() : (typeof calendar === 'string' ?
this.instance(calendar, language) : calendar)) || this.instance();
return calendar.newDate(year, month, day);
} | [
"function",
"(",
"year",
",",
"month",
",",
"day",
",",
"calendar",
",",
"language",
")",
"{",
"calendar",
"=",
"(",
"year",
"!=",
"null",
"&&",
"year",
".",
"year",
"?",
"year",
".",
"calendar",
"(",
")",
":",
"(",
"typeof",
"calendar",
"===",
"'string'",
"?",
"this",
".",
"instance",
"(",
"calendar",
",",
"language",
")",
":",
"calendar",
")",
")",
"||",
"this",
".",
"instance",
"(",
")",
";",
"return",
"calendar",
".",
"newDate",
"(",
"year",
",",
"month",
",",
"day",
")",
";",
"}"
]
| Create a new date - for today if no other parameters given.
@memberof Calendars
@param year {CDate|number} The date to copy or the year for the date.
@param [month] {number} The month for the date.
@param [day] {number} The day for the date.
@param [calendar='gregorian'] {BaseCalendar|string} The underlying calendar or the name of the calendar.
@param [language=''] {string} The language to use for localisation (default English).
@return {CDate} The new date.
@throws Error if an invalid date. | [
"Create",
"a",
"new",
"date",
"-",
"for",
"today",
"if",
"no",
"other",
"parameters",
"given",
"."
]
| 810693882512dec1b804456f8d435b962bd6cf31 | https://github.com/alexcjohnson/world-calendars/blob/810693882512dec1b804456f8d435b962bd6cf31/jquery-src/jquery.calendars.js#L59-L63 | train |
|
alexcjohnson/world-calendars | jquery-src/jquery.calendars.js | function(digits, powers) {
return function(value) {
var localNumber = '';
var power = 0;
while (value > 0) {
var units = value % 10;
localNumber = (units === 0 ? '' : digits[units] + powers[power]) + localNumber;
power++;
value = Math.floor(value / 10);
}
if (localNumber.indexOf(digits[1] + powers[1]) === 0) {
localNumber = localNumber.substr(1);
}
return localNumber || digits[0];
}
} | javascript | function(digits, powers) {
return function(value) {
var localNumber = '';
var power = 0;
while (value > 0) {
var units = value % 10;
localNumber = (units === 0 ? '' : digits[units] + powers[power]) + localNumber;
power++;
value = Math.floor(value / 10);
}
if (localNumber.indexOf(digits[1] + powers[1]) === 0) {
localNumber = localNumber.substr(1);
}
return localNumber || digits[0];
}
} | [
"function",
"(",
"digits",
",",
"powers",
")",
"{",
"return",
"function",
"(",
"value",
")",
"{",
"var",
"localNumber",
"=",
"''",
";",
"var",
"power",
"=",
"0",
";",
"while",
"(",
"value",
">",
"0",
")",
"{",
"var",
"units",
"=",
"value",
"%",
"10",
";",
"localNumber",
"=",
"(",
"units",
"===",
"0",
"?",
"''",
":",
"digits",
"[",
"units",
"]",
"+",
"powers",
"[",
"power",
"]",
")",
"+",
"localNumber",
";",
"power",
"++",
";",
"value",
"=",
"Math",
".",
"floor",
"(",
"value",
"/",
"10",
")",
";",
"}",
"if",
"(",
"localNumber",
".",
"indexOf",
"(",
"digits",
"[",
"1",
"]",
"+",
"powers",
"[",
"1",
"]",
")",
"===",
"0",
")",
"{",
"localNumber",
"=",
"localNumber",
".",
"substr",
"(",
"1",
")",
";",
"}",
"return",
"localNumber",
"||",
"digits",
"[",
"0",
"]",
";",
"}",
"}"
]
| Digit substitution function for localising Chinese style numbers via the Calendar digits option.
@member Calendars
@param digits {string[]} The substitute digits, for 0 through 9.
@param powers {string[]} The characters denoting powers of 10, i.e. 1, 10, 100, 1000.
@return {function} The substitution function. | [
"Digit",
"substitution",
"function",
"for",
"localising",
"Chinese",
"style",
"numbers",
"via",
"the",
"Calendar",
"digits",
"option",
"."
]
| 810693882512dec1b804456f8d435b962bd6cf31 | https://github.com/alexcjohnson/world-calendars/blob/810693882512dec1b804456f8d435b962bd6cf31/jquery-src/jquery.calendars.js#L82-L97 | train |
|
alexcjohnson/world-calendars | jquery-src/jquery.calendars.js | CDate | function CDate(calendar, year, month, day) {
this._calendar = calendar;
this._year = year;
this._month = month;
this._day = day;
if (this._calendar._validateLevel === 0 &&
!this._calendar.isValid(this._year, this._month, this._day)) {
throw ($.calendars.local.invalidDate || $.calendars.regionalOptions[''].invalidDate).
replace(/\{0\}/, this._calendar.local.name);
}
} | javascript | function CDate(calendar, year, month, day) {
this._calendar = calendar;
this._year = year;
this._month = month;
this._day = day;
if (this._calendar._validateLevel === 0 &&
!this._calendar.isValid(this._year, this._month, this._day)) {
throw ($.calendars.local.invalidDate || $.calendars.regionalOptions[''].invalidDate).
replace(/\{0\}/, this._calendar.local.name);
}
} | [
"function",
"CDate",
"(",
"calendar",
",",
"year",
",",
"month",
",",
"day",
")",
"{",
"this",
".",
"_calendar",
"=",
"calendar",
";",
"this",
".",
"_year",
"=",
"year",
";",
"this",
".",
"_month",
"=",
"month",
";",
"this",
".",
"_day",
"=",
"day",
";",
"if",
"(",
"this",
".",
"_calendar",
".",
"_validateLevel",
"===",
"0",
"&&",
"!",
"this",
".",
"_calendar",
".",
"isValid",
"(",
"this",
".",
"_year",
",",
"this",
".",
"_month",
",",
"this",
".",
"_day",
")",
")",
"{",
"throw",
"(",
"$",
".",
"calendars",
".",
"local",
".",
"invalidDate",
"||",
"$",
".",
"calendars",
".",
"regionalOptions",
"[",
"''",
"]",
".",
"invalidDate",
")",
".",
"replace",
"(",
"/",
"\\{0\\}",
"/",
",",
"this",
".",
"_calendar",
".",
"local",
".",
"name",
")",
";",
"}",
"}"
]
| Generic date, based on a particular calendar.
@class CDate
@param calendar {BaseCalendar} The underlying calendar implementation.
@param year {number} The year for this date.
@param month {number} The month for this date.
@param day {number} The day for this date.
@return {CDate} The date object.
@throws Error if an invalid date. | [
"Generic",
"date",
"based",
"on",
"a",
"particular",
"calendar",
"."
]
| 810693882512dec1b804456f8d435b962bd6cf31 | https://github.com/alexcjohnson/world-calendars/blob/810693882512dec1b804456f8d435b962bd6cf31/jquery-src/jquery.calendars.js#L108-L118 | train |
alexcjohnson/world-calendars | jquery-src/jquery.calendars.js | pad | function pad(value, length) {
value = '' + value;
return '000000'.substring(0, length - value.length) + value;
} | javascript | function pad(value, length) {
value = '' + value;
return '000000'.substring(0, length - value.length) + value;
} | [
"function",
"pad",
"(",
"value",
",",
"length",
")",
"{",
"value",
"=",
"''",
"+",
"value",
";",
"return",
"'000000'",
".",
"substring",
"(",
"0",
",",
"length",
"-",
"value",
".",
"length",
")",
"+",
"value",
";",
"}"
]
| Pad a numeric value with leading zeroes.
@private
@param value {number} The number to format.
@param length {number} The minimum length.
@return {string} The formatted number. | [
"Pad",
"a",
"numeric",
"value",
"with",
"leading",
"zeroes",
"."
]
| 810693882512dec1b804456f8d435b962bd6cf31 | https://github.com/alexcjohnson/world-calendars/blob/810693882512dec1b804456f8d435b962bd6cf31/jquery-src/jquery.calendars.js#L125-L128 | train |
alexcjohnson/world-calendars | jquery-src/jquery.calendars.js | function(year, month, day) {
return this._calendar.newDate((year == null ? this : year), month, day);
} | javascript | function(year, month, day) {
return this._calendar.newDate((year == null ? this : year), month, day);
} | [
"function",
"(",
"year",
",",
"month",
",",
"day",
")",
"{",
"return",
"this",
".",
"_calendar",
".",
"newDate",
"(",
"(",
"year",
"==",
"null",
"?",
"this",
":",
"year",
")",
",",
"month",
",",
"day",
")",
";",
"}"
]
| Create a new date.
@memberof CDate
@param [year] {CDate|number} The date to copy or the year for the date (default this date).
@param [month] {number} The month for the date.
@param [day] {number} The day for the date.
@return {CDate} The new date.
@throws Error if an invalid date. | [
"Create",
"a",
"new",
"date",
"."
]
| 810693882512dec1b804456f8d435b962bd6cf31 | https://github.com/alexcjohnson/world-calendars/blob/810693882512dec1b804456f8d435b962bd6cf31/jquery-src/jquery.calendars.js#L139-L141 | train |
|
alexcjohnson/world-calendars | jquery-src/jquery.calendars.js | function(year, month, day) {
if (!this._calendar.isValid(year, month, day)) {
throw ($.calendars.local.invalidDate || $.calendars.regionalOptions[''].invalidDate).
replace(/\{0\}/, this._calendar.local.name);
}
this._year = year;
this._month = month;
this._day = day;
return this;
} | javascript | function(year, month, day) {
if (!this._calendar.isValid(year, month, day)) {
throw ($.calendars.local.invalidDate || $.calendars.regionalOptions[''].invalidDate).
replace(/\{0\}/, this._calendar.local.name);
}
this._year = year;
this._month = month;
this._day = day;
return this;
} | [
"function",
"(",
"year",
",",
"month",
",",
"day",
")",
"{",
"if",
"(",
"!",
"this",
".",
"_calendar",
".",
"isValid",
"(",
"year",
",",
"month",
",",
"day",
")",
")",
"{",
"throw",
"(",
"$",
".",
"calendars",
".",
"local",
".",
"invalidDate",
"||",
"$",
".",
"calendars",
".",
"regionalOptions",
"[",
"''",
"]",
".",
"invalidDate",
")",
".",
"replace",
"(",
"/",
"\\{0\\}",
"/",
",",
"this",
".",
"_calendar",
".",
"local",
".",
"name",
")",
";",
"}",
"this",
".",
"_year",
"=",
"year",
";",
"this",
".",
"_month",
"=",
"month",
";",
"this",
".",
"_day",
"=",
"day",
";",
"return",
"this",
";",
"}"
]
| Set new values for this date.
@memberof CDate
@param year {number} The year for the date.
@param month {number} The month for the date.
@param day {number} The day for the date.
@return {CDate} The updated date.
@throws Error if an invalid date. | [
"Set",
"new",
"values",
"for",
"this",
"date",
"."
]
| 810693882512dec1b804456f8d435b962bd6cf31 | https://github.com/alexcjohnson/world-calendars/blob/810693882512dec1b804456f8d435b962bd6cf31/jquery-src/jquery.calendars.js#L177-L186 | train |
|
alexcjohnson/world-calendars | jquery-src/jquery.calendars.js | function(year) {
var date = this._validate(year, this.minMonth, this.minDay,
$.calendars.local.invalidYear || $.calendars.regionalOptions[''].invalidYear);
return (date.year() < 0 ? this.local.epochs[0] : this.local.epochs[1]);
} | javascript | function(year) {
var date = this._validate(year, this.minMonth, this.minDay,
$.calendars.local.invalidYear || $.calendars.regionalOptions[''].invalidYear);
return (date.year() < 0 ? this.local.epochs[0] : this.local.epochs[1]);
} | [
"function",
"(",
"year",
")",
"{",
"var",
"date",
"=",
"this",
".",
"_validate",
"(",
"year",
",",
"this",
".",
"minMonth",
",",
"this",
".",
"minDay",
",",
"$",
".",
"calendars",
".",
"local",
".",
"invalidYear",
"||",
"$",
".",
"calendars",
".",
"regionalOptions",
"[",
"''",
"]",
".",
"invalidYear",
")",
";",
"return",
"(",
"date",
".",
"year",
"(",
")",
"<",
"0",
"?",
"this",
".",
"local",
".",
"epochs",
"[",
"0",
"]",
":",
"this",
".",
"local",
".",
"epochs",
"[",
"1",
"]",
")",
";",
"}"
]
| Retrieve the epoch designator for this date.
@memberof BaseCalendar
@param year {CDate|number} The date to examine or the year to examine.
@return {string} The current epoch.
@throws Error if an invalid year or a different calendar used. | [
"Retrieve",
"the",
"epoch",
"designator",
"for",
"this",
"date",
"."
]
| 810693882512dec1b804456f8d435b962bd6cf31 | https://github.com/alexcjohnson/world-calendars/blob/810693882512dec1b804456f8d435b962bd6cf31/jquery-src/jquery.calendars.js#L392-L396 | train |
|
alexcjohnson/world-calendars | jquery-src/jquery.calendars.js | function(year, month) {
var date = this._validate(year, month, this.minDay,
$.calendars.local.invalidMonth || $.calendars.regionalOptions[''].invalidMonth);
return (date.month() + this.monthsInYear(date) - this.firstMonth) %
this.monthsInYear(date) + this.minMonth;
} | javascript | function(year, month) {
var date = this._validate(year, month, this.minDay,
$.calendars.local.invalidMonth || $.calendars.regionalOptions[''].invalidMonth);
return (date.month() + this.monthsInYear(date) - this.firstMonth) %
this.monthsInYear(date) + this.minMonth;
} | [
"function",
"(",
"year",
",",
"month",
")",
"{",
"var",
"date",
"=",
"this",
".",
"_validate",
"(",
"year",
",",
"month",
",",
"this",
".",
"minDay",
",",
"$",
".",
"calendars",
".",
"local",
".",
"invalidMonth",
"||",
"$",
".",
"calendars",
".",
"regionalOptions",
"[",
"''",
"]",
".",
"invalidMonth",
")",
";",
"return",
"(",
"date",
".",
"month",
"(",
")",
"+",
"this",
".",
"monthsInYear",
"(",
"date",
")",
"-",
"this",
".",
"firstMonth",
")",
"%",
"this",
".",
"monthsInYear",
"(",
"date",
")",
"+",
"this",
".",
"minMonth",
";",
"}"
]
| Calculate the month's ordinal position within the year -
for those calendars that don't start at month 1!
@memberof BaseCalendar
@param year {CDate|number} The date to examine or the year to examine.
@param month {number} The month to examine.
@return {number} The ordinal position, starting from <code>minMonth</code>.
@throws Error if an invalid year/month or a different calendar used. | [
"Calculate",
"the",
"month",
"s",
"ordinal",
"position",
"within",
"the",
"year",
"-",
"for",
"those",
"calendars",
"that",
"don",
"t",
"start",
"at",
"month",
"1!"
]
| 810693882512dec1b804456f8d435b962bd6cf31 | https://github.com/alexcjohnson/world-calendars/blob/810693882512dec1b804456f8d435b962bd6cf31/jquery-src/jquery.calendars.js#L427-L432 | train |
|
dominictarr/lossy-store | store.js | apply_write | function apply_write (key, value, err) {
var _reading = reading[key]
reading[key] = null
while(_reading && _reading.length)
_reading.shift()(err, value)
_write()
} | javascript | function apply_write (key, value, err) {
var _reading = reading[key]
reading[key] = null
while(_reading && _reading.length)
_reading.shift()(err, value)
_write()
} | [
"function",
"apply_write",
"(",
"key",
",",
"value",
",",
"err",
")",
"{",
"var",
"_reading",
"=",
"reading",
"[",
"key",
"]",
"reading",
"[",
"key",
"]",
"=",
"null",
"while",
"(",
"_reading",
"&&",
"_reading",
".",
"length",
")",
"_reading",
".",
"shift",
"(",
")",
"(",
"err",
",",
"value",
")",
"_write",
"(",
")",
"}"
]
| this writes only once at a time. at least, we want it to write at most once per file. or maybe if it's written recently then wait. anyway, this is good enough for now. | [
"this",
"writes",
"only",
"once",
"at",
"a",
"time",
".",
"at",
"least",
"we",
"want",
"it",
"to",
"write",
"at",
"most",
"once",
"per",
"file",
".",
"or",
"maybe",
"if",
"it",
"s",
"written",
"recently",
"then",
"wait",
".",
"anyway",
"this",
"is",
"good",
"enough",
"for",
"now",
"."
]
| 713fadc62c730b8dfd15547dafde9c683424e7da | https://github.com/dominictarr/lossy-store/blob/713fadc62c730b8dfd15547dafde9c683424e7da/store.js#L15-L21 | train |
dominictarr/lossy-store | store.js | function (key, value) {
store[key] = value
//not urgent, but save this if we are not doing anything.
dirty[key] = true
apply_write(key, value)
} | javascript | function (key, value) {
store[key] = value
//not urgent, but save this if we are not doing anything.
dirty[key] = true
apply_write(key, value)
} | [
"function",
"(",
"key",
",",
"value",
")",
"{",
"store",
"[",
"key",
"]",
"=",
"value",
"dirty",
"[",
"key",
"]",
"=",
"true",
"apply_write",
"(",
"key",
",",
"value",
")",
"}"
]
| if set is called during a read, cb the readers immediately, and cancel the current read. | [
"if",
"set",
"is",
"called",
"during",
"a",
"read",
"cb",
"the",
"readers",
"immediately",
"and",
"cancel",
"the",
"current",
"read",
"."
]
| 713fadc62c730b8dfd15547dafde9c683424e7da | https://github.com/dominictarr/lossy-store/blob/713fadc62c730b8dfd15547dafde9c683424e7da/store.js#L71-L76 | train |
|
i0null/node-lgtv-2012 | index.js | send_commands | function send_commands(cmds, cb) {
function callback(value) {
if (cb) cb(value)
this.locked = false
}
function run() {
if (this.locked = cmds.length > 0) send_command(cmds.shift(), (success) => {
if (success) setTimeout(run, 200);
else callback(false);
});
else callback(true);
};
if(!this.locked) run();
} | javascript | function send_commands(cmds, cb) {
function callback(value) {
if (cb) cb(value)
this.locked = false
}
function run() {
if (this.locked = cmds.length > 0) send_command(cmds.shift(), (success) => {
if (success) setTimeout(run, 200);
else callback(false);
});
else callback(true);
};
if(!this.locked) run();
} | [
"function",
"send_commands",
"(",
"cmds",
",",
"cb",
")",
"{",
"function",
"callback",
"(",
"value",
")",
"{",
"if",
"(",
"cb",
")",
"cb",
"(",
"value",
")",
"this",
".",
"locked",
"=",
"false",
"}",
"function",
"run",
"(",
")",
"{",
"if",
"(",
"this",
".",
"locked",
"=",
"cmds",
".",
"length",
">",
"0",
")",
"send_command",
"(",
"cmds",
".",
"shift",
"(",
")",
",",
"(",
"success",
")",
"=>",
"{",
"if",
"(",
"success",
")",
"setTimeout",
"(",
"run",
",",
"200",
")",
";",
"else",
"callback",
"(",
"false",
")",
";",
"}",
")",
";",
"else",
"callback",
"(",
"true",
")",
";",
"}",
";",
"if",
"(",
"!",
"this",
".",
"locked",
")",
"run",
"(",
")",
";",
"}"
]
| Send Multiple Commands | [
"Send",
"Multiple",
"Commands"
]
| a579c7d6024c309575c43adc81c7b64d748692ee | https://github.com/i0null/node-lgtv-2012/blob/a579c7d6024c309575c43adc81c7b64d748692ee/index.js#L130-L143 | train |
CumberlandGroup/node-spark | lib/spark.js | getDefPath | function getDefPath(defPath) {
// if path passed...
if(defPath) {
// if not url and not absolute...
if(!/^https?:/.test(defPath) && !path.isAbsolute(defPath)) {
// normalize path as relative to folder containing node_modules
return path.normalize(path.join(__dirname, '/../../../', defPath));
}
// else, return unchanged...
else {
return defPath;
}
}
// else, return defualt path...
else {
return path.normalize(path.join(__dirname, _swaggerDef));
}
} | javascript | function getDefPath(defPath) {
// if path passed...
if(defPath) {
// if not url and not absolute...
if(!/^https?:/.test(defPath) && !path.isAbsolute(defPath)) {
// normalize path as relative to folder containing node_modules
return path.normalize(path.join(__dirname, '/../../../', defPath));
}
// else, return unchanged...
else {
return defPath;
}
}
// else, return defualt path...
else {
return path.normalize(path.join(__dirname, _swaggerDef));
}
} | [
"function",
"getDefPath",
"(",
"defPath",
")",
"{",
"if",
"(",
"defPath",
")",
"{",
"if",
"(",
"!",
"/",
"^https?:",
"/",
".",
"test",
"(",
"defPath",
")",
"&&",
"!",
"path",
".",
"isAbsolute",
"(",
"defPath",
")",
")",
"{",
"return",
"path",
".",
"normalize",
"(",
"path",
".",
"join",
"(",
"__dirname",
",",
"'/../../../'",
",",
"defPath",
")",
")",
";",
"}",
"else",
"{",
"return",
"defPath",
";",
"}",
"}",
"else",
"{",
"return",
"path",
".",
"normalize",
"(",
"path",
".",
"join",
"(",
"__dirname",
",",
"_swaggerDef",
")",
")",
";",
"}",
"}"
]
| get full path for spark swagger definition file | [
"get",
"full",
"path",
"for",
"spark",
"swagger",
"definition",
"file"
]
| dc4a50c5ba487af56173ac8316d8dc6a87dccd32 | https://github.com/CumberlandGroup/node-spark/blob/dc4a50c5ba487af56173ac8316d8dc6a87dccd32/lib/spark.js#L21-L40 | train |
rochars/bitdepth | index.js | truncateSamples | function truncateSamples(samples) {
/** @type {number} */
let len = samples.length;
for (let i=0; i<len; i++) {
if (samples[i] > 1) {
samples[i] = 1;
} else if (samples[i] < -1) {
samples[i] = -1;
}
}
} | javascript | function truncateSamples(samples) {
/** @type {number} */
let len = samples.length;
for (let i=0; i<len; i++) {
if (samples[i] > 1) {
samples[i] = 1;
} else if (samples[i] < -1) {
samples[i] = -1;
}
}
} | [
"function",
"truncateSamples",
"(",
"samples",
")",
"{",
"let",
"len",
"=",
"samples",
".",
"length",
";",
"for",
"(",
"let",
"i",
"=",
"0",
";",
"i",
"<",
"len",
";",
"i",
"++",
")",
"{",
"if",
"(",
"samples",
"[",
"i",
"]",
">",
"1",
")",
"{",
"samples",
"[",
"i",
"]",
"=",
"1",
";",
"}",
"else",
"if",
"(",
"samples",
"[",
"i",
"]",
"<",
"-",
"1",
")",
"{",
"samples",
"[",
"i",
"]",
"=",
"-",
"1",
";",
"}",
"}",
"}"
]
| Truncate float samples on over and underflow.
@private | [
"Truncate",
"float",
"samples",
"on",
"over",
"and",
"underflow",
"."
]
| 19921a297bc254ce80c90c793db99e40ad105385 | https://github.com/rochars/bitdepth/blob/19921a297bc254ce80c90c793db99e40ad105385/index.js#L179-L189 | train |
fex-team/fis-prepackager-auto-pack | lib/request-sync.js | Response | function Response(statusCode, headers, body) {
this.statusCode = statusCode;
this.headers = {};
for (var key in headers) {
this.headers[key.toLowerCase()] = headers[key];
}
this.body = body;
} | javascript | function Response(statusCode, headers, body) {
this.statusCode = statusCode;
this.headers = {};
for (var key in headers) {
this.headers[key.toLowerCase()] = headers[key];
}
this.body = body;
} | [
"function",
"Response",
"(",
"statusCode",
",",
"headers",
",",
"body",
")",
"{",
"this",
".",
"statusCode",
"=",
"statusCode",
";",
"this",
".",
"headers",
"=",
"{",
"}",
";",
"for",
"(",
"var",
"key",
"in",
"headers",
")",
"{",
"this",
".",
"headers",
"[",
"key",
".",
"toLowerCase",
"(",
")",
"]",
"=",
"headers",
"[",
"key",
"]",
";",
"}",
"this",
".",
"body",
"=",
"body",
";",
"}"
]
| A response from a web request
@param {Number} statusCode
@param {Object} headers
@param {Buffer} body | [
"A",
"response",
"from",
"a",
"web",
"request"
]
| 4b45a5cfa6741fbe287d5e664f7dff129015c41b | https://github.com/fex-team/fis-prepackager-auto-pack/blob/4b45a5cfa6741fbe287d5e664f7dff129015c41b/lib/request-sync.js#L159-L166 | train |
alchemy-fr/Phraseanet-common | src/components/vendors/contextMenu.js | function (menu, cmenu) {
var className = cmenu.className;
$.each(cmenu.theme.split(","), function (i, n) {
className += ' ' + cmenu.themePrefix + n;
});
// var $t = $('<div style="background-color:#ffff00; xwidth:200px; height:200px"><table style="" cellspacing=0 cellpadding=0></table></div>').click(function(){cmenu.hide(); return false;}); // We wrap a table around it so width can be flexible
var $t = $('<table style="" cellspacing="0" cellpadding="0"></table>').click(function () {
cmenu.hide();
return false;
}); // We wrap a table around it so width can be flexible
var $tr = $('<tr></tr>');
var $td = $('<td></td>');
var $div = cmenu._div = $('<div class="' + className + '"></div>');
cmenu._div.hover(
function () {
if (cmenu.closeTimer) {
clearTimeout(cmenu.closeTimer);
cmenu.closeTimer = null;
}
},
function () {
var myClass = cmenu;
function timerRelay() {
myClass.hide();
}
myClass.closeTimer = setTimeout(timerRelay, 500);
}
);
// Each menu item is specified as either:
// title:function
// or title: { property:value ... }
/*
for (var i=0; i<menu.length; i++) {
var m = menu[i];
if (m==$.contextMenu.separator) {
$div.append(cmenu.createSeparator());
}
else {
for (var opt in menu[i]) {
$div.append(cmenu.createMenuItem(opt,menu[i][opt])); // Extracted to method for extensibility
}
}
}
*/
for (var i = 0; i < menu.length; i++) {
var m = menu[i];
if (m === $.contextMenu.separator) {
$div.append(cmenu.createSeparator());
}
else {
$div.append(cmenu.createMenuItem(m)); // Extracted to method for extensibility
}
}
if (cmenu.useIframe) {
$td.append(cmenu.createIframe());
}
$t.append($tr.append($td.append($div)));
return $t;
} | javascript | function (menu, cmenu) {
var className = cmenu.className;
$.each(cmenu.theme.split(","), function (i, n) {
className += ' ' + cmenu.themePrefix + n;
});
// var $t = $('<div style="background-color:#ffff00; xwidth:200px; height:200px"><table style="" cellspacing=0 cellpadding=0></table></div>').click(function(){cmenu.hide(); return false;}); // We wrap a table around it so width can be flexible
var $t = $('<table style="" cellspacing="0" cellpadding="0"></table>').click(function () {
cmenu.hide();
return false;
}); // We wrap a table around it so width can be flexible
var $tr = $('<tr></tr>');
var $td = $('<td></td>');
var $div = cmenu._div = $('<div class="' + className + '"></div>');
cmenu._div.hover(
function () {
if (cmenu.closeTimer) {
clearTimeout(cmenu.closeTimer);
cmenu.closeTimer = null;
}
},
function () {
var myClass = cmenu;
function timerRelay() {
myClass.hide();
}
myClass.closeTimer = setTimeout(timerRelay, 500);
}
);
// Each menu item is specified as either:
// title:function
// or title: { property:value ... }
/*
for (var i=0; i<menu.length; i++) {
var m = menu[i];
if (m==$.contextMenu.separator) {
$div.append(cmenu.createSeparator());
}
else {
for (var opt in menu[i]) {
$div.append(cmenu.createMenuItem(opt,menu[i][opt])); // Extracted to method for extensibility
}
}
}
*/
for (var i = 0; i < menu.length; i++) {
var m = menu[i];
if (m === $.contextMenu.separator) {
$div.append(cmenu.createSeparator());
}
else {
$div.append(cmenu.createMenuItem(m)); // Extracted to method for extensibility
}
}
if (cmenu.useIframe) {
$td.append(cmenu.createIframe());
}
$t.append($tr.append($td.append($div)));
return $t;
} | [
"function",
"(",
"menu",
",",
"cmenu",
")",
"{",
"var",
"className",
"=",
"cmenu",
".",
"className",
";",
"$",
".",
"each",
"(",
"cmenu",
".",
"theme",
".",
"split",
"(",
"\",\"",
")",
",",
"function",
"(",
"i",
",",
"n",
")",
"{",
"className",
"+=",
"' '",
"+",
"cmenu",
".",
"themePrefix",
"+",
"n",
";",
"}",
")",
";",
"var",
"$t",
"=",
"$",
"(",
"'<table style=\"\" cellspacing=\"0\" cellpadding=\"0\"></table>'",
")",
".",
"click",
"(",
"function",
"(",
")",
"{",
"cmenu",
".",
"hide",
"(",
")",
";",
"return",
"false",
";",
"}",
")",
";",
"var",
"$tr",
"=",
"$",
"(",
"'<tr></tr>'",
")",
";",
"var",
"$td",
"=",
"$",
"(",
"'<td></td>'",
")",
";",
"var",
"$div",
"=",
"cmenu",
".",
"_div",
"=",
"$",
"(",
"'<div class=\"'",
"+",
"className",
"+",
"'\"></div>'",
")",
";",
"cmenu",
".",
"_div",
".",
"hover",
"(",
"function",
"(",
")",
"{",
"if",
"(",
"cmenu",
".",
"closeTimer",
")",
"{",
"clearTimeout",
"(",
"cmenu",
".",
"closeTimer",
")",
";",
"cmenu",
".",
"closeTimer",
"=",
"null",
";",
"}",
"}",
",",
"function",
"(",
")",
"{",
"var",
"myClass",
"=",
"cmenu",
";",
"function",
"timerRelay",
"(",
")",
"{",
"myClass",
".",
"hide",
"(",
")",
";",
"}",
"myClass",
".",
"closeTimer",
"=",
"setTimeout",
"(",
"timerRelay",
",",
"500",
")",
";",
"}",
")",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"menu",
".",
"length",
";",
"i",
"++",
")",
"{",
"var",
"m",
"=",
"menu",
"[",
"i",
"]",
";",
"if",
"(",
"m",
"===",
"$",
".",
"contextMenu",
".",
"separator",
")",
"{",
"$div",
".",
"append",
"(",
"cmenu",
".",
"createSeparator",
"(",
")",
")",
";",
"}",
"else",
"{",
"$div",
".",
"append",
"(",
"cmenu",
".",
"createMenuItem",
"(",
"m",
")",
")",
";",
"}",
"}",
"if",
"(",
"cmenu",
".",
"useIframe",
")",
"{",
"$td",
".",
"append",
"(",
"cmenu",
".",
"createIframe",
"(",
")",
")",
";",
"}",
"$t",
".",
"append",
"(",
"$tr",
".",
"append",
"(",
"$td",
".",
"append",
"(",
"$div",
")",
")",
")",
";",
"return",
"$t",
";",
"}"
]
| Accept an Array representing a menu structure and turn it into HTML | [
"Accept",
"an",
"Array",
"representing",
"a",
"menu",
"structure",
"and",
"turn",
"it",
"into",
"HTML"
]
| 84eacc15a65694ace4e7a2df46638c3a98252cab | https://github.com/alchemy-fr/Phraseanet-common/blob/84eacc15a65694ace4e7a2df46638c3a98252cab/src/components/vendors/contextMenu.js#L161-L223 | train |
|
alchemy-fr/Phraseanet-common | src/components/vendors/contextMenu.js | function (obj) {
var cmenu = this;
var label = obj.label;
if (typeof obj === "function") {
obj = {onclick: obj};
} // If passed a simple function, turn it into a property of an object
// Default properties, extended in case properties are passed
var o = $.extend({
onclick: function () {
},
className: '',
hoverClassName: cmenu.itemHoverClassName,
icon: '',
disabled: false,
title: '',
hoverItem: cmenu.hoverItem,
hoverItemOut: cmenu.hoverItemOut
}, obj);
// If an icon is specified, hard-code the background-image style. Themes that don't show images should take this into account in their CSS
var iconStyle = (o.icon) ? 'background-image:url(' + o.icon + ');' : '';
var $div = $('<div class="' + cmenu.itemClassName + ' ' + o.className + ((o.disabled) ? ' ' + cmenu.disabledItemClassName : '') + '" title="' + o.title + '"></div>')
// If the item is disabled, don't do anything when it is clicked
.click(
function (e) {
if (cmenu.isItemDisabled(this)) {
return false;
}
else {
return o.onclick.call(cmenu.target, this, cmenu, e, label);
}
}
)
// Change the class of the item when hovered over
.hover(
function () {
o.hoverItem.call(this, (cmenu.isItemDisabled(this)) ? cmenu.disabledItemHoverClassName : o.hoverClassName);
}
, function () {
o.hoverItemOut.call(this, (cmenu.isItemDisabled(this)) ? cmenu.disabledItemHoverClassName : o.hoverClassName);
}
);
var $idiv = $('<div class="' + cmenu.innerDivClassName + '" style="' + iconStyle + '">' + label + '</div>');
$div.append($idiv);
return $div;
} | javascript | function (obj) {
var cmenu = this;
var label = obj.label;
if (typeof obj === "function") {
obj = {onclick: obj};
} // If passed a simple function, turn it into a property of an object
// Default properties, extended in case properties are passed
var o = $.extend({
onclick: function () {
},
className: '',
hoverClassName: cmenu.itemHoverClassName,
icon: '',
disabled: false,
title: '',
hoverItem: cmenu.hoverItem,
hoverItemOut: cmenu.hoverItemOut
}, obj);
// If an icon is specified, hard-code the background-image style. Themes that don't show images should take this into account in their CSS
var iconStyle = (o.icon) ? 'background-image:url(' + o.icon + ');' : '';
var $div = $('<div class="' + cmenu.itemClassName + ' ' + o.className + ((o.disabled) ? ' ' + cmenu.disabledItemClassName : '') + '" title="' + o.title + '"></div>')
// If the item is disabled, don't do anything when it is clicked
.click(
function (e) {
if (cmenu.isItemDisabled(this)) {
return false;
}
else {
return o.onclick.call(cmenu.target, this, cmenu, e, label);
}
}
)
// Change the class of the item when hovered over
.hover(
function () {
o.hoverItem.call(this, (cmenu.isItemDisabled(this)) ? cmenu.disabledItemHoverClassName : o.hoverClassName);
}
, function () {
o.hoverItemOut.call(this, (cmenu.isItemDisabled(this)) ? cmenu.disabledItemHoverClassName : o.hoverClassName);
}
);
var $idiv = $('<div class="' + cmenu.innerDivClassName + '" style="' + iconStyle + '">' + label + '</div>');
$div.append($idiv);
return $div;
} | [
"function",
"(",
"obj",
")",
"{",
"var",
"cmenu",
"=",
"this",
";",
"var",
"label",
"=",
"obj",
".",
"label",
";",
"if",
"(",
"typeof",
"obj",
"===",
"\"function\"",
")",
"{",
"obj",
"=",
"{",
"onclick",
":",
"obj",
"}",
";",
"}",
"var",
"o",
"=",
"$",
".",
"extend",
"(",
"{",
"onclick",
":",
"function",
"(",
")",
"{",
"}",
",",
"className",
":",
"''",
",",
"hoverClassName",
":",
"cmenu",
".",
"itemHoverClassName",
",",
"icon",
":",
"''",
",",
"disabled",
":",
"false",
",",
"title",
":",
"''",
",",
"hoverItem",
":",
"cmenu",
".",
"hoverItem",
",",
"hoverItemOut",
":",
"cmenu",
".",
"hoverItemOut",
"}",
",",
"obj",
")",
";",
"var",
"iconStyle",
"=",
"(",
"o",
".",
"icon",
")",
"?",
"'background-image:url('",
"+",
"o",
".",
"icon",
"+",
"');'",
":",
"''",
";",
"var",
"$div",
"=",
"$",
"(",
"'<div class=\"'",
"+",
"cmenu",
".",
"itemClassName",
"+",
"' '",
"+",
"o",
".",
"className",
"+",
"(",
"(",
"o",
".",
"disabled",
")",
"?",
"' '",
"+",
"cmenu",
".",
"disabledItemClassName",
":",
"''",
")",
"+",
"'\" title=\"'",
"+",
"o",
".",
"title",
"+",
"'\"></div>'",
")",
".",
"click",
"(",
"function",
"(",
"e",
")",
"{",
"if",
"(",
"cmenu",
".",
"isItemDisabled",
"(",
"this",
")",
")",
"{",
"return",
"false",
";",
"}",
"else",
"{",
"return",
"o",
".",
"onclick",
".",
"call",
"(",
"cmenu",
".",
"target",
",",
"this",
",",
"cmenu",
",",
"e",
",",
"label",
")",
";",
"}",
"}",
")",
".",
"hover",
"(",
"function",
"(",
")",
"{",
"o",
".",
"hoverItem",
".",
"call",
"(",
"this",
",",
"(",
"cmenu",
".",
"isItemDisabled",
"(",
"this",
")",
")",
"?",
"cmenu",
".",
"disabledItemHoverClassName",
":",
"o",
".",
"hoverClassName",
")",
";",
"}",
",",
"function",
"(",
")",
"{",
"o",
".",
"hoverItemOut",
".",
"call",
"(",
"this",
",",
"(",
"cmenu",
".",
"isItemDisabled",
"(",
"this",
")",
")",
"?",
"cmenu",
".",
"disabledItemHoverClassName",
":",
"o",
".",
"hoverClassName",
")",
";",
"}",
")",
";",
"var",
"$idiv",
"=",
"$",
"(",
"'<div class=\"'",
"+",
"cmenu",
".",
"innerDivClassName",
"+",
"'\" style=\"'",
"+",
"iconStyle",
"+",
"'\">'",
"+",
"label",
"+",
"'</div>'",
")",
";",
"$div",
".",
"append",
"(",
"$idiv",
")",
";",
"return",
"$div",
";",
"}"
]
| Create an individual menu item | [
"Create",
"an",
"individual",
"menu",
"item"
]
| 84eacc15a65694ace4e7a2df46638c3a98252cab | https://github.com/alchemy-fr/Phraseanet-common/blob/84eacc15a65694ace4e7a2df46638c3a98252cab/src/components/vendors/contextMenu.js#L226-L270 | train |
|
alchemy-fr/Phraseanet-common | src/components/vendors/contextMenu.js | function (cmenu) {
cmenu.shadowObj = $('<div class="' + cmenu.shadowClass + '"></div>').css({
display: 'none',
position: "absolute",
zIndex: 9998,
opacity: cmenu.shadowOpacity,
backgroundColor: cmenu.shadowColor
});
$(cmenu.appendTo).append(cmenu.shadowObj);
} | javascript | function (cmenu) {
cmenu.shadowObj = $('<div class="' + cmenu.shadowClass + '"></div>').css({
display: 'none',
position: "absolute",
zIndex: 9998,
opacity: cmenu.shadowOpacity,
backgroundColor: cmenu.shadowColor
});
$(cmenu.appendTo).append(cmenu.shadowObj);
} | [
"function",
"(",
"cmenu",
")",
"{",
"cmenu",
".",
"shadowObj",
"=",
"$",
"(",
"'<div class=\"'",
"+",
"cmenu",
".",
"shadowClass",
"+",
"'\"></div>'",
")",
".",
"css",
"(",
"{",
"display",
":",
"'none'",
",",
"position",
":",
"\"absolute\"",
",",
"zIndex",
":",
"9998",
",",
"opacity",
":",
"cmenu",
".",
"shadowOpacity",
",",
"backgroundColor",
":",
"cmenu",
".",
"shadowColor",
"}",
")",
";",
"$",
"(",
"cmenu",
".",
"appendTo",
")",
".",
"append",
"(",
"cmenu",
".",
"shadowObj",
")",
";",
"}"
]
| Create the shadow object | [
"Create",
"the",
"shadow",
"object"
]
| 84eacc15a65694ace4e7a2df46638c3a98252cab | https://github.com/alchemy-fr/Phraseanet-common/blob/84eacc15a65694ace4e7a2df46638c3a98252cab/src/components/vendors/contextMenu.js#L291-L300 | train |
|
alchemy-fr/Phraseanet-common | src/components/vendors/contextMenu.js | function (x, y, e) {
var cmenu = this;
if (cmenu.shadow) {
cmenu.shadowObj.css({
width: (cmenu.menu.width() + cmenu.shadowWidthAdjust) + "px",
height: (cmenu.menu.height() + cmenu.shadowHeightAdjust) + "px",
top: (y + cmenu.shadowOffsetY) + "px",
left: (x + cmenu.shadowOffsetX) + "px"
}).addClass(cmenu.shadowClass)[cmenu.showTransition](cmenu.showSpeed);
}
} | javascript | function (x, y, e) {
var cmenu = this;
if (cmenu.shadow) {
cmenu.shadowObj.css({
width: (cmenu.menu.width() + cmenu.shadowWidthAdjust) + "px",
height: (cmenu.menu.height() + cmenu.shadowHeightAdjust) + "px",
top: (y + cmenu.shadowOffsetY) + "px",
left: (x + cmenu.shadowOffsetX) + "px"
}).addClass(cmenu.shadowClass)[cmenu.showTransition](cmenu.showSpeed);
}
} | [
"function",
"(",
"x",
",",
"y",
",",
"e",
")",
"{",
"var",
"cmenu",
"=",
"this",
";",
"if",
"(",
"cmenu",
".",
"shadow",
")",
"{",
"cmenu",
".",
"shadowObj",
".",
"css",
"(",
"{",
"width",
":",
"(",
"cmenu",
".",
"menu",
".",
"width",
"(",
")",
"+",
"cmenu",
".",
"shadowWidthAdjust",
")",
"+",
"\"px\"",
",",
"height",
":",
"(",
"cmenu",
".",
"menu",
".",
"height",
"(",
")",
"+",
"cmenu",
".",
"shadowHeightAdjust",
")",
"+",
"\"px\"",
",",
"top",
":",
"(",
"y",
"+",
"cmenu",
".",
"shadowOffsetY",
")",
"+",
"\"px\"",
",",
"left",
":",
"(",
"x",
"+",
"cmenu",
".",
"shadowOffsetX",
")",
"+",
"\"px\"",
"}",
")",
".",
"addClass",
"(",
"cmenu",
".",
"shadowClass",
")",
"[",
"cmenu",
".",
"showTransition",
"]",
"(",
"cmenu",
".",
"showSpeed",
")",
";",
"}",
"}"
]
| Display the shadow object, given the position of the menu itself | [
"Display",
"the",
"shadow",
"object",
"given",
"the",
"position",
"of",
"the",
"menu",
"itself"
]
| 84eacc15a65694ace4e7a2df46638c3a98252cab | https://github.com/alchemy-fr/Phraseanet-common/blob/84eacc15a65694ace4e7a2df46638c3a98252cab/src/components/vendors/contextMenu.js#L303-L313 | train |
|
alchemy-fr/Phraseanet-common | src/components/vendors/contextMenu.js | function (clickX, clickY, cmenu, e) {
var x = clickX + cmenu.offsetX;
var y = clickY + cmenu.offsetY;
var h = $(cmenu.menu).height();
var w = $(cmenu.menu).width();
var dir = cmenu.direction;
if (cmenu.constrainToScreen) {
var $w = $(window);
var wh = $w.height();
var ww = $w.width();
var st = $w.scrollTop();
var maxTop = y - st - 5;
var maxBottom = wh + st - y - 5;
if (h > maxBottom) {
if (h > maxTop) {
if (maxTop > maxBottom) {
// scrollable en haut
h = maxTop;
cmenu._div.css('height', h + 'px').css('overflow-y', 'scroll');
y -= h;
}
else {
// scrollable en bas
h = maxBottom;
cmenu._div.css('height', h + 'px').css('overflow-y', 'scroll');
}
}
else {
// menu ok en haut
y -= h;
}
}
else {
// menu ok en bas
}
var maxRight = x + w - $w.scrollLeft();
if (maxRight > ww) {
x -= (maxRight - ww);
}
}
return {'x': x, 'y': y};
} | javascript | function (clickX, clickY, cmenu, e) {
var x = clickX + cmenu.offsetX;
var y = clickY + cmenu.offsetY;
var h = $(cmenu.menu).height();
var w = $(cmenu.menu).width();
var dir = cmenu.direction;
if (cmenu.constrainToScreen) {
var $w = $(window);
var wh = $w.height();
var ww = $w.width();
var st = $w.scrollTop();
var maxTop = y - st - 5;
var maxBottom = wh + st - y - 5;
if (h > maxBottom) {
if (h > maxTop) {
if (maxTop > maxBottom) {
// scrollable en haut
h = maxTop;
cmenu._div.css('height', h + 'px').css('overflow-y', 'scroll');
y -= h;
}
else {
// scrollable en bas
h = maxBottom;
cmenu._div.css('height', h + 'px').css('overflow-y', 'scroll');
}
}
else {
// menu ok en haut
y -= h;
}
}
else {
// menu ok en bas
}
var maxRight = x + w - $w.scrollLeft();
if (maxRight > ww) {
x -= (maxRight - ww);
}
}
return {'x': x, 'y': y};
} | [
"function",
"(",
"clickX",
",",
"clickY",
",",
"cmenu",
",",
"e",
")",
"{",
"var",
"x",
"=",
"clickX",
"+",
"cmenu",
".",
"offsetX",
";",
"var",
"y",
"=",
"clickY",
"+",
"cmenu",
".",
"offsetY",
";",
"var",
"h",
"=",
"$",
"(",
"cmenu",
".",
"menu",
")",
".",
"height",
"(",
")",
";",
"var",
"w",
"=",
"$",
"(",
"cmenu",
".",
"menu",
")",
".",
"width",
"(",
")",
";",
"var",
"dir",
"=",
"cmenu",
".",
"direction",
";",
"if",
"(",
"cmenu",
".",
"constrainToScreen",
")",
"{",
"var",
"$w",
"=",
"$",
"(",
"window",
")",
";",
"var",
"wh",
"=",
"$w",
".",
"height",
"(",
")",
";",
"var",
"ww",
"=",
"$w",
".",
"width",
"(",
")",
";",
"var",
"st",
"=",
"$w",
".",
"scrollTop",
"(",
")",
";",
"var",
"maxTop",
"=",
"y",
"-",
"st",
"-",
"5",
";",
"var",
"maxBottom",
"=",
"wh",
"+",
"st",
"-",
"y",
"-",
"5",
";",
"if",
"(",
"h",
">",
"maxBottom",
")",
"{",
"if",
"(",
"h",
">",
"maxTop",
")",
"{",
"if",
"(",
"maxTop",
">",
"maxBottom",
")",
"{",
"h",
"=",
"maxTop",
";",
"cmenu",
".",
"_div",
".",
"css",
"(",
"'height'",
",",
"h",
"+",
"'px'",
")",
".",
"css",
"(",
"'overflow-y'",
",",
"'scroll'",
")",
";",
"y",
"-=",
"h",
";",
"}",
"else",
"{",
"h",
"=",
"maxBottom",
";",
"cmenu",
".",
"_div",
".",
"css",
"(",
"'height'",
",",
"h",
"+",
"'px'",
")",
".",
"css",
"(",
"'overflow-y'",
",",
"'scroll'",
")",
";",
"}",
"}",
"else",
"{",
"y",
"-=",
"h",
";",
"}",
"}",
"else",
"{",
"}",
"var",
"maxRight",
"=",
"x",
"+",
"w",
"-",
"$w",
".",
"scrollLeft",
"(",
")",
";",
"if",
"(",
"maxRight",
">",
"ww",
")",
"{",
"x",
"-=",
"(",
"maxRight",
"-",
"ww",
")",
";",
"}",
"}",
"return",
"{",
"'x'",
":",
"x",
",",
"'y'",
":",
"y",
"}",
";",
"}"
]
| Find the position where the menu should appear, given an x,y of the click event | [
"Find",
"the",
"position",
"where",
"the",
"menu",
"should",
"appear",
"given",
"an",
"x",
"y",
"of",
"the",
"click",
"event"
]
| 84eacc15a65694ace4e7a2df46638c3a98252cab | https://github.com/alchemy-fr/Phraseanet-common/blob/84eacc15a65694ace4e7a2df46638c3a98252cab/src/components/vendors/contextMenu.js#L418-L460 | train |
|
alchemy-fr/Phraseanet-common | src/components/vendors/contextMenu.js | function () {
var cmenu = this;
if (cmenu.shown) {
if (cmenu.iframe) {
$(cmenu.iframe).hide();
}
if (cmenu.menu) {
cmenu.menu[cmenu.hideTransition](cmenu.hideSpeed, ((cmenu.hideCallback) ? function () {
cmenu.hideCallback.call(cmenu);
} : null));
}
if (cmenu.shadow) {
cmenu.shadowObj[cmenu.hideTransition](cmenu.hideSpeed);
}
}
cmenu.shown = false;
} | javascript | function () {
var cmenu = this;
if (cmenu.shown) {
if (cmenu.iframe) {
$(cmenu.iframe).hide();
}
if (cmenu.menu) {
cmenu.menu[cmenu.hideTransition](cmenu.hideSpeed, ((cmenu.hideCallback) ? function () {
cmenu.hideCallback.call(cmenu);
} : null));
}
if (cmenu.shadow) {
cmenu.shadowObj[cmenu.hideTransition](cmenu.hideSpeed);
}
}
cmenu.shown = false;
} | [
"function",
"(",
")",
"{",
"var",
"cmenu",
"=",
"this",
";",
"if",
"(",
"cmenu",
".",
"shown",
")",
"{",
"if",
"(",
"cmenu",
".",
"iframe",
")",
"{",
"$",
"(",
"cmenu",
".",
"iframe",
")",
".",
"hide",
"(",
")",
";",
"}",
"if",
"(",
"cmenu",
".",
"menu",
")",
"{",
"cmenu",
".",
"menu",
"[",
"cmenu",
".",
"hideTransition",
"]",
"(",
"cmenu",
".",
"hideSpeed",
",",
"(",
"(",
"cmenu",
".",
"hideCallback",
")",
"?",
"function",
"(",
")",
"{",
"cmenu",
".",
"hideCallback",
".",
"call",
"(",
"cmenu",
")",
";",
"}",
":",
"null",
")",
")",
";",
"}",
"if",
"(",
"cmenu",
".",
"shadow",
")",
"{",
"cmenu",
".",
"shadowObj",
"[",
"cmenu",
".",
"hideTransition",
"]",
"(",
"cmenu",
".",
"hideSpeed",
")",
";",
"}",
"}",
"cmenu",
".",
"shown",
"=",
"false",
";",
"}"
]
| Hide the menu, of course | [
"Hide",
"the",
"menu",
"of",
"course"
]
| 84eacc15a65694ace4e7a2df46638c3a98252cab | https://github.com/alchemy-fr/Phraseanet-common/blob/84eacc15a65694ace4e7a2df46638c3a98252cab/src/components/vendors/contextMenu.js#L463-L479 | train |
|
S3bb1/ah-dashboard-plugin | public/dashboard/bower_components/admin-lte/plugins/datatables/extensions/ColReorder/js/dataTables.colReorder.js | fnArraySwitch | function fnArraySwitch( aArray, iFrom, iTo )
{
var mStore = aArray.splice( iFrom, 1 )[0];
aArray.splice( iTo, 0, mStore );
} | javascript | function fnArraySwitch( aArray, iFrom, iTo )
{
var mStore = aArray.splice( iFrom, 1 )[0];
aArray.splice( iTo, 0, mStore );
} | [
"function",
"fnArraySwitch",
"(",
"aArray",
",",
"iFrom",
",",
"iTo",
")",
"{",
"var",
"mStore",
"=",
"aArray",
".",
"splice",
"(",
"iFrom",
",",
"1",
")",
"[",
"0",
"]",
";",
"aArray",
".",
"splice",
"(",
"iTo",
",",
"0",
",",
"mStore",
")",
";",
"}"
]
| Modify an array by switching the position of two elements
@method fnArraySwitch
@param array aArray Array to consider, will be modified by reference (i.e. no return)
@param int iFrom From point
@param int iTo Insert point
@returns void | [
"Modify",
"an",
"array",
"by",
"switching",
"the",
"position",
"of",
"two",
"elements"
]
| c283370ec0f99a25db5bb7029a98b4febf8c5251 | https://github.com/S3bb1/ah-dashboard-plugin/blob/c283370ec0f99a25db5bb7029a98b4febf8c5251/public/dashboard/bower_components/admin-lte/plugins/datatables/extensions/ColReorder/js/dataTables.colReorder.js#L53-L57 | train |
S3bb1/ah-dashboard-plugin | public/dashboard/bower_components/admin-lte/plugins/datatables/extensions/ColReorder/js/dataTables.colReorder.js | function( dt, opts )
{
var oDTSettings;
if ( $.fn.dataTable.Api ) {
oDTSettings = new $.fn.dataTable.Api( dt ).settings()[0];
}
// 1.9 compatibility
else if ( dt.fnSettings ) {
// DataTables object, convert to the settings object
oDTSettings = dt.fnSettings();
}
else if ( typeof dt === 'string' ) {
// jQuery selector
if ( $.fn.dataTable.fnIsDataTable( $(dt)[0] ) ) {
oDTSettings = $(dt).eq(0).dataTable().fnSettings();
}
}
else if ( dt.nodeName && dt.nodeName.toLowerCase() === 'table' ) {
// Table node
if ( $.fn.dataTable.fnIsDataTable( dt.nodeName ) ) {
oDTSettings = $(dt.nodeName).dataTable().fnSettings();
}
}
else if ( dt instanceof jQuery ) {
// jQuery object
if ( $.fn.dataTable.fnIsDataTable( dt[0] ) ) {
oDTSettings = dt.eq(0).dataTable().fnSettings();
}
}
else {
// DataTables settings object
oDTSettings = dt;
}
// Ensure that we can't initialise on the same table twice
if ( oDTSettings._colReorder ) {
throw "ColReorder already initialised on table #"+oDTSettings.nTable.id;
}
// Convert from camelCase to Hungarian, just as DataTables does
var camelToHungarian = $.fn.dataTable.camelToHungarian;
if ( camelToHungarian ) {
camelToHungarian( ColReorder.defaults, ColReorder.defaults, true );
camelToHungarian( ColReorder.defaults, opts || {} );
}
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Public class variables
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/**
* @namespace Settings object which contains customisable information for ColReorder instance
*/
this.s = {
/**
* DataTables settings object
* @property dt
* @type Object
* @default null
*/
"dt": null,
/**
* Initialisation object used for this instance
* @property init
* @type object
* @default {}
*/
"init": $.extend( true, {}, ColReorder.defaults, opts ),
/**
* Number of columns to fix (not allow to be reordered)
* @property fixed
* @type int
* @default 0
*/
"fixed": 0,
/**
* Number of columns to fix counting from right (not allow to be reordered)
* @property fixedRight
* @type int
* @default 0
*/
"fixedRight": 0,
/**
* Callback function for once the reorder has been done
* @property reorderCallback
* @type function
* @default null
*/
"reorderCallback": null,
/**
* @namespace Information used for the mouse drag
*/
"mouse": {
"startX": -1,
"startY": -1,
"offsetX": -1,
"offsetY": -1,
"target": -1,
"targetIndex": -1,
"fromIndex": -1
},
/**
* Information which is used for positioning the insert cusor and knowing where to do the
* insert. Array of objects with the properties:
* x: x-axis position
* to: insert point
* @property aoTargets
* @type array
* @default []
*/
"aoTargets": []
};
/**
* @namespace Common and useful DOM elements for the class instance
*/
this.dom = {
/**
* Dragging element (the one the mouse is moving)
* @property drag
* @type element
* @default null
*/
"drag": null,
/**
* The insert cursor
* @property pointer
* @type element
* @default null
*/
"pointer": null
};
/* Constructor logic */
this.s.dt = oDTSettings;
this.s.dt._colReorder = this;
this._fnConstruct();
/* Add destroy callback */
oDTSettings.oApi._fnCallbackReg(oDTSettings, 'aoDestroyCallback', $.proxy(this._fnDestroy, this), 'ColReorder');
return this;
} | javascript | function( dt, opts )
{
var oDTSettings;
if ( $.fn.dataTable.Api ) {
oDTSettings = new $.fn.dataTable.Api( dt ).settings()[0];
}
// 1.9 compatibility
else if ( dt.fnSettings ) {
// DataTables object, convert to the settings object
oDTSettings = dt.fnSettings();
}
else if ( typeof dt === 'string' ) {
// jQuery selector
if ( $.fn.dataTable.fnIsDataTable( $(dt)[0] ) ) {
oDTSettings = $(dt).eq(0).dataTable().fnSettings();
}
}
else if ( dt.nodeName && dt.nodeName.toLowerCase() === 'table' ) {
// Table node
if ( $.fn.dataTable.fnIsDataTable( dt.nodeName ) ) {
oDTSettings = $(dt.nodeName).dataTable().fnSettings();
}
}
else if ( dt instanceof jQuery ) {
// jQuery object
if ( $.fn.dataTable.fnIsDataTable( dt[0] ) ) {
oDTSettings = dt.eq(0).dataTable().fnSettings();
}
}
else {
// DataTables settings object
oDTSettings = dt;
}
// Ensure that we can't initialise on the same table twice
if ( oDTSettings._colReorder ) {
throw "ColReorder already initialised on table #"+oDTSettings.nTable.id;
}
// Convert from camelCase to Hungarian, just as DataTables does
var camelToHungarian = $.fn.dataTable.camelToHungarian;
if ( camelToHungarian ) {
camelToHungarian( ColReorder.defaults, ColReorder.defaults, true );
camelToHungarian( ColReorder.defaults, opts || {} );
}
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Public class variables
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/**
* @namespace Settings object which contains customisable information for ColReorder instance
*/
this.s = {
/**
* DataTables settings object
* @property dt
* @type Object
* @default null
*/
"dt": null,
/**
* Initialisation object used for this instance
* @property init
* @type object
* @default {}
*/
"init": $.extend( true, {}, ColReorder.defaults, opts ),
/**
* Number of columns to fix (not allow to be reordered)
* @property fixed
* @type int
* @default 0
*/
"fixed": 0,
/**
* Number of columns to fix counting from right (not allow to be reordered)
* @property fixedRight
* @type int
* @default 0
*/
"fixedRight": 0,
/**
* Callback function for once the reorder has been done
* @property reorderCallback
* @type function
* @default null
*/
"reorderCallback": null,
/**
* @namespace Information used for the mouse drag
*/
"mouse": {
"startX": -1,
"startY": -1,
"offsetX": -1,
"offsetY": -1,
"target": -1,
"targetIndex": -1,
"fromIndex": -1
},
/**
* Information which is used for positioning the insert cusor and knowing where to do the
* insert. Array of objects with the properties:
* x: x-axis position
* to: insert point
* @property aoTargets
* @type array
* @default []
*/
"aoTargets": []
};
/**
* @namespace Common and useful DOM elements for the class instance
*/
this.dom = {
/**
* Dragging element (the one the mouse is moving)
* @property drag
* @type element
* @default null
*/
"drag": null,
/**
* The insert cursor
* @property pointer
* @type element
* @default null
*/
"pointer": null
};
/* Constructor logic */
this.s.dt = oDTSettings;
this.s.dt._colReorder = this;
this._fnConstruct();
/* Add destroy callback */
oDTSettings.oApi._fnCallbackReg(oDTSettings, 'aoDestroyCallback', $.proxy(this._fnDestroy, this), 'ColReorder');
return this;
} | [
"function",
"(",
"dt",
",",
"opts",
")",
"{",
"var",
"oDTSettings",
";",
"if",
"(",
"$",
".",
"fn",
".",
"dataTable",
".",
"Api",
")",
"{",
"oDTSettings",
"=",
"new",
"$",
".",
"fn",
".",
"dataTable",
".",
"Api",
"(",
"dt",
")",
".",
"settings",
"(",
")",
"[",
"0",
"]",
";",
"}",
"else",
"if",
"(",
"dt",
".",
"fnSettings",
")",
"{",
"oDTSettings",
"=",
"dt",
".",
"fnSettings",
"(",
")",
";",
"}",
"else",
"if",
"(",
"typeof",
"dt",
"===",
"'string'",
")",
"{",
"if",
"(",
"$",
".",
"fn",
".",
"dataTable",
".",
"fnIsDataTable",
"(",
"$",
"(",
"dt",
")",
"[",
"0",
"]",
")",
")",
"{",
"oDTSettings",
"=",
"$",
"(",
"dt",
")",
".",
"eq",
"(",
"0",
")",
".",
"dataTable",
"(",
")",
".",
"fnSettings",
"(",
")",
";",
"}",
"}",
"else",
"if",
"(",
"dt",
".",
"nodeName",
"&&",
"dt",
".",
"nodeName",
".",
"toLowerCase",
"(",
")",
"===",
"'table'",
")",
"{",
"if",
"(",
"$",
".",
"fn",
".",
"dataTable",
".",
"fnIsDataTable",
"(",
"dt",
".",
"nodeName",
")",
")",
"{",
"oDTSettings",
"=",
"$",
"(",
"dt",
".",
"nodeName",
")",
".",
"dataTable",
"(",
")",
".",
"fnSettings",
"(",
")",
";",
"}",
"}",
"else",
"if",
"(",
"dt",
"instanceof",
"jQuery",
")",
"{",
"if",
"(",
"$",
".",
"fn",
".",
"dataTable",
".",
"fnIsDataTable",
"(",
"dt",
"[",
"0",
"]",
")",
")",
"{",
"oDTSettings",
"=",
"dt",
".",
"eq",
"(",
"0",
")",
".",
"dataTable",
"(",
")",
".",
"fnSettings",
"(",
")",
";",
"}",
"}",
"else",
"{",
"oDTSettings",
"=",
"dt",
";",
"}",
"if",
"(",
"oDTSettings",
".",
"_colReorder",
")",
"{",
"throw",
"\"ColReorder already initialised on table #\"",
"+",
"oDTSettings",
".",
"nTable",
".",
"id",
";",
"}",
"var",
"camelToHungarian",
"=",
"$",
".",
"fn",
".",
"dataTable",
".",
"camelToHungarian",
";",
"if",
"(",
"camelToHungarian",
")",
"{",
"camelToHungarian",
"(",
"ColReorder",
".",
"defaults",
",",
"ColReorder",
".",
"defaults",
",",
"true",
")",
";",
"camelToHungarian",
"(",
"ColReorder",
".",
"defaults",
",",
"opts",
"||",
"{",
"}",
")",
";",
"}",
"this",
".",
"s",
"=",
"{",
"\"dt\"",
":",
"null",
",",
"\"init\"",
":",
"$",
".",
"extend",
"(",
"true",
",",
"{",
"}",
",",
"ColReorder",
".",
"defaults",
",",
"opts",
")",
",",
"\"fixed\"",
":",
"0",
",",
"\"fixedRight\"",
":",
"0",
",",
"\"reorderCallback\"",
":",
"null",
",",
"\"mouse\"",
":",
"{",
"\"startX\"",
":",
"-",
"1",
",",
"\"startY\"",
":",
"-",
"1",
",",
"\"offsetX\"",
":",
"-",
"1",
",",
"\"offsetY\"",
":",
"-",
"1",
",",
"\"target\"",
":",
"-",
"1",
",",
"\"targetIndex\"",
":",
"-",
"1",
",",
"\"fromIndex\"",
":",
"-",
"1",
"}",
",",
"\"aoTargets\"",
":",
"[",
"]",
"}",
";",
"this",
".",
"dom",
"=",
"{",
"\"drag\"",
":",
"null",
",",
"\"pointer\"",
":",
"null",
"}",
";",
"this",
".",
"s",
".",
"dt",
"=",
"oDTSettings",
";",
"this",
".",
"s",
".",
"dt",
".",
"_colReorder",
"=",
"this",
";",
"this",
".",
"_fnConstruct",
"(",
")",
";",
"oDTSettings",
".",
"oApi",
".",
"_fnCallbackReg",
"(",
"oDTSettings",
",",
"'aoDestroyCallback'",
",",
"$",
".",
"proxy",
"(",
"this",
".",
"_fnDestroy",
",",
"this",
")",
",",
"'ColReorder'",
")",
";",
"return",
"this",
";",
"}"
]
| ColReorder provides column visibility control for DataTables
@class ColReorder
@constructor
@param {object} dt DataTables settings object
@param {object} opts ColReorder options | [
"ColReorder",
"provides",
"column",
"visibility",
"control",
"for",
"DataTables"
]
| c283370ec0f99a25db5bb7029a98b4febf8c5251 | https://github.com/S3bb1/ah-dashboard-plugin/blob/c283370ec0f99a25db5bb7029a98b4febf8c5251/public/dashboard/bower_components/admin-lte/plugins/datatables/extensions/ColReorder/js/dataTables.colReorder.js#L349-L502 | train |
|
S3bb1/ah-dashboard-plugin | public/dashboard/bower_components/admin-lte/plugins/datatables/extensions/ColReorder/js/dataTables.colReorder.js | function ( a )
{
if ( a.length != this.s.dt.aoColumns.length )
{
this.s.dt.oInstance.oApi._fnLog( this.s.dt, 1, "ColReorder - array reorder does not "+
"match known number of columns. Skipping." );
return;
}
for ( var i=0, iLen=a.length ; i<iLen ; i++ )
{
var currIndex = $.inArray( i, a );
if ( i != currIndex )
{
/* Reorder our switching array */
fnArraySwitch( a, currIndex, i );
/* Do the column reorder in the table */
this.s.dt.oInstance.fnColReorder( currIndex, i );
}
}
/* When scrolling we need to recalculate the column sizes to allow for the shift */
if ( this.s.dt.oScroll.sX !== "" || this.s.dt.oScroll.sY !== "" )
{
this.s.dt.oInstance.fnAdjustColumnSizing( false );
}
/* Save the state */
this.s.dt.oInstance.oApi._fnSaveState( this.s.dt );
this._fnSetColumnIndexes();
if ( this.s.reorderCallback !== null )
{
this.s.reorderCallback.call( this );
}
} | javascript | function ( a )
{
if ( a.length != this.s.dt.aoColumns.length )
{
this.s.dt.oInstance.oApi._fnLog( this.s.dt, 1, "ColReorder - array reorder does not "+
"match known number of columns. Skipping." );
return;
}
for ( var i=0, iLen=a.length ; i<iLen ; i++ )
{
var currIndex = $.inArray( i, a );
if ( i != currIndex )
{
/* Reorder our switching array */
fnArraySwitch( a, currIndex, i );
/* Do the column reorder in the table */
this.s.dt.oInstance.fnColReorder( currIndex, i );
}
}
/* When scrolling we need to recalculate the column sizes to allow for the shift */
if ( this.s.dt.oScroll.sX !== "" || this.s.dt.oScroll.sY !== "" )
{
this.s.dt.oInstance.fnAdjustColumnSizing( false );
}
/* Save the state */
this.s.dt.oInstance.oApi._fnSaveState( this.s.dt );
this._fnSetColumnIndexes();
if ( this.s.reorderCallback !== null )
{
this.s.reorderCallback.call( this );
}
} | [
"function",
"(",
"a",
")",
"{",
"if",
"(",
"a",
".",
"length",
"!=",
"this",
".",
"s",
".",
"dt",
".",
"aoColumns",
".",
"length",
")",
"{",
"this",
".",
"s",
".",
"dt",
".",
"oInstance",
".",
"oApi",
".",
"_fnLog",
"(",
"this",
".",
"s",
".",
"dt",
",",
"1",
",",
"\"ColReorder - array reorder does not \"",
"+",
"\"match known number of columns. Skipping.\"",
")",
";",
"return",
";",
"}",
"for",
"(",
"var",
"i",
"=",
"0",
",",
"iLen",
"=",
"a",
".",
"length",
";",
"i",
"<",
"iLen",
";",
"i",
"++",
")",
"{",
"var",
"currIndex",
"=",
"$",
".",
"inArray",
"(",
"i",
",",
"a",
")",
";",
"if",
"(",
"i",
"!=",
"currIndex",
")",
"{",
"fnArraySwitch",
"(",
"a",
",",
"currIndex",
",",
"i",
")",
";",
"this",
".",
"s",
".",
"dt",
".",
"oInstance",
".",
"fnColReorder",
"(",
"currIndex",
",",
"i",
")",
";",
"}",
"}",
"if",
"(",
"this",
".",
"s",
".",
"dt",
".",
"oScroll",
".",
"sX",
"!==",
"\"\"",
"||",
"this",
".",
"s",
".",
"dt",
".",
"oScroll",
".",
"sY",
"!==",
"\"\"",
")",
"{",
"this",
".",
"s",
".",
"dt",
".",
"oInstance",
".",
"fnAdjustColumnSizing",
"(",
"false",
")",
";",
"}",
"this",
".",
"s",
".",
"dt",
".",
"oInstance",
".",
"oApi",
".",
"_fnSaveState",
"(",
"this",
".",
"s",
".",
"dt",
")",
";",
"this",
".",
"_fnSetColumnIndexes",
"(",
")",
";",
"if",
"(",
"this",
".",
"s",
".",
"reorderCallback",
"!==",
"null",
")",
"{",
"this",
".",
"s",
".",
"reorderCallback",
".",
"call",
"(",
"this",
")",
";",
"}",
"}"
]
| Set the column order from an array
@method _fnOrderColumns
@param array a An array of integers which dictate the column order that should be applied
@returns void
@private | [
"Set",
"the",
"column",
"order",
"from",
"an",
"array"
]
| c283370ec0f99a25db5bb7029a98b4febf8c5251 | https://github.com/S3bb1/ah-dashboard-plugin/blob/c283370ec0f99a25db5bb7029a98b4febf8c5251/public/dashboard/bower_components/admin-lte/plugins/datatables/extensions/ColReorder/js/dataTables.colReorder.js#L710-L747 | train |
|
S3bb1/ah-dashboard-plugin | public/dashboard/bower_components/admin-lte/plugins/datatables/extensions/ColReorder/js/dataTables.colReorder.js | function ( oState )
{
var i, iLen, aCopy, iOrigColumn;
var oSettings = this.s.dt;
var columns = oSettings.aoColumns;
oState.ColReorder = [];
/* Sorting */
if ( oState.aaSorting ) {
// 1.10.0-
for ( i=0 ; i<oState.aaSorting.length ; i++ ) {
oState.aaSorting[i][0] = columns[ oState.aaSorting[i][0] ]._ColReorder_iOrigCol;
}
var aSearchCopy = $.extend( true, [], oState.aoSearchCols );
for ( i=0, iLen=columns.length ; i<iLen ; i++ )
{
iOrigColumn = columns[i]._ColReorder_iOrigCol;
/* Column filter */
oState.aoSearchCols[ iOrigColumn ] = aSearchCopy[i];
/* Visibility */
oState.abVisCols[ iOrigColumn ] = columns[i].bVisible;
/* Column reordering */
oState.ColReorder.push( iOrigColumn );
}
}
else if ( oState.order ) {
// 1.10.1+
for ( i=0 ; i<oState.order.length ; i++ ) {
oState.order[i][0] = columns[ oState.order[i][0] ]._ColReorder_iOrigCol;
}
var stateColumnsCopy = $.extend( true, [], oState.columns );
for ( i=0, iLen=columns.length ; i<iLen ; i++ )
{
iOrigColumn = columns[i]._ColReorder_iOrigCol;
/* Columns */
oState.columns[ iOrigColumn ] = stateColumnsCopy[i];
/* Column reordering */
oState.ColReorder.push( iOrigColumn );
}
}
} | javascript | function ( oState )
{
var i, iLen, aCopy, iOrigColumn;
var oSettings = this.s.dt;
var columns = oSettings.aoColumns;
oState.ColReorder = [];
/* Sorting */
if ( oState.aaSorting ) {
// 1.10.0-
for ( i=0 ; i<oState.aaSorting.length ; i++ ) {
oState.aaSorting[i][0] = columns[ oState.aaSorting[i][0] ]._ColReorder_iOrigCol;
}
var aSearchCopy = $.extend( true, [], oState.aoSearchCols );
for ( i=0, iLen=columns.length ; i<iLen ; i++ )
{
iOrigColumn = columns[i]._ColReorder_iOrigCol;
/* Column filter */
oState.aoSearchCols[ iOrigColumn ] = aSearchCopy[i];
/* Visibility */
oState.abVisCols[ iOrigColumn ] = columns[i].bVisible;
/* Column reordering */
oState.ColReorder.push( iOrigColumn );
}
}
else if ( oState.order ) {
// 1.10.1+
for ( i=0 ; i<oState.order.length ; i++ ) {
oState.order[i][0] = columns[ oState.order[i][0] ]._ColReorder_iOrigCol;
}
var stateColumnsCopy = $.extend( true, [], oState.columns );
for ( i=0, iLen=columns.length ; i<iLen ; i++ )
{
iOrigColumn = columns[i]._ColReorder_iOrigCol;
/* Columns */
oState.columns[ iOrigColumn ] = stateColumnsCopy[i];
/* Column reordering */
oState.ColReorder.push( iOrigColumn );
}
}
} | [
"function",
"(",
"oState",
")",
"{",
"var",
"i",
",",
"iLen",
",",
"aCopy",
",",
"iOrigColumn",
";",
"var",
"oSettings",
"=",
"this",
".",
"s",
".",
"dt",
";",
"var",
"columns",
"=",
"oSettings",
".",
"aoColumns",
";",
"oState",
".",
"ColReorder",
"=",
"[",
"]",
";",
"if",
"(",
"oState",
".",
"aaSorting",
")",
"{",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"oState",
".",
"aaSorting",
".",
"length",
";",
"i",
"++",
")",
"{",
"oState",
".",
"aaSorting",
"[",
"i",
"]",
"[",
"0",
"]",
"=",
"columns",
"[",
"oState",
".",
"aaSorting",
"[",
"i",
"]",
"[",
"0",
"]",
"]",
".",
"_ColReorder_iOrigCol",
";",
"}",
"var",
"aSearchCopy",
"=",
"$",
".",
"extend",
"(",
"true",
",",
"[",
"]",
",",
"oState",
".",
"aoSearchCols",
")",
";",
"for",
"(",
"i",
"=",
"0",
",",
"iLen",
"=",
"columns",
".",
"length",
";",
"i",
"<",
"iLen",
";",
"i",
"++",
")",
"{",
"iOrigColumn",
"=",
"columns",
"[",
"i",
"]",
".",
"_ColReorder_iOrigCol",
";",
"oState",
".",
"aoSearchCols",
"[",
"iOrigColumn",
"]",
"=",
"aSearchCopy",
"[",
"i",
"]",
";",
"oState",
".",
"abVisCols",
"[",
"iOrigColumn",
"]",
"=",
"columns",
"[",
"i",
"]",
".",
"bVisible",
";",
"oState",
".",
"ColReorder",
".",
"push",
"(",
"iOrigColumn",
")",
";",
"}",
"}",
"else",
"if",
"(",
"oState",
".",
"order",
")",
"{",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"oState",
".",
"order",
".",
"length",
";",
"i",
"++",
")",
"{",
"oState",
".",
"order",
"[",
"i",
"]",
"[",
"0",
"]",
"=",
"columns",
"[",
"oState",
".",
"order",
"[",
"i",
"]",
"[",
"0",
"]",
"]",
".",
"_ColReorder_iOrigCol",
";",
"}",
"var",
"stateColumnsCopy",
"=",
"$",
".",
"extend",
"(",
"true",
",",
"[",
"]",
",",
"oState",
".",
"columns",
")",
";",
"for",
"(",
"i",
"=",
"0",
",",
"iLen",
"=",
"columns",
".",
"length",
";",
"i",
"<",
"iLen",
";",
"i",
"++",
")",
"{",
"iOrigColumn",
"=",
"columns",
"[",
"i",
"]",
".",
"_ColReorder_iOrigCol",
";",
"oState",
".",
"columns",
"[",
"iOrigColumn",
"]",
"=",
"stateColumnsCopy",
"[",
"i",
"]",
";",
"oState",
".",
"ColReorder",
".",
"push",
"(",
"iOrigColumn",
")",
";",
"}",
"}",
"}"
]
| Because we change the indexes of columns in the table, relative to their starting point
we need to reorder the state columns to what they are at the starting point so we can
then rearrange them again on state load!
@method _fnStateSave
@param object oState DataTables state
@returns string JSON encoded cookie string for DataTables
@private | [
"Because",
"we",
"change",
"the",
"indexes",
"of",
"columns",
"in",
"the",
"table",
"relative",
"to",
"their",
"starting",
"point",
"we",
"need",
"to",
"reorder",
"the",
"state",
"columns",
"to",
"what",
"they",
"are",
"at",
"the",
"starting",
"point",
"so",
"we",
"can",
"then",
"rearrange",
"them",
"again",
"on",
"state",
"load!"
]
| c283370ec0f99a25db5bb7029a98b4febf8c5251 | https://github.com/S3bb1/ah-dashboard-plugin/blob/c283370ec0f99a25db5bb7029a98b4febf8c5251/public/dashboard/bower_components/admin-lte/plugins/datatables/extensions/ColReorder/js/dataTables.colReorder.js#L759-L809 | train |
|
S3bb1/ah-dashboard-plugin | public/dashboard/bower_components/admin-lte/plugins/datatables/extensions/ColReorder/js/dataTables.colReorder.js | function ( e, nTh )
{
var that = this;
/* Store information about the mouse position */
var target = $(e.target).closest('th, td');
var offset = target.offset();
var idx = parseInt( $(nTh).attr('data-column-index'), 10 );
if ( idx === undefined ) {
return;
}
this.s.mouse.startX = e.pageX;
this.s.mouse.startY = e.pageY;
this.s.mouse.offsetX = e.pageX - offset.left;
this.s.mouse.offsetY = e.pageY - offset.top;
this.s.mouse.target = this.s.dt.aoColumns[ idx ].nTh;//target[0];
this.s.mouse.targetIndex = idx;
this.s.mouse.fromIndex = idx;
this._fnRegions();
/* Add event handlers to the document */
$(document)
.on( 'mousemove.ColReorder', function (e) {
that._fnMouseMove.call( that, e );
} )
.on( 'mouseup.ColReorder', function (e) {
that._fnMouseUp.call( that, e );
} );
} | javascript | function ( e, nTh )
{
var that = this;
/* Store information about the mouse position */
var target = $(e.target).closest('th, td');
var offset = target.offset();
var idx = parseInt( $(nTh).attr('data-column-index'), 10 );
if ( idx === undefined ) {
return;
}
this.s.mouse.startX = e.pageX;
this.s.mouse.startY = e.pageY;
this.s.mouse.offsetX = e.pageX - offset.left;
this.s.mouse.offsetY = e.pageY - offset.top;
this.s.mouse.target = this.s.dt.aoColumns[ idx ].nTh;//target[0];
this.s.mouse.targetIndex = idx;
this.s.mouse.fromIndex = idx;
this._fnRegions();
/* Add event handlers to the document */
$(document)
.on( 'mousemove.ColReorder', function (e) {
that._fnMouseMove.call( that, e );
} )
.on( 'mouseup.ColReorder', function (e) {
that._fnMouseUp.call( that, e );
} );
} | [
"function",
"(",
"e",
",",
"nTh",
")",
"{",
"var",
"that",
"=",
"this",
";",
"var",
"target",
"=",
"$",
"(",
"e",
".",
"target",
")",
".",
"closest",
"(",
"'th, td'",
")",
";",
"var",
"offset",
"=",
"target",
".",
"offset",
"(",
")",
";",
"var",
"idx",
"=",
"parseInt",
"(",
"$",
"(",
"nTh",
")",
".",
"attr",
"(",
"'data-column-index'",
")",
",",
"10",
")",
";",
"if",
"(",
"idx",
"===",
"undefined",
")",
"{",
"return",
";",
"}",
"this",
".",
"s",
".",
"mouse",
".",
"startX",
"=",
"e",
".",
"pageX",
";",
"this",
".",
"s",
".",
"mouse",
".",
"startY",
"=",
"e",
".",
"pageY",
";",
"this",
".",
"s",
".",
"mouse",
".",
"offsetX",
"=",
"e",
".",
"pageX",
"-",
"offset",
".",
"left",
";",
"this",
".",
"s",
".",
"mouse",
".",
"offsetY",
"=",
"e",
".",
"pageY",
"-",
"offset",
".",
"top",
";",
"this",
".",
"s",
".",
"mouse",
".",
"target",
"=",
"this",
".",
"s",
".",
"dt",
".",
"aoColumns",
"[",
"idx",
"]",
".",
"nTh",
";",
"this",
".",
"s",
".",
"mouse",
".",
"targetIndex",
"=",
"idx",
";",
"this",
".",
"s",
".",
"mouse",
".",
"fromIndex",
"=",
"idx",
";",
"this",
".",
"_fnRegions",
"(",
")",
";",
"$",
"(",
"document",
")",
".",
"on",
"(",
"'mousemove.ColReorder'",
",",
"function",
"(",
"e",
")",
"{",
"that",
".",
"_fnMouseMove",
".",
"call",
"(",
"that",
",",
"e",
")",
";",
"}",
")",
".",
"on",
"(",
"'mouseup.ColReorder'",
",",
"function",
"(",
"e",
")",
"{",
"that",
".",
"_fnMouseUp",
".",
"call",
"(",
"that",
",",
"e",
")",
";",
"}",
")",
";",
"}"
]
| Mouse down on a TH element in the table header
@method _fnMouseDown
@param event e Mouse event
@param element nTh TH element to be dragged
@returns void
@private | [
"Mouse",
"down",
"on",
"a",
"TH",
"element",
"in",
"the",
"table",
"header"
]
| c283370ec0f99a25db5bb7029a98b4febf8c5251 | https://github.com/S3bb1/ah-dashboard-plugin/blob/c283370ec0f99a25db5bb7029a98b4febf8c5251/public/dashboard/bower_components/admin-lte/plugins/datatables/extensions/ColReorder/js/dataTables.colReorder.js#L842-L873 | train |
|
S3bb1/ah-dashboard-plugin | public/dashboard/bower_components/admin-lte/plugins/datatables/extensions/ColReorder/js/dataTables.colReorder.js | function ( e )
{
var that = this;
if ( this.dom.drag === null )
{
/* Only create the drag element if the mouse has moved a specific distance from the start
* point - this allows the user to make small mouse movements when sorting and not have a
* possibly confusing drag element showing up
*/
if ( Math.pow(
Math.pow(e.pageX - this.s.mouse.startX, 2) +
Math.pow(e.pageY - this.s.mouse.startY, 2), 0.5 ) < 5 )
{
return;
}
this._fnCreateDragNode();
}
/* Position the element - we respect where in the element the click occured */
this.dom.drag.css( {
left: e.pageX - this.s.mouse.offsetX,
top: e.pageY - this.s.mouse.offsetY
} );
/* Based on the current mouse position, calculate where the insert should go */
var bSet = false;
var lastToIndex = this.s.mouse.toIndex;
for ( var i=1, iLen=this.s.aoTargets.length ; i<iLen ; i++ )
{
if ( e.pageX < this.s.aoTargets[i-1].x + ((this.s.aoTargets[i].x-this.s.aoTargets[i-1].x)/2) )
{
this.dom.pointer.css( 'left', this.s.aoTargets[i-1].x );
this.s.mouse.toIndex = this.s.aoTargets[i-1].to;
bSet = true;
break;
}
}
// The insert element wasn't positioned in the array (less than
// operator), so we put it at the end
if ( !bSet )
{
this.dom.pointer.css( 'left', this.s.aoTargets[this.s.aoTargets.length-1].x );
this.s.mouse.toIndex = this.s.aoTargets[this.s.aoTargets.length-1].to;
}
// Perform reordering if realtime updating is on and the column has moved
if ( this.s.init.bRealtime && lastToIndex !== this.s.mouse.toIndex ) {
this.s.dt.oInstance.fnColReorder( this.s.mouse.fromIndex, this.s.mouse.toIndex );
this.s.mouse.fromIndex = this.s.mouse.toIndex;
this._fnRegions();
}
} | javascript | function ( e )
{
var that = this;
if ( this.dom.drag === null )
{
/* Only create the drag element if the mouse has moved a specific distance from the start
* point - this allows the user to make small mouse movements when sorting and not have a
* possibly confusing drag element showing up
*/
if ( Math.pow(
Math.pow(e.pageX - this.s.mouse.startX, 2) +
Math.pow(e.pageY - this.s.mouse.startY, 2), 0.5 ) < 5 )
{
return;
}
this._fnCreateDragNode();
}
/* Position the element - we respect where in the element the click occured */
this.dom.drag.css( {
left: e.pageX - this.s.mouse.offsetX,
top: e.pageY - this.s.mouse.offsetY
} );
/* Based on the current mouse position, calculate where the insert should go */
var bSet = false;
var lastToIndex = this.s.mouse.toIndex;
for ( var i=1, iLen=this.s.aoTargets.length ; i<iLen ; i++ )
{
if ( e.pageX < this.s.aoTargets[i-1].x + ((this.s.aoTargets[i].x-this.s.aoTargets[i-1].x)/2) )
{
this.dom.pointer.css( 'left', this.s.aoTargets[i-1].x );
this.s.mouse.toIndex = this.s.aoTargets[i-1].to;
bSet = true;
break;
}
}
// The insert element wasn't positioned in the array (less than
// operator), so we put it at the end
if ( !bSet )
{
this.dom.pointer.css( 'left', this.s.aoTargets[this.s.aoTargets.length-1].x );
this.s.mouse.toIndex = this.s.aoTargets[this.s.aoTargets.length-1].to;
}
// Perform reordering if realtime updating is on and the column has moved
if ( this.s.init.bRealtime && lastToIndex !== this.s.mouse.toIndex ) {
this.s.dt.oInstance.fnColReorder( this.s.mouse.fromIndex, this.s.mouse.toIndex );
this.s.mouse.fromIndex = this.s.mouse.toIndex;
this._fnRegions();
}
} | [
"function",
"(",
"e",
")",
"{",
"var",
"that",
"=",
"this",
";",
"if",
"(",
"this",
".",
"dom",
".",
"drag",
"===",
"null",
")",
"{",
"if",
"(",
"Math",
".",
"pow",
"(",
"Math",
".",
"pow",
"(",
"e",
".",
"pageX",
"-",
"this",
".",
"s",
".",
"mouse",
".",
"startX",
",",
"2",
")",
"+",
"Math",
".",
"pow",
"(",
"e",
".",
"pageY",
"-",
"this",
".",
"s",
".",
"mouse",
".",
"startY",
",",
"2",
")",
",",
"0.5",
")",
"<",
"5",
")",
"{",
"return",
";",
"}",
"this",
".",
"_fnCreateDragNode",
"(",
")",
";",
"}",
"this",
".",
"dom",
".",
"drag",
".",
"css",
"(",
"{",
"left",
":",
"e",
".",
"pageX",
"-",
"this",
".",
"s",
".",
"mouse",
".",
"offsetX",
",",
"top",
":",
"e",
".",
"pageY",
"-",
"this",
".",
"s",
".",
"mouse",
".",
"offsetY",
"}",
")",
";",
"var",
"bSet",
"=",
"false",
";",
"var",
"lastToIndex",
"=",
"this",
".",
"s",
".",
"mouse",
".",
"toIndex",
";",
"for",
"(",
"var",
"i",
"=",
"1",
",",
"iLen",
"=",
"this",
".",
"s",
".",
"aoTargets",
".",
"length",
";",
"i",
"<",
"iLen",
";",
"i",
"++",
")",
"{",
"if",
"(",
"e",
".",
"pageX",
"<",
"this",
".",
"s",
".",
"aoTargets",
"[",
"i",
"-",
"1",
"]",
".",
"x",
"+",
"(",
"(",
"this",
".",
"s",
".",
"aoTargets",
"[",
"i",
"]",
".",
"x",
"-",
"this",
".",
"s",
".",
"aoTargets",
"[",
"i",
"-",
"1",
"]",
".",
"x",
")",
"/",
"2",
")",
")",
"{",
"this",
".",
"dom",
".",
"pointer",
".",
"css",
"(",
"'left'",
",",
"this",
".",
"s",
".",
"aoTargets",
"[",
"i",
"-",
"1",
"]",
".",
"x",
")",
";",
"this",
".",
"s",
".",
"mouse",
".",
"toIndex",
"=",
"this",
".",
"s",
".",
"aoTargets",
"[",
"i",
"-",
"1",
"]",
".",
"to",
";",
"bSet",
"=",
"true",
";",
"break",
";",
"}",
"}",
"if",
"(",
"!",
"bSet",
")",
"{",
"this",
".",
"dom",
".",
"pointer",
".",
"css",
"(",
"'left'",
",",
"this",
".",
"s",
".",
"aoTargets",
"[",
"this",
".",
"s",
".",
"aoTargets",
".",
"length",
"-",
"1",
"]",
".",
"x",
")",
";",
"this",
".",
"s",
".",
"mouse",
".",
"toIndex",
"=",
"this",
".",
"s",
".",
"aoTargets",
"[",
"this",
".",
"s",
".",
"aoTargets",
".",
"length",
"-",
"1",
"]",
".",
"to",
";",
"}",
"if",
"(",
"this",
".",
"s",
".",
"init",
".",
"bRealtime",
"&&",
"lastToIndex",
"!==",
"this",
".",
"s",
".",
"mouse",
".",
"toIndex",
")",
"{",
"this",
".",
"s",
".",
"dt",
".",
"oInstance",
".",
"fnColReorder",
"(",
"this",
".",
"s",
".",
"mouse",
".",
"fromIndex",
",",
"this",
".",
"s",
".",
"mouse",
".",
"toIndex",
")",
";",
"this",
".",
"s",
".",
"mouse",
".",
"fromIndex",
"=",
"this",
".",
"s",
".",
"mouse",
".",
"toIndex",
";",
"this",
".",
"_fnRegions",
"(",
")",
";",
"}",
"}"
]
| Deal with a mouse move event while dragging a node
@method _fnMouseMove
@param event e Mouse event
@returns void
@private | [
"Deal",
"with",
"a",
"mouse",
"move",
"event",
"while",
"dragging",
"a",
"node"
]
| c283370ec0f99a25db5bb7029a98b4febf8c5251 | https://github.com/S3bb1/ah-dashboard-plugin/blob/c283370ec0f99a25db5bb7029a98b4febf8c5251/public/dashboard/bower_components/admin-lte/plugins/datatables/extensions/ColReorder/js/dataTables.colReorder.js#L883-L937 | train |
|
S3bb1/ah-dashboard-plugin | public/dashboard/bower_components/admin-lte/plugins/datatables/extensions/ColReorder/js/dataTables.colReorder.js | function ( e )
{
var that = this;
$(document).off( 'mousemove.ColReorder mouseup.ColReorder' );
if ( this.dom.drag !== null )
{
/* Remove the guide elements */
this.dom.drag.remove();
this.dom.pointer.remove();
this.dom.drag = null;
this.dom.pointer = null;
/* Actually do the reorder */
this.s.dt.oInstance.fnColReorder( this.s.mouse.fromIndex, this.s.mouse.toIndex );
this._fnSetColumnIndexes();
/* When scrolling we need to recalculate the column sizes to allow for the shift */
if ( this.s.dt.oScroll.sX !== "" || this.s.dt.oScroll.sY !== "" )
{
this.s.dt.oInstance.fnAdjustColumnSizing( false );
}
/* Save the state */
this.s.dt.oInstance.oApi._fnSaveState( this.s.dt );
if ( this.s.reorderCallback !== null )
{
this.s.reorderCallback.call( this );
}
}
} | javascript | function ( e )
{
var that = this;
$(document).off( 'mousemove.ColReorder mouseup.ColReorder' );
if ( this.dom.drag !== null )
{
/* Remove the guide elements */
this.dom.drag.remove();
this.dom.pointer.remove();
this.dom.drag = null;
this.dom.pointer = null;
/* Actually do the reorder */
this.s.dt.oInstance.fnColReorder( this.s.mouse.fromIndex, this.s.mouse.toIndex );
this._fnSetColumnIndexes();
/* When scrolling we need to recalculate the column sizes to allow for the shift */
if ( this.s.dt.oScroll.sX !== "" || this.s.dt.oScroll.sY !== "" )
{
this.s.dt.oInstance.fnAdjustColumnSizing( false );
}
/* Save the state */
this.s.dt.oInstance.oApi._fnSaveState( this.s.dt );
if ( this.s.reorderCallback !== null )
{
this.s.reorderCallback.call( this );
}
}
} | [
"function",
"(",
"e",
")",
"{",
"var",
"that",
"=",
"this",
";",
"$",
"(",
"document",
")",
".",
"off",
"(",
"'mousemove.ColReorder mouseup.ColReorder'",
")",
";",
"if",
"(",
"this",
".",
"dom",
".",
"drag",
"!==",
"null",
")",
"{",
"this",
".",
"dom",
".",
"drag",
".",
"remove",
"(",
")",
";",
"this",
".",
"dom",
".",
"pointer",
".",
"remove",
"(",
")",
";",
"this",
".",
"dom",
".",
"drag",
"=",
"null",
";",
"this",
".",
"dom",
".",
"pointer",
"=",
"null",
";",
"this",
".",
"s",
".",
"dt",
".",
"oInstance",
".",
"fnColReorder",
"(",
"this",
".",
"s",
".",
"mouse",
".",
"fromIndex",
",",
"this",
".",
"s",
".",
"mouse",
".",
"toIndex",
")",
";",
"this",
".",
"_fnSetColumnIndexes",
"(",
")",
";",
"if",
"(",
"this",
".",
"s",
".",
"dt",
".",
"oScroll",
".",
"sX",
"!==",
"\"\"",
"||",
"this",
".",
"s",
".",
"dt",
".",
"oScroll",
".",
"sY",
"!==",
"\"\"",
")",
"{",
"this",
".",
"s",
".",
"dt",
".",
"oInstance",
".",
"fnAdjustColumnSizing",
"(",
"false",
")",
";",
"}",
"this",
".",
"s",
".",
"dt",
".",
"oInstance",
".",
"oApi",
".",
"_fnSaveState",
"(",
"this",
".",
"s",
".",
"dt",
")",
";",
"if",
"(",
"this",
".",
"s",
".",
"reorderCallback",
"!==",
"null",
")",
"{",
"this",
".",
"s",
".",
"reorderCallback",
".",
"call",
"(",
"this",
")",
";",
"}",
"}",
"}"
]
| Finish off the mouse drag and insert the column where needed
@method _fnMouseUp
@param event e Mouse event
@returns void
@private | [
"Finish",
"off",
"the",
"mouse",
"drag",
"and",
"insert",
"the",
"column",
"where",
"needed"
]
| c283370ec0f99a25db5bb7029a98b4febf8c5251 | https://github.com/S3bb1/ah-dashboard-plugin/blob/c283370ec0f99a25db5bb7029a98b4febf8c5251/public/dashboard/bower_components/admin-lte/plugins/datatables/extensions/ColReorder/js/dataTables.colReorder.js#L947-L979 | train |
|
S3bb1/ah-dashboard-plugin | public/dashboard/bower_components/admin-lte/plugins/datatables/extensions/ColReorder/js/dataTables.colReorder.js | function ()
{
var aoColumns = this.s.dt.aoColumns;
this.s.aoTargets.splice( 0, this.s.aoTargets.length );
this.s.aoTargets.push( {
"x": $(this.s.dt.nTable).offset().left,
"to": 0
} );
var iToPoint = 0;
for ( var i=0, iLen=aoColumns.length ; i<iLen ; i++ )
{
/* For the column / header in question, we want it's position to remain the same if the
* position is just to it's immediate left or right, so we only incremement the counter for
* other columns
*/
if ( i != this.s.mouse.fromIndex )
{
iToPoint++;
}
if ( aoColumns[i].bVisible )
{
this.s.aoTargets.push( {
"x": $(aoColumns[i].nTh).offset().left + $(aoColumns[i].nTh).outerWidth(),
"to": iToPoint
} );
}
}
/* Disallow columns for being reordered by drag and drop, counting right to left */
if ( this.s.fixedRight !== 0 )
{
this.s.aoTargets.splice( this.s.aoTargets.length - this.s.fixedRight );
}
/* Disallow columns for being reordered by drag and drop, counting left to right */
if ( this.s.fixed !== 0 )
{
this.s.aoTargets.splice( 0, this.s.fixed );
}
} | javascript | function ()
{
var aoColumns = this.s.dt.aoColumns;
this.s.aoTargets.splice( 0, this.s.aoTargets.length );
this.s.aoTargets.push( {
"x": $(this.s.dt.nTable).offset().left,
"to": 0
} );
var iToPoint = 0;
for ( var i=0, iLen=aoColumns.length ; i<iLen ; i++ )
{
/* For the column / header in question, we want it's position to remain the same if the
* position is just to it's immediate left or right, so we only incremement the counter for
* other columns
*/
if ( i != this.s.mouse.fromIndex )
{
iToPoint++;
}
if ( aoColumns[i].bVisible )
{
this.s.aoTargets.push( {
"x": $(aoColumns[i].nTh).offset().left + $(aoColumns[i].nTh).outerWidth(),
"to": iToPoint
} );
}
}
/* Disallow columns for being reordered by drag and drop, counting right to left */
if ( this.s.fixedRight !== 0 )
{
this.s.aoTargets.splice( this.s.aoTargets.length - this.s.fixedRight );
}
/* Disallow columns for being reordered by drag and drop, counting left to right */
if ( this.s.fixed !== 0 )
{
this.s.aoTargets.splice( 0, this.s.fixed );
}
} | [
"function",
"(",
")",
"{",
"var",
"aoColumns",
"=",
"this",
".",
"s",
".",
"dt",
".",
"aoColumns",
";",
"this",
".",
"s",
".",
"aoTargets",
".",
"splice",
"(",
"0",
",",
"this",
".",
"s",
".",
"aoTargets",
".",
"length",
")",
";",
"this",
".",
"s",
".",
"aoTargets",
".",
"push",
"(",
"{",
"\"x\"",
":",
"$",
"(",
"this",
".",
"s",
".",
"dt",
".",
"nTable",
")",
".",
"offset",
"(",
")",
".",
"left",
",",
"\"to\"",
":",
"0",
"}",
")",
";",
"var",
"iToPoint",
"=",
"0",
";",
"for",
"(",
"var",
"i",
"=",
"0",
",",
"iLen",
"=",
"aoColumns",
".",
"length",
";",
"i",
"<",
"iLen",
";",
"i",
"++",
")",
"{",
"if",
"(",
"i",
"!=",
"this",
".",
"s",
".",
"mouse",
".",
"fromIndex",
")",
"{",
"iToPoint",
"++",
";",
"}",
"if",
"(",
"aoColumns",
"[",
"i",
"]",
".",
"bVisible",
")",
"{",
"this",
".",
"s",
".",
"aoTargets",
".",
"push",
"(",
"{",
"\"x\"",
":",
"$",
"(",
"aoColumns",
"[",
"i",
"]",
".",
"nTh",
")",
".",
"offset",
"(",
")",
".",
"left",
"+",
"$",
"(",
"aoColumns",
"[",
"i",
"]",
".",
"nTh",
")",
".",
"outerWidth",
"(",
")",
",",
"\"to\"",
":",
"iToPoint",
"}",
")",
";",
"}",
"}",
"if",
"(",
"this",
".",
"s",
".",
"fixedRight",
"!==",
"0",
")",
"{",
"this",
".",
"s",
".",
"aoTargets",
".",
"splice",
"(",
"this",
".",
"s",
".",
"aoTargets",
".",
"length",
"-",
"this",
".",
"s",
".",
"fixedRight",
")",
";",
"}",
"if",
"(",
"this",
".",
"s",
".",
"fixed",
"!==",
"0",
")",
"{",
"this",
".",
"s",
".",
"aoTargets",
".",
"splice",
"(",
"0",
",",
"this",
".",
"s",
".",
"fixed",
")",
";",
"}",
"}"
]
| Calculate a cached array with the points of the column inserts, and the
'to' points
@method _fnRegions
@returns void
@private | [
"Calculate",
"a",
"cached",
"array",
"with",
"the",
"points",
"of",
"the",
"column",
"inserts",
"and",
"the",
"to",
"points"
]
| c283370ec0f99a25db5bb7029a98b4febf8c5251 | https://github.com/S3bb1/ah-dashboard-plugin/blob/c283370ec0f99a25db5bb7029a98b4febf8c5251/public/dashboard/bower_components/admin-lte/plugins/datatables/extensions/ColReorder/js/dataTables.colReorder.js#L989-L1032 | train |
|
S3bb1/ah-dashboard-plugin | public/dashboard/bower_components/admin-lte/plugins/datatables/extensions/ColReorder/js/dataTables.colReorder.js | function ()
{
var scrolling = this.s.dt.oScroll.sX !== "" || this.s.dt.oScroll.sY !== "";
var origCell = this.s.dt.aoColumns[ this.s.mouse.targetIndex ].nTh;
var origTr = origCell.parentNode;
var origThead = origTr.parentNode;
var origTable = origThead.parentNode;
var cloneCell = $(origCell).clone();
// This is a slightly odd combination of jQuery and DOM, but it is the
// fastest and least resource intensive way I could think of cloning
// the table with just a single header cell in it.
this.dom.drag = $(origTable.cloneNode(false))
.addClass( 'DTCR_clonedTable' )
.append(
$(origThead.cloneNode(false)).append(
$(origTr.cloneNode(false)).append(
cloneCell[0]
)
)
)
.css( {
position: 'absolute',
top: 0,
left: 0,
width: $(origCell).outerWidth(),
height: $(origCell).outerHeight()
} )
.appendTo( 'body' );
this.dom.pointer = $('<div></div>')
.addClass( 'DTCR_pointer' )
.css( {
position: 'absolute',
top: scrolling ?
$('div.dataTables_scroll', this.s.dt.nTableWrapper).offset().top :
$(this.s.dt.nTable).offset().top,
height : scrolling ?
$('div.dataTables_scroll', this.s.dt.nTableWrapper).height() :
$(this.s.dt.nTable).height()
} )
.appendTo( 'body' );
} | javascript | function ()
{
var scrolling = this.s.dt.oScroll.sX !== "" || this.s.dt.oScroll.sY !== "";
var origCell = this.s.dt.aoColumns[ this.s.mouse.targetIndex ].nTh;
var origTr = origCell.parentNode;
var origThead = origTr.parentNode;
var origTable = origThead.parentNode;
var cloneCell = $(origCell).clone();
// This is a slightly odd combination of jQuery and DOM, but it is the
// fastest and least resource intensive way I could think of cloning
// the table with just a single header cell in it.
this.dom.drag = $(origTable.cloneNode(false))
.addClass( 'DTCR_clonedTable' )
.append(
$(origThead.cloneNode(false)).append(
$(origTr.cloneNode(false)).append(
cloneCell[0]
)
)
)
.css( {
position: 'absolute',
top: 0,
left: 0,
width: $(origCell).outerWidth(),
height: $(origCell).outerHeight()
} )
.appendTo( 'body' );
this.dom.pointer = $('<div></div>')
.addClass( 'DTCR_pointer' )
.css( {
position: 'absolute',
top: scrolling ?
$('div.dataTables_scroll', this.s.dt.nTableWrapper).offset().top :
$(this.s.dt.nTable).offset().top,
height : scrolling ?
$('div.dataTables_scroll', this.s.dt.nTableWrapper).height() :
$(this.s.dt.nTable).height()
} )
.appendTo( 'body' );
} | [
"function",
"(",
")",
"{",
"var",
"scrolling",
"=",
"this",
".",
"s",
".",
"dt",
".",
"oScroll",
".",
"sX",
"!==",
"\"\"",
"||",
"this",
".",
"s",
".",
"dt",
".",
"oScroll",
".",
"sY",
"!==",
"\"\"",
";",
"var",
"origCell",
"=",
"this",
".",
"s",
".",
"dt",
".",
"aoColumns",
"[",
"this",
".",
"s",
".",
"mouse",
".",
"targetIndex",
"]",
".",
"nTh",
";",
"var",
"origTr",
"=",
"origCell",
".",
"parentNode",
";",
"var",
"origThead",
"=",
"origTr",
".",
"parentNode",
";",
"var",
"origTable",
"=",
"origThead",
".",
"parentNode",
";",
"var",
"cloneCell",
"=",
"$",
"(",
"origCell",
")",
".",
"clone",
"(",
")",
";",
"this",
".",
"dom",
".",
"drag",
"=",
"$",
"(",
"origTable",
".",
"cloneNode",
"(",
"false",
")",
")",
".",
"addClass",
"(",
"'DTCR_clonedTable'",
")",
".",
"append",
"(",
"$",
"(",
"origThead",
".",
"cloneNode",
"(",
"false",
")",
")",
".",
"append",
"(",
"$",
"(",
"origTr",
".",
"cloneNode",
"(",
"false",
")",
")",
".",
"append",
"(",
"cloneCell",
"[",
"0",
"]",
")",
")",
")",
".",
"css",
"(",
"{",
"position",
":",
"'absolute'",
",",
"top",
":",
"0",
",",
"left",
":",
"0",
",",
"width",
":",
"$",
"(",
"origCell",
")",
".",
"outerWidth",
"(",
")",
",",
"height",
":",
"$",
"(",
"origCell",
")",
".",
"outerHeight",
"(",
")",
"}",
")",
".",
"appendTo",
"(",
"'body'",
")",
";",
"this",
".",
"dom",
".",
"pointer",
"=",
"$",
"(",
"'<div></div>'",
")",
".",
"addClass",
"(",
"'DTCR_pointer'",
")",
".",
"css",
"(",
"{",
"position",
":",
"'absolute'",
",",
"top",
":",
"scrolling",
"?",
"$",
"(",
"'div.dataTables_scroll'",
",",
"this",
".",
"s",
".",
"dt",
".",
"nTableWrapper",
")",
".",
"offset",
"(",
")",
".",
"top",
":",
"$",
"(",
"this",
".",
"s",
".",
"dt",
".",
"nTable",
")",
".",
"offset",
"(",
")",
".",
"top",
",",
"height",
":",
"scrolling",
"?",
"$",
"(",
"'div.dataTables_scroll'",
",",
"this",
".",
"s",
".",
"dt",
".",
"nTableWrapper",
")",
".",
"height",
"(",
")",
":",
"$",
"(",
"this",
".",
"s",
".",
"dt",
".",
"nTable",
")",
".",
"height",
"(",
")",
"}",
")",
".",
"appendTo",
"(",
"'body'",
")",
";",
"}"
]
| Copy the TH element that is being drags so the user has the idea that they are actually
moving it around the page.
@method _fnCreateDragNode
@returns void
@private | [
"Copy",
"the",
"TH",
"element",
"that",
"is",
"being",
"drags",
"so",
"the",
"user",
"has",
"the",
"idea",
"that",
"they",
"are",
"actually",
"moving",
"it",
"around",
"the",
"page",
"."
]
| c283370ec0f99a25db5bb7029a98b4febf8c5251 | https://github.com/S3bb1/ah-dashboard-plugin/blob/c283370ec0f99a25db5bb7029a98b4febf8c5251/public/dashboard/bower_components/admin-lte/plugins/datatables/extensions/ColReorder/js/dataTables.colReorder.js#L1042-L1085 | train |
|
S3bb1/ah-dashboard-plugin | public/dashboard/bower_components/admin-lte/plugins/datatables/extensions/ColReorder/js/dataTables.colReorder.js | function ()
{
var i, iLen;
for ( i=0, iLen=this.s.dt.aoDrawCallback.length ; i<iLen ; i++ )
{
if ( this.s.dt.aoDrawCallback[i].sName === 'ColReorder_Pre' )
{
this.s.dt.aoDrawCallback.splice( i, 1 );
break;
}
}
$(this.s.dt.nTHead).find( '*' ).off( '.ColReorder' );
$.each( this.s.dt.aoColumns, function (i, column) {
$(column.nTh).removeAttr('data-column-index');
} );
this.s.dt._colReorder = null;
this.s = null;
} | javascript | function ()
{
var i, iLen;
for ( i=0, iLen=this.s.dt.aoDrawCallback.length ; i<iLen ; i++ )
{
if ( this.s.dt.aoDrawCallback[i].sName === 'ColReorder_Pre' )
{
this.s.dt.aoDrawCallback.splice( i, 1 );
break;
}
}
$(this.s.dt.nTHead).find( '*' ).off( '.ColReorder' );
$.each( this.s.dt.aoColumns, function (i, column) {
$(column.nTh).removeAttr('data-column-index');
} );
this.s.dt._colReorder = null;
this.s = null;
} | [
"function",
"(",
")",
"{",
"var",
"i",
",",
"iLen",
";",
"for",
"(",
"i",
"=",
"0",
",",
"iLen",
"=",
"this",
".",
"s",
".",
"dt",
".",
"aoDrawCallback",
".",
"length",
";",
"i",
"<",
"iLen",
";",
"i",
"++",
")",
"{",
"if",
"(",
"this",
".",
"s",
".",
"dt",
".",
"aoDrawCallback",
"[",
"i",
"]",
".",
"sName",
"===",
"'ColReorder_Pre'",
")",
"{",
"this",
".",
"s",
".",
"dt",
".",
"aoDrawCallback",
".",
"splice",
"(",
"i",
",",
"1",
")",
";",
"break",
";",
"}",
"}",
"$",
"(",
"this",
".",
"s",
".",
"dt",
".",
"nTHead",
")",
".",
"find",
"(",
"'*'",
")",
".",
"off",
"(",
"'.ColReorder'",
")",
";",
"$",
".",
"each",
"(",
"this",
".",
"s",
".",
"dt",
".",
"aoColumns",
",",
"function",
"(",
"i",
",",
"column",
")",
"{",
"$",
"(",
"column",
".",
"nTh",
")",
".",
"removeAttr",
"(",
"'data-column-index'",
")",
";",
"}",
")",
";",
"this",
".",
"s",
".",
"dt",
".",
"_colReorder",
"=",
"null",
";",
"this",
".",
"s",
"=",
"null",
";",
"}"
]
| Clean up ColReorder memory references and event handlers
@method _fnDestroy
@returns void
@private | [
"Clean",
"up",
"ColReorder",
"memory",
"references",
"and",
"event",
"handlers"
]
| c283370ec0f99a25db5bb7029a98b4febf8c5251 | https://github.com/S3bb1/ah-dashboard-plugin/blob/c283370ec0f99a25db5bb7029a98b4febf8c5251/public/dashboard/bower_components/admin-lte/plugins/datatables/extensions/ColReorder/js/dataTables.colReorder.js#L1093-L1114 | train |
|
S3bb1/ah-dashboard-plugin | public/dashboard/bower_components/admin-lte/plugins/datatables/extensions/ColReorder/js/dataTables.colReorder.js | function ()
{
$.each( this.s.dt.aoColumns, function (i, column) {
$(column.nTh).attr('data-column-index', i);
} );
} | javascript | function ()
{
$.each( this.s.dt.aoColumns, function (i, column) {
$(column.nTh).attr('data-column-index', i);
} );
} | [
"function",
"(",
")",
"{",
"$",
".",
"each",
"(",
"this",
".",
"s",
".",
"dt",
".",
"aoColumns",
",",
"function",
"(",
"i",
",",
"column",
")",
"{",
"$",
"(",
"column",
".",
"nTh",
")",
".",
"attr",
"(",
"'data-column-index'",
",",
"i",
")",
";",
"}",
")",
";",
"}"
]
| Add a data attribute to the column headers, so we know the index of
the row to be reordered. This allows fast detection of the index, and
for this plug-in to work with FixedHeader which clones the nodes.
@private | [
"Add",
"a",
"data",
"attribute",
"to",
"the",
"column",
"headers",
"so",
"we",
"know",
"the",
"index",
"of",
"the",
"row",
"to",
"be",
"reordered",
".",
"This",
"allows",
"fast",
"detection",
"of",
"the",
"index",
"and",
"for",
"this",
"plug",
"-",
"in",
"to",
"work",
"with",
"FixedHeader",
"which",
"clones",
"the",
"nodes",
"."
]
| c283370ec0f99a25db5bb7029a98b4febf8c5251 | https://github.com/S3bb1/ah-dashboard-plugin/blob/c283370ec0f99a25db5bb7029a98b4febf8c5251/public/dashboard/bower_components/admin-lte/plugins/datatables/extensions/ColReorder/js/dataTables.colReorder.js#L1123-L1128 | train |
|
Mozu/grunt-mozu-appdev-sync | tasks/mozusync.js | function() {
return appdev.getMetadata(['./assets/functions.json']).then(function() {
if (!appdev.client.context['user-claims']) {
grunt.fail.fatal('failed to authenticate to Mozu');
done();
return false;
}
return false;
}).catch(
function(err) {
grunt.fail.fatal('failed to authenticate to Mozu');
done();
return true;
});
} | javascript | function() {
return appdev.getMetadata(['./assets/functions.json']).then(function() {
if (!appdev.client.context['user-claims']) {
grunt.fail.fatal('failed to authenticate to Mozu');
done();
return false;
}
return false;
}).catch(
function(err) {
grunt.fail.fatal('failed to authenticate to Mozu');
done();
return true;
});
} | [
"function",
"(",
")",
"{",
"return",
"appdev",
".",
"getMetadata",
"(",
"[",
"'./assets/functions.json'",
"]",
")",
".",
"then",
"(",
"function",
"(",
")",
"{",
"if",
"(",
"!",
"appdev",
".",
"client",
".",
"context",
"[",
"'user-claims'",
"]",
")",
"{",
"grunt",
".",
"fail",
".",
"fatal",
"(",
"'failed to authenticate to Mozu'",
")",
";",
"done",
"(",
")",
";",
"return",
"false",
";",
"}",
"return",
"false",
";",
"}",
")",
".",
"catch",
"(",
"function",
"(",
"err",
")",
"{",
"grunt",
".",
"fail",
".",
"fatal",
"(",
"'failed to authenticate to Mozu'",
")",
";",
"done",
"(",
")",
";",
"return",
"true",
";",
"}",
")",
";",
"}"
]
| add a single get call to initialize the credentials. Paralallezing calls caused issues reading from the console . | [
"add",
"a",
"single",
"get",
"call",
"to",
"initialize",
"the",
"credentials",
".",
"Paralallezing",
"calls",
"caused",
"issues",
"reading",
"from",
"the",
"console",
"."
]
| 5eb27b91113c8b30420404b767895bcb7e9a92b5 | https://github.com/Mozu/grunt-mozu-appdev-sync/blob/5eb27b91113c8b30420404b767895bcb7e9a92b5/tasks/mozusync.js#L246-L260 | train |
|
tywei90/arr-del | index.js | arrDel | function arrDel(arr, indexArr) {
// check params
if (arr == null) {
return [];
}else if(Object.prototype.toString.call(arr) !== "[object Array]"){
throw new TypeError('PARAM MUST BE ARRAY');
}
if(indexArr == null){
return arr
}else if(Object.prototype.toString.call(indexArr) !== "[object Array]"){
throw new TypeError('PARAM MUST BE ARRAY');
}
var arrLen = arr.length;
for(var i=0, len=indexArr.length; i < len; i++){
if(typeof indexArr[i] !== "number"){
throw new TypeError('PARAM MUST BE NUMBER ARRAY');
}
if(Math.abs(indexArr[i]) > arrLen){
indexArr[i] = arrLen + 1;
}
if(indexArr[i] >= -arrLen && indexArr[i] < 0){
indexArr[i] = indexArr[i] + arrLen;
}
}
// first sort indexArr, then remove redupliction
indexArr.sort(function(a, b){
return a - b
})
var tmpArr = [];
for(var i=0, len=indexArr.length; i < len; i++){
if(tmpArr.indexOf(indexArr[i]) == -1){
tmpArr.push(indexArr[i])
}
}
// should not change the value of input arr
var outArr = JSON.parse(JSON.stringify(arr));
if (arr.length === 0) {
return [];
}
for (var i = 0, len = tmpArr.length; i < len; i++) {
outArr.splice(tmpArr[i] - i, 1);
}
return outArr
} | javascript | function arrDel(arr, indexArr) {
// check params
if (arr == null) {
return [];
}else if(Object.prototype.toString.call(arr) !== "[object Array]"){
throw new TypeError('PARAM MUST BE ARRAY');
}
if(indexArr == null){
return arr
}else if(Object.prototype.toString.call(indexArr) !== "[object Array]"){
throw new TypeError('PARAM MUST BE ARRAY');
}
var arrLen = arr.length;
for(var i=0, len=indexArr.length; i < len; i++){
if(typeof indexArr[i] !== "number"){
throw new TypeError('PARAM MUST BE NUMBER ARRAY');
}
if(Math.abs(indexArr[i]) > arrLen){
indexArr[i] = arrLen + 1;
}
if(indexArr[i] >= -arrLen && indexArr[i] < 0){
indexArr[i] = indexArr[i] + arrLen;
}
}
// first sort indexArr, then remove redupliction
indexArr.sort(function(a, b){
return a - b
})
var tmpArr = [];
for(var i=0, len=indexArr.length; i < len; i++){
if(tmpArr.indexOf(indexArr[i]) == -1){
tmpArr.push(indexArr[i])
}
}
// should not change the value of input arr
var outArr = JSON.parse(JSON.stringify(arr));
if (arr.length === 0) {
return [];
}
for (var i = 0, len = tmpArr.length; i < len; i++) {
outArr.splice(tmpArr[i] - i, 1);
}
return outArr
} | [
"function",
"arrDel",
"(",
"arr",
",",
"indexArr",
")",
"{",
"if",
"(",
"arr",
"==",
"null",
")",
"{",
"return",
"[",
"]",
";",
"}",
"else",
"if",
"(",
"Object",
".",
"prototype",
".",
"toString",
".",
"call",
"(",
"arr",
")",
"!==",
"\"[object Array]\"",
")",
"{",
"throw",
"new",
"TypeError",
"(",
"'PARAM MUST BE ARRAY'",
")",
";",
"}",
"if",
"(",
"indexArr",
"==",
"null",
")",
"{",
"return",
"arr",
"}",
"else",
"if",
"(",
"Object",
".",
"prototype",
".",
"toString",
".",
"call",
"(",
"indexArr",
")",
"!==",
"\"[object Array]\"",
")",
"{",
"throw",
"new",
"TypeError",
"(",
"'PARAM MUST BE ARRAY'",
")",
";",
"}",
"var",
"arrLen",
"=",
"arr",
".",
"length",
";",
"for",
"(",
"var",
"i",
"=",
"0",
",",
"len",
"=",
"indexArr",
".",
"length",
";",
"i",
"<",
"len",
";",
"i",
"++",
")",
"{",
"if",
"(",
"typeof",
"indexArr",
"[",
"i",
"]",
"!==",
"\"number\"",
")",
"{",
"throw",
"new",
"TypeError",
"(",
"'PARAM MUST BE NUMBER ARRAY'",
")",
";",
"}",
"if",
"(",
"Math",
".",
"abs",
"(",
"indexArr",
"[",
"i",
"]",
")",
">",
"arrLen",
")",
"{",
"indexArr",
"[",
"i",
"]",
"=",
"arrLen",
"+",
"1",
";",
"}",
"if",
"(",
"indexArr",
"[",
"i",
"]",
">=",
"-",
"arrLen",
"&&",
"indexArr",
"[",
"i",
"]",
"<",
"0",
")",
"{",
"indexArr",
"[",
"i",
"]",
"=",
"indexArr",
"[",
"i",
"]",
"+",
"arrLen",
";",
"}",
"}",
"indexArr",
".",
"sort",
"(",
"function",
"(",
"a",
",",
"b",
")",
"{",
"return",
"a",
"-",
"b",
"}",
")",
"var",
"tmpArr",
"=",
"[",
"]",
";",
"for",
"(",
"var",
"i",
"=",
"0",
",",
"len",
"=",
"indexArr",
".",
"length",
";",
"i",
"<",
"len",
";",
"i",
"++",
")",
"{",
"if",
"(",
"tmpArr",
".",
"indexOf",
"(",
"indexArr",
"[",
"i",
"]",
")",
"==",
"-",
"1",
")",
"{",
"tmpArr",
".",
"push",
"(",
"indexArr",
"[",
"i",
"]",
")",
"}",
"}",
"var",
"outArr",
"=",
"JSON",
".",
"parse",
"(",
"JSON",
".",
"stringify",
"(",
"arr",
")",
")",
";",
"if",
"(",
"arr",
".",
"length",
"===",
"0",
")",
"{",
"return",
"[",
"]",
";",
"}",
"for",
"(",
"var",
"i",
"=",
"0",
",",
"len",
"=",
"tmpArr",
".",
"length",
";",
"i",
"<",
"len",
";",
"i",
"++",
")",
"{",
"outArr",
".",
"splice",
"(",
"tmpArr",
"[",
"i",
"]",
"-",
"i",
",",
"1",
")",
";",
"}",
"return",
"outArr",
"}"
]
| Delete array elements in one time by array consists of their indexes
@param {Array} `arr` The Array to sort.
@param {Number Array} `indexArr` Array consists of indexes which you want to delete.
@return {Array} Returns a new deleted array.
@api public | [
"Delete",
"array",
"elements",
"in",
"one",
"time",
"by",
"array",
"consists",
"of",
"their",
"indexes"
]
| c1f55b9621a154785d8ef35bfc60fb4d1c3a2d62 | https://github.com/tywei90/arr-del/blob/c1f55b9621a154785d8ef35bfc60fb4d1c3a2d62/index.js#L21-L64 | train |
gillesruppert/nodecopter-leap | leap-remote.js | getGesture | function getGesture(gestures, type) {
if (!gestures.length) return;
var types = _.pluck(gestures, 'type');
var index = types.indexOf(type);
if (index > -1) return gestures[index];
} | javascript | function getGesture(gestures, type) {
if (!gestures.length) return;
var types = _.pluck(gestures, 'type');
var index = types.indexOf(type);
if (index > -1) return gestures[index];
} | [
"function",
"getGesture",
"(",
"gestures",
",",
"type",
")",
"{",
"if",
"(",
"!",
"gestures",
".",
"length",
")",
"return",
";",
"var",
"types",
"=",
"_",
".",
"pluck",
"(",
"gestures",
",",
"'type'",
")",
";",
"var",
"index",
"=",
"types",
".",
"indexOf",
"(",
"type",
")",
";",
"if",
"(",
"index",
">",
"-",
"1",
")",
"return",
"gestures",
"[",
"index",
"]",
";",
"}"
]
| get only the circle gesture from the gestures array | [
"get",
"only",
"the",
"circle",
"gesture",
"from",
"the",
"gestures",
"array"
]
| d0fea0166bc13f0bec5ede97dd418be0016260f6 | https://github.com/gillesruppert/nodecopter-leap/blob/d0fea0166bc13f0bec5ede97dd418be0016260f6/leap-remote.js#L94-L99 | train |
tarunc/mongoose-stamp | lib/mongoose-stamps.js | timestampsPlugin | function timestampsPlugin(schema, options) {
// Add the fields to the schema
schema.add({
createdAt: {
type: Date,
'default': Date.now
},
updatedAt: {
type: Date,
'default': Date.now
},
deletedAt: {
type: Date,
sparse: true
}
});
// Define the pre save hook
schema.pre('save', function (next) {
this.updatedAt = new Date();
next();
});
// Create an index on all the paths
schema.path('createdAt').index(true);
schema.path('updatedAt').index(true);
schema.path('deletedAt').index(true);
} | javascript | function timestampsPlugin(schema, options) {
// Add the fields to the schema
schema.add({
createdAt: {
type: Date,
'default': Date.now
},
updatedAt: {
type: Date,
'default': Date.now
},
deletedAt: {
type: Date,
sparse: true
}
});
// Define the pre save hook
schema.pre('save', function (next) {
this.updatedAt = new Date();
next();
});
// Create an index on all the paths
schema.path('createdAt').index(true);
schema.path('updatedAt').index(true);
schema.path('deletedAt').index(true);
} | [
"function",
"timestampsPlugin",
"(",
"schema",
",",
"options",
")",
"{",
"schema",
".",
"add",
"(",
"{",
"createdAt",
":",
"{",
"type",
":",
"Date",
",",
"'default'",
":",
"Date",
".",
"now",
"}",
",",
"updatedAt",
":",
"{",
"type",
":",
"Date",
",",
"'default'",
":",
"Date",
".",
"now",
"}",
",",
"deletedAt",
":",
"{",
"type",
":",
"Date",
",",
"sparse",
":",
"true",
"}",
"}",
")",
";",
"schema",
".",
"pre",
"(",
"'save'",
",",
"function",
"(",
"next",
")",
"{",
"this",
".",
"updatedAt",
"=",
"new",
"Date",
"(",
")",
";",
"next",
"(",
")",
";",
"}",
")",
";",
"schema",
".",
"path",
"(",
"'createdAt'",
")",
".",
"index",
"(",
"true",
")",
";",
"schema",
".",
"path",
"(",
"'updatedAt'",
")",
".",
"index",
"(",
"true",
")",
";",
"schema",
".",
"path",
"(",
"'deletedAt'",
")",
".",
"index",
"(",
"true",
")",
";",
"}"
]
| `Timestamps` Plugin for Mongoose.
@param {mongoose.Schema} schema -
@param {Object} options - some options
@api public | [
"Timestamps",
"Plugin",
"for",
"Mongoose",
"."
]
| 9714b79b5cd1ee17195fc4812c28cf5534f7764a | https://github.com/tarunc/mongoose-stamp/blob/9714b79b5cd1ee17195fc4812c28cf5534f7764a/lib/mongoose-stamps.js#L9-L37 | train |
alexcjohnson/world-calendars | dist/main.js | function(date) {
if (this._calendar.name !== date._calendar.name) {
throw (_exports.local.differentCalendars || _exports.regionalOptions[''].differentCalendars).
replace(/\{0\}/, this._calendar.local.name).replace(/\{1\}/, date._calendar.local.name);
}
var c = (this._year !== date._year ? this._year - date._year :
this._month !== date._month ? this.monthOfYear() - date.monthOfYear() :
this._day - date._day);
return (c === 0 ? 0 : (c < 0 ? -1 : +1));
} | javascript | function(date) {
if (this._calendar.name !== date._calendar.name) {
throw (_exports.local.differentCalendars || _exports.regionalOptions[''].differentCalendars).
replace(/\{0\}/, this._calendar.local.name).replace(/\{1\}/, date._calendar.local.name);
}
var c = (this._year !== date._year ? this._year - date._year :
this._month !== date._month ? this.monthOfYear() - date.monthOfYear() :
this._day - date._day);
return (c === 0 ? 0 : (c < 0 ? -1 : +1));
} | [
"function",
"(",
"date",
")",
"{",
"if",
"(",
"this",
".",
"_calendar",
".",
"name",
"!==",
"date",
".",
"_calendar",
".",
"name",
")",
"{",
"throw",
"(",
"_exports",
".",
"local",
".",
"differentCalendars",
"||",
"_exports",
".",
"regionalOptions",
"[",
"''",
"]",
".",
"differentCalendars",
")",
".",
"replace",
"(",
"/",
"\\{0\\}",
"/",
",",
"this",
".",
"_calendar",
".",
"local",
".",
"name",
")",
".",
"replace",
"(",
"/",
"\\{1\\}",
"/",
",",
"date",
".",
"_calendar",
".",
"local",
".",
"name",
")",
";",
"}",
"var",
"c",
"=",
"(",
"this",
".",
"_year",
"!==",
"date",
".",
"_year",
"?",
"this",
".",
"_year",
"-",
"date",
".",
"_year",
":",
"this",
".",
"_month",
"!==",
"date",
".",
"_month",
"?",
"this",
".",
"monthOfYear",
"(",
")",
"-",
"date",
".",
"monthOfYear",
"(",
")",
":",
"this",
".",
"_day",
"-",
"date",
".",
"_day",
")",
";",
"return",
"(",
"c",
"===",
"0",
"?",
"0",
":",
"(",
"c",
"<",
"0",
"?",
"-",
"1",
":",
"+",
"1",
")",
")",
";",
"}"
]
| Compare this date to another date.
@memberof CDate
@param date {CDate} The other date.
@return {number} -1 if this date is before the other date,
0 if they are equal, or +1 if this date is after the other date. | [
"Compare",
"this",
"date",
"to",
"another",
"date",
"."
]
| 810693882512dec1b804456f8d435b962bd6cf31 | https://github.com/alexcjohnson/world-calendars/blob/810693882512dec1b804456f8d435b962bd6cf31/dist/main.js#L302-L311 | train |
|
alexcjohnson/world-calendars | dist/main.js | function(year) {
var date = this._validate(year, this.minMonth, this.minDay,
_exports.local.invalidYear || _exports.regionalOptions[''].invalidYear);
return (date.year() < 0 ? '-' : '') + pad(Math.abs(date.year()), 4)
} | javascript | function(year) {
var date = this._validate(year, this.minMonth, this.minDay,
_exports.local.invalidYear || _exports.regionalOptions[''].invalidYear);
return (date.year() < 0 ? '-' : '') + pad(Math.abs(date.year()), 4)
} | [
"function",
"(",
"year",
")",
"{",
"var",
"date",
"=",
"this",
".",
"_validate",
"(",
"year",
",",
"this",
".",
"minMonth",
",",
"this",
".",
"minDay",
",",
"_exports",
".",
"local",
".",
"invalidYear",
"||",
"_exports",
".",
"regionalOptions",
"[",
"''",
"]",
".",
"invalidYear",
")",
";",
"return",
"(",
"date",
".",
"year",
"(",
")",
"<",
"0",
"?",
"'-'",
":",
"''",
")",
"+",
"pad",
"(",
"Math",
".",
"abs",
"(",
"date",
".",
"year",
"(",
")",
")",
",",
"4",
")",
"}"
]
| Format the year, if not a simple sequential number
@memberof BaseCalendar
@param year {CDate|number} The date to format or the year to format.
@return {string} The formatted year.
@throws Error if an invalid year or a different calendar used. | [
"Format",
"the",
"year",
"if",
"not",
"a",
"simple",
"sequential",
"number"
]
| 810693882512dec1b804456f8d435b962bd6cf31 | https://github.com/alexcjohnson/world-calendars/blob/810693882512dec1b804456f8d435b962bd6cf31/dist/main.js#L415-L419 | train |
|
alexcjohnson/world-calendars | dist/main.js | function(year, ord) {
var m = (ord + this.firstMonth - 2 * this.minMonth) %
this.monthsInYear(year) + this.minMonth;
this._validate(year, m, this.minDay,
_exports.local.invalidMonth || _exports.regionalOptions[''].invalidMonth);
return m;
} | javascript | function(year, ord) {
var m = (ord + this.firstMonth - 2 * this.minMonth) %
this.monthsInYear(year) + this.minMonth;
this._validate(year, m, this.minDay,
_exports.local.invalidMonth || _exports.regionalOptions[''].invalidMonth);
return m;
} | [
"function",
"(",
"year",
",",
"ord",
")",
"{",
"var",
"m",
"=",
"(",
"ord",
"+",
"this",
".",
"firstMonth",
"-",
"2",
"*",
"this",
".",
"minMonth",
")",
"%",
"this",
".",
"monthsInYear",
"(",
"year",
")",
"+",
"this",
".",
"minMonth",
";",
"this",
".",
"_validate",
"(",
"year",
",",
"m",
",",
"this",
".",
"minDay",
",",
"_exports",
".",
"local",
".",
"invalidMonth",
"||",
"_exports",
".",
"regionalOptions",
"[",
"''",
"]",
".",
"invalidMonth",
")",
";",
"return",
"m",
";",
"}"
]
| Calculate actual month from ordinal position, starting from minMonth.
@memberof BaseCalendar
@param year {number} The year to examine.
@param ord {number} The month's ordinal position.
@return {number} The month's number.
@throws Error if an invalid year/month. | [
"Calculate",
"actual",
"month",
"from",
"ordinal",
"position",
"starting",
"from",
"minMonth",
"."
]
| 810693882512dec1b804456f8d435b962bd6cf31 | https://github.com/alexcjohnson/world-calendars/blob/810693882512dec1b804456f8d435b962bd6cf31/dist/main.js#L452-L458 | train |
|
alexcjohnson/world-calendars | dist/main.js | function(year, month, day) {
var date = this._validate(year, month, day,
_exports.local.invalidDate || _exports.regionalOptions[''].invalidDate);
return date.toJD() - this.newDate(date.year(),
this.fromMonthOfYear(date.year(), this.minMonth), this.minDay).toJD() + 1;
} | javascript | function(year, month, day) {
var date = this._validate(year, month, day,
_exports.local.invalidDate || _exports.regionalOptions[''].invalidDate);
return date.toJD() - this.newDate(date.year(),
this.fromMonthOfYear(date.year(), this.minMonth), this.minDay).toJD() + 1;
} | [
"function",
"(",
"year",
",",
"month",
",",
"day",
")",
"{",
"var",
"date",
"=",
"this",
".",
"_validate",
"(",
"year",
",",
"month",
",",
"day",
",",
"_exports",
".",
"local",
".",
"invalidDate",
"||",
"_exports",
".",
"regionalOptions",
"[",
"''",
"]",
".",
"invalidDate",
")",
";",
"return",
"date",
".",
"toJD",
"(",
")",
"-",
"this",
".",
"newDate",
"(",
"date",
".",
"year",
"(",
")",
",",
"this",
".",
"fromMonthOfYear",
"(",
"date",
".",
"year",
"(",
")",
",",
"this",
".",
"minMonth",
")",
",",
"this",
".",
"minDay",
")",
".",
"toJD",
"(",
")",
"+",
"1",
";",
"}"
]
| Retrieve the day of the year for a date.
@memberof BaseCalendar
@param year {CDate|number} The date to convert or the year to convert.
@param [month] {number} The month to convert.
@param [day] {number} The day to convert.
@return {number} The day of the year.
@throws Error if an invalid date or a different calendar used. | [
"Retrieve",
"the",
"day",
"of",
"the",
"year",
"for",
"a",
"date",
"."
]
| 810693882512dec1b804456f8d435b962bd6cf31 | https://github.com/alexcjohnson/world-calendars/blob/810693882512dec1b804456f8d435b962bd6cf31/dist/main.js#L478-L483 | train |
|
alexcjohnson/world-calendars | dist/main.js | function(year, month, day) {
var date = this._validate(year, month, day,
_exports.local.invalidDate || _exports.regionalOptions[''].invalidDate);
return (Math.floor(this.toJD(date)) + 2) % this.daysInWeek();
} | javascript | function(year, month, day) {
var date = this._validate(year, month, day,
_exports.local.invalidDate || _exports.regionalOptions[''].invalidDate);
return (Math.floor(this.toJD(date)) + 2) % this.daysInWeek();
} | [
"function",
"(",
"year",
",",
"month",
",",
"day",
")",
"{",
"var",
"date",
"=",
"this",
".",
"_validate",
"(",
"year",
",",
"month",
",",
"day",
",",
"_exports",
".",
"local",
".",
"invalidDate",
"||",
"_exports",
".",
"regionalOptions",
"[",
"''",
"]",
".",
"invalidDate",
")",
";",
"return",
"(",
"Math",
".",
"floor",
"(",
"this",
".",
"toJD",
"(",
"date",
")",
")",
"+",
"2",
")",
"%",
"this",
".",
"daysInWeek",
"(",
")",
";",
"}"
]
| Retrieve the day of the week for a date.
@memberof BaseCalendar
@param year {CDate|number} The date to examine or the year to examine.
@param [month] {number} The month to examine.
@param [day] {number} The day to examine.
@return {number} The day of the week: 0 to number of days - 1.
@throws Error if an invalid date or a different calendar used. | [
"Retrieve",
"the",
"day",
"of",
"the",
"week",
"for",
"a",
"date",
"."
]
| 810693882512dec1b804456f8d435b962bd6cf31 | https://github.com/alexcjohnson/world-calendars/blob/810693882512dec1b804456f8d435b962bd6cf31/dist/main.js#L499-L503 | train |
|
alexcjohnson/world-calendars | dist/main.js | function(year, month, day) {
this._validate(year, month, day,
_exports.local.invalidDate || _exports.regionalOptions[''].invalidDate);
return {};
} | javascript | function(year, month, day) {
this._validate(year, month, day,
_exports.local.invalidDate || _exports.regionalOptions[''].invalidDate);
return {};
} | [
"function",
"(",
"year",
",",
"month",
",",
"day",
")",
"{",
"this",
".",
"_validate",
"(",
"year",
",",
"month",
",",
"day",
",",
"_exports",
".",
"local",
".",
"invalidDate",
"||",
"_exports",
".",
"regionalOptions",
"[",
"''",
"]",
".",
"invalidDate",
")",
";",
"return",
"{",
"}",
";",
"}"
]
| Retrieve additional information about a date.
@memberof BaseCalendar
@param year {CDate|number} The date to examine or the year to examine.
@param [month] {number} The month to examine.
@param [day] {number} The day to examine.
@return {object} Additional information - contents depends on calendar.
@throws Error if an invalid date or a different calendar used. | [
"Retrieve",
"additional",
"information",
"about",
"a",
"date",
"."
]
| 810693882512dec1b804456f8d435b962bd6cf31 | https://github.com/alexcjohnson/world-calendars/blob/810693882512dec1b804456f8d435b962bd6cf31/dist/main.js#L512-L516 | train |
|
alexcjohnson/world-calendars | dist/main.js | function(date, value, period) {
this._validate(date, this.minMonth, this.minDay,
_exports.local.invalidDate || _exports.regionalOptions[''].invalidDate);
var y = (period === 'y' ? value : date.year());
var m = (period === 'm' ? value : date.month());
var d = (period === 'd' ? value : date.day());
if (period === 'y' || period === 'm') {
d = Math.min(d, this.daysInMonth(y, m));
}
return date.date(y, m, d);
} | javascript | function(date, value, period) {
this._validate(date, this.minMonth, this.minDay,
_exports.local.invalidDate || _exports.regionalOptions[''].invalidDate);
var y = (period === 'y' ? value : date.year());
var m = (period === 'm' ? value : date.month());
var d = (period === 'd' ? value : date.day());
if (period === 'y' || period === 'm') {
d = Math.min(d, this.daysInMonth(y, m));
}
return date.date(y, m, d);
} | [
"function",
"(",
"date",
",",
"value",
",",
"period",
")",
"{",
"this",
".",
"_validate",
"(",
"date",
",",
"this",
".",
"minMonth",
",",
"this",
".",
"minDay",
",",
"_exports",
".",
"local",
".",
"invalidDate",
"||",
"_exports",
".",
"regionalOptions",
"[",
"''",
"]",
".",
"invalidDate",
")",
";",
"var",
"y",
"=",
"(",
"period",
"===",
"'y'",
"?",
"value",
":",
"date",
".",
"year",
"(",
")",
")",
";",
"var",
"m",
"=",
"(",
"period",
"===",
"'m'",
"?",
"value",
":",
"date",
".",
"month",
"(",
")",
")",
";",
"var",
"d",
"=",
"(",
"period",
"===",
"'d'",
"?",
"value",
":",
"date",
".",
"day",
"(",
")",
")",
";",
"if",
"(",
"period",
"===",
"'y'",
"||",
"period",
"===",
"'m'",
")",
"{",
"d",
"=",
"Math",
".",
"min",
"(",
"d",
",",
"this",
".",
"daysInMonth",
"(",
"y",
",",
"m",
")",
")",
";",
"}",
"return",
"date",
".",
"date",
"(",
"y",
",",
"m",
",",
"d",
")",
";",
"}"
]
| Set a portion of the date.
@memberof BaseCalendar
@param date {CDate} The starting date.
@param value {number} The new value for the period.
@param period {string} One of 'y' for year, 'm' for month, 'd' for day.
@return {CDate} The updated date.
@throws Error if an invalid date or a different calendar used. | [
"Set",
"a",
"portion",
"of",
"the",
"date",
"."
]
| 810693882512dec1b804456f8d435b962bd6cf31 | https://github.com/alexcjohnson/world-calendars/blob/810693882512dec1b804456f8d435b962bd6cf31/dist/main.js#L615-L625 | train |
|
S3bb1/ah-dashboard-plugin | public/dashboard/bower_components/admin-lte/dist/js/app.js | function () {
//Get the object
var _this = this;
//Update options
var o = $.AdminLTE.options.controlSidebarOptions;
//Get the sidebar
var sidebar = $(o.selector);
//The toggle button
var btn = $(o.toggleBtnSelector);
//Listen to the click event
btn.on('click', function (e) {
e.preventDefault();
//If the sidebar is not open
if (!sidebar.hasClass('control-sidebar-open')
&& !$('body').hasClass('control-sidebar-open')) {
//Open the sidebar
_this.open(sidebar, o.slide);
} else {
_this.close(sidebar, o.slide);
}
});
//If the body has a boxed layout, fix the sidebar bg position
var bg = $(".control-sidebar-bg");
_this._fix(bg);
//If the body has a fixed layout, make the control sidebar fixed
if ($('body').hasClass('fixed')) {
_this._fixForFixed(sidebar);
} else {
//If the content height is less than the sidebar's height, force max height
if ($('.content-wrapper, .right-side').height() < sidebar.height()) {
_this._fixForContent(sidebar);
}
}
} | javascript | function () {
//Get the object
var _this = this;
//Update options
var o = $.AdminLTE.options.controlSidebarOptions;
//Get the sidebar
var sidebar = $(o.selector);
//The toggle button
var btn = $(o.toggleBtnSelector);
//Listen to the click event
btn.on('click', function (e) {
e.preventDefault();
//If the sidebar is not open
if (!sidebar.hasClass('control-sidebar-open')
&& !$('body').hasClass('control-sidebar-open')) {
//Open the sidebar
_this.open(sidebar, o.slide);
} else {
_this.close(sidebar, o.slide);
}
});
//If the body has a boxed layout, fix the sidebar bg position
var bg = $(".control-sidebar-bg");
_this._fix(bg);
//If the body has a fixed layout, make the control sidebar fixed
if ($('body').hasClass('fixed')) {
_this._fixForFixed(sidebar);
} else {
//If the content height is less than the sidebar's height, force max height
if ($('.content-wrapper, .right-side').height() < sidebar.height()) {
_this._fixForContent(sidebar);
}
}
} | [
"function",
"(",
")",
"{",
"var",
"_this",
"=",
"this",
";",
"var",
"o",
"=",
"$",
".",
"AdminLTE",
".",
"options",
".",
"controlSidebarOptions",
";",
"var",
"sidebar",
"=",
"$",
"(",
"o",
".",
"selector",
")",
";",
"var",
"btn",
"=",
"$",
"(",
"o",
".",
"toggleBtnSelector",
")",
";",
"btn",
".",
"on",
"(",
"'click'",
",",
"function",
"(",
"e",
")",
"{",
"e",
".",
"preventDefault",
"(",
")",
";",
"if",
"(",
"!",
"sidebar",
".",
"hasClass",
"(",
"'control-sidebar-open'",
")",
"&&",
"!",
"$",
"(",
"'body'",
")",
".",
"hasClass",
"(",
"'control-sidebar-open'",
")",
")",
"{",
"_this",
".",
"open",
"(",
"sidebar",
",",
"o",
".",
"slide",
")",
";",
"}",
"else",
"{",
"_this",
".",
"close",
"(",
"sidebar",
",",
"o",
".",
"slide",
")",
";",
"}",
"}",
")",
";",
"var",
"bg",
"=",
"$",
"(",
"\".control-sidebar-bg\"",
")",
";",
"_this",
".",
"_fix",
"(",
"bg",
")",
";",
"if",
"(",
"$",
"(",
"'body'",
")",
".",
"hasClass",
"(",
"'fixed'",
")",
")",
"{",
"_this",
".",
"_fixForFixed",
"(",
"sidebar",
")",
";",
"}",
"else",
"{",
"if",
"(",
"$",
"(",
"'.content-wrapper, .right-side'",
")",
".",
"height",
"(",
")",
"<",
"sidebar",
".",
"height",
"(",
")",
")",
"{",
"_this",
".",
"_fixForContent",
"(",
"sidebar",
")",
";",
"}",
"}",
"}"
]
| instantiate the object | [
"instantiate",
"the",
"object"
]
| c283370ec0f99a25db5bb7029a98b4febf8c5251 | https://github.com/S3bb1/ah-dashboard-plugin/blob/c283370ec0f99a25db5bb7029a98b4febf8c5251/public/dashboard/bower_components/admin-lte/dist/js/app.js#L443-L479 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.