-
Notifications
You must be signed in to change notification settings - Fork 69
/
elementQuery.min.js
4 lines (4 loc) · 3.82 KB
/
elementQuery.min.js
1
2
3
4
/*! elementQuery | Author: Tyson Matanich (http://matanich.com), 2013 | License: MIT */
(function(n,t,i){"use strict";var o=n.Sizzle||jQuery.find,r={},u=null,v=function(){t.styleSheets[0]&&(u=t.styleSheets[0].cssRules!==i?"cssRules":"rules")},s=function(n,t,u,f,s){if(n=e(n),n!=""){var h;f||s||(h=/^([0-9]*.?[0-9]+)(px|em)$/.exec(u),h!=null&&(f=Number(h[1]),f+""!="NaN"&&(s=h[2]))),s&&(o.compile&&o.compile(n),r[n]===i&&(r[n]={}),r[n][t]===i&&(r[n][t]={}),r[n][t][u]=[f,s])}},y=function(n,t){var i,r,u;for(i in n)for(r in n[i])if(typeof n[i][r]=="string")s(i,r,n[i][r]);else if(typeof n[i][r]=="object")for(u=0;u<n[i][r].length;u++)s(i,r,n[i][r][u]);t==!0&&f()},c=function(n){if(n)for(var a=/(\[(min\-width|max\-width|min\-height|max\-height)\~\=(\'|\")([0-9]*.?[0-9]+)(px|em)(\'|\")\])(\[(min\-width|max\-width|min\-height|max\-height)\~\=(\'|\")([0-9]*.?[0-9]+)(px|em)(\'|\")\])?/gi,e=n.split(","),u,t,h,c,l,r,o,f=0;f<e.length;f++)for(u=null,c=0,l=0;l==0||t!=null;)t=a.exec(e[f]),t!=null&&(h=Number(t[4]),h+""!="NaN"&&(u==null&&(u=e[f].substring(c,t.index),r=e[f].substring(t.index+t[1].length),r.length>0&&(o=r.indexOf(" "),o!=0&&(o>0&&(r=r.substring(0,o)),r=r.replace(/(\[(min\-width|max\-width|min\-height|max\-height)\~\=(\'|\")([0-9]*.?[0-9]+)(px|em)(\'|\")\])/gi,""),u+=r))),s(u,t[2],t[4]+t[5],h,t[5])),t[7]===i||t[7]==""?(c=t.index+t[1].length,u=null):a.lastIndex=t.index+t[1].length),l++},l=function(n,t){var r,f,e,i;if(u==null&&v(),n[u]&&n[u].length>0&&(r=n.ownerNode||n.owningElement,t||r.getAttribute("data-elementquery-bypass")===null&&r.getAttribute("data-elementquery-processed")===null)){for(f=0;f<n[u].length;f++)if(i=n[u][f],i[u]&&i[u].length>0)for(e=0;e<i[u].length;e++)c(i[u][e].selectorText);else c(i.selectorText);r.setAttribute("data-elementquery-processed","")}},e=function(n){if(n==null)return"";var t="".trim;return t&&!t.call(" ")?t.call(n):(n+"").replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,"")},a=function(n,t){var i=n.getAttribute(t);return i?(" "+i+" ").replace(/[\t\r\n]/g," "):" "},p=function(n,t,i){var r,u;n.nodeType===1&&(r=e(i),r!=""&&(u=a(n,t),u.indexOf(" "+r+" ")<0&&n.setAttribute(t,e(u+r))))},w=function(n,t,i){var u,r,f;if(n.nodeType===1&&(u=e(i),u!="")){for(r=a(n,t),f=!1;r.indexOf(" "+u+" ")>=0;)r=r.replace(" "+u+" "," "),f=!0;f&&n.setAttribute(t,e(r))}},h=function(){for(var n=0;n<t.styleSheets.length;n++)l(t.styleSheets[n]);f()},f=function(){var e,h,i,s,c,u,f,l;for(e in r)if(c=o(e),c.length>0)for(h=0;h<c.length;h++){u=c[h];for(i in r[e])for(s in r[e][i])f=r[e][i][s][0],r[e][i][s][1]=="em"&&(f=f*(n.getEmPixels?getEmPixels(u):16)),i=="min-width"&&u.offsetWidth>=f||i=="max-width"&&u.offsetWidth<=f||i=="min-height"&&u.offsetHeight>=f||i=="max-height"&&u.offsetHeight<=f?p(u,i,s):w(u,i,s)}!n.addEventListener&&n.attachEvent&&(l=t.documentElement.className,t.documentElement.className=" "+l,t.documentElement.className=l)};n.elementQuery=function(n,t){n&&typeof n=="object"?n.cssRules||n.rules?(l(n,!0),t==!0&&f()):y(n,t):n||t||f()},n.elementQuery.selectors=function(){var t={},n,u,f;for(n in r)for(u in r[n])for(f in r[n][u])t[n]===i&&(t[n]={}),t[n][u]===i&&(t[n][u]=[]),t[n][u][t[n][u].length]=f;return t},n.addEventListener?(n.addEventListener("resize",f,!1),n.addEventListener("DOMContentLoaded",h,!1),n.addEventListener("load",h,!1)):n.attachEvent&&(n.attachEvent("onresize",f),n.attachEvent("onload",h))})(this,document,undefined);
/*! getEmPixels | Author: Tyson Matanich (http://matanich.com), 2013 | License: MIT */
(function(n,t){"use strict";var i="!important;",r="position:absolute"+i+"visibility:hidden"+i+"width:1em"+i+"font-size:1em"+i+"padding:0"+i;window.getEmPixels=function(u){var f,e,o;return u||(u=f=n.createElement("body"),f.style.cssText="font-size:1em"+i,t.insertBefore(f,n.body)),e=n.createElement("i"),e.style.cssText=r,u.appendChild(e),o=e.clientWidth,f?t.removeChild(f):u.removeChild(e),o}})(document,document.documentElement);