Last active
January 15, 2020 17:57
-
-
Save cuylerstuwe/7148acc820cdbc73f9c6d1f5a74f2844 to your computer and use it in GitHub Desktop.
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 documentFunctionMappings = { | |
"$": document.querySelector, | |
"$$": document.querySelectorAll, | |
"e$": document.addEventListener | |
}; | |
Object.entries(documentFunctionMappings).forEach(([key, fn]) => window[key] = fn.bind(document)); | |
const _noop = () => {}; | |
const _switch = (val, branches) => (branches[val] || branches.default || _noop)(); | |
const $createDosForAttr = (attr, attrValArrs, callbacks) => { | |
const { before, every, after } = callbacks; | |
every = typeof callbacks === "function" ? callbacks : every; | |
return attrValArrs.map(attrValArr => ( | |
() => { | |
(before || _noop)(); | |
const els = attrValArr.map(attrVal => $(`[${attr}="${attrVal}"]`)); | |
els.forEach(el => fnEach(el)); | |
(after || _noop)(); | |
} | |
)); | |
} | |
const $createDosForValueAttr = (attrValArrs, callbacks) => $createDosForAttr("value", attrValArrs, callbacks); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment