Skip to content

Instantly share code, notes, and snippets.

@cuylerstuwe
Last active January 15, 2020 17:57
Show Gist options
  • Save cuylerstuwe/7148acc820cdbc73f9c6d1f5a74f2844 to your computer and use it in GitHub Desktop.
Save cuylerstuwe/7148acc820cdbc73f9c6d1f5a74f2844 to your computer and use it in GitHub Desktop.
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