transition-debug.js revision ef982fe144b380cd6cd8dd1bc6ba74c7210033f9
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
ef982fe144b380cd6cd8dd1bc6ba74c7210033f9Matt Sweeney* @requires node
100cd7da99ccec416d3021e9a567addc2d9ed3dfMatt Sweeney TRANSITION_PROPERTY_CAMEL = 'WebkitTransition',
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)$/;
959c053d56a076109993a2f14094d20b1f8c0c17Matt Sweeneyif (TRANSITION in Y.config.doc.documentElement.style) {
576e5aadaa60b824ce0a3875d3551ca3151a1957Matt Sweeney config.duration: anim.constructor.DEFAULT_DURATION;
576e5aadaa60b824ce0a3875d3551ca3151a1957Matt Sweeney anim._easing = config.easing || anim.constructor.DEFAULT_EASING;
576e5aadaa60b824ce0a3875d3551ca3151a1957Matt Sweeney anim._count = 0; // track number of animated properties
100cd7da99ccec416d3021e9a567addc2d9ed3dfMatt Sweeney // might just be a value
100cd7da99ccec416d3021e9a567addc2d9ed3dfMatt Sweeney // take control if another transition owns this property
100cd7da99ccec416d3021e9a567addc2d9ed3dfMatt Sweeney if (attr && attr.transition && attr.transition !== anim) {
100cd7da99ccec416d3021e9a567addc2d9ed3dfMatt Sweeney attr.transition._count--; // remapping attr to this transition
100cd7da99ccec416d3021e9a567addc2d9ed3dfMatt Sweeney duration: ((typeof config.duration !== 'undefined') ? config.duration :
100cd7da99ccec416d3021e9a567addc2d9ed3dfMatt Sweeney anim._duration) || 0.0001, // make 0 async and fire events
100cd7da99ccec416d3021e9a567addc2d9ed3dfMatt 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)) {
959c053d56a076109993a2f14094d20b1f8c0c17Matt Sweeney * Starts or an animation.
959c053d56a076109993a2f14094d20b1f8c0c17Matt Sweeney * @method run
959c053d56a076109993a2f14094d20b1f8c0c17Matt Sweeney * @chainable
959c053d56a076109993a2f14094d20b1f8c0c17Matt Sweeney _start: function() {
448834d88f7c2818b5a70125bba193051806ccf9Matt Sweeney // preserve existing transitions
959c053d56a076109993a2f14094d20b1f8c0c17Matt Sweeney duration += computed[TRANSITION_DURATION] + ',';
959c053d56a076109993a2f14094d20b1f8c0c17Matt Sweeney easing += computed[TRANSITION_TIMING_FUNCTION] + ',';
448834d88f7c2818b5a70125bba193051806ccf9Matt Sweeney // run transitions mapped to this instance
448834d88f7c2818b5a70125bba193051806ccf9Matt Sweeney if (attrs.hasOwnProperty(name) && attr.transition === anim) {
f01d121976553130cab6089d35c71d5b947d1204Matt Sweeney if (name in domNode.style) { // only native styles allowed
f01d121976553130cab6089d35c71d5b947d1204Matt Sweeney duration += anim._prepDur(attr.duration) + ',';
959c053d56a076109993a2f14094d20b1f8c0c17Matt Sweeney transitionText = transitionText.replace(/,$/, ';');
448834d88f7c2818b5a70125bba193051806ccf9Matt Sweeney // only one native end event per node
6ae23e4adfd7a02fb24e8240a363e0decf126c95Matt Sweeney anim._detach = node.on(TRANSITION_END, anim._onNativeEnd);
448834d88f7c2818b5a70125bba193051806ccf9Matt Sweeney style.cssText += transitionText + duration + easing + delay + cssText;
576e5aadaa60b824ce0a3875d3551ca3151a1957Matt Sweeney setTimeout(function() { // IE: allow previous update to finish
100cd7da99ccec416d3021e9a567addc2d9ed3dfMatt Sweeney value = node.getComputedStyle(TRANSITION_PROPERTY);
100cd7da99ccec416d3021e9a567addc2d9ed3dfMatt Sweeney value = value.replace(new RegExp('(?:^|,\\s)' + name + ',?'), ',');
100cd7da99ccec416d3021e9a567addc2d9ed3dfMatt Sweeney node.setStyle(TRANSITION_PROPERTY_CAMEL, value);
959c053d56a076109993a2f14094d20b1f8c0c17Matt Sweeney _onNativeEnd: function(e) {
f01d121976553130cab6089d35c71d5b947d1204Matt Sweeney name = Transition._toCamel(event.propertyName),
100cd7da99ccec416d3021e9a567addc2d9ed3dfMatt Sweeney if (anim._count <= 0) { // after propertEnd fires
959c053d56a076109993a2f14094d20b1f8c0c17Matt Sweeney destroy: function() {
959c053d56a076109993a2f14094d20b1f8c0c17Matt SweeneyY.TransitionNative = Transition; // TODO: remove
54329bf323458a34db1104ad4b4b0b1eaa1f12feMatt Sweeney * Animate one or more css properties to a given value. Requires the "transition" module.
54329bf323458a34db1104ad4b4b0b1eaa1f12feMatt Sweeney * <pre>example usage:
54329bf323458a34db1104ad4b4b0b1eaa1f12feMatt Sweeney * Y.one('#demo').transition({
54329bf323458a34db1104ad4b4b0b1eaa1f12feMatt Sweeney * duration: 1, // in seconds, default is 0.5
54329bf323458a34db1104ad4b4b0b1eaa1f12feMatt Sweeney * easing: 'ease-out', // default is 'ease'
ef982fe144b380cd6cd8dd1bc6ba74c7210033f9Matt Sweeney * delay: '1', // delay start for 1 second, default is 0
54329bf323458a34db1104ad4b4b0b1eaa1f12feMatt Sweeney * height: '10px',
54329bf323458a34db1104ad4b4b0b1eaa1f12feMatt Sweeney * width: '10px',
54329bf323458a34db1104ad4b4b0b1eaa1f12feMatt Sweeney * opacity: { // per property
54329bf323458a34db1104ad4b4b0b1eaa1f12feMatt Sweeney * duration: 2,
54329bf323458a34db1104ad4b4b0b1eaa1f12feMatt 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
959c053d56a076109993a2f14094d20b1f8c0c17Matt SweeneyY.Node.prototype.transition = function(config, callback) {
959c053d56a076109993a2f14094d20b1f8c0c17Matt Sweeney return this;
54329bf323458a34db1104ad4b4b0b1eaa1f12feMatt Sweeney * Animate one or more css properties to a given value. Requires the "transition" module.
54329bf323458a34db1104ad4b4b0b1eaa1f12feMatt Sweeney * <pre>example usage:
54329bf323458a34db1104ad4b4b0b1eaa1f12feMatt Sweeney * Y.all('.demo').transition({
54329bf323458a34db1104ad4b4b0b1eaa1f12feMatt Sweeney * duration: 1, // in seconds, default is 0.5
54329bf323458a34db1104ad4b4b0b1eaa1f12feMatt Sweeney * easing: 'ease-out', // default is 'ease'
ef982fe144b380cd6cd8dd1bc6ba74c7210033f9Matt Sweeney * delay: '1', // delay start for 1 second, default is 0
54329bf323458a34db1104ad4b4b0b1eaa1f12feMatt Sweeney * height: '10px',
54329bf323458a34db1104ad4b4b0b1eaa1f12feMatt Sweeney * width: '10px',
54329bf323458a34db1104ad4b4b0b1eaa1f12feMatt Sweeney * opacity: { // per property
54329bf323458a34db1104ad4b4b0b1eaa1f12feMatt Sweeney * duration: 2,
54329bf323458a34db1104ad4b4b0b1eaa1f12feMatt 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.
54329bf323458a34db1104ad4b4b0b1eaa1f12feMatt Sweeney * @param {Function} callback A function to run after the transition has completed. The callback fires
54329bf323458a34db1104ad4b4b0b1eaa1f12feMatt Sweeney * once per item in the NodeList.
54329bf323458a34db1104ad4b4b0b1eaa1f12feMatt Sweeney * @chainable