Ticket #1051: getStyle_safe.patch
| File getStyle_safe.patch, 2.8 kB (added by euzuro, 6 months ago) |
|---|
-
tests/BaseTypes/Element.html
old new 137 137 } 138 138 139 139 function test_Element_getStyle(t) { 140 t.plan( 4);140 t.plan(5); 141 141 142 142 //tests for this function are not 100% complete... there is some funky 143 143 // business going on in there with 144 144 // * document.defaultView (moz/ff I believe) 145 145 // but I cant seem to find a good way to test them. 146 146 // 147 t.ok(OpenLayers.Element.getStyle(null, null) == null, "passing null values in to getStyle() doesnt bomb, returns null"); 147 148 148 149 var elem = document.getElementById("elemID"); 149 150 elem.style.chickenHead = {} -
lib/OpenLayers/BaseTypes/Element.js
old new 135 135 */ 136 136 getStyle: function(element, style) { 137 137 element = OpenLayers.Util.getElement(element); 138 var value = element.style[OpenLayers.String.camelize(style)]; 139 if (!value) { 140 if (document.defaultView && 141 document.defaultView.getComputedStyle) { 142 143 var css = document.defaultView.getComputedStyle(element, null); 144 value = css ? css.getPropertyValue(style) : null; 145 } else if (element.currentStyle) { 146 value = element.currentStyle[OpenLayers.String.camelize(style)]; 138 139 var value = null; 140 if (element && element.style) { 141 value = element.style[OpenLayers.String.camelize(style)]; 142 if (!value) { 143 if (document.defaultView && 144 document.defaultView.getComputedStyle) { 145 146 var css = document.defaultView.getComputedStyle(element, null); 147 value = css ? css.getPropertyValue(style) : null; 148 } else if (element.currentStyle) { 149 value = element.currentStyle[OpenLayers.String.camelize(style)]; 150 } 147 151 } 152 153 var positions = ['left', 'top', 'right', 'bottom']; 154 if (window.opera && 155 (OpenLayers.Util.indexOf(positions,style) != -1) && 156 (OpenLayers.Element.getStyle(element, 'position') == 'static')) { 157 value = 'auto'; 158 } 148 159 } 149 160 150 var positions = ['left', 'top', 'right', 'bottom'];151 if (window.opera &&152 (OpenLayers.Util.indexOf(positions,style) != -1) &&153 (OpenLayers.Element.getStyle(element, 'position') == 'static')) {154 value = 'auto';155 }156 157 161 return value == 'auto' ? null : value; 158 162 } 159 163
