Skip to content
This repository

Can not disable 'push state' plugin when jQM loaded via require.js #4136

Closed
irnc opened this Issue April 20, 2012 · 8 comments

4 participants

Pavel Zubkou Todd Parker Ghislain Seguin John Bender
Pavel Zubkou
irnc commented April 20, 2012

When jQM are loaded after document ready event, $.mobile.pushStateEnabled option are read before mobileinit event (it is actually read on already fired ready event, i.e. immediately on script execution), thus it is not possible to change it.

John Bender

@irnc

This will be low priority since we don't officially support this method of loading jqm. I believe what we've done in the past is to create a meta module where jquery is the initial load dependency, your init methods are in a callback with require of the rest of jqm. Something like:

require( ["jquery"], function(){
  require( ["my-mobile-init-stuff"], function(){
    require( ["jquery.mobile"] );
  });
});
John Bender

@gseguin

Maybe you can comment?

Ghislain Seguin
Collaborator

What @johnbender mentioned should work or even simpler:

require( [ "jquery" ], function( $ ){
  $( window ).one( "mobileinit", function() {
    $.mobile.pushStateEnabled = false;
  });
  require( [ "jquery.mobile" ] );
});

UPDATE: $.one -> $( window ).one

John Bender

@gseguin

That's a much better idea :+1:

Todd Parker

Closing this since we don't support it and there is a suggested workaround.

Todd Parker toddparker closed this April 20, 2012
Pavel Zubkou
irnc commented April 21, 2012

@gseguin This will not work if require( [ "jquery.mobile" ] ); will be called after document.ready because in this case, $.mobile.pushStateEnabled are read immediately upon execution and before mobileinit event.

See https://github.com/jquery/jquery-mobile/blob/master/js/jquery.mobile.navigation.pushstate.js#L155, maybe this initialization can be done on mibileinit event and not on document.ready?

John Bender

@gseguin @irnc

Ah, he's right. The pushStateHandler does it's init on domready instead of page create. I think there's a legit reason for that (ie the initial nav event). Something to think about.

Ghislain Seguin gseguin reopened this May 16, 2012
Ghislain Seguin
Collaborator
gseguin commented May 16, 2012

Should be fixed by 8b938e2

Todd Parker toddparker closed this May 16, 2012
Jasper de Groot uGoMobi referenced this issue from a commit in uGoMobi/jquery-mobile May 16, 2012
Ghislain Seguin Call init when both mobileinit and domready have happened instead of …
…just domready.

Fixes #4136
46480bc
John Bender johnbender referenced this issue from a commit in johnbender/jquery-mobile May 16, 2012
Ghislain Seguin Call init when both mobileinit and domready have happened instead of …
…just domready.

Fixes #4136
8b938e2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.