Last active
January 13, 2020 13:48
-
-
Save long-lazuli/6d394fa6b083f0f6da09a515ae4c3c31 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
// @jsxFactory: $create | |
// untested yet | |
const D=document,Arr=(a,b,e) => Array.prototype.slice.call(a,b,e) | |
export $ = (s,r=D) => r.querySelector(s) | |
export $$ = (s,r=D) => Arr(r.querySelectorAll(s)) | |
export $create = (t,p={},c,el) => ( | |
el=D.createElement(t), | |
Object.keys(p).forEach(k=>el.setAttribute(k,p[k])), | |
c&&(Array.isArray(c)?c:[c]).forEach(n=>el.appendChild(n.nodeType?n:D.createTextNode(n))), | |
el | |
) | |
export $walk = (el,f,cb)=>!f?null:el.childNodes.forEach(n=>n.nodeType==1?$walk(n,f,cb):cb?f(n)&&cb(n):f(n)) |
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
// @jsxFactory: $create | |
var D=document,Arr=function(a,b,e){return Array.prototype.slice.call(a,b,e)} | |
function $(s,r){r=r||D;return r.querySelector(s)} | |
function $$(s,r){r=r||D;return r.querySelectorAll(s)} | |
function $create(t,p,c){p=p||{};var el=D.createElement(t) | |
Object.keys(p).forEach(function(k){el.setAttribute(k,p[k])}) | |
c&&(Array.isArray(c)?c:[c]).forEach(function(n){el.appendChild(n.nodeType?n:D.createTextNode(n))}) | |
return el | |
} | |
function walkInDOM(elem, filterOrCallback, maybeCallback) { | |
// don't walk mindless | |
if(!filterOrCallback) return; | |
elem.childNodes.forEach(function(node){ | |
return node.nodeType===1 | |
? walkInDOM(node, filterOrCallback, maybeCallback) | |
// if you have a callback, you have a filter | |
: maybeCallback | |
// if filter return true, callback | |
? filterOrCallback(node) && maybeCallback(node) | |
// else, just callback | |
: filterOrCallback(node) | |
}) | |
} |
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
E(window, 'bs-style-event') | |
E($('form'), 'submit') | |
Ewhen( $('form'), 'submit', doShit ) | |
Ewhen( window, { beforeunload: doShit, onload: doShit} ) | |
Ewhen( $$('button'), ['click', 'keypress'], doShit ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Can do:
$(selector)
to get one element$$(selector)
to get a array of elements$create(tagName, attributes, children)
to create elements