OpenLayers OpenLayers

Ticket #1051: getStyle_safe.patch

File getStyle_safe.patch, 2.8 kB (added by euzuro, 6 months ago)

how about this? ((or should this patch include the propsed chanes to getPagePosition() or whatever it's called function))

  • tests/BaseTypes/Element.html

    old new  
    137137    }     
    138138 
    139139    function test_Element_getStyle(t) { 
    140         t.plan(4); 
     140        t.plan(5); 
    141141 
    142142    //tests for this function are not 100% complete... there is some funky 
    143143    // business going on in there with  
    144144    //  * document.defaultView (moz/ff I believe) 
    145145    // but I cant seem to find a good way to test them. 
    146146    //  
     147        t.ok(OpenLayers.Element.getStyle(null, null) == null, "passing null values in to getStyle() doesnt bomb, returns null"); 
    147148 
    148149        var elem = document.getElementById("elemID"); 
    149150        elem.style.chickenHead = {} 
  • lib/OpenLayers/BaseTypes/Element.js

    old new  
    135135     */ 
    136136    getStyle: function(element, style) { 
    137137        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                } 
    147151            } 
     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            } 
    148159        } 
    149160     
    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      
    157161        return value == 'auto' ? null : value; 
    158162    } 
    159163