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
47,800
vertical-knowledge/jsocrud
helpers.js
ValidatedPath
function ValidatedPath(path, firstPathPart, pathRemainder) { this.path = path; this.firstPathPart = firstPathPart; this.pathRemainder = pathRemainder; }
javascript
function ValidatedPath(path, firstPathPart, pathRemainder) { this.path = path; this.firstPathPart = firstPathPart; this.pathRemainder = pathRemainder; }
[ "function", "ValidatedPath", "(", "path", ",", "firstPathPart", ",", "pathRemainder", ")", "{", "this", ".", "path", "=", "path", ";", "this", ".", "firstPathPart", "=", "firstPathPart", ";", "this", ".", "pathRemainder", "=", "pathRemainder", ";", "}" ]
Storage for a validated path @param {String} path - Full validated path @param {String|Null} firstPathPart - "Converted" first path if necessary (see helpers::convertFirstPathPart) @param {String|Null} pathRemainder - "Converted" remainder of the path if necessary (see helpers::convertFirstPathPart) @constructor
[ "Storage", "for", "a", "validated", "path" ]
d8142df1e2c9404fe34162b35543622822938b33
https://github.com/vertical-knowledge/jsocrud/blob/d8142df1e2c9404fe34162b35543622822938b33/helpers.js#L10-L14
47,801
simbo/gulp-watchify-browserify
demo/gulpfile.js
streamHandler
function streamHandler(stream) { return stream .pipe(plumber()) .pipe(sourcemaps.init({loadMaps: true})) .pipe(sourcemaps.write('.', {includeContent: true, sourceRoot: '.'})) .pipe(gulp.dest(dest)); }
javascript
function streamHandler(stream) { return stream .pipe(plumber()) .pipe(sourcemaps.init({loadMaps: true})) .pipe(sourcemaps.write('.', {includeContent: true, sourceRoot: '.'})) .pipe(gulp.dest(dest)); }
[ "function", "streamHandler", "(", "stream", ")", "{", "return", "stream", ".", "pipe", "(", "plumber", "(", ")", ")", ".", "pipe", "(", "sourcemaps", ".", "init", "(", "{", "loadMaps", ":", "true", "}", ")", ")", ".", "pipe", "(", "sourcemaps", ".", "write", "(", "'.'", ",", "{", "includeContent", ":", "true", ",", "sourceRoot", ":", "'.'", "}", ")", ")", ".", "pipe", "(", "gulp", ".", "dest", "(", "dest", ")", ")", ";", "}" ]
stream handler to apply further gulp plugins @param {Object} stream gulp file stream @return {Object} processed stream
[ "stream", "handler", "to", "apply", "further", "gulp", "plugins" ]
149bee169c9a104cc641bc0e0eaf5a6aa52f9936
https://github.com/simbo/gulp-watchify-browserify/blob/149bee169c9a104cc641bc0e0eaf5a6aa52f9936/demo/gulpfile.js#L50-L56
47,802
smartface/sf-component-calendar
scripts/components/calendarContext.js
reducer
function reducer(context, action, target, state) { const newState = Object.assign({}, state); let actor; switch(action.type) { case INIT_CONTEXT_ACTION_TYPE: newState.days = context.reduce((acc, actor, name) => { if(name.indexOf("_weekDay") > 0) acc.push(name); return acc; }, []); return newState; case "resetDays": context.map(resetDays); return newState; case "deselectDays": context.map(deselectDays); return newState; case "daySelected": const selected = context.find(newState.selectedDay); if(selected){ removeSelection(context, newState); } actor = context.find(target, {pushClassNames: raiseTargetNotfound(target)}); actor.pushClassNames(".calendar.day_label-selected"); newState.selectedDay = target; return newState; case "clearSelectedDay": removeSelection(context, newState); return newState; case "changeMonth": removeSelection(context, newState); return newState; case "changeCalendar": context.map(function(actor){ if(!actor || actor.name === undefined) raiseTargetNotfound(target); const className = actor.getInitialClassName(); actor.resetClassNames([className, className+"-lang_"+action.lang, "#"+actor.name, "#"+actor.name+"-lang_"+action.lang, "#"+actor.name+"-os_"+System.OS ]); // actor.pushClassName("#"+actor.name+"-os_"+System.OS); }); return newState; case "updateDayType": actor = context.find(target); const data = action.data; if(data.isWeekend) { actor.pushClassNames(".calendar.day_label-weekend"); } if(Array.isArray(data.specialDay) && data.specialDay.length > 0) { actor.pushClassNames(".calendar.day_label-specialDay"); } if(data.month != "current") { actor.pushClassNames(".calendar.day_label-deactiveDays"); } return newState; } return state; }
javascript
function reducer(context, action, target, state) { const newState = Object.assign({}, state); let actor; switch(action.type) { case INIT_CONTEXT_ACTION_TYPE: newState.days = context.reduce((acc, actor, name) => { if(name.indexOf("_weekDay") > 0) acc.push(name); return acc; }, []); return newState; case "resetDays": context.map(resetDays); return newState; case "deselectDays": context.map(deselectDays); return newState; case "daySelected": const selected = context.find(newState.selectedDay); if(selected){ removeSelection(context, newState); } actor = context.find(target, {pushClassNames: raiseTargetNotfound(target)}); actor.pushClassNames(".calendar.day_label-selected"); newState.selectedDay = target; return newState; case "clearSelectedDay": removeSelection(context, newState); return newState; case "changeMonth": removeSelection(context, newState); return newState; case "changeCalendar": context.map(function(actor){ if(!actor || actor.name === undefined) raiseTargetNotfound(target); const className = actor.getInitialClassName(); actor.resetClassNames([className, className+"-lang_"+action.lang, "#"+actor.name, "#"+actor.name+"-lang_"+action.lang, "#"+actor.name+"-os_"+System.OS ]); // actor.pushClassName("#"+actor.name+"-os_"+System.OS); }); return newState; case "updateDayType": actor = context.find(target); const data = action.data; if(data.isWeekend) { actor.pushClassNames(".calendar.day_label-weekend"); } if(Array.isArray(data.specialDay) && data.specialDay.length > 0) { actor.pushClassNames(".calendar.day_label-specialDay"); } if(data.month != "current") { actor.pushClassNames(".calendar.day_label-deactiveDays"); } return newState; } return state; }
[ "function", "reducer", "(", "context", ",", "action", ",", "target", ",", "state", ")", "{", "const", "newState", "=", "Object", ".", "assign", "(", "{", "}", ",", "state", ")", ";", "let", "actor", ";", "switch", "(", "action", ".", "type", ")", "{", "case", "INIT_CONTEXT_ACTION_TYPE", ":", "newState", ".", "days", "=", "context", ".", "reduce", "(", "(", "acc", ",", "actor", ",", "name", ")", "=>", "{", "if", "(", "name", ".", "indexOf", "(", "\"_weekDay\"", ")", ">", "0", ")", "acc", ".", "push", "(", "name", ")", ";", "return", "acc", ";", "}", ",", "[", "]", ")", ";", "return", "newState", ";", "case", "\"resetDays\"", ":", "context", ".", "map", "(", "resetDays", ")", ";", "return", "newState", ";", "case", "\"deselectDays\"", ":", "context", ".", "map", "(", "deselectDays", ")", ";", "return", "newState", ";", "case", "\"daySelected\"", ":", "const", "selected", "=", "context", ".", "find", "(", "newState", ".", "selectedDay", ")", ";", "if", "(", "selected", ")", "{", "removeSelection", "(", "context", ",", "newState", ")", ";", "}", "actor", "=", "context", ".", "find", "(", "target", ",", "{", "pushClassNames", ":", "raiseTargetNotfound", "(", "target", ")", "}", ")", ";", "actor", ".", "pushClassNames", "(", "\".calendar.day_label-selected\"", ")", ";", "newState", ".", "selectedDay", "=", "target", ";", "return", "newState", ";", "case", "\"clearSelectedDay\"", ":", "removeSelection", "(", "context", ",", "newState", ")", ";", "return", "newState", ";", "case", "\"changeMonth\"", ":", "removeSelection", "(", "context", ",", "newState", ")", ";", "return", "newState", ";", "case", "\"changeCalendar\"", ":", "context", ".", "map", "(", "function", "(", "actor", ")", "{", "if", "(", "!", "actor", "||", "actor", ".", "name", "===", "undefined", ")", "raiseTargetNotfound", "(", "target", ")", ";", "const", "className", "=", "actor", ".", "getInitialClassName", "(", ")", ";", "actor", ".", "resetClassNames", "(", "[", "className", ",", "className", "+", "\"-lang_\"", "+", "action", ".", "lang", ",", "\"#\"", "+", "actor", ".", "name", ",", "\"#\"", "+", "actor", ".", "name", "+", "\"-lang_\"", "+", "action", ".", "lang", ",", "\"#\"", "+", "actor", ".", "name", "+", "\"-os_\"", "+", "System", ".", "OS", "]", ")", ";", "// actor.pushClassName(\"#\"+actor.name+\"-os_\"+System.OS);", "}", ")", ";", "return", "newState", ";", "case", "\"updateDayType\"", ":", "actor", "=", "context", ".", "find", "(", "target", ")", ";", "const", "data", "=", "action", ".", "data", ";", "if", "(", "data", ".", "isWeekend", ")", "{", "actor", ".", "pushClassNames", "(", "\".calendar.day_label-weekend\"", ")", ";", "}", "if", "(", "Array", ".", "isArray", "(", "data", ".", "specialDay", ")", "&&", "data", ".", "specialDay", ".", "length", ">", "0", ")", "{", "actor", ".", "pushClassNames", "(", "\".calendar.day_label-specialDay\"", ")", ";", "}", "if", "(", "data", ".", "month", "!=", "\"current\"", ")", "{", "actor", ".", "pushClassNames", "(", "\".calendar.day_label-deactiveDays\"", ")", ";", "}", "return", "newState", ";", "}", "return", "state", ";", "}" ]
reducer for context's components
[ "reducer", "for", "context", "s", "components" ]
d6c8310564ff551b9424ac6955efa5e8cf5f8dff
https://github.com/smartface/sf-component-calendar/blob/d6c8310564ff551b9424ac6955efa5e8cf5f8dff/scripts/components/calendarContext.js#L46-L122
47,803
tenorviol/xjs
lib/XjsStream.js
emitBuffer
function emitBuffer() { if (!this._buffer) { return; } for (var i = this._marker; i < this._buffer.length; i++) { var data = this._buffer[i]; if (data.writable === true) { break; } else if (data.writable === false) { emitBuffer.call(data); } else { this.emit('data', data, 'utf8'); } } if (i === this._buffer.length) { delete this._buffer; delete this._marker; if (!this.writable) { this.emit('end'); } } else { this._marker = i; } }
javascript
function emitBuffer() { if (!this._buffer) { return; } for (var i = this._marker; i < this._buffer.length; i++) { var data = this._buffer[i]; if (data.writable === true) { break; } else if (data.writable === false) { emitBuffer.call(data); } else { this.emit('data', data, 'utf8'); } } if (i === this._buffer.length) { delete this._buffer; delete this._marker; if (!this.writable) { this.emit('end'); } } else { this._marker = i; } }
[ "function", "emitBuffer", "(", ")", "{", "if", "(", "!", "this", ".", "_buffer", ")", "{", "return", ";", "}", "for", "(", "var", "i", "=", "this", ".", "_marker", ";", "i", "<", "this", ".", "_buffer", ".", "length", ";", "i", "++", ")", "{", "var", "data", "=", "this", ".", "_buffer", "[", "i", "]", ";", "if", "(", "data", ".", "writable", "===", "true", ")", "{", "break", ";", "}", "else", "if", "(", "data", ".", "writable", "===", "false", ")", "{", "emitBuffer", ".", "call", "(", "data", ")", ";", "}", "else", "{", "this", ".", "emit", "(", "'data'", ",", "data", ",", "'utf8'", ")", ";", "}", "}", "if", "(", "i", "===", "this", ".", "_buffer", ".", "length", ")", "{", "delete", "this", ".", "_buffer", ";", "delete", "this", ".", "_marker", ";", "if", "(", "!", "this", ".", "writable", ")", "{", "this", ".", "emit", "(", "'end'", ")", ";", "}", "}", "else", "{", "this", ".", "_marker", "=", "i", ";", "}", "}" ]
When not waiting on an async substream, emit right away. Otherwise start._buffering.
[ "When", "not", "waiting", "on", "an", "async", "substream", "emit", "right", "away", ".", "Otherwise", "start", ".", "_buffering", "." ]
1f0744354b311066d6e58d11f9f5c602dae926af
https://github.com/tenorviol/xjs/blob/1f0744354b311066d6e58d11f9f5c602dae926af/lib/XjsStream.js#L163-L186
47,804
node-tastypie/tastypie
lib/class/options.js
setOptions
function setOptions( options ){ if( this.addListener ){ for( var opt in options ){ if( typeof( options[ opt ] ) !== 'function' || !(/^on[A-z]/).test(opt)){ continue; } this.addListener( removeOn( opt ), options[ opt ]); delete options[opt]; } } this.options = merge.apply(null, append([{}, this.options], arguments ) ); return this; }
javascript
function setOptions( options ){ if( this.addListener ){ for( var opt in options ){ if( typeof( options[ opt ] ) !== 'function' || !(/^on[A-z]/).test(opt)){ continue; } this.addListener( removeOn( opt ), options[ opt ]); delete options[opt]; } } this.options = merge.apply(null, append([{}, this.options], arguments ) ); return this; }
[ "function", "setOptions", "(", "options", ")", "{", "if", "(", "this", ".", "addListener", ")", "{", "for", "(", "var", "opt", "in", "options", ")", "{", "if", "(", "typeof", "(", "options", "[", "opt", "]", ")", "!==", "'function'", "||", "!", "(", "/", "^on[A-z]", "/", ")", ".", "test", "(", "opt", ")", ")", "{", "continue", ";", "}", "this", ".", "addListener", "(", "removeOn", "(", "opt", ")", ",", "options", "[", "opt", "]", ")", ";", "delete", "options", "[", "opt", "]", ";", "}", "}", "this", ".", "options", "=", "merge", ".", "apply", "(", "null", ",", "append", "(", "[", "{", "}", ",", "this", ".", "options", "]", ",", "arguments", ")", ")", ";", "return", "this", ";", "}" ]
Over rides internal values with supplied object @method module:tastypie/lib/class/options#setOptions @param {Object} options The options object to use as configuration overrides
[ "Over", "rides", "internal", "values", "with", "supplied", "object" ]
bf42227975704ac19cce2c5f62427a205cadafdb
https://github.com/node-tastypie/tastypie/blob/bf42227975704ac19cce2c5f62427a205cadafdb/lib/class/options.js#L43-L55
47,805
knownasilya/ember-leaflet-cartodb
vendor/ember-leaflet-cartodb/cartodb_noleaflet.js
sanitize
function sanitize(htmlText, opt_uriPolicy, opt_nmTokenPolicy) { var out = []; makeHtmlSanitizer( function sanitizeAttribs(tagName, attribs) { for (var i = 0; i < attribs.length; i += 2) { var attribName = attribs[i]; var value = attribs[i + 1]; var atype = null, attribKey; if ((attribKey = tagName + '::' + attribName, html4.ATTRIBS.hasOwnProperty(attribKey)) || (attribKey = '*::' + attribName, html4.ATTRIBS.hasOwnProperty(attribKey))) { atype = html4.ATTRIBS[attribKey]; } if (atype !== null) { switch (atype) { case html4.atype.NONE: break; case html4.atype.SCRIPT: case html4.atype.STYLE: value = null; break; case html4.atype.ID: case html4.atype.IDREF: case html4.atype.IDREFS: case html4.atype.GLOBAL_NAME: case html4.atype.LOCAL_NAME: case html4.atype.CLASSES: value = opt_nmTokenPolicy ? opt_nmTokenPolicy(value) : value; break; case html4.atype.URI: var parsedUri = ('' + value).match(URI_SCHEME_RE); if (!parsedUri) { value = null; } else if (!parsedUri[1] || WHITELISTED_SCHEMES.test(parsedUri[1])) { value = opt_uriPolicy && opt_uriPolicy(value); } else { value = null; } break; case html4.atype.URI_FRAGMENT: if (value && '#' === value.charAt(0)) { value = opt_nmTokenPolicy ? opt_nmTokenPolicy(value) : value; if (value) { value = '#' + value; } } else { value = null; } break; default: value = null; break; } } else { value = null; } attribs[i + 1] = value; } return attribs; })(htmlText, out); return out.join(''); }
javascript
function sanitize(htmlText, opt_uriPolicy, opt_nmTokenPolicy) { var out = []; makeHtmlSanitizer( function sanitizeAttribs(tagName, attribs) { for (var i = 0; i < attribs.length; i += 2) { var attribName = attribs[i]; var value = attribs[i + 1]; var atype = null, attribKey; if ((attribKey = tagName + '::' + attribName, html4.ATTRIBS.hasOwnProperty(attribKey)) || (attribKey = '*::' + attribName, html4.ATTRIBS.hasOwnProperty(attribKey))) { atype = html4.ATTRIBS[attribKey]; } if (atype !== null) { switch (atype) { case html4.atype.NONE: break; case html4.atype.SCRIPT: case html4.atype.STYLE: value = null; break; case html4.atype.ID: case html4.atype.IDREF: case html4.atype.IDREFS: case html4.atype.GLOBAL_NAME: case html4.atype.LOCAL_NAME: case html4.atype.CLASSES: value = opt_nmTokenPolicy ? opt_nmTokenPolicy(value) : value; break; case html4.atype.URI: var parsedUri = ('' + value).match(URI_SCHEME_RE); if (!parsedUri) { value = null; } else if (!parsedUri[1] || WHITELISTED_SCHEMES.test(parsedUri[1])) { value = opt_uriPolicy && opt_uriPolicy(value); } else { value = null; } break; case html4.atype.URI_FRAGMENT: if (value && '#' === value.charAt(0)) { value = opt_nmTokenPolicy ? opt_nmTokenPolicy(value) : value; if (value) { value = '#' + value; } } else { value = null; } break; default: value = null; break; } } else { value = null; } attribs[i + 1] = value; } return attribs; })(htmlText, out); return out.join(''); }
[ "function", "sanitize", "(", "htmlText", ",", "opt_uriPolicy", ",", "opt_nmTokenPolicy", ")", "{", "var", "out", "=", "[", "]", ";", "makeHtmlSanitizer", "(", "function", "sanitizeAttribs", "(", "tagName", ",", "attribs", ")", "{", "for", "(", "var", "i", "=", "0", ";", "i", "<", "attribs", ".", "length", ";", "i", "+=", "2", ")", "{", "var", "attribName", "=", "attribs", "[", "i", "]", ";", "var", "value", "=", "attribs", "[", "i", "+", "1", "]", ";", "var", "atype", "=", "null", ",", "attribKey", ";", "if", "(", "(", "attribKey", "=", "tagName", "+", "'::'", "+", "attribName", ",", "html4", ".", "ATTRIBS", ".", "hasOwnProperty", "(", "attribKey", ")", ")", "||", "(", "attribKey", "=", "'*::'", "+", "attribName", ",", "html4", ".", "ATTRIBS", ".", "hasOwnProperty", "(", "attribKey", ")", ")", ")", "{", "atype", "=", "html4", ".", "ATTRIBS", "[", "attribKey", "]", ";", "}", "if", "(", "atype", "!==", "null", ")", "{", "switch", "(", "atype", ")", "{", "case", "html4", ".", "atype", ".", "NONE", ":", "break", ";", "case", "html4", ".", "atype", ".", "SCRIPT", ":", "case", "html4", ".", "atype", ".", "STYLE", ":", "value", "=", "null", ";", "break", ";", "case", "html4", ".", "atype", ".", "ID", ":", "case", "html4", ".", "atype", ".", "IDREF", ":", "case", "html4", ".", "atype", ".", "IDREFS", ":", "case", "html4", ".", "atype", ".", "GLOBAL_NAME", ":", "case", "html4", ".", "atype", ".", "LOCAL_NAME", ":", "case", "html4", ".", "atype", ".", "CLASSES", ":", "value", "=", "opt_nmTokenPolicy", "?", "opt_nmTokenPolicy", "(", "value", ")", ":", "value", ";", "break", ";", "case", "html4", ".", "atype", ".", "URI", ":", "var", "parsedUri", "=", "(", "''", "+", "value", ")", ".", "match", "(", "URI_SCHEME_RE", ")", ";", "if", "(", "!", "parsedUri", ")", "{", "value", "=", "null", ";", "}", "else", "if", "(", "!", "parsedUri", "[", "1", "]", "||", "WHITELISTED_SCHEMES", ".", "test", "(", "parsedUri", "[", "1", "]", ")", ")", "{", "value", "=", "opt_uriPolicy", "&&", "opt_uriPolicy", "(", "value", ")", ";", "}", "else", "{", "value", "=", "null", ";", "}", "break", ";", "case", "html4", ".", "atype", ".", "URI_FRAGMENT", ":", "if", "(", "value", "&&", "'#'", "===", "value", ".", "charAt", "(", "0", ")", ")", "{", "value", "=", "opt_nmTokenPolicy", "?", "opt_nmTokenPolicy", "(", "value", ")", ":", "value", ";", "if", "(", "value", ")", "{", "value", "=", "'#'", "+", "value", ";", "}", "}", "else", "{", "value", "=", "null", ";", "}", "break", ";", "default", ":", "value", "=", "null", ";", "break", ";", "}", "}", "else", "{", "value", "=", "null", ";", "}", "attribs", "[", "i", "+", "1", "]", "=", "value", ";", "}", "return", "attribs", ";", "}", ")", "(", "htmlText", ",", "out", ")", ";", "return", "out", ".", "join", "(", "''", ")", ";", "}" ]
Strips unsafe tags and attributes from html. @param {string} htmlText to sanitize @param {Function} opt_uriPolicy -- a transform to apply to uri/url attribute values. If no opt_uriPolicy is provided, no uris are allowed ie. the default uriPolicy rewrites all uris to null @param {Function} opt_nmTokenPolicy : string -> string? -- a transform to apply to names, ids, and classes. If no opt_nmTokenPolicy is provided, all names, ids and classes are passed through ie. the default nmTokenPolicy is an identity transform @return {string} html
[ "Strips", "unsafe", "tags", "and", "attributes", "from", "html", "." ]
61d11c6268d59343746809639e0d23419674ae87
https://github.com/knownasilya/ember-leaflet-cartodb/blob/61d11c6268d59343746809639e0d23419674ae87/vendor/ember-leaflet-cartodb/cartodb_noleaflet.js#L3926-L3986
47,806
knownasilya/ember-leaflet-cartodb
vendor/ember-leaflet-cartodb/cartodb_noleaflet.js
onDown
function onDown(e) { // Prevent interaction offset calculations happening while // the user is dragging the map. // // Store this event so that we can compare it to the // up event _downLock = true; var _e = (e.type !== "MSPointerDown" && e.type !== "pointerdown" ? e : e.originalEvent); _d = wax.u.eventoffset(_e); if (e.type === 'mousedown') { bean.add(document.body, 'click', onUp); // track mouse up to remove lockDown when the drags end bean.add(document.body, 'mouseup', dragEnd); // Only track single-touches. Double-touches will not affect this // control } else if (e.type === 'touchstart' && e.touches.length === 1) { //GMaps fix: Because it's triggering always mousedown and click, we've to remove it bean.remove(document.body, 'click', onUp); //GMaps fix //When we finish dragging, then the click will be bean.add(document.body, 'click', onUp); bean.add(document.body, 'touchEnd', dragEnd); } else if (e.originalEvent.type === "MSPointerDown" && e.originalEvent.touches && e.originalEvent.touches.length === 1) { // Don't make the user click close if they hit another tooltip bean.fire(interaction, 'off'); // Touch moves invalidate touches bean.add(parent(), mspointerEnds); } else if (e.type === "pointerdown" && e.originalEvent.touches && e.originalEvent.touches.length === 1) { // Don't make the user click close if they hit another tooltip bean.fire(interaction, 'off'); // Touch moves invalidate touches bean.add(parent(), pointerEnds); } else { // Fix layer interaction in IE10/11 (CDBjs #139) // Reason: Internet Explorer is triggering pointerdown when you click on the marker, and other browsers don't. // Because of that, _downLock was active and it believed that you're dragging the map, instead of dragging the marker _downLock = false; } }
javascript
function onDown(e) { // Prevent interaction offset calculations happening while // the user is dragging the map. // // Store this event so that we can compare it to the // up event _downLock = true; var _e = (e.type !== "MSPointerDown" && e.type !== "pointerdown" ? e : e.originalEvent); _d = wax.u.eventoffset(_e); if (e.type === 'mousedown') { bean.add(document.body, 'click', onUp); // track mouse up to remove lockDown when the drags end bean.add(document.body, 'mouseup', dragEnd); // Only track single-touches. Double-touches will not affect this // control } else if (e.type === 'touchstart' && e.touches.length === 1) { //GMaps fix: Because it's triggering always mousedown and click, we've to remove it bean.remove(document.body, 'click', onUp); //GMaps fix //When we finish dragging, then the click will be bean.add(document.body, 'click', onUp); bean.add(document.body, 'touchEnd', dragEnd); } else if (e.originalEvent.type === "MSPointerDown" && e.originalEvent.touches && e.originalEvent.touches.length === 1) { // Don't make the user click close if they hit another tooltip bean.fire(interaction, 'off'); // Touch moves invalidate touches bean.add(parent(), mspointerEnds); } else if (e.type === "pointerdown" && e.originalEvent.touches && e.originalEvent.touches.length === 1) { // Don't make the user click close if they hit another tooltip bean.fire(interaction, 'off'); // Touch moves invalidate touches bean.add(parent(), pointerEnds); } else { // Fix layer interaction in IE10/11 (CDBjs #139) // Reason: Internet Explorer is triggering pointerdown when you click on the marker, and other browsers don't. // Because of that, _downLock was active and it believed that you're dragging the map, instead of dragging the marker _downLock = false; } }
[ "function", "onDown", "(", "e", ")", "{", "// Prevent interaction offset calculations happening while", "// the user is dragging the map.", "//", "// Store this event so that we can compare it to the", "// up event", "_downLock", "=", "true", ";", "var", "_e", "=", "(", "e", ".", "type", "!==", "\"MSPointerDown\"", "&&", "e", ".", "type", "!==", "\"pointerdown\"", "?", "e", ":", "e", ".", "originalEvent", ")", ";", "_d", "=", "wax", ".", "u", ".", "eventoffset", "(", "_e", ")", ";", "if", "(", "e", ".", "type", "===", "'mousedown'", ")", "{", "bean", ".", "add", "(", "document", ".", "body", ",", "'click'", ",", "onUp", ")", ";", "// track mouse up to remove lockDown when the drags end", "bean", ".", "add", "(", "document", ".", "body", ",", "'mouseup'", ",", "dragEnd", ")", ";", "// Only track single-touches. Double-touches will not affect this", "// control", "}", "else", "if", "(", "e", ".", "type", "===", "'touchstart'", "&&", "e", ".", "touches", ".", "length", "===", "1", ")", "{", "//GMaps fix: Because it's triggering always mousedown and click, we've to remove it", "bean", ".", "remove", "(", "document", ".", "body", ",", "'click'", ",", "onUp", ")", ";", "//GMaps fix", "//When we finish dragging, then the click will be ", "bean", ".", "add", "(", "document", ".", "body", ",", "'click'", ",", "onUp", ")", ";", "bean", ".", "add", "(", "document", ".", "body", ",", "'touchEnd'", ",", "dragEnd", ")", ";", "}", "else", "if", "(", "e", ".", "originalEvent", ".", "type", "===", "\"MSPointerDown\"", "&&", "e", ".", "originalEvent", ".", "touches", "&&", "e", ".", "originalEvent", ".", "touches", ".", "length", "===", "1", ")", "{", "// Don't make the user click close if they hit another tooltip", "bean", ".", "fire", "(", "interaction", ",", "'off'", ")", ";", "// Touch moves invalidate touches", "bean", ".", "add", "(", "parent", "(", ")", ",", "mspointerEnds", ")", ";", "}", "else", "if", "(", "e", ".", "type", "===", "\"pointerdown\"", "&&", "e", ".", "originalEvent", ".", "touches", "&&", "e", ".", "originalEvent", ".", "touches", ".", "length", "===", "1", ")", "{", "// Don't make the user click close if they hit another tooltip", "bean", ".", "fire", "(", "interaction", ",", "'off'", ")", ";", "// Touch moves invalidate touches", "bean", ".", "add", "(", "parent", "(", ")", ",", "pointerEnds", ")", ";", "}", "else", "{", "// Fix layer interaction in IE10/11 (CDBjs #139)", "// Reason: Internet Explorer is triggering pointerdown when you click on the marker, and other browsers don't.", "// Because of that, _downLock was active and it believed that you're dragging the map, instead of dragging the marker", "_downLock", "=", "false", ";", "}", "}" ]
A handler for 'down' events - which means `mousedown` and `touchstart`
[ "A", "handler", "for", "down", "events", "-", "which", "means", "mousedown", "and", "touchstart" ]
61d11c6268d59343746809639e0d23419674ae87
https://github.com/knownasilya/ember-leaflet-cartodb/blob/61d11c6268d59343746809639e0d23419674ae87/vendor/ember-leaflet-cartodb/cartodb_noleaflet.js#L5041-L5082
47,807
knownasilya/ember-leaflet-cartodb
vendor/ember-leaflet-cartodb/cartodb_noleaflet.js
initTouch
function initTouch() { var startX, startY, touchStartX, touchStartY, moved, moving = false; container.unbind('touchstart.jsp touchmove.jsp touchend.jsp click.jsp-touchclick').bind( 'touchstart.jsp', function(e) { var touch = e.originalEvent.touches[0]; startX = contentPositionX(); startY = contentPositionY(); touchStartX = touch.pageX; touchStartY = touch.pageY; moved = false; moving = true; } ).bind( 'touchmove.jsp', function(ev) { if(!moving) { return; } var touchPos = ev.originalEvent.touches[0], dX = horizontalDragPosition, dY = verticalDragPosition; jsp.scrollTo(startX + touchStartX - touchPos.pageX, startY + touchStartY - touchPos.pageY); moved = moved || Math.abs(touchStartX - touchPos.pageX) > 5 || Math.abs(touchStartY - touchPos.pageY) > 5; // return true if there was no movement so rest of screen can scroll return dX == horizontalDragPosition && dY == verticalDragPosition; } ).bind( 'touchend.jsp', function(e) { moving = false; /*if(moved) { return false; }*/ } ).bind( 'click.jsp-touchclick', function(e) { if(moved) { moved = false; return false; } } ); }
javascript
function initTouch() { var startX, startY, touchStartX, touchStartY, moved, moving = false; container.unbind('touchstart.jsp touchmove.jsp touchend.jsp click.jsp-touchclick').bind( 'touchstart.jsp', function(e) { var touch = e.originalEvent.touches[0]; startX = contentPositionX(); startY = contentPositionY(); touchStartX = touch.pageX; touchStartY = touch.pageY; moved = false; moving = true; } ).bind( 'touchmove.jsp', function(ev) { if(!moving) { return; } var touchPos = ev.originalEvent.touches[0], dX = horizontalDragPosition, dY = verticalDragPosition; jsp.scrollTo(startX + touchStartX - touchPos.pageX, startY + touchStartY - touchPos.pageY); moved = moved || Math.abs(touchStartX - touchPos.pageX) > 5 || Math.abs(touchStartY - touchPos.pageY) > 5; // return true if there was no movement so rest of screen can scroll return dX == horizontalDragPosition && dY == verticalDragPosition; } ).bind( 'touchend.jsp', function(e) { moving = false; /*if(moved) { return false; }*/ } ).bind( 'click.jsp-touchclick', function(e) { if(moved) { moved = false; return false; } } ); }
[ "function", "initTouch", "(", ")", "{", "var", "startX", ",", "startY", ",", "touchStartX", ",", "touchStartY", ",", "moved", ",", "moving", "=", "false", ";", "container", ".", "unbind", "(", "'touchstart.jsp touchmove.jsp touchend.jsp click.jsp-touchclick'", ")", ".", "bind", "(", "'touchstart.jsp'", ",", "function", "(", "e", ")", "{", "var", "touch", "=", "e", ".", "originalEvent", ".", "touches", "[", "0", "]", ";", "startX", "=", "contentPositionX", "(", ")", ";", "startY", "=", "contentPositionY", "(", ")", ";", "touchStartX", "=", "touch", ".", "pageX", ";", "touchStartY", "=", "touch", ".", "pageY", ";", "moved", "=", "false", ";", "moving", "=", "true", ";", "}", ")", ".", "bind", "(", "'touchmove.jsp'", ",", "function", "(", "ev", ")", "{", "if", "(", "!", "moving", ")", "{", "return", ";", "}", "var", "touchPos", "=", "ev", ".", "originalEvent", ".", "touches", "[", "0", "]", ",", "dX", "=", "horizontalDragPosition", ",", "dY", "=", "verticalDragPosition", ";", "jsp", ".", "scrollTo", "(", "startX", "+", "touchStartX", "-", "touchPos", ".", "pageX", ",", "startY", "+", "touchStartY", "-", "touchPos", ".", "pageY", ")", ";", "moved", "=", "moved", "||", "Math", ".", "abs", "(", "touchStartX", "-", "touchPos", ".", "pageX", ")", ">", "5", "||", "Math", ".", "abs", "(", "touchStartY", "-", "touchPos", ".", "pageY", ")", ">", "5", ";", "// return true if there was no movement so rest of screen can scroll", "return", "dX", "==", "horizontalDragPosition", "&&", "dY", "==", "verticalDragPosition", ";", "}", ")", ".", "bind", "(", "'touchend.jsp'", ",", "function", "(", "e", ")", "{", "moving", "=", "false", ";", "/*if(moved) {\n return false;\n }*/", "}", ")", ".", "bind", "(", "'click.jsp-touchclick'", ",", "function", "(", "e", ")", "{", "if", "(", "moved", ")", "{", "moved", "=", "false", ";", "return", "false", ";", "}", "}", ")", ";", "}" ]
Init touch on iPad, iPhone, iPod, Android
[ "Init", "touch", "on", "iPad", "iPhone", "iPod", "Android" ]
61d11c6268d59343746809639e0d23419674ae87
https://github.com/knownasilya/ember-leaflet-cartodb/blob/61d11c6268d59343746809639e0d23419674ae87/vendor/ember-leaflet-cartodb/cartodb_noleaflet.js#L7251-L7309
47,808
knownasilya/ember-leaflet-cartodb
vendor/ember-leaflet-cartodb/cartodb_noleaflet.js
function(vars) { var c = this.compiled = this.compiled || this.get('compiled') || this.compile(); var rendered = c(vars); return rendered; }
javascript
function(vars) { var c = this.compiled = this.compiled || this.get('compiled') || this.compile(); var rendered = c(vars); return rendered; }
[ "function", "(", "vars", ")", "{", "var", "c", "=", "this", ".", "compiled", "=", "this", ".", "compiled", "||", "this", ".", "get", "(", "'compiled'", ")", "||", "this", ".", "compile", "(", ")", ";", "var", "rendered", "=", "c", "(", "vars", ")", ";", "return", "rendered", ";", "}" ]
renders the template with specified vars
[ "renders", "the", "template", "with", "specified", "vars" ]
61d11c6268d59343746809639e0d23419674ae87
https://github.com/knownasilya/ember-leaflet-cartodb/blob/61d11c6268d59343746809639e0d23419674ae87/vendor/ember-leaflet-cartodb/cartodb_noleaflet.js#L17141-L17145
47,809
knownasilya/ember-leaflet-cartodb
vendor/ember-leaflet-cartodb/cartodb_noleaflet.js
function(args) { var self = this; // var date = new Date(); this.trigger('loadModelStarted'); $.when(this.elder('fetch', args)).done(function(ev){ self.trigger('loadModelCompleted', ev); // var dateComplete = new Date() // console.log('completed in '+(dateComplete - date)); }).fail(function(ev) { self.trigger('loadModelFailed', ev); }) }
javascript
function(args) { var self = this; // var date = new Date(); this.trigger('loadModelStarted'); $.when(this.elder('fetch', args)).done(function(ev){ self.trigger('loadModelCompleted', ev); // var dateComplete = new Date() // console.log('completed in '+(dateComplete - date)); }).fail(function(ev) { self.trigger('loadModelFailed', ev); }) }
[ "function", "(", "args", ")", "{", "var", "self", "=", "this", ";", "// var date = new Date();", "this", ".", "trigger", "(", "'loadModelStarted'", ")", ";", "$", ".", "when", "(", "this", ".", "elder", "(", "'fetch'", ",", "args", ")", ")", ".", "done", "(", "function", "(", "ev", ")", "{", "self", ".", "trigger", "(", "'loadModelCompleted'", ",", "ev", ")", ";", "// var dateComplete = new Date()", "// console.log('completed in '+(dateComplete - date));", "}", ")", ".", "fail", "(", "function", "(", "ev", ")", "{", "self", ".", "trigger", "(", "'loadModelFailed'", ",", "ev", ")", ";", "}", ")", "}" ]
We are redefining fetch to be able to trigger an event when the ajax call ends, no matter if there's a change in the data or not. Why don't backbone does this by default? ahh, my friend, who knows. @method fetch @param args {Object}
[ "We", "are", "redefining", "fetch", "to", "be", "able", "to", "trigger", "an", "event", "when", "the", "ajax", "call", "ends", "no", "matter", "if", "there", "s", "a", "change", "in", "the", "data", "or", "not", ".", "Why", "don", "t", "backbone", "does", "this", "by", "default?", "ahh", "my", "friend", "who", "knows", "." ]
61d11c6268d59343746809639e0d23419674ae87
https://github.com/knownasilya/ember-leaflet-cartodb/blob/61d11c6268d59343746809639e0d23419674ae87/vendor/ember-leaflet-cartodb/cartodb_noleaflet.js#L17250-L17261
47,810
knownasilya/ember-leaflet-cartodb
vendor/ember-leaflet-cartodb/cartodb_noleaflet.js
function(ev, obj, retrigEvent) { if(!retrigEvent) { retrigEvent = ev; } var self = this; obj.bind && obj.bind(ev, function() { self.trigger(retrigEvent); }, self) }
javascript
function(ev, obj, retrigEvent) { if(!retrigEvent) { retrigEvent = ev; } var self = this; obj.bind && obj.bind(ev, function() { self.trigger(retrigEvent); }, self) }
[ "function", "(", "ev", ",", "obj", ",", "retrigEvent", ")", "{", "if", "(", "!", "retrigEvent", ")", "{", "retrigEvent", "=", "ev", ";", "}", "var", "self", "=", "this", ";", "obj", ".", "bind", "&&", "obj", ".", "bind", "(", "ev", ",", "function", "(", ")", "{", "self", ".", "trigger", "(", "retrigEvent", ")", ";", "}", ",", "self", ")", "}" ]
Listen for an event on another object and triggers on itself, with the same name or a new one @method retrigger @param ev {String} event who triggers the action @param obj {Object} object where the event happens @param obj {Object} [optional] name of the retriggered event; @todo [xabel]: This method is repeated here and in the base view definition. There's should be a way to make it unique
[ "Listen", "for", "an", "event", "on", "another", "object", "and", "triggers", "on", "itself", "with", "the", "same", "name", "or", "a", "new", "one" ]
61d11c6268d59343746809639e0d23419674ae87
https://github.com/knownasilya/ember-leaflet-cartodb/blob/61d11c6268d59343746809639e0d23419674ae87/vendor/ember-leaflet-cartodb/cartodb_noleaflet.js#L17278-L17286
47,811
knownasilya/ember-leaflet-cartodb
vendor/ember-leaflet-cartodb/cartodb_noleaflet.js
function() { var self = this; this.trigger('clean'); this.clearSubViews(); // remove from parent if(this._parent) { this._parent.removeView(this); this._parent = null; } this.remove(); this.unbind(); // remove this model binding if (this.model && this.model.unbind) this.model.unbind(null, null, this); // remove model binding _(this._models).each(function(m) { m.unbind(null, null, self); }); this._models = []; View.viewCount--; delete View.views[this.cid]; return this; }
javascript
function() { var self = this; this.trigger('clean'); this.clearSubViews(); // remove from parent if(this._parent) { this._parent.removeView(this); this._parent = null; } this.remove(); this.unbind(); // remove this model binding if (this.model && this.model.unbind) this.model.unbind(null, null, this); // remove model binding _(this._models).each(function(m) { m.unbind(null, null, self); }); this._models = []; View.viewCount--; delete View.views[this.cid]; return this; }
[ "function", "(", ")", "{", "var", "self", "=", "this", ";", "this", ".", "trigger", "(", "'clean'", ")", ";", "this", ".", "clearSubViews", "(", ")", ";", "// remove from parent", "if", "(", "this", ".", "_parent", ")", "{", "this", ".", "_parent", ".", "removeView", "(", "this", ")", ";", "this", ".", "_parent", "=", "null", ";", "}", "this", ".", "remove", "(", ")", ";", "this", ".", "unbind", "(", ")", ";", "// remove this model binding", "if", "(", "this", ".", "model", "&&", "this", ".", "model", ".", "unbind", ")", "this", ".", "model", ".", "unbind", "(", "null", ",", "null", ",", "this", ")", ";", "// remove model binding", "_", "(", "this", ".", "_models", ")", ".", "each", "(", "function", "(", "m", ")", "{", "m", ".", "unbind", "(", "null", ",", "null", ",", "self", ")", ";", "}", ")", ";", "this", ".", "_models", "=", "[", "]", ";", "View", ".", "viewCount", "--", ";", "delete", "View", ".", "views", "[", "this", ".", "cid", "]", ";", "return", "this", ";", "}" ]
this methid clean removes the view and clean and events associated. call it when the view is not going to be used anymore
[ "this", "methid", "clean", "removes", "the", "view", "and", "clean", "and", "events", "associated", ".", "call", "it", "when", "the", "view", "is", "not", "going", "to", "be", "used", "anymore" ]
61d11c6268d59343746809639e0d23419674ae87
https://github.com/knownasilya/ember-leaflet-cartodb/blob/61d11c6268d59343746809639e0d23419674ae87/vendor/ember-leaflet-cartodb/cartodb_noleaflet.js#L17355-L17376
47,812
knownasilya/ember-leaflet-cartodb
vendor/ember-leaflet-cartodb/cartodb_noleaflet.js
function(ev) { if(ev && ev.preventDefault) { ev.preventDefault(); }; if(ev && ev.stopPropagation) { ev.stopPropagation(); }; }
javascript
function(ev) { if(ev && ev.preventDefault) { ev.preventDefault(); }; if(ev && ev.stopPropagation) { ev.stopPropagation(); }; }
[ "function", "(", "ev", ")", "{", "if", "(", "ev", "&&", "ev", ".", "preventDefault", ")", "{", "ev", ".", "preventDefault", "(", ")", ";", "}", ";", "if", "(", "ev", "&&", "ev", ".", "stopPropagation", ")", "{", "ev", ".", "stopPropagation", "(", ")", ";", "}", ";", "}" ]
Captures an event and prevents the default behaviour and stops it from bubbling @method killEvent @param event {Event}
[ "Captures", "an", "event", "and", "prevents", "the", "default", "behaviour", "and", "stops", "it", "from", "bubbling" ]
61d11c6268d59343746809639e0d23419674ae87
https://github.com/knownasilya/ember-leaflet-cartodb/blob/61d11c6268d59343746809639e0d23419674ae87/vendor/ember-leaflet-cartodb/cartodb_noleaflet.js#L17420-L17427
47,813
knownasilya/ember-leaflet-cartodb
vendor/ember-leaflet-cartodb/cartodb_noleaflet.js
function() { _.each(cdb.core.View.views, function(view) { _.each(view, function(prop, k) { if( k !== '_parent' && view.hasOwnProperty(k) && prop instanceof cdb.core.View && view._subviews[prop.cid] === undefined) { console.log("========="); console.log("untracked view: "); console.log(prop.el); console.log('parent'); console.log(view.el); console.log(" "); } }); }); }
javascript
function() { _.each(cdb.core.View.views, function(view) { _.each(view, function(prop, k) { if( k !== '_parent' && view.hasOwnProperty(k) && prop instanceof cdb.core.View && view._subviews[prop.cid] === undefined) { console.log("========="); console.log("untracked view: "); console.log(prop.el); console.log('parent'); console.log(view.el); console.log(" "); } }); }); }
[ "function", "(", ")", "{", "_", ".", "each", "(", "cdb", ".", "core", ".", "View", ".", "views", ",", "function", "(", "view", ")", "{", "_", ".", "each", "(", "view", ",", "function", "(", "prop", ",", "k", ")", "{", "if", "(", "k", "!==", "'_parent'", "&&", "view", ".", "hasOwnProperty", "(", "k", ")", "&&", "prop", "instanceof", "cdb", ".", "core", ".", "View", "&&", "view", ".", "_subviews", "[", "prop", ".", "cid", "]", "===", "undefined", ")", "{", "console", ".", "log", "(", "\"=========\"", ")", ";", "console", ".", "log", "(", "\"untracked view: \"", ")", ";", "console", ".", "log", "(", "prop", ".", "el", ")", ";", "console", ".", "log", "(", "'parent'", ")", ";", "console", ".", "log", "(", "view", ".", "el", ")", ";", "console", ".", "log", "(", "\" \"", ")", ";", "}", "}", ")", ";", "}", ")", ";", "}" ]
search for views in a view and check if they are added as subviews
[ "search", "for", "views", "in", "a", "view", "and", "check", "if", "they", "are", "added", "as", "subviews" ]
61d11c6268d59343746809639e0d23419674ae87
https://github.com/knownasilya/ember-leaflet-cartodb/blob/61d11c6268d59343746809639e0d23419674ae87/vendor/ember-leaflet-cartodb/cartodb_noleaflet.js#L17462-L17478
47,814
knownasilya/ember-leaflet-cartodb
vendor/ember-leaflet-cartodb/cartodb_noleaflet.js
function() { var e = this.get('extra_params') || e; e.cache_buster = new Date().getTime(); this.set('extra_params', e); this.trigger('change', this); }
javascript
function() { var e = this.get('extra_params') || e; e.cache_buster = new Date().getTime(); this.set('extra_params', e); this.trigger('change', this); }
[ "function", "(", ")", "{", "var", "e", "=", "this", ".", "get", "(", "'extra_params'", ")", "||", "e", ";", "e", ".", "cache_buster", "=", "new", "Date", "(", ")", ".", "getTime", "(", ")", ";", "this", ".", "set", "(", "'extra_params'", ",", "e", ")", ";", "this", ".", "trigger", "(", "'change'", ",", "this", ")", ";", "}" ]
refresh the layer
[ "refresh", "the", "layer" ]
61d11c6268d59343746809639e0d23419674ae87
https://github.com/knownasilya/ember-leaflet-cartodb/blob/61d11c6268d59343746809639e0d23419674ae87/vendor/ember-leaflet-cartodb/cartodb_noleaflet.js#L18052-L18057
47,815
knownasilya/ember-leaflet-cartodb
vendor/ember-leaflet-cartodb/cartodb_noleaflet.js
function(model, col, options) { if (this.size() > 0) { // Assign an order of 0 to the first layer this.at(0).set({ order: 0 }); if (this.size() > 1) { var layersByType = {}; for (var i = 1; i < this.size(); ++i) { var layer = this.at(i); var layerType = layer.get('type'); layersByType[layerType] = layersByType[layerType] || []; layersByType[layerType].push(layer); } var lastOrder = 0; var sortedTypes = [CARTODB_LAYER_TYPE, TORQUE_LAYER_TYPE, TILED_LAYER_TYPE]; for (var i = 0; i < sortedTypes.length; ++i) { var type = sortedTypes[i]; var layers = layersByType[type] || []; for (var j = 0; j < layers.length; ++j) { var layer = layers[j]; layer.set({ order: ++lastOrder }); } } } } }
javascript
function(model, col, options) { if (this.size() > 0) { // Assign an order of 0 to the first layer this.at(0).set({ order: 0 }); if (this.size() > 1) { var layersByType = {}; for (var i = 1; i < this.size(); ++i) { var layer = this.at(i); var layerType = layer.get('type'); layersByType[layerType] = layersByType[layerType] || []; layersByType[layerType].push(layer); } var lastOrder = 0; var sortedTypes = [CARTODB_LAYER_TYPE, TORQUE_LAYER_TYPE, TILED_LAYER_TYPE]; for (var i = 0; i < sortedTypes.length; ++i) { var type = sortedTypes[i]; var layers = layersByType[type] || []; for (var j = 0; j < layers.length; ++j) { var layer = layers[j]; layer.set({ order: ++lastOrder }); } } } } }
[ "function", "(", "model", ",", "col", ",", "options", ")", "{", "if", "(", "this", ".", "size", "(", ")", ">", "0", ")", "{", "// Assign an order of 0 to the first layer", "this", ".", "at", "(", "0", ")", ".", "set", "(", "{", "order", ":", "0", "}", ")", ";", "if", "(", "this", ".", "size", "(", ")", ">", "1", ")", "{", "var", "layersByType", "=", "{", "}", ";", "for", "(", "var", "i", "=", "1", ";", "i", "<", "this", ".", "size", "(", ")", ";", "++", "i", ")", "{", "var", "layer", "=", "this", ".", "at", "(", "i", ")", ";", "var", "layerType", "=", "layer", ".", "get", "(", "'type'", ")", ";", "layersByType", "[", "layerType", "]", "=", "layersByType", "[", "layerType", "]", "||", "[", "]", ";", "layersByType", "[", "layerType", "]", ".", "push", "(", "layer", ")", ";", "}", "var", "lastOrder", "=", "0", ";", "var", "sortedTypes", "=", "[", "CARTODB_LAYER_TYPE", ",", "TORQUE_LAYER_TYPE", ",", "TILED_LAYER_TYPE", "]", ";", "for", "(", "var", "i", "=", "0", ";", "i", "<", "sortedTypes", ".", "length", ";", "++", "i", ")", "{", "var", "type", "=", "sortedTypes", "[", "i", "]", ";", "var", "layers", "=", "layersByType", "[", "type", "]", "||", "[", "]", ";", "for", "(", "var", "j", "=", "0", ";", "j", "<", "layers", ".", "length", ";", "++", "j", ")", "{", "var", "layer", "=", "layers", "[", "j", "]", ";", "layer", ".", "set", "(", "{", "order", ":", "++", "lastOrder", "}", ")", ";", "}", "}", "}", "}", "}" ]
each time a layer is added or removed the index should be recalculated
[ "each", "time", "a", "layer", "is", "added", "or", "removed", "the", "index", "should", "be", "recalculated" ]
61d11c6268d59343746809639e0d23419674ae87
https://github.com/knownasilya/ember-leaflet-cartodb/blob/61d11c6268d59343746809639e0d23419674ae87/vendor/ember-leaflet-cartodb/cartodb_noleaflet.js#L18124-L18153
47,816
knownasilya/ember-leaflet-cartodb
vendor/ember-leaflet-cartodb/cartodb_noleaflet.js
function(options) { if (typeof options != "object" || options.length) { if (this.options.debug) { throw (options + ' options has to be an object'); } else { return; } } // Set options _.defaults(this.options, options); }
javascript
function(options) { if (typeof options != "object" || options.length) { if (this.options.debug) { throw (options + ' options has to be an object'); } else { return; } } // Set options _.defaults(this.options, options); }
[ "function", "(", "options", ")", "{", "if", "(", "typeof", "options", "!=", "\"object\"", "||", "options", ".", "length", ")", "{", "if", "(", "this", ".", "options", ".", "debug", ")", "{", "throw", "(", "options", "+", "' options has to be an object'", ")", ";", "}", "else", "{", "return", ";", "}", "}", "// Set options", "_", ".", "defaults", "(", "this", ".", "options", ",", "options", ")", ";", "}" ]
Change multiple options at the same time @params {Object} New options object
[ "Change", "multiple", "options", "at", "the", "same", "time" ]
61d11c6268d59343746809639e0d23419674ae87
https://github.com/knownasilya/ember-leaflet-cartodb/blob/61d11c6268d59343746809639e0d23419674ae87/vendor/ember-leaflet-cartodb/cartodb_noleaflet.js#L18258-L18269
47,817
knownasilya/ember-leaflet-cartodb
vendor/ember-leaflet-cartodb/cartodb_noleaflet.js
function(bounds, mapSize) { var z = this.getBoundsZoom(bounds, mapSize); if(z === null) { return; } // project -> calculate center -> unproject var swPoint = cdb.geo.Map.latlngToMercator(bounds[0], z); var nePoint = cdb.geo.Map.latlngToMercator(bounds[1], z); var center = cdb.geo.Map.mercatorToLatLng({ x: (swPoint[0] + nePoint[0])*0.5, y: (swPoint[1] + nePoint[1])*0.5 }, z); this.set({ center: center, zoom: z }) }
javascript
function(bounds, mapSize) { var z = this.getBoundsZoom(bounds, mapSize); if(z === null) { return; } // project -> calculate center -> unproject var swPoint = cdb.geo.Map.latlngToMercator(bounds[0], z); var nePoint = cdb.geo.Map.latlngToMercator(bounds[1], z); var center = cdb.geo.Map.mercatorToLatLng({ x: (swPoint[0] + nePoint[0])*0.5, y: (swPoint[1] + nePoint[1])*0.5 }, z); this.set({ center: center, zoom: z }) }
[ "function", "(", "bounds", ",", "mapSize", ")", "{", "var", "z", "=", "this", ".", "getBoundsZoom", "(", "bounds", ",", "mapSize", ")", ";", "if", "(", "z", "===", "null", ")", "{", "return", ";", "}", "// project -> calculate center -> unproject", "var", "swPoint", "=", "cdb", ".", "geo", ".", "Map", ".", "latlngToMercator", "(", "bounds", "[", "0", "]", ",", "z", ")", ";", "var", "nePoint", "=", "cdb", ".", "geo", ".", "Map", ".", "latlngToMercator", "(", "bounds", "[", "1", "]", ",", "z", ")", ";", "var", "center", "=", "cdb", ".", "geo", ".", "Map", ".", "mercatorToLatLng", "(", "{", "x", ":", "(", "swPoint", "[", "0", "]", "+", "nePoint", "[", "0", "]", ")", "*", "0.5", ",", "y", ":", "(", "swPoint", "[", "1", "]", "+", "nePoint", "[", "1", "]", ")", "*", "0.5", "}", ",", "z", ")", ";", "this", ".", "set", "(", "{", "center", ":", "center", ",", "zoom", ":", "z", "}", ")", "}" ]
set center and zoom according to fit bounds
[ "set", "center", "and", "zoom", "according", "to", "fit", "bounds" ]
61d11c6268d59343746809639e0d23419674ae87
https://github.com/knownasilya/ember-leaflet-cartodb/blob/61d11c6268d59343746809639e0d23419674ae87/vendor/ember-leaflet-cartodb/cartodb_noleaflet.js#L18392-L18410
47,818
knownasilya/ember-leaflet-cartodb
vendor/ember-leaflet-cartodb/cartodb_noleaflet.js
function(boundsSWNE, mapSize) { // sometimes the map reports size = 0 so return null if(mapSize.x === 0 || mapSize.y === 0) return null; var size = [mapSize.x, mapSize.y], zoom = this.get('minZoom') || 0, maxZoom = this.get('maxZoom') || 24, ne = boundsSWNE[1], sw = boundsSWNE[0], boundsSize = [], nePoint, swPoint, zoomNotFound = true; do { zoom++; nePoint = cdb.geo.Map.latlngToMercator(ne, zoom); swPoint = cdb.geo.Map.latlngToMercator(sw, zoom); boundsSize[0] = Math.abs(nePoint[0] - swPoint[0]); boundsSize[1] = Math.abs(swPoint[1] - nePoint[1]); zoomNotFound = boundsSize[0] <= size[0] || boundsSize[1] <= size[1]; } while (zoomNotFound && zoom <= maxZoom); if (zoomNotFound) { return maxZoom; } return zoom - 1; }
javascript
function(boundsSWNE, mapSize) { // sometimes the map reports size = 0 so return null if(mapSize.x === 0 || mapSize.y === 0) return null; var size = [mapSize.x, mapSize.y], zoom = this.get('minZoom') || 0, maxZoom = this.get('maxZoom') || 24, ne = boundsSWNE[1], sw = boundsSWNE[0], boundsSize = [], nePoint, swPoint, zoomNotFound = true; do { zoom++; nePoint = cdb.geo.Map.latlngToMercator(ne, zoom); swPoint = cdb.geo.Map.latlngToMercator(sw, zoom); boundsSize[0] = Math.abs(nePoint[0] - swPoint[0]); boundsSize[1] = Math.abs(swPoint[1] - nePoint[1]); zoomNotFound = boundsSize[0] <= size[0] || boundsSize[1] <= size[1]; } while (zoomNotFound && zoom <= maxZoom); if (zoomNotFound) { return maxZoom; } return zoom - 1; }
[ "function", "(", "boundsSWNE", ",", "mapSize", ")", "{", "// sometimes the map reports size = 0 so return null", "if", "(", "mapSize", ".", "x", "===", "0", "||", "mapSize", ".", "y", "===", "0", ")", "return", "null", ";", "var", "size", "=", "[", "mapSize", ".", "x", ",", "mapSize", ".", "y", "]", ",", "zoom", "=", "this", ".", "get", "(", "'minZoom'", ")", "||", "0", ",", "maxZoom", "=", "this", ".", "get", "(", "'maxZoom'", ")", "||", "24", ",", "ne", "=", "boundsSWNE", "[", "1", "]", ",", "sw", "=", "boundsSWNE", "[", "0", "]", ",", "boundsSize", "=", "[", "]", ",", "nePoint", ",", "swPoint", ",", "zoomNotFound", "=", "true", ";", "do", "{", "zoom", "++", ";", "nePoint", "=", "cdb", ".", "geo", ".", "Map", ".", "latlngToMercator", "(", "ne", ",", "zoom", ")", ";", "swPoint", "=", "cdb", ".", "geo", ".", "Map", ".", "latlngToMercator", "(", "sw", ",", "zoom", ")", ";", "boundsSize", "[", "0", "]", "=", "Math", ".", "abs", "(", "nePoint", "[", "0", "]", "-", "swPoint", "[", "0", "]", ")", ";", "boundsSize", "[", "1", "]", "=", "Math", ".", "abs", "(", "swPoint", "[", "1", "]", "-", "nePoint", "[", "1", "]", ")", ";", "zoomNotFound", "=", "boundsSize", "[", "0", "]", "<=", "size", "[", "0", "]", "||", "boundsSize", "[", "1", "]", "<=", "size", "[", "1", "]", ";", "}", "while", "(", "zoomNotFound", "&&", "zoom", "<=", "maxZoom", ")", ";", "if", "(", "zoomNotFound", ")", "{", "return", "maxZoom", ";", "}", "return", "zoom", "-", "1", ";", "}" ]
adapted from leaflat src @return {Number, null} Calculated zoom from given bounds or the maxZoom if no appropriate zoom level could be found or null if given mapSize has no size.
[ "adapted", "from", "leaflat", "src" ]
61d11c6268d59343746809639e0d23419674ae87
https://github.com/knownasilya/ember-leaflet-cartodb/blob/61d11c6268d59343746809639e0d23419674ae87/vendor/ember-leaflet-cartodb/cartodb_noleaflet.js#L18415-L18442
47,819
knownasilya/ember-leaflet-cartodb
vendor/ember-leaflet-cartodb/cartodb_noleaflet.js
function() { var result = []; for (var s in this._subviews) { if(this._subviews[s] instanceof cdb.geo.ui.Infowindow) { result.push(this._subviews[s]); } } return result; }
javascript
function() { var result = []; for (var s in this._subviews) { if(this._subviews[s] instanceof cdb.geo.ui.Infowindow) { result.push(this._subviews[s]); } } return result; }
[ "function", "(", ")", "{", "var", "result", "=", "[", "]", ";", "for", "(", "var", "s", "in", "this", ".", "_subviews", ")", "{", "if", "(", "this", ".", "_subviews", "[", "s", "]", "instanceof", "cdb", ".", "geo", ".", "ui", ".", "Infowindow", ")", "{", "result", ".", "push", "(", "this", ".", "_subviews", "[", "s", "]", ")", ";", "}", "}", "return", "result", ";", "}" ]
search in the subviews and return the infowindows
[ "search", "in", "the", "subviews", "and", "return", "the", "infowindows" ]
61d11c6268d59343746809639e0d23419674ae87
https://github.com/knownasilya/ember-leaflet-cartodb/blob/61d11c6268d59343746809639e0d23419674ae87/vendor/ember-leaflet-cartodb/cartodb_noleaflet.js#L18503-L18511
47,820
knownasilya/ember-leaflet-cartodb
vendor/ember-leaflet-cartodb/cartodb_noleaflet.js
function() { this._unbindModel(); this.map.bind('change:view_bounds_sw', this._changeBounds, this); this.map.bind('change:view_bounds_ne', this._changeBounds, this); this.map.bind('change:zoom', this._setZoom, this); this.map.bind('change:scrollwheel', this._setScrollWheel, this); this.map.bind('change:keyboard', this._setKeyboard, this); this.map.bind('change:center', this._setCenter, this); this.map.bind('change:attribution', this.setAttribution, this); }
javascript
function() { this._unbindModel(); this.map.bind('change:view_bounds_sw', this._changeBounds, this); this.map.bind('change:view_bounds_ne', this._changeBounds, this); this.map.bind('change:zoom', this._setZoom, this); this.map.bind('change:scrollwheel', this._setScrollWheel, this); this.map.bind('change:keyboard', this._setKeyboard, this); this.map.bind('change:center', this._setCenter, this); this.map.bind('change:attribution', this.setAttribution, this); }
[ "function", "(", ")", "{", "this", ".", "_unbindModel", "(", ")", ";", "this", ".", "map", ".", "bind", "(", "'change:view_bounds_sw'", ",", "this", ".", "_changeBounds", ",", "this", ")", ";", "this", ".", "map", ".", "bind", "(", "'change:view_bounds_ne'", ",", "this", ".", "_changeBounds", ",", "this", ")", ";", "this", ".", "map", ".", "bind", "(", "'change:zoom'", ",", "this", ".", "_setZoom", ",", "this", ")", ";", "this", ".", "map", ".", "bind", "(", "'change:scrollwheel'", ",", "this", ".", "_setScrollWheel", ",", "this", ")", ";", "this", ".", "map", ".", "bind", "(", "'change:keyboard'", ",", "this", ".", "_setKeyboard", ",", "this", ")", ";", "this", ".", "map", ".", "bind", "(", "'change:center'", ",", "this", ".", "_setCenter", ",", "this", ")", ";", "this", ".", "map", ".", "bind", "(", "'change:attribution'", ",", "this", ".", "setAttribution", ",", "this", ")", ";", "}" ]
bind model properties
[ "bind", "model", "properties" ]
61d11c6268d59343746809639e0d23419674ae87
https://github.com/knownasilya/ember-leaflet-cartodb/blob/61d11c6268d59343746809639e0d23419674ae87/vendor/ember-leaflet-cartodb/cartodb_noleaflet.js#L18544-L18553
47,821
knownasilya/ember-leaflet-cartodb
vendor/ember-leaflet-cartodb/cartodb_noleaflet.js
function() { this.map.unbind('change:view_bounds_sw', null, this); this.map.unbind('change:view_bounds_ne', null, this); this.map.unbind('change:zoom', null, this); this.map.unbind('change:scrollwheel', null, this); this.map.unbind('change:keyboard', null, this); this.map.unbind('change:center', null, this); this.map.unbind('change:attribution', null, this); }
javascript
function() { this.map.unbind('change:view_bounds_sw', null, this); this.map.unbind('change:view_bounds_ne', null, this); this.map.unbind('change:zoom', null, this); this.map.unbind('change:scrollwheel', null, this); this.map.unbind('change:keyboard', null, this); this.map.unbind('change:center', null, this); this.map.unbind('change:attribution', null, this); }
[ "function", "(", ")", "{", "this", ".", "map", ".", "unbind", "(", "'change:view_bounds_sw'", ",", "null", ",", "this", ")", ";", "this", ".", "map", ".", "unbind", "(", "'change:view_bounds_ne'", ",", "null", ",", "this", ")", ";", "this", ".", "map", ".", "unbind", "(", "'change:zoom'", ",", "null", ",", "this", ")", ";", "this", ".", "map", ".", "unbind", "(", "'change:scrollwheel'", ",", "null", ",", "this", ")", ";", "this", ".", "map", ".", "unbind", "(", "'change:keyboard'", ",", "null", ",", "this", ")", ";", "this", ".", "map", ".", "unbind", "(", "'change:center'", ",", "null", ",", "this", ")", ";", "this", ".", "map", ".", "unbind", "(", "'change:attribution'", ",", "null", ",", "this", ")", ";", "}" ]
unbind model properties
[ "unbind", "model", "properties" ]
61d11c6268d59343746809639e0d23419674ae87
https://github.com/knownasilya/ember-leaflet-cartodb/blob/61d11c6268d59343746809639e0d23419674ae87/vendor/ember-leaflet-cartodb/cartodb_noleaflet.js#L18556-L18564
47,822
knownasilya/ember-leaflet-cartodb
vendor/ember-leaflet-cartodb/cartodb_noleaflet.js
function(attributes) { var fields = this.get('fields'); this.set('content', cdb.geo.ui.InfowindowModel.contentForFields(attributes, fields)); }
javascript
function(attributes) { var fields = this.get('fields'); this.set('content', cdb.geo.ui.InfowindowModel.contentForFields(attributes, fields)); }
[ "function", "(", "attributes", ")", "{", "var", "fields", "=", "this", ".", "get", "(", "'fields'", ")", ";", "this", ".", "set", "(", "'content'", ",", "cdb", ".", "geo", ".", "ui", ".", "InfowindowModel", ".", "contentForFields", "(", "attributes", ",", "fields", ")", ")", ";", "}" ]
updates content with attributes
[ "updates", "content", "with", "attributes" ]
61d11c6268d59343746809639e0d23419674ae87
https://github.com/knownasilya/ember-leaflet-cartodb/blob/61d11c6268d59343746809639e0d23419674ae87/vendor/ember-leaflet-cartodb/cartodb_noleaflet.js#L21115-L21118
47,823
knownasilya/ember-leaflet-cartodb
vendor/ember-leaflet-cartodb/cartodb_noleaflet.js
function() { if(this.template) { // If there is content, destroy the jscrollpane first, then remove the content. var $jscrollpane = this.$(".cartodb-popup-content"); if ($jscrollpane.length > 0 && $jscrollpane.data() != null) { $jscrollpane.data().jsp && $jscrollpane.data().jsp.destroy(); } // Clone fields and template name var fields = _.map(this.model.attributes.content.fields, function(field){ return _.clone(field); }); var data = this.model.get('content') ? this.model.get('content').data : {}; // If a custom template is not applied, let's sanitized // fields for the template rendering if (this.model.get('template_name')) { var template_name = _.clone(this.model.attributes.template_name); // Sanitized them fields = this._fieldsToString(fields, template_name); } // Join plan fields values with content to work with // custom infowindows and CartoDB infowindows. var values = {}; _.each(this.model.get('content').fields, function(pair) { values[pair.title] = pair.value; }) var obj = _.extend({ content: { fields: fields, data: data } },values); this.$el.html( cdb.core.sanitize.html(this.template(obj), this.model.get('sanitizeTemplate')) ); // Set width and max-height from the model only // If there is no width set, we don't force our infowindow if (this.model.get('width')) { this.$('.cartodb-popup').css('width', this.model.get('width') + 'px'); } this.$('.cartodb-popup .cartodb-popup-content').css('max-height', this.model.get('maxHeight') + 'px'); // Hello jscrollpane hacks! // It needs some time to initialize, if not it doesn't render properly the fields // Check the height of the content + the header if exists var self = this; setTimeout(function() { var actual_height = self.$(".cartodb-popup-content").outerHeight(); if (self.model.get('maxHeight') <= actual_height) self.$(".cartodb-popup-content").jScrollPane({ verticalDragMinHeight: 20, autoReinitialise: true }); }, 1); // If the infowindow is loading, show spin this._checkLoading(); // If the template is 'cover-enabled', load the cover this._loadCover(); if(!this.isLoadingData()) { this.model.trigger('domready', this, this.$el); this.trigger('domready', this, this.$el); } } return this; }
javascript
function() { if(this.template) { // If there is content, destroy the jscrollpane first, then remove the content. var $jscrollpane = this.$(".cartodb-popup-content"); if ($jscrollpane.length > 0 && $jscrollpane.data() != null) { $jscrollpane.data().jsp && $jscrollpane.data().jsp.destroy(); } // Clone fields and template name var fields = _.map(this.model.attributes.content.fields, function(field){ return _.clone(field); }); var data = this.model.get('content') ? this.model.get('content').data : {}; // If a custom template is not applied, let's sanitized // fields for the template rendering if (this.model.get('template_name')) { var template_name = _.clone(this.model.attributes.template_name); // Sanitized them fields = this._fieldsToString(fields, template_name); } // Join plan fields values with content to work with // custom infowindows and CartoDB infowindows. var values = {}; _.each(this.model.get('content').fields, function(pair) { values[pair.title] = pair.value; }) var obj = _.extend({ content: { fields: fields, data: data } },values); this.$el.html( cdb.core.sanitize.html(this.template(obj), this.model.get('sanitizeTemplate')) ); // Set width and max-height from the model only // If there is no width set, we don't force our infowindow if (this.model.get('width')) { this.$('.cartodb-popup').css('width', this.model.get('width') + 'px'); } this.$('.cartodb-popup .cartodb-popup-content').css('max-height', this.model.get('maxHeight') + 'px'); // Hello jscrollpane hacks! // It needs some time to initialize, if not it doesn't render properly the fields // Check the height of the content + the header if exists var self = this; setTimeout(function() { var actual_height = self.$(".cartodb-popup-content").outerHeight(); if (self.model.get('maxHeight') <= actual_height) self.$(".cartodb-popup-content").jScrollPane({ verticalDragMinHeight: 20, autoReinitialise: true }); }, 1); // If the infowindow is loading, show spin this._checkLoading(); // If the template is 'cover-enabled', load the cover this._loadCover(); if(!this.isLoadingData()) { this.model.trigger('domready', this, this.$el); this.trigger('domready', this, this.$el); } } return this; }
[ "function", "(", ")", "{", "if", "(", "this", ".", "template", ")", "{", "// If there is content, destroy the jscrollpane first, then remove the content.", "var", "$jscrollpane", "=", "this", ".", "$", "(", "\".cartodb-popup-content\"", ")", ";", "if", "(", "$jscrollpane", ".", "length", ">", "0", "&&", "$jscrollpane", ".", "data", "(", ")", "!=", "null", ")", "{", "$jscrollpane", ".", "data", "(", ")", ".", "jsp", "&&", "$jscrollpane", ".", "data", "(", ")", ".", "jsp", ".", "destroy", "(", ")", ";", "}", "// Clone fields and template name", "var", "fields", "=", "_", ".", "map", "(", "this", ".", "model", ".", "attributes", ".", "content", ".", "fields", ",", "function", "(", "field", ")", "{", "return", "_", ".", "clone", "(", "field", ")", ";", "}", ")", ";", "var", "data", "=", "this", ".", "model", ".", "get", "(", "'content'", ")", "?", "this", ".", "model", ".", "get", "(", "'content'", ")", ".", "data", ":", "{", "}", ";", "// If a custom template is not applied, let's sanitized", "// fields for the template rendering", "if", "(", "this", ".", "model", ".", "get", "(", "'template_name'", ")", ")", "{", "var", "template_name", "=", "_", ".", "clone", "(", "this", ".", "model", ".", "attributes", ".", "template_name", ")", ";", "// Sanitized them", "fields", "=", "this", ".", "_fieldsToString", "(", "fields", ",", "template_name", ")", ";", "}", "// Join plan fields values with content to work with", "// custom infowindows and CartoDB infowindows.", "var", "values", "=", "{", "}", ";", "_", ".", "each", "(", "this", ".", "model", ".", "get", "(", "'content'", ")", ".", "fields", ",", "function", "(", "pair", ")", "{", "values", "[", "pair", ".", "title", "]", "=", "pair", ".", "value", ";", "}", ")", "var", "obj", "=", "_", ".", "extend", "(", "{", "content", ":", "{", "fields", ":", "fields", ",", "data", ":", "data", "}", "}", ",", "values", ")", ";", "this", ".", "$el", ".", "html", "(", "cdb", ".", "core", ".", "sanitize", ".", "html", "(", "this", ".", "template", "(", "obj", ")", ",", "this", ".", "model", ".", "get", "(", "'sanitizeTemplate'", ")", ")", ")", ";", "// Set width and max-height from the model only", "// If there is no width set, we don't force our infowindow", "if", "(", "this", ".", "model", ".", "get", "(", "'width'", ")", ")", "{", "this", ".", "$", "(", "'.cartodb-popup'", ")", ".", "css", "(", "'width'", ",", "this", ".", "model", ".", "get", "(", "'width'", ")", "+", "'px'", ")", ";", "}", "this", ".", "$", "(", "'.cartodb-popup .cartodb-popup-content'", ")", ".", "css", "(", "'max-height'", ",", "this", ".", "model", ".", "get", "(", "'maxHeight'", ")", "+", "'px'", ")", ";", "// Hello jscrollpane hacks!", "// It needs some time to initialize, if not it doesn't render properly the fields", "// Check the height of the content + the header if exists", "var", "self", "=", "this", ";", "setTimeout", "(", "function", "(", ")", "{", "var", "actual_height", "=", "self", ".", "$", "(", "\".cartodb-popup-content\"", ")", ".", "outerHeight", "(", ")", ";", "if", "(", "self", ".", "model", ".", "get", "(", "'maxHeight'", ")", "<=", "actual_height", ")", "self", ".", "$", "(", "\".cartodb-popup-content\"", ")", ".", "jScrollPane", "(", "{", "verticalDragMinHeight", ":", "20", ",", "autoReinitialise", ":", "true", "}", ")", ";", "}", ",", "1", ")", ";", "// If the infowindow is loading, show spin", "this", ".", "_checkLoading", "(", ")", ";", "// If the template is 'cover-enabled', load the cover", "this", ".", "_loadCover", "(", ")", ";", "if", "(", "!", "this", ".", "isLoadingData", "(", ")", ")", "{", "this", ".", "model", ".", "trigger", "(", "'domready'", ",", "this", ",", "this", ".", "$el", ")", ";", "this", ".", "trigger", "(", "'domready'", ",", "this", ",", "this", ".", "$el", ")", ";", "}", "}", "return", "this", ";", "}" ]
Render infowindow content
[ "Render", "infowindow", "content" ]
61d11c6268d59343746809639e0d23419674ae87
https://github.com/knownasilya/ember-leaflet-cartodb/blob/61d11c6268d59343746809639e0d23419674ae87/vendor/ember-leaflet-cartodb/cartodb_noleaflet.js#L21236-L21312
47,824
knownasilya/ember-leaflet-cartodb
vendor/ember-leaflet-cartodb/cartodb_noleaflet.js
function() { var template = this.model.get('template') ? this.model.get('template') : cdb.templates.getTemplate(this._getModelTemplate()); if(typeof(template) !== 'function') { this.template = new cdb.core.Template({ template: template, type: this.model.get('template_type') || 'mustache' }).asFunction() } else { this.template = template } this.render(); }
javascript
function() { var template = this.model.get('template') ? this.model.get('template') : cdb.templates.getTemplate(this._getModelTemplate()); if(typeof(template) !== 'function') { this.template = new cdb.core.Template({ template: template, type: this.model.get('template_type') || 'mustache' }).asFunction() } else { this.template = template } this.render(); }
[ "function", "(", ")", "{", "var", "template", "=", "this", ".", "model", ".", "get", "(", "'template'", ")", "?", "this", ".", "model", ".", "get", "(", "'template'", ")", ":", "cdb", ".", "templates", ".", "getTemplate", "(", "this", ".", "_getModelTemplate", "(", ")", ")", ";", "if", "(", "typeof", "(", "template", ")", "!==", "'function'", ")", "{", "this", ".", "template", "=", "new", "cdb", ".", "core", ".", "Template", "(", "{", "template", ":", "template", ",", "type", ":", "this", ".", "model", ".", "get", "(", "'template_type'", ")", "||", "'mustache'", "}", ")", ".", "asFunction", "(", ")", "}", "else", "{", "this", ".", "template", "=", "template", "}", "this", ".", "render", "(", ")", ";", "}" ]
Compile template of the infowindow
[ "Compile", "template", "of", "the", "infowindow" ]
61d11c6268d59343746809639e0d23419674ae87
https://github.com/knownasilya/ember-leaflet-cartodb/blob/61d11c6268d59343746809639e0d23419674ae87/vendor/ember-leaflet-cartodb/cartodb_noleaflet.js#L21331-L21346
47,825
knownasilya/ember-leaflet-cartodb
vendor/ember-leaflet-cartodb/cartodb_noleaflet.js
function(ev) { // If the mouse down come from jspVerticalBar // dont stop the propagation, but if the event // is a touchstart, stop the propagation var come_from_scroll = (($(ev.target).closest(".jspVerticalBar").length > 0) && (ev.type != "touchstart")); if (!come_from_scroll) { ev.stopPropagation(); } }
javascript
function(ev) { // If the mouse down come from jspVerticalBar // dont stop the propagation, but if the event // is a touchstart, stop the propagation var come_from_scroll = (($(ev.target).closest(".jspVerticalBar").length > 0) && (ev.type != "touchstart")); if (!come_from_scroll) { ev.stopPropagation(); } }
[ "function", "(", "ev", ")", "{", "// If the mouse down come from jspVerticalBar", "// dont stop the propagation, but if the event", "// is a touchstart, stop the propagation", "var", "come_from_scroll", "=", "(", "(", "$", "(", "ev", ".", "target", ")", ".", "closest", "(", "\".jspVerticalBar\"", ")", ".", "length", ">", "0", ")", "&&", "(", "ev", ".", "type", "!=", "\"touchstart\"", ")", ")", ";", "if", "(", "!", "come_from_scroll", ")", "{", "ev", ".", "stopPropagation", "(", ")", ";", "}", "}" ]
Check event origin
[ "Check", "event", "origin" ]
61d11c6268d59343746809639e0d23419674ae87
https://github.com/knownasilya/ember-leaflet-cartodb/blob/61d11c6268d59343746809639e0d23419674ae87/vendor/ember-leaflet-cartodb/cartodb_noleaflet.js#L21351-L21360
47,826
knownasilya/ember-leaflet-cartodb
vendor/ember-leaflet-cartodb/cartodb_noleaflet.js
function(fields, template_name) { var fields_sanitized = []; if (fields && fields.length > 0) { var self = this; fields_sanitized = _.map(fields, function(field,i) { // Return whole attribute sanitized return self._sanitizeField(field, template_name, field.index || i); }); } return fields_sanitized; }
javascript
function(fields, template_name) { var fields_sanitized = []; if (fields && fields.length > 0) { var self = this; fields_sanitized = _.map(fields, function(field,i) { // Return whole attribute sanitized return self._sanitizeField(field, template_name, field.index || i); }); } return fields_sanitized; }
[ "function", "(", "fields", ",", "template_name", ")", "{", "var", "fields_sanitized", "=", "[", "]", ";", "if", "(", "fields", "&&", "fields", ".", "length", ">", "0", ")", "{", "var", "self", "=", "this", ";", "fields_sanitized", "=", "_", ".", "map", "(", "fields", ",", "function", "(", "field", ",", "i", ")", "{", "// Return whole attribute sanitized", "return", "self", ".", "_sanitizeField", "(", "field", ",", "template_name", ",", "field", ".", "index", "||", "i", ")", ";", "}", ")", ";", "}", "return", "fields_sanitized", ";", "}" ]
Convert values to string unless value is NULL
[ "Convert", "values", "to", "string", "unless", "value", "is", "NULL" ]
61d11c6268d59343746809639e0d23419674ae87
https://github.com/knownasilya/ember-leaflet-cartodb/blob/61d11c6268d59343746809639e0d23419674ae87/vendor/ember-leaflet-cartodb/cartodb_noleaflet.js#L21365-L21375
47,827
knownasilya/ember-leaflet-cartodb
vendor/ember-leaflet-cartodb/cartodb_noleaflet.js
function($el) { this._stopSpinner(); var $el = this.$el.find('.loading'); if ($el) { // Check if it is dark or other to change color var template_dark = this.model.get('template_name').search('dark') != -1; if (template_dark) { this.spin_options.color = '#FFF'; } else { this.spin_options.color = 'rgba(0,0,0,0.5)'; } this.spinner = new Spinner(this.spin_options).spin(); $el.append(this.spinner.el); } }
javascript
function($el) { this._stopSpinner(); var $el = this.$el.find('.loading'); if ($el) { // Check if it is dark or other to change color var template_dark = this.model.get('template_name').search('dark') != -1; if (template_dark) { this.spin_options.color = '#FFF'; } else { this.spin_options.color = 'rgba(0,0,0,0.5)'; } this.spinner = new Spinner(this.spin_options).spin(); $el.append(this.spinner.el); } }
[ "function", "(", "$el", ")", "{", "this", ".", "_stopSpinner", "(", ")", ";", "var", "$el", "=", "this", ".", "$el", ".", "find", "(", "'.loading'", ")", ";", "if", "(", "$el", ")", "{", "// Check if it is dark or other to change color", "var", "template_dark", "=", "this", ".", "model", ".", "get", "(", "'template_name'", ")", ".", "search", "(", "'dark'", ")", "!=", "-", "1", ";", "if", "(", "template_dark", ")", "{", "this", ".", "spin_options", ".", "color", "=", "'#FFF'", ";", "}", "else", "{", "this", ".", "spin_options", ".", "color", "=", "'rgba(0,0,0,0.5)'", ";", "}", "this", ".", "spinner", "=", "new", "Spinner", "(", "this", ".", "spin_options", ")", ".", "spin", "(", ")", ";", "$el", ".", "append", "(", "this", ".", "spinner", ".", "el", ")", ";", "}", "}" ]
Start loading spinner
[ "Start", "loading", "spinner" ]
61d11c6268d59343746809639e0d23419674ae87
https://github.com/knownasilya/ember-leaflet-cartodb/blob/61d11c6268d59343746809639e0d23419674ae87/vendor/ember-leaflet-cartodb/cartodb_noleaflet.js#L21458-L21476
47,828
knownasilya/ember-leaflet-cartodb
vendor/ember-leaflet-cartodb/cartodb_noleaflet.js
function() { var content = this.model.get("content"); if (content && content.fields && content.fields.length > 0) { return (content.fields[0].value || '').toString(); } return false; }
javascript
function() { var content = this.model.get("content"); if (content && content.fields && content.fields.length > 0) { return (content.fields[0].value || '').toString(); } return false; }
[ "function", "(", ")", "{", "var", "content", "=", "this", ".", "model", ".", "get", "(", "\"content\"", ")", ";", "if", "(", "content", "&&", "content", ".", "fields", "&&", "content", ".", "fields", ".", "length", ">", "0", ")", "{", "return", "(", "content", ".", "fields", "[", "0", "]", ".", "value", "||", "''", ")", ".", "toString", "(", ")", ";", "}", "return", "false", ";", "}" ]
Get cover URL
[ "Get", "cover", "URL" ]
61d11c6268d59343746809639e0d23419674ae87
https://github.com/knownasilya/ember-leaflet-cartodb/blob/61d11c6268d59343746809639e0d23419674ae87/vendor/ember-leaflet-cartodb/cartodb_noleaflet.js#L21489-L21497
47,829
knownasilya/ember-leaflet-cartodb
vendor/ember-leaflet-cartodb/cartodb_noleaflet.js
function() { if (!this._containsCover()) return; var self = this; var $cover = this.$(".cover"); var $img = $cover.find("img"); var $shadow = this.$(".shadow"); var url = this._getCoverURL(); if (!this._isValidURL(url)) { $img.hide(); $shadow.hide(); cdb.log.info("Header image url not valid"); return; } // configure spinner var target = document.getElementById('spinner'); var opts = { lines: 9, length: 4, width: 2, radius: 4, corners: 1, rotate: 0, color: '#ccc', speed: 1, trail: 60, shadow: true, hwaccel: false, zIndex: 2e9 }; var spinner = new Spinner(opts).spin(target); // create the image $img.hide(function() { this.remove(); }); $img = $("<img />").attr("src", url); $cover.append($img); $img.load(function(){ spinner.stop(); var w = $img.width(); var h = $img.height(); var coverWidth = $cover.width(); var coverHeight = $cover.height(); var ratio = h / w; var coverRatio = coverHeight / coverWidth; // Resize rules if ( w > coverWidth && h > coverHeight) { // bigger image if ( ratio < coverRatio ) $img.css({ height: coverHeight }); else { var calculatedHeight = h / (w / coverWidth); $img.css({ width: coverWidth, top: "50%", position: "absolute", "margin-top": -1*parseInt(calculatedHeight, 10)/2 }); } } else { var calculatedHeight = h / (w / coverWidth); $img.css({ width: coverWidth, top: "50%", position: "absolute", "margin-top": -1*parseInt(calculatedHeight, 10)/2 }); } $img.fadeIn(300); }) .error(function(){ spinner.stop(); }); }
javascript
function() { if (!this._containsCover()) return; var self = this; var $cover = this.$(".cover"); var $img = $cover.find("img"); var $shadow = this.$(".shadow"); var url = this._getCoverURL(); if (!this._isValidURL(url)) { $img.hide(); $shadow.hide(); cdb.log.info("Header image url not valid"); return; } // configure spinner var target = document.getElementById('spinner'); var opts = { lines: 9, length: 4, width: 2, radius: 4, corners: 1, rotate: 0, color: '#ccc', speed: 1, trail: 60, shadow: true, hwaccel: false, zIndex: 2e9 }; var spinner = new Spinner(opts).spin(target); // create the image $img.hide(function() { this.remove(); }); $img = $("<img />").attr("src", url); $cover.append($img); $img.load(function(){ spinner.stop(); var w = $img.width(); var h = $img.height(); var coverWidth = $cover.width(); var coverHeight = $cover.height(); var ratio = h / w; var coverRatio = coverHeight / coverWidth; // Resize rules if ( w > coverWidth && h > coverHeight) { // bigger image if ( ratio < coverRatio ) $img.css({ height: coverHeight }); else { var calculatedHeight = h / (w / coverWidth); $img.css({ width: coverWidth, top: "50%", position: "absolute", "margin-top": -1*parseInt(calculatedHeight, 10)/2 }); } } else { var calculatedHeight = h / (w / coverWidth); $img.css({ width: coverWidth, top: "50%", position: "absolute", "margin-top": -1*parseInt(calculatedHeight, 10)/2 }); } $img.fadeIn(300); }) .error(function(){ spinner.stop(); }); }
[ "function", "(", ")", "{", "if", "(", "!", "this", ".", "_containsCover", "(", ")", ")", "return", ";", "var", "self", "=", "this", ";", "var", "$cover", "=", "this", ".", "$", "(", "\".cover\"", ")", ";", "var", "$img", "=", "$cover", ".", "find", "(", "\"img\"", ")", ";", "var", "$shadow", "=", "this", ".", "$", "(", "\".shadow\"", ")", ";", "var", "url", "=", "this", ".", "_getCoverURL", "(", ")", ";", "if", "(", "!", "this", ".", "_isValidURL", "(", "url", ")", ")", "{", "$img", ".", "hide", "(", ")", ";", "$shadow", ".", "hide", "(", ")", ";", "cdb", ".", "log", ".", "info", "(", "\"Header image url not valid\"", ")", ";", "return", ";", "}", "// configure spinner", "var", "target", "=", "document", ".", "getElementById", "(", "'spinner'", ")", ";", "var", "opts", "=", "{", "lines", ":", "9", ",", "length", ":", "4", ",", "width", ":", "2", ",", "radius", ":", "4", ",", "corners", ":", "1", ",", "rotate", ":", "0", ",", "color", ":", "'#ccc'", ",", "speed", ":", "1", ",", "trail", ":", "60", ",", "shadow", ":", "true", ",", "hwaccel", ":", "false", ",", "zIndex", ":", "2e9", "}", ";", "var", "spinner", "=", "new", "Spinner", "(", "opts", ")", ".", "spin", "(", "target", ")", ";", "// create the image", "$img", ".", "hide", "(", "function", "(", ")", "{", "this", ".", "remove", "(", ")", ";", "}", ")", ";", "$img", "=", "$", "(", "\"<img />\"", ")", ".", "attr", "(", "\"src\"", ",", "url", ")", ";", "$cover", ".", "append", "(", "$img", ")", ";", "$img", ".", "load", "(", "function", "(", ")", "{", "spinner", ".", "stop", "(", ")", ";", "var", "w", "=", "$img", ".", "width", "(", ")", ";", "var", "h", "=", "$img", ".", "height", "(", ")", ";", "var", "coverWidth", "=", "$cover", ".", "width", "(", ")", ";", "var", "coverHeight", "=", "$cover", ".", "height", "(", ")", ";", "var", "ratio", "=", "h", "/", "w", ";", "var", "coverRatio", "=", "coverHeight", "/", "coverWidth", ";", "// Resize rules", "if", "(", "w", ">", "coverWidth", "&&", "h", ">", "coverHeight", ")", "{", "// bigger image", "if", "(", "ratio", "<", "coverRatio", ")", "$img", ".", "css", "(", "{", "height", ":", "coverHeight", "}", ")", ";", "else", "{", "var", "calculatedHeight", "=", "h", "/", "(", "w", "/", "coverWidth", ")", ";", "$img", ".", "css", "(", "{", "width", ":", "coverWidth", ",", "top", ":", "\"50%\"", ",", "position", ":", "\"absolute\"", ",", "\"margin-top\"", ":", "-", "1", "*", "parseInt", "(", "calculatedHeight", ",", "10", ")", "/", "2", "}", ")", ";", "}", "}", "else", "{", "var", "calculatedHeight", "=", "h", "/", "(", "w", "/", "coverWidth", ")", ";", "$img", ".", "css", "(", "{", "width", ":", "coverWidth", ",", "top", ":", "\"50%\"", ",", "position", ":", "\"absolute\"", ",", "\"margin-top\"", ":", "-", "1", "*", "parseInt", "(", "calculatedHeight", ",", "10", ")", "/", "2", "}", ")", ";", "}", "$img", ".", "fadeIn", "(", "300", ")", ";", "}", ")", ".", "error", "(", "function", "(", ")", "{", "spinner", ".", "stop", "(", ")", ";", "}", ")", ";", "}" ]
Attempts to load the cover URL and show it
[ "Attempts", "to", "load", "the", "cover", "URL", "and", "show", "it" ]
61d11c6268d59343746809639e0d23419674ae87
https://github.com/knownasilya/ember-leaflet-cartodb/blob/61d11c6268d59343746809639e0d23419674ae87/vendor/ember-leaflet-cartodb/cartodb_noleaflet.js#L21502-L21561
47,830
knownasilya/ember-leaflet-cartodb
vendor/ember-leaflet-cartodb/cartodb_noleaflet.js
function(url) { if (url) { var urlPattern = /^(http|ftp|https):\/\/[\w-]+(\.[\w-]+)+([\w.,@?^=%&amp;:\/~+#-|]*[\w@?^=%&amp;\/~+#-])?$/ return String(url).match(urlPattern) != null ? true : false; } return false; }
javascript
function(url) { if (url) { var urlPattern = /^(http|ftp|https):\/\/[\w-]+(\.[\w-]+)+([\w.,@?^=%&amp;:\/~+#-|]*[\w@?^=%&amp;\/~+#-])?$/ return String(url).match(urlPattern) != null ? true : false; } return false; }
[ "function", "(", "url", ")", "{", "if", "(", "url", ")", "{", "var", "urlPattern", "=", "/", "^(http|ftp|https):\\/\\/[\\w-]+(\\.[\\w-]+)+([\\w.,@?^=%&amp;:\\/~+#-|]*[\\w@?^=%&amp;\\/~+#-])?$", "/", "return", "String", "(", "url", ")", ".", "match", "(", "urlPattern", ")", "!=", "null", "?", "true", ":", "false", ";", "}", "return", "false", ";", "}" ]
Return true if the provided URL is valid
[ "Return", "true", "if", "the", "provided", "URL", "is", "valid" ]
61d11c6268d59343746809639e0d23419674ae87
https://github.com/knownasilya/ember-leaflet-cartodb/blob/61d11c6268d59343746809639e0d23419674ae87/vendor/ember-leaflet-cartodb/cartodb_noleaflet.js#L21566-L21573
47,831
knownasilya/ember-leaflet-cartodb
vendor/ember-leaflet-cartodb/cartodb_noleaflet.js
function() { this.model.set({ content: { fields: [{ title: null, alternative_name: null, value: 'Loading content...', index: null, type: "loading" }], data: {} } }) return this; }
javascript
function() { this.model.set({ content: { fields: [{ title: null, alternative_name: null, value: 'Loading content...', index: null, type: "loading" }], data: {} } }) return this; }
[ "function", "(", ")", "{", "this", ".", "model", ".", "set", "(", "{", "content", ":", "{", "fields", ":", "[", "{", "title", ":", "null", ",", "alternative_name", ":", "null", ",", "value", ":", "'Loading content...'", ",", "index", ":", "null", ",", "type", ":", "\"loading\"", "}", "]", ",", "data", ":", "{", "}", "}", "}", ")", "return", "this", ";", "}" ]
Set loading state adding its content
[ "Set", "loading", "state", "adding", "its", "content" ]
61d11c6268d59343746809639e0d23419674ae87
https://github.com/knownasilya/ember-leaflet-cartodb/blob/61d11c6268d59343746809639e0d23419674ae87/vendor/ember-leaflet-cartodb/cartodb_noleaflet.js#L21600-L21614
47,832
knownasilya/ember-leaflet-cartodb
vendor/ember-leaflet-cartodb/cartodb_noleaflet.js
function(delay) { if (!cdb.core.util.ie || (cdb.core.util.browser.ie && cdb.core.util.browser.ie.version > 8)) { this.$el.css({ 'marginBottom':'-10px', 'display': 'block', 'visibility':'visible', opacity:0 }); this.$el .delay(delay) .animate({ opacity: 1, marginBottom: 0 },300); } else { this.$el.show(); } }
javascript
function(delay) { if (!cdb.core.util.ie || (cdb.core.util.browser.ie && cdb.core.util.browser.ie.version > 8)) { this.$el.css({ 'marginBottom':'-10px', 'display': 'block', 'visibility':'visible', opacity:0 }); this.$el .delay(delay) .animate({ opacity: 1, marginBottom: 0 },300); } else { this.$el.show(); } }
[ "function", "(", "delay", ")", "{", "if", "(", "!", "cdb", ".", "core", ".", "util", ".", "ie", "||", "(", "cdb", ".", "core", ".", "util", ".", "browser", ".", "ie", "&&", "cdb", ".", "core", ".", "util", ".", "browser", ".", "ie", ".", "version", ">", "8", ")", ")", "{", "this", ".", "$el", ".", "css", "(", "{", "'marginBottom'", ":", "'-10px'", ",", "'display'", ":", "'block'", ",", "'visibility'", ":", "'visible'", ",", "opacity", ":", "0", "}", ")", ";", "this", ".", "$el", ".", "delay", "(", "delay", ")", ".", "animate", "(", "{", "opacity", ":", "1", ",", "marginBottom", ":", "0", "}", ",", "300", ")", ";", "}", "else", "{", "this", ".", "$el", ".", "show", "(", ")", ";", "}", "}" ]
Animate infowindow to show up
[ "Animate", "infowindow", "to", "show", "up" ]
61d11c6268d59343746809639e0d23419674ae87
https://github.com/knownasilya/ember-leaflet-cartodb/blob/61d11c6268d59343746809639e0d23419674ae87/vendor/ember-leaflet-cartodb/cartodb_noleaflet.js#L21710-L21728
47,833
knownasilya/ember-leaflet-cartodb
vendor/ember-leaflet-cartodb/cartodb_noleaflet.js
function() { if (!$.browser.msie || ($.browser.msie && parseInt($.browser.version) > 8 )) { var self = this; this.$el.animate({ marginBottom: "-10px", opacity: "0", display: "block" }, 180, function() { self.$el.css({visibility: "hidden"}); }); } else { this.$el.hide(); } }
javascript
function() { if (!$.browser.msie || ($.browser.msie && parseInt($.browser.version) > 8 )) { var self = this; this.$el.animate({ marginBottom: "-10px", opacity: "0", display: "block" }, 180, function() { self.$el.css({visibility: "hidden"}); }); } else { this.$el.hide(); } }
[ "function", "(", ")", "{", "if", "(", "!", "$", ".", "browser", ".", "msie", "||", "(", "$", ".", "browser", ".", "msie", "&&", "parseInt", "(", "$", ".", "browser", ".", "version", ")", ">", "8", ")", ")", "{", "var", "self", "=", "this", ";", "this", ".", "$el", ".", "animate", "(", "{", "marginBottom", ":", "\"-10px\"", ",", "opacity", ":", "\"0\"", ",", "display", ":", "\"block\"", "}", ",", "180", ",", "function", "(", ")", "{", "self", ".", "$el", ".", "css", "(", "{", "visibility", ":", "\"hidden\"", "}", ")", ";", "}", ")", ";", "}", "else", "{", "this", ".", "$el", ".", "hide", "(", ")", ";", "}", "}" ]
Animate infowindow to disappear
[ "Animate", "infowindow", "to", "disappear" ]
61d11c6268d59343746809639e0d23419674ae87
https://github.com/knownasilya/ember-leaflet-cartodb/blob/61d11c6268d59343746809639e0d23419674ae87/vendor/ember-leaflet-cartodb/cartodb_noleaflet.js#L21733-L21746
47,834
knownasilya/ember-leaflet-cartodb
vendor/ember-leaflet-cartodb/cartodb_noleaflet.js
function () { var offset = this.model.get("offset"); if (!this.model.get("autoPan") || this.isHidden()) { return; } var x = this.$el.position().left, y = this.$el.position().top, containerHeight = this.$el.outerHeight(true) + 15, // Adding some more space containerWidth = this.$el.width(), pos = this.mapView.latLonToPixel(this.model.get("latlng")), adjustOffset = {x: 0, y: 0}; size = this.mapView.getSize() wait_callback = 0; if (pos.x - offset[0] < 0) { adjustOffset.x = pos.x - offset[0] - 10; } if (pos.x - offset[0] + containerWidth > size.x) { adjustOffset.x = pos.x + containerWidth - size.x - offset[0] + 10; } if (pos.y - containerHeight < 0) { adjustOffset.y = pos.y - containerHeight - 10; } if (pos.y - containerHeight > size.y) { adjustOffset.y = pos.y + containerHeight - size.y; } if (adjustOffset.x || adjustOffset.y) { this.mapView.panBy(adjustOffset); wait_callback = 300; } return wait_callback; }
javascript
function () { var offset = this.model.get("offset"); if (!this.model.get("autoPan") || this.isHidden()) { return; } var x = this.$el.position().left, y = this.$el.position().top, containerHeight = this.$el.outerHeight(true) + 15, // Adding some more space containerWidth = this.$el.width(), pos = this.mapView.latLonToPixel(this.model.get("latlng")), adjustOffset = {x: 0, y: 0}; size = this.mapView.getSize() wait_callback = 0; if (pos.x - offset[0] < 0) { adjustOffset.x = pos.x - offset[0] - 10; } if (pos.x - offset[0] + containerWidth > size.x) { adjustOffset.x = pos.x + containerWidth - size.x - offset[0] + 10; } if (pos.y - containerHeight < 0) { adjustOffset.y = pos.y - containerHeight - 10; } if (pos.y - containerHeight > size.y) { adjustOffset.y = pos.y + containerHeight - size.y; } if (adjustOffset.x || adjustOffset.y) { this.mapView.panBy(adjustOffset); wait_callback = 300; } return wait_callback; }
[ "function", "(", ")", "{", "var", "offset", "=", "this", ".", "model", ".", "get", "(", "\"offset\"", ")", ";", "if", "(", "!", "this", ".", "model", ".", "get", "(", "\"autoPan\"", ")", "||", "this", ".", "isHidden", "(", ")", ")", "{", "return", ";", "}", "var", "x", "=", "this", ".", "$el", ".", "position", "(", ")", ".", "left", ",", "y", "=", "this", ".", "$el", ".", "position", "(", ")", ".", "top", ",", "containerHeight", "=", "this", ".", "$el", ".", "outerHeight", "(", "true", ")", "+", "15", ",", "// Adding some more space", "containerWidth", "=", "this", ".", "$el", ".", "width", "(", ")", ",", "pos", "=", "this", ".", "mapView", ".", "latLonToPixel", "(", "this", ".", "model", ".", "get", "(", "\"latlng\"", ")", ")", ",", "adjustOffset", "=", "{", "x", ":", "0", ",", "y", ":", "0", "}", ";", "size", "=", "this", ".", "mapView", ".", "getSize", "(", ")", "wait_callback", "=", "0", ";", "if", "(", "pos", ".", "x", "-", "offset", "[", "0", "]", "<", "0", ")", "{", "adjustOffset", ".", "x", "=", "pos", ".", "x", "-", "offset", "[", "0", "]", "-", "10", ";", "}", "if", "(", "pos", ".", "x", "-", "offset", "[", "0", "]", "+", "containerWidth", ">", "size", ".", "x", ")", "{", "adjustOffset", ".", "x", "=", "pos", ".", "x", "+", "containerWidth", "-", "size", ".", "x", "-", "offset", "[", "0", "]", "+", "10", ";", "}", "if", "(", "pos", ".", "y", "-", "containerHeight", "<", "0", ")", "{", "adjustOffset", ".", "y", "=", "pos", ".", "y", "-", "containerHeight", "-", "10", ";", "}", "if", "(", "pos", ".", "y", "-", "containerHeight", ">", "size", ".", "y", ")", "{", "adjustOffset", ".", "y", "=", "pos", ".", "y", "+", "containerHeight", "-", "size", ".", "y", ";", "}", "if", "(", "adjustOffset", ".", "x", "||", "adjustOffset", ".", "y", ")", "{", "this", ".", "mapView", ".", "panBy", "(", "adjustOffset", ")", ";", "wait_callback", "=", "300", ";", "}", "return", "wait_callback", ";", "}" ]
Adjust pan to show correctly the infowindow
[ "Adjust", "pan", "to", "show", "correctly", "the", "infowindow" ]
61d11c6268d59343746809639e0d23419674ae87
https://github.com/knownasilya/ember-leaflet-cartodb/blob/61d11c6268d59343746809639e0d23419674ae87/vendor/ember-leaflet-cartodb/cartodb_noleaflet.js#L21771-L21808
47,835
knownasilya/ember-leaflet-cartodb
vendor/ember-leaflet-cartodb/cartodb_noleaflet.js
function(pos) { var props = {}; if(pos.indexOf('top') !== -1) { props.top = this.options.pos_margin; } else if(pos.indexOf('bottom') !== -1) { props.bottom = this.options.pos_margin; } if(pos.indexOf('left') !== -1) { props.left = this.options.pos_margin; } else if(pos.indexOf('right') !== -1) { props.right = this.options.pos_margin; } this.$el.css(props); }
javascript
function(pos) { var props = {}; if(pos.indexOf('top') !== -1) { props.top = this.options.pos_margin; } else if(pos.indexOf('bottom') !== -1) { props.bottom = this.options.pos_margin; } if(pos.indexOf('left') !== -1) { props.left = this.options.pos_margin; } else if(pos.indexOf('right') !== -1) { props.right = this.options.pos_margin; } this.$el.css(props); }
[ "function", "(", "pos", ")", "{", "var", "props", "=", "{", "}", ";", "if", "(", "pos", ".", "indexOf", "(", "'top'", ")", "!==", "-", "1", ")", "{", "props", ".", "top", "=", "this", ".", "options", ".", "pos_margin", ";", "}", "else", "if", "(", "pos", ".", "indexOf", "(", "'bottom'", ")", "!==", "-", "1", ")", "{", "props", ".", "bottom", "=", "this", ".", "options", ".", "pos_margin", ";", "}", "if", "(", "pos", ".", "indexOf", "(", "'left'", ")", "!==", "-", "1", ")", "{", "props", ".", "left", "=", "this", ".", "options", ".", "pos_margin", ";", "}", "else", "if", "(", "pos", ".", "indexOf", "(", "'right'", ")", "!==", "-", "1", ")", "{", "props", ".", "right", "=", "this", ".", "options", ".", "pos_margin", ";", "}", "this", ".", "$el", ".", "css", "(", "props", ")", ";", "}" ]
set position based on a string like "top|right", "top|left", "bottom|righ"...
[ "set", "position", "based", "on", "a", "string", "like", "top|right", "top|left", "bottom|righ", "..." ]
61d11c6268d59343746809639e0d23419674ae87
https://github.com/knownasilya/ember-leaflet-cartodb/blob/61d11c6268d59343746809639e0d23419674ae87/vendor/ember-leaflet-cartodb/cartodb_noleaflet.js#L23404-L23419
47,836
knownasilya/ember-leaflet-cartodb
vendor/ember-leaflet-cartodb/cartodb_noleaflet.js
function(payload) { var self = this; if (this.options.compressor) { return this.options.compressor; } payload = payload || JSON.stringify(this.toJSON()); if (!this.options.force_compress && payload.length < this.options.MAX_GET_SIZE) { return function(data, level, callback) { callback("config=" + encodeURIComponent(data)); }; } return function(data, level, callback) { data = JSON.stringify({ config: data }); LZMA.compress(data, level, function(encoded) { callback("lzma=" + encodeURIComponent(cdb.core.util.array2hex(encoded))); }); }; }
javascript
function(payload) { var self = this; if (this.options.compressor) { return this.options.compressor; } payload = payload || JSON.stringify(this.toJSON()); if (!this.options.force_compress && payload.length < this.options.MAX_GET_SIZE) { return function(data, level, callback) { callback("config=" + encodeURIComponent(data)); }; } return function(data, level, callback) { data = JSON.stringify({ config: data }); LZMA.compress(data, level, function(encoded) { callback("lzma=" + encodeURIComponent(cdb.core.util.array2hex(encoded))); }); }; }
[ "function", "(", "payload", ")", "{", "var", "self", "=", "this", ";", "if", "(", "this", ".", "options", ".", "compressor", ")", "{", "return", "this", ".", "options", ".", "compressor", ";", "}", "payload", "=", "payload", "||", "JSON", ".", "stringify", "(", "this", ".", "toJSON", "(", ")", ")", ";", "if", "(", "!", "this", ".", "options", ".", "force_compress", "&&", "payload", ".", "length", "<", "this", ".", "options", ".", "MAX_GET_SIZE", ")", "{", "return", "function", "(", "data", ",", "level", ",", "callback", ")", "{", "callback", "(", "\"config=\"", "+", "encodeURIComponent", "(", "data", ")", ")", ";", "}", ";", "}", "return", "function", "(", "data", ",", "level", ",", "callback", ")", "{", "data", "=", "JSON", ".", "stringify", "(", "{", "config", ":", "data", "}", ")", ";", "LZMA", ".", "compress", "(", "data", ",", "level", ",", "function", "(", "encoded", ")", "{", "callback", "(", "\"lzma=\"", "+", "encodeURIComponent", "(", "cdb", ".", "core", ".", "util", ".", "array2hex", "(", "encoded", ")", ")", ")", ";", "}", ")", ";", "}", ";", "}" ]
returns the compressor depending on the size of the layer
[ "returns", "the", "compressor", "depending", "on", "the", "size", "of", "the", "layer" ]
61d11c6268d59343746809639e0d23419674ae87
https://github.com/knownasilya/ember-leaflet-cartodb/blob/61d11c6268d59343746809639e0d23419674ae87/vendor/ember-leaflet-cartodb/cartodb_noleaflet.js#L24341-L24361
47,837
knownasilya/ember-leaflet-cartodb
vendor/ember-leaflet-cartodb/cartodb_noleaflet.js
function(params, included) { if(!params) return ''; var url_params = []; included = included || _.keys(params); for(var i in included) { var k = included[i] var p = params[k]; if(p) { if (_.isArray(p)) { for (var j = 0, len = p.length; j < len; j++) { url_params.push(k + "[]=" + encodeURIComponent(p[j])); } } else { var q = encodeURIComponent(p); q = q.replace(/%7Bx%7D/g,"{x}").replace(/%7By%7D/g,"{y}").replace(/%7Bz%7D/g,"{z}"); url_params.push(k + "=" + q); } } } return url_params.join('&') }
javascript
function(params, included) { if(!params) return ''; var url_params = []; included = included || _.keys(params); for(var i in included) { var k = included[i] var p = params[k]; if(p) { if (_.isArray(p)) { for (var j = 0, len = p.length; j < len; j++) { url_params.push(k + "[]=" + encodeURIComponent(p[j])); } } else { var q = encodeURIComponent(p); q = q.replace(/%7Bx%7D/g,"{x}").replace(/%7By%7D/g,"{y}").replace(/%7Bz%7D/g,"{z}"); url_params.push(k + "=" + q); } } } return url_params.join('&') }
[ "function", "(", "params", ",", "included", ")", "{", "if", "(", "!", "params", ")", "return", "''", ";", "var", "url_params", "=", "[", "]", ";", "included", "=", "included", "||", "_", ".", "keys", "(", "params", ")", ";", "for", "(", "var", "i", "in", "included", ")", "{", "var", "k", "=", "included", "[", "i", "]", "var", "p", "=", "params", "[", "k", "]", ";", "if", "(", "p", ")", "{", "if", "(", "_", ".", "isArray", "(", "p", ")", ")", "{", "for", "(", "var", "j", "=", "0", ",", "len", "=", "p", ".", "length", ";", "j", "<", "len", ";", "j", "++", ")", "{", "url_params", ".", "push", "(", "k", "+", "\"[]=\"", "+", "encodeURIComponent", "(", "p", "[", "j", "]", ")", ")", ";", "}", "}", "else", "{", "var", "q", "=", "encodeURIComponent", "(", "p", ")", ";", "q", "=", "q", ".", "replace", "(", "/", "%7Bx%7D", "/", "g", ",", "\"{x}\"", ")", ".", "replace", "(", "/", "%7By%7D", "/", "g", ",", "\"{y}\"", ")", ".", "replace", "(", "/", "%7Bz%7D", "/", "g", ",", "\"{z}\"", ")", ";", "url_params", ".", "push", "(", "k", "+", "\"=\"", "+", "q", ")", ";", "}", "}", "}", "return", "url_params", ".", "join", "(", "'&'", ")", "}" ]
Change query of the tiles @params {str} New sql for the tiles
[ "Change", "query", "of", "the", "tiles" ]
61d11c6268d59343746809639e0d23419674ae87
https://github.com/knownasilya/ember-leaflet-cartodb/blob/61d11c6268d59343746809639e0d23419674ae87/vendor/ember-leaflet-cartodb/cartodb_noleaflet.js#L24516-L24536
47,838
knownasilya/ember-leaflet-cartodb
vendor/ember-leaflet-cartodb/cartodb_noleaflet.js
function(layer, callback) { layer = layer == undefined ? 0: layer; var self = this; this.getTiles(function(urls) { if(!urls) { callback(null); return; } if(callback) { callback(self._tileJSONfromTiles(layer, urls)); } }); }
javascript
function(layer, callback) { layer = layer == undefined ? 0: layer; var self = this; this.getTiles(function(urls) { if(!urls) { callback(null); return; } if(callback) { callback(self._tileJSONfromTiles(layer, urls)); } }); }
[ "function", "(", "layer", ",", "callback", ")", "{", "layer", "=", "layer", "==", "undefined", "?", "0", ":", "layer", ";", "var", "self", "=", "this", ";", "this", ".", "getTiles", "(", "function", "(", "urls", ")", "{", "if", "(", "!", "urls", ")", "{", "callback", "(", "null", ")", ";", "return", ";", "}", "if", "(", "callback", ")", "{", "callback", "(", "self", ".", "_tileJSONfromTiles", "(", "layer", ",", "urls", ")", ")", ";", "}", "}", ")", ";", "}" ]
get tile json for layer
[ "get", "tile", "json", "for", "layer" ]
61d11c6268d59343746809639e0d23419674ae87
https://github.com/knownasilya/ember-leaflet-cartodb/blob/61d11c6268d59343746809639e0d23419674ae87/vendor/ember-leaflet-cartodb/cartodb_noleaflet.js#L24552-L24564
47,839
knownasilya/ember-leaflet-cartodb
vendor/ember-leaflet-cartodb/cartodb_noleaflet.js
function(number) { var layers = {} var c = 0; for(var i = 0; i < this.layers.length; ++i) { var layer = this.layers[i]; layers[i] = c; if(layer.options && !layer.options.hidden) { ++c; } } return layers[number]; }
javascript
function(number) { var layers = {} var c = 0; for(var i = 0; i < this.layers.length; ++i) { var layer = this.layers[i]; layers[i] = c; if(layer.options && !layer.options.hidden) { ++c; } } return layers[number]; }
[ "function", "(", "number", ")", "{", "var", "layers", "=", "{", "}", "var", "c", "=", "0", ";", "for", "(", "var", "i", "=", "0", ";", "i", "<", "this", ".", "layers", ".", "length", ";", "++", "i", ")", "{", "var", "layer", "=", "this", ".", "layers", "[", "i", "]", ";", "layers", "[", "i", "]", "=", "c", ";", "if", "(", "layer", ".", "options", "&&", "!", "layer", ".", "options", ".", "hidden", ")", "{", "++", "c", ";", "}", "}", "return", "layers", "[", "number", "]", ";", "}" ]
given number inside layergroup returns the real index in tiler layergroup`
[ "given", "number", "inside", "layergroup", "returns", "the", "real", "index", "in", "tiler", "layergroup" ]
61d11c6268d59343746809639e0d23419674ae87
https://github.com/knownasilya/ember-leaflet-cartodb/blob/61d11c6268d59343746809639e0d23419674ae87/vendor/ember-leaflet-cartodb/cartodb_noleaflet.js#L24634-L24645
47,840
knownasilya/ember-leaflet-cartodb
vendor/ember-leaflet-cartodb/cartodb_noleaflet.js
function(index) { var layers = []; for(var i = 0; i < this.layers.length; ++i) { var layer = this.layers[i]; if(this._isLayerVisible(layer)) { layers.push(i); } } if (index >= layers.length) { return -1; } return +layers[index]; }
javascript
function(index) { var layers = []; for(var i = 0; i < this.layers.length; ++i) { var layer = this.layers[i]; if(this._isLayerVisible(layer)) { layers.push(i); } } if (index >= layers.length) { return -1; } return +layers[index]; }
[ "function", "(", "index", ")", "{", "var", "layers", "=", "[", "]", ";", "for", "(", "var", "i", "=", "0", ";", "i", "<", "this", ".", "layers", ".", "length", ";", "++", "i", ")", "{", "var", "layer", "=", "this", ".", "layers", "[", "i", "]", ";", "if", "(", "this", ".", "_isLayerVisible", "(", "layer", ")", ")", "{", "layers", ".", "push", "(", "i", ")", ";", "}", "}", "if", "(", "index", ">=", "layers", ".", "length", ")", "{", "return", "-", "1", ";", "}", "return", "+", "layers", "[", "index", "]", ";", "}" ]
return the layer number by index taking into account the hidden layers.
[ "return", "the", "layer", "number", "by", "index", "taking", "into", "account", "the", "hidden", "layers", "." ]
61d11c6268d59343746809639e0d23419674ae87
https://github.com/knownasilya/ember-leaflet-cartodb/blob/61d11c6268d59343746809639e0d23419674ae87/vendor/ember-leaflet-cartodb/cartodb_noleaflet.js#L24651-L24663
47,841
knownasilya/ember-leaflet-cartodb
vendor/ember-leaflet-cartodb/cartodb_noleaflet.js
function(layer, attributes) { if(attributes === undefined) { attributes = layer; layer = 0; } if(layer >= this.getLayerCount() && layer < 0) { throw new Error("layer does not exist"); } if(typeof(attributes) == 'string') { attributes = attributes.split(','); } for(var i = 0; i < attributes.length; ++i) { attributes[i] = attributes[i].replace(/ /g, ''); } this.layers[layer].options.interactivity = attributes; this._definitionUpdated(); return this; }
javascript
function(layer, attributes) { if(attributes === undefined) { attributes = layer; layer = 0; } if(layer >= this.getLayerCount() && layer < 0) { throw new Error("layer does not exist"); } if(typeof(attributes) == 'string') { attributes = attributes.split(','); } for(var i = 0; i < attributes.length; ++i) { attributes[i] = attributes[i].replace(/ /g, ''); } this.layers[layer].options.interactivity = attributes; this._definitionUpdated(); return this; }
[ "function", "(", "layer", ",", "attributes", ")", "{", "if", "(", "attributes", "===", "undefined", ")", "{", "attributes", "=", "layer", ";", "layer", "=", "0", ";", "}", "if", "(", "layer", ">=", "this", ".", "getLayerCount", "(", ")", "&&", "layer", "<", "0", ")", "{", "throw", "new", "Error", "(", "\"layer does not exist\"", ")", ";", "}", "if", "(", "typeof", "(", "attributes", ")", "==", "'string'", ")", "{", "attributes", "=", "attributes", ".", "split", "(", "','", ")", ";", "}", "for", "(", "var", "i", "=", "0", ";", "i", "<", "attributes", ".", "length", ";", "++", "i", ")", "{", "attributes", "[", "i", "]", "=", "attributes", "[", "i", "]", ".", "replace", "(", "/", " ", "/", "g", ",", "''", ")", ";", "}", "this", ".", "layers", "[", "layer", "]", ".", "options", ".", "interactivity", "=", "attributes", ";", "this", ".", "_definitionUpdated", "(", ")", ";", "return", "this", ";", "}" ]
set interactivity attributes for a layer. if attributes are passed as first param layer 0 is set
[ "set", "interactivity", "attributes", "for", "a", "layer", ".", "if", "attributes", "are", "passed", "as", "first", "param", "layer", "0", "is", "set" ]
61d11c6268d59343746809639e0d23419674ae87
https://github.com/knownasilya/ember-leaflet-cartodb/blob/61d11c6268d59343746809639e0d23419674ae87/vendor/ember-leaflet-cartodb/cartodb_noleaflet.js#L24874-L24895
47,842
knownasilya/ember-leaflet-cartodb
vendor/ember-leaflet-cartodb/cartodb_noleaflet.js
function(layer, style, version) { if(version === undefined) { version = style; style = layer; layer = 0; } version = version || cartodb.CARTOCSS_DEFAULT_VERSION; this.layers[layer].options.cartocss = style; this.layers[layer].options.cartocss_version = version; this._definitionUpdated(); }
javascript
function(layer, style, version) { if(version === undefined) { version = style; style = layer; layer = 0; } version = version || cartodb.CARTOCSS_DEFAULT_VERSION; this.layers[layer].options.cartocss = style; this.layers[layer].options.cartocss_version = version; this._definitionUpdated(); }
[ "function", "(", "layer", ",", "style", ",", "version", ")", "{", "if", "(", "version", "===", "undefined", ")", "{", "version", "=", "style", ";", "style", "=", "layer", ";", "layer", "=", "0", ";", "}", "version", "=", "version", "||", "cartodb", ".", "CARTOCSS_DEFAULT_VERSION", ";", "this", ".", "layers", "[", "layer", "]", ".", "options", ".", "cartocss", "=", "style", ";", "this", ".", "layers", "[", "layer", "]", ".", "options", ".", "cartocss_version", "=", "version", ";", "this", ".", "_definitionUpdated", "(", ")", ";", "}" ]
Change style of the tiles @params {style} New carto for the tiles
[ "Change", "style", "of", "the", "tiles" ]
61d11c6268d59343746809639e0d23419674ae87
https://github.com/knownasilya/ember-leaflet-cartodb/blob/61d11c6268d59343746809639e0d23419674ae87/vendor/ember-leaflet-cartodb/cartodb_noleaflet.js#L24915-L24927
47,843
knownasilya/ember-leaflet-cartodb
vendor/ember-leaflet-cartodb/cartodb_noleaflet.js
function(layer, b) { // shift arguments to maintain caompatibility if(b == undefined) { b = layer; layer = 0; } var layerInteraction; this.interactionEnabled[layer] = b; if(!b) { layerInteraction = this.interaction[layer]; if(layerInteraction) { layerInteraction.remove(); this.interaction[layer] = null; } } else { // if urls is null it means that setInteraction will be called // when the layergroup token was recieved, then the real interaction // layer will be created if(this.urls) { // generate the tilejson from the urls. wax needs it var layer_index = this.getLayerIndexByNumber(+layer); var tilejson = this._tileJSONfromTiles(layer_index, this.urls); // remove previous layerInteraction = this.interaction[layer]; if(layerInteraction) { layerInteraction.remove(); } var self = this; // add the new one this.interaction[layer] = this.interactionClass() .map(this.options.map) .tilejson(tilejson) .on('on', function(o) { if (self._interactionDisabled) return; o.layer = +layer; self._manageOnEvents(self.options.map, o); }) .on('off', function(o) { if (self._interactionDisabled) return; o = o || {} o.layer = +layer; self._manageOffEvents(self.options.map, o); }); } } return this; }
javascript
function(layer, b) { // shift arguments to maintain caompatibility if(b == undefined) { b = layer; layer = 0; } var layerInteraction; this.interactionEnabled[layer] = b; if(!b) { layerInteraction = this.interaction[layer]; if(layerInteraction) { layerInteraction.remove(); this.interaction[layer] = null; } } else { // if urls is null it means that setInteraction will be called // when the layergroup token was recieved, then the real interaction // layer will be created if(this.urls) { // generate the tilejson from the urls. wax needs it var layer_index = this.getLayerIndexByNumber(+layer); var tilejson = this._tileJSONfromTiles(layer_index, this.urls); // remove previous layerInteraction = this.interaction[layer]; if(layerInteraction) { layerInteraction.remove(); } var self = this; // add the new one this.interaction[layer] = this.interactionClass() .map(this.options.map) .tilejson(tilejson) .on('on', function(o) { if (self._interactionDisabled) return; o.layer = +layer; self._manageOnEvents(self.options.map, o); }) .on('off', function(o) { if (self._interactionDisabled) return; o = o || {} o.layer = +layer; self._manageOffEvents(self.options.map, o); }); } } return this; }
[ "function", "(", "layer", ",", "b", ")", "{", "// shift arguments to maintain caompatibility", "if", "(", "b", "==", "undefined", ")", "{", "b", "=", "layer", ";", "layer", "=", "0", ";", "}", "var", "layerInteraction", ";", "this", ".", "interactionEnabled", "[", "layer", "]", "=", "b", ";", "if", "(", "!", "b", ")", "{", "layerInteraction", "=", "this", ".", "interaction", "[", "layer", "]", ";", "if", "(", "layerInteraction", ")", "{", "layerInteraction", ".", "remove", "(", ")", ";", "this", ".", "interaction", "[", "layer", "]", "=", "null", ";", "}", "}", "else", "{", "// if urls is null it means that setInteraction will be called", "// when the layergroup token was recieved, then the real interaction", "// layer will be created", "if", "(", "this", ".", "urls", ")", "{", "// generate the tilejson from the urls. wax needs it", "var", "layer_index", "=", "this", ".", "getLayerIndexByNumber", "(", "+", "layer", ")", ";", "var", "tilejson", "=", "this", ".", "_tileJSONfromTiles", "(", "layer_index", ",", "this", ".", "urls", ")", ";", "// remove previous", "layerInteraction", "=", "this", ".", "interaction", "[", "layer", "]", ";", "if", "(", "layerInteraction", ")", "{", "layerInteraction", ".", "remove", "(", ")", ";", "}", "var", "self", "=", "this", ";", "// add the new one", "this", ".", "interaction", "[", "layer", "]", "=", "this", ".", "interactionClass", "(", ")", ".", "map", "(", "this", ".", "options", ".", "map", ")", ".", "tilejson", "(", "tilejson", ")", ".", "on", "(", "'on'", ",", "function", "(", "o", ")", "{", "if", "(", "self", ".", "_interactionDisabled", ")", "return", ";", "o", ".", "layer", "=", "+", "layer", ";", "self", ".", "_manageOnEvents", "(", "self", ".", "options", ".", "map", ",", "o", ")", ";", "}", ")", ".", "on", "(", "'off'", ",", "function", "(", "o", ")", "{", "if", "(", "self", ".", "_interactionDisabled", ")", "return", ";", "o", "=", "o", "||", "{", "}", "o", ".", "layer", "=", "+", "layer", ";", "self", ".", "_manageOffEvents", "(", "self", ".", "options", ".", "map", ",", "o", ")", ";", "}", ")", ";", "}", "}", "return", "this", ";", "}" ]
Active or desactive interaction @params enable {Number} layer number @params layer {Boolean} Choose if wants interaction or not
[ "Active", "or", "desactive", "interaction" ]
61d11c6268d59343746809639e0d23419674ae87
https://github.com/knownasilya/ember-leaflet-cartodb/blob/61d11c6268d59343746809639e0d23419674ae87/vendor/ember-leaflet-cartodb/cartodb_noleaflet.js#L25140-L25188
47,844
knownasilya/ember-leaflet-cartodb
vendor/ember-leaflet-cartodb/cartodb_noleaflet.js
function() { var xyz = {z: 4, x: 6, y: 6} , self = this , img = new Image() , urls = this._tileJSON() getTiles(function(urls) { var grid_url = urls.tiles[0] .replace(/\{z\}/g,xyz.z) .replace(/\{x\}/g,xyz.x) .replace(/\{y\}/g,xyz.y); this.options.ajax({ method: "get", url: grid_url, crossDomain: true, success: function() { self.tilesOk(); clearTimeout(timeout) }, error: function(xhr, msg, data) { clearTimeout(timeout); self.error(xhr.responseText && JSON.parse(xhr.responseText)); } }); }); var timeout = setTimeout(function(){ clearTimeout(timeout); self.error("tile timeout"); }, 30000); }
javascript
function() { var xyz = {z: 4, x: 6, y: 6} , self = this , img = new Image() , urls = this._tileJSON() getTiles(function(urls) { var grid_url = urls.tiles[0] .replace(/\{z\}/g,xyz.z) .replace(/\{x\}/g,xyz.x) .replace(/\{y\}/g,xyz.y); this.options.ajax({ method: "get", url: grid_url, crossDomain: true, success: function() { self.tilesOk(); clearTimeout(timeout) }, error: function(xhr, msg, data) { clearTimeout(timeout); self.error(xhr.responseText && JSON.parse(xhr.responseText)); } }); }); var timeout = setTimeout(function(){ clearTimeout(timeout); self.error("tile timeout"); }, 30000); }
[ "function", "(", ")", "{", "var", "xyz", "=", "{", "z", ":", "4", ",", "x", ":", "6", ",", "y", ":", "6", "}", ",", "self", "=", "this", ",", "img", "=", "new", "Image", "(", ")", ",", "urls", "=", "this", ".", "_tileJSON", "(", ")", "getTiles", "(", "function", "(", "urls", ")", "{", "var", "grid_url", "=", "urls", ".", "tiles", "[", "0", "]", ".", "replace", "(", "/", "\\{z\\}", "/", "g", ",", "xyz", ".", "z", ")", ".", "replace", "(", "/", "\\{x\\}", "/", "g", ",", "xyz", ".", "x", ")", ".", "replace", "(", "/", "\\{y\\}", "/", "g", ",", "xyz", ".", "y", ")", ";", "this", ".", "options", ".", "ajax", "(", "{", "method", ":", "\"get\"", ",", "url", ":", "grid_url", ",", "crossDomain", ":", "true", ",", "success", ":", "function", "(", ")", "{", "self", ".", "tilesOk", "(", ")", ";", "clearTimeout", "(", "timeout", ")", "}", ",", "error", ":", "function", "(", "xhr", ",", "msg", ",", "data", ")", "{", "clearTimeout", "(", "timeout", ")", ";", "self", ".", "error", "(", "xhr", ".", "responseText", "&&", "JSON", ".", "parse", "(", "xhr", ".", "responseText", ")", ")", ";", "}", "}", ")", ";", "}", ")", ";", "var", "timeout", "=", "setTimeout", "(", "function", "(", ")", "{", "clearTimeout", "(", "timeout", ")", ";", "self", ".", "error", "(", "\"tile timeout\"", ")", ";", "}", ",", "30000", ")", ";", "}" ]
Check the tiles
[ "Check", "the", "tiles" ]
61d11c6268d59343746809639e0d23419674ae87
https://github.com/knownasilya/ember-leaflet-cartodb/blob/61d11c6268d59343746809639e0d23419674ae87/vendor/ember-leaflet-cartodb/cartodb_noleaflet.js#L25278-L25311
47,845
knownasilya/ember-leaflet-cartodb
vendor/ember-leaflet-cartodb/cartodb_noleaflet.js
function(container, className) { // Check if any cartodb-logo exists within container var a = []; var re = new RegExp('\\b' + className + '\\b'); var els = container.getElementsByTagName("*"); for(var i=0,j=els.length; i<j; i++) if(re.test(els[i].className))a.push(els[i]); return a.length > 0; }
javascript
function(container, className) { // Check if any cartodb-logo exists within container var a = []; var re = new RegExp('\\b' + className + '\\b'); var els = container.getElementsByTagName("*"); for(var i=0,j=els.length; i<j; i++) if(re.test(els[i].className))a.push(els[i]); return a.length > 0; }
[ "function", "(", "container", ",", "className", ")", "{", "// Check if any cartodb-logo exists within container", "var", "a", "=", "[", "]", ";", "var", "re", "=", "new", "RegExp", "(", "'\\\\b'", "+", "className", "+", "'\\\\b'", ")", ";", "var", "els", "=", "container", ".", "getElementsByTagName", "(", "\"*\"", ")", ";", "for", "(", "var", "i", "=", "0", ",", "j", "=", "els", ".", "length", ";", "i", "<", "j", ";", "i", "++", ")", "if", "(", "re", ".", "test", "(", "els", "[", "i", "]", ".", "className", ")", ")", "a", ".", "push", "(", "els", "[", "i", "]", ")", ";", "return", "a", ".", "length", ">", "0", ";", "}" ]
Check if any class already exists in the provided container
[ "Check", "if", "any", "class", "already", "exists", "in", "the", "provided", "container" ]
61d11c6268d59343746809639e0d23419674ae87
https://github.com/knownasilya/ember-leaflet-cartodb/blob/61d11c6268d59343746809639e0d23419674ae87/vendor/ember-leaflet-cartodb/cartodb_noleaflet.js#L25322-L25331
47,846
knownasilya/ember-leaflet-cartodb
vendor/ember-leaflet-cartodb/cartodb_noleaflet.js
function(position, timeout, container) { var self = this; setTimeout(function() { if (!self.isWadusAdded(container, 'cartodb-logo')) { var cartodb_link = document.createElement("div"); var is_retina = self.isRetinaBrowser(); cartodb_link.setAttribute('class','cartodb-logo'); cartodb_link.setAttribute('style',"position:absolute; bottom:0; left:0; display:block; border:none; z-index:1000000;"); var protocol = location.protocol.indexOf('https') === -1 ? 'http': 'https'; var link = cdb.config.get('cartodb_logo_link'); cartodb_link.innerHTML = "<a href='" + link + "' target='_blank'><img width='71' height='29' src='" + protocol + "://cartodb.s3.amazonaws.com/static/new_logo" + (is_retina ? '@2x' : '') + ".png' style='position:absolute; bottom:" + ( position.bottom || 0 ) + "px; left:" + ( position.left || 0 ) + "px; display:block; width:71px!important; height:29px!important; border:none; outline:none;' alt='CARTO' title='CARTO' />"; container.appendChild(cartodb_link); } },( timeout || 0 )); }
javascript
function(position, timeout, container) { var self = this; setTimeout(function() { if (!self.isWadusAdded(container, 'cartodb-logo')) { var cartodb_link = document.createElement("div"); var is_retina = self.isRetinaBrowser(); cartodb_link.setAttribute('class','cartodb-logo'); cartodb_link.setAttribute('style',"position:absolute; bottom:0; left:0; display:block; border:none; z-index:1000000;"); var protocol = location.protocol.indexOf('https') === -1 ? 'http': 'https'; var link = cdb.config.get('cartodb_logo_link'); cartodb_link.innerHTML = "<a href='" + link + "' target='_blank'><img width='71' height='29' src='" + protocol + "://cartodb.s3.amazonaws.com/static/new_logo" + (is_retina ? '@2x' : '') + ".png' style='position:absolute; bottom:" + ( position.bottom || 0 ) + "px; left:" + ( position.left || 0 ) + "px; display:block; width:71px!important; height:29px!important; border:none; outline:none;' alt='CARTO' title='CARTO' />"; container.appendChild(cartodb_link); } },( timeout || 0 )); }
[ "function", "(", "position", ",", "timeout", ",", "container", ")", "{", "var", "self", "=", "this", ";", "setTimeout", "(", "function", "(", ")", "{", "if", "(", "!", "self", ".", "isWadusAdded", "(", "container", ",", "'cartodb-logo'", ")", ")", "{", "var", "cartodb_link", "=", "document", ".", "createElement", "(", "\"div\"", ")", ";", "var", "is_retina", "=", "self", ".", "isRetinaBrowser", "(", ")", ";", "cartodb_link", ".", "setAttribute", "(", "'class'", ",", "'cartodb-logo'", ")", ";", "cartodb_link", ".", "setAttribute", "(", "'style'", ",", "\"position:absolute; bottom:0; left:0; display:block; border:none; z-index:1000000;\"", ")", ";", "var", "protocol", "=", "location", ".", "protocol", ".", "indexOf", "(", "'https'", ")", "===", "-", "1", "?", "'http'", ":", "'https'", ";", "var", "link", "=", "cdb", ".", "config", ".", "get", "(", "'cartodb_logo_link'", ")", ";", "cartodb_link", ".", "innerHTML", "=", "\"<a href='\"", "+", "link", "+", "\"' target='_blank'><img width='71' height='29' src='\"", "+", "protocol", "+", "\"://cartodb.s3.amazonaws.com/static/new_logo\"", "+", "(", "is_retina", "?", "'@2x'", ":", "''", ")", "+", "\".png' style='position:absolute; bottom:\"", "+", "(", "position", ".", "bottom", "||", "0", ")", "+", "\"px; left:\"", "+", "(", "position", ".", "left", "||", "0", ")", "+", "\"px; display:block; width:71px!important; height:29px!important; border:none; outline:none;' alt='CARTO' title='CARTO' />\"", ";", "container", ".", "appendChild", "(", "cartodb_link", ")", ";", "}", "}", ",", "(", "timeout", "||", "0", ")", ")", ";", "}" ]
Add Cartodb logo It needs a position, timeout if it is needed and the container where to add it
[ "Add", "Cartodb", "logo", "It", "needs", "a", "position", "timeout", "if", "it", "is", "needed", "and", "the", "container", "where", "to", "add", "it" ]
61d11c6268d59343746809639e0d23419674ae87
https://github.com/knownasilya/ember-leaflet-cartodb/blob/61d11c6268d59343746809639e0d23419674ae87/vendor/ember-leaflet-cartodb/cartodb_noleaflet.js#L25346-L25361
47,847
knownasilya/ember-leaflet-cartodb
vendor/ember-leaflet-cartodb/cartodb_noleaflet.js
function(layerModel, leafletLayer, leafletMap) { this.leafletLayer = leafletLayer; this.leafletMap = leafletMap; this.model = layerModel; this.setModel(layerModel); this.type = layerModel.get('type') || layerModel.get('kind'); this.type = this.type.toLowerCase(); }
javascript
function(layerModel, leafletLayer, leafletMap) { this.leafletLayer = leafletLayer; this.leafletMap = leafletMap; this.model = layerModel; this.setModel(layerModel); this.type = layerModel.get('type') || layerModel.get('kind'); this.type = this.type.toLowerCase(); }
[ "function", "(", "layerModel", ",", "leafletLayer", ",", "leafletMap", ")", "{", "this", ".", "leafletLayer", "=", "leafletLayer", ";", "this", ".", "leafletMap", "=", "leafletMap", ";", "this", ".", "model", "=", "layerModel", ";", "this", ".", "setModel", "(", "layerModel", ")", ";", "this", ".", "type", "=", "layerModel", ".", "get", "(", "'type'", ")", "||", "layerModel", ".", "get", "(", "'kind'", ")", ";", "this", ".", "type", "=", "this", ".", "type", ".", "toLowerCase", "(", ")", ";", "}" ]
base layer for all leaflet layers
[ "base", "layer", "for", "all", "leaflet", "layers" ]
61d11c6268d59343746809639e0d23419674ae87
https://github.com/knownasilya/ember-leaflet-cartodb/blob/61d11c6268d59343746809639e0d23419674ae87/vendor/ember-leaflet-cartodb/cartodb_noleaflet.js#L25370-L25379
47,848
knownasilya/ember-leaflet-cartodb
vendor/ember-leaflet-cartodb/cartodb_noleaflet.js
function (tilePoint) { var EMPTY_GIF = "data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7"; this._adjustTilePoint(tilePoint); var tiles = [EMPTY_GIF]; if(this.tilejson) { tiles = this.tilejson.tiles; } var index = (tilePoint.x + tilePoint.y) % tiles.length; return L.Util.template(tiles[index], L.Util.extend({ z: this._getZoomForUrl(), x: tilePoint.x, y: tilePoint.y }, this.options)); }
javascript
function (tilePoint) { var EMPTY_GIF = "data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7"; this._adjustTilePoint(tilePoint); var tiles = [EMPTY_GIF]; if(this.tilejson) { tiles = this.tilejson.tiles; } var index = (tilePoint.x + tilePoint.y) % tiles.length; return L.Util.template(tiles[index], L.Util.extend({ z: this._getZoomForUrl(), x: tilePoint.x, y: tilePoint.y }, this.options)); }
[ "function", "(", "tilePoint", ")", "{", "var", "EMPTY_GIF", "=", "\"data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7\"", ";", "this", ".", "_adjustTilePoint", "(", "tilePoint", ")", ";", "var", "tiles", "=", "[", "EMPTY_GIF", "]", ";", "if", "(", "this", ".", "tilejson", ")", "{", "tiles", "=", "this", ".", "tilejson", ".", "tiles", ";", "}", "var", "index", "=", "(", "tilePoint", ".", "x", "+", "tilePoint", ".", "y", ")", "%", "tiles", ".", "length", ";", "return", "L", ".", "Util", ".", "template", "(", "tiles", "[", "index", "]", ",", "L", ".", "Util", ".", "extend", "(", "{", "z", ":", "this", ".", "_getZoomForUrl", "(", ")", ",", "x", ":", "tilePoint", ".", "x", ",", "y", ":", "tilePoint", ".", "y", "}", ",", "this", ".", "options", ")", ")", ";", "}" ]
overwrite getTileUrl in order to support different tiles subdomains in tilejson way
[ "overwrite", "getTileUrl", "in", "order", "to", "support", "different", "tiles", "subdomains", "in", "tilejson", "way" ]
61d11c6268d59343746809639e0d23419674ae87
https://github.com/knownasilya/ember-leaflet-cartodb/blob/61d11c6268d59343746809639e0d23419674ae87/vendor/ember-leaflet-cartodb/cartodb_noleaflet.js#L25723-L25739
47,849
knownasilya/ember-leaflet-cartodb
vendor/ember-leaflet-cartodb/cartodb_noleaflet.js
function(opacity) { if (isNaN(opacity) || opacity>1 || opacity<0) { throw new Error(opacity + ' is not a valid value'); } // Leaflet only accepts 0-0.99... Weird! this.options.opacity = Math.min(opacity, 0.99); if (this.options.visible) { L.TileLayer.prototype.setOpacity.call(this, this.options.opacity); this.fire('updated'); } }
javascript
function(opacity) { if (isNaN(opacity) || opacity>1 || opacity<0) { throw new Error(opacity + ' is not a valid value'); } // Leaflet only accepts 0-0.99... Weird! this.options.opacity = Math.min(opacity, 0.99); if (this.options.visible) { L.TileLayer.prototype.setOpacity.call(this, this.options.opacity); this.fire('updated'); } }
[ "function", "(", "opacity", ")", "{", "if", "(", "isNaN", "(", "opacity", ")", "||", "opacity", ">", "1", "||", "opacity", "<", "0", ")", "{", "throw", "new", "Error", "(", "opacity", "+", "' is not a valid value'", ")", ";", "}", "// Leaflet only accepts 0-0.99... Weird!", "this", ".", "options", ".", "opacity", "=", "Math", ".", "min", "(", "opacity", ",", "0.99", ")", ";", "if", "(", "this", ".", "options", ".", "visible", ")", "{", "L", ".", "TileLayer", ".", "prototype", ".", "setOpacity", ".", "call", "(", "this", ",", "this", ".", "options", ".", "opacity", ")", ";", "this", ".", "fire", "(", "'updated'", ")", ";", "}", "}" ]
Change opacity of the layer @params {Integer} New opacity
[ "Change", "opacity", "of", "the", "layer" ]
61d11c6268d59343746809639e0d23419674ae87
https://github.com/knownasilya/ember-leaflet-cartodb/blob/61d11c6268d59343746809639e0d23419674ae87/vendor/ember-leaflet-cartodb/cartodb_noleaflet.js#L25745-L25758
47,850
knownasilya/ember-leaflet-cartodb
vendor/ember-leaflet-cartodb/cartodb_noleaflet.js
function(map) { var self = this; this.options.map = map; // Add cartodb logo if (this.options.cartodb_logo != false) cdb.geo.common.CartoDBLogo.addWadus({ left:8, bottom:8 }, 0, map._container); this.__update(function() { // if while the layer was processed in the server is removed // it should not be added to the map var id = L.stamp(self); if (!map._layers[id]) { return; } L.TileLayer.prototype.onAdd.call(self, map); self.fire('added'); self.options.added = true; }); }
javascript
function(map) { var self = this; this.options.map = map; // Add cartodb logo if (this.options.cartodb_logo != false) cdb.geo.common.CartoDBLogo.addWadus({ left:8, bottom:8 }, 0, map._container); this.__update(function() { // if while the layer was processed in the server is removed // it should not be added to the map var id = L.stamp(self); if (!map._layers[id]) { return; } L.TileLayer.prototype.onAdd.call(self, map); self.fire('added'); self.options.added = true; }); }
[ "function", "(", "map", ")", "{", "var", "self", "=", "this", ";", "this", ".", "options", ".", "map", "=", "map", ";", "// Add cartodb logo", "if", "(", "this", ".", "options", ".", "cartodb_logo", "!=", "false", ")", "cdb", ".", "geo", ".", "common", ".", "CartoDBLogo", ".", "addWadus", "(", "{", "left", ":", "8", ",", "bottom", ":", "8", "}", ",", "0", ",", "map", ".", "_container", ")", ";", "this", ".", "__update", "(", "function", "(", ")", "{", "// if while the layer was processed in the server is removed", "// it should not be added to the map", "var", "id", "=", "L", ".", "stamp", "(", "self", ")", ";", "if", "(", "!", "map", ".", "_layers", "[", "id", "]", ")", "{", "return", ";", "}", "L", ".", "TileLayer", ".", "prototype", ".", "onAdd", ".", "call", "(", "self", ",", "map", ")", ";", "self", ".", "fire", "(", "'added'", ")", ";", "self", ".", "options", ".", "added", "=", "true", ";", "}", ")", ";", "}" ]
When Leaflet adds the layer... go! @params {map}
[ "When", "Leaflet", "adds", "the", "layer", "...", "go!" ]
61d11c6268d59343746809639e0d23419674ae87
https://github.com/knownasilya/ember-leaflet-cartodb/blob/61d11c6268d59343746809639e0d23419674ae87/vendor/ember-leaflet-cartodb/cartodb_noleaflet.js#L25765-L25785
47,851
knownasilya/ember-leaflet-cartodb
vendor/ember-leaflet-cartodb/cartodb_noleaflet.js
function(map) { if(this.options.added) { this.options.added = false; L.TileLayer.prototype.onRemove.call(this, map); } }
javascript
function(map) { if(this.options.added) { this.options.added = false; L.TileLayer.prototype.onRemove.call(this, map); } }
[ "function", "(", "map", ")", "{", "if", "(", "this", ".", "options", ".", "added", ")", "{", "this", ".", "options", ".", "added", "=", "false", ";", "L", ".", "TileLayer", ".", "prototype", ".", "onRemove", ".", "call", "(", "this", ",", "map", ")", ";", "}", "}" ]
When removes the layer, destroy interactivity if exist
[ "When", "removes", "the", "layer", "destroy", "interactivity", "if", "exist" ]
61d11c6268d59343746809639e0d23419674ae87
https://github.com/knownasilya/ember-leaflet-cartodb/blob/61d11c6268d59343746809639e0d23419674ae87/vendor/ember-leaflet-cartodb/cartodb_noleaflet.js#L25794-L25799
47,852
knownasilya/ember-leaflet-cartodb
vendor/ember-leaflet-cartodb/cartodb_noleaflet.js
function(done) { var self = this; this.fire('updated'); this.fire('loading'); var map = this.options.map; this.getTiles(function(urls, err) { if(urls) { self.tilejson = urls; self.setUrl(self.tilejson.tiles[0]); // manage interaction self._reloadInteraction(); self.ok && self.ok(); done && done(); } else { self.error && self.error(err); done && done(); } }); }
javascript
function(done) { var self = this; this.fire('updated'); this.fire('loading'); var map = this.options.map; this.getTiles(function(urls, err) { if(urls) { self.tilejson = urls; self.setUrl(self.tilejson.tiles[0]); // manage interaction self._reloadInteraction(); self.ok && self.ok(); done && done(); } else { self.error && self.error(err); done && done(); } }); }
[ "function", "(", "done", ")", "{", "var", "self", "=", "this", ";", "this", ".", "fire", "(", "'updated'", ")", ";", "this", ".", "fire", "(", "'loading'", ")", ";", "var", "map", "=", "this", ".", "options", ".", "map", ";", "this", ".", "getTiles", "(", "function", "(", "urls", ",", "err", ")", "{", "if", "(", "urls", ")", "{", "self", ".", "tilejson", "=", "urls", ";", "self", ".", "setUrl", "(", "self", ".", "tilejson", ".", "tiles", "[", "0", "]", ")", ";", "// manage interaction", "self", ".", "_reloadInteraction", "(", ")", ";", "self", ".", "ok", "&&", "self", ".", "ok", "(", ")", ";", "done", "&&", "done", "(", ")", ";", "}", "else", "{", "self", ".", "error", "&&", "self", ".", "error", "(", "err", ")", ";", "done", "&&", "done", "(", ")", ";", "}", "}", ")", ";", "}" ]
Update CartoDB layer generates a new url for tiles and refresh leaflet layer do not collide with leaflet _update
[ "Update", "CartoDB", "layer", "generates", "a", "new", "url", "for", "tiles", "and", "refresh", "leaflet", "layer", "do", "not", "collide", "with", "leaflet", "_update" ]
61d11c6268d59343746809639e0d23419674ae87
https://github.com/knownasilya/ember-leaflet-cartodb/blob/61d11c6268d59343746809639e0d23419674ae87/vendor/ember-leaflet-cartodb/cartodb_noleaflet.js#L25806-L25825
47,853
knownasilya/ember-leaflet-cartodb
vendor/ember-leaflet-cartodb/cartodb_noleaflet.js
function(attribution) { this._checkLayer(); // Remove old one this.map.attributionControl.removeAttribution( cdb.core.sanitize.html(this.options.attribution) ); // Change text this.map.attributionControl.addAttribution( cdb.core.sanitize.html(attribution) ); // Set new attribution in the options this.options.attribution = attribution; // Change in the layer this.tilejson.attribution = this.options.attribution; this.fire('updated'); }
javascript
function(attribution) { this._checkLayer(); // Remove old one this.map.attributionControl.removeAttribution( cdb.core.sanitize.html(this.options.attribution) ); // Change text this.map.attributionControl.addAttribution( cdb.core.sanitize.html(attribution) ); // Set new attribution in the options this.options.attribution = attribution; // Change in the layer this.tilejson.attribution = this.options.attribution; this.fire('updated'); }
[ "function", "(", "attribution", ")", "{", "this", ".", "_checkLayer", "(", ")", ";", "// Remove old one", "this", ".", "map", ".", "attributionControl", ".", "removeAttribution", "(", "cdb", ".", "core", ".", "sanitize", ".", "html", "(", "this", ".", "options", ".", "attribution", ")", ")", ";", "// Change text", "this", ".", "map", ".", "attributionControl", ".", "addAttribution", "(", "cdb", ".", "core", ".", "sanitize", ".", "html", "(", "attribution", ")", ")", ";", "// Set new attribution in the options", "this", ".", "options", ".", "attribution", "=", "attribution", ";", "// Change in the layer", "this", ".", "tilejson", ".", "attribution", "=", "this", ".", "options", ".", "attribution", ";", "this", ".", "fire", "(", "'updated'", ")", ";", "}" ]
Set a new layer attribution @params {String} New attribution string
[ "Set", "a", "new", "layer", "attribution" ]
61d11c6268d59343746809639e0d23419674ae87
https://github.com/knownasilya/ember-leaflet-cartodb/blob/61d11c6268d59343746809639e0d23419674ae87/vendor/ember-leaflet-cartodb/cartodb_noleaflet.js#L25838-L25854
47,854
knownasilya/ember-leaflet-cartodb
vendor/ember-leaflet-cartodb/cartodb_noleaflet.js
function(map, o) { var layer_point = this._findPos(map,o); if (!layer_point || isNaN(layer_point.x) || isNaN(layer_point.y)) { // If layer_point doesn't contain x and y, // we can't calculate event map position return false; } var latlng = map.layerPointToLatLng(layer_point); var event_type = o.e.type.toLowerCase(); var screenPos = map.layerPointToContainerPoint(layer_point); switch (event_type) { case 'mousemove': if (this.options.featureOver) { return this.options.featureOver(o.e,latlng, screenPos, o.data, o.layer); } break; case 'click': case 'touchend': case 'touchmove': // for some reason android browser does not send touchend case 'mspointerup': case 'pointerup': case 'pointermove': if (this.options.featureClick) { this.options.featureClick(o.e,latlng, screenPos, o.data, o.layer); } break; default: break; } }
javascript
function(map, o) { var layer_point = this._findPos(map,o); if (!layer_point || isNaN(layer_point.x) || isNaN(layer_point.y)) { // If layer_point doesn't contain x and y, // we can't calculate event map position return false; } var latlng = map.layerPointToLatLng(layer_point); var event_type = o.e.type.toLowerCase(); var screenPos = map.layerPointToContainerPoint(layer_point); switch (event_type) { case 'mousemove': if (this.options.featureOver) { return this.options.featureOver(o.e,latlng, screenPos, o.data, o.layer); } break; case 'click': case 'touchend': case 'touchmove': // for some reason android browser does not send touchend case 'mspointerup': case 'pointerup': case 'pointermove': if (this.options.featureClick) { this.options.featureClick(o.e,latlng, screenPos, o.data, o.layer); } break; default: break; } }
[ "function", "(", "map", ",", "o", ")", "{", "var", "layer_point", "=", "this", ".", "_findPos", "(", "map", ",", "o", ")", ";", "if", "(", "!", "layer_point", "||", "isNaN", "(", "layer_point", ".", "x", ")", "||", "isNaN", "(", "layer_point", ".", "y", ")", ")", "{", "// If layer_point doesn't contain x and y,", "// we can't calculate event map position", "return", "false", ";", "}", "var", "latlng", "=", "map", ".", "layerPointToLatLng", "(", "layer_point", ")", ";", "var", "event_type", "=", "o", ".", "e", ".", "type", ".", "toLowerCase", "(", ")", ";", "var", "screenPos", "=", "map", ".", "layerPointToContainerPoint", "(", "layer_point", ")", ";", "switch", "(", "event_type", ")", "{", "case", "'mousemove'", ":", "if", "(", "this", ".", "options", ".", "featureOver", ")", "{", "return", "this", ".", "options", ".", "featureOver", "(", "o", ".", "e", ",", "latlng", ",", "screenPos", ",", "o", ".", "data", ",", "o", ".", "layer", ")", ";", "}", "break", ";", "case", "'click'", ":", "case", "'touchend'", ":", "case", "'touchmove'", ":", "// for some reason android browser does not send touchend", "case", "'mspointerup'", ":", "case", "'pointerup'", ":", "case", "'pointermove'", ":", "if", "(", "this", ".", "options", ".", "featureClick", ")", "{", "this", ".", "options", ".", "featureClick", "(", "o", ".", "e", ",", "latlng", ",", "screenPos", ",", "o", ".", "data", ",", "o", ".", "layer", ")", ";", "}", "break", ";", "default", ":", "break", ";", "}", "}" ]
Bind events for wax interaction @param {Object} Layer map object @param {Event} Wax event
[ "Bind", "events", "for", "wax", "interaction" ]
61d11c6268d59343746809639e0d23419674ae87
https://github.com/knownasilya/ember-leaflet-cartodb/blob/61d11c6268d59343746809639e0d23419674ae87/vendor/ember-leaflet-cartodb/cartodb_noleaflet.js#L25861-L25894
47,855
knownasilya/ember-leaflet-cartodb
vendor/ember-leaflet-cartodb/cartodb_noleaflet.js
function() { var b = this.map_leaflet.getBounds(); var sw = b.getSouthWest(); var ne = b.getNorthEast(); return [ [sw.lat, sw.lng], [ne.lat, ne.lng] ]; }
javascript
function() { var b = this.map_leaflet.getBounds(); var sw = b.getSouthWest(); var ne = b.getNorthEast(); return [ [sw.lat, sw.lng], [ne.lat, ne.lng] ]; }
[ "function", "(", ")", "{", "var", "b", "=", "this", ".", "map_leaflet", ".", "getBounds", "(", ")", ";", "var", "sw", "=", "b", ".", "getSouthWest", "(", ")", ";", "var", "ne", "=", "b", ".", "getNorthEast", "(", ")", ";", "return", "[", "[", "sw", ".", "lat", ",", "sw", ".", "lng", "]", ",", "[", "ne", ".", "lat", ",", "ne", ".", "lng", "]", "]", ";", "}" ]
return the current bounds of the map view
[ "return", "the", "current", "bounds", "of", "the", "map", "view" ]
61d11c6268d59343746809639e0d23419674ae87
https://github.com/knownasilya/ember-leaflet-cartodb/blob/61d11c6268d59343746809639e0d23419674ae87/vendor/ember-leaflet-cartodb/cartodb_noleaflet.js#L26703-L26711
47,856
knownasilya/ember-leaflet-cartodb
vendor/ember-leaflet-cartodb/cartodb_noleaflet.js
function(layerModel, gmapsLayer, gmapsMap) { this.gmapsLayer = gmapsLayer; this.map = this.gmapsMap = gmapsMap; this.model = layerModel; this.model.bind('change', this._update, this); this.type = layerModel.get('type') || layerModel.get('kind'); this.type = this.type.toLowerCase(); }
javascript
function(layerModel, gmapsLayer, gmapsMap) { this.gmapsLayer = gmapsLayer; this.map = this.gmapsMap = gmapsMap; this.model = layerModel; this.model.bind('change', this._update, this); this.type = layerModel.get('type') || layerModel.get('kind'); this.type = this.type.toLowerCase(); }
[ "function", "(", "layerModel", ",", "gmapsLayer", ",", "gmapsMap", ")", "{", "this", ".", "gmapsLayer", "=", "gmapsLayer", ";", "this", ".", "map", "=", "this", ".", "gmapsMap", "=", "gmapsMap", ";", "this", ".", "model", "=", "layerModel", ";", "this", ".", "model", ".", "bind", "(", "'change'", ",", "this", ".", "_update", ",", "this", ")", ";", "this", ".", "type", "=", "layerModel", ".", "get", "(", "'type'", ")", "||", "layerModel", ".", "get", "(", "'kind'", ")", ";", "this", ".", "type", "=", "this", ".", "type", ".", "toLowerCase", "(", ")", ";", "}" ]
base layer for all google maps
[ "base", "layer", "for", "all", "google", "maps" ]
61d11c6268d59343746809639e0d23419674ae87
https://github.com/knownasilya/ember-leaflet-cartodb/blob/61d11c6268d59343746809639e0d23419674ae87/vendor/ember-leaflet-cartodb/cartodb_noleaflet.js#L26860-L26868
47,857
knownasilya/ember-leaflet-cartodb
vendor/ember-leaflet-cartodb/cartodb_noleaflet.js
function() { var self = this; var index = -1; this.gmapsMap.overlayMapTypes.forEach( function(layer, i) { if (layer == self) { index = i; } } ); return index; }
javascript
function() { var self = this; var index = -1; this.gmapsMap.overlayMapTypes.forEach( function(layer, i) { if (layer == self) { index = i; } } ); return index; }
[ "function", "(", ")", "{", "var", "self", "=", "this", ";", "var", "index", "=", "-", "1", ";", "this", ".", "gmapsMap", ".", "overlayMapTypes", ".", "forEach", "(", "function", "(", "layer", ",", "i", ")", "{", "if", "(", "layer", "==", "self", ")", "{", "index", "=", "i", ";", "}", "}", ")", ";", "return", "index", ";", "}" ]
hack function to search layer inside google maps layers
[ "hack", "function", "to", "search", "layer", "inside", "google", "maps", "layers" ]
61d11c6268d59343746809639e0d23419674ae87
https://github.com/knownasilya/ember-leaflet-cartodb/blob/61d11c6268d59343746809639e0d23419674ae87/vendor/ember-leaflet-cartodb/cartodb_noleaflet.js#L26874-L26885
47,858
knownasilya/ember-leaflet-cartodb
vendor/ember-leaflet-cartodb/cartodb_noleaflet.js
function() { if(!this.isBase) { var self = this; var idx = this._searchLayerIndex(); if(idx >= 0) { this.gmapsMap.overlayMapTypes.removeAt(idx); } else if (this.gmapsLayer.setMap){ this.gmapsLayer.setMap(null); } this.model.unbind(null, null, this); this.unbind(); } }
javascript
function() { if(!this.isBase) { var self = this; var idx = this._searchLayerIndex(); if(idx >= 0) { this.gmapsMap.overlayMapTypes.removeAt(idx); } else if (this.gmapsLayer.setMap){ this.gmapsLayer.setMap(null); } this.model.unbind(null, null, this); this.unbind(); } }
[ "function", "(", ")", "{", "if", "(", "!", "this", ".", "isBase", ")", "{", "var", "self", "=", "this", ";", "var", "idx", "=", "this", ".", "_searchLayerIndex", "(", ")", ";", "if", "(", "idx", ">=", "0", ")", "{", "this", ".", "gmapsMap", ".", "overlayMapTypes", ".", "removeAt", "(", "idx", ")", ";", "}", "else", "if", "(", "this", ".", "gmapsLayer", ".", "setMap", ")", "{", "this", ".", "gmapsLayer", ".", "setMap", "(", "null", ")", ";", "}", "this", ".", "model", ".", "unbind", "(", "null", ",", "null", ",", "this", ")", ";", "this", ".", "unbind", "(", ")", ";", "}", "}" ]
remove layer from the map and unbind events
[ "remove", "layer", "from", "the", "map", "and", "unbind", "events" ]
61d11c6268d59343746809639e0d23419674ae87
https://github.com/knownasilya/ember-leaflet-cartodb/blob/61d11c6268d59343746809639e0d23419674ae87/vendor/ember-leaflet-cartodb/cartodb_noleaflet.js#L26890-L26902
47,859
knownasilya/ember-leaflet-cartodb
vendor/ember-leaflet-cartodb/cartodb_noleaflet.js
function(layerModel, gmapsMap) { var self = this; _.bindAll(this, 'featureOut', 'featureOver', 'featureClick'); var opts = _.clone(layerModel.attributes); opts.map = gmapsMap; var // preserve the user's callbacks _featureOver = opts.featureOver, _featureOut = opts.featureOut, _featureClick = opts.featureClick; opts.featureOver = function() { _featureOver && _featureOver.apply(this, arguments); self.featureOver && self.featureOver.apply(this, arguments); }; opts.featureOut = function() { _featureOut && _featureOut.apply(this, arguments); self.featureOut && self.featureOut.apply(this, arguments); }; opts.featureClick = function() { _featureClick && _featureClick.apply(this, arguments); self.featureClick && self.featureClick.apply(opts, arguments); }; cdb.geo.CartoDBLayerGMaps.call(this, opts); cdb.geo.GMapsLayerView.call(this, layerModel, this, gmapsMap); }
javascript
function(layerModel, gmapsMap) { var self = this; _.bindAll(this, 'featureOut', 'featureOver', 'featureClick'); var opts = _.clone(layerModel.attributes); opts.map = gmapsMap; var // preserve the user's callbacks _featureOver = opts.featureOver, _featureOut = opts.featureOut, _featureClick = opts.featureClick; opts.featureOver = function() { _featureOver && _featureOver.apply(this, arguments); self.featureOver && self.featureOver.apply(this, arguments); }; opts.featureOut = function() { _featureOut && _featureOut.apply(this, arguments); self.featureOut && self.featureOut.apply(this, arguments); }; opts.featureClick = function() { _featureClick && _featureClick.apply(this, arguments); self.featureClick && self.featureClick.apply(opts, arguments); }; cdb.geo.CartoDBLayerGMaps.call(this, opts); cdb.geo.GMapsLayerView.call(this, layerModel, this, gmapsMap); }
[ "function", "(", "layerModel", ",", "gmapsMap", ")", "{", "var", "self", "=", "this", ";", "_", ".", "bindAll", "(", "this", ",", "'featureOut'", ",", "'featureOver'", ",", "'featureClick'", ")", ";", "var", "opts", "=", "_", ".", "clone", "(", "layerModel", ".", "attributes", ")", ";", "opts", ".", "map", "=", "gmapsMap", ";", "var", "// preserve the user's callbacks", "_featureOver", "=", "opts", ".", "featureOver", ",", "_featureOut", "=", "opts", ".", "featureOut", ",", "_featureClick", "=", "opts", ".", "featureClick", ";", "opts", ".", "featureOver", "=", "function", "(", ")", "{", "_featureOver", "&&", "_featureOver", ".", "apply", "(", "this", ",", "arguments", ")", ";", "self", ".", "featureOver", "&&", "self", ".", "featureOver", ".", "apply", "(", "this", ",", "arguments", ")", ";", "}", ";", "opts", ".", "featureOut", "=", "function", "(", ")", "{", "_featureOut", "&&", "_featureOut", ".", "apply", "(", "this", ",", "arguments", ")", ";", "self", ".", "featureOut", "&&", "self", ".", "featureOut", ".", "apply", "(", "this", ",", "arguments", ")", ";", "}", ";", "opts", ".", "featureClick", "=", "function", "(", ")", "{", "_featureClick", "&&", "_featureClick", ".", "apply", "(", "this", ",", "arguments", ")", ";", "self", ".", "featureClick", "&&", "self", ".", "featureClick", ".", "apply", "(", "opts", ",", "arguments", ")", ";", "}", ";", "cdb", ".", "geo", ".", "CartoDBLayerGMaps", ".", "call", "(", "this", ",", "opts", ")", ";", "cdb", ".", "geo", ".", "GMapsLayerView", ".", "call", "(", "this", ",", "layerModel", ",", "this", ",", "gmapsMap", ")", ";", "}" ]
gmaps cartodb layer
[ "gmaps", "cartodb", "layer" ]
61d11c6268d59343746809639e0d23419674ae87
https://github.com/knownasilya/ember-leaflet-cartodb/blob/61d11c6268d59343746809639e0d23419674ae87/vendor/ember-leaflet-cartodb/cartodb_noleaflet.js#L27601-L27632
47,860
knownasilya/ember-leaflet-cartodb
vendor/ember-leaflet-cartodb/cartodb_noleaflet.js
PointView
function PointView(geometryModel) { var self = this; // events to link var events = [ 'click', 'dblclick', 'mousedown', 'mouseover', 'mouseout', 'dragstart', 'drag', 'dragend' ]; this._eventHandlers = {}; this.model = geometryModel; this.points = []; var style = _.clone(geometryModel.get('style')) || {}; var iconAnchor = this.model.get('iconAnchor'); var icon = { url: this.model.get('iconUrl') || cdb.config.get('assets_url') + '/images/layout/default_marker.png', anchor: { x: iconAnchor && iconAnchor[0] || 10, y: iconAnchor && iconAnchor[1] || 10, } }; this.geom = new GeoJSON ( geometryModel.get('geojson'), { icon: icon, raiseOnDrag: false, crossOnDrag: false } ); // bind events var i; for(i = 0; i < events.length; ++i) { var e = events[i]; google.maps.event.addListener(this.geom, e, self._eventHandler(e)); } // link dragging this.bind('dragend', function(e, pos) { geometryModel.set({ geojson: { type: 'Point', // geojson is lng,lat coordinates: [pos[1], pos[0]] } }); }); }
javascript
function PointView(geometryModel) { var self = this; // events to link var events = [ 'click', 'dblclick', 'mousedown', 'mouseover', 'mouseout', 'dragstart', 'drag', 'dragend' ]; this._eventHandlers = {}; this.model = geometryModel; this.points = []; var style = _.clone(geometryModel.get('style')) || {}; var iconAnchor = this.model.get('iconAnchor'); var icon = { url: this.model.get('iconUrl') || cdb.config.get('assets_url') + '/images/layout/default_marker.png', anchor: { x: iconAnchor && iconAnchor[0] || 10, y: iconAnchor && iconAnchor[1] || 10, } }; this.geom = new GeoJSON ( geometryModel.get('geojson'), { icon: icon, raiseOnDrag: false, crossOnDrag: false } ); // bind events var i; for(i = 0; i < events.length; ++i) { var e = events[i]; google.maps.event.addListener(this.geom, e, self._eventHandler(e)); } // link dragging this.bind('dragend', function(e, pos) { geometryModel.set({ geojson: { type: 'Point', // geojson is lng,lat coordinates: [pos[1], pos[0]] } }); }); }
[ "function", "PointView", "(", "geometryModel", ")", "{", "var", "self", "=", "this", ";", "// events to link", "var", "events", "=", "[", "'click'", ",", "'dblclick'", ",", "'mousedown'", ",", "'mouseover'", ",", "'mouseout'", ",", "'dragstart'", ",", "'drag'", ",", "'dragend'", "]", ";", "this", ".", "_eventHandlers", "=", "{", "}", ";", "this", ".", "model", "=", "geometryModel", ";", "this", ".", "points", "=", "[", "]", ";", "var", "style", "=", "_", ".", "clone", "(", "geometryModel", ".", "get", "(", "'style'", ")", ")", "||", "{", "}", ";", "var", "iconAnchor", "=", "this", ".", "model", ".", "get", "(", "'iconAnchor'", ")", ";", "var", "icon", "=", "{", "url", ":", "this", ".", "model", ".", "get", "(", "'iconUrl'", ")", "||", "cdb", ".", "config", ".", "get", "(", "'assets_url'", ")", "+", "'/images/layout/default_marker.png'", ",", "anchor", ":", "{", "x", ":", "iconAnchor", "&&", "iconAnchor", "[", "0", "]", "||", "10", ",", "y", ":", "iconAnchor", "&&", "iconAnchor", "[", "1", "]", "||", "10", ",", "}", "}", ";", "this", ".", "geom", "=", "new", "GeoJSON", "(", "geometryModel", ".", "get", "(", "'geojson'", ")", ",", "{", "icon", ":", "icon", ",", "raiseOnDrag", ":", "false", ",", "crossOnDrag", ":", "false", "}", ")", ";", "// bind events", "var", "i", ";", "for", "(", "i", "=", "0", ";", "i", "<", "events", ".", "length", ";", "++", "i", ")", "{", "var", "e", "=", "events", "[", "i", "]", ";", "google", ".", "maps", ".", "event", ".", "addListener", "(", "this", ".", "geom", ",", "e", ",", "self", ".", "_eventHandler", "(", "e", ")", ")", ";", "}", "// link dragging", "this", ".", "bind", "(", "'dragend'", ",", "function", "(", "e", ",", "pos", ")", "{", "geometryModel", ".", "set", "(", "{", "geojson", ":", "{", "type", ":", "'Point'", ",", "// geojson is lng,lat", "coordinates", ":", "[", "pos", "[", "1", "]", ",", "pos", "[", "0", "]", "]", "}", "}", ")", ";", "}", ")", ";", "}" ]
view for markers
[ "view", "for", "markers" ]
61d11c6268d59343746809639e0d23419674ae87
https://github.com/knownasilya/ember-leaflet-cartodb/blob/61d11c6268d59343746809639e0d23419674ae87/vendor/ember-leaflet-cartodb/cartodb_noleaflet.js#L27699-L27754
47,861
knownasilya/ember-leaflet-cartodb
vendor/ember-leaflet-cartodb/cartodb_noleaflet.js
function(index, columnName) { var r = this.at(index); if(!r) { return null; } return r.get(columnName); }
javascript
function(index, columnName) { var r = this.at(index); if(!r) { return null; } return r.get(columnName); }
[ "function", "(", "index", ",", "columnName", ")", "{", "var", "r", "=", "this", ".", "at", "(", "index", ")", ";", "if", "(", "!", "r", ")", "{", "return", "null", ";", "}", "return", "r", ".", "get", "(", "columnName", ")", ";", "}" ]
get value for row index and columnName
[ "get", "value", "for", "row", "index", "and", "columnName" ]
61d11c6268d59343746809639e0d23419674ae87
https://github.com/knownasilya/ember-leaflet-cartodb/blob/61d11c6268d59343746809639e0d23419674ae87/vendor/ember-leaflet-cartodb/cartodb_noleaflet.js#L28762-L28768
47,862
knownasilya/ember-leaflet-cartodb
vendor/ember-leaflet-cartodb/cartodb_noleaflet.js
function() { this.$('tfoot').remove(); this.$('tr.noRows').remove(); // unbind rows before cleaning them when all are gonna be removed var rowView = null; while(rowView = this.rowViews.pop()) { // this is a hack to avoid all the elements are removed one by one rowView.unbind(null, null, this); // each element removes itself from rowViews rowView.clean(); } // clean all the html at the same time this.rowViews = []; }
javascript
function() { this.$('tfoot').remove(); this.$('tr.noRows').remove(); // unbind rows before cleaning them when all are gonna be removed var rowView = null; while(rowView = this.rowViews.pop()) { // this is a hack to avoid all the elements are removed one by one rowView.unbind(null, null, this); // each element removes itself from rowViews rowView.clean(); } // clean all the html at the same time this.rowViews = []; }
[ "function", "(", ")", "{", "this", ".", "$", "(", "'tfoot'", ")", ".", "remove", "(", ")", ";", "this", ".", "$", "(", "'tr.noRows'", ")", ".", "remove", "(", ")", ";", "// unbind rows before cleaning them when all are gonna be removed", "var", "rowView", "=", "null", ";", "while", "(", "rowView", "=", "this", ".", "rowViews", ".", "pop", "(", ")", ")", "{", "// this is a hack to avoid all the elements are removed one by one", "rowView", ".", "unbind", "(", "null", ",", "null", ",", "this", ")", ";", "// each element removes itself from rowViews", "rowView", ".", "clean", "(", ")", ";", "}", "// clean all the html at the same time", "this", ".", "rowViews", "=", "[", "]", ";", "}" ]
remove all rows
[ "remove", "all", "rows" ]
61d11c6268d59343746809639e0d23419674ae87
https://github.com/knownasilya/ember-leaflet-cartodb/blob/61d11c6268d59343746809639e0d23419674ae87/vendor/ember-leaflet-cartodb/cartodb_noleaflet.js#L28977-L28991
47,863
knownasilya/ember-leaflet-cartodb
vendor/ember-leaflet-cartodb/cartodb_noleaflet.js
function() { this.clear_rows(); if(! this.isEmptyTable()) { if(this.dataModel.fetched) { var self = this; this.dataModel.each(function(row) { self.addRow(row); }); } else { this._renderLoading(); } } else { this._renderEmpty(); } }
javascript
function() { this.clear_rows(); if(! this.isEmptyTable()) { if(this.dataModel.fetched) { var self = this; this.dataModel.each(function(row) { self.addRow(row); }); } else { this._renderLoading(); } } else { this._renderEmpty(); } }
[ "function", "(", ")", "{", "this", ".", "clear_rows", "(", ")", ";", "if", "(", "!", "this", ".", "isEmptyTable", "(", ")", ")", "{", "if", "(", "this", ".", "dataModel", ".", "fetched", ")", "{", "var", "self", "=", "this", ";", "this", ".", "dataModel", ".", "each", "(", "function", "(", "row", ")", "{", "self", ".", "addRow", "(", "row", ")", ";", "}", ")", ";", "}", "else", "{", "this", ".", "_renderLoading", "(", ")", ";", "}", "}", "else", "{", "this", ".", "_renderEmpty", "(", ")", ";", "}", "}" ]
render only data rows
[ "render", "only", "data", "rows" ]
61d11c6268d59343746809639e0d23419674ae87
https://github.com/knownasilya/ember-leaflet-cartodb/blob/61d11c6268d59343746809639e0d23419674ae87/vendor/ember-leaflet-cartodb/cartodb_noleaflet.js#L29099-L29115
47,864
knownasilya/ember-leaflet-cartodb
vendor/ember-leaflet-cartodb/cartodb_noleaflet.js
function(type, vis, data) { var t = Overlay._types[type]; if (!t) { cdb.log.error("Overlay: " + type + " does not exist"); return; } data.options = typeof data.options === 'string' ? JSON.parse(data.options): data.options; data.options = data.options || {} var widget = t(data, vis); if (widget) { widget.type = type; return widget; } return false; }
javascript
function(type, vis, data) { var t = Overlay._types[type]; if (!t) { cdb.log.error("Overlay: " + type + " does not exist"); return; } data.options = typeof data.options === 'string' ? JSON.parse(data.options): data.options; data.options = data.options || {} var widget = t(data, vis); if (widget) { widget.type = type; return widget; } return false; }
[ "function", "(", "type", ",", "vis", ",", "data", ")", "{", "var", "t", "=", "Overlay", ".", "_types", "[", "type", "]", ";", "if", "(", "!", "t", ")", "{", "cdb", ".", "log", ".", "error", "(", "\"Overlay: \"", "+", "type", "+", "\" does not exist\"", ")", ";", "return", ";", "}", "data", ".", "options", "=", "typeof", "data", ".", "options", "===", "'string'", "?", "JSON", ".", "parse", "(", "data", ".", "options", ")", ":", "data", ".", "options", ";", "data", ".", "options", "=", "data", ".", "options", "||", "{", "}", "var", "widget", "=", "t", "(", "data", ",", "vis", ")", ";", "if", "(", "widget", ")", "{", "widget", ".", "type", "=", "type", ";", "return", "widget", ";", "}", "return", "false", ";", "}" ]
create a type given the data raise an exception if the type does not exist
[ "create", "a", "type", "given", "the", "data", "raise", "an", "exception", "if", "the", "type", "does", "not", "exist" ]
61d11c6268d59343746809639e0d23419674ae87
https://github.com/knownasilya/ember-leaflet-cartodb/blob/61d11c6268d59343746809639e0d23419674ae87/vendor/ember-leaflet-cartodb/cartodb_noleaflet.js#L29344-L29362
47,865
knownasilya/ember-leaflet-cartodb
vendor/ember-leaflet-cartodb/cartodb_noleaflet.js
function(layers) { var mods = Layers.modulesForLayers(layers); return _.every(_.map(mods, function(m) { return cartodb[m] !== undefined; })); }
javascript
function(layers) { var mods = Layers.modulesForLayers(layers); return _.every(_.map(mods, function(m) { return cartodb[m] !== undefined; })); }
[ "function", "(", "layers", ")", "{", "var", "mods", "=", "Layers", ".", "modulesForLayers", "(", "layers", ")", ";", "return", "_", ".", "every", "(", "_", ".", "map", "(", "mods", ",", "function", "(", "m", ")", "{", "return", "cartodb", "[", "m", "]", "!==", "undefined", ";", "}", ")", ")", ";", "}" ]
check if all the modules needed to create layers are loaded
[ "check", "if", "all", "the", "modules", "needed", "to", "create", "layers", "are", "loaded" ]
61d11c6268d59343746809639e0d23419674ae87
https://github.com/knownasilya/ember-leaflet-cartodb/blob/61d11c6268d59343746809639e0d23419674ae87/vendor/ember-leaflet-cartodb/cartodb_noleaflet.js#L29454-L29457
47,866
knownasilya/ember-leaflet-cartodb
vendor/ember-leaflet-cartodb/cartodb_noleaflet.js
function() { var self = this; return _.compact(this.map.layers.map(function(layer) { return self.mapView.getLayerByCid(layer.cid); })); }
javascript
function() { var self = this; return _.compact(this.map.layers.map(function(layer) { return self.mapView.getLayerByCid(layer.cid); })); }
[ "function", "(", ")", "{", "var", "self", "=", "this", ";", "return", "_", ".", "compact", "(", "this", ".", "map", ".", "layers", ".", "map", "(", "function", "(", "layer", ")", "{", "return", "self", ".", "mapView", ".", "getLayerByCid", "(", "layer", ".", "cid", ")", ";", "}", ")", ")", ";", "}" ]
returns an array of layers
[ "returns", "an", "array", "of", "layers" ]
61d11c6268d59343746809639e0d23419674ae87
https://github.com/knownasilya/ember-leaflet-cartodb/blob/61d11c6268d59343746809639e0d23419674ae87/vendor/ember-leaflet-cartodb/cartodb_noleaflet.js#L30681-L30686
47,867
knownasilya/ember-leaflet-cartodb
vendor/ember-leaflet-cartodb/cartodb_noleaflet.js
cartodbUrl
function cartodbUrl(opts) { var host = opts.host || 'carto.com'; var protocol = opts.protocol || 'https'; return protocol + '://' + opts.user + '.' + host + '/api/v1/viz/' + opts.table + '/viz.json'; }
javascript
function cartodbUrl(opts) { var host = opts.host || 'carto.com'; var protocol = opts.protocol || 'https'; return protocol + '://' + opts.user + '.' + host + '/api/v1/viz/' + opts.table + '/viz.json'; }
[ "function", "cartodbUrl", "(", "opts", ")", "{", "var", "host", "=", "opts", ".", "host", "||", "'carto.com'", ";", "var", "protocol", "=", "opts", ".", "protocol", "||", "'https'", ";", "return", "protocol", "+", "'://'", "+", "opts", ".", "user", "+", "'.'", "+", "host", "+", "'/api/v1/viz/'", "+", "opts", ".", "table", "+", "'/viz.json'", ";", "}" ]
compose cartodb url
[ "compose", "cartodb", "url" ]
61d11c6268d59343746809639e0d23419674ae87
https://github.com/knownasilya/ember-leaflet-cartodb/blob/61d11c6268d59343746809639e0d23419674ae87/vendor/ember-leaflet-cartodb/cartodb_noleaflet.js#L32053-L32057
47,868
knownasilya/ember-leaflet-cartodb
vendor/ember-leaflet-cartodb/cartodb_noleaflet.js
_getLayerJson
function _getLayerJson(layer, callback) { var url = null; if(layer.layers !== undefined || ((layer.kind || layer.type) !== undefined)) { // layer object contains the layer data _.defer(function() { callback(layer); }); return; } else if(layer.table !== undefined && layer.user !== undefined) { // layer object points to cartodbjson url = cartodbUrl(layer); } else if(layer.indexOf) { // fetch from url url = layer; } if(url) { cdb.core.Loader.get(url, callback); } else { _.defer(function() { callback(null); }); } }
javascript
function _getLayerJson(layer, callback) { var url = null; if(layer.layers !== undefined || ((layer.kind || layer.type) !== undefined)) { // layer object contains the layer data _.defer(function() { callback(layer); }); return; } else if(layer.table !== undefined && layer.user !== undefined) { // layer object points to cartodbjson url = cartodbUrl(layer); } else if(layer.indexOf) { // fetch from url url = layer; } if(url) { cdb.core.Loader.get(url, callback); } else { _.defer(function() { callback(null); }); } }
[ "function", "_getLayerJson", "(", "layer", ",", "callback", ")", "{", "var", "url", "=", "null", ";", "if", "(", "layer", ".", "layers", "!==", "undefined", "||", "(", "(", "layer", ".", "kind", "||", "layer", ".", "type", ")", "!==", "undefined", ")", ")", "{", "// layer object contains the layer data", "_", ".", "defer", "(", "function", "(", ")", "{", "callback", "(", "layer", ")", ";", "}", ")", ";", "return", ";", "}", "else", "if", "(", "layer", ".", "table", "!==", "undefined", "&&", "layer", ".", "user", "!==", "undefined", ")", "{", "// layer object points to cartodbjson", "url", "=", "cartodbUrl", "(", "layer", ")", ";", "}", "else", "if", "(", "layer", ".", "indexOf", ")", "{", "// fetch from url", "url", "=", "layer", ";", "}", "if", "(", "url", ")", "{", "cdb", ".", "core", ".", "Loader", ".", "get", "(", "url", ",", "callback", ")", ";", "}", "else", "{", "_", ".", "defer", "(", "function", "(", ")", "{", "callback", "(", "null", ")", ";", "}", ")", ";", "}", "}" ]
given layer params fetchs the layer json
[ "given", "layer", "params", "fetchs", "the", "layer", "json" ]
61d11c6268d59343746809639e0d23419674ae87
https://github.com/knownasilya/ember-leaflet-cartodb/blob/61d11c6268d59343746809639e0d23419674ae87/vendor/ember-leaflet-cartodb/cartodb_noleaflet.js#L32062-L32080
47,869
rtm/upward
src/Utl.js
seq
function seq(to, from = 0, step = 1) { var result = []; var count = 0; if (to > from) for (let i = from; i < to; i += step) result[count++] = i; else for (let i = from; i > to; i -= step) result[count++] = i; return result; }
javascript
function seq(to, from = 0, step = 1) { var result = []; var count = 0; if (to > from) for (let i = from; i < to; i += step) result[count++] = i; else for (let i = from; i > to; i -= step) result[count++] = i; return result; }
[ "function", "seq", "(", "to", ",", "from", "=", "0", ",", "step", "=", "1", ")", "{", "var", "result", "=", "[", "]", ";", "var", "count", "=", "0", ";", "if", "(", "to", ">", "from", ")", "for", "(", "let", "i", "=", "from", ";", "i", "<", "to", ";", "i", "+=", "step", ")", "result", "[", "count", "++", "]", "=", "i", ";", "else", "for", "(", "let", "i", "=", "from", ";", "i", ">", "to", ";", "i", "-=", "step", ")", "result", "[", "count", "++", "]", "=", "i", ";", "return", "result", ";", "}" ]
Create an array of a sequence of integers.
[ "Create", "an", "array", "of", "a", "sequence", "of", "integers", "." ]
82495c34f70c9a4336a3b34cc6781e5662324c03
https://github.com/rtm/upward/blob/82495c34f70c9a4336a3b34cc6781e5662324c03/src/Utl.js#L15-L22
47,870
rtm/upward
src/Utl.js
omit
function omit(a, elt) { var index = a.indexOf(elt); if (index !== -1) { a.splice(index, 1); } return a; }
javascript
function omit(a, elt) { var index = a.indexOf(elt); if (index !== -1) { a.splice(index, 1); } return a; }
[ "function", "omit", "(", "a", ",", "elt", ")", "{", "var", "index", "=", "a", ".", "indexOf", "(", "elt", ")", ";", "if", "(", "index", "!==", "-", "1", ")", "{", "a", ".", "splice", "(", "index", ",", "1", ")", ";", "}", "return", "a", ";", "}" ]
Omit elements from array destructively.
[ "Omit", "elements", "from", "array", "destructively", "." ]
82495c34f70c9a4336a3b34cc6781e5662324c03
https://github.com/rtm/upward/blob/82495c34f70c9a4336a3b34cc6781e5662324c03/src/Utl.js#L100-L106
47,871
rtm/upward
src/Utl.js
replace
function replace(a, elt1, elt2) { var idx = a.indexOf(elt1); if (idx !== -1) { a[idx] = elt2; } return a; }
javascript
function replace(a, elt1, elt2) { var idx = a.indexOf(elt1); if (idx !== -1) { a[idx] = elt2; } return a; }
[ "function", "replace", "(", "a", ",", "elt1", ",", "elt2", ")", "{", "var", "idx", "=", "a", ".", "indexOf", "(", "elt1", ")", ";", "if", "(", "idx", "!==", "-", "1", ")", "{", "a", "[", "idx", "]", "=", "elt2", ";", "}", "return", "a", ";", "}" ]
Replace one element in an array with another.
[ "Replace", "one", "element", "in", "an", "array", "with", "another", "." ]
82495c34f70c9a4336a3b34cc6781e5662324c03
https://github.com/rtm/upward/blob/82495c34f70c9a4336a3b34cc6781e5662324c03/src/Utl.js#L109-L113
47,872
rtm/upward
src/Utl.js
reverse
function reverse(a) { var len = a.length; for (var i = 0; i < Math.floor(len/2); i++) { [a[i], a[len-i-1]] = [a[len-i-1], a[i]]; } return a; }
javascript
function reverse(a) { var len = a.length; for (var i = 0; i < Math.floor(len/2); i++) { [a[i], a[len-i-1]] = [a[len-i-1], a[i]]; } return a; }
[ "function", "reverse", "(", "a", ")", "{", "var", "len", "=", "a", ".", "length", ";", "for", "(", "var", "i", "=", "0", ";", "i", "<", "Math", ".", "floor", "(", "len", "/", "2", ")", ";", "i", "++", ")", "{", "[", "a", "[", "i", "]", ",", "a", "[", "len", "-", "i", "-", "1", "]", "]", "=", "[", "a", "[", "len", "-", "i", "-", "1", "]", ",", "a", "[", "i", "]", "]", ";", "}", "return", "a", ";", "}" ]
reverse an array in place
[ "reverse", "an", "array", "in", "place" ]
82495c34f70c9a4336a3b34cc6781e5662324c03
https://github.com/rtm/upward/blob/82495c34f70c9a4336a3b34cc6781e5662324c03/src/Utl.js#L116-L122
47,873
rtm/upward
src/Utl.js
flatten
function flatten(a) { function _reduce(a) { return a.reduce(_flatten, []); } function _flatten(a, b) { return a.concat(Array.isArray(b) ? _reduce(b) : b); } return _reduce(a); }
javascript
function flatten(a) { function _reduce(a) { return a.reduce(_flatten, []); } function _flatten(a, b) { return a.concat(Array.isArray(b) ? _reduce(b) : b); } return _reduce(a); }
[ "function", "flatten", "(", "a", ")", "{", "function", "_reduce", "(", "a", ")", "{", "return", "a", ".", "reduce", "(", "_flatten", ",", "[", "]", ")", ";", "}", "function", "_flatten", "(", "a", ",", "b", ")", "{", "return", "a", ".", "concat", "(", "Array", ".", "isArray", "(", "b", ")", "?", "_reduce", "(", "b", ")", ":", "b", ")", ";", "}", "return", "_reduce", "(", "a", ")", ";", "}" ]
Flatten an array.
[ "Flatten", "an", "array", "." ]
82495c34f70c9a4336a3b34cc6781e5662324c03
https://github.com/rtm/upward/blob/82495c34f70c9a4336a3b34cc6781e5662324c03/src/Utl.js#L125-L133
47,874
rtm/upward
src/Utl.js
uniqueize
function uniqueize(a) { return a.filter((elt, i) => a.indexOf(elt) === i); }
javascript
function uniqueize(a) { return a.filter((elt, i) => a.indexOf(elt) === i); }
[ "function", "uniqueize", "(", "a", ")", "{", "return", "a", ".", "filter", "(", "(", "elt", ",", "i", ")", "=>", "a", ".", "indexOf", "(", "elt", ")", "===", "i", ")", ";", "}" ]
Create an array of unique values. @TODO replace this logic using Set.
[ "Create", "an", "array", "of", "unique", "values", "." ]
82495c34f70c9a4336a3b34cc6781e5662324c03
https://github.com/rtm/upward/blob/82495c34f70c9a4336a3b34cc6781e5662324c03/src/Utl.js#L189-L191
47,875
rtm/upward
src/Utl.js
indexesOf
function indexesOf(a, elt) { var ret = [], index = 0; while ((index = a.indexOf(elt, index)) !== -1) { ret.push(index++); } return ret; }
javascript
function indexesOf(a, elt) { var ret = [], index = 0; while ((index = a.indexOf(elt, index)) !== -1) { ret.push(index++); } return ret; }
[ "function", "indexesOf", "(", "a", ",", "elt", ")", "{", "var", "ret", "=", "[", "]", ",", "index", "=", "0", ";", "while", "(", "(", "index", "=", "a", ".", "indexOf", "(", "elt", ",", "index", ")", ")", "!==", "-", "1", ")", "{", "ret", ".", "push", "(", "index", "++", ")", ";", "}", "return", "ret", ";", "}" ]
Find all occurrences of element in an array, return indices. @NOTUSED
[ "Find", "all", "occurrences", "of", "element", "in", "an", "array", "return", "indices", "." ]
82495c34f70c9a4336a3b34cc6781e5662324c03
https://github.com/rtm/upward/blob/82495c34f70c9a4336a3b34cc6781e5662324c03/src/Utl.js#L195-L201
47,876
rtm/upward
src/Utl.js
runningMap
function runningMap(a, fn, init) { return a.map(v => init = fn(v, init)); }
javascript
function runningMap(a, fn, init) { return a.map(v => init = fn(v, init)); }
[ "function", "runningMap", "(", "a", ",", "fn", ",", "init", ")", "{", "return", "a", ".", "map", "(", "v", "=>", "init", "=", "fn", "(", "v", ",", "init", ")", ")", ";", "}" ]
Create an array of running totals, etc.
[ "Create", "an", "array", "of", "running", "totals", "etc", "." ]
82495c34f70c9a4336a3b34cc6781e5662324c03
https://github.com/rtm/upward/blob/82495c34f70c9a4336a3b34cc6781e5662324c03/src/Utl.js#L209-L211
47,877
rtm/upward
src/Utl.js
chainPromises
function chainPromises(...fns) { return [...fns].reduce( (result, fn) => result.then(fn), Promise.resolve() ); }
javascript
function chainPromises(...fns) { return [...fns].reduce( (result, fn) => result.then(fn), Promise.resolve() ); }
[ "function", "chainPromises", "(", "...", "fns", ")", "{", "return", "[", "...", "fns", "]", ".", "reduce", "(", "(", "result", ",", "fn", ")", "=>", "result", ".", "then", "(", "fn", ")", ",", "Promise", ".", "resolve", "(", ")", ")", ";", "}" ]
Chain fns together using promises.
[ "Chain", "fns", "together", "using", "promises", "." ]
82495c34f70c9a4336a3b34cc6781e5662324c03
https://github.com/rtm/upward/blob/82495c34f70c9a4336a3b34cc6781e5662324c03/src/Utl.js#L229-L234
47,878
rtm/upward
src/Utl.js
makeCounterMap
function makeCounterMap() { var map = new WeakMap(); return { init(obj) { map.set(obj, 0); }, incr(obj) { console.assert(map.has(obj), "Object must be in counter map."); map.set(obj, map.get(obj) + 1); }, get(obj) { return map.get(obj); } }; }
javascript
function makeCounterMap() { var map = new WeakMap(); return { init(obj) { map.set(obj, 0); }, incr(obj) { console.assert(map.has(obj), "Object must be in counter map."); map.set(obj, map.get(obj) + 1); }, get(obj) { return map.get(obj); } }; }
[ "function", "makeCounterMap", "(", ")", "{", "var", "map", "=", "new", "WeakMap", "(", ")", ";", "return", "{", "init", "(", "obj", ")", "{", "map", ".", "set", "(", "obj", ",", "0", ")", ";", "}", ",", "incr", "(", "obj", ")", "{", "console", ".", "assert", "(", "map", ".", "has", "(", "obj", ")", ",", "\"Object must be in counter map.\"", ")", ";", "map", ".", "set", "(", "obj", ",", "map", ".", "get", "(", "obj", ")", "+", "1", ")", ";", "}", ",", "get", "(", "obj", ")", "{", "return", "map", ".", "get", "(", "obj", ")", ";", "}", "}", ";", "}" ]
Make a counter for occurrences of something on an object, using weak map. For example, used to count recomputations of "keepXXX" results.
[ "Make", "a", "counter", "for", "occurrences", "of", "something", "on", "an", "object", "using", "weak", "map", ".", "For", "example", "used", "to", "count", "recomputations", "of", "keepXXX", "results", "." ]
82495c34f70c9a4336a3b34cc6781e5662324c03
https://github.com/rtm/upward/blob/82495c34f70c9a4336a3b34cc6781e5662324c03/src/Utl.js#L259-L269
47,879
rtm/upward
src/Utl.js
interleave
function interleave(...arrays) { var more = true; var n = 0; var result = []; while (more) { more = false; for (var array of arrays) { if (n >= array.length) continue; result.push(array[n]); more = true; } n++; } return result; }
javascript
function interleave(...arrays) { var more = true; var n = 0; var result = []; while (more) { more = false; for (var array of arrays) { if (n >= array.length) continue; result.push(array[n]); more = true; } n++; } return result; }
[ "function", "interleave", "(", "...", "arrays", ")", "{", "var", "more", "=", "true", ";", "var", "n", "=", "0", ";", "var", "result", "=", "[", "]", ";", "while", "(", "more", ")", "{", "more", "=", "false", ";", "for", "(", "var", "array", "of", "arrays", ")", "{", "if", "(", "n", ">=", "array", ".", "length", ")", "continue", ";", "result", ".", "push", "(", "array", "[", "n", "]", ")", ";", "more", "=", "true", ";", "}", "n", "++", ";", "}", "return", "result", ";", "}" ]
Interleave multiple arrays.
[ "Interleave", "multiple", "arrays", "." ]
82495c34f70c9a4336a3b34cc6781e5662324c03
https://github.com/rtm/upward/blob/82495c34f70c9a4336a3b34cc6781e5662324c03/src/Utl.js#L272-L286
47,880
thybzi/styledoc
styledoc.js
getUniqueItemId
function getUniqueItemId(selector) { var base_id = selectorToId(selector), id = base_id, numeric_suffix = 0; while (used_item_ids.indexOf(id) !== -1) { id = base_id + "_" + ++numeric_suffix; } used_item_ids.push(id); return id; }
javascript
function getUniqueItemId(selector) { var base_id = selectorToId(selector), id = base_id, numeric_suffix = 0; while (used_item_ids.indexOf(id) !== -1) { id = base_id + "_" + ++numeric_suffix; } used_item_ids.push(id); return id; }
[ "function", "getUniqueItemId", "(", "selector", ")", "{", "var", "base_id", "=", "selectorToId", "(", "selector", ")", ",", "id", "=", "base_id", ",", "numeric_suffix", "=", "0", ";", "while", "(", "used_item_ids", ".", "indexOf", "(", "id", ")", "!==", "-", "1", ")", "{", "id", "=", "base_id", "+", "\"_\"", "+", "++", "numeric_suffix", ";", "}", "used_item_ids", ".", "push", "(", "id", ")", ";", "return", "id", ";", "}" ]
Converts selector to ID and assures it is unique @param {string} selector @returns {string} @todo dry?
[ "Converts", "selector", "to", "ID", "and", "assures", "it", "is", "unique" ]
f478da33b66ffa10d1426ed2dd90a5f457fe5248
https://github.com/thybzi/styledoc/blob/f478da33b66ffa10d1426ed2dd90a5f457fe5248/styledoc.js#L349-L361
47,881
thybzi/styledoc
styledoc.js
getUniqueSectionAnchor
function getUniqueSectionAnchor(anchor) { var base_anchor = anchor, numeric_suffix = 0; while (used_section_anchors.indexOf(anchor) !== -1) { anchor = base_anchor + "_" + ++numeric_suffix; } used_section_anchors.push(anchor); return anchor; }
javascript
function getUniqueSectionAnchor(anchor) { var base_anchor = anchor, numeric_suffix = 0; while (used_section_anchors.indexOf(anchor) !== -1) { anchor = base_anchor + "_" + ++numeric_suffix; } used_section_anchors.push(anchor); return anchor; }
[ "function", "getUniqueSectionAnchor", "(", "anchor", ")", "{", "var", "base_anchor", "=", "anchor", ",", "numeric_suffix", "=", "0", ";", "while", "(", "used_section_anchors", ".", "indexOf", "(", "anchor", ")", "!==", "-", "1", ")", "{", "anchor", "=", "base_anchor", "+", "\"_\"", "+", "++", "numeric_suffix", ";", "}", "used_section_anchors", ".", "push", "(", "anchor", ")", ";", "return", "anchor", ";", "}" ]
Assures section anchor to be unique @param {string} anchor @returns {string} @todo dry?
[ "Assures", "section", "anchor", "to", "be", "unique" ]
f478da33b66ffa10d1426ed2dd90a5f457fe5248
https://github.com/thybzi/styledoc/blob/f478da33b66ffa10d1426ed2dd90a5f457fe5248/styledoc.js#L370-L381
47,882
thybzi/styledoc
styledoc.js
getPreviewContainerStyle
function getPreviewContainerStyle(options) { var preview_container_style = ""; var padding_value = options.preview_padding; if (typeof padding_value === "number") { padding_value = [ padding_value ]; } if (isArray(padding_value)) { preview_container_style += "padding: " + padding_value.join("px ") + "px !important; "; } if (options.background_color) { preview_container_style += "background-color: " + options.background_color + " !important; "; } return preview_container_style.replace(/\s$/, "") || undefined; }
javascript
function getPreviewContainerStyle(options) { var preview_container_style = ""; var padding_value = options.preview_padding; if (typeof padding_value === "number") { padding_value = [ padding_value ]; } if (isArray(padding_value)) { preview_container_style += "padding: " + padding_value.join("px ") + "px !important; "; } if (options.background_color) { preview_container_style += "background-color: " + options.background_color + " !important; "; } return preview_container_style.replace(/\s$/, "") || undefined; }
[ "function", "getPreviewContainerStyle", "(", "options", ")", "{", "var", "preview_container_style", "=", "\"\"", ";", "var", "padding_value", "=", "options", ".", "preview_padding", ";", "if", "(", "typeof", "padding_value", "===", "\"number\"", ")", "{", "padding_value", "=", "[", "padding_value", "]", ";", "}", "if", "(", "isArray", "(", "padding_value", ")", ")", "{", "preview_container_style", "+=", "\"padding: \"", "+", "padding_value", ".", "join", "(", "\"px \"", ")", "+", "\"px !important; \"", ";", "}", "if", "(", "options", ".", "background_color", ")", "{", "preview_container_style", "+=", "\"background-color: \"", "+", "options", ".", "background_color", "+", "\" !important; \"", ";", "}", "return", "preview_container_style", ".", "replace", "(", "/", "\\s$", "/", ",", "\"\"", ")", "||", "undefined", ";", "}" ]
Generate value for the preview container "style" attribute @param {object} options @param {number|number[]} [options.preview_padding] Padding value(s) for preview container (4 or [4, 8], or [4, 0, 12, 8] etc.) @param {string} [options.background_color] Background color CSS value for both main showcase page and preview iframe pages @returns {string|undefined} Undefined value denies redundant attribute creating: $elem.attr("style", undefined) @todo enable string value for preview_padding (like "4px 8px")?
[ "Generate", "value", "for", "the", "preview", "container", "style", "attribute" ]
f478da33b66ffa10d1426ed2dd90a5f457fe5248
https://github.com/thybzi/styledoc/blob/f478da33b66ffa10d1426ed2dd90a5f457fe5248/styledoc.js#L1340-L1356
47,883
thybzi/styledoc
styledoc.js
selectorToId
function selectorToId(selector) { var id = selector.replace(/[^a-z0-9_-]/ig, "_"); if (styledoc.item_id_trim_underscores) { id = id.replace(/_{2,}/g, "_").replace(/^_/, "").replace(/_$/, ""); } return id; }
javascript
function selectorToId(selector) { var id = selector.replace(/[^a-z0-9_-]/ig, "_"); if (styledoc.item_id_trim_underscores) { id = id.replace(/_{2,}/g, "_").replace(/^_/, "").replace(/_$/, ""); } return id; }
[ "function", "selectorToId", "(", "selector", ")", "{", "var", "id", "=", "selector", ".", "replace", "(", "/", "[^a-z0-9_-]", "/", "ig", ",", "\"_\"", ")", ";", "if", "(", "styledoc", ".", "item_id_trim_underscores", ")", "{", "id", "=", "id", ".", "replace", "(", "/", "_{2,}", "/", "g", ",", "\"_\"", ")", ".", "replace", "(", "/", "^_", "/", ",", "\"\"", ")", ".", "replace", "(", "/", "_$", "/", ",", "\"\"", ")", ";", "}", "return", "id", ";", "}" ]
Replace any char other than latin letters, digits, hyphens and underscores with underscore char Also wipes out the first underscore char (@todo is it really good and safe idea?) E.g.: .my-class => my-class .my-class.subclass#id #otherid => my-class_subclass_id__otherid @param {string} selector @returns {string}
[ "Replace", "any", "char", "other", "than", "latin", "letters", "digits", "hyphens", "and", "underscores", "with", "underscore", "char", "Also", "wipes", "out", "the", "first", "underscore", "char", "(" ]
f478da33b66ffa10d1426ed2dd90a5f457fe5248
https://github.com/thybzi/styledoc/blob/f478da33b66ffa10d1426ed2dd90a5f457fe5248/styledoc.js#L1367-L1375
47,884
flatiron/cortex.js
lib/cortex.js
on
function on(event, callback, context) { var events = eventsplitter.test(event) ? event.split(eventsplitter) : [event]; this.events = this.events || (this.events = {}); while (event = events.shift()) { if (!event) continue; (this.events[event] = this.events[event] || []).push({ context: context , callback: callback }); } return this; }
javascript
function on(event, callback, context) { var events = eventsplitter.test(event) ? event.split(eventsplitter) : [event]; this.events = this.events || (this.events = {}); while (event = events.shift()) { if (!event) continue; (this.events[event] = this.events[event] || []).push({ context: context , callback: callback }); } return this; }
[ "function", "on", "(", "event", ",", "callback", ",", "context", ")", "{", "var", "events", "=", "eventsplitter", ".", "test", "(", "event", ")", "?", "event", ".", "split", "(", "eventsplitter", ")", ":", "[", "event", "]", ";", "this", ".", "events", "=", "this", ".", "events", "||", "(", "this", ".", "events", "=", "{", "}", ")", ";", "while", "(", "event", "=", "events", ".", "shift", "(", ")", ")", "{", "if", "(", "!", "event", ")", "continue", ";", "(", "this", ".", "events", "[", "event", "]", "=", "this", ".", "events", "[", "event", "]", "||", "[", "]", ")", ".", "push", "(", "{", "context", ":", "context", ",", "callback", ":", "callback", "}", ")", ";", "}", "return", "this", ";", "}" ]
Adds an event listener. @param {String} events space separated list of events to listen on @param {Function} callback @param {Mixed} context @api public
[ "Adds", "an", "event", "listener", "." ]
d8fe3829513e36755a5380933a778758c4bf5892
https://github.com/flatiron/cortex.js/blob/d8fe3829513e36755a5380933a778758c4bf5892/lib/cortex.js#L205-L222
47,885
flatiron/cortex.js
lib/cortex.js
remove
function remove(handle) { return !( handle.callback === callback && (!context ? true : handle.context === context) ); }
javascript
function remove(handle) { return !( handle.callback === callback && (!context ? true : handle.context === context) ); }
[ "function", "remove", "(", "handle", ")", "{", "return", "!", "(", "handle", ".", "callback", "===", "callback", "&&", "(", "!", "context", "?", "true", ":", "handle", ".", "context", "===", "context", ")", ")", ";", "}" ]
Helper function to filter out the `this.events` array @param {Function} handle the callback of the event @api private
[ "Helper", "function", "to", "filter", "out", "the", "this", ".", "events", "array" ]
d8fe3829513e36755a5380933a778758c4bf5892
https://github.com/flatiron/cortex.js/blob/d8fe3829513e36755a5380933a778758c4bf5892/lib/cortex.js#L255-L260
47,886
flatiron/cortex.js
lib/cortex.js
call
function call(handle) { handle.callback.apply(handle.context, args); called = true; }
javascript
function call(handle) { handle.callback.apply(handle.context, args); called = true; }
[ "function", "call", "(", "handle", ")", "{", "handle", ".", "callback", ".", "apply", "(", "handle", ".", "context", ",", "args", ")", ";", "called", "=", "true", ";", "}" ]
Helper function that is called on each iteration of matching events. @param {Function} handle @api private
[ "Helper", "function", "that", "is", "called", "on", "each", "iteration", "of", "matching", "events", "." ]
d8fe3829513e36755a5380933a778758c4bf5892
https://github.com/flatiron/cortex.js/blob/d8fe3829513e36755a5380933a778758c4bf5892/lib/cortex.js#L298-L301
47,887
flatiron/cortex.js
lib/cortex.js
get
function get(attr) { if (!~attr.indexOf('.')) return this.attributes[attr]; var result = attr , structure = this.attributes; for (var paths = attr.split('.'), i = 0, length = paths.length; i < length && structure; i++) { result = structure[+paths[i] || paths[i]]; structure = result; } return result || this.attributes[attr]; }
javascript
function get(attr) { if (!~attr.indexOf('.')) return this.attributes[attr]; var result = attr , structure = this.attributes; for (var paths = attr.split('.'), i = 0, length = paths.length; i < length && structure; i++) { result = structure[+paths[i] || paths[i]]; structure = result; } return result || this.attributes[attr]; }
[ "function", "get", "(", "attr", ")", "{", "if", "(", "!", "~", "attr", ".", "indexOf", "(", "'.'", ")", ")", "return", "this", ".", "attributes", "[", "attr", "]", ";", "var", "result", "=", "attr", ",", "structure", "=", "this", ".", "attributes", ";", "for", "(", "var", "paths", "=", "attr", ".", "split", "(", "'.'", ")", ",", "i", "=", "0", ",", "length", "=", "paths", ".", "length", ";", "i", "<", "length", "&&", "structure", ";", "i", "++", ")", "{", "result", "=", "structure", "[", "+", "paths", "[", "i", "]", "||", "paths", "[", "i", "]", "]", ";", "structure", "=", "result", ";", "}", "return", "result", "||", "this", ".", "attributes", "[", "attr", "]", ";", "}" ]
Get attributes from the structure @param {String} attr @returns {Mixed} @api public
[ "Get", "attributes", "from", "the", "structure" ]
d8fe3829513e36755a5380933a778758c4bf5892
https://github.com/flatiron/cortex.js/blob/d8fe3829513e36755a5380933a778758c4bf5892/lib/cortex.js#L408-L420
47,888
alexindigo/batcher
default_reporter.js
function(state) { console.log('# Started batch process\n'); console.log('## Initial State:\n'); console.log('```'); console.log(JSON.stringify(sortKeys(state), null, 2)); console.log('```'); console.log('\n## Execution\n'); }
javascript
function(state) { console.log('# Started batch process\n'); console.log('## Initial State:\n'); console.log('```'); console.log(JSON.stringify(sortKeys(state), null, 2)); console.log('```'); console.log('\n## Execution\n'); }
[ "function", "(", "state", ")", "{", "console", ".", "log", "(", "'# Started batch process\\n'", ")", ";", "console", ".", "log", "(", "'## Initial State:\\n'", ")", ";", "console", ".", "log", "(", "'```'", ")", ";", "console", ".", "log", "(", "JSON", ".", "stringify", "(", "sortKeys", "(", "state", ")", ",", "null", ",", "2", ")", ")", ";", "console", ".", "log", "(", "'```'", ")", ";", "console", ".", "log", "(", "'\\n## Execution\\n'", ")", ";", "}" ]
Handles initial state report @param {object} state - current state @returns {void}
[ "Handles", "initial", "state", "report" ]
73d9c8c994f915688db0627ea3b4854ead771138
https://github.com/alexindigo/batcher/blob/73d9c8c994f915688db0627ea3b4854ead771138/default_reporter.js#L13-L21
47,889
alexindigo/batcher
default_reporter.js
function(state, command, error) { console.log('> Failed to execute ``', command, '``' + withCmdPrefix(state) + ':'); console.log('```'); console.log(JSON.stringify(error, null, 2)); console.log('```'); }
javascript
function(state, command, error) { console.log('> Failed to execute ``', command, '``' + withCmdPrefix(state) + ':'); console.log('```'); console.log(JSON.stringify(error, null, 2)); console.log('```'); }
[ "function", "(", "state", ",", "command", ",", "error", ")", "{", "console", ".", "log", "(", "'> Failed to execute ``'", ",", "command", ",", "'``'", "+", "withCmdPrefix", "(", "state", ")", "+", "':'", ")", ";", "console", ".", "log", "(", "'```'", ")", ";", "console", ".", "log", "(", "JSON", ".", "stringify", "(", "error", ",", "null", ",", "2", ")", ")", ";", "console", ".", "log", "(", "'```'", ")", ";", "}" ]
Handles reports with command's errors @param {object} state - current state @param {string} command - string representation of the command @param {object} error - error returned by the command's execution @returns {void}
[ "Handles", "reports", "with", "command", "s", "errors" ]
73d9c8c994f915688db0627ea3b4854ead771138
https://github.com/alexindigo/batcher/blob/73d9c8c994f915688db0627ea3b4854ead771138/default_reporter.js#L43-L49
47,890
alexindigo/batcher
default_reporter.js
function(state, command, output) { console.log('> Finished execution of ``', command, '``' + withCmdPrefix(state) + ':'); if (!Array.isArray(output)) output = [output]; console.log('```'); console.log(output.map(format).join('\n')); console.log('```'); }
javascript
function(state, command, output) { console.log('> Finished execution of ``', command, '``' + withCmdPrefix(state) + ':'); if (!Array.isArray(output)) output = [output]; console.log('```'); console.log(output.map(format).join('\n')); console.log('```'); }
[ "function", "(", "state", ",", "command", ",", "output", ")", "{", "console", ".", "log", "(", "'> Finished execution of ``'", ",", "command", ",", "'``'", "+", "withCmdPrefix", "(", "state", ")", "+", "':'", ")", ";", "if", "(", "!", "Array", ".", "isArray", "(", "output", ")", ")", "output", "=", "[", "output", "]", ";", "console", ".", "log", "(", "'```'", ")", ";", "console", ".", "log", "(", "output", ".", "map", "(", "format", ")", ".", "join", "(", "'\\n'", ")", ")", ";", "console", ".", "log", "(", "'```'", ")", ";", "}" ]
Handles reports with command's output @param {object} state - current state @param {string} command - string representation of the command @param {array|string|undefined} output - command's output @returns {void}
[ "Handles", "reports", "with", "command", "s", "output" ]
73d9c8c994f915688db0627ea3b4854ead771138
https://github.com/alexindigo/batcher/blob/73d9c8c994f915688db0627ea3b4854ead771138/default_reporter.js#L64-L71
47,891
alexindigo/batcher
default_reporter.js
function(state, error) { if (error) { console.log('\n## Finished with errors:\n'); console.log('```'); console.log(JSON.stringify(error, null, 2)); console.log('```'); } console.log('\n## Final State:\n'); console.log('```'); console.log(JSON.stringify(sortKeys(state), null, 2)); console.log('```'); }
javascript
function(state, error) { if (error) { console.log('\n## Finished with errors:\n'); console.log('```'); console.log(JSON.stringify(error, null, 2)); console.log('```'); } console.log('\n## Final State:\n'); console.log('```'); console.log(JSON.stringify(sortKeys(state), null, 2)); console.log('```'); }
[ "function", "(", "state", ",", "error", ")", "{", "if", "(", "error", ")", "{", "console", ".", "log", "(", "'\\n## Finished with errors:\\n'", ")", ";", "console", ".", "log", "(", "'```'", ")", ";", "console", ".", "log", "(", "JSON", ".", "stringify", "(", "error", ",", "null", ",", "2", ")", ")", ";", "console", ".", "log", "(", "'```'", ")", ";", "}", "console", ".", "log", "(", "'\\n## Final State:\\n'", ")", ";", "console", ".", "log", "(", "'```'", ")", ";", "console", ".", "log", "(", "JSON", ".", "stringify", "(", "sortKeys", "(", "state", ")", ",", "null", ",", "2", ")", ")", ";", "console", ".", "log", "(", "'```'", ")", ";", "}" ]
Handles reports with starting command's execution @param {object} state - final state @param {object|null} error - optional error object @returns {void}
[ "Handles", "reports", "with", "starting", "command", "s", "execution" ]
73d9c8c994f915688db0627ea3b4854ead771138
https://github.com/alexindigo/batcher/blob/73d9c8c994f915688db0627ea3b4854ead771138/default_reporter.js#L93-L107
47,892
alexindigo/batcher
default_reporter.js
sortKeys
function sortKeys(obj) { var sortedObj = {}; if (typeOf(obj) == 'object') { Object.keys(obj).sort().forEach(function(key) { sortedObj[key] = sortKeys(obj[key]); }); obj = sortedObj; } return obj; }
javascript
function sortKeys(obj) { var sortedObj = {}; if (typeOf(obj) == 'object') { Object.keys(obj).sort().forEach(function(key) { sortedObj[key] = sortKeys(obj[key]); }); obj = sortedObj; } return obj; }
[ "function", "sortKeys", "(", "obj", ")", "{", "var", "sortedObj", "=", "{", "}", ";", "if", "(", "typeOf", "(", "obj", ")", "==", "'object'", ")", "{", "Object", ".", "keys", "(", "obj", ")", ".", "sort", "(", ")", ".", "forEach", "(", "function", "(", "key", ")", "{", "sortedObj", "[", "key", "]", "=", "sortKeys", "(", "obj", "[", "key", "]", ")", ";", "}", ")", ";", "obj", "=", "sortedObj", ";", "}", "return", "obj", ";", "}" ]
Tries really hard to sort object's keys alphabetically @param {object} obj - object to sort @returns {object} - sorted object
[ "Tries", "really", "hard", "to", "sort", "object", "s", "keys", "alphabetically" ]
73d9c8c994f915688db0627ea3b4854ead771138
https://github.com/alexindigo/batcher/blob/73d9c8c994f915688db0627ea3b4854ead771138/default_reporter.js#L116-L131
47,893
alexindigo/batcher
default_reporter.js
format
function format(obj) { var output; if (typeOf(obj) == 'object' || typeOf(obj) == 'array' || typeOf(obj) == 'null') { output = JSON.stringify(obj); } else if (typeOf(obj) != 'undefined') { output = obj.toString(); } else { output = ''; } return output; }
javascript
function format(obj) { var output; if (typeOf(obj) == 'object' || typeOf(obj) == 'array' || typeOf(obj) == 'null') { output = JSON.stringify(obj); } else if (typeOf(obj) != 'undefined') { output = obj.toString(); } else { output = ''; } return output; }
[ "function", "format", "(", "obj", ")", "{", "var", "output", ";", "if", "(", "typeOf", "(", "obj", ")", "==", "'object'", "||", "typeOf", "(", "obj", ")", "==", "'array'", "||", "typeOf", "(", "obj", ")", "==", "'null'", ")", "{", "output", "=", "JSON", ".", "stringify", "(", "obj", ")", ";", "}", "else", "if", "(", "typeOf", "(", "obj", ")", "!=", "'undefined'", ")", "{", "output", "=", "obj", ".", "toString", "(", ")", ";", "}", "else", "{", "output", "=", "''", ";", "}", "return", "output", ";", "}" ]
Formats provided variable into a string, ready for console @param {mixed} obj – object to format @returns {string} - formatted string
[ "Formats", "provided", "variable", "into", "a", "string", "ready", "for", "console" ]
73d9c8c994f915688db0627ea3b4854ead771138
https://github.com/alexindigo/batcher/blob/73d9c8c994f915688db0627ea3b4854ead771138/default_reporter.js#L139-L157
47,894
alexindigo/batcher
default_reporter.js
withCmdPrefix
function withCmdPrefix(state) { var prefix; if (state.options && state.options.cmdPrefix) { prefix = ' with ``' + state.options.cmdPrefix + '`` prefix'; } return prefix || ''; }
javascript
function withCmdPrefix(state) { var prefix; if (state.options && state.options.cmdPrefix) { prefix = ' with ``' + state.options.cmdPrefix + '`` prefix'; } return prefix || ''; }
[ "function", "withCmdPrefix", "(", "state", ")", "{", "var", "prefix", ";", "if", "(", "state", ".", "options", "&&", "state", ".", "options", ".", "cmdPrefix", ")", "{", "prefix", "=", "' with ``'", "+", "state", ".", "options", ".", "cmdPrefix", "+", "'`` prefix'", ";", "}", "return", "prefix", "||", "''", ";", "}" ]
Generates command prefix line @param {object} state - current state @returns {string} - prefix line or empty string
[ "Generates", "command", "prefix", "line" ]
73d9c8c994f915688db0627ea3b4854ead771138
https://github.com/alexindigo/batcher/blob/73d9c8c994f915688db0627ea3b4854ead771138/default_reporter.js#L165-L175
47,895
fczbkk/the-box
src/utilities/get-boxes-around.spec.js
isMatching
function isMatching(result, expectation) { if (result.length !== expectation.length) { return false; } // convert results and expectations to strings for easier comparison result = result.map(item => item.toString()); expectation = expectation.map(item => getBox(item).toString()); const reduce_callback = function (previous_result, current_item) { return previous_result === true && result.indexOf(current_item) > -1; }; return expectation.reduce(reduce_callback, true); }
javascript
function isMatching(result, expectation) { if (result.length !== expectation.length) { return false; } // convert results and expectations to strings for easier comparison result = result.map(item => item.toString()); expectation = expectation.map(item => getBox(item).toString()); const reduce_callback = function (previous_result, current_item) { return previous_result === true && result.indexOf(current_item) > -1; }; return expectation.reduce(reduce_callback, true); }
[ "function", "isMatching", "(", "result", ",", "expectation", ")", "{", "if", "(", "result", ".", "length", "!==", "expectation", ".", "length", ")", "{", "return", "false", ";", "}", "// convert results and expectations to strings for easier comparison", "result", "=", "result", ".", "map", "(", "item", "=>", "item", ".", "toString", "(", ")", ")", ";", "expectation", "=", "expectation", ".", "map", "(", "item", "=>", "getBox", "(", "item", ")", ".", "toString", "(", ")", ")", ";", "const", "reduce_callback", "=", "function", "(", "previous_result", ",", "current_item", ")", "{", "return", "previous_result", "===", "true", "&&", "result", ".", "indexOf", "(", "current_item", ")", ">", "-", "1", ";", "}", ";", "return", "expectation", ".", "reduce", "(", "reduce_callback", ",", "true", ")", ";", "}" ]
helper function that compares length and values of expectations
[ "helper", "function", "that", "compares", "length", "and", "values", "of", "expectations" ]
337efc6bd00f92565dac8abffeb271b03caae2ba
https://github.com/fczbkk/the-box/blob/337efc6bd00f92565dac8abffeb271b03caae2ba/src/utilities/get-boxes-around.spec.js#L6-L20
47,896
mikesamuel/module-keys
index.js
selfContained
function selfContained(collection) { const proto = getPrototypeOf(collection); /* istanbul ignore if */ if (!proto || getPrototypeOf(proto) !== ObjectPrototype) { // The loop below is insufficient. throw new Error(); } for (const key of getOwnPropertyNames(proto)) { defineProperty(collection, key, { value: collection[key] }); } return collection; }
javascript
function selfContained(collection) { const proto = getPrototypeOf(collection); /* istanbul ignore if */ if (!proto || getPrototypeOf(proto) !== ObjectPrototype) { // The loop below is insufficient. throw new Error(); } for (const key of getOwnPropertyNames(proto)) { defineProperty(collection, key, { value: collection[key] }); } return collection; }
[ "function", "selfContained", "(", "collection", ")", "{", "const", "proto", "=", "getPrototypeOf", "(", "collection", ")", ";", "/* istanbul ignore if */", "if", "(", "!", "proto", "||", "getPrototypeOf", "(", "proto", ")", "!==", "ObjectPrototype", ")", "{", "// The loop below is insufficient.", "throw", "new", "Error", "(", ")", ";", "}", "for", "(", "const", "key", "of", "getOwnPropertyNames", "(", "proto", ")", ")", "{", "defineProperty", "(", "collection", ",", "key", ",", "{", "value", ":", "collection", "[", "key", "]", "}", ")", ";", "}", "return", "collection", ";", "}" ]
eslint-disable-line no-unused-vars, init-declarations Called before attacker-controlled code on an internal collections, copies prototype members onto the instance directly, so that later changes to prototypes cannot expose collection internals. @param {!T} collection @return {!T} collection @template T
[ "eslint", "-", "disable", "-", "line", "no", "-", "unused", "-", "vars", "init", "-", "declarations", "Called", "before", "attacker", "-", "controlled", "code", "on", "an", "internal", "collections", "copies", "prototype", "members", "onto", "the", "instance", "directly", "so", "that", "later", "changes", "to", "prototypes", "cannot", "expose", "collection", "internals", "." ]
39100b07d143af3f77a0bec519a92634d5173dd6
https://github.com/mikesamuel/module-keys/blob/39100b07d143af3f77a0bec519a92634d5173dd6/index.js#L82-L93
47,897
mikesamuel/module-keys
index.js
makeModuleKeys
function makeModuleKeys(moduleIdentifier) { // Allocate a public/private key pair. function privateKey(fun) { const previous = hidden; hidden = privateKey; try { return fun(); } finally { hidden = previous; } } function publicKey() { return hidden === privateKey; } publicKeys.add(publicKey); // Allow a private key to be used in lieu of the pair. defineProperty( privateKey, 'publicKey', { value: publicKey, enumerable: true }); // We attach a module identifier to the public key to enable // whitelisting based on strings in a configuration without having // to load modules before storing their public key in a set. defineProperties( publicKey, { moduleIdentifier: { value: `${ moduleIdentifier }`, enumerable: true }, call: { value: fCall, enumerable: true }, apply: { value: fApply, enumerable: true }, }); /** * Wraps a value in a box so that only an approved * opener may unbox it. * * @param {*} value the value that will be given to * an approved unboxer. * @param {!function(function():boolean):boolean} mayOpen * receives the public key of the opener. * Should return `true` to allow. * This will be called in the context of the opener's * private key, so the public key should also return true * called with no arguments. * @return {!Box} a box that is opaque to any receivers that cannot * unbox it. */ function box(value, mayOpen) { if (typeof mayOpen !== 'function') { throw new TypeError(`Expected function not ${ mayOpen }`); } // Allocate an opaque token const newBox = new Box(); boxes.set( newBox, freeze({ boxerPriv: privateKey, boxerPub: publicKey, value, mayOpen })); return newBox; } /** * Tries to open a box. * * @param {*} box the box to unbox. * @param {?function(function():boolean):boolean} ifFrom * if the box may be opened by this unboxer's owner, * then ifFrom receives the publicKey of the box creator. * It should return true to allow unboxing to proceed. * @param {*} fallback a value to substitute if unboxing failed. * Defaults to undefined. * @return {*} the value if unboxing is allowed or fallback otherwise. */ function unbox(box, ifFrom, fallback) { // eslint-disable-line no-shadow if (ifFrom == null) { // eslint-disable-line ifFrom = () => true; } if (typeof ifFrom !== 'function') { throw new TypeError(`Expected function not ${ ifFrom }`); } const boxData = boxes.get(box); if (!boxData) { return fallback; } const { boxerPriv, boxerPub, value, mayOpen } = boxData; // Require mutual consent // TODO: Is this the object identity equivalent of an // out-of-order verify/decrypt fault? // http://world.std.com/~dtd/sign_encrypt/sign_encrypt7.html return (privateKey(() => mayOpen(publicKey)) === true && boxerPriv(() => ifFrom(boxerPub)) === true) ? value : fallback; } const neverBoxed = {}; /** * Like unbox but raises an exception if unboxing fails. * @param {*} box the box to unbox. * @param {?function(function():boolean):boolean} ifFrom * if the box may be opened by this unboxer's owner, * then ifFrom receives the publicKey of the box creator. * It should return true to allow unboxing to proceed. * @return {*} the value if unboxing is allowed or fallback otherwise. */ function unboxStrict(box, ifFrom) { // eslint-disable-line no-shadow const result = unbox(box, ifFrom, neverBoxed); if (result === neverBoxed) { throw new Error('Could not unbox'); } return result; } return defineProperties( create(null), { // These close over private keys, so do not leak them. box: { value: box, enumerable: true }, unbox: { value: unbox, enumerable: true }, unboxStrict: { value: unboxStrict, enumerable: true }, privateKey: { value: privateKey, enumerable: true }, isPublicKey: { value: isPublicKey, enumerable: true }, // Modules may allow access to this, perhaps via module object. // See cjs/index.js. publicKey: { value: publicKey, enumerable: true }, [publicKeySymbol]: { value: publicKey, enumerable: true }, }); }
javascript
function makeModuleKeys(moduleIdentifier) { // Allocate a public/private key pair. function privateKey(fun) { const previous = hidden; hidden = privateKey; try { return fun(); } finally { hidden = previous; } } function publicKey() { return hidden === privateKey; } publicKeys.add(publicKey); // Allow a private key to be used in lieu of the pair. defineProperty( privateKey, 'publicKey', { value: publicKey, enumerable: true }); // We attach a module identifier to the public key to enable // whitelisting based on strings in a configuration without having // to load modules before storing their public key in a set. defineProperties( publicKey, { moduleIdentifier: { value: `${ moduleIdentifier }`, enumerable: true }, call: { value: fCall, enumerable: true }, apply: { value: fApply, enumerable: true }, }); /** * Wraps a value in a box so that only an approved * opener may unbox it. * * @param {*} value the value that will be given to * an approved unboxer. * @param {!function(function():boolean):boolean} mayOpen * receives the public key of the opener. * Should return `true` to allow. * This will be called in the context of the opener's * private key, so the public key should also return true * called with no arguments. * @return {!Box} a box that is opaque to any receivers that cannot * unbox it. */ function box(value, mayOpen) { if (typeof mayOpen !== 'function') { throw new TypeError(`Expected function not ${ mayOpen }`); } // Allocate an opaque token const newBox = new Box(); boxes.set( newBox, freeze({ boxerPriv: privateKey, boxerPub: publicKey, value, mayOpen })); return newBox; } /** * Tries to open a box. * * @param {*} box the box to unbox. * @param {?function(function():boolean):boolean} ifFrom * if the box may be opened by this unboxer's owner, * then ifFrom receives the publicKey of the box creator. * It should return true to allow unboxing to proceed. * @param {*} fallback a value to substitute if unboxing failed. * Defaults to undefined. * @return {*} the value if unboxing is allowed or fallback otherwise. */ function unbox(box, ifFrom, fallback) { // eslint-disable-line no-shadow if (ifFrom == null) { // eslint-disable-line ifFrom = () => true; } if (typeof ifFrom !== 'function') { throw new TypeError(`Expected function not ${ ifFrom }`); } const boxData = boxes.get(box); if (!boxData) { return fallback; } const { boxerPriv, boxerPub, value, mayOpen } = boxData; // Require mutual consent // TODO: Is this the object identity equivalent of an // out-of-order verify/decrypt fault? // http://world.std.com/~dtd/sign_encrypt/sign_encrypt7.html return (privateKey(() => mayOpen(publicKey)) === true && boxerPriv(() => ifFrom(boxerPub)) === true) ? value : fallback; } const neverBoxed = {}; /** * Like unbox but raises an exception if unboxing fails. * @param {*} box the box to unbox. * @param {?function(function():boolean):boolean} ifFrom * if the box may be opened by this unboxer's owner, * then ifFrom receives the publicKey of the box creator. * It should return true to allow unboxing to proceed. * @return {*} the value if unboxing is allowed or fallback otherwise. */ function unboxStrict(box, ifFrom) { // eslint-disable-line no-shadow const result = unbox(box, ifFrom, neverBoxed); if (result === neverBoxed) { throw new Error('Could not unbox'); } return result; } return defineProperties( create(null), { // These close over private keys, so do not leak them. box: { value: box, enumerable: true }, unbox: { value: unbox, enumerable: true }, unboxStrict: { value: unboxStrict, enumerable: true }, privateKey: { value: privateKey, enumerable: true }, isPublicKey: { value: isPublicKey, enumerable: true }, // Modules may allow access to this, perhaps via module object. // See cjs/index.js. publicKey: { value: publicKey, enumerable: true }, [publicKeySymbol]: { value: publicKey, enumerable: true }, }); }
[ "function", "makeModuleKeys", "(", "moduleIdentifier", ")", "{", "// Allocate a public/private key pair.", "function", "privateKey", "(", "fun", ")", "{", "const", "previous", "=", "hidden", ";", "hidden", "=", "privateKey", ";", "try", "{", "return", "fun", "(", ")", ";", "}", "finally", "{", "hidden", "=", "previous", ";", "}", "}", "function", "publicKey", "(", ")", "{", "return", "hidden", "===", "privateKey", ";", "}", "publicKeys", ".", "add", "(", "publicKey", ")", ";", "// Allow a private key to be used in lieu of the pair.", "defineProperty", "(", "privateKey", ",", "'publicKey'", ",", "{", "value", ":", "publicKey", ",", "enumerable", ":", "true", "}", ")", ";", "// We attach a module identifier to the public key to enable", "// whitelisting based on strings in a configuration without having", "// to load modules before storing their public key in a set.", "defineProperties", "(", "publicKey", ",", "{", "moduleIdentifier", ":", "{", "value", ":", "`", "${", "moduleIdentifier", "}", "`", ",", "enumerable", ":", "true", "}", ",", "call", ":", "{", "value", ":", "fCall", ",", "enumerable", ":", "true", "}", ",", "apply", ":", "{", "value", ":", "fApply", ",", "enumerable", ":", "true", "}", ",", "}", ")", ";", "/**\n * Wraps a value in a box so that only an approved\n * opener may unbox it.\n *\n * @param {*} value the value that will be given to\n * an approved unboxer.\n * @param {!function(function():boolean):boolean} mayOpen\n * receives the public key of the opener.\n * Should return `true` to allow.\n * This will be called in the context of the opener's\n * private key, so the public key should also return true\n * called with no arguments.\n * @return {!Box} a box that is opaque to any receivers that cannot\n * unbox it.\n */", "function", "box", "(", "value", ",", "mayOpen", ")", "{", "if", "(", "typeof", "mayOpen", "!==", "'function'", ")", "{", "throw", "new", "TypeError", "(", "`", "${", "mayOpen", "}", "`", ")", ";", "}", "// Allocate an opaque token", "const", "newBox", "=", "new", "Box", "(", ")", ";", "boxes", ".", "set", "(", "newBox", ",", "freeze", "(", "{", "boxerPriv", ":", "privateKey", ",", "boxerPub", ":", "publicKey", ",", "value", ",", "mayOpen", "}", ")", ")", ";", "return", "newBox", ";", "}", "/**\n * Tries to open a box.\n *\n * @param {*} box the box to unbox.\n * @param {?function(function():boolean):boolean} ifFrom\n * if the box may be opened by this unboxer's owner,\n * then ifFrom receives the publicKey of the box creator.\n * It should return true to allow unboxing to proceed.\n * @param {*} fallback a value to substitute if unboxing failed.\n * Defaults to undefined.\n * @return {*} the value if unboxing is allowed or fallback otherwise.\n */", "function", "unbox", "(", "box", ",", "ifFrom", ",", "fallback", ")", "{", "// eslint-disable-line no-shadow", "if", "(", "ifFrom", "==", "null", ")", "{", "// eslint-disable-line", "ifFrom", "=", "(", ")", "=>", "true", ";", "}", "if", "(", "typeof", "ifFrom", "!==", "'function'", ")", "{", "throw", "new", "TypeError", "(", "`", "${", "ifFrom", "}", "`", ")", ";", "}", "const", "boxData", "=", "boxes", ".", "get", "(", "box", ")", ";", "if", "(", "!", "boxData", ")", "{", "return", "fallback", ";", "}", "const", "{", "boxerPriv", ",", "boxerPub", ",", "value", ",", "mayOpen", "}", "=", "boxData", ";", "// Require mutual consent", "// TODO: Is this the object identity equivalent of an", "// out-of-order verify/decrypt fault?", "// http://world.std.com/~dtd/sign_encrypt/sign_encrypt7.html", "return", "(", "privateKey", "(", "(", ")", "=>", "mayOpen", "(", "publicKey", ")", ")", "===", "true", "&&", "boxerPriv", "(", "(", ")", "=>", "ifFrom", "(", "boxerPub", ")", ")", "===", "true", ")", "?", "value", ":", "fallback", ";", "}", "const", "neverBoxed", "=", "{", "}", ";", "/**\n * Like unbox but raises an exception if unboxing fails.\n * @param {*} box the box to unbox.\n * @param {?function(function():boolean):boolean} ifFrom\n * if the box may be opened by this unboxer's owner,\n * then ifFrom receives the publicKey of the box creator.\n * It should return true to allow unboxing to proceed.\n * @return {*} the value if unboxing is allowed or fallback otherwise.\n */", "function", "unboxStrict", "(", "box", ",", "ifFrom", ")", "{", "// eslint-disable-line no-shadow", "const", "result", "=", "unbox", "(", "box", ",", "ifFrom", ",", "neverBoxed", ")", ";", "if", "(", "result", "===", "neverBoxed", ")", "{", "throw", "new", "Error", "(", "'Could not unbox'", ")", ";", "}", "return", "result", ";", "}", "return", "defineProperties", "(", "create", "(", "null", ")", ",", "{", "// These close over private keys, so do not leak them.", "box", ":", "{", "value", ":", "box", ",", "enumerable", ":", "true", "}", ",", "unbox", ":", "{", "value", ":", "unbox", ",", "enumerable", ":", "true", "}", ",", "unboxStrict", ":", "{", "value", ":", "unboxStrict", ",", "enumerable", ":", "true", "}", ",", "privateKey", ":", "{", "value", ":", "privateKey", ",", "enumerable", ":", "true", "}", ",", "isPublicKey", ":", "{", "value", ":", "isPublicKey", ",", "enumerable", ":", "true", "}", ",", "// Modules may allow access to this, perhaps via module object.", "// See cjs/index.js.", "publicKey", ":", "{", "value", ":", "publicKey", ",", "enumerable", ":", "true", "}", ",", "[", "publicKeySymbol", "]", ":", "{", "value", ":", "publicKey", ",", "enumerable", ":", "true", "}", ",", "}", ")", ";", "}" ]
Creates a bundle that should be available as a local variable to module code.
[ "Creates", "a", "bundle", "that", "should", "be", "available", "as", "a", "local", "variable", "to", "module", "code", "." ]
39100b07d143af3f77a0bec519a92634d5173dd6
https://github.com/mikesamuel/module-keys/blob/39100b07d143af3f77a0bec519a92634d5173dd6/index.js#L140-L266
47,898
mikesamuel/module-keys
index.js
box
function box(value, mayOpen) { if (typeof mayOpen !== 'function') { throw new TypeError(`Expected function not ${ mayOpen }`); } // Allocate an opaque token const newBox = new Box(); boxes.set( newBox, freeze({ boxerPriv: privateKey, boxerPub: publicKey, value, mayOpen })); return newBox; }
javascript
function box(value, mayOpen) { if (typeof mayOpen !== 'function') { throw new TypeError(`Expected function not ${ mayOpen }`); } // Allocate an opaque token const newBox = new Box(); boxes.set( newBox, freeze({ boxerPriv: privateKey, boxerPub: publicKey, value, mayOpen })); return newBox; }
[ "function", "box", "(", "value", ",", "mayOpen", ")", "{", "if", "(", "typeof", "mayOpen", "!==", "'function'", ")", "{", "throw", "new", "TypeError", "(", "`", "${", "mayOpen", "}", "`", ")", ";", "}", "// Allocate an opaque token", "const", "newBox", "=", "new", "Box", "(", ")", ";", "boxes", ".", "set", "(", "newBox", ",", "freeze", "(", "{", "boxerPriv", ":", "privateKey", ",", "boxerPub", ":", "publicKey", ",", "value", ",", "mayOpen", "}", ")", ")", ";", "return", "newBox", ";", "}" ]
Wraps a value in a box so that only an approved opener may unbox it. @param {*} value the value that will be given to an approved unboxer. @param {!function(function():boolean):boolean} mayOpen receives the public key of the opener. Should return `true` to allow. This will be called in the context of the opener's private key, so the public key should also return true called with no arguments. @return {!Box} a box that is opaque to any receivers that cannot unbox it.
[ "Wraps", "a", "value", "in", "a", "box", "so", "that", "only", "an", "approved", "opener", "may", "unbox", "it", "." ]
39100b07d143af3f77a0bec519a92634d5173dd6
https://github.com/mikesamuel/module-keys/blob/39100b07d143af3f77a0bec519a92634d5173dd6/index.js#L187-L197
47,899
mikesamuel/module-keys
index.js
unbox
function unbox(box, ifFrom, fallback) { // eslint-disable-line no-shadow if (ifFrom == null) { // eslint-disable-line ifFrom = () => true; } if (typeof ifFrom !== 'function') { throw new TypeError(`Expected function not ${ ifFrom }`); } const boxData = boxes.get(box); if (!boxData) { return fallback; } const { boxerPriv, boxerPub, value, mayOpen } = boxData; // Require mutual consent // TODO: Is this the object identity equivalent of an // out-of-order verify/decrypt fault? // http://world.std.com/~dtd/sign_encrypt/sign_encrypt7.html return (privateKey(() => mayOpen(publicKey)) === true && boxerPriv(() => ifFrom(boxerPub)) === true) ? value : fallback; }
javascript
function unbox(box, ifFrom, fallback) { // eslint-disable-line no-shadow if (ifFrom == null) { // eslint-disable-line ifFrom = () => true; } if (typeof ifFrom !== 'function') { throw new TypeError(`Expected function not ${ ifFrom }`); } const boxData = boxes.get(box); if (!boxData) { return fallback; } const { boxerPriv, boxerPub, value, mayOpen } = boxData; // Require mutual consent // TODO: Is this the object identity equivalent of an // out-of-order verify/decrypt fault? // http://world.std.com/~dtd/sign_encrypt/sign_encrypt7.html return (privateKey(() => mayOpen(publicKey)) === true && boxerPriv(() => ifFrom(boxerPub)) === true) ? value : fallback; }
[ "function", "unbox", "(", "box", ",", "ifFrom", ",", "fallback", ")", "{", "// eslint-disable-line no-shadow", "if", "(", "ifFrom", "==", "null", ")", "{", "// eslint-disable-line", "ifFrom", "=", "(", ")", "=>", "true", ";", "}", "if", "(", "typeof", "ifFrom", "!==", "'function'", ")", "{", "throw", "new", "TypeError", "(", "`", "${", "ifFrom", "}", "`", ")", ";", "}", "const", "boxData", "=", "boxes", ".", "get", "(", "box", ")", ";", "if", "(", "!", "boxData", ")", "{", "return", "fallback", ";", "}", "const", "{", "boxerPriv", ",", "boxerPub", ",", "value", ",", "mayOpen", "}", "=", "boxData", ";", "// Require mutual consent", "// TODO: Is this the object identity equivalent of an", "// out-of-order verify/decrypt fault?", "// http://world.std.com/~dtd/sign_encrypt/sign_encrypt7.html", "return", "(", "privateKey", "(", "(", ")", "=>", "mayOpen", "(", "publicKey", ")", ")", "===", "true", "&&", "boxerPriv", "(", "(", ")", "=>", "ifFrom", "(", "boxerPub", ")", ")", "===", "true", ")", "?", "value", ":", "fallback", ";", "}" ]
Tries to open a box. @param {*} box the box to unbox. @param {?function(function():boolean):boolean} ifFrom if the box may be opened by this unboxer's owner, then ifFrom receives the publicKey of the box creator. It should return true to allow unboxing to proceed. @param {*} fallback a value to substitute if unboxing failed. Defaults to undefined. @return {*} the value if unboxing is allowed or fallback otherwise.
[ "Tries", "to", "open", "a", "box", "." ]
39100b07d143af3f77a0bec519a92634d5173dd6
https://github.com/mikesamuel/module-keys/blob/39100b07d143af3f77a0bec519a92634d5173dd6/index.js#L211-L231