polyfill-query
Version:
A polyfill for DOM query, queryAll, and Elements
10 lines • 1.31 kB
JavaScript
!function(){function t(t,e){for(var r,n,o=[],l=-1,p=0,u=0;++l<t.length;){r=t.charAt(l)
t:if(i===r)++l
else{for(n=0;n<c.length;++n){if(nester=c[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(p,l)),p=++l)}}return o.push(t.slice(p,l)),o}function e(t,e){var r=[]
return l.call(t,function(t){p.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 p.call(o,this),l.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 i(t){return o.call(this,t)[0]||null}r.prototype.queryAll||(r.prototype.queryAll=o),r.prototype.query||(r.prototype.query=i)}function n(){}var o=Array.prototype.filter||function(t){for(var e=0,r=[];e<this.length;++e)t(this[e],e)&&r.push(this[e])
return r},l=Array.prototype.forEach||function(t){for(var e=0;e<this.length;++e)t(this[e],e)},p=Array.prototype.push,u=Array.prototype.sort,i="\\",c=[{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)}()