polyfill-query
Version:
A polyfill for DOM query, queryAll, and Elements
9 lines • 1.16 kB
JavaScript
!function(){function t(t,e){for(var r,n,o=[],p=-1,l=0,u=0;++p<t.length;){r=t.charAt(p)
t:if(c===r)++p
else{for(n=0;n<a.length;++n){if(nester=a[n],nester.depth&&nester.end===r){--nester.depth,--u
break t}if(nester.start===r){++nester.depth,++u
break t}}u||e!==r||(o.push(t.slice(l,p)),l=++p)}}return o.push(t.slice(l,p)),o}function e(t,e){var r=[]
return p.call(t,function(t){l.apply(r,t.querySelectorAll(e))}),o.call(r,function(t,e){return e===r.indexOf(t)})}function r(r){function o(r){var o=new n
return l.call(o,this),p.call(t(r,","),function(r){var n=t(r.trim()," ")
o=e(o,n[0]),1<n.length&&(o=e(o,r))}),u.call(o,function(t,e){return 3-(6&t.compareDocumentPosition(e))}),o}function c(t){return o.call(this,t)[0]||null}r.prototype.queryAll||(r.prototype.queryAll=o),r.prototype.query||(r.prototype.query=c)}function n(){}var o=Array.prototype.filter,p=Array.prototype.forEach,l=Array.prototype.push,u=Array.prototype.sort,c="\\",a=[{start:"[",end:"]",depth:0},{start:"(",end:")",depth:0},{start:'"',end:'"',depth:0},{start:"'",end:"'",depth:0}]
n.prototype=[],n.prototype.constructor=n,window.Elements=window.Elements||n,r(Document||HTMLDocument),r(Element)}()