id
int32
0
58k
repo
stringlengths
5
67
path
stringlengths
4
116
func_name
stringlengths
0
58
original_string
stringlengths
52
373k
language
stringclasses
1 value
code
stringlengths
52
373k
code_tokens
list
docstring
stringlengths
4
11.8k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
86
226
18,300
Reportr/dashboard
public/build/static/application.js
mixin
function mixin(object, source, options) { var chain = true, methodNames = source && functions(source); if (!source || (!options && !methodNames.length)) { if (options == null) { options = source; } source = object; object = lodash; methodNames = functions(source); } if (options === false) { chain = false; } else if (isObject(options) && 'chain' in options) { chain = options.chain; } var index = -1, isFunc = isFunction(object), length = methodNames ? methodNames.length : 0; while (++index < length) { var methodName = methodNames[index], func = object[methodName] = source[methodName]; if (isFunc) { object.prototype[methodName] = (function(func) { return function() { var chainAll = this.__chain__, value = this.__wrapped__, args = [value]; push.apply(args, arguments); var result = func.apply(object, args); if (chain || chainAll) { if (value === result && isObject(result)) { return this; } result = new object(result); result.__chain__ = chainAll; } return result; }; }(func)); } } }
javascript
function mixin(object, source, options) { var chain = true, methodNames = source && functions(source); if (!source || (!options && !methodNames.length)) { if (options == null) { options = source; } source = object; object = lodash; methodNames = functions(source); } if (options === false) { chain = false; } else if (isObject(options) && 'chain' in options) { chain = options.chain; } var index = -1, isFunc = isFunction(object), length = methodNames ? methodNames.length : 0; while (++index < length) { var methodName = methodNames[index], func = object[methodName] = source[methodName]; if (isFunc) { object.prototype[methodName] = (function(func) { return function() { var chainAll = this.__chain__, value = this.__wrapped__, args = [value]; push.apply(args, arguments); var result = func.apply(object, args); if (chain || chainAll) { if (value === result && isObject(result)) { return this; } result = new object(result); result.__chain__ = chainAll; } return result; }; }(func)); } } }
[ "function", "mixin", "(", "object", ",", "source", ",", "options", ")", "{", "var", "chain", "=", "true", ",", "methodNames", "=", "source", "&&", "functions", "(", "source", ")", ";", "if", "(", "!", "source", "||", "(", "!", "options", "&&", "!", "methodNames", ".", "length", ")", ")", "{", "if", "(", "options", "==", "null", ")", "{", "options", "=", "source", ";", "}", "source", "=", "object", ";", "object", "=", "lodash", ";", "methodNames", "=", "functions", "(", "source", ")", ";", "}", "if", "(", "options", "===", "false", ")", "{", "chain", "=", "false", ";", "}", "else", "if", "(", "isObject", "(", "options", ")", "&&", "'chain'", "in", "options", ")", "{", "chain", "=", "options", ".", "chain", ";", "}", "var", "index", "=", "-", "1", ",", "isFunc", "=", "isFunction", "(", "object", ")", ",", "length", "=", "methodNames", "?", "methodNames", ".", "length", ":", "0", ";", "while", "(", "++", "index", "<", "length", ")", "{", "var", "methodName", "=", "methodNames", "[", "index", "]", ",", "func", "=", "object", "[", "methodName", "]", "=", "source", "[", "methodName", "]", ";", "if", "(", "isFunc", ")", "{", "object", ".", "prototype", "[", "methodName", "]", "=", "(", "function", "(", "func", ")", "{", "return", "function", "(", ")", "{", "var", "chainAll", "=", "this", ".", "__chain__", ",", "value", "=", "this", ".", "__wrapped__", ",", "args", "=", "[", "value", "]", ";", "push", ".", "apply", "(", "args", ",", "arguments", ")", ";", "var", "result", "=", "func", ".", "apply", "(", "object", ",", "args", ")", ";", "if", "(", "chain", "||", "chainAll", ")", "{", "if", "(", "value", "===", "result", "&&", "isObject", "(", "result", ")", ")", "{", "return", "this", ";", "}", "result", "=", "new", "object", "(", "result", ")", ";", "result", ".", "__chain__", "=", "chainAll", ";", "}", "return", "result", ";", "}", ";", "}", "(", "func", ")", ")", ";", "}", "}", "}" ]
Adds function properties of a source object to the destination object. If `object` is a function methods will be added to its prototype as well. @static @memberOf _ @category Utilities @param {Function|Object} [object=lodash] object The destination object. @param {Object} source The object of functions to add. @param {Object} [options] The options object. @param {boolean} [options.chain=true] Specify whether the functions added are chainable. @example function vowels(string) { return _.filter(string, function(v) { return /[aeiou]/i.test(v); }); } _.mixin({ 'vowels': vowels }); _.vowels('fred'); // => ['e'] _('fred').vowels().value(); // => ['e'] _.mixin({ 'vowels': vowels }, { 'chain': false }); _('fred').vowels(); // => ['e']
[ "Adds", "function", "properties", "of", "a", "source", "object", "to", "the", "destination", "object", ".", "If", "object", "is", "a", "function", "methods", "will", "be", "added", "to", "its", "prototype", "as", "well", "." ]
bff0ea7f324de78ab8bf8c4301ce30696ad7d960
https://github.com/Reportr/dashboard/blob/bff0ea7f324de78ab8bf8c4301ce30696ad7d960/public/build/static/application.js#L20369-L20415
18,301
Reportr/dashboard
public/build/static/application.js
result
function result(object, key, defaultValue) { var value = object == null ? undefined : object[key]; if (typeof value == 'undefined') { return defaultValue; } return isFunction(value) ? object[key]() : value; }
javascript
function result(object, key, defaultValue) { var value = object == null ? undefined : object[key]; if (typeof value == 'undefined') { return defaultValue; } return isFunction(value) ? object[key]() : value; }
[ "function", "result", "(", "object", ",", "key", ",", "defaultValue", ")", "{", "var", "value", "=", "object", "==", "null", "?", "undefined", ":", "object", "[", "key", "]", ";", "if", "(", "typeof", "value", "==", "'undefined'", ")", "{", "return", "defaultValue", ";", "}", "return", "isFunction", "(", "value", ")", "?", "object", "[", "key", "]", "(", ")", ":", "value", ";", "}" ]
Resolves the value of property `key` on `object`. If `key` is a function it will be invoked with the `this` binding of `object` and its result returned, else the property value is returned. If `object` is `null` or `undefined` then `undefined` is returned. If a default value is provided it will be returned if the property value resolves to `undefined`. @static @memberOf _ @category Utilities @param {Object} object The object to inspect. @param {string} key The name of the property to resolve. @param {*} [defaultValue] The value returned if the property value resolves to `undefined`. @returns {*} Returns the resolved value. @example var object = { 'name': 'fred', 'age': function() { return 40; } }; _.result(object, 'name'); // => 'fred' _.result(object, 'age'); // => 40 _.result(object, 'employer', 'slate'); // => 'slate'
[ "Resolves", "the", "value", "of", "property", "key", "on", "object", ".", "If", "key", "is", "a", "function", "it", "will", "be", "invoked", "with", "the", "this", "binding", "of", "object", "and", "its", "result", "returned", "else", "the", "property", "value", "is", "returned", ".", "If", "object", "is", "null", "or", "undefined", "then", "undefined", "is", "returned", ".", "If", "a", "default", "value", "is", "provided", "it", "will", "be", "returned", "if", "the", "property", "value", "resolves", "to", "undefined", "." ]
bff0ea7f324de78ab8bf8c4301ce30696ad7d960
https://github.com/Reportr/dashboard/blob/bff0ea7f324de78ab8bf8c4301ce30696ad7d960/public/build/static/application.js#L20617-L20623
18,302
Reportr/dashboard
public/build/static/application.js
function(obj, name, callback) { var listeningTo = this._listeningTo; if (!listeningTo) return this; var remove = !name && !callback; if (!callback && typeof name === 'object') callback = this; if (obj) (listeningTo = {})[obj.cid] = obj; for (var id in listeningTo) { obj = listeningTo[id]; obj.off(name, callback, this); if (remove || _.isEmpty(obj._events)) delete this._listeningTo[id]; } return this; }
javascript
function(obj, name, callback) { var listeningTo = this._listeningTo; if (!listeningTo) return this; var remove = !name && !callback; if (!callback && typeof name === 'object') callback = this; if (obj) (listeningTo = {})[obj.cid] = obj; for (var id in listeningTo) { obj = listeningTo[id]; obj.off(name, callback, this); if (remove || _.isEmpty(obj._events)) delete this._listeningTo[id]; } return this; }
[ "function", "(", "obj", ",", "name", ",", "callback", ")", "{", "var", "listeningTo", "=", "this", ".", "_listeningTo", ";", "if", "(", "!", "listeningTo", ")", "return", "this", ";", "var", "remove", "=", "!", "name", "&&", "!", "callback", ";", "if", "(", "!", "callback", "&&", "typeof", "name", "===", "'object'", ")", "callback", "=", "this", ";", "if", "(", "obj", ")", "(", "listeningTo", "=", "{", "}", ")", "[", "obj", ".", "cid", "]", "=", "obj", ";", "for", "(", "var", "id", "in", "listeningTo", ")", "{", "obj", "=", "listeningTo", "[", "id", "]", ";", "obj", ".", "off", "(", "name", ",", "callback", ",", "this", ")", ";", "if", "(", "remove", "||", "_", ".", "isEmpty", "(", "obj", ".", "_events", ")", ")", "delete", "this", ".", "_listeningTo", "[", "id", "]", ";", "}", "return", "this", ";", "}" ]
Tell this object to stop listening to either specific events or to every object it's currently listening to. @method stopListening @param {Class} [obj] object to stop listening to @param {string} [name] event to stop listening for @param {function} [callback] callback to stop listening for @chainable
[ "Tell", "this", "object", "to", "stop", "listening", "to", "either", "specific", "events", "or", "to", "every", "object", "it", "s", "currently", "listening", "to", "." ]
bff0ea7f324de78ab8bf8c4301ce30696ad7d960
https://github.com/Reportr/dashboard/blob/bff0ea7f324de78ab8bf8c4301ce30696ad7d960/public/build/static/application.js#L21363-L21376
18,303
Reportr/dashboard
public/build/static/application.js
function(namespace, key) { key = JSON.stringify(key); return "cache_" + configs.revision + "_" + namespace + "_" + key; }
javascript
function(namespace, key) { key = JSON.stringify(key); return "cache_" + configs.revision + "_" + namespace + "_" + key; }
[ "function", "(", "namespace", ",", "key", ")", "{", "key", "=", "JSON", ".", "stringify", "(", "key", ")", ";", "return", "\"cache_\"", "+", "configs", ".", "revision", "+", "\"_\"", "+", "namespace", "+", "\"_\"", "+", "key", ";", "}" ]
Transform a key in cache key @method key @param {string} namespace namespace for this key @param {string} key key of the data to cache @return {string} complete key for the cache
[ "Transform", "a", "key", "in", "cache", "key" ]
bff0ea7f324de78ab8bf8c4301ce30696ad7d960
https://github.com/Reportr/dashboard/blob/bff0ea7f324de78ab8bf8c4301ce30696ad7d960/public/build/static/application.js#L21907-L21910
18,304
Reportr/dashboard
public/build/static/application.js
function(namespace, key) { var ckey = Cache.key(namespace, key); var ctime = (new Date()).getTime(); var v = Storage.get(ckey); if (v == null) { return null; } else { if (v.expiration == -1 || v.expiration > ctime) { return v.value; } else { Storage.remove(ckey); return null; } } }
javascript
function(namespace, key) { var ckey = Cache.key(namespace, key); var ctime = (new Date()).getTime(); var v = Storage.get(ckey); if (v == null) { return null; } else { if (v.expiration == -1 || v.expiration > ctime) { return v.value; } else { Storage.remove(ckey); return null; } } }
[ "function", "(", "namespace", ",", "key", ")", "{", "var", "ckey", "=", "Cache", ".", "key", "(", "namespace", ",", "key", ")", ";", "var", "ctime", "=", "(", "new", "Date", "(", ")", ")", ".", "getTime", "(", ")", ";", "var", "v", "=", "Storage", ".", "get", "(", "ckey", ")", ";", "if", "(", "v", "==", "null", ")", "{", "return", "null", ";", "}", "else", "{", "if", "(", "v", ".", "expiration", "==", "-", "1", "||", "v", ".", "expiration", ">", "ctime", ")", "{", "return", "v", ".", "value", ";", "}", "else", "{", "Storage", ".", "remove", "(", "ckey", ")", ";", "return", "null", ";", "}", "}", "}" ]
Get data from the cache @method get @param {string} namespace namespace for this key @param {string} key key of the data to cache @return {object} value from the cache
[ "Get", "data", "from", "the", "cache" ]
bff0ea7f324de78ab8bf8c4301ce30696ad7d960
https://github.com/Reportr/dashboard/blob/bff0ea7f324de78ab8bf8c4301ce30696ad7d960/public/build/static/application.js#L21920-L21935
18,305
Reportr/dashboard
public/build/static/application.js
function(namespace, key) { var ckey = Cache.key(namespace, key); var ctime = (new Date()).getTime(); Storage.remove(ckey); }
javascript
function(namespace, key) { var ckey = Cache.key(namespace, key); var ctime = (new Date()).getTime(); Storage.remove(ckey); }
[ "function", "(", "namespace", ",", "key", ")", "{", "var", "ckey", "=", "Cache", ".", "key", "(", "namespace", ",", "key", ")", ";", "var", "ctime", "=", "(", "new", "Date", "(", ")", ")", ".", "getTime", "(", ")", ";", "Storage", ".", "remove", "(", "ckey", ")", ";", "}" ]
Delete a cache value @method remove @param {string} namespace namespace for this key @param {string} key key of the data to cache
[ "Delete", "a", "cache", "value" ]
bff0ea7f324de78ab8bf8c4301ce30696ad7d960
https://github.com/Reportr/dashboard/blob/bff0ea7f324de78ab8bf8c4301ce30696ad7d960/public/build/static/application.js#L21944-L21948
18,306
Reportr/dashboard
public/build/static/application.js
function(namespace, key, value, expiration) { var ckey = Cache.key(namespace, key); var ctime = (new Date()).getTime(); if (expiration > 0) { expiration = ctime + expiration * 1000; } else { expiration = -1; } Storage.set(ckey, { "expiration": expiration, "value": value }); return Cache.get(key); }
javascript
function(namespace, key, value, expiration) { var ckey = Cache.key(namespace, key); var ctime = (new Date()).getTime(); if (expiration > 0) { expiration = ctime + expiration * 1000; } else { expiration = -1; } Storage.set(ckey, { "expiration": expiration, "value": value }); return Cache.get(key); }
[ "function", "(", "namespace", ",", "key", ",", "value", ",", "expiration", ")", "{", "var", "ckey", "=", "Cache", ".", "key", "(", "namespace", ",", "key", ")", ";", "var", "ctime", "=", "(", "new", "Date", "(", ")", ")", ".", "getTime", "(", ")", ";", "if", "(", "expiration", ">", "0", ")", "{", "expiration", "=", "ctime", "+", "expiration", "*", "1000", ";", "}", "else", "{", "expiration", "=", "-", "1", ";", "}", "Storage", ".", "set", "(", "ckey", ",", "{", "\"expiration\"", ":", "expiration", ",", "\"value\"", ":", "value", "}", ")", ";", "return", "Cache", ".", "get", "(", "key", ")", ";", "}" ]
Set a data in the cache @method get @param {string} namespace namespace for this key @param {string} key key of the data to cache @param {object} value value to store in teh cache associated to this key @param {number} [expiration] seconds before epiration of this value in the cache
[ "Set", "a", "data", "in", "the", "cache" ]
bff0ea7f324de78ab8bf8c4301ce30696ad7d960
https://github.com/Reportr/dashboard/blob/bff0ea7f324de78ab8bf8c4301ce30696ad7d960/public/build/static/application.js#L21959-L21974
18,307
Reportr/dashboard
public/build/static/application.js
function() { var s = Storage.storage(); if (s == null) { return false; } Object.keys(s).forEach(function(key){ if (/^(cache_)/.test(key)) { s.removeItem(key); } }); }
javascript
function() { var s = Storage.storage(); if (s == null) { return false; } Object.keys(s).forEach(function(key){ if (/^(cache_)/.test(key)) { s.removeItem(key); } }); }
[ "function", "(", ")", "{", "var", "s", "=", "Storage", ".", "storage", "(", ")", ";", "if", "(", "s", "==", "null", ")", "{", "return", "false", ";", "}", "Object", ".", "keys", "(", "s", ")", ".", "forEach", "(", "function", "(", "key", ")", "{", "if", "(", "/", "^(cache_)", "/", ".", "test", "(", "key", ")", ")", "{", "s", ".", "removeItem", "(", "key", ")", ";", "}", "}", ")", ";", "}" ]
Clear the entire cache @method clear
[ "Clear", "the", "entire", "cache" ]
bff0ea7f324de78ab8bf8c4301ce30696ad7d960
https://github.com/Reportr/dashboard/blob/bff0ea7f324de78ab8bf8c4301ce30696ad7d960/public/build/static/application.js#L21981-L21991
18,308
Reportr/dashboard
public/build/static/application.js
function(namespace) { var ncache = {}; _.each(cache_methods, function(method) { ncache[method] = _.partial(Cache[method], namespace); }) return ncache; }
javascript
function(namespace) { var ncache = {}; _.each(cache_methods, function(method) { ncache[method] = _.partial(Cache[method], namespace); }) return ncache; }
[ "function", "(", "namespace", ")", "{", "var", "ncache", "=", "{", "}", ";", "_", ".", "each", "(", "cache_methods", ",", "function", "(", "method", ")", "{", "ncache", "[", "method", "]", "=", "_", ".", "partial", "(", "Cache", "[", "method", "]", ",", "namespace", ")", ";", "}", ")", "return", "ncache", ";", "}" ]
Return a cahce interface for a specific namespace @method namespace @param {string} namespace name of the namespace
[ "Return", "a", "cahce", "interface", "for", "a", "specific", "namespace" ]
bff0ea7f324de78ab8bf8c4301ce30696ad7d960
https://github.com/Reportr/dashboard/blob/bff0ea7f324de78ab8bf8c4301ce30696ad7d960/public/build/static/application.js#L21999-L22005
18,309
Reportr/dashboard
public/build/static/application.js
function() { if (!this.available) return; if (window.applicationCache.status === window.applicationCache.UPDATEREADY) { this.trigger("update"); } return window.applicationCache.status === window.applicationCache.UPDATEREADY; }
javascript
function() { if (!this.available) return; if (window.applicationCache.status === window.applicationCache.UPDATEREADY) { this.trigger("update"); } return window.applicationCache.status === window.applicationCache.UPDATEREADY; }
[ "function", "(", ")", "{", "if", "(", "!", "this", ".", "available", ")", "return", ";", "if", "(", "window", ".", "applicationCache", ".", "status", "===", "window", ".", "applicationCache", ".", "UPDATEREADY", ")", "{", "this", ".", "trigger", "(", "\"update\"", ")", ";", "}", "return", "window", ".", "applicationCache", ".", "status", "===", "window", ".", "applicationCache", ".", "UPDATEREADY", ";", "}" ]
Check for cache update
[ "Check", "for", "cache", "update" ]
bff0ea7f324de78ab8bf8c4301ce30696ad7d960
https://github.com/Reportr/dashboard/blob/bff0ea7f324de78ab8bf8c4301ce30696ad7d960/public/build/static/application.js#L22490-L22497
18,310
Reportr/dashboard
public/build/static/application.js
function(state) { if (state == this.state) return; this.state = state; logging.log("state ", this.state); this.trigger("state", this.state); }
javascript
function(state) { if (state == this.state) return; this.state = state; logging.log("state ", this.state); this.trigger("state", this.state); }
[ "function", "(", "state", ")", "{", "if", "(", "state", "==", "this", ".", "state", ")", "return", ";", "this", ".", "state", "=", "state", ";", "logging", ".", "log", "(", "\"state \"", ",", "this", ".", "state", ")", ";", "this", ".", "trigger", "(", "\"state\"", ",", "this", ".", "state", ")", ";", "}" ]
Set connexion status
[ "Set", "connexion", "status" ]
bff0ea7f324de78ab8bf8c4301ce30696ad7d960
https://github.com/Reportr/dashboard/blob/bff0ea7f324de78ab8bf8c4301ce30696ad7d960/public/build/static/application.js#L22500-L22506
18,311
Reportr/dashboard
public/build/static/application.js
function(title) { if (this._preTitle.length > 0) title = this._preTitle + " " + title; if (_.size(title) == 0) return this.app.name; return title + " - " + this.app.name; }
javascript
function(title) { if (this._preTitle.length > 0) title = this._preTitle + " " + title; if (_.size(title) == 0) return this.app.name; return title + " - " + this.app.name; }
[ "function", "(", "title", ")", "{", "if", "(", "this", ".", "_preTitle", ".", "length", ">", "0", ")", "title", "=", "this", ".", "_preTitle", "+", "\" \"", "+", "title", ";", "if", "(", "_", ".", "size", "(", "title", ")", "==", "0", ")", "return", "this", ".", "app", ".", "name", ";", "return", "title", "+", "\" - \"", "+", "this", ".", "app", ".", "name", ";", "}" ]
Transform a page name in complete title @method completeTitle @param {string} title title of the page @return {string} complete name with application name
[ "Transform", "a", "page", "name", "in", "complete", "title" ]
bff0ea7f324de78ab8bf8c4301ce30696ad7d960
https://github.com/Reportr/dashboard/blob/bff0ea7f324de78ab8bf8c4301ce30696ad7d960/public/build/static/application.js#L23076-L23080
18,312
Reportr/dashboard
public/build/static/application.js
function(name, value, metaName) { if (_.isObject(name)) { _.each(name, function(value, name) { this.meta(name, value); }, this); return; } if (metaName == null) metaName = "name"; var mt = this.$('meta['+metaName+'="'+name+'"]'); if (mt.length === 0) { mt = $("<meta>", {}).attr(metaName, name).appendTo('head'); } if (value != null) { mt.attr('content', value); return this; } else { return mt.attr('content'); } }
javascript
function(name, value, metaName) { if (_.isObject(name)) { _.each(name, function(value, name) { this.meta(name, value); }, this); return; } if (metaName == null) metaName = "name"; var mt = this.$('meta['+metaName+'="'+name+'"]'); if (mt.length === 0) { mt = $("<meta>", {}).attr(metaName, name).appendTo('head'); } if (value != null) { mt.attr('content', value); return this; } else { return mt.attr('content'); } }
[ "function", "(", "name", ",", "value", ",", "metaName", ")", "{", "if", "(", "_", ".", "isObject", "(", "name", ")", ")", "{", "_", ".", "each", "(", "name", ",", "function", "(", "value", ",", "name", ")", "{", "this", ".", "meta", "(", "name", ",", "value", ")", ";", "}", ",", "this", ")", ";", "return", ";", "}", "if", "(", "metaName", "==", "null", ")", "metaName", "=", "\"name\"", ";", "var", "mt", "=", "this", ".", "$", "(", "'meta['", "+", "metaName", "+", "'=\"'", "+", "name", "+", "'\"]'", ")", ";", "if", "(", "mt", ".", "length", "===", "0", ")", "{", "mt", "=", "$", "(", "\"<meta>\"", ",", "{", "}", ")", ".", "attr", "(", "metaName", ",", "name", ")", ".", "appendTo", "(", "'head'", ")", ";", "}", "if", "(", "value", "!=", "null", ")", "{", "mt", ".", "attr", "(", "'content'", ",", "value", ")", ";", "return", "this", ";", "}", "else", "{", "return", "mt", ".", "attr", "(", "'content'", ")", ";", "}", "}" ]
Set or get a meta tag value @method meta @param {string} name name of the meta tag @param {string} [value] value to set on the meta tag @param {string} [metaName="name"] selector for the meta name @return {string} value of the meta tag
[ "Set", "or", "get", "a", "meta", "tag", "value" ]
bff0ea7f324de78ab8bf8c4301ce30696ad7d960
https://github.com/Reportr/dashboard/blob/bff0ea7f324de78ab8bf8c4301ce30696ad7d960/public/build/static/application.js#L23091-L23110
18,313
Reportr/dashboard
public/build/static/application.js
function(rel, href, mimetype) { if (_.isObject(rel)) { _.each(rel, function(value, name) { this.link(name, value); }, this); return; } var mt = this.$('link[rel="'+rel+'"]'); if (mt.length === 0) { mt = $("<link>", {}).attr("rel", rel).appendTo(this.$el); } if (mimetype != null) mt.attr("type", mimetype); if (href != null) { mt.attr('href', href); } else { return mt.attr('href'); } }
javascript
function(rel, href, mimetype) { if (_.isObject(rel)) { _.each(rel, function(value, name) { this.link(name, value); }, this); return; } var mt = this.$('link[rel="'+rel+'"]'); if (mt.length === 0) { mt = $("<link>", {}).attr("rel", rel).appendTo(this.$el); } if (mimetype != null) mt.attr("type", mimetype); if (href != null) { mt.attr('href', href); } else { return mt.attr('href'); } }
[ "function", "(", "rel", ",", "href", ",", "mimetype", ")", "{", "if", "(", "_", ".", "isObject", "(", "rel", ")", ")", "{", "_", ".", "each", "(", "rel", ",", "function", "(", "value", ",", "name", ")", "{", "this", ".", "link", "(", "name", ",", "value", ")", ";", "}", ",", "this", ")", ";", "return", ";", "}", "var", "mt", "=", "this", ".", "$", "(", "'link[rel=\"'", "+", "rel", "+", "'\"]'", ")", ";", "if", "(", "mt", ".", "length", "===", "0", ")", "{", "mt", "=", "$", "(", "\"<link>\"", ",", "{", "}", ")", ".", "attr", "(", "\"rel\"", ",", "rel", ")", ".", "appendTo", "(", "this", ".", "$el", ")", ";", "}", "if", "(", "mimetype", "!=", "null", ")", "mt", ".", "attr", "(", "\"type\"", ",", "mimetype", ")", ";", "if", "(", "href", "!=", "null", ")", "{", "mt", ".", "attr", "(", "'href'", ",", "href", ")", ";", "}", "else", "{", "return", "mt", ".", "attr", "(", "'href'", ")", ";", "}", "}" ]
Set or get a link tag value @method link @param {string} ref name of the link tag @param {string} [href] value to set on the link tag @param {string} [mimetype] mimetype for this link @return {string} value of the link tag
[ "Set", "or", "get", "a", "link", "tag", "value" ]
bff0ea7f324de78ab8bf8c4301ce30696ad7d960
https://github.com/Reportr/dashboard/blob/bff0ea7f324de78ab8bf8c4301ce30696ad7d960/public/build/static/application.js#L23121-L23139
18,314
Reportr/dashboard
public/build/static/application.js
function(value, absolute) { var mt = this.$('title'); if (mt.length === 0) { mt = $("<title>", {}).appendTo(this.$el); } if (value != null) { this._title = value; if (absolute !== false) value = this.completeTitle(value); mt.text(value); } else { return mt.attr('content'); } }
javascript
function(value, absolute) { var mt = this.$('title'); if (mt.length === 0) { mt = $("<title>", {}).appendTo(this.$el); } if (value != null) { this._title = value; if (absolute !== false) value = this.completeTitle(value); mt.text(value); } else { return mt.attr('content'); } }
[ "function", "(", "value", ",", "absolute", ")", "{", "var", "mt", "=", "this", ".", "$", "(", "'title'", ")", ";", "if", "(", "mt", ".", "length", "===", "0", ")", "{", "mt", "=", "$", "(", "\"<title>\"", ",", "{", "}", ")", ".", "appendTo", "(", "this", ".", "$el", ")", ";", "}", "if", "(", "value", "!=", "null", ")", "{", "this", ".", "_title", "=", "value", ";", "if", "(", "absolute", "!==", "false", ")", "value", "=", "this", ".", "completeTitle", "(", "value", ")", ";", "mt", ".", "text", "(", "value", ")", ";", "}", "else", "{", "return", "mt", ".", "attr", "(", "'content'", ")", ";", "}", "}" ]
Set or get the page title @method title @param {string} value value for the title @param {boolean} [absolute] if true, it'll not use completeTitle @return {string} value of the title
[ "Set", "or", "get", "the", "page", "title" ]
bff0ea7f324de78ab8bf8c4301ce30696ad7d960
https://github.com/Reportr/dashboard/blob/bff0ea7f324de78ab8bf8c4301ce30696ad7d960/public/build/static/application.js#L23149-L23161
18,315
Reportr/dashboard
public/build/static/application.js
function(index, follow) { if (_.isNull(follow)) follow = index; var value = ""; value = index ? "index" : "noindex"; value = value + "," + (follow ? "follow" : "nofollow"); this.meta("robots", value); return this; }
javascript
function(index, follow) { if (_.isNull(follow)) follow = index; var value = ""; value = index ? "index" : "noindex"; value = value + "," + (follow ? "follow" : "nofollow"); this.meta("robots", value); return this; }
[ "function", "(", "index", ",", "follow", ")", "{", "if", "(", "_", ".", "isNull", "(", "follow", ")", ")", "follow", "=", "index", ";", "var", "value", "=", "\"\"", ";", "value", "=", "index", "?", "\"index\"", ":", "\"noindex\"", ";", "value", "=", "value", "+", "\",\"", "+", "(", "follow", "?", "\"follow\"", ":", "\"nofollow\"", ")", ";", "this", ".", "meta", "(", "\"robots\"", ",", "value", ")", ";", "return", "this", ";", "}" ]
Active or desactive page indexation using robots meta tag @method setCrawling @param {boolean} index @return {boolean} follow
[ "Active", "or", "desactive", "page", "indexation", "using", "robots", "meta", "tag" ]
bff0ea7f324de78ab8bf8c4301ce30696ad7d960
https://github.com/Reportr/dashboard/blob/bff0ea7f324de78ab8bf8c4301ce30696ad7d960/public/build/static/application.js#L23195-L23202
18,316
Reportr/dashboard
public/build/static/application.js
function() { if (this.started) { logging.warn("routing history already started"); return false; } var self = this; var $window = $(window); var rootUrl = document.location.protocol+'//'+(document.location.hostname||document.location.host); logging.log("start routing history"); $window.bind('hashchange', _.bind(this._handleCurrentState, this)); var ret = this._handleCurrentState(); this.started = true; return ret; }
javascript
function() { if (this.started) { logging.warn("routing history already started"); return false; } var self = this; var $window = $(window); var rootUrl = document.location.protocol+'//'+(document.location.hostname||document.location.host); logging.log("start routing history"); $window.bind('hashchange', _.bind(this._handleCurrentState, this)); var ret = this._handleCurrentState(); this.started = true; return ret; }
[ "function", "(", ")", "{", "if", "(", "this", ".", "started", ")", "{", "logging", ".", "warn", "(", "\"routing history already started\"", ")", ";", "return", "false", ";", "}", "var", "self", "=", "this", ";", "var", "$window", "=", "$", "(", "window", ")", ";", "var", "rootUrl", "=", "document", ".", "location", ".", "protocol", "+", "'//'", "+", "(", "document", ".", "location", ".", "hostname", "||", "document", ".", "location", ".", "host", ")", ";", "logging", ".", "log", "(", "\"start routing history\"", ")", ";", "$window", ".", "bind", "(", "'hashchange'", ",", "_", ".", "bind", "(", "this", ".", "_handleCurrentState", ",", "this", ")", ")", ";", "var", "ret", "=", "this", ".", "_handleCurrentState", "(", ")", ";", "this", ".", "started", "=", "true", ";", "return", "ret", ";", "}" ]
Add the navigation handling @method start @chainable
[ "Add", "the", "navigation", "handling" ]
bff0ea7f324de78ab8bf8c4301ce30696ad7d960
https://github.com/Reportr/dashboard/blob/bff0ea7f324de78ab8bf8c4301ce30696ad7d960/public/build/static/application.js#L23262-L23279
18,317
Reportr/dashboard
public/build/static/application.js
function(route, args) { url = urls.route(route, args); logging.log("navigate to ", url); window.location.hash = url; return this; }
javascript
function(route, args) { url = urls.route(route, args); logging.log("navigate to ", url); window.location.hash = url; return this; }
[ "function", "(", "route", ",", "args", ")", "{", "url", "=", "urls", ".", "route", "(", "route", ",", "args", ")", ";", "logging", ".", "log", "(", "\"navigate to \"", ",", "url", ")", ";", "window", ".", "location", ".", "hash", "=", "url", ";", "return", "this", ";", "}" ]
Navigation to a specific route @method navigate @param {string} route to navigate to @param {object} [args] arguments for the route @chainable
[ "Navigation", "to", "a", "specific", "route" ]
bff0ea7f324de78ab8bf8c4301ce30696ad7d960
https://github.com/Reportr/dashboard/blob/bff0ea7f324de78ab8bf8c4301ce30696ad7d960/public/build/static/application.js#L23289-L23294
18,318
Reportr/dashboard
public/build/static/application.js
function(route, name) { var handler; if (_.isObject(route) && !_.isRegExp(route)) { _.each(route, function(callback, route) { this.route(route, callback); }, this); return this; } handler = this[name]; if (handler == null) { handler = function() { var args = _.values(arguments); args.unshift('route:'+name); this.trigger.apply(this, args); }; } /** * Router controller for this application * * @property router * @type {Router} */ if (!this.router) this.router = new this.Router(); this.router.route(route, name, _.bind(handler, this)); return this; }
javascript
function(route, name) { var handler; if (_.isObject(route) && !_.isRegExp(route)) { _.each(route, function(callback, route) { this.route(route, callback); }, this); return this; } handler = this[name]; if (handler == null) { handler = function() { var args = _.values(arguments); args.unshift('route:'+name); this.trigger.apply(this, args); }; } /** * Router controller for this application * * @property router * @type {Router} */ if (!this.router) this.router = new this.Router(); this.router.route(route, name, _.bind(handler, this)); return this; }
[ "function", "(", "route", ",", "name", ")", "{", "var", "handler", ";", "if", "(", "_", ".", "isObject", "(", "route", ")", "&&", "!", "_", ".", "isRegExp", "(", "route", ")", ")", "{", "_", ".", "each", "(", "route", ",", "function", "(", "callback", ",", "route", ")", "{", "this", ".", "route", "(", "route", ",", "callback", ")", ";", "}", ",", "this", ")", ";", "return", "this", ";", "}", "handler", "=", "this", "[", "name", "]", ";", "if", "(", "handler", "==", "null", ")", "{", "handler", "=", "function", "(", ")", "{", "var", "args", "=", "_", ".", "values", "(", "arguments", ")", ";", "args", ".", "unshift", "(", "'route:'", "+", "name", ")", ";", "this", ".", "trigger", ".", "apply", "(", "this", ",", "args", ")", ";", "}", ";", "}", "/**\n * Router controller for this application\n *\n * @property router\n * @type {Router}\n */", "if", "(", "!", "this", ".", "router", ")", "this", ".", "router", "=", "new", "this", ".", "Router", "(", ")", ";", "this", ".", "router", ".", "route", "(", "route", ",", "name", ",", "_", ".", "bind", "(", "handler", ",", "this", ")", ")", ";", "return", "this", ";", "}" ]
Add new route @method route @param {string} route regex or route string @param {string} name method to use as a route callback @return {string} page title
[ "Add", "new", "route" ]
bff0ea7f324de78ab8bf8c4301ce30696ad7d960
https://github.com/Reportr/dashboard/blob/bff0ea7f324de78ab8bf8c4301ce30696ad7d960/public/build/static/application.js#L23560-L23587
18,319
Reportr/dashboard
public/build/static/application.js
function(models, options) { options = _.defaults(options || {}, { totalCount: false }); // Manage {list:[], n:0} for infinite list if (_.size(models) == 2 && models.list != null && models.n != null) { this._totalCount = models.n; return this.reset(models.list, options); } // Remove reference for (var i = 0, length = this.models.length; i < length; i++) { this._removeReference(this.models[i], options); } options.previousModels = this.models; this.options.startIndex = 0; this.models = []; this._byId = {}; if (options.totalCount) this._totalCount = null; this.add(models, _.extend({silent: true}, options || {})); options = _.defaults(options || {}, { silent: false }); if (!options.silent) this.trigger('reset', this, options); return this; }
javascript
function(models, options) { options = _.defaults(options || {}, { totalCount: false }); // Manage {list:[], n:0} for infinite list if (_.size(models) == 2 && models.list != null && models.n != null) { this._totalCount = models.n; return this.reset(models.list, options); } // Remove reference for (var i = 0, length = this.models.length; i < length; i++) { this._removeReference(this.models[i], options); } options.previousModels = this.models; this.options.startIndex = 0; this.models = []; this._byId = {}; if (options.totalCount) this._totalCount = null; this.add(models, _.extend({silent: true}, options || {})); options = _.defaults(options || {}, { silent: false }); if (!options.silent) this.trigger('reset', this, options); return this; }
[ "function", "(", "models", ",", "options", ")", "{", "options", "=", "_", ".", "defaults", "(", "options", "||", "{", "}", ",", "{", "totalCount", ":", "false", "}", ")", ";", "// Manage {list:[], n:0} for infinite list", "if", "(", "_", ".", "size", "(", "models", ")", "==", "2", "&&", "models", ".", "list", "!=", "null", "&&", "models", ".", "n", "!=", "null", ")", "{", "this", ".", "_totalCount", "=", "models", ".", "n", ";", "return", "this", ".", "reset", "(", "models", ".", "list", ",", "options", ")", ";", "}", "// Remove reference", "for", "(", "var", "i", "=", "0", ",", "length", "=", "this", ".", "models", ".", "length", ";", "i", "<", "length", ";", "i", "++", ")", "{", "this", ".", "_removeReference", "(", "this", ".", "models", "[", "i", "]", ",", "options", ")", ";", "}", "options", ".", "previousModels", "=", "this", ".", "models", ";", "this", ".", "options", ".", "startIndex", "=", "0", ";", "this", ".", "models", "=", "[", "]", ";", "this", ".", "_byId", "=", "{", "}", ";", "if", "(", "options", ".", "totalCount", ")", "this", ".", "_totalCount", "=", "null", ";", "this", ".", "add", "(", "models", ",", "_", ".", "extend", "(", "{", "silent", ":", "true", "}", ",", "options", "||", "{", "}", ")", ")", ";", "options", "=", "_", ".", "defaults", "(", "options", "||", "{", "}", ",", "{", "silent", ":", "false", "}", ")", ";", "if", "(", "!", "options", ".", "silent", ")", "this", ".", "trigger", "(", "'reset'", ",", "this", ",", "options", ")", ";", "return", "this", ";", "}" ]
Reset the collection with new models or new data. @method reset @param {array} models array of models or data to set in the collection @param {object} [options] options for reseting @chainable
[ "Reset", "the", "collection", "with", "new", "models", "or", "new", "data", "." ]
bff0ea7f324de78ab8bf8c4301ce30696ad7d960
https://github.com/Reportr/dashboard/blob/bff0ea7f324de78ab8bf8c4301ce30696ad7d960/public/build/static/application.js#L24829-L24856
18,320
Reportr/dashboard
public/build/static/application.js
function(model, options) { var index; if (_.isArray(model)) { _.each(model, function(m) { this.remove(m, options); }, this); return this; } options = _.defaults(options || {}, { silent: false }); model = this._prepareModel(model); _.each(this.models, function(m, i) { if (!m || model.id == m.id) { this.models.splice(i, 1); index = i; return; } }, this); delete this._byId[model.id]; if (options.silent) return this; options.index = index; if (this._totalCount != null) this._totalCount = _.max([0, this._totalCount - 1]); this.trigger('remove', model, this, options); this._removeReference(model); return this; }
javascript
function(model, options) { var index; if (_.isArray(model)) { _.each(model, function(m) { this.remove(m, options); }, this); return this; } options = _.defaults(options || {}, { silent: false }); model = this._prepareModel(model); _.each(this.models, function(m, i) { if (!m || model.id == m.id) { this.models.splice(i, 1); index = i; return; } }, this); delete this._byId[model.id]; if (options.silent) return this; options.index = index; if (this._totalCount != null) this._totalCount = _.max([0, this._totalCount - 1]); this.trigger('remove', model, this, options); this._removeReference(model); return this; }
[ "function", "(", "model", ",", "options", ")", "{", "var", "index", ";", "if", "(", "_", ".", "isArray", "(", "model", ")", ")", "{", "_", ".", "each", "(", "model", ",", "function", "(", "m", ")", "{", "this", ".", "remove", "(", "m", ",", "options", ")", ";", "}", ",", "this", ")", ";", "return", "this", ";", "}", "options", "=", "_", ".", "defaults", "(", "options", "||", "{", "}", ",", "{", "silent", ":", "false", "}", ")", ";", "model", "=", "this", ".", "_prepareModel", "(", "model", ")", ";", "_", ".", "each", "(", "this", ".", "models", ",", "function", "(", "m", ",", "i", ")", "{", "if", "(", "!", "m", "||", "model", ".", "id", "==", "m", ".", "id", ")", "{", "this", ".", "models", ".", "splice", "(", "i", ",", "1", ")", ";", "index", "=", "i", ";", "return", ";", "}", "}", ",", "this", ")", ";", "delete", "this", ".", "_byId", "[", "model", ".", "id", "]", ";", "if", "(", "options", ".", "silent", ")", "return", "this", ";", "options", ".", "index", "=", "index", ";", "if", "(", "this", ".", "_totalCount", "!=", "null", ")", "this", ".", "_totalCount", "=", "_", ".", "max", "(", "[", "0", ",", "this", ".", "_totalCount", "-", "1", "]", ")", ";", "this", ".", "trigger", "(", "'remove'", ",", "model", ",", "this", ",", "options", ")", ";", "this", ".", "_removeReference", "(", "model", ")", ";", "return", "this", ";", "}" ]
Remove a model from the collection. @method remove @param {Model} model model or data to remove @param {object} [options] options for removing @chainable
[ "Remove", "a", "model", "from", "the", "collection", "." ]
bff0ea7f324de78ab8bf8c4301ce30696ad7d960
https://github.com/Reportr/dashboard/blob/bff0ea7f324de78ab8bf8c4301ce30696ad7d960/public/build/static/application.js#L24929-L24961
18,321
Reportr/dashboard
public/build/static/application.js
function(model, options) { model = this._prepareModel(model, options); this.add(model, options); return model; }
javascript
function(model, options) { model = this._prepareModel(model, options); this.add(model, options); return model; }
[ "function", "(", "model", ",", "options", ")", "{", "model", "=", "this", ".", "_prepareModel", "(", "model", ",", "options", ")", ";", "this", ".", "add", "(", "model", ",", "options", ")", ";", "return", "model", ";", "}" ]
Add a model at the end of the collection. @method push @param {Model} model model or data to add @param {object} [options] options for adding @return {Model} Return the new added model
[ "Add", "a", "model", "at", "the", "end", "of", "the", "collection", "." ]
bff0ea7f324de78ab8bf8c4301ce30696ad7d960
https://github.com/Reportr/dashboard/blob/bff0ea7f324de78ab8bf8c4301ce30696ad7d960/public/build/static/application.js#L25000-L25004
18,322
Reportr/dashboard
public/build/static/application.js
function(options) { this.queue.defer(function() { options = _.defaults(options || {}, { refresh: false }); var d, self = this; if (this.options.loader == null) return this; if (options.refresh) { this.options.startIndex = 0; this._totalCount = null; this.reset([]); } if (this._totalCount == null || this.hasMore() > 0 || options.refresh) { this.options.startIndex = this.options.startIndex || 0; d = Q(this[this.options.loader].apply(this, this.options.loaderArgs || [])); d.done(function() { self.options.startIndex = self.options.startIndex + self.options.limit }); } else { d = Q.reject(); } return d; }, this); return this; }
javascript
function(options) { this.queue.defer(function() { options = _.defaults(options || {}, { refresh: false }); var d, self = this; if (this.options.loader == null) return this; if (options.refresh) { this.options.startIndex = 0; this._totalCount = null; this.reset([]); } if (this._totalCount == null || this.hasMore() > 0 || options.refresh) { this.options.startIndex = this.options.startIndex || 0; d = Q(this[this.options.loader].apply(this, this.options.loaderArgs || [])); d.done(function() { self.options.startIndex = self.options.startIndex + self.options.limit }); } else { d = Q.reject(); } return d; }, this); return this; }
[ "function", "(", "options", ")", "{", "this", ".", "queue", ".", "defer", "(", "function", "(", ")", "{", "options", "=", "_", ".", "defaults", "(", "options", "||", "{", "}", ",", "{", "refresh", ":", "false", "}", ")", ";", "var", "d", ",", "self", "=", "this", ";", "if", "(", "this", ".", "options", ".", "loader", "==", "null", ")", "return", "this", ";", "if", "(", "options", ".", "refresh", ")", "{", "this", ".", "options", ".", "startIndex", "=", "0", ";", "this", ".", "_totalCount", "=", "null", ";", "this", ".", "reset", "(", "[", "]", ")", ";", "}", "if", "(", "this", ".", "_totalCount", "==", "null", "||", "this", ".", "hasMore", "(", ")", ">", "0", "||", "options", ".", "refresh", ")", "{", "this", ".", "options", ".", "startIndex", "=", "this", ".", "options", ".", "startIndex", "||", "0", ";", "d", "=", "Q", "(", "this", "[", "this", ".", "options", ".", "loader", "]", ".", "apply", "(", "this", ",", "this", ".", "options", ".", "loaderArgs", "||", "[", "]", ")", ")", ";", "d", ".", "done", "(", "function", "(", ")", "{", "self", ".", "options", ".", "startIndex", "=", "self", ".", "options", ".", "startIndex", "+", "self", ".", "options", ".", "limit", "}", ")", ";", "}", "else", "{", "d", "=", "Q", ".", "reject", "(", ")", ";", "}", "return", "d", ";", "}", ",", "this", ")", ";", "return", "this", ";", "}" ]
Get more elements from an infinite collection @method getMore @chainable
[ "Get", "more", "elements", "from", "an", "infinite", "collection" ]
bff0ea7f324de78ab8bf8c4301ce30696ad7d960
https://github.com/Reportr/dashboard/blob/bff0ea7f324de78ab8bf8c4301ce30696ad7d960/public/build/static/application.js#L25134-L25162
18,323
Reportr/dashboard
public/build/static/application.js
function(method, properties) { if (this.methods[method]) throw "Method already define for this backend: "+method; properties.id = method; properties.regexp = this.routeToRegExp(method); this.methods[method] = properties; return this; }
javascript
function(method, properties) { if (this.methods[method]) throw "Method already define for this backend: "+method; properties.id = method; properties.regexp = this.routeToRegExp(method); this.methods[method] = properties; return this; }
[ "function", "(", "method", ",", "properties", ")", "{", "if", "(", "this", ".", "methods", "[", "method", "]", ")", "throw", "\"Method already define for this backend: \"", "+", "method", ";", "properties", ".", "id", "=", "method", ";", "properties", ".", "regexp", "=", "this", ".", "routeToRegExp", "(", "method", ")", ";", "this", ".", "methods", "[", "method", "]", "=", "properties", ";", "return", "this", ";", "}" ]
Add a backend method @method addMethod @param {string} method name for this method @param {object} informations about this method
[ "Add", "a", "backend", "method" ]
bff0ea7f324de78ab8bf8c4301ce30696ad7d960
https://github.com/Reportr/dashboard/blob/bff0ea7f324de78ab8bf8c4301ce30696ad7d960/public/build/static/application.js#L25705-L25713
18,324
Reportr/dashboard
public/build/static/application.js
function(method, sId) { sId = sId || method; sId = this.options.prefix+"."+sId; return this.addMethod(method, { fallback: function(args, options, method) { return Storage.get(sId+"."+method); }, after: function(args, results, options, method) { Storage.set(sId+"."+method, results); } }); }
javascript
function(method, sId) { sId = sId || method; sId = this.options.prefix+"."+sId; return this.addMethod(method, { fallback: function(args, options, method) { return Storage.get(sId+"."+method); }, after: function(args, results, options, method) { Storage.set(sId+"."+method, results); } }); }
[ "function", "(", "method", ",", "sId", ")", "{", "sId", "=", "sId", "||", "method", ";", "sId", "=", "this", ".", "options", ".", "prefix", "+", "\".\"", "+", "sId", ";", "return", "this", ".", "addMethod", "(", "method", ",", "{", "fallback", ":", "function", "(", "args", ",", "options", ",", "method", ")", "{", "return", "Storage", ".", "get", "(", "sId", "+", "\".\"", "+", "method", ")", ";", "}", ",", "after", ":", "function", "(", "args", ",", "results", ",", "options", ",", "method", ")", "{", "Storage", ".", "set", "(", "sId", "+", "\".\"", "+", "method", ",", "results", ")", ";", "}", "}", ")", ";", "}" ]
Add a cached method for offline mode only @method addCachedMethod @param {string} method name for this method @param {string} [sId] id used for caching
[ "Add", "a", "cached", "method", "for", "offline", "mode", "only" ]
bff0ea7f324de78ab8bf8c4301ce30696ad7d960
https://github.com/Reportr/dashboard/blob/bff0ea7f324de78ab8bf8c4301ce30696ad7d960/public/build/static/application.js#L25722-L25733
18,325
Reportr/dashboard
public/build/static/application.js
function(method) { return _.find(this.methods, function(handler) { return handler.regexp.test(method); }) || this.defaultHandler; }
javascript
function(method) { return _.find(this.methods, function(handler) { return handler.regexp.test(method); }) || this.defaultHandler; }
[ "function", "(", "method", ")", "{", "return", "_", ".", "find", "(", "this", ".", "methods", ",", "function", "(", "handler", ")", "{", "return", "handler", ".", "regexp", ".", "test", "(", "method", ")", ";", "}", ")", "||", "this", ".", "defaultHandler", ";", "}" ]
Get the method handler to use for a method @method getHandler
[ "Get", "the", "method", "handler", "to", "use", "for", "a", "method" ]
bff0ea7f324de78ab8bf8c4301ce30696ad7d960
https://github.com/Reportr/dashboard/blob/bff0ea7f324de78ab8bf8c4301ce30696ad7d960/public/build/static/application.js#L25740-L25744
18,326
Reportr/dashboard
public/build/static/application.js
function(method, args, options) { var that = this, methodHandler; options = options || {}; var handler = this.getHandler(method); if (!handler) return Q.reject(new Error("No handler found for method: "+method)); // Is offline if (!Offline.isConnected()) { methodHandler = handler.fallback; } methodHandler = methodHandler || handler.execute || this.defaultHandler.execute; // No default if (!methodHandler) { return Q.reject(new Error("No handler found for this method in this backend")); } return Q(methodHandler(args, options, method)).then(function(results) { if (handler.after) { return Q.all([ Q(handler.after(args, results, options, method)), Q((that.defaultHandler.after || function() {})(args, results, options, method)) ]).then(function() { return Q(results); }, function() { return Q(results); }); } return results; }); }
javascript
function(method, args, options) { var that = this, methodHandler; options = options || {}; var handler = this.getHandler(method); if (!handler) return Q.reject(new Error("No handler found for method: "+method)); // Is offline if (!Offline.isConnected()) { methodHandler = handler.fallback; } methodHandler = methodHandler || handler.execute || this.defaultHandler.execute; // No default if (!methodHandler) { return Q.reject(new Error("No handler found for this method in this backend")); } return Q(methodHandler(args, options, method)).then(function(results) { if (handler.after) { return Q.all([ Q(handler.after(args, results, options, method)), Q((that.defaultHandler.after || function() {})(args, results, options, method)) ]).then(function() { return Q(results); }, function() { return Q(results); }); } return results; }); }
[ "function", "(", "method", ",", "args", ",", "options", ")", "{", "var", "that", "=", "this", ",", "methodHandler", ";", "options", "=", "options", "||", "{", "}", ";", "var", "handler", "=", "this", ".", "getHandler", "(", "method", ")", ";", "if", "(", "!", "handler", ")", "return", "Q", ".", "reject", "(", "new", "Error", "(", "\"No handler found for method: \"", "+", "method", ")", ")", ";", "// Is offline", "if", "(", "!", "Offline", ".", "isConnected", "(", ")", ")", "{", "methodHandler", "=", "handler", ".", "fallback", ";", "}", "methodHandler", "=", "methodHandler", "||", "handler", ".", "execute", "||", "this", ".", "defaultHandler", ".", "execute", ";", "// No default", "if", "(", "!", "methodHandler", ")", "{", "return", "Q", ".", "reject", "(", "new", "Error", "(", "\"No handler found for this method in this backend\"", ")", ")", ";", "}", "return", "Q", "(", "methodHandler", "(", "args", ",", "options", ",", "method", ")", ")", ".", "then", "(", "function", "(", "results", ")", "{", "if", "(", "handler", ".", "after", ")", "{", "return", "Q", ".", "all", "(", "[", "Q", "(", "handler", ".", "after", "(", "args", ",", "results", ",", "options", ",", "method", ")", ")", ",", "Q", "(", "(", "that", ".", "defaultHandler", ".", "after", "||", "function", "(", ")", "{", "}", ")", "(", "args", ",", "results", ",", "options", ",", "method", ")", ")", "]", ")", ".", "then", "(", "function", "(", ")", "{", "return", "Q", "(", "results", ")", ";", "}", ",", "function", "(", ")", "{", "return", "Q", "(", "results", ")", ";", "}", ")", ";", "}", "return", "results", ";", "}", ")", ";", "}" ]
Execute a method @method execute @param {string} method name of the method to execute @param {object} args arguments for this method @param {options} [options] options for execution @return {promise<object>}
[ "Execute", "a", "method" ]
bff0ea7f324de78ab8bf8c4301ce30696ad7d960
https://github.com/Reportr/dashboard/blob/bff0ea7f324de78ab8bf8c4301ce30696ad7d960/public/build/static/application.js#L25767-L25799
18,327
Reportr/dashboard
public/build/static/application.js
function (url, protocol, hostname, port) { var match = text.xdRegExp.exec(url), uProtocol, uHostName, uPort; if (!match) { return true; } uProtocol = match[2]; uHostName = match[3]; uHostName = uHostName.split(':'); uPort = uHostName[1]; uHostName = uHostName[0]; return (!uProtocol || uProtocol === protocol) && (!uHostName || uHostName === hostname) && ((!uPort && !uHostName) || uPort === port); }
javascript
function (url, protocol, hostname, port) { var match = text.xdRegExp.exec(url), uProtocol, uHostName, uPort; if (!match) { return true; } uProtocol = match[2]; uHostName = match[3]; uHostName = uHostName.split(':'); uPort = uHostName[1]; uHostName = uHostName[0]; return (!uProtocol || uProtocol === protocol) && (!uHostName || uHostName === hostname) && ((!uPort && !uHostName) || uPort === port); }
[ "function", "(", "url", ",", "protocol", ",", "hostname", ",", "port", ")", "{", "var", "match", "=", "text", ".", "xdRegExp", ".", "exec", "(", "url", ")", ",", "uProtocol", ",", "uHostName", ",", "uPort", ";", "if", "(", "!", "match", ")", "{", "return", "true", ";", "}", "uProtocol", "=", "match", "[", "2", "]", ";", "uHostName", "=", "match", "[", "3", "]", ";", "uHostName", "=", "uHostName", ".", "split", "(", "':'", ")", ";", "uPort", "=", "uHostName", "[", "1", "]", ";", "uHostName", "=", "uHostName", "[", "0", "]", ";", "return", "(", "!", "uProtocol", "||", "uProtocol", "===", "protocol", ")", "&&", "(", "!", "uHostName", "||", "uHostName", "===", "hostname", ")", "&&", "(", "(", "!", "uPort", "&&", "!", "uHostName", ")", "||", "uPort", "===", "port", ")", ";", "}" ]
Is an URL on another domain. Only works for browser use, returns false in non-browser environments. Only used to know if an optimized .js version of a text resource should be loaded instead. @param {String} url @returns Boolean
[ "Is", "an", "URL", "on", "another", "domain", ".", "Only", "works", "for", "browser", "use", "returns", "false", "in", "non", "-", "browser", "environments", ".", "Only", "used", "to", "know", "if", "an", "optimized", ".", "js", "version", "of", "a", "text", "resource", "should", "be", "loaded", "instead", "." ]
bff0ea7f324de78ab8bf8c4301ce30696ad7d960
https://github.com/Reportr/dashboard/blob/bff0ea7f324de78ab8bf8c4301ce30696ad7d960/public/build/static/application.js#L26162-L26178
18,328
Reportr/dashboard
public/build/static/application.js
function(cls, options) { var d = Q.defer(); cls = cls || DialogView; var diag = new cls(options); diag.once("close", function(result, e) { if (result != null) { d.resolve(result); } else { d.reject(result); } }); setTimeout(function() { d.notify(diag); }, 1); diag.update(); return d.promise; }
javascript
function(cls, options) { var d = Q.defer(); cls = cls || DialogView; var diag = new cls(options); diag.once("close", function(result, e) { if (result != null) { d.resolve(result); } else { d.reject(result); } }); setTimeout(function() { d.notify(diag); }, 1); diag.update(); return d.promise; }
[ "function", "(", "cls", ",", "options", ")", "{", "var", "d", "=", "Q", ".", "defer", "(", ")", ";", "cls", "=", "cls", "||", "DialogView", ";", "var", "diag", "=", "new", "cls", "(", "options", ")", ";", "diag", ".", "once", "(", "\"close\"", ",", "function", "(", "result", ",", "e", ")", "{", "if", "(", "result", "!=", "null", ")", "{", "d", ".", "resolve", "(", "result", ")", ";", "}", "else", "{", "d", ".", "reject", "(", "result", ")", ";", "}", "}", ")", ";", "setTimeout", "(", "function", "(", ")", "{", "d", ".", "notify", "(", "diag", ")", ";", "}", ",", "1", ")", ";", "diag", ".", "update", "(", ")", ";", "return", "d", ".", "promise", ";", "}" ]
Open a dialog from a specific view class with some configuration @param {DialogView} cls dialog view class @param {options} options dialog view constructor options @return {promise}
[ "Open", "a", "dialog", "from", "a", "specific", "view", "class", "with", "some", "configuration" ]
bff0ea7f324de78ab8bf8c4301ce30696ad7d960
https://github.com/Reportr/dashboard/blob/bff0ea7f324de78ab8bf8c4301ce30696ad7d960/public/build/static/application.js#L26446-L26465
18,329
Reportr/dashboard
public/build/static/application.js
function(title, message, defaultmsg) { return Dialogs.open(null, { "title": title, "message": message, "dialog": "prompt", "default": defaultmsg, "autoFocus": true, "valueSelector": "selectorPrompt" }); }
javascript
function(title, message, defaultmsg) { return Dialogs.open(null, { "title": title, "message": message, "dialog": "prompt", "default": defaultmsg, "autoFocus": true, "valueSelector": "selectorPrompt" }); }
[ "function", "(", "title", ",", "message", ",", "defaultmsg", ")", "{", "return", "Dialogs", ".", "open", "(", "null", ",", "{", "\"title\"", ":", "title", ",", "\"message\"", ":", "message", ",", "\"dialog\"", ":", "\"prompt\"", ",", "\"default\"", ":", "defaultmsg", ",", "\"autoFocus\"", ":", "true", ",", "\"valueSelector\"", ":", "\"selectorPrompt\"", "}", ")", ";", "}" ]
Open a prompt modal dialog @param {string} title @param {string} message @param {string} defaultmsg
[ "Open", "a", "prompt", "modal", "dialog" ]
bff0ea7f324de78ab8bf8c4301ce30696ad7d960
https://github.com/Reportr/dashboard/blob/bff0ea7f324de78ab8bf8c4301ce30696ad7d960/public/build/static/application.js#L26512-L26521
18,330
Reportr/dashboard
public/build/static/application.js
function(title, message, choices, defaultChoice) { return Dialogs.open(null, { "title": title, "message": message, "dialog": "select", "default": defaultChoice, "choices": choices, "autoFocus": true, "valueSelector": "selectorPrompt" }); }
javascript
function(title, message, choices, defaultChoice) { return Dialogs.open(null, { "title": title, "message": message, "dialog": "select", "default": defaultChoice, "choices": choices, "autoFocus": true, "valueSelector": "selectorPrompt" }); }
[ "function", "(", "title", ",", "message", ",", "choices", ",", "defaultChoice", ")", "{", "return", "Dialogs", ".", "open", "(", "null", ",", "{", "\"title\"", ":", "title", ",", "\"message\"", ":", "message", ",", "\"dialog\"", ":", "\"select\"", ",", "\"default\"", ":", "defaultChoice", ",", "\"choices\"", ":", "choices", ",", "\"autoFocus\"", ":", "true", ",", "\"valueSelector\"", ":", "\"selectorPrompt\"", "}", ")", ";", "}" ]
Open a select modal dialog @param {string} title @param {string} message @param {object} choices @param {string} defaultChoice
[ "Open", "a", "select", "modal", "dialog" ]
bff0ea7f324de78ab8bf8c4301ce30696ad7d960
https://github.com/Reportr/dashboard/blob/bff0ea7f324de78ab8bf8c4301ce30696ad7d960/public/build/static/application.js#L26531-L26541
18,331
Reportr/dashboard
public/build/static/application.js
function(title, message) { if (!message) { message = title; title = null; } return Dialogs.open(null, { "title": title, "message": message, "dialog": "confirm" }); }
javascript
function(title, message) { if (!message) { message = title; title = null; } return Dialogs.open(null, { "title": title, "message": message, "dialog": "confirm" }); }
[ "function", "(", "title", ",", "message", ")", "{", "if", "(", "!", "message", ")", "{", "message", "=", "title", ";", "title", "=", "null", ";", "}", "return", "Dialogs", ".", "open", "(", "null", ",", "{", "\"title\"", ":", "title", ",", "\"message\"", ":", "message", ",", "\"dialog\"", ":", "\"confirm\"", "}", ")", ";", "}" ]
Open a confirmation modal dialog @param {string} title @param {string} message
[ "Open", "a", "confirmation", "modal", "dialog" ]
bff0ea7f324de78ab8bf8c4301ce30696ad7d960
https://github.com/Reportr/dashboard/blob/bff0ea7f324de78ab8bf8c4301ce30696ad7d960/public/build/static/application.js#L26549-L26560
18,332
Reportr/dashboard
public/build/static/application.js
function(err) { Dialogs.alert("Error:", err.message || err); console.error(err.stack || err.message || err); return Q.reject(err); }
javascript
function(err) { Dialogs.alert("Error:", err.message || err); console.error(err.stack || err.message || err); return Q.reject(err); }
[ "function", "(", "err", ")", "{", "Dialogs", ".", "alert", "(", "\"Error:\"", ",", "err", ".", "message", "||", "err", ")", ";", "console", ".", "error", "(", "err", ".", "stack", "||", "err", ".", "message", "||", "err", ")", ";", "return", "Q", ".", "reject", "(", "err", ")", ";", "}" ]
Show an error message
[ "Show", "an", "error", "message" ]
bff0ea7f324de78ab8bf8c4301ce30696ad7d960
https://github.com/Reportr/dashboard/blob/bff0ea7f324de78ab8bf8c4301ce30696ad7d960/public/build/static/application.js#L26579-L26583
18,333
Reportr/dashboard
public/build/static/application.js
dfl
function dfl(a, b, c) { switch (arguments.length) { case 2: return a != null ? a : b; case 3: return a != null ? a : b != null ? b : c; default: throw new Error("Implement me"); } }
javascript
function dfl(a, b, c) { switch (arguments.length) { case 2: return a != null ? a : b; case 3: return a != null ? a : b != null ? b : c; default: throw new Error("Implement me"); } }
[ "function", "dfl", "(", "a", ",", "b", ",", "c", ")", "{", "switch", "(", "arguments", ".", "length", ")", "{", "case", "2", ":", "return", "a", "!=", "null", "?", "a", ":", "b", ";", "case", "3", ":", "return", "a", "!=", "null", "?", "a", ":", "b", "!=", "null", "?", "b", ":", "c", ";", "default", ":", "throw", "new", "Error", "(", "\"Implement me\"", ")", ";", "}", "}" ]
Pick the first defined of two or three arguments. dfl comes from default.
[ "Pick", "the", "first", "defined", "of", "two", "or", "three", "arguments", ".", "dfl", "comes", "from", "default", "." ]
bff0ea7f324de78ab8bf8c4301ce30696ad7d960
https://github.com/Reportr/dashboard/blob/bff0ea7f324de78ab8bf8c4301ce30696ad7d960/public/build/static/application.js#L27061-L27067
18,334
Reportr/dashboard
public/build/static/application.js
setProjection
function setProjection( element, options ) { var width = options.width || element.offsetWidth; var height = options.height || element.offsetHeight; var projection, path; if ( options && typeof options.scope === 'undefined') { options.scope = 'world'; } if ( options.scope === 'usa' ) { projection = d3.geo.albersUsa() .scale(width) .translate([width / 2, height / 2]); } else if ( options.scope === 'world' ) { projection = d3.geo[options.projection]() .scale((width + 1) / 2 / Math.PI) .translate([width / 2, height / (options.projection === "mercator" ? 1.45 : 1.8)]); } path = d3.geo.path() .projection( projection ); return {path: path, projection: projection}; }
javascript
function setProjection( element, options ) { var width = options.width || element.offsetWidth; var height = options.height || element.offsetHeight; var projection, path; if ( options && typeof options.scope === 'undefined') { options.scope = 'world'; } if ( options.scope === 'usa' ) { projection = d3.geo.albersUsa() .scale(width) .translate([width / 2, height / 2]); } else if ( options.scope === 'world' ) { projection = d3.geo[options.projection]() .scale((width + 1) / 2 / Math.PI) .translate([width / 2, height / (options.projection === "mercator" ? 1.45 : 1.8)]); } path = d3.geo.path() .projection( projection ); return {path: path, projection: projection}; }
[ "function", "setProjection", "(", "element", ",", "options", ")", "{", "var", "width", "=", "options", ".", "width", "||", "element", ".", "offsetWidth", ";", "var", "height", "=", "options", ".", "height", "||", "element", ".", "offsetHeight", ";", "var", "projection", ",", "path", ";", "if", "(", "options", "&&", "typeof", "options", ".", "scope", "===", "'undefined'", ")", "{", "options", ".", "scope", "=", "'world'", ";", "}", "if", "(", "options", ".", "scope", "===", "'usa'", ")", "{", "projection", "=", "d3", ".", "geo", ".", "albersUsa", "(", ")", ".", "scale", "(", "width", ")", ".", "translate", "(", "[", "width", "/", "2", ",", "height", "/", "2", "]", ")", ";", "}", "else", "if", "(", "options", ".", "scope", "===", "'world'", ")", "{", "projection", "=", "d3", ".", "geo", "[", "options", ".", "projection", "]", "(", ")", ".", "scale", "(", "(", "width", "+", "1", ")", "/", "2", "/", "Math", ".", "PI", ")", ".", "translate", "(", "[", "width", "/", "2", ",", "height", "/", "(", "options", ".", "projection", "===", "\"mercator\"", "?", "1.45", ":", "1.8", ")", "]", ")", ";", "}", "path", "=", "d3", ".", "geo", ".", "path", "(", ")", ".", "projection", "(", "projection", ")", ";", "return", "{", "path", ":", "path", ",", "projection", ":", "projection", "}", ";", "}" ]
setProjection takes the svg element and options
[ "setProjection", "takes", "the", "svg", "element", "and", "options" ]
bff0ea7f324de78ab8bf8c4301ce30696ad7d960
https://github.com/Reportr/dashboard/blob/bff0ea7f324de78ab8bf8c4301ce30696ad7d960/public/build/static/application.js#L43432-L43455
18,335
Reportr/dashboard
public/build/static/application.js
addLegend
function addLegend(layer, data, options) { data = data || {}; if ( !this.options.fills ) { return; } var html = '<dl>'; var label = ''; if ( data.legendTitle ) { html = '<h2>' + data.legendTitle + '</h2>' + html; } for ( var fillKey in this.options.fills ) { if ( fillKey === 'defaultFill') { if (! data.defaultFillName ) { continue; } label = data.defaultFillName; } else { if (data.labels && data.labels[fillKey]) { label = data.labels[fillKey]; } else { label= fillKey + ': '; } } html += '<dt>' + label + '</dt>'; html += '<dd style="background-color:' + this.options.fills[fillKey] + '">&nbsp;</dd>'; } html += '</dl>'; var hoverover = d3.select( this.options.element ).append('div') .attr('class', 'datamaps-legend') .html(html); }
javascript
function addLegend(layer, data, options) { data = data || {}; if ( !this.options.fills ) { return; } var html = '<dl>'; var label = ''; if ( data.legendTitle ) { html = '<h2>' + data.legendTitle + '</h2>' + html; } for ( var fillKey in this.options.fills ) { if ( fillKey === 'defaultFill') { if (! data.defaultFillName ) { continue; } label = data.defaultFillName; } else { if (data.labels && data.labels[fillKey]) { label = data.labels[fillKey]; } else { label= fillKey + ': '; } } html += '<dt>' + label + '</dt>'; html += '<dd style="background-color:' + this.options.fills[fillKey] + '">&nbsp;</dd>'; } html += '</dl>'; var hoverover = d3.select( this.options.element ).append('div') .attr('class', 'datamaps-legend') .html(html); }
[ "function", "addLegend", "(", "layer", ",", "data", ",", "options", ")", "{", "data", "=", "data", "||", "{", "}", ";", "if", "(", "!", "this", ".", "options", ".", "fills", ")", "{", "return", ";", "}", "var", "html", "=", "'<dl>'", ";", "var", "label", "=", "''", ";", "if", "(", "data", ".", "legendTitle", ")", "{", "html", "=", "'<h2>'", "+", "data", ".", "legendTitle", "+", "'</h2>'", "+", "html", ";", "}", "for", "(", "var", "fillKey", "in", "this", ".", "options", ".", "fills", ")", "{", "if", "(", "fillKey", "===", "'defaultFill'", ")", "{", "if", "(", "!", "data", ".", "defaultFillName", ")", "{", "continue", ";", "}", "label", "=", "data", ".", "defaultFillName", ";", "}", "else", "{", "if", "(", "data", ".", "labels", "&&", "data", ".", "labels", "[", "fillKey", "]", ")", "{", "label", "=", "data", ".", "labels", "[", "fillKey", "]", ";", "}", "else", "{", "label", "=", "fillKey", "+", "': '", ";", "}", "}", "html", "+=", "'<dt>'", "+", "label", "+", "'</dt>'", ";", "html", "+=", "'<dd style=\"background-color:'", "+", "this", ".", "options", ".", "fills", "[", "fillKey", "]", "+", "'\">&nbsp;</dd>'", ";", "}", "html", "+=", "'</dl>'", ";", "var", "hoverover", "=", "d3", ".", "select", "(", "this", ".", "options", ".", "element", ")", ".", "append", "(", "'div'", ")", ".", "attr", "(", "'class'", ",", "'datamaps-legend'", ")", ".", "html", "(", "html", ")", ";", "}" ]
plugin to add a simple map legend
[ "plugin", "to", "add", "a", "simple", "map", "legend" ]
bff0ea7f324de78ab8bf8c4301ce30696ad7d960
https://github.com/Reportr/dashboard/blob/bff0ea7f324de78ab8bf8c4301ce30696ad7d960/public/build/static/application.js#L43563-L43596
18,336
Reportr/dashboard
public/build/static/application.js
defaults
function defaults(obj) { Array.prototype.slice.call(arguments, 1).forEach(function(source) { if (source) { for (var prop in source) { if (obj[prop] == null) obj[prop] = source[prop]; } } }); return obj; }
javascript
function defaults(obj) { Array.prototype.slice.call(arguments, 1).forEach(function(source) { if (source) { for (var prop in source) { if (obj[prop] == null) obj[prop] = source[prop]; } } }); return obj; }
[ "function", "defaults", "(", "obj", ")", "{", "Array", ".", "prototype", ".", "slice", ".", "call", "(", "arguments", ",", "1", ")", ".", "forEach", "(", "function", "(", "source", ")", "{", "if", "(", "source", ")", "{", "for", "(", "var", "prop", "in", "source", ")", "{", "if", "(", "obj", "[", "prop", "]", "==", "null", ")", "obj", "[", "prop", "]", "=", "source", "[", "prop", "]", ";", "}", "}", "}", ")", ";", "return", "obj", ";", "}" ]
stolen from underscore.js
[ "stolen", "from", "underscore", ".", "js" ]
bff0ea7f324de78ab8bf8c4301ce30696ad7d960
https://github.com/Reportr/dashboard/blob/bff0ea7f324de78ab8bf8c4301ce30696ad7d960/public/build/static/application.js#L43811-L43820
18,337
Reportr/dashboard
public/build/static/application.js
function(data) { var that = this; data = data || this.toJSON(); return api.execute("put:report/"+this.get("id"), data) .then(function(_data) { that.set(_data); return that; }); }
javascript
function(data) { var that = this; data = data || this.toJSON(); return api.execute("put:report/"+this.get("id"), data) .then(function(_data) { that.set(_data); return that; }); }
[ "function", "(", "data", ")", "{", "var", "that", "=", "this", ";", "data", "=", "data", "||", "this", ".", "toJSON", "(", ")", ";", "return", "api", ".", "execute", "(", "\"put:report/\"", "+", "this", ".", "get", "(", "\"id\"", ")", ",", "data", ")", ".", "then", "(", "function", "(", "_data", ")", "{", "that", ".", "set", "(", "_data", ")", ";", "return", "that", ";", "}", ")", ";", "}" ]
Update a report
[ "Update", "a", "report" ]
bff0ea7f324de78ab8bf8c4301ce30696ad7d960
https://github.com/Reportr/dashboard/blob/bff0ea7f324de78ab8bf8c4301ce30696ad7d960/public/build/static/application.js#L55720-L55729
18,338
Reportr/dashboard
public/build/static/application.js
function() { var that = this; return api.execute("get:alerts") .then(function(data) { console.log("alerts", data); that.reset(data); return that; }); }
javascript
function() { var that = this; return api.execute("get:alerts") .then(function(data) { console.log("alerts", data); that.reset(data); return that; }); }
[ "function", "(", ")", "{", "var", "that", "=", "this", ";", "return", "api", ".", "execute", "(", "\"get:alerts\"", ")", ".", "then", "(", "function", "(", "data", ")", "{", "console", ".", "log", "(", "\"alerts\"", ",", "data", ")", ";", "that", ".", "reset", "(", "data", ")", ";", "return", "that", ";", "}", ")", ";", "}" ]
Load all alerts
[ "Load", "all", "alerts" ]
bff0ea7f324de78ab8bf8c4301ce30696ad7d960
https://github.com/Reportr/dashboard/blob/bff0ea7f324de78ab8bf8c4301ce30696ad7d960/public/build/static/application.js#L55893-L55902
18,339
Reportr/dashboard
public/build/static/application.js
function(r) { r = r.toJSON? r.toJSON() : r; this.report.del("visualizations", { silent: true }); this.report.set(r); hr.History.navigate("report/"+this.report.get("id")); }
javascript
function(r) { r = r.toJSON? r.toJSON() : r; this.report.del("visualizations", { silent: true }); this.report.set(r); hr.History.navigate("report/"+this.report.get("id")); }
[ "function", "(", "r", ")", "{", "r", "=", "r", ".", "toJSON", "?", "r", ".", "toJSON", "(", ")", ":", "r", ";", "this", ".", "report", ".", "del", "(", "\"visualizations\"", ",", "{", "silent", ":", "true", "}", ")", ";", "this", ".", "report", ".", "set", "(", "r", ")", ";", "hr", ".", "History", ".", "navigate", "(", "\"report/\"", "+", "this", ".", "report", ".", "get", "(", "\"id\"", ")", ")", ";", "}" ]
Set active report
[ "Set", "active", "report" ]
bff0ea7f324de78ab8bf8c4301ce30696ad7d960
https://github.com/Reportr/dashboard/blob/bff0ea7f324de78ab8bf8c4301ce30696ad7d960/public/build/static/application.js#L56542-L56548
18,340
Reportr/dashboard
public/build/static/application.js
function() { var that = this; return that.reports.loadAll() .then(function() { return dialogs.select( i18n.t("reports.select.title"), i18n.t("reports.select.message"), _.object(that.reports.map(function(r) { return [ r.get("id"), r.get("title") ] })), that.report.get("id") ); }) .then(function(rId) { hr.History.navigate("report/"+rId); }); }
javascript
function() { var that = this; return that.reports.loadAll() .then(function() { return dialogs.select( i18n.t("reports.select.title"), i18n.t("reports.select.message"), _.object(that.reports.map(function(r) { return [ r.get("id"), r.get("title") ] })), that.report.get("id") ); }) .then(function(rId) { hr.History.navigate("report/"+rId); }); }
[ "function", "(", ")", "{", "var", "that", "=", "this", ";", "return", "that", ".", "reports", ".", "loadAll", "(", ")", ".", "then", "(", "function", "(", ")", "{", "return", "dialogs", ".", "select", "(", "i18n", ".", "t", "(", "\"reports.select.title\"", ")", ",", "i18n", ".", "t", "(", "\"reports.select.message\"", ")", ",", "_", ".", "object", "(", "that", ".", "reports", ".", "map", "(", "function", "(", "r", ")", "{", "return", "[", "r", ".", "get", "(", "\"id\"", ")", ",", "r", ".", "get", "(", "\"title\"", ")", "]", "}", ")", ")", ",", "that", ".", "report", ".", "get", "(", "\"id\"", ")", ")", ";", "}", ")", ".", "then", "(", "function", "(", "rId", ")", "{", "hr", ".", "History", ".", "navigate", "(", "\"report/\"", "+", "rId", ")", ";", "}", ")", ";", "}" ]
Change current report
[ "Change", "current", "report" ]
bff0ea7f324de78ab8bf8c4301ce30696ad7d960
https://github.com/Reportr/dashboard/blob/bff0ea7f324de78ab8bf8c4301ce30696ad7d960/public/build/static/application.js#L56551-L56571
18,341
Reportr/dashboard
public/build/static/application.js
function() { var that = this; return dialogs.fields(i18n.t("reports.create.title"), { "title": { label: i18n.t("reports.create.fields.title"), type: "text" } }) .then(function(args) { return that.reports.create(args); }); }
javascript
function() { var that = this; return dialogs.fields(i18n.t("reports.create.title"), { "title": { label: i18n.t("reports.create.fields.title"), type: "text" } }) .then(function(args) { return that.reports.create(args); }); }
[ "function", "(", ")", "{", "var", "that", "=", "this", ";", "return", "dialogs", ".", "fields", "(", "i18n", ".", "t", "(", "\"reports.create.title\"", ")", ",", "{", "\"title\"", ":", "{", "label", ":", "i18n", ".", "t", "(", "\"reports.create.fields.title\"", ")", ",", "type", ":", "\"text\"", "}", "}", ")", ".", "then", "(", "function", "(", "args", ")", "{", "return", "that", ".", "reports", ".", "create", "(", "args", ")", ";", "}", ")", ";", "}" ]
Create a new report
[ "Create", "a", "new", "report" ]
bff0ea7f324de78ab8bf8c4301ce30696ad7d960
https://github.com/Reportr/dashboard/blob/bff0ea7f324de78ab8bf8c4301ce30696ad7d960/public/build/static/application.js#L56574-L56586
18,342
Reportr/dashboard
public/build/static/application.js
function() { var that = this; return dialogs.fields(i18n.t("reports.edit.title"), { "title": { label: i18n.t("reports.edit.fields.title"), type: "text" } }, this.report.toJSON()) .then(function(data) { return that.report.edit(data); }); }
javascript
function() { var that = this; return dialogs.fields(i18n.t("reports.edit.title"), { "title": { label: i18n.t("reports.edit.fields.title"), type: "text" } }, this.report.toJSON()) .then(function(data) { return that.report.edit(data); }); }
[ "function", "(", ")", "{", "var", "that", "=", "this", ";", "return", "dialogs", ".", "fields", "(", "i18n", ".", "t", "(", "\"reports.edit.title\"", ")", ",", "{", "\"title\"", ":", "{", "label", ":", "i18n", ".", "t", "(", "\"reports.edit.fields.title\"", ")", ",", "type", ":", "\"text\"", "}", "}", ",", "this", ".", "report", ".", "toJSON", "(", ")", ")", ".", "then", "(", "function", "(", "data", ")", "{", "return", "that", ".", "report", ".", "edit", "(", "data", ")", ";", "}", ")", ";", "}" ]
Edit current report
[ "Edit", "current", "report" ]
bff0ea7f324de78ab8bf8c4301ce30696ad7d960
https://github.com/Reportr/dashboard/blob/bff0ea7f324de78ab8bf8c4301ce30696ad7d960/public/build/static/application.js#L56589-L56600
18,343
Reportr/dashboard
public/build/static/application.js
function() { var that = this; return dialogs.confirm(i18n.t("reports.remove.title")) .then(function() { return that.report.remove(); }) .then(function() { that.report.clear(); return that.reports.loadAll(); }) .then(function() { that.update(); }) .fail(dialogs.error); }
javascript
function() { var that = this; return dialogs.confirm(i18n.t("reports.remove.title")) .then(function() { return that.report.remove(); }) .then(function() { that.report.clear(); return that.reports.loadAll(); }) .then(function() { that.update(); }) .fail(dialogs.error); }
[ "function", "(", ")", "{", "var", "that", "=", "this", ";", "return", "dialogs", ".", "confirm", "(", "i18n", ".", "t", "(", "\"reports.remove.title\"", ")", ")", ".", "then", "(", "function", "(", ")", "{", "return", "that", ".", "report", ".", "remove", "(", ")", ";", "}", ")", ".", "then", "(", "function", "(", ")", "{", "that", ".", "report", ".", "clear", "(", ")", ";", "return", "that", ".", "reports", ".", "loadAll", "(", ")", ";", "}", ")", ".", "then", "(", "function", "(", ")", "{", "that", ".", "update", "(", ")", ";", "}", ")", ".", "fail", "(", "dialogs", ".", "error", ")", ";", "}" ]
Remove current report
[ "Remove", "current", "report" ]
bff0ea7f324de78ab8bf8c4301ce30696ad7d960
https://github.com/Reportr/dashboard/blob/bff0ea7f324de78ab8bf8c4301ce30696ad7d960/public/build/static/application.js#L56603-L56618
18,344
Reportr/dashboard
public/build/static/application.js
function() { var that = this; return api.execute("get:types") .then(function(types) { return dialogs.fields(i18n.t("visualization.create.title"), { "eventName": { 'label': i18n.t("visualization.create.fields.eventName"), 'type': "select", 'options': _.chain(types) .map(function(type) { return [type.type, type.type]; }) .object() .value() }, "type": { 'label': i18n.t("visualization.create.fields.type"), 'type': "select", 'options': _.chain(allVisualizations) .map(function(visualization, vId) { return [ vId, visualization.title ]; }) .object() .value() } }) }) .then(function(data) { that.report.visualizations.add(data); return that.report.edit().fail(dialogs.error); }); }
javascript
function() { var that = this; return api.execute("get:types") .then(function(types) { return dialogs.fields(i18n.t("visualization.create.title"), { "eventName": { 'label': i18n.t("visualization.create.fields.eventName"), 'type': "select", 'options': _.chain(types) .map(function(type) { return [type.type, type.type]; }) .object() .value() }, "type": { 'label': i18n.t("visualization.create.fields.type"), 'type': "select", 'options': _.chain(allVisualizations) .map(function(visualization, vId) { return [ vId, visualization.title ]; }) .object() .value() } }) }) .then(function(data) { that.report.visualizations.add(data); return that.report.edit().fail(dialogs.error); }); }
[ "function", "(", ")", "{", "var", "that", "=", "this", ";", "return", "api", ".", "execute", "(", "\"get:types\"", ")", ".", "then", "(", "function", "(", "types", ")", "{", "return", "dialogs", ".", "fields", "(", "i18n", ".", "t", "(", "\"visualization.create.title\"", ")", ",", "{", "\"eventName\"", ":", "{", "'label'", ":", "i18n", ".", "t", "(", "\"visualization.create.fields.eventName\"", ")", ",", "'type'", ":", "\"select\"", ",", "'options'", ":", "_", ".", "chain", "(", "types", ")", ".", "map", "(", "function", "(", "type", ")", "{", "return", "[", "type", ".", "type", ",", "type", ".", "type", "]", ";", "}", ")", ".", "object", "(", ")", ".", "value", "(", ")", "}", ",", "\"type\"", ":", "{", "'label'", ":", "i18n", ".", "t", "(", "\"visualization.create.fields.type\"", ")", ",", "'type'", ":", "\"select\"", ",", "'options'", ":", "_", ".", "chain", "(", "allVisualizations", ")", ".", "map", "(", "function", "(", "visualization", ",", "vId", ")", "{", "return", "[", "vId", ",", "visualization", ".", "title", "]", ";", "}", ")", ".", "object", "(", ")", ".", "value", "(", ")", "}", "}", ")", "}", ")", ".", "then", "(", "function", "(", "data", ")", "{", "that", ".", "report", ".", "visualizations", ".", "add", "(", "data", ")", ";", "return", "that", ".", "report", ".", "edit", "(", ")", ".", "fail", "(", "dialogs", ".", "error", ")", ";", "}", ")", ";", "}" ]
Create a new visualization
[ "Create", "a", "new", "visualization" ]
bff0ea7f324de78ab8bf8c4301ce30696ad7d960
https://github.com/Reportr/dashboard/blob/bff0ea7f324de78ab8bf8c4301ce30696ad7d960/public/build/static/application.js#L56621-L56657
18,345
Reportr/dashboard
public/build/static/application.js
function(e) { if (e) e.preventDefault(); var that = this; return api.execute("get:types") .fail(dialogs.error) .then(function(events) { return dialogs.fields(i18n.t("alerts.create.title"), { "title": { "label": i18n.t("alerts.create.fields.title.label"), "type": "text" }, "eventName": { 'label': i18n.t("alerts.create.fields.eventName.label"), 'type': "select", 'options': _.chain(events) .map(function(type) { return [type.type, type.type]; }) .object() .value() }, "type": { 'label': i18n.t("alerts.create.fields.type.label"), 'type': "select", 'options': _.chain(allAlerts) .map(function(a, aId) { return [aId, a.title]; }) .object() .value() }, "interval": { "label": i18n.t("alerts.create.fields.interval.label"), "type": "number", 'min': 1, 'default': 1, 'help': i18n.t("alerts.create.fields.interval.help") }, "condition": { "label": i18n.t("alerts.create.fields.condition.label"), "type": "text", "help": i18n.t("alerts.create.fields.condition.help") }, }); }) .then(function(data) { return that.alerts.create({ 'title': data.title, 'condition': data.condition, 'eventName': data.eventName, 'interval': data.interval, 'type': data.type }) .then(that.manageAlerts.bind(that), dialogs.error) }); }
javascript
function(e) { if (e) e.preventDefault(); var that = this; return api.execute("get:types") .fail(dialogs.error) .then(function(events) { return dialogs.fields(i18n.t("alerts.create.title"), { "title": { "label": i18n.t("alerts.create.fields.title.label"), "type": "text" }, "eventName": { 'label': i18n.t("alerts.create.fields.eventName.label"), 'type': "select", 'options': _.chain(events) .map(function(type) { return [type.type, type.type]; }) .object() .value() }, "type": { 'label': i18n.t("alerts.create.fields.type.label"), 'type': "select", 'options': _.chain(allAlerts) .map(function(a, aId) { return [aId, a.title]; }) .object() .value() }, "interval": { "label": i18n.t("alerts.create.fields.interval.label"), "type": "number", 'min': 1, 'default': 1, 'help': i18n.t("alerts.create.fields.interval.help") }, "condition": { "label": i18n.t("alerts.create.fields.condition.label"), "type": "text", "help": i18n.t("alerts.create.fields.condition.help") }, }); }) .then(function(data) { return that.alerts.create({ 'title': data.title, 'condition': data.condition, 'eventName': data.eventName, 'interval': data.interval, 'type': data.type }) .then(that.manageAlerts.bind(that), dialogs.error) }); }
[ "function", "(", "e", ")", "{", "if", "(", "e", ")", "e", ".", "preventDefault", "(", ")", ";", "var", "that", "=", "this", ";", "return", "api", ".", "execute", "(", "\"get:types\"", ")", ".", "fail", "(", "dialogs", ".", "error", ")", ".", "then", "(", "function", "(", "events", ")", "{", "return", "dialogs", ".", "fields", "(", "i18n", ".", "t", "(", "\"alerts.create.title\"", ")", ",", "{", "\"title\"", ":", "{", "\"label\"", ":", "i18n", ".", "t", "(", "\"alerts.create.fields.title.label\"", ")", ",", "\"type\"", ":", "\"text\"", "}", ",", "\"eventName\"", ":", "{", "'label'", ":", "i18n", ".", "t", "(", "\"alerts.create.fields.eventName.label\"", ")", ",", "'type'", ":", "\"select\"", ",", "'options'", ":", "_", ".", "chain", "(", "events", ")", ".", "map", "(", "function", "(", "type", ")", "{", "return", "[", "type", ".", "type", ",", "type", ".", "type", "]", ";", "}", ")", ".", "object", "(", ")", ".", "value", "(", ")", "}", ",", "\"type\"", ":", "{", "'label'", ":", "i18n", ".", "t", "(", "\"alerts.create.fields.type.label\"", ")", ",", "'type'", ":", "\"select\"", ",", "'options'", ":", "_", ".", "chain", "(", "allAlerts", ")", ".", "map", "(", "function", "(", "a", ",", "aId", ")", "{", "return", "[", "aId", ",", "a", ".", "title", "]", ";", "}", ")", ".", "object", "(", ")", ".", "value", "(", ")", "}", ",", "\"interval\"", ":", "{", "\"label\"", ":", "i18n", ".", "t", "(", "\"alerts.create.fields.interval.label\"", ")", ",", "\"type\"", ":", "\"number\"", ",", "'min'", ":", "1", ",", "'default'", ":", "1", ",", "'help'", ":", "i18n", ".", "t", "(", "\"alerts.create.fields.interval.help\"", ")", "}", ",", "\"condition\"", ":", "{", "\"label\"", ":", "i18n", ".", "t", "(", "\"alerts.create.fields.condition.label\"", ")", ",", "\"type\"", ":", "\"text\"", ",", "\"help\"", ":", "i18n", ".", "t", "(", "\"alerts.create.fields.condition.help\"", ")", "}", ",", "}", ")", ";", "}", ")", ".", "then", "(", "function", "(", "data", ")", "{", "return", "that", ".", "alerts", ".", "create", "(", "{", "'title'", ":", "data", ".", "title", ",", "'condition'", ":", "data", ".", "condition", ",", "'eventName'", ":", "data", ".", "eventName", ",", "'interval'", ":", "data", ".", "interval", ",", "'type'", ":", "data", ".", "type", "}", ")", ".", "then", "(", "that", ".", "manageAlerts", ".", "bind", "(", "that", ")", ",", "dialogs", ".", "error", ")", "}", ")", ";", "}" ]
Create an alert
[ "Create", "an", "alert" ]
bff0ea7f324de78ab8bf8c4301ce30696ad7d960
https://github.com/Reportr/dashboard/blob/bff0ea7f324de78ab8bf8c4301ce30696ad7d960/public/build/static/application.js#L56672-L56729
18,346
APIDevTools/swagger-cli
bin/swagger-cli.js
parseArgs
function parseArgs () { // Configure the argument parser yargs .option("schema", { type: "boolean", default: true, }) .option("spec", { type: "boolean", default: true, }) .option("o", { alias: "outfile", type: "string", normalize: true, }) .option("r", { alias: "dereference", type: "boolean", }) .option("t", { alias: "type", type: "string", normalize: true, default: "json", }) .option("f", { alias: "format", type: "number", default: 2, }) .option("w", { alias: "wrap", type: "number", default: Infinity, }) .option("d", { alias: "debug", type: "boolean", }) .option("h", { alias: "help", type: "boolean", }); // Show the version number on "--version" or "-v" yargs .version() .alias("v", "version"); // Disable the default "--help" behavior yargs.help(false); // Parse the command-line arguments let args = yargs.argv; // Normalize the parsed arguments let parsed = { command: args._[0], file: args._[1], options: { schema: args.schema, spec: args.spec, outfile: args.outfile, dereference: args.dereference, format: args.format || 2, type: args.type || "json", wrap: args.wrap || Infinity, debug: args.debug, help: args.help, } }; if (parsed.options.debug) { console.log(JSON.stringify(parsed, null, 2)); } return parsed; }
javascript
function parseArgs () { // Configure the argument parser yargs .option("schema", { type: "boolean", default: true, }) .option("spec", { type: "boolean", default: true, }) .option("o", { alias: "outfile", type: "string", normalize: true, }) .option("r", { alias: "dereference", type: "boolean", }) .option("t", { alias: "type", type: "string", normalize: true, default: "json", }) .option("f", { alias: "format", type: "number", default: 2, }) .option("w", { alias: "wrap", type: "number", default: Infinity, }) .option("d", { alias: "debug", type: "boolean", }) .option("h", { alias: "help", type: "boolean", }); // Show the version number on "--version" or "-v" yargs .version() .alias("v", "version"); // Disable the default "--help" behavior yargs.help(false); // Parse the command-line arguments let args = yargs.argv; // Normalize the parsed arguments let parsed = { command: args._[0], file: args._[1], options: { schema: args.schema, spec: args.spec, outfile: args.outfile, dereference: args.dereference, format: args.format || 2, type: args.type || "json", wrap: args.wrap || Infinity, debug: args.debug, help: args.help, } }; if (parsed.options.debug) { console.log(JSON.stringify(parsed, null, 2)); } return parsed; }
[ "function", "parseArgs", "(", ")", "{", "// Configure the argument parser", "yargs", ".", "option", "(", "\"schema\"", ",", "{", "type", ":", "\"boolean\"", ",", "default", ":", "true", ",", "}", ")", ".", "option", "(", "\"spec\"", ",", "{", "type", ":", "\"boolean\"", ",", "default", ":", "true", ",", "}", ")", ".", "option", "(", "\"o\"", ",", "{", "alias", ":", "\"outfile\"", ",", "type", ":", "\"string\"", ",", "normalize", ":", "true", ",", "}", ")", ".", "option", "(", "\"r\"", ",", "{", "alias", ":", "\"dereference\"", ",", "type", ":", "\"boolean\"", ",", "}", ")", ".", "option", "(", "\"t\"", ",", "{", "alias", ":", "\"type\"", ",", "type", ":", "\"string\"", ",", "normalize", ":", "true", ",", "default", ":", "\"json\"", ",", "}", ")", ".", "option", "(", "\"f\"", ",", "{", "alias", ":", "\"format\"", ",", "type", ":", "\"number\"", ",", "default", ":", "2", ",", "}", ")", ".", "option", "(", "\"w\"", ",", "{", "alias", ":", "\"wrap\"", ",", "type", ":", "\"number\"", ",", "default", ":", "Infinity", ",", "}", ")", ".", "option", "(", "\"d\"", ",", "{", "alias", ":", "\"debug\"", ",", "type", ":", "\"boolean\"", ",", "}", ")", ".", "option", "(", "\"h\"", ",", "{", "alias", ":", "\"help\"", ",", "type", ":", "\"boolean\"", ",", "}", ")", ";", "// Show the version number on \"--version\" or \"-v\"", "yargs", ".", "version", "(", ")", ".", "alias", "(", "\"v\"", ",", "\"version\"", ")", ";", "// Disable the default \"--help\" behavior", "yargs", ".", "help", "(", "false", ")", ";", "// Parse the command-line arguments", "let", "args", "=", "yargs", ".", "argv", ";", "// Normalize the parsed arguments", "let", "parsed", "=", "{", "command", ":", "args", ".", "_", "[", "0", "]", ",", "file", ":", "args", ".", "_", "[", "1", "]", ",", "options", ":", "{", "schema", ":", "args", ".", "schema", ",", "spec", ":", "args", ".", "spec", ",", "outfile", ":", "args", ".", "outfile", ",", "dereference", ":", "args", ".", "dereference", ",", "format", ":", "args", ".", "format", "||", "2", ",", "type", ":", "args", ".", "type", "||", "\"json\"", ",", "wrap", ":", "args", ".", "wrap", "||", "Infinity", ",", "debug", ":", "args", ".", "debug", ",", "help", ":", "args", ".", "help", ",", "}", "}", ";", "if", "(", "parsed", ".", "options", ".", "debug", ")", "{", "console", ".", "log", "(", "JSON", ".", "stringify", "(", "parsed", ",", "null", ",", "2", ")", ")", ";", "}", "return", "parsed", ";", "}" ]
Parses the command-line arguments @returns {object} - The parsed arguments
[ "Parses", "the", "command", "-", "line", "arguments" ]
e3cc39e223e2e5dcb92128447d297649ca338076
https://github.com/APIDevTools/swagger-cli/blob/e3cc39e223e2e5dcb92128447d297649ca338076/bin/swagger-cli.js#L56-L134
18,347
APIDevTools/swagger-cli
bin/swagger-cli.js
bundle
function bundle (file, options) { api.bundle(file, options) .then((bundled) => { if (options.outfile) { console.log("Created %s from %s", options.outfile, file); } else { // Write the bundled API to stdout console.log(bundled); } }) .catch(errorHandler); }
javascript
function bundle (file, options) { api.bundle(file, options) .then((bundled) => { if (options.outfile) { console.log("Created %s from %s", options.outfile, file); } else { // Write the bundled API to stdout console.log(bundled); } }) .catch(errorHandler); }
[ "function", "bundle", "(", "file", ",", "options", ")", "{", "api", ".", "bundle", "(", "file", ",", "options", ")", ".", "then", "(", "(", "bundled", ")", "=>", "{", "if", "(", "options", ".", "outfile", ")", "{", "console", ".", "log", "(", "\"Created %s from %s\"", ",", "options", ".", "outfile", ",", "file", ")", ";", "}", "else", "{", "// Write the bundled API to stdout", "console", ".", "log", "(", "bundled", ")", ";", "}", "}", ")", ".", "catch", "(", "errorHandler", ")", ";", "}" ]
Bundles a multi-file API definition @param {string} file - The path of the file to validate @param {object} options - Validation options
[ "Bundles", "a", "multi", "-", "file", "API", "definition" ]
e3cc39e223e2e5dcb92128447d297649ca338076
https://github.com/APIDevTools/swagger-cli/blob/e3cc39e223e2e5dcb92128447d297649ca338076/bin/swagger-cli.js#L160-L172
18,348
APIDevTools/swagger-cli
bin/swagger-cli.js
errorHandler
function errorHandler (err) { let errorMessage = process.env.DEBUG ? err.stack : err.message; console.error(chalk.red(errorMessage)); process.exit(1); }
javascript
function errorHandler (err) { let errorMessage = process.env.DEBUG ? err.stack : err.message; console.error(chalk.red(errorMessage)); process.exit(1); }
[ "function", "errorHandler", "(", "err", ")", "{", "let", "errorMessage", "=", "process", ".", "env", ".", "DEBUG", "?", "err", ".", "stack", ":", "err", ".", "message", ";", "console", ".", "error", "(", "chalk", ".", "red", "(", "errorMessage", ")", ")", ";", "process", ".", "exit", "(", "1", ")", ";", "}" ]
Writes error information to stderr and exits with a non-zero code @param {Error} err
[ "Writes", "error", "information", "to", "stderr", "and", "exits", "with", "a", "non", "-", "zero", "code" ]
e3cc39e223e2e5dcb92128447d297649ca338076
https://github.com/APIDevTools/swagger-cli/blob/e3cc39e223e2e5dcb92128447d297649ca338076/bin/swagger-cli.js#L192-L196
18,349
APIDevTools/swagger-cli
lib/bundle.js
toYAML
function toYAML (api, spaces, wrap) { const jsYaml = require("js-yaml"); return jsYaml.dump(api, { indent: spaces, lineWidth: wrap, noRefs: true }); }
javascript
function toYAML (api, spaces, wrap) { const jsYaml = require("js-yaml"); return jsYaml.dump(api, { indent: spaces, lineWidth: wrap, noRefs: true }); }
[ "function", "toYAML", "(", "api", ",", "spaces", ",", "wrap", ")", "{", "const", "jsYaml", "=", "require", "(", "\"js-yaml\"", ")", ";", "return", "jsYaml", ".", "dump", "(", "api", ",", "{", "indent", ":", "spaces", ",", "lineWidth", ":", "wrap", ",", "noRefs", ":", "true", "}", ")", ";", "}" ]
Serializes the given API as YAML, using the given spaces for formatting. @param {object} api API to convert to YAML @param {string|number} spaces number of spaces to ident @param {number} wrap the column to word-wrap at
[ "Serializes", "the", "given", "API", "as", "YAML", "using", "the", "given", "spaces", "for", "formatting", "." ]
e3cc39e223e2e5dcb92128447d297649ca338076
https://github.com/APIDevTools/swagger-cli/blob/e3cc39e223e2e5dcb92128447d297649ca338076/lib/bundle.js#L91-L99
18,350
ethul/purs-loader
src/to-javascript.js
makeBundleJS
function makeBundleJS(psModule) { const bundleOutput = psModule.options.bundleOutput; const name = psModule.name; const srcDir = psModule.srcDir; const escaped = jsStringEscape(path.relative(srcDir, bundleOutput)); const result = `module.exports = require("${escaped}")["${name}"]`; return Promise.resolve(result); }
javascript
function makeBundleJS(psModule) { const bundleOutput = psModule.options.bundleOutput; const name = psModule.name; const srcDir = psModule.srcDir; const escaped = jsStringEscape(path.relative(srcDir, bundleOutput)); const result = `module.exports = require("${escaped}")["${name}"]`; return Promise.resolve(result); }
[ "function", "makeBundleJS", "(", "psModule", ")", "{", "const", "bundleOutput", "=", "psModule", ".", "options", ".", "bundleOutput", ";", "const", "name", "=", "psModule", ".", "name", ";", "const", "srcDir", "=", "psModule", ".", "srcDir", ";", "const", "escaped", "=", "jsStringEscape", "(", "path", ".", "relative", "(", "srcDir", ",", "bundleOutput", ")", ")", ";", "const", "result", "=", "`", "${", "escaped", "}", "${", "name", "}", "`", ";", "return", "Promise", ".", "resolve", "(", "result", ")", ";", "}" ]
Reference the bundle.
[ "Reference", "the", "bundle", "." ]
f5a2abb1da6068203698255c123f097979443b6b
https://github.com/ethul/purs-loader/blob/f5a2abb1da6068203698255c123f097979443b6b/src/to-javascript.js#L51-L63
18,351
ethul/purs-loader
src/to-javascript.js
makeJS
function makeJS(psModule, psModuleMap, js) { const requireRE = /require\(['"]\.\.\/([\w\.]+)(?:\/index\.js)?['"]\)/g; const foreignRE = /require\(['"]\.\/foreign(?:\.js)?['"]\)/g; const name = psModule.name; const imports = psModuleMap[name].imports; var replacedImports = []; const result = js .replace(requireRE, (m, p1) => { const moduleValue = psModuleMap[p1]; if (!moduleValue) { debug('module %s was not found in the map, replacing require with null', p1); return 'null'; } else { const escapedPath = jsStringEscape(moduleValue.src); replacedImports.push(p1); return `require("${escapedPath}")`; } }) .replace(foreignRE, () => { const escapedPath = jsStringEscape(psModuleMap[name].ffi); return `require("${escapedPath}")`; }) ; const additionalImports = difference(imports, replacedImports); if (!additionalImports.length) { return Promise.resolve(result); } else { debug('rebuilding module map due to additional imports for %s: %o', name, additionalImports); psModule.cache.psModuleMap = null; return updatePsModuleMap(psModule).then(updatedPsModuleMap => { const additionalImportsResult = additionalImports.map(import_ => { const moduleValue = updatedPsModuleMap[import_]; if (!moduleValue) { debug('module %s was not found in the map, skipping require', import_); return null; } else { const escapedPath = jsStringEscape(moduleValue.src); return `var ${import_.replace(/\./g, '_')} = require("${escapedPath}")`; } }).filter(a => a !== null).join('\n'); return result + '\n' + additionalImportsResult; }); } }
javascript
function makeJS(psModule, psModuleMap, js) { const requireRE = /require\(['"]\.\.\/([\w\.]+)(?:\/index\.js)?['"]\)/g; const foreignRE = /require\(['"]\.\/foreign(?:\.js)?['"]\)/g; const name = psModule.name; const imports = psModuleMap[name].imports; var replacedImports = []; const result = js .replace(requireRE, (m, p1) => { const moduleValue = psModuleMap[p1]; if (!moduleValue) { debug('module %s was not found in the map, replacing require with null', p1); return 'null'; } else { const escapedPath = jsStringEscape(moduleValue.src); replacedImports.push(p1); return `require("${escapedPath}")`; } }) .replace(foreignRE, () => { const escapedPath = jsStringEscape(psModuleMap[name].ffi); return `require("${escapedPath}")`; }) ; const additionalImports = difference(imports, replacedImports); if (!additionalImports.length) { return Promise.resolve(result); } else { debug('rebuilding module map due to additional imports for %s: %o', name, additionalImports); psModule.cache.psModuleMap = null; return updatePsModuleMap(psModule).then(updatedPsModuleMap => { const additionalImportsResult = additionalImports.map(import_ => { const moduleValue = updatedPsModuleMap[import_]; if (!moduleValue) { debug('module %s was not found in the map, skipping require', import_); return null; } else { const escapedPath = jsStringEscape(moduleValue.src); return `var ${import_.replace(/\./g, '_')} = require("${escapedPath}")`; } }).filter(a => a !== null).join('\n'); return result + '\n' + additionalImportsResult; }); } }
[ "function", "makeJS", "(", "psModule", ",", "psModuleMap", ",", "js", ")", "{", "const", "requireRE", "=", "/", "require\\(['\"]\\.\\.\\/([\\w\\.]+)(?:\\/index\\.js)?['\"]\\)", "/", "g", ";", "const", "foreignRE", "=", "/", "require\\(['\"]\\.\\/foreign(?:\\.js)?['\"]\\)", "/", "g", ";", "const", "name", "=", "psModule", ".", "name", ";", "const", "imports", "=", "psModuleMap", "[", "name", "]", ".", "imports", ";", "var", "replacedImports", "=", "[", "]", ";", "const", "result", "=", "js", ".", "replace", "(", "requireRE", ",", "(", "m", ",", "p1", ")", "=>", "{", "const", "moduleValue", "=", "psModuleMap", "[", "p1", "]", ";", "if", "(", "!", "moduleValue", ")", "{", "debug", "(", "'module %s was not found in the map, replacing require with null'", ",", "p1", ")", ";", "return", "'null'", ";", "}", "else", "{", "const", "escapedPath", "=", "jsStringEscape", "(", "moduleValue", ".", "src", ")", ";", "replacedImports", ".", "push", "(", "p1", ")", ";", "return", "`", "${", "escapedPath", "}", "`", ";", "}", "}", ")", ".", "replace", "(", "foreignRE", ",", "(", ")", "=>", "{", "const", "escapedPath", "=", "jsStringEscape", "(", "psModuleMap", "[", "name", "]", ".", "ffi", ")", ";", "return", "`", "${", "escapedPath", "}", "`", ";", "}", ")", ";", "const", "additionalImports", "=", "difference", "(", "imports", ",", "replacedImports", ")", ";", "if", "(", "!", "additionalImports", ".", "length", ")", "{", "return", "Promise", ".", "resolve", "(", "result", ")", ";", "}", "else", "{", "debug", "(", "'rebuilding module map due to additional imports for %s: %o'", ",", "name", ",", "additionalImports", ")", ";", "psModule", ".", "cache", ".", "psModuleMap", "=", "null", ";", "return", "updatePsModuleMap", "(", "psModule", ")", ".", "then", "(", "updatedPsModuleMap", "=>", "{", "const", "additionalImportsResult", "=", "additionalImports", ".", "map", "(", "import_", "=>", "{", "const", "moduleValue", "=", "updatedPsModuleMap", "[", "import_", "]", ";", "if", "(", "!", "moduleValue", ")", "{", "debug", "(", "'module %s was not found in the map, skipping require'", ",", "import_", ")", ";", "return", "null", ";", "}", "else", "{", "const", "escapedPath", "=", "jsStringEscape", "(", "moduleValue", ".", "src", ")", ";", "return", "`", "${", "import_", ".", "replace", "(", "/", "\\.", "/", "g", ",", "'_'", ")", "}", "${", "escapedPath", "}", "`", ";", "}", "}", ")", ".", "filter", "(", "a", "=>", "a", "!==", "null", ")", ".", "join", "(", "'\\n'", ")", ";", "return", "result", "+", "'\\n'", "+", "additionalImportsResult", ";", "}", ")", ";", "}", "}" ]
Replace require paths to output files generated by psc with paths to purescript sources, which are then also run through this loader. Additionally, the imports replaced are tracked so that in the event the compiler fails to compile the PureScript source, we can tack on any new imports in order to allow webpack to watch the new files before they have been successfully compiled.
[ "Replace", "require", "paths", "to", "output", "files", "generated", "by", "psc", "with", "paths", "to", "purescript", "sources", "which", "are", "then", "also", "run", "through", "this", "loader", ".", "Additionally", "the", "imports", "replaced", "are", "tracked", "so", "that", "in", "the", "event", "the", "compiler", "fails", "to", "compile", "the", "PureScript", "source", "we", "can", "tack", "on", "any", "new", "imports", "in", "order", "to", "allow", "webpack", "to", "watch", "the", "new", "files", "before", "they", "have", "been", "successfully", "compiled", "." ]
f5a2abb1da6068203698255c123f097979443b6b
https://github.com/ethul/purs-loader/blob/f5a2abb1da6068203698255c123f097979443b6b/src/to-javascript.js#L71-L135
18,352
nolimits4web/dom7
dist/dom7.module.js
addClass
function addClass(className) { if (typeof className === 'undefined') { return this; } const classes = className.split(' '); for (let i = 0; i < classes.length; i += 1) { for (let j = 0; j < this.length; j += 1) { if (typeof this[j] !== 'undefined' && typeof this[j].classList !== 'undefined') this[j].classList.add(classes[i]); } } return this; }
javascript
function addClass(className) { if (typeof className === 'undefined') { return this; } const classes = className.split(' '); for (let i = 0; i < classes.length; i += 1) { for (let j = 0; j < this.length; j += 1) { if (typeof this[j] !== 'undefined' && typeof this[j].classList !== 'undefined') this[j].classList.add(classes[i]); } } return this; }
[ "function", "addClass", "(", "className", ")", "{", "if", "(", "typeof", "className", "===", "'undefined'", ")", "{", "return", "this", ";", "}", "const", "classes", "=", "className", ".", "split", "(", "' '", ")", ";", "for", "(", "let", "i", "=", "0", ";", "i", "<", "classes", ".", "length", ";", "i", "+=", "1", ")", "{", "for", "(", "let", "j", "=", "0", ";", "j", "<", "this", ".", "length", ";", "j", "+=", "1", ")", "{", "if", "(", "typeof", "this", "[", "j", "]", "!==", "'undefined'", "&&", "typeof", "this", "[", "j", "]", ".", "classList", "!==", "'undefined'", ")", "this", "[", "j", "]", ".", "classList", ".", "add", "(", "classes", "[", "i", "]", ")", ";", "}", "}", "return", "this", ";", "}" ]
Classes and attributes
[ "Classes", "and", "attributes" ]
28b0db30d77fa765ccae9497a2f0e3dfbc2cf55f
https://github.com/nolimits4web/dom7/blob/28b0db30d77fa765ccae9497a2f0e3dfbc2cf55f/dist/dom7.module.js#L107-L118
18,353
nolimits4web/dom7
dist/dom7.module.js
transform
function transform(transform) { for (let i = 0; i < this.length; i += 1) { const elStyle = this[i].style; elStyle.webkitTransform = transform; elStyle.transform = transform; } return this; }
javascript
function transform(transform) { for (let i = 0; i < this.length; i += 1) { const elStyle = this[i].style; elStyle.webkitTransform = transform; elStyle.transform = transform; } return this; }
[ "function", "transform", "(", "transform", ")", "{", "for", "(", "let", "i", "=", "0", ";", "i", "<", "this", ".", "length", ";", "i", "+=", "1", ")", "{", "const", "elStyle", "=", "this", "[", "i", "]", ".", "style", ";", "elStyle", ".", "webkitTransform", "=", "transform", ";", "elStyle", ".", "transform", "=", "transform", ";", "}", "return", "this", ";", "}" ]
Transforms eslint-disable-next-line
[ "Transforms", "eslint", "-", "disable", "-", "next", "-", "line" ]
28b0db30d77fa765ccae9497a2f0e3dfbc2cf55f
https://github.com/nolimits4web/dom7/blob/28b0db30d77fa765ccae9497a2f0e3dfbc2cf55f/dist/dom7.module.js#L285-L292
18,354
nolimits4web/dom7
dist/dom7.module.js
each
function each(callback) { // Don't bother continuing without a callback if (!callback) return this; // Iterate over the current collection for (let i = 0; i < this.length; i += 1) { // If the callback returns false if (callback.call(this[i], i, this[i]) === false) { // End the loop early return this; } } // Return `this` to allow chained DOM operations return this; }
javascript
function each(callback) { // Don't bother continuing without a callback if (!callback) return this; // Iterate over the current collection for (let i = 0; i < this.length; i += 1) { // If the callback returns false if (callback.call(this[i], i, this[i]) === false) { // End the loop early return this; } } // Return `this` to allow chained DOM operations return this; }
[ "function", "each", "(", "callback", ")", "{", "// Don't bother continuing without a callback", "if", "(", "!", "callback", ")", "return", "this", ";", "// Iterate over the current collection", "for", "(", "let", "i", "=", "0", ";", "i", "<", "this", ".", "length", ";", "i", "+=", "1", ")", "{", "// If the callback returns false", "if", "(", "callback", ".", "call", "(", "this", "[", "i", "]", ",", "i", ",", "this", "[", "i", "]", ")", "===", "false", ")", "{", "// End the loop early", "return", "this", ";", "}", "}", "// Return `this` to allow chained DOM operations", "return", "this", ";", "}" ]
Iterate over the collection passing elements to `callback`
[ "Iterate", "over", "the", "collection", "passing", "elements", "to", "callback" ]
28b0db30d77fa765ccae9497a2f0e3dfbc2cf55f
https://github.com/nolimits4web/dom7/blob/28b0db30d77fa765ccae9497a2f0e3dfbc2cf55f/dist/dom7.module.js#L604-L617
18,355
bitovi/funcunit
site/examples/todo/js/todos/todos.js
function (el, e) { var value = can.trim(el.val()); if (e.keyCode === ENTER_KEY && value !== '') { new Models.Todo({ text : value, complete : false }).save(function () { el.val(''); }); } }
javascript
function (el, e) { var value = can.trim(el.val()); if (e.keyCode === ENTER_KEY && value !== '') { new Models.Todo({ text : value, complete : false }).save(function () { el.val(''); }); } }
[ "function", "(", "el", ",", "e", ")", "{", "var", "value", "=", "can", ".", "trim", "(", "el", ".", "val", "(", ")", ")", ";", "if", "(", "e", ".", "keyCode", "===", "ENTER_KEY", "&&", "value", "!==", "''", ")", "{", "new", "Models", ".", "Todo", "(", "{", "text", ":", "value", ",", "complete", ":", "false", "}", ")", ".", "save", "(", "function", "(", ")", "{", "el", ".", "val", "(", "''", ")", ";", "}", ")", ";", "}", "}" ]
Listen for when a new Todo has been entered
[ "Listen", "for", "when", "a", "new", "Todo", "has", "been", "entered" ]
6c0056bed585927c76c3a22c0f482adb48b0fde2
https://github.com/bitovi/funcunit/blob/6c0056bed585927c76c3a22c0f482adb48b0fde2/site/examples/todo/js/todos/todos.js#L19-L29
18,356
bitovi/funcunit
site/examples/todo/js/todos/todos.js
function (list, e, item) { this.options.todos.push(item); // Reset the filter so that you always see your new todo this.options.state.attr('filter', ''); }
javascript
function (list, e, item) { this.options.todos.push(item); // Reset the filter so that you always see your new todo this.options.state.attr('filter', ''); }
[ "function", "(", "list", ",", "e", ",", "item", ")", "{", "this", ".", "options", ".", "todos", ".", "push", "(", "item", ")", ";", "// Reset the filter so that you always see your new todo", "this", ".", "options", ".", "state", ".", "attr", "(", "'filter'", ",", "''", ")", ";", "}" ]
Handle a newly created Todo
[ "Handle", "a", "newly", "created", "Todo" ]
6c0056bed585927c76c3a22c0f482adb48b0fde2
https://github.com/bitovi/funcunit/blob/6c0056bed585927c76c3a22c0f482adb48b0fde2/site/examples/todo/js/todos/todos.js#L32-L36
18,357
bitovi/funcunit
site/examples/todo/js/todos/todos.js
function () { // Remove the `selected` class from the old link and add it to the link for the current location hash this.element.find('#filters').find('a').removeClass('selected') .end().find('[href="' + window.location.hash + '"]').addClass('selected'); }
javascript
function () { // Remove the `selected` class from the old link and add it to the link for the current location hash this.element.find('#filters').find('a').removeClass('selected') .end().find('[href="' + window.location.hash + '"]').addClass('selected'); }
[ "function", "(", ")", "{", "// Remove the `selected` class from the old link and add it to the link for the current location hash", "this", ".", "element", ".", "find", "(", "'#filters'", ")", ".", "find", "(", "'a'", ")", ".", "removeClass", "(", "'selected'", ")", ".", "end", "(", ")", ".", "find", "(", "'[href=\"'", "+", "window", ".", "location", ".", "hash", "+", "'\"]'", ")", ".", "addClass", "(", "'selected'", ")", ";", "}" ]
Listener for when the route changes
[ "Listener", "for", "when", "the", "route", "changes" ]
6c0056bed585927c76c3a22c0f482adb48b0fde2
https://github.com/bitovi/funcunit/blob/6c0056bed585927c76c3a22c0f482adb48b0fde2/site/examples/todo/js/todos/todos.js#L39-L43
18,358
bitovi/funcunit
site/examples/todo/js/todos/todos.js
function (el) { var value = can.trim(el.val()), todo = el.closest('.todo').data('todo'); // If we don't have a todo we don't need to do anything if (!todo) { return; } if (value === '') { todo.destroy(); } else { todo.attr({ editing : false, text : value }).save(); } }
javascript
function (el) { var value = can.trim(el.val()), todo = el.closest('.todo').data('todo'); // If we don't have a todo we don't need to do anything if (!todo) { return; } if (value === '') { todo.destroy(); } else { todo.attr({ editing : false, text : value }).save(); } }
[ "function", "(", "el", ")", "{", "var", "value", "=", "can", ".", "trim", "(", "el", ".", "val", "(", ")", ")", ",", "todo", "=", "el", ".", "closest", "(", "'.todo'", ")", ".", "data", "(", "'todo'", ")", ";", "// If we don't have a todo we don't need to do anything", "if", "(", "!", "todo", ")", "{", "return", ";", "}", "if", "(", "value", "===", "''", ")", "{", "todo", ".", "destroy", "(", ")", ";", "}", "else", "{", "todo", ".", "attr", "(", "{", "editing", ":", "false", ",", "text", ":", "value", "}", ")", ".", "save", "(", ")", ";", "}", "}" ]
Update a todo
[ "Update", "a", "todo" ]
6c0056bed585927c76c3a22c0f482adb48b0fde2
https://github.com/bitovi/funcunit/blob/6c0056bed585927c76c3a22c0f482adb48b0fde2/site/examples/todo/js/todos/todos.js#L53-L70
18,359
bitovi/funcunit
site/examples/todo/js/todos/todos.js
function (el) { var toggle = el.prop('checked'); can.each(this.options.todos, function (todo) { todo.attr('complete', toggle).save(); }); }
javascript
function (el) { var toggle = el.prop('checked'); can.each(this.options.todos, function (todo) { todo.attr('complete', toggle).save(); }); }
[ "function", "(", "el", ")", "{", "var", "toggle", "=", "el", ".", "prop", "(", "'checked'", ")", ";", "can", ".", "each", "(", "this", ".", "options", ".", "todos", ",", "function", "(", "todo", ")", "{", "todo", ".", "attr", "(", "'complete'", ",", "toggle", ")", ".", "save", "(", ")", ";", "}", ")", ";", "}" ]
Listen for toggle all completed Todos
[ "Listen", "for", "toggle", "all", "completed", "Todos" ]
6c0056bed585927c76c3a22c0f482adb48b0fde2
https://github.com/bitovi/funcunit/blob/6c0056bed585927c76c3a22c0f482adb48b0fde2/site/examples/todo/js/todos/todos.js#L94-L99
18,360
bitovi/funcunit
site/examples/todo/js/todos/todos.js
function () { for (var i = this.options.todos.length - 1, todo; i > -1 && (todo = this.options.todos[i]); i--) { if (todo.attr('complete')) { todo.destroy(); } } }
javascript
function () { for (var i = this.options.todos.length - 1, todo; i > -1 && (todo = this.options.todos[i]); i--) { if (todo.attr('complete')) { todo.destroy(); } } }
[ "function", "(", ")", "{", "for", "(", "var", "i", "=", "this", ".", "options", ".", "todos", ".", "length", "-", "1", ",", "todo", ";", "i", ">", "-", "1", "&&", "(", "todo", "=", "this", ".", "options", ".", "todos", "[", "i", "]", ")", ";", "i", "--", ")", "{", "if", "(", "todo", ".", "attr", "(", "'complete'", ")", ")", "{", "todo", ".", "destroy", "(", ")", ";", "}", "}", "}" ]
Listen for removing all completed Todos
[ "Listen", "for", "removing", "all", "completed", "Todos" ]
6c0056bed585927c76c3a22c0f482adb48b0fde2
https://github.com/bitovi/funcunit/blob/6c0056bed585927c76c3a22c0f482adb48b0fde2/site/examples/todo/js/todos/todos.js#L102-L108
18,361
bitovi/funcunit
site/examples/resources/funcunit.js
function( type, options, element ) { options || (options = {}); var create = Syn.create, setup = create[type] && create[type].setup, kind = key.test(type) ? 'key' : (page.test(type) ? "page" : "mouse"), createType = create[type] || {}, createKind = create[kind], event, ret, autoPrevent, dispatchEl = element; //any setup code? Syn.support.ready === 2 && setup && setup(type, options, element); autoPrevent = options._autoPrevent; //get kind delete options._autoPrevent; if ( createType.event ) { ret = createType.event(type, options, element); } else { //convert options options = createKind.options ? createKind.options(type, options, element) : options; if (!Syn.support.changeBubbles && /option/i.test(element.nodeName) ) { dispatchEl = element.parentNode; //jQuery expects clicks on select } //create the event event = createKind.event(type, options, dispatchEl); //send the event ret = Syn.dispatch(event, dispatchEl, type, autoPrevent); } ret && Syn.support.ready === 2 && Syn.defaults[type] && Syn.defaults[type].call(element, options, autoPrevent); return ret; }
javascript
function( type, options, element ) { options || (options = {}); var create = Syn.create, setup = create[type] && create[type].setup, kind = key.test(type) ? 'key' : (page.test(type) ? "page" : "mouse"), createType = create[type] || {}, createKind = create[kind], event, ret, autoPrevent, dispatchEl = element; //any setup code? Syn.support.ready === 2 && setup && setup(type, options, element); autoPrevent = options._autoPrevent; //get kind delete options._autoPrevent; if ( createType.event ) { ret = createType.event(type, options, element); } else { //convert options options = createKind.options ? createKind.options(type, options, element) : options; if (!Syn.support.changeBubbles && /option/i.test(element.nodeName) ) { dispatchEl = element.parentNode; //jQuery expects clicks on select } //create the event event = createKind.event(type, options, dispatchEl); //send the event ret = Syn.dispatch(event, dispatchEl, type, autoPrevent); } ret && Syn.support.ready === 2 && Syn.defaults[type] && Syn.defaults[type].call(element, options, autoPrevent); return ret; }
[ "function", "(", "type", ",", "options", ",", "element", ")", "{", "options", "||", "(", "options", "=", "{", "}", ")", ";", "var", "create", "=", "Syn", ".", "create", ",", "setup", "=", "create", "[", "type", "]", "&&", "create", "[", "type", "]", ".", "setup", ",", "kind", "=", "key", ".", "test", "(", "type", ")", "?", "'key'", ":", "(", "page", ".", "test", "(", "type", ")", "?", "\"page\"", ":", "\"mouse\"", ")", ",", "createType", "=", "create", "[", "type", "]", "||", "{", "}", ",", "createKind", "=", "create", "[", "kind", "]", ",", "event", ",", "ret", ",", "autoPrevent", ",", "dispatchEl", "=", "element", ";", "//any setup code?", "Syn", ".", "support", ".", "ready", "===", "2", "&&", "setup", "&&", "setup", "(", "type", ",", "options", ",", "element", ")", ";", "autoPrevent", "=", "options", ".", "_autoPrevent", ";", "//get kind", "delete", "options", ".", "_autoPrevent", ";", "if", "(", "createType", ".", "event", ")", "{", "ret", "=", "createType", ".", "event", "(", "type", ",", "options", ",", "element", ")", ";", "}", "else", "{", "//convert options", "options", "=", "createKind", ".", "options", "?", "createKind", ".", "options", "(", "type", ",", "options", ",", "element", ")", ":", "options", ";", "if", "(", "!", "Syn", ".", "support", ".", "changeBubbles", "&&", "/", "option", "/", "i", ".", "test", "(", "element", ".", "nodeName", ")", ")", "{", "dispatchEl", "=", "element", ".", "parentNode", ";", "//jQuery expects clicks on select", "}", "//create the event", "event", "=", "createKind", ".", "event", "(", "type", ",", "options", ",", "dispatchEl", ")", ";", "//send the event", "ret", "=", "Syn", ".", "dispatch", "(", "event", ",", "dispatchEl", ",", "type", ",", "autoPrevent", ")", ";", "}", "ret", "&&", "Syn", ".", "support", ".", "ready", "===", "2", "&&", "Syn", ".", "defaults", "[", "type", "]", "&&", "Syn", ".", "defaults", "[", "type", "]", ".", "call", "(", "element", ",", "options", ",", "autoPrevent", ")", ";", "return", "ret", ";", "}" ]
Creates a synthetic event and dispatches it on the element. This will run any default actions for the element. Typically you want to use Syn, but if you want the return value, use this. @param {String} type @param {Object} options @param {HTMLElement} element @return {Boolean} true if default events were run, false if otherwise.
[ "Creates", "a", "synthetic", "event", "and", "dispatches", "it", "on", "the", "element", ".", "This", "will", "run", "any", "default", "actions", "for", "the", "element", ".", "Typically", "you", "want", "to", "use", "Syn", "but", "if", "you", "want", "the", "return", "value", "use", "this", "." ]
6c0056bed585927c76c3a22c0f482adb48b0fde2
https://github.com/bitovi/funcunit/blob/6c0056bed585927c76c3a22c0f482adb48b0fde2/site/examples/resources/funcunit.js#L608-L644
18,362
bitovi/funcunit
site/examples/resources/funcunit.js
function( type, options, element ) { //check if options is character or has character options = typeof options != "object" ? { character: options } : options; //don't change the orignial options = h.extend({}, options) if ( options.character ) { h.extend(options, Syn.key.options(options.character, type)); delete options.character; } options = h.extend({ ctrlKey: !! Syn.key.ctrlKey, altKey: !! Syn.key.altKey, shiftKey: !! Syn.key.shiftKey, metaKey: !! Syn.key.metaKey }, options) return options; }
javascript
function( type, options, element ) { //check if options is character or has character options = typeof options != "object" ? { character: options } : options; //don't change the orignial options = h.extend({}, options) if ( options.character ) { h.extend(options, Syn.key.options(options.character, type)); delete options.character; } options = h.extend({ ctrlKey: !! Syn.key.ctrlKey, altKey: !! Syn.key.altKey, shiftKey: !! Syn.key.shiftKey, metaKey: !! Syn.key.metaKey }, options) return options; }
[ "function", "(", "type", ",", "options", ",", "element", ")", "{", "//check if options is character or has character", "options", "=", "typeof", "options", "!=", "\"object\"", "?", "{", "character", ":", "options", "}", ":", "options", ";", "//don't change the orignial", "options", "=", "h", ".", "extend", "(", "{", "}", ",", "options", ")", "if", "(", "options", ".", "character", ")", "{", "h", ".", "extend", "(", "options", ",", "Syn", ".", "key", ".", "options", "(", "options", ".", "character", ",", "type", ")", ")", ";", "delete", "options", ".", "character", ";", "}", "options", "=", "h", ".", "extend", "(", "{", "ctrlKey", ":", "!", "!", "Syn", ".", "key", ".", "ctrlKey", ",", "altKey", ":", "!", "!", "Syn", ".", "key", ".", "altKey", ",", "shiftKey", ":", "!", "!", "Syn", ".", "key", ".", "shiftKey", ",", "metaKey", ":", "!", "!", "Syn", ".", "key", ".", "metaKey", "}", ",", "options", ")", "return", "options", ";", "}" ]
return the options for a key event
[ "return", "the", "options", "for", "a", "key", "event" ]
6c0056bed585927c76c3a22c0f482adb48b0fde2
https://github.com/bitovi/funcunit/blob/6c0056bed585927c76c3a22c0f482adb48b0fde2/site/examples/resources/funcunit.js#L1951-L1972
18,363
bitovi/funcunit
site/examples/todo/js/lib/canjs/can.jquery.js
function (elems, context) { var oldFragment = $.buildFragment, ret; elems = [elems]; // Set context per 1.8 logic context = context || document; context = !context.nodeType && context[0] || context; context = context.ownerDocument || context; ret = oldFragment.call(jQuery, elems, context); return ret.cacheable ? $.clone(ret.fragment) : ret.fragment || ret; }
javascript
function (elems, context) { var oldFragment = $.buildFragment, ret; elems = [elems]; // Set context per 1.8 logic context = context || document; context = !context.nodeType && context[0] || context; context = context.ownerDocument || context; ret = oldFragment.call(jQuery, elems, context); return ret.cacheable ? $.clone(ret.fragment) : ret.fragment || ret; }
[ "function", "(", "elems", ",", "context", ")", "{", "var", "oldFragment", "=", "$", ".", "buildFragment", ",", "ret", ";", "elems", "=", "[", "elems", "]", ";", "// Set context per 1.8 logic", "context", "=", "context", "||", "document", ";", "context", "=", "!", "context", ".", "nodeType", "&&", "context", "[", "0", "]", "||", "context", ";", "context", "=", "context", ".", "ownerDocument", "||", "context", ";", "ret", "=", "oldFragment", ".", "call", "(", "jQuery", ",", "elems", ",", "context", ")", ";", "return", "ret", ".", "cacheable", "?", "$", ".", "clone", "(", "ret", ".", "fragment", ")", ":", "ret", ".", "fragment", "||", "ret", ";", "}" ]
jquery caches fragments, we always needs a new one
[ "jquery", "caches", "fragments", "we", "always", "needs", "a", "new", "one" ]
6c0056bed585927c76c3a22c0f482adb48b0fde2
https://github.com/bitovi/funcunit/blob/6c0056bed585927c76c3a22c0f482adb48b0fde2/site/examples/todo/js/lib/canjs/can.jquery.js#L74-L87
18,364
bitovi/funcunit
site/examples/todo/js/lib/canjs/can.jquery.js
function (content) { // Convert bad values into empty strings var isInvalid = content === null || content === undefined || (isNaN(content) && ("" + content === 'NaN')); return ("" + (isInvalid ? '' : content)).replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(strQuote, '&#34;').replace(strSingleQuote, "&#39;"); }
javascript
function (content) { // Convert bad values into empty strings var isInvalid = content === null || content === undefined || (isNaN(content) && ("" + content === 'NaN')); return ("" + (isInvalid ? '' : content)).replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(strQuote, '&#34;').replace(strSingleQuote, "&#39;"); }
[ "function", "(", "content", ")", "{", "// Convert bad values into empty strings", "var", "isInvalid", "=", "content", "===", "null", "||", "content", "===", "undefined", "||", "(", "isNaN", "(", "content", ")", "&&", "(", "\"\"", "+", "content", "===", "'NaN'", ")", ")", ";", "return", "(", "\"\"", "+", "(", "isInvalid", "?", "''", ":", "content", ")", ")", ".", "replace", "(", "/", "&", "/", "g", ",", "'&amp;'", ")", ".", "replace", "(", "/", "<", "/", "g", ",", "'&lt;'", ")", ".", "replace", "(", "/", ">", "/", "g", ",", "'&gt;'", ")", ".", "replace", "(", "strQuote", ",", "'&#34;'", ")", ".", "replace", "(", "strSingleQuote", ",", "\"&#39;\"", ")", ";", "}" ]
Escapes strings for HTML.
[ "Escapes", "strings", "for", "HTML", "." ]
6c0056bed585927c76c3a22c0f482adb48b0fde2
https://github.com/bitovi/funcunit/blob/6c0056bed585927c76c3a22c0f482adb48b0fde2/site/examples/todo/js/lib/canjs/can.jquery.js#L149-L153
18,365
bitovi/funcunit
site/examples/todo/js/lib/canjs/can.jquery.js
function (s) { return s.replace(strColons, '/').replace(strWords, '$1_$2').replace(strLowUp, '$1_$2').replace(strDash, '_').toLowerCase(); }
javascript
function (s) { return s.replace(strColons, '/').replace(strWords, '$1_$2').replace(strLowUp, '$1_$2').replace(strDash, '_').toLowerCase(); }
[ "function", "(", "s", ")", "{", "return", "s", ".", "replace", "(", "strColons", ",", "'/'", ")", ".", "replace", "(", "strWords", ",", "'$1_$2'", ")", ".", "replace", "(", "strLowUp", ",", "'$1_$2'", ")", ".", "replace", "(", "strDash", ",", "'_'", ")", ".", "toLowerCase", "(", ")", ";", "}" ]
Underscores a string.
[ "Underscores", "a", "string", "." ]
6c0056bed585927c76c3a22c0f482adb48b0fde2
https://github.com/bitovi/funcunit/blob/6c0056bed585927c76c3a22c0f482adb48b0fde2/site/examples/todo/js/lib/canjs/can.jquery.js#L208-L210
18,366
bitovi/funcunit
site/examples/todo/js/lib/canjs/can.jquery.js
function (str, data, remove) { var obs = []; obs.push(str.replace(strReplacer, function (whole, inside) { // Convert inside to type. var ob = can.getObject(inside, data, remove === undefined ? remove : !remove); if (ob === undefined) { obs = null; return ""; } // If a container, push into objs (which will return objects found). if (isContainer(ob) && obs) { obs.push(ob); return ""; } return "" + ob; })); return obs === null ? obs : (obs.length <= 1 ? obs[0] : obs); }
javascript
function (str, data, remove) { var obs = []; obs.push(str.replace(strReplacer, function (whole, inside) { // Convert inside to type. var ob = can.getObject(inside, data, remove === undefined ? remove : !remove); if (ob === undefined) { obs = null; return ""; } // If a container, push into objs (which will return objects found). if (isContainer(ob) && obs) { obs.push(ob); return ""; } return "" + ob; })); return obs === null ? obs : (obs.length <= 1 ? obs[0] : obs); }
[ "function", "(", "str", ",", "data", ",", "remove", ")", "{", "var", "obs", "=", "[", "]", ";", "obs", ".", "push", "(", "str", ".", "replace", "(", "strReplacer", ",", "function", "(", "whole", ",", "inside", ")", "{", "// Convert inside to type.", "var", "ob", "=", "can", ".", "getObject", "(", "inside", ",", "data", ",", "remove", "===", "undefined", "?", "remove", ":", "!", "remove", ")", ";", "if", "(", "ob", "===", "undefined", ")", "{", "obs", "=", "null", ";", "return", "\"\"", ";", "}", "// If a container, push into objs (which will return objects found).", "if", "(", "isContainer", "(", "ob", ")", "&&", "obs", ")", "{", "obs", ".", "push", "(", "ob", ")", ";", "return", "\"\"", ";", "}", "return", "\"\"", "+", "ob", ";", "}", ")", ")", ";", "return", "obs", "===", "null", "?", "obs", ":", "(", "obs", ".", "length", "<=", "1", "?", "obs", "[", "0", "]", ":", "obs", ")", ";", "}" ]
Micro-templating.
[ "Micro", "-", "templating", "." ]
6c0056bed585927c76c3a22c0f482adb48b0fde2
https://github.com/bitovi/funcunit/blob/6c0056bed585927c76c3a22c0f482adb48b0fde2/site/examples/todo/js/lib/canjs/can.jquery.js#L212-L235
18,367
bitovi/funcunit
site/examples/todo/js/lib/canjs/can.jquery.js
function (result) { var frag = can.buildFragment(result, document.body); // If we have an empty frag... if (!frag.childNodes.length) { frag.appendChild(document.createTextNode('')); } return frag; }
javascript
function (result) { var frag = can.buildFragment(result, document.body); // If we have an empty frag... if (!frag.childNodes.length) { frag.appendChild(document.createTextNode('')); } return frag; }
[ "function", "(", "result", ")", "{", "var", "frag", "=", "can", ".", "buildFragment", "(", "result", ",", "document", ".", "body", ")", ";", "// If we have an empty frag...", "if", "(", "!", "frag", ".", "childNodes", ".", "length", ")", "{", "frag", ".", "appendChild", "(", "document", ".", "createTextNode", "(", "''", ")", ")", ";", "}", "return", "frag", ";", "}" ]
simply creates a frag this is used internally to create a frag insert it then hook it up
[ "simply", "creates", "a", "frag", "this", "is", "used", "internally", "to", "create", "a", "frag", "insert", "it", "then", "hook", "it", "up" ]
6c0056bed585927c76c3a22c0f482adb48b0fde2
https://github.com/bitovi/funcunit/blob/6c0056bed585927c76c3a22c0f482adb48b0fde2/site/examples/todo/js/lib/canjs/can.jquery.js#L2194-L2201
18,368
bitovi/funcunit
site/examples/todo/js/lib/canjs/can.jquery.js
function (src) { return can.map(src.toString().split(/\/|\./g), function (part) { // Dont include empty strings in toId functions if (part) { return part; } }).join("_"); }
javascript
function (src) { return can.map(src.toString().split(/\/|\./g), function (part) { // Dont include empty strings in toId functions if (part) { return part; } }).join("_"); }
[ "function", "(", "src", ")", "{", "return", "can", ".", "map", "(", "src", ".", "toString", "(", ")", ".", "split", "(", "/", "\\/|\\.", "/", "g", ")", ",", "function", "(", "part", ")", "{", "// Dont include empty strings in toId functions", "if", "(", "part", ")", "{", "return", "part", ";", "}", "}", ")", ".", "join", "(", "\"_\"", ")", ";", "}" ]
Convert a path like string into something that's ok for an `element` ID.
[ "Convert", "a", "path", "like", "string", "into", "something", "that", "s", "ok", "for", "an", "element", "ID", "." ]
6c0056bed585927c76c3a22c0f482adb48b0fde2
https://github.com/bitovi/funcunit/blob/6c0056bed585927c76c3a22c0f482adb48b0fde2/site/examples/todo/js/lib/canjs/can.jquery.js#L2204-L2211
18,369
bitovi/funcunit
site/examples/todo/js/lib/canjs/can.jquery.js
function (url, async) { var suffix = url.match(/\.[\w\d]+$/), type, // If we are reading a script element for the content of the template, // `el` will be set to that script element. el, // A unique identifier for the view (used for caching). // This is typically derived from the element id or // the url for the template. id, // The ajax request used to retrieve the template content. jqXHR; //If the url has a #, we assume we want to use an inline template //from a script element and not current page's HTML if (url.match(/^#/)) { url = url.substr(1); } // If we have an inline template, derive the suffix from the `text/???` part. // This only supports `<script>` tags. if (el = document.getElementById(url)) { suffix = "." + el.type.match(/\/(x\-)?(.+)/)[2]; } // If there is no suffix, add one. if (!suffix && !$view.cached[url]) { url += (suffix = $view.ext); } if (can.isArray(suffix)) { suffix = suffix[0] } // Convert to a unique and valid id. id = $view.toId(url); // If an absolute path, use `steal` to get it. // You should only be using `//` if you are using `steal`. if (url.match(/^\/\//)) { var sub = url.substr(2); url = !window.steal ? sub : steal.config().root.mapJoin(sub); } // Set the template engine type. type = $view.types[suffix]; // If it is cached, if ($view.cached[id]) { // Return the cached deferred renderer. return $view.cached[id]; // Otherwise if we are getting this from a `<script>` element. } else if (el) { // Resolve immediately with the element's `innerHTML`. return $view.registerView(id, el.innerHTML, type); } else { // Make an ajax request for text. var d = new can.Deferred(); can.ajax({ async: async, url: url, dataType: "text", error: function (jqXHR) { checkText("", url); d.reject(jqXHR); }, success: function (text) { // Make sure we got some text back. checkText(text, url); $view.registerView(id, text, type, d) } }); return d; } }
javascript
function (url, async) { var suffix = url.match(/\.[\w\d]+$/), type, // If we are reading a script element for the content of the template, // `el` will be set to that script element. el, // A unique identifier for the view (used for caching). // This is typically derived from the element id or // the url for the template. id, // The ajax request used to retrieve the template content. jqXHR; //If the url has a #, we assume we want to use an inline template //from a script element and not current page's HTML if (url.match(/^#/)) { url = url.substr(1); } // If we have an inline template, derive the suffix from the `text/???` part. // This only supports `<script>` tags. if (el = document.getElementById(url)) { suffix = "." + el.type.match(/\/(x\-)?(.+)/)[2]; } // If there is no suffix, add one. if (!suffix && !$view.cached[url]) { url += (suffix = $view.ext); } if (can.isArray(suffix)) { suffix = suffix[0] } // Convert to a unique and valid id. id = $view.toId(url); // If an absolute path, use `steal` to get it. // You should only be using `//` if you are using `steal`. if (url.match(/^\/\//)) { var sub = url.substr(2); url = !window.steal ? sub : steal.config().root.mapJoin(sub); } // Set the template engine type. type = $view.types[suffix]; // If it is cached, if ($view.cached[id]) { // Return the cached deferred renderer. return $view.cached[id]; // Otherwise if we are getting this from a `<script>` element. } else if (el) { // Resolve immediately with the element's `innerHTML`. return $view.registerView(id, el.innerHTML, type); } else { // Make an ajax request for text. var d = new can.Deferred(); can.ajax({ async: async, url: url, dataType: "text", error: function (jqXHR) { checkText("", url); d.reject(jqXHR); }, success: function (text) { // Make sure we got some text back. checkText(text, url); $view.registerView(id, text, type, d) } }); return d; } }
[ "function", "(", "url", ",", "async", ")", "{", "var", "suffix", "=", "url", ".", "match", "(", "/", "\\.[\\w\\d]+$", "/", ")", ",", "type", ",", "// If we are reading a script element for the content of the template,", "// `el` will be set to that script element.", "el", ",", "// A unique identifier for the view (used for caching).", "// This is typically derived from the element id or", "// the url for the template.", "id", ",", "// The ajax request used to retrieve the template content.", "jqXHR", ";", "//If the url has a #, we assume we want to use an inline template", "//from a script element and not current page's HTML", "if", "(", "url", ".", "match", "(", "/", "^#", "/", ")", ")", "{", "url", "=", "url", ".", "substr", "(", "1", ")", ";", "}", "// If we have an inline template, derive the suffix from the `text/???` part.", "// This only supports `<script>` tags.", "if", "(", "el", "=", "document", ".", "getElementById", "(", "url", ")", ")", "{", "suffix", "=", "\".\"", "+", "el", ".", "type", ".", "match", "(", "/", "\\/(x\\-)?(.+)", "/", ")", "[", "2", "]", ";", "}", "// If there is no suffix, add one.", "if", "(", "!", "suffix", "&&", "!", "$view", ".", "cached", "[", "url", "]", ")", "{", "url", "+=", "(", "suffix", "=", "$view", ".", "ext", ")", ";", "}", "if", "(", "can", ".", "isArray", "(", "suffix", ")", ")", "{", "suffix", "=", "suffix", "[", "0", "]", "}", "// Convert to a unique and valid id.", "id", "=", "$view", ".", "toId", "(", "url", ")", ";", "// If an absolute path, use `steal` to get it.", "// You should only be using `//` if you are using `steal`.", "if", "(", "url", ".", "match", "(", "/", "^\\/\\/", "/", ")", ")", "{", "var", "sub", "=", "url", ".", "substr", "(", "2", ")", ";", "url", "=", "!", "window", ".", "steal", "?", "sub", ":", "steal", ".", "config", "(", ")", ".", "root", ".", "mapJoin", "(", "sub", ")", ";", "}", "// Set the template engine type.", "type", "=", "$view", ".", "types", "[", "suffix", "]", ";", "// If it is cached,", "if", "(", "$view", ".", "cached", "[", "id", "]", ")", "{", "// Return the cached deferred renderer.", "return", "$view", ".", "cached", "[", "id", "]", ";", "// Otherwise if we are getting this from a `<script>` element.", "}", "else", "if", "(", "el", ")", "{", "// Resolve immediately with the element's `innerHTML`.", "return", "$view", ".", "registerView", "(", "id", ",", "el", ".", "innerHTML", ",", "type", ")", ";", "}", "else", "{", "// Make an ajax request for text.", "var", "d", "=", "new", "can", ".", "Deferred", "(", ")", ";", "can", ".", "ajax", "(", "{", "async", ":", "async", ",", "url", ":", "url", ",", "dataType", ":", "\"text\"", ",", "error", ":", "function", "(", "jqXHR", ")", "{", "checkText", "(", "\"\"", ",", "url", ")", ";", "d", ".", "reject", "(", "jqXHR", ")", ";", "}", ",", "success", ":", "function", "(", "text", ")", "{", "// Make sure we got some text back.", "checkText", "(", "text", ",", "url", ")", ";", "$view", ".", "registerView", "(", "id", ",", "text", ",", "type", ",", "d", ")", "}", "}", ")", ";", "return", "d", ";", "}", "}" ]
Makes sure there's a template, if not, have `steal` provide a warning.
[ "Makes", "sure", "there", "s", "a", "template", "if", "not", "have", "steal", "provide", "a", "warning", "." ]
6c0056bed585927c76c3a22c0f482adb48b0fde2
https://github.com/bitovi/funcunit/blob/6c0056bed585927c76c3a22c0f482adb48b0fde2/site/examples/todo/js/lib/canjs/can.jquery.js#L2398-L2472
18,370
bitovi/funcunit
site/examples/todo/js/lib/canjs/can.jquery.js
function () { for (var name in observing) { var ob = observing[name]; ob.observe.obj.unbind(ob.observe.attr, onchanged); delete observing[name]; } }
javascript
function () { for (var name in observing) { var ob = observing[name]; ob.observe.obj.unbind(ob.observe.attr, onchanged); delete observing[name]; } }
[ "function", "(", ")", "{", "for", "(", "var", "name", "in", "observing", ")", "{", "var", "ob", "=", "observing", "[", "name", "]", ";", "ob", ".", "observe", ".", "obj", ".", "unbind", "(", "ob", ".", "observe", ".", "attr", ",", "onchanged", ")", ";", "delete", "observing", "[", "name", "]", ";", "}", "}" ]
a teardown method that stops listening
[ "a", "teardown", "method", "that", "stops", "listening" ]
6c0056bed585927c76c3a22c0f482adb48b0fde2
https://github.com/bitovi/funcunit/blob/6c0056bed585927c76c3a22c0f482adb48b0fde2/site/examples/todo/js/lib/canjs/can.jquery.js#L2592-L2598
18,371
bitovi/funcunit
site/examples/todo/js/lib/canjs/can.jquery.js
function (ev) { // If the compute is no longer bound (because the same change event led to an unbind) // then do not call getValueAndBind, or we will leak bindings. if (computeState && !computeState.bound) { return; } if (ev.batchNum === undefined || ev.batchNum !== batchNum) { // store the old value var oldValue = data.value, // get the new value newvalue = getValueAndBind(); // update the value reference (in case someone reads) data.value = newvalue; // if a change happened if (newvalue !== oldValue) { callback(newvalue, oldValue); } batchNum = batchNum = ev.batchNum; } }
javascript
function (ev) { // If the compute is no longer bound (because the same change event led to an unbind) // then do not call getValueAndBind, or we will leak bindings. if (computeState && !computeState.bound) { return; } if (ev.batchNum === undefined || ev.batchNum !== batchNum) { // store the old value var oldValue = data.value, // get the new value newvalue = getValueAndBind(); // update the value reference (in case someone reads) data.value = newvalue; // if a change happened if (newvalue !== oldValue) { callback(newvalue, oldValue); } batchNum = batchNum = ev.batchNum; } }
[ "function", "(", "ev", ")", "{", "// If the compute is no longer bound (because the same change event led to an unbind)", "// then do not call getValueAndBind, or we will leak bindings.", "if", "(", "computeState", "&&", "!", "computeState", ".", "bound", ")", "{", "return", ";", "}", "if", "(", "ev", ".", "batchNum", "===", "undefined", "||", "ev", ".", "batchNum", "!==", "batchNum", ")", "{", "// store the old value", "var", "oldValue", "=", "data", ".", "value", ",", "// get the new value", "newvalue", "=", "getValueAndBind", "(", ")", ";", "// update the value reference (in case someone reads)", "data", ".", "value", "=", "newvalue", ";", "// if a change happened", "if", "(", "newvalue", "!==", "oldValue", ")", "{", "callback", "(", "newvalue", ",", "oldValue", ")", ";", "}", "batchNum", "=", "batchNum", "=", "ev", ".", "batchNum", ";", "}", "}" ]
when a property value is changed
[ "when", "a", "property", "value", "is", "changed" ]
6c0056bed585927c76c3a22c0f482adb48b0fde2
https://github.com/bitovi/funcunit/blob/6c0056bed585927c76c3a22c0f482adb48b0fde2/site/examples/todo/js/lib/canjs/can.jquery.js#L2603-L2624
18,372
bitovi/funcunit
site/examples/todo/js/lib/canjs/can.jquery.js
function () { var info = getValueAndObserved(getterSetter, context), newObserveSet = info.observed; var value = info.value; matched = !matched; // go through every attribute read by this observe can.each(newObserveSet, function (ob) { // if the observe/attribute pair is being observed if (observing[ob.obj._cid + "|" + ob.attr]) { // mark at as observed observing[ob.obj._cid + "|" + ob.attr].matched = matched; } else { // otherwise, set the observe/attribute on oldObserved, marking it as being observed observing[ob.obj._cid + "|" + ob.attr] = { matched: matched, observe: ob }; ob.obj.bind(ob.attr, onchanged); } }); // Iterate through oldObserved, looking for observe/attributes // that are no longer being bound and unbind them for (var name in observing) { var ob = observing[name]; if (ob.matched !== matched) { ob.observe.obj.unbind(ob.observe.attr, onchanged); delete observing[name]; } } return value; }
javascript
function () { var info = getValueAndObserved(getterSetter, context), newObserveSet = info.observed; var value = info.value; matched = !matched; // go through every attribute read by this observe can.each(newObserveSet, function (ob) { // if the observe/attribute pair is being observed if (observing[ob.obj._cid + "|" + ob.attr]) { // mark at as observed observing[ob.obj._cid + "|" + ob.attr].matched = matched; } else { // otherwise, set the observe/attribute on oldObserved, marking it as being observed observing[ob.obj._cid + "|" + ob.attr] = { matched: matched, observe: ob }; ob.obj.bind(ob.attr, onchanged); } }); // Iterate through oldObserved, looking for observe/attributes // that are no longer being bound and unbind them for (var name in observing) { var ob = observing[name]; if (ob.matched !== matched) { ob.observe.obj.unbind(ob.observe.attr, onchanged); delete observing[name]; } } return value; }
[ "function", "(", ")", "{", "var", "info", "=", "getValueAndObserved", "(", "getterSetter", ",", "context", ")", ",", "newObserveSet", "=", "info", ".", "observed", ";", "var", "value", "=", "info", ".", "value", ";", "matched", "=", "!", "matched", ";", "// go through every attribute read by this observe", "can", ".", "each", "(", "newObserveSet", ",", "function", "(", "ob", ")", "{", "// if the observe/attribute pair is being observed", "if", "(", "observing", "[", "ob", ".", "obj", ".", "_cid", "+", "\"|\"", "+", "ob", ".", "attr", "]", ")", "{", "// mark at as observed", "observing", "[", "ob", ".", "obj", ".", "_cid", "+", "\"|\"", "+", "ob", ".", "attr", "]", ".", "matched", "=", "matched", ";", "}", "else", "{", "// otherwise, set the observe/attribute on oldObserved, marking it as being observed", "observing", "[", "ob", ".", "obj", ".", "_cid", "+", "\"|\"", "+", "ob", ".", "attr", "]", "=", "{", "matched", ":", "matched", ",", "observe", ":", "ob", "}", ";", "ob", ".", "obj", ".", "bind", "(", "ob", ".", "attr", ",", "onchanged", ")", ";", "}", "}", ")", ";", "// Iterate through oldObserved, looking for observe/attributes", "// that are no longer being bound and unbind them", "for", "(", "var", "name", "in", "observing", ")", "{", "var", "ob", "=", "observing", "[", "name", "]", ";", "if", "(", "ob", ".", "matched", "!==", "matched", ")", "{", "ob", ".", "observe", ".", "obj", ".", "unbind", "(", "ob", ".", "observe", ".", "attr", ",", "onchanged", ")", ";", "delete", "observing", "[", "name", "]", ";", "}", "}", "return", "value", ";", "}" ]
gets the value returned by `getterSetter` and also binds to any attributes read by the call
[ "gets", "the", "value", "returned", "by", "getterSetter", "and", "also", "binds", "to", "any", "attributes", "read", "by", "the", "call" ]
6c0056bed585927c76c3a22c0f482adb48b0fde2
https://github.com/bitovi/funcunit/blob/6c0056bed585927c76c3a22c0f482adb48b0fde2/site/examples/todo/js/lib/canjs/can.jquery.js#L2628-L2661
18,373
bitovi/funcunit
site/examples/todo/js/lib/canjs/can.jquery.js
function (el, parentNode) { // updates the text of the text node update = function (newVal) { node.nodeValue = "" + newVal; teardownCheck(node.parentNode); }; var parent = getParentNode(el, parentNode), node = document.createTextNode(binding.value); // When iterating through an Observe.List with no DOM // elements containing the individual items, the parent // is sometimes incorrect not the true parent of the // source element. (#153) if (el.parentNode !== parent) { parent = el.parentNode; parent.insertBefore(node, el); parent.removeChild(el); } else { parent.insertBefore(node, el); parent.removeChild(el); } setupTeardownOnDestroy(parent); }
javascript
function (el, parentNode) { // updates the text of the text node update = function (newVal) { node.nodeValue = "" + newVal; teardownCheck(node.parentNode); }; var parent = getParentNode(el, parentNode), node = document.createTextNode(binding.value); // When iterating through an Observe.List with no DOM // elements containing the individual items, the parent // is sometimes incorrect not the true parent of the // source element. (#153) if (el.parentNode !== parent) { parent = el.parentNode; parent.insertBefore(node, el); parent.removeChild(el); } else { parent.insertBefore(node, el); parent.removeChild(el); } setupTeardownOnDestroy(parent); }
[ "function", "(", "el", ",", "parentNode", ")", "{", "// updates the text of the text node", "update", "=", "function", "(", "newVal", ")", "{", "node", ".", "nodeValue", "=", "\"\"", "+", "newVal", ";", "teardownCheck", "(", "node", ".", "parentNode", ")", ";", "}", ";", "var", "parent", "=", "getParentNode", "(", "el", ",", "parentNode", ")", ",", "node", "=", "document", ".", "createTextNode", "(", "binding", ".", "value", ")", ";", "// When iterating through an Observe.List with no DOM", "// elements containing the individual items, the parent", "// is sometimes incorrect not the true parent of the", "// source element. (#153)", "if", "(", "el", ".", "parentNode", "!==", "parent", ")", "{", "parent", "=", "el", ".", "parentNode", ";", "parent", ".", "insertBefore", "(", "node", ",", "el", ")", ";", "parent", ".", "removeChild", "(", "el", ")", ";", "}", "else", "{", "parent", ".", "insertBefore", "(", "node", ",", "el", ")", ";", "parent", ".", "removeChild", "(", "el", ")", ";", "}", "setupTeardownOnDestroy", "(", "parent", ")", ";", "}" ]
If we are escaping, replace the parentNode with a text node who's value is `func`'s return value.
[ "If", "we", "are", "escaping", "replace", "the", "parentNode", "with", "a", "text", "node", "who", "s", "value", "is", "func", "s", "return", "value", "." ]
6c0056bed585927c76c3a22c0f482adb48b0fde2
https://github.com/bitovi/funcunit/blob/6c0056bed585927c76c3a22c0f482adb48b0fde2/site/examples/todo/js/lib/canjs/can.jquery.js#L3433-L3456
18,374
bitovi/funcunit
site/examples/todo/js/lib/canjs/can.jquery.js
function (span, parentNode) { // updates the elements with the new content update = function (newVal) { // is this still part of the DOM? var attached = nodes[0].parentNode; // update the nodes in the DOM with the new rendered value if (attached) { makeAndPut(newVal); } teardownCheck(nodes[0].parentNode); }; // make sure we have a valid parentNode parentNode = getParentNode(span, parentNode); // A helper function to manage inserting the contents // and removing the old contents var nodes, makeAndPut = function (val) { // create the fragment, but don't hook it up // we need to insert it into the document first var frag = can.view.frag(val, parentNode), // keep a reference to each node newNodes = can.makeArray(frag.childNodes), last = nodes ? nodes[nodes.length - 1] : span; // Insert it in the `document` or `documentFragment` if (last.nextSibling) { last.parentNode.insertBefore(frag, last.nextSibling); } else { last.parentNode.appendChild(frag); } // nodes hasn't been set yet if (!nodes) { can.remove(can.$(span)); nodes = newNodes; // set the teardown nodeList nodeList = nodes; can.view.registerNode(nodes); } else { // Update node Array's to point to new nodes // and then remove the old nodes. // It has to be in this order for Mootools // and IE because somehow, after an element // is removed from the DOM, it loses its // expando values. var nodesToRemove = can.makeArray(nodes); can.view.replace(nodes, newNodes); can.remove(can.$(nodesToRemove)); } }; // nodes are the nodes that any updates will replace // at this point, these nodes could be part of a documentFragment makeAndPut(binding.value, [span]); setupTeardownOnDestroy(parentNode); //children have to be properly nested HTML for buildFragment to work properly }
javascript
function (span, parentNode) { // updates the elements with the new content update = function (newVal) { // is this still part of the DOM? var attached = nodes[0].parentNode; // update the nodes in the DOM with the new rendered value if (attached) { makeAndPut(newVal); } teardownCheck(nodes[0].parentNode); }; // make sure we have a valid parentNode parentNode = getParentNode(span, parentNode); // A helper function to manage inserting the contents // and removing the old contents var nodes, makeAndPut = function (val) { // create the fragment, but don't hook it up // we need to insert it into the document first var frag = can.view.frag(val, parentNode), // keep a reference to each node newNodes = can.makeArray(frag.childNodes), last = nodes ? nodes[nodes.length - 1] : span; // Insert it in the `document` or `documentFragment` if (last.nextSibling) { last.parentNode.insertBefore(frag, last.nextSibling); } else { last.parentNode.appendChild(frag); } // nodes hasn't been set yet if (!nodes) { can.remove(can.$(span)); nodes = newNodes; // set the teardown nodeList nodeList = nodes; can.view.registerNode(nodes); } else { // Update node Array's to point to new nodes // and then remove the old nodes. // It has to be in this order for Mootools // and IE because somehow, after an element // is removed from the DOM, it loses its // expando values. var nodesToRemove = can.makeArray(nodes); can.view.replace(nodes, newNodes); can.remove(can.$(nodesToRemove)); } }; // nodes are the nodes that any updates will replace // at this point, these nodes could be part of a documentFragment makeAndPut(binding.value, [span]); setupTeardownOnDestroy(parentNode); //children have to be properly nested HTML for buildFragment to work properly }
[ "function", "(", "span", ",", "parentNode", ")", "{", "// updates the elements with the new content", "update", "=", "function", "(", "newVal", ")", "{", "// is this still part of the DOM?", "var", "attached", "=", "nodes", "[", "0", "]", ".", "parentNode", ";", "// update the nodes in the DOM with the new rendered value", "if", "(", "attached", ")", "{", "makeAndPut", "(", "newVal", ")", ";", "}", "teardownCheck", "(", "nodes", "[", "0", "]", ".", "parentNode", ")", ";", "}", ";", "// make sure we have a valid parentNode", "parentNode", "=", "getParentNode", "(", "span", ",", "parentNode", ")", ";", "// A helper function to manage inserting the contents", "// and removing the old contents", "var", "nodes", ",", "makeAndPut", "=", "function", "(", "val", ")", "{", "// create the fragment, but don't hook it up", "// we need to insert it into the document first", "var", "frag", "=", "can", ".", "view", ".", "frag", "(", "val", ",", "parentNode", ")", ",", "// keep a reference to each node", "newNodes", "=", "can", ".", "makeArray", "(", "frag", ".", "childNodes", ")", ",", "last", "=", "nodes", "?", "nodes", "[", "nodes", ".", "length", "-", "1", "]", ":", "span", ";", "// Insert it in the `document` or `documentFragment`", "if", "(", "last", ".", "nextSibling", ")", "{", "last", ".", "parentNode", ".", "insertBefore", "(", "frag", ",", "last", ".", "nextSibling", ")", ";", "}", "else", "{", "last", ".", "parentNode", ".", "appendChild", "(", "frag", ")", ";", "}", "// nodes hasn't been set yet", "if", "(", "!", "nodes", ")", "{", "can", ".", "remove", "(", "can", ".", "$", "(", "span", ")", ")", ";", "nodes", "=", "newNodes", ";", "// set the teardown nodeList", "nodeList", "=", "nodes", ";", "can", ".", "view", ".", "registerNode", "(", "nodes", ")", ";", "}", "else", "{", "// Update node Array's to point to new nodes", "// and then remove the old nodes.", "// It has to be in this order for Mootools", "// and IE because somehow, after an element", "// is removed from the DOM, it loses its", "// expando values.", "var", "nodesToRemove", "=", "can", ".", "makeArray", "(", "nodes", ")", ";", "can", ".", "view", ".", "replace", "(", "nodes", ",", "newNodes", ")", ";", "can", ".", "remove", "(", "can", ".", "$", "(", "nodesToRemove", ")", ")", ";", "}", "}", ";", "// nodes are the nodes that any updates will replace", "// at this point, these nodes could be part of a documentFragment", "makeAndPut", "(", "binding", ".", "value", ",", "[", "span", "]", ")", ";", "setupTeardownOnDestroy", "(", "parentNode", ")", ";", "//children have to be properly nested HTML for buildFragment to work properly", "}" ]
If we are not escaping, replace the parentNode with a documentFragment created as with `func`'s return value.
[ "If", "we", "are", "not", "escaping", "replace", "the", "parentNode", "with", "a", "documentFragment", "created", "as", "with", "func", "s", "return", "value", "." ]
6c0056bed585927c76c3a22c0f482adb48b0fde2
https://github.com/bitovi/funcunit/blob/6c0056bed585927c76c3a22c0f482adb48b0fde2/site/examples/todo/js/lib/canjs/can.jquery.js#L3461-L3516
18,375
bitovi/funcunit
site/examples/todo/js/lib/canjs/can.jquery.js
function (val) { // create the fragment, but don't hook it up // we need to insert it into the document first var frag = can.view.frag(val, parentNode), // keep a reference to each node newNodes = can.makeArray(frag.childNodes), last = nodes ? nodes[nodes.length - 1] : span; // Insert it in the `document` or `documentFragment` if (last.nextSibling) { last.parentNode.insertBefore(frag, last.nextSibling); } else { last.parentNode.appendChild(frag); } // nodes hasn't been set yet if (!nodes) { can.remove(can.$(span)); nodes = newNodes; // set the teardown nodeList nodeList = nodes; can.view.registerNode(nodes); } else { // Update node Array's to point to new nodes // and then remove the old nodes. // It has to be in this order for Mootools // and IE because somehow, after an element // is removed from the DOM, it loses its // expando values. var nodesToRemove = can.makeArray(nodes); can.view.replace(nodes, newNodes); can.remove(can.$(nodesToRemove)); } }
javascript
function (val) { // create the fragment, but don't hook it up // we need to insert it into the document first var frag = can.view.frag(val, parentNode), // keep a reference to each node newNodes = can.makeArray(frag.childNodes), last = nodes ? nodes[nodes.length - 1] : span; // Insert it in the `document` or `documentFragment` if (last.nextSibling) { last.parentNode.insertBefore(frag, last.nextSibling); } else { last.parentNode.appendChild(frag); } // nodes hasn't been set yet if (!nodes) { can.remove(can.$(span)); nodes = newNodes; // set the teardown nodeList nodeList = nodes; can.view.registerNode(nodes); } else { // Update node Array's to point to new nodes // and then remove the old nodes. // It has to be in this order for Mootools // and IE because somehow, after an element // is removed from the DOM, it loses its // expando values. var nodesToRemove = can.makeArray(nodes); can.view.replace(nodes, newNodes); can.remove(can.$(nodesToRemove)); } }
[ "function", "(", "val", ")", "{", "// create the fragment, but don't hook it up", "// we need to insert it into the document first", "var", "frag", "=", "can", ".", "view", ".", "frag", "(", "val", ",", "parentNode", ")", ",", "// keep a reference to each node", "newNodes", "=", "can", ".", "makeArray", "(", "frag", ".", "childNodes", ")", ",", "last", "=", "nodes", "?", "nodes", "[", "nodes", ".", "length", "-", "1", "]", ":", "span", ";", "// Insert it in the `document` or `documentFragment`", "if", "(", "last", ".", "nextSibling", ")", "{", "last", ".", "parentNode", ".", "insertBefore", "(", "frag", ",", "last", ".", "nextSibling", ")", ";", "}", "else", "{", "last", ".", "parentNode", ".", "appendChild", "(", "frag", ")", ";", "}", "// nodes hasn't been set yet", "if", "(", "!", "nodes", ")", "{", "can", ".", "remove", "(", "can", ".", "$", "(", "span", ")", ")", ";", "nodes", "=", "newNodes", ";", "// set the teardown nodeList", "nodeList", "=", "nodes", ";", "can", ".", "view", ".", "registerNode", "(", "nodes", ")", ";", "}", "else", "{", "// Update node Array's to point to new nodes", "// and then remove the old nodes.", "// It has to be in this order for Mootools", "// and IE because somehow, after an element", "// is removed from the DOM, it loses its", "// expando values.", "var", "nodesToRemove", "=", "can", ".", "makeArray", "(", "nodes", ")", ";", "can", ".", "view", ".", "replace", "(", "nodes", ",", "newNodes", ")", ";", "can", ".", "remove", "(", "can", ".", "$", "(", "nodesToRemove", ")", ")", ";", "}", "}" ]
A helper function to manage inserting the contents and removing the old contents
[ "A", "helper", "function", "to", "manage", "inserting", "the", "contents", "and", "removing", "the", "old", "contents" ]
6c0056bed585927c76c3a22c0f482adb48b0fde2
https://github.com/bitovi/funcunit/blob/6c0056bed585927c76c3a22c0f482adb48b0fde2/site/examples/todo/js/lib/canjs/can.jquery.js#L3477-L3509
18,376
deseretdigital/dayzed
src/utils.js
getStartDate
function getStartDate(date, minDate, maxDate) { let startDate = startOfDay(date); if (minDate) { const minDateNormalized = startOfDay(minDate); if (isBefore(startDate, minDateNormalized)) { startDate = minDateNormalized; } } if (maxDate) { const maxDateNormalized = startOfDay(maxDate); if (isBefore(maxDateNormalized, startDate)) { startDate = maxDateNormalized; } } return startDate; }
javascript
function getStartDate(date, minDate, maxDate) { let startDate = startOfDay(date); if (minDate) { const minDateNormalized = startOfDay(minDate); if (isBefore(startDate, minDateNormalized)) { startDate = minDateNormalized; } } if (maxDate) { const maxDateNormalized = startOfDay(maxDate); if (isBefore(maxDateNormalized, startDate)) { startDate = maxDateNormalized; } } return startDate; }
[ "function", "getStartDate", "(", "date", ",", "minDate", ",", "maxDate", ")", "{", "let", "startDate", "=", "startOfDay", "(", "date", ")", ";", "if", "(", "minDate", ")", "{", "const", "minDateNormalized", "=", "startOfDay", "(", "minDate", ")", ";", "if", "(", "isBefore", "(", "startDate", ",", "minDateNormalized", ")", ")", "{", "startDate", "=", "minDateNormalized", ";", "}", "}", "if", "(", "maxDate", ")", "{", "const", "maxDateNormalized", "=", "startOfDay", "(", "maxDate", ")", ";", "if", "(", "isBefore", "(", "maxDateNormalized", ",", "startDate", ")", ")", "{", "startDate", "=", "maxDateNormalized", ";", "}", "}", "return", "startDate", ";", "}" ]
Figures out the actual start date based on the min and max dates available. @param {Date} date The we want to start the calendar at @param {Date} minDate The earliest date available to start at @param {Date} maxDate The latest date available to start at @returns {Date} The actual start date
[ "Figures", "out", "the", "actual", "start", "date", "based", "on", "the", "min", "and", "max", "dates", "available", "." ]
93499eb6d9434219d6f0697bb8c8a99bde704109
https://github.com/deseretdigital/dayzed/blob/93499eb6d9434219d6f0697bb8c8a99bde704109/src/utils.js#L174-L189
18,377
deseretdigital/dayzed
src/utils.js
fillFrontWeek
function fillFrontWeek({ firstDayOfMonth, minDate, maxDate, selectedDates, firstDayOfWeek, showOutsideDays }) { const dates = []; let firstDay = (firstDayOfMonth.getDay() + 7 - firstDayOfWeek) % 7; if (showOutsideDays) { const lastDayOfPrevMonth = addDays(firstDayOfMonth, -1); const prevDate = lastDayOfPrevMonth.getDate(); const prevDateMonth = lastDayOfPrevMonth.getMonth(); const prevDateYear = lastDayOfPrevMonth.getFullYear(); // Fill out front week for days from // preceding month with dates from previous month. let counter = 0; while (counter < firstDay) { const date = new Date(prevDateYear, prevDateMonth, prevDate - counter); const dateObj = { date, selected: isSelected(selectedDates, date), selectable: isSelectable(minDate, maxDate, date), today: false, prevMonth: true, nextMonth: false }; dates.unshift(dateObj); counter++; } } else { // Fill out front week for days from // preceding month with buffer. while (firstDay > 0) { dates.unshift(''); firstDay--; } } return dates; }
javascript
function fillFrontWeek({ firstDayOfMonth, minDate, maxDate, selectedDates, firstDayOfWeek, showOutsideDays }) { const dates = []; let firstDay = (firstDayOfMonth.getDay() + 7 - firstDayOfWeek) % 7; if (showOutsideDays) { const lastDayOfPrevMonth = addDays(firstDayOfMonth, -1); const prevDate = lastDayOfPrevMonth.getDate(); const prevDateMonth = lastDayOfPrevMonth.getMonth(); const prevDateYear = lastDayOfPrevMonth.getFullYear(); // Fill out front week for days from // preceding month with dates from previous month. let counter = 0; while (counter < firstDay) { const date = new Date(prevDateYear, prevDateMonth, prevDate - counter); const dateObj = { date, selected: isSelected(selectedDates, date), selectable: isSelectable(minDate, maxDate, date), today: false, prevMonth: true, nextMonth: false }; dates.unshift(dateObj); counter++; } } else { // Fill out front week for days from // preceding month with buffer. while (firstDay > 0) { dates.unshift(''); firstDay--; } } return dates; }
[ "function", "fillFrontWeek", "(", "{", "firstDayOfMonth", ",", "minDate", ",", "maxDate", ",", "selectedDates", ",", "firstDayOfWeek", ",", "showOutsideDays", "}", ")", "{", "const", "dates", "=", "[", "]", ";", "let", "firstDay", "=", "(", "firstDayOfMonth", ".", "getDay", "(", ")", "+", "7", "-", "firstDayOfWeek", ")", "%", "7", ";", "if", "(", "showOutsideDays", ")", "{", "const", "lastDayOfPrevMonth", "=", "addDays", "(", "firstDayOfMonth", ",", "-", "1", ")", ";", "const", "prevDate", "=", "lastDayOfPrevMonth", ".", "getDate", "(", ")", ";", "const", "prevDateMonth", "=", "lastDayOfPrevMonth", ".", "getMonth", "(", ")", ";", "const", "prevDateYear", "=", "lastDayOfPrevMonth", ".", "getFullYear", "(", ")", ";", "// Fill out front week for days from", "// preceding month with dates from previous month.", "let", "counter", "=", "0", ";", "while", "(", "counter", "<", "firstDay", ")", "{", "const", "date", "=", "new", "Date", "(", "prevDateYear", ",", "prevDateMonth", ",", "prevDate", "-", "counter", ")", ";", "const", "dateObj", "=", "{", "date", ",", "selected", ":", "isSelected", "(", "selectedDates", ",", "date", ")", ",", "selectable", ":", "isSelectable", "(", "minDate", ",", "maxDate", ",", "date", ")", ",", "today", ":", "false", ",", "prevMonth", ":", "true", ",", "nextMonth", ":", "false", "}", ";", "dates", ".", "unshift", "(", "dateObj", ")", ";", "counter", "++", ";", "}", "}", "else", "{", "// Fill out front week for days from", "// preceding month with buffer.", "while", "(", "firstDay", ">", "0", ")", "{", "dates", ".", "unshift", "(", "''", ")", ";", "firstDay", "--", ";", "}", "}", "return", "dates", ";", "}" ]
Fill front week with either empty buffer or dates from previous month, depending on showOutsideDays flag @param {Object} param The param object @param {Array.<Date>} param.selectedDates An array of dates currently selected @param {Date} param.minDate The earliest date available @param {Date} param.maxDate The furthest date available @param {Date} param.firstDayOfMonth First day of the month @param {Number} param.firstDayOfWeek First day of week, 0-6 (Sunday to Saturday) @param {Bool} param.showOutsideDays Flag to fill front and back weeks with dates from adjacent months @returns {Array.<Date>} Buffer to fill front week
[ "Fill", "front", "week", "with", "either", "empty", "buffer", "or", "dates", "from", "previous", "month", "depending", "on", "showOutsideDays", "flag" ]
93499eb6d9434219d6f0697bb8c8a99bde704109
https://github.com/deseretdigital/dayzed/blob/93499eb6d9434219d6f0697bb8c8a99bde704109/src/utils.js#L284-L327
18,378
deseretdigital/dayzed
src/utils.js
fillBackWeek
function fillBackWeek({ lastDayOfMonth, minDate, maxDate, selectedDates, firstDayOfWeek, showOutsideDays }) { const dates = []; let lastDay = (lastDayOfMonth.getDay() + 7 - firstDayOfWeek) % 7; if (showOutsideDays) { const firstDayOfNextMonth = addDays(lastDayOfMonth, 1); const nextDateMonth = firstDayOfNextMonth.getMonth(); const nextDateYear = firstDayOfNextMonth.getFullYear(); // Fill out back week for days from // following month with dates from next month. let counter = 0; while (counter < 6 - lastDay) { const date = new Date(nextDateYear, nextDateMonth, 1 + counter); const dateObj = { date, selected: isSelected(selectedDates, date), selectable: isSelectable(minDate, maxDate, date), today: false, prevMonth: false, nextMonth: true }; dates.push(dateObj); counter++; } } else { // Fill out back week for days from // following month with buffer. while (lastDay < 6) { dates.push(''); lastDay++; } } return dates; }
javascript
function fillBackWeek({ lastDayOfMonth, minDate, maxDate, selectedDates, firstDayOfWeek, showOutsideDays }) { const dates = []; let lastDay = (lastDayOfMonth.getDay() + 7 - firstDayOfWeek) % 7; if (showOutsideDays) { const firstDayOfNextMonth = addDays(lastDayOfMonth, 1); const nextDateMonth = firstDayOfNextMonth.getMonth(); const nextDateYear = firstDayOfNextMonth.getFullYear(); // Fill out back week for days from // following month with dates from next month. let counter = 0; while (counter < 6 - lastDay) { const date = new Date(nextDateYear, nextDateMonth, 1 + counter); const dateObj = { date, selected: isSelected(selectedDates, date), selectable: isSelectable(minDate, maxDate, date), today: false, prevMonth: false, nextMonth: true }; dates.push(dateObj); counter++; } } else { // Fill out back week for days from // following month with buffer. while (lastDay < 6) { dates.push(''); lastDay++; } } return dates; }
[ "function", "fillBackWeek", "(", "{", "lastDayOfMonth", ",", "minDate", ",", "maxDate", ",", "selectedDates", ",", "firstDayOfWeek", ",", "showOutsideDays", "}", ")", "{", "const", "dates", "=", "[", "]", ";", "let", "lastDay", "=", "(", "lastDayOfMonth", ".", "getDay", "(", ")", "+", "7", "-", "firstDayOfWeek", ")", "%", "7", ";", "if", "(", "showOutsideDays", ")", "{", "const", "firstDayOfNextMonth", "=", "addDays", "(", "lastDayOfMonth", ",", "1", ")", ";", "const", "nextDateMonth", "=", "firstDayOfNextMonth", ".", "getMonth", "(", ")", ";", "const", "nextDateYear", "=", "firstDayOfNextMonth", ".", "getFullYear", "(", ")", ";", "// Fill out back week for days from", "// following month with dates from next month.", "let", "counter", "=", "0", ";", "while", "(", "counter", "<", "6", "-", "lastDay", ")", "{", "const", "date", "=", "new", "Date", "(", "nextDateYear", ",", "nextDateMonth", ",", "1", "+", "counter", ")", ";", "const", "dateObj", "=", "{", "date", ",", "selected", ":", "isSelected", "(", "selectedDates", ",", "date", ")", ",", "selectable", ":", "isSelectable", "(", "minDate", ",", "maxDate", ",", "date", ")", ",", "today", ":", "false", ",", "prevMonth", ":", "false", ",", "nextMonth", ":", "true", "}", ";", "dates", ".", "push", "(", "dateObj", ")", ";", "counter", "++", ";", "}", "}", "else", "{", "// Fill out back week for days from", "// following month with buffer.", "while", "(", "lastDay", "<", "6", ")", "{", "dates", ".", "push", "(", "''", ")", ";", "lastDay", "++", ";", "}", "}", "return", "dates", ";", "}" ]
Fill back weeks with either empty buffer or dates from next month, depending on showOutsideDays flag @param {Object} param The param object @param {Array.<Date>} param.selectedDates An array of dates currently selected @param {Date} param.minDate The earliest date available @param {Date} param.maxDate The furthest date available @param {Date} param.lastDayOfMonth Last day of the month @param {Number} param.firstDayOfWeek First day of week, 0-6 (Sunday to Saturday) @param {Bool} param.showOutsideDays Flag to fill front and back weeks with dates from adjacent months @returns {Array.<Date>} Buffer to fill back week
[ "Fill", "back", "weeks", "with", "either", "empty", "buffer", "or", "dates", "from", "next", "month", "depending", "on", "showOutsideDays", "flag" ]
93499eb6d9434219d6f0697bb8c8a99bde704109
https://github.com/deseretdigital/dayzed/blob/93499eb6d9434219d6f0697bb8c8a99bde704109/src/utils.js#L341-L383
18,379
deseretdigital/dayzed
src/utils.js
getWeeks
function getWeeks(dates) { const weeksLength = Math.ceil(dates.length / 7); const weeks = []; for (let i = 0; i < weeksLength; i++) { weeks[i] = []; for (let x = 0; x < 7; x++) { weeks[i].push(dates[i * 7 + x]); } } return weeks; }
javascript
function getWeeks(dates) { const weeksLength = Math.ceil(dates.length / 7); const weeks = []; for (let i = 0; i < weeksLength; i++) { weeks[i] = []; for (let x = 0; x < 7; x++) { weeks[i].push(dates[i * 7 + x]); } } return weeks; }
[ "function", "getWeeks", "(", "dates", ")", "{", "const", "weeksLength", "=", "Math", ".", "ceil", "(", "dates", ".", "length", "/", "7", ")", ";", "const", "weeks", "=", "[", "]", ";", "for", "(", "let", "i", "=", "0", ";", "i", "<", "weeksLength", ";", "i", "++", ")", "{", "weeks", "[", "i", "]", "=", "[", "]", ";", "for", "(", "let", "x", "=", "0", ";", "x", "<", "7", ";", "x", "++", ")", "{", "weeks", "[", "i", "]", ".", "push", "(", "dates", "[", "i", "*", "7", "+", "x", "]", ")", ";", "}", "}", "return", "weeks", ";", "}" ]
Takes an array of dates, and turns them into a multi dimensional array with 7 entries for each week. @param {Array.<Object>} dates An array of dates @returns {Array} The weeks as a multi dimensional array
[ "Takes", "an", "array", "of", "dates", "and", "turns", "them", "into", "a", "multi", "dimensional", "array", "with", "7", "entries", "for", "each", "week", "." ]
93499eb6d9434219d6f0697bb8c8a99bde704109
https://github.com/deseretdigital/dayzed/blob/93499eb6d9434219d6f0697bb8c8a99bde704109/src/utils.js#L416-L426
18,380
deseretdigital/dayzed
src/utils.js
isSelected
function isSelected(selectedDates, date) { selectedDates = Array.isArray(selectedDates) ? selectedDates : [selectedDates]; return selectedDates.some(selectedDate => { if ( selectedDate instanceof Date && startOfDay(selectedDate).getTime() === startOfDay(date).getTime() ) { return true; } return false; }); }
javascript
function isSelected(selectedDates, date) { selectedDates = Array.isArray(selectedDates) ? selectedDates : [selectedDates]; return selectedDates.some(selectedDate => { if ( selectedDate instanceof Date && startOfDay(selectedDate).getTime() === startOfDay(date).getTime() ) { return true; } return false; }); }
[ "function", "isSelected", "(", "selectedDates", ",", "date", ")", "{", "selectedDates", "=", "Array", ".", "isArray", "(", "selectedDates", ")", "?", "selectedDates", ":", "[", "selectedDates", "]", ";", "return", "selectedDates", ".", "some", "(", "selectedDate", "=>", "{", "if", "(", "selectedDate", "instanceof", "Date", "&&", "startOfDay", "(", "selectedDate", ")", ".", "getTime", "(", ")", "===", "startOfDay", "(", "date", ")", ".", "getTime", "(", ")", ")", "{", "return", "true", ";", "}", "return", "false", ";", "}", ")", ";", "}" ]
Normalizes dates to the beginning of the day, then checks to see if the day given is found in the selectedDates. @param {Array.<Date>} selectedDates An array of dates currently selected @param {Date} date The date to search with against selectedDates @returns {Boolean} Whether day is found in selectedDates
[ "Normalizes", "dates", "to", "the", "beginning", "of", "the", "day", "then", "checks", "to", "see", "if", "the", "day", "given", "is", "found", "in", "the", "selectedDates", "." ]
93499eb6d9434219d6f0697bb8c8a99bde704109
https://github.com/deseretdigital/dayzed/blob/93499eb6d9434219d6f0697bb8c8a99bde704109/src/utils.js#L436-L449
18,381
deseretdigital/dayzed
src/utils.js
isSelectable
function isSelectable(minDate, maxDate, date) { if ( (minDate && isBefore(date, minDate)) || (maxDate && isBefore(maxDate, date)) ) { return false; } return true; }
javascript
function isSelectable(minDate, maxDate, date) { if ( (minDate && isBefore(date, minDate)) || (maxDate && isBefore(maxDate, date)) ) { return false; } return true; }
[ "function", "isSelectable", "(", "minDate", ",", "maxDate", ",", "date", ")", "{", "if", "(", "(", "minDate", "&&", "isBefore", "(", "date", ",", "minDate", ")", ")", "||", "(", "maxDate", "&&", "isBefore", "(", "maxDate", ",", "date", ")", ")", ")", "{", "return", "false", ";", "}", "return", "true", ";", "}" ]
Checks to see if the date given is between the min and max dates. @param {Date} minDate The earliest date available @param {Date} maxDate The furthest date available @param {Date} date The date to compare with @returns {Boolean} Whether the date is between min and max date
[ "Checks", "to", "see", "if", "the", "date", "given", "is", "between", "the", "min", "and", "max", "dates", "." ]
93499eb6d9434219d6f0697bb8c8a99bde704109
https://github.com/deseretdigital/dayzed/blob/93499eb6d9434219d6f0697bb8c8a99bde704109/src/utils.js#L459-L467
18,382
taromero/swal-forms
swal-forms.js
extendPreventingOverrides
function extendPreventingOverrides (a, b) { Object.keys(b).forEach(addContentFromBtoA) return a function addContentFromBtoA (key) { if (a.hasOwnProperty(key)) { mergeIntoAnArray(a, b, key) } else { a[key] = b[key] } } }
javascript
function extendPreventingOverrides (a, b) { Object.keys(b).forEach(addContentFromBtoA) return a function addContentFromBtoA (key) { if (a.hasOwnProperty(key)) { mergeIntoAnArray(a, b, key) } else { a[key] = b[key] } } }
[ "function", "extendPreventingOverrides", "(", "a", ",", "b", ")", "{", "Object", ".", "keys", "(", "b", ")", ".", "forEach", "(", "addContentFromBtoA", ")", "return", "a", "function", "addContentFromBtoA", "(", "key", ")", "{", "if", "(", "a", ".", "hasOwnProperty", "(", "key", ")", ")", "{", "mergeIntoAnArray", "(", "a", ",", "b", ",", "key", ")", "}", "else", "{", "a", "[", "key", "]", "=", "b", "[", "key", "]", "}", "}", "}" ]
for checkboxes we want to obtain all selected values in an array
[ "for", "checkboxes", "we", "want", "to", "obtain", "all", "selected", "values", "in", "an", "array" ]
8095f1f89d60eedf0c24dc6850b65f32116925e7
https://github.com/taromero/swal-forms/blob/8095f1f89d60eedf0c24dc6850b65f32116925e7/swal-forms.js#L91-L102
18,383
taromero/swal-forms
swal-forms.js
t
function t (template, data) { for (var key in data) { template = template.replace(new RegExp('{' + key + '}', 'g'), data[key] || '') } return template }
javascript
function t (template, data) { for (var key in data) { template = template.replace(new RegExp('{' + key + '}', 'g'), data[key] || '') } return template }
[ "function", "t", "(", "template", ",", "data", ")", "{", "for", "(", "var", "key", "in", "data", ")", "{", "template", "=", "template", ".", "replace", "(", "new", "RegExp", "(", "'{'", "+", "key", "+", "'}'", ",", "'g'", ")", ",", "data", "[", "key", "]", "||", "''", ")", "}", "return", "template", "}" ]
string interpolation hack
[ "string", "interpolation", "hack" ]
8095f1f89d60eedf0c24dc6850b65f32116925e7
https://github.com/taromero/swal-forms/blob/8095f1f89d60eedf0c24dc6850b65f32116925e7/swal-forms.js#L230-L235
18,384
kentcdodds/rtl-css-js
src/internal/utils.js
getValuesAsList
function getValuesAsList(value) { return ( value .replace(/ +/g, ' ') // remove all extraneous spaces .split(' ') .map(i => i.trim()) // get rid of extra space before/after each item .filter(Boolean) // get rid of empty strings // join items which are within parenthese // luckily `calc (100% - 5px)` is invalid syntax and it must be `calc(100% - 5px)`, otherwise this would be even more complex .reduce( ({list, state}, item) => { const openParansCount = (item.match(/\(/g) || []).length const closedParansCount = (item.match(/\)/g) || []).length if (state.parensDepth > 0) { list[list.length - 1] = `${list[list.length - 1]} ${item}` } else { list.push(item) } state.parensDepth += openParansCount - closedParansCount return {list, state} }, {list: [], state: {parensDepth: 0}}, ).list ) }
javascript
function getValuesAsList(value) { return ( value .replace(/ +/g, ' ') // remove all extraneous spaces .split(' ') .map(i => i.trim()) // get rid of extra space before/after each item .filter(Boolean) // get rid of empty strings // join items which are within parenthese // luckily `calc (100% - 5px)` is invalid syntax and it must be `calc(100% - 5px)`, otherwise this would be even more complex .reduce( ({list, state}, item) => { const openParansCount = (item.match(/\(/g) || []).length const closedParansCount = (item.match(/\)/g) || []).length if (state.parensDepth > 0) { list[list.length - 1] = `${list[list.length - 1]} ${item}` } else { list.push(item) } state.parensDepth += openParansCount - closedParansCount return {list, state} }, {list: [], state: {parensDepth: 0}}, ).list ) }
[ "function", "getValuesAsList", "(", "value", ")", "{", "return", "(", "value", ".", "replace", "(", "/", " +", "/", "g", ",", "' '", ")", "// remove all extraneous spaces", ".", "split", "(", "' '", ")", ".", "map", "(", "i", "=>", "i", ".", "trim", "(", ")", ")", "// get rid of extra space before/after each item", ".", "filter", "(", "Boolean", ")", "// get rid of empty strings", "// join items which are within parenthese", "// luckily `calc (100% - 5px)` is invalid syntax and it must be `calc(100% - 5px)`, otherwise this would be even more complex", ".", "reduce", "(", "(", "{", "list", ",", "state", "}", ",", "item", ")", "=>", "{", "const", "openParansCount", "=", "(", "item", ".", "match", "(", "/", "\\(", "/", "g", ")", "||", "[", "]", ")", ".", "length", "const", "closedParansCount", "=", "(", "item", ".", "match", "(", "/", "\\)", "/", "g", ")", "||", "[", "]", ")", ".", "length", "if", "(", "state", ".", "parensDepth", ">", "0", ")", "{", "list", "[", "list", ".", "length", "-", "1", "]", "=", "`", "${", "list", "[", "list", ".", "length", "-", "1", "]", "}", "${", "item", "}", "`", "}", "else", "{", "list", ".", "push", "(", "item", ")", "}", "state", ".", "parensDepth", "+=", "openParansCount", "-", "closedParansCount", "return", "{", "list", ",", "state", "}", "}", ",", "{", "list", ":", "[", "]", ",", "state", ":", "{", "parensDepth", ":", "0", "}", "}", ",", ")", ".", "list", ")", "}" ]
This takes a list of CSS values and converts it to an array @param {String} value - something like `1px`, `1px 2em`, or `3pt rgb(150, 230, 550) 40px calc(100% - 5px)` @return {Array} the split values (for example: `['3pt', 'rgb(150, 230, 550)', '40px', 'calc(100% - 5px)']`)
[ "This", "takes", "a", "list", "of", "CSS", "values", "and", "converts", "it", "to", "an", "array" ]
b148865ce6a4c994eba292015b8f44b5dae7edaa
https://github.com/kentcdodds/rtl-css-js/blob/b148865ce6a4c994eba292015b8f44b5dae7edaa/src/internal/utils.js#L89-L113
18,385
kentcdodds/rtl-css-js
src/internal/utils.js
handleQuartetValues
function handleQuartetValues(value) { const splitValues = getValuesAsList(value) if (splitValues.length <= 3 || splitValues.length > 4) { return value } const [top, right, bottom, left] = splitValues return [top, left, bottom, right].join(' ') }
javascript
function handleQuartetValues(value) { const splitValues = getValuesAsList(value) if (splitValues.length <= 3 || splitValues.length > 4) { return value } const [top, right, bottom, left] = splitValues return [top, left, bottom, right].join(' ') }
[ "function", "handleQuartetValues", "(", "value", ")", "{", "const", "splitValues", "=", "getValuesAsList", "(", "value", ")", "if", "(", "splitValues", ".", "length", "<=", "3", "||", "splitValues", ".", "length", ">", "4", ")", "{", "return", "value", "}", "const", "[", "top", ",", "right", ",", "bottom", ",", "left", "]", "=", "splitValues", "return", "[", "top", ",", "left", ",", "bottom", ",", "right", "]", ".", "join", "(", "' '", ")", "}" ]
This is intended for properties that are `top right bottom left` and will switch them to `top left bottom right` @param {String} value - `1px 2px 3px 4px` for example, but also handles cases where there are too few/too many and simply returns the value in those cases (which is the correct behavior) @return {String} the result - `1px 4px 3px 2px` for example.
[ "This", "is", "intended", "for", "properties", "that", "are", "top", "right", "bottom", "left", "and", "will", "switch", "them", "to", "top", "left", "bottom", "right" ]
b148865ce6a4c994eba292015b8f44b5dae7edaa
https://github.com/kentcdodds/rtl-css-js/blob/b148865ce6a4c994eba292015b8f44b5dae7edaa/src/internal/utils.js#L121-L128
18,386
kentcdodds/rtl-css-js
src/index.js
convert
function convert(object) { return Object.keys(object).reduce((newObj, originalKey) => { let originalValue = object[originalKey] if (isString(originalValue)) { // you're welcome to later code 😺 originalValue = originalValue.trim() } // Some properties should never be transformed if (includes(propsToIgnore, originalKey)) { newObj[originalKey] = originalValue return newObj } const {key, value} = convertProperty(originalKey, originalValue) newObj[key] = value return newObj }, Array.isArray(object) ? [] : {}) }
javascript
function convert(object) { return Object.keys(object).reduce((newObj, originalKey) => { let originalValue = object[originalKey] if (isString(originalValue)) { // you're welcome to later code 😺 originalValue = originalValue.trim() } // Some properties should never be transformed if (includes(propsToIgnore, originalKey)) { newObj[originalKey] = originalValue return newObj } const {key, value} = convertProperty(originalKey, originalValue) newObj[key] = value return newObj }, Array.isArray(object) ? [] : {}) }
[ "function", "convert", "(", "object", ")", "{", "return", "Object", ".", "keys", "(", "object", ")", ".", "reduce", "(", "(", "newObj", ",", "originalKey", ")", "=>", "{", "let", "originalValue", "=", "object", "[", "originalKey", "]", "if", "(", "isString", "(", "originalValue", ")", ")", "{", "// you're welcome to later code 😺", "originalValue", "=", "originalValue", ".", "trim", "(", ")", "}", "// Some properties should never be transformed", "if", "(", "includes", "(", "propsToIgnore", ",", "originalKey", ")", ")", "{", "newObj", "[", "originalKey", "]", "=", "originalValue", "return", "newObj", "}", "const", "{", "key", ",", "value", "}", "=", "convertProperty", "(", "originalKey", ",", "originalValue", ")", "newObj", "[", "key", "]", "=", "value", "return", "newObj", "}", ",", "Array", ".", "isArray", "(", "object", ")", "?", "[", "]", ":", "{", "}", ")", "}" ]
converts properties and values in the CSS in JS object to their corresponding RTL values @param {Object} object the CSS in JS object @return {Object} the RTL converted object
[ "converts", "properties", "and", "values", "in", "the", "CSS", "in", "JS", "object", "to", "their", "corresponding", "RTL", "values" ]
b148865ce6a4c994eba292015b8f44b5dae7edaa
https://github.com/kentcdodds/rtl-css-js/blob/b148865ce6a4c994eba292015b8f44b5dae7edaa/src/index.js#L61-L79
18,387
kentcdodds/rtl-css-js
src/index.js
convertProperty
function convertProperty(originalKey, originalValue) { const isNoFlip = /\/\*\s?@noflip\s?\*\//.test(originalValue) const key = isNoFlip ? originalKey : getPropertyDoppelganger(originalKey) const value = isNoFlip ? originalValue : getValueDoppelganger(key, originalValue) return {key, value} }
javascript
function convertProperty(originalKey, originalValue) { const isNoFlip = /\/\*\s?@noflip\s?\*\//.test(originalValue) const key = isNoFlip ? originalKey : getPropertyDoppelganger(originalKey) const value = isNoFlip ? originalValue : getValueDoppelganger(key, originalValue) return {key, value} }
[ "function", "convertProperty", "(", "originalKey", ",", "originalValue", ")", "{", "const", "isNoFlip", "=", "/", "\\/\\*\\s?@noflip\\s?\\*\\/", "/", ".", "test", "(", "originalValue", ")", "const", "key", "=", "isNoFlip", "?", "originalKey", ":", "getPropertyDoppelganger", "(", "originalKey", ")", "const", "value", "=", "isNoFlip", "?", "originalValue", ":", "getValueDoppelganger", "(", "key", ",", "originalValue", ")", "return", "{", "key", ",", "value", "}", "}" ]
Converts a property and its value to the corresponding RTL key and value @param {String} originalKey the original property key @param {Number|String|Object} originalValue the original css property value @return {Object} the new {key, value} pair
[ "Converts", "a", "property", "and", "its", "value", "to", "the", "corresponding", "RTL", "key", "and", "value" ]
b148865ce6a4c994eba292015b8f44b5dae7edaa
https://github.com/kentcdodds/rtl-css-js/blob/b148865ce6a4c994eba292015b8f44b5dae7edaa/src/index.js#L87-L94
18,388
kentcdodds/rtl-css-js
src/index.js
getValueDoppelganger
function getValueDoppelganger(key, originalValue) { /* eslint complexity:[2, 9] */ // let's try to keep the complexity down... If we have to do this much more, let's break this up if (isNullOrUndefined(originalValue) || isBoolean(originalValue)) { return originalValue } if (isObject(originalValue)) { return convert(originalValue) // recurssion 🌀 } const isNum = isNumber(originalValue) const importantlessValue = isNum ? originalValue : originalValue.replace(/ !important.*?$/, '') const isImportant = !isNum && importantlessValue.length !== originalValue.length const valueConverter = propertyValueConverters[key] let newValue if (valueConverter) { newValue = valueConverter({ value: importantlessValue, valuesToConvert, isRtl: true, bgImgDirectionRegex, bgPosDirectionRegex, }) } else { newValue = valuesToConvert[importantlessValue] || importantlessValue } if (isImportant) { return `${newValue} !important` } return newValue }
javascript
function getValueDoppelganger(key, originalValue) { /* eslint complexity:[2, 9] */ // let's try to keep the complexity down... If we have to do this much more, let's break this up if (isNullOrUndefined(originalValue) || isBoolean(originalValue)) { return originalValue } if (isObject(originalValue)) { return convert(originalValue) // recurssion 🌀 } const isNum = isNumber(originalValue) const importantlessValue = isNum ? originalValue : originalValue.replace(/ !important.*?$/, '') const isImportant = !isNum && importantlessValue.length !== originalValue.length const valueConverter = propertyValueConverters[key] let newValue if (valueConverter) { newValue = valueConverter({ value: importantlessValue, valuesToConvert, isRtl: true, bgImgDirectionRegex, bgPosDirectionRegex, }) } else { newValue = valuesToConvert[importantlessValue] || importantlessValue } if (isImportant) { return `${newValue} !important` } return newValue }
[ "function", "getValueDoppelganger", "(", "key", ",", "originalValue", ")", "{", "/* eslint complexity:[2, 9] */", "// let's try to keep the complexity down... If we have to do this much more, let's break this up", "if", "(", "isNullOrUndefined", "(", "originalValue", ")", "||", "isBoolean", "(", "originalValue", ")", ")", "{", "return", "originalValue", "}", "if", "(", "isObject", "(", "originalValue", ")", ")", "{", "return", "convert", "(", "originalValue", ")", "// recurssion 🌀", "}", "const", "isNum", "=", "isNumber", "(", "originalValue", ")", "const", "importantlessValue", "=", "isNum", "?", "originalValue", ":", "originalValue", ".", "replace", "(", "/", " !important.*?$", "/", ",", "''", ")", "const", "isImportant", "=", "!", "isNum", "&&", "importantlessValue", ".", "length", "!==", "originalValue", ".", "length", "const", "valueConverter", "=", "propertyValueConverters", "[", "key", "]", "let", "newValue", "if", "(", "valueConverter", ")", "{", "newValue", "=", "valueConverter", "(", "{", "value", ":", "importantlessValue", ",", "valuesToConvert", ",", "isRtl", ":", "true", ",", "bgImgDirectionRegex", ",", "bgPosDirectionRegex", ",", "}", ")", "}", "else", "{", "newValue", "=", "valuesToConvert", "[", "importantlessValue", "]", "||", "importantlessValue", "}", "if", "(", "isImportant", ")", "{", "return", "`", "${", "newValue", "}", "`", "}", "return", "newValue", "}" ]
This converts the given value to the RTL version of that value based on the key @param {String} key this is the key (note: this should be the RTL version of the originalKey) @param {String|Number|Object} originalValue the original css property value. If it's an object, then we'll convert that as well @return {String|Number|Object} the converted value
[ "This", "converts", "the", "given", "value", "to", "the", "RTL", "version", "of", "that", "value", "based", "on", "the", "key" ]
b148865ce6a4c994eba292015b8f44b5dae7edaa
https://github.com/kentcdodds/rtl-css-js/blob/b148865ce6a4c994eba292015b8f44b5dae7edaa/src/index.js#L111-L143
18,389
chain/chain
docs/common/js/layout.js
selectOSTab
function selectOSTab(target, osName) { // Declare all variables var i, tabcontent, tablinks; // Get all elements with class="tabcontent" and hide them tabcontent = document.getElementsByClassName("tabcontent"); for (i = 0; i < tabcontent.length; i++) { tabcontent[i].style.display = "none"; } // Get all elements with class="tablinks" and remove the class "active" tablinks = document.getElementsByClassName("tablinks"); for (i = 0; i < tablinks.length; i++) { tablinks[i].className = tablinks[i].className.replace(" active", ""); } // Show the current tab, and add an "active" class to the link that opened the tab document.getElementById(osName).style.display = "block"; target.className += " active"; }
javascript
function selectOSTab(target, osName) { // Declare all variables var i, tabcontent, tablinks; // Get all elements with class="tabcontent" and hide them tabcontent = document.getElementsByClassName("tabcontent"); for (i = 0; i < tabcontent.length; i++) { tabcontent[i].style.display = "none"; } // Get all elements with class="tablinks" and remove the class "active" tablinks = document.getElementsByClassName("tablinks"); for (i = 0; i < tablinks.length; i++) { tablinks[i].className = tablinks[i].className.replace(" active", ""); } // Show the current tab, and add an "active" class to the link that opened the tab document.getElementById(osName).style.display = "block"; target.className += " active"; }
[ "function", "selectOSTab", "(", "target", ",", "osName", ")", "{", "// Declare all variables", "var", "i", ",", "tabcontent", ",", "tablinks", ";", "// Get all elements with class=\"tabcontent\" and hide them", "tabcontent", "=", "document", ".", "getElementsByClassName", "(", "\"tabcontent\"", ")", ";", "for", "(", "i", "=", "0", ";", "i", "<", "tabcontent", ".", "length", ";", "i", "++", ")", "{", "tabcontent", "[", "i", "]", ".", "style", ".", "display", "=", "\"none\"", ";", "}", "// Get all elements with class=\"tablinks\" and remove the class \"active\"", "tablinks", "=", "document", ".", "getElementsByClassName", "(", "\"tablinks\"", ")", ";", "for", "(", "i", "=", "0", ";", "i", "<", "tablinks", ".", "length", ";", "i", "++", ")", "{", "tablinks", "[", "i", "]", ".", "className", "=", "tablinks", "[", "i", "]", ".", "className", ".", "replace", "(", "\" active\"", ",", "\"\"", ")", ";", "}", "// Show the current tab, and add an \"active\" class to the link that opened the tab", "document", ".", "getElementById", "(", "osName", ")", ".", "style", ".", "display", "=", "\"block\"", ";", "target", ".", "className", "+=", "\" active\"", ";", "}" ]
switcher between the navtabs for operating systems
[ "switcher", "between", "the", "navtabs", "for", "operating", "systems" ]
4e9b90d76fe9a4c53adadf03cf8db96a0a5ff38c
https://github.com/chain/chain/blob/4e9b90d76fe9a4c53adadf03cf8db96a0a5ff38c/docs/common/js/layout.js#L104-L123
18,390
chain/chain
docs/common/js/layout.js
showSignUpForm
function showSignUpForm() { var modal = document.getElementById('downloadModal'); // Make sure modal is in the body, not where it was originally deployed. $("body").append($(modal)) // Get the button that opens the modal var btn = document.getElementById("downloadBtn"); // Get the <span> element that closes the modal var span = document.getElementsByClassName("close")[0]; // When the user clicks on the button, open the modal modal.style.display = "block"; // When the user clicks on <span> (x), close the modal span.onclick = function () { modal.style.display = "none"; } // When the user clicks anywhere outside of the modal, close it window.onclick = function (event) { if (event.target == modal) { modal.style.display = "none"; } } }
javascript
function showSignUpForm() { var modal = document.getElementById('downloadModal'); // Make sure modal is in the body, not where it was originally deployed. $("body").append($(modal)) // Get the button that opens the modal var btn = document.getElementById("downloadBtn"); // Get the <span> element that closes the modal var span = document.getElementsByClassName("close")[0]; // When the user clicks on the button, open the modal modal.style.display = "block"; // When the user clicks on <span> (x), close the modal span.onclick = function () { modal.style.display = "none"; } // When the user clicks anywhere outside of the modal, close it window.onclick = function (event) { if (event.target == modal) { modal.style.display = "none"; } } }
[ "function", "showSignUpForm", "(", ")", "{", "var", "modal", "=", "document", ".", "getElementById", "(", "'downloadModal'", ")", ";", "// Make sure modal is in the body, not where it was originally deployed.", "$", "(", "\"body\"", ")", ".", "append", "(", "$", "(", "modal", ")", ")", "// Get the button that opens the modal", "var", "btn", "=", "document", ".", "getElementById", "(", "\"downloadBtn\"", ")", ";", "// Get the <span> element that closes the modal", "var", "span", "=", "document", ".", "getElementsByClassName", "(", "\"close\"", ")", "[", "0", "]", ";", "// When the user clicks on the button, open the modal", "modal", ".", "style", ".", "display", "=", "\"block\"", ";", "// When the user clicks on <span> (x), close the modal", "span", ".", "onclick", "=", "function", "(", ")", "{", "modal", ".", "style", ".", "display", "=", "\"none\"", ";", "}", "// When the user clicks anywhere outside of the modal, close it", "window", ".", "onclick", "=", "function", "(", "event", ")", "{", "if", "(", "event", ".", "target", "==", "modal", ")", "{", "modal", ".", "style", ".", "display", "=", "\"none\"", ";", "}", "}", "}" ]
Modal to sign up for newsletter
[ "Modal", "to", "sign", "up", "for", "newsletter" ]
4e9b90d76fe9a4c53adadf03cf8db96a0a5ff38c
https://github.com/chain/chain/blob/4e9b90d76fe9a4c53adadf03cf8db96a0a5ff38c/docs/common/js/layout.js#L133-L159
18,391
atsepkov/RapydScript
tools/repl.js
global_names
function global_names(ctx, options) { try { var ans = vm.runInContext(options.enum_global, ctx); ans = ans.concat(all_keywords); ans.sort(); var seen = {}; ans.filter(function (item) { if (Object.prototype.hasOwnProperty.call(seen, item)) return false; seen[item] = true; return true; }); return ans; } catch(e) { console.log(e.stack || e.toString()); } return []; }
javascript
function global_names(ctx, options) { try { var ans = vm.runInContext(options.enum_global, ctx); ans = ans.concat(all_keywords); ans.sort(); var seen = {}; ans.filter(function (item) { if (Object.prototype.hasOwnProperty.call(seen, item)) return false; seen[item] = true; return true; }); return ans; } catch(e) { console.log(e.stack || e.toString()); } return []; }
[ "function", "global_names", "(", "ctx", ",", "options", ")", "{", "try", "{", "var", "ans", "=", "vm", ".", "runInContext", "(", "options", ".", "enum_global", ",", "ctx", ")", ";", "ans", "=", "ans", ".", "concat", "(", "all_keywords", ")", ";", "ans", ".", "sort", "(", ")", ";", "var", "seen", "=", "{", "}", ";", "ans", ".", "filter", "(", "function", "(", "item", ")", "{", "if", "(", "Object", ".", "prototype", ".", "hasOwnProperty", ".", "call", "(", "seen", ",", "item", ")", ")", "return", "false", ";", "seen", "[", "item", "]", "=", "true", ";", "return", "true", ";", "}", ")", ";", "return", "ans", ";", "}", "catch", "(", "e", ")", "{", "console", ".", "log", "(", "e", ".", "stack", "||", "e", ".", "toString", "(", ")", ")", ";", "}", "return", "[", "]", ";", "}" ]
tab-completion
[ "tab", "-", "completion" ]
ef3c03dab890eedb1eed9b5d427153743f55e919
https://github.com/atsepkov/RapydScript/blob/ef3c03dab890eedb1eed9b5d427153743f55e919/tools/repl.js#L95-L111
18,392
zhangxiang958/vue-tab
src/lib/demo.js
function(element, type, handler) { if(element.addEventListener) { addEvent = function(element, type, handler) { element.addEventListener(type, handler, false); }; } else if(element.attachEvent) { addEvent = function(element, type, handler) { element.attachEvent('on' + type, handler); }; } else { addEvent = function(element, type, handler) { element['on' + type] = handler; }; } addEvent(element, type, handler); }
javascript
function(element, type, handler) { if(element.addEventListener) { addEvent = function(element, type, handler) { element.addEventListener(type, handler, false); }; } else if(element.attachEvent) { addEvent = function(element, type, handler) { element.attachEvent('on' + type, handler); }; } else { addEvent = function(element, type, handler) { element['on' + type] = handler; }; } addEvent(element, type, handler); }
[ "function", "(", "element", ",", "type", ",", "handler", ")", "{", "if", "(", "element", ".", "addEventListener", ")", "{", "addEvent", "=", "function", "(", "element", ",", "type", ",", "handler", ")", "{", "element", ".", "addEventListener", "(", "type", ",", "handler", ",", "false", ")", ";", "}", ";", "}", "else", "if", "(", "element", ".", "attachEvent", ")", "{", "addEvent", "=", "function", "(", "element", ",", "type", ",", "handler", ")", "{", "element", ".", "attachEvent", "(", "'on'", "+", "type", ",", "handler", ")", ";", "}", ";", "}", "else", "{", "addEvent", "=", "function", "(", "element", ",", "type", ",", "handler", ")", "{", "element", "[", "'on'", "+", "type", "]", "=", "handler", ";", "}", ";", "}", "addEvent", "(", "element", ",", "type", ",", "handler", ")", ";", "}" ]
Cross-browser compatible event handler.
[ "Cross", "-", "browser", "compatible", "event", "handler", "." ]
8d54e04abbfe134ecc63ccc21872f45f165516e4
https://github.com/zhangxiang958/vue-tab/blob/8d54e04abbfe134ecc63ccc21872f45f165516e4/src/lib/demo.js#L28-L43
18,393
zhangxiang958/vue-tab
src/lib/demo.js
function(arr) { var key = 0; var min = arr[0]; for(var i = 1, len = arr.length; i < len; i++) { if(arr[i] < min) { key = i; min = arr[i]; } } return key; }
javascript
function(arr) { var key = 0; var min = arr[0]; for(var i = 1, len = arr.length; i < len; i++) { if(arr[i] < min) { key = i; min = arr[i]; } } return key; }
[ "function", "(", "arr", ")", "{", "var", "key", "=", "0", ";", "var", "min", "=", "arr", "[", "0", "]", ";", "for", "(", "var", "i", "=", "1", ",", "len", "=", "arr", ".", "length", ";", "i", "<", "len", ";", "i", "++", ")", "{", "if", "(", "arr", "[", "i", "]", "<", "min", ")", "{", "key", "=", "i", ";", "min", "=", "arr", "[", "i", "]", ";", "}", "}", "return", "key", ";", "}" ]
Get index of the minimal value within an array of numbers.
[ "Get", "index", "of", "the", "minimal", "value", "within", "an", "array", "of", "numbers", "." ]
8d54e04abbfe134ecc63ccc21872f45f165516e4
https://github.com/zhangxiang958/vue-tab/blob/8d54e04abbfe134ecc63ccc21872f45f165516e4/src/lib/demo.js#L56-L66
18,394
zhangxiang958/vue-tab
src/lib/demo.js
function(arr) { var key = 0; var max = arr[0]; for(var i = 1, len = arr.length; i < len; i++) { if(arr[i] > max) { key = i; max = arr[i]; } } return key; }
javascript
function(arr) { var key = 0; var max = arr[0]; for(var i = 1, len = arr.length; i < len; i++) { if(arr[i] > max) { key = i; max = arr[i]; } } return key; }
[ "function", "(", "arr", ")", "{", "var", "key", "=", "0", ";", "var", "max", "=", "arr", "[", "0", "]", ";", "for", "(", "var", "i", "=", "1", ",", "len", "=", "arr", ".", "length", ";", "i", "<", "len", ";", "i", "++", ")", "{", "if", "(", "arr", "[", "i", "]", ">", "max", ")", "{", "key", "=", "i", ";", "max", "=", "arr", "[", "i", "]", ";", "}", "}", "return", "key", ";", "}" ]
Get index of the maximal value within an array of numbers.
[ "Get", "index", "of", "the", "maximal", "value", "within", "an", "array", "of", "numbers", "." ]
8d54e04abbfe134ecc63ccc21872f45f165516e4
https://github.com/zhangxiang958/vue-tab/blob/8d54e04abbfe134ecc63ccc21872f45f165516e4/src/lib/demo.js#L69-L79
18,395
zhangxiang958/vue-tab
src/lib/demo.js
function(event) { clearTimeout(noticeDelay); var e = event || window.event; var target = e.target || e.srcElement; if(target.tagName == 'SPAN') { var targetTitle = target.parentNode.tagLine; noticeContainer.innerHTML = (target.className == 'like' ? 'Liked ' : 'Marked ') + '<strong>' + targetTitle + '</strong>'; noticeContainer.className = 'on'; noticeDelay = setTimeout(function() { noticeContainer.className = 'off'; }, 2000); } }
javascript
function(event) { clearTimeout(noticeDelay); var e = event || window.event; var target = e.target || e.srcElement; if(target.tagName == 'SPAN') { var targetTitle = target.parentNode.tagLine; noticeContainer.innerHTML = (target.className == 'like' ? 'Liked ' : 'Marked ') + '<strong>' + targetTitle + '</strong>'; noticeContainer.className = 'on'; noticeDelay = setTimeout(function() { noticeContainer.className = 'off'; }, 2000); } }
[ "function", "(", "event", ")", "{", "clearTimeout", "(", "noticeDelay", ")", ";", "var", "e", "=", "event", "||", "window", ".", "event", ";", "var", "target", "=", "e", ".", "target", "||", "e", ".", "srcElement", ";", "if", "(", "target", ".", "tagName", "==", "'SPAN'", ")", "{", "var", "targetTitle", "=", "target", ".", "parentNode", ".", "tagLine", ";", "noticeContainer", ".", "innerHTML", "=", "(", "target", ".", "className", "==", "'like'", "?", "'Liked '", ":", "'Marked '", ")", "+", "'<strong>'", "+", "targetTitle", "+", "'</strong>'", ";", "noticeContainer", ".", "className", "=", "'on'", ";", "noticeDelay", "=", "setTimeout", "(", "function", "(", ")", "{", "noticeContainer", ".", "className", "=", "'off'", ";", "}", ",", "2000", ")", ";", "}", "}" ]
Pop notice tag after user liked or marked an item.
[ "Pop", "notice", "tag", "after", "user", "liked", "or", "marked", "an", "item", "." ]
8d54e04abbfe134ecc63ccc21872f45f165516e4
https://github.com/zhangxiang958/vue-tab/blob/8d54e04abbfe134ecc63ccc21872f45f165516e4/src/lib/demo.js#L82-L94
18,396
zhangxiang958/vue-tab
src/lib/demo.js
function() { return Math.max(MIN_COLUMN_COUNT, Math.floor((document.body.offsetWidth + GAP_WIDTH) / (COLUMN_WIDTH + GAP_WIDTH))); }
javascript
function() { return Math.max(MIN_COLUMN_COUNT, Math.floor((document.body.offsetWidth + GAP_WIDTH) / (COLUMN_WIDTH + GAP_WIDTH))); }
[ "function", "(", ")", "{", "return", "Math", ".", "max", "(", "MIN_COLUMN_COUNT", ",", "Math", ".", "floor", "(", "(", "document", ".", "body", ".", "offsetWidth", "+", "GAP_WIDTH", ")", "/", "(", "COLUMN_WIDTH", "+", "GAP_WIDTH", ")", ")", ")", ";", "}" ]
Calculate column count from current page width.
[ "Calculate", "column", "count", "from", "current", "page", "width", "." ]
8d54e04abbfe134ecc63ccc21872f45f165516e4
https://github.com/zhangxiang958/vue-tab/blob/8d54e04abbfe134ecc63ccc21872f45f165516e4/src/lib/demo.js#L97-L99
18,397
zhangxiang958/vue-tab
src/lib/demo.js
function(count) { columnHeights = []; for(var i = 0; i < count; i++) { columnHeights.push(0); } cellsContainer.style.width = (count * (COLUMN_WIDTH + GAP_WIDTH) - GAP_WIDTH) + 'px'; }
javascript
function(count) { columnHeights = []; for(var i = 0; i < count; i++) { columnHeights.push(0); } cellsContainer.style.width = (count * (COLUMN_WIDTH + GAP_WIDTH) - GAP_WIDTH) + 'px'; }
[ "function", "(", "count", ")", "{", "columnHeights", "=", "[", "]", ";", "for", "(", "var", "i", "=", "0", ";", "i", "<", "count", ";", "i", "++", ")", "{", "columnHeights", ".", "push", "(", "0", ")", ";", "}", "cellsContainer", ".", "style", ".", "width", "=", "(", "count", "*", "(", "COLUMN_WIDTH", "+", "GAP_WIDTH", ")", "-", "GAP_WIDTH", ")", "+", "'px'", ";", "}" ]
Reset array of column heights and container width.
[ "Reset", "array", "of", "column", "heights", "and", "container", "width", "." ]
8d54e04abbfe134ecc63ccc21872f45f165516e4
https://github.com/zhangxiang958/vue-tab/blob/8d54e04abbfe134ecc63ccc21872f45f165516e4/src/lib/demo.js#L102-L108
18,398
zhangxiang958/vue-tab
src/lib/demo.js
function(num) { if(loading) { // Avoid sending too many requests to get new cells. return; } var xhrRequest = new XMLHttpRequest(); var fragment = document.createDocumentFragment(); var cells = []; var images; xhrRequest.open('GET', 'json.php?n=' + num, true); xhrRequest.onreadystatechange = function() { if(xhrRequest.readyState == 4 && xhrRequest.status == 200) { images = JSON.parse(xhrRequest.responseText); for(var j = 0, k = images.length; j < k; j++) { var cell = document.createElement('div'); cell.className = 'cell pending'; cell.tagLine = images[j].title; cells.push(cell); front(cellTemplate, images[j], cell); fragment.appendChild(cell); } cellsContainer.appendChild(fragment); loading = false; adjustCells(cells); } }; loading = true; xhrRequest.send(null); }
javascript
function(num) { if(loading) { // Avoid sending too many requests to get new cells. return; } var xhrRequest = new XMLHttpRequest(); var fragment = document.createDocumentFragment(); var cells = []; var images; xhrRequest.open('GET', 'json.php?n=' + num, true); xhrRequest.onreadystatechange = function() { if(xhrRequest.readyState == 4 && xhrRequest.status == 200) { images = JSON.parse(xhrRequest.responseText); for(var j = 0, k = images.length; j < k; j++) { var cell = document.createElement('div'); cell.className = 'cell pending'; cell.tagLine = images[j].title; cells.push(cell); front(cellTemplate, images[j], cell); fragment.appendChild(cell); } cellsContainer.appendChild(fragment); loading = false; adjustCells(cells); } }; loading = true; xhrRequest.send(null); }
[ "function", "(", "num", ")", "{", "if", "(", "loading", ")", "{", "// Avoid sending too many requests to get new cells.", "return", ";", "}", "var", "xhrRequest", "=", "new", "XMLHttpRequest", "(", ")", ";", "var", "fragment", "=", "document", ".", "createDocumentFragment", "(", ")", ";", "var", "cells", "=", "[", "]", ";", "var", "images", ";", "xhrRequest", ".", "open", "(", "'GET'", ",", "'json.php?n='", "+", "num", ",", "true", ")", ";", "xhrRequest", ".", "onreadystatechange", "=", "function", "(", ")", "{", "if", "(", "xhrRequest", ".", "readyState", "==", "4", "&&", "xhrRequest", ".", "status", "==", "200", ")", "{", "images", "=", "JSON", ".", "parse", "(", "xhrRequest", ".", "responseText", ")", ";", "for", "(", "var", "j", "=", "0", ",", "k", "=", "images", ".", "length", ";", "j", "<", "k", ";", "j", "++", ")", "{", "var", "cell", "=", "document", ".", "createElement", "(", "'div'", ")", ";", "cell", ".", "className", "=", "'cell pending'", ";", "cell", ".", "tagLine", "=", "images", "[", "j", "]", ".", "title", ";", "cells", ".", "push", "(", "cell", ")", ";", "front", "(", "cellTemplate", ",", "images", "[", "j", "]", ",", "cell", ")", ";", "fragment", ".", "appendChild", "(", "cell", ")", ";", "}", "cellsContainer", ".", "appendChild", "(", "fragment", ")", ";", "loading", "=", "false", ";", "adjustCells", "(", "cells", ")", ";", "}", "}", ";", "loading", "=", "true", ";", "xhrRequest", ".", "send", "(", "null", ")", ";", "}" ]
Fetch JSON string via Ajax, parse to HTML and append to the container.
[ "Fetch", "JSON", "string", "via", "Ajax", "parse", "to", "HTML", "and", "append", "to", "the", "container", "." ]
8d54e04abbfe134ecc63ccc21872f45f165516e4
https://github.com/zhangxiang958/vue-tab/blob/8d54e04abbfe134ecc63ccc21872f45f165516e4/src/lib/demo.js#L111-L139
18,399
zhangxiang958/vue-tab
src/lib/demo.js
function(num) { if(loading) { // Avoid sending too many requests to get new cells. return; } var fragment = document.createDocumentFragment(); var cells = []; var images = [0, 286, 143, 270, 143, 190, 285, 152, 275, 285, 285, 128, 281, 242, 339, 236, 157, 286, 259, 267, 137, 253, 127, 190, 190, 225, 269, 264, 272, 126, 265, 287, 269, 125, 285, 190, 314, 141, 119, 274, 274, 285, 126, 279, 143, 266, 279, 600, 276, 285, 182, 143, 287, 126, 190, 285, 143, 241, 166, 240, 190]; for(var j = 0; j < num; j++) { var key = Math.floor(Math.random() * 60) + 1; var cell = document.createElement('div'); cell.className = 'cell pending'; cell.tagLine = 'demo picture ' + key; cells.push(cell); front(cellTemplate, { 'title': 'demo picture ' + key, 'src': key, 'height': images[key], 'width': 190 }, cell); fragment.appendChild(cell); } // Faking network latency. setTimeout(function() { loading = false; cellsContainer.appendChild(fragment); adjustCells(cells); }, 2000); }
javascript
function(num) { if(loading) { // Avoid sending too many requests to get new cells. return; } var fragment = document.createDocumentFragment(); var cells = []; var images = [0, 286, 143, 270, 143, 190, 285, 152, 275, 285, 285, 128, 281, 242, 339, 236, 157, 286, 259, 267, 137, 253, 127, 190, 190, 225, 269, 264, 272, 126, 265, 287, 269, 125, 285, 190, 314, 141, 119, 274, 274, 285, 126, 279, 143, 266, 279, 600, 276, 285, 182, 143, 287, 126, 190, 285, 143, 241, 166, 240, 190]; for(var j = 0; j < num; j++) { var key = Math.floor(Math.random() * 60) + 1; var cell = document.createElement('div'); cell.className = 'cell pending'; cell.tagLine = 'demo picture ' + key; cells.push(cell); front(cellTemplate, { 'title': 'demo picture ' + key, 'src': key, 'height': images[key], 'width': 190 }, cell); fragment.appendChild(cell); } // Faking network latency. setTimeout(function() { loading = false; cellsContainer.appendChild(fragment); adjustCells(cells); }, 2000); }
[ "function", "(", "num", ")", "{", "if", "(", "loading", ")", "{", "// Avoid sending too many requests to get new cells.", "return", ";", "}", "var", "fragment", "=", "document", ".", "createDocumentFragment", "(", ")", ";", "var", "cells", "=", "[", "]", ";", "var", "images", "=", "[", "0", ",", "286", ",", "143", ",", "270", ",", "143", ",", "190", ",", "285", ",", "152", ",", "275", ",", "285", ",", "285", ",", "128", ",", "281", ",", "242", ",", "339", ",", "236", ",", "157", ",", "286", ",", "259", ",", "267", ",", "137", ",", "253", ",", "127", ",", "190", ",", "190", ",", "225", ",", "269", ",", "264", ",", "272", ",", "126", ",", "265", ",", "287", ",", "269", ",", "125", ",", "285", ",", "190", ",", "314", ",", "141", ",", "119", ",", "274", ",", "274", ",", "285", ",", "126", ",", "279", ",", "143", ",", "266", ",", "279", ",", "600", ",", "276", ",", "285", ",", "182", ",", "143", ",", "287", ",", "126", ",", "190", ",", "285", ",", "143", ",", "241", ",", "166", ",", "240", ",", "190", "]", ";", "for", "(", "var", "j", "=", "0", ";", "j", "<", "num", ";", "j", "++", ")", "{", "var", "key", "=", "Math", ".", "floor", "(", "Math", ".", "random", "(", ")", "*", "60", ")", "+", "1", ";", "var", "cell", "=", "document", ".", "createElement", "(", "'div'", ")", ";", "cell", ".", "className", "=", "'cell pending'", ";", "cell", ".", "tagLine", "=", "'demo picture '", "+", "key", ";", "cells", ".", "push", "(", "cell", ")", ";", "front", "(", "cellTemplate", ",", "{", "'title'", ":", "'demo picture '", "+", "key", ",", "'src'", ":", "key", ",", "'height'", ":", "images", "[", "key", "]", ",", "'width'", ":", "190", "}", ",", "cell", ")", ";", "fragment", ".", "appendChild", "(", "cell", ")", ";", "}", "// Faking network latency.", "setTimeout", "(", "function", "(", ")", "{", "loading", "=", "false", ";", "cellsContainer", ".", "appendChild", "(", "fragment", ")", ";", "adjustCells", "(", "cells", ")", ";", "}", ",", "2000", ")", ";", "}" ]
Fake mode, only for GitHub demo. Delete this function in your project.
[ "Fake", "mode", "only", "for", "GitHub", "demo", ".", "Delete", "this", "function", "in", "your", "project", "." ]
8d54e04abbfe134ecc63ccc21872f45f165516e4
https://github.com/zhangxiang958/vue-tab/blob/8d54e04abbfe134ecc63ccc21872f45f165516e4/src/lib/demo.js#L142-L165