-
Notifications
You must be signed in to change notification settings - Fork 20
/
jquery.css3finalize.min.js
8 lines (8 loc) · 7.59 KB
/
jquery.css3finalize.min.js
1
2
3
4
5
6
7
8
/* CSS.supports() Polyfill
* https://gist.github.com/codler/03a0995195aa2859465f
* Copyright (c) 2014 Han Lin Yap http://yap.nu; MIT license */
if(!("CSS" in window)){window.CSS={}}if(!("supports" in window.CSS)){window.CSS._cacheSupports={};window.CSS.supports=function(a,d){var b=[a,d].toString();if(b in window.CSS._cacheSupports){return window.CSS._cacheSupports[b]}function c(e,i){var g=document.createElement("div").style;if(typeof i=="undefined"){function j(l,m){var k=l.split(m);if(k.length>1){return k.map(function(p,o,n){return(o%2==0)?p+n[o+1]:""}).filter(Boolean)}}var f=j(e,/([)])\s*or\s*([(])/gi);if(f){return f.some(function(k){return window.CSS.supports(k)})}var h=j(e,/([)])\s*and\s*([(])/gi);if(h){return h.every(function(k){return window.CSS.supports(k)})}g.cssText=e.replace("(","").replace(/[)]$/,"")}else{g.cssText=e+":"+i}return !!g.length}return window.CSS._cacheSupports[b]=c(a,d)};
/* CSS3 Finalize - v4.1.0 - 2014-10-18 - Automatically add vendor prefixes.
* https://github.com/codler/jQuery-Css3-Finalize
* Copyright (c) 2014 Han Lin Yap http://yap.nu; MIT license */
}(function(a){if(a.cssFinalize){return}a.cssFinalizeSetup={node:"style,link",append:true,callback:function(b){}};a.fn.cssFinalize=function(b){if(!b||typeof b!="object"){b={}}b.node=this;a.cssFinalize(b);return this};a.cssFinalize=function(e){if(document.documentMode&&document.documentMode<=9){return true}var p=document.createElement("div");p.style.cssText="background-image:linear-gradient(#9f9, white);";e=a.extend({},a.cssFinalizeSetup,e);var x=function(i){return i.replace(/[A-Z]/g,function(A){return"-"+A.toLowerCase()})};var f=[];var u;var l=window.getComputedStyle(document.documentElement,null);for(var t=0;t<l.length;t++){if(l[t].charAt(0)==="-"){var g=l[t].indexOf("-",1);f.push(l[t].substr(g+1));u=l[t].substr(1,g-1)}}if(u=="ms"&&f.indexOf("flex")===-1){f.push("flex")}else{if(u=="webkit"){for(var t in p.style){if(t.indexOf("webkit")===0){var v=x(t);if(a.inArray(v.substr(7),f)===-1){f.push(v.substr(7))}}}}}function k(i){var A=a.camelCase(i);return(u=="ms")?A.charAt(0).toLowerCase()+A.substr(1):A}function w(i){i=i.replace(/\/\*((?:[^\*]|\*[^\/])*)\*\//g,"");i=i.replace(/\n/g,"");i=i.replace(/\r/g,"");i=i.replace(/\@import[^;]*;/g,"");return i}function z(i,A){i.after('<style class="css-finalized" '+((i.attr("media")&&i.attr("media").length>0)?'media="'+i.attr("media")+'"':"")+">"+a.cssFinalize.cssObjToText(A)+"</style>")}function c(A,B){B=w(B);if(a.trim(B)===""){return}var C=d(B);var i=[];i=D(C);function D(F){var E=[];a.each(F,function(G,I){if(I.attributes){var H=q(I.attributes);if(!a.isEmptyObject(H)){E.push({selector:m(I.selector),attributes:H})}else{if(b(I.selector)){E=E.concat(q(I.attributes,true))}else{if(m(I.selector)!=I.selector){E.push({selector:m(I.selector),attributes:q(I.attributes,true)})}else{if((H=D(I.attributes))&&H.length>0){E.push({selector:I.selector,attributes:H})}}}}}});return E}A.addClass("css-finalize-read");if(i.length>0&&e.append){z(A,i)}if(a.isFunction(e.callback)){e.callback.call(A,i)}}function d(H){var C=H.split(/({[^{}]*})/);if(C[C.length-1].indexOf("}")==-1){C.pop()}var D=[];var A=false;var I;var F=0;var G;var E=0;while(E<C.length){if(E%2===0){var B=a.trim(C[E]);if(A){if(B.indexOf("}")!=-1){B=B.substr(1);C[E]=B;G=C.splice(F,E-F);G.shift();G.unshift(I[1]);D[D.length-1].attributes=d(G.join(""));A=false;E=F;continue}}else{if(B.indexOf("{")!=-1){I=B.split("{");B=a.trim(I[0]);A=true;F=E}if(B!==""){D.push({selector:B})}}}else{if(!A){D[D.length-1].attributes=y(C[E].substr(1,C[E].length-2))}}E++}return D}function y(B){var A;B=B.replace(/url\(([^)]+)\)/g,function(C){return C.replace(/;/g,"[cssFinalize]")});A=B.split(/(:[^;]*;?)/);A.pop();var i={};a.map(A,function(D,C){if(C%2==1){i[a.trim(A[C-1])]=a.trim(D.substr(1).replace(";","").replace(/url\(([^)]+)\)/g,function(E){return E.replace(/\[cssFinalize\]/g,";")}))}});return i}function q(A,i){if(a.isArray(A)){if(i){return a.map(A,function(D,C){return{selector:D.selector,attributes:q(D.attributes,i)}})}else{return{}}}var B={};a.each(A,function(F,E){var H=false;var C=r(F);if(C){H=true;B[C]=E}var G=n(F,E,C);if(G){H=true;B[(C)?C:F]=G}var D=s(F,E);if(D){H=true;a.each(D,function(I,J){if(I=="filter"&&B[I]){B[I]+=" "+J}else{B[I]=J}})}if(i&&!H){B[F]=E}});return B}function r(i){if(a.inArray(i,f)>-1){if(!(k(i) in p.style)){if(k("-"+u+"-"+i) in p.style){return"-"+u+"-"+i}}}return false}function n(C,B,i){i=i||C;if(C=="transition"||C=="transition-property"){var A=B.split(/\s?,\s?/);var D=[];a.each(A,function(E){var F,G;if(C=="transition"){F=A[E].split(" ")[0]}else{F=A[E]}if((G=r(F))!==false){D.push(G+A[E].substr(F.length))}else{D.push(A[E])}});return D.join(",")}if(u=="moz"){if(B.indexOf("element")===0){return"-moz-"+B}}if(C=="display"){if(!("flexBasis" in p.style)){if(u=="ms"){if(B.indexOf("flex")===0){return"-ms-flexbox"}else{if(B.indexOf("inline-flex")===0){return"-ms-inline-flexbox"}}}if(B.indexOf("flex")===0||B.indexOf("inline-flex")===0){return"-"+u+"-"+B}}if(B.indexOf("grid")===0||B.indexOf("inline-grid")===0){return"-"+u+"-"+B}}return false}function s(A,i){if(u=="ms"&&!("flexBasis" in p.style)){if(A=="justify-content"||A=="align-content"||A=="align-items"||A=="align-self"){var B=i;if(i=="space-between"){B="justify"}else{if(i=="space-around"){B="distribute"}else{if(i=="flex-start"){B="start"}else{if(i=="flex-end"){B="end"}}}}if(A=="justify-content"){return{"-ms-flex-pack":B}}else{if(A=="align-content"){return{"-ms-flex-line-pack":B}}else{if(A=="align-items"){return{"-ms-flex-align":B}}else{if(A=="align-self"){return{"-ms-flex-item-align":B}}}}}}if(A=="order"){return{"-ms-flex-order":i}}if(A=="flex-wrap"){var B=i;if(i=="nowrap"){B="none"}return{"-ms-flex-wrap":B}}}return false}function m(i){switch(u){case"moz":i=i.replace("::selection","::-moz-selection");i=i.replace(":input-placeholder","::-moz-placeholder");break;case"webkit":i=i.replace("@keyframes","@-webkit-keyframes");i=i.replace(":input-placeholder","::-webkit-input-placeholder");break;case"ms":i=i.replace(":input-placeholder",":-ms-input-placeholder");i=i.replace("@viewport","@-ms-viewport");break}return i}function b(i){if(!!window.CSS._cacheSupports){if(i.indexOf("@supports")==0){return CSS.supports(i.substring("@supports".length))}}}if(!(e.node instanceof jQuery)){e.node=a(e.node)}e.node.each(function(i,A){var B=a(this);if(B.hasClass("css-finalize-read")||B.hasClass("css-finalized")){return true}if(this.tagName=="LINK"&&B.attr("rel")=="stylesheet"){j(this.href,B)}else{if(this.tagName=="TEXTAREA"){c(B,B.val())}else{c(B,B.html())}}});function j(i,A){var F=document.location,E=F.protocol||"http:";var D=/^(\w+:)\/\/([^\/?#:]+)(?::(\d+))?/.exec(i.toLowerCase());var B=!!(D&&(D[1]!=E||D[2]!=F.hostname||(D[3]||(D[1]==="http:"?80:443))!=(F.port||(E==="http:"?80:443))));if(B){return}try{a("<div />").load(i,function(G){if(G){c(A,G)}})}catch(C){}}var h="background background-image transition transition-property".split(" ");a.each(h,function(i){if(a.inArray(h[i],f)===-1){o(h[i],h[i])}});function o(A,i){i=k(i);a.cssHooks[k(A)]={get:function(D,C,B){if(!C){return D.style[i]}},set:function(B,D){var F=n(A,D,i);try{B.style[i]=(F)?F:D}catch(E){}var C=s(A,D);if(C){a.each(C,function(G,H){try{if(G=="filter"&&B.style[G]){B.style[G]+=" "+H}else{B.style[G]=H}}catch(I){}})}}}}};a.cssFinalize.cssObjToText=function(d,c,b){var e="";c=c||false;b=b||1;a.each(d,function(f,g){if(c){e+=Array(b).join(" ")}e+=g.selector+"{";if(a.isArray(g.attributes)){if(c){e+="\r\n"+Array(b).join(" ")}e+=a.cssFinalize.cssObjToText(g.attributes,c,b+1)}else{a.each(g.attributes,function(i,h){if(c){e+="\r\n"+Array(b+1).join(" ")}e+=i+":"+h+";"});if(c){e+="\r\n"+Array(b).join(" ")}}e+="}";if(c){e+="\r\n"}});return e};a(function(){if(window.cssFinalize!==false){a.cssFinalize()}})})(jQuery);