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
17,800
numbers/numbers.js
lib/numbers/matrix.js
function (M) { //starting at bottom right, moving horizontally var jump = false, tl = n * n, br = 1, inc = 1, row, col, val, i, j; M[0][0] = tl; M[n - 1][n - 1] = br; for (i = 1; i < n; i++) { //generate top/bottom row if (jump) { tl -= 4 * inc; br += 4 * inc; inc++; } else { tl--; br++; } M[0][i] = tl; M[n - 1][n - 1 - i] = br; jump = !jump; } var dec = true; for (i = 1; i < n; i++) { //iterate diagonally from top row row = 0; col = i; val = M[row][col]; for (j = 1; j < i + 1; j++) { if (dec) { val -= 1; } else { val += 1; } row++; col--; M[row][col] = val; } dec = !dec; } if (n % 2 === 0) { dec = true; } else { dec = false; } for (i = 1; i < n - 1; i++) { //iterate diagonally from bottom row row = n - 1; col = i; val = M[row][col]; for (j = 1; j < n - i; j++) { if (dec) { val--; } else { val++; } row--; col++; M[row][col] = val; } dec = !dec; } return M; }
javascript
function (M) { //starting at bottom right, moving horizontally var jump = false, tl = n * n, br = 1, inc = 1, row, col, val, i, j; M[0][0] = tl; M[n - 1][n - 1] = br; for (i = 1; i < n; i++) { //generate top/bottom row if (jump) { tl -= 4 * inc; br += 4 * inc; inc++; } else { tl--; br++; } M[0][i] = tl; M[n - 1][n - 1 - i] = br; jump = !jump; } var dec = true; for (i = 1; i < n; i++) { //iterate diagonally from top row row = 0; col = i; val = M[row][col]; for (j = 1; j < i + 1; j++) { if (dec) { val -= 1; } else { val += 1; } row++; col--; M[row][col] = val; } dec = !dec; } if (n % 2 === 0) { dec = true; } else { dec = false; } for (i = 1; i < n - 1; i++) { //iterate diagonally from bottom row row = n - 1; col = i; val = M[row][col]; for (j = 1; j < n - i; j++) { if (dec) { val--; } else { val++; } row--; col++; M[row][col] = val; } dec = !dec; } return M; }
[ "function", "(", "M", ")", "{", "//starting at bottom right, moving horizontally", "var", "jump", "=", "false", ",", "tl", "=", "n", "*", "n", ",", "br", "=", "1", ",", "inc", "=", "1", ",", "row", ",", "col", ",", "val", ",", "i", ",", "j", ";", "M", "[", "0", "]", "[", "0", "]", "=", "tl", ";", "M", "[", "n", "-", "1", "]", "[", "n", "-", "1", "]", "=", "br", ";", "for", "(", "i", "=", "1", ";", "i", "<", "n", ";", "i", "++", ")", "{", "//generate top/bottom row", "if", "(", "jump", ")", "{", "tl", "-=", "4", "*", "inc", ";", "br", "+=", "4", "*", "inc", ";", "inc", "++", ";", "}", "else", "{", "tl", "--", ";", "br", "++", ";", "}", "M", "[", "0", "]", "[", "i", "]", "=", "tl", ";", "M", "[", "n", "-", "1", "]", "[", "n", "-", "1", "-", "i", "]", "=", "br", ";", "jump", "=", "!", "jump", ";", "}", "var", "dec", "=", "true", ";", "for", "(", "i", "=", "1", ";", "i", "<", "n", ";", "i", "++", ")", "{", "//iterate diagonally from top row", "row", "=", "0", ";", "col", "=", "i", ";", "val", "=", "M", "[", "row", "]", "[", "col", "]", ";", "for", "(", "j", "=", "1", ";", "j", "<", "i", "+", "1", ";", "j", "++", ")", "{", "if", "(", "dec", ")", "{", "val", "-=", "1", ";", "}", "else", "{", "val", "+=", "1", ";", "}", "row", "++", ";", "col", "--", ";", "M", "[", "row", "]", "[", "col", "]", "=", "val", ";", "}", "dec", "=", "!", "dec", ";", "}", "if", "(", "n", "%", "2", "===", "0", ")", "{", "dec", "=", "true", ";", "}", "else", "{", "dec", "=", "false", ";", "}", "for", "(", "i", "=", "1", ";", "i", "<", "n", "-", "1", ";", "i", "++", ")", "{", "//iterate diagonally from bottom row", "row", "=", "n", "-", "1", ";", "col", "=", "i", ";", "val", "=", "M", "[", "row", "]", "[", "col", "]", ";", "for", "(", "j", "=", "1", ";", "j", "<", "n", "-", "i", ";", "j", "++", ")", "{", "if", "(", "dec", ")", "{", "val", "--", ";", "}", "else", "{", "val", "++", ";", "}", "row", "--", ";", "col", "++", ";", "M", "[", "row", "]", "[", "col", "]", "=", "val", ";", "}", "dec", "=", "!", "dec", ";", "}", "return", "M", ";", "}" ]
create one kind of permutation - all other permutations can be created from this particular permutation through transformations
[ "create", "one", "kind", "of", "permutation", "-", "all", "other", "permutations", "can", "be", "created", "from", "this", "particular", "permutation", "through", "transformations" ]
ca3076a7bfc670a5c45bb18ade9c3a868363bcc3
https://github.com/numbers/numbers.js/blob/ca3076a7bfc670a5c45bb18ade9c3a868363bcc3/lib/numbers/matrix.js#L821-L890
17,801
jkphl/gulp-svg-sprite
index.js
gulpSVGSprite
function gulpSVGSprite(config) { // Extend plugin error function extendError(pError, error) { if (error && (typeof error === 'object')) { ['name', 'errno'].forEach(function(property) { if (property in error) { this[property] = error[property]; } }, pError); } return pError; } // Instanciate spriter instance var spriter = new SVGSpriter(config); var shapes = 0; // Intercept error log and convert to plugin errors spriter.config.log.error = function(message, error) { this.emit('error', extendError(new PluginError(PLUGIN_NAME, message), error)); }; return through2.obj(function (file, enc, cb) { var error = null; try { spriter.add(file); ++shapes; } catch(e) { error = (!e.plugin || (e.plugin !== PLUGIN_NAME)) ? extendError(new PluginError(PLUGIN_NAME, e.message), e) : e; } return cb(error); }, function(cb) { var stream = this; spriter.compile(function(error, result /*, data*/){ if (error) { stream.emit('error', new PluginError(PLUGIN_NAME, error)); } else if (shapes > 0) { for (var mode in result) { for (var resource in result[mode]) { stream.push(result[mode][resource]); } } } cb(); }); }); }
javascript
function gulpSVGSprite(config) { // Extend plugin error function extendError(pError, error) { if (error && (typeof error === 'object')) { ['name', 'errno'].forEach(function(property) { if (property in error) { this[property] = error[property]; } }, pError); } return pError; } // Instanciate spriter instance var spriter = new SVGSpriter(config); var shapes = 0; // Intercept error log and convert to plugin errors spriter.config.log.error = function(message, error) { this.emit('error', extendError(new PluginError(PLUGIN_NAME, message), error)); }; return through2.obj(function (file, enc, cb) { var error = null; try { spriter.add(file); ++shapes; } catch(e) { error = (!e.plugin || (e.plugin !== PLUGIN_NAME)) ? extendError(new PluginError(PLUGIN_NAME, e.message), e) : e; } return cb(error); }, function(cb) { var stream = this; spriter.compile(function(error, result /*, data*/){ if (error) { stream.emit('error', new PluginError(PLUGIN_NAME, error)); } else if (shapes > 0) { for (var mode in result) { for (var resource in result[mode]) { stream.push(result[mode][resource]); } } } cb(); }); }); }
[ "function", "gulpSVGSprite", "(", "config", ")", "{", "// Extend plugin error", "function", "extendError", "(", "pError", ",", "error", ")", "{", "if", "(", "error", "&&", "(", "typeof", "error", "===", "'object'", ")", ")", "{", "[", "'name'", ",", "'errno'", "]", ".", "forEach", "(", "function", "(", "property", ")", "{", "if", "(", "property", "in", "error", ")", "{", "this", "[", "property", "]", "=", "error", "[", "property", "]", ";", "}", "}", ",", "pError", ")", ";", "}", "return", "pError", ";", "}", "// Instanciate spriter instance", "var", "spriter", "=", "new", "SVGSpriter", "(", "config", ")", ";", "var", "shapes", "=", "0", ";", "// Intercept error log and convert to plugin errors", "spriter", ".", "config", ".", "log", ".", "error", "=", "function", "(", "message", ",", "error", ")", "{", "this", ".", "emit", "(", "'error'", ",", "extendError", "(", "new", "PluginError", "(", "PLUGIN_NAME", ",", "message", ")", ",", "error", ")", ")", ";", "}", ";", "return", "through2", ".", "obj", "(", "function", "(", "file", ",", "enc", ",", "cb", ")", "{", "var", "error", "=", "null", ";", "try", "{", "spriter", ".", "add", "(", "file", ")", ";", "++", "shapes", ";", "}", "catch", "(", "e", ")", "{", "error", "=", "(", "!", "e", ".", "plugin", "||", "(", "e", ".", "plugin", "!==", "PLUGIN_NAME", ")", ")", "?", "extendError", "(", "new", "PluginError", "(", "PLUGIN_NAME", ",", "e", ".", "message", ")", ",", "e", ")", ":", "e", ";", "}", "return", "cb", "(", "error", ")", ";", "}", ",", "function", "(", "cb", ")", "{", "var", "stream", "=", "this", ";", "spriter", ".", "compile", "(", "function", "(", "error", ",", "result", "/*, data*/", ")", "{", "if", "(", "error", ")", "{", "stream", ".", "emit", "(", "'error'", ",", "new", "PluginError", "(", "PLUGIN_NAME", ",", "error", ")", ")", ";", "}", "else", "if", "(", "shapes", ">", "0", ")", "{", "for", "(", "var", "mode", "in", "result", ")", "{", "for", "(", "var", "resource", "in", "result", "[", "mode", "]", ")", "{", "stream", ".", "push", "(", "result", "[", "mode", "]", "[", "resource", "]", ")", ";", "}", "}", "}", "cb", "(", ")", ";", "}", ")", ";", "}", ")", ";", "}" ]
Plugin level function @param {Object} config SVGSpriter main configuration
[ "Plugin", "level", "function" ]
babc7efe1c3c0538cc31b349b44b8b4b5041952c
https://github.com/jkphl/gulp-svg-sprite/blob/babc7efe1c3c0538cc31b349b44b8b4b5041952c/index.js#L24-L73
17,802
jkphl/gulp-svg-sprite
index.js
extendError
function extendError(pError, error) { if (error && (typeof error === 'object')) { ['name', 'errno'].forEach(function(property) { if (property in error) { this[property] = error[property]; } }, pError); } return pError; }
javascript
function extendError(pError, error) { if (error && (typeof error === 'object')) { ['name', 'errno'].forEach(function(property) { if (property in error) { this[property] = error[property]; } }, pError); } return pError; }
[ "function", "extendError", "(", "pError", ",", "error", ")", "{", "if", "(", "error", "&&", "(", "typeof", "error", "===", "'object'", ")", ")", "{", "[", "'name'", ",", "'errno'", "]", ".", "forEach", "(", "function", "(", "property", ")", "{", "if", "(", "property", "in", "error", ")", "{", "this", "[", "property", "]", "=", "error", "[", "property", "]", ";", "}", "}", ",", "pError", ")", ";", "}", "return", "pError", ";", "}" ]
Extend plugin error
[ "Extend", "plugin", "error" ]
babc7efe1c3c0538cc31b349b44b8b4b5041952c
https://github.com/jkphl/gulp-svg-sprite/blob/babc7efe1c3c0538cc31b349b44b8b4b5041952c/index.js#L27-L37
17,803
expressjs/errorhandler
index.js
stringify
function stringify (val) { var stack = val.stack if (stack) { return String(stack) } var str = String(val) return str === toString.call(val) ? inspect(val) : str }
javascript
function stringify (val) { var stack = val.stack if (stack) { return String(stack) } var str = String(val) return str === toString.call(val) ? inspect(val) : str }
[ "function", "stringify", "(", "val", ")", "{", "var", "stack", "=", "val", ".", "stack", "if", "(", "stack", ")", "{", "return", "String", "(", "stack", ")", "}", "var", "str", "=", "String", "(", "val", ")", "return", "str", "===", "toString", ".", "call", "(", "val", ")", "?", "inspect", "(", "val", ")", ":", "str", "}" ]
Stringify a value. @api private
[ "Stringify", "a", "value", "." ]
2dbd778764ab2fd9e9a85bbbf4267984ed803c44
https://github.com/expressjs/errorhandler/blob/2dbd778764ab2fd9e9a85bbbf4267984ed803c44/index.js#L177-L189
17,804
mfranzke/datalist-polyfill
datalist-polyfill.js
function(event) { var input = event.target, datalist = input.list, keyOpen = event.keyCode === keyUP || event.keyCode === keyDOWN; // Check for whether the events target was an input and still check for an existing instance of the datalist and polyfilling select if (input.tagName.toLowerCase() !== 'input' || datalist === null) { return; } // Handling IE10+ & EDGE if (isGteIE10 || isEDGE) { // On keypress check for value if ( getInputValue(input) !== '' && !keyOpen && event.keyCode !== keyENTER && event.keyCode !== keyESC && // As only EDGE doesn't trigger the input event after selecting an item via mouse, we need to differentiate here (isGteIE10 || input.type === 'text') ) { updateIEOptions(input, datalist); // TODO: Check whether this update is necessary depending on the options values input.focus(); } return; } var visible = false, // Creating the select if there's no instance so far (e.g. because of that it hasn't been handled or it has been dynamically inserted) datalistSelect = datalist.getElementsByClassName(classNamePolyfillingSelect)[0] || setUpPolyfillingSelect(input, datalist); // On an ESC or ENTER key press within the input, let's break here and afterwards hide the datalist select, but if the input contains a value or one of the opening keys have been pressed ... if ( event.keyCode !== keyESC && event.keyCode !== keyENTER && (getInputValue(input) !== '' || keyOpen) && datalistSelect !== undefined ) { // ... prepare the options if (prepOptions(datalist, input).length > 0) { visible = true; } var firstEntry = 0, lastEntry = datalistSelect.options.length - 1; // ... preselect best fitting index if (touched) { datalistSelect.selectedIndex = firstEntry; } else if (keyOpen && input.getAttribute('type') !== 'number') { datalistSelect.selectedIndex = event.keyCode === keyUP ? lastEntry : firstEntry; // ... and on arrow up or down keys, focus the select datalistSelect.focus(); } } // Toggle the visibility of the datalist select according to previous checks toggleVisibility(visible, datalistSelect); }
javascript
function(event) { var input = event.target, datalist = input.list, keyOpen = event.keyCode === keyUP || event.keyCode === keyDOWN; // Check for whether the events target was an input and still check for an existing instance of the datalist and polyfilling select if (input.tagName.toLowerCase() !== 'input' || datalist === null) { return; } // Handling IE10+ & EDGE if (isGteIE10 || isEDGE) { // On keypress check for value if ( getInputValue(input) !== '' && !keyOpen && event.keyCode !== keyENTER && event.keyCode !== keyESC && // As only EDGE doesn't trigger the input event after selecting an item via mouse, we need to differentiate here (isGteIE10 || input.type === 'text') ) { updateIEOptions(input, datalist); // TODO: Check whether this update is necessary depending on the options values input.focus(); } return; } var visible = false, // Creating the select if there's no instance so far (e.g. because of that it hasn't been handled or it has been dynamically inserted) datalistSelect = datalist.getElementsByClassName(classNamePolyfillingSelect)[0] || setUpPolyfillingSelect(input, datalist); // On an ESC or ENTER key press within the input, let's break here and afterwards hide the datalist select, but if the input contains a value or one of the opening keys have been pressed ... if ( event.keyCode !== keyESC && event.keyCode !== keyENTER && (getInputValue(input) !== '' || keyOpen) && datalistSelect !== undefined ) { // ... prepare the options if (prepOptions(datalist, input).length > 0) { visible = true; } var firstEntry = 0, lastEntry = datalistSelect.options.length - 1; // ... preselect best fitting index if (touched) { datalistSelect.selectedIndex = firstEntry; } else if (keyOpen && input.getAttribute('type') !== 'number') { datalistSelect.selectedIndex = event.keyCode === keyUP ? lastEntry : firstEntry; // ... and on arrow up or down keys, focus the select datalistSelect.focus(); } } // Toggle the visibility of the datalist select according to previous checks toggleVisibility(visible, datalistSelect); }
[ "function", "(", "event", ")", "{", "var", "input", "=", "event", ".", "target", ",", "datalist", "=", "input", ".", "list", ",", "keyOpen", "=", "event", ".", "keyCode", "===", "keyUP", "||", "event", ".", "keyCode", "===", "keyDOWN", ";", "// Check for whether the events target was an input and still check for an existing instance of the datalist and polyfilling select", "if", "(", "input", ".", "tagName", ".", "toLowerCase", "(", ")", "!==", "'input'", "||", "datalist", "===", "null", ")", "{", "return", ";", "}", "// Handling IE10+ & EDGE", "if", "(", "isGteIE10", "||", "isEDGE", ")", "{", "// On keypress check for value", "if", "(", "getInputValue", "(", "input", ")", "!==", "''", "&&", "!", "keyOpen", "&&", "event", ".", "keyCode", "!==", "keyENTER", "&&", "event", ".", "keyCode", "!==", "keyESC", "&&", "// As only EDGE doesn't trigger the input event after selecting an item via mouse, we need to differentiate here", "(", "isGteIE10", "||", "input", ".", "type", "===", "'text'", ")", ")", "{", "updateIEOptions", "(", "input", ",", "datalist", ")", ";", "// TODO: Check whether this update is necessary depending on the options values", "input", ".", "focus", "(", ")", ";", "}", "return", ";", "}", "var", "visible", "=", "false", ",", "// Creating the select if there's no instance so far (e.g. because of that it hasn't been handled or it has been dynamically inserted)", "datalistSelect", "=", "datalist", ".", "getElementsByClassName", "(", "classNamePolyfillingSelect", ")", "[", "0", "]", "||", "setUpPolyfillingSelect", "(", "input", ",", "datalist", ")", ";", "// On an ESC or ENTER key press within the input, let's break here and afterwards hide the datalist select, but if the input contains a value or one of the opening keys have been pressed ...", "if", "(", "event", ".", "keyCode", "!==", "keyESC", "&&", "event", ".", "keyCode", "!==", "keyENTER", "&&", "(", "getInputValue", "(", "input", ")", "!==", "''", "||", "keyOpen", ")", "&&", "datalistSelect", "!==", "undefined", ")", "{", "// ... prepare the options", "if", "(", "prepOptions", "(", "datalist", ",", "input", ")", ".", "length", ">", "0", ")", "{", "visible", "=", "true", ";", "}", "var", "firstEntry", "=", "0", ",", "lastEntry", "=", "datalistSelect", ".", "options", ".", "length", "-", "1", ";", "// ... preselect best fitting index", "if", "(", "touched", ")", "{", "datalistSelect", ".", "selectedIndex", "=", "firstEntry", ";", "}", "else", "if", "(", "keyOpen", "&&", "input", ".", "getAttribute", "(", "'type'", ")", "!==", "'number'", ")", "{", "datalistSelect", ".", "selectedIndex", "=", "event", ".", "keyCode", "===", "keyUP", "?", "lastEntry", ":", "firstEntry", ";", "// ... and on arrow up or down keys, focus the select", "datalistSelect", ".", "focus", "(", ")", ";", "}", "}", "// Toggle the visibility of the datalist select according to previous checks", "toggleVisibility", "(", "visible", ",", "datalistSelect", ")", ";", "}" ]
Function regarding the inputs interactions on keyup event
[ "Function", "regarding", "the", "inputs", "interactions", "on", "keyup", "event" ]
491b1bc93c2a3f4b51e37f96cbf3440311cbcbb8
https://github.com/mfranzke/datalist-polyfill/blob/491b1bc93c2a3f4b51e37f96cbf3440311cbcbb8/datalist-polyfill.js#L103-L168
17,805
mfranzke/datalist-polyfill
datalist-polyfill.js
function(event) { var input = event.target, datalist = input.list; if ( !input.matches('input[list]') || !input.matches('.' + classNameInput) || !datalist ) { return; } // Query for related option - and escaping the value as doublequotes wouldn't work var option = datalist.querySelector( 'option[value="' + getInputValue(input).replace(/\\([\s\S])|(")/g, '\\$1$2') + '"]' ); // We're using .getAttribute instead of .dataset here for IE10 if (option && option.getAttribute('data-originalvalue')) { setInputValue(input, option.getAttribute('data-originalvalue')); } }
javascript
function(event) { var input = event.target, datalist = input.list; if ( !input.matches('input[list]') || !input.matches('.' + classNameInput) || !datalist ) { return; } // Query for related option - and escaping the value as doublequotes wouldn't work var option = datalist.querySelector( 'option[value="' + getInputValue(input).replace(/\\([\s\S])|(")/g, '\\$1$2') + '"]' ); // We're using .getAttribute instead of .dataset here for IE10 if (option && option.getAttribute('data-originalvalue')) { setInputValue(input, option.getAttribute('data-originalvalue')); } }
[ "function", "(", "event", ")", "{", "var", "input", "=", "event", ".", "target", ",", "datalist", "=", "input", ".", "list", ";", "if", "(", "!", "input", ".", "matches", "(", "'input[list]'", ")", "||", "!", "input", ".", "matches", "(", "'.'", "+", "classNameInput", ")", "||", "!", "datalist", ")", "{", "return", ";", "}", "// Query for related option - and escaping the value as doublequotes wouldn't work", "var", "option", "=", "datalist", ".", "querySelector", "(", "'option[value=\"'", "+", "getInputValue", "(", "input", ")", ".", "replace", "(", "/", "\\\\([\\s\\S])|(\")", "/", "g", ",", "'\\\\$1$2'", ")", "+", "'\"]'", ")", ";", "// We're using .getAttribute instead of .dataset here for IE10", "if", "(", "option", "&&", "option", ".", "getAttribute", "(", "'data-originalvalue'", ")", ")", "{", "setInputValue", "(", "input", ",", "option", ".", "getAttribute", "(", "'data-originalvalue'", ")", ")", ";", "}", "}" ]
Check for the input and probably replace by correct options elements value
[ "Check", "for", "the", "input", "and", "probably", "replace", "by", "correct", "options", "elements", "value" ]
491b1bc93c2a3f4b51e37f96cbf3440311cbcbb8
https://github.com/mfranzke/datalist-polyfill/blob/491b1bc93c2a3f4b51e37f96cbf3440311cbcbb8/datalist-polyfill.js#L205-L228
17,806
mfranzke/datalist-polyfill
datalist-polyfill.js
function(option, inputValue) { var optVal = option.value.toLowerCase(), inptVal = inputValue.toLowerCase(), label = option.getAttribute('label'), text = option.text.toLowerCase(); /* "Each option element that is a descendant of the datalist element, that is not disabled, and whose value is a string that isn't the empty string, represents a suggestion. Each suggestion has a value and a label." "If appropriate, the user agent should use the suggestion's label and value to identify the suggestion to the user." */ return Boolean( option.disabled === false && ((optVal !== '' && optVal.indexOf(inptVal) !== -1) || (label && label.toLowerCase().indexOf(inptVal) !== -1) || (text !== '' && text.indexOf(inptVal) !== -1)) ); }
javascript
function(option, inputValue) { var optVal = option.value.toLowerCase(), inptVal = inputValue.toLowerCase(), label = option.getAttribute('label'), text = option.text.toLowerCase(); /* "Each option element that is a descendant of the datalist element, that is not disabled, and whose value is a string that isn't the empty string, represents a suggestion. Each suggestion has a value and a label." "If appropriate, the user agent should use the suggestion's label and value to identify the suggestion to the user." */ return Boolean( option.disabled === false && ((optVal !== '' && optVal.indexOf(inptVal) !== -1) || (label && label.toLowerCase().indexOf(inptVal) !== -1) || (text !== '' && text.indexOf(inptVal) !== -1)) ); }
[ "function", "(", "option", ",", "inputValue", ")", "{", "var", "optVal", "=", "option", ".", "value", ".", "toLowerCase", "(", ")", ",", "inptVal", "=", "inputValue", ".", "toLowerCase", "(", ")", ",", "label", "=", "option", ".", "getAttribute", "(", "'label'", ")", ",", "text", "=", "option", ".", "text", ".", "toLowerCase", "(", ")", ";", "/*\n\t\t\"Each option element that is a descendant of the datalist element, that is not disabled, and whose value is a string that isn't the empty string, represents a suggestion. Each suggestion has a value and a label.\"\n\t\t\"If appropriate, the user agent should use the suggestion's label and value to identify the suggestion to the user.\"\n\t\t*/", "return", "Boolean", "(", "option", ".", "disabled", "===", "false", "&&", "(", "(", "optVal", "!==", "''", "&&", "optVal", ".", "indexOf", "(", "inptVal", ")", "!==", "-", "1", ")", "||", "(", "label", "&&", "label", ".", "toLowerCase", "(", ")", ".", "indexOf", "(", "inptVal", ")", "!==", "-", "1", ")", "||", "(", "text", "!==", "''", "&&", "text", ".", "indexOf", "(", "inptVal", ")", "!==", "-", "1", ")", ")", ")", ";", "}" ]
Check for whether this is a valid suggestion
[ "Check", "for", "whether", "this", "is", "a", "valid", "suggestion" ]
491b1bc93c2a3f4b51e37f96cbf3440311cbcbb8
https://github.com/mfranzke/datalist-polyfill/blob/491b1bc93c2a3f4b51e37f96cbf3440311cbcbb8/datalist-polyfill.js#L231-L247
17,807
mfranzke/datalist-polyfill
datalist-polyfill.js
function(event) { // Check for correct element on this event delegation if (!event.target.matches('input[list]')) { return; } var input = event.target, datalist = input.list; // Check for whether the events target was an input and still check for an existing instance of the datalist if (input.tagName.toLowerCase() !== 'input' || datalist === null) { return; } // Test for whether this input has already been enhanced by the polyfill if (!input.matches('.' + classNameInput)) { prepareInput(input, event.type); } // #GH-49: Microsoft EDGE / datalist popups get "emptied" when receiving focus via tabbing if (isEDGE && event.type === 'focusin') { // Set the value of the first option to it's value - this actually triggers a redraw of the complete list var firstOption = input.list.options[0]; firstOption.value = firstOption.value; } // Break here for IE10+ & EDGE if (isGteIE10 || isEDGE) { return; } var // Creating the select if there's no instance so far (e.g. because of that it hasn't been handled or it has been dynamically inserted) datalistSelect = datalist.getElementsByClassName(classNamePolyfillingSelect)[0] || setUpPolyfillingSelect(input, datalist), // Either have the select set to the state to get displayed in case of that it would have been focused or because it's the target on the inputs blur - and check for general existance of any option as suggestions visible = datalistSelect && datalistSelect.querySelector('option:not(:disabled)') && ((event.type === 'focusin' && getInputValue(input) !== '') || (event.relatedTarget && event.relatedTarget === datalistSelect)); // Toggle the visibility of the datalist select according to previous checks toggleVisibility(visible, datalistSelect); }
javascript
function(event) { // Check for correct element on this event delegation if (!event.target.matches('input[list]')) { return; } var input = event.target, datalist = input.list; // Check for whether the events target was an input and still check for an existing instance of the datalist if (input.tagName.toLowerCase() !== 'input' || datalist === null) { return; } // Test for whether this input has already been enhanced by the polyfill if (!input.matches('.' + classNameInput)) { prepareInput(input, event.type); } // #GH-49: Microsoft EDGE / datalist popups get "emptied" when receiving focus via tabbing if (isEDGE && event.type === 'focusin') { // Set the value of the first option to it's value - this actually triggers a redraw of the complete list var firstOption = input.list.options[0]; firstOption.value = firstOption.value; } // Break here for IE10+ & EDGE if (isGteIE10 || isEDGE) { return; } var // Creating the select if there's no instance so far (e.g. because of that it hasn't been handled or it has been dynamically inserted) datalistSelect = datalist.getElementsByClassName(classNamePolyfillingSelect)[0] || setUpPolyfillingSelect(input, datalist), // Either have the select set to the state to get displayed in case of that it would have been focused or because it's the target on the inputs blur - and check for general existance of any option as suggestions visible = datalistSelect && datalistSelect.querySelector('option:not(:disabled)') && ((event.type === 'focusin' && getInputValue(input) !== '') || (event.relatedTarget && event.relatedTarget === datalistSelect)); // Toggle the visibility of the datalist select according to previous checks toggleVisibility(visible, datalistSelect); }
[ "function", "(", "event", ")", "{", "// Check for correct element on this event delegation", "if", "(", "!", "event", ".", "target", ".", "matches", "(", "'input[list]'", ")", ")", "{", "return", ";", "}", "var", "input", "=", "event", ".", "target", ",", "datalist", "=", "input", ".", "list", ";", "// Check for whether the events target was an input and still check for an existing instance of the datalist", "if", "(", "input", ".", "tagName", ".", "toLowerCase", "(", ")", "!==", "'input'", "||", "datalist", "===", "null", ")", "{", "return", ";", "}", "// Test for whether this input has already been enhanced by the polyfill", "if", "(", "!", "input", ".", "matches", "(", "'.'", "+", "classNameInput", ")", ")", "{", "prepareInput", "(", "input", ",", "event", ".", "type", ")", ";", "}", "// #GH-49: Microsoft EDGE / datalist popups get \"emptied\" when receiving focus via tabbing", "if", "(", "isEDGE", "&&", "event", ".", "type", "===", "'focusin'", ")", "{", "// Set the value of the first option to it's value - this actually triggers a redraw of the complete list", "var", "firstOption", "=", "input", ".", "list", ".", "options", "[", "0", "]", ";", "firstOption", ".", "value", "=", "firstOption", ".", "value", ";", "}", "// Break here for IE10+ & EDGE", "if", "(", "isGteIE10", "||", "isEDGE", ")", "{", "return", ";", "}", "var", "// Creating the select if there's no instance so far (e.g. because of that it hasn't been handled or it has been dynamically inserted)", "datalistSelect", "=", "datalist", ".", "getElementsByClassName", "(", "classNamePolyfillingSelect", ")", "[", "0", "]", "||", "setUpPolyfillingSelect", "(", "input", ",", "datalist", ")", ",", "// Either have the select set to the state to get displayed in case of that it would have been focused or because it's the target on the inputs blur - and check for general existance of any option as suggestions", "visible", "=", "datalistSelect", "&&", "datalistSelect", ".", "querySelector", "(", "'option:not(:disabled)'", ")", "&&", "(", "(", "event", ".", "type", "===", "'focusin'", "&&", "getInputValue", "(", "input", ")", "!==", "''", ")", "||", "(", "event", ".", "relatedTarget", "&&", "event", ".", "relatedTarget", "===", "datalistSelect", ")", ")", ";", "// Toggle the visibility of the datalist select according to previous checks", "toggleVisibility", "(", "visible", ",", "datalistSelect", ")", ";", "}" ]
Focusin and -out events
[ "Focusin", "and", "-", "out", "events" ]
491b1bc93c2a3f4b51e37f96cbf3440311cbcbb8
https://github.com/mfranzke/datalist-polyfill/blob/491b1bc93c2a3f4b51e37f96cbf3440311cbcbb8/datalist-polyfill.js#L250-L295
17,808
mfranzke/datalist-polyfill
datalist-polyfill.js
function(input, eventType) { // We'd like to prevent autocomplete on the input datalist field input.setAttribute('autocomplete', 'off'); // WAI ARIA attributes input.setAttribute('role', 'textbox'); input.setAttribute('aria-haspopup', 'true'); input.setAttribute('aria-autocomplete', 'list'); input.setAttribute('aria-owns', input.getAttribute('list')); // Bind the keyup event on the related datalists input if (eventType === 'focusin') { input.addEventListener('keyup', inputInputList); input.addEventListener('focusout', changesInputList, true); // As only EDGE doesn't trigger the input event after selecting an item via mouse, we need to differentiate here if (isGteIE10 || (isEDGE && input.type === 'text')) { input.addEventListener('input', inputInputListIE); } } else if (eventType === 'blur') { input.removeEventListener('keyup', inputInputList); input.removeEventListener('focusout', changesInputList, true); // As only EDGE doesn't trigger the input event after selecting an item via mouse, we need to differentiate here if (isGteIE10 || (isEDGE && input.type === 'text')) { input.removeEventListener('input', inputInputListIE); } } // Add class for identifying that this input is even already being polyfilled input.className += ' ' + classNameInput; }
javascript
function(input, eventType) { // We'd like to prevent autocomplete on the input datalist field input.setAttribute('autocomplete', 'off'); // WAI ARIA attributes input.setAttribute('role', 'textbox'); input.setAttribute('aria-haspopup', 'true'); input.setAttribute('aria-autocomplete', 'list'); input.setAttribute('aria-owns', input.getAttribute('list')); // Bind the keyup event on the related datalists input if (eventType === 'focusin') { input.addEventListener('keyup', inputInputList); input.addEventListener('focusout', changesInputList, true); // As only EDGE doesn't trigger the input event after selecting an item via mouse, we need to differentiate here if (isGteIE10 || (isEDGE && input.type === 'text')) { input.addEventListener('input', inputInputListIE); } } else if (eventType === 'blur') { input.removeEventListener('keyup', inputInputList); input.removeEventListener('focusout', changesInputList, true); // As only EDGE doesn't trigger the input event after selecting an item via mouse, we need to differentiate here if (isGteIE10 || (isEDGE && input.type === 'text')) { input.removeEventListener('input', inputInputListIE); } } // Add class for identifying that this input is even already being polyfilled input.className += ' ' + classNameInput; }
[ "function", "(", "input", ",", "eventType", ")", "{", "// We'd like to prevent autocomplete on the input datalist field", "input", ".", "setAttribute", "(", "'autocomplete'", ",", "'off'", ")", ";", "// WAI ARIA attributes", "input", ".", "setAttribute", "(", "'role'", ",", "'textbox'", ")", ";", "input", ".", "setAttribute", "(", "'aria-haspopup'", ",", "'true'", ")", ";", "input", ".", "setAttribute", "(", "'aria-autocomplete'", ",", "'list'", ")", ";", "input", ".", "setAttribute", "(", "'aria-owns'", ",", "input", ".", "getAttribute", "(", "'list'", ")", ")", ";", "// Bind the keyup event on the related datalists input", "if", "(", "eventType", "===", "'focusin'", ")", "{", "input", ".", "addEventListener", "(", "'keyup'", ",", "inputInputList", ")", ";", "input", ".", "addEventListener", "(", "'focusout'", ",", "changesInputList", ",", "true", ")", ";", "// As only EDGE doesn't trigger the input event after selecting an item via mouse, we need to differentiate here", "if", "(", "isGteIE10", "||", "(", "isEDGE", "&&", "input", ".", "type", "===", "'text'", ")", ")", "{", "input", ".", "addEventListener", "(", "'input'", ",", "inputInputListIE", ")", ";", "}", "}", "else", "if", "(", "eventType", "===", "'blur'", ")", "{", "input", ".", "removeEventListener", "(", "'keyup'", ",", "inputInputList", ")", ";", "input", ".", "removeEventListener", "(", "'focusout'", ",", "changesInputList", ",", "true", ")", ";", "// As only EDGE doesn't trigger the input event after selecting an item via mouse, we need to differentiate here", "if", "(", "isGteIE10", "||", "(", "isEDGE", "&&", "input", ".", "type", "===", "'text'", ")", ")", "{", "input", ".", "removeEventListener", "(", "'input'", ",", "inputInputListIE", ")", ";", "}", "}", "// Add class for identifying that this input is even already being polyfilled", "input", ".", "className", "+=", "' '", "+", "classNameInput", ";", "}" ]
Prepare the input
[ "Prepare", "the", "input" ]
491b1bc93c2a3f4b51e37f96cbf3440311cbcbb8
https://github.com/mfranzke/datalist-polyfill/blob/491b1bc93c2a3f4b51e37f96cbf3440311cbcbb8/datalist-polyfill.js#L298-L331
17,809
mfranzke/datalist-polyfill
datalist-polyfill.js
function(input) { // In case of type=email and multiple attribute, we would need to grab the last piece // Using .getAttribute here for IE9 purpose - elsewhere it wouldn't return the newer HTML5 values correctly return input.getAttribute('type') === 'email' && input.getAttribute('multiple') !== null ? input.value.substring(input.value.lastIndexOf(',') + 1) : input.value; }
javascript
function(input) { // In case of type=email and multiple attribute, we would need to grab the last piece // Using .getAttribute here for IE9 purpose - elsewhere it wouldn't return the newer HTML5 values correctly return input.getAttribute('type') === 'email' && input.getAttribute('multiple') !== null ? input.value.substring(input.value.lastIndexOf(',') + 1) : input.value; }
[ "function", "(", "input", ")", "{", "// In case of type=email and multiple attribute, we would need to grab the last piece", "// Using .getAttribute here for IE9 purpose - elsewhere it wouldn't return the newer HTML5 values correctly", "return", "input", ".", "getAttribute", "(", "'type'", ")", "===", "'email'", "&&", "input", ".", "getAttribute", "(", "'multiple'", ")", "!==", "null", "?", "input", ".", "value", ".", "substring", "(", "input", ".", "value", ".", "lastIndexOf", "(", "','", ")", "+", "1", ")", ":", "input", ".", "value", ";", "}" ]
Get the input value for dividing regular and mail types
[ "Get", "the", "input", "value", "for", "dividing", "regular", "and", "mail", "types" ]
491b1bc93c2a3f4b51e37f96cbf3440311cbcbb8
https://github.com/mfranzke/datalist-polyfill/blob/491b1bc93c2a3f4b51e37f96cbf3440311cbcbb8/datalist-polyfill.js#L334-L341
17,810
mfranzke/datalist-polyfill
datalist-polyfill.js
function(input, datalistSelectValue) { var lastSeperator; // In case of type=email and multiple attribute, we need to set up the resulting inputs value differently input.value = // Using .getAttribute here for IE9 purpose - elsewhere it wouldn't return the newer HTML5 values correctly input.getAttribute('type') === 'email' && input.getAttribute('multiple') !== null && (lastSeperator = input.value.lastIndexOf(',')) > -1 ? input.value.slice(0, lastSeperator) + ',' + datalistSelectValue : datalistSelectValue; }
javascript
function(input, datalistSelectValue) { var lastSeperator; // In case of type=email and multiple attribute, we need to set up the resulting inputs value differently input.value = // Using .getAttribute here for IE9 purpose - elsewhere it wouldn't return the newer HTML5 values correctly input.getAttribute('type') === 'email' && input.getAttribute('multiple') !== null && (lastSeperator = input.value.lastIndexOf(',')) > -1 ? input.value.slice(0, lastSeperator) + ',' + datalistSelectValue : datalistSelectValue; }
[ "function", "(", "input", ",", "datalistSelectValue", ")", "{", "var", "lastSeperator", ";", "// In case of type=email and multiple attribute, we need to set up the resulting inputs value differently", "input", ".", "value", "=", "// Using .getAttribute here for IE9 purpose - elsewhere it wouldn't return the newer HTML5 values correctly", "input", ".", "getAttribute", "(", "'type'", ")", "===", "'email'", "&&", "input", ".", "getAttribute", "(", "'multiple'", ")", "!==", "null", "&&", "(", "lastSeperator", "=", "input", ".", "value", ".", "lastIndexOf", "(", "','", ")", ")", ">", "-", "1", "?", "input", ".", "value", ".", "slice", "(", "0", ",", "lastSeperator", ")", "+", "','", "+", "datalistSelectValue", ":", "datalistSelectValue", ";", "}" ]
Set the input value for dividing regular and mail types
[ "Set", "the", "input", "value", "for", "dividing", "regular", "and", "mail", "types" ]
491b1bc93c2a3f4b51e37f96cbf3440311cbcbb8
https://github.com/mfranzke/datalist-polyfill/blob/491b1bc93c2a3f4b51e37f96cbf3440311cbcbb8/datalist-polyfill.js#L344-L355
17,811
mfranzke/datalist-polyfill
datalist-polyfill.js
function(input, datalist) { // Check for whether it's of one of the supported input types defined at the beginning // Using .getAttribute here for IE9 purpose - elsewhere it wouldn't return the newer HTML5 values correctly // and still check for an existing instance if ( (input.getAttribute('type') && supportedTypes.indexOf(input.getAttribute('type')) === -1) || datalist === null ) { return; } var rects = input.getClientRects(), // Measurements inputStyles = window.getComputedStyle(input), datalistSelect = dcmnt.createElement('select'); // Setting a class for easier identifying that select afterwards datalistSelect.setAttribute('class', classNamePolyfillingSelect); // Set general styling related definitions datalistSelect.style.position = 'absolute'; // Initially hiding the datalist select toggleVisibility(false, datalistSelect); // The select itself shouldn't be a possible target for tabbing datalistSelect.setAttribute('tabindex', '-1'); // WAI ARIA attributes datalistSelect.setAttribute('aria-live', 'polite'); datalistSelect.setAttribute('role', 'listbox'); if (!touched) { datalistSelect.setAttribute('aria-multiselectable', 'false'); } // The select should get positioned underneath the input field ... if (inputStyles.getPropertyValue('display') === 'block') { datalistSelect.style.marginTop = '-' + inputStyles.getPropertyValue('margin-bottom'); } else { var direction = inputStyles.getPropertyValue('direction') === 'rtl' ? 'right' : 'left'; datalistSelect.style.setProperty( 'margin-' + direction, '-' + (rects[0].width + parseFloat(inputStyles.getPropertyValue('margin-' + direction))) + 'px' ); datalistSelect.style.marginTop = parseInt(rects[0].height + (input.offsetTop - datalist.offsetTop), 10) + 'px'; } // Set the polyfilling selects border-radius equally to the one by the polyfilled input datalistSelect.style.borderRadius = inputStyles.getPropertyValue( 'border-radius' ); datalistSelect.style.minWidth = rects[0].width + 'px'; if (touched) { var messageElement = dcmnt.createElement('option'); // ... and it's first entry should contain the localized message to select an entry messageElement.innerText = datalist.title; // ... and disable this option, as it shouldn't get selected by the user messageElement.disabled = true; // ... and assign a dividable class to it messageElement.setAttribute('class', 'message'); // ... and finally insert it into the select datalistSelect.appendChild(messageElement); } // Add select to datalist element ... datalist.appendChild(datalistSelect); // ... and our upfollowing functions to the related event if (touched) { datalistSelect.addEventListener('change', changeDataListSelect); } else { datalistSelect.addEventListener('click', changeDataListSelect); } datalistSelect.addEventListener('blur', changeDataListSelect); datalistSelect.addEventListener('keydown', changeDataListSelect); datalistSelect.addEventListener('keypress', datalistSelectKeyPress); return datalistSelect; }
javascript
function(input, datalist) { // Check for whether it's of one of the supported input types defined at the beginning // Using .getAttribute here for IE9 purpose - elsewhere it wouldn't return the newer HTML5 values correctly // and still check for an existing instance if ( (input.getAttribute('type') && supportedTypes.indexOf(input.getAttribute('type')) === -1) || datalist === null ) { return; } var rects = input.getClientRects(), // Measurements inputStyles = window.getComputedStyle(input), datalistSelect = dcmnt.createElement('select'); // Setting a class for easier identifying that select afterwards datalistSelect.setAttribute('class', classNamePolyfillingSelect); // Set general styling related definitions datalistSelect.style.position = 'absolute'; // Initially hiding the datalist select toggleVisibility(false, datalistSelect); // The select itself shouldn't be a possible target for tabbing datalistSelect.setAttribute('tabindex', '-1'); // WAI ARIA attributes datalistSelect.setAttribute('aria-live', 'polite'); datalistSelect.setAttribute('role', 'listbox'); if (!touched) { datalistSelect.setAttribute('aria-multiselectable', 'false'); } // The select should get positioned underneath the input field ... if (inputStyles.getPropertyValue('display') === 'block') { datalistSelect.style.marginTop = '-' + inputStyles.getPropertyValue('margin-bottom'); } else { var direction = inputStyles.getPropertyValue('direction') === 'rtl' ? 'right' : 'left'; datalistSelect.style.setProperty( 'margin-' + direction, '-' + (rects[0].width + parseFloat(inputStyles.getPropertyValue('margin-' + direction))) + 'px' ); datalistSelect.style.marginTop = parseInt(rects[0].height + (input.offsetTop - datalist.offsetTop), 10) + 'px'; } // Set the polyfilling selects border-radius equally to the one by the polyfilled input datalistSelect.style.borderRadius = inputStyles.getPropertyValue( 'border-radius' ); datalistSelect.style.minWidth = rects[0].width + 'px'; if (touched) { var messageElement = dcmnt.createElement('option'); // ... and it's first entry should contain the localized message to select an entry messageElement.innerText = datalist.title; // ... and disable this option, as it shouldn't get selected by the user messageElement.disabled = true; // ... and assign a dividable class to it messageElement.setAttribute('class', 'message'); // ... and finally insert it into the select datalistSelect.appendChild(messageElement); } // Add select to datalist element ... datalist.appendChild(datalistSelect); // ... and our upfollowing functions to the related event if (touched) { datalistSelect.addEventListener('change', changeDataListSelect); } else { datalistSelect.addEventListener('click', changeDataListSelect); } datalistSelect.addEventListener('blur', changeDataListSelect); datalistSelect.addEventListener('keydown', changeDataListSelect); datalistSelect.addEventListener('keypress', datalistSelectKeyPress); return datalistSelect; }
[ "function", "(", "input", ",", "datalist", ")", "{", "// Check for whether it's of one of the supported input types defined at the beginning", "// Using .getAttribute here for IE9 purpose - elsewhere it wouldn't return the newer HTML5 values correctly", "// and still check for an existing instance", "if", "(", "(", "input", ".", "getAttribute", "(", "'type'", ")", "&&", "supportedTypes", ".", "indexOf", "(", "input", ".", "getAttribute", "(", "'type'", ")", ")", "===", "-", "1", ")", "||", "datalist", "===", "null", ")", "{", "return", ";", "}", "var", "rects", "=", "input", ".", "getClientRects", "(", ")", ",", "// Measurements", "inputStyles", "=", "window", ".", "getComputedStyle", "(", "input", ")", ",", "datalistSelect", "=", "dcmnt", ".", "createElement", "(", "'select'", ")", ";", "// Setting a class for easier identifying that select afterwards", "datalistSelect", ".", "setAttribute", "(", "'class'", ",", "classNamePolyfillingSelect", ")", ";", "// Set general styling related definitions", "datalistSelect", ".", "style", ".", "position", "=", "'absolute'", ";", "// Initially hiding the datalist select", "toggleVisibility", "(", "false", ",", "datalistSelect", ")", ";", "// The select itself shouldn't be a possible target for tabbing", "datalistSelect", ".", "setAttribute", "(", "'tabindex'", ",", "'-1'", ")", ";", "// WAI ARIA attributes", "datalistSelect", ".", "setAttribute", "(", "'aria-live'", ",", "'polite'", ")", ";", "datalistSelect", ".", "setAttribute", "(", "'role'", ",", "'listbox'", ")", ";", "if", "(", "!", "touched", ")", "{", "datalistSelect", ".", "setAttribute", "(", "'aria-multiselectable'", ",", "'false'", ")", ";", "}", "// The select should get positioned underneath the input field ...", "if", "(", "inputStyles", ".", "getPropertyValue", "(", "'display'", ")", "===", "'block'", ")", "{", "datalistSelect", ".", "style", ".", "marginTop", "=", "'-'", "+", "inputStyles", ".", "getPropertyValue", "(", "'margin-bottom'", ")", ";", "}", "else", "{", "var", "direction", "=", "inputStyles", ".", "getPropertyValue", "(", "'direction'", ")", "===", "'rtl'", "?", "'right'", ":", "'left'", ";", "datalistSelect", ".", "style", ".", "setProperty", "(", "'margin-'", "+", "direction", ",", "'-'", "+", "(", "rects", "[", "0", "]", ".", "width", "+", "parseFloat", "(", "inputStyles", ".", "getPropertyValue", "(", "'margin-'", "+", "direction", ")", ")", ")", "+", "'px'", ")", ";", "datalistSelect", ".", "style", ".", "marginTop", "=", "parseInt", "(", "rects", "[", "0", "]", ".", "height", "+", "(", "input", ".", "offsetTop", "-", "datalist", ".", "offsetTop", ")", ",", "10", ")", "+", "'px'", ";", "}", "// Set the polyfilling selects border-radius equally to the one by the polyfilled input", "datalistSelect", ".", "style", ".", "borderRadius", "=", "inputStyles", ".", "getPropertyValue", "(", "'border-radius'", ")", ";", "datalistSelect", ".", "style", ".", "minWidth", "=", "rects", "[", "0", "]", ".", "width", "+", "'px'", ";", "if", "(", "touched", ")", "{", "var", "messageElement", "=", "dcmnt", ".", "createElement", "(", "'option'", ")", ";", "// ... and it's first entry should contain the localized message to select an entry", "messageElement", ".", "innerText", "=", "datalist", ".", "title", ";", "// ... and disable this option, as it shouldn't get selected by the user", "messageElement", ".", "disabled", "=", "true", ";", "// ... and assign a dividable class to it", "messageElement", ".", "setAttribute", "(", "'class'", ",", "'message'", ")", ";", "// ... and finally insert it into the select", "datalistSelect", ".", "appendChild", "(", "messageElement", ")", ";", "}", "// Add select to datalist element ...", "datalist", ".", "appendChild", "(", "datalistSelect", ")", ";", "// ... and our upfollowing functions to the related event", "if", "(", "touched", ")", "{", "datalistSelect", ".", "addEventListener", "(", "'change'", ",", "changeDataListSelect", ")", ";", "}", "else", "{", "datalistSelect", ".", "addEventListener", "(", "'click'", ",", "changeDataListSelect", ")", ";", "}", "datalistSelect", ".", "addEventListener", "(", "'blur'", ",", "changeDataListSelect", ")", ";", "datalistSelect", ".", "addEventListener", "(", "'keydown'", ",", "changeDataListSelect", ")", ";", "datalistSelect", ".", "addEventListener", "(", "'keypress'", ",", "datalistSelectKeyPress", ")", ";", "return", "datalistSelect", ";", "}" ]
Define function for setting up the polyfilling select
[ "Define", "function", "for", "setting", "up", "the", "polyfilling", "select" ]
491b1bc93c2a3f4b51e37f96cbf3440311cbcbb8
https://github.com/mfranzke/datalist-polyfill/blob/491b1bc93c2a3f4b51e37f96cbf3440311cbcbb8/datalist-polyfill.js#L453-L543
17,812
mfranzke/datalist-polyfill
datalist-polyfill.js
function(event) { var datalistSelect = event.target, datalist = datalistSelect.parentNode, input = dcmnt.querySelector('input[list="' + datalist.id + '"]'); // Check for whether the events target was a select or whether the input doesn't exist if (datalistSelect.tagName.toLowerCase() !== 'select' || input === null) { return; } // Determine a relevant key - either printable characters (that would have a length of 1) or controlling like Backspace if (event.key && (event.key === 'Backspace' || event.key.length === 1)) { input.focus(); if (event.key === 'Backspace') { input.value = input.value.substr(0, input.value.length - 1); // Dispatch the input event on the related input[list] dispatchInputEvent(input); } else { input.value += event.key; } prepOptions(datalist, input); } }
javascript
function(event) { var datalistSelect = event.target, datalist = datalistSelect.parentNode, input = dcmnt.querySelector('input[list="' + datalist.id + '"]'); // Check for whether the events target was a select or whether the input doesn't exist if (datalistSelect.tagName.toLowerCase() !== 'select' || input === null) { return; } // Determine a relevant key - either printable characters (that would have a length of 1) or controlling like Backspace if (event.key && (event.key === 'Backspace' || event.key.length === 1)) { input.focus(); if (event.key === 'Backspace') { input.value = input.value.substr(0, input.value.length - 1); // Dispatch the input event on the related input[list] dispatchInputEvent(input); } else { input.value += event.key; } prepOptions(datalist, input); } }
[ "function", "(", "event", ")", "{", "var", "datalistSelect", "=", "event", ".", "target", ",", "datalist", "=", "datalistSelect", ".", "parentNode", ",", "input", "=", "dcmnt", ".", "querySelector", "(", "'input[list=\"'", "+", "datalist", ".", "id", "+", "'\"]'", ")", ";", "// Check for whether the events target was a select or whether the input doesn't exist", "if", "(", "datalistSelect", ".", "tagName", ".", "toLowerCase", "(", ")", "!==", "'select'", "||", "input", "===", "null", ")", "{", "return", ";", "}", "// Determine a relevant key - either printable characters (that would have a length of 1) or controlling like Backspace", "if", "(", "event", ".", "key", "&&", "(", "event", ".", "key", "===", "'Backspace'", "||", "event", ".", "key", ".", "length", "===", "1", ")", ")", "{", "input", ".", "focus", "(", ")", ";", "if", "(", "event", ".", "key", "===", "'Backspace'", ")", "{", "input", ".", "value", "=", "input", ".", "value", ".", "substr", "(", "0", ",", "input", ".", "value", ".", "length", "-", "1", ")", ";", "// Dispatch the input event on the related input[list]", "dispatchInputEvent", "(", "input", ")", ";", "}", "else", "{", "input", ".", "value", "+=", "event", ".", "key", ";", "}", "prepOptions", "(", "datalist", ",", "input", ")", ";", "}", "}" ]
Functions regarding changes to the datalist polyfilling created selects keypress
[ "Functions", "regarding", "changes", "to", "the", "datalist", "polyfilling", "created", "selects", "keypress" ]
491b1bc93c2a3f4b51e37f96cbf3440311cbcbb8
https://github.com/mfranzke/datalist-polyfill/blob/491b1bc93c2a3f4b51e37f96cbf3440311cbcbb8/datalist-polyfill.js#L546-L571
17,813
mfranzke/datalist-polyfill
datalist-polyfill.js
function(event) { var datalistSelect = event.currentTarget, datalist = datalistSelect.parentNode, input = dcmnt.querySelector('input[list="' + datalist.id + '"]'); // Check for whether the events target was a select or whether the input doesn't exist if (datalistSelect.tagName.toLowerCase() !== 'select' || input === null) { return; } var eventType = event.type, // ENTER and ESC visible = eventType === 'keydown' && (event.keyCode !== keyENTER && event.keyCode !== keyESC); // On change, click or after pressing ENTER or TAB key, input the selects value into the input on a change within the list if ( (eventType === 'change' || eventType === 'click' || (eventType === 'keydown' && (event.keyCode === keyENTER || event.key === 'Tab'))) && datalistSelect.value.length > 0 && datalistSelect.value !== datalist.title ) { setInputValue(input, datalistSelect.value); // Dispatch the input event on the related input[list] dispatchInputEvent(input); // Finally focusing the input, as other browser do this as well if (event.key !== 'Tab') { input.focus(); } // #GH-51 / Prevent the form to be submitted on selecting a value via ENTER key within the select if (event.keyCode === keyENTER) { event.preventDefault(); } // Set the visibility to false afterwards, as we're done here visible = false; } else if (eventType === 'keydown' && event.keyCode === keyESC) { // In case of the ESC key being pressed, we still want to focus the input[list] input.focus(); } // Toggle the visibility of the datalist select according to previous checks toggleVisibility(visible, datalistSelect); }
javascript
function(event) { var datalistSelect = event.currentTarget, datalist = datalistSelect.parentNode, input = dcmnt.querySelector('input[list="' + datalist.id + '"]'); // Check for whether the events target was a select or whether the input doesn't exist if (datalistSelect.tagName.toLowerCase() !== 'select' || input === null) { return; } var eventType = event.type, // ENTER and ESC visible = eventType === 'keydown' && (event.keyCode !== keyENTER && event.keyCode !== keyESC); // On change, click or after pressing ENTER or TAB key, input the selects value into the input on a change within the list if ( (eventType === 'change' || eventType === 'click' || (eventType === 'keydown' && (event.keyCode === keyENTER || event.key === 'Tab'))) && datalistSelect.value.length > 0 && datalistSelect.value !== datalist.title ) { setInputValue(input, datalistSelect.value); // Dispatch the input event on the related input[list] dispatchInputEvent(input); // Finally focusing the input, as other browser do this as well if (event.key !== 'Tab') { input.focus(); } // #GH-51 / Prevent the form to be submitted on selecting a value via ENTER key within the select if (event.keyCode === keyENTER) { event.preventDefault(); } // Set the visibility to false afterwards, as we're done here visible = false; } else if (eventType === 'keydown' && event.keyCode === keyESC) { // In case of the ESC key being pressed, we still want to focus the input[list] input.focus(); } // Toggle the visibility of the datalist select according to previous checks toggleVisibility(visible, datalistSelect); }
[ "function", "(", "event", ")", "{", "var", "datalistSelect", "=", "event", ".", "currentTarget", ",", "datalist", "=", "datalistSelect", ".", "parentNode", ",", "input", "=", "dcmnt", ".", "querySelector", "(", "'input[list=\"'", "+", "datalist", ".", "id", "+", "'\"]'", ")", ";", "// Check for whether the events target was a select or whether the input doesn't exist", "if", "(", "datalistSelect", ".", "tagName", ".", "toLowerCase", "(", ")", "!==", "'select'", "||", "input", "===", "null", ")", "{", "return", ";", "}", "var", "eventType", "=", "event", ".", "type", ",", "// ENTER and ESC", "visible", "=", "eventType", "===", "'keydown'", "&&", "(", "event", ".", "keyCode", "!==", "keyENTER", "&&", "event", ".", "keyCode", "!==", "keyESC", ")", ";", "// On change, click or after pressing ENTER or TAB key, input the selects value into the input on a change within the list", "if", "(", "(", "eventType", "===", "'change'", "||", "eventType", "===", "'click'", "||", "(", "eventType", "===", "'keydown'", "&&", "(", "event", ".", "keyCode", "===", "keyENTER", "||", "event", ".", "key", "===", "'Tab'", ")", ")", ")", "&&", "datalistSelect", ".", "value", ".", "length", ">", "0", "&&", "datalistSelect", ".", "value", "!==", "datalist", ".", "title", ")", "{", "setInputValue", "(", "input", ",", "datalistSelect", ".", "value", ")", ";", "// Dispatch the input event on the related input[list]", "dispatchInputEvent", "(", "input", ")", ";", "// Finally focusing the input, as other browser do this as well", "if", "(", "event", ".", "key", "!==", "'Tab'", ")", "{", "input", ".", "focus", "(", ")", ";", "}", "// #GH-51 / Prevent the form to be submitted on selecting a value via ENTER key within the select", "if", "(", "event", ".", "keyCode", "===", "keyENTER", ")", "{", "event", ".", "preventDefault", "(", ")", ";", "}", "// Set the visibility to false afterwards, as we're done here", "visible", "=", "false", ";", "}", "else", "if", "(", "eventType", "===", "'keydown'", "&&", "event", ".", "keyCode", "===", "keyESC", ")", "{", "// In case of the ESC key being pressed, we still want to focus the input[list]", "input", ".", "focus", "(", ")", ";", "}", "// Toggle the visibility of the datalist select according to previous checks", "toggleVisibility", "(", "visible", ",", "datalistSelect", ")", ";", "}" ]
Change, Click, Blur, Keydown
[ "Change", "Click", "Blur", "Keydown" ]
491b1bc93c2a3f4b51e37f96cbf3440311cbcbb8
https://github.com/mfranzke/datalist-polyfill/blob/491b1bc93c2a3f4b51e37f96cbf3440311cbcbb8/datalist-polyfill.js#L574-L623
17,814
mfranzke/datalist-polyfill
datalist-polyfill.js
function(input) { var evt; if (typeof Event === 'function') { evt = new Event('input', { bubbles: true }); } else { evt = dcmnt.createEvent('Event'); evt.initEvent('input', true, false); } input.dispatchEvent(evt); }
javascript
function(input) { var evt; if (typeof Event === 'function') { evt = new Event('input', { bubbles: true }); } else { evt = dcmnt.createEvent('Event'); evt.initEvent('input', true, false); } input.dispatchEvent(evt); }
[ "function", "(", "input", ")", "{", "var", "evt", ";", "if", "(", "typeof", "Event", "===", "'function'", ")", "{", "evt", "=", "new", "Event", "(", "'input'", ",", "{", "bubbles", ":", "true", "}", ")", ";", "}", "else", "{", "evt", "=", "dcmnt", ".", "createEvent", "(", "'Event'", ")", ";", "evt", ".", "initEvent", "(", "'input'", ",", "true", ",", "false", ")", ";", "}", "input", ".", "dispatchEvent", "(", "evt", ")", ";", "}" ]
Create and dispatch the input event; divided for IE9 usage
[ "Create", "and", "dispatch", "the", "input", "event", ";", "divided", "for", "IE9", "usage" ]
491b1bc93c2a3f4b51e37f96cbf3440311cbcbb8
https://github.com/mfranzke/datalist-polyfill/blob/491b1bc93c2a3f4b51e37f96cbf3440311cbcbb8/datalist-polyfill.js#L626-L639
17,815
mfranzke/datalist-polyfill
datalist-polyfill.js
function(visible, datalistSelect) { if (visible) { datalistSelect.removeAttribute('hidden'); } else { datalistSelect.setAttributeNode(dcmnt.createAttribute('hidden')); } datalistSelect.setAttribute('aria-hidden', (!visible).toString()); }
javascript
function(visible, datalistSelect) { if (visible) { datalistSelect.removeAttribute('hidden'); } else { datalistSelect.setAttributeNode(dcmnt.createAttribute('hidden')); } datalistSelect.setAttribute('aria-hidden', (!visible).toString()); }
[ "function", "(", "visible", ",", "datalistSelect", ")", "{", "if", "(", "visible", ")", "{", "datalistSelect", ".", "removeAttribute", "(", "'hidden'", ")", ";", "}", "else", "{", "datalistSelect", ".", "setAttributeNode", "(", "dcmnt", ".", "createAttribute", "(", "'hidden'", ")", ")", ";", "}", "datalistSelect", ".", "setAttribute", "(", "'aria-hidden'", ",", "(", "!", "visible", ")", ".", "toString", "(", ")", ")", ";", "}" ]
Toggle the visibility of the datalist select
[ "Toggle", "the", "visibility", "of", "the", "datalist", "select" ]
491b1bc93c2a3f4b51e37f96cbf3440311cbcbb8
https://github.com/mfranzke/datalist-polyfill/blob/491b1bc93c2a3f4b51e37f96cbf3440311cbcbb8/datalist-polyfill.js#L642-L650
17,816
mddub/minimed-connect-to-nightscout
filter.js
makeRecencyFilter
function makeRecencyFilter(timeFn) { var lastTime = 0; return function(items) { var out = []; items.forEach(function(item) { if (timeFn(item) > lastTime) { out.push(item); } }); out.forEach(function(item) { lastTime = Math.max(lastTime, timeFn(item)); }); return out; }; }
javascript
function makeRecencyFilter(timeFn) { var lastTime = 0; return function(items) { var out = []; items.forEach(function(item) { if (timeFn(item) > lastTime) { out.push(item); } }); out.forEach(function(item) { lastTime = Math.max(lastTime, timeFn(item)); }); return out; }; }
[ "function", "makeRecencyFilter", "(", "timeFn", ")", "{", "var", "lastTime", "=", "0", ";", "return", "function", "(", "items", ")", "{", "var", "out", "=", "[", "]", ";", "items", ".", "forEach", "(", "function", "(", "item", ")", "{", "if", "(", "timeFn", "(", "item", ")", ">", "lastTime", ")", "{", "out", ".", "push", "(", "item", ")", ";", "}", "}", ")", ";", "out", ".", "forEach", "(", "function", "(", "item", ")", "{", "lastTime", "=", "Math", ".", "max", "(", "lastTime", ",", "timeFn", "(", "item", ")", ")", ";", "}", ")", ";", "return", "out", ";", "}", ";", "}" ]
Returns a stateful filter which remembers the time of the last-seen entry to prevent uploading duplicates.
[ "Returns", "a", "stateful", "filter", "which", "remembers", "the", "time", "of", "the", "last", "-", "seen", "entry", "to", "prevent", "uploading", "duplicates", "." ]
83f8d4684ac781c87d9f673af2165c70ef7082d5
https://github.com/mddub/minimed-connect-to-nightscout/blob/83f8d4684ac781c87d9f673af2165c70ef7082d5/filter.js#L6-L22
17,817
willowtreeapps/wist
src/js/config/config-file.js
getBaseDir
function getBaseDir(configFilePath) { // calculates the path of the project including Wist as dependency const projectPath = path.resolve(__dirname, '../../../'); if (configFilePath && pathIsInside(configFilePath, projectPath)) { // be careful of https://github.com/substack/node-resolve/issues/78 return path.join(path.resolve(configFilePath)); } /* * default to Wist project path since it's unlikely that plugins will be * in this directory */ return path.join(projectPath); }
javascript
function getBaseDir(configFilePath) { // calculates the path of the project including Wist as dependency const projectPath = path.resolve(__dirname, '../../../'); if (configFilePath && pathIsInside(configFilePath, projectPath)) { // be careful of https://github.com/substack/node-resolve/issues/78 return path.join(path.resolve(configFilePath)); } /* * default to Wist project path since it's unlikely that plugins will be * in this directory */ return path.join(projectPath); }
[ "function", "getBaseDir", "(", "configFilePath", ")", "{", "// calculates the path of the project including Wist as dependency", "const", "projectPath", "=", "path", ".", "resolve", "(", "__dirname", ",", "'../../../'", ")", ";", "if", "(", "configFilePath", "&&", "pathIsInside", "(", "configFilePath", ",", "projectPath", ")", ")", "{", "// be careful of https://github.com/substack/node-resolve/issues/78", "return", "path", ".", "join", "(", "path", ".", "resolve", "(", "configFilePath", ")", ")", ";", "}", "/*\n * default to Wist project path since it's unlikely that plugins will be\n * in this directory\n */", "return", "path", ".", "join", "(", "projectPath", ")", ";", "}" ]
Determines the base directory for node packages referenced in a config file. This does not include node_modules in the path so it can be used for all references relative to a config file. @param {string} configFilePath The config file referencing the file. @returns {string} The base directory for the file path. @private
[ "Determines", "the", "base", "directory", "for", "node", "packages", "referenced", "in", "a", "config", "file", ".", "This", "does", "not", "include", "node_modules", "in", "the", "path", "so", "it", "can", "be", "used", "for", "all", "references", "relative", "to", "a", "config", "file", "." ]
c456c98f2af3fc59c53b2f8495d4f13d41eb9e0e
https://github.com/willowtreeapps/wist/blob/c456c98f2af3fc59c53b2f8495d4f13d41eb9e0e/src/js/config/config-file.js#L131-L147
17,818
willowtreeapps/wist
src/js/cli.js
handleInitialize
function handleInitialize(currentOptions) { const recommendedFilePath = path.resolve(__dirname, '../../config/wist-recommended.json'); let result = 0; if (currentOptions.config) { result = handleConfiguration(currentOptions.config); } else { result = handleConfiguration(recommendedFilePath); } return result }
javascript
function handleInitialize(currentOptions) { const recommendedFilePath = path.resolve(__dirname, '../../config/wist-recommended.json'); let result = 0; if (currentOptions.config) { result = handleConfiguration(currentOptions.config); } else { result = handleConfiguration(recommendedFilePath); } return result }
[ "function", "handleInitialize", "(", "currentOptions", ")", "{", "const", "recommendedFilePath", "=", "path", ".", "resolve", "(", "__dirname", ",", "'../../config/wist-recommended.json'", ")", ";", "let", "result", "=", "0", ";", "if", "(", "currentOptions", ".", "config", ")", "{", "result", "=", "handleConfiguration", "(", "currentOptions", ".", "config", ")", ";", "}", "else", "{", "result", "=", "handleConfiguration", "(", "recommendedFilePath", ")", ";", "}", "return", "result", "}" ]
Creates the .wistrc.json file in the default location if a configuration path is not specified. @param currentOptions Command lines arguments input by user. @returns {boolean} True if the initialization succeeds, false if not. @private
[ "Creates", "the", ".", "wistrc", ".", "json", "file", "in", "the", "default", "location", "if", "a", "configuration", "path", "is", "not", "specified", "." ]
c456c98f2af3fc59c53b2f8495d4f13d41eb9e0e
https://github.com/willowtreeapps/wist/blob/c456c98f2af3fc59c53b2f8495d4f13d41eb9e0e/src/js/cli.js#L81-L90
17,819
willowtreeapps/wist
src/js/cli.js
handleConfiguration
function handleConfiguration(filePath) { if (fs.existsSync(filePath)) { filePath = path.resolve(filePath); } else { console.error('Invalid path to configuration file.'); return 1; } return setupConfigurationFile(filePath); }
javascript
function handleConfiguration(filePath) { if (fs.existsSync(filePath)) { filePath = path.resolve(filePath); } else { console.error('Invalid path to configuration file.'); return 1; } return setupConfigurationFile(filePath); }
[ "function", "handleConfiguration", "(", "filePath", ")", "{", "if", "(", "fs", ".", "existsSync", "(", "filePath", ")", ")", "{", "filePath", "=", "path", ".", "resolve", "(", "filePath", ")", ";", "}", "else", "{", "console", ".", "error", "(", "'Invalid path to configuration file.'", ")", ";", "return", "1", ";", "}", "return", "setupConfigurationFile", "(", "filePath", ")", ";", "}" ]
Creates the .wistrc.json file from the user-defined configuration file. @param filePath Path to the user-defined configuration file. @returns {boolean} True if the creation of the configuration file succeeds, false if not. @private
[ "Creates", "the", ".", "wistrc", ".", "json", "file", "from", "the", "user", "-", "defined", "configuration", "file", "." ]
c456c98f2af3fc59c53b2f8495d4f13d41eb9e0e
https://github.com/willowtreeapps/wist/blob/c456c98f2af3fc59c53b2f8495d4f13d41eb9e0e/src/js/cli.js#L98-L107
17,820
willowtreeapps/wist
src/js/cli.js
setupConfigurationFile
function setupConfigurationFile(configFilePath) { const fileName = '.wistrc.json'; try { let contents = require(configFilePath); fs.writeFileSync(fileName, JSON.stringify(contents, null, 2)); log.info(`Initialized directory with a ${fileName}`) } catch (e) { console.error(e.message); return 1; } return 0; }
javascript
function setupConfigurationFile(configFilePath) { const fileName = '.wistrc.json'; try { let contents = require(configFilePath); fs.writeFileSync(fileName, JSON.stringify(contents, null, 2)); log.info(`Initialized directory with a ${fileName}`) } catch (e) { console.error(e.message); return 1; } return 0; }
[ "function", "setupConfigurationFile", "(", "configFilePath", ")", "{", "const", "fileName", "=", "'.wistrc.json'", ";", "try", "{", "let", "contents", "=", "require", "(", "configFilePath", ")", ";", "fs", ".", "writeFileSync", "(", "fileName", ",", "JSON", ".", "stringify", "(", "contents", ",", "null", ",", "2", ")", ")", ";", "log", ".", "info", "(", "`", "${", "fileName", "}", "`", ")", "}", "catch", "(", "e", ")", "{", "console", ".", "error", "(", "e", ".", "message", ")", ";", "return", "1", ";", "}", "return", "0", ";", "}" ]
Creates the .wistrc.json file from the contents of the specified file. @param configFilePath Path to the configuration file. @returns {boolean} True if the creation of the configuration file succeeds, false if not. @private
[ "Creates", "the", ".", "wistrc", ".", "json", "file", "from", "the", "contents", "of", "the", "specified", "file", "." ]
c456c98f2af3fc59c53b2f8495d4f13d41eb9e0e
https://github.com/willowtreeapps/wist/blob/c456c98f2af3fc59c53b2f8495d4f13d41eb9e0e/src/js/cli.js#L115-L127
17,821
willowtreeapps/wist
src/js/config/config-ops.js
deepmerge
function deepmerge(target, src, combine, isRule) { /* The MIT License (MIT) Copyright (c) 2012 Nicholas Fisher Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /* * This code is taken from deepmerge repo * (https://github.com/KyleAMathews/deepmerge) * and modified to meet our needs. */ const array = Array.isArray(src) || Array.isArray(target); let dst = array && [] || {}; combine = !!combine; isRule = !!isRule; if (array) { target = target || []; // src could be a string, so check for array if (isRule && Array.isArray(src) && src.length > 1) { dst = dst.concat(src); } else { dst = dst.concat(target); } if (typeof src !== 'object' && !Array.isArray(src)) { src = [src]; } Object.keys(src).forEach((e, i) => { e = src[i]; if (typeof dst[i] === 'undefined') { dst[i] = e; } else if (typeof e === 'object') { if (isRule) { dst[i] = e; } else { dst[i] = deepmerge(target[i], e, combine, isRule); } } else { if (!combine) { dst[i] = e; } else { if (dst.indexOf(e) === -1) { dst.push(e); } } } }); } else { if (target && typeof target === 'object') { Object.keys(target).forEach(key => { dst[key] = target[key]; }); } Object.keys(src).forEach(key => { if (key === 'overrides') { dst[key] = (target[key] || []).concat(src[key] || []); } else if (Array.isArray(src[key]) || Array.isArray(target[key])) { dst[key] = deepmerge(target[key], src[key], key === 'plugins' || key === 'extends', isRule); } else if (typeof src[key] !== 'object' || !src[key] || key === 'exported' || key === 'astGlobals') { dst[key] = src[key]; } else { dst[key] = deepmerge(target[key] || {}, src[key], combine, key === 'rules'); } }); } return dst; }
javascript
function deepmerge(target, src, combine, isRule) { /* The MIT License (MIT) Copyright (c) 2012 Nicholas Fisher Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /* * This code is taken from deepmerge repo * (https://github.com/KyleAMathews/deepmerge) * and modified to meet our needs. */ const array = Array.isArray(src) || Array.isArray(target); let dst = array && [] || {}; combine = !!combine; isRule = !!isRule; if (array) { target = target || []; // src could be a string, so check for array if (isRule && Array.isArray(src) && src.length > 1) { dst = dst.concat(src); } else { dst = dst.concat(target); } if (typeof src !== 'object' && !Array.isArray(src)) { src = [src]; } Object.keys(src).forEach((e, i) => { e = src[i]; if (typeof dst[i] === 'undefined') { dst[i] = e; } else if (typeof e === 'object') { if (isRule) { dst[i] = e; } else { dst[i] = deepmerge(target[i], e, combine, isRule); } } else { if (!combine) { dst[i] = e; } else { if (dst.indexOf(e) === -1) { dst.push(e); } } } }); } else { if (target && typeof target === 'object') { Object.keys(target).forEach(key => { dst[key] = target[key]; }); } Object.keys(src).forEach(key => { if (key === 'overrides') { dst[key] = (target[key] || []).concat(src[key] || []); } else if (Array.isArray(src[key]) || Array.isArray(target[key])) { dst[key] = deepmerge(target[key], src[key], key === 'plugins' || key === 'extends', isRule); } else if (typeof src[key] !== 'object' || !src[key] || key === 'exported' || key === 'astGlobals') { dst[key] = src[key]; } else { dst[key] = deepmerge(target[key] || {}, src[key], combine, key === 'rules'); } }); } return dst; }
[ "function", "deepmerge", "(", "target", ",", "src", ",", "combine", ",", "isRule", ")", "{", "/*\n The MIT License (MIT)\n\n Copyright (c) 2012 Nicholas Fisher\n\n Permission is hereby granted, free of charge, to any person obtaining a copy\n of this software and associated documentation files (the 'Software'), to deal\n in the Software without restriction, including without limitation the rights\n to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n copies of the Software, and to permit persons to whom the Software is\n furnished to do so, subject to the following conditions:\n\n The above copyright notice and this permission notice shall be included in\n all copies or substantial portions of the Software.\n\n THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n THE SOFTWARE.\n */", "/*\n * This code is taken from deepmerge repo\n * (https://github.com/KyleAMathews/deepmerge)\n * and modified to meet our needs.\n */", "const", "array", "=", "Array", ".", "isArray", "(", "src", ")", "||", "Array", ".", "isArray", "(", "target", ")", ";", "let", "dst", "=", "array", "&&", "[", "]", "||", "{", "}", ";", "combine", "=", "!", "!", "combine", ";", "isRule", "=", "!", "!", "isRule", ";", "if", "(", "array", ")", "{", "target", "=", "target", "||", "[", "]", ";", "// src could be a string, so check for array", "if", "(", "isRule", "&&", "Array", ".", "isArray", "(", "src", ")", "&&", "src", ".", "length", ">", "1", ")", "{", "dst", "=", "dst", ".", "concat", "(", "src", ")", ";", "}", "else", "{", "dst", "=", "dst", ".", "concat", "(", "target", ")", ";", "}", "if", "(", "typeof", "src", "!==", "'object'", "&&", "!", "Array", ".", "isArray", "(", "src", ")", ")", "{", "src", "=", "[", "src", "]", ";", "}", "Object", ".", "keys", "(", "src", ")", ".", "forEach", "(", "(", "e", ",", "i", ")", "=>", "{", "e", "=", "src", "[", "i", "]", ";", "if", "(", "typeof", "dst", "[", "i", "]", "===", "'undefined'", ")", "{", "dst", "[", "i", "]", "=", "e", ";", "}", "else", "if", "(", "typeof", "e", "===", "'object'", ")", "{", "if", "(", "isRule", ")", "{", "dst", "[", "i", "]", "=", "e", ";", "}", "else", "{", "dst", "[", "i", "]", "=", "deepmerge", "(", "target", "[", "i", "]", ",", "e", ",", "combine", ",", "isRule", ")", ";", "}", "}", "else", "{", "if", "(", "!", "combine", ")", "{", "dst", "[", "i", "]", "=", "e", ";", "}", "else", "{", "if", "(", "dst", ".", "indexOf", "(", "e", ")", "===", "-", "1", ")", "{", "dst", ".", "push", "(", "e", ")", ";", "}", "}", "}", "}", ")", ";", "}", "else", "{", "if", "(", "target", "&&", "typeof", "target", "===", "'object'", ")", "{", "Object", ".", "keys", "(", "target", ")", ".", "forEach", "(", "key", "=>", "{", "dst", "[", "key", "]", "=", "target", "[", "key", "]", ";", "}", ")", ";", "}", "Object", ".", "keys", "(", "src", ")", ".", "forEach", "(", "key", "=>", "{", "if", "(", "key", "===", "'overrides'", ")", "{", "dst", "[", "key", "]", "=", "(", "target", "[", "key", "]", "||", "[", "]", ")", ".", "concat", "(", "src", "[", "key", "]", "||", "[", "]", ")", ";", "}", "else", "if", "(", "Array", ".", "isArray", "(", "src", "[", "key", "]", ")", "||", "Array", ".", "isArray", "(", "target", "[", "key", "]", ")", ")", "{", "dst", "[", "key", "]", "=", "deepmerge", "(", "target", "[", "key", "]", ",", "src", "[", "key", "]", ",", "key", "===", "'plugins'", "||", "key", "===", "'extends'", ",", "isRule", ")", ";", "}", "else", "if", "(", "typeof", "src", "[", "key", "]", "!==", "'object'", "||", "!", "src", "[", "key", "]", "||", "key", "===", "'exported'", "||", "key", "===", "'astGlobals'", ")", "{", "dst", "[", "key", "]", "=", "src", "[", "key", "]", ";", "}", "else", "{", "dst", "[", "key", "]", "=", "deepmerge", "(", "target", "[", "key", "]", "||", "{", "}", ",", "src", "[", "key", "]", ",", "combine", ",", "key", "===", "'rules'", ")", ";", "}", "}", ")", ";", "}", "return", "dst", ";", "}" ]
Merges two config objects. This will not only add missing keys, but will also modify values to match. @param {Object} target config object @param {Object} src config object. Overrides in this config object will take priority over base. @param {boolean} [combine] Whether to combine arrays or not @param {boolean} [isRule] Whether its a rule @returns {Object} merged config object.
[ "Merges", "two", "config", "objects", ".", "This", "will", "not", "only", "add", "missing", "keys", "but", "will", "also", "modify", "values", "to", "match", "." ]
c456c98f2af3fc59c53b2f8495d4f13d41eb9e0e
https://github.com/willowtreeapps/wist/blob/c456c98f2af3fc59c53b2f8495d4f13d41eb9e0e/src/js/config/config-ops.js#L95-L194
17,822
WebReflection/viperHTML
index.js
createAsync
function createAsync() { var wired = new Async, wire = render.bind(wired), chunksReceiver ; wired.update = function () { this.callback = chunksReceiver; return chunks.apply(this, arguments); }; return function (callback) { chunksReceiver = callback || String; return wire; }; }
javascript
function createAsync() { var wired = new Async, wire = render.bind(wired), chunksReceiver ; wired.update = function () { this.callback = chunksReceiver; return chunks.apply(this, arguments); }; return function (callback) { chunksReceiver = callback || String; return wire; }; }
[ "function", "createAsync", "(", ")", "{", "var", "wired", "=", "new", "Async", ",", "wire", "=", "render", ".", "bind", "(", "wired", ")", ",", "chunksReceiver", ";", "wired", ".", "update", "=", "function", "(", ")", "{", "this", ".", "callback", "=", "chunksReceiver", ";", "return", "chunks", ".", "apply", "(", "this", ",", "arguments", ")", ";", "}", ";", "return", "function", "(", "callback", ")", "{", "chunksReceiver", "=", "callback", "||", "String", ";", "return", "wire", ";", "}", ";", "}" ]
instrument a wire to work asynchronously passing along an optional resolved chunks interceptor callback
[ "instrument", "a", "wire", "to", "work", "asynchronously", "passing", "along", "an", "optional", "resolved", "chunks", "interceptor", "callback" ]
7dbdd3951b88d3b315e0a4a01608f36d0fc83795
https://github.com/WebReflection/viperHTML/blob/7dbdd3951b88d3b315e0a4a01608f36d0fc83795/index.js#L92-L106
17,823
WebReflection/viperHTML
index.js
fixUpdates
function fixUpdates(updates) { for (var update, i = 0, length = updates.length, out = []; i < length; i++ ) { update = updates[i]; out.push(update === getUpdateForHTML ? update.call(this) : update); } return out; }
javascript
function fixUpdates(updates) { for (var update, i = 0, length = updates.length, out = []; i < length; i++ ) { update = updates[i]; out.push(update === getUpdateForHTML ? update.call(this) : update); } return out; }
[ "function", "fixUpdates", "(", "updates", ")", "{", "for", "(", "var", "update", ",", "i", "=", "0", ",", "length", "=", "updates", ".", "length", ",", "out", "=", "[", "]", ";", "i", "<", "length", ";", "i", "++", ")", "{", "update", "=", "updates", "[", "i", "]", ";", "out", ".", "push", "(", "update", "===", "getUpdateForHTML", "?", "update", ".", "call", "(", "this", ")", ":", "update", ")", ";", "}", "return", "out", ";", "}" ]
given a list of updates create a copy with the right update for HTML
[ "given", "a", "list", "of", "updates", "create", "a", "copy", "with", "the", "right", "update", "for", "HTML" ]
7dbdd3951b88d3b315e0a4a01608f36d0fc83795
https://github.com/WebReflection/viperHTML/blob/7dbdd3951b88d3b315e0a4a01608f36d0fc83795/index.js#L120-L132
17,824
WebReflection/viperHTML
index.js
invokeAtDistance
function invokeAtDistance(value, asTPV) { var after = asTPV ? asTemplateValue : identity; if ('text' in value) { return Promise.resolve(value.text).then(String).then(after); } else if ('any' in value) { return Promise.resolve(value.any).then(after); } else if ('html' in value) { return Promise.resolve(value.html).then(asHTML).then(after); } else { return Promise.resolve(invokeTransformer(value)).then(after); } }
javascript
function invokeAtDistance(value, asTPV) { var after = asTPV ? asTemplateValue : identity; if ('text' in value) { return Promise.resolve(value.text).then(String).then(after); } else if ('any' in value) { return Promise.resolve(value.any).then(after); } else if ('html' in value) { return Promise.resolve(value.html).then(asHTML).then(after); } else { return Promise.resolve(invokeTransformer(value)).then(after); } }
[ "function", "invokeAtDistance", "(", "value", ",", "asTPV", ")", "{", "var", "after", "=", "asTPV", "?", "asTemplateValue", ":", "identity", ";", "if", "(", "'text'", "in", "value", ")", "{", "return", "Promise", ".", "resolve", "(", "value", ".", "text", ")", ".", "then", "(", "String", ")", ".", "then", "(", "after", ")", ";", "}", "else", "if", "(", "'any'", "in", "value", ")", "{", "return", "Promise", ".", "resolve", "(", "value", ".", "any", ")", ".", "then", "(", "after", ")", ";", "}", "else", "if", "(", "'html'", "in", "value", ")", "{", "return", "Promise", ".", "resolve", "(", "value", ".", "html", ")", ".", "then", "(", "asHTML", ")", ".", "then", "(", "after", ")", ";", "}", "else", "{", "return", "Promise", ".", "resolve", "(", "invokeTransformer", "(", "value", ")", ")", ".", "then", "(", "after", ")", ";", "}", "}" ]
use a placeholder and resolve with the right callback
[ "use", "a", "placeholder", "and", "resolve", "with", "the", "right", "callback" ]
7dbdd3951b88d3b315e0a4a01608f36d0fc83795
https://github.com/WebReflection/viperHTML/blob/7dbdd3951b88d3b315e0a4a01608f36d0fc83795/index.js#L146-L157
17,825
WebReflection/viperHTML
index.js
invokeTransformer
function invokeTransformer(object) { for (var key, i = 0, length = transformersKeys.length; i < length; i++) { key = transformersKeys[i]; if (object.hasOwnProperty(key)) { // noop is passed to respect hyperHTML API but it won't have // any effect at distance for the time being return transformers[key](object[key], noop); } } }
javascript
function invokeTransformer(object) { for (var key, i = 0, length = transformersKeys.length; i < length; i++) { key = transformersKeys[i]; if (object.hasOwnProperty(key)) { // noop is passed to respect hyperHTML API but it won't have // any effect at distance for the time being return transformers[key](object[key], noop); } } }
[ "function", "invokeTransformer", "(", "object", ")", "{", "for", "(", "var", "key", ",", "i", "=", "0", ",", "length", "=", "transformersKeys", ".", "length", ";", "i", "<", "length", ";", "i", "++", ")", "{", "key", "=", "transformersKeys", "[", "i", "]", ";", "if", "(", "object", ".", "hasOwnProperty", "(", "key", ")", ")", "{", "// noop is passed to respect hyperHTML API but it won't have", "// any effect at distance for the time being", "return", "transformers", "[", "key", "]", "(", "object", "[", "key", "]", ",", "noop", ")", ";", "}", "}", "}" ]
last attempt to transform content
[ "last", "attempt", "to", "transform", "content" ]
7dbdd3951b88d3b315e0a4a01608f36d0fc83795
https://github.com/WebReflection/viperHTML/blob/7dbdd3951b88d3b315e0a4a01608f36d0fc83795/index.js#L160-L169
17,826
WebReflection/viperHTML
index.js
asTemplateValue
function asTemplateValue(value, isAttribute) { var presuf = isAttribute ? '' : createHyperComment(); switch(typeof value) { case 'string': return presuf + escape(value) + presuf; case 'boolean': case 'number': return presuf + value + presuf; case 'function': return asTemplateValue(value({}), isAttribute); case 'object': if (value instanceof Buffer) return presuf + value + presuf; if (value instanceof Component) return asTemplateValue(value.render(), isAttribute); case 'undefined': if (value == null) return presuf + '' + presuf; default: if (isArray(value)) { for (var i = 0, length = value.length; i < length; i++) { if (value[i] instanceof Component) { value[i] = value[i].render(); } } return presuf + value.join('') + presuf; } if ('placeholder' in value) return invokeAtDistance(value, true); if ('text' in value) return presuf + escape(value.text) + presuf; if ('any' in value) return asTemplateValue(value.any, isAttribute); if ('html' in value) return presuf + [].concat(value.html).join('') + presuf; return asTemplateValue(invokeTransformer(value), isAttribute); } }
javascript
function asTemplateValue(value, isAttribute) { var presuf = isAttribute ? '' : createHyperComment(); switch(typeof value) { case 'string': return presuf + escape(value) + presuf; case 'boolean': case 'number': return presuf + value + presuf; case 'function': return asTemplateValue(value({}), isAttribute); case 'object': if (value instanceof Buffer) return presuf + value + presuf; if (value instanceof Component) return asTemplateValue(value.render(), isAttribute); case 'undefined': if (value == null) return presuf + '' + presuf; default: if (isArray(value)) { for (var i = 0, length = value.length; i < length; i++) { if (value[i] instanceof Component) { value[i] = value[i].render(); } } return presuf + value.join('') + presuf; } if ('placeholder' in value) return invokeAtDistance(value, true); if ('text' in value) return presuf + escape(value.text) + presuf; if ('any' in value) return asTemplateValue(value.any, isAttribute); if ('html' in value) return presuf + [].concat(value.html).join('') + presuf; return asTemplateValue(invokeTransformer(value), isAttribute); } }
[ "function", "asTemplateValue", "(", "value", ",", "isAttribute", ")", "{", "var", "presuf", "=", "isAttribute", "?", "''", ":", "createHyperComment", "(", ")", ";", "switch", "(", "typeof", "value", ")", "{", "case", "'string'", ":", "return", "presuf", "+", "escape", "(", "value", ")", "+", "presuf", ";", "case", "'boolean'", ":", "case", "'number'", ":", "return", "presuf", "+", "value", "+", "presuf", ";", "case", "'function'", ":", "return", "asTemplateValue", "(", "value", "(", "{", "}", ")", ",", "isAttribute", ")", ";", "case", "'object'", ":", "if", "(", "value", "instanceof", "Buffer", ")", "return", "presuf", "+", "value", "+", "presuf", ";", "if", "(", "value", "instanceof", "Component", ")", "return", "asTemplateValue", "(", "value", ".", "render", "(", ")", ",", "isAttribute", ")", ";", "case", "'undefined'", ":", "if", "(", "value", "==", "null", ")", "return", "presuf", "+", "''", "+", "presuf", ";", "default", ":", "if", "(", "isArray", "(", "value", ")", ")", "{", "for", "(", "var", "i", "=", "0", ",", "length", "=", "value", ".", "length", ";", "i", "<", "length", ";", "i", "++", ")", "{", "if", "(", "value", "[", "i", "]", "instanceof", "Component", ")", "{", "value", "[", "i", "]", "=", "value", "[", "i", "]", ".", "render", "(", ")", ";", "}", "}", "return", "presuf", "+", "value", ".", "join", "(", "''", ")", "+", "presuf", ";", "}", "if", "(", "'placeholder'", "in", "value", ")", "return", "invokeAtDistance", "(", "value", ",", "true", ")", ";", "if", "(", "'text'", "in", "value", ")", "return", "presuf", "+", "escape", "(", "value", ".", "text", ")", "+", "presuf", ";", "if", "(", "'any'", "in", "value", ")", "return", "asTemplateValue", "(", "value", ".", "any", ",", "isAttribute", ")", ";", "if", "(", "'html'", "in", "value", ")", "return", "presuf", "+", "[", "]", ".", "concat", "(", "value", ".", "html", ")", ".", "join", "(", "''", ")", "+", "presuf", ";", "return", "asTemplateValue", "(", "invokeTransformer", "(", "value", ")", ",", "isAttribute", ")", ";", "}", "}" ]
multiple content joined as single string
[ "multiple", "content", "joined", "as", "single", "string" ]
7dbdd3951b88d3b315e0a4a01608f36d0fc83795
https://github.com/WebReflection/viperHTML/blob/7dbdd3951b88d3b315e0a4a01608f36d0fc83795/index.js#L175-L202
17,827
WebReflection/viperHTML
index.js
updateBoolean
function updateBoolean(name) { name = ' ' + name; function update(value) { switch (value) { case true: case 'true': return name; } return ''; } update[UID] = true; return update; }
javascript
function updateBoolean(name) { name = ' ' + name; function update(value) { switch (value) { case true: case 'true': return name; } return ''; } update[UID] = true; return update; }
[ "function", "updateBoolean", "(", "name", ")", "{", "name", "=", "' '", "+", "name", ";", "function", "update", "(", "value", ")", "{", "switch", "(", "value", ")", "{", "case", "true", ":", "case", "'true'", ":", "return", "name", ";", "}", "return", "''", ";", "}", "update", "[", "UID", "]", "=", "true", ";", "return", "update", ";", "}" ]
return the right callback to update a boolean attribute after modifying the template to ignore such attribute if falsy
[ "return", "the", "right", "callback", "to", "update", "a", "boolean", "attribute", "after", "modifying", "the", "template", "to", "ignore", "such", "attribute", "if", "falsy" ]
7dbdd3951b88d3b315e0a4a01608f36d0fc83795
https://github.com/WebReflection/viperHTML/blob/7dbdd3951b88d3b315e0a4a01608f36d0fc83795/index.js#L339-L351
17,828
WebReflection/viperHTML
index.js
updateEvent
function updateEvent(value) { switch (typeof value) { case 'function': return 'return (' + escape( JS_SHORTCUT.test(value) && !JS_FUNCTION.test(value) ? ('function ' + value) : value ) + ').call(this, event)'; case 'object': return ''; default: return escape(value || ''); } }
javascript
function updateEvent(value) { switch (typeof value) { case 'function': return 'return (' + escape( JS_SHORTCUT.test(value) && !JS_FUNCTION.test(value) ? ('function ' + value) : value ) + ').call(this, event)'; case 'object': return ''; default: return escape(value || ''); } }
[ "function", "updateEvent", "(", "value", ")", "{", "switch", "(", "typeof", "value", ")", "{", "case", "'function'", ":", "return", "'return ('", "+", "escape", "(", "JS_SHORTCUT", ".", "test", "(", "value", ")", "&&", "!", "JS_FUNCTION", ".", "test", "(", "value", ")", "?", "(", "'function '", "+", "value", ")", ":", "value", ")", "+", "').call(this, event)'", ";", "case", "'object'", ":", "return", "''", ";", "default", ":", "return", "escape", "(", "value", "||", "''", ")", ";", "}", "}" ]
return the right callback to invoke an event stringifying the callback and invoking it to simulate a proper DOM behavior
[ "return", "the", "right", "callback", "to", "invoke", "an", "event", "stringifying", "the", "callback", "and", "invoking", "it", "to", "simulate", "a", "proper", "DOM", "behavior" ]
7dbdd3951b88d3b315e0a4a01608f36d0fc83795
https://github.com/WebReflection/viperHTML/blob/7dbdd3951b88d3b315e0a4a01608f36d0fc83795/index.js#L387-L397
17,829
WebReflection/viperHTML
index.js
chunks
function chunks() { for (var update, out = [], updates = this.updates, template = this.chunks, callback = this.callback, all = Promise.resolve(template[0]), chain = function (after) { return all.then(function (through) { notify(through); return after; }); }, getSubValue = function (value) { if (isArray(value)) { value.forEach(getSubValue); } else { all = chain( Promise.resolve(value) .then(resolveArray) ); } }, getValue = function (value) { if (isArray(value)) { var hc = Promise.resolve(createHyperComment()); all = chain(hc); value.forEach(getSubValue); all = chain(hc); } else { all = chain( Promise.resolve(value) .then(resolveAsTemplateValue(update)) .then(update === asTemplateValue ? identity : update) ); } }, notify = function (chunk) { out.push(chunk); callback(chunk); }, i = 1, length = arguments.length; i < length; i++ ) { update = updates[i - 1]; getValue(arguments[i]); all = chain(template[i]); } return all.then(notify).then(function () { return out; }); }
javascript
function chunks() { for (var update, out = [], updates = this.updates, template = this.chunks, callback = this.callback, all = Promise.resolve(template[0]), chain = function (after) { return all.then(function (through) { notify(through); return after; }); }, getSubValue = function (value) { if (isArray(value)) { value.forEach(getSubValue); } else { all = chain( Promise.resolve(value) .then(resolveArray) ); } }, getValue = function (value) { if (isArray(value)) { var hc = Promise.resolve(createHyperComment()); all = chain(hc); value.forEach(getSubValue); all = chain(hc); } else { all = chain( Promise.resolve(value) .then(resolveAsTemplateValue(update)) .then(update === asTemplateValue ? identity : update) ); } }, notify = function (chunk) { out.push(chunk); callback(chunk); }, i = 1, length = arguments.length; i < length; i++ ) { update = updates[i - 1]; getValue(arguments[i]); all = chain(template[i]); } return all.then(notify).then(function () { return out; }); }
[ "function", "chunks", "(", ")", "{", "for", "(", "var", "update", ",", "out", "=", "[", "]", ",", "updates", "=", "this", ".", "updates", ",", "template", "=", "this", ".", "chunks", ",", "callback", "=", "this", ".", "callback", ",", "all", "=", "Promise", ".", "resolve", "(", "template", "[", "0", "]", ")", ",", "chain", "=", "function", "(", "after", ")", "{", "return", "all", ".", "then", "(", "function", "(", "through", ")", "{", "notify", "(", "through", ")", ";", "return", "after", ";", "}", ")", ";", "}", ",", "getSubValue", "=", "function", "(", "value", ")", "{", "if", "(", "isArray", "(", "value", ")", ")", "{", "value", ".", "forEach", "(", "getSubValue", ")", ";", "}", "else", "{", "all", "=", "chain", "(", "Promise", ".", "resolve", "(", "value", ")", ".", "then", "(", "resolveArray", ")", ")", ";", "}", "}", ",", "getValue", "=", "function", "(", "value", ")", "{", "if", "(", "isArray", "(", "value", ")", ")", "{", "var", "hc", "=", "Promise", ".", "resolve", "(", "createHyperComment", "(", ")", ")", ";", "all", "=", "chain", "(", "hc", ")", ";", "value", ".", "forEach", "(", "getSubValue", ")", ";", "all", "=", "chain", "(", "hc", ")", ";", "}", "else", "{", "all", "=", "chain", "(", "Promise", ".", "resolve", "(", "value", ")", ".", "then", "(", "resolveAsTemplateValue", "(", "update", ")", ")", ".", "then", "(", "update", "===", "asTemplateValue", "?", "identity", ":", "update", ")", ")", ";", "}", "}", ",", "notify", "=", "function", "(", "chunk", ")", "{", "out", ".", "push", "(", "chunk", ")", ";", "callback", "(", "chunk", ")", ";", "}", ",", "i", "=", "1", ",", "length", "=", "arguments", ".", "length", ";", "i", "<", "length", ";", "i", "++", ")", "{", "update", "=", "updates", "[", "i", "-", "1", "]", ";", "getValue", "(", "arguments", "[", "i", "]", ")", ";", "all", "=", "chain", "(", "template", "[", "i", "]", ")", ";", "}", "return", "all", ".", "then", "(", "notify", ")", ".", "then", "(", "function", "(", ")", "{", "return", "out", ";", "}", ")", ";", "}" ]
resolves through promises and invoke a notifier per each resolved chunk the context will be a viper
[ "resolves", "through", "promises", "and", "invoke", "a", "notifier", "per", "each", "resolved", "chunk", "the", "context", "will", "be", "a", "viper" ]
7dbdd3951b88d3b315e0a4a01608f36d0fc83795
https://github.com/WebReflection/viperHTML/blob/7dbdd3951b88d3b315e0a4a01608f36d0fc83795/index.js#L422-L472
17,830
WebReflection/viperHTML
index.js
resolveAsTemplateValue
function resolveAsTemplateValue(update) { return function (value) { return asTemplateValue( value, update === updateAttribute || update === updateEvent || UID in update ); }; }
javascript
function resolveAsTemplateValue(update) { return function (value) { return asTemplateValue( value, update === updateAttribute || update === updateEvent || UID in update ); }; }
[ "function", "resolveAsTemplateValue", "(", "update", ")", "{", "return", "function", "(", "value", ")", "{", "return", "asTemplateValue", "(", "value", ",", "update", "===", "updateAttribute", "||", "update", "===", "updateEvent", "||", "UID", "in", "update", ")", ";", "}", ";", "}" ]
invokes at distance asTemplateValue passing the "isAttribute" flag
[ "invokes", "at", "distance", "asTemplateValue", "passing", "the", "isAttribute", "flag" ]
7dbdd3951b88d3b315e0a4a01608f36d0fc83795
https://github.com/WebReflection/viperHTML/blob/7dbdd3951b88d3b315e0a4a01608f36d0fc83795/index.js#L484-L493
17,831
WebReflection/viperHTML
index.js
update
function update() { for (var tmp, promise = false, updates = this.updates, template = this.chunks, out = [template[0]], i = 1, length = arguments.length; i < length; i++ ) { tmp = arguments[i]; if ( (typeof tmp === 'object' && tmp !== null) && (typeof tmp.then === 'function' || 'placeholder' in tmp) ) { promise = true; out.push( ('placeholder' in tmp ? invokeAtDistance(tmp, false) : tmp) .then(updates[i - 1]), template[i] ); } else { out.push(updates[i - 1](tmp), template[i]); } } return promise ? Promise.all(out).then(asBuffer) : asBuffer(out); }
javascript
function update() { for (var tmp, promise = false, updates = this.updates, template = this.chunks, out = [template[0]], i = 1, length = arguments.length; i < length; i++ ) { tmp = arguments[i]; if ( (typeof tmp === 'object' && tmp !== null) && (typeof tmp.then === 'function' || 'placeholder' in tmp) ) { promise = true; out.push( ('placeholder' in tmp ? invokeAtDistance(tmp, false) : tmp) .then(updates[i - 1]), template[i] ); } else { out.push(updates[i - 1](tmp), template[i]); } } return promise ? Promise.all(out).then(asBuffer) : asBuffer(out); }
[ "function", "update", "(", ")", "{", "for", "(", "var", "tmp", ",", "promise", "=", "false", ",", "updates", "=", "this", ".", "updates", ",", "template", "=", "this", ".", "chunks", ",", "out", "=", "[", "template", "[", "0", "]", "]", ",", "i", "=", "1", ",", "length", "=", "arguments", ".", "length", ";", "i", "<", "length", ";", "i", "++", ")", "{", "tmp", "=", "arguments", "[", "i", "]", ";", "if", "(", "(", "typeof", "tmp", "===", "'object'", "&&", "tmp", "!==", "null", ")", "&&", "(", "typeof", "tmp", ".", "then", "===", "'function'", "||", "'placeholder'", "in", "tmp", ")", ")", "{", "promise", "=", "true", ";", "out", ".", "push", "(", "(", "'placeholder'", "in", "tmp", "?", "invokeAtDistance", "(", "tmp", ",", "false", ")", ":", "tmp", ")", ".", "then", "(", "updates", "[", "i", "-", "1", "]", ")", ",", "template", "[", "i", "]", ")", ";", "}", "else", "{", "out", ".", "push", "(", "updates", "[", "i", "-", "1", "]", "(", "tmp", ")", ",", "template", "[", "i", "]", ")", ";", "}", "}", "return", "promise", "?", "Promise", ".", "all", "(", "out", ")", ".", "then", "(", "asBuffer", ")", ":", "asBuffer", "(", "out", ")", ";", "}" ]
each known viperHTML update is kept as simple as possible. the context will be a viper
[ "each", "known", "viperHTML", "update", "is", "kept", "as", "simple", "as", "possible", ".", "the", "context", "will", "be", "a", "viper" ]
7dbdd3951b88d3b315e0a4a01608f36d0fc83795
https://github.com/WebReflection/viperHTML/blob/7dbdd3951b88d3b315e0a4a01608f36d0fc83795/index.js#L498-L526
17,832
Autarc/optimal-select
src/match.js
checkAttributes
function checkAttributes (priority, element, ignore, path, parent = element.parentNode) { const pattern = findAttributesPattern(priority, element, ignore) if (pattern) { const matches = parent.querySelectorAll(pattern) if (matches.length === 1) { path.unshift(pattern) return true } } return false }
javascript
function checkAttributes (priority, element, ignore, path, parent = element.parentNode) { const pattern = findAttributesPattern(priority, element, ignore) if (pattern) { const matches = parent.querySelectorAll(pattern) if (matches.length === 1) { path.unshift(pattern) return true } } return false }
[ "function", "checkAttributes", "(", "priority", ",", "element", ",", "ignore", ",", "path", ",", "parent", "=", "element", ".", "parentNode", ")", "{", "const", "pattern", "=", "findAttributesPattern", "(", "priority", ",", "element", ",", "ignore", ")", "if", "(", "pattern", ")", "{", "const", "matches", "=", "parent", ".", "querySelectorAll", "(", "pattern", ")", "if", "(", "matches", ".", "length", "===", "1", ")", "{", "path", ".", "unshift", "(", "pattern", ")", "return", "true", "}", "}", "return", "false", "}" ]
Extend path with attribute identifier @param {Array.<string>} priority - [description] @param {HTMLElement} element - [description] @param {Object} ignore - [description] @param {Array.<string>} path - [description] @param {HTMLElement} parent - [description] @return {boolean} - [description]
[ "Extend", "path", "with", "attribute", "identifier" ]
722d220d2dc54d78121d610a69f6544c2e116721
https://github.com/Autarc/optimal-select/blob/722d220d2dc54d78121d610a69f6544c2e116721/src/match.js#L117-L127
17,833
Autarc/optimal-select
src/match.js
findAttributesPattern
function findAttributesPattern (priority, element, ignore) { const attributes = element.attributes const sortedKeys = Object.keys(attributes).sort((curr, next) => { const currPos = priority.indexOf(attributes[curr].name) const nextPos = priority.indexOf(attributes[next].name) if (nextPos === -1) { if (currPos === -1) { return 0 } return -1 } return currPos - nextPos }) for (var i = 0, l = sortedKeys.length; i < l; i++) { const key = sortedKeys[i] const attribute = attributes[key] const attributeName = attribute.name const attributeValue = escapeValue(attribute.value) const currentIgnore = ignore[attributeName] || ignore.attribute const currentDefaultIgnore = defaultIgnore[attributeName] || defaultIgnore.attribute if (checkIgnore(currentIgnore, attributeName, attributeValue, currentDefaultIgnore)) { continue } var pattern = `[${attributeName}="${attributeValue}"]` if ((/\b\d/).test(attributeValue) === false) { if (attributeName === 'id') { pattern = `#${attributeValue}` } if (attributeName === 'class') { const className = attributeValue.trim().replace(/\s+/g, '.') pattern = `.${className}` } } return pattern } return null }
javascript
function findAttributesPattern (priority, element, ignore) { const attributes = element.attributes const sortedKeys = Object.keys(attributes).sort((curr, next) => { const currPos = priority.indexOf(attributes[curr].name) const nextPos = priority.indexOf(attributes[next].name) if (nextPos === -1) { if (currPos === -1) { return 0 } return -1 } return currPos - nextPos }) for (var i = 0, l = sortedKeys.length; i < l; i++) { const key = sortedKeys[i] const attribute = attributes[key] const attributeName = attribute.name const attributeValue = escapeValue(attribute.value) const currentIgnore = ignore[attributeName] || ignore.attribute const currentDefaultIgnore = defaultIgnore[attributeName] || defaultIgnore.attribute if (checkIgnore(currentIgnore, attributeName, attributeValue, currentDefaultIgnore)) { continue } var pattern = `[${attributeName}="${attributeValue}"]` if ((/\b\d/).test(attributeValue) === false) { if (attributeName === 'id') { pattern = `#${attributeValue}` } if (attributeName === 'class') { const className = attributeValue.trim().replace(/\s+/g, '.') pattern = `.${className}` } } return pattern } return null }
[ "function", "findAttributesPattern", "(", "priority", ",", "element", ",", "ignore", ")", "{", "const", "attributes", "=", "element", ".", "attributes", "const", "sortedKeys", "=", "Object", ".", "keys", "(", "attributes", ")", ".", "sort", "(", "(", "curr", ",", "next", ")", "=>", "{", "const", "currPos", "=", "priority", ".", "indexOf", "(", "attributes", "[", "curr", "]", ".", "name", ")", "const", "nextPos", "=", "priority", ".", "indexOf", "(", "attributes", "[", "next", "]", ".", "name", ")", "if", "(", "nextPos", "===", "-", "1", ")", "{", "if", "(", "currPos", "===", "-", "1", ")", "{", "return", "0", "}", "return", "-", "1", "}", "return", "currPos", "-", "nextPos", "}", ")", "for", "(", "var", "i", "=", "0", ",", "l", "=", "sortedKeys", ".", "length", ";", "i", "<", "l", ";", "i", "++", ")", "{", "const", "key", "=", "sortedKeys", "[", "i", "]", "const", "attribute", "=", "attributes", "[", "key", "]", "const", "attributeName", "=", "attribute", ".", "name", "const", "attributeValue", "=", "escapeValue", "(", "attribute", ".", "value", ")", "const", "currentIgnore", "=", "ignore", "[", "attributeName", "]", "||", "ignore", ".", "attribute", "const", "currentDefaultIgnore", "=", "defaultIgnore", "[", "attributeName", "]", "||", "defaultIgnore", ".", "attribute", "if", "(", "checkIgnore", "(", "currentIgnore", ",", "attributeName", ",", "attributeValue", ",", "currentDefaultIgnore", ")", ")", "{", "continue", "}", "var", "pattern", "=", "`", "${", "attributeName", "}", "${", "attributeValue", "}", "`", "if", "(", "(", "/", "\\b\\d", "/", ")", ".", "test", "(", "attributeValue", ")", "===", "false", ")", "{", "if", "(", "attributeName", "===", "'id'", ")", "{", "pattern", "=", "`", "${", "attributeValue", "}", "`", "}", "if", "(", "attributeName", "===", "'class'", ")", "{", "const", "className", "=", "attributeValue", ".", "trim", "(", ")", ".", "replace", "(", "/", "\\s+", "/", "g", ",", "'.'", ")", "pattern", "=", "`", "${", "className", "}", "`", "}", "}", "return", "pattern", "}", "return", "null", "}" ]
Lookup attribute identifier @param {Array.<string>} priority - [description] @param {HTMLElement} element - [description] @param {Object} ignore - [description] @return {string?} - [description]
[ "Lookup", "attribute", "identifier" ]
722d220d2dc54d78121d610a69f6544c2e116721
https://github.com/Autarc/optimal-select/blob/722d220d2dc54d78121d610a69f6544c2e116721/src/match.js#L137-L179
17,834
Autarc/optimal-select
src/match.js
checkTag
function checkTag (element, ignore, path, parent = element.parentNode) { const pattern = findTagPattern(element, ignore) if (pattern) { const matches = parent.getElementsByTagName(pattern) if (matches.length === 1) { path.unshift(pattern) return true } } return false }
javascript
function checkTag (element, ignore, path, parent = element.parentNode) { const pattern = findTagPattern(element, ignore) if (pattern) { const matches = parent.getElementsByTagName(pattern) if (matches.length === 1) { path.unshift(pattern) return true } } return false }
[ "function", "checkTag", "(", "element", ",", "ignore", ",", "path", ",", "parent", "=", "element", ".", "parentNode", ")", "{", "const", "pattern", "=", "findTagPattern", "(", "element", ",", "ignore", ")", "if", "(", "pattern", ")", "{", "const", "matches", "=", "parent", ".", "getElementsByTagName", "(", "pattern", ")", "if", "(", "matches", ".", "length", "===", "1", ")", "{", "path", ".", "unshift", "(", "pattern", ")", "return", "true", "}", "}", "return", "false", "}" ]
Extend path with tag identifier @param {HTMLElement} element - [description] @param {Object} ignore - [description] @param {Array.<string>} path - [description] @param {HTMLElement} parent - [description] @return {boolean} - [description]
[ "Extend", "path", "with", "tag", "identifier" ]
722d220d2dc54d78121d610a69f6544c2e116721
https://github.com/Autarc/optimal-select/blob/722d220d2dc54d78121d610a69f6544c2e116721/src/match.js#L190-L200
17,835
Autarc/optimal-select
src/match.js
findTagPattern
function findTagPattern (element, ignore) { const tagName = element.tagName.toLowerCase() if (checkIgnore(ignore.tag, null, tagName)) { return null } return tagName }
javascript
function findTagPattern (element, ignore) { const tagName = element.tagName.toLowerCase() if (checkIgnore(ignore.tag, null, tagName)) { return null } return tagName }
[ "function", "findTagPattern", "(", "element", ",", "ignore", ")", "{", "const", "tagName", "=", "element", ".", "tagName", ".", "toLowerCase", "(", ")", "if", "(", "checkIgnore", "(", "ignore", ".", "tag", ",", "null", ",", "tagName", ")", ")", "{", "return", "null", "}", "return", "tagName", "}" ]
Lookup tag identifier @param {HTMLElement} element - [description] @param {Object} ignore - [description] @return {boolean} - [description]
[ "Lookup", "tag", "identifier" ]
722d220d2dc54d78121d610a69f6544c2e116721
https://github.com/Autarc/optimal-select/blob/722d220d2dc54d78121d610a69f6544c2e116721/src/match.js#L209-L215
17,836
Autarc/optimal-select
src/match.js
checkChilds
function checkChilds (priority, element, ignore, path) { const parent = element.parentNode const children = parent.childTags || parent.children for (var i = 0, l = children.length; i < l; i++) { const child = children[i] if (child === element) { const childPattern = findPattern(priority, child, ignore) if (!childPattern) { return console.warn(` Element couldn\'t be matched through strict ignore pattern! `, child, ignore, childPattern) } const pattern = `> ${childPattern}:nth-child(${i+1})` path.unshift(pattern) return true } } return false }
javascript
function checkChilds (priority, element, ignore, path) { const parent = element.parentNode const children = parent.childTags || parent.children for (var i = 0, l = children.length; i < l; i++) { const child = children[i] if (child === element) { const childPattern = findPattern(priority, child, ignore) if (!childPattern) { return console.warn(` Element couldn\'t be matched through strict ignore pattern! `, child, ignore, childPattern) } const pattern = `> ${childPattern}:nth-child(${i+1})` path.unshift(pattern) return true } } return false }
[ "function", "checkChilds", "(", "priority", ",", "element", ",", "ignore", ",", "path", ")", "{", "const", "parent", "=", "element", ".", "parentNode", "const", "children", "=", "parent", ".", "childTags", "||", "parent", ".", "children", "for", "(", "var", "i", "=", "0", ",", "l", "=", "children", ".", "length", ";", "i", "<", "l", ";", "i", "++", ")", "{", "const", "child", "=", "children", "[", "i", "]", "if", "(", "child", "===", "element", ")", "{", "const", "childPattern", "=", "findPattern", "(", "priority", ",", "child", ",", "ignore", ")", "if", "(", "!", "childPattern", ")", "{", "return", "console", ".", "warn", "(", "`", "\\'", "`", ",", "child", ",", "ignore", ",", "childPattern", ")", "}", "const", "pattern", "=", "`", "${", "childPattern", "}", "${", "i", "+", "1", "}", "`", "path", ".", "unshift", "(", "pattern", ")", "return", "true", "}", "}", "return", "false", "}" ]
Extend path with specific child identifier NOTE: 'childTags' is a custom property to use as a view filter for tags using 'adapter.js' @param {Array.<string>} priority - [description] @param {HTMLElement} element - [description] @param {Object} ignore - [description] @param {Array.<string>} path - [description] @return {boolean} - [description]
[ "Extend", "path", "with", "specific", "child", "identifier" ]
722d220d2dc54d78121d610a69f6544c2e116721
https://github.com/Autarc/optimal-select/blob/722d220d2dc54d78121d610a69f6544c2e116721/src/match.js#L228-L246
17,837
Autarc/optimal-select
src/match.js
checkIgnore
function checkIgnore (predicate, name, value, defaultPredicate) { if (!value) { return true } const check = predicate || defaultPredicate if (!check) { return false } return check(name, value, defaultPredicate) }
javascript
function checkIgnore (predicate, name, value, defaultPredicate) { if (!value) { return true } const check = predicate || defaultPredicate if (!check) { return false } return check(name, value, defaultPredicate) }
[ "function", "checkIgnore", "(", "predicate", ",", "name", ",", "value", ",", "defaultPredicate", ")", "{", "if", "(", "!", "value", ")", "{", "return", "true", "}", "const", "check", "=", "predicate", "||", "defaultPredicate", "if", "(", "!", "check", ")", "{", "return", "false", "}", "return", "check", "(", "name", ",", "value", ",", "defaultPredicate", ")", "}" ]
Validate with custom and default functions @param {Function} predicate - [description] @param {string?} name - [description] @param {string} value - [description] @param {Function} defaultPredicate - [description] @return {boolean} - [description]
[ "Validate", "with", "custom", "and", "default", "functions" ]
722d220d2dc54d78121d610a69f6544c2e116721
https://github.com/Autarc/optimal-select/blob/722d220d2dc54d78121d610a69f6544c2e116721/src/match.js#L273-L282
17,838
Autarc/optimal-select
src/select.js
getCommonSelectors
function getCommonSelectors (elements) { const { classes, attributes, tag } = getCommonProperties(elements) const selectorPath = [] if (tag) { selectorPath.push(tag) } if (classes) { const classSelector = classes.map((name) => `.${name}`).join('') selectorPath.push(classSelector) } if (attributes) { const attributeSelector = Object.keys(attributes).reduce((parts, name) => { parts.push(`[${name}="${attributes[name]}"]`) return parts }, []).join('') selectorPath.push(attributeSelector) } if (selectorPath.length) { // TODO: check for parent-child relation } return [ selectorPath.join('') ] }
javascript
function getCommonSelectors (elements) { const { classes, attributes, tag } = getCommonProperties(elements) const selectorPath = [] if (tag) { selectorPath.push(tag) } if (classes) { const classSelector = classes.map((name) => `.${name}`).join('') selectorPath.push(classSelector) } if (attributes) { const attributeSelector = Object.keys(attributes).reduce((parts, name) => { parts.push(`[${name}="${attributes[name]}"]`) return parts }, []).join('') selectorPath.push(attributeSelector) } if (selectorPath.length) { // TODO: check for parent-child relation } return [ selectorPath.join('') ] }
[ "function", "getCommonSelectors", "(", "elements", ")", "{", "const", "{", "classes", ",", "attributes", ",", "tag", "}", "=", "getCommonProperties", "(", "elements", ")", "const", "selectorPath", "=", "[", "]", "if", "(", "tag", ")", "{", "selectorPath", ".", "push", "(", "tag", ")", "}", "if", "(", "classes", ")", "{", "const", "classSelector", "=", "classes", ".", "map", "(", "(", "name", ")", "=>", "`", "${", "name", "}", "`", ")", ".", "join", "(", "''", ")", "selectorPath", ".", "push", "(", "classSelector", ")", "}", "if", "(", "attributes", ")", "{", "const", "attributeSelector", "=", "Object", ".", "keys", "(", "attributes", ")", ".", "reduce", "(", "(", "parts", ",", "name", ")", "=>", "{", "parts", ".", "push", "(", "`", "${", "name", "}", "${", "attributes", "[", "name", "]", "}", "`", ")", "return", "parts", "}", ",", "[", "]", ")", ".", "join", "(", "''", ")", "selectorPath", ".", "push", "(", "attributeSelector", ")", "}", "if", "(", "selectorPath", ".", "length", ")", "{", "// TODO: check for parent-child relation", "}", "return", "[", "selectorPath", ".", "join", "(", "''", ")", "]", "}" ]
Get selectors to describe a set of elements @param {Array.<HTMLElements>} elements - [description] @return {string} - [description]
[ "Get", "selectors", "to", "describe", "a", "set", "of", "elements" ]
722d220d2dc54d78121d610a69f6544c2e116721
https://github.com/Autarc/optimal-select/blob/722d220d2dc54d78121d610a69f6544c2e116721/src/select.js#L99-L129
17,839
Autarc/optimal-select
src/adapt.js
traverseDescendants
function traverseDescendants (nodes, handler) { nodes.forEach((node) => { var progress = true handler(node, () => progress = false) if (node.childTags && progress) { traverseDescendants(node.childTags, handler) } }) }
javascript
function traverseDescendants (nodes, handler) { nodes.forEach((node) => { var progress = true handler(node, () => progress = false) if (node.childTags && progress) { traverseDescendants(node.childTags, handler) } }) }
[ "function", "traverseDescendants", "(", "nodes", ",", "handler", ")", "{", "nodes", ".", "forEach", "(", "(", "node", ")", "=>", "{", "var", "progress", "=", "true", "handler", "(", "node", ",", "(", ")", "=>", "progress", "=", "false", ")", "if", "(", "node", ".", "childTags", "&&", "progress", ")", "{", "traverseDescendants", "(", "node", ".", "childTags", ",", "handler", ")", "}", "}", ")", "}" ]
Walking recursive to invoke callbacks @param {Array.<HTMLElement>} nodes - [description] @param {Function} handler - [description]
[ "Walking", "recursive", "to", "invoke", "callbacks" ]
722d220d2dc54d78121d610a69f6544c2e116721
https://github.com/Autarc/optimal-select/blob/722d220d2dc54d78121d610a69f6544c2e116721/src/adapt.js#L310-L318
17,840
Autarc/optimal-select
src/adapt.js
getAncestor
function getAncestor (node, root, validate) { while (node.parent) { node = node.parent if (validate(node)) { return node } if (node === root) { break } } return null }
javascript
function getAncestor (node, root, validate) { while (node.parent) { node = node.parent if (validate(node)) { return node } if (node === root) { break } } return null }
[ "function", "getAncestor", "(", "node", ",", "root", ",", "validate", ")", "{", "while", "(", "node", ".", "parent", ")", "{", "node", "=", "node", ".", "parent", "if", "(", "validate", "(", "node", ")", ")", "{", "return", "node", "}", "if", "(", "node", "===", "root", ")", "{", "break", "}", "}", "return", "null", "}" ]
Bubble up from bottom to top @param {HTMLELement} node - [description] @param {HTMLELement} root - [description] @param {Function} validate - [description] @return {HTMLELement} - [description]
[ "Bubble", "up", "from", "bottom", "to", "top" ]
722d220d2dc54d78121d610a69f6544c2e116721
https://github.com/Autarc/optimal-select/blob/722d220d2dc54d78121d610a69f6544c2e116721/src/adapt.js#L328-L339
17,841
Autarc/optimal-select
src/optimize.js
compareResults
function compareResults (matches, elements) { const { length } = matches return length === elements.length && elements.every((element) => { for (var i = 0; i < length; i++) { if (matches[i] === element) { return true } } return false }) }
javascript
function compareResults (matches, elements) { const { length } = matches return length === elements.length && elements.every((element) => { for (var i = 0; i < length; i++) { if (matches[i] === element) { return true } } return false }) }
[ "function", "compareResults", "(", "matches", ",", "elements", ")", "{", "const", "{", "length", "}", "=", "matches", "return", "length", "===", "elements", ".", "length", "&&", "elements", ".", "every", "(", "(", "element", ")", "=>", "{", "for", "(", "var", "i", "=", "0", ";", "i", "<", "length", ";", "i", "++", ")", "{", "if", "(", "matches", "[", "i", "]", "===", "element", ")", "{", "return", "true", "}", "}", "return", "false", "}", ")", "}" ]
Evaluate matches with expected elements @param {Array.<HTMLElement>} matches - [description] @param {Array.<HTMLElement>} elements - [description] @return {Boolean} - [description]
[ "Evaluate", "matches", "with", "expected", "elements" ]
722d220d2dc54d78121d610a69f6544c2e116721
https://github.com/Autarc/optimal-select/blob/722d220d2dc54d78121d610a69f6544c2e116721/src/optimize.js#L172-L182
17,842
barmalei/zebkit
src/js/ui/web/ui.web.core.js
$isInInvisibleState
function $isInInvisibleState(c) { if (c.isVisible === false || c.$container.parentNode === null || c.width <= 0 || c.height <= 0 || c.parent === null || zebkit.web.$contains(c.$container) === false) { return true; } var p = c.parent; while (p !== null && p.isVisible === true && p.width > 0 && p.height > 0) { p = p.parent; } return p !== null || ui.$cvp(c) === null; }
javascript
function $isInInvisibleState(c) { if (c.isVisible === false || c.$container.parentNode === null || c.width <= 0 || c.height <= 0 || c.parent === null || zebkit.web.$contains(c.$container) === false) { return true; } var p = c.parent; while (p !== null && p.isVisible === true && p.width > 0 && p.height > 0) { p = p.parent; } return p !== null || ui.$cvp(c) === null; }
[ "function", "$isInInvisibleState", "(", "c", ")", "{", "if", "(", "c", ".", "isVisible", "===", "false", "||", "c", ".", "$container", ".", "parentNode", "===", "null", "||", "c", ".", "width", "<=", "0", "||", "c", ".", "height", "<=", "0", "||", "c", ".", "parent", "===", "null", "||", "zebkit", ".", "web", ".", "$contains", "(", "c", ".", "$container", ")", "===", "false", ")", "{", "return", "true", ";", "}", "var", "p", "=", "c", ".", "parent", ";", "while", "(", "p", "!==", "null", "&&", "p", ".", "isVisible", "===", "true", "&&", "p", ".", "width", ">", "0", "&&", "p", ".", "height", ">", "0", ")", "{", "p", "=", "p", ".", "parent", ";", "}", "return", "p", "!==", "null", "||", "ui", ".", "$cvp", "(", "c", ")", "===", "null", ";", "}" ]
Evaluates if the given zebkit HTML UI component is in invisible state. @param {zebkit.ui.HtmlElement} c an UI HTML element wrapper @private @method $isInInvisibleState @return {Boolean} true if the HTML element wrapped with zebkit UI is in invisible state
[ "Evaluates", "if", "the", "given", "zebkit", "HTML", "UI", "component", "is", "in", "invisible", "state", "." ]
eea59bcdba9f07158098f3d8c6efd4f80770efad
https://github.com/barmalei/zebkit/blob/eea59bcdba9f07158098f3d8c6efd4f80770efad/src/js/ui/web/ui.web.core.js#L644-L661
17,843
barmalei/zebkit
src/js/ui/web/ui.web.core.js
$resolveDOMParent
function $resolveDOMParent(c) { // try to find an HTML element in zebkit (pay attention, in zebkit hierarchy !) // hierarchy that has to be a DOM parent for the given component var parentElement = null; for(var p = c.parent; p !== null; p = p.parent) { if (p.isDOMElement === true) { parentElement = p.$container; break; } } // parentElement is null means the component has // not been inserted into DOM hierarchy if (parentElement !== null && c.$container.parentNode === null) { // parent DOM element of the component is null, but a DOM container // for the element has been detected. We need to add it to DOM // than we have to add the DOM to the found DOM parent element parentElement.appendChild(c.$container); // adjust location of just attached DOM component $adjustLocation(c); } else { // test consistency whether the DOM element already has // parent node that doesn't match the discovered if (parentElement !== null && c.$container.parentNode !== null && c.$container.parentNode !== parentElement) { throw new Error("DOM parent inconsistent state "); } } }
javascript
function $resolveDOMParent(c) { // try to find an HTML element in zebkit (pay attention, in zebkit hierarchy !) // hierarchy that has to be a DOM parent for the given component var parentElement = null; for(var p = c.parent; p !== null; p = p.parent) { if (p.isDOMElement === true) { parentElement = p.$container; break; } } // parentElement is null means the component has // not been inserted into DOM hierarchy if (parentElement !== null && c.$container.parentNode === null) { // parent DOM element of the component is null, but a DOM container // for the element has been detected. We need to add it to DOM // than we have to add the DOM to the found DOM parent element parentElement.appendChild(c.$container); // adjust location of just attached DOM component $adjustLocation(c); } else { // test consistency whether the DOM element already has // parent node that doesn't match the discovered if (parentElement !== null && c.$container.parentNode !== null && c.$container.parentNode !== parentElement) { throw new Error("DOM parent inconsistent state "); } } }
[ "function", "$resolveDOMParent", "(", "c", ")", "{", "// try to find an HTML element in zebkit (pay attention, in zebkit hierarchy !)", "// hierarchy that has to be a DOM parent for the given component", "var", "parentElement", "=", "null", ";", "for", "(", "var", "p", "=", "c", ".", "parent", ";", "p", "!==", "null", ";", "p", "=", "p", ".", "parent", ")", "{", "if", "(", "p", ".", "isDOMElement", "===", "true", ")", "{", "parentElement", "=", "p", ".", "$container", ";", "break", ";", "}", "}", "// parentElement is null means the component has", "// not been inserted into DOM hierarchy", "if", "(", "parentElement", "!==", "null", "&&", "c", ".", "$container", ".", "parentNode", "===", "null", ")", "{", "// parent DOM element of the component is null, but a DOM container", "// for the element has been detected. We need to add it to DOM", "// than we have to add the DOM to the found DOM parent element", "parentElement", ".", "appendChild", "(", "c", ".", "$container", ")", ";", "// adjust location of just attached DOM component", "$adjustLocation", "(", "c", ")", ";", "}", "else", "{", "// test consistency whether the DOM element already has", "// parent node that doesn't match the discovered", "if", "(", "parentElement", "!==", "null", "&&", "c", ".", "$container", ".", "parentNode", "!==", "null", "&&", "c", ".", "$container", ".", "parentNode", "!==", "parentElement", ")", "{", "throw", "new", "Error", "(", "\"DOM parent inconsistent state \"", ")", ";", "}", "}", "}" ]
attach to appropriate DOM parent if necessary c parameter has to be DOM element
[ "attach", "to", "appropriate", "DOM", "parent", "if", "necessary", "c", "parameter", "has", "to", "be", "DOM", "element" ]
eea59bcdba9f07158098f3d8c6efd4f80770efad
https://github.com/barmalei/zebkit/blob/eea59bcdba9f07158098f3d8c6efd4f80770efad/src/js/ui/web/ui.web.core.js#L708-L739
17,844
barmalei/zebkit
src/js/ui/ui.menu.js
setParent
function setParent(p) { this.$super(p); if (p !== null && p.noSubIfEmpty === true) { this.getSub().setVisible(false); } }
javascript
function setParent(p) { this.$super(p); if (p !== null && p.noSubIfEmpty === true) { this.getSub().setVisible(false); } }
[ "function", "setParent", "(", "p", ")", "{", "this", ".", "$super", "(", "p", ")", ";", "if", "(", "p", "!==", "null", "&&", "p", ".", "noSubIfEmpty", "===", "true", ")", "{", "this", ".", "getSub", "(", ")", ".", "setVisible", "(", "false", ")", ";", "}", "}" ]
Override setParent method to catch the moment when the item is inserted to a menu @param {zebkit.ui.Panel} p a parent @method setParent
[ "Override", "setParent", "method", "to", "catch", "the", "moment", "when", "the", "item", "is", "inserted", "to", "a", "menu" ]
eea59bcdba9f07158098f3d8c6efd4f80770efad
https://github.com/barmalei/zebkit/blob/eea59bcdba9f07158098f3d8c6efd4f80770efad/src/js/ui/ui.menu.js#L342-L347
17,845
barmalei/zebkit
src/js/ui/ui.menu.js
keyPressed
function keyPressed(e){ if (e.code === "Escape") { if (this.parent !== null) { var p = this.$parentMenu; this.$canceled(this); this.$hideMenu(); if (p !== null) { p.requestFocus(); } } } else { this.$super(e); } }
javascript
function keyPressed(e){ if (e.code === "Escape") { if (this.parent !== null) { var p = this.$parentMenu; this.$canceled(this); this.$hideMenu(); if (p !== null) { p.requestFocus(); } } } else { this.$super(e); } }
[ "function", "keyPressed", "(", "e", ")", "{", "if", "(", "e", ".", "code", "===", "\"Escape\"", ")", "{", "if", "(", "this", ".", "parent", "!==", "null", ")", "{", "var", "p", "=", "this", ".", "$parentMenu", ";", "this", ".", "$canceled", "(", "this", ")", ";", "this", ".", "$hideMenu", "(", ")", ";", "if", "(", "p", "!==", "null", ")", "{", "p", ".", "requestFocus", "(", ")", ";", "}", "}", "}", "else", "{", "this", ".", "$super", "(", "e", ")", ";", "}", "}" ]
Override key pressed events handler to handle key events according to context menu component requirements @param {zebkit.ui.event.KeyEvent} e a key event @method keyPressed
[ "Override", "key", "pressed", "events", "handler", "to", "handle", "key", "events", "according", "to", "context", "menu", "component", "requirements" ]
eea59bcdba9f07158098f3d8c6efd4f80770efad
https://github.com/barmalei/zebkit/blob/eea59bcdba9f07158098f3d8c6efd4f80770efad/src/js/ui/ui.menu.js#L729-L742
17,846
barmalei/zebkit
src/js/ui/ui.menu.js
addDecorative
function addDecorative(c) { if (c.$isDecorative !== true) { c.$$isDecorative = true; } this.$getSuper("insert").call(this, this.kids.length, null, c); }
javascript
function addDecorative(c) { if (c.$isDecorative !== true) { c.$$isDecorative = true; } this.$getSuper("insert").call(this, this.kids.length, null, c); }
[ "function", "addDecorative", "(", "c", ")", "{", "if", "(", "c", ".", "$isDecorative", "!==", "true", ")", "{", "c", ".", "$$isDecorative", "=", "true", ";", "}", "this", ".", "$getSuper", "(", "\"insert\"", ")", ".", "call", "(", "this", ",", "this", ".", "kids", ".", "length", ",", "null", ",", "c", ")", ";", "}" ]
Add the specified component as a decorative item of the menu @param {zebkit.ui.Panel} c an UI component @method addDecorative
[ "Add", "the", "specified", "component", "as", "a", "decorative", "item", "of", "the", "menu" ]
eea59bcdba9f07158098f3d8c6efd4f80770efad
https://github.com/barmalei/zebkit/blob/eea59bcdba9f07158098f3d8c6efd4f80770efad/src/js/ui/ui.menu.js#L770-L775
17,847
barmalei/zebkit
src/js/ui/ui.field.js
setValue
function setValue(s) { var txt = this.getValue(); if (txt !== s){ if (this.position !== null) { this.position.setOffset(0); } this.scrollManager.scrollTo(0, 0); this.$super(s); } return this; }
javascript
function setValue(s) { var txt = this.getValue(); if (txt !== s){ if (this.position !== null) { this.position.setOffset(0); } this.scrollManager.scrollTo(0, 0); this.$super(s); } return this; }
[ "function", "setValue", "(", "s", ")", "{", "var", "txt", "=", "this", ".", "getValue", "(", ")", ";", "if", "(", "txt", "!==", "s", ")", "{", "if", "(", "this", ".", "position", "!==", "null", ")", "{", "this", ".", "position", ".", "setOffset", "(", "0", ")", ";", "}", "this", ".", "scrollManager", ".", "scrollTo", "(", "0", ",", "0", ")", ";", "this", ".", "$super", "(", "s", ")", ";", "}", "return", "this", ";", "}" ]
Set the text content of the text field component @param {String} s a text the text field component has to be filled @method setValue @chainable
[ "Set", "the", "text", "content", "of", "the", "text", "field", "component" ]
eea59bcdba9f07158098f3d8c6efd4f80770efad
https://github.com/barmalei/zebkit/blob/eea59bcdba9f07158098f3d8c6efd4f80770efad/src/js/ui/ui.field.js#L1247-L1257
17,848
barmalei/zebkit
src/js/dthen.js
function(e, pr) { if (arguments.length === 0) { if (this.$error !== null) { this.dumpError(e); } } else { if (this.$error === null) { if (this.$ignoreError) { this.$ignored(e); } else { this.$taskCounter = this.$level = this.$busy = 0; this.$error = e; this.$results = []; } this.$schedule(); } else if (arguments.length < 2 || pr === true) { this.dumpError(e); } } return this; }
javascript
function(e, pr) { if (arguments.length === 0) { if (this.$error !== null) { this.dumpError(e); } } else { if (this.$error === null) { if (this.$ignoreError) { this.$ignored(e); } else { this.$taskCounter = this.$level = this.$busy = 0; this.$error = e; this.$results = []; } this.$schedule(); } else if (arguments.length < 2 || pr === true) { this.dumpError(e); } } return this; }
[ "function", "(", "e", ",", "pr", ")", "{", "if", "(", "arguments", ".", "length", "===", "0", ")", "{", "if", "(", "this", ".", "$error", "!==", "null", ")", "{", "this", ".", "dumpError", "(", "e", ")", ";", "}", "}", "else", "{", "if", "(", "this", ".", "$error", "===", "null", ")", "{", "if", "(", "this", ".", "$ignoreError", ")", "{", "this", ".", "$ignored", "(", "e", ")", ";", "}", "else", "{", "this", ".", "$taskCounter", "=", "this", ".", "$level", "=", "this", ".", "$busy", "=", "0", ";", "this", ".", "$error", "=", "e", ";", "this", ".", "$results", "=", "[", "]", ";", "}", "this", ".", "$schedule", "(", ")", ";", "}", "else", "if", "(", "arguments", ".", "length", "<", "2", "||", "pr", "===", "true", ")", "{", "this", ".", "dumpError", "(", "e", ")", ";", "}", "}", "return", "this", ";", "}" ]
Force to fire error. @param {Error} [e] an error to be fired @method error @chainable
[ "Force", "to", "fire", "error", "." ]
eea59bcdba9f07158098f3d8c6efd4f80770efad
https://github.com/barmalei/zebkit/blob/eea59bcdba9f07158098f3d8c6efd4f80770efad/src/js/dthen.js#L241-L263
17,849
barmalei/zebkit
src/js/dthen.js
function(body) { var level = this.$level; // store level then was executed for the given task // to be used to compute correct the level inside the // method below var task = function() { // clean results of execution of a previous task this.$busy = 0; var pc = this.$taskCounter; if (this.$error !== null) { this.$taskCounter = 0; // we have to count the tasks on this level this.$level = level + 1; try { if (typeof body === 'function') { body.call(this, this.$error); } else if (body === null) { } else { this.dumpError(this.$error); } } catch(e) { this.$level = level; // restore level this.$taskCounter = pc; // restore counter throw e; } } if (level === 0) { try { this.$schedule(); } catch(e) { this.error(e); } } else { this.$schedule(); } this.$level = level; // restore level this.$taskCounter = pc; // restore counter }; if (this.$level > 0) { this.$tasks.splice(this.$taskCounter++, 0, task); } else { this.$tasks.push(task); } if (this.$level === 0) { this.$schedule(); } return this; }
javascript
function(body) { var level = this.$level; // store level then was executed for the given task // to be used to compute correct the level inside the // method below var task = function() { // clean results of execution of a previous task this.$busy = 0; var pc = this.$taskCounter; if (this.$error !== null) { this.$taskCounter = 0; // we have to count the tasks on this level this.$level = level + 1; try { if (typeof body === 'function') { body.call(this, this.$error); } else if (body === null) { } else { this.dumpError(this.$error); } } catch(e) { this.$level = level; // restore level this.$taskCounter = pc; // restore counter throw e; } } if (level === 0) { try { this.$schedule(); } catch(e) { this.error(e); } } else { this.$schedule(); } this.$level = level; // restore level this.$taskCounter = pc; // restore counter }; if (this.$level > 0) { this.$tasks.splice(this.$taskCounter++, 0, task); } else { this.$tasks.push(task); } if (this.$level === 0) { this.$schedule(); } return this; }
[ "function", "(", "body", ")", "{", "var", "level", "=", "this", ".", "$level", ";", "// store level then was executed for the given task", "// to be used to compute correct the level inside the", "// method below", "var", "task", "=", "function", "(", ")", "{", "// clean results of execution of a previous task", "this", ".", "$busy", "=", "0", ";", "var", "pc", "=", "this", ".", "$taskCounter", ";", "if", "(", "this", ".", "$error", "!==", "null", ")", "{", "this", ".", "$taskCounter", "=", "0", ";", "// we have to count the tasks on this level", "this", ".", "$level", "=", "level", "+", "1", ";", "try", "{", "if", "(", "typeof", "body", "===", "'function'", ")", "{", "body", ".", "call", "(", "this", ",", "this", ".", "$error", ")", ";", "}", "else", "if", "(", "body", "===", "null", ")", "{", "}", "else", "{", "this", ".", "dumpError", "(", "this", ".", "$error", ")", ";", "}", "}", "catch", "(", "e", ")", "{", "this", ".", "$level", "=", "level", ";", "// restore level", "this", ".", "$taskCounter", "=", "pc", ";", "// restore counter", "throw", "e", ";", "}", "}", "if", "(", "level", "===", "0", ")", "{", "try", "{", "this", ".", "$schedule", "(", ")", ";", "}", "catch", "(", "e", ")", "{", "this", ".", "error", "(", "e", ")", ";", "}", "}", "else", "{", "this", ".", "$schedule", "(", ")", ";", "}", "this", ".", "$level", "=", "level", ";", "// restore level", "this", ".", "$taskCounter", "=", "pc", ";", "// restore counter", "}", ";", "if", "(", "this", ".", "$level", ">", "0", ")", "{", "this", ".", "$tasks", ".", "splice", "(", "this", ".", "$taskCounter", "++", ",", "0", ",", "task", ")", ";", "}", "else", "{", "this", ".", "$tasks", ".", "push", "(", "task", ")", ";", "}", "if", "(", "this", ".", "$level", "===", "0", ")", "{", "this", ".", "$schedule", "(", ")", ";", "}", "return", "this", ";", "}" ]
Method to catch error that has occurred during the doit sequence execution. @param {Function} [body] a callback to handle the error. The method gets an error that has happened as its argument. If there is no argument the error will be printed in output. If passed argument is null then no error output is expected. @chainable @method catch
[ "Method", "to", "catch", "error", "that", "has", "occurred", "during", "the", "doit", "sequence", "execution", "." ]
eea59bcdba9f07158098f3d8c6efd4f80770efad
https://github.com/barmalei/zebkit/blob/eea59bcdba9f07158098f3d8c6efd4f80770efad/src/js/dthen.js#L409-L463
17,850
barmalei/zebkit
src/js/dthen.js
function() { // clean results of execution of a previous task this.$busy = 0; var pc = this.$taskCounter; if (this.$error !== null) { this.$taskCounter = 0; // we have to count the tasks on this level this.$level = level + 1; try { if (typeof body === 'function') { body.call(this, this.$error); } else if (body === null) { } else { this.dumpError(this.$error); } } catch(e) { this.$level = level; // restore level this.$taskCounter = pc; // restore counter throw e; } } if (level === 0) { try { this.$schedule(); } catch(e) { this.error(e); } } else { this.$schedule(); } this.$level = level; // restore level this.$taskCounter = pc; // restore counter }
javascript
function() { // clean results of execution of a previous task this.$busy = 0; var pc = this.$taskCounter; if (this.$error !== null) { this.$taskCounter = 0; // we have to count the tasks on this level this.$level = level + 1; try { if (typeof body === 'function') { body.call(this, this.$error); } else if (body === null) { } else { this.dumpError(this.$error); } } catch(e) { this.$level = level; // restore level this.$taskCounter = pc; // restore counter throw e; } } if (level === 0) { try { this.$schedule(); } catch(e) { this.error(e); } } else { this.$schedule(); } this.$level = level; // restore level this.$taskCounter = pc; // restore counter }
[ "function", "(", ")", "{", "// clean results of execution of a previous task", "this", ".", "$busy", "=", "0", ";", "var", "pc", "=", "this", ".", "$taskCounter", ";", "if", "(", "this", ".", "$error", "!==", "null", ")", "{", "this", ".", "$taskCounter", "=", "0", ";", "// we have to count the tasks on this level", "this", ".", "$level", "=", "level", "+", "1", ";", "try", "{", "if", "(", "typeof", "body", "===", "'function'", ")", "{", "body", ".", "call", "(", "this", ",", "this", ".", "$error", ")", ";", "}", "else", "if", "(", "body", "===", "null", ")", "{", "}", "else", "{", "this", ".", "dumpError", "(", "this", ".", "$error", ")", ";", "}", "}", "catch", "(", "e", ")", "{", "this", ".", "$level", "=", "level", ";", "// restore level", "this", ".", "$taskCounter", "=", "pc", ";", "// restore counter", "throw", "e", ";", "}", "}", "if", "(", "level", "===", "0", ")", "{", "try", "{", "this", ".", "$schedule", "(", ")", ";", "}", "catch", "(", "e", ")", "{", "this", ".", "error", "(", "e", ")", ";", "}", "}", "else", "{", "this", ".", "$schedule", "(", ")", ";", "}", "this", ".", "$level", "=", "level", ";", "// restore level", "this", ".", "$taskCounter", "=", "pc", ";", "// restore counter", "}" ]
store level then was executed for the given task to be used to compute correct the level inside the method below
[ "store", "level", "then", "was", "executed", "for", "the", "given", "task", "to", "be", "used", "to", "compute", "correct", "the", "level", "inside", "the", "method", "below" ]
eea59bcdba9f07158098f3d8c6efd4f80770efad
https://github.com/barmalei/zebkit/blob/eea59bcdba9f07158098f3d8c6efd4f80770efad/src/js/dthen.js#L414-L450
17,851
barmalei/zebkit
src/js/ui/ui.Slider.js
getView
function getView(t, v) { if (v !== null && v !== undefined && this.numPrecision !== -1 && zebkit.isNumber(v)) { v = v.toFixed(this.numPrecision); } return this.$super(t, v); }
javascript
function getView(t, v) { if (v !== null && v !== undefined && this.numPrecision !== -1 && zebkit.isNumber(v)) { v = v.toFixed(this.numPrecision); } return this.$super(t, v); }
[ "function", "getView", "(", "t", ",", "v", ")", "{", "if", "(", "v", "!==", "null", "&&", "v", "!==", "undefined", "&&", "this", ".", "numPrecision", "!==", "-", "1", "&&", "zebkit", ".", "isNumber", "(", "v", ")", ")", "{", "v", "=", "v", ".", "toFixed", "(", "this", ".", "numPrecision", ")", ";", "}", "return", "this", ".", "$super", "(", "t", ",", "v", ")", ";", "}" ]
Get a view to render the given number. @param {zebkit.ui.RulerPan} t a target ruler panel. @param {Number} v a number to be rendered @return {zebkit.draw.View} a view to render the number @method getView
[ "Get", "a", "view", "to", "render", "the", "given", "number", "." ]
eea59bcdba9f07158098f3d8c6efd4f80770efad
https://github.com/barmalei/zebkit/blob/eea59bcdba9f07158098f3d8c6efd4f80770efad/src/js/ui/ui.Slider.js#L169-L174
17,852
barmalei/zebkit
src/js/ui/tree/ui.tree.Tree.js
setViewProvider
function setViewProvider(p){ if (this.provider != p) { this.stopEditing(false); this.provider = p; delete this.nodes; this.nodes = {}; this.vrp(); } return this; }
javascript
function setViewProvider(p){ if (this.provider != p) { this.stopEditing(false); this.provider = p; delete this.nodes; this.nodes = {}; this.vrp(); } return this; }
[ "function", "setViewProvider", "(", "p", ")", "{", "if", "(", "this", ".", "provider", "!=", "p", ")", "{", "this", ".", "stopEditing", "(", "false", ")", ";", "this", ".", "provider", "=", "p", ";", "delete", "this", ".", "nodes", ";", "this", ".", "nodes", "=", "{", "}", ";", "this", ".", "vrp", "(", ")", ";", "}", "return", "this", ";", "}" ]
Set tree component items view provider. Provider says how tree model items have to be visualized. @param {zebkit.ui.tree.DefViews} p a view provider @method setViewProvider @chainable
[ "Set", "tree", "component", "items", "view", "provider", ".", "Provider", "says", "how", "tree", "model", "items", "have", "to", "be", "visualized", "." ]
eea59bcdba9f07158098f3d8c6efd4f80770efad
https://github.com/barmalei/zebkit/blob/eea59bcdba9f07158098f3d8c6efd4f80770efad/src/js/ui/tree/ui.tree.Tree.js#L293-L302
17,853
barmalei/zebkit
src/js/misc.js
dumpError
function dumpError(e) { if (typeof console !== "undefined" && typeof console.log !== "undefined") { var msg = "zebkit.err ["; if (typeof Date !== 'undefined') { var date = new Date(); msg = msg + date.getDate() + "/" + (date.getMonth() + 1) + "/" + date.getFullYear() + " " + date.getHours() + ":" + date.getMinutes() + ":" + date.getSeconds(); } if (e === null || e === undefined) { console.log("Unknown error"); } else { console.log(msg + " : " + e); console.log((e.stack ? e.stack : e)); } } }
javascript
function dumpError(e) { if (typeof console !== "undefined" && typeof console.log !== "undefined") { var msg = "zebkit.err ["; if (typeof Date !== 'undefined') { var date = new Date(); msg = msg + date.getDate() + "/" + (date.getMonth() + 1) + "/" + date.getFullYear() + " " + date.getHours() + ":" + date.getMinutes() + ":" + date.getSeconds(); } if (e === null || e === undefined) { console.log("Unknown error"); } else { console.log(msg + " : " + e); console.log((e.stack ? e.stack : e)); } } }
[ "function", "dumpError", "(", "e", ")", "{", "if", "(", "typeof", "console", "!==", "\"undefined\"", "&&", "typeof", "console", ".", "log", "!==", "\"undefined\"", ")", "{", "var", "msg", "=", "\"zebkit.err [\"", ";", "if", "(", "typeof", "Date", "!==", "'undefined'", ")", "{", "var", "date", "=", "new", "Date", "(", ")", ";", "msg", "=", "msg", "+", "date", ".", "getDate", "(", ")", "+", "\"/\"", "+", "(", "date", ".", "getMonth", "(", ")", "+", "1", ")", "+", "\"/\"", "+", "date", ".", "getFullYear", "(", ")", "+", "\" \"", "+", "date", ".", "getHours", "(", ")", "+", "\":\"", "+", "date", ".", "getMinutes", "(", ")", "+", "\":\"", "+", "date", ".", "getSeconds", "(", ")", ";", "}", "if", "(", "e", "===", "null", "||", "e", "===", "undefined", ")", "{", "console", ".", "log", "(", "\"Unknown error\"", ")", ";", "}", "else", "{", "console", ".", "log", "(", "msg", "+", "\" : \"", "+", "e", ")", ";", "console", ".", "log", "(", "(", "e", ".", "stack", "?", "e", ".", "stack", ":", "e", ")", ")", ";", "}", "}", "}" ]
Dump the given error to output. @param {Exception | Object} e an error. @method dumpError @for zebkit
[ "Dump", "the", "given", "error", "to", "output", "." ]
eea59bcdba9f07158098f3d8c6efd4f80770efad
https://github.com/barmalei/zebkit/blob/eea59bcdba9f07158098f3d8c6efd4f80770efad/src/js/misc.js#L195-L212
17,854
barmalei/zebkit
src/js/misc.js
image
function image(ph, fireErr) { if (arguments.length < 2) { fireErr = false; } var doit = new DoIt(), jn = doit.join(), marker = "data:image"; if (isString(ph) && ph.length > marker.length) { // use "for" instead of "indexOf === 0" var i = 0; for(; i < marker.length && marker[i] === ph[i]; i++) {} if (i < marker.length) { var file = ZFS.read(ph); if (file !== null) { ph = "data:image/" + file.ext + ";base64," + file.data; } } } $zenv.loadImage(ph, function(img) { jn(img); }, function(img, e) { if (fireErr === true) { doit.error(e); } else { jn(img); } } ); return doit; }
javascript
function image(ph, fireErr) { if (arguments.length < 2) { fireErr = false; } var doit = new DoIt(), jn = doit.join(), marker = "data:image"; if (isString(ph) && ph.length > marker.length) { // use "for" instead of "indexOf === 0" var i = 0; for(; i < marker.length && marker[i] === ph[i]; i++) {} if (i < marker.length) { var file = ZFS.read(ph); if (file !== null) { ph = "data:image/" + file.ext + ";base64," + file.data; } } } $zenv.loadImage(ph, function(img) { jn(img); }, function(img, e) { if (fireErr === true) { doit.error(e); } else { jn(img); } } ); return doit; }
[ "function", "image", "(", "ph", ",", "fireErr", ")", "{", "if", "(", "arguments", ".", "length", "<", "2", ")", "{", "fireErr", "=", "false", ";", "}", "var", "doit", "=", "new", "DoIt", "(", ")", ",", "jn", "=", "doit", ".", "join", "(", ")", ",", "marker", "=", "\"data:image\"", ";", "if", "(", "isString", "(", "ph", ")", "&&", "ph", ".", "length", ">", "marker", ".", "length", ")", "{", "// use \"for\" instead of \"indexOf === 0\"", "var", "i", "=", "0", ";", "for", "(", ";", "i", "<", "marker", ".", "length", "&&", "marker", "[", "i", "]", "===", "ph", "[", "i", "]", ";", "i", "++", ")", "{", "}", "if", "(", "i", "<", "marker", ".", "length", ")", "{", "var", "file", "=", "ZFS", ".", "read", "(", "ph", ")", ";", "if", "(", "file", "!==", "null", ")", "{", "ph", "=", "\"data:image/\"", "+", "file", ".", "ext", "+", "\";base64,\"", "+", "file", ".", "data", ";", "}", "}", "}", "$zenv", ".", "loadImage", "(", "ph", ",", "function", "(", "img", ")", "{", "jn", "(", "img", ")", ";", "}", ",", "function", "(", "img", ",", "e", ")", "{", "if", "(", "fireErr", "===", "true", ")", "{", "doit", ".", "error", "(", "e", ")", ";", "}", "else", "{", "jn", "(", "img", ")", ";", "}", "}", ")", ";", "return", "doit", ";", "}" ]
Load image or complete the given image loading. @param {String|Image} ph path or image to complete loading. @param {Boolean} [fireErr] flag to force or preserve error firing. @return {zebkit.DoIt} @method image @for zebkit
[ "Load", "image", "or", "complete", "the", "given", "image", "loading", "." ]
eea59bcdba9f07158098f3d8c6efd4f80770efad
https://github.com/barmalei/zebkit/blob/eea59bcdba9f07158098f3d8c6efd4f80770efad/src/js/misc.js#L223-L257
17,855
barmalei/zebkit
src/js/misc.js
isNumber
function isNumber(o) { return o !== undefined && o !== null && (typeof o === "number" || o.constructor === Number); }
javascript
function isNumber(o) { return o !== undefined && o !== null && (typeof o === "number" || o.constructor === Number); }
[ "function", "isNumber", "(", "o", ")", "{", "return", "o", "!==", "undefined", "&&", "o", "!==", "null", "&&", "(", "typeof", "o", "===", "\"number\"", "||", "o", ".", "constructor", "===", "Number", ")", ";", "}" ]
Check if the given value is number @param {Object} v a value. @return {Boolean} true if the given value is number @method isNumber @for zebkit
[ "Check", "if", "the", "given", "value", "is", "number" ]
eea59bcdba9f07158098f3d8c6efd4f80770efad
https://github.com/barmalei/zebkit/blob/eea59bcdba9f07158098f3d8c6efd4f80770efad/src/js/misc.js#L282-L285
17,856
barmalei/zebkit
src/js/misc.js
isBoolean
function isBoolean(o) { return o !== undefined && o !== null && (typeof o === "boolean" || o.constructor === Boolean); }
javascript
function isBoolean(o) { return o !== undefined && o !== null && (typeof o === "boolean" || o.constructor === Boolean); }
[ "function", "isBoolean", "(", "o", ")", "{", "return", "o", "!==", "undefined", "&&", "o", "!==", "null", "&&", "(", "typeof", "o", "===", "\"boolean\"", "||", "o", ".", "constructor", "===", "Boolean", ")", ";", "}" ]
Check if the given value is boolean @param {Object} v a value. @return {Boolean} true if the given value is boolean @method isBoolean @for zebkit
[ "Check", "if", "the", "given", "value", "is", "boolean" ]
eea59bcdba9f07158098f3d8c6efd4f80770efad
https://github.com/barmalei/zebkit/blob/eea59bcdba9f07158098f3d8c6efd4f80770efad/src/js/misc.js#L294-L297
17,857
barmalei/zebkit
src/js/misc.js
getPropertyValue
function getPropertyValue(obj, path, useGetter) { // if (arguments.length < 3) { // useGetter = false; // } path = path.trim(); if (path === undefined || path.length === 0) { throw new Error("Invalid field path: '" + path + "'"); } // if (obj === undefined || obj === null) { // throw new Error("Undefined target object"); // } var paths = null, m = null, p = null; if (path.indexOf('.') > 0) { paths = path.split('.'); for(var i = 0; i < paths.length; i++) { p = paths[i]; if (obj !== undefined && obj !== null && ((useGetter === true && (m = getPropertyGetter(obj, p))) || obj.hasOwnProperty(p))) { if (useGetter === true && m !== null) { obj = m.call(obj); } else { obj = obj[p]; } } else { return undefined; } } } else if (path === '*') { var res = {}; for (var k in obj) { if (k[0] !== '$' && obj.hasOwnProperty(k)) { res[k] = getPropertyValue(obj, k, useGetter === true); } } return res; } else { if (useGetter === true) { m = getPropertyGetter(obj, path); if (m !== null) { return m.call(obj); } } if (obj.hasOwnProperty(path) === true) { obj = obj[path]; } else { return undefined; } } // detect object value factory if (obj !== null && obj !== undefined && obj.$new !== undefined) { return obj.$new(); } else { return obj; } }
javascript
function getPropertyValue(obj, path, useGetter) { // if (arguments.length < 3) { // useGetter = false; // } path = path.trim(); if (path === undefined || path.length === 0) { throw new Error("Invalid field path: '" + path + "'"); } // if (obj === undefined || obj === null) { // throw new Error("Undefined target object"); // } var paths = null, m = null, p = null; if (path.indexOf('.') > 0) { paths = path.split('.'); for(var i = 0; i < paths.length; i++) { p = paths[i]; if (obj !== undefined && obj !== null && ((useGetter === true && (m = getPropertyGetter(obj, p))) || obj.hasOwnProperty(p))) { if (useGetter === true && m !== null) { obj = m.call(obj); } else { obj = obj[p]; } } else { return undefined; } } } else if (path === '*') { var res = {}; for (var k in obj) { if (k[0] !== '$' && obj.hasOwnProperty(k)) { res[k] = getPropertyValue(obj, k, useGetter === true); } } return res; } else { if (useGetter === true) { m = getPropertyGetter(obj, path); if (m !== null) { return m.call(obj); } } if (obj.hasOwnProperty(path) === true) { obj = obj[path]; } else { return undefined; } } // detect object value factory if (obj !== null && obj !== undefined && obj.$new !== undefined) { return obj.$new(); } else { return obj; } }
[ "function", "getPropertyValue", "(", "obj", ",", "path", ",", "useGetter", ")", "{", "// if (arguments.length < 3) {", "// useGetter = false;", "// }", "path", "=", "path", ".", "trim", "(", ")", ";", "if", "(", "path", "===", "undefined", "||", "path", ".", "length", "===", "0", ")", "{", "throw", "new", "Error", "(", "\"Invalid field path: '\"", "+", "path", "+", "\"'\"", ")", ";", "}", "// if (obj === undefined || obj === null) {", "// throw new Error(\"Undefined target object\");", "// }", "var", "paths", "=", "null", ",", "m", "=", "null", ",", "p", "=", "null", ";", "if", "(", "path", ".", "indexOf", "(", "'.'", ")", ">", "0", ")", "{", "paths", "=", "path", ".", "split", "(", "'.'", ")", ";", "for", "(", "var", "i", "=", "0", ";", "i", "<", "paths", ".", "length", ";", "i", "++", ")", "{", "p", "=", "paths", "[", "i", "]", ";", "if", "(", "obj", "!==", "undefined", "&&", "obj", "!==", "null", "&&", "(", "(", "useGetter", "===", "true", "&&", "(", "m", "=", "getPropertyGetter", "(", "obj", ",", "p", ")", ")", ")", "||", "obj", ".", "hasOwnProperty", "(", "p", ")", ")", ")", "{", "if", "(", "useGetter", "===", "true", "&&", "m", "!==", "null", ")", "{", "obj", "=", "m", ".", "call", "(", "obj", ")", ";", "}", "else", "{", "obj", "=", "obj", "[", "p", "]", ";", "}", "}", "else", "{", "return", "undefined", ";", "}", "}", "}", "else", "if", "(", "path", "===", "'*'", ")", "{", "var", "res", "=", "{", "}", ";", "for", "(", "var", "k", "in", "obj", ")", "{", "if", "(", "k", "[", "0", "]", "!==", "'$'", "&&", "obj", ".", "hasOwnProperty", "(", "k", ")", ")", "{", "res", "[", "k", "]", "=", "getPropertyValue", "(", "obj", ",", "k", ",", "useGetter", "===", "true", ")", ";", "}", "}", "return", "res", ";", "}", "else", "{", "if", "(", "useGetter", "===", "true", ")", "{", "m", "=", "getPropertyGetter", "(", "obj", ",", "path", ")", ";", "if", "(", "m", "!==", "null", ")", "{", "return", "m", ".", "call", "(", "obj", ")", ";", "}", "}", "if", "(", "obj", ".", "hasOwnProperty", "(", "path", ")", "===", "true", ")", "{", "obj", "=", "obj", "[", "path", "]", ";", "}", "else", "{", "return", "undefined", ";", "}", "}", "// detect object value factory", "if", "(", "obj", "!==", "null", "&&", "obj", "!==", "undefined", "&&", "obj", ".", "$new", "!==", "undefined", ")", "{", "return", "obj", ".", "$new", "(", ")", ";", "}", "else", "{", "return", "obj", ";", "}", "}" ]
Get property value for the given object and the specified property path @param {Object} obj a target object. as the target object @param {String} path property path. Use "`*" as path to collect all available public properties. @param {Boolean} [useGetter] says too try getter method when it exists. By default the parameter is false @return {Object} a property value, return undefined if property cannot be found @method getPropertyValue @for zebkit
[ "Get", "property", "value", "for", "the", "given", "object", "and", "the", "specified", "property", "path" ]
eea59bcdba9f07158098f3d8c6efd4f80770efad
https://github.com/barmalei/zebkit/blob/eea59bcdba9f07158098f3d8c6efd4f80770efad/src/js/misc.js#L334-L399
17,858
barmalei/zebkit
src/js/misc.js
function() { return (this.scheme !== null ? this.scheme + "://" : '') + (this.host !== null ? this.host : '' ) + (this.port !== -1 ? ":" + this.port : '' ) + (this.path !== null ? this.path : '' ) + (this.qs !== null ? "?" + this.qs : '' ); }
javascript
function() { return (this.scheme !== null ? this.scheme + "://" : '') + (this.host !== null ? this.host : '' ) + (this.port !== -1 ? ":" + this.port : '' ) + (this.path !== null ? this.path : '' ) + (this.qs !== null ? "?" + this.qs : '' ); }
[ "function", "(", ")", "{", "return", "(", "this", ".", "scheme", "!==", "null", "?", "this", ".", "scheme", "+", "\"://\"", ":", "''", ")", "+", "(", "this", ".", "host", "!==", "null", "?", "this", ".", "host", ":", "''", ")", "+", "(", "this", ".", "port", "!==", "-", "1", "?", "\":\"", "+", "this", ".", "port", ":", "''", ")", "+", "(", "this", ".", "path", "!==", "null", "?", "this", ".", "path", ":", "''", ")", "+", "(", "this", ".", "qs", "!==", "null", "?", "\"?\"", "+", "this", ".", "qs", ":", "''", ")", ";", "}" ]
Serialize URI to its string representation. @method toString @return {String} an URI as a string.
[ "Serialize", "URI", "to", "its", "string", "representation", "." ]
eea59bcdba9f07158098f3d8c6efd4f80770efad
https://github.com/barmalei/zebkit/blob/eea59bcdba9f07158098f3d8c6efd4f80770efad/src/js/misc.js#L715-L721
17,859
barmalei/zebkit
src/js/misc.js
function() { if (this.path === null) { return null; } else { var i = this.path.lastIndexOf('/'); return (i < 0 || this.path === '/') ? null : new URI(this.scheme, this.host, this.port, this.path.substring(0, i), this.qs); } }
javascript
function() { if (this.path === null) { return null; } else { var i = this.path.lastIndexOf('/'); return (i < 0 || this.path === '/') ? null : new URI(this.scheme, this.host, this.port, this.path.substring(0, i), this.qs); } }
[ "function", "(", ")", "{", "if", "(", "this", ".", "path", "===", "null", ")", "{", "return", "null", ";", "}", "else", "{", "var", "i", "=", "this", ".", "path", ".", "lastIndexOf", "(", "'/'", ")", ";", "return", "(", "i", "<", "0", "||", "this", ".", "path", "===", "'/'", ")", "?", "null", ":", "new", "URI", "(", "this", ".", "scheme", ",", "this", ".", "host", ",", "this", ".", "port", ",", "this", ".", "path", ".", "substring", "(", "0", ",", "i", ")", ",", "this", ".", "qs", ")", ";", "}", "}" ]
Get a parent URI. @method getParent @return {zebkit.URI} a parent URI.
[ "Get", "a", "parent", "URI", "." ]
eea59bcdba9f07158098f3d8c6efd4f80770efad
https://github.com/barmalei/zebkit/blob/eea59bcdba9f07158098f3d8c6efd4f80770efad/src/js/misc.js#L728-L740
17,860
barmalei/zebkit
src/js/misc.js
function(obj) { if (obj !== null) { if (this.qs === null) { this.qs = ''; } if (this.qs.length > 0) { this.qs = this.qs + "&" + URI.toQS(obj); } else { this.qs = URI.toQS(obj); } } }
javascript
function(obj) { if (obj !== null) { if (this.qs === null) { this.qs = ''; } if (this.qs.length > 0) { this.qs = this.qs + "&" + URI.toQS(obj); } else { this.qs = URI.toQS(obj); } } }
[ "function", "(", "obj", ")", "{", "if", "(", "obj", "!==", "null", ")", "{", "if", "(", "this", ".", "qs", "===", "null", ")", "{", "this", ".", "qs", "=", "''", ";", "}", "if", "(", "this", ".", "qs", ".", "length", ">", "0", ")", "{", "this", ".", "qs", "=", "this", ".", "qs", "+", "\"&\"", "+", "URI", ".", "toQS", "(", "obj", ")", ";", "}", "else", "{", "this", ".", "qs", "=", "URI", ".", "toQS", "(", "obj", ")", ";", "}", "}", "}" ]
Append the given parameters to a query string of the URI. @param {Object} obj a dictionary of parameters to be appended to the URL query string @method appendQS
[ "Append", "the", "given", "parameters", "to", "a", "query", "string", "of", "the", "URI", "." ]
eea59bcdba9f07158098f3d8c6efd4f80770efad
https://github.com/barmalei/zebkit/blob/eea59bcdba9f07158098f3d8c6efd4f80770efad/src/js/misc.js#L748-L760
17,861
barmalei/zebkit
src/js/misc.js
function() { var args = Array.prototype.slice.call(arguments); args.splice(0, 0, this.toString()); return URI.join.apply(URI, args); }
javascript
function() { var args = Array.prototype.slice.call(arguments); args.splice(0, 0, this.toString()); return URI.join.apply(URI, args); }
[ "function", "(", ")", "{", "var", "args", "=", "Array", ".", "prototype", ".", "slice", ".", "call", "(", "arguments", ")", ";", "args", ".", "splice", "(", "0", ",", "0", ",", "this", ".", "toString", "(", ")", ")", ";", "return", "URI", ".", "join", ".", "apply", "(", "URI", ",", "args", ")", ";", "}" ]
Join URI with the specified path @param {String} p* relative paths @return {String} an absolute URI @method join
[ "Join", "URI", "with", "the", "specified", "path" ]
eea59bcdba9f07158098f3d8c6efd4f80770efad
https://github.com/barmalei/zebkit/blob/eea59bcdba9f07158098f3d8c6efd4f80770efad/src/js/misc.js#L777-L781
17,862
barmalei/zebkit
src/js/misc.js
function(to) { if ((to instanceof URI) === false) { to = new URI(to); } if (this.isAbsolute() && to.isAbsolute() && this.host === to.host && this.port === to.port && (this.scheme === to.scheme || (this.isFilePath() && to.isFilePath()) ) && (this.path.indexOf(to.path) === 0 && (to.path.length === this.path.length || (to.path.length === 1 && to.path[0] === '/') || this.path[to.path.length] === '/' ))) { return (to.path.length === 1 && to.path[0] === '/') ? this.path.substring(to.path.length) : this.path.substring(to.path.length + 1); } else { return null; } }
javascript
function(to) { if ((to instanceof URI) === false) { to = new URI(to); } if (this.isAbsolute() && to.isAbsolute() && this.host === to.host && this.port === to.port && (this.scheme === to.scheme || (this.isFilePath() && to.isFilePath()) ) && (this.path.indexOf(to.path) === 0 && (to.path.length === this.path.length || (to.path.length === 1 && to.path[0] === '/') || this.path[to.path.length] === '/' ))) { return (to.path.length === 1 && to.path[0] === '/') ? this.path.substring(to.path.length) : this.path.substring(to.path.length + 1); } else { return null; } }
[ "function", "(", "to", ")", "{", "if", "(", "(", "to", "instanceof", "URI", ")", "===", "false", ")", "{", "to", "=", "new", "URI", "(", "to", ")", ";", "}", "if", "(", "this", ".", "isAbsolute", "(", ")", "&&", "to", ".", "isAbsolute", "(", ")", "&&", "this", ".", "host", "===", "to", ".", "host", "&&", "this", ".", "port", "===", "to", ".", "port", "&&", "(", "this", ".", "scheme", "===", "to", ".", "scheme", "||", "(", "this", ".", "isFilePath", "(", ")", "&&", "to", ".", "isFilePath", "(", ")", ")", ")", "&&", "(", "this", ".", "path", ".", "indexOf", "(", "to", ".", "path", ")", "===", "0", "&&", "(", "to", ".", "path", ".", "length", "===", "this", ".", "path", ".", "length", "||", "(", "to", ".", "path", ".", "length", "===", "1", "&&", "to", ".", "path", "[", "0", "]", "===", "'/'", ")", "||", "this", ".", "path", "[", "to", ".", "path", ".", "length", "]", "===", "'/'", ")", ")", ")", "{", "return", "(", "to", ".", "path", ".", "length", "===", "1", "&&", "to", ".", "path", "[", "0", "]", "===", "'/'", ")", "?", "this", ".", "path", ".", "substring", "(", "to", ".", "path", ".", "length", ")", ":", "this", ".", "path", ".", "substring", "(", "to", ".", "path", ".", "length", "+", "1", ")", ";", "}", "else", "{", "return", "null", ";", "}", "}" ]
Get an URI relative to the given URI. @param {String|zebkit.URI} to an URI to that the relative URI has to be detected. @return {String} a relative URI @method relative
[ "Get", "an", "URI", "relative", "to", "the", "given", "URI", "." ]
eea59bcdba9f07158098f3d8c6efd4f80770efad
https://github.com/barmalei/zebkit/blob/eea59bcdba9f07158098f3d8c6efd4f80770efad/src/js/misc.js#L798-L817
17,863
barmalei/zebkit
src/js/web/web.event.key.js
$initializeCodesMap
function $initializeCodesMap() { var k = null, code = null; // validate codes mapping for(k in CODES) { code = CODES[k]; if (code.map !== undefined) { if (CODES[code.map] === undefined) { throw new Error("Invalid mapping for code = '" + k + "'"); } } else if (code.keyCode === undefined) { throw new Error("unknown keyCode for code = '" + k + "'"); } } // build codes map table for the cases when "code" property CODES_MAP = {}; for(k in CODES) { code = CODES[k]; if (code.map !== undefined) { if (code.keyCode !== undefined) { CODES_MAP[code.keyCode] = code.map; } } else { CODES_MAP[code.keyCode] = k; } } }
javascript
function $initializeCodesMap() { var k = null, code = null; // validate codes mapping for(k in CODES) { code = CODES[k]; if (code.map !== undefined) { if (CODES[code.map] === undefined) { throw new Error("Invalid mapping for code = '" + k + "'"); } } else if (code.keyCode === undefined) { throw new Error("unknown keyCode for code = '" + k + "'"); } } // build codes map table for the cases when "code" property CODES_MAP = {}; for(k in CODES) { code = CODES[k]; if (code.map !== undefined) { if (code.keyCode !== undefined) { CODES_MAP[code.keyCode] = code.map; } } else { CODES_MAP[code.keyCode] = k; } } }
[ "function", "$initializeCodesMap", "(", ")", "{", "var", "k", "=", "null", ",", "code", "=", "null", ";", "// validate codes mapping", "for", "(", "k", "in", "CODES", ")", "{", "code", "=", "CODES", "[", "k", "]", ";", "if", "(", "code", ".", "map", "!==", "undefined", ")", "{", "if", "(", "CODES", "[", "code", ".", "map", "]", "===", "undefined", ")", "{", "throw", "new", "Error", "(", "\"Invalid mapping for code = '\"", "+", "k", "+", "\"'\"", ")", ";", "}", "}", "else", "if", "(", "code", ".", "keyCode", "===", "undefined", ")", "{", "throw", "new", "Error", "(", "\"unknown keyCode for code = '\"", "+", "k", "+", "\"'\"", ")", ";", "}", "}", "// build codes map table for the cases when \"code\" property", "CODES_MAP", "=", "{", "}", ";", "for", "(", "k", "in", "CODES", ")", "{", "code", "=", "CODES", "[", "k", "]", ";", "if", "(", "code", ".", "map", "!==", "undefined", ")", "{", "if", "(", "code", ".", "keyCode", "!==", "undefined", ")", "{", "CODES_MAP", "[", "code", ".", "keyCode", "]", "=", "code", ".", "map", ";", "}", "}", "else", "{", "CODES_MAP", "[", "code", ".", "keyCode", "]", "=", "k", ";", "}", "}", "}" ]
codes to that are not the same for different browsers
[ "codes", "to", "that", "are", "not", "the", "same", "for", "different", "browsers" ]
eea59bcdba9f07158098f3d8c6efd4f80770efad
https://github.com/barmalei/zebkit/blob/eea59bcdba9f07158098f3d8c6efd4f80770efad/src/js/web/web.event.key.js#L135-L163
17,864
barmalei/zebkit
src/js/ui/date/ui.date.js
setFormat
function setFormat(format) { if (format === null || format === undefined) { throw new Error("Format is not defined " + this.clazz.$name); } if (this.format !== format) { this.format = format; this.$getSuper("setValue").call(this, this.$format(this.date)); } return this; }
javascript
function setFormat(format) { if (format === null || format === undefined) { throw new Error("Format is not defined " + this.clazz.$name); } if (this.format !== format) { this.format = format; this.$getSuper("setValue").call(this, this.$format(this.date)); } return this; }
[ "function", "setFormat", "(", "format", ")", "{", "if", "(", "format", "===", "null", "||", "format", "===", "undefined", ")", "{", "throw", "new", "Error", "(", "\"Format is not defined \"", "+", "this", ".", "clazz", ".", "$name", ")", ";", "}", "if", "(", "this", ".", "format", "!==", "format", ")", "{", "this", ".", "format", "=", "format", ";", "this", ".", "$getSuper", "(", "\"setValue\"", ")", ".", "call", "(", "this", ",", "this", ".", "$format", "(", "this", ".", "date", ")", ")", ";", "}", "return", "this", ";", "}" ]
Set the pattern to be used to format date @param {String} format a format pattern @method setFormat @chainable
[ "Set", "the", "pattern", "to", "be", "used", "to", "format", "date" ]
eea59bcdba9f07158098f3d8c6efd4f80770efad
https://github.com/barmalei/zebkit/blob/eea59bcdba9f07158098f3d8c6efd4f80770efad/src/js/ui/date/ui.date.js#L1338-L1349
17,865
barmalei/zebkit
src/js/ui/date/ui.date.js
getCalendar
function getCalendar() { if (this.clazz.$name === undefined) { throw new Error(); } if (this.calendar === undefined || this.calendar === null) { var $this = this; this.$freezeCalendar = false; this.calendar = new pkg.Calendar([ function $clazz() { this.MonthsCombo.$name = "INNER"; }, function winActivated(e) { if (e.isActive === false) { $this.hideCalendar(); } }, function childKeyPressed(e){ if (e.code === "Escape") { $this.hideCalendar(); } }, function dateSelected(date, b) { this.$super(date, b); if (date !== null && b) { if ($this.$freezeCalendar === false) { if ($this.dateSelected !== undefined) { $this.dateSelected.call($this, date, b); } $this.hideCalendar(); } } } ]); } return this.calendar; }
javascript
function getCalendar() { if (this.clazz.$name === undefined) { throw new Error(); } if (this.calendar === undefined || this.calendar === null) { var $this = this; this.$freezeCalendar = false; this.calendar = new pkg.Calendar([ function $clazz() { this.MonthsCombo.$name = "INNER"; }, function winActivated(e) { if (e.isActive === false) { $this.hideCalendar(); } }, function childKeyPressed(e){ if (e.code === "Escape") { $this.hideCalendar(); } }, function dateSelected(date, b) { this.$super(date, b); if (date !== null && b) { if ($this.$freezeCalendar === false) { if ($this.dateSelected !== undefined) { $this.dateSelected.call($this, date, b); } $this.hideCalendar(); } } } ]); } return this.calendar; }
[ "function", "getCalendar", "(", ")", "{", "if", "(", "this", ".", "clazz", ".", "$name", "===", "undefined", ")", "{", "throw", "new", "Error", "(", ")", ";", "}", "if", "(", "this", ".", "calendar", "===", "undefined", "||", "this", ".", "calendar", "===", "null", ")", "{", "var", "$this", "=", "this", ";", "this", ".", "$freezeCalendar", "=", "false", ";", "this", ".", "calendar", "=", "new", "pkg", ".", "Calendar", "(", "[", "function", "$clazz", "(", ")", "{", "this", ".", "MonthsCombo", ".", "$name", "=", "\"INNER\"", ";", "}", ",", "function", "winActivated", "(", "e", ")", "{", "if", "(", "e", ".", "isActive", "===", "false", ")", "{", "$this", ".", "hideCalendar", "(", ")", ";", "}", "}", ",", "function", "childKeyPressed", "(", "e", ")", "{", "if", "(", "e", ".", "code", "===", "\"Escape\"", ")", "{", "$this", ".", "hideCalendar", "(", ")", ";", "}", "}", ",", "function", "dateSelected", "(", "date", ",", "b", ")", "{", "this", ".", "$super", "(", "date", ",", "b", ")", ";", "if", "(", "date", "!==", "null", "&&", "b", ")", "{", "if", "(", "$this", ".", "$freezeCalendar", "===", "false", ")", "{", "if", "(", "$this", ".", "dateSelected", "!==", "undefined", ")", "{", "$this", ".", "dateSelected", ".", "call", "(", "$this", ",", "date", ",", "b", ")", ";", "}", "$this", ".", "hideCalendar", "(", ")", ";", "}", "}", "}", "]", ")", ";", "}", "return", "this", ".", "calendar", ";", "}" ]
Get calendar component. @return {zebkit.ui.date.Calendar} a calendar @method getCalendar
[ "Get", "calendar", "component", "." ]
eea59bcdba9f07158098f3d8c6efd4f80770efad
https://github.com/barmalei/zebkit/blob/eea59bcdba9f07158098f3d8c6efd4f80770efad/src/js/ui/date/ui.date.js#L1405-L1446
17,866
barmalei/zebkit
src/js/ui/date/ui.date.js
showCalendar
function showCalendar(anchor) { try { this.$freezeCalendar = true; this.hideCalendar(); var calendar = this.getCalendar(); this.$anchor = anchor; var c = this.getCanvas(), w = c.getLayer("win"), p = zebkit.layout.toParentOrigin(0, 0, anchor, c); calendar.toPreferredSize(); p.y = p.y + anchor.height; if (p.y + calendar.height > w.height - w.getBottom()) { p.y = p.y - calendar.height - anchor.height - 1; } if (p.x + calendar.width > w.width - w.getRight()) { p.x -= (p.x + calendar.width - w.width + w.getRight()); } calendar.setLocation(p.x, p.y); ui.showWindow(this, "mdi", calendar); ui.activateWindow(calendar); calendar.monthDays.requestFocus(); if (this.calendarShown !== undefined) { this.calendarShown(this.calendar); } } finally { this.$freezeCalendar = false; } return this; }
javascript
function showCalendar(anchor) { try { this.$freezeCalendar = true; this.hideCalendar(); var calendar = this.getCalendar(); this.$anchor = anchor; var c = this.getCanvas(), w = c.getLayer("win"), p = zebkit.layout.toParentOrigin(0, 0, anchor, c); calendar.toPreferredSize(); p.y = p.y + anchor.height; if (p.y + calendar.height > w.height - w.getBottom()) { p.y = p.y - calendar.height - anchor.height - 1; } if (p.x + calendar.width > w.width - w.getRight()) { p.x -= (p.x + calendar.width - w.width + w.getRight()); } calendar.setLocation(p.x, p.y); ui.showWindow(this, "mdi", calendar); ui.activateWindow(calendar); calendar.monthDays.requestFocus(); if (this.calendarShown !== undefined) { this.calendarShown(this.calendar); } } finally { this.$freezeCalendar = false; } return this; }
[ "function", "showCalendar", "(", "anchor", ")", "{", "try", "{", "this", ".", "$freezeCalendar", "=", "true", ";", "this", ".", "hideCalendar", "(", ")", ";", "var", "calendar", "=", "this", ".", "getCalendar", "(", ")", ";", "this", ".", "$anchor", "=", "anchor", ";", "var", "c", "=", "this", ".", "getCanvas", "(", ")", ",", "w", "=", "c", ".", "getLayer", "(", "\"win\"", ")", ",", "p", "=", "zebkit", ".", "layout", ".", "toParentOrigin", "(", "0", ",", "0", ",", "anchor", ",", "c", ")", ";", "calendar", ".", "toPreferredSize", "(", ")", ";", "p", ".", "y", "=", "p", ".", "y", "+", "anchor", ".", "height", ";", "if", "(", "p", ".", "y", "+", "calendar", ".", "height", ">", "w", ".", "height", "-", "w", ".", "getBottom", "(", ")", ")", "{", "p", ".", "y", "=", "p", ".", "y", "-", "calendar", ".", "height", "-", "anchor", ".", "height", "-", "1", ";", "}", "if", "(", "p", ".", "x", "+", "calendar", ".", "width", ">", "w", ".", "width", "-", "w", ".", "getRight", "(", ")", ")", "{", "p", ".", "x", "-=", "(", "p", ".", "x", "+", "calendar", ".", "width", "-", "w", ".", "width", "+", "w", ".", "getRight", "(", ")", ")", ";", "}", "calendar", ".", "setLocation", "(", "p", ".", "x", ",", "p", ".", "y", ")", ";", "ui", ".", "showWindow", "(", "this", ",", "\"mdi\"", ",", "calendar", ")", ";", "ui", ".", "activateWindow", "(", "calendar", ")", ";", "calendar", ".", "monthDays", ".", "requestFocus", "(", ")", ";", "if", "(", "this", ".", "calendarShown", "!==", "undefined", ")", "{", "this", ".", "calendarShown", "(", "this", ".", "calendar", ")", ";", "}", "}", "finally", "{", "this", ".", "$freezeCalendar", "=", "false", ";", "}", "return", "this", ";", "}" ]
Show calendar as popup window for the given anchor component @param {zebkit.ui.Panel} anchor an anchor component. @chainable @method showCalendar
[ "Show", "calendar", "as", "popup", "window", "for", "the", "given", "anchor", "component" ]
eea59bcdba9f07158098f3d8c6efd4f80770efad
https://github.com/barmalei/zebkit/blob/eea59bcdba9f07158098f3d8c6efd4f80770efad/src/js/ui/date/ui.date.js#L1454-L1491
17,867
barmalei/zebkit
src/js/ui/date/ui.date.js
hideCalendar
function hideCalendar() { if (this.calendar !== undefined && this.calendar !== null) { var calendar = this.getCalendar(); if (calendar.parent !== null) { calendar.removeMe(); if (this.calendarHidden !== undefined) { this.calendarHidden(); } this.$anchor.requestFocus(); this.$anchor = null; } } return this; }
javascript
function hideCalendar() { if (this.calendar !== undefined && this.calendar !== null) { var calendar = this.getCalendar(); if (calendar.parent !== null) { calendar.removeMe(); if (this.calendarHidden !== undefined) { this.calendarHidden(); } this.$anchor.requestFocus(); this.$anchor = null; } } return this; }
[ "function", "hideCalendar", "(", ")", "{", "if", "(", "this", ".", "calendar", "!==", "undefined", "&&", "this", ".", "calendar", "!==", "null", ")", "{", "var", "calendar", "=", "this", ".", "getCalendar", "(", ")", ";", "if", "(", "calendar", ".", "parent", "!==", "null", ")", "{", "calendar", ".", "removeMe", "(", ")", ";", "if", "(", "this", ".", "calendarHidden", "!==", "undefined", ")", "{", "this", ".", "calendarHidden", "(", ")", ";", "}", "this", ".", "$anchor", ".", "requestFocus", "(", ")", ";", "this", ".", "$anchor", "=", "null", ";", "}", "}", "return", "this", ";", "}" ]
Hide calendar that has been shown as popup window. @chainable @method hideCalendar
[ "Hide", "calendar", "that", "has", "been", "shown", "as", "popup", "window", "." ]
eea59bcdba9f07158098f3d8c6efd4f80770efad
https://github.com/barmalei/zebkit/blob/eea59bcdba9f07158098f3d8c6efd4f80770efad/src/js/ui/date/ui.date.js#L1498-L1511
17,868
barmalei/zebkit
src/js/ui/date/ui.date.js
setValue
function setValue(d1, d2) { if (compareDates(d1, d2) === 1) { throw new RangeError(); } if (compareDates(d1, this.minDateField.date) !== 0 || compareDates(d2, this.maxDateField.date) !== 0 ) { var prev = this.getValue(); this.minDateField.setValue(d1); this.maxDateField.setValue(d2); this.getCalendar().monthDays.retagModel(); this.fire("dateRangeSelected", [this, prev]); if (this.dateRangeSelected !== undefined) { this.dateRangeSelected(prev); } } }
javascript
function setValue(d1, d2) { if (compareDates(d1, d2) === 1) { throw new RangeError(); } if (compareDates(d1, this.minDateField.date) !== 0 || compareDates(d2, this.maxDateField.date) !== 0 ) { var prev = this.getValue(); this.minDateField.setValue(d1); this.maxDateField.setValue(d2); this.getCalendar().monthDays.retagModel(); this.fire("dateRangeSelected", [this, prev]); if (this.dateRangeSelected !== undefined) { this.dateRangeSelected(prev); } } }
[ "function", "setValue", "(", "d1", ",", "d2", ")", "{", "if", "(", "compareDates", "(", "d1", ",", "d2", ")", "===", "1", ")", "{", "throw", "new", "RangeError", "(", ")", ";", "}", "if", "(", "compareDates", "(", "d1", ",", "this", ".", "minDateField", ".", "date", ")", "!==", "0", "||", "compareDates", "(", "d2", ",", "this", ".", "maxDateField", ".", "date", ")", "!==", "0", ")", "{", "var", "prev", "=", "this", ".", "getValue", "(", ")", ";", "this", ".", "minDateField", ".", "setValue", "(", "d1", ")", ";", "this", ".", "maxDateField", ".", "setValue", "(", "d2", ")", ";", "this", ".", "getCalendar", "(", ")", ".", "monthDays", ".", "retagModel", "(", ")", ";", "this", ".", "fire", "(", "\"dateRangeSelected\"", ",", "[", "this", ",", "prev", "]", ")", ";", "if", "(", "this", ".", "dateRangeSelected", "!==", "undefined", ")", "{", "this", ".", "dateRangeSelected", "(", "prev", ")", ";", "}", "}", "}" ]
Set the given date range. @param {Date} d1 a minimal possible date @param {Date} d2 a maximal possible date @method setValue
[ "Set", "the", "given", "date", "range", "." ]
eea59bcdba9f07158098f3d8c6efd4f80770efad
https://github.com/barmalei/zebkit/blob/eea59bcdba9f07158098f3d8c6efd4f80770efad/src/js/ui/date/ui.date.js#L1714-L1733
17,869
barmalei/zebkit
src/js/oop.js
$cpMethods
function $cpMethods(src, dest, clazz) { var overriddenAbstractMethods = 0; for(var name in src) { if (name !== CNAME && name !== "clazz" && src.hasOwnProperty(name) ) { var method = src[name]; if (typeof method === "function" && method !== $toString) { if (name === "$prototype") { method.call(dest, clazz); } else { // TODO analyze if we overwrite existent field if (dest[name] !== undefined) { // abstract method is overridden, let's skip abstract method // stub implementation if (method.$isAbstract === true) { overriddenAbstractMethods++; continue; } if (dest[name].boundTo === clazz) { throw new Error("Method '" + name + "(...)'' bound to this class already exists"); } } if (method.methodBody !== undefined) { dest[name] = $ProxyMethod(name, method.methodBody, clazz); } else { dest[name] = $ProxyMethod(name, method, clazz); } // save information about abstract method if (method.$isAbstract === true) { dest[name].$isAbstract = true; } } } } } return overriddenAbstractMethods; }
javascript
function $cpMethods(src, dest, clazz) { var overriddenAbstractMethods = 0; for(var name in src) { if (name !== CNAME && name !== "clazz" && src.hasOwnProperty(name) ) { var method = src[name]; if (typeof method === "function" && method !== $toString) { if (name === "$prototype") { method.call(dest, clazz); } else { // TODO analyze if we overwrite existent field if (dest[name] !== undefined) { // abstract method is overridden, let's skip abstract method // stub implementation if (method.$isAbstract === true) { overriddenAbstractMethods++; continue; } if (dest[name].boundTo === clazz) { throw new Error("Method '" + name + "(...)'' bound to this class already exists"); } } if (method.methodBody !== undefined) { dest[name] = $ProxyMethod(name, method.methodBody, clazz); } else { dest[name] = $ProxyMethod(name, method, clazz); } // save information about abstract method if (method.$isAbstract === true) { dest[name].$isAbstract = true; } } } } } return overriddenAbstractMethods; }
[ "function", "$cpMethods", "(", "src", ",", "dest", ",", "clazz", ")", "{", "var", "overriddenAbstractMethods", "=", "0", ";", "for", "(", "var", "name", "in", "src", ")", "{", "if", "(", "name", "!==", "CNAME", "&&", "name", "!==", "\"clazz\"", "&&", "src", ".", "hasOwnProperty", "(", "name", ")", ")", "{", "var", "method", "=", "src", "[", "name", "]", ";", "if", "(", "typeof", "method", "===", "\"function\"", "&&", "method", "!==", "$toString", ")", "{", "if", "(", "name", "===", "\"$prototype\"", ")", "{", "method", ".", "call", "(", "dest", ",", "clazz", ")", ";", "}", "else", "{", "// TODO analyze if we overwrite existent field", "if", "(", "dest", "[", "name", "]", "!==", "undefined", ")", "{", "// abstract method is overridden, let's skip abstract method", "// stub implementation", "if", "(", "method", ".", "$isAbstract", "===", "true", ")", "{", "overriddenAbstractMethods", "++", ";", "continue", ";", "}", "if", "(", "dest", "[", "name", "]", ".", "boundTo", "===", "clazz", ")", "{", "throw", "new", "Error", "(", "\"Method '\"", "+", "name", "+", "\"(...)'' bound to this class already exists\"", ")", ";", "}", "}", "if", "(", "method", ".", "methodBody", "!==", "undefined", ")", "{", "dest", "[", "name", "]", "=", "$ProxyMethod", "(", "name", ",", "method", ".", "methodBody", ",", "clazz", ")", ";", "}", "else", "{", "dest", "[", "name", "]", "=", "$ProxyMethod", "(", "name", ",", "method", ",", "clazz", ")", ";", "}", "// save information about abstract method", "if", "(", "method", ".", "$isAbstract", "===", "true", ")", "{", "dest", "[", "name", "]", ".", "$isAbstract", "=", "true", ";", "}", "}", "}", "}", "}", "return", "overriddenAbstractMethods", ";", "}" ]
copy methods from source to destination
[ "copy", "methods", "from", "source", "to", "destination" ]
eea59bcdba9f07158098f3d8c6efd4f80770efad
https://github.com/barmalei/zebkit/blob/eea59bcdba9f07158098f3d8c6efd4f80770efad/src/js/oop.js#L100-L141
17,870
barmalei/zebkit
src/js/oop.js
newInstance
function newInstance(clazz, args) { if (arguments.length > 1 && args.length > 0) { var f = function () {}; f.prototype = clazz.prototype; var o = new f(); clazz.apply(o, args); return o; } return new clazz(); }
javascript
function newInstance(clazz, args) { if (arguments.length > 1 && args.length > 0) { var f = function () {}; f.prototype = clazz.prototype; var o = new f(); clazz.apply(o, args); return o; } return new clazz(); }
[ "function", "newInstance", "(", "clazz", ",", "args", ")", "{", "if", "(", "arguments", ".", "length", ">", "1", "&&", "args", ".", "length", ">", "0", ")", "{", "var", "f", "=", "function", "(", ")", "{", "}", ";", "f", ".", "prototype", "=", "clazz", ".", "prototype", ";", "var", "o", "=", "new", "f", "(", ")", ";", "clazz", ".", "apply", "(", "o", ",", "args", ")", ";", "return", "o", ";", "}", "return", "new", "clazz", "(", ")", ";", "}" ]
Instantiate a new class instance of the given class with the specified constructor arguments. @param {Function} clazz a class @param {Array} [args] an arguments list @return {Object} a new instance of the given class initialized with the specified arguments @method newInstance @for zebkit
[ "Instantiate", "a", "new", "class", "instance", "of", "the", "given", "class", "with", "the", "specified", "constructor", "arguments", "." ]
eea59bcdba9f07158098f3d8c6efd4f80770efad
https://github.com/barmalei/zebkit/blob/eea59bcdba9f07158098f3d8c6efd4f80770efad/src/js/oop.js#L304-L314
17,871
barmalei/zebkit
src/js/oop.js
function() { var methods = arguments[arguments.length - 1], hasMethod = Array.isArray(methods); // inject class if (hasMethod && this.$isExtended !== true) { // create intermediate class var A = this.$parent !== null ? Class(this.$parent, []) : Class([]); // copy this class prototypes methods to intermediate class A and re-define // boundTo to the intermediate class A if they were bound to source class // methods that have been moved from source class to class have to be re-bound // to A class for(var name in this.prototype) { if (name !== "clazz" && this.prototype.hasOwnProperty(name) ) { var f = this.prototype[name]; if (typeof f === 'function') { A.prototype[name] = f.methodBody !== undefined ? $ProxyMethod(name, f.methodBody, f.boundTo) : f; if (A.prototype[name].boundTo === this) { A.prototype[name].boundTo = A; if (f.boundTo === this) { f.boundTo = A; } } } } } this.$parent = A; this.$isExtended = true; } if (hasMethod) { $mixing(this, methods); } // add passed interfaces for(var i = 0; i < arguments.length - (hasMethod ? 1 : 0); i++) { var I = arguments[i]; if (I === null || I === undefined || I.clazz !== Interface) { throw new Error("Interface is expected"); } if (this.$parents[I.$hash$] !== undefined) { throw new Error("Interface has been already inherited"); } $cpMethods(I.prototype, this.prototype, this); this.$parents[I.$hash$] = I; } return this; }
javascript
function() { var methods = arguments[arguments.length - 1], hasMethod = Array.isArray(methods); // inject class if (hasMethod && this.$isExtended !== true) { // create intermediate class var A = this.$parent !== null ? Class(this.$parent, []) : Class([]); // copy this class prototypes methods to intermediate class A and re-define // boundTo to the intermediate class A if they were bound to source class // methods that have been moved from source class to class have to be re-bound // to A class for(var name in this.prototype) { if (name !== "clazz" && this.prototype.hasOwnProperty(name) ) { var f = this.prototype[name]; if (typeof f === 'function') { A.prototype[name] = f.methodBody !== undefined ? $ProxyMethod(name, f.methodBody, f.boundTo) : f; if (A.prototype[name].boundTo === this) { A.prototype[name].boundTo = A; if (f.boundTo === this) { f.boundTo = A; } } } } } this.$parent = A; this.$isExtended = true; } if (hasMethod) { $mixing(this, methods); } // add passed interfaces for(var i = 0; i < arguments.length - (hasMethod ? 1 : 0); i++) { var I = arguments[i]; if (I === null || I === undefined || I.clazz !== Interface) { throw new Error("Interface is expected"); } if (this.$parents[I.$hash$] !== undefined) { throw new Error("Interface has been already inherited"); } $cpMethods(I.prototype, this.prototype, this); this.$parents[I.$hash$] = I; } return this; }
[ "function", "(", ")", "{", "var", "methods", "=", "arguments", "[", "arguments", ".", "length", "-", "1", "]", ",", "hasMethod", "=", "Array", ".", "isArray", "(", "methods", ")", ";", "// inject class", "if", "(", "hasMethod", "&&", "this", ".", "$isExtended", "!==", "true", ")", "{", "// create intermediate class", "var", "A", "=", "this", ".", "$parent", "!==", "null", "?", "Class", "(", "this", ".", "$parent", ",", "[", "]", ")", ":", "Class", "(", "[", "]", ")", ";", "// copy this class prototypes methods to intermediate class A and re-define", "// boundTo to the intermediate class A if they were bound to source class", "// methods that have been moved from source class to class have to be re-bound", "// to A class", "for", "(", "var", "name", "in", "this", ".", "prototype", ")", "{", "if", "(", "name", "!==", "\"clazz\"", "&&", "this", ".", "prototype", ".", "hasOwnProperty", "(", "name", ")", ")", "{", "var", "f", "=", "this", ".", "prototype", "[", "name", "]", ";", "if", "(", "typeof", "f", "===", "'function'", ")", "{", "A", ".", "prototype", "[", "name", "]", "=", "f", ".", "methodBody", "!==", "undefined", "?", "$ProxyMethod", "(", "name", ",", "f", ".", "methodBody", ",", "f", ".", "boundTo", ")", ":", "f", ";", "if", "(", "A", ".", "prototype", "[", "name", "]", ".", "boundTo", "===", "this", ")", "{", "A", ".", "prototype", "[", "name", "]", ".", "boundTo", "=", "A", ";", "if", "(", "f", ".", "boundTo", "===", "this", ")", "{", "f", ".", "boundTo", "=", "A", ";", "}", "}", "}", "}", "}", "this", ".", "$parent", "=", "A", ";", "this", ".", "$isExtended", "=", "true", ";", "}", "if", "(", "hasMethod", ")", "{", "$mixing", "(", "this", ",", "methods", ")", ";", "}", "// add passed interfaces", "for", "(", "var", "i", "=", "0", ";", "i", "<", "arguments", ".", "length", "-", "(", "hasMethod", "?", "1", ":", "0", ")", ";", "i", "++", ")", "{", "var", "I", "=", "arguments", "[", "i", "]", ";", "if", "(", "I", "===", "null", "||", "I", "===", "undefined", "||", "I", ".", "clazz", "!==", "Interface", ")", "{", "throw", "new", "Error", "(", "\"Interface is expected\"", ")", ";", "}", "if", "(", "this", ".", "$parents", "[", "I", ".", "$hash$", "]", "!==", "undefined", ")", "{", "throw", "new", "Error", "(", "\"Interface has been already inherited\"", ")", ";", "}", "$cpMethods", "(", "I", ".", "prototype", ",", "this", ".", "prototype", ",", "this", ")", ";", "this", ".", "$parents", "[", "I", ".", "$hash$", "]", "=", "I", ";", "}", "return", "this", ";", "}" ]
Extend the class with new method and implemented interfaces. @param {zebkit.Interface} [interfaces]* number of interfaces the class has to implement. @param {Array} methods set of methods the given class has to be extended. @method extend @chainable @for zebkit.Class add extend method later to avoid the method be inherited as a class static field
[ "Extend", "the", "class", "with", "new", "method", "and", "implemented", "interfaces", "." ]
eea59bcdba9f07158098f3d8c6efd4f80770efad
https://github.com/barmalei/zebkit/blob/eea59bcdba9f07158098f3d8c6efd4f80770efad/src/js/oop.js#L689-L744
17,872
barmalei/zebkit
src/js/oop.js
function(clazz) { if (this !== clazz) { // detect class if (clazz.clazz === this.clazz) { for (var p = this.$parent; p !== null; p = p.$parent) { if (p === clazz) { return true; } } } else { // detect interface if (this.$parents[clazz.$hash$] === clazz) { return true; } } } return false; }
javascript
function(clazz) { if (this !== clazz) { // detect class if (clazz.clazz === this.clazz) { for (var p = this.$parent; p !== null; p = p.$parent) { if (p === clazz) { return true; } } } else { // detect interface if (this.$parents[clazz.$hash$] === clazz) { return true; } } } return false; }
[ "function", "(", "clazz", ")", "{", "if", "(", "this", "!==", "clazz", ")", "{", "// detect class", "if", "(", "clazz", ".", "clazz", "===", "this", ".", "clazz", ")", "{", "for", "(", "var", "p", "=", "this", ".", "$parent", ";", "p", "!==", "null", ";", "p", "=", "p", ".", "$parent", ")", "{", "if", "(", "p", "===", "clazz", ")", "{", "return", "true", ";", "}", "}", "}", "else", "{", "// detect interface", "if", "(", "this", ".", "$parents", "[", "clazz", ".", "$hash$", "]", "===", "clazz", ")", "{", "return", "true", ";", "}", "}", "}", "return", "false", ";", "}" ]
Tests if the class inherits the given class or interface. @param {zebkit.Class | zebkit.Interface} clazz a class or interface. @return {Boolean} true if the class or interface is inherited with the class. @method isInherit @for zebkit.Class
[ "Tests", "if", "the", "class", "inherits", "the", "given", "class", "or", "interface", "." ]
eea59bcdba9f07158098f3d8c6efd4f80770efad
https://github.com/barmalei/zebkit/blob/eea59bcdba9f07158098f3d8c6efd4f80770efad/src/js/oop.js#L754-L770
17,873
barmalei/zebkit
src/js/oop.js
function(name) { if ($caller !== null) { for(var $s = $caller.boundTo.$parent; $s !== null; $s = $s.$parent) { var m = $s.prototype[name]; if (typeof m === 'function') { return m; } } return null; } throw new Error("$super is called outside of class context"); }
javascript
function(name) { if ($caller !== null) { for(var $s = $caller.boundTo.$parent; $s !== null; $s = $s.$parent) { var m = $s.prototype[name]; if (typeof m === 'function') { return m; } } return null; } throw new Error("$super is called outside of class context"); }
[ "function", "(", "name", ")", "{", "if", "(", "$caller", "!==", "null", ")", "{", "for", "(", "var", "$s", "=", "$caller", ".", "boundTo", ".", "$parent", ";", "$s", "!==", "null", ";", "$s", "=", "$s", ".", "$parent", ")", "{", "var", "m", "=", "$s", ".", "prototype", "[", "name", "]", ";", "if", "(", "typeof", "m", "===", "'function'", ")", "{", "return", "m", ";", "}", "}", "return", "null", ";", "}", "throw", "new", "Error", "(", "\"$super is called outside of class context\"", ")", ";", "}" ]
Get a first super implementation of the given method in a parent classes hierarchy. @param {String} name a name of the method @return {Function} a super method implementation @method $getSuper @for zebkit.Class.zObject
[ "Get", "a", "first", "super", "implementation", "of", "the", "given", "method", "in", "a", "parent", "classes", "hierarchy", "." ]
eea59bcdba9f07158098f3d8c6efd4f80770efad
https://github.com/barmalei/zebkit/blob/eea59bcdba9f07158098f3d8c6efd4f80770efad/src/js/oop.js#L972-L983
17,874
barmalei/zebkit
src/js/oop.js
instanceOf
function instanceOf(obj, clazz) { if (clazz !== null && clazz !== undefined) { if (obj === null || obj === undefined) { return false; } else if (obj.clazz === undefined) { return (obj instanceof clazz); } else { return obj.clazz !== null && (obj.clazz === clazz || obj.clazz.$parents[clazz.$hash$] !== undefined); } } throw new Error("instanceOf(): null class"); }
javascript
function instanceOf(obj, clazz) { if (clazz !== null && clazz !== undefined) { if (obj === null || obj === undefined) { return false; } else if (obj.clazz === undefined) { return (obj instanceof clazz); } else { return obj.clazz !== null && (obj.clazz === clazz || obj.clazz.$parents[clazz.$hash$] !== undefined); } } throw new Error("instanceOf(): null class"); }
[ "function", "instanceOf", "(", "obj", ",", "clazz", ")", "{", "if", "(", "clazz", "!==", "null", "&&", "clazz", "!==", "undefined", ")", "{", "if", "(", "obj", "===", "null", "||", "obj", "===", "undefined", ")", "{", "return", "false", ";", "}", "else", "if", "(", "obj", ".", "clazz", "===", "undefined", ")", "{", "return", "(", "obj", "instanceof", "clazz", ")", ";", "}", "else", "{", "return", "obj", ".", "clazz", "!==", "null", "&&", "(", "obj", ".", "clazz", "===", "clazz", "||", "obj", ".", "clazz", ".", "$parents", "[", "clazz", ".", "$hash$", "]", "!==", "undefined", ")", ";", "}", "}", "throw", "new", "Error", "(", "\"instanceOf(): null class\"", ")", ";", "}" ]
Test if the given object is instance of the specified class or interface. It is preferable to use this method instead of JavaScript "instanceof" operator whenever you are dealing with zebkit classes and interfaces. @param {Object} obj an object to be evaluated @param {Function} clazz a class or interface @return {Boolean} true if a passed object is instance of the given class or interface @method instanceOf @for zebkit
[ "Test", "if", "the", "given", "object", "is", "instance", "of", "the", "specified", "class", "or", "interface", ".", "It", "is", "preferable", "to", "use", "this", "method", "instead", "of", "JavaScript", "instanceof", "operator", "whenever", "you", "are", "dealing", "with", "zebkit", "classes", "and", "interfaces", "." ]
eea59bcdba9f07158098f3d8c6efd4f80770efad
https://github.com/barmalei/zebkit/blob/eea59bcdba9f07158098f3d8c6efd4f80770efad/src/js/oop.js#L1268-L1282
17,875
RadLikeWhoa/Countable
Countable.js
validateArguments
function validateArguments (targets, callback) { const nodes = Object.prototype.toString.call(targets) const targetsValid = typeof targets === 'string' || ((nodes === '[object NodeList]' || nodes === '[object HTMLCollection]') || targets.nodeType === 1) const callbackValid = typeof callback === 'function' if (!targetsValid) console.error('Countable: Not a valid target') if (!callbackValid) console.error('Countable: Not a valid callback function') return targetsValid && callbackValid }
javascript
function validateArguments (targets, callback) { const nodes = Object.prototype.toString.call(targets) const targetsValid = typeof targets === 'string' || ((nodes === '[object NodeList]' || nodes === '[object HTMLCollection]') || targets.nodeType === 1) const callbackValid = typeof callback === 'function' if (!targetsValid) console.error('Countable: Not a valid target') if (!callbackValid) console.error('Countable: Not a valid callback function') return targetsValid && callbackValid }
[ "function", "validateArguments", "(", "targets", ",", "callback", ")", "{", "const", "nodes", "=", "Object", ".", "prototype", ".", "toString", ".", "call", "(", "targets", ")", "const", "targetsValid", "=", "typeof", "targets", "===", "'string'", "||", "(", "(", "nodes", "===", "'[object NodeList]'", "||", "nodes", "===", "'[object HTMLCollection]'", ")", "||", "targets", ".", "nodeType", "===", "1", ")", "const", "callbackValid", "=", "typeof", "callback", "===", "'function'", "if", "(", "!", "targetsValid", ")", "console", ".", "error", "(", "'Countable: Not a valid target'", ")", "if", "(", "!", "callbackValid", ")", "console", ".", "error", "(", "'Countable: Not a valid callback function'", ")", "return", "targetsValid", "&&", "callbackValid", "}" ]
`validateArguments` validates the arguments given to each function call. Errors are logged to the console as warnings, but Countable fails silently. @private @param {Nodes|String} targets A (collection of) element(s) or a single string to validate. @param {Function} callback The callback function to validate. @return {Boolean} Returns whether all arguments are vaild.
[ "validateArguments", "validates", "the", "arguments", "given", "to", "each", "function", "call", ".", "Errors", "are", "logged", "to", "the", "console", "as", "warnings", "but", "Countable", "fails", "silently", "." ]
4d2812d7b53736d2bca4268b783997545d261c43
https://github.com/RadLikeWhoa/Countable/blob/4d2812d7b53736d2bca4268b783997545d261c43/Countable.js#L92-L101
17,876
RadLikeWhoa/Countable
Countable.js
function (elements, callback, options) { if (!validateArguments(elements, callback)) return if (!Array.isArray(elements)) { elements = [ elements ] } each.call(elements, function (e) { const handler = function () { callback.call(e, count(e, options)) } liveElements.push({ element: e, handler: handler }) handler() e.addEventListener('input', handler) }) return this }
javascript
function (elements, callback, options) { if (!validateArguments(elements, callback)) return if (!Array.isArray(elements)) { elements = [ elements ] } each.call(elements, function (e) { const handler = function () { callback.call(e, count(e, options)) } liveElements.push({ element: e, handler: handler }) handler() e.addEventListener('input', handler) }) return this }
[ "function", "(", "elements", ",", "callback", ",", "options", ")", "{", "if", "(", "!", "validateArguments", "(", "elements", ",", "callback", ")", ")", "return", "if", "(", "!", "Array", ".", "isArray", "(", "elements", ")", ")", "{", "elements", "=", "[", "elements", "]", "}", "each", ".", "call", "(", "elements", ",", "function", "(", "e", ")", "{", "const", "handler", "=", "function", "(", ")", "{", "callback", ".", "call", "(", "e", ",", "count", "(", "e", ",", "options", ")", ")", "}", "liveElements", ".", "push", "(", "{", "element", ":", "e", ",", "handler", ":", "handler", "}", ")", "handler", "(", ")", "e", ".", "addEventListener", "(", "'input'", ",", "handler", ")", "}", ")", "return", "this", "}" ]
The `on` method binds the counting handler to all given elements. The event is either `oninput` or `onkeydown`, based on the capabilities of the browser. @param {Nodes} elements All elements that should receive the Countable functionality. @param {Function} callback The callback to fire whenever the element's value changes. The callback is called with the relevant element bound to `this` and the counted values as the single parameter. @param {Object} [options] An object to modify Countable's behaviour. @return {Object} Returns the Countable object to allow for chaining.
[ "The", "on", "method", "binds", "the", "counting", "handler", "to", "all", "given", "elements", ".", "The", "event", "is", "either", "oninput", "or", "onkeydown", "based", "on", "the", "capabilities", "of", "the", "browser", "." ]
4d2812d7b53736d2bca4268b783997545d261c43
https://github.com/RadLikeWhoa/Countable/blob/4d2812d7b53736d2bca4268b783997545d261c43/Countable.js#L194-L214
17,877
RadLikeWhoa/Countable
Countable.js
function (elements) { if (!validateArguments(elements, function () {})) return if (!Array.isArray(elements)) { elements = [ elements ] } liveElements.filter(function (e) { return elements.indexOf(e.element) !== -1 }).forEach(function (e) { e.element.removeEventListener('input', e.handler) }) liveElements = liveElements.filter(function (e) { return elements.indexOf(e.element) === -1 }) return this }
javascript
function (elements) { if (!validateArguments(elements, function () {})) return if (!Array.isArray(elements)) { elements = [ elements ] } liveElements.filter(function (e) { return elements.indexOf(e.element) !== -1 }).forEach(function (e) { e.element.removeEventListener('input', e.handler) }) liveElements = liveElements.filter(function (e) { return elements.indexOf(e.element) === -1 }) return this }
[ "function", "(", "elements", ")", "{", "if", "(", "!", "validateArguments", "(", "elements", ",", "function", "(", ")", "{", "}", ")", ")", "return", "if", "(", "!", "Array", ".", "isArray", "(", "elements", ")", ")", "{", "elements", "=", "[", "elements", "]", "}", "liveElements", ".", "filter", "(", "function", "(", "e", ")", "{", "return", "elements", ".", "indexOf", "(", "e", ".", "element", ")", "!==", "-", "1", "}", ")", ".", "forEach", "(", "function", "(", "e", ")", "{", "e", ".", "element", ".", "removeEventListener", "(", "'input'", ",", "e", ".", "handler", ")", "}", ")", "liveElements", "=", "liveElements", ".", "filter", "(", "function", "(", "e", ")", "{", "return", "elements", ".", "indexOf", "(", "e", ".", "element", ")", "===", "-", "1", "}", ")", "return", "this", "}" ]
The `off` method removes the Countable functionality from all given elements. @param {Nodes} elements All elements whose Countable functionality should be unbound. @return {Object} Returns the Countable object to allow for chaining.
[ "The", "off", "method", "removes", "the", "Countable", "functionality", "from", "all", "given", "elements", "." ]
4d2812d7b53736d2bca4268b783997545d261c43
https://github.com/RadLikeWhoa/Countable/blob/4d2812d7b53736d2bca4268b783997545d261c43/Countable.js#L226-L244
17,878
RadLikeWhoa/Countable
Countable.js
function (targets, callback, options) { if (!validateArguments(targets, callback)) return if (!Array.isArray(targets)) { targets = [ targets ] } each.call(targets, function (e) { callback.call(e, count(e, options)) }) return this }
javascript
function (targets, callback, options) { if (!validateArguments(targets, callback)) return if (!Array.isArray(targets)) { targets = [ targets ] } each.call(targets, function (e) { callback.call(e, count(e, options)) }) return this }
[ "function", "(", "targets", ",", "callback", ",", "options", ")", "{", "if", "(", "!", "validateArguments", "(", "targets", ",", "callback", ")", ")", "return", "if", "(", "!", "Array", ".", "isArray", "(", "targets", ")", ")", "{", "targets", "=", "[", "targets", "]", "}", "each", ".", "call", "(", "targets", ",", "function", "(", "e", ")", "{", "callback", ".", "call", "(", "e", ",", "count", "(", "e", ",", "options", ")", ")", "}", ")", "return", "this", "}" ]
The `count` method works mostly like the `live` method, but no events are bound, the functionality is only executed once. @param {Nodes|String} targets All elements that should be counted. @param {Function} callback The callback to fire whenever the element's value changes. The callback is called with the relevant element bound to `this` and the counted values as the single parameter. @param {Object} [options] An object to modify Countable's behaviour. @return {Object} Returns the Countable object to allow for chaining.
[ "The", "count", "method", "works", "mostly", "like", "the", "live", "method", "but", "no", "events", "are", "bound", "the", "functionality", "is", "only", "executed", "once", "." ]
4d2812d7b53736d2bca4268b783997545d261c43
https://github.com/RadLikeWhoa/Countable/blob/4d2812d7b53736d2bca4268b783997545d261c43/Countable.js#L264-L276
17,879
RadLikeWhoa/Countable
Countable.js
function (elements) { if (elements.length === undefined) { elements = [ elements ] } return liveElements.filter(function (e) { return elements.indexOf(e.element) !== -1 }).length === elements.length }
javascript
function (elements) { if (elements.length === undefined) { elements = [ elements ] } return liveElements.filter(function (e) { return elements.indexOf(e.element) !== -1 }).length === elements.length }
[ "function", "(", "elements", ")", "{", "if", "(", "elements", ".", "length", "===", "undefined", ")", "{", "elements", "=", "[", "elements", "]", "}", "return", "liveElements", ".", "filter", "(", "function", "(", "e", ")", "{", "return", "elements", ".", "indexOf", "(", "e", ".", "element", ")", "!==", "-", "1", "}", ")", ".", "length", "===", "elements", ".", "length", "}" ]
The `enabled` method checks if the live-counting functionality is bound to an element. @param {Node} element All elements that should be checked for the Countable functionality. @return {Boolean} A boolean value representing whether Countable functionality is bound to all given elements.
[ "The", "enabled", "method", "checks", "if", "the", "live", "-", "counting", "functionality", "is", "bound", "to", "an", "element", "." ]
4d2812d7b53736d2bca4268b783997545d261c43
https://github.com/RadLikeWhoa/Countable/blob/4d2812d7b53736d2bca4268b783997545d261c43/Countable.js#L289-L297
17,880
IonicaBizau/node-cobol
lib/run/index.js
Run
function Run(path, options, callback) { var p = Spawn(path, options.args), err = "", data = ""; if (options.remove !== false) { Fs.unlink(path, () => {}); } if (options.stdin) { options.stdin.pipe(p.stdin); } if (options.stdout) { p.stdout.pipe(options.stdout); } else { p.stdout.on("data", function (chunk) { data += chunk.toString(); }); } if (options.stderr) { p.stderr.pipe(options.stderr); } else { p.stderr.on("data", function (err) { err += err.toString(); }); } p.on("close", function () { callback([null, err][Number(!!err)], data.slice(0, -1)); }); }
javascript
function Run(path, options, callback) { var p = Spawn(path, options.args), err = "", data = ""; if (options.remove !== false) { Fs.unlink(path, () => {}); } if (options.stdin) { options.stdin.pipe(p.stdin); } if (options.stdout) { p.stdout.pipe(options.stdout); } else { p.stdout.on("data", function (chunk) { data += chunk.toString(); }); } if (options.stderr) { p.stderr.pipe(options.stderr); } else { p.stderr.on("data", function (err) { err += err.toString(); }); } p.on("close", function () { callback([null, err][Number(!!err)], data.slice(0, -1)); }); }
[ "function", "Run", "(", "path", ",", "options", ",", "callback", ")", "{", "var", "p", "=", "Spawn", "(", "path", ",", "options", ".", "args", ")", ",", "err", "=", "\"\"", ",", "data", "=", "\"\"", ";", "if", "(", "options", ".", "remove", "!==", "false", ")", "{", "Fs", ".", "unlink", "(", "path", ",", "(", ")", "=>", "{", "}", ")", ";", "}", "if", "(", "options", ".", "stdin", ")", "{", "options", ".", "stdin", ".", "pipe", "(", "p", ".", "stdin", ")", ";", "}", "if", "(", "options", ".", "stdout", ")", "{", "p", ".", "stdout", ".", "pipe", "(", "options", ".", "stdout", ")", ";", "}", "else", "{", "p", ".", "stdout", ".", "on", "(", "\"data\"", ",", "function", "(", "chunk", ")", "{", "data", "+=", "chunk", ".", "toString", "(", ")", ";", "}", ")", ";", "}", "if", "(", "options", ".", "stderr", ")", "{", "p", ".", "stderr", ".", "pipe", "(", "options", ".", "stderr", ")", ";", "}", "else", "{", "p", ".", "stderr", ".", "on", "(", "\"data\"", ",", "function", "(", "err", ")", "{", "err", "+=", "err", ".", "toString", "(", ")", ";", "}", ")", ";", "}", "p", ".", "on", "(", "\"close\"", ",", "function", "(", ")", "{", "callback", "(", "[", "null", ",", "err", "]", "[", "Number", "(", "!", "!", "err", ")", "]", ",", "data", ".", "slice", "(", "0", ",", "-", "1", ")", ")", ";", "}", ")", ";", "}" ]
Run Runs the executable output. @name Run @function @param {String} path The executable path. @param {Object} options An object containing the following fields: @param {Function} callback The callback function.
[ "Run", "Runs", "the", "executable", "output", "." ]
b3084a8262166a324dcaf54d976f6f3f8712b2a1
https://github.com/IonicaBizau/node-cobol/blob/b3084a8262166a324dcaf54d976f6f3f8712b2a1/lib/run/index.js#L17-L49
17,881
IonicaBizau/node-cobol
lib/move/index.js
Move
function Move(old, cwd, callback) { var n = Path.join(cwd, Path.basename(old)); Fs.rename(old, n, function (err) { callback(null, [old, n][Number(!err)]); }); }
javascript
function Move(old, cwd, callback) { var n = Path.join(cwd, Path.basename(old)); Fs.rename(old, n, function (err) { callback(null, [old, n][Number(!err)]); }); }
[ "function", "Move", "(", "old", ",", "cwd", ",", "callback", ")", "{", "var", "n", "=", "Path", ".", "join", "(", "cwd", ",", "Path", ".", "basename", "(", "old", ")", ")", ";", "Fs", ".", "rename", "(", "old", ",", "n", ",", "function", "(", "err", ")", "{", "callback", "(", "null", ",", "[", "old", ",", "n", "]", "[", "Number", "(", "!", "err", ")", "]", ")", ";", "}", ")", ";", "}" ]
Move Moves the executable file into another directory. @name Move @function @param {String} old The old executable path. @param {String} cwd The destination folder (most probably the current working directory). @param {Function} callback The callback function.
[ "Move", "Moves", "the", "executable", "file", "into", "another", "directory", "." ]
b3084a8262166a324dcaf54d976f6f3f8712b2a1
https://github.com/IonicaBizau/node-cobol/blob/b3084a8262166a324dcaf54d976f6f3f8712b2a1/lib/move/index.js#L17-L22
17,882
IonicaBizau/node-cobol
lib/compile/index.js
Compile
function Compile(input, options, callback) { var output = Path.join(options.cwd, Path.basename(input).slice(0, -4)); if (options.precompiled) { callback(null, output); } else { CheckCobc(function (exists) { if (!exists) { return callback(new Error("Couldn't find the cobc executable in the PATH. Make sure you installed Open Cobol.")); } var args = { x: true, _: input }; Object.assign(args, options.compileargs); Exec(OArgv(args, "cobc"), { cwd: options.cwd }, function (err, stdout, stderr) { if (stderr || err) { return callback(stderr || err); } callback(null, output); }); }); } }
javascript
function Compile(input, options, callback) { var output = Path.join(options.cwd, Path.basename(input).slice(0, -4)); if (options.precompiled) { callback(null, output); } else { CheckCobc(function (exists) { if (!exists) { return callback(new Error("Couldn't find the cobc executable in the PATH. Make sure you installed Open Cobol.")); } var args = { x: true, _: input }; Object.assign(args, options.compileargs); Exec(OArgv(args, "cobc"), { cwd: options.cwd }, function (err, stdout, stderr) { if (stderr || err) { return callback(stderr || err); } callback(null, output); }); }); } }
[ "function", "Compile", "(", "input", ",", "options", ",", "callback", ")", "{", "var", "output", "=", "Path", ".", "join", "(", "options", ".", "cwd", ",", "Path", ".", "basename", "(", "input", ")", ".", "slice", "(", "0", ",", "-", "4", ")", ")", ";", "if", "(", "options", ".", "precompiled", ")", "{", "callback", "(", "null", ",", "output", ")", ";", "}", "else", "{", "CheckCobc", "(", "function", "(", "exists", ")", "{", "if", "(", "!", "exists", ")", "{", "return", "callback", "(", "new", "Error", "(", "\"Couldn't find the cobc executable in the PATH. Make sure you installed Open Cobol.\"", ")", ")", ";", "}", "var", "args", "=", "{", "x", ":", "true", ",", "_", ":", "input", "}", ";", "Object", ".", "assign", "(", "args", ",", "options", ".", "compileargs", ")", ";", "Exec", "(", "OArgv", "(", "args", ",", "\"cobc\"", ")", ",", "{", "cwd", ":", "options", ".", "cwd", "}", ",", "function", "(", "err", ",", "stdout", ",", "stderr", ")", "{", "if", "(", "stderr", "||", "err", ")", "{", "return", "callback", "(", "stderr", "||", "err", ")", ";", "}", "callback", "(", "null", ",", "output", ")", ";", "}", ")", ";", "}", ")", ";", "}", "}" ]
Compile Compiles the cobol file. @name Compile @function @param {String} input The path to the cobol file. @param {Object} options An object containing the following fields: @param {Function} callback The callback function.
[ "Compile", "Compiles", "the", "cobol", "file", "." ]
b3084a8262166a324dcaf54d976f6f3f8712b2a1
https://github.com/IonicaBizau/node-cobol/blob/b3084a8262166a324dcaf54d976f6f3f8712b2a1/lib/compile/index.js#L40-L68
17,883
IonicaBizau/node-cobol
lib/index.js
Cobol
function Cobol(input, options, callback) { var args = Sliced(arguments); if (typeof options === "function") { callback = options; options = {}; } callback = callback || function () {}; // Merge the defaults options = Ul.merge(options, { cwd: process.cwd(), compileargs: {}, args: [] }); if (_typeof(args[1]) === "object") {} // options = Ul.merge(options, { // stdout: process.stdout // , stderr: process.stderr // , stdin: process.stdin // }); // File if (typeof input === "string" && input.split("\n").length === 1) { return OneByOne([Compile.bind(this, input, options), function (next, path) { Run(path, options, next); }], function (err, data) { callback(err, data && data.slice(-1)[0]); }); } // Comment // TODO We should improve this. if (typeof input === "function") { input = input.toString(); input = input.slice(input.indexOf("/*") + 2, input.indexOf("*/")); } // Code if (typeof input === "string") { return OneByOne([Tmp.file.bind(Tmp), function (next, path) { Fs.writeFile(path, input, function (err) { next(err, path); }); }, function (next, path) { if (_typeof(args[1]) !== "object") { return Cobol(path, next); } Cobol(path, options, next); }], function (err, data) { //if (options.autoclose !== false) { // process.nextTick(function () { // process.exit(); // }); //} callback(err, data && data.slice(-1)[0]); }); } callback(new Error("Incorrect usage.")); }
javascript
function Cobol(input, options, callback) { var args = Sliced(arguments); if (typeof options === "function") { callback = options; options = {}; } callback = callback || function () {}; // Merge the defaults options = Ul.merge(options, { cwd: process.cwd(), compileargs: {}, args: [] }); if (_typeof(args[1]) === "object") {} // options = Ul.merge(options, { // stdout: process.stdout // , stderr: process.stderr // , stdin: process.stdin // }); // File if (typeof input === "string" && input.split("\n").length === 1) { return OneByOne([Compile.bind(this, input, options), function (next, path) { Run(path, options, next); }], function (err, data) { callback(err, data && data.slice(-1)[0]); }); } // Comment // TODO We should improve this. if (typeof input === "function") { input = input.toString(); input = input.slice(input.indexOf("/*") + 2, input.indexOf("*/")); } // Code if (typeof input === "string") { return OneByOne([Tmp.file.bind(Tmp), function (next, path) { Fs.writeFile(path, input, function (err) { next(err, path); }); }, function (next, path) { if (_typeof(args[1]) !== "object") { return Cobol(path, next); } Cobol(path, options, next); }], function (err, data) { //if (options.autoclose !== false) { // process.nextTick(function () { // process.exit(); // }); //} callback(err, data && data.slice(-1)[0]); }); } callback(new Error("Incorrect usage.")); }
[ "function", "Cobol", "(", "input", ",", "options", ",", "callback", ")", "{", "var", "args", "=", "Sliced", "(", "arguments", ")", ";", "if", "(", "typeof", "options", "===", "\"function\"", ")", "{", "callback", "=", "options", ";", "options", "=", "{", "}", ";", "}", "callback", "=", "callback", "||", "function", "(", ")", "{", "}", ";", "// Merge the defaults", "options", "=", "Ul", ".", "merge", "(", "options", ",", "{", "cwd", ":", "process", ".", "cwd", "(", ")", ",", "compileargs", ":", "{", "}", ",", "args", ":", "[", "]", "}", ")", ";", "if", "(", "_typeof", "(", "args", "[", "1", "]", ")", "===", "\"object\"", ")", "{", "}", "// options = Ul.merge(options, {", "// stdout: process.stdout", "// , stderr: process.stderr", "// , stdin: process.stdin", "// });", "// File", "if", "(", "typeof", "input", "===", "\"string\"", "&&", "input", ".", "split", "(", "\"\\n\"", ")", ".", "length", "===", "1", ")", "{", "return", "OneByOne", "(", "[", "Compile", ".", "bind", "(", "this", ",", "input", ",", "options", ")", ",", "function", "(", "next", ",", "path", ")", "{", "Run", "(", "path", ",", "options", ",", "next", ")", ";", "}", "]", ",", "function", "(", "err", ",", "data", ")", "{", "callback", "(", "err", ",", "data", "&&", "data", ".", "slice", "(", "-", "1", ")", "[", "0", "]", ")", ";", "}", ")", ";", "}", "// Comment", "// TODO We should improve this.", "if", "(", "typeof", "input", "===", "\"function\"", ")", "{", "input", "=", "input", ".", "toString", "(", ")", ";", "input", "=", "input", ".", "slice", "(", "input", ".", "indexOf", "(", "\"/*\"", ")", "+", "2", ",", "input", ".", "indexOf", "(", "\"*/\"", ")", ")", ";", "}", "// Code", "if", "(", "typeof", "input", "===", "\"string\"", ")", "{", "return", "OneByOne", "(", "[", "Tmp", ".", "file", ".", "bind", "(", "Tmp", ")", ",", "function", "(", "next", ",", "path", ")", "{", "Fs", ".", "writeFile", "(", "path", ",", "input", ",", "function", "(", "err", ")", "{", "next", "(", "err", ",", "path", ")", ";", "}", ")", ";", "}", ",", "function", "(", "next", ",", "path", ")", "{", "if", "(", "_typeof", "(", "args", "[", "1", "]", ")", "!==", "\"object\"", ")", "{", "return", "Cobol", "(", "path", ",", "next", ")", ";", "}", "Cobol", "(", "path", ",", "options", ",", "next", ")", ";", "}", "]", ",", "function", "(", "err", ",", "data", ")", "{", "//if (options.autoclose !== false) {", "// process.nextTick(function () {", "// process.exit();", "// });", "//}", "callback", "(", "err", ",", "data", "&&", "data", ".", "slice", "(", "-", "1", ")", "[", "0", "]", ")", ";", "}", ")", ";", "}", "callback", "(", "new", "Error", "(", "\"Incorrect usage.\"", ")", ")", ";", "}" ]
Cobol Runs COBOL code from Node.JS side. @name Cobol @function @param {Function|String|Path} input A function containing a comment with inline COBOL code, the cobol code itself or a path to a COBOL file. @param {Object} options An object containing the following fields: - `cwd` (String): Where the COBOL code will run (by default in the current working directory) - `args` (Array): An array of strings to pass to the COBOL process. - `compileargs` (Object): Use to specificy cobc compiler options - `stdin` (Stream): An optional stdin stream used to pipe data to the stdin stream of the COBOL process. - `stderr` (Stream): An optional stderr stream used to pipe data to the stdin stream of the COBOL process. - `stdeout` (Stream): An optional stdout stream used to pipe data to the stdin stream of the COBOL process. - `remove` (Boolean): Should the compiled executable be removed after running, default is true. - `precompiled` (Boolean): Run the precompiled executable instead of re-compiling, default is false. @param {Function} callback The callback function called with `err`, `stdout` and `stderr`.
[ "Cobol", "Runs", "COBOL", "code", "from", "Node", ".", "JS", "side", "." ]
b3084a8262166a324dcaf54d976f6f3f8712b2a1
https://github.com/IonicaBizau/node-cobol/blob/b3084a8262166a324dcaf54d976f6f3f8712b2a1/lib/index.js#L36-L100
17,884
pelias/leaflet-plugin
spec/helpers.js
loadJSON
function loadJSON (path, callback) { var xobj = new XMLHttpRequest(); xobj.overrideMimeType('application/json'); xobj.open('GET', path, true); xobj.onreadystatechange = function () { if (xobj.readyState === 4 && xobj.status === 200) { callback(xobj.responseText); } }; xobj.send(null); }
javascript
function loadJSON (path, callback) { var xobj = new XMLHttpRequest(); xobj.overrideMimeType('application/json'); xobj.open('GET', path, true); xobj.onreadystatechange = function () { if (xobj.readyState === 4 && xobj.status === 200) { callback(xobj.responseText); } }; xobj.send(null); }
[ "function", "loadJSON", "(", "path", ",", "callback", ")", "{", "var", "xobj", "=", "new", "XMLHttpRequest", "(", ")", ";", "xobj", ".", "overrideMimeType", "(", "'application/json'", ")", ";", "xobj", ".", "open", "(", "'GET'", ",", "path", ",", "true", ")", ";", "xobj", ".", "onreadystatechange", "=", "function", "(", ")", "{", "if", "(", "xobj", ".", "readyState", "===", "4", "&&", "xobj", ".", "status", "===", "200", ")", "{", "callback", "(", "xobj", ".", "responseText", ")", ";", "}", "}", ";", "xobj", ".", "send", "(", "null", ")", ";", "}" ]
Read sample results data
[ "Read", "sample", "results", "data" ]
f915387e131c9f8b156ff4c3f135446137bf5265
https://github.com/pelias/leaflet-plugin/blob/f915387e131c9f8b156ff4c3f135446137bf5265/spec/helpers.js#L2-L12
17,885
pelias/leaflet-plugin
spec/suites/SearchOptionsSpec.js
destroyMap
function destroyMap (map) { var el = map.getContainer(); map.remove(); document.body.removeChild(el); }
javascript
function destroyMap (map) { var el = map.getContainer(); map.remove(); document.body.removeChild(el); }
[ "function", "destroyMap", "(", "map", ")", "{", "var", "el", "=", "map", ".", "getContainer", "(", ")", ";", "map", ".", "remove", "(", ")", ";", "document", ".", "body", ".", "removeChild", "(", "el", ")", ";", "}" ]
Don't forget to clean up the map and DOM after you're done
[ "Don", "t", "forget", "to", "clean", "up", "the", "map", "and", "DOM", "after", "you", "re", "done" ]
f915387e131c9f8b156ff4c3f135446137bf5265
https://github.com/pelias/leaflet-plugin/blob/f915387e131c9f8b156ff4c3f135446137bf5265/spec/suites/SearchOptionsSpec.js#L17-L21
17,886
erming/shout
client/js/libs/jquery/tse.js
startDrag
function startDrag(e) { // Preventing the event's default action stops text being // selectable during the drag. e.preventDefault(); var self = $(this); self.trigger('startDrag'); // Measure how far the user's mouse is from the top of the scrollbar drag handle. var eventOffset = e.pageY; if (scrollDirection === 'horiz') { eventOffset = e.pageX; } dragOffset = eventOffset - $dragHandleEl.offset()[offsetAttr]; $(document).on('mousemove', drag); $(document).on('mouseup', function() { endDrag.call(self); }); }
javascript
function startDrag(e) { // Preventing the event's default action stops text being // selectable during the drag. e.preventDefault(); var self = $(this); self.trigger('startDrag'); // Measure how far the user's mouse is from the top of the scrollbar drag handle. var eventOffset = e.pageY; if (scrollDirection === 'horiz') { eventOffset = e.pageX; } dragOffset = eventOffset - $dragHandleEl.offset()[offsetAttr]; $(document).on('mousemove', drag); $(document).on('mouseup', function() { endDrag.call(self); }); }
[ "function", "startDrag", "(", "e", ")", "{", "// Preventing the event's default action stops text being", "// selectable during the drag.", "e", ".", "preventDefault", "(", ")", ";", "var", "self", "=", "$", "(", "this", ")", ";", "self", ".", "trigger", "(", "'startDrag'", ")", ";", "// Measure how far the user's mouse is from the top of the scrollbar drag handle.", "var", "eventOffset", "=", "e", ".", "pageY", ";", "if", "(", "scrollDirection", "===", "'horiz'", ")", "{", "eventOffset", "=", "e", ".", "pageX", ";", "}", "dragOffset", "=", "eventOffset", "-", "$dragHandleEl", ".", "offset", "(", ")", "[", "offsetAttr", "]", ";", "$", "(", "document", ")", ".", "on", "(", "'mousemove'", ",", "drag", ")", ";", "$", "(", "document", ")", ".", "on", "(", "'mouseup'", ",", "function", "(", ")", "{", "endDrag", ".", "call", "(", "self", ")", ";", "}", ")", ";", "}" ]
Start scrollbar handle drag
[ "Start", "scrollbar", "handle", "drag" ]
90a62c56af4412c6b0e0ae51fe84f3825f49e226
https://github.com/erming/shout/blob/90a62c56af4412c6b0e0ae51fe84f3825f49e226/client/js/libs/jquery/tse.js#L93-L112
17,887
erming/shout
client/js/libs/jquery/tse.js
drag
function drag(e) { e.preventDefault(); // Calculate how far the user's mouse is from the top/left of the scrollbar (minus the dragOffset). var eventOffset = e.pageY; if (scrollDirection === 'horiz') { eventOffset = e.pageX; } var dragPos = eventOffset - $scrollbarEl.offset()[offsetAttr] - dragOffset; // Convert the mouse position into a percentage of the scrollbar height/width. var dragPerc = dragPos / $scrollbarEl[sizeAttr](); // Scroll the content by the same percentage. var scrollPos = dragPerc * $contentEl[sizeAttr](); $scrollContentEl[scrollOffsetAttr](scrollPos); }
javascript
function drag(e) { e.preventDefault(); // Calculate how far the user's mouse is from the top/left of the scrollbar (minus the dragOffset). var eventOffset = e.pageY; if (scrollDirection === 'horiz') { eventOffset = e.pageX; } var dragPos = eventOffset - $scrollbarEl.offset()[offsetAttr] - dragOffset; // Convert the mouse position into a percentage of the scrollbar height/width. var dragPerc = dragPos / $scrollbarEl[sizeAttr](); // Scroll the content by the same percentage. var scrollPos = dragPerc * $contentEl[sizeAttr](); $scrollContentEl[scrollOffsetAttr](scrollPos); }
[ "function", "drag", "(", "e", ")", "{", "e", ".", "preventDefault", "(", ")", ";", "// Calculate how far the user's mouse is from the top/left of the scrollbar (minus the dragOffset).", "var", "eventOffset", "=", "e", ".", "pageY", ";", "if", "(", "scrollDirection", "===", "'horiz'", ")", "{", "eventOffset", "=", "e", ".", "pageX", ";", "}", "var", "dragPos", "=", "eventOffset", "-", "$scrollbarEl", ".", "offset", "(", ")", "[", "offsetAttr", "]", "-", "dragOffset", ";", "// Convert the mouse position into a percentage of the scrollbar height/width.", "var", "dragPerc", "=", "dragPos", "/", "$scrollbarEl", "[", "sizeAttr", "]", "(", ")", ";", "// Scroll the content by the same percentage.", "var", "scrollPos", "=", "dragPerc", "*", "$contentEl", "[", "sizeAttr", "]", "(", ")", ";", "$scrollContentEl", "[", "scrollOffsetAttr", "]", "(", "scrollPos", ")", ";", "}" ]
Drag scrollbar handle
[ "Drag", "scrollbar", "handle" ]
90a62c56af4412c6b0e0ae51fe84f3825f49e226
https://github.com/erming/shout/blob/90a62c56af4412c6b0e0ae51fe84f3825f49e226/client/js/libs/jquery/tse.js#L117-L132
17,888
erming/shout
client/js/libs/jquery/tse.js
resizeScrollContent
function resizeScrollContent() { if (scrollDirection === 'vert'){ $scrollContentEl.width($el.width()+scrollbarWidth()); $scrollContentEl.height($el.height()); } else { $scrollContentEl.width($el.width()); $scrollContentEl.height($el.height()+scrollbarWidth()); $contentEl.height($el.height()); } }
javascript
function resizeScrollContent() { if (scrollDirection === 'vert'){ $scrollContentEl.width($el.width()+scrollbarWidth()); $scrollContentEl.height($el.height()); } else { $scrollContentEl.width($el.width()); $scrollContentEl.height($el.height()+scrollbarWidth()); $contentEl.height($el.height()); } }
[ "function", "resizeScrollContent", "(", ")", "{", "if", "(", "scrollDirection", "===", "'vert'", ")", "{", "$scrollContentEl", ".", "width", "(", "$el", ".", "width", "(", ")", "+", "scrollbarWidth", "(", ")", ")", ";", "$scrollContentEl", ".", "height", "(", "$el", ".", "height", "(", ")", ")", ";", "}", "else", "{", "$scrollContentEl", ".", "width", "(", "$el", ".", "width", "(", ")", ")", ";", "$scrollContentEl", ".", "height", "(", "$el", ".", "height", "(", ")", "+", "scrollbarWidth", "(", ")", ")", ";", "$contentEl", ".", "height", "(", "$el", ".", "height", "(", ")", ")", ";", "}", "}" ]
Resize content element
[ "Resize", "content", "element" ]
90a62c56af4412c6b0e0ae51fe84f3825f49e226
https://github.com/erming/shout/blob/90a62c56af4412c6b0e0ae51fe84f3825f49e226/client/js/libs/jquery/tse.js#L238-L247
17,889
erming/shout
client/js/libs/jquery/tse.js
scrollbarWidth
function scrollbarWidth() { // Append a temporary scrolling element to the DOM, then measure // the difference between between its outer and inner elements. var tempEl = $('<div class="scrollbar-width-tester" style="width:50px;height:50px;overflow-y:scroll;position:absolute;top:-200px;left:-200px;"><div style="height:100px;"></div>'); $('body').append(tempEl); var width = $(tempEl).innerWidth(); var widthMinusScrollbars = $('div', tempEl).innerWidth(); tempEl.remove(); // On OS X if the scrollbar is set to auto hide it will have zero width. On webkit we can still // hide it using ::-webkit-scrollbar { width:0; height:0; } but there is no moz equivalent. So we're // forced to sniff Firefox and return a hard-coded scrollbar width. I know, I know... if (width === widthMinusScrollbars && navigator.userAgent.toLowerCase().indexOf('firefox') > -1) { return 17; } return (width - widthMinusScrollbars); }
javascript
function scrollbarWidth() { // Append a temporary scrolling element to the DOM, then measure // the difference between between its outer and inner elements. var tempEl = $('<div class="scrollbar-width-tester" style="width:50px;height:50px;overflow-y:scroll;position:absolute;top:-200px;left:-200px;"><div style="height:100px;"></div>'); $('body').append(tempEl); var width = $(tempEl).innerWidth(); var widthMinusScrollbars = $('div', tempEl).innerWidth(); tempEl.remove(); // On OS X if the scrollbar is set to auto hide it will have zero width. On webkit we can still // hide it using ::-webkit-scrollbar { width:0; height:0; } but there is no moz equivalent. So we're // forced to sniff Firefox and return a hard-coded scrollbar width. I know, I know... if (width === widthMinusScrollbars && navigator.userAgent.toLowerCase().indexOf('firefox') > -1) { return 17; } return (width - widthMinusScrollbars); }
[ "function", "scrollbarWidth", "(", ")", "{", "// Append a temporary scrolling element to the DOM, then measure", "// the difference between between its outer and inner elements.", "var", "tempEl", "=", "$", "(", "'<div class=\"scrollbar-width-tester\" style=\"width:50px;height:50px;overflow-y:scroll;position:absolute;top:-200px;left:-200px;\"><div style=\"height:100px;\"></div>'", ")", ";", "$", "(", "'body'", ")", ".", "append", "(", "tempEl", ")", ";", "var", "width", "=", "$", "(", "tempEl", ")", ".", "innerWidth", "(", ")", ";", "var", "widthMinusScrollbars", "=", "$", "(", "'div'", ",", "tempEl", ")", ".", "innerWidth", "(", ")", ";", "tempEl", ".", "remove", "(", ")", ";", "// On OS X if the scrollbar is set to auto hide it will have zero width. On webkit we can still", "// hide it using ::-webkit-scrollbar { width:0; height:0; } but there is no moz equivalent. So we're", "// forced to sniff Firefox and return a hard-coded scrollbar width. I know, I know...", "if", "(", "width", "===", "widthMinusScrollbars", "&&", "navigator", ".", "userAgent", ".", "toLowerCase", "(", ")", ".", "indexOf", "(", "'firefox'", ")", ">", "-", "1", ")", "{", "return", "17", ";", "}", "return", "(", "width", "-", "widthMinusScrollbars", ")", ";", "}" ]
Calculate scrollbar width Original function by Jonathan Sharp: http://jdsharp.us/jQuery/minute/calculate-scrollbar-width.php Updated to work in Chrome v25.
[ "Calculate", "scrollbar", "width" ]
90a62c56af4412c6b0e0ae51fe84f3825f49e226
https://github.com/erming/shout/blob/90a62c56af4412c6b0e0ae51fe84f3825f49e226/client/js/libs/jquery/tse.js#L256-L271
17,890
erming/shout
client/js/libs/favico.js
function(imageElement) { _readyCb = function() { try { var w = imageElement.width; var h = imageElement.height; var newImg = document.createElement('img'); var ratio = (w / _w < h / _h) ? (w / _w) : (h / _h); newImg.setAttribute('src', imageElement.getAttribute('src')); newImg.height = (h / ratio); newImg.width = (w / ratio); _context.clearRect(0, 0, _w, _h); _context.drawImage(newImg, 0, 0, _w, _h); link.setIcon(_canvas); } catch(e) { throw 'Error setting image. Message: ' + e.message; } }; if (_ready) { _readyCb(); } }
javascript
function(imageElement) { _readyCb = function() { try { var w = imageElement.width; var h = imageElement.height; var newImg = document.createElement('img'); var ratio = (w / _w < h / _h) ? (w / _w) : (h / _h); newImg.setAttribute('src', imageElement.getAttribute('src')); newImg.height = (h / ratio); newImg.width = (w / ratio); _context.clearRect(0, 0, _w, _h); _context.drawImage(newImg, 0, 0, _w, _h); link.setIcon(_canvas); } catch(e) { throw 'Error setting image. Message: ' + e.message; } }; if (_ready) { _readyCb(); } }
[ "function", "(", "imageElement", ")", "{", "_readyCb", "=", "function", "(", ")", "{", "try", "{", "var", "w", "=", "imageElement", ".", "width", ";", "var", "h", "=", "imageElement", ".", "height", ";", "var", "newImg", "=", "document", ".", "createElement", "(", "'img'", ")", ";", "var", "ratio", "=", "(", "w", "/", "_w", "<", "h", "/", "_h", ")", "?", "(", "w", "/", "_w", ")", ":", "(", "h", "/", "_h", ")", ";", "newImg", ".", "setAttribute", "(", "'src'", ",", "imageElement", ".", "getAttribute", "(", "'src'", ")", ")", ";", "newImg", ".", "height", "=", "(", "h", "/", "ratio", ")", ";", "newImg", ".", "width", "=", "(", "w", "/", "ratio", ")", ";", "_context", ".", "clearRect", "(", "0", ",", "0", ",", "_w", ",", "_h", ")", ";", "_context", ".", "drawImage", "(", "newImg", ",", "0", ",", "0", ",", "_w", ",", "_h", ")", ";", "link", ".", "setIcon", "(", "_canvas", ")", ";", "}", "catch", "(", "e", ")", "{", "throw", "'Error setting image. Message: '", "+", "e", ".", "message", ";", "}", "}", ";", "if", "(", "_ready", ")", "{", "_readyCb", "(", ")", ";", "}", "}" ]
Set image as icon
[ "Set", "image", "as", "icon" ]
90a62c56af4412c6b0e0ae51fe84f3825f49e226
https://github.com/erming/shout/blob/90a62c56af4412c6b0e0ae51fe84f3825f49e226/client/js/libs/favico.js#L340-L360
17,891
erming/shout
client/js/libs/favico.js
function(action) { //UR if (!window.URL || !window.URL.createObjectURL) { window.URL = window.URL || {}; window.URL.createObjectURL = function(obj) { return obj; }; } if (_browser.supported) { var newVideo = false; navigator.getUserMedia = navigator.getUserMedia || navigator.oGetUserMedia || navigator.msGetUserMedia || navigator.mozGetUserMedia || navigator.webkitGetUserMedia; _readyCb = function() { try { if (action === 'stop') { _stop = true; icon.reset(); _stop = false; return; } newVideo = document.createElement('video'); newVideo.width = _w; newVideo.height = _h; navigator.getUserMedia({ video : true, audio : false }, function(stream) { newVideo.src = URL.createObjectURL(stream); newVideo.play(); drawVideo(newVideo); }, function() { }); } catch(e) { throw 'Error setting webcam. Message: ' + e.message; } }; if (_ready) { _readyCb(); } } }
javascript
function(action) { //UR if (!window.URL || !window.URL.createObjectURL) { window.URL = window.URL || {}; window.URL.createObjectURL = function(obj) { return obj; }; } if (_browser.supported) { var newVideo = false; navigator.getUserMedia = navigator.getUserMedia || navigator.oGetUserMedia || navigator.msGetUserMedia || navigator.mozGetUserMedia || navigator.webkitGetUserMedia; _readyCb = function() { try { if (action === 'stop') { _stop = true; icon.reset(); _stop = false; return; } newVideo = document.createElement('video'); newVideo.width = _w; newVideo.height = _h; navigator.getUserMedia({ video : true, audio : false }, function(stream) { newVideo.src = URL.createObjectURL(stream); newVideo.play(); drawVideo(newVideo); }, function() { }); } catch(e) { throw 'Error setting webcam. Message: ' + e.message; } }; if (_ready) { _readyCb(); } } }
[ "function", "(", "action", ")", "{", "//UR", "if", "(", "!", "window", ".", "URL", "||", "!", "window", ".", "URL", ".", "createObjectURL", ")", "{", "window", ".", "URL", "=", "window", ".", "URL", "||", "{", "}", ";", "window", ".", "URL", ".", "createObjectURL", "=", "function", "(", "obj", ")", "{", "return", "obj", ";", "}", ";", "}", "if", "(", "_browser", ".", "supported", ")", "{", "var", "newVideo", "=", "false", ";", "navigator", ".", "getUserMedia", "=", "navigator", ".", "getUserMedia", "||", "navigator", ".", "oGetUserMedia", "||", "navigator", ".", "msGetUserMedia", "||", "navigator", ".", "mozGetUserMedia", "||", "navigator", ".", "webkitGetUserMedia", ";", "_readyCb", "=", "function", "(", ")", "{", "try", "{", "if", "(", "action", "===", "'stop'", ")", "{", "_stop", "=", "true", ";", "icon", ".", "reset", "(", ")", ";", "_stop", "=", "false", ";", "return", ";", "}", "newVideo", "=", "document", ".", "createElement", "(", "'video'", ")", ";", "newVideo", ".", "width", "=", "_w", ";", "newVideo", ".", "height", "=", "_h", ";", "navigator", ".", "getUserMedia", "(", "{", "video", ":", "true", ",", "audio", ":", "false", "}", ",", "function", "(", "stream", ")", "{", "newVideo", ".", "src", "=", "URL", ".", "createObjectURL", "(", "stream", ")", ";", "newVideo", ".", "play", "(", ")", ";", "drawVideo", "(", "newVideo", ")", ";", "}", ",", "function", "(", ")", "{", "}", ")", ";", "}", "catch", "(", "e", ")", "{", "throw", "'Error setting webcam. Message: '", "+", "e", ".", "message", ";", "}", "}", ";", "if", "(", "_ready", ")", "{", "_readyCb", "(", ")", ";", "}", "}", "}" ]
Set video as icon
[ "Set", "video", "as", "icon" ]
90a62c56af4412c6b0e0ae51fe84f3825f49e226
https://github.com/erming/shout/blob/90a62c56af4412c6b0e0ae51fe84f3825f49e226/client/js/libs/favico.js#L391-L431
17,892
erming/shout
client/js/libs/favico.js
function() { var link = document.getElementsByTagName('head')[0].getElementsByTagName('link'); for (var l = link.length, i = (l - 1); i >= 0; i--) { if ((/(^|\s)icon(\s|$)/i).test(link[i].getAttribute('rel'))) { return link[i]; } } return false; }
javascript
function() { var link = document.getElementsByTagName('head')[0].getElementsByTagName('link'); for (var l = link.length, i = (l - 1); i >= 0; i--) { if ((/(^|\s)icon(\s|$)/i).test(link[i].getAttribute('rel'))) { return link[i]; } } return false; }
[ "function", "(", ")", "{", "var", "link", "=", "document", ".", "getElementsByTagName", "(", "'head'", ")", "[", "0", "]", ".", "getElementsByTagName", "(", "'link'", ")", ";", "for", "(", "var", "l", "=", "link", ".", "length", ",", "i", "=", "(", "l", "-", "1", ")", ";", "i", ">=", "0", ";", "i", "--", ")", "{", "if", "(", "(", "/", "(^|\\s)icon(\\s|$)", "/", "i", ")", ".", "test", "(", "link", "[", "i", "]", ".", "getAttribute", "(", "'rel'", ")", ")", ")", "{", "return", "link", "[", "i", "]", ";", "}", "}", "return", "false", ";", "}" ]
get link element
[ "get", "link", "element" ]
90a62c56af4412c6b0e0ae51fe84f3825f49e226
https://github.com/erming/shout/blob/90a62c56af4412c6b0e0ae51fe84f3825f49e226/client/js/libs/favico.js#L459-L467
17,893
erming/shout
client/js/libs/stringcolor.js
function(word) { var h = 0; for (var i = 0; i < word.length; i++) { h = word.charCodeAt(i) + ((h << 5) - h); } return h; }
javascript
function(word) { var h = 0; for (var i = 0; i < word.length; i++) { h = word.charCodeAt(i) + ((h << 5) - h); } return h; }
[ "function", "(", "word", ")", "{", "var", "h", "=", "0", ";", "for", "(", "var", "i", "=", "0", ";", "i", "<", "word", ".", "length", ";", "i", "++", ")", "{", "h", "=", "word", ".", "charCodeAt", "(", "i", ")", "+", "(", "(", "h", "<<", "5", ")", "-", "h", ")", ";", "}", "return", "h", ";", "}" ]
Generate a Hash for the String
[ "Generate", "a", "Hash", "for", "the", "String" ]
90a62c56af4412c6b0e0ae51fe84f3825f49e226
https://github.com/erming/shout/blob/90a62c56af4412c6b0e0ae51fe84f3825f49e226/client/js/libs/stringcolor.js#L47-L53
17,894
erming/shout
client/js/libs/stringcolor.js
function(color, prc) { var num = parseInt(color, 16), amt = Math.round(2.55 * prc), R = (num >> 16) + amt, G = (num >> 8 & 0x00FF) + amt, B = (num & 0x0000FF) + amt; return (0x1000000 + (R < 255 ? R < 1 ? 0 : R : 255) * 0x10000 + (G < 255 ? G < 1 ? 0 : G : 255) * 0x100 + (B < 255 ? B < 1 ? 0 : B : 255)) .toString(16) .slice(1); }
javascript
function(color, prc) { var num = parseInt(color, 16), amt = Math.round(2.55 * prc), R = (num >> 16) + amt, G = (num >> 8 & 0x00FF) + amt, B = (num & 0x0000FF) + amt; return (0x1000000 + (R < 255 ? R < 1 ? 0 : R : 255) * 0x10000 + (G < 255 ? G < 1 ? 0 : G : 255) * 0x100 + (B < 255 ? B < 1 ? 0 : B : 255)) .toString(16) .slice(1); }
[ "function", "(", "color", ",", "prc", ")", "{", "var", "num", "=", "parseInt", "(", "color", ",", "16", ")", ",", "amt", "=", "Math", ".", "round", "(", "2.55", "*", "prc", ")", ",", "R", "=", "(", "num", ">>", "16", ")", "+", "amt", ",", "G", "=", "(", "num", ">>", "8", "&", "0x00FF", ")", "+", "amt", ",", "B", "=", "(", "num", "&", "0x0000FF", ")", "+", "amt", ";", "return", "(", "0x1000000", "+", "(", "R", "<", "255", "?", "R", "<", "1", "?", "0", ":", "R", ":", "255", ")", "*", "0x10000", "+", "(", "G", "<", "255", "?", "G", "<", "1", "?", "0", ":", "G", ":", "255", ")", "*", "0x100", "+", "(", "B", "<", "255", "?", "B", "<", "1", "?", "0", ":", "B", ":", "255", ")", ")", ".", "toString", "(", "16", ")", ".", "slice", "(", "1", ")", ";", "}" ]
Change the darkness or lightness
[ "Change", "the", "darkness", "or", "lightness" ]
90a62c56af4412c6b0e0ae51fe84f3825f49e226
https://github.com/erming/shout/blob/90a62c56af4412c6b0e0ae51fe84f3825f49e226/client/js/libs/stringcolor.js#L56-L67
17,895
erming/shout
client/js/libs/stringcolor.js
function(i) { var color = ((i >> 24) & 0xFF).toString(16) + ((i >> 16) & 0xFF).toString(16) + ((i >> 8) & 0xFF).toString(16) + (i & 0xFF).toString(16); return color; }
javascript
function(i) { var color = ((i >> 24) & 0xFF).toString(16) + ((i >> 16) & 0xFF).toString(16) + ((i >> 8) & 0xFF).toString(16) + (i & 0xFF).toString(16); return color; }
[ "function", "(", "i", ")", "{", "var", "color", "=", "(", "(", "i", ">>", "24", ")", "&", "0xFF", ")", ".", "toString", "(", "16", ")", "+", "(", "(", "i", ">>", "16", ")", "&", "0xFF", ")", ".", "toString", "(", "16", ")", "+", "(", "(", "i", ">>", "8", ")", "&", "0xFF", ")", ".", "toString", "(", "16", ")", "+", "(", "i", "&", "0xFF", ")", ".", "toString", "(", "16", ")", ";", "return", "color", ";", "}" ]
Convert init to an RGBA
[ "Convert", "init", "to", "an", "RGBA" ]
90a62c56af4412c6b0e0ae51fe84f3825f49e226
https://github.com/erming/shout/blob/90a62c56af4412c6b0e0ae51fe84f3825f49e226/client/js/libs/stringcolor.js#L70-L76
17,896
erming/shout
client/js/libs/notification.js
swaptitle
function swaptitle(title){ if(a.length===0){ a = [document.title]; } a.push(title); if(!iv){ iv = setInterval(function(){ // has document.title changed externally? if(a.indexOf(document.title) === -1 ){ // update the default title a[0] = document.title; } document.title = a[++i%a.length]; }, 1000); } }
javascript
function swaptitle(title){ if(a.length===0){ a = [document.title]; } a.push(title); if(!iv){ iv = setInterval(function(){ // has document.title changed externally? if(a.indexOf(document.title) === -1 ){ // update the default title a[0] = document.title; } document.title = a[++i%a.length]; }, 1000); } }
[ "function", "swaptitle", "(", "title", ")", "{", "if", "(", "a", ".", "length", "===", "0", ")", "{", "a", "=", "[", "document", ".", "title", "]", ";", "}", "a", ".", "push", "(", "title", ")", ";", "if", "(", "!", "iv", ")", "{", "iv", "=", "setInterval", "(", "function", "(", ")", "{", "// has document.title changed externally?", "if", "(", "a", ".", "indexOf", "(", "document", ".", "title", ")", "===", "-", "1", ")", "{", "// update the default title", "a", "[", "0", "]", "=", "document", ".", "title", ";", "}", "document", ".", "title", "=", "a", "[", "++", "i", "%", "a", ".", "length", "]", ";", "}", ",", "1000", ")", ";", "}", "}" ]
Swap the document.title with the notification
[ "Swap", "the", "document", ".", "title", "with", "the", "notification" ]
90a62c56af4412c6b0e0ae51fe84f3825f49e226
https://github.com/erming/shout/blob/90a62c56af4412c6b0e0ae51fe84f3825f49e226/client/js/libs/notification.js#L25-L45
17,897
erming/shout
client/js/libs/notification.js
addEvent
function addEvent(el,name,func){ if(name.match(" ")){ var a = name.split(' '); for(var i=0;i<a.length;i++){ addEvent( el, a[i], func); } } if(el.addEventListener){ el.removeEventListener(name, func, false); el.addEventListener(name, func, false); } else { el.detachEvent('on'+name, func); el.attachEvent('on'+name, func); } }
javascript
function addEvent(el,name,func){ if(name.match(" ")){ var a = name.split(' '); for(var i=0;i<a.length;i++){ addEvent( el, a[i], func); } } if(el.addEventListener){ el.removeEventListener(name, func, false); el.addEventListener(name, func, false); } else { el.detachEvent('on'+name, func); el.attachEvent('on'+name, func); } }
[ "function", "addEvent", "(", "el", ",", "name", ",", "func", ")", "{", "if", "(", "name", ".", "match", "(", "\" \"", ")", ")", "{", "var", "a", "=", "name", ".", "split", "(", "' '", ")", ";", "for", "(", "var", "i", "=", "0", ";", "i", "<", "a", ".", "length", ";", "i", "++", ")", "{", "addEvent", "(", "el", ",", "a", "[", "i", "]", ",", "func", ")", ";", "}", "}", "if", "(", "el", ".", "addEventListener", ")", "{", "el", ".", "removeEventListener", "(", "name", ",", "func", ",", "false", ")", ";", "el", ".", "addEventListener", "(", "name", ",", "func", ",", "false", ")", ";", "}", "else", "{", "el", ".", "detachEvent", "(", "'on'", "+", "name", ",", "func", ")", ";", "el", ".", "attachEvent", "(", "'on'", "+", "name", ",", "func", ")", ";", "}", "}" ]
Add aevent handlers
[ "Add", "aevent", "handlers" ]
90a62c56af4412c6b0e0ae51fe84f3825f49e226
https://github.com/erming/shout/blob/90a62c56af4412c6b0e0ae51fe84f3825f49e226/client/js/libs/notification.js#L68-L83
17,898
erming/shout
client/js/libs/jquery/tabcomplete.js
match
function match(word, array, caseSensitive) { return $.grep( array, function(w) { if (caseSensitive) { return !w.indexOf(word); } else { return !w.toLowerCase().indexOf(word.toLowerCase()); } } ); }
javascript
function match(word, array, caseSensitive) { return $.grep( array, function(w) { if (caseSensitive) { return !w.indexOf(word); } else { return !w.toLowerCase().indexOf(word.toLowerCase()); } } ); }
[ "function", "match", "(", "word", ",", "array", ",", "caseSensitive", ")", "{", "return", "$", ".", "grep", "(", "array", ",", "function", "(", "w", ")", "{", "if", "(", "caseSensitive", ")", "{", "return", "!", "w", ".", "indexOf", "(", "word", ")", ";", "}", "else", "{", "return", "!", "w", ".", "toLowerCase", "(", ")", ".", "indexOf", "(", "word", ".", "toLowerCase", "(", ")", ")", ";", "}", "}", ")", ";", "}" ]
Simple matching. Filter the array and return the items that begins with 'word'.
[ "Simple", "matching", ".", "Filter", "the", "array", "and", "return", "the", "items", "that", "begins", "with", "word", "." ]
90a62c56af4412c6b0e0ae51fe84f3825f49e226
https://github.com/erming/shout/blob/90a62c56af4412c6b0e0ae51fe84f3825f49e226/client/js/libs/jquery/tabcomplete.js#L191-L202
17,899
erming/shout
client/js/libs/jquery/tabcomplete.js
placeholder
function placeholder(word) { var input = this; var clone = input.prev(".hint"); input.css({ backgroundColor: "transparent", position: "relative", }); // Lets create a clone of the input if it does // not already exist. if (!clone.length) { input.wrap( $("<div>").css({position: "relative", height: input.css("height")}) ); clone = input .clone() .attr("tabindex", -1) .removeAttr("id name placeholder") .addClass("hint") .insertBefore(input); clone.css({ position: "absolute", }); } var hint = ""; if (typeof word !== "undefined") { var value = input.val(); hint = value + word.substr(value.split(/ |\n/).pop().length); } clone.val(hint); }
javascript
function placeholder(word) { var input = this; var clone = input.prev(".hint"); input.css({ backgroundColor: "transparent", position: "relative", }); // Lets create a clone of the input if it does // not already exist. if (!clone.length) { input.wrap( $("<div>").css({position: "relative", height: input.css("height")}) ); clone = input .clone() .attr("tabindex", -1) .removeAttr("id name placeholder") .addClass("hint") .insertBefore(input); clone.css({ position: "absolute", }); } var hint = ""; if (typeof word !== "undefined") { var value = input.val(); hint = value + word.substr(value.split(/ |\n/).pop().length); } clone.val(hint); }
[ "function", "placeholder", "(", "word", ")", "{", "var", "input", "=", "this", ";", "var", "clone", "=", "input", ".", "prev", "(", "\".hint\"", ")", ";", "input", ".", "css", "(", "{", "backgroundColor", ":", "\"transparent\"", ",", "position", ":", "\"relative\"", ",", "}", ")", ";", "// Lets create a clone of the input if it does", "// not already exist.", "if", "(", "!", "clone", ".", "length", ")", "{", "input", ".", "wrap", "(", "$", "(", "\"<div>\"", ")", ".", "css", "(", "{", "position", ":", "\"relative\"", ",", "height", ":", "input", ".", "css", "(", "\"height\"", ")", "}", ")", ")", ";", "clone", "=", "input", ".", "clone", "(", ")", ".", "attr", "(", "\"tabindex\"", ",", "-", "1", ")", ".", "removeAttr", "(", "\"id name placeholder\"", ")", ".", "addClass", "(", "\"hint\"", ")", ".", "insertBefore", "(", "input", ")", ";", "clone", ".", "css", "(", "{", "position", ":", "\"absolute\"", ",", "}", ")", ";", "}", "var", "hint", "=", "\"\"", ";", "if", "(", "typeof", "word", "!==", "\"undefined\"", ")", "{", "var", "value", "=", "input", ".", "val", "(", ")", ";", "hint", "=", "value", "+", "word", ".", "substr", "(", "value", ".", "split", "(", "/", " |\\n", "/", ")", ".", "pop", "(", ")", ".", "length", ")", ";", "}", "clone", ".", "val", "(", "hint", ")", ";", "}" ]
Show placeholder text. This works by creating a copy of the input and placing it behind the real input.
[ "Show", "placeholder", "text", ".", "This", "works", "by", "creating", "a", "copy", "of", "the", "input", "and", "placing", "it", "behind", "the", "real", "input", "." ]
90a62c56af4412c6b0e0ae51fe84f3825f49e226
https://github.com/erming/shout/blob/90a62c56af4412c6b0e0ae51fe84f3825f49e226/client/js/libs/jquery/tabcomplete.js#L207-L240