transition-native.js revision 7f03c81c9c42b32e09a911682e00adb57f0985b9
0b062f4990db5cc6db2fe3398926f71b92a67407Brian WellingtonYUI.add('transition-native', function(Y) {
dd1ce8b52478fa98c844720af9e77fae2978f18dTinderbox User
75c0816e8295e180f4bc7f10db3d0d880383bc1cMark Andrews/**
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein* Provides the transition method for Node.
4a14ce5ba00ab7bc55c99ffdcf59c7a4ab902721Automatic Updater* Transition has no API of its own, but adds the transition method to Node.
0b062f4990db5cc6db2fe3398926f71b92a67407Brian Wellington*
0b062f4990db5cc6db2fe3398926f71b92a67407Brian Wellington* @module transition
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein* @requires node-style
9016767f4e15191b7c763b8a4ad36a57dc2705a2Mark Andrews*/
9016767f4e15191b7c763b8a4ad36a57dc2705a2Mark Andrews
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austeinvar TRANSITION = '-webkit-transition',
9016767f4e15191b7c763b8a4ad36a57dc2705a2Mark Andrews TRANSITION_CAMEL = 'WebkitTransition',
9016767f4e15191b7c763b8a4ad36a57dc2705a2Mark Andrews TRANSITION_PROPERTY_CAMEL = 'WebkitTransitionProperty',
9016767f4e15191b7c763b8a4ad36a57dc2705a2Mark Andrews TRANSITION_PROPERTY = '-webkit-transition-property',
9016767f4e15191b7c763b8a4ad36a57dc2705a2Mark Andrews TRANSITION_DURATION = '-webkit-transition-duration',
0b062f4990db5cc6db2fe3398926f71b92a67407Brian Wellington TRANSITION_TIMING_FUNCTION = '-webkit-transition-timing-function',
ea94d370123a5892f6c47a97f21d1b28d44bb168Tinderbox User TRANSITION_DELAY = '-webkit-transition-delay',
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein TRANSITION_END = 'webkitTransitionEnd',
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein ON_TRANSITION_END = 'onwebkittransitionend',
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein TRANSFORM_CAMEL = 'WebkitTransform',
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein
ca67ebfe9eef0b8f04179f7e511a19e0337a5422Automatic Updater EMPTY_OBJ = {},
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein/**
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews * A class for constructing transition instances.
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein * Adds the "transition" method to Node.
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein * @class Transition
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein * @constructor
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein */
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob AusteinTransition = function() {
6f1205897504b8f50b1785975482c995888dd630Tinderbox User this.init.apply(this, arguments);
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein};
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein
5fa6a064b8301e4f274bd132fd577def59e4fb4cTinderbox UserTransition.fx = {};
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob AusteinTransition.toggles = {};
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein
d71e2e0c61df16ff37c9934c371a4a60c08974f7Mark AndrewsTransition._hasEnd = {};
0a7ed88633a680bb881868b75ded4d09a7bbbc50Automatic Updater
0a7ed88633a680bb881868b75ded4d09a7bbbc50Automatic UpdaterTransition._toCamel = function(property) {
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein property = property.replace(/-([a-z])/gi, function(m0, m1) {
ad671240d635376dd8681550eebee799d2e3d1fdAutomatic Updater return m1.toUpperCase();
ad671240d635376dd8681550eebee799d2e3d1fdAutomatic Updater });
ad671240d635376dd8681550eebee799d2e3d1fdAutomatic Updater
ad671240d635376dd8681550eebee799d2e3d1fdAutomatic Updater return property;
ad671240d635376dd8681550eebee799d2e3d1fdAutomatic Updater};
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob AusteinTransition._toHyphen = function(property) {
5fa6a064b8301e4f274bd132fd577def59e4fb4cTinderbox User property = property.replace(/([A-Z]?)([a-z]+)([A-Z]?)/g, function(m0, m1, m2, m3) {
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein var str = '';
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein if (m1) {
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein str += '-' + m1.toLowerCase();
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein }
0a7ed88633a680bb881868b75ded4d09a7bbbc50Automatic Updater str += m2;
0a7ed88633a680bb881868b75ded4d09a7bbbc50Automatic Updater
aaaf8d4f4873d21e55c3ffb4f656203d08339865Mark Andrews if (m3) {
aaaf8d4f4873d21e55c3ffb4f656203d08339865Mark Andrews str += '-' + m3.toLowerCase();
8e821eea5f57ac47a94305aa7ab0c3570d92a311Automatic Updater }
0a7ed88633a680bb881868b75ded4d09a7bbbc50Automatic Updater
0a7ed88633a680bb881868b75ded4d09a7bbbc50Automatic Updater return str;
0a7ed88633a680bb881868b75ded4d09a7bbbc50Automatic Updater });
0a7ed88633a680bb881868b75ded4d09a7bbbc50Automatic Updater
0a7ed88633a680bb881868b75ded4d09a7bbbc50Automatic Updater return property;
0a7ed88633a680bb881868b75ded4d09a7bbbc50Automatic Updater};
0a7ed88633a680bb881868b75ded4d09a7bbbc50Automatic Updater
8e821eea5f57ac47a94305aa7ab0c3570d92a311Automatic Updater
8e821eea5f57ac47a94305aa7ab0c3570d92a311Automatic UpdaterTransition._reKeywords = /^(?:node|duration|iterations|easing|delay|on|onstart|onend)$/i;
8e821eea5f57ac47a94305aa7ab0c3570d92a311Automatic Updater
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob AusteinTransition.useNative = false;
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austeinif (TRANSITION in Y.config.doc.documentElement.style) {
731cc132f22dbc9e0ecd7035dce314a61076d31bAutomatic Updater Transition.useNative = true;
731cc132f22dbc9e0ecd7035dce314a61076d31bAutomatic Updater Transition.supported = true; // TODO: remove
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein}
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein
0a7ed88633a680bb881868b75ded4d09a7bbbc50Automatic UpdaterY.Node.DOM_EVENTS[TRANSITION_END] = 1;
0a7ed88633a680bb881868b75ded4d09a7bbbc50Automatic Updater
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob AusteinTransition.NAME = 'transition';
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob AusteinTransition.DEFAULT_EASING = 'ease';
b272d38cc5d24f64c0647a9afb340c21c4b9aaf7Evan HuntTransition.DEFAULT_DURATION = 0.5;
b272d38cc5d24f64c0647a9afb340c21c4b9aaf7Evan HuntTransition.DEFAULT_DELAY = 0;
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein
8e821eea5f57ac47a94305aa7ab0c3570d92a311Automatic UpdaterTransition._nodeAttrs = {};
b272d38cc5d24f64c0647a9afb340c21c4b9aaf7Evan Hunt
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob AusteinTransition.prototype = {
8e821eea5f57ac47a94305aa7ab0c3570d92a311Automatic Updater constructor: Transition,
aaaf8d4f4873d21e55c3ffb4f656203d08339865Mark Andrews init: function(node, config) {
aaaf8d4f4873d21e55c3ffb4f656203d08339865Mark Andrews var anim = this;
b272d38cc5d24f64c0647a9afb340c21c4b9aaf7Evan Hunt anim._node = node;
0a7ed88633a680bb881868b75ded4d09a7bbbc50Automatic Updater if (!anim._running && config) {
0a7ed88633a680bb881868b75ded4d09a7bbbc50Automatic Updater anim._config = config;
0a7ed88633a680bb881868b75ded4d09a7bbbc50Automatic Updater node._transition = anim; // cache for reuse
6478b87fd23bcd3ab74c25b261021fe19a239c4fTinderbox User
0a7ed88633a680bb881868b75ded4d09a7bbbc50Automatic Updater anim._duration = ('duration' in config) ?
0a7ed88633a680bb881868b75ded4d09a7bbbc50Automatic Updater config.duration: anim.constructor.DEFAULT_DURATION;
0a7ed88633a680bb881868b75ded4d09a7bbbc50Automatic Updater
0a7ed88633a680bb881868b75ded4d09a7bbbc50Automatic Updater anim._delay = ('delay' in config) ?
b272d38cc5d24f64c0647a9afb340c21c4b9aaf7Evan Hunt config.delay: anim.constructor.DEFAULT_DELAY;
b272d38cc5d24f64c0647a9afb340c21c4b9aaf7Evan Hunt
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein anim._easing = config.easing || anim.constructor.DEFAULT_EASING;
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein anim._count = 0; // track number of animated properties
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein anim._running = false;
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein }
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein return anim;
2f8d63983c297c62630044d28a6f66676b4d339dMark Andrews },
2f8d63983c297c62630044d28a6f66676b4d339dMark Andrews
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein addProperty: function(prop, config) {
0a7ed88633a680bb881868b75ded4d09a7bbbc50Automatic Updater var anim = this,
0a7ed88633a680bb881868b75ded4d09a7bbbc50Automatic Updater node = this._node,
0a7ed88633a680bb881868b75ded4d09a7bbbc50Automatic Updater uid = Y.stamp(node),
0a7ed88633a680bb881868b75ded4d09a7bbbc50Automatic Updater nodeInstance = Y.one(node),
0a7ed88633a680bb881868b75ded4d09a7bbbc50Automatic Updater attrs = Transition._nodeAttrs[uid],
aaaf8d4f4873d21e55c3ffb4f656203d08339865Mark Andrews computed,
aaaf8d4f4873d21e55c3ffb4f656203d08339865Mark Andrews compareVal,
8e821eea5f57ac47a94305aa7ab0c3570d92a311Automatic Updater dur,
0a7ed88633a680bb881868b75ded4d09a7bbbc50Automatic Updater attr,
0a7ed88633a680bb881868b75ded4d09a7bbbc50Automatic Updater val;
0a7ed88633a680bb881868b75ded4d09a7bbbc50Automatic Updater
0a7ed88633a680bb881868b75ded4d09a7bbbc50Automatic Updater if (!attrs) {
0a7ed88633a680bb881868b75ded4d09a7bbbc50Automatic Updater attrs = Transition._nodeAttrs[uid] = {};
0a7ed88633a680bb881868b75ded4d09a7bbbc50Automatic Updater }
0a7ed88633a680bb881868b75ded4d09a7bbbc50Automatic Updater
0a7ed88633a680bb881868b75ded4d09a7bbbc50Automatic Updater attr = attrs[prop];
0a7ed88633a680bb881868b75ded4d09a7bbbc50Automatic Updater
0a7ed88633a680bb881868b75ded4d09a7bbbc50Automatic Updater // might just be a value
0a7ed88633a680bb881868b75ded4d09a7bbbc50Automatic Updater if (config && config.value !== undefined) {
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein val = config.value;
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein } else if (config !== undefined) {
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein val = config;
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein config = EMPTY_OBJ;
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein }
8ec3c085233cedb22b05da36e2773c8f357a7e45Automatic Updater
6ea2385360e9e2167e65f9286447da9eea189457Tinderbox User if (typeof val === 'function') {
6ea2385360e9e2167e65f9286447da9eea189457Tinderbox User val = val.call(nodeInstance, nodeInstance);
6ea2385360e9e2167e65f9286447da9eea189457Tinderbox User }
6ea2385360e9e2167e65f9286447da9eea189457Tinderbox User
6ea2385360e9e2167e65f9286447da9eea189457Tinderbox User if (attr && attr.transition) {
6ea2385360e9e2167e65f9286447da9eea189457Tinderbox User // take control if another transition owns this property
6ea2385360e9e2167e65f9286447da9eea189457Tinderbox User if (attr.transition !== anim) {
6ea2385360e9e2167e65f9286447da9eea189457Tinderbox User attr.transition._count--; // remapping attr to this transition
6ea2385360e9e2167e65f9286447da9eea189457Tinderbox User }
6ea2385360e9e2167e65f9286447da9eea189457Tinderbox User }
6ea2385360e9e2167e65f9286447da9eea189457Tinderbox User
6ea2385360e9e2167e65f9286447da9eea189457Tinderbox User anim._count++; // properties per transition
6ea2385360e9e2167e65f9286447da9eea189457Tinderbox User
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein // make 0 async and fire events
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein dur = ((typeof config.duration != 'undefined') ? config.duration :
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein anim._duration) || 0.0001;
0a7ed88633a680bb881868b75ded4d09a7bbbc50Automatic Updater
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein attrs[prop] = {
f8e3e03cacd16ffb923a9603fca23a9e1a1fee07Automatic Updater value: val,
f8e3e03cacd16ffb923a9603fca23a9e1a1fee07Automatic Updater duration: dur,
f8e3e03cacd16ffb923a9603fca23a9e1a1fee07Automatic Updater delay: (typeof config.delay != 'undefined') ? config.delay :
f8e3e03cacd16ffb923a9603fca23a9e1a1fee07Automatic Updater anim._delay,
f8e3e03cacd16ffb923a9603fca23a9e1a1fee07Automatic Updater
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein easing: config.easing || anim._easing,
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein transition: anim
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein };
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein // native end event doesnt fire when setting to same value
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein // supplementing with timer
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein // val may be a string or number (height: 0, etc), but computedStyle is always string
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein computed = Y.DOM.getComputedStyle(node, prop);
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein compareVal = (typeof val === 'string') ? computed : parseFloat(computed);
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein if (Transition.useNative && compareVal === val) {
0a7ed88633a680bb881868b75ded4d09a7bbbc50Automatic Updater setTimeout(function() {
0a7ed88633a680bb881868b75ded4d09a7bbbc50Automatic Updater anim._onNativeEnd.call(node, {
0a7ed88633a680bb881868b75ded4d09a7bbbc50Automatic Updater propertyName: prop,
0a7ed88633a680bb881868b75ded4d09a7bbbc50Automatic Updater elapsedTime: dur
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein });
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein }, dur * 1000);
0a7ed88633a680bb881868b75ded4d09a7bbbc50Automatic Updater }
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein },
a3f8c8e20780e488141d200acdfea6c5f3303513Automatic Updater
a3f8c8e20780e488141d200acdfea6c5f3303513Automatic Updater removeProperty: function(prop) {
a3f8c8e20780e488141d200acdfea6c5f3303513Automatic Updater var anim = this,
a3f8c8e20780e488141d200acdfea6c5f3303513Automatic Updater attrs = Transition._nodeAttrs[Y.stamp(anim._node)];
a3f8c8e20780e488141d200acdfea6c5f3303513Automatic Updater
a3f8c8e20780e488141d200acdfea6c5f3303513Automatic Updater if (attrs && attrs[prop]) {
a3f8c8e20780e488141d200acdfea6c5f3303513Automatic Updater delete attrs[prop];
a3f8c8e20780e488141d200acdfea6c5f3303513Automatic Updater anim._count--;
a3f8c8e20780e488141d200acdfea6c5f3303513Automatic Updater }
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein },
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein initAttrs: function(config) {
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein var attr,
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein node = this._node;
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein
575e15fed997a3ad1cb35c5b9ef34ab24ce47e72Automatic Updater if (config.transform && !config[TRANSFORM_CAMEL]) {
575e15fed997a3ad1cb35c5b9ef34ab24ce47e72Automatic Updater config[TRANSFORM_CAMEL] = config.transform;
575e15fed997a3ad1cb35c5b9ef34ab24ce47e72Automatic Updater delete config.transform; // TODO: copy
575e15fed997a3ad1cb35c5b9ef34ab24ce47e72Automatic Updater }
575e15fed997a3ad1cb35c5b9ef34ab24ce47e72Automatic Updater
575e15fed997a3ad1cb35c5b9ef34ab24ce47e72Automatic Updater for (attr in config) {
575e15fed997a3ad1cb35c5b9ef34ab24ce47e72Automatic Updater if (config.hasOwnProperty(attr) && !Transition._reKeywords.test(attr)) {
575e15fed997a3ad1cb35c5b9ef34ab24ce47e72Automatic Updater this.addProperty(attr, config[attr]);
575e15fed997a3ad1cb35c5b9ef34ab24ce47e72Automatic Updater
575e15fed997a3ad1cb35c5b9ef34ab24ce47e72Automatic Updater // when size is auto or % webkit starts from zero instead of computed
575e15fed997a3ad1cb35c5b9ef34ab24ce47e72Automatic Updater // (https://bugs.webkit.org/show_bug.cgi?id=16020)
575e15fed997a3ad1cb35c5b9ef34ab24ce47e72Automatic Updater // TODO: selective set
575e15fed997a3ad1cb35c5b9ef34ab24ce47e72Automatic Updater if (node.style[attr] === '') {
575e15fed997a3ad1cb35c5b9ef34ab24ce47e72Automatic Updater Y.DOM.setStyle(node, attr, Y.DOM.getComputedStyle(node, attr));
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein }
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein }
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein }
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein },
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein /**
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein * Starts or an animation.
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein * @method run
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein * @chainable
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein * @private
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein */
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein run: function(callback) {
3acf5eb97cebc2ba868e6ac4a4e01e6d1be0c892Automatic Updater var anim = this,
3acf5eb97cebc2ba868e6ac4a4e01e6d1be0c892Automatic Updater node = anim._node,
3acf5eb97cebc2ba868e6ac4a4e01e6d1be0c892Automatic Updater config = anim._config,
3acf5eb97cebc2ba868e6ac4a4e01e6d1be0c892Automatic Updater data = {
3acf5eb97cebc2ba868e6ac4a4e01e6d1be0c892Automatic Updater type: 'transition:start',
3acf5eb97cebc2ba868e6ac4a4e01e6d1be0c892Automatic Updater config: config
3acf5eb97cebc2ba868e6ac4a4e01e6d1be0c892Automatic Updater };
3acf5eb97cebc2ba868e6ac4a4e01e6d1be0c892Automatic Updater
3acf5eb97cebc2ba868e6ac4a4e01e6d1be0c892Automatic Updater
3acf5eb97cebc2ba868e6ac4a4e01e6d1be0c892Automatic Updater if (!anim._running) {
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein anim._running = true;
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein //anim._node.fire('transition:start', data);
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein if (config.on && config.on.start) {
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein config.on.start.call(Y.one(node), data);
0a7ed88633a680bb881868b75ded4d09a7bbbc50Automatic Updater }
0a7ed88633a680bb881868b75ded4d09a7bbbc50Automatic Updater
0a7ed88633a680bb881868b75ded4d09a7bbbc50Automatic Updater anim.initAttrs(anim._config);
0a7ed88633a680bb881868b75ded4d09a7bbbc50Automatic Updater
0a7ed88633a680bb881868b75ded4d09a7bbbc50Automatic Updater anim._callback = callback;
0a7ed88633a680bb881868b75ded4d09a7bbbc50Automatic Updater anim._start();
0a7ed88633a680bb881868b75ded4d09a7bbbc50Automatic Updater }
0a7ed88633a680bb881868b75ded4d09a7bbbc50Automatic Updater
0a7ed88633a680bb881868b75ded4d09a7bbbc50Automatic Updater
0a7ed88633a680bb881868b75ded4d09a7bbbc50Automatic Updater return anim;
0a7ed88633a680bb881868b75ded4d09a7bbbc50Automatic Updater },
0a7ed88633a680bb881868b75ded4d09a7bbbc50Automatic Updater
0a7ed88633a680bb881868b75ded4d09a7bbbc50Automatic Updater _start: function() {
0a7ed88633a680bb881868b75ded4d09a7bbbc50Automatic Updater this._runNative();
0a7ed88633a680bb881868b75ded4d09a7bbbc50Automatic Updater },
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein _prepDur: function(dur) {
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein dur = parseFloat(dur);
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein return dur + 's';
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein },
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein _runNative: function(time) {
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein var anim = this,
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein node = anim._node,
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein uid = Y.stamp(node),
6f1205897504b8f50b1785975482c995888dd630Tinderbox User style = node.style,
6f1205897504b8f50b1785975482c995888dd630Tinderbox User computed = getComputedStyle(node),
6f1205897504b8f50b1785975482c995888dd630Tinderbox User attrs = Transition._nodeAttrs[uid],
6f1205897504b8f50b1785975482c995888dd630Tinderbox User cssText = '',
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein cssTransition = computed[TRANSITION_PROPERTY],
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein transitionText = TRANSITION_PROPERTY + ': ',
5fa6a064b8301e4f274bd132fd577def59e4fb4cTinderbox User duration = TRANSITION_DURATION + ': ',
0a7ed88633a680bb881868b75ded4d09a7bbbc50Automatic Updater easing = TRANSITION_TIMING_FUNCTION + ': ',
0a7ed88633a680bb881868b75ded4d09a7bbbc50Automatic Updater delay = TRANSITION_DELAY + ': ',
0a7ed88633a680bb881868b75ded4d09a7bbbc50Automatic Updater hyphy,
2895f101b5585a19015ac2c2c1e1812ac467fa12Automatic Updater attr,
2895f101b5585a19015ac2c2c1e1812ac467fa12Automatic Updater name;
2895f101b5585a19015ac2c2c1e1812ac467fa12Automatic Updater
2895f101b5585a19015ac2c2c1e1812ac467fa12Automatic Updater // preserve existing transitions
2895f101b5585a19015ac2c2c1e1812ac467fa12Automatic Updater if (cssTransition !== 'all') {
bbbf2e27d3a981163dab139497d6b2dc85449db0Tinderbox User transitionText += cssTransition + ',';
bbbf2e27d3a981163dab139497d6b2dc85449db0Tinderbox User duration += computed[TRANSITION_DURATION] + ',';
0a7ed88633a680bb881868b75ded4d09a7bbbc50Automatic Updater easing += computed[TRANSITION_TIMING_FUNCTION] + ',';
0a7ed88633a680bb881868b75ded4d09a7bbbc50Automatic Updater delay += computed[TRANSITION_DELAY] + ',';
0a7ed88633a680bb881868b75ded4d09a7bbbc50Automatic Updater
0a7ed88633a680bb881868b75ded4d09a7bbbc50Automatic Updater }
0a7ed88633a680bb881868b75ded4d09a7bbbc50Automatic Updater
0a7ed88633a680bb881868b75ded4d09a7bbbc50Automatic Updater // run transitions mapped to this instance
f8e3e03cacd16ffb923a9603fca23a9e1a1fee07Automatic Updater for (name in attrs) {
f8e3e03cacd16ffb923a9603fca23a9e1a1fee07Automatic Updater hyphy = Transition._toHyphen(name);
0a7ed88633a680bb881868b75ded4d09a7bbbc50Automatic Updater attr = attrs[name];
0a7ed88633a680bb881868b75ded4d09a7bbbc50Automatic Updater if (attrs.hasOwnProperty(name) && attr.transition === anim) {
0a7ed88633a680bb881868b75ded4d09a7bbbc50Automatic Updater if (name in node.style) { // only native styles allowed
0a7ed88633a680bb881868b75ded4d09a7bbbc50Automatic Updater duration += anim._prepDur(attr.duration) + ',';
5a24d24c8fba3480d707c0c902379ddb36501e12Automatic Updater delay += anim._prepDur(attr.delay) + ',';
f8e3e03cacd16ffb923a9603fca23a9e1a1fee07Automatic Updater easing += (attr.easing) + ',';
bbbf2e27d3a981163dab139497d6b2dc85449db0Tinderbox User
bbbf2e27d3a981163dab139497d6b2dc85449db0Tinderbox User transitionText += hyphy + ',';
bbbf2e27d3a981163dab139497d6b2dc85449db0Tinderbox User cssText += hyphy + ': ' + attr.value + '; ';
0a7ed88633a680bb881868b75ded4d09a7bbbc50Automatic Updater } else {
0a7ed88633a680bb881868b75ded4d09a7bbbc50Automatic Updater this.removeProperty(name);
0a7ed88633a680bb881868b75ded4d09a7bbbc50Automatic Updater }
0a7ed88633a680bb881868b75ded4d09a7bbbc50Automatic Updater }
0a7ed88633a680bb881868b75ded4d09a7bbbc50Automatic Updater }
0a7ed88633a680bb881868b75ded4d09a7bbbc50Automatic Updater
0a7ed88633a680bb881868b75ded4d09a7bbbc50Automatic Updater transitionText = transitionText.replace(/,$/, ';');
f8e3e03cacd16ffb923a9603fca23a9e1a1fee07Automatic Updater duration = duration.replace(/,$/, ';');
0a7ed88633a680bb881868b75ded4d09a7bbbc50Automatic Updater easing = easing.replace(/,$/, ';');
f8e3e03cacd16ffb923a9603fca23a9e1a1fee07Automatic Updater delay = delay.replace(/,$/, ';');
f8e3e03cacd16ffb923a9603fca23a9e1a1fee07Automatic Updater
f8e3e03cacd16ffb923a9603fca23a9e1a1fee07Automatic Updater // only one native end event per node
0a7ed88633a680bb881868b75ded4d09a7bbbc50Automatic Updater if (!Transition._hasEnd[uid]) {
0a7ed88633a680bb881868b75ded4d09a7bbbc50Automatic Updater //anim._detach = Y.on(TRANSITION_END, anim._onNativeEnd, node);
0a7ed88633a680bb881868b75ded4d09a7bbbc50Automatic Updater //node[ON_TRANSITION_END] = anim._onNativeEnd;
0a7ed88633a680bb881868b75ded4d09a7bbbc50Automatic Updater node.addEventListener(TRANSITION_END, anim._onNativeEnd, false);
f8e3e03cacd16ffb923a9603fca23a9e1a1fee07Automatic Updater Transition._hasEnd[uid] = true;
f8e3e03cacd16ffb923a9603fca23a9e1a1fee07Automatic Updater
0a7ed88633a680bb881868b75ded4d09a7bbbc50Automatic Updater }
3acf5eb97cebc2ba868e6ac4a4e01e6d1be0c892Automatic Updater
3acf5eb97cebc2ba868e6ac4a4e01e6d1be0c892Automatic Updater //setTimeout(function() { // allow updates to apply (size fix, onstart, etc)
3acf5eb97cebc2ba868e6ac4a4e01e6d1be0c892Automatic Updater style.cssText += transitionText + duration + easing + delay + cssText;
3acf5eb97cebc2ba868e6ac4a4e01e6d1be0c892Automatic Updater //}, 1);
3acf5eb97cebc2ba868e6ac4a4e01e6d1be0c892Automatic Updater
3acf5eb97cebc2ba868e6ac4a4e01e6d1be0c892Automatic Updater },
3acf5eb97cebc2ba868e6ac4a4e01e6d1be0c892Automatic Updater
3acf5eb97cebc2ba868e6ac4a4e01e6d1be0c892Automatic Updater _end: function(elapsed) {
3acf5eb97cebc2ba868e6ac4a4e01e6d1be0c892Automatic Updater var anim = this,
3acf5eb97cebc2ba868e6ac4a4e01e6d1be0c892Automatic Updater node = anim._node,
3acf5eb97cebc2ba868e6ac4a4e01e6d1be0c892Automatic Updater callback = anim._callback,
3acf5eb97cebc2ba868e6ac4a4e01e6d1be0c892Automatic Updater config = anim._config,
3acf5eb97cebc2ba868e6ac4a4e01e6d1be0c892Automatic Updater data = {
3acf5eb97cebc2ba868e6ac4a4e01e6d1be0c892Automatic Updater type: 'transition:end',
3acf5eb97cebc2ba868e6ac4a4e01e6d1be0c892Automatic Updater config: config,
3acf5eb97cebc2ba868e6ac4a4e01e6d1be0c892Automatic Updater elapsedTime: elapsed
3acf5eb97cebc2ba868e6ac4a4e01e6d1be0c892Automatic Updater },
3acf5eb97cebc2ba868e6ac4a4e01e6d1be0c892Automatic Updater
3acf5eb97cebc2ba868e6ac4a4e01e6d1be0c892Automatic Updater nodeInstance = Y.one(node);
3acf5eb97cebc2ba868e6ac4a4e01e6d1be0c892Automatic Updater
3acf5eb97cebc2ba868e6ac4a4e01e6d1be0c892Automatic Updater anim._running = false;
3acf5eb97cebc2ba868e6ac4a4e01e6d1be0c892Automatic Updater anim._callback = null;
3acf5eb97cebc2ba868e6ac4a4e01e6d1be0c892Automatic Updater
3acf5eb97cebc2ba868e6ac4a4e01e6d1be0c892Automatic Updater if (node) {
0a7ed88633a680bb881868b75ded4d09a7bbbc50Automatic Updater if (config.on && config.on.end) {
0a7ed88633a680bb881868b75ded4d09a7bbbc50Automatic Updater setTimeout(function() { // IE: allow previous update to finish
0a7ed88633a680bb881868b75ded4d09a7bbbc50Automatic Updater config.on.end.call(nodeInstance, data);
5fa6a064b8301e4f274bd132fd577def59e4fb4cTinderbox User
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein // nested to ensure proper fire order
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein if (callback) {
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein callback.call(nodeInstance, data);
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein }
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein
90153b6536f7a5078e1c157c980110dbcd7fe205Mark Andrews }, 1);
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein } else if (callback) {
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein setTimeout(function() { // IE: allow previous update to finish
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein callback.call(nodeInstance, data);
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein }, 1);
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein }
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein //node.fire('transition:end', data);
8ffa8320abcc17ae593af566cb946a58fe293860Brian Wellington }
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein },
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein _endNative: function(name) {
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein var node = this._node,
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein value = node.ownerDocument.defaultView.getComputedStyle(node, '')[TRANSITION_PROPERTY];
d71e2e0c61df16ff37c9934c371a4a60c08974f7Mark Andrews
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein if (typeof value === 'string') {
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein value = value.replace(new RegExp('(?:^|,\\s)' + name + ',?'), ',');
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein value = value.replace(/^,|,$/, '');
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein node.style[TRANSITION_CAMEL] = value;
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein }
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein },
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein _onNativeEnd: function(e) {
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein var node = this,
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein uid = Y.stamp(node),
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein event = e,//e._event,
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein name = Transition._toCamel(event.propertyName),
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein elapsed = event.elapsedTime,
d71e2e0c61df16ff37c9934c371a4a60c08974f7Mark Andrews attrs = Transition._nodeAttrs[uid],
d71e2e0c61df16ff37c9934c371a4a60c08974f7Mark Andrews attr = attrs[name],
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein anim = (attr) ? attr.transition : null,
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein data,
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein config;
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein if (anim) {
d71e2e0c61df16ff37c9934c371a4a60c08974f7Mark Andrews anim.removeProperty(name);
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein anim._endNative(name);
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein config = anim._config[name];
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein data = {
5fa6a064b8301e4f274bd132fd577def59e4fb4cTinderbox User type: 'propertyEnd',
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein propertyName: name,
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein elapsedTime: elapsed,
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein config: config
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein };
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein if (config && config.on && config.on.end) {
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein config.on.end.call(Y.one(node), data);
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein }
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein //node.fire('transition:propertyEnd', data);
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein if (anim._count <= 0) { // after propertyEnd fires
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein anim._end(elapsed);
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein }
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein }
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein },
d71e2e0c61df16ff37c9934c371a4a60c08974f7Mark Andrews
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein destroy: function() {
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein var anim = this;
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein /*
5fa6a064b8301e4f274bd132fd577def59e4fb4cTinderbox User if (anim._detach) {
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein anim._detach.detach();
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein }
c6c78f699b55b3344fb6b17ddc854cbae4610468Automatic Updater */
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein //anim._node[ON_TRANSITION_END] = null;
8e821eea5f57ac47a94305aa7ab0c3570d92a311Automatic Updater node.removeEventListener(TRANSITION_END, anim._onNativeEnd, false);
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein anim._node = null;
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein }
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein};
5fa6a064b8301e4f274bd132fd577def59e4fb4cTinderbox User
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob AusteinY.Transition = Transition;
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob AusteinY.TransitionNative = Transition; // TODO: remove
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein/**
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein * Animate one or more css properties to a given value. Requires the "transition" module.
* <pre>example usage:
* Y.one('#demo').transition({
* duration: 1, // in seconds, default is 0.5
* easing: 'ease-out', // default is 'ease'
* delay: '1', // delay start for 1 second, default is 0
*
* height: '10px',
* width: '10px',
*
* opacity: { // per property
* value: 0,
* duration: 2,
* delay: 2,
* easing: 'ease-in'
* }
* });
* </pre>
* @for Node
* @method transition
* @param {Object} config An object containing one or more style properties, a duration and an easing.
* @param {Function} callback A function to run after the transition has completed.
* @chainable
*/
Y.Node.prototype.transition = function(name, config, callback) {
var
transitionAttrs = Transition._nodeAttrs[Y.stamp(this._node)],
anim = (transitionAttrs) ? transitionAttrs.transition || null : null,
fxConfig,
prop;
if (typeof name === 'string') { // named effect, pull config from registry
if (typeof config === 'function') {
callback = config;
config = null;
}
fxConfig = Transition.fx[name];
if (config && typeof config !== 'boolean') {
config = Y.clone(config);
for (prop in fxConfig) {
if (fxConfig.hasOwnProperty(prop)) {
if (! (prop in config)) {
config[prop] = fxConfig[prop];
}
}
}
} else {
config = fxConfig;
}
} else { // name is a config, config is a callback or undefined
callback = config;
config = name;
}
if (anim && !anim._running) {
anim.init(this, config);
} else {
anim = new Transition(this._node, config);
}
anim.run(callback);
return this;
};
Y.Node.prototype.show = function(name, config, callback) {
this._show(); // show prior to transition
if (name && Y.Transition) {
if (typeof name !== 'string' && !name.push) { // named effect or array of effects supercedes default
if (typeof config === 'function') {
callback = config;
config = name;
}
name = this.SHOW_TRANSITION;
}
this.transition(name, config, callback);
}
return this;
};
var _wrapCallBack = function(anim, fn, callback) {
return function() {
if (fn) {
fn.call(anim);
}
if (callback) {
callback.apply(anim._node, arguments);
}
};
};
Y.Node.prototype.hide = function(name, config, callback) {
if (name && Y.Transition) {
if (typeof config === 'function') {
callback = config;
config = null;
}
callback = _wrapCallBack(this, this._hide, callback); // wrap with existing callback
if (typeof name !== 'string' && !name.push) { // named effect or array of effects supercedes default
if (typeof config === 'function') {
callback = config;
config = name;
}
name = this.HIDE_TRANSITION;
}
this.transition(name, config, callback);
} else {
this._hide();
}
return this;
};
/**
* Animate one or more css properties to a given value. Requires the "transition" module.
* <pre>example usage:
* Y.all('.demo').transition({
* duration: 1, // in seconds, default is 0.5
* easing: 'ease-out', // default is 'ease'
* delay: '1', // delay start for 1 second, default is 0
*
* height: '10px',
* width: '10px',
*
* opacity: { // per property
* value: 0,
* duration: 2,
* delay: 2,
* easing: 'ease-in'
* }
* });
* </pre>
* @for NodeList
* @method transition
* @param {Object} config An object containing one or more style properties, a duration and an easing.
* @param {Function} callback A function to run after the transition has completed. The callback fires
* once per item in the NodeList.
* @chainable
*/
Y.NodeList.prototype.transition = function(config, callback) {
var nodes = this._nodes,
i = 0,
node;
while ((node = nodes[i++])) {
Y.one(node).transition(config, callback);
}
return this;
};
Y.Node.prototype.toggleView = function(name, on, callback) {
this._toggles = this._toggles || [];
callback = arguments[arguments.length - 1];
if (typeof name == 'boolean') { // no transition, just toggle
on = name;
name = null;
}
name = name || Y.Transition.DEFAULT_TOGGLE;
if (typeof on == 'undefined' && name in this._toggles) { // reverse current toggle
on = ! this._toggles[name];
}
on = (on) ? 1 : 0;
if (on) {
this._show();
} else {
callback = _wrapCallBack(this, this._hide, callback);
}
this._toggles[name] = on;
this.transition(Y.Transition.toggles[name][on], callback);
return this;
};
Y.NodeList.prototype.toggleView = function(name, on, callback) {
var nodes = this._nodes,
i = 0,
node;
while ((node = nodes[i++])) {
Y.one(node).toggleView(name, on, callback);
}
return this;
};
Y.mix(Transition.fx, {
fadeOut: {
opacity: 0,
duration: 0.5,
easing: 'ease-out'
},
fadeIn: {
opacity: 1,
duration: 0.5,
easing: 'ease-in'
},
sizeOut: {
height: 0,
width: 0,
duration: 0.75,
easing: 'ease-out'
},
sizeIn: {
height: function(node) {
return node.get('scrollHeight') + 'px';
},
width: function(node) {
return node.get('scrollWidth') + 'px';
},
duration: 0.5,
easing: 'ease-in',
on: {
start: function() {
var overflow = this.getStyle('overflow');
if (overflow !== 'hidden') { // enable scrollHeight/Width
this.setStyle('overflow', 'hidden');
this._transitionOverflow = overflow;
}
},
end: function() {
if (this._transitionOverflow) { // revert overridden value
this.setStyle('overflow', this._transitionOverflow);
}
}
}
}
});
Y.mix(Transition.toggles, {
size: ['sizeOut', 'sizeIn'],
fade: ['fadeOut', 'fadeIn']
});
Transition.DEFAULT_TOGGLE = 'fade';
}, '@VERSION@' ,{requires:['node-base']});