How to stop jQuery Mobile calling $.mobile.loading('hide') during changePage? -
i'm trying stop jquery mobile hiding loading spinner when changepage called.
the program flow goes this, starting clicking link, has click event defined this:
$('body').delegate('.library-link', 'click', function() { $.mobile.loading( 'show' ); $.mobile.changepage($('#page-library')); return false; });
upon clicking link, pagebeforeshow
event fired, triggers function populate page local storage, or else make ajax call data.
$(document).on('pagebeforeshow', '#page-library', function(event){ ui.populate_data(); });
in ui.populate_data()
data local storage or make ajax call.
ui.populate_data = function() { if (localdata) { // populate ui on page $.mobile.loading( 'hide' ); } else { // make ajax call } };
if data there, load data container , hide loading spinner. if not makes ajax call, on complete saves data in local storage, , calls ui.populate_data()
the problem is, after pagebeforeshow
event finished, changepage calling $.mobile.loading( 'hide' )
, though data might not there yet. can't find way prevent changepage hiding spinner, other temporarily redefining $.mobile.loading
, feels pretty wrong:
$('body').delegate('.library-link', 'click', function() { $.mobile.loading( 'show' ); loading_fn = $.mobile.loading; $.mobile.loading = function() { return; }; $.mobile.changepage($('#page-library'), {showloadmsg: false}); return false; });
and before hiding spinner in ui function:
ui.populate_data = function() { if (localdata) { // populate ui on page if (typeof loading_fn === 'function') { $.mobile.loading = loading_fn; } $.mobile.loading( 'hide' ); } else { // make ajax call } };
surely there must way complete control on showing , hiding of loading widget, can't find it. tried passing {showloadmsg: false}
changepage, suggested docs things when loading pages on ajax, i'm not doing.
maybe it's many, found solution other written in comments (which didn't work me).
i use jquery mobile router , in 'show' event of page, $.mobile.loading("show");
, when page appears loading spinner showing.
though hide spinner, had use $('.ui-loader').hide();
, weird, know...
i use jquery mobile router lot more, solved issue.
(maybe listening proper event , triggering spinner work, jqmr does...)
i'm using jqm 1.4.2...
Comments
Post a Comment