Bug Tracker

Changeset 5274

Show
Ignore:
Timestamp:
04/21/08 22:54:25 (8 months ago)
Author:
brandon.aaron
Message:

Small optimization to jQuery.curCSS (thanks Ariel Flesler)

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/jquery/src/core.js

    r5214 r5274  
    612612// exclude the following css properties to add px 
    613613var exclude = /z-?index|font-?weight|opacity|zoom|line-?height/i; 
     614// cache getComputedStyle 
     615var getComputedStyle = document.defaultView && document.defaultView.getComputedStyle; 
    614616 
    615617jQuery.extend({ 
     
    838840            if ( !jQuery.browser.safari ) 
    839841                return false; 
    840  
    841             var ret = document.defaultView.getComputedStyle( elem, null ); 
     842             
     843            // getComputedStyle is cached 
     844            var ret = getComputedStyle( elem, null ); 
    842845            return !ret || ret.getPropertyValue("color") == ""; 
    843846        } 
     
    865868            ret = elem.style[ name ]; 
    866869 
    867         else if ( document.defaultView && document.defaultView.getComputedStyle ) { 
     870        else if ( getComputedStyle ) { 
    868871 
    869872            // Only "float" is needed here 
     
    873876            name = name.replace( /([A-Z])/g, "-$1" ).toLowerCase(); 
    874877 
    875             var getComputedStyle = document.defaultView.getComputedStyle( elem, null ); 
    876  
    877             if ( getComputedStyle && !color( elem ) ) 
    878                 ret = getComputedStyle.getPropertyValue( name ); 
     878            var computedStyle = getComputedStyle( elem, null ); 
     879 
     880            if ( computedStyle && !color( elem ) ) 
     881                ret = computedStyle.getPropertyValue( name ); 
    879882 
    880883            // If the element isn't reporting its values properly in Safari 
     
    899902                ret = name == "display" && swap[ stack.length - 1 ] != null ? 
    900903                    "none" : 
    901                     ( getComputedStyle && getComputedStyle.getPropertyValue( name ) ) || ""; 
     904                    ( computedStyle && computedStyle.getPropertyValue( name ) ) || ""; 
    902905 
    903906                // Finally, revert the display styles back