I have a JQM apps and I am incorporating Backbone.
Since my initial javascript code is huge, I am only extracting what I believe is problematic.
I am following the advices and calls steps cited here:
I have a major problem, and this is the behaviour, the problem comes from this code:
var r = Backbone.Router.extend
router: ...
"page": "pageDisplay"
...
pageDisplay: function(){
c = new AView(); // Backbone.View ...fetch() data...
$(c.el).page(); // Call to JQM to add its extra stuff; seems done correctly
$.mobile.changePage( "#" + c.id, {changeHash: false}); // line 50
}
When following the links of `<a href="#page" >`, I come as expected to the
page "#page" properly processed. But once there, if I click a `refresh`, which is indirectly reprocessed by the same router rule, I end up with the following error:
> Uncaught TypeError: Cannot call method 'trigger' of undefined
I downloaded the jquery mobile development code and observed this:
> // JQM1.1.2 - Line #3772 Show a specific page in the page container.
>
> $.mobile.changePage = function( toPage, options ) {
>
> if ( isPageTransitioning ) {
> pageTransitionQueue.unshift(arguments );
> return;
> }
> var settings = $.extend( {}, $.mobile.changePage.defaults, options);
>
> // Make sure we have a pageContainer to work with.
> settings.pageContainer = settings.pageContainer || $.mobile.pageContainer;
> // Make sure we have a fromPage.
> settings.fromPage = settings.fromPage || $.mobile.activePage;
> // Line #3788
> var mpc = settings.pageContainer, // Line #3789
> pbcEvent = new $.Event("pagebeforechange" ),
> triggerData = { toPage: toPage, options: settings };
> // Let listeners know we're about to change the current page.
> mpc.trigger( pbcEvent, triggerData ); // Line #3794
The `Uncaught TypeError` is caused by Line #3794, because `mpc` is `undefined`.
So, from JQM, In the Chrome inspector, I can see also that `settings.fromPage` is `undefined` and `settings.pageContainer` is `undefined`. I kind of imagine, that JQM cannot make an assumption on the fromPage, and therefore, cannot proceed on my refresh. All the options I have tried on the $mobile.changePage() have not succeed. I am out of ideas.
Any help will be appreciated.
UPDATE: I have cut all unnecessary code and left the bug kept on a live website:
apartindex.com. Hope can help somebody look into it ? To make the problem appears, just update on your browser until the javascript error appears.