App.Transitions Class
Y.App
extension that provides view transitions in browsers which support
native CSS3 transitions.
View transitions provide an nice way to move from one "page" to the next that is both pleasant to the user and helps to communicate a hierarchy between sections of an application.
When the "app-transitions"
module is used, it will automatically mix itself
into Y.App
and transition between activeView
changes using the following
effects:
-
fade
: Cross-fades between the old an new active views. -
slideLeft
: The old and new active views are positioned next to each other and both slide to the left. -
slideRight
: The old and new active views are positioned next to each other and both slide to the right.
Note: Transitions are an opt-in feature and are enabled via an app's
transitions
attribute.
Methods
showView
-
view
-
[config]
-
[options]
-
[callback]
Sets which view is active/visible for the application. This will set the
app's activeView
attribute to the specified view
.
The view
will be "attached" to this app, meaning it will be both rendered
into this app's viewContainer
node and all of its events will bubble to
the app. The previous activeView
will be "detached" from this app.
When a string-name is provided for a view which has been registered on this
app's views
object, the referenced metadata will be used and the
activeView
will be set to either a preserved view instance, or a new
instance of the registered view will be created using the specified config
object passed-into this method.
A callback function can be specified as either the third or fourth argument,
and this function will be called after the new view
becomes the
activeView
, is rendered to the viewContainer
, and is ready to use.
Parameters:
-
view
String | ViewThe name of a view defined in the
views
object, or a view instance which should become this app'sactiveView
. -
[config]
Object optionalOptional configuration to use when creating a new view instance. This config object can also be used to update an existing or preserved view's attributes when
options.update
istrue
. -
[options]
Object optionalOptional object containing any of the following properties:
-
[callback]
Function optionalOptional callback function to call after new
activeView
is ready to use, the function will be passed:-
view
ViewA reference to the newactiveView
.
-
-
[prepend=false]
Boolean optionalWhether the
view
should be prepended instead of appended to theviewContainer
. -
[render]
Boolean optionalWhether the
view
should be rendered. Note: If no value is specified, a view instance will only be rendered if it's newly created by this method. -
[transition]
Boolean | String optionalOptional transition override. A transition can be specified which will override the default, or
false
for no transition. -
[update=false]
Boolean optionalWhether an existing view should have its attributes updated by passing the
config
object to itssetAttrs()
method. Note: This option does not have an effect if theview
instance is created as a result of calling this method.
-
-
[callback]
Function optionalOptional callback Function to call after the new
activeView
is ready to use. Note: this will overrideoptions.callback
and it can be specified as either the third or fourth argument. The function will be passed the following:-
view
ViewA reference to the new
activeView
.
-
Example:
var app = new Y.App({
views: {
usersView: {
// Imagine that Y.UsersView
has been defined.
type: Y.UsersView
}
},
transitions: true,
users : new Y.ModelList()
});
app.route('/users/', function () {
this.showView('usersView', {users: this.get('users')});
});
app.render();
app.navigate('/uses/');
// => Creates a new Y.UsersView
and transitions to it.
Properties
FX
Object
static
Collect of transitions -> fx.
A transition (e.g. "fade") is a simple name given to a configuration of fx to
apply, consisting of viewIn
and viewOut
properties who's values are names of
fx registered on Y.Transition.fx
.
By default transitions: fade
, slideLeft
, and slideRight
have fx defined.
transitions
Object
Default transitions to use when the activeView
changes.
The following are types of changes for which transitions can be defined that
correspond to the relationship between the new and previous activeView
:
-
navigate
: The default transition to use when changing theactiveView
of the application. -
toChild
: The transition to use when the newactiveView
is configured as a child of the previously active view via itsparent
property as defined in this app'sviews
. -
toParent
: The transition to use when the newactiveView
is configured as theparent
of the previously active view as defined in this app'sviews
.
Note: Transitions are an opt-in feature and will only be used in browsers which support native CSS3 transitions.
Default: { navigate: 'fade', toChild : 'slideLeft', toParent: 'slideRight' }
Attributes
transitions
Boolean | Object
Whether or not this application should use view transitions, and if so then
which ones or true
for the defaults which are specified by the
transitions
prototype property.
Note: Transitions are an opt-in feature and will only be used in browsers which support native CSS3 transitions.
Default: false
Fires event transitionsChange
Fires when the value for the configuration attribute transitions
is
changed. You can listen for the event using the on
method if you
wish to be notified before the attribute's value has changed, or
using the after
method if you wish to be notified after the
attribute's value has changed.
Parameters:
-
e
EventFacadeAn Event Facade object with the following attribute-specific properties added: