This file contains hidden or 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
/** | |
* A simple function can be used to generate a random string with the specified length. | |
* And,the range of the characters is configurable. | |
* | |
* Default: | |
* len: 32 | |
* chars: '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghiklmnopqrstuvwxyz' | |
* | |
* Note: | |
* The method charAt will convert its first parameter to an integer by floor. |
This file contains hidden or 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
/* | |
* Notes: window.scrollX and window.scrollY is CSSOM Editor's Draft, but IE6-8 doesn't support it. | |
* Date: 2014-8-30 | |
* Ref: | |
* http://help.dottoro.com/ljnvjiow.php | |
* http://stackoverflow.com/questions/19635188/why-is-body-scrolltop-deprecated | |
* | |
* Account for zoom example: http://stackoverflow.com/questions/16618785/ie8-alternative-to-window-scrolly#answer-16618863 | |
*/ |
This file contains hidden or 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 if a number has a decimal place. | |
* Example: | |
* 12 --> false | |
* -12 --> false | |
* 0.12 --> true | |
* -0.12 --> true | |
* 12.12 --> true | |
* -12.12 --> true | |
* Reference: |
This file contains hidden or 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
/** | |
* Escape html with no dependencies. | |
* Ref: | |
* http://stackoverflow.com/questions/24816/escaping-html-strings-with-jquery#answer-12034334 | |
*/ | |
var escapeMap = { | |
"<": "<", | |
">": ">", | |
"&": "&", | |
"'": """, |
This file contains hidden or 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
/** | |
* Accessing nested object by the string (or namespace). | |
* Ref: | |
* http://stackoverflow.com/questions/6491463/accessing-nested-javascript-objects-with-string-key | |
*/ | |
function getProperty(obj, namespace) { | |
var props = namespace.split("."); | |
for (var i = 0; i < props.length; i++) { | |
if (obj.hasOwnProperty(props[i])) { | |
obj = obj[props[i]]; |
This file contains hidden or 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
/** | |
* Unique values in a array. | |
* | |
* Ref: | |
* http://stackoverflow.com/questions/1960473/unique-values-in-an-array#answer-14438954 | |
* http://stackoverflow.com/questions/1960473/unique-values-in-an-array#answer-1961068 | |
* | |
* Perf: | |
* http://jsperf.com/distinct-hash-vs-comparison | |
*/ |
This file contains hidden or 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
// Some utility functions to check the object's type. | |
// Ref: | |
// https://github.com/lifesinger/lifesinger.github.com/issues/175 | |
// https://github.com/seajs/seajs/issues/1314 | |
// Note: | |
// I think we should compare the compressed(min+gzip) file size. | |
function isType(type) { | |
return function(obj) { | |
return Object.prototype.toString.call(obj) == '[object ' + type + ']'; | |
}; |
This file contains hidden or 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 number of days in a month in javascript. | |
* | |
* Ref: | |
* http://stackoverflow.com/questions/315760/what-is-the-best-way-to-determine-the-number-of-days-in-a-month-with-javascript | |
*/ | |
function daysInMonth(year, month) { | |
var now = new Date; | |
month = typeof month != undefined ? month |
This file contains hidden or 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 if a attribute exists on the element | |
* | |
* IE6/7 doesn't support the `hasAttribute` method | |
* | |
* Ref: | |
* http://codereview.stackexchange.com/questions/10131/will-this-test-to-check-if-an-element-has-an-attribute-work | |
*/ | |
// Native javascript |