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
| var fitElement = function fitElement(elementSelector, elementAspect) { | |
| var element = (typeof elementSelector === 'string' || elementSelector instanceof String) ? document.querySelector(elementSelector) : elementSelector, | |
| parW = element.parentNode.clientWidth, | |
| parH = element.parentNode.clientHeight, | |
| parAsp = parW / parH, | |
| aspect = elementAspect || 16 / 9, | |
| elW, elH; | |
| if (aspect > parAsp) { | |
| elW = parW; | |
| elH = elW / aspect; |
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
| function BrowserInfo() { | |
| this.supported = false; | |
| this.isBrowser = true; | |
| this.webBrowser = null; | |
| this.webBrowserVer = null; | |
| this.os = 'unknown os'; | |
| var detectedUA = null; | |
| if (typeof window === 'undefined' || !window.navigator) { |
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
| /** | |
| * remove - removes DOM elements | |
| * working with: usual dom element, selector, jQuery object, Polymer object | |
| * @param {string | object} selectorOrObject - dom object | |
| */ | |
| function remove(selectorOrObject) { | |
| if (!selectorOrObject) { | |
| return; | |
| } |
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
| //source: http://stackoverflow.com/questions/4508574/remove-hash-from-url | |
| //Best is Homero Barbosa's answer below: | |
| history.pushState('', document.title, window.location.pathname); | |
| //... or, if you want to maintain the search parameters: | |
| history.pushState('', document.title, window.location.pathname + window.location.search); | |
| //Old, do not use, badwrongfun: | |
| // var loc = window.location.href, | |
| // index = loc.indexOf('#'); | |
| // if (index > 0) { |
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
| //https://developer.mozilla.org/en-US/docs/Web/Events/resize | |
| ; | |
| (function() { | |
| var throttle = function(type, name, obj_) { | |
| var obj = obj_ || window; | |
| var running = false; | |
| var func = function() { | |
| if (running) { | |
| return; | |
| } |
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
| //Setup | |
| let el = document.getElementById('thingy'); | |
| let elChild = document.createElement('div'); | |
| elChild.innerHTML = 'Content'; | |
| //Append | |
| el.appendChild(elChild); | |
| //Prepend | |
| el.insertBefore(elChild, el.firstChild); |
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
| const clone = data => { | |
| if (typeof data !== 'object' || data === null) { | |
| return data; | |
| } | |
| const copy = data instanceof Array ? data.constructor() : Object.create(Object.getPrototypeOf(data)); | |
| for (const [key, value] of Object.entries(data)) { | |
| copy[key] = clone(value); | |
| } | |
| return copy; | |
| }; |
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
| const prefetch = document.createElement('link'); | |
| prefetch.setAttribute('rel', 'prefetch'); | |
| prefetch.setAttribute('href', url); | |
| document.head.appendChild(prefetch); |
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
| // speed winners is: for-with-cached-length OR for-of-with-let > map > forEach | |
| for (let key of iterable) { | |
| // do stuff | |
| } | |
| for (let key in obj) { | |
| if (obj.hasOwnProperty(key)) { | |
| // do stuff | |
| } |