From 15cb9773fe73647a6071d0a59995949932fb3d59 Mon Sep 17 00:00:00 2001 From: Matt Kantor Date: Sat, 23 Jun 2012 16:18:32 -0700 Subject: [PATCH] Replace many for..in loops with $.each to allow for safely changing Array.prototype. --- jquery.css3finalize.js | 44 ++++++++++++++++++++++++-------------- jquery.css3finalize.min.js | 4 ++-- 2 files changed, 30 insertions(+), 18 deletions(-) diff --git a/jquery.css3finalize.js b/jquery.css3finalize.js index e625a0c..d63db53 100644 --- a/jquery.css3finalize.js +++ b/jquery.css3finalize.js @@ -3,7 +3,7 @@ * @copyright 2012 zencodez.net * @license http://creativecommons.org/licenses/by-sa/3.0/ * @package Css3-Finalize - * @version 2.4 - 2012-05-07 + * @version 2.5 - 2012-06-21 * @website https://github.com/codler/jQuery-Css3-Finalize * * == Description == @@ -63,6 +63,7 @@ // For FF 3.6 and safari 4 supportRules.push('border-radius'); } else { + // In Opera CSSStyleDeclaration objects returned by getComputedStyle have length 0 var deCamelCase = function(str) { return str.replace(/[A-Z]/g, function($0) { return '-' + $0.toLowerCase() }); } @@ -132,12 +133,12 @@ var match = str.match(RegExp(separator, 'g')); var notmatch = str.replace(new RegExp(separator, 'g'), '[|]').split('[|]'); var merge = []; - for(i in notmatch) { + $.each(notmatch, function(i) { merge.push(notmatch[i]); if (match && match[i]) { merge.push(match[i]); } - } + }); return merge; } @@ -338,17 +339,23 @@ function propertyRules(property) { if (property in rules) { - for (prefix in rules[property]) { + var returnValue; + $.each(rules[property], function(prefix) { if ($.isFunction(rules[property][prefix])) { var found = rules[property][prefix](property); if (found) { - return found; + returnValue = found; + return false; // break out of iterator } } else { if (currentPrefix == rules[property][prefix] || !currentPrefix) { - return '-' + rules[property][prefix] + '-' + property; + returnValue = '-' + rules[property][prefix] + '-' + property; + return false; // break out of iterator } } + }); + if (returnValue !== undefined) { + return returnValue; } } @@ -360,11 +367,16 @@ if (cssCamelCase('-' + currentPrefix + '-' + property) in div.style) { return '-' + currentPrefix + '-' + property; } /*else if (property in rules) { - for (prefix in rules[property]) { + var returnValue; + $.each(rules[property], function(prefix) { var found = rules[property][prefix](property); if (found) { - return found; + returnValue = found; + return false; // break out of iterator } + }); + if (returnValue !== undefined) { + return returnValue; } }*/ } @@ -388,7 +400,7 @@ property == 'transition-property') { var keys = value.split(/\s?,\s?/); var newValue = []; - for (var keyProperty in keys) { + $.each(keys, function(keyProperty) { var v, t; if (property == 'transition') { v = keys[keyProperty].split(' ')[0]; @@ -400,7 +412,7 @@ } else { newValue.push(keys[keyProperty]); } - } + }); return newValue.join(','); } @@ -588,24 +600,24 @@ } catch(e){} } - for (property in rules) { + $.each(rules, function(property) { if ((newProperty = propertyRules(property)) !== false) { setCssHook(property, newProperty); } - } + }); - for (property in supportRules) { + $.each(supportRules, function(property) { if ((newProperty = propertyRules(supportRules[property])) !== false) { setCssHook(supportRules[property], newProperty); } - } + }); var valueRules = 'background background-image background-clip background-origin transition transition-property display'.split(' '); - for (property in valueRules) { + $.each(valueRules, function(property) { if ($.inArray(valueRules[property], supportRules) === -1) { setCssHook(valueRules[property], valueRules[property]); } - } + }); function setCssHook(property, newProperty) { newProperty = cssCamelCase(newProperty); diff --git a/jquery.css3finalize.min.js b/jquery.css3finalize.min.js index 2d3a085..5c286ae 100644 --- a/jquery.css3finalize.min.js +++ b/jquery.css3finalize.min.js @@ -3,7 +3,7 @@ * @copyright 2012 zencodez.net * @license http://creativecommons.org/licenses/by-sa/3.0/ * @package Css3-Finalize - * @version 2.4 - 2012-05-07 + * @version 2.5 - 2012-06-21 * @website https://github.com/codler/jQuery-Css3-Finalize * * == Description == @@ -12,4 +12,4 @@ * == Example Usage == * $('style').cssFinalize(); // parse all style-tags */ -(function(a){if(a.cssFinalize){return}a.cssFinalizeSetup={shim:true,node:"style,link",checkMedia:true,append:true,callback:function(){}};a.fn.cssFinalize=function(b){if(!b||typeof b!="object"){b={}}b.node=this;a.cssFinalize(b);return this};a.cssFinalize=function(f){var r=document.createElement("div");f=a.extend({},a.cssFinalizeSetup,f);f.checkMedia=!!(f.checkMedia&&window.matchMedia);var g=[];var w;if(window.getComputedStyle){var m=getComputedStyle(document.documentElement,null);if(m.length){for(var v=0;v0)?'media="'+i.attr("media")+'"':"")+"/>");a("head:first").append(D);D[0].styleSheet.cssText=a.cssFinalize.cssObjToText(E)}else{i.after('")}}function c(D,E){E=y(E);if(a.trim(E)===""){return}var F=d(E);var i=[];i=G(F);function G(I){var H=[];a.each(I,function(J,L){if(L.attributes){var K=s(L.attributes);if(!a.isEmptyObject(K)){H.push({selector:n(L.selector),attributes:K})}else{if(n(L.selector)!=L.selector){H.push({selector:n(L.selector),attributes:s(L.attributes,true)})}else{if(!f.checkMedia||(f.checkMedia&&L.selector.indexOf("@media")===0&&matchMedia(L.selector.substr(7)).matches)){H.push({selector:L.selector,attributes:G(L.attributes)})}}}}});return H}D.addClass("css-finalize-read");if(i.length>0&&f.append){C(D,i)}if(a.isFunction(f.callback)){f.callback.call(D,i)}}function d(K){var F;if(w=="ms"&&a.browser.version<=8){F=B(K,"({[^{}]*})")}else{F=K.split(/({[^{}]*})/)}if(F[F.length-1].indexOf("}")==-1){F.pop()}var G=[];var D=false;var L;var I=0;var J;var H=0;while(H-1){if(!(l(D) in r.style)||D=="mask"){if(l("-"+w+"-"+D) in r.style){return"-"+w+"-"+D}}}return false}function o(H,G,J){J=J||H;if(H=="background-clip"||H=="background-origin"){r.style.cssText=J+":"+G;if(r.style[l(J)]!==undefined&&""+r.style[l(J)].indexOf(G)==-1){return G.split("-")[0]}}if(H=="transition"||H=="transition-property"){var L=G.split(/\s?,\s?/);var i=[];for(var D in L){var I,M;if(H=="transition"){I=L[D].split(" ")[0]}else{I=L[D]}if((M=t(I))!==false){i.push(M+L[D].substr(I.length))}else{i.push(L[D])}}return i.join(",")}if(w=="moz"){if(G.indexOf("calc")===0){return"-moz-"+G}if(G.indexOf("element")===0){return"-moz-"+G}}if(H=="display"){if(G.indexOf("box")===0||G.indexOf("flexbox")===0||G.indexOf("inline-flexbox")===0){return"-"+w+"-"+G}}var O;if(H=="background"||H=="background-image"){if(G.indexOf("linear-gradient")===0){if(w=="webkit"){O=G.replace(/^linear-gradient\s?\(\s?(.*?)\s?\)$/,"$1").split(/,\s?/);if(O.length==2){return"-webkit-gradient(linear, 0% 0%, 0% 100%, from("+O[0]+"), to("+O[1]+"))"}var N="";if(O.length>=3){var E="0% 0%, 0% 100%";if(O[0]==="left"){E="0% 0%, 100% 0%"}if(O.length>3){var K=O.slice(2,O.length-1);a.each(K,function(Q,R){var P=R.split(/ /);if(P.length===2){N+="color-stop("+P[1]+", "+P[0]+"),"}})}return"-webkit-gradient(linear, "+E+", from("+O[1]+"), "+N+" to("+O[O.length-1]+"))"}}else{if(w=="ms"&&a.browser.version==9){O=G.replace(/^linear-gradient\s?\(\s?(.*?)\s?\)$/,"$1").split(/,\s?/);if(O.length==2){var F='';return"url(data:image/svg+xml,"+escape(F)+")"}}}return"-"+w+"-"+G}else{if(G.indexOf("radial-gradient")===0){return"-"+w+"-"+G}}}return false}function u(E,D){if(f.shim){if(w=="ms"){if(a.browser.version<=8){if(E.toUpperCase()=="OPACITY"&&!a.support.opacity&&!isNaN(D)){return{filter:"alpha(opacity="+D*100+")",zoom:1}}if(E.toUpperCase()==="BACKGROUND-COLOR"&&D.indexOf("rgba")===0){D=b(D);return{background:"url(#)",filter:"progid:DXImageTransform.Microsoft.gradient(startColorStr='"+D+"',EndColorStr='"+D+"')"}}if((E.toUpperCase()=="BACKGROUND"||E.toUpperCase()==="BACKGROUND-IMAGE")&&D.indexOf("linear-gradient")===0){var i=D.replace(/^linear-gradient\s?\(\s?(.*?)\s?\)$/,"$1").split(/,\s?/);if(i.length==2){return{background:"url(#)",filter:"progid:DXImageTransform.Microsoft.gradient(startColorStr='"+i[0]+"',EndColorStr='"+i[1]+"')"}}}}}}return false}function n(i){if(w=="moz"){i=i.replace("::selection","::-moz-selection");i=i.replace("::placeholder",":-moz-placeholder");i=i.replace("@keyframes","@-moz-keyframes")}else{if(w=="webkit"){i=i.replace("@keyframes","@-webkit-keyframes");i=i.replace("::placeholder","::-webkit-input-placeholder")}}return i}function b(H){var E=H.replace(/^rgba\s?\(\s?(.*?)\s?\)$/,"$1").split(/,\s?/);var D=[];var G;for(var F=0;F0&&matchMedia(E.attr("media")).matches)||!E.attr("media")){k(this.href,E)}}else{if(this.tagName=="TEXTAREA"){c(E,E.val())}else{c(E,E.html())}}});function k(i,D){var I=document.location,H=I.protocol||"http:";var G=/^(\w+:)\/\/([^\/?#:]+)(?::(\d+))?/.exec(i.toLowerCase());var E=!!(G&&(G[1]!=H||G[2]!=I.hostname||(G[3]||(G[1]==="http:"?80:443))!=(I.port||(H==="http:"?80:443))));if(E){return}try{a("
").load(i,function(J){c(D,J)})}catch(F){}}for(property in p){if((newProperty=t(property))!==false){q(property,newProperty)}}for(property in g){if((newProperty=t(g[property]))!==false){q(g[property],newProperty)}}var j="background background-image background-clip background-origin transition transition-property display".split(" ");for(property in j){if(a.inArray(j[property],g)===-1){q(j[property],j[property])}}function q(D,i){i=l(i);a.cssHooks[l(D)]={get:function(G,F,E){return G.style[i]},set:function(E,G){var I=o(D,G,i);try{E.style[i]=(I)?I:G}catch(H){}var F=u(D,G);if(F){a.each(F,function(J,K){try{if(J=="filter"&&E.style[J]){E.style[J]+=" "+K}else{E.style[J]=K}}catch(L){}})}}}}};a.cssFinalize.cssObjToText=function(c,b){var d="";b=b||false;a.each(c,function(e,f){d+=f.selector+"{";if(a.isArray(f.attributes)){if(b){d+="\r\n"}d+=a.cssFinalize.cssObjToText(f.attributes,b)}else{a.each(f.attributes,function(h,g){if(b){d+="\r\n "}d+=h+":"+g+";"});if(b){d+="\r\n"}}d+="}";if(b){d+="\r\n"}});return d};a(function(){if(window.cssFinalize!==false){a.cssFinalize()}})})(jQuery);window.matchMedia=window.matchMedia||(function(e,f){var c,a=e.documentElement,b=a.firstElementChild||a.firstChild,d=e.createElement("body"),g=e.createElement("div");g.id="mq-test-1";g.style.cssText="position:absolute;top:-100em";d.appendChild(g);return function(h){g.innerHTML='­';a.insertBefore(d,b);c=g.offsetWidth==42;a.removeChild(d);return{matches:c,media:h}}})(document); +(function(a){if(a.cssFinalize){return}a.cssFinalizeSetup={shim:true,node:"style,link",checkMedia:true,append:true,callback:function(){}};a.fn.cssFinalize=function(b){if(!b||typeof b!="object"){b={}}b.node=this;a.cssFinalize(b);return this};a.cssFinalize=function(f){var r=document.createElement("div");f=a.extend({},a.cssFinalizeSetup,f);f.checkMedia=!!(f.checkMedia&&window.matchMedia);var g=[];var w;if(window.getComputedStyle){var m=getComputedStyle(document.documentElement,null);if(m.length){for(var v=0;v0)?'media="'+i.attr("media")+'"':"")+"/>");a("head:first").append(D);D[0].styleSheet.cssText=a.cssFinalize.cssObjToText(E)}else{i.after('")}}function c(D,E){E=y(E);if(a.trim(E)===""){return}var F=d(E);var i=[];i=G(F);function G(I){var H=[];a.each(I,function(J,L){if(L.attributes){var K=s(L.attributes);if(!a.isEmptyObject(K)){H.push({selector:n(L.selector),attributes:K})}else{if(n(L.selector)!=L.selector){H.push({selector:n(L.selector),attributes:s(L.attributes,true)})}else{if(!f.checkMedia||(f.checkMedia&&L.selector.indexOf("@media")===0&&matchMedia(L.selector.substr(7)).matches)){H.push({selector:L.selector,attributes:G(L.attributes)})}}}}});return H}D.addClass("css-finalize-read");if(i.length>0&&f.append){C(D,i)}if(a.isFunction(f.callback)){f.callback.call(D,i)}}function d(K){var F;if(w=="ms"&&a.browser.version<=8){F=B(K,"({[^{}]*})")}else{F=K.split(/({[^{}]*})/)}if(F[F.length-1].indexOf("}")==-1){F.pop()}var G=[];var D=false;var L;var I=0;var J;var H=0;while(H-1){if(!(l(D) in r.style)||D=="mask"){if(l("-"+w+"-"+D) in r.style){return"-"+w+"-"+D}}}return false}function o(G,F,H){H=H||G;if(G=="background-clip"||G=="background-origin"){r.style.cssText=H+":"+F;if(r.style[l(H)]!==undefined&&""+r.style[l(H)].indexOf(F)==-1){return F.split("-")[0]}}if(G=="transition"||G=="transition-property"){var J=F.split(/\s?,\s?/);var i=[];a.each(J,function(M){var N,O;if(G=="transition"){N=J[M].split(" ")[0]}else{N=J[M]}if((O=t(N))!==false){i.push(O+J[M].substr(N.length))}else{i.push(J[M])}});return i.join(",")}if(w=="moz"){if(F.indexOf("calc")===0){return"-moz-"+F}if(F.indexOf("element")===0){return"-moz-"+F}}if(G=="display"){if(F.indexOf("box")===0||F.indexOf("flexbox")===0||F.indexOf("inline-flexbox")===0){return"-"+w+"-"+F}}var K;if(G=="background"||G=="background-image"){if(F.indexOf("linear-gradient")===0){if(w=="webkit"){K=F.replace(/^linear-gradient\s?\(\s?(.*?)\s?\)$/,"$1").split(/,\s?/);if(K.length==2){return"-webkit-gradient(linear, 0% 0%, 0% 100%, from("+K[0]+"), to("+K[1]+"))"}var L="";if(K.length>=3){var D="0% 0%, 0% 100%";if(K[0]==="left"){D="0% 0%, 100% 0%"}if(K.length>3){var I=K.slice(2,K.length-1);a.each(I,function(N,O){var M=O.split(/ /);if(M.length===2){L+="color-stop("+M[1]+", "+M[0]+"),"}})}return"-webkit-gradient(linear, "+D+", from("+K[1]+"), "+L+" to("+K[K.length-1]+"))"}}else{if(w=="ms"&&a.browser.version==9){K=F.replace(/^linear-gradient\s?\(\s?(.*?)\s?\)$/,"$1").split(/,\s?/);if(K.length==2){var E='';return"url(data:image/svg+xml,"+escape(E)+")"}}}return"-"+w+"-"+F}else{if(F.indexOf("radial-gradient")===0){return"-"+w+"-"+F}}}return false}function u(E,D){if(f.shim){if(w=="ms"){if(a.browser.version<=8){if(E.toUpperCase()=="OPACITY"&&!a.support.opacity&&!isNaN(D)){return{filter:"alpha(opacity="+D*100+")",zoom:1}}if(E.toUpperCase()==="BACKGROUND-COLOR"&&D.indexOf("rgba")===0){D=b(D);return{background:"url(#)",filter:"progid:DXImageTransform.Microsoft.gradient(startColorStr='"+D+"',EndColorStr='"+D+"')"}}if((E.toUpperCase()=="BACKGROUND"||E.toUpperCase()==="BACKGROUND-IMAGE")&&D.indexOf("linear-gradient")===0){var i=D.replace(/^linear-gradient\s?\(\s?(.*?)\s?\)$/,"$1").split(/,\s?/);if(i.length==2){return{background:"url(#)",filter:"progid:DXImageTransform.Microsoft.gradient(startColorStr='"+i[0]+"',EndColorStr='"+i[1]+"')"}}}}}}return false}function n(i){if(w=="moz"){i=i.replace("::selection","::-moz-selection");i=i.replace("::placeholder",":-moz-placeholder");i=i.replace("@keyframes","@-moz-keyframes")}else{if(w=="webkit"){i=i.replace("@keyframes","@-webkit-keyframes");i=i.replace("::placeholder","::-webkit-input-placeholder")}}return i}function b(H){var E=H.replace(/^rgba\s?\(\s?(.*?)\s?\)$/,"$1").split(/,\s?/);var D=[];var G;for(var F=0;F0&&matchMedia(E.attr("media")).matches)||!E.attr("media")){k(this.href,E)}}else{if(this.tagName=="TEXTAREA"){c(E,E.val())}else{c(E,E.html())}}});function k(i,D){var I=document.location,H=I.protocol||"http:";var G=/^(\w+:)\/\/([^\/?#:]+)(?::(\d+))?/.exec(i.toLowerCase());var E=!!(G&&(G[1]!=H||G[2]!=I.hostname||(G[3]||(G[1]==="http:"?80:443))!=(I.port||(H==="http:"?80:443))));if(E){return}try{a("
").load(i,function(J){c(D,J)})}catch(F){}}a.each(p,function(i){if((newProperty=t(i))!==false){q(i,newProperty)}});a.each(g,function(i){if((newProperty=t(g[i]))!==false){q(g[i],newProperty)}});var j="background background-image background-clip background-origin transition transition-property display".split(" ");a.each(j,function(i){if(a.inArray(j[i],g)===-1){q(j[i],j[i])}});function q(D,i){i=l(i);a.cssHooks[l(D)]={get:function(G,F,E){return G.style[i]},set:function(E,G){var I=o(D,G,i);try{E.style[i]=(I)?I:G}catch(H){}var F=u(D,G);if(F){a.each(F,function(J,K){try{if(J=="filter"&&E.style[J]){E.style[J]+=" "+K}else{E.style[J]=K}}catch(L){}})}}}}};a.cssFinalize.cssObjToText=function(c,b){var d="";b=b||false;a.each(c,function(e,f){d+=f.selector+"{";if(a.isArray(f.attributes)){if(b){d+="\r\n"}d+=a.cssFinalize.cssObjToText(f.attributes,b)}else{a.each(f.attributes,function(h,g){if(b){d+="\r\n "}d+=h+":"+g+";"});if(b){d+="\r\n"}}d+="}";if(b){d+="\r\n"}});return d};a(function(){if(window.cssFinalize!==false){a.cssFinalize()}})})(jQuery);window.matchMedia=window.matchMedia||(function(e,f){var c,a=e.documentElement,b=a.firstElementChild||a.firstChild,d=e.createElement("body"),g=e.createElement("div");g.id="mq-test-1";g.style.cssText="position:absolute;top:-100em";d.appendChild(g);return function(h){g.innerHTML='­';a.insertBefore(d,b);c=g.offsetWidth==42;a.removeChild(d);return{matches:c,media:h}}})(document);