|
19 | 19 | isTransitioningIn = function(page){
|
20 | 20 | return page.hasClass("in") && isTransitioning(page);
|
21 | 21 | },
|
22 |
| - |
| 22 | + |
23 | 23 | disableMaxTransWidth = function(){
|
24 | 24 | $.mobile.maxTransitionWidth = false;
|
25 | 25 | },
|
26 |
| - |
| 26 | + |
27 | 27 | enableMaxTransWidth = function(){
|
28 | 28 | $.mobile.maxTransitionWidth = defaultMaxTrans;
|
29 | 29 | },
|
|
36 | 36 | fromQueue = [];
|
37 | 37 | toQueue = [];
|
38 | 38 | },
|
39 |
| - |
| 39 | + |
40 | 40 | onFromComplete = function( f ){
|
41 | 41 | fromQueue.push( f );
|
42 | 42 | },
|
43 |
| - |
| 43 | + |
44 | 44 | onToComplete = function( f ){
|
45 | 45 | toQueue.push( f );
|
46 | 46 | },
|
47 |
| - |
| 47 | + |
48 | 48 |
|
49 | 49 | //wipe all urls
|
50 | 50 | clearUrlHistory = function(){
|
|
55 | 55 |
|
56 | 56 | module('jquery.mobile.navigation.js', {
|
57 | 57 | setup: function(){
|
| 58 | + |
| 59 | + |
58 | 60 | // disable this option so we can test transitions regardless of window width
|
59 | 61 | disableMaxTransWidth();
|
60 |
| - |
| 62 | + |
61 | 63 | //stub to allow callback before function is returned to transition handler
|
62 | 64 | $.fn.animationComplete = function( callback ){
|
63 | 65 | animationCompleteFn.call( this, function(){
|
|
72 | 74 |
|
73 | 75 | resetQueues();
|
74 | 76 | clearUrlHistory();
|
| 77 | + |
| 78 | + if ( location.hash !== "#harmless-default-page" ) { |
| 79 | + stop(); |
| 80 | + |
| 81 | + $(document).one("pagechange", function() { |
| 82 | + start(); |
| 83 | + } ); |
| 84 | + |
| 85 | + location.hash = "#harmless-default-page"; |
| 86 | + } |
| 87 | + |
75 | 88 | },
|
76 | 89 |
|
77 | 90 | teardown: function(){
|
|
80 | 93 | enableMaxTransWidth();
|
81 | 94 | }
|
82 | 95 | });
|
83 |
| - |
84 |
| - /* |
85 |
| - NOTES: |
86 |
| - Our default transition handler now has either one or two animationComplete calls - two if there are two pages in play (from and to) |
| 96 | + |
| 97 | + /* |
| 98 | + NOTES: |
| 99 | + Our default transition handler now has either one or two animationComplete calls - two if there are two pages in play (from and to) |
87 | 100 | To is required, so each async function must call start() onToComplete, not onFromComplete.
|
88 | 101 | */
|
89 |
| - |
| 102 | + |
90 | 103 |
|
91 | 104 | asyncTest( "changePage applies perspective class to mobile viewport for flip", function(){
|
92 | 105 | expect(1);
|
93 |
| - |
| 106 | + |
94 | 107 | onToComplete( function( el ){
|
95 | 108 | ok($("body").hasClass(perspective), "has perspective class");
|
96 | 109 | start();
|
97 | 110 | } );
|
98 |
| - |
99 |
| - $("#foo > a").click(); |
100 | 111 |
|
| 112 | + $("#foo > a").click(); |
101 | 113 | });
|
102 |
| - |
| 114 | + |
103 | 115 | asyncTest( "changePage does not apply perspective class to mobile viewport for transitions other than flip", function(){
|
104 | 116 | expect(1);
|
105 |
| - |
| 117 | + |
106 | 118 | onToComplete( function( el ){
|
107 | 119 | ok(!$("body").hasClass(perspective), "doesn't have perspective class");
|
108 | 120 | start();
|
109 | 121 | } );
|
110 |
| - |
| 122 | + |
111 | 123 | $("#bar > a").click();
|
112 | 124 | });
|
113 |
| - |
| 125 | + |
114 | 126 | asyncTest( "changePage applies transition class to mobile viewport for default transition", function(){
|
115 | 127 | expect(1);
|
116 |
| - |
| 128 | + |
117 | 129 | onToComplete( function( el ){
|
118 | 130 | ok($("body").hasClass(transitioning), "has transitioning class");
|
119 | 131 | start();
|
120 | 132 | } );
|
121 |
| - |
| 133 | + |
122 | 134 | $("#baz > a").click();
|
123 | 135 |
|
124 | 136 | });
|
125 |
| - |
| 137 | + |
126 | 138 | asyncTest( "explicit transition preferred for page navigation reversal (ie back)", function(){
|
127 | 139 | expect( 1 );
|
128 |
| - |
| 140 | + |
129 | 141 | onToComplete(function(){
|
130 | 142 | $("#flip-trans > a").click();
|
131 | 143 | onToComplete(function(){
|
|
136 | 148 | });
|
137 | 149 | });
|
138 | 150 | });
|
139 |
| - |
| 151 | + |
140 | 152 | $("#fade-trans > a").click();
|
141 | 153 | });
|
142 | 154 |
|
|
145 | 157 | ok($("#no-trans").hasClass("fade"), "has fade class");
|
146 | 158 | start();
|
147 | 159 | })
|
148 |
| - |
| 160 | + |
149 | 161 | $("#default-trans > a").click();
|
150 | 162 | });
|
151 | 163 |
|
|
164 | 176 | ok(!isTransitioningIn(firstPage), "first page transition should be complete");
|
165 | 177 | ok(isTransitioningIn(secondPage), "second page should begin transitioning");
|
166 | 178 | start();
|
167 |
| - |
| 179 | + |
168 | 180 | });
|
169 | 181 | });
|
170 | 182 | });
|
|
175 | 187 | ok($("#no-trans-dialog").hasClass("pop"), "has pop class" );
|
176 | 188 | start();
|
177 | 189 | });
|
178 |
| - |
| 190 | + |
179 | 191 | $("#default-trans-dialog > a").click();
|
180 | 192 | });
|
181 | 193 |
|
182 | 194 | test( "animationComplete return value", function(){
|
183 | 195 | $.fn.animationComplete = animationCompleteFn;
|
184 | 196 | equals($("#foo").animationComplete(function(){})[0], $("#foo")[0]);
|
185 | 197 | });
|
186 |
| - |
187 |
| - |
| 198 | + |
| 199 | + |
188 | 200 | // reusable function for a few tests below
|
189 | 201 | function testTransitionMaxWidth( val, expected ){
|
190 | 202 | expect( 1 );
|
191 |
| - |
| 203 | + |
192 | 204 | $.mobile.maxTransitionWidth = val;
|
193 |
| - |
| 205 | + |
194 | 206 | var transitionOccurred = false;
|
195 |
| - |
| 207 | + |
196 | 208 | onToComplete(function(){
|
197 | 209 | transitionOccurred = true;
|
198 | 210 | });
|
199 |
| - |
200 |
| - |
| 211 | + |
| 212 | + |
201 | 213 | return setTimeout(function(){
|
202 | 214 | ok( transitionOccurred === expected, (expected ? "" : "no ") + "transition occurred" );
|
203 | 215 | start();
|
204 | 216 | }, 5000);
|
205 |
| - |
| 217 | + |
206 | 218 | $.mobile.changePage( $(".ui-page:not(.ui-page-active)").first() );
|
207 |
| - |
| 219 | + |
208 | 220 | }
|
209 |
| - |
| 221 | + |
210 | 222 | asyncTest( "maxTransitionWidth property disables transitions when value is less than browser width", function(){
|
211 | 223 | testTransitionMaxWidth( $( window ).width() - 1, false );
|
212 | 224 | });
|
213 |
| - |
| 225 | + |
214 | 226 | asyncTest( "maxTransitionWidth property disables transitions when value is false", function(){
|
215 | 227 | testTransitionMaxWidth( false, false );
|
216 | 228 | });
|
217 |
| - |
218 |
| - |
219 |
| - |
220 |
| - |
221 | 229 | })(jQuery);
|
0 commit comments