Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

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

Closed
irnc opened this Issue · 8 comments

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

@johnbender

@gseguin

That's a much better idea :+1:

@toddparker

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

@toddparker toddparker closed this
@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
@gseguin gseguin reopened this
@gseguin
Collaborator

Should be fixed by 8b938e2

@toddparker toddparker closed this
@johnbender johnbender referenced this issue from a commit in johnbender/jquery-mobile
@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
Something went wrong with that request. Please try again.