Side navigation
Ticket #2550: offset-curCSS-getComp.diff
File offset-curCSS-getComp.diff, 3.5 KB (added by flesler, March 19, 2008 04:09AM UTC)
Replacing css for curCSS inside offset, caching getComputedStyle
Index: src/offset.js
===================================================================
--- src/offset.js (revision 5084)
+++ src/offset.js (working copy)
@@ -10,7 +10,7 @@
offsetParent = elem.offsetParent,
doc = elem.ownerDocument,
safari2 = safari && parseInt(version) < 522 && !/adobeair/i.test(userAgent),
- fixed = jQuery.css(elem, "position") == "fixed";
+ fixed = jQuery.curCSS(elem, "position") == "fixed";
// Use getBoundingClientRect if available
if ( elem.getBoundingClientRect ) {
@@ -45,7 +45,7 @@
border( offsetParent );
// Add the document scroll offsets if position is fixed on any offsetParent
- if ( !fixed && jQuery.css(offsetParent, "position") == "fixed" )
+ if ( !fixed && jQuery.curCSS(offsetParent, "position") == "fixed" )
fixed = true;
// Set offsetChild to previous offsetParent unless it is the body element
@@ -57,12 +57,12 @@
// Get parent scroll offsets
while ( parent && parent.tagName && !/^body|html$/i.test(parent.tagName) ) {
// Remove parent scroll UNLESS that parent is inline or a table to work around Opera inline/table scrollLeft/Top bug
- if ( !/^inline|table.*$/i.test(jQuery.css(parent, "display")) )
+ if ( !/^inline|table.*$/i.test(jQuery.curCSS(parent, "display")) )
// Subtract parent scroll offsets
add( -parent.scrollLeft, -parent.scrollTop );
// Mozilla does not add the border for a parent that has overflow != visible
- if ( mozilla && jQuery.css(parent, "overflow") != "visible" )
+ if ( mozilla && jQuery.curCSS(parent, "overflow") != "visible" )
border( parent );
// Get next parent
@@ -71,8 +71,8 @@
// Safari <= 2 doubles body offsets with a fixed position element/offsetParent or absolutely positioned offsetChild
// Mozilla doubles body offsets with a non-absolutely positioned offsetChild
- if ( (safari2 && (fixed || jQuery.css(offsetChild, "position") == "absolute")) ||
- (mozilla && jQuery.css(offsetChild, "position") != "absolute") )
+ if ( (safari2 && (fixed || jQuery.curCSS(offsetChild, "position") == "absolute")) ||
+ (mozilla && jQuery.curCSS(offsetChild, "position") != "absolute") )
add( -doc.body.offsetLeft, -doc.body.offsetTop );
// Add the document scroll offsets if position is fixed
Index: src/core.js
===================================================================
--- src/core.js (revision 5084)
+++ src/core.js (working copy)
@@ -611,6 +611,8 @@
// exclude the following css properties to add px
var exclude = /z-?index|font-?weight|opacity|zoom|line-?height/i;
+//cache this
+var CS = document.defaultView && document.defaultView.getComputedStyle;
jQuery.extend({
noConflict: function( deep ) {
@@ -838,7 +840,7 @@
if ( !jQuery.browser.safari )
return false;
- var ret = document.defaultView.getComputedStyle( elem, null );
+ var ret = CS( elem, null );
return !ret || ret.getPropertyValue("color") == "";
}
@@ -864,7 +866,7 @@
if ( !force && elem.style && elem.style[ name ] )
ret = elem.style[ name ];
- else if ( document.defaultView && document.defaultView.getComputedStyle ) {
+ else if ( CS ) {
// Only "float" is needed here
if ( name.match( /float/i ) )
@@ -872,7 +874,7 @@
name = name.replace( /([A-Z])/g, "-$1" ).toLowerCase();
- var getComputedStyle = document.defaultView.getComputedStyle( elem, null );
+ var getComputedStyle = CS( elem, null );
if ( getComputedStyle && !color( elem ) )
ret = getComputedStyle.getPropertyValue( name );
Download in other formats:
Original Format
File offset-curCSS-getComp.diff, 3.5 KB (added by flesler, March 19, 2008 04:09AM UTC)
Replacing css for curCSS inside offset, caching getComputedStyle
Index: src/offset.js
===================================================================
--- src/offset.js (revision 5084)
+++ src/offset.js (working copy)
@@ -10,7 +10,7 @@
offsetParent = elem.offsetParent,
doc = elem.ownerDocument,
safari2 = safari && parseInt(version) < 522 && !/adobeair/i.test(userAgent),
- fixed = jQuery.css(elem, "position") == "fixed";
+ fixed = jQuery.curCSS(elem, "position") == "fixed";
// Use getBoundingClientRect if available
if ( elem.getBoundingClientRect ) {
@@ -45,7 +45,7 @@
border( offsetParent );
// Add the document scroll offsets if position is fixed on any offsetParent
- if ( !fixed && jQuery.css(offsetParent, "position") == "fixed" )
+ if ( !fixed && jQuery.curCSS(offsetParent, "position") == "fixed" )
fixed = true;
// Set offsetChild to previous offsetParent unless it is the body element
@@ -57,12 +57,12 @@
// Get parent scroll offsets
while ( parent && parent.tagName && !/^body|html$/i.test(parent.tagName) ) {
// Remove parent scroll UNLESS that parent is inline or a table to work around Opera inline/table scrollLeft/Top bug
- if ( !/^inline|table.*$/i.test(jQuery.css(parent, "display")) )
+ if ( !/^inline|table.*$/i.test(jQuery.curCSS(parent, "display")) )
// Subtract parent scroll offsets
add( -parent.scrollLeft, -parent.scrollTop );
// Mozilla does not add the border for a parent that has overflow != visible
- if ( mozilla && jQuery.css(parent, "overflow") != "visible" )
+ if ( mozilla && jQuery.curCSS(parent, "overflow") != "visible" )
border( parent );
// Get next parent
@@ -71,8 +71,8 @@
// Safari <= 2 doubles body offsets with a fixed position element/offsetParent or absolutely positioned offsetChild
// Mozilla doubles body offsets with a non-absolutely positioned offsetChild
- if ( (safari2 && (fixed || jQuery.css(offsetChild, "position") == "absolute")) ||
- (mozilla && jQuery.css(offsetChild, "position") != "absolute") )
+ if ( (safari2 && (fixed || jQuery.curCSS(offsetChild, "position") == "absolute")) ||
+ (mozilla && jQuery.curCSS(offsetChild, "position") != "absolute") )
add( -doc.body.offsetLeft, -doc.body.offsetTop );
// Add the document scroll offsets if position is fixed
Index: src/core.js
===================================================================
--- src/core.js (revision 5084)
+++ src/core.js (working copy)
@@ -611,6 +611,8 @@
// exclude the following css properties to add px
var exclude = /z-?index|font-?weight|opacity|zoom|line-?height/i;
+//cache this
+var CS = document.defaultView && document.defaultView.getComputedStyle;
jQuery.extend({
noConflict: function( deep ) {
@@ -838,7 +840,7 @@
if ( !jQuery.browser.safari )
return false;
- var ret = document.defaultView.getComputedStyle( elem, null );
+ var ret = CS( elem, null );
return !ret || ret.getPropertyValue("color") == "";
}
@@ -864,7 +866,7 @@
if ( !force && elem.style && elem.style[ name ] )
ret = elem.style[ name ];
- else if ( document.defaultView && document.defaultView.getComputedStyle ) {
+ else if ( CS ) {
// Only "float" is needed here
if ( name.match( /float/i ) )
@@ -872,7 +874,7 @@
name = name.replace( /([A-Z])/g, "-$1" ).toLowerCase();
- var getComputedStyle = document.defaultView.getComputedStyle( elem, null );
+ var getComputedStyle = CS( elem, null );
if ( getComputedStyle && !color( elem ) )
ret = getComputedStyle.getPropertyValue( name );