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
escapeHTML = (html = '') => { | |
// Ensure that html is a string | |
html += '' | |
// Escape all critical characters | |
html = html.replace(/&/g, '&') | |
.replace(/</g, '<') | |
.replace(/>/g, '>') | |
.replace(/"/g, '"') |
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
const closest = (elem, className) => { | |
if (elem==null || elem.classList==null) return null | |
return (elem.classList.contains(className) ? elem : closest(elem.parentNode, className)) | |
} |
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
const decodeHTML = (str) => { | |
const elem = document.createElement('div') | |
elem.innerHTML = str | |
return (elem.childNodes.length===0 ? '' : elem.childNodes[0].nodeValue) | |
} |
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
const hasLocalStorage = () => { | |
const tmp = 'tmp' | |
try { | |
localStorage.setItem(tmp, tmp) | |
localStorage.removeItem(tmp) | |
return true |
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
const nicetry = (fn) => { | |
try { return fn() } | |
catch (e) {} | |
} |
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
const toClassString = (obj) => Object.keys(obj).filter((key) => obj[key]===true).join(' ').trim() |
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
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 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 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 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 |
OlderNewer