OpenLayers OpenLayers

Changeset 7888

Show
Ignore:
Timestamp:
08/28/08 20:46:45 (3 months ago)
Author:
euzuro
Message:

improving the biceps of getStyle(). Now if you pass it a null object, it will not die. r=cr5 (Closes #1051)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/openlayers/lib/OpenLayers/BaseTypes/Element.js

    r7627 r7888  
    216216    getStyle: function(element, style) { 
    217217        element = OpenLayers.Util.getElement(element); 
    218         var value = element.style[OpenLayers.String.camelize(style)]; 
    219         if (!value) { 
    220             if (document.defaultView &&  
    221                 document.defaultView.getComputedStyle) { 
    222                  
    223                 var css = document.defaultView.getComputedStyle(element, null); 
    224                 value = css ? css.getPropertyValue(style) : null; 
    225             } else if (element.currentStyle) { 
    226                 value = element.currentStyle[OpenLayers.String.camelize(style)]; 
     218 
     219        var value = null; 
     220        if (element && element.style) { 
     221            value = element.style[OpenLayers.String.camelize(style)]; 
     222            if (!value) { 
     223                if (document.defaultView &&  
     224                    document.defaultView.getComputedStyle) { 
     225                     
     226                    var css = document.defaultView.getComputedStyle(element, null); 
     227                    value = css ? css.getPropertyValue(style) : null; 
     228                } else if (element.currentStyle) { 
     229                    value = element.currentStyle[OpenLayers.String.camelize(style)]; 
     230                } 
    227231            } 
    228         } 
    229      
    230         var positions = ['left', 'top', 'right', 'bottom']; 
    231         if (window.opera && 
    232             (OpenLayers.Util.indexOf(positions,style) != -1) && 
    233             (OpenLayers.Element.getStyle(element, 'position') == 'static')) {  
    234             value = 'auto'; 
     232         
     233            var positions = ['left', 'top', 'right', 'bottom']; 
     234            if (window.opera && 
     235                (OpenLayers.Util.indexOf(positions,style) != -1) && 
     236                (OpenLayers.Element.getStyle(element, 'position') == 'static')) {  
     237                value = 'auto'; 
     238            } 
    235239        } 
    236240     
  • trunk/openlayers/lib/OpenLayers/Util.js

    r7684 r7888  
    10671067 
    10681068        if(element == document.body) { 
    1069             // FIXME: IE, when passed 'window' as the forElement, treats it as 
    1070             // equal to document.body, but window.style fails, so getStyle 
    1071             // fails, so we are paranoid and check this here. This check should 
    1072             // probably move into element.getStyle in 2.6. 
    1073             if(child && child.style &&  
    1074                OpenLayers.Element.getStyle(child, 'position') == 'absolute') { 
     1069            if(OpenLayers.Element.getStyle(child, 'position') == 'absolute') { 
    10751070                break; 
    10761071            } 
  • trunk/openlayers/tests/BaseTypes/Element.html

    r7579 r7888  
    220220 
    221221    function test_Element_getStyle(t) { 
    222         t.plan(4); 
     222        t.plan(5); 
    223223 
    224224    //tests for this function are not 100% complete... there is some funky 
     
    227227    // but I cant seem to find a good way to test them. 
    228228    //  
     229        t.ok(OpenLayers.Element.getStyle(null, null) == null, "passing null values in to getStyle() doesnt bomb, returns null"); 
    229230 
    230231        var elem = document.getElementById("elemID");