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

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

Projects

None yet

4 participants

@irnc

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.

@johnbender

@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"] );
  });
});
@johnbender

@gseguin

Maybe you can comment?

@gseguin
jQuery Foundation member

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

@johnbender

@gseguin

That's a much better idea 👍

@toddparker

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

@toddparker toddparker closed this Apr 20, 2012
@irnc

@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?

@johnbender

@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.

@gseguin gseguin was assigned May 16, 2012
@gseguin gseguin reopened this May 16, 2012
@gseguin
jQuery Foundation member

Should be fixed by 8b938e2

@toddparker toddparker closed this May 17, 2012
@johnbender johnbender pushed a commit to johnbender/jquery-mobile that referenced this issue May 22, 2012
@gseguin gseguin 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