jquery/jquery — pull request #731 by gnarf37 (2012-04-08 23:02:59+00:00)
Title: 1.8 effects

So - I don't feel like this branch is by any means DONE... I just want an easy way for people to look at what I'm doing and discuss it. It currently passes all jQuery core unit tests in chrome so I figure its time to share it on a wider scale. It currently weighs in a little under 300 bytes more than the current core after min and gzip.

#jQuery 1.8 Effects

To quote my own summary from an email thread:

> My goal in the end is to have a plugin to sit alongside jQuery 1.8 (like `jQuery.color.js`) which implements animations that CAN be done with transitions or css animations, yet lets all the "complex" animations fall through to the default provider in jQuery core. This would allow you to define your animations in terms of CSS animation / transition style apis, and know that if the browser can't support CSS3, jQuery core will be doing what its doing now. This plugin may or may not find its way into UI Effects Core as jQuery.color already has.

## General organization

`jQuery.Animation` is a new function which implements most of what our current `doAnimation` function hiding inside `jQuery.fn.animate` currently does. It returns an animation object which has the standard promise methods ( `.done()` and `.fail()` ) plus a helper called `.finished()` to publish its state information to the outside world. `fail()` functions will be called with a boolean `gotoEnd` whenever someone `.stop()`s the animation. `.done()` functions will NOT be called on `.stop( gotoEnd )` but will be called whenever the animation comes to its natural completion. `.finish()` functions will be called whenever the animation completes - regardless of it had been `.stop()`ed.

`jQuery.Tween` is very similar to the old `jQuery.fx` (so much so that it is being used as such for backwards-compat). It handles the actual easing/get/set operations for a single element and property from 0% to 100%. Animations contain an array of Tweens that will be updated when their `tick` function is called.

## New hook points

###`jQuery.Animation.preFilter( function( element, props, opts ) { var animation = this; })`
Pre-filters allow a plugin to look at the `props` and `opts` of an animation being created and overide some default functionality, or do something else entirely with it. The hide / show special case preFilter in the code is a good example. It creates its own tweens for the hide and show scope to retain access to in the `finish()` callbacks it attaches to hook all of timmy's `fxstop` goodness together. Pre-filters are allowed to return their own object so long as it implements `.stop( gotoEnd )`, and `.finish()`. `jQuery.fn.animate` will be none the wiser.

###`jQuery.Animation.tweener( propsList, function( property, value ) { var animation = this; })`
Allows you to peek at the property/value combinations and decide how to create a tween for that property or value. It should return truthy if it created the tween. If you want the tween to be managed by the animation you should use the `animation.createTween( property, value )` helper, or push your own object containing a `run( percent )` function to `animation.tweens` array.

###`jQuery.Tween.propHooks[ property ]`
A `{ get: function( tween ) {}, set: function( tween ) {} }` hook point for individual properties with a `_default` that uses `jQuery.css` and `element.style`

## Current Issues

* The first `preFilter` defined here might have its `camelCase` / `cssHooks.expand` stuff put in before all prefilters to make that a "standard" you can count on even if you are "prepend"ing (not a real word @danheberden) to the preFilters

* The "special easing" code right now bugs me because it really should run before the hide/show preFilter, but since makes it basically impossible to accept an array as a possible animated property value, anyone wanting an array value will have to prepend to the preFilter - perhaps not such a bad thing...

* I have not yet tested this code for performance or potential memory leaks.