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 an event is supported. | |
| * Ref: http://perfectionkills.com/detecting-event-support-without-browser-sniffing/ | |
| */ | |
| function isEventSupported(event) { | |
| var testEl = document.createElement('div'); | |
| var isSupported; | |
| event = 'on' + event; | |
| isSupported = (event in testEl); |
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 closest matched element of an element. (Include itself) | |
| function closest(elem, className, context) { | |
| context = context || document; | |
| do { | |
| if (hasClass(elem, className)) return elem; | |
| } while ((elem = elem.parentNode) && elem !== context) | |
| return null; | |
| } |
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 window/viewport width and height. The window.innerWidth value includes the scrollbar, | |
| * and document.documentElement.clientWidth/document.body.clientWidth doesn't include. | |
| * Compatibility: IE6+ and other modern browsers | |
| */ | |
| function winW() { | |
| return window.innerWidth || document.documentElement.clientWidth; | |
| } | |
| function winH() { |
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 event delegation method. | |
| */ | |
| // closest method: https://gist.github.com/Alex1990/5547956babc593852c3a | |
| function delegate(elem, type, selector, listener, capture) { | |
| listener._delegateWrapper = function(e) { | |
| if (e.delegateTarget = closest(e.target, selector, elem)) { | |
| listener.call(e.delegateTarget, e); |
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 an element has the specified class. | |
| function hasClass(el, cls) { | |
| return (' ' + el.className + ' ').indexOf(' ' + cls + ' ') > -1; | |
| } |
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
| isIE = /MSIE|Trident/.test(navigator.userAgent); | |
| // isIE = 'ActiveXObject' in window; |
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
| /** | |
| * IE 11 has discarded the "MSIE" feature string. | |
| */ | |
| isIE11 = /Trident.*rv:11\.0/.test(navigator.userAgent); |
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
| /** | |
| * Valid number primitive regular expression. The keyword "Infinity" is invalid. | |
| */ | |
| var rNumber = /^[+-]?(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d+)?$/; |
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
| /** | |
| * Decimal number regular expression. | |
| * | |
| * Valid decimal strings: | |
| * ['1', '1.', '1.1', '.1', '+1', '+1.', '+1.1', '+.1', '-1', '-1.', '-1.1', '-.1'] | |
| * Invalid decimal strings: | |
| * ['', '.', '+.', '-.', '1.1.', '1..1', 'Infinity', '-Infinity'] | |
| * | |
| * Ref: | |
| * http://stackoverflow.com/questions/12117024/decimal-number-regular-expression |
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 to test performance. | |
| */ | |
| function benchmark() { | |
| var tests = Array.prototype.slice.call(arguments); | |
| var length = tests.length; | |
| var startTimes = Array(length); | |
| var result = Array(length); | |
| var times = typeof benchmark.times === 'number' ? benchmark.times/2 : 5000; |