This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* This function is used to generate the page list like below: | |
* | |
* ``` | |
* [1] 2 3 4 5 6 » 20 | |
* 1 « 6 7 [8] 9 10 » 20 | |
* 1 « 15 16 17 18 19 [20] | |
* ``` | |
* | |
* Note: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Check whether the URL is absolute | |
* | |
* @param {string} url - The URL to check | |
* @returns {boolean} - If the url is absolute return true, otherwise return false | |
*/ | |
var isAbsoluteURL = function (url) { | |
return /^(?:[a-z][a-z0-9\-\.\+]*:)?\/\//i.test(url); | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Parse the URL string to get the details of the URL. | |
* | |
* The names of the properties of the returned object is same with the names of | |
* the properties in the `window.location` object in the browser, but the | |
* returned object only have one method, that is toString(). | |
* | |
* @typedef {Object} URLInformation The URL Information | |
* @property {string} protocol example: https: | |
* @property {string} hostname example: developer.mozilla.org |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Using String.prorotype.indexOf to search in the data array. | |
* This function just do simple match no rank in the result. | |
* | |
* @param {string} text text to search | |
* @param {any[]} array the data list | |
* @param {string[]} [keys] the keys that hold the string to be searched | |
* @returns {any[]} the filtered array | |
*/ | |
var searchByIndexOf = function (text, array, keys) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* debounce | |
* | |
* @param {number} time time to wait next call | |
* @param {(...any) => any} callback the callback function | |
* @returns {(...any) => any} | |
*/ | |
var debounce = function (time, callback) { | |
var timer = null; | |
var slice = Array.prototype.slice; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Get the index of the element in the given array | |
* | |
* @param {any} element the element to find | |
* @param {any[]} array the array to be searched | |
* @param {number} [fromIndex=0] the array index at which to begin the search | |
* @returns {number} returns the index of the element. if the element is not found, -1 is returned. | |
*/ | |
var indexOf = function (element, array, fromIndex) { | |
if (typeof Array.prototype.indexOf === 'function') { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var SimpleEvent = (function () { | |
/** | |
* A simple event registry, designed to exchange message among components | |
* | |
* API: | |
* | |
* * `SimpleEvent.prototype.emit(eventName, message)` | |
* * `SimpleEvent.prototype.on(eventName, listener)` | |
* * `SimpleEvent.prototype.off(eventName, listener)` | |
* * `SimpleEvent.prototype.once(eventName, listener)` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Get the first `Node` that has the `className` in the path from the `fromNode` to the `toNode` | |
* | |
* @param {Node} fromNode The `Node` at which the search begins | |
* @param {string} className The class name to test (only single className) | |
* @param {Node} [toNode] The optional `Node` at which the search ends | |
* @returns {Node} Returns the `Node` we found, if not found, `null` is returned | |
*/ | |
var closestNode = function (fromNode, className, toNode) { | |
var node = null; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Check whether the variable passed in is a normal object. Normal object means | |
* an object that is created by `{}` or `new Object()`. | |
* | |
* @param {any} it The variable to check | |
* @returns {boolean} Returns `true` if `it` is a normal object | |
*/ | |
var isNormalObject = function (it) { | |
if (!it || '[object Object]' !== {}.toString.call(it)) { | |
return false; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Merge the `source` into the `target`. This function will do deep copy, and | |
* modify the target object. | |
* | |
* @param {Object.<string, *>|any[]} target The target to merge into | |
* @param {Object.<string, *>|any[]} srouce The source to copy | |
* @returns {Object.<string, *>|any[]} returns The modified target | |
*/ | |
var merge = function(target, source) { | |
var toString = Object.prototype.toString; |
OlderNewer