-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Effects: Rewrote "clip" effect to animate CSS clip property #876
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
Conversation
@@ -13,51 +13,127 @@ | |||
*/ | |||
(function( $, undefined ) { | |||
|
|||
var clipRegex = /^rect\((-?\d*.?\d*px|-?\d+%|auto),?\s+(-?\d*.?\d*px|-?\d+%|auto),?\s+(-?\d*.?\d*px|-?\d+%|auto),?\s+(-?\d*.?\d*px|-?\d+%|auto)\)$/, |
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's gotta be a shorter version of this.
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.
You prolly want to escape that .
since now it acts like a "any character"-capture
which makes this valid: rect(#10px, Mpx, 100!px, 2A0px)
Solution:
(-?\d*\.?\d*px|-?\d+%|auto)
@mikesherov only thing I can think of is adding {4} after the capture group, thus this would only capture one big group instead of 4 afaik =/
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.
@Jellyfrog How would you repeat the capture group to extract the necessary fields? In JS, only the last capture is kept.
A more maintainable solution might be to first split on delimiters and then extract each clip dimension in an exec
loop. I'll test out that approach.
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 don't know, thereof the
thus this would only capture one big group instead of 4 afaik =/
a while((match = regex.exec(str)) !== null)
might look better yes, tho I don't mind the current regex, except for the bug (see my prev. comment)
For now, don't worry about positional selectors being effected by the shadow. |
var clipRegex = /^rect\((-?\d*.?\d*px|-?\d+%|auto),?\s+(-?\d*.?\d*px|-?\d+%|auto),?\s+(-?\d*.?\d*px|-?\d+%|auto),?\s+(-?\d*.?\d*px|-?\d+%|auto)\)$/, | ||
parseClip = function( str, outerWidth, outerHeight ) { | ||
var clip, | ||
values = clipRegex.exec( str ); |
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.
byte saver:
values = clipRegex.exec( str ) || [ "", 0, outerWidth, outerHeight, 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.
Funny, I originally did the same thing but changed it to its current form to prevent the unnecessary ternary and parseInt
calls for the most common case where clip is auto
. Another case of premature optimization on my part ;)
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.
:-) Speed here takes a back seat to size and maintainability, as @scottgonzalez mentions.
I'm going to create a |
values[ 3 ] = "auto"; | ||
} | ||
|
||
clip = { |
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.
no need for clip
variable. Just return the object.
abstract out createPlaceholder
fix margin-collapse
encapsulate more information into createPlaceholder
More generalizations
FURTHER ABSTRACTION
Closing this for now, @mpetrovich. I'll open a new one so you're not a blocker. Thanks for contributing! |
Known issues:
.class:first
,:nth-child
, etc.