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

Commit dc530ea

Browse files
committed
page sequence helper added, nav tests in a somewhat better state. the event trigger spot, namespace, and general setup are all up for debate
1 parent 2cfacc4 commit dc530ea

File tree

5 files changed

+59
-26
lines changed

5 files changed

+59
-26
lines changed

js/jquery.mobile.navigation.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -191,14 +191,14 @@
191191

192192
//existing base tag?
193193
$base = $head.children( "base" ),
194-
195-
//get domain path
194+
195+
//get domain path
196196
//(note: use explicit protocol here, protocol-relative urls won't work as expected on localhost)
197197
docBase = location.protocol + "//" + location.host,
198-
198+
199199
//initialPath for first page load without hash. pathname (href - search)
200200
initialPath = docBase + location.pathname;
201-
201+
202202
//already a base element?
203203
if ( $base.length ) {
204204
var href = $base.attr( "href" );
@@ -212,7 +212,7 @@
212212
docBase = href;
213213
}
214214
}
215-
215+
216216
//make sure docBase ends with a slash
217217
docBase = docBase + ( docBase.charAt( docBase.length - 1 ) === "/" ? " " : "/" );
218218
}
@@ -307,14 +307,14 @@
307307
//jump to top or prev scroll, sometimes on iOS the page has not rendered yet.
308308
$.mobile.silentScroll( toPage.jqmData( "lastScroll" ) || 0 );
309309
$( document ).one( "silentscroll", function() { reFocus( toPage ); } );
310-
310+
311311
//trigger show/hide events
312312
if( fromPage ) {
313313
fromPage.data( "page" )._trigger( "hide", null, { nextPage: toPage } );
314314
}
315315
//trigger pageshow, define prevPage as either fromPage or empty jQuery obj
316316
toPage.data( "page" )._trigger( "show", null, { prevPage: fromPage || $( "" ) } );
317-
317+
318318
});
319319

320320
return promise;
@@ -538,7 +538,7 @@
538538
// Remove loading message.
539539
if ( settings.showLoadMsg ) {
540540
$.mobile.hidePageLoadingMsg();
541-
541+
542542
//show error message
543543
$( "<div class='ui-loader ui-overlay-shadow ui-body-e ui-corner-all'><h1>"+ $.mobile.pageLoadErrorMessage +"</h1></div>" )
544544
.css({ "display": "block", "opacity": 0.96, "top": $window.scrollTop() + 100 })
@@ -697,17 +697,17 @@
697697

698698
promise.done(function() {
699699
removeActiveLinkClass();
700-
700+
701701
//if there's a duplicateCachedPage, remove it from the DOM now that it's hidden
702702
if ( settings.duplicateCachedPage ) {
703703
settings.duplicateCachedPage.remove();
704704
}
705-
705+
706706
//remove initial build class (only present on first pageshow)
707707
$html.removeClass( "ui-mobile-rendering" );
708-
708+
709709
releasePageTransitionLock();
710-
710+
711711
// Let listeners know we're all done changing the current page.
712712
mpc.trigger( "changepage" );
713713
});

tests/jquery.testHelper.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,31 @@
7373
$.each(fns, function(i, fn){
7474
setTimeout(fn, i * interval);
7575
});
76+
},
77+
78+
pageSequence: function(fns, event){
79+
var fn = fns.shift(),
80+
self = this;
81+
82+
if(fn === undefined) return;
83+
84+
event = event || "changepage";
85+
86+
// if a changepage or defined event is never triggered
87+
// continue in the sequence to alert possible failures
88+
var warnTimer = setTimeout(function(){
89+
self.pageSequence(fns, event);
90+
}, 2000);
91+
92+
// bind the recursive call to the event
93+
$.mobile.pageContainer.one(event, function(){
94+
clearTimeout(warnTimer);
95+
self.pageSequence(fns, event);
96+
});
97+
98+
// invoke the function which should, in some fashion,
99+
// trigger the defined event
100+
fn();
76101
}
77102
};
78103
})(jQuery);

tests/unit/navigation/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ <h1>Dialog</h1>
224224
</div>
225225

226226
<div data-nstest-role="page" id="pathing-tests-reset">
227-
<div class="test-value">page didn't change!</div>
227+
<div class="reset-value">page didn't change!</div>
228228
</div>
229229
</body>
230230
</html>

tests/unit/navigation/navigation_core.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
originalTitle = document.title,
77
siteDirectory = location.pathname.replace(/[^/]+$/, "");
88
module('jquery.mobile.navigation.js', {
9-
setup: function(){
9+
teardown: function(){
1010
$.mobile.urlHistory.stack = [];
1111
$.mobile.urlHistory.activeIndex = 0;
1212
$.mobile.changePage = changePageFn;
@@ -58,10 +58,10 @@
5858
});
5959

6060
asyncTest( "forms with data attribute ajax set to false will not call changePage", function(){
61-
var called = false,
62-
newChangePage = function(){
63-
called = true;
64-
};
61+
var called = false;
62+
var newChangePage = function(){
63+
called = true;
64+
};
6565

6666
$.testHelper.sequence([
6767
// avoid initial page load triggering changePage early
@@ -77,7 +77,7 @@
7777
function(){
7878
ok(!called, "change page should not be called");
7979
start();
80-
}], 500);
80+
}], 1000);
8181
});
8282

8383
asyncTest( "forms with data attribute ajax not set or set to anything but false will call changepage", function(){

tests/unit/navigation/navigation_paths.js

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,38 @@
33
*/
44
(function($){
55
var testPageLoad = function(testPageAnchorSelector, expectedTextValue){
6-
expect( 1 );
6+
expect( 2 );
77

8-
$.testHelper.sequence([
8+
// remove cached pages to make sure the page request hits the test
9+
$(".ui-page > .test-value").parents(".ui-page").remove();
10+
11+
$.testHelper.pageSequence([
912
// open our test page
1013
function(){
1114
$.testHelper.openPage("#pathing-tests");
1215
},
1316

1417
// navigate to the linked page
1518
function(){
16-
$( ".ui-page-active a" + testPageAnchorSelector ).click();
19+
var page = $.mobile.activePage;
20+
21+
// check that the reset page isn't still open
22+
equal("", page.find(".reset-value").text());
23+
24+
//click he test page link to execute the path
25+
page.find("a" + testPageAnchorSelector).click();
1726
},
1827

1928
// verify that the page has changed and the expected text value is present
2029
function(){
21-
same($(".ui-page-active .test-value").text(), expectedTextValue);
30+
same($.mobile.activePage.find(".test-value").text(), expectedTextValue);
31+
$.testHelper.openPage("#pathing-tests-reset");
2232
},
2333

24-
// open the reset page to help signify when pages aren't changing
2534
function(){
26-
$.testHelper.openPage("#pathing-tests-reset");
2735
start();
2836
}
29-
], 800);
37+
]);
3038
};
3139

3240
// all of these alterations assume location.pathname will be a directory

0 commit comments

Comments
 (0)