…tyle (currently set values).
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -29,7 +29,7 @@ jQuery.fn.extend({ | ||
|
||
this[i].style.display = old || ""; | ||
|
||
if ( jQuery.css(this[i], "display") === "none" ) { | ||
if ( jQuery.css( this[i], "display" ) === "none" ) { | ||
var nodeName = this[i].nodeName, display; | ||
|
||
if ( elemdisplay[ nodeName ] ) { | ||
@@ -71,7 +71,7 @@ jQuery.fn.extend({ | ||
for ( var i = 0, l = this.length; i < l; i++ ) { | ||
var old = jQuery.data(this[i], "olddisplay"); | ||
if ( !old && old !== "none" ) { | ||
jQuery.data( this[i], "olddisplay", jQuery.css(this[i], "display") ); | ||
jQuery.data( this[i], "olddisplay", jQuery.css( this[i], "display" ) ); | ||
} | ||
} | ||
|
||
@@ -139,7 +139,7 @@ jQuery.fn.extend({ | ||
|
||
if ( ( p === "height" || p === "width" ) && this.style ) { | ||
// Store display property | ||
opt.display = jQuery.css(this, "display"); | ||
opt.display = this.style.display; | ||
|
||
// Make sure that nothing sneaks out | ||
opt.overflow = this.style.overflow; | ||
@@ -316,13 +316,13 @@ jQuery.fx.prototype = { | ||
}, | ||
|
||
// Get the current size | ||
cur: function( force ) { | ||
cur: function() { | ||
if ( this.elem[this.prop] != null && (!this.elem.style || this.elem.style[this.prop] == null) ) { | ||
return this.elem[ this.prop ]; | ||
} | ||
|
||
var r = parseFloat(jQuery.css(this.elem, this.prop, undefined, force)); | ||
return r && r > -10000 ? r : parseFloat(jQuery.css(this.elem, this.prop)) || 0; | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
DanielBaulig
|
||
var r = jQuery.css( this.elem, this.prop ); | ||
return r && r > -10000 ? r : 0; | ||
}, | ||
|
||
// Start an animation from one number to another | ||
@@ -349,7 +349,7 @@ jQuery.fx.prototype = { | ||
// Simple 'show' function | ||
show: function() { | ||
// Remember where we started, so that we can go back to it later | ||
this.options.orig[this.prop] = jQuery.css( this.elem, this.prop, undefined, false ); | ||
this.options.orig[this.prop] = jQuery.style( this.elem, this.prop ); | ||
this.options.show = true; | ||
|
||
// Begin the animation | ||
@@ -364,7 +364,7 @@ jQuery.fx.prototype = { | ||
// Simple 'hide' function | ||
hide: function() { | ||
// Remember where we started, so that we can go back to it later | ||
this.options.orig[this.prop] = jQuery.css( this.elem, this.prop, undefined, false ); | ||
this.options.orig[this.prop] = jQuery.style( this.elem, this.prop ); | ||
this.options.hide = true; | ||
|
||
// Begin the animation | ||
@@ -397,7 +397,7 @@ jQuery.fx.prototype = { | ||
var old = jQuery.data(this.elem, "olddisplay"); | ||
this.elem.style.display = old ? old : this.options.display; | ||
|
||
if ( jQuery.css(this.elem, "display") === "none" ) { | ||
if ( jQuery.css( this.elem, "display" ) === "none" ) { | ||
this.elem.style.display = "block"; | ||
} | ||
} | ||
@@ -410,7 +410,7 @@ jQuery.fx.prototype = { | ||
// Reset the properties, if the item has been hidden or shown | ||
if ( this.options.hide || this.options.show ) { | ||
for ( var p in this.options.curAnim ) { | ||
jQuery.css( this.elem, p, this.options.orig[p] ); | ||
jQuery.style( this.elem, p, this.options.orig[p] ); | ||
} | ||
} | ||
|
||
@@ -467,7 +467,7 @@ jQuery.extend( jQuery.fx, { | ||
|
||
step: { | ||
opacity: function( fx ) { | ||
jQuery.css( fx.elem, "opacity", fx.now ); | ||
jQuery.style( fx.elem, "opacity", fx.now ); | ||
}, | ||
|
||
_default: function( fx ) { | ||
12 comments
on commit 37b607d
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it just me or do "css" and "style" names sound rather non-descriptive? Is there anything about "css" name suggesting that method should return computed style values? Why not have "style" and "computedStyle" (or "compStyle")?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because that's the API that we have - and have had for years? The methods aren't typically user-facing but they are used by plugin authors so they're likely going to stay as-is for quite some time.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see.
I was just surprised by how unclear those 2 method names are, that you had to specify how they differ in parens. I thought — why not just make names more descriptive? Have you considered aliasing methods like these to more explanatory names? And then discourage their usage in favor of new ones? Or are method names like these not considered a problem?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not really considered a problem - they're almost entirely used internally. As far as the naming goes it seems to work fairly well - our main .css() methods (used by the end user and provides the computed styling of an element) maps directly to our internal jQuery.css(). jQuery.style() is another method that we use internally to manage the setting and getting of the style property.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aliasing seems like a good start.
But if the new method wants to have different behavior (bug fix), then aliasing wouldn't work. With method delegation, the new [and] old methods share scope with a new private method, introduced to perform common tasks.
{ ... css: deprecatedCSS, computedStyle: computedStyle, ... } function deprecatedCSS(a, b, c) { /* legacy-related code here */ var style = _readComputedtStyle(a, b, c); /* more legacy-related code */ return style; } function _readComputedStyle(a, b, c) { var style; /*...*/ return style; } function computedStyle(a, b, c) { return _readComputedStyle(a, b, c); }
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi, I would suggest that the row 325 effects.js
return r && r > -10000 ? r : 0;
would be changed back to
return r;
It works correctly in opera, otherwise anything moved with animate with a position > 10000 will get back to 0 and animate from there.
thank you
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return r && r > -10000 ? r : 0;
Yes. I agree with CaViCcHi. I have application where 'left property can be less when -10000
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Flcn an easy way around it according to your needs is to add this to your code. So you can keep on going :)
/* * Overwrites the Method created, because of a jQuery bug * http://github.com/jquery/jquery/commit/37b607d2815b893d13de4ac3461090d0dd46535e#commitcomment-170919 */ jQuery.fx.prototype.cur = function() { if ( this.elem[this.prop] != null && (!this.elem.style || this.elem.style[this.prop] == null) ) { return this.elem[ this.prop ]; } var r = parseFloat( jQuery.css( this.elem, this.prop ) ); return r /*&& r > -10000 ? r : 0*/; };
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I came across this myself just today. Hadn't seen this discussion yet, however. #101
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use my workaround :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually I propose to rather use
return r ? r : 0;
or
return r || 0;
Note though that the latter might be subject to compiler optimizations because the right part will never evaluate to true and thus might not be evaluated if JS engines optimize this kind of behavior. Also suggested this in the trac bug report.
whe you remove this? parseFloat(jQuery.css(this.elem, this.prop)) ?
it breaks some applications where values can be less then -10000.
and i wonder, why exactly -10000 ? not -100000 for example