Make sure that opacity is being reset properly on a show animation. Additionally expose jQuery.isNaN from the data module.

This commit is contained in:
jeresig 2010-09-27 11:51:01 -04:00
parent 0da700a4d0
commit 0be7f4eb4f
4 changed files with 27 additions and 21 deletions

View file

@ -33,6 +33,9 @@ var jQuery = function( selector, context ) {
// Check for non-word characters // Check for non-word characters
rnonword = /\W/, rnonword = /\W/,
// Check for digits
rdigit = /\d/,
// Match a standalone tag // Match a standalone tag
rsingleTag = /^<(\w+)\s*\/?>(?:<\/\1>)?$/, rsingleTag = /^<(\w+)\s*\/?>(?:<\/\1>)?$/,
@ -488,6 +491,10 @@ jQuery.extend({
return obj && typeof obj === "object" && "setInterval" in obj; return obj && typeof obj === "object" && "setInterval" in obj;
}, },
isNaN: function( obj ) {
return obj == null || !rdigit.test( obj ) || isNaN( obj );
},
type: function( obj ) { type: function( obj ) {
return obj == null ? return obj == null ?
String( obj ) : String( obj ) :

View file

@ -32,10 +32,15 @@ jQuery.extend({
// behavior of getting and setting a style property // behavior of getting and setting a style property
cssHooks: { cssHooks: {
opacity: { opacity: {
get: function( elem ) { get: function( elem, computed ) {
// We should always get a number back from opacity if ( computed ) {
var ret = curCSS( elem, "opacity", "opacity" ); // We should always get a number back from opacity
return ret === "" ? "1" : ret; var ret = curCSS( elem, "opacity", "opacity" );
return ret === "" ? "1" : ret;
} else {
return elem.style.opacity;
}
} }
} }
}, },
@ -176,7 +181,7 @@ if ( !jQuery.support.opacity ) {
// IE uses filters for opacity // IE uses filters for opacity
return ropacity.test((computed && elem.currentStyle ? elem.currentStyle.filter : elem.style.filter) || "") ? return ropacity.test((computed && elem.currentStyle ? elem.currentStyle.filter : elem.style.filter) || "") ?
(parseFloat(RegExp.$1) / 100) + "" : (parseFloat(RegExp.$1) / 100) + "" :
"1"; computed ? "1" : "";
}, },
set: function( elem, value ) { set: function( elem, value ) {
@ -187,11 +192,10 @@ if ( !jQuery.support.opacity ) {
style.zoom = 1; style.zoom = 1;
// Set the alpha filter to set the opacity // Set the alpha filter to set the opacity
var opacity = isNaN(value) ? var opacity = jQuery.isNaN(value) ?
"" : "" :
"alpha(opacity=" + value * 100 + ")"; "alpha(opacity=" + value * 100 + ")",
filter = style.filter || "";
var filter = style.filter || elem.currentStyle && elem.currentStyle.filter || "";
style.filter = ralpha.test(filter) ? style.filter = ralpha.test(filter) ?
filter.replace(ralpha, opacity) : filter.replace(ralpha, opacity) :

View file

@ -1,8 +1,7 @@
(function( jQuery ) { (function( jQuery ) {
var windowData = {}, var windowData = {},
rbrace = /^(?:\{.*\}|\[.*\])$/, rbrace = /^(?:\{.*\}|\[.*\])$/;
rdigit = /\d/;
jQuery.extend({ jQuery.extend({
cache: {}, cache: {},
@ -174,7 +173,7 @@ jQuery.fn.extend({
data = data === "true" ? true : data = data === "true" ? true :
data === "false" ? false : data === "false" ? false :
data === "null" ? null : data === "null" ? null :
rdigit.test( data ) && !isNaN( data ) ? parseFloat( data ) : !jQuery.isNaN( data ) ? parseFloat( data ) :
rbrace.test( data ) ? jQuery.parseJSON( data ) : rbrace.test( data ) ? jQuery.parseJSON( data ) :
data; data;
} catch( e ) {} } catch( e ) {}

14
test/unit/effects.js vendored
View file

@ -389,16 +389,16 @@ jQuery.each( {
"CSS Auto": function(elem,prop){ "CSS Auto": function(elem,prop){
jQuery(elem).addClass("auto" + prop) jQuery(elem).addClass("auto" + prop)
.text("This is a long string of text."); .text("This is a long string of text.");
return prop == "opacity" ? 1 : ""; return "";
}, },
"JS Auto": function(elem,prop){ "JS Auto": function(elem,prop){
jQuery(elem).css(prop,"") jQuery(elem).css(prop,"")
.text("This is a long string of text."); .text("This is a long string of text.");
return prop == "opacity" ? 1 : ""; return "";
}, },
"CSS 100": function(elem,prop){ "CSS 100": function(elem,prop){
jQuery(elem).addClass("large" + prop); jQuery(elem).addClass("large" + prop);
return prop == "opacity" ? 1 : ""; return "";
}, },
"JS 100": function(elem,prop){ "JS 100": function(elem,prop){
jQuery(elem).css(prop,prop == "opacity" ? 1 : "100px"); jQuery(elem).css(prop,prop == "opacity" ? 1 : "100px");
@ -406,7 +406,7 @@ jQuery.each( {
}, },
"CSS 50": function(elem,prop){ "CSS 50": function(elem,prop){
jQuery(elem).addClass("med" + prop); jQuery(elem).addClass("med" + prop);
return prop == "opacity" ? 0.5 : ""; return "";
}, },
"JS 50": function(elem,prop){ "JS 50": function(elem,prop){
jQuery(elem).css(prop,prop == "opacity" ? 0.50 : "50px"); jQuery(elem).css(prop,prop == "opacity" ? 0.50 : "50px");
@ -414,7 +414,7 @@ jQuery.each( {
}, },
"CSS 0": function(elem,prop){ "CSS 0": function(elem,prop){
jQuery(elem).addClass("no" + prop); jQuery(elem).addClass("no" + prop);
return prop == "opacity" ? 0 : ""; return "";
}, },
"JS 0": function(elem,prop){ "JS 0": function(elem,prop){
jQuery(elem).css(prop,prop == "opacity" ? 0 : "0px"); jQuery(elem).css(prop,prop == "opacity" ? 0 : "0px");
@ -481,10 +481,6 @@ jQuery.each( {
var cur_o = jQuery.style(this, "opacity"); var cur_o = jQuery.style(this, "opacity");
if ( cur_o !== "" ) {
cur_o = jQuery.css(this, "opacity");
}
if ( t_o == "hide" || t_o == "show" ) if ( t_o == "hide" || t_o == "show" )
equals(cur_o, f_o, "Opacity must be reset to " + f_o + ": " + cur_o); equals(cur_o, f_o, "Opacity must be reset to " + f_o + ": " + cur_o);