From 89f12a4f6069aa284c743d9989f00fc688668f1b Mon Sep 17 00:00:00 2001 From: Rick Waldron Date: Wed, 28 Sep 2011 18:14:35 -0400 Subject: [PATCH 1/4] Migrate from document.defaultView => window. Fixes #10373 --- src/css.js | 21 +++++++++------------ src/support.js | 5 +++-- 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/src/css.js b/src/css.js index 76c2255ce4..acfbda5452 100644 --- a/src/css.js +++ b/src/css.js @@ -13,8 +13,8 @@ var ralpha = /alpha\([^)]*\)/i, cssHeight = [ "Top", "Bottom" ], curCSS, - getComputedStyle, - currentStyle; + getComputedStyle = window.getComputedStyle, + computedStyle, currentStyle; jQuery.fn.css = function( name, value ) { // Setting 'undefined' is a no-op @@ -262,18 +262,15 @@ jQuery(function() { } }); -if ( document.defaultView && document.defaultView.getComputedStyle ) { - getComputedStyle = function( elem, name ) { - var ret, defaultView, computedStyle; +if ( getComputedStyle ) { + computedStyle = function( elem, name ) { + var ret, + computed = getComputedStyle( elem, null ); name = name.replace( rupper, "-$1" ).toLowerCase(); - if ( !(defaultView = elem.ownerDocument.defaultView) ) { - return undefined; - } - - if ( (computedStyle = defaultView.getComputedStyle( elem, null )) ) { - ret = computedStyle.getPropertyValue( name ); + if ( computed ) { + ret = computed.getPropertyValue( name ); if ( ret === "" && !jQuery.contains( elem.ownerDocument.documentElement, elem ) ) { ret = jQuery.style( elem, name ); } @@ -317,7 +314,7 @@ if ( document.documentElement.currentStyle ) { }; } -curCSS = getComputedStyle || currentStyle; +curCSS = computedStyle || currentStyle; function getWH( elem, name, extra ) { diff --git a/src/support.js b/src/support.js index dc93164a42..d70c232fe5 100644 --- a/src/support.js +++ b/src/support.js @@ -4,6 +4,7 @@ jQuery.support = (function() { var div = document.createElement( "div" ), documentElement = document.documentElement, + getComputedStyle = window.getComputedStyle, all, a, select, @@ -219,13 +220,13 @@ jQuery.support = (function() { // info see bug #3333 // Fails in WebKit before Feb 2011 nightlies // WebKit Bug 13343 - getComputedStyle returns wrong value for margin-right - if ( document.defaultView && document.defaultView.getComputedStyle ) { + if ( getComputedStyle ) { marginDiv = document.createElement( "div" ); marginDiv.style.width = "0"; marginDiv.style.marginRight = "0"; div.appendChild( marginDiv ); support.reliableMarginRight = - ( parseInt( ( document.defaultView.getComputedStyle( marginDiv, null ) || { marginRight: 0 } ).marginRight, 10 ) || 0 ) === 0; + ( parseInt( ( getComputedStyle( marginDiv, null ) || { marginRight: 0 } ).marginRight, 10 ) || 0 ) === 0; } // Remove the body element we added From df272c2f36f268c0a610548e6e8246cf3cfdba3f Mon Sep 17 00:00:00 2001 From: Rick Waldron Date: Wed, 28 Sep 2011 18:51:53 -0400 Subject: [PATCH 2/4] Direct calls to window.getComputedStyle --- src/css.js | 5 ++--- src/support.js | 5 ++--- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/css.js b/src/css.js index acfbda5452..430ac37732 100644 --- a/src/css.js +++ b/src/css.js @@ -13,7 +13,6 @@ var ralpha = /alpha\([^)]*\)/i, cssHeight = [ "Top", "Bottom" ], curCSS, - getComputedStyle = window.getComputedStyle, computedStyle, currentStyle; jQuery.fn.css = function( name, value ) { @@ -262,10 +261,10 @@ jQuery(function() { } }); -if ( getComputedStyle ) { +if ( window.getComputedStyle ) { computedStyle = function( elem, name ) { var ret, - computed = getComputedStyle( elem, null ); + computed = window.getComputedStyle( elem, null ); name = name.replace( rupper, "-$1" ).toLowerCase(); diff --git a/src/support.js b/src/support.js index d70c232fe5..77aa5f24e3 100644 --- a/src/support.js +++ b/src/support.js @@ -4,7 +4,6 @@ jQuery.support = (function() { var div = document.createElement( "div" ), documentElement = document.documentElement, - getComputedStyle = window.getComputedStyle, all, a, select, @@ -220,13 +219,13 @@ jQuery.support = (function() { // info see bug #3333 // Fails in WebKit before Feb 2011 nightlies // WebKit Bug 13343 - getComputedStyle returns wrong value for margin-right - if ( getComputedStyle ) { + if ( window.getComputedStyle ) { marginDiv = document.createElement( "div" ); marginDiv.style.width = "0"; marginDiv.style.marginRight = "0"; div.appendChild( marginDiv ); support.reliableMarginRight = - ( parseInt( ( getComputedStyle( marginDiv, null ) || { marginRight: 0 } ).marginRight, 10 ) || 0 ) === 0; + ( parseInt( ( window.getComputedStyle( marginDiv, null ) || { marginRight: 0 } ).marginRight, 10 ) || 0 ) === 0; } // Remove the body element we added From ffc7a560c1fa2aed899b6a7787e9360dae2c8754 Mon Sep 17 00:00:00 2001 From: Rick Waldron Date: Wed, 28 Sep 2011 19:01:48 -0400 Subject: [PATCH 3/4] Migrate to window.getComputedStyle in offset.js (alt) --- src/offset.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/offset.js b/src/offset.js index 4cc87acff5..db4696d4ba 100644 --- a/src/offset.js +++ b/src/offset.js @@ -69,8 +69,7 @@ if ( "getBoundingClientRect" in document.documentElement ) { doc = elem.ownerDocument, docElem = doc.documentElement, body = doc.body, - defaultView = doc.defaultView, - prevComputedStyle = defaultView ? defaultView.getComputedStyle( elem, null ) : elem.currentStyle, + prevComputedStyle = window.getComputedStyle ? window.getComputedStyle( elem, null ) : elem.currentStyle, top = elem.offsetTop, left = elem.offsetLeft; @@ -79,7 +78,7 @@ if ( "getBoundingClientRect" in document.documentElement ) { break; } - computedStyle = defaultView ? defaultView.getComputedStyle(elem, null) : elem.currentStyle; + computedStyle = window.getComputedStyle ? window.getComputedStyle(elem, null) : elem.currentStyle; top -= elem.scrollTop; left -= elem.scrollLeft; From 8880e384d10bd5b1d585eaaf6410124ea4f1fe52 Mon Sep 17 00:00:00 2001 From: Rick Waldron Date: Wed, 28 Sep 2011 19:19:29 -0400 Subject: [PATCH 4/4] Migrate to window.getComputedStyle. Fixes #10373 --- src/css.js | 2 +- src/offset.js | 4 ++-- src/support.js | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/css.js b/src/css.js index 430ac37732..99cb7cb652 100644 --- a/src/css.js +++ b/src/css.js @@ -264,7 +264,7 @@ jQuery(function() { if ( window.getComputedStyle ) { computedStyle = function( elem, name ) { var ret, - computed = window.getComputedStyle( elem, null ); + computed = getComputedStyle( elem, null ); name = name.replace( rupper, "-$1" ).toLowerCase(); diff --git a/src/offset.js b/src/offset.js index db4696d4ba..1f3612dbf0 100644 --- a/src/offset.js +++ b/src/offset.js @@ -69,7 +69,7 @@ if ( "getBoundingClientRect" in document.documentElement ) { doc = elem.ownerDocument, docElem = doc.documentElement, body = doc.body, - prevComputedStyle = window.getComputedStyle ? window.getComputedStyle( elem, null ) : elem.currentStyle, + prevComputedStyle = window.getComputedStyle ? getComputedStyle( elem, null ) : elem.currentStyle, top = elem.offsetTop, left = elem.offsetLeft; @@ -78,7 +78,7 @@ if ( "getBoundingClientRect" in document.documentElement ) { break; } - computedStyle = window.getComputedStyle ? window.getComputedStyle(elem, null) : elem.currentStyle; + computedStyle = window.getComputedStyle ? getComputedStyle(elem, null) : elem.currentStyle; top -= elem.scrollTop; left -= elem.scrollLeft; diff --git a/src/support.js b/src/support.js index 77aa5f24e3..ce35c91be5 100644 --- a/src/support.js +++ b/src/support.js @@ -225,7 +225,7 @@ jQuery.support = (function() { marginDiv.style.marginRight = "0"; div.appendChild( marginDiv ); support.reliableMarginRight = - ( parseInt( ( window.getComputedStyle( marginDiv, null ) || { marginRight: 0 } ).marginRight, 10 ) || 0 ) === 0; + ( parseInt( ( getComputedStyle( marginDiv, null ) || { marginRight: 0 } ).marginRight, 10 ) || 0 ) === 0; } // Remove the body element we added