2 (function( $, window, undefined ) {
4 var createHandler = function( sequential ) {
6 // Default to sequential
7 if ( sequential === undefined ) {
11 return function( name, reverse, $to, $from ) {
13 var deferred = new $.Deferred(),
14 reverseClass = reverse ? " reverse" : "",
15 active = $.mobile.urlHistory.getActive(),
16 toScroll = active.lastScroll || $.mobile.defaultHomeScroll,
17 screenHeight = $.mobile.getScreenHeight(),
18 maxTransitionOverride = $.mobile.maxTransitionWidth !== false && $.mobile.$window.width() > $.mobile.maxTransitionWidth,
19 none = !$.support.cssTransitions || maxTransitionOverride || !name || name === "none" || Math.max( $.mobile.$window.scrollTop(), toScroll ) > $.mobile.getMaxScrollForTransition(),
20 toPreClass = " ui-page-pre-in",
21 toggleViewportClass = function() {
22 $.mobile.pageContainer.toggleClass( "ui-mobile-viewport-transitioning viewport-" + name );
24 scrollPage = function() {
25 // Prevent blinking on page scrolling in Tizen/Android devices.
26 // Don't scoll window, when current scroll top(scrollTop()) is already at toScroll,
27 // or when current scroll top is 0 and toScroll is same to defaultHomeScroll
28 // (which means the top position of page). In these case, page scrolling is not needed.
29 var st = $.mobile.$window.scrollTop();
30 if( st === toScroll || ( $.mobile.defaultHomeScroll === toScroll && st == 0 ) ) {
34 // By using scrollTo instead of silentScroll, we can keep things better in order
35 // Just to be precautios, disable scrollstart listening like silentScroll would
36 $.event.special.scrollstart.enabled = false;
38 window.scrollTo( 0, toScroll );
40 // reenable scrollstart listening like silentScroll would
41 setTimeout( function() {
42 $.event.special.scrollstart.enabled = true;
45 cleanFrom = function() {
47 .removeClass( $.mobile.activePageClass + " out in reverse " + name )
50 startOut = function() {
51 // if it's not sequential, call the doneOut transition to start the TO page animating in simultaneously
56 $from.animationComplete( doneOut );
59 // Set the from page's height and start it transitioning out
60 // Note: setting an explicit height helps eliminate tiling in the transitions
62 .height( screenHeight + $.mobile.$window.scrollTop() )
63 .addClass( name + " out" + reverseClass );
66 doneOut = function() {
68 if ( $from && sequential ) {
75 startIn = function() {
77 // Prevent flickering in phonegap container: see comments at #4024 regarding iOS
78 $to.css( "z-index", -10 );
80 $to.addClass( $.mobile.activePageClass + toPreClass );
82 // Send focus to page as it is now display: block
83 $.mobile.focusPage( $to );
86 $to.height( screenHeight + toScroll );
90 // Restores visibility of the new page: added together with $to.css( "z-index", -10 );
91 $to.css( "z-index", "" );
94 $to.animationComplete( doneIn );
98 .removeClass( toPreClass )
99 .addClass( name + " in" + reverseClass );
102 setTimeout( doneIn, 0 );
107 doneIn = function() {
117 .removeClass( "out in reverse " + name )
120 toggleViewportClass();
122 // In some browsers (iOS5), 3D transitions block the ability to scroll to the desired location during transition
123 // This ensures we jump to that spot after the fact, if we aren't there already.
124 if ( $.mobile.$window.scrollTop() !== toScroll ) {
128 deferred.resolve( name, reverse, $to, $from, true );
131 toggleViewportClass();
133 if ( $from && !none ) {
140 return deferred.promise();
144 // generate the handlers from the above
145 var sequentialHandler = createHandler(),
146 simultaneousHandler = createHandler( false ),
147 defaultGetMaxScrollForTransition = function() {
148 return $.mobile.getScreenHeight() * 3;
151 // Make our transition handler the public default.
152 $.mobile.defaultTransitionHandler = sequentialHandler;
154 //transition handler dictionary for 3rd party transitions
155 $.mobile.transitionHandlers = {
156 "default": $.mobile.defaultTransitionHandler,
157 "sequential": sequentialHandler,
158 "simultaneous": simultaneousHandler
161 $.mobile.transitionFallbacks = {};
163 // If transition is defined, check if css 3D transforms are supported, and if not, if a fallback is specified
164 $.mobile._maybeDegradeTransition = function( transition ) {
165 if ( transition && !$.support.cssTransform3d && $.mobile.transitionFallbacks[ transition ] ) {
166 transition = $.mobile.transitionFallbacks[ transition ];
172 // Set the getMaxScrollForTransition to default if no implementation was set by user
173 $.mobile.getMaxScrollForTransition = $.mobile.getMaxScrollForTransition || defaultGetMaxScrollForTransition;