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 getElementsByAttribute = (target, attr) => { | |
const nodeArray = []; | |
const considerNode = node => node.hasAttribute(attr) ? 1 : 3; | |
const treeWalker = document.createTreeWalker(target, 1, { acceptNode: considerNode }, false); | |
while(treeWalker.nextNode()) nodeArray.push(treeWalker.currentNode); | |
return nodeArray | |
}; |
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
/** | |
* Very simple Pub/Sub implementation using Symbols and setImmediate. | |
*/ | |
const topics = {}; | |
const getTokens = (str, obj) => Object.getOwnPropertySymbols(obj).filter(t => t.toString() === `Symbol(${str})`); | |
export default { | |
subscribe: (topic, listener) => { | |
const token = Symbol(topic); | |
topics[token] = listener; |
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
let hasPreload = false; | |
try { | |
hasPreload = document.createElement("link").relList.supports("preload"); | |
} catch(err) {} | |
const hasStyle = href => [...document.styleSheets].some(ss => href === ss.href); | |
const defaults = { | |
media: 'all', | |
crossorigin: undefined, |
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
import test from 'tape'; | |
// For each unit test you write, | |
// answer these questions: | |
test('What component aspect are you testing?', assert => { | |
const actual = 'What is the actual output?'; | |
const expected = 'What is the expected output?'; | |
assert.equal(actual, expected, | |
'What should the feature do?'); |
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
let passive = false; | |
window.addEventListener("detectPassiveSupport", null, Object.defineProperty({}, 'passive', { | |
get: function() { | |
passive = { passive: true }; | |
} | |
})); | |
export { passive as default }; | |
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
import passive from './setPassiveEvent.js'; | |
// DOMMouseScroll is specific to Firefox | |
const eventTypes = ['mousewheel', 'touchmove', 'DOMMouseScroll']; | |
class ScrollPosition { | |
constructor(viewport) { | |
this.viewport = viewport || document.body; | |
this.scrollPosition = this.getScrollPosition(); |
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: https://stackoverflow.com/questions/13627308/add-st-nd-rd-and-th-ordinal-suffix-to-a-number | |
const ordinalConverter = (i) => { | |
const ordinal = ["st","nd","rd"][((i+90)%100-10)%10-1]||"th"; | |
return `${i}${ordinal}`; | |
}; | |
export ordinalConverter; | |
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 domReady(fn) { | |
(/d$|^i|^c/).test(document.readyState) ? requestAnimationFrame(fn) : document.addEventListener('DOMContentLoaded', fn); | |
} |
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
export default function(reg) { | |
// select the target node | |
const HEAD = document.querySelector('head'); | |
// configuration of the observer: | |
const CONFIG = { attributes: false, childList: true, characterData: false }; | |
// create an observer instance | |
const observer = new MutationObserver(mutations => { | |
mutations.forEach(mutation => { | |
const node = mutation.addedNodes[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
/** | |
* Module file domReady.js | |
*/ | |
let domReady = () => { | |
return new Promise((resolve, reject) => { | |
(document.readyState) || reject("Can't resolve document readystate"); | |
let listener; | |
(/d$|^i|^c/).test(document.readyState) ? resolve() : document.addEventListener("DOMContentLoaded", listener = event => { | |
document.removeEventListener("DOMContentLoaded", listener); |