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 decodeHTML = (str) => { | |
const elem = document.createElement('div') | |
elem.innerHTML = str | |
return (elem.childNodes.length===0 ? '' : elem.childNodes[0].nodeValue) | |
} |
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 nicetry = (fn) => { | |
try { return fn() } | |
catch (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
const hasTouchscreen = () => { | |
const mobileDevice = (/Android|iPhone|iPad|iPod/i).test(navigator.userAgent || navigator.vendor || window.opera) | |
const onTouchEnd = ('ontouchend' in document.documentElement) | |
return (mobileDevice && onTouchEnd) | |
} |
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 debounce = function(fn, duration) { | |
let timeout = null | |
return (...args) => { | |
clearTimeout(timeout) | |
timeout = setTimeout(() => fn(...args), duration) |
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 select = (query, elem = null) => { | |
elem = (elem==null ? document : elem) | |
let elems = elem.querySelectorAll(query) | |
if (elems==null) return [] | |
else return Array.prototype.slice.call(elems, 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
const toggler = (initState) => { | |
initState = initState!==false | |
let state = initState | |
return { | |
get : () => state, | |
reset : () => state = initState, | |
toggle : () => state = !state, |
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 counter = (min, max, initial) => { | |
let index = initial - min | |
let length = max - min + 1 | |
return (modifier = 0) => { | |
index = (index + modifier) % length | |
if (index>=0) index = 0 + index |
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 limit = (min, max, num) => Math.min(Math.max(num, min), max) |
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 stopEvent = (e = {}) => { | |
if (typeof e.stopPropagation==='function') e.stopPropagation() | |
if (typeof e.preventDefault==='function') e.preventDefault() | |
} |
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 scrollroot = (() => { | |
if ('scrollingElement' in document) return document.scrollingElement | |
const initial = document.documentElement.scrollTop | |
document.documentElement.scrollTop = initial + 1 | |
const updated = document.documentElement.scrollTop | |
document.documentElement.scrollTop = initial | |