Skip to content
Permalink
Browse files

Small optimization to jQuery.curCSS (thanks Ariel Flesler)

  • Loading branch information
brandonaaron committed Apr 21, 2008
1 parent 5d033db commit 3e285bd60de63afe314971957a0547603bb74386
Showing with 10 additions and 7 deletions.
  1. +10 −7 src/core.js
@@ -611,6 +611,8 @@ var expando = "jQuery" + (new Date()).getTime(), uuid = 0, windowData = {};

// exclude the following css properties to add px
var exclude = /z-?index|font-?weight|opacity|zoom|line-?height/i;
// cache getComputedStyle
var getComputedStyle = document.defaultView && document.defaultView.getComputedStyle;

jQuery.extend({
noConflict: function( deep ) {
@@ -837,8 +839,9 @@ jQuery.extend({
function color( elem ) {
if ( !jQuery.browser.safari )
return false;

var ret = document.defaultView.getComputedStyle( elem, null );

// getComputedStyle is cached
var ret = getComputedStyle( elem, null );
return !ret || ret.getPropertyValue("color") == "";
}

@@ -864,18 +867,18 @@ jQuery.extend({
if ( !force && elem.style && elem.style[ name ] )
ret = elem.style[ name ];

else if ( document.defaultView && document.defaultView.getComputedStyle ) {
else if ( getComputedStyle ) {

// Only "float" is needed here
if ( name.match( /float/i ) )
name = "float";

name = name.replace( /([A-Z])/g, "-$1" ).toLowerCase();

var getComputedStyle = document.defaultView.getComputedStyle( elem, null );
var computedStyle = getComputedStyle( elem, null );

if ( getComputedStyle && !color( elem ) )
ret = getComputedStyle.getPropertyValue( name );
if ( computedStyle && !color( elem ) )
ret = computedStyle.getPropertyValue( name );

// If the element isn't reporting its values properly in Safari
// then some display: none elements are involved
@@ -898,7 +901,7 @@ jQuery.extend({
// one special, otherwise get the value
ret = name == "display" && swap[ stack.length - 1 ] != null ?
"none" :
( getComputedStyle && getComputedStyle.getPropertyValue( name ) ) || "";
( computedStyle && computedStyle.getPropertyValue( name ) ) || "";

// Finally, revert the display styles back
for ( var i = 0; i < swap.length; i++ )

0 comments on commit 3e285bd

Please sign in to comment.
You can’t perform that action at this time.