Created
November 13, 2014 10:31
-
-
Save DChinin/98032a9cfba8e8d89b5b 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
(function(win){ | |
'use strict'; | |
var doc = win.document, simpleRe = /^(#?[\w-]+|\.[\w-.]+)$/, periodRe = /\./g, slice = [].slice; | |
win.query = function(selector, context){ | |
context = context || doc; | |
if(simpleRe.test(selector)){ | |
switch(selector.charAt(0)){ | |
case '#': | |
return context.getElementById(selector.substr(1)); | |
case '.': | |
return slice.call(context.getElementsByClassName(selector.substr(1).replace(periodRe, ' '))); | |
default: | |
return slice.call(context.getElementsByTagName(selector)); | |
} | |
} | |
return slice.call(context.querySelectorAll(selector)); | |
}; | |
})(this); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment