3 Copyright 2012 Yahoo! Inc. All rights reserved.
4 Licensed under the BSD License.
5 http://yuilibrary.com/license/
7 YUI.add('app-transitions', function(Y) {
10 Provides view transitions for `Y.App` in browsers which support native CSS3
14 @submodule app-transitions
19 Provides view transitions for `Y.App` in browsers which support native CSS3
22 View transitions provide an nice way to move from one "page" to the next that is
23 both pleasant to the user and helps to communicate a hierarchy between sections
26 When this module is used, it will automatically mix itself in to `Y.App` and
27 transition between `activeView` changes using the following effects:
29 * **`fade`**: Cross-fades between the old an new active views.
31 * **`slideLeft`**: The old and new active views are positioned next to each
32 other and both slide to the left.
34 * **`slideRight`**: The old and new active views are positioned next to each
35 other and both slide to the right.
37 **Note:** Transitions are an opt-in feature and are enabled via an app's
38 `transitions` attribute.
40 @class App.Transitions
41 @uses App.TransitionsNative
44 function AppTransitions() {}
46 AppTransitions.ATTRS = {
48 Whether or not this application should use view transitions, and if so then
49 which ones or `true` for the defaults which are specified by the
50 `transitions` prototype property.
52 **Note:** Transitions are an opt-in feature and will only be used in
53 browsers which support native CSS3 transitions.
55 @attribute transitions
61 setter: '_setTransitions',
67 CSS classes used by `App.Transitions`.
69 When an app is transitioning between `activeView`s, its `container` node will
70 have the "yui3-app-transitioning" CSS class added.
77 AppTransitions.CLASS_NAMES = {
78 transitioning: Y.ClassNameManager.getClassName('app', 'transitioning')
82 Collect of transitions -> fx.
84 A transition (e.g. "fade") is a simple name given to a configuration of fx to
85 apply, consisting of `viewIn` and `viewOut` properties who's values are names of
86 fx registered on `Y.Transition.fx`.
88 By default transitions: `fade`, `slideLeft`, and `slideRight` have fx defined.
97 viewIn : 'app:fadeIn',
98 viewOut: 'app:fadeOut'
102 viewIn : 'app:slideLeft',
103 viewOut: 'app:slideLeft'
107 viewIn : 'app:slideRight',
108 viewOut: 'app:slideRight'
112 AppTransitions.prototype = {
113 // -- Public Properties ----------------------------------------------------
116 Default transitions to use when the `activeView` changes.
118 The following are types of changes for which transitions can be defined that
119 correspond to the relationship between the new and previous `activeView`:
121 * `navigate`: The default transition to use when changing the `activeView`
124 * `toChild`: The transition to use when the new `activeView` is configured
125 as a child of the previously active view via its `parent` property as
126 defined in this app's `views`.
128 * `toParent`: The transition to use when the new `activeView` is
129 configured as the `parent` of the previously active view as defined in
132 **Note:** Transitions are an opt-in feature and will only be used in
133 browsers which support native CSS3 transitions.
135 @property transitions
140 toChild : 'slideLeft',
141 toParent: 'slideRight'
147 toChild : 'slideLeft',
148 toParent: 'slideRight'
151 // -- Public Methods -------------------------------------------------------
154 Sets which view is active/visible for the application. This will set the
155 app's `activeView` attribute to the specified `view`.
157 When a string-name is provided for a view which has been registered on this
158 app's `views` object, the referenced metadata will be used and the
159 `activeView` will be set to either a preserved view instance, or a new
160 instance of the registered view will be created using the specified `config`
161 object passed-into this method.
163 A callback function can be specified as either the third or fourth argument,
164 and this function will be called after the new `view` becomes the
165 `activeView`, is rendered to the `viewContainer`, and is ready to use.
168 var app = new Y.App({
173 // Imagine that `Y.UsersView` has been defined.
179 app.route('/users/', function () {
180 this.showView('users');
184 app.navigate('/uses/');
185 // => Creates a new `Y.UsersView` and transitions to it.
188 @param {String|View} view The name of a view defined in the `views` object,
190 @param {Object} [config] Optional configuration to use when creating a new
192 @param {Object} [options] Optional object containing any of the following
194 @param {Function} [options.callback] Optional callback function to call
195 after new `activeView` is ready to use, the function will be passed:
196 @param {View} options.callback.view A reference to the new
198 @param {Boolean} [options.prepend] Whether the new view should be
199 prepended instead of appended to the `viewContainer`.
200 @param {Boolean|String} [options.transition] Optional transition override.
201 A transition can be specified which will override the default, or
202 `false` for no transition.
203 @param {Function} [callback] Optional callback Function to call after the
204 new `activeView` is ready to use. **Note:** this will override
205 `options.callback`. The function will be passed the following:
206 @param {View} callback.view A reference to the new `activeView`.
208 @see App.Base.showView()
210 // Does not override `showView()` but does use `options.transitions`.
212 // -- Protected Methods ----------------------------------------------------
215 Setter for `transitions` attribute.
217 When specified as `true`, the defaults will be use as specified by the
218 `transitions` prototype property.
220 @method _setTransitions
221 @param {Boolean|Object} transitions The new `transitions` attribute value.
222 @return {Mixed} The processed value which represents the new state.
226 _setTransitions: function (transitions) {
227 var defTransitions = this.transitions;
229 if (transitions && transitions === true) {
230 return Y.merge(defTransitions);
237 // -- Namespace ----------------------------------------------------------------
238 Y.App.Transitions = AppTransitions;
239 Y.Base.mix(Y.App, [AppTransitions]);
242 }, '3.5.0' ,{requires:['app-base']});