code
stringlengths
24
2.07M
docstring
stringlengths
25
85.3k
func_name
stringlengths
1
92
language
stringclasses
1 value
repo
stringlengths
5
64
path
stringlengths
4
172
url
stringlengths
44
218
license
stringclasses
7 values
function render_tree( jsonml ) { // basic case if ( typeof jsonml === "string" ) { return escapeHTML( jsonml ); } var tag = jsonml.shift(), attributes = {}, content = []; if ( jsonml.length && typeof jsonml[ 0 ] === "object" && !( jsonml[ 0 ] instanceof Array ) ) { attributes = jsonml.sh...
renderJsonML( jsonml[, options] ) -> String - jsonml (Array): JsonML array to render to XML - options (Object): options Converts the given JsonML into well-formed XML. The options currently understood are: - root (Boolean): wether or not the root node should be included in the output, or just its children. T...
render_tree
javascript
CartoDB/cartodb
vendor/assets/javascripts/markdown.js
https://github.com/CartoDB/cartodb/blob/master/vendor/assets/javascripts/markdown.js
BSD-3-Clause
function convert_tree_to_html( tree, references, options ) { var i; options = options || {}; // shallow clone var jsonml = tree.slice( 0 ); if ( typeof options.preprocessTreeNode === "function" ) { jsonml = options.preprocessTreeNode(jsonml, references); } // Clone attributes if they exist var ...
renderJsonML( jsonml[, options] ) -> String - jsonml (Array): JsonML array to render to XML - options (Object): options Converts the given JsonML into well-formed XML. The options currently understood are: - root (Boolean): wether or not the root node should be included in the output, or just its children. T...
convert_tree_to_html
javascript
CartoDB/cartodb
vendor/assets/javascripts/markdown.js
https://github.com/CartoDB/cartodb/blob/master/vendor/assets/javascripts/markdown.js
BSD-3-Clause
function merge_text_nodes( jsonml ) { // skip the tag name and attribute hash var i = extract_attr( jsonml ) ? 2 : 1; while ( i < jsonml.length ) { // if it's a string check the next item too if ( typeof jsonml[ i ] === "string" ) { if ( i + 1 < jsonml.length && typeof jsonml[ i + 1 ] === "string" ...
renderJsonML( jsonml[, options] ) -> String - jsonml (Array): JsonML array to render to XML - options (Object): options Converts the given JsonML into well-formed XML. The options currently understood are: - root (Boolean): wether or not the root node should be included in the output, or just its children. T...
merge_text_nodes
javascript
CartoDB/cartodb
vendor/assets/javascripts/markdown.js
https://github.com/CartoDB/cartodb/blob/master/vendor/assets/javascripts/markdown.js
BSD-3-Clause
function equal(a, b) { if (a === b) return true; if (a === undefined || b === undefined) return false; if (a === null || b === null) return false; if (a.constructor === String) return a.localeCompare(b) === 0; if (b.constructor === String) return b.localeCompare(a) === 0; ...
Compares equality of a and b taking into account that a and b may be strings, in which case localeCompare is used @param a @param b
equal
javascript
CartoDB/cartodb
vendor/assets/javascripts/select2.min.js
https://github.com/CartoDB/cartodb/blob/master/vendor/assets/javascripts/select2.min.js
BSD-3-Clause
function splitVal(string, separator) { var val, i, l; if (string === null || string.length < 1) return []; val = string.split(separator); for (i = 0, l = val.length; i < l; i = i + 1) val[i] = $.trim(val[i]); return val; }
Splits the string into an array of values, trimming each value. An empty array is returned for nulls or empty strings @param string @param separator
splitVal
javascript
CartoDB/cartodb
vendor/assets/javascripts/select2.min.js
https://github.com/CartoDB/cartodb/blob/master/vendor/assets/javascripts/select2.min.js
BSD-3-Clause
function getSideBorderPadding(element) { return element.outerWidth(false) - element.width(); }
Splits the string into an array of values, trimming each value. An empty array is returned for nulls or empty strings @param string @param separator
getSideBorderPadding
javascript
CartoDB/cartodb
vendor/assets/javascripts/select2.min.js
https://github.com/CartoDB/cartodb/blob/master/vendor/assets/javascripts/select2.min.js
BSD-3-Clause
function installKeyUpChangeEvent(element) { var key="keyup-change-value"; element.bind("keydown", function () { if ($.data(element, key) === undefined) { $.data(element, key, element.val()); } }); element.bind("keyup", function () { var...
Splits the string into an array of values, trimming each value. An empty array is returned for nulls or empty strings @param string @param separator
installKeyUpChangeEvent
javascript
CartoDB/cartodb
vendor/assets/javascripts/select2.min.js
https://github.com/CartoDB/cartodb/blob/master/vendor/assets/javascripts/select2.min.js
BSD-3-Clause
function installFilteredMouseMove(element) { element.bind("mousemove", function (e) { var lastpos = lastMousePosition; if (lastpos === undefined || lastpos.x !== e.pageX || lastpos.y !== e.pageY) { $(e.target).trigger("mousemove-filtered", e); } }); ...
filters mouse events so an event is fired only if the mouse moved. filters out mouse events that occur when mouse is stationary but the elements under the pointer are scrolled.
installFilteredMouseMove
javascript
CartoDB/cartodb
vendor/assets/javascripts/select2.min.js
https://github.com/CartoDB/cartodb/blob/master/vendor/assets/javascripts/select2.min.js
BSD-3-Clause
function debounce(quietMillis, fn, ctx) { ctx = ctx || undefined; var timeout; return function () { var args = arguments; window.clearTimeout(timeout); timeout = window.setTimeout(function() { fn.apply(ctx, args); }, quietMillis); ...
Debounces a function. Returns a function that calls the original fn function only if no invocations have been made within the last quietMillis milliseconds. @param quietMillis number of milliseconds to wait before invoking fn @param fn function to be debounced @param ctx object to be used as this reference within fn @...
debounce
javascript
CartoDB/cartodb
vendor/assets/javascripts/select2.min.js
https://github.com/CartoDB/cartodb/blob/master/vendor/assets/javascripts/select2.min.js
BSD-3-Clause
function thunk(formula) { var evaluated = false, value; return function() { if (evaluated === false) { value = formula(); evaluated = true; } return value; }; }
A simple implementation of a thunk @param formula function used to lazily initialize the thunk @return {Function}
thunk
javascript
CartoDB/cartodb
vendor/assets/javascripts/select2.min.js
https://github.com/CartoDB/cartodb/blob/master/vendor/assets/javascripts/select2.min.js
BSD-3-Clause
function installDebouncedScroll(threshold, element) { var notify = debounce(threshold, function (e) { element.trigger("scroll-debounced", e);}); element.bind("scroll", function (e) { if (indexOf(e.target, element.get()) >= 0) notify(e); }); }
A simple implementation of a thunk @param formula function used to lazily initialize the thunk @return {Function}
installDebouncedScroll
javascript
CartoDB/cartodb
vendor/assets/javascripts/select2.min.js
https://github.com/CartoDB/cartodb/blob/master/vendor/assets/javascripts/select2.min.js
BSD-3-Clause
function killEvent(event) { event.preventDefault(); event.stopPropagation(); }
A simple implementation of a thunk @param formula function used to lazily initialize the thunk @return {Function}
killEvent
javascript
CartoDB/cartodb
vendor/assets/javascripts/select2.min.js
https://github.com/CartoDB/cartodb/blob/master/vendor/assets/javascripts/select2.min.js
BSD-3-Clause
function killEventImmediately(event) { event.preventDefault(); event.stopImmediatePropagation(); }
A simple implementation of a thunk @param formula function used to lazily initialize the thunk @return {Function}
killEventImmediately
javascript
CartoDB/cartodb
vendor/assets/javascripts/select2.min.js
https://github.com/CartoDB/cartodb/blob/master/vendor/assets/javascripts/select2.min.js
BSD-3-Clause
function measureTextWidth(e) { if (!sizer){ var style = e[0].currentStyle || window.getComputedStyle(e[0], null); sizer = $("<div></div>").css({ position: "absolute", left: "-10000px", top: "-10000px", display: "none", fon...
A simple implementation of a thunk @param formula function used to lazily initialize the thunk @return {Function}
measureTextWidth
javascript
CartoDB/cartodb
vendor/assets/javascripts/select2.min.js
https://github.com/CartoDB/cartodb/blob/master/vendor/assets/javascripts/select2.min.js
BSD-3-Clause
function markMatch(text, term, markup) { var match=text.toUpperCase().indexOf(term.toUpperCase()), tl=term.length; if (match<0) { markup.push(text); return; } markup.push(text.substring(0, match)); markup.push("<span class='select2-match'>");...
A simple implementation of a thunk @param formula function used to lazily initialize the thunk @return {Function}
markMatch
javascript
CartoDB/cartodb
vendor/assets/javascripts/select2.min.js
https://github.com/CartoDB/cartodb/blob/master/vendor/assets/javascripts/select2.min.js
BSD-3-Clause
function ajax(options) { var timeout, // current scheduled but not yet executed request requestSequence = 0, // sequence used to drop out-of-order responses handler = null, quietMillis = options.quietMillis || 100; return function (query) { window.clearTi...
Produces an ajax-based query function @param options object containing configuration paramters @param options.transport function that will be used to execute the ajax request. must be compatible with parameters supported by $.ajax @param options.url url for the data @param options.data a function(searchTerm, pageNumbe...
ajax
javascript
CartoDB/cartodb
vendor/assets/javascripts/select2.min.js
https://github.com/CartoDB/cartodb/blob/master/vendor/assets/javascripts/select2.min.js
BSD-3-Clause
function local(options) { var data = options, // data elements dataText, text = function (item) { return ""+item.text; }; // function used to retrieve the text portion of a data item that is matched against the search if (!$.isArray(data)) { text = data.text; ...
Produces a query function that works with a local array @param options object containing configuration parameters. The options parameter can either be an array or an object. If the array form is used it is assumed that it contains objects with 'id' and 'text' keys. If the object form is used ti is assumed that it co...
local
javascript
CartoDB/cartodb
vendor/assets/javascripts/select2.min.js
https://github.com/CartoDB/cartodb/blob/master/vendor/assets/javascripts/select2.min.js
BSD-3-Clause
function tags(data) { // TODO even for a function we should probably return a wrapper that does the same object/string check as // the function for arrays. otherwise only functions that return objects are supported. if ($.isFunction(data)) { return data; } // if not ...
Produces a query function that works with a local array @param options object containing configuration parameters. The options parameter can either be an array or an object. If the array form is used it is assumed that it contains objects with 'id' and 'text' keys. If the object form is used ti is assumed that it co...
tags
javascript
CartoDB/cartodb
vendor/assets/javascripts/select2.min.js
https://github.com/CartoDB/cartodb/blob/master/vendor/assets/javascripts/select2.min.js
BSD-3-Clause
function checkFormatter(formatter, formatterName) { if ($.isFunction(formatter)) return true; if (!formatter) return false; throw new Error("formatterName must be a function or a falsy value"); }
Checks if the formatter function should be used. Throws an error if it is not a function. Returns true if it should be used, false if no formatting should be performed. @param formatter
checkFormatter
javascript
CartoDB/cartodb
vendor/assets/javascripts/select2.min.js
https://github.com/CartoDB/cartodb/blob/master/vendor/assets/javascripts/select2.min.js
BSD-3-Clause
function evaluate(val) { return $.isFunction(val) ? val() : val; }
Checks if the formatter function should be used. Throws an error if it is not a function. Returns true if it should be used, false if no formatting should be performed. @param formatter
evaluate
javascript
CartoDB/cartodb
vendor/assets/javascripts/select2.min.js
https://github.com/CartoDB/cartodb/blob/master/vendor/assets/javascripts/select2.min.js
BSD-3-Clause
function countResults(results) { var count = 0; $.each(results, function(i, item) { if (item.children) { count += countResults(item.children); } else { count++; } }); return count; }
Checks if the formatter function should be used. Throws an error if it is not a function. Returns true if it should be used, false if no formatting should be performed. @param formatter
countResults
javascript
CartoDB/cartodb
vendor/assets/javascripts/select2.min.js
https://github.com/CartoDB/cartodb/blob/master/vendor/assets/javascripts/select2.min.js
BSD-3-Clause
function defaultTokenizer(input, selection, selectCallback, opts) { var original = input, // store the original so we can compare and know if we need to tell the search to update its text dupe = false, // check for whether a token we extracted represents a duplicate selected choice token...
Default tokenizer. This function uses breaks the input on substring match of any string from the opts.tokenSeparators array and uses opts.createSearchChoice to create the choice object. Both of those two options have to be defined in order for the tokenizer to work. @param input text user has typed so far or pasted in...
defaultTokenizer
javascript
CartoDB/cartodb
vendor/assets/javascripts/select2.min.js
https://github.com/CartoDB/cartodb/blob/master/vendor/assets/javascripts/select2.min.js
BSD-3-Clause
function clazz(SuperClass, methods) { var constructor = function () {}; constructor.prototype = new SuperClass; constructor.prototype.constructor = constructor; constructor.prototype.parent = SuperClass.prototype; constructor.prototype = $.extend(constructor.prototype, methods); ...
Creates a new class @param superClass @param methods
clazz
javascript
CartoDB/cartodb
vendor/assets/javascripts/select2.min.js
https://github.com/CartoDB/cartodb/blob/master/vendor/assets/javascripts/select2.min.js
BSD-3-Clause
function removeTipsys() { results.find('.select2-result').each(function(i,el){ var $el = $(el); var tipsy = $el.data('tipsy'); if (tipsy) { $el .tipsy('hide') .unbind('mouseleave mouseenter'); ...
@param initial whether or not this is the call to this method right after the dropdown has been opened
removeTipsys
javascript
CartoDB/cartodb
vendor/assets/javascripts/select2.min.js
https://github.com/CartoDB/cartodb/blob/master/vendor/assets/javascripts/select2.min.js
BSD-3-Clause
function postRender() { results.scrollTop(0); search.removeClass("select2-active"); self.positionDropdown(); }
@param initial whether or not this is the call to this method right after the dropdown has been opened
postRender
javascript
CartoDB/cartodb
vendor/assets/javascripts/select2.min.js
https://github.com/CartoDB/cartodb/blob/master/vendor/assets/javascripts/select2.min.js
BSD-3-Clause
function render(html) { results.html(self.opts.escapeMarkup(html)); postRender(); }
@param initial whether or not this is the call to this method right after the dropdown has been opened
render
javascript
CartoDB/cartodb
vendor/assets/javascripts/select2.min.js
https://github.com/CartoDB/cartodb/blob/master/vendor/assets/javascripts/select2.min.js
BSD-3-Clause
function resolveContainerWidth() { var style, attrs, matches, i, l; if (this.opts.width === "off") { return null; } else if (this.opts.width === "element"){ return this.opts.element.outerWidth(false) === 0 ? 'auto' : this.opts.elem...
Get the desired width for the container element. This is derived first from option `width` passed to select2, then the inline 'style' on the original element, and finally falls back to the jQuery calculated element width.
resolveContainerWidth
javascript
CartoDB/cartodb
vendor/assets/javascripts/select2.min.js
https://github.com/CartoDB/cartodb/blob/master/vendor/assets/javascripts/select2.min.js
BSD-3-Clause
function encode(s) { // Calculate result length and allocate output array. // encodedLength() also validates string and throws errors, // so we don't need repeat validation here. var arr = new Uint8Array(encodedLength(s)); var pos = 0; for (var i = 0; i < s.length; i++) { var c = s.charC...
Encodes the given string into UTF-8 byte array. Throws if the source string has invalid UTF-16 encoding.
encode
javascript
pusher/pusher-js
dist/node/pusher.js
https://github.com/pusher/pusher-js/blob/master/dist/node/pusher.js
MIT
function encodedLength(s) { var result = 0; for (var i = 0; i < s.length; i++) { var c = s.charCodeAt(i); if (c < 0x80) { result += 1; } else if (c < 0x800) { result += 2; } else if (c < 0xd800) { result += 3; } ...
Returns the number of bytes required to encode the given string into UTF-8. Throws if the source string has invalid UTF-16 encoding.
encodedLength
javascript
pusher/pusher-js
dist/node/pusher.js
https://github.com/pusher/pusher-js/blob/master/dist/node/pusher.js
MIT
function decode(arr) { var chars = []; for (var i = 0; i < arr.length; i++) { var b = arr[i]; if (b & 0x80) { var min = void 0; if (b < 0xe0) { // Need 1 more byte. if (i >= arr.length) { throw new Error(INVALID_UTF8); ...
Decodes the given byte array from UTF-8 into a string. Throws if encoding is invalid.
decode
javascript
pusher/pusher-js
dist/node/pusher.js
https://github.com/pusher/pusher-js/blob/master/dist/node/pusher.js
MIT
isAllowedHttpHeader = function(header) { return disableHeaderCheck || (header && forbiddenRequestHeaders.indexOf(header.toLowerCase()) === -1); }
Check if the specified header is allowed. @param string header Header to validate @return boolean False if not allowed, otherwise true
isAllowedHttpHeader
javascript
pusher/pusher-js
dist/node/pusher.js
https://github.com/pusher/pusher-js/blob/master/dist/node/pusher.js
MIT
isAllowedHttpMethod = function(method) { return (method && forbiddenRequestMethods.indexOf(method) === -1); }
Check if the specified method is allowed. @param string method Request method to validate @return boolean False if not allowed, otherwise true
isAllowedHttpMethod
javascript
pusher/pusher-js
dist/node/pusher.js
https://github.com/pusher/pusher-js/blob/master/dist/node/pusher.js
MIT
responseHandler = function responseHandler(resp) { // Set response var to the response we got back // This is so it remains accessable outside this scope response = resp; // Check for redirect // @TODO Prevent looped redirects if (response.statusCode === 301 || response.s...
Sends the request to the server. @param string data Optional data to send as request body.
responseHandler
javascript
pusher/pusher-js
dist/node/pusher.js
https://github.com/pusher/pusher-js/blob/master/dist/node/pusher.js
MIT
setState = function(state) { if (state == self.LOADING || self.readyState !== state) { self.readyState = state; if (settings.async || self.readyState < self.OPENED || self.readyState === self.DONE) { self.dispatchEvent("readystatechange"); } if (self.readyState === self.DONE && !er...
Changes readyState and calls onreadystatechange. @param int state New state
setState
javascript
pusher/pusher-js
dist/node/pusher.js
https://github.com/pusher/pusher-js/blob/master/dist/node/pusher.js
MIT
function encode(s) { // Calculate result length and allocate output array. // encodedLength() also validates string and throws errors, // so we don't need repeat validation here. var arr = new Uint8Array(encodedLength(s)); var pos = 0; for (var i = 0; i < s.length; i++) { var c = s.charC...
Encodes the given string into UTF-8 byte array. Throws if the source string has invalid UTF-16 encoding.
encode
javascript
pusher/pusher-js
dist/web/pusher-with-encryption.js
https://github.com/pusher/pusher-js/blob/master/dist/web/pusher-with-encryption.js
MIT
function encodedLength(s) { var result = 0; for (var i = 0; i < s.length; i++) { var c = s.charCodeAt(i); if (c < 0x80) { result += 1; } else if (c < 0x800) { result += 2; } else if (c < 0xd800) { result += 3; } ...
Returns the number of bytes required to encode the given string into UTF-8. Throws if the source string has invalid UTF-16 encoding.
encodedLength
javascript
pusher/pusher-js
dist/web/pusher-with-encryption.js
https://github.com/pusher/pusher-js/blob/master/dist/web/pusher-with-encryption.js
MIT
function decode(arr) { var chars = []; for (var i = 0; i < arr.length; i++) { var b = arr[i]; if (b & 0x80) { var min = void 0; if (b < 0xe0) { // Need 1 more byte. if (i >= arr.length) { throw new Error(INVALID_UTF8); ...
Decodes the given byte array from UTF-8 into a string. Throws if encoding is invalid.
decode
javascript
pusher/pusher-js
dist/web/pusher-with-encryption.js
https://github.com/pusher/pusher-js/blob/master/dist/web/pusher-with-encryption.js
MIT
function encode(s) { // Calculate result length and allocate output array. // encodedLength() also validates string and throws errors, // so we don't need repeat validation here. var arr = new Uint8Array(encodedLength(s)); var pos = 0; for (var i = 0; i < s.length; i++) { var c = s.charC...
Encodes the given string into UTF-8 byte array. Throws if the source string has invalid UTF-16 encoding.
encode
javascript
pusher/pusher-js
dist/web/pusher.js
https://github.com/pusher/pusher-js/blob/master/dist/web/pusher.js
MIT
function encodedLength(s) { var result = 0; for (var i = 0; i < s.length; i++) { var c = s.charCodeAt(i); if (c < 0x80) { result += 1; } else if (c < 0x800) { result += 2; } else if (c < 0xd800) { result += 3; } ...
Returns the number of bytes required to encode the given string into UTF-8. Throws if the source string has invalid UTF-16 encoding.
encodedLength
javascript
pusher/pusher-js
dist/web/pusher.js
https://github.com/pusher/pusher-js/blob/master/dist/web/pusher.js
MIT
function decode(arr) { var chars = []; for (var i = 0; i < arr.length; i++) { var b = arr[i]; if (b & 0x80) { var min = void 0; if (b < 0xe0) { // Need 1 more byte. if (i >= arr.length) { throw new Error(INVALID_UTF8); ...
Decodes the given byte array from UTF-8 into a string. Throws if encoding is invalid.
decode
javascript
pusher/pusher-js
dist/web/pusher.js
https://github.com/pusher/pusher-js/blob/master/dist/web/pusher.js
MIT
function encode(s) { // Calculate result length and allocate output array. // encodedLength() also validates string and throws errors, // so we don't need repeat validation here. var arr = new Uint8Array(encodedLength(s)); var pos = 0; for (var i = 0; i < s.length; i++) { var c = s.charC...
Encodes the given string into UTF-8 byte array. Throws if the source string has invalid UTF-16 encoding.
encode
javascript
pusher/pusher-js
dist/worker/pusher-with-encryption.worker.js
https://github.com/pusher/pusher-js/blob/master/dist/worker/pusher-with-encryption.worker.js
MIT
function encodedLength(s) { var result = 0; for (var i = 0; i < s.length; i++) { var c = s.charCodeAt(i); if (c < 0x80) { result += 1; } else if (c < 0x800) { result += 2; } else if (c < 0xd800) { result += 3; } ...
Returns the number of bytes required to encode the given string into UTF-8. Throws if the source string has invalid UTF-16 encoding.
encodedLength
javascript
pusher/pusher-js
dist/worker/pusher-with-encryption.worker.js
https://github.com/pusher/pusher-js/blob/master/dist/worker/pusher-with-encryption.worker.js
MIT
function decode(arr) { var chars = []; for (var i = 0; i < arr.length; i++) { var b = arr[i]; if (b & 0x80) { var min = void 0; if (b < 0xe0) { // Need 1 more byte. if (i >= arr.length) { throw new Error(INVALID_UTF8); ...
Decodes the given byte array from UTF-8 into a string. Throws if encoding is invalid.
decode
javascript
pusher/pusher-js
dist/worker/pusher-with-encryption.worker.js
https://github.com/pusher/pusher-js/blob/master/dist/worker/pusher-with-encryption.worker.js
MIT
function encode(s) { // Calculate result length and allocate output array. // encodedLength() also validates string and throws errors, // so we don't need repeat validation here. var arr = new Uint8Array(encodedLength(s)); var pos = 0; for (var i = 0; i < s.length; i++) { var c = s.charC...
Encodes the given string into UTF-8 byte array. Throws if the source string has invalid UTF-16 encoding.
encode
javascript
pusher/pusher-js
dist/worker/pusher.worker.js
https://github.com/pusher/pusher-js/blob/master/dist/worker/pusher.worker.js
MIT
function encodedLength(s) { var result = 0; for (var i = 0; i < s.length; i++) { var c = s.charCodeAt(i); if (c < 0x80) { result += 1; } else if (c < 0x800) { result += 2; } else if (c < 0xd800) { result += 3; } ...
Returns the number of bytes required to encode the given string into UTF-8. Throws if the source string has invalid UTF-16 encoding.
encodedLength
javascript
pusher/pusher-js
dist/worker/pusher.worker.js
https://github.com/pusher/pusher-js/blob/master/dist/worker/pusher.worker.js
MIT
function decode(arr) { var chars = []; for (var i = 0; i < arr.length; i++) { var b = arr[i]; if (b & 0x80) { var min = void 0; if (b < 0xe0) { // Need 1 more byte. if (i >= arr.length) { throw new Error(INVALID_UTF8); ...
Decodes the given byte array from UTF-8 into a string. Throws if encoding is invalid.
decode
javascript
pusher/pusher-js
dist/worker/pusher.worker.js
https://github.com/pusher/pusher-js/blob/master/dist/worker/pusher.worker.js
MIT
App = function () { this.init.apply(this, arguments); }
@class App @constructor @description Main application object. Acts as view dispatcher
App
javascript
hojberg/cssarrowplease
app/main.js
https://github.com/hojberg/cssarrowplease/blob/master/app/main.js
MIT
function attachModuleSymbols(doclets, modules) { var symbols = {} // build a lookup table doclets.forEach(function(symbol) { symbols[symbol.longname] = symbols[symbol.longname] || [] symbols[symbol.longname].push(symbol) }) modules.forEach(function(module) { if (symbols[module.longname]) { ...
Look for classes or functions with the same name as modules (which indicates that the module exports only that class or function), then attach the classes or functions to the `module` property of the appropriate module doclets. The name of each class or function is also updated for display purposes. This function mutat...
attachModuleSymbols
javascript
SoftwareBrothers/better-docs
publish.js
https://github.com/SoftwareBrothers/better-docs/blob/master/publish.js
MIT
function buildMemberNav(items, itemHeading, itemsSeen, linktoFn) { const subCategories = items.reduce((memo, item) => { const subCategory = item.subCategory || '' memo[subCategory] = memo[subCategory] || [] return { ...memo, [subCategory]: [...memo[subCategory], item] } }, {}) const s...
Look for classes or functions with the same name as modules (which indicates that the module exports only that class or function), then attach the classes or functions to the `module` property of the appropriate module doclets. The name of each class or function is also updated for display purposes. This function mutat...
buildMemberNav
javascript
SoftwareBrothers/better-docs
publish.js
https://github.com/SoftwareBrothers/better-docs/blob/master/publish.js
MIT
function linktoTutorial(longName, name) { return tutoriallink(name) }
Look for classes or functions with the same name as modules (which indicates that the module exports only that class or function), then attach the classes or functions to the `module` property of the appropriate module doclets. The name of each class or function is also updated for display purposes. This function mutat...
linktoTutorial
javascript
SoftwareBrothers/better-docs
publish.js
https://github.com/SoftwareBrothers/better-docs/blob/master/publish.js
MIT
function linktoExternal(longName, name) { return linkto(longName, name.replace(/(^"|"$)/g, '')) }
Look for classes or functions with the same name as modules (which indicates that the module exports only that class or function), then attach the classes or functions to the `module` property of the appropriate module doclets. The name of each class or function is also updated for display purposes. This function mutat...
linktoExternal
javascript
SoftwareBrothers/better-docs
publish.js
https://github.com/SoftwareBrothers/better-docs/blob/master/publish.js
MIT
function buildGroupNav (members, title) { var globalNav var seenTutorials = {} var nav = '' var seen = {} nav += '<div class="category">' if (title) { nav += '<h2>' + title + '</h2>' } nav += buildMemberNav(members.tutorials || [], 'Tutorials', seenTutorials, linktoTutorial) nav += buildMemberNav(...
Look for classes or functions with the same name as modules (which indicates that the module exports only that class or function), then attach the classes or functions to the `module` property of the appropriate module doclets. The name of each class or function is also updated for display purposes. This function mutat...
buildGroupNav
javascript
SoftwareBrothers/better-docs
publish.js
https://github.com/SoftwareBrothers/better-docs/blob/master/publish.js
MIT
function buildNav(members, navTypes = null, betterDocs) { const href = betterDocs.landing ? 'docs.html' : 'index.html' var nav = navTypes ? '' : `<h2><a href="${href}">Documentation</a></h2>` var categorised = {} var rootScope = {} var types = navTypes || ['modules', 'externals', 'namespaces', 'classes', ...
Create the navigation sidebar. @param {object} members The members that will be used to create the sidebar. @param {array<object>} members.classes @param {array<object>} members.components @param {array<object>} members.externals @param {array<object>} members.globals @param {array<object>} members.mixins @param {array...
buildNav
javascript
SoftwareBrothers/better-docs
publish.js
https://github.com/SoftwareBrothers/better-docs/blob/master/publish.js
MIT
function generateTutorial(title, subtitle, tutorial, filename) { var tutorialData = { title: title, subtitle: subtitle, header: tutorial.title, content: tutorial.parse(), children: tutorial.children } var tutorialPath = path.join(outdir, filename) var html = view.render('tu...
@param {TAFFY} taffyData See <http://taffydb.com/>. @param {object} opts @param {Tutorial} tutorials
generateTutorial
javascript
SoftwareBrothers/better-docs
publish.js
https://github.com/SoftwareBrothers/better-docs/blob/master/publish.js
MIT
function saveChildren(node) { node.children.forEach(function(child) { generateTutorial(child.title, 'Tutorial', child, helper.tutorialToUrl(child.name)) saveChildren(child) }) }
@param {TAFFY} taffyData See <http://taffydb.com/>. @param {object} opts @param {Tutorial} tutorials
saveChildren
javascript
SoftwareBrothers/better-docs
publish.js
https://github.com/SoftwareBrothers/better-docs/blob/master/publish.js
MIT
function saveLandingPage() { const content = fs.readFileSync(conf.betterDocs.landing, 'utf8') var landingPageData = { title: 'Home', content, } var homePath = path.join(outdir, 'index.html') var docsPath = path.join(outdir, 'docs.html') fs.renameSync(homePath, docsPath) ...
@param {TAFFY} taffyData See <http://taffydb.com/>. @param {object} opts @param {Tutorial} tutorials
saveLandingPage
javascript
SoftwareBrothers/better-docs
publish.js
https://github.com/SoftwareBrothers/better-docs/blob/master/publish.js
MIT
selectOnScroll = () => { const position = core.scrollTop() let activeSet = false for (let index = (links.length-1); index >= 0; index--) { const link = links[index] link.link.removeClass('is-active') if ((position + OFFSET) >= link.offset) { if (!activeSet) { link.link.ad...
@type {Array<{link: El, offset: number}>}
selectOnScroll
javascript
SoftwareBrothers/better-docs
scripts/side-nav.js
https://github.com/SoftwareBrothers/better-docs/blob/master/scripts/side-nav.js
MIT
selectOnScroll = () => { const position = core.scrollTop() let activeSet = false for (let index = (links.length-1); index >= 0; index--) { const link = links[index] link.link.removeClass('is-active') if ((position + OFFSET) >= link.offset) { if (!activeSet) { link.link.ad...
@type {Array<{link: El, offset: number}>}
selectOnScroll
javascript
SoftwareBrothers/better-docs
scripts/side-nav.js
https://github.com/SoftwareBrothers/better-docs/blob/master/scripts/side-nav.js
MIT
getTypeName = (type, src) => { if(!type) { return ''} if (type.typeName && type.typeName.escapedText) { const typeName = type.typeName.escapedText if(type.typeArguments && type.typeArguments.length) { const args = type.typeArguments.map(subType => getTypeName(subType, src)).join(', ') return `${...
Get type from a node @param {ts.TypeNode} type which should be parsed to string @param {string} src source for an entire parsed file @returns {string} node type
getTypeName
javascript
SoftwareBrothers/better-docs
typescript/type-converter.js
https://github.com/SoftwareBrothers/better-docs/blob/master/typescript/type-converter.js
MIT
getTypeName = (type, src) => { if(!type) { return ''} if (type.typeName && type.typeName.escapedText) { const typeName = type.typeName.escapedText if(type.typeArguments && type.typeArguments.length) { const args = type.typeArguments.map(subType => getTypeName(subType, src)).join(', ') return `${...
Get type from a node @param {ts.TypeNode} type which should be parsed to string @param {string} src source for an entire parsed file @returns {string} node type
getTypeName
javascript
SoftwareBrothers/better-docs
typescript/type-converter.js
https://github.com/SoftwareBrothers/better-docs/blob/master/typescript/type-converter.js
MIT
function checkType(node) { console.group(node.name?.escapedText); const predictedTypes = Object.keys(ts).reduce((acc, key) => { if (typeof ts[key] !== "function" && !key.startsWith("is")) { return acc; } try { if (ts[key](node) === true) { acc.push(key); } } catch (error) {...
Check type of node (dev only) @param {node} node @return {void} Console log predicted types
checkType
javascript
SoftwareBrothers/better-docs
typescript/type-converter.js
https://github.com/SoftwareBrothers/better-docs/blob/master/typescript/type-converter.js
MIT
fillMethodComment = (comment, member, src) => { if (!comment.includes('@method')) { comment = appendComment(comment, '@method') } if (!comment.includes('@param')) { comment = convertParams(comment, member, src) } if (member.type && ts.isArrayTypeNode(member.type)) { comment = convertMembers(commen...
Fill missing method declaration @param {string} comment @param member @param {string} src @return {string}
fillMethodComment
javascript
SoftwareBrothers/better-docs
typescript/type-converter.js
https://github.com/SoftwareBrothers/better-docs/blob/master/typescript/type-converter.js
MIT
fillMethodComment = (comment, member, src) => { if (!comment.includes('@method')) { comment = appendComment(comment, '@method') } if (!comment.includes('@param')) { comment = convertParams(comment, member, src) } if (member.type && ts.isArrayTypeNode(member.type)) { comment = convertMembers(commen...
Fill missing method declaration @param {string} comment @param member @param {string} src @return {string}
fillMethodComment
javascript
SoftwareBrothers/better-docs
typescript/type-converter.js
https://github.com/SoftwareBrothers/better-docs/blob/master/typescript/type-converter.js
MIT
convertParams = (jsDoc = '', node, src) => { const parameters = node.type?.parameters || node.parameters if(!parameters) { return } parameters.forEach(parameter => { let name = getName(parameter, src) let comment = getCommentAsString(parameter, src) if (parameter.questionToken) { name = ['[', na...
converts function parameters to @params @param {string} [jsDoc] existing jsdoc text where all @param comments should be appended @param {ts.FunctionDeclaration} wrapper ts node which has to be parsed @param {string} src source for an entire parsed file (we are fetching substrings from it) @param {string} parentN...
convertParams
javascript
SoftwareBrothers/better-docs
typescript/type-converter.js
https://github.com/SoftwareBrothers/better-docs/blob/master/typescript/type-converter.js
MIT
convertParams = (jsDoc = '', node, src) => { const parameters = node.type?.parameters || node.parameters if(!parameters) { return } parameters.forEach(parameter => { let name = getName(parameter, src) let comment = getCommentAsString(parameter, src) if (parameter.questionToken) { name = ['[', na...
converts function parameters to @params @param {string} [jsDoc] existing jsdoc text where all @param comments should be appended @param {ts.FunctionDeclaration} wrapper ts node which has to be parsed @param {string} src source for an entire parsed file (we are fetching substrings from it) @param {string} parentN...
convertParams
javascript
SoftwareBrothers/better-docs
typescript/type-converter.js
https://github.com/SoftwareBrothers/better-docs/blob/master/typescript/type-converter.js
MIT
convertMembers = (jsDoc = '', type, src, parentName = null) => { // type could be an array of types like: `{sth: 1} | string` - so we parse // each type separately const typesToCheck = [type] if (type.types && type.types.length) { typesToCheck.push(...type.types) } typesToCheck.forEach(type => { // ...
Convert type properties to @property @param {string} [jsDoc] existing jsdoc text where all @param comments should be appended @param {ts.TypeNode} wrapper ts node which has to be parsed @param {string} src source for an entire parsed file (we are fetching substrings from it) @param {string} parentName name of...
convertMembers
javascript
SoftwareBrothers/better-docs
typescript/type-converter.js
https://github.com/SoftwareBrothers/better-docs/blob/master/typescript/type-converter.js
MIT
convertMembers = (jsDoc = '', type, src, parentName = null) => { // type could be an array of types like: `{sth: 1} | string` - so we parse // each type separately const typesToCheck = [type] if (type.types && type.types.length) { typesToCheck.push(...type.types) } typesToCheck.forEach(type => { // ...
Convert type properties to @property @param {string} [jsDoc] existing jsdoc text where all @param comments should be appended @param {ts.TypeNode} wrapper ts node which has to be parsed @param {string} src source for an entire parsed file (we are fetching substrings from it) @param {string} parentName name of...
convertMembers
javascript
SoftwareBrothers/better-docs
typescript/type-converter.js
https://github.com/SoftwareBrothers/better-docs/blob/master/typescript/type-converter.js
MIT
function getCommentAsString(member, src) { if (member.jsDoc && member.jsDoc[0] && member.jsDoc[0].comment) { const comment = member.jsDoc[0].comment; if (Array.isArray(comment)) { return comment .map((c) => c.text.length ? c.text : src.substring(c.pos, c.end)) .join(''); } return...
Extract comment from member jsDoc as string @param member @param {string} src @returns {string}
getCommentAsString
javascript
SoftwareBrothers/better-docs
typescript/type-converter.js
https://github.com/SoftwareBrothers/better-docs/blob/master/typescript/type-converter.js
MIT
function main() { var display = gamejs.display.getSurface(); console.log(display.getRect().width) var spear = gamejs.image.load('./spear.png'); var unit = gamejs.image.load('./unit.png'); // create image masks from surface var mUnit = new pixelcollision.Mask(unit); var mSpear = new pixelcollision...
@fileoverview Demonstrates pixel perfect collision detection utilizing image masks. A 'spear' is moved around with mouse or cursors keys - the text 'COLLISION' appears if the spear pixel collides with the unit. gamejs.mask.fromSurface is used to create two pixel masks that do the actual collision detection.
main
javascript
GameJs/gamejs
examples/collisionmask/main.js
https://github.com/GameJs/gamejs/blob/master/examples/collisionmask/main.js
MIT
function main() { // set resolution & title var display = gamejs.display.getSurface(); gamejs.display.setCaption("Example Draw"); var colorOne = '#ff0000'; var colorTwo = 'rgb(255, 50, 60)'; var colorThree = 'rgba(50, 0, 150, 0.8)'; // All gamejs.draw methods share the same parameter order: //...
@fileoverview Draw lines, polygons, circles, etc on the screen. Render text in a certain font to the screen.
main
javascript
GameJs/gamejs
examples/draw/main.js
https://github.com/GameJs/gamejs/blob/master/examples/draw/main.js
MIT
function main() { var display = gamejs.display.getSurface(); gamejs.display.setCaption('example event'); var starImage = gamejs.image.load('./sparkle.png'); var instructionFont = new gamejs.font.Font('30px monospace'); var displayRect = display.rect; var sparkles = []; // to keep track of pointe...
@fileoverview Sparkles with position and alpha are created by mouse movement. The sparkles position is updated in a time-dependant way. A sparkle is removed from the simulation once it leaves the screen. Additionally, by pressing the cursor UP key the existing sparkles will move upwards (movement vecor inverted).
main
javascript
GameJs/gamejs
examples/event/main.js
https://github.com/GameJs/gamejs/blob/master/examples/event/main.js
MIT
function Ball(center) { this.center = center; this.growPerSec = Ball.GROW_PER_SEC; this.radius = this.growPerSec * 2; this.color = 0; return this; }
@fileoverview Minimal is the smalles GameJs app I could think of, which still shows off most of the concepts GameJs introduces. It's a pulsating, colored circle. You can make the circle change color by clicking.
Ball
javascript
GameJs/gamejs
examples/minimal/main.js
https://github.com/GameJs/gamejs/blob/master/examples/minimal/main.js
MIT
function main() { // setup screen and ball. // ball in screen center. // start game loop. var display = gamejs.display.getSurface(); var ballCenter = [display.getRect().width / 2, display.getRect().height / 2]; var ball = new Ball(ballCenter); // ball changes color on mouse up gamejs.event.onM...
@fileoverview Minimal is the smalles GameJs app I could think of, which still shows off most of the concepts GameJs introduces. It's a pulsating, colored circle. You can make the circle change color by clicking.
main
javascript
GameJs/gamejs
examples/minimal/main.js
https://github.com/GameJs/gamejs/blob/master/examples/minimal/main.js
MIT
function main() { // screen setup var display = gamejs.display.getSurface(); gamejs.display.setCaption("Example Workers"); var font = new gamejs.font.Font(); // create a background worker var primeWorker = new gamejs.thread.Worker('./prime-worker'); // send a question to the worker var startNu...
Creates a Worker which - given a starting number - will produce primes coming after that number. This examples shows how messages are being sent from and to a worker, and that the number-crunching worker does not block the browser's UI (like a normal script running this long would).
main
javascript
GameJs/gamejs
examples/thread/main.js
https://github.com/GameJs/gamejs/blob/master/examples/thread/main.js
MIT
handleEvent = function(data) { if (data.todo === 'nextprimes') { var foundPrime = false; var n = data.start; var primes = []; var x = 10000; search: while(primes.length < 5) { n += 1; for (var i = 2; i <= Math.sqrt(n); i += 1) { if (n % i == 0) { ...
This worker responds to a message `{todo: "nextprimes", start: 123}` and will return five primes after the `start` number. It will skip 100.000 primes between each of those five. (arbitrary algorithm, designed to be long running)
handleEvent
javascript
GameJs/gamejs
examples/thread/prime-worker.js
https://github.com/GameJs/gamejs/blob/master/examples/thread/prime-worker.js
MIT
function _ready() { if (!document.body) { return window.setTimeout(_ready, 50); } getImageProgress = gamejs.image.preload(RESOURCES); try { getMixerProgress = gamejs.audio.preload(RESOURCES); } catch (e) { gamejs.debug('Error loading audio...
ReadyFn is called once all modules and assets are loaded. @param {Function} callbackFunction the function to be called once gamejs finished loading @name ready
_ready
javascript
GameJs/gamejs
src/gamejs.js
https://github.com/GameJs/gamejs/blob/master/src/gamejs.js
MIT
function _readyResources() { if (getImageProgress() < 1 || getMixerProgress() < 1) { return window.setTimeout(_readyResources, 100); } gamejs.display.init(); gamejs.image.init(); gamejs.audio.init(); gamejs.event.init(); gamejs.math.random.init(...
ReadyFn is called once all modules and assets are loaded. @param {Function} callbackFunction the function to be called once gamejs finished loading @name ready
_readyResources
javascript
GameJs/gamejs
src/gamejs.js
https://github.com/GameJs/gamejs/blob/master/src/gamejs.js
MIT
function getLoadProgress() { if (getImageProgress) { return (0.5 * getImageProgress()) + (0.5 * getMixerProgress()); } return 0.1; }
ReadyFn is called once all modules and assets are loaded. @param {Function} callbackFunction the function to be called once gamejs finished loading @name ready
getLoadProgress
javascript
GameJs/gamejs
src/gamejs.js
https://github.com/GameJs/gamejs/blob/master/src/gamejs.js
MIT
resourceBaseHref = function() { return (window.$g && window.$g.resourceBaseHref) || document.location.href; }
Initialize all gamejs modules. This is automatically called by `gamejs.ready()`. @returns {Object} the properties of this objecte are the moduleIds that failed, they value are the exceptions @ignore
resourceBaseHref
javascript
GameJs/gamejs
src/gamejs.js
https://github.com/GameJs/gamejs/blob/master/src/gamejs.js
MIT
function linePosition(point) { var x = point[0]; var y = point[1]; return (y2 - y1) * x + (x1 - x2) * y + (x2 * y1 - x1 * y2); }
@param {Array} pointA start point of the line @param {Array} pointB end point of the line @returns true if the line intersects with the rectangle @see http://stackoverflow.com/questions/99353/how-to-test-if-a-line-segment-intersects-an-axis-aligned-rectange-in-2d/293052#293052
linePosition
javascript
GameJs/gamejs
src/gamejs.js
https://github.com/GameJs/gamejs/blob/master/src/gamejs.js
MIT
function incrementLoaded() { countLoaded++; if (countLoaded == countTotal) { _PRELOADING = false; } }
Preload the audios into cache @param {String[]} List of audio URIs to load @returns {Function} which returns 0-1 for preload progress @ignore
incrementLoaded
javascript
GameJs/gamejs
src/gamejs/audio.js
https://github.com/GameJs/gamejs/blob/master/src/gamejs/audio.js
MIT
function getProgress() { return countTotal > 0 ? countLoaded / countTotal : 1; }
Preload the audios into cache @param {String[]} List of audio URIs to load @returns {Function} which returns 0-1 for preload progress @ignore
getProgress
javascript
GameJs/gamejs
src/gamejs/audio.js
https://github.com/GameJs/gamejs/blob/master/src/gamejs/audio.js
MIT
function successHandler() { addToCache(this); incrementLoaded(); }
Preload the audios into cache @param {String[]} List of audio URIs to load @returns {Function} which returns 0-1 for preload progress @ignore
successHandler
javascript
GameJs/gamejs
src/gamejs/audio.js
https://github.com/GameJs/gamejs/blob/master/src/gamejs/audio.js
MIT
function errorHandler() { incrementLoaded(); throw new Error('Error loading ' + this.src); }
Preload the audios into cache @param {String[]} List of audio URIs to load @returns {Function} which returns 0-1 for preload progress @ignore
errorHandler
javascript
GameJs/gamejs
src/gamejs/audio.js
https://github.com/GameJs/gamejs/blob/master/src/gamejs/audio.js
MIT
function addToCache(audios) { if (!(audios instanceof Array)) { audios = [audios]; } var docLoc = document.location.href; audios.forEach(function(audio) { CACHE[audio.gamejsKey] = audio; }); return; }
@param {dom.ImgElement} audios the <audio> elements to put into cache @ignore
addToCache
javascript
GameJs/gamejs
src/gamejs/audio.js
https://github.com/GameJs/gamejs/blob/master/src/gamejs/audio.js
MIT
getFullScreenToggle = function() { var fullScreenButton = document.getElementById('gjs-fullscreen-toggle'); if (!fullScreenButton) { // before canvas fullScreenButton = document.createElement('button'); fullScreenButton.innerHTML = 'Fullscreen'; fullScreenButton.id = 'gjs-fullscreen-toggle...
@returns {document.Element} the canvas dom element @ignore
getFullScreenToggle
javascript
GameJs/gamejs
src/gamejs/display.js
https://github.com/GameJs/gamejs/blob/master/src/gamejs/display.js
MIT
fullScreenChange = function(event) { var gjsEvent ={ type: isFullScreen() ? require('./event').DISPLAY_FULLSCREEN_ENABLED : require('./event').DISPLAY_FULLSCREEN_DISABLED }; if (isFullScreen()) { if (_flags & POINTERLOCK) { enablePointerLock(); } } requ...
@returns {document.Element} the canvas dom element @ignore
fullScreenChange
javascript
GameJs/gamejs
src/gamejs/display.js
https://github.com/GameJs/gamejs/blob/master/src/gamejs/display.js
MIT
function onResize(event) { var canvas = getCanvas(); SURFACE._canvas.width = canvas.clientWidth; SURFACE._canvas.height = canvas.clientHeight; require('./event')._triggerCallbacks({ type: require('./event').DISPLAY_RESIZE }); }
@returns {document.Element} the canvas dom element @ignore
onResize
javascript
GameJs/gamejs
src/gamejs/display.js
https://github.com/GameJs/gamejs/blob/master/src/gamejs/display.js
MIT
enableFullScreen = function(event) { var wrapper = getCanvas(); wrapper.requestFullScreen = wrapper.requestFullScreen || wrapper.mozRequestFullScreen || wrapper.webkitRequestFullScreen; if (!wrapper.requestFullScreen) { return false; } // @xbrowser chrome allows keboard input onl if ask for it (why...
Switches the display window normal browser mode and fullscreen. @ignore @returns {Boolean} true if operation was successfull, false otherwise
enableFullScreen
javascript
GameJs/gamejs
src/gamejs/display.js
https://github.com/GameJs/gamejs/blob/master/src/gamejs/display.js
MIT
enablePointerLock = function() { var wrapper = getCanvas(); wrapper.requestPointerLock = wrapper.requestPointerLock || wrapper.mozRequestPointerLock || wrapper.webkitRequestPointerLock; if (wrapper.requestPointerLock) { wrapper.requestPointerLock(); } }
Switches the display window normal browser mode and fullscreen. @ignore @returns {Boolean} true if operation was successfull, false otherwise
enablePointerLock
javascript
GameJs/gamejs
src/gamejs/display.js
https://github.com/GameJs/gamejs/blob/master/src/gamejs/display.js
MIT
function stringify(response) { /* jshint ignore:start */ return eval('(' + response.responseText + ')'); /* jshint ignore:end */ }
Make http POST request to server-side @param {String} url @param {String|Object} data @param {String|Object} type "Accept" header value @returns {Response}
stringify
javascript
GameJs/gamejs
src/gamejs/http.js
https://github.com/GameJs/gamejs/blob/master/src/gamejs/http.js
MIT
function ajaxBaseHref() { return (window.$g && window.$g.ajaxBaseHref) || './'; }
Make http POST request to server-side @param {String} url @param {String|Object} data @param {String|Object} type "Accept" header value @returns {Response}
ajaxBaseHref
javascript
GameJs/gamejs
src/gamejs/http.js
https://github.com/GameJs/gamejs/blob/master/src/gamejs/http.js
MIT
function incrementLoaded() { countLoaded++; if (countLoaded == countTotal) { _PRELOADING = false; } if (countLoaded % 10 === 0) { gamejs.logging.debug('gamejs.image: preloaded ' + countLoaded + ' of ' + countTotal); } }
preload the given img URIs @returns {Function} which returns 0-1 for preload progress @ignore
incrementLoaded
javascript
GameJs/gamejs
src/gamejs/image.js
https://github.com/GameJs/gamejs/blob/master/src/gamejs/image.js
MIT
function getProgress() { return countTotal > 0 ? countLoaded / countTotal : 1; }
preload the given img URIs @returns {Function} which returns 0-1 for preload progress @ignore
getProgress
javascript
GameJs/gamejs
src/gamejs/image.js
https://github.com/GameJs/gamejs/blob/master/src/gamejs/image.js
MIT
function successHandler() { addToCache(this); incrementLoaded(); }
preload the given img URIs @returns {Function} which returns 0-1 for preload progress @ignore
successHandler
javascript
GameJs/gamejs
src/gamejs/image.js
https://github.com/GameJs/gamejs/blob/master/src/gamejs/image.js
MIT
function errorHandler() { incrementLoaded(); throw new Error('Error loading ' + this.src); }
preload the given img URIs @returns {Function} which returns 0-1 for preload progress @ignore
errorHandler
javascript
GameJs/gamejs
src/gamejs/image.js
https://github.com/GameJs/gamejs/blob/master/src/gamejs/image.js
MIT
addToCache = function(img) { CACHE[img.gamejsKey] = img; return; }
add the given <img> dom elements into the cache. @private
addToCache
javascript
GameJs/gamejs
src/gamejs/image.js
https://github.com/GameJs/gamejs/blob/master/src/gamejs/image.js
MIT
function routeScore(route) { if (route.score === undefined) { route.score = map.estimatedDistance(route.point, to) + route.length; } return route.score; }
A* search function. This function expects a `Map` implementation and the origin and destination points given. If there is a path between the two it will return the optimal path as a linked list. If there is no path it will return null. The linked list is in reverse order: the first item is the destination and the pat...
routeScore
javascript
GameJs/gamejs
src/gamejs/pathfinding.js
https://github.com/GameJs/gamejs/blob/master/src/gamejs/pathfinding.js
MIT
function addOpenRoute(route) { open.push(route); reached.store(route.point, route); }
A* search function. This function expects a `Map` implementation and the origin and destination points given. If there is a path between the two it will return the optimal path as a linked list. If there is no path it will return null. The linked list is in reverse order: the first item is the destination and the pat...
addOpenRoute
javascript
GameJs/gamejs
src/gamejs/pathfinding.js
https://github.com/GameJs/gamejs/blob/master/src/gamejs/pathfinding.js
MIT
function processNewPoints(direction) { var known = reached.find(direction); var newLength = route.length + map.actualDistance(route.point, direction); if (!known || known.length > newLength){ if (known) { open.remove(known); } addOpenRoute({ point: di...
A* search function. This function expects a `Map` implementation and the origin and destination points given. If there is a path between the two it will return the optimal path as a linked list. If there is no path it will return null. The linked list is in reverse order: the first item is the destination and the pat...
processNewPoints
javascript
GameJs/gamejs
src/gamejs/pathfinding.js
https://github.com/GameJs/gamejs/blob/master/src/gamejs/pathfinding.js
MIT