mirror of
https://github.com/Hopiu/jquery-mobile.git
synced 2026-04-20 14:20:59 +00:00
page sequence helper added, nav tests in a somewhat better state. the event trigger spot, namespace, and general setup are all up for debate
This commit is contained in:
parent
2cfacc4804
commit
dc530ea751
5 changed files with 59 additions and 26 deletions
|
|
@ -191,14 +191,14 @@
|
|||
|
||||
//existing base tag?
|
||||
$base = $head.children( "base" ),
|
||||
|
||||
//get domain path
|
||||
|
||||
//get domain path
|
||||
//(note: use explicit protocol here, protocol-relative urls won't work as expected on localhost)
|
||||
docBase = location.protocol + "//" + location.host,
|
||||
|
||||
|
||||
//initialPath for first page load without hash. pathname (href - search)
|
||||
initialPath = docBase + location.pathname;
|
||||
|
||||
|
||||
//already a base element?
|
||||
if ( $base.length ) {
|
||||
var href = $base.attr( "href" );
|
||||
|
|
@ -212,7 +212,7 @@
|
|||
docBase = href;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//make sure docBase ends with a slash
|
||||
docBase = docBase + ( docBase.charAt( docBase.length - 1 ) === "/" ? " " : "/" );
|
||||
}
|
||||
|
|
@ -307,14 +307,14 @@
|
|||
//jump to top or prev scroll, sometimes on iOS the page has not rendered yet.
|
||||
$.mobile.silentScroll( toPage.jqmData( "lastScroll" ) || 0 );
|
||||
$( document ).one( "silentscroll", function() { reFocus( toPage ); } );
|
||||
|
||||
|
||||
//trigger show/hide events
|
||||
if( fromPage ) {
|
||||
fromPage.data( "page" )._trigger( "hide", null, { nextPage: toPage } );
|
||||
}
|
||||
//trigger pageshow, define prevPage as either fromPage or empty jQuery obj
|
||||
toPage.data( "page" )._trigger( "show", null, { prevPage: fromPage || $( "" ) } );
|
||||
|
||||
|
||||
});
|
||||
|
||||
return promise;
|
||||
|
|
@ -538,7 +538,7 @@
|
|||
// Remove loading message.
|
||||
if ( settings.showLoadMsg ) {
|
||||
$.mobile.hidePageLoadingMsg();
|
||||
|
||||
|
||||
//show error message
|
||||
$( "<div class='ui-loader ui-overlay-shadow ui-body-e ui-corner-all'><h1>"+ $.mobile.pageLoadErrorMessage +"</h1></div>" )
|
||||
.css({ "display": "block", "opacity": 0.96, "top": $window.scrollTop() + 100 })
|
||||
|
|
@ -697,17 +697,17 @@
|
|||
|
||||
promise.done(function() {
|
||||
removeActiveLinkClass();
|
||||
|
||||
|
||||
//if there's a duplicateCachedPage, remove it from the DOM now that it's hidden
|
||||
if ( settings.duplicateCachedPage ) {
|
||||
settings.duplicateCachedPage.remove();
|
||||
}
|
||||
|
||||
|
||||
//remove initial build class (only present on first pageshow)
|
||||
$html.removeClass( "ui-mobile-rendering" );
|
||||
|
||||
|
||||
releasePageTransitionLock();
|
||||
|
||||
|
||||
// Let listeners know we're all done changing the current page.
|
||||
mpc.trigger( "changepage" );
|
||||
});
|
||||
|
|
|
|||
|
|
@ -73,6 +73,31 @@
|
|||
$.each(fns, function(i, fn){
|
||||
setTimeout(fn, i * interval);
|
||||
});
|
||||
},
|
||||
|
||||
pageSequence: function(fns, event){
|
||||
var fn = fns.shift(),
|
||||
self = this;
|
||||
|
||||
if(fn === undefined) return;
|
||||
|
||||
event = event || "changepage";
|
||||
|
||||
// if a changepage or defined event is never triggered
|
||||
// continue in the sequence to alert possible failures
|
||||
var warnTimer = setTimeout(function(){
|
||||
self.pageSequence(fns, event);
|
||||
}, 2000);
|
||||
|
||||
// bind the recursive call to the event
|
||||
$.mobile.pageContainer.one(event, function(){
|
||||
clearTimeout(warnTimer);
|
||||
self.pageSequence(fns, event);
|
||||
});
|
||||
|
||||
// invoke the function which should, in some fashion,
|
||||
// trigger the defined event
|
||||
fn();
|
||||
}
|
||||
};
|
||||
})(jQuery);
|
||||
|
|
@ -224,7 +224,7 @@
|
|||
</div>
|
||||
|
||||
<div data-nstest-role="page" id="pathing-tests-reset">
|
||||
<div class="test-value">page didn't change!</div>
|
||||
<div class="reset-value">page didn't change!</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
originalTitle = document.title,
|
||||
siteDirectory = location.pathname.replace(/[^/]+$/, "");
|
||||
module('jquery.mobile.navigation.js', {
|
||||
setup: function(){
|
||||
teardown: function(){
|
||||
$.mobile.urlHistory.stack = [];
|
||||
$.mobile.urlHistory.activeIndex = 0;
|
||||
$.mobile.changePage = changePageFn;
|
||||
|
|
@ -58,10 +58,10 @@
|
|||
});
|
||||
|
||||
asyncTest( "forms with data attribute ajax set to false will not call changePage", function(){
|
||||
var called = false,
|
||||
newChangePage = function(){
|
||||
called = true;
|
||||
};
|
||||
var called = false;
|
||||
var newChangePage = function(){
|
||||
called = true;
|
||||
};
|
||||
|
||||
$.testHelper.sequence([
|
||||
// avoid initial page load triggering changePage early
|
||||
|
|
@ -77,7 +77,7 @@
|
|||
function(){
|
||||
ok(!called, "change page should not be called");
|
||||
start();
|
||||
}], 500);
|
||||
}], 1000);
|
||||
});
|
||||
|
||||
asyncTest( "forms with data attribute ajax not set or set to anything but false will call changepage", function(){
|
||||
|
|
|
|||
|
|
@ -3,9 +3,12 @@
|
|||
*/
|
||||
(function($){
|
||||
var testPageLoad = function(testPageAnchorSelector, expectedTextValue){
|
||||
expect( 1 );
|
||||
expect( 2 );
|
||||
|
||||
$.testHelper.sequence([
|
||||
// remove cached pages to make sure the page request hits the test
|
||||
$(".ui-page > .test-value").parents(".ui-page").remove();
|
||||
|
||||
$.testHelper.pageSequence([
|
||||
// open our test page
|
||||
function(){
|
||||
$.testHelper.openPage("#pathing-tests");
|
||||
|
|
@ -13,20 +16,25 @@
|
|||
|
||||
// navigate to the linked page
|
||||
function(){
|
||||
$( ".ui-page-active a" + testPageAnchorSelector ).click();
|
||||
var page = $.mobile.activePage;
|
||||
|
||||
// check that the reset page isn't still open
|
||||
equal("", page.find(".reset-value").text());
|
||||
|
||||
//click he test page link to execute the path
|
||||
page.find("a" + testPageAnchorSelector).click();
|
||||
},
|
||||
|
||||
// verify that the page has changed and the expected text value is present
|
||||
function(){
|
||||
same($(".ui-page-active .test-value").text(), expectedTextValue);
|
||||
same($.mobile.activePage.find(".test-value").text(), expectedTextValue);
|
||||
$.testHelper.openPage("#pathing-tests-reset");
|
||||
},
|
||||
|
||||
// open the reset page to help signify when pages aren't changing
|
||||
function(){
|
||||
$.testHelper.openPage("#pathing-tests-reset");
|
||||
start();
|
||||
}
|
||||
], 800);
|
||||
]);
|
||||
};
|
||||
|
||||
// all of these alterations assume location.pathname will be a directory
|
||||
|
|
|
|||
Loading…
Reference in a new issue