code
stringlengths
24
2.07M
docstring
stringlengths
25
85.3k
func_name
stringlengths
1
92
language
stringclasses
1 value
repo
stringlengths
5
64
path
stringlengths
4
172
url
stringlengths
44
218
license
stringclasses
7 values
function drainQueue() { if (draining) { return; } var timeout = setTimeout(cleanUpNextTick); draining = true; var len = queue.length; while(len) { currentQueue = queue; queue = []; while (++queueIndex < len) { if (currentQueue) { currentQueue[queueIndex].run(); } } queueIndex = -1; len = queue.length; } currentQueue = null; draining = false; clearTimeout(timeout); }
Used to grok the `now` parameter to createClock.
drainQueue
javascript
rowanmanning/joblint
build/test.js
https://github.com/rowanmanning/joblint/blob/master/build/test.js
MIT
function Item(fun, array) { this.fun = fun; this.array = array; }
Used to grok the `now` parameter to createClock.
Item
javascript
rowanmanning/joblint
build/test.js
https://github.com/rowanmanning/joblint/blob/master/build/test.js
MIT
function ok (val, msg) { if (!!!val) { fail(val, true, msg, '=='); } }
Used to grok the `now` parameter to createClock.
ok
javascript
rowanmanning/joblint
build/test.js
https://github.com/rowanmanning/joblint/blob/master/build/test.js
MIT
function AssertionError (opts) { opts = opts || {}; this.name = 'AssertionError'; this.actual = opts.actual; this.expected = opts.expected; this.operator = opts.operator || ''; this.message = opts.message || getAssertionErrorMessage(this); if (Error.captureStackTrace) { Error.captureStackTrace(this, opts.stackStartFunction || fail); } }
Used to grok the `now` parameter to createClock.
AssertionError
javascript
rowanmanning/joblint
build/test.js
https://github.com/rowanmanning/joblint/blob/master/build/test.js
MIT
function fail (actual, expected, message, operator, stackStartFunction) { throw new AssertionError({ message: message, actual: actual, expected: expected, operator: operator, stackStartFunction: stackStartFunction }); }
Used to grok the `now` parameter to createClock.
fail
javascript
rowanmanning/joblint
build/test.js
https://github.com/rowanmanning/joblint/blob/master/build/test.js
MIT
function isUndefinedOrNull (val) { return (val === null || typeof val === 'undefined'); }
Used to grok the `now` parameter to createClock.
isUndefinedOrNull
javascript
rowanmanning/joblint
build/test.js
https://github.com/rowanmanning/joblint/blob/master/build/test.js
MIT
function isArgumentsObject (val) { return (Object.prototype.toString.call(val) === '[object Arguments]'); }
Used to grok the `now` parameter to createClock.
isArgumentsObject
javascript
rowanmanning/joblint
build/test.js
https://github.com/rowanmanning/joblint/blob/master/build/test.js
MIT
function isPlainObject (val) { return Object.prototype.toString.call(val) === '[object Object]'; }
Used to grok the `now` parameter to createClock.
isPlainObject
javascript
rowanmanning/joblint
build/test.js
https://github.com/rowanmanning/joblint/blob/master/build/test.js
MIT
function includes (haystack, needle) { /* jshint maxdepth: 3*/ var i; // Array#indexOf, but ie... if (isArray(haystack)) { for (i = haystack.length - 1; i >= 0; i = i - 1) { if (haystack[i] === needle) { return true; } } } // String#indexOf if (typeof haystack === 'string') { if (haystack.indexOf(needle) !== -1) { return true; } } // Object#hasOwnProperty if (isPlainObject(haystack)) { if (haystack.hasOwnProperty(needle)) { return true; } } return false; }
Used to grok the `now` parameter to createClock.
includes
javascript
rowanmanning/joblint
build/test.js
https://github.com/rowanmanning/joblint/blob/master/build/test.js
MIT
function getObjectKeys (obj) { var key; var keys = []; for (key in obj) { if (obj.hasOwnProperty(key)) { keys.push(key); } } return keys; }
Used to grok the `now` parameter to createClock.
getObjectKeys
javascript
rowanmanning/joblint
build/test.js
https://github.com/rowanmanning/joblint/blob/master/build/test.js
MIT
function objectsEqual (obj1, obj2) { /* jshint eqeqeq: false */ // Check for undefined or null if (isUndefinedOrNull(obj1) || isUndefinedOrNull(obj2)) { return false; } // Object prototypes must be the same if (obj1.prototype !== obj2.prototype) { return false; } // Handle argument objects if (isArgumentsObject(obj1)) { if (!isArgumentsObject(obj2)) { return false; } obj1 = Array.prototype.slice.call(obj1); obj2 = Array.prototype.slice.call(obj2); } // Check number of own properties var obj1Keys = getObjectKeys(obj1); var obj2Keys = getObjectKeys(obj2); if (obj1Keys.length !== obj2Keys.length) { return false; } obj1Keys.sort(); obj2Keys.sort(); // Cheap initial key test (see https://github.com/joyent/node/blob/master/lib/assert.js) var key; var i; var len = obj1Keys.length; for (i = 0; i < len; i += 1) { if (obj1Keys[i] != obj2Keys[i]) { return false; } } // Expensive deep test for (i = 0; i < len; i += 1) { key = obj1Keys[i]; if (!isDeepEqual(obj1[key], obj2[key])) { return false; } } // If it got this far... return true; }
Used to grok the `now` parameter to createClock.
objectsEqual
javascript
rowanmanning/joblint
build/test.js
https://github.com/rowanmanning/joblint/blob/master/build/test.js
MIT
function isDeepEqual (actual, expected) { /* jshint eqeqeq: false */ if (actual === expected) { return true; } if (expected instanceof Date && actual instanceof Date) { return actual.getTime() === expected.getTime(); } if (actual instanceof RegExp && expected instanceof RegExp) { return ( actual.source === expected.source && actual.global === expected.global && actual.multiline === expected.multiline && actual.lastIndex === expected.lastIndex && actual.ignoreCase === expected.ignoreCase ); } if (typeof actual !== 'object' && typeof expected !== 'object') { return actual == expected; } return objectsEqual(actual, expected); }
Used to grok the `now` parameter to createClock.
isDeepEqual
javascript
rowanmanning/joblint
build/test.js
https://github.com/rowanmanning/joblint/blob/master/build/test.js
MIT
function functionThrows (fn, expected) { // Try/catch var thrown = false; var thrownError; try { fn(); } catch (err) { thrown = true; thrownError = err; } // Check error if (thrown && expected) { thrown = errorMatches(thrownError, expected); } return thrown; }
Used to grok the `now` parameter to createClock.
functionThrows
javascript
rowanmanning/joblint
build/test.js
https://github.com/rowanmanning/joblint/blob/master/build/test.js
MIT
function errorMatches (actual, expected) { if (typeof expected === 'string') { return actual.message === expected; } if (expected instanceof RegExp) { return expected.test(actual.message); } if (actual instanceof expected) { return true; } return false; }
Used to grok the `now` parameter to createClock.
errorMatches
javascript
rowanmanning/joblint
build/test.js
https://github.com/rowanmanning/joblint/blob/master/build/test.js
MIT
function getAssertionErrorMessage (error) { if (typeof require === 'function') { var util = require('util'); return [ truncateString(util.inspect(error.actual, {depth: null}), 128), error.operator, truncateString(util.inspect(error.expected, {depth: null}), 128) ].join(' '); } else { return error.actual + ' ' + error.operator + ' ' + error.expected; } }
Used to grok the `now` parameter to createClock.
getAssertionErrorMessage
javascript
rowanmanning/joblint
build/test.js
https://github.com/rowanmanning/joblint/blob/master/build/test.js
MIT
function isNaN(value) { // Unlike global isNaN, this avoids type coercion // typeof check avoids IE host object issues, hat tip to // lodash var val = value; // JsLint thinks value !== value is "weird" return typeof value === "number" && value !== val; }
Used to grok the `now` parameter to createClock.
isNaN
javascript
rowanmanning/joblint
build/test.js
https://github.com/rowanmanning/joblint/blob/master/build/test.js
MIT
function getClass(value) { // Returns the internal [[Class]] by calling Object.prototype.toString // with the provided value as this. Return value is a string, naming the // internal class, e.g. "Array" return o.toString.call(value).split(/[ \]]/)[1]; }
Used to grok the `now` parameter to createClock.
getClass
javascript
rowanmanning/joblint
build/test.js
https://github.com/rowanmanning/joblint/blob/master/build/test.js
MIT
function isArguments(object) { if (getClass(object) === 'Arguments') { return true; } if (typeof object !== "object" || typeof object.length !== "number" || getClass(object) === "Array") { return false; } if (typeof object.callee == "function") { return true; } try { object[object.length] = 6; delete object[object.length]; } catch (e) { return true; } return false; }
@name samsam.isArguments @param Object object Returns ``true`` if ``object`` is an ``arguments`` object, ``false`` otherwise.
isArguments
javascript
rowanmanning/joblint
build/test.js
https://github.com/rowanmanning/joblint/blob/master/build/test.js
MIT
function isElement(object) { if (!object || object.nodeType !== 1 || !div) { return false; } try { object.appendChild(div); object.removeChild(div); } catch (e) { return false; } return true; }
@name samsam.isElement @param Object object Returns ``true`` if ``object`` is a DOM element node. Unlike Underscore.js/lodash, this function will return ``false`` if ``object`` is an *element-like* object, i.e. a regular object with a ``nodeType`` property that holds the value ``1``.
isElement
javascript
rowanmanning/joblint
build/test.js
https://github.com/rowanmanning/joblint/blob/master/build/test.js
MIT
function keys(object) { var ks = [], prop; for (prop in object) { if (o.hasOwnProperty.call(object, prop)) { ks.push(prop); } } return ks; }
@name samsam.keys @param Object object Return an array of own property names.
keys
javascript
rowanmanning/joblint
build/test.js
https://github.com/rowanmanning/joblint/blob/master/build/test.js
MIT
function isDate(value) { return typeof value.getTime == "function" && value.getTime() == value.valueOf(); }
@name samsam.isDate @param Object value Returns true if the object is a ``Date``, or *date-like*. Duck typing of date objects work by checking that the object has a ``getTime`` function whose return value equals the return value from the object's ``valueOf``.
isDate
javascript
rowanmanning/joblint
build/test.js
https://github.com/rowanmanning/joblint/blob/master/build/test.js
MIT
function isNegZero(value) { return value === 0 && 1 / value === -Infinity; }
@name samsam.isNegZero @param Object value Returns ``true`` if ``value`` is ``-0``.
isNegZero
javascript
rowanmanning/joblint
build/test.js
https://github.com/rowanmanning/joblint/blob/master/build/test.js
MIT
function identical(obj1, obj2) { if (obj1 === obj2 || (isNaN(obj1) && isNaN(obj2))) { return obj1 !== 0 || isNegZero(obj1) === isNegZero(obj2); } }
@name samsam.equal @param Object obj1 @param Object obj2 Returns ``true`` if two objects are strictly equal. Compared to ``===`` there are two exceptions: - NaN is considered equal to NaN - -0 and +0 are not considered equal
identical
javascript
rowanmanning/joblint
build/test.js
https://github.com/rowanmanning/joblint/blob/master/build/test.js
MIT
function deepEqualCyclic(obj1, obj2) { // used for cyclic comparison // contain already visited objects var objects1 = [], objects2 = [], // contain pathes (position in the object structure) // of the already visited objects // indexes same as in objects arrays paths1 = [], paths2 = [], // contains combinations of already compared objects // in the manner: { "$1['ref']$2['ref']": true } compared = {}; /** * used to check, if the value of a property is an object * (cyclic logic is only needed for objects) * only needed for cyclic logic */ function isObject(value) { if (typeof value === 'object' && value !== null && !(value instanceof Boolean) && !(value instanceof Date) && !(value instanceof Number) && !(value instanceof RegExp) && !(value instanceof String)) { return true; } return false; } /** * returns the index of the given object in the * given objects array, -1 if not contained * only needed for cyclic logic */ function getIndex(objects, obj) { var i; for (i = 0; i < objects.length; i++) { if (objects[i] === obj) { return i; } } return -1; } // does the recursion for the deep equal check return (function deepEqual(obj1, obj2, path1, path2) { var type1 = typeof obj1; var type2 = typeof obj2; // == null also matches undefined if (obj1 === obj2 || isNaN(obj1) || isNaN(obj2) || obj1 == null || obj2 == null || type1 !== "object" || type2 !== "object") { return identical(obj1, obj2); } // Elements are only equal if identical(expected, actual) if (isElement(obj1) || isElement(obj2)) { return false; } var isDate1 = isDate(obj1), isDate2 = isDate(obj2); if (isDate1 || isDate2) { if (!isDate1 || !isDate2 || obj1.getTime() !== obj2.getTime()) { return false; } } if (obj1 instanceof RegExp && obj2 instanceof RegExp) { if (obj1.toString() !== obj2.toString()) { return false; } } var class1 = getClass(obj1); var class2 = getClass(obj2); var keys1 = keys(obj1); var keys2 = keys(obj2); if (isArguments(obj1) || isArguments(obj2)) { if (obj1.length !== obj2.length) { return false; } } else { if (type1 !== type2 || class1 !== class2 || keys1.length !== keys2.length) { return false; } } var key, i, l, // following vars are used for the cyclic logic value1, value2, isObject1, isObject2, index1, index2, newPath1, newPath2; for (i = 0, l = keys1.length; i < l; i++) { key = keys1[i]; if (!o.hasOwnProperty.call(obj2, key)) { return false; } // Start of the cyclic logic value1 = obj1[key]; value2 = obj2[key]; isObject1 = isObject(value1); isObject2 = isObject(value2); // determine, if the objects were already visited // (it's faster to check for isObject first, than to // get -1 from getIndex for non objects) index1 = isObject1 ? getIndex(objects1, value1) : -1; index2 = isObject2 ? getIndex(objects2, value2) : -1; // determine the new pathes of the objects // - for non cyclic objects the current path will be extended // by current property name // - for cyclic objects the stored path is taken newPath1 = index1 !== -1 ? paths1[index1] : path1 + '[' + JSON.stringify(key) + ']'; newPath2 = index2 !== -1 ? paths2[index2] : path2 + '[' + JSON.stringify(key) + ']'; // stop recursion if current objects are already compared if (compared[newPath1 + newPath2]) { return true; } // remember the current objects and their pathes if (index1 === -1 && isObject1) { objects1.push(value1); paths1.push(newPath1); } if (index2 === -1 && isObject2) { objects2.push(value2); paths2.push(newPath2); } // remember that the current objects are already compared if (isObject1 && isObject2) { compared[newPath1 + newPath2] = true; } // End of cyclic logic // neither value1 nor value2 is a cycle // continue with next level if (!deepEqual(value1, value2, newPath1, newPath2)) { return false; } } return true; }(obj1, obj2, '$1', '$2')); }
@name samsam.deepEqual @param Object obj1 @param Object obj2 Deep equal comparison. Two values are "deep equal" if: - They are equal, according to samsam.identical - They are both date objects representing the same time - They are both arrays containing elements that are all deepEqual - They are objects with the same set of properties, and each property in ``obj1`` is deepEqual to the corresponding property in ``obj2`` Supports cyclic objects.
deepEqualCyclic
javascript
rowanmanning/joblint
build/test.js
https://github.com/rowanmanning/joblint/blob/master/build/test.js
MIT
function isObject(value) { if (typeof value === 'object' && value !== null && !(value instanceof Boolean) && !(value instanceof Date) && !(value instanceof Number) && !(value instanceof RegExp) && !(value instanceof String)) { return true; } return false; }
used to check, if the value of a property is an object (cyclic logic is only needed for objects) only needed for cyclic logic
isObject
javascript
rowanmanning/joblint
build/test.js
https://github.com/rowanmanning/joblint/blob/master/build/test.js
MIT
function getIndex(objects, obj) { var i; for (i = 0; i < objects.length; i++) { if (objects[i] === obj) { return i; } } return -1; }
returns the index of the given object in the given objects array, -1 if not contained only needed for cyclic logic
getIndex
javascript
rowanmanning/joblint
build/test.js
https://github.com/rowanmanning/joblint/blob/master/build/test.js
MIT
function arrayContains(array, subset) { if (subset.length === 0) { return true; } var i, l, j, k; for (i = 0, l = array.length; i < l; ++i) { if (match(array[i], subset[0])) { for (j = 0, k = subset.length; j < k; ++j) { if (!match(array[i + j], subset[j])) { return false; } } return true; } } return false; }
returns the index of the given object in the given objects array, -1 if not contained only needed for cyclic logic
arrayContains
javascript
rowanmanning/joblint
build/test.js
https://github.com/rowanmanning/joblint/blob/master/build/test.js
MIT
function inspect(obj, opts) { // default options var ctx = { seen: [], stylize: stylizeNoColor }; // legacy... if (arguments.length >= 3) ctx.depth = arguments[2]; if (arguments.length >= 4) ctx.colors = arguments[3]; if (isBoolean(opts)) { // legacy... ctx.showHidden = opts; } else if (opts) { // got an "options" object exports._extend(ctx, opts); } // set default options if (isUndefined(ctx.showHidden)) ctx.showHidden = false; if (isUndefined(ctx.depth)) ctx.depth = 2; if (isUndefined(ctx.colors)) ctx.colors = false; if (isUndefined(ctx.customInspect)) ctx.customInspect = true; if (ctx.colors) ctx.stylize = stylizeWithColor; return formatValue(ctx, obj, ctx.depth); }
Echos the value of a value. Trys to print the value out in the best way possible given the different types. @param {Object} obj The object to print out. @param {Object} opts Optional options object that alters the output.
inspect
javascript
rowanmanning/joblint
build/test.js
https://github.com/rowanmanning/joblint/blob/master/build/test.js
MIT
function stylizeWithColor(str, styleType) { var style = inspect.styles[styleType]; if (style) { return '\u001b[' + inspect.colors[style][0] + 'm' + str + '\u001b[' + inspect.colors[style][1] + 'm'; } else { return str; } }
Echos the value of a value. Trys to print the value out in the best way possible given the different types. @param {Object} obj The object to print out. @param {Object} opts Optional options object that alters the output.
stylizeWithColor
javascript
rowanmanning/joblint
build/test.js
https://github.com/rowanmanning/joblint/blob/master/build/test.js
MIT
function stylizeNoColor(str, styleType) { return str; }
Echos the value of a value. Trys to print the value out in the best way possible given the different types. @param {Object} obj The object to print out. @param {Object} opts Optional options object that alters the output.
stylizeNoColor
javascript
rowanmanning/joblint
build/test.js
https://github.com/rowanmanning/joblint/blob/master/build/test.js
MIT
function arrayToHash(array) { var hash = {}; array.forEach(function(val, idx) { hash[val] = true; }); return hash; }
Echos the value of a value. Trys to print the value out in the best way possible given the different types. @param {Object} obj The object to print out. @param {Object} opts Optional options object that alters the output.
arrayToHash
javascript
rowanmanning/joblint
build/test.js
https://github.com/rowanmanning/joblint/blob/master/build/test.js
MIT
function formatValue(ctx, value, recurseTimes) { // Provide a hook for user-specified inspect functions. // Check that value is an object with an inspect function on it if (ctx.customInspect && value && isFunction(value.inspect) && // Filter out the util module, it's inspect function is special value.inspect !== exports.inspect && // Also filter out any prototype objects using the circular check. !(value.constructor && value.constructor.prototype === value)) { var ret = value.inspect(recurseTimes, ctx); if (!isString(ret)) { ret = formatValue(ctx, ret, recurseTimes); } return ret; } // Primitive types cannot have properties var primitive = formatPrimitive(ctx, value); if (primitive) { return primitive; } // Look up the keys of the object. var keys = Object.keys(value); var visibleKeys = arrayToHash(keys); if (ctx.showHidden) { keys = Object.getOwnPropertyNames(value); } // IE doesn't make error fields non-enumerable // http://msdn.microsoft.com/en-us/library/ie/dww52sbt(v=vs.94).aspx if (isError(value) && (keys.indexOf('message') >= 0 || keys.indexOf('description') >= 0)) { return formatError(value); } // Some type of object without properties can be shortcutted. if (keys.length === 0) { if (isFunction(value)) { var name = value.name ? ': ' + value.name : ''; return ctx.stylize('[Function' + name + ']', 'special'); } if (isRegExp(value)) { return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp'); } if (isDate(value)) { return ctx.stylize(Date.prototype.toString.call(value), 'date'); } if (isError(value)) { return formatError(value); } } var base = '', array = false, braces = ['{', '}']; // Make Array say that they are Array if (isArray(value)) { array = true; braces = ['[', ']']; } // Make functions say that they are functions if (isFunction(value)) { var n = value.name ? ': ' + value.name : ''; base = ' [Function' + n + ']'; } // Make RegExps say that they are RegExps if (isRegExp(value)) { base = ' ' + RegExp.prototype.toString.call(value); } // Make dates with properties first say the date if (isDate(value)) { base = ' ' + Date.prototype.toUTCString.call(value); } // Make error with message first say the error if (isError(value)) { base = ' ' + formatError(value); } if (keys.length === 0 && (!array || value.length == 0)) { return braces[0] + base + braces[1]; } if (recurseTimes < 0) { if (isRegExp(value)) { return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp'); } else { return ctx.stylize('[Object]', 'special'); } } ctx.seen.push(value); var output; if (array) { output = formatArray(ctx, value, recurseTimes, visibleKeys, keys); } else { output = keys.map(function(key) { return formatProperty(ctx, value, recurseTimes, visibleKeys, key, array); }); } ctx.seen.pop(); return reduceToSingleString(output, base, braces); }
Echos the value of a value. Trys to print the value out in the best way possible given the different types. @param {Object} obj The object to print out. @param {Object} opts Optional options object that alters the output.
formatValue
javascript
rowanmanning/joblint
build/test.js
https://github.com/rowanmanning/joblint/blob/master/build/test.js
MIT
function formatPrimitive(ctx, value) { if (isUndefined(value)) return ctx.stylize('undefined', 'undefined'); if (isString(value)) { var simple = '\'' + JSON.stringify(value).replace(/^"|"$/g, '') .replace(/'/g, "\\'") .replace(/\\"/g, '"') + '\''; return ctx.stylize(simple, 'string'); } if (isNumber(value)) return ctx.stylize('' + value, 'number'); if (isBoolean(value)) return ctx.stylize('' + value, 'boolean'); // For some reason typeof null is "object", so special case here. if (isNull(value)) return ctx.stylize('null', 'null'); }
Echos the value of a value. Trys to print the value out in the best way possible given the different types. @param {Object} obj The object to print out. @param {Object} opts Optional options object that alters the output.
formatPrimitive
javascript
rowanmanning/joblint
build/test.js
https://github.com/rowanmanning/joblint/blob/master/build/test.js
MIT
function formatError(value) { return '[' + Error.prototype.toString.call(value) + ']'; }
Echos the value of a value. Trys to print the value out in the best way possible given the different types. @param {Object} obj The object to print out. @param {Object} opts Optional options object that alters the output.
formatError
javascript
rowanmanning/joblint
build/test.js
https://github.com/rowanmanning/joblint/blob/master/build/test.js
MIT
function formatArray(ctx, value, recurseTimes, visibleKeys, keys) { var output = []; for (var i = 0, l = value.length; i < l; ++i) { if (hasOwnProperty(value, String(i))) { output.push(formatProperty(ctx, value, recurseTimes, visibleKeys, String(i), true)); } else { output.push(''); } } keys.forEach(function(key) { if (!key.match(/^\d+$/)) { output.push(formatProperty(ctx, value, recurseTimes, visibleKeys, key, true)); } }); return output; }
Echos the value of a value. Trys to print the value out in the best way possible given the different types. @param {Object} obj The object to print out. @param {Object} opts Optional options object that alters the output.
formatArray
javascript
rowanmanning/joblint
build/test.js
https://github.com/rowanmanning/joblint/blob/master/build/test.js
MIT
function formatProperty(ctx, value, recurseTimes, visibleKeys, key, array) { var name, str, desc; desc = Object.getOwnPropertyDescriptor(value, key) || { value: value[key] }; if (desc.get) { if (desc.set) { str = ctx.stylize('[Getter/Setter]', 'special'); } else { str = ctx.stylize('[Getter]', 'special'); } } else { if (desc.set) { str = ctx.stylize('[Setter]', 'special'); } } if (!hasOwnProperty(visibleKeys, key)) { name = '[' + key + ']'; } if (!str) { if (ctx.seen.indexOf(desc.value) < 0) { if (isNull(recurseTimes)) { str = formatValue(ctx, desc.value, null); } else { str = formatValue(ctx, desc.value, recurseTimes - 1); } if (str.indexOf('\n') > -1) { if (array) { str = str.split('\n').map(function(line) { return ' ' + line; }).join('\n').substr(2); } else { str = '\n' + str.split('\n').map(function(line) { return ' ' + line; }).join('\n'); } } } else { str = ctx.stylize('[Circular]', 'special'); } } if (isUndefined(name)) { if (array && key.match(/^\d+$/)) { return str; } name = JSON.stringify('' + key); if (name.match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)) { name = name.substr(1, name.length - 2); name = ctx.stylize(name, 'name'); } else { name = name.replace(/'/g, "\\'") .replace(/\\"/g, '"') .replace(/(^"|"$)/g, "'"); name = ctx.stylize(name, 'string'); } } return name + ': ' + str; }
Echos the value of a value. Trys to print the value out in the best way possible given the different types. @param {Object} obj The object to print out. @param {Object} opts Optional options object that alters the output.
formatProperty
javascript
rowanmanning/joblint
build/test.js
https://github.com/rowanmanning/joblint/blob/master/build/test.js
MIT
function reduceToSingleString(output, base, braces) { var numLinesEst = 0; var length = output.reduce(function(prev, cur) { numLinesEst++; if (cur.indexOf('\n') >= 0) numLinesEst++; return prev + cur.replace(/\u001b\[\d\d?m/g, '').length + 1; }, 0); if (length > 60) { return braces[0] + (base === '' ? '' : base + '\n ') + ' ' + output.join(',\n ') + ' ' + braces[1]; } return braces[0] + base + ' ' + output.join(', ') + ' ' + braces[1]; }
Echos the value of a value. Trys to print the value out in the best way possible given the different types. @param {Object} obj The object to print out. @param {Object} opts Optional options object that alters the output.
reduceToSingleString
javascript
rowanmanning/joblint
build/test.js
https://github.com/rowanmanning/joblint/blob/master/build/test.js
MIT
function isArray(ar) { return Array.isArray(ar); }
Echos the value of a value. Trys to print the value out in the best way possible given the different types. @param {Object} obj The object to print out. @param {Object} opts Optional options object that alters the output.
isArray
javascript
rowanmanning/joblint
build/test.js
https://github.com/rowanmanning/joblint/blob/master/build/test.js
MIT
function isBoolean(arg) { return typeof arg === 'boolean'; }
Echos the value of a value. Trys to print the value out in the best way possible given the different types. @param {Object} obj The object to print out. @param {Object} opts Optional options object that alters the output.
isBoolean
javascript
rowanmanning/joblint
build/test.js
https://github.com/rowanmanning/joblint/blob/master/build/test.js
MIT
function isNull(arg) { return arg === null; }
Echos the value of a value. Trys to print the value out in the best way possible given the different types. @param {Object} obj The object to print out. @param {Object} opts Optional options object that alters the output.
isNull
javascript
rowanmanning/joblint
build/test.js
https://github.com/rowanmanning/joblint/blob/master/build/test.js
MIT
function isNullOrUndefined(arg) { return arg == null; }
Echos the value of a value. Trys to print the value out in the best way possible given the different types. @param {Object} obj The object to print out. @param {Object} opts Optional options object that alters the output.
isNullOrUndefined
javascript
rowanmanning/joblint
build/test.js
https://github.com/rowanmanning/joblint/blob/master/build/test.js
MIT
function isNumber(arg) { return typeof arg === 'number'; }
Echos the value of a value. Trys to print the value out in the best way possible given the different types. @param {Object} obj The object to print out. @param {Object} opts Optional options object that alters the output.
isNumber
javascript
rowanmanning/joblint
build/test.js
https://github.com/rowanmanning/joblint/blob/master/build/test.js
MIT
function isString(arg) { return typeof arg === 'string'; }
Echos the value of a value. Trys to print the value out in the best way possible given the different types. @param {Object} obj The object to print out. @param {Object} opts Optional options object that alters the output.
isString
javascript
rowanmanning/joblint
build/test.js
https://github.com/rowanmanning/joblint/blob/master/build/test.js
MIT
function isSymbol(arg) { return typeof arg === 'symbol'; }
Echos the value of a value. Trys to print the value out in the best way possible given the different types. @param {Object} obj The object to print out. @param {Object} opts Optional options object that alters the output.
isSymbol
javascript
rowanmanning/joblint
build/test.js
https://github.com/rowanmanning/joblint/blob/master/build/test.js
MIT
function isUndefined(arg) { return arg === void 0; }
Echos the value of a value. Trys to print the value out in the best way possible given the different types. @param {Object} obj The object to print out. @param {Object} opts Optional options object that alters the output.
isUndefined
javascript
rowanmanning/joblint
build/test.js
https://github.com/rowanmanning/joblint/blob/master/build/test.js
MIT
function isRegExp(re) { return isObject(re) && objectToString(re) === '[object RegExp]'; }
Echos the value of a value. Trys to print the value out in the best way possible given the different types. @param {Object} obj The object to print out. @param {Object} opts Optional options object that alters the output.
isRegExp
javascript
rowanmanning/joblint
build/test.js
https://github.com/rowanmanning/joblint/blob/master/build/test.js
MIT
function isObject(arg) { return typeof arg === 'object' && arg !== null; }
Echos the value of a value. Trys to print the value out in the best way possible given the different types. @param {Object} obj The object to print out. @param {Object} opts Optional options object that alters the output.
isObject
javascript
rowanmanning/joblint
build/test.js
https://github.com/rowanmanning/joblint/blob/master/build/test.js
MIT
function isDate(d) { return isObject(d) && objectToString(d) === '[object Date]'; }
Echos the value of a value. Trys to print the value out in the best way possible given the different types. @param {Object} obj The object to print out. @param {Object} opts Optional options object that alters the output.
isDate
javascript
rowanmanning/joblint
build/test.js
https://github.com/rowanmanning/joblint/blob/master/build/test.js
MIT
function isError(e) { return isObject(e) && (objectToString(e) === '[object Error]' || e instanceof Error); }
Echos the value of a value. Trys to print the value out in the best way possible given the different types. @param {Object} obj The object to print out. @param {Object} opts Optional options object that alters the output.
isError
javascript
rowanmanning/joblint
build/test.js
https://github.com/rowanmanning/joblint/blob/master/build/test.js
MIT
function isFunction(arg) { return typeof arg === 'function'; }
Echos the value of a value. Trys to print the value out in the best way possible given the different types. @param {Object} obj The object to print out. @param {Object} opts Optional options object that alters the output.
isFunction
javascript
rowanmanning/joblint
build/test.js
https://github.com/rowanmanning/joblint/blob/master/build/test.js
MIT
function isPrimitive(arg) { return arg === null || typeof arg === 'boolean' || typeof arg === 'number' || typeof arg === 'string' || typeof arg === 'symbol' || // ES6 symbol typeof arg === 'undefined'; }
Echos the value of a value. Trys to print the value out in the best way possible given the different types. @param {Object} obj The object to print out. @param {Object} opts Optional options object that alters the output.
isPrimitive
javascript
rowanmanning/joblint
build/test.js
https://github.com/rowanmanning/joblint/blob/master/build/test.js
MIT
function objectToString(o) { return Object.prototype.toString.call(o); }
Echos the value of a value. Trys to print the value out in the best way possible given the different types. @param {Object} obj The object to print out. @param {Object} opts Optional options object that alters the output.
objectToString
javascript
rowanmanning/joblint
build/test.js
https://github.com/rowanmanning/joblint/blob/master/build/test.js
MIT
function pad(n) { return n < 10 ? '0' + n.toString(10) : n.toString(10); }
Echos the value of a value. Trys to print the value out in the best way possible given the different types. @param {Object} obj The object to print out. @param {Object} opts Optional options object that alters the output.
pad
javascript
rowanmanning/joblint
build/test.js
https://github.com/rowanmanning/joblint/blob/master/build/test.js
MIT
function timestamp() { var d = new Date(); var time = [pad(d.getHours()), pad(d.getMinutes()), pad(d.getSeconds())].join(':'); return [d.getDate(), months[d.getMonth()], time].join(' '); }
Echos the value of a value. Trys to print the value out in the best way possible given the different types. @param {Object} obj The object to print out. @param {Object} opts Optional options object that alters the output.
timestamp
javascript
rowanmanning/joblint
build/test.js
https://github.com/rowanmanning/joblint/blob/master/build/test.js
MIT
function hasOwnProperty(obj, prop) { return Object.prototype.hasOwnProperty.call(obj, prop); }
Inherit the prototype methods from one constructor into another. The Function.prototype.inherits from lang.js rewritten as a standalone function (not on Function.prototype). NOTE: If this file is to be loaded during bootstrapping this function needs to be rewritten using some native functions as prototype setup using normal JavaScript does not work as expected during bootstrapping (see mirror.js in r114903). @param {function} ctor Constructor function which needs to inherit the prototype. @param {function} superCtor Constructor function to inherit prototype from.
hasOwnProperty
javascript
rowanmanning/joblint
build/test.js
https://github.com/rowanmanning/joblint/blob/master/build/test.js
MIT
getElementToNavigate(linkOnly = false) { const focusedElement = document.activeElement; // StartPage seems to still focus and change it to body when the page loads. if (focusedElement == null || focusedElement.localName === 'body') { if ( this.focusedIndex < 0 || this.focusedIndex >= this.searchResults.length ) { return null; } return this.searchResults[this.focusedIndex].anchor; } const isLink = focusedElement.localName === 'a' && focusedElement.hasAttribute('href'); if (!linkOnly || isLink) { return focusedElement; } }
Returns the element to click on upon navigation. The focused element in the document is preferred (if there is one) over the highlighted result. Note that the focused element does not have to be an anchor <a> element. @param {boolean} linkOnly If true the focused element is preferred only when it is a link with "href" attribute. @return {Element}
getElementToNavigate
javascript
infokiller/web-search-navigator
src/main.js
https://github.com/infokiller/web-search-navigator/blob/master/src/main.js
MIT
highlight(searchResult) { const highlighted = searchResult.highlightedElement; if (highlighted == null) { console.error('No element to highlight: %o', highlighted); return; } highlighted.classList.add(searchResult.highlightClass); if ( this.options.sync.get('hideOutline') || searchResult.anchor !== highlighted ) { searchResult.anchor.classList.add('wsn-no-outline'); } }
Returns the element to click on upon navigation. The focused element in the document is preferred (if there is one) over the highlighted result. Note that the focused element does not have to be an anchor <a> element. @param {boolean} linkOnly If true the focused element is preferred only when it is a link with "href" attribute. @return {Element}
highlight
javascript
infokiller/web-search-navigator
src/main.js
https://github.com/infokiller/web-search-navigator/blob/master/src/main.js
MIT
unhighlight(searchResult) { const highlighted = searchResult.highlightedElement; if (highlighted == null) { console.error('No element to unhighlight: %o', highlighted); return; } highlighted.classList.remove(searchResult.highlightClass); highlighted.classList.remove('wsn-no-outline'); }
Returns the element to click on upon navigation. The focused element in the document is preferred (if there is one) over the highlighted result. Note that the focused element does not have to be an anchor <a> element. @param {boolean} linkOnly If true the focused element is preferred only when it is a link with "href" attribute. @return {Element}
unhighlight
javascript
infokiller/web-search-navigator
src/main.js
https://github.com/infokiller/web-search-navigator/blob/master/src/main.js
MIT
focus(index, scroll = FOCUS_SCROLL_ONLY) { if (this.focusedIndex >= 0) { const searchResult = this.searchResults[this.focusedIndex]; // If the current result is outside the viewport and FOCUS_SCROLL_ONLY was // requested, scroll to the current hidden result, but don't focus on the // new result. // This behavior is intended to handle cases where the user scrolls away // from the currently focused result and then presses the keybindings to // focus on the previous/next result. In this case, since the user // doesn't see the current result, it's more intuitive to only scroll to // the current result, and then on the next keypress they can focus on the // previous/next result and actually see on what result they want to focus // on. if ( scroll === FOCUS_SCROLL_ONLY && scrollToElement(this.searchEngine, searchResult.container) ) { return; } // Remove highlighting from previous item. this.unhighlight(searchResult); } const searchResult = this.searchResults[index]; if (!searchResult) { this.focusedIndex = -1; return; } this.highlight(searchResult); // We already scroll below, so no need for focus to scroll. The scrolling // behavior of `focus` also seems less predictable and caused an issue, see: // https://github.com/infokiller/web-search-navigator/issues/35 searchResult.anchor.focus({preventScroll: true}); // Ensure whole search result container is visible in the viewport, not only // the search result link. if (scroll !== FOCUS_SCROLL_OFF) { scrollToElement(this.searchEngine, searchResult.container); } this.focusedIndex = index; this.isInitialFocusSet = true; }
Returns the element to click on upon navigation. The focused element in the document is preferred (if there is one) over the highlighted result. Note that the focused element does not have to be an anchor <a> element. @param {boolean} linkOnly If true the focused element is preferred only when it is a link with "href" attribute. @return {Element}
focus
javascript
infokiller/web-search-navigator
src/main.js
https://github.com/infokiller/web-search-navigator/blob/master/src/main.js
MIT
focusNext(shouldWrap) { if (this.focusedIndex < this.searchResults.length - 1) { this.focus(this.focusedIndex + 1); } else if (shouldWrap) { this.focus(0); } }
Returns the element to click on upon navigation. The focused element in the document is preferred (if there is one) over the highlighted result. Note that the focused element does not have to be an anchor <a> element. @param {boolean} linkOnly If true the focused element is preferred only when it is a link with "href" attribute. @return {Element}
focusNext
javascript
infokiller/web-search-navigator
src/main.js
https://github.com/infokiller/web-search-navigator/blob/master/src/main.js
MIT
focusPrevious(shouldWrap) { if (this.focusedIndex > 0) { this.focus(this.focusedIndex - 1); } else if (shouldWrap) { this.focus(this.searchResults.length - 1); } else { window.scrollTo(window.scrollX, 0); } }
Returns the element to click on upon navigation. The focused element in the document is preferred (if there is one) over the highlighted result. Note that the focused element does not have to be an anchor <a> element. @param {boolean} linkOnly If true the focused element is preferred only when it is a link with "href" attribute. @return {Element}
focusPrevious
javascript
infokiller/web-search-navigator
src/main.js
https://github.com/infokiller/web-search-navigator/blob/master/src/main.js
MIT
focusDown(shouldWrap) { if ( this.focusedIndex + this.searchResults.itemsPerRow < this.searchResults.length ) { this.focus(this.focusedIndex + this.searchResults.itemsPerRow); } else if (shouldWrap) { const focusedRowIndex = this.focusedIndex % this.searchResults.itemsPerRow; this.focus(focusedRowIndex); } }
Returns the element to click on upon navigation. The focused element in the document is preferred (if there is one) over the highlighted result. Note that the focused element does not have to be an anchor <a> element. @param {boolean} linkOnly If true the focused element is preferred only when it is a link with "href" attribute. @return {Element}
focusDown
javascript
infokiller/web-search-navigator
src/main.js
https://github.com/infokiller/web-search-navigator/blob/master/src/main.js
MIT
focusUp(shouldWrap) { if (this.focusedIndex - this.searchResults.itemsPerRow >= 0) { this.focus(this.focusedIndex - this.searchResults.itemsPerRow); } else if (shouldWrap) { const focusedRowIndex = this.focusedIndex % this.searchResults.itemsPerRow; this.focus( this.searchResults - 1 - this.searchResults.itemsPerRow + focusedRowIndex, ); } else { window.scrollTo(window.scrollY, 0); } }
Returns the element to click on upon navigation. The focused element in the document is preferred (if there is one) over the highlighted result. Note that the focused element does not have to be an anchor <a> element. @param {boolean} linkOnly If true the focused element is preferred only when it is a link with "href" attribute. @return {Element}
focusUp
javascript
infokiller/web-search-navigator
src/main.js
https://github.com/infokiller/web-search-navigator/blob/master/src/main.js
MIT
constructor() { this.bindings = []; this.bindingsToggle = {active: true}; }
Returns the element to click on upon navigation. The focused element in the document is preferred (if there is one) over the highlighted result. Note that the focused element does not have to be an anchor <a> element. @param {boolean} linkOnly If true the focused element is preferred only when it is a link with "href" attribute. @return {Element}
constructor
javascript
infokiller/web-search-navigator
src/main.js
https://github.com/infokiller/web-search-navigator/blob/master/src/main.js
MIT
async init() { this.options = new ExtensionOptions(); await this.options.load(); this.searchEngine = await getSearchEngine(this.options.sync.getAll()); if (this.searchEngine == null) { return; } const sleep = (milliseconds) => { return new Promise((resolve) => setTimeout(resolve, milliseconds)); }; await sleep(this.options.sync.get('delay')); this.injectCSS(); this.initKeybindings(); }
Returns the element to click on upon navigation. The focused element in the document is preferred (if there is one) over the highlighted result. Note that the focused element does not have to be an anchor <a> element. @param {boolean} linkOnly If true the focused element is preferred only when it is a link with "href" attribute. @return {Element}
init
javascript
infokiller/web-search-navigator
src/main.js
https://github.com/infokiller/web-search-navigator/blob/master/src/main.js
MIT
sleep = (milliseconds) => { return new Promise((resolve) => setTimeout(resolve, milliseconds)); }
Returns the element to click on upon navigation. The focused element in the document is preferred (if there is one) over the highlighted result. Note that the focused element does not have to be an anchor <a> element. @param {boolean} linkOnly If true the focused element is preferred only when it is a link with "href" attribute. @return {Element}
sleep
javascript
infokiller/web-search-navigator
src/main.js
https://github.com/infokiller/web-search-navigator/blob/master/src/main.js
MIT
sleep = (milliseconds) => { return new Promise((resolve) => setTimeout(resolve, milliseconds)); }
Returns the element to click on upon navigation. The focused element in the document is preferred (if there is one) over the highlighted result. Note that the focused element does not have to be an anchor <a> element. @param {boolean} linkOnly If true the focused element is preferred only when it is a link with "href" attribute. @return {Element}
sleep
javascript
infokiller/web-search-navigator
src/main.js
https://github.com/infokiller/web-search-navigator/blob/master/src/main.js
MIT
injectCSS() { const style = document.createElement('style'); style.textContent = this.options.sync.get('customCSS'); document.head.append(style); }
Returns the element to click on upon navigation. The focused element in the document is preferred (if there is one) over the highlighted result. Note that the focused element does not have to be an anchor <a> element. @param {boolean} linkOnly If true the focused element is preferred only when it is a link with "href" attribute. @return {Element}
injectCSS
javascript
infokiller/web-search-navigator
src/main.js
https://github.com/infokiller/web-search-navigator/blob/master/src/main.js
MIT
initKeybindings() { this.bindingsToggle['active'] = false; for (const [shortcut, element, ,] of this.bindings) { /* eslint-disable-next-line new-cap */ const ms = Mousetrap(element); ms.unbind(shortcut); ms.reset(); } const isFirstCall = this.bindings.length === 0; this.bindings = []; // UGLY WORKAROUND: Results navigation breaks YouTube space keybinding for // pausing/resuming a video. A workaround is to click on an element on the // page (except the video), but for now I'm disabling results navigation // when watching a video. // TODO: Find a proper fix. if (!window.location.href.match(/^https:\/\/(www)\.youtube\.com\/watch/)) { this.initResultsNavigation(isFirstCall); } this.initTabsNavigation(); this.initChangeToolsNavigation(); this.initSearchInputNavigation(); this.bindingsToggle = {active: true}; bindKeys(this.bindings, this.bindingsToggle); }
Returns the element to click on upon navigation. The focused element in the document is preferred (if there is one) over the highlighted result. Note that the focused element does not have to be an anchor <a> element. @param {boolean} linkOnly If true the focused element is preferred only when it is a link with "href" attribute. @return {Element}
initKeybindings
javascript
infokiller/web-search-navigator
src/main.js
https://github.com/infokiller/web-search-navigator/blob/master/src/main.js
MIT
initSearchInputNavigation() { let searchInput = document.querySelector( this.searchEngine.searchBoxSelector, ); if (searchInput == null) { return; } // Only apply the extension logic if the key is not something the user may // have wanted to type into the searchbox, so that we don't interfere with // regular typing. const shouldHandleSearchInputKey = (event) => { return event.ctrlKey || event.metaKey || event.key === 'Escape'; }; // In Github, the search input element changes while in the page, so we // redetect it if it's not visible. const detectSearchInput = () => { if (searchInput != null && searchInput.offsetParent != null) { return true; } searchInput = document.querySelector(this.searchEngine.searchBoxSelector); return searchInput != null && searchInput.offsetParent != null; }; // If insideSearchboxHandler returns true, outsideSearchboxHandler will also // be called (because it's defined on document, hence has lower priority), // in which case we don't want to handle the event. Therefore, we store the // last event handled in insideSearchboxHandler, and only handle the event // in outsideSearchboxHandler if it's not the same one. let lastEvent; const outsideSearchboxHandler = (event) => { if (!detectSearchInput()) { return; } if (event === lastEvent) { return !shouldHandleSearchInputKey(event); } const element = document.activeElement; if ( element.isContentEditable || ['textarea', 'input'].includes(element.tagName.toLowerCase()) ) { return true; } // Scroll to the search box in case it's outside the viewport so that it's // clear to the user that it has focus. scrollToElement(this.searchEngine, searchInput); searchInput.select(); // searchInput.click(); return false; }; const insideSearchboxHandler = (event) => { if (!detectSearchInput()) { return; } lastEvent = event; if (!shouldHandleSearchInputKey(event)) { return true; } // Everything is selected; deselect all. if ( searchInput.selectionStart === 0 && searchInput.selectionEnd === searchInput.value.length ) { // Scroll to the search box in case it's outside the viewport so that // it's clear to the user that it has focus. scrollToElement(this.searchEngine, searchInput); searchInput.setSelectionRange( searchInput.value.length, searchInput.value.length, ); return false; } // Closing search suggestions via document.body.click() or // searchInput.blur() breaks the state of google's controller. // The suggestion box is closed, yet it won't re-appear on the next // search box focus event. // Input can be blurred only when the suggestion box is already // closed, hence the blur event is queued. window.setTimeout(() => searchInput.blur()); // Invoke the default handler which will close-up search suggestions // properly (google's controller won't break), but it won't remove the // focus. return true; }; this.register( this.options.sync.get('focusSearchInput'), outsideSearchboxHandler, ); // Bind globally, otherwise Mousetrap ignores keypresses inside inputs. // We must bind it separately to the search box element, or otherwise the // key event won't always be captured (for example this is the case on // Google Search as of 2020-06-22), presumably because the javascript in the // page will disable further processing. this.register( this.options.sync.get('focusSearchInput'), insideSearchboxHandler, searchInput, true, ); }
Returns the element to click on upon navigation. The focused element in the document is preferred (if there is one) over the highlighted result. Note that the focused element does not have to be an anchor <a> element. @param {boolean} linkOnly If true the focused element is preferred only when it is a link with "href" attribute. @return {Element}
initSearchInputNavigation
javascript
infokiller/web-search-navigator
src/main.js
https://github.com/infokiller/web-search-navigator/blob/master/src/main.js
MIT
shouldHandleSearchInputKey = (event) => { return event.ctrlKey || event.metaKey || event.key === 'Escape'; }
Returns the element to click on upon navigation. The focused element in the document is preferred (if there is one) over the highlighted result. Note that the focused element does not have to be an anchor <a> element. @param {boolean} linkOnly If true the focused element is preferred only when it is a link with "href" attribute. @return {Element}
shouldHandleSearchInputKey
javascript
infokiller/web-search-navigator
src/main.js
https://github.com/infokiller/web-search-navigator/blob/master/src/main.js
MIT
shouldHandleSearchInputKey = (event) => { return event.ctrlKey || event.metaKey || event.key === 'Escape'; }
Returns the element to click on upon navigation. The focused element in the document is preferred (if there is one) over the highlighted result. Note that the focused element does not have to be an anchor <a> element. @param {boolean} linkOnly If true the focused element is preferred only when it is a link with "href" attribute. @return {Element}
shouldHandleSearchInputKey
javascript
infokiller/web-search-navigator
src/main.js
https://github.com/infokiller/web-search-navigator/blob/master/src/main.js
MIT
detectSearchInput = () => { if (searchInput != null && searchInput.offsetParent != null) { return true; } searchInput = document.querySelector(this.searchEngine.searchBoxSelector); return searchInput != null && searchInput.offsetParent != null; }
Returns the element to click on upon navigation. The focused element in the document is preferred (if there is one) over the highlighted result. Note that the focused element does not have to be an anchor <a> element. @param {boolean} linkOnly If true the focused element is preferred only when it is a link with "href" attribute. @return {Element}
detectSearchInput
javascript
infokiller/web-search-navigator
src/main.js
https://github.com/infokiller/web-search-navigator/blob/master/src/main.js
MIT
detectSearchInput = () => { if (searchInput != null && searchInput.offsetParent != null) { return true; } searchInput = document.querySelector(this.searchEngine.searchBoxSelector); return searchInput != null && searchInput.offsetParent != null; }
Returns the element to click on upon navigation. The focused element in the document is preferred (if there is one) over the highlighted result. Note that the focused element does not have to be an anchor <a> element. @param {boolean} linkOnly If true the focused element is preferred only when it is a link with "href" attribute. @return {Element}
detectSearchInput
javascript
infokiller/web-search-navigator
src/main.js
https://github.com/infokiller/web-search-navigator/blob/master/src/main.js
MIT
outsideSearchboxHandler = (event) => { if (!detectSearchInput()) { return; } if (event === lastEvent) { return !shouldHandleSearchInputKey(event); } const element = document.activeElement; if ( element.isContentEditable || ['textarea', 'input'].includes(element.tagName.toLowerCase()) ) { return true; } // Scroll to the search box in case it's outside the viewport so that it's // clear to the user that it has focus. scrollToElement(this.searchEngine, searchInput); searchInput.select(); // searchInput.click(); return false; }
Returns the element to click on upon navigation. The focused element in the document is preferred (if there is one) over the highlighted result. Note that the focused element does not have to be an anchor <a> element. @param {boolean} linkOnly If true the focused element is preferred only when it is a link with "href" attribute. @return {Element}
outsideSearchboxHandler
javascript
infokiller/web-search-navigator
src/main.js
https://github.com/infokiller/web-search-navigator/blob/master/src/main.js
MIT
outsideSearchboxHandler = (event) => { if (!detectSearchInput()) { return; } if (event === lastEvent) { return !shouldHandleSearchInputKey(event); } const element = document.activeElement; if ( element.isContentEditable || ['textarea', 'input'].includes(element.tagName.toLowerCase()) ) { return true; } // Scroll to the search box in case it's outside the viewport so that it's // clear to the user that it has focus. scrollToElement(this.searchEngine, searchInput); searchInput.select(); // searchInput.click(); return false; }
Returns the element to click on upon navigation. The focused element in the document is preferred (if there is one) over the highlighted result. Note that the focused element does not have to be an anchor <a> element. @param {boolean} linkOnly If true the focused element is preferred only when it is a link with "href" attribute. @return {Element}
outsideSearchboxHandler
javascript
infokiller/web-search-navigator
src/main.js
https://github.com/infokiller/web-search-navigator/blob/master/src/main.js
MIT
insideSearchboxHandler = (event) => { if (!detectSearchInput()) { return; } lastEvent = event; if (!shouldHandleSearchInputKey(event)) { return true; } // Everything is selected; deselect all. if ( searchInput.selectionStart === 0 && searchInput.selectionEnd === searchInput.value.length ) { // Scroll to the search box in case it's outside the viewport so that // it's clear to the user that it has focus. scrollToElement(this.searchEngine, searchInput); searchInput.setSelectionRange( searchInput.value.length, searchInput.value.length, ); return false; } // Closing search suggestions via document.body.click() or // searchInput.blur() breaks the state of google's controller. // The suggestion box is closed, yet it won't re-appear on the next // search box focus event. // Input can be blurred only when the suggestion box is already // closed, hence the blur event is queued. window.setTimeout(() => searchInput.blur()); // Invoke the default handler which will close-up search suggestions // properly (google's controller won't break), but it won't remove the // focus. return true; }
Returns the element to click on upon navigation. The focused element in the document is preferred (if there is one) over the highlighted result. Note that the focused element does not have to be an anchor <a> element. @param {boolean} linkOnly If true the focused element is preferred only when it is a link with "href" attribute. @return {Element}
insideSearchboxHandler
javascript
infokiller/web-search-navigator
src/main.js
https://github.com/infokiller/web-search-navigator/blob/master/src/main.js
MIT
insideSearchboxHandler = (event) => { if (!detectSearchInput()) { return; } lastEvent = event; if (!shouldHandleSearchInputKey(event)) { return true; } // Everything is selected; deselect all. if ( searchInput.selectionStart === 0 && searchInput.selectionEnd === searchInput.value.length ) { // Scroll to the search box in case it's outside the viewport so that // it's clear to the user that it has focus. scrollToElement(this.searchEngine, searchInput); searchInput.setSelectionRange( searchInput.value.length, searchInput.value.length, ); return false; } // Closing search suggestions via document.body.click() or // searchInput.blur() breaks the state of google's controller. // The suggestion box is closed, yet it won't re-appear on the next // search box focus event. // Input can be blurred only when the suggestion box is already // closed, hence the blur event is queued. window.setTimeout(() => searchInput.blur()); // Invoke the default handler which will close-up search suggestions // properly (google's controller won't break), but it won't remove the // focus. return true; }
Returns the element to click on upon navigation. The focused element in the document is preferred (if there is one) over the highlighted result. Note that the focused element does not have to be an anchor <a> element. @param {boolean} linkOnly If true the focused element is preferred only when it is a link with "href" attribute. @return {Element}
insideSearchboxHandler
javascript
infokiller/web-search-navigator
src/main.js
https://github.com/infokiller/web-search-navigator/blob/master/src/main.js
MIT
registerObject(obj) { for (const [optionName, elementOrGetter] of Object.entries(obj)) { this.register(this.options.sync.get(optionName), () => { if (elementOrGetter == null) { return true; } let element; if (elementOrGetter instanceof HTMLElement) { element = elementOrGetter; } else { element = elementOrGetter(); } if (element == null) { return true; } // Some search engines use forms instead of links for navigation if (element.tagName == 'FORM') { element.submit(); } else { element.click(); } return false; }); } }
Returns the element to click on upon navigation. The focused element in the document is preferred (if there is one) over the highlighted result. Note that the focused element does not have to be an anchor <a> element. @param {boolean} linkOnly If true the focused element is preferred only when it is a link with "href" attribute. @return {Element}
registerObject
javascript
infokiller/web-search-navigator
src/main.js
https://github.com/infokiller/web-search-navigator/blob/master/src/main.js
MIT
initTabsNavigation() { const tabs = this.searchEngine.tabs || {}; this.registerObject(tabs); }
Returns the element to click on upon navigation. The focused element in the document is preferred (if there is one) over the highlighted result. Note that the focused element does not have to be an anchor <a> element. @param {boolean} linkOnly If true the focused element is preferred only when it is a link with "href" attribute. @return {Element}
initTabsNavigation
javascript
infokiller/web-search-navigator
src/main.js
https://github.com/infokiller/web-search-navigator/blob/master/src/main.js
MIT
initResultsNavigation(isFirstCall) { this.registerObject({ navigatePreviousResultPage: this.searchEngine.previousPageButton, navigateNextResultPage: this.searchEngine.nextPageButton, }); this.resetResultsManager(); let gridNavigation = this.resultsManager.searchResults.gridNavigation; this.registerResultsNavigationKeybindings(gridNavigation); // NOTE: we must not call onChangedResults multiple times, otherwise the // URL change detection logic (which exists in YouTube) will break. if (!isFirstCall || !this.searchEngine.onChangedResults) { return; } this.searchEngine.onChangedResults((appendedOnly) => { if (appendedOnly) { this.resultsManager.reloadSearchResults(); } else { this.resetResultsManager(); } // In YouTube, the initial load does not always detect the grid navigation // (because it can happen before results are actually loaded to the page). // In this case, we must rebind the navigation keys after the results are // loaded. if (gridNavigation != this.resultsManager.searchResults.gridNavigation) { gridNavigation = this.resultsManager.searchResults.gridNavigation; this.initKeybindings(); } }); }
Returns the element to click on upon navigation. The focused element in the document is preferred (if there is one) over the highlighted result. Note that the focused element does not have to be an anchor <a> element. @param {boolean} linkOnly If true the focused element is preferred only when it is a link with "href" attribute. @return {Element}
initResultsNavigation
javascript
infokiller/web-search-navigator
src/main.js
https://github.com/infokiller/web-search-navigator/blob/master/src/main.js
MIT
resetResultsManager() { if (this.resultsManager != null && this.resultsManager.focusedIndex >= 0) { const searchResult = this.resultsManager.searchResults[this.resultsManager.focusedIndex]; // NOTE: it seems that search results can become undefined when the DOM // elements are removed (for example when the results change). if (searchResult != null) { this.resultsManager.unhighlight(searchResult); } } this.resultsManager = new SearchResultsManager( this.searchEngine, this.options, ); this.resultsManager.reloadSearchResults(); }
Returns the element to click on upon navigation. The focused element in the document is preferred (if there is one) over the highlighted result. Note that the focused element does not have to be an anchor <a> element. @param {boolean} linkOnly If true the focused element is preferred only when it is a link with "href" attribute. @return {Element}
resetResultsManager
javascript
infokiller/web-search-navigator
src/main.js
https://github.com/infokiller/web-search-navigator/blob/master/src/main.js
MIT
registerResultsNavigationKeybindings(gridNavigation) { const getOpt = (key) => { return this.options.sync.get(key); }; const onFocusChange = (callback) => { return () => { if (!this.resultsManager.isInitialFocusSet) { this.resultsManager.focus(0); } else { const _callback = callback.bind(this.resultsManager); _callback(getOpt('wrapNavigation')); } return false; }; }; if (!gridNavigation) { this.register( getOpt('nextKey'), onFocusChange(this.resultsManager.focusNext), ); this.register( getOpt('previousKey'), onFocusChange(this.resultsManager.focusPrevious), ); } else { this.register( getOpt('nextKey'), onFocusChange(this.resultsManager.focusDown), ); this.register( getOpt('previousKey'), onFocusChange(this.resultsManager.focusUp), ); // Left this.register( getOpt('navigatePreviousResultPage'), onFocusChange(this.resultsManager.focusPrevious), ); // Right this.register( getOpt('navigateNextResultPage'), onFocusChange(this.resultsManager.focusNext), ); } this.register(getOpt('navigateKey'), () => { const link = this.resultsManager.getElementToNavigate(); if (link == null) { return true; } const lastNavigation = this.options.local.values; lastNavigation.lastQueryUrl = location.href; lastNavigation.lastFocusedIndex = this.resultsManager.focusedIndex; this.options.local.save(); // If the element is a link, use the href to directly navigate, since some // websites will open it in a new tab. if (link.localName === 'a' && link.href) { window.location.href = link.href; } else { link.click(); } return false; }); this.register(getOpt('navigateNewTabKey'), () => { const link = this.resultsManager.getElementToNavigate(true); if (link == null) { return true; } browser.runtime.sendMessage({ type: 'tabsCreate', options: { url: link.href, active: true, }, }); return false; }); this.register(getOpt('navigateNewTabBackgroundKey'), () => { const link = this.resultsManager.getElementToNavigate(true); if (link == null) { return true; } if (getOpt('simulateMiddleClick')) { const mouseEventParams = { bubbles: true, cancelable: false, view: window, button: 1, which: 2, buttons: 0, clientX: link.getBoundingClientRect().x, clientY: link.getBoundingClientRect().y, }; const middleClickMousedown = new MouseEvent( 'mousedown', mouseEventParams, ); link.dispatchEvent(middleClickMousedown); const middleClickMouseup = new MouseEvent('mouseup', mouseEventParams); link.dispatchEvent(middleClickMouseup); } browser.runtime.sendMessage({ type: 'tabsCreate', options: { url: link.href, active: false, }, }); return false; }); this.register(getOpt('copyUrlKey'), () => { const link = this.resultsManager.getElementToNavigate(); if ( link == null || link.localName !== 'a' || !link.href || !navigator.clipboard ) { return true; } navigator.clipboard.writeText(link.href).then( () => false, (err) => true, ); }); }
Returns the element to click on upon navigation. The focused element in the document is preferred (if there is one) over the highlighted result. Note that the focused element does not have to be an anchor <a> element. @param {boolean} linkOnly If true the focused element is preferred only when it is a link with "href" attribute. @return {Element}
registerResultsNavigationKeybindings
javascript
infokiller/web-search-navigator
src/main.js
https://github.com/infokiller/web-search-navigator/blob/master/src/main.js
MIT
getOpt = (key) => { return this.options.sync.get(key); }
Returns the element to click on upon navigation. The focused element in the document is preferred (if there is one) over the highlighted result. Note that the focused element does not have to be an anchor <a> element. @param {boolean} linkOnly If true the focused element is preferred only when it is a link with "href" attribute. @return {Element}
getOpt
javascript
infokiller/web-search-navigator
src/main.js
https://github.com/infokiller/web-search-navigator/blob/master/src/main.js
MIT
getOpt = (key) => { return this.options.sync.get(key); }
Returns the element to click on upon navigation. The focused element in the document is preferred (if there is one) over the highlighted result. Note that the focused element does not have to be an anchor <a> element. @param {boolean} linkOnly If true the focused element is preferred only when it is a link with "href" attribute. @return {Element}
getOpt
javascript
infokiller/web-search-navigator
src/main.js
https://github.com/infokiller/web-search-navigator/blob/master/src/main.js
MIT
onFocusChange = (callback) => { return () => { if (!this.resultsManager.isInitialFocusSet) { this.resultsManager.focus(0); } else { const _callback = callback.bind(this.resultsManager); _callback(getOpt('wrapNavigation')); } return false; }; }
Returns the element to click on upon navigation. The focused element in the document is preferred (if there is one) over the highlighted result. Note that the focused element does not have to be an anchor <a> element. @param {boolean} linkOnly If true the focused element is preferred only when it is a link with "href" attribute. @return {Element}
onFocusChange
javascript
infokiller/web-search-navigator
src/main.js
https://github.com/infokiller/web-search-navigator/blob/master/src/main.js
MIT
onFocusChange = (callback) => { return () => { if (!this.resultsManager.isInitialFocusSet) { this.resultsManager.focus(0); } else { const _callback = callback.bind(this.resultsManager); _callback(getOpt('wrapNavigation')); } return false; }; }
Returns the element to click on upon navigation. The focused element in the document is preferred (if there is one) over the highlighted result. Note that the focused element does not have to be an anchor <a> element. @param {boolean} linkOnly If true the focused element is preferred only when it is a link with "href" attribute. @return {Element}
onFocusChange
javascript
infokiller/web-search-navigator
src/main.js
https://github.com/infokiller/web-search-navigator/blob/master/src/main.js
MIT
initChangeToolsNavigation() { if (this.searchEngine.changeTools == null) { return; } const getOpt = (key) => { return this.options.sync.get(key); }; this.register(getOpt('navigateShowAll'), () => this.searchEngine.changeTools('a'), ); this.register(getOpt('navigateShowHour'), () => this.searchEngine.changeTools('h'), ); this.register(getOpt('navigateShowDay'), () => this.searchEngine.changeTools('d'), ); this.register(getOpt('navigateShowWeek'), () => this.searchEngine.changeTools('w'), ); this.register(getOpt('navigateShowMonth'), () => this.searchEngine.changeTools('m'), ); this.register(getOpt('navigateShowYear'), () => this.searchEngine.changeTools('y'), ); this.register(getOpt('toggleVerbatimSearch'), () => this.searchEngine.changeTools('v'), ); this.register(getOpt('toggleSort'), () => this.searchEngine.changeTools(null), ); this.register(getOpt('showImagesLarge'), () => this.searchEngine.changeImageSize('l'), ); this.register(getOpt('showImagesMedium'), () => this.searchEngine.changeImageSize('e'), ); this.register(getOpt('showImagesIcon'), () => this.searchEngine.changeImageSize('i'), ); }
Returns the element to click on upon navigation. The focused element in the document is preferred (if there is one) over the highlighted result. Note that the focused element does not have to be an anchor <a> element. @param {boolean} linkOnly If true the focused element is preferred only when it is a link with "href" attribute. @return {Element}
initChangeToolsNavigation
javascript
infokiller/web-search-navigator
src/main.js
https://github.com/infokiller/web-search-navigator/blob/master/src/main.js
MIT
getOpt = (key) => { return this.options.sync.get(key); }
Returns the element to click on upon navigation. The focused element in the document is preferred (if there is one) over the highlighted result. Note that the focused element does not have to be an anchor <a> element. @param {boolean} linkOnly If true the focused element is preferred only when it is a link with "href" attribute. @return {Element}
getOpt
javascript
infokiller/web-search-navigator
src/main.js
https://github.com/infokiller/web-search-navigator/blob/master/src/main.js
MIT
getOpt = (key) => { return this.options.sync.get(key); }
Returns the element to click on upon navigation. The focused element in the document is preferred (if there is one) over the highlighted result. Note that the focused element does not have to be an anchor <a> element. @param {boolean} linkOnly If true the focused element is preferred only when it is a link with "href" attribute. @return {Element}
getOpt
javascript
infokiller/web-search-navigator
src/main.js
https://github.com/infokiller/web-search-navigator/blob/master/src/main.js
MIT
register(shortcuts, callback, element = document, global = false) { for (const shortcut of shortcuts) { this.bindings.push([shortcut, element, global, callback]); } }
Returns the element to click on upon navigation. The focused element in the document is preferred (if there is one) over the highlighted result. Note that the focused element does not have to be an anchor <a> element. @param {boolean} linkOnly If true the focused element is preferred only when it is a link with "href" attribute. @return {Element}
register
javascript
infokiller/web-search-navigator
src/main.js
https://github.com/infokiller/web-search-navigator/blob/master/src/main.js
MIT
constructor(storage, defaultValues) { this.storage = storage; this.values = {}; this.defaultValues = defaultValues; }
@param {StorageArea} storage The storage area to which this section will write. @param {Object} defaultValues The default options. @constructor
constructor
javascript
infokiller/web-search-navigator
src/options.js
https://github.com/infokiller/web-search-navigator/blob/master/src/options.js
MIT
load() { // this.storage.get(null) returns all the data stored: // https://developer.chrome.com/extensions/storage#method-StorageArea-get return this.storage.get(null).then((values) => { this.values = values; // Prior to versions 0.4.* the keybindings were stored as strings, so we // migrate them to arrays if needed. let migrated = false; for (const [key, value] of Object.entries(this.values)) { if (!(key in DEFAULT_KEYBINDINGS) || Array.isArray(value)) { continue; } migrated = true; this.values[key] = keybindingStringToArray(value); } if (migrated) { return this.save(); } }); }
@param {StorageArea} storage The storage area to which this section will write. @param {Object} defaultValues The default options. @constructor
load
javascript
infokiller/web-search-navigator
src/options.js
https://github.com/infokiller/web-search-navigator/blob/master/src/options.js
MIT
save() { return this.storage.set(this.values); }
@param {StorageArea} storage The storage area to which this section will write. @param {Object} defaultValues The default options. @constructor
save
javascript
infokiller/web-search-navigator
src/options.js
https://github.com/infokiller/web-search-navigator/blob/master/src/options.js
MIT
get(key) { const value = this.values[key]; if (value != null) { return value; } return this.defaultValues[key]; }
@param {StorageArea} storage The storage area to which this section will write. @param {Object} defaultValues The default options. @constructor
get
javascript
infokiller/web-search-navigator
src/options.js
https://github.com/infokiller/web-search-navigator/blob/master/src/options.js
MIT
set(key, value) { this.values[key] = value; }
@param {StorageArea} storage The storage area to which this section will write. @param {Object} defaultValues The default options. @constructor
set
javascript
infokiller/web-search-navigator
src/options.js
https://github.com/infokiller/web-search-navigator/blob/master/src/options.js
MIT
clear() { return this.storage.clear().then(() => { this.values = {}; }); }
@param {StorageArea} storage The storage area to which this section will write. @param {Object} defaultValues The default options. @constructor
clear
javascript
infokiller/web-search-navigator
src/options.js
https://github.com/infokiller/web-search-navigator/blob/master/src/options.js
MIT
getAll() { // Merge options from storage with defaults. return {...this.defaultValues, ...this.values}; }
@param {StorageArea} storage The storage area to which this section will write. @param {Object} defaultValues The default options. @constructor
getAll
javascript
infokiller/web-search-navigator
src/options.js
https://github.com/infokiller/web-search-navigator/blob/master/src/options.js
MIT
createSyncedOptions = () => { return new BrowserStorage(browser.storage.sync, DEFAULT_OPTIONS); }
@param {StorageArea} storage The storage area to which this section will write. @param {Object} defaultValues The default options. @constructor
createSyncedOptions
javascript
infokiller/web-search-navigator
src/options.js
https://github.com/infokiller/web-search-navigator/blob/master/src/options.js
MIT
createSyncedOptions = () => { return new BrowserStorage(browser.storage.sync, DEFAULT_OPTIONS); }
@param {StorageArea} storage The storage area to which this section will write. @param {Object} defaultValues The default options. @constructor
createSyncedOptions
javascript
infokiller/web-search-navigator
src/options.js
https://github.com/infokiller/web-search-navigator/blob/master/src/options.js
MIT