polyfill-service
Version:
A polyfill combinator
1 lines • 6.94 kB
JSON
{"browsers":{"ie":"6 - 8"},"dependencies":["Window"],"docs":"https://developer.mozilla.org/en-US/docs/Web/API/Window/getComputedStyle","spec":"http://www.w3.org/TR/DOM-Level-2-Style/css.html#CSS-CSSview-getComputedStyle","baseDir":"getComputedStyle","hasTests":false,"rawSource":"\n// getComputedStyle\n(function (global) {\n\tfunction getComputedStylePixel(element, property, fontSize) {\n\t\tvar\n\t\t// Internet Explorer sometimes struggles to read currentStyle until the element's document is accessed.\n\t\tvalue = element.document && element.currentStyle[property].match(/([\\d\\.]+)(%|cm|em|in|mm|pc|pt|)/) || [0, 0, ''],\n\t\tsize = value[1],\n\t\tsuffix = value[2],\n\t\trootSize;\n\n\t\tfontSize = !fontSize ? fontSize : /%|em/.test(suffix) && element.parentElement ? getComputedStylePixel(element.parentElement, 'fontSize', null) : 16;\n\t\trootSize = property == 'fontSize' ? fontSize : /width/i.test(property) ? element.clientWidth : element.clientHeight;\n\n\t\treturn suffix == '%' ? size / 100 * rootSize :\n\t\t suffix == 'cm' ? size * 0.3937 * 96 :\n\t\t suffix == 'em' ? size * fontSize :\n\t\t suffix == 'in' ? size * 96 :\n\t\t suffix == 'mm' ? size * 0.3937 * 96 / 10 :\n\t\t suffix == 'pc' ? size * 12 * 96 / 72 :\n\t\t suffix == 'pt' ? size * 96 / 72 :\n\t\t size;\n\t}\n\n\tfunction setShortStyleProperty(style, property) {\n\t\tvar\n\t\tborderSuffix = property == 'border' ? 'Width' : '',\n\t\tt = property + 'Top' + borderSuffix,\n\t\tr = property + 'Right' + borderSuffix,\n\t\tb = property + 'Bottom' + borderSuffix,\n\t\tl = property + 'Left' + borderSuffix;\n\n\t\tstyle[property] = (style[t] == style[r] && style[t] == style[b] && style[t] == style[l] ? [ style[t] ] :\n\t\t style[t] == style[b] && style[l] == style[r] ? [ style[t], style[r] ] :\n\t\t style[l] == style[r] ? [ style[t], style[r], style[b] ] :\n\t\t [ style[t], style[r], style[b], style[l] ]).join(' ');\n\t}\n\n\t// <CSSStyleDeclaration>\n\tfunction CSSStyleDeclaration(element) {\n\t\tvar\n\t\tstyle = this,\n\t\tcurrentStyle = element.currentStyle,\n\t\tfontSize = getComputedStylePixel(element, 'fontSize'),\n\t\tunCamelCase = function (match) {\n\t\t\treturn '-' + match.toLowerCase();\n\t\t},\n\t\tproperty;\n\n\t\tfor (property in currentStyle) {\n\t\t\tArray.prototype.push.call(style, property == 'styleFloat' ? 'float' : property.replace(/[A-Z]/, unCamelCase));\n\n\t\t\tif (property == 'width') {\n\t\t\t\tstyle[property] = element.offsetWidth + 'px';\n\t\t\t} else if (property == 'height') {\n\t\t\t\tstyle[property] = element.offsetHeight + 'px';\n\t\t\t} else if (property == 'styleFloat') {\n\t\t\t\tstyle.float = currentStyle[property];\n\t\t\t} else if (/margin.|padding.|border.+W/.test(property) && style[property] != 'auto') {\n\t\t\t\tstyle[property] = Math.round(getComputedStylePixel(element, property, fontSize)) + 'px';\n\t\t\t} else if (/^outline/.test(property)) {\n\t\t\t\t// errors on checking outline\n\t\t\t\ttry {\n\t\t\t\t\tstyle[property] = currentStyle[property];\n\t\t\t\t} catch (error) {\n\t\t\t\t\tstyle.outlineColor = currentStyle.color;\n\t\t\t\t\tstyle.outlineStyle = style.outlineStyle || 'none';\n\t\t\t\t\tstyle.outlineWidth = style.outlineWidth || '0px';\n\t\t\t\t\tstyle.outline = [style.outlineColor, style.outlineWidth, style.outlineStyle].join(' ');\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tstyle[property] = currentStyle[property];\n\t\t\t}\n\t\t}\n\n\t\tsetShortStyleProperty(style, 'margin');\n\t\tsetShortStyleProperty(style, 'padding');\n\t\tsetShortStyleProperty(style, 'border');\n\n\t\tstyle.fontSize = Math.round(fontSize) + 'px';\n\t}\n\n\tCSSStyleDeclaration.prototype = {\n\t\tconstructor: CSSStyleDeclaration,\n\t\t// <CSSStyleDeclaration>.getPropertyPriority\n\t\tgetPropertyPriority: function () {\n\t\t\tthrow new Error('NotSupportedError: DOM Exception 9');\n\t\t},\n\t\t// <CSSStyleDeclaration>.getPropertyValue\n\t\tgetPropertyValue: function (property) {\n\t\t\treturn this[property.replace(/-\\w/g, function (match) {\n\t\t\t\treturn match[1].toUpperCase();\n\t\t\t})];\n\t\t},\n\t\t// <CSSStyleDeclaration>.item\n\t\titem: function (index) {\n\t\t\treturn this[index];\n\t\t},\n\t\t// <CSSStyleDeclaration>.removeProperty\n\t\tremoveProperty: function () {\n\t\t\tthrow new Error('NoModificationAllowedError: DOM Exception 7');\n\t\t},\n\t\t// <CSSStyleDeclaration>.setProperty\n\t\tsetProperty: function () {\n\t\t\tthrow new Error('NoModificationAllowedError: DOM Exception 7');\n\t\t},\n\t\t// <CSSStyleDeclaration>.getPropertyCSSValue\n\t\tgetPropertyCSSValue: function () {\n\t\t\tthrow new Error('NotSupportedError: DOM Exception 9');\n\t\t}\n\t};\n\n\t// <Global>.getComputedStyle\n\tglobal.getComputedStyle = function getComputedStyle(element) {\n\t\treturn new CSSStyleDeclaration(element);\n\t};\n})(this);\n","minSource":"!function(t){function e(t,o,r){var n,i=t.document&&t.currentStyle[o].match(/([\\d\\.]+)(%|cm|em|in|mm|pc|pt|)/)||[0,0,\"\"],l=i[1],u=i[2];return r=r?/%|em/.test(u)&&t.parentElement?e(t.parentElement,\"fontSize\",null):16:r,n=\"fontSize\"==o?r:/width/i.test(o)?t.clientWidth:t.clientHeight,\"%\"==u?l/100*n:\"cm\"==u?.3937*l*96:\"em\"==u?l*r:\"in\"==u?96*l:\"mm\"==u?.3937*l*96/10:\"pc\"==u?12*l*96/72:\"pt\"==u?96*l/72:l}function o(t,e){var o=\"border\"==e?\"Width\":\"\",r=e+\"Top\"+o,n=e+\"Right\"+o,i=e+\"Bottom\"+o,l=e+\"Left\"+o;t[e]=(t[r]==t[n]&&t[r]==t[i]&&t[r]==t[l]?[t[r]]:t[r]==t[i]&&t[l]==t[n]?[t[r],t[n]]:t[l]==t[n]?[t[r],t[n],t[i]]:[t[r],t[n],t[i],t[l]]).join(\" \")}function r(t){var r,n=this,i=t.currentStyle,l=e(t,\"fontSize\"),u=function(t){return\"-\"+t.toLowerCase()};for(r in i)if(Array.prototype.push.call(n,\"styleFloat\"==r?\"float\":r.replace(/[A-Z]/,u)),\"width\"==r)n[r]=t.offsetWidth+\"px\";else if(\"height\"==r)n[r]=t.offsetHeight+\"px\";else if(\"styleFloat\"==r)n[\"float\"]=i[r];else if(/margin.|padding.|border.+W/.test(r)&&\"auto\"!=n[r])n[r]=Math.round(e(t,r,l))+\"px\";else if(/^outline/.test(r))try{n[r]=i[r]}catch(c){n.outlineColor=i.color,n.outlineStyle=n.outlineStyle||\"none\",n.outlineWidth=n.outlineWidth||\"0px\",n.outline=[n.outlineColor,n.outlineWidth,n.outlineStyle].join(\" \")}else n[r]=i[r];o(n,\"margin\"),o(n,\"padding\"),o(n,\"border\"),n.fontSize=Math.round(l)+\"px\"}r.prototype={constructor:r,getPropertyPriority:function(){throw new Error(\"NotSupportedError: DOM Exception 9\")},getPropertyValue:function(t){return this[t.replace(/-\\w/g,function(t){return t[1].toUpperCase()})]},item:function(t){return this[t]},removeProperty:function(){throw new Error(\"NoModificationAllowedError: DOM Exception 7\")},setProperty:function(){throw new Error(\"NoModificationAllowedError: DOM Exception 7\")},getPropertyCSSValue:function(){throw new Error(\"NotSupportedError: DOM Exception 9\")}},t.getComputedStyle=function(t){return new r(t)}}(this);","detectSource":"'getComputedStyle' in this"}