Posted By

doowron on 10/26/11


Tagged

typography Preefixfree


Versions (?)

PrefixFree.js


 / Published in: JavaScript
 

URL: http://leaverou.github.com/prefixfree/

  1. /**
  2.  * PrefixFree 1.0.4
  3.  * @author Lea Verou
  4.  * MIT license
  5.  */
  6. (function(l){function k(b,f){return[].slice.call((f||document).querySelectorAll(b))}if(window.getComputedStyle&&window.addEventListener){var b=window.PrefixFree={prefixCSS:function(d,f){function a(a,c,f,i){a=b[a];c=c||(i!=void 0?i:"")+g+"$1"+(f!=void 0?f:"");a.length&&(a=RegExp((i!=void 0?i:"\\b")+"("+a.join("|")+")"+(f!=void 0?f:"\\b"),"gi"),d=d.replace(a,c))}var g=b.prefix;a("functions",g+"$1(","\\s*\\(");a("keywords",null);a("properties",g+"$1:","\\s*:");if(b.properties.length){var c=RegExp("\\b("+
  7. b.properties.join("|")+")(?!:)","gi");a("valueProperties",function(a){return a.replace(c,g+"$1")},":(.+?);")}f&&(a("selectors",b.prefixSelector,"\\b",""),a("atrules",null,void 0,"@"));return d=d.replace(RegExp("-"+g,"g"),"-")},process:{link:function(d){try{if(!/\bstylesheet\b/i.test(d.rel)||!d.sheet.cssRules)return}catch(f){return}var a=d.getAttribute("href")||d.getAttribute("data-href"),g=a.replace(/[^\/]+$/,""),c=d.parentNode,e=new XMLHttpRequest;e.open("GET",a);e.onreadystatechange=function(){if(e.readyState===
  8. 4){var a=e.responseText;if(a&&d.parentNode){var a=b.prefixCSS(a,true),a=a.replace(/url\((?:'|")?(.+?)(?:'|")?\)/gi,function(a,b){return!/^([a-z]{3,10}:|\/)/i.test(b)?'url("'+g+b+'")':a}),f=document.createElement("style");f.textContent=a;c.insertBefore(f,d);c.removeChild(d)}}};e.send(null)},styleElement:function(d){d.textContent=b.prefixCSS(d.textContent,true)},styleAttribute:function(d){var f=d.getAttribute("style"),f=b.prefixCSS(f);d.setAttribute("style",f)}},prefixSelector:function(d){return d.replace(/^:{1,2}/,
  9. function(d){return d+b.prefix})},prefixProperty:function(d,f){var a=b.prefix+d;return f?b.camelCase(a):a},camelCase:function(b){return b.replace(/-([a-z])/g,function(b,a){return a.toUpperCase()}).replace("-","")},deCamelCase:function(b){return b.replace(/[A-Z]/g,function(b){return"-"+b.toLowerCase()})}};(function(){var d={},f="",a=0,g=[],c=getComputedStyle(document.documentElement,null),e=document.createElement("div").style,h=function(c){g.indexOf(c)===-1&&g.push(c);if(c.indexOf("-")>-1){var i=c.split("-");
  10. if(c.charAt(0)==="-"){var c=i[1],h=++d[c]||1;d[c]=h;for(a<h&&(f=c,a=h);i.length>3;)i.pop(),h=i.join("-"),b.camelCase(h)in e&&(c=g,c.indexOf(h)===-1&&c.push(h))}}};if(c.length>0)for(var j=0;j<c.length;j++)h(c[j]);else for(var i in c)h(b.deCamelCase(i));b.prefix="-"+f+"-";b.Prefix=b.camelCase(b.prefix);g.sort();b.properties=[];for(j=0;j<g.length;j++){i=g[j];if(i.charAt(0)!=="-")break;i.indexOf(b.prefix)===0&&(c=i.slice(b.prefix.length),g.indexOf(c)===-1&&b.properties.push(c))}b.Prefix=="Ms"&&!("transform"in
  11. e)&&!("MsTransform"in e)&&"msTransform"in e&&b.properties.push("transform","transform-origin");b.properties.sort()})();(function(){var d={"linear-gradient":{property:"backgroundImage",params:"red, teal"},calc:{property:"width",params:"1px + 5%"},element:{property:"backgroundImage",params:"#foo"}},f={initial:"color","zoom-in":"cursor","zoom-out":"cursor"};d["repeating-linear-gradient"]=d["repeating-radial-gradient"]=d["radial-gradient"]=d["linear-gradient"];b.functions=[];b.keywords=[];var a=document.createElement("div").style,
  12. g;for(g in d){var c=d[g],e=c.property,c=g+"("+c.params+")";a[e]="";a[e]=c;a[e]||(a[e]="",a[e]=b.prefix+c,a[e]&&b.functions.push(g))}for(var h in f)e=f[h],a[e]="",a[e]=h,a[e]||(a[e]="",a[e]=b.prefix+h,a[e]&&b.keywords.push(h))})();(function(){var d={":read-only":null,":read-write":null,":any-link":null,"::selection":null},f={keyframes:"name",viewport:null,document:'regexp(".")'};b.selectors=[];b.atrules=[];var a=l.appendChild(document.createElement("style")),g;for(g in d){var c=d[g]?"("+d[g]+"){}":
  13. "{}",c=b.prefixSelector(g)+c+g+c;a.textContent=c;c=a.sheet.cssRules;c.length===1&&c[0].selectorText.indexOf(b.prefix)>-1&&b.selectors.push(g)}for(var e in f)if(c=e+" "+(f[e]||"")+"{}",a.textContent="@"+c,a.sheet.cssRules.length===0)a.textContent="@"+b.prefix+c,a.sheet.cssRules.length>0&&b.atrules.push(e);l.removeChild(a)})();b.valueProperties=["transition","transition-property"];k('link[rel~="stylesheet"]').forEach(b.process.link);l.className+=" "+b.prefix;document.addEventListener("DOMContentLoaded",
  14. function(){k('link[rel~="stylesheet"]').forEach(b.process.link);k("style").forEach(b.process.styleElement);k("[style]").forEach(b.process.styleAttribute)},false)}})(document.documentElement);

Report this snippet  

You need to login to post a comment.