Permalink
Browse files

Fix for issue 2503 - User can't specify own error handling logic

- Added the following notifications to $.mobile.loadPage():

	- pagebeforeload
		- Triggered just before loadPage() attempts to dynamically load an external page.
		- Developers can prevent the default loading behavior by calling preventDefault() on the event. If preventDefault() is called, it is up to the developer to call resolve()/reject() on the deferred object passed within the data object (2nd arg to the event callback).

	- pageload
		- Triggered after an external page has been loaded and inserted into the document.

	- pageloadfailed
		- Triggered when the load of an external page fails.
		- Developers can prevent the default behavior (error dialog display) by calling preventDefault() on the event. If preventDefault() is called, it is up to the developer to call resolve()/reject() on the deferred object (2nd arg to the event callback).
  • Loading branch information...
jblas committed Sep 23, 2011
1 parent fe35e36 commit 4f066b7e078d0751225524177e865e872ff428ae
Showing with 31 additions and 0 deletions.
  1. +31 −0 js/jquery.mobile.navigation.js
@@ -742,6 +742,18 @@
dupCachedPage = page;
}
var mpc = settings.pageContainer,
pblEvent = new $.Event( "pagebeforeload" ),
triggerData = { url: url, absUrl: absUrl, dataUrl: dataUrl, deferred: deferred, options: settings };
// Let listeners know we're about to load a page.
mpc.trigger( pblEvent, triggerData );
// If the default behavior is prevented, stop here!
if( pblEvent.isDefaultPrevented() ){
return deferred.promise();
}
if ( settings.showLoadMsg ) {
// This configurable timeout allows cached pages a brief delay to load without showing a message
@@ -863,6 +875,12 @@
hideMsg();
}
// Add the page reference to our triggerData.
triggerData.page = page;
// Let listeners know the page loaded successfully.
settings.pageContainer.trigger( "pageload", triggerData );
deferred.resolve( absUrl, options, page, dupCachedPage );
},
error: function() {
@@ -871,6 +889,19 @@
base.set( path.get() );
}
var plfEvent = new $.Event( "pageloadfailed" );
// Let listeners know the page load failed.
settings.pageContainer.trigger( plfEvent, triggerData );
// If the default behavior is prevented, stop here!
// Note that it is the responsibility of the listener/handler
// that called preventDefault(), to resolve/reject the
// deferred object within the triggerData.
if( plfEvent.isDefaultPrevented() ){
return;

This comment has been minimized.

Show comment
Hide comment
@redaemn

redaemn Dec 19, 2011

Contributor

@jblas

I don't understand: shouldn't this line be return deferred.promise() as it is on line 754?!?

@redaemn

redaemn Dec 19, 2011

Contributor

@jblas

I don't understand: shouldn't this line be return deferred.promise() as it is on line 754?!?

This comment has been minimized.

Show comment
Hide comment
@jblas

jblas Dec 21, 2011

Contributor

@redaemn

No, the return on line 902 is returning from the failed callback, not the loadPage() function.

@jblas

jblas Dec 21, 2011

Contributor

@redaemn

No, the return on line 902 is returning from the failed callback, not the loadPage() function.

}
// Remove loading message.
if ( settings.showLoadMsg ) {

1 comment on commit 4f066b7

@jblas

This comment has been minimized.

Show comment
Hide comment
@jblas

jblas Dec 21, 2011

Contributor

@redaemn

No, the return on line 902 is returning from the failed callback, not the loadPage() function.

Contributor

jblas commented on 4f066b7 Dec 21, 2011

@redaemn

No, the return on line 902 is returning from the failed callback, not the loadPage() function.

Please sign in to comment.