-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathqsa.min.js
More file actions
31 lines (31 loc) · 8.93 KB
/
qsa.min.js
File metadata and controls
31 lines (31 loc) · 8.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
/*
* QSA CSS3 Selector Engine v1.3
*
* Copyright 2011, Dmitriy Pakhtinov ( spb.piksel@gmail.com )
*
* http://spb-piksel.ru/
*
* Dual licensed under the MIT and GPL licenses:
* http://www.opensource.org/licenses/mit-license.php
* http://www.gnu.org/licenses/gpl.html
*
* Update: 06-05-2012
*/
(function(G,B){var u=/\s*(?:(\*|(?:(?:\*|[\w\-]+)\|)?(?:[\w\-]+|\*)))?(?:\[\s*(?:((?:[\w\-]+\|)?[\w\-]+)\s*((?:~|\^|\$|\*|\||!)?=)\s*)?((?:".*?(?:(?:[\\]{2}(?="))|[^\\])"|'.*?(?:(?:[\\]{2}(?='))|[^\\])'|[^\]].*?)?)\s*\])?(?:(\.|#)([\w\-]+))?(?:(:(?::)?)([\w\-]+)(?:\(\s*([^)]+)\s*\))?)?(?:(?:\s*(?=\s))?(?:(?:\s(?=,|>|\+|~))?([\s,>+~](?!$)))?)?/g,H=!0,w=!1,A=G.document,o=A.documentElement,E=Array.prototype.slice,I=Array.prototype.splice,F=Array.prototype.push,t=A.createElement("div"),C=o.matchesSelector||
o.oMatchesSelector||o.mozMatchesSelector||o.webkitMatchesSelector||o.msMatchesSelector,K=C&&!C.call(t,"div"),J;t.innerHTML="<p class='TEST'></p>";J=!(!t.querySelectorAll||0===t.querySelectorAll(".TEST").length);var i={moveElems:function(){var b=!0;t.innerHTML="";t.appendChild(A.createComment(""));try{E.call(o.childNodes,0)}catch(d){b=!1}return 0<t.getElementsByTagName("*").length||!b?function(a,d,x,c,g){if(!x&&!c&&b)F.apply(d,E.call(a,0));else if(!x&&!c&&g)F.apply(d,a);else{c=0;for(g=d.length;a[c];c++)if(1===
a[c].nodeType&&(!x||x===a[c]))d[g++]=a[c];g===d.length||(d.length=g)}return d}:function(a,b,d){if(d){for(var c=0,g=b.length;a[c];c++)1===a[c].nodeType&&d===a[c]&&(b[g++]=a[c]);g===b.length||(b.length=g)}else F.apply(b,E.call(a,0));return b}}(),sortElems:function(){[0,0].sort(function(){H=!1;return 0});return o.compareDocumentPosition?function(b,d){if(b==d)return w=!0,0;if(o.compareDocumentPosition)return!b.compareDocumentPosition||!d.compareDocumentPosition?b.compareDocumentPosition?-1:1:b.compareDocumentPosition(d)&
4?-1:b===d?0:1}:"sourceIndex"in o?function(b,d){return b==d?(w=!0,0):!b.sourceIndex||!d.sourceIndex?b.sourceIndex?-1:1:b.sourceIndex-d.sourceIndex}:A.createRange?function(b,d){if(b==d)return w=!0,0;if(!b.ownerDocument||!d.ownerDocument)return b.ownerDocument?-1:1;var a=b.ownerDocument.createRange(),n=d.ownerDocument.createRange();a.setStart(b,0);a.setEnd(b,0);n.setStart(d,0);n.setEnd(d,0);return a.compareBoundaryPoints(Range.START_TO_END,n)}:function(b,d){b==d&&(w=!0);return 0}}(),attrMap:{"class":"className",
"for":"htmlFor"},attrHandle:{href:function(b){return b.getAttribute("href",2)},type:function(b){return b.getAttribute("type")},style:function(b){var d=b.getAttribute("style");return"object"===typeof d?b.style.cssText||"":d}},checkAttr:function(b,d,a){var a=i.attrHandle[a]?i.attrHandle[a](d):null!=d[a]?d[a]:d.getAttribute(a),d=b[3],b=b[4],n=a+"";return null==a?"!="===d:"="===d?n===b:"*="===d?0<=n.indexOf(b):"~="===d?0<=(" "+n+" ").indexOf(" "+b+" "):!b?n&&!1!==a:"!="===d?n!==b:"^="===d?0===n.indexOf(b):
"$="===d?n.substr(n.length-b.length)===b:"|="===d?n===b||n.substr(0,b.length+1)===b+"-":!1},filters:function(){function b(a,b,d){a=d-b[1];return 0===b[0]?0===a:0===a%b[0]&&0<=a/b[0]}var d={":":{"nth-child":function(a,d){return b(a,d,a.nodeIndex||1)},"nth-last-child":function(a,d){var i=a.parentNode;return b(a,d,(i&&(i._qsaCE||i.children.length||0)+1||2)-(a.nodeIndex||1))},"first-child":function(a){a=a.previousSibling;return!(a&&(3===a.nodeType?a.previousSibling:1))},"last-child":function(a){a=a.nextSibling;
return!(a&&(3===a.nodeType?a.nextSibling:1))},empty:function(a){return!a.firstChild},enabled:function(a){return!1===a.disabled&&"hidden"!==a.type},disabled:function(a){return!0===a.disabled},checked:function(a){return!0===a.checked},not:function(a,b,d,c){return(!c[1]||c[1]&&a.nodeName===c[1])&&0<i.checkRule(c,[a],[]).length?!1:!0},contains:function(a,b){return 0<=(a.textContent||a.innerText||a.nodeValue||a.value||"").indexOf(b)}},"::":{}};d[":"]["only-child"]=function(a){return d[":"]["first-child"](a)&&
d[":"]["last-child"](a)};return d}(),preFilters:function(){var b={"nth-child":function(b){var a=b[9].replace(/^\+|\s*/g,""),a=/(-?)(\d*)(?:n([+\-]?\d*))?/.exec("even"===a&&"2n"||"odd"===a&&"2n+1"||!/\D/.test(a)&&"0n+"+a||a);b[9]=[a[1]+(a[2]||1)-0,a[3]-0];return!(1===b[9][0]&&0===b[9][1])}};b["nth-last-child"]=b["nth-child"];return b}(),checkRule:function(b,d,a,n,x){var c,g,D=d.length,j,m,h=!1,q,p,e,f=0,v,k;!b[2]&&b[4]?(b[2]=b[4],b[4]=B):b[4]&&(b[4]=b[4].replace(/^(?:"(.*)"|'(.*)')$/,"$1$2").replace(/\\/g,
""));j=i.attrMap[b[2]]||b[2];q="."===b[5]?1:"#"===b[5]?2:!1;m=b[6];p=i.filters[b[7]]&&i.filters[b[7]][b[8]]||b[8]&&i.error(b[8])||!1;if(!j&&!q&&!p&&D)i.moveElems(d,a,x,!n,d instanceof Array);else{p&&b[9]&&(u.lastIndex=0,e=u.exec(b[9]),e[1]=e[1]&&"*"!==e[1]?e[1].replace("|",":").toUpperCase():B,i.preFilters[b[8]]&&(h=i.preFilters[b[8]](b)));c=a.length;for(n=0;n<D;n++)if(g=d[n],1===g.nodeType){j&&!i.checkAttr(b,g,j)&&(g=null);if(g&&q)if(1===q){if(!g.className||!(0<=(" "+g.className+" ").indexOf(" "+
m+" ")))g=null}else 2===q&&g.id!==m&&(g=null);if(g&&p){if(h&&(v=g.parentNode)&&(!g.nodeIndex||v._qsaCL!==v.children.length)){f=0;for(k=v.firstChild;k;k=k.nextSibling)1===k.nodeType&&(k.nodeIndex=++f);v._qsaCE=f;v._qsaCL=v.children.length}p(g,b[9],b,e)||(g=null)}x&&x!==g&&(g=null);g&&(a[c++]=g)}c===a.length||(a.length=c)}return a},parser:function(b,d,a,n,x){var c,g,D,j,m,h,q,p=b.length,e,f,v=!0,k,l=[],o=[],t,w,z=a[0],C=u.lastIndex,r,y,s;g=0;for(D=d.length;g<D;g++){w=d[g];s=C;do{u.lastIndex=s;c=u.exec(b);
(t=!c[4]&&!c[5]&&!c[7])&&!c[1]&&i.error(b.substring(s));s=u.lastIndex;r=c[1]&&"*"!==c[1]?c[1].replace("|",":"):B;k=c[10];if(t&&!0===v&&("~"===k||">"===k))o.push({tag:r?r.toUpperCase():r,rule:k}),k=!0,e=[];else if(">"===v){e=[];y=r?r.toUpperCase():r;for(j=0;f=l[j];j++){f=f.children;for(h=0;m=f[h];h++)1===m.nodeType&&(y?y===m.nodeName&&(e[e.length]=m):e[e.length]=m)}a[1]=!0}else if("+"===v||"~"===v){e=[];j=0;for(m=l.length;j<m;j++){y=r?r.toUpperCase():r;for(f=l[j];(f=f.nextSibling)&&!(1===f.nodeType&&
(y?y===f.nodeName&&(e[e.length]=f):e[e.length]=f,"+"===v)););}a[1]=!0}else if("#"===c[5]&&!(q=!1)||"id"===c[2]&&"="===c[3]&&(q=!0)){q&&(c[6]=c[4].replace(/^(?:"(.*)"|'(.*)')$/,"$1$2").replace(/\\/g,""),c[2]=c[3]=c[4]=B);e=[];h=c[6];if(w===A){l=[];y=r?r.toUpperCase():r;do if(m=A.getElementById(h))l[l.length]=m,m.setAttribute("id",h+" _");while(m);for(q=0;f=l[q];q++)if(f.setAttribute("id",h),!y||f.nodeName===y)e[e.length]=f}else{l=w.getElementsByTagName(r||"*");for(q=0;f=l[q];q++)f.id&&f.id===h&&(e[e.length]=
f)}c[5]=B}else"."===c[5]&&!r&&w.getElementsByClassName?(e=w.getElementsByClassName(c[6]),t=!c[4]&&!c[7]&&(","===k||s===p),c[5]=B):e=w.getElementsByTagName(r||"*");if(t)l=e,0==o.length&&e.length&&(","===k||s===p)&&i.moveElems(e,z,x,!r,e instanceof Array);else if(l=0<e.length?0==o.length&&(","===k||s===p)?i.checkRule(c,e,z,r,x):i.checkRule(c,e,[],r):[],!k&&s<p){m=l.length;do if(u.lastIndex=s,c=u.exec(b),s=u.lastIndex,k=c[10],m&&(l=0==o.length&&(","===k||s===p)?i.checkRule(c,l,z,r,x):i.checkRule(c,l,
[],r),m=l.length),k)break;while(s<p)}if(!0!==k&&0<o.length)if(0===l.length)o.length=0;else{e=[];for(h=0;f=l[h];)e[h++]=f;for(j=z.length;c=o.pop();)if(m=o.length,">"===c.rule)for(h=0;f=e[h];h++)f.parentNode&&(!c.tag||f.parentNode.nodeName===c.tag)?0===m?","===k||s===p?z[j++]=l[h]:e[h]=l[h]:e[h]=f.parentNode:e[h]=!0;else for(h=0;f=e[h];h++){f=f.previousSibling;for(q=!1;f;){if(1===f.nodeType&&(!c.tag||f.nodeName===c.tag)){0===m?","===k||s===p?z[j++]=l[h]:e[h]=l[h]:e[h]=f;q=!0;break}f=f.previousSibling}q||
(e[h]=!0)}j===z.length||(z.length=j);if(!(","===k||s===p)){l=[];for(h=0;f=e[h];h++)!0!==f&&l.push(f)}}if(" "===k)if(0<l.length)u.lastIndex=s,a=i.parser(b,l,a,!0,x),s=u.lastIndex,a[1]=!0;else{u.lastIndex=s;do if(c=u.exec(b),!c[4]&&!c[5]&&!c[7]&&!c[1]&&i.error(b.substring(s)),","===c[10])break;while(u.lastIndex<p);s=u.lastIndex;k=c[10]}if(","===k&&(a[1]=!0,n))break;v=k}while(s<p)}return a},querySelectorAll:function(b,d,a,n,o){a=a||[];a.length=a.length||0;d=d&&(d.nodeType?[d]:d)||[A];u.lastIndex=0;var c,
g,t,j,m=!0,h=a instanceof Array;if(J){var q,p,e,f=/^\s*[>+~]/.test(b);t=[a,0<a.length||1<d.length];c=0;for(g=d.length;c<g;c++)if(j=d[c],9===j.nodeType)try{i.moveElems(j.querySelectorAll(b),t[0],o),m=!1}catch(v){break}else if(1===j.nodeType&&"OBJECT"!==j.nodeName)if(f&&(q=j.parentNode)){e=(p=j.getAttribute("id"))&&p.replace(/'/g,"\\$&")||"__qsaEngine__";!p&&j.setAttribute("id",e);try{i.moveElems(q.querySelectorAll("[id='"+e+"'] "+b),t[0],o),m=!1}catch(k){break}!p&&j.removeAttribute("id")}else if(f)break;
else try{i.moveElems(j.querySelectorAll(b),t[0],o),m=!1}catch(l){break}}m&&(t=i.parser(b,d,[a,0<a.length||1<d.length],0,o));if(t[1]&&1<a.length)if(n){for(c=a.length;c--;)a[c]._hasDuplicate?(I.call(a,c,1),h||delete a[a.length]):a[c]._hasDuplicate=!0;for(c=a.length;c--;)a[c]._hasDuplicate=null}else if(w=H,Array.prototype.sort.call(a,i.sortElems),w)for(c=1;c<a.length;c++)a[c]===a[c-1]&&(I.call(a,c--,1),h||delete a[a.length]);return a},matchesSelector:function(b,d){if(C){var a=C.call(b,d);if(a||!K||b.document&&
11!==b.document.nodeType)return a}return 0<i.querySelectorAll(d,null,null,!0,b).length},error:function(b){throw Error("Syntax error: "+b);}};G.qsa=i})(window);