Skip to content
This repository was archived by the owner on Oct 8, 2021. It is now read-only.

Commit c358947

Browse files
author
Gabriel Schulhof
committed
Transition: Calculate "none" after establishing this.toScroll
Closes gh-7143 Fixes gh-7140
1 parent 5bbb46a commit c358947

File tree

2 files changed

+50
-3
lines changed

2 files changed

+50
-3
lines changed

js/transitions/transition.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,12 +144,19 @@ define( [ "jquery",
144144
// better transitions with fewer bugs. Ie, it's not guaranteed that the
145145
// object will be created and transition will be run immediately after as
146146
// it is today. So we wait until transition is invoked to gather the following
147-
var reverseClass = this.reverse ? " reverse" : "",
147+
var none,
148+
reverseClass = this.reverse ? " reverse" : "",
148149
screenHeight = $.mobile.getScreenHeight(),
149-
maxTransitionOverride = $.mobile.maxTransitionWidth !== false && $.mobile.window.width() > $.mobile.maxTransitionWidth,
150-
none = !$.support.cssTransitions || !$.support.cssAnimations || maxTransitionOverride || !this.name || this.name === "none" || Math.max( $.mobile.window.scrollTop(), this.toScroll ) > $.mobile.getMaxScrollForTransition();
150+
maxTransitionOverride = $.mobile.maxTransitionWidth !== false &&
151+
$.mobile.window.width() > $.mobile.maxTransitionWidth;
151152

152153
this.toScroll = $.mobile.navigate.history.getActive().lastScroll || $.mobile.defaultHomeScroll;
154+
155+
none = !$.support.cssTransitions || !$.support.cssAnimations ||
156+
maxTransitionOverride || !this.name || this.name === "none" ||
157+
Math.max( $.mobile.window.scrollTop(), this.toScroll ) >
158+
$.mobile.getMaxScrollForTransition();
159+
153160
this.toggleViewportClass();
154161

155162
if ( this.$from && !none ) {

tests/unit/transitions/transitions_core.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,4 +194,44 @@
194194

195195
instance.transition();
196196
});
197+
198+
test( "transition respects getMaxScrollForTransition", function() {
199+
var transition, valuePassedToNone,
200+
original = {
201+
maxScroll: $.mobile.getMaxScrollForTransition,
202+
startOut: $.mobile.Transition.prototype.startOut,
203+
doneOut: $.mobile.Transition.prototype.doneOut,
204+
defaultHomeScroll: $.mobile.defaultHomeScroll
205+
},
206+
startOutCalled = false,
207+
doneOutCalled = false;
208+
209+
$.mobile.getMaxScrollForTransition = function() {
210+
return -1;
211+
};
212+
213+
$.mobile.Transition.prototype.startOut = function( screenHeight, reverseClass, none ) {
214+
startOutCalled = true;
215+
return original.startOut.apply( this, arguments );
216+
};
217+
218+
$.mobile.Transition.prototype.doneOut = function( height, reverse, none, preventFocus ) {
219+
doneOutCalled = true;
220+
valuePassedToNone = none;
221+
return original.doneOut.apply( this, arguments );
222+
};
223+
224+
$.mobile.defaultHomeScroll = 0;
225+
226+
( new $.mobile.Transition( "slide", false, $([]), $([]) ) ).transition();
227+
228+
deepEqual( startOutCalled, false, "startOut was not called" );
229+
deepEqual( doneOutCalled, true, "doneOut was called" );
230+
deepEqual( valuePassedToNone, true, "The value passed to none was true" );
231+
232+
$.mobile.getMaxScrollForTransition = original.maxScroll;
233+
$.mobile.Transition.prototype.startOut = original.startOut;
234+
$.mobile.Transition.prototype.doneOut = original.doneOut;
235+
$.mobile.defaultHomeScroll = original.defaultHomeScroll;
236+
});
197237
})( jQuery );

0 commit comments

Comments
 (0)