transition-debug.js revision 142b1eb4e6b33c96ecf163bf42d31147b2e0e1d0
9c94a3bab3da130a453194d151f33f11cd53f44eMatt Sweeney* Provides the transition method for Node.
4527b08ced97d1bf5f88cf786302fd66eb80a35bMatt Sweeney* Transition has no API of its own, but adds the transition method to Node.
60dcf3ebba038d9ec57d617a7395a9bff15802fcMatt Sweeney* @module transition
b92e4372c5a34f48e457b60dfa9b136cf19c8498Matt Sweeney* @requires node
142b1eb4e6b33c96ecf163bf42d31147b2e0e1d0Matt Sweeney TRANSITION_PROPERTY_CAMEL = 'WebkitTransitionProperty',
959c053d56a076109993a2f14094d20b1f8c0c17Matt Sweeney TRANSITION_PROPERTY = '-webkit-transition-property',
959c053d56a076109993a2f14094d20b1f8c0c17Matt Sweeney TRANSITION_DURATION = '-webkit-transition-duration',
959c053d56a076109993a2f14094d20b1f8c0c17Matt Sweeney TRANSITION_TIMING_FUNCTION = '-webkit-transition-timing-function',
ef982fe144b380cd6cd8dd1bc6ba74c7210033f9Matt Sweeney * A class for constructing transition instances.
ef982fe144b380cd6cd8dd1bc6ba74c7210033f9Matt Sweeney * Adds the "transition" method to Node.
ef982fe144b380cd6cd8dd1bc6ba74c7210033f9Matt Sweeney * @class Transition
ef982fe144b380cd6cd8dd1bc6ba74c7210033f9Matt Sweeney * @constructor
f01d121976553130cab6089d35c71d5b947d1204Matt Sweeney property = property.replace(/-([a-z])/gi, function(m0, m1) {
bf3c648d6ab588c8b04fb824a7281898c469bd67Matt Sweeney property = property.replace(/([A-Z]?)([a-z]+)([A-Z]?)/g, function(m0, m1, m2, m3) {
959c053d56a076109993a2f14094d20b1f8c0c17Matt SweeneyTransition._reKeywords = /^(?:node|duration|iterations|easing|delay|on|onstart|onend)$/i;
959c053d56a076109993a2f14094d20b1f8c0c17Matt Sweeneyif (TRANSITION in Y.config.doc.documentElement.style) {
576e5aadaa60b824ce0a3875d3551ca3151a1957Matt Sweeney config.duration: anim.constructor.DEFAULT_DURATION;
959c053d56a076109993a2f14094d20b1f8c0c17Matt Sweeney anim._easing = config.easing || anim.constructor.DEFAULT_EASING;
959c053d56a076109993a2f14094d20b1f8c0c17Matt Sweeney anim._count = 0; // track number of animated properties
100cd7da99ccec416d3021e9a567addc2d9ed3dfMatt Sweeney // might just be a value
142b1eb4e6b33c96ecf163bf42d31147b2e0e1d0Matt Sweeney // take control if another transition owns this property
448834d88f7c2818b5a70125bba193051806ccf9Matt Sweeney attr.transition._count--; // remapping attr to this transition
0df23d09dc16bc41af5ceff68c11ed9c7d6285edMatt Sweeney // when size is auto or % webkit starts from zero instead of computed
5985d0db35cae8ef4c1a022bb03ac15792ff51adMatt Sweeney // (https://bugs.webkit.org/show_bug.cgi?id=16020)
0df23d09dc16bc41af5ceff68c11ed9c7d6285edMatt Sweeney // workaround by setting to current value
0df23d09dc16bc41af5ceff68c11ed9c7d6285edMatt Sweeney // TODO: move to run
100cd7da99ccec416d3021e9a567addc2d9ed3dfMatt Sweeney if (prop == 'height' || prop == 'width') {
0df23d09dc16bc41af5ceff68c11ed9c7d6285edMatt Sweeney // avoid setting if already set or transitioning
5985d0db35cae8ef4c1a022bb03ac15792ff51adMatt Sweeney // TODO: handle inline percent / auto
100cd7da99ccec416d3021e9a567addc2d9ed3dfMatt Sweeney if (!node._node.style[prop] && !node.getStyle(TRANSITION_PROPERTY_CAMEL) == 'prop') {
448834d88f7c2818b5a70125bba193051806ccf9Matt Sweeney node.setStyle(prop, node.getComputedStyle(prop));
5985d0db35cae8ef4c1a022bb03ac15792ff51adMatt Sweeney duration: ((typeof config.duration !== 'undefined') ? config.duration :
5985d0db35cae8ef4c1a022bb03ac15792ff51adMatt Sweeney anim._duration) || 0.0001, // make 0 async and fire events
0df23d09dc16bc41af5ceff68c11ed9c7d6285edMatt Sweeney delay: (typeof config.delay !== 'undefined') ? config.delay :
100cd7da99ccec416d3021e9a567addc2d9ed3dfMatt Sweeney attrs = Transition._nodeAttrs[Y.stamp(anim._node)];
100cd7da99ccec416d3021e9a567addc2d9ed3dfMatt Sweeney if (config.transform && !config[TRANSFORM_CAMEL]) {
100cd7da99ccec416d3021e9a567addc2d9ed3dfMatt Sweeney if (config.hasOwnProperty(attr) && !Transition._reKeywords.test(attr)) {
ac08645fa535c4f48d2fa888fee02423ff9afe17Matt Sweeney * Starts or an animation.
ac08645fa535c4f48d2fa888fee02423ff9afe17Matt Sweeney * @method run
ac08645fa535c4f48d2fa888fee02423ff9afe17Matt Sweeney * @chainable
73857faca3d4266c7840cd6ce428a71cf9a94d0cMatt Sweeney _start: function() {
959c053d56a076109993a2f14094d20b1f8c0c17Matt Sweeney // preserve existing transitions
448834d88f7c2818b5a70125bba193051806ccf9Matt Sweeney duration += computed[TRANSITION_DURATION] + ',';
448834d88f7c2818b5a70125bba193051806ccf9Matt Sweeney easing += computed[TRANSITION_TIMING_FUNCTION] + ',';
959c053d56a076109993a2f14094d20b1f8c0c17Matt Sweeney // run transitions mapped to this instance
959c053d56a076109993a2f14094d20b1f8c0c17Matt Sweeney if (attrs.hasOwnProperty(name) && attr.transition === anim) {
959c053d56a076109993a2f14094d20b1f8c0c17Matt Sweeney if (name in domNode.style) { // only native styles allowed
448834d88f7c2818b5a70125bba193051806ccf9Matt Sweeney duration += anim._prepDur(attr.duration) + ',';
100cd7da99ccec416d3021e9a567addc2d9ed3dfMatt Sweeney transitionText = transitionText.replace(/,$/, ';');
959c053d56a076109993a2f14094d20b1f8c0c17Matt Sweeney // only one native end event per node
959c053d56a076109993a2f14094d20b1f8c0c17Matt Sweeney anim._detach = node.on(TRANSITION_END, anim._onNativeEnd);
564c5c8d77e1fe074bfa96133bfdbbd0707c1ed3Matt Sweeney //setTimeout(function() { // allow updates to apply (size fix, onstart, etc)
564c5c8d77e1fe074bfa96133bfdbbd0707c1ed3Matt Sweeney style.cssText += transitionText + duration + easing + delay + cssText;
576e5aadaa60b824ce0a3875d3551ca3151a1957Matt Sweeney setTimeout(function() { // IE: allow previous update to finish
b92e4372c5a34f48e457b60dfa9b136cf19c8498Matt Sweeney // nested to ensure proper fire order
b92e4372c5a34f48e457b60dfa9b136cf19c8498Matt Sweeney } else if (callback) {
b92e4372c5a34f48e457b60dfa9b136cf19c8498Matt Sweeney setTimeout(function() { // IE: allow previous update to finish
b92e4372c5a34f48e457b60dfa9b136cf19c8498Matt Sweeney value = node.getComputedStyle(TRANSITION_PROPERTY);
b92e4372c5a34f48e457b60dfa9b136cf19c8498Matt Sweeney value = value.replace(new RegExp('(?:^|,\\s)' + name + ',?'), ',');
100cd7da99ccec416d3021e9a567addc2d9ed3dfMatt Sweeney _onNativeEnd: function(e) {
100cd7da99ccec416d3021e9a567addc2d9ed3dfMatt Sweeney name = Transition._toCamel(event.propertyName),
100cd7da99ccec416d3021e9a567addc2d9ed3dfMatt Sweeney if (anim._count <= 0) { // after propertEnd fires
0512667d3ebce1dd2bac2bd1de6367420402cfb3Matt Sweeney destroy: function() {
959c053d56a076109993a2f14094d20b1f8c0c17Matt SweeneyY.TransitionNative = Transition; // TODO: remove
959c053d56a076109993a2f14094d20b1f8c0c17Matt Sweeney * Animate one or more css properties to a given value. Requires the "transition" module.
959c053d56a076109993a2f14094d20b1f8c0c17Matt Sweeney * <pre>example usage:
6ae23e4adfd7a02fb24e8240a363e0decf126c95Matt Sweeney * Y.one('#demo').transition({
564c5c8d77e1fe074bfa96133bfdbbd0707c1ed3Matt Sweeney * duration: 1, // in seconds, default is 0.5
6ae23e4adfd7a02fb24e8240a363e0decf126c95Matt Sweeney * easing: 'ease-out', // default is 'ease'
6ae23e4adfd7a02fb24e8240a363e0decf126c95Matt Sweeney * delay: '1', // delay start for 1 second, default is 0
564c5c8d77e1fe074bfa96133bfdbbd0707c1ed3Matt Sweeney * height: '10px',
564c5c8d77e1fe074bfa96133bfdbbd0707c1ed3Matt Sweeney * width: '10px',
6ae23e4adfd7a02fb24e8240a363e0decf126c95Matt Sweeney * opacity: { // per property
959c053d56a076109993a2f14094d20b1f8c0c17Matt Sweeney * duration: 2,
959c053d56a076109993a2f14094d20b1f8c0c17Matt Sweeney * easing: 'ease-in'
54329bf323458a34db1104ad4b4b0b1eaa1f12feMatt Sweeney * @method transition
54329bf323458a34db1104ad4b4b0b1eaa1f12feMatt Sweeney * @param {Object} config An object containing one or more style properties, a duration and an easing.
54329bf323458a34db1104ad4b4b0b1eaa1f12feMatt Sweeney * @param {Function} callback A function to run after the transition has completed.
54329bf323458a34db1104ad4b4b0b1eaa1f12feMatt Sweeney * @chainable
ef982fe144b380cd6cd8dd1bc6ba74c7210033f9Matt SweeneyY.Node.prototype.transition = function(name, config, callback) {
54329bf323458a34db1104ad4b4b0b1eaa1f12feMatt Sweeney transitionAttrs = Transition._nodeAttrs[Y.stamp(this)],
ef982fe144b380cd6cd8dd1bc6ba74c7210033f9Matt Sweeney anim = (transitionAttrs) ? transitionAttrs.transition : null,
54329bf323458a34db1104ad4b4b0b1eaa1f12feMatt Sweeney if (typeof name === 'string') { // named effect, pull config from registry
c56d37350cde9ba6fcde1a42433b3d759fe2b2ecMatt Sweeney } else { // name is a config, config is a callback or undefined
c56d37350cde9ba6fcde1a42433b3d759fe2b2ecMatt Sweeney return this;
c56d37350cde9ba6fcde1a42433b3d759fe2b2ecMatt SweeneyY.Node.prototype.show = function(name, config, callback) {
c56d37350cde9ba6fcde1a42433b3d759fe2b2ecMatt Sweeney if (typeof name !== 'string' && !name.push) { // named effect or array of effects supercedes default
959c053d56a076109993a2f14094d20b1f8c0c17Matt Sweeney else if (name && !Y.Transition) { Y.log('unable to transition show; missing transition module', 'warn', 'node'); }
959c053d56a076109993a2f14094d20b1f8c0c17Matt Sweeney return this;
959c053d56a076109993a2f14094d20b1f8c0c17Matt Sweeney return function() {
73857faca3d4266c7840cd6ce428a71cf9a94d0cMatt SweeneyY.Node.prototype.hide = function(name, config, callback) {
73857faca3d4266c7840cd6ce428a71cf9a94d0cMatt Sweeney if (callback) { // need to hide when transition ends
73857faca3d4266c7840cd6ce428a71cf9a94d0cMatt Sweeney callback = _wrapCallBack(callback, this._hide); // wrap with existing callback
b92e4372c5a34f48e457b60dfa9b136cf19c8498Matt Sweeney if (typeof name !== 'string' && !name.push) { // named effect or array of effects supercedes default
73857faca3d4266c7840cd6ce428a71cf9a94d0cMatt Sweeney } else if (name && !Y.Transition) { Y.log('unable to transition hide; missing transition module', 'warn', 'node'); // end if on nex
73857faca3d4266c7840cd6ce428a71cf9a94d0cMatt Sweeney return this;
73857faca3d4266c7840cd6ce428a71cf9a94d0cMatt Sweeney * Animate one or more css properties to a given value. Requires the "transition" module.
73857faca3d4266c7840cd6ce428a71cf9a94d0cMatt Sweeney * <pre>example usage:
73857faca3d4266c7840cd6ce428a71cf9a94d0cMatt Sweeney * Y.all('.demo').transition({
73857faca3d4266c7840cd6ce428a71cf9a94d0cMatt Sweeney * duration: 1, // in seconds, default is 0.5
73857faca3d4266c7840cd6ce428a71cf9a94d0cMatt Sweeney * easing: 'ease-out', // default is 'ease'
73857faca3d4266c7840cd6ce428a71cf9a94d0cMatt Sweeney * delay: '1', // delay start for 1 second, default is 0
73857faca3d4266c7840cd6ce428a71cf9a94d0cMatt Sweeney * height: '10px',
73857faca3d4266c7840cd6ce428a71cf9a94d0cMatt Sweeney * width: '10px',
73857faca3d4266c7840cd6ce428a71cf9a94d0cMatt Sweeney * opacity: { // per property
73857faca3d4266c7840cd6ce428a71cf9a94d0cMatt Sweeney * duration: 2,
73857faca3d4266c7840cd6ce428a71cf9a94d0cMatt Sweeney * easing: 'ease-in'
54329bf323458a34db1104ad4b4b0b1eaa1f12feMatt Sweeney * @for NodeList
54329bf323458a34db1104ad4b4b0b1eaa1f12feMatt Sweeney * @method transition
54329bf323458a34db1104ad4b4b0b1eaa1f12feMatt Sweeney * @param {Object} config An object containing one or more style properties, a duration and an easing.
ef982fe144b380cd6cd8dd1bc6ba74c7210033f9Matt Sweeney * @param {Function} callback A function to run after the transition has completed. The callback fires
ef982fe144b380cd6cd8dd1bc6ba74c7210033f9Matt Sweeney * once per item in the NodeList.
54329bf323458a34db1104ad4b4b0b1eaa1f12feMatt Sweeney * @chainable
ef982fe144b380cd6cd8dd1bc6ba74c7210033f9Matt SweeneyY.NodeList.prototype.transition = function(config, callback) {
54329bf323458a34db1104ad4b4b0b1eaa1f12feMatt Sweeney return this;
0512667d3ebce1dd2bac2bd1de6367420402cfb3Matt Sweeney start: function() {
0512667d3ebce1dd2bac2bd1de6367420402cfb3Matt Sweeney if (overflow !== 'hidden') { // enable scrollHeight/Width
0512667d3ebce1dd2bac2bd1de6367420402cfb3Matt Sweeney end: function() {
0512667d3ebce1dd2bac2bd1de6367420402cfb3Matt Sweeney if (this._transitionOverflow) { // revert overridden value
0512667d3ebce1dd2bac2bd1de6367420402cfb3Matt Sweeney this.setStyle('overflow', this._transitionOverflow);
0512667d3ebce1dd2bac2bd1de6367420402cfb3Matt Sweeney* The Transition Utility provides an API for creating advanced transitions.
0512667d3ebce1dd2bac2bd1de6367420402cfb3Matt Sweeney* @module transition
c56d37350cde9ba6fcde1a42433b3d759fe2b2ecMatt Sweeney* Provides the base Transition class, for animating numeric properties.
c56d37350cde9ba6fcde1a42433b3d759fe2b2ecMatt Sweeney* @module transition
c56d37350cde9ba6fcde1a42433b3d759fe2b2ecMatt Sweeney* @submodule transition-timer
484ded111840f4104ab556e0628b0e84632eba34Matt Sweeney _start: function() {
484ded111840f4104ab556e0628b0e84632eba34Matt Sweeney var t = new Date() - this._startTime;