-
-
Save icek/e359679fa58b0e0d0b1c to your computer and use it in GitHub Desktop.
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
// original ofca/$.3.js | |
// based on https://gist.github.com/Potfur/5576225 & https://github.com/james2doyle/saltjs | |
// more info: https://plus.google.com/109231487156400680487/posts/63eZzzrBSb6 | |
// 2 bytes less than original ;) | |
// V1 - 160b | |
window.$ = function(s,c) { | |
c = { | |
'#': 'ById', | |
'.': 'sByClassName', | |
'@': 'sByName', | |
'=': 'sByTagName'}[s[0]]; | |
return document[c?'getElement'+c:'querySelectorAll'](s.slice(1)) | |
}; | |
// V2 - 160b | |
window.$ = function(s,c) { | |
return document[(c = { | |
'#': 'ById', | |
'.': 'sByClassName', | |
'@': 'sByName', | |
'=': 'sByTagName'}[s[0]])?'getElement'+c:'querySelectorAll'](s.slice(1)) | |
}; | |
// versions with scope | |
// $('#id',scope); throws error if scope != document | |
// based on V1 - 167b | |
window.$ = function(s,p,c) { | |
c = { | |
'#': 'ById', | |
'.': 'sByClassName', | |
'@': 'sByName', | |
'=': 'sByTagName'}[s[0]]; | |
return (p||document)[c?'getElement'+c:'querySelectorAll'](s.slice(1)) | |
}; | |
// based on V2 - 165b | |
window.$=function(s,c){ | |
return (c||document)[ | |
(c={'#':'ById','.':'sByClassName','@':'sByName','=':'sByTagName'}[s[0]]) | |
?'getElement'+c | |
:'querySelectorAll' | |
](s.slice(1)) | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment