-
Notifications
You must be signed in to change notification settings - Fork 20.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
#11317: jQuery.ifNumeric #684
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
(function( jQuery ) { | ||
|
||
var ralpha = /alpha\([^)]*\)/i, | ||
var ralpha = /alpha\([^)]*\)|$/i, | ||
ropacity = /opacity=([^)]*)/, | ||
// fixed for IE9, see #8346 | ||
rupper = /([A-Z]|^ms)/g, | ||
|
@@ -319,23 +319,22 @@ if ( !jQuery.support.opacity ) { | |
jQuery.cssHooks.opacity = { | ||
get: function( elem, computed ) { | ||
// IE uses filters for opacity | ||
return ropacity.test( (computed && elem.currentStyle ? elem.currentStyle.filter : elem.style.filter) || "" ) ? | ||
return ropacity.test( (computed && elem.currentStyle || elem.style).filter || "" ) ? | ||
( parseFloat( RegExp.$1 ) / 100 ) + "" : | ||
computed ? "1" : ""; | ||
}, | ||
|
||
set: function( elem, value ) { | ||
var style = elem.style, | ||
currentStyle = elem.currentStyle, | ||
opacity = jQuery.isNumeric( value ) ? "alpha(opacity=" + value * 100 + ")" : "", | ||
filter = currentStyle && currentStyle.filter || style.filter || ""; | ||
|
||
// IE has trouble with opacity if it does not have layout | ||
// Force it by setting the zoom level | ||
style.zoom = 1; | ||
|
||
// if setting opacity to 1, and no other filters exist - attempt to remove filter attribute #6652 | ||
if ( value >= 1 && jQuery.trim( filter.replace( ralpha, "" ) ) === "" ) { | ||
if ( value >= 1 && !jQuery.trim( filter.replace( ralpha, "" ) ) ) { | ||
|
||
// Setting style.filter to null, "" & " " still leave "filter:" in the cssText | ||
// if "filter:" is present at all, clearType is disabled, we want to avoid this | ||
|
@@ -349,9 +348,11 @@ if ( !jQuery.support.opacity ) { | |
} | ||
|
||
// otherwise, set new filter values | ||
style.filter = ralpha.test( filter ) ? | ||
filter.replace( ralpha, opacity ) : | ||
filter + " " + opacity; | ||
style.filter = filter.replace( ralpha, function( current, offset ) { | ||
return jQuery.ifNumeric( value ) != null ? | ||
( current ? "" : " " ) + "alpha(opacity=" + value * 100 + ")" : | ||
""; | ||
}); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How is this an improvement? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is smaller (5 bytes gzipped) and saves a redundant regular expression test in the "replacement" case. That being said, it may or may not be faster. I've opened a jsPerf, and would appreciate IE testing if someone can help. |
||
} | ||
}; | ||
} | ||
|
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.
Did you read the complete discussion here: http://bugs.jquery.com/ticket/6652 or the original patch #416? The check for an empty string is very much intentional. PLEASE read tickets that are cited before making changes like this.
cc @gnarf37
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.
As a matter of fact, I did read http://bugs.jquery.com/ticket/6652. And I also read the source for
jQuery.trim
, which always returns a string. The equality check may be intentional, but it is not necessary.