(value, property, context)
| 65 | // Or like this: |
| 66 | // getPixelValue(someElement, 'paddingTop'); |
| 67 | function getPixelValue(value, property, context) { |
| 68 | var element = null; |
| 69 | if (Object.isElement(value)) { |
| 70 | element = value; |
| 71 | value = getRawStyle(element, property); |
| 72 | } |
| 73 | |
| 74 | if (value === null || Object.isUndefined(value)) { |
| 75 | return null; |
| 76 | } |
| 77 | |
| 78 | // Non-IE browsers will always return pixels if possible. |
| 79 | // (We use parseFloat instead of parseInt because Firefox can return |
| 80 | // non-integer pixel values.) |
| 81 | if ((/^(?:-)?\d+(\.\d+)?(px)?$/i).test(value)) { |
| 82 | return window.parseFloat(value); |
| 83 | } |
| 84 | |
| 85 | var isPercentage = value.include('%'), isViewport = (context === document.viewport); |
| 86 | |
| 87 | // When IE gives us something other than a pixel value, this technique |
| 88 | // (invented by Dean Edwards) will convert it to pixels. |
| 89 | // |
| 90 | // (This doesn't work for percentage values on elements with `position: fixed` |
| 91 | // because those percentages are relative to the viewport.) |
| 92 | if (/\d/.test(value) && element && element.runtimeStyle && !(isPercentage && isViewport)) { |
| 93 | var style = element.style.left, rStyle = element.runtimeStyle.left; |
| 94 | element.runtimeStyle.left = element.currentStyle.left; |
| 95 | element.style.left = value || 0; |
| 96 | value = element.style.pixelLeft; |
| 97 | element.style.left = style; |
| 98 | element.runtimeStyle.left = rStyle; |
| 99 | |
| 100 | return value; |
| 101 | } |
| 102 | |
| 103 | // For other browsers, we have to do a bit of work. |
| 104 | // (At this point, only percentages should be left; all other CSS units |
| 105 | // are converted to pixels by getComputedStyle.) |
| 106 | if (element && isPercentage) { |
| 107 | // The `context` argument comes into play for percentage units; it's |
| 108 | // the thing that the unit represents a percentage of. When an |
| 109 | // absolutely-positioned element has a width of 50%, we know that's |
| 110 | // 50% of its offset parent. If it's `position: fixed` instead, we know |
| 111 | // it's 50% of the viewport. And so on. |
| 112 | context = context || element.parentNode; |
| 113 | var decimal = toDecimal(value), whole = null; |
| 114 | |
| 115 | var isHorizontal = property.include('left') || property.include('right') || |
| 116 | property.include('width'); |
| 117 | |
| 118 | var isVertical = property.include('top') || property.include('bottom') || |
| 119 | property.include('height'); |
| 120 | |
| 121 | if (context === document.viewport) { |
| 122 | if (isHorizontal) { |
| 123 | whole = document.viewport.getWidth(); |
| 124 | } else if (isVertical) { |
no test coverage detected