setting pushStateEnabled=false when loading jquery/mobile with requireJS is ineffective #4364

Closed
cjolif opened this Issue May 15, 2012 · 7 comments

Comments

Projects
None yet
4 participants
@cjolif

cjolif commented May 15, 2012

HTML:

<head>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="http://code.jquery.com/mobile/1.1.0/jquery.mobile-1.1.0.min.css" />
    <script data-main="main" src="require-jquery.js"></script>
</head>

main.js:

require(["jquery"], function($) {
    require(["jquery-mobile"], function(){
        $(document).bind("mobileinit", function(){
            $.mobile.hashListeningEnabled = false;
            $.mobile.pushStateEnabled = false;
        });
    });
});

even if pushStateEnabled is set to false push state manage is enabled. You can check that by setting a breakpoint in jQuery mobile pushStateHandler.init method. You will see it is called while it is not if jQuery is not loaded with requireJS. This comes from the fact that in requireJS context this:

    $( function() { 
        if( $.mobile.pushStateEnabled && $.support.pushState ){
            pushStateHandler.init();
        }
    });

is called before mobileinit.

@toddparker

This comment has been minimized.

Show comment Hide comment
@toddparker

toddparker May 16, 2012

Contributor

@gseguin - mind weighing in on this one?

Contributor

toddparker commented May 16, 2012

@gseguin - mind weighing in on this one?

@ghost ghost assigned gseguin May 16, 2012

@gseguin

This comment has been minimized.

Show comment Hide comment
@gseguin

gseguin May 16, 2012

Member

This is a duplicate of #4136

Member

gseguin commented May 16, 2012

This is a duplicate of #4136

@gseguin gseguin closed this May 16, 2012

@gseguin

This comment has been minimized.

Show comment Hide comment
@gseguin

gseguin May 16, 2012

Member

@cjolif I believe your main.js should look like that instead:

require( [ "jquery" ], function( $ ) {
    $(document).bind( "mobileinit", function(){
        $.mobile.hashListeningEnabled = false;
        $.mobile.pushStateEnabled = false;
    });

    require( [ "jquery-mobile" ], function(){
         // do cool stuff with jQM
    });
});

But regardless, there is indeed an issue with the way pushState is initialized.

Member

gseguin commented May 16, 2012

@cjolif I believe your main.js should look like that instead:

require( [ "jquery" ], function( $ ) {
    $(document).bind( "mobileinit", function(){
        $.mobile.hashListeningEnabled = false;
        $.mobile.pushStateEnabled = false;
    });

    require( [ "jquery-mobile" ], function(){
         // do cool stuff with jQM
    });
});

But regardless, there is indeed an issue with the way pushState is initialized.

@cjolif

This comment has been minimized.

Show comment Hide comment
@cjolif

cjolif May 16, 2012

@gseguin right I agree the main.js should be as you suggested, unfortunately it does not work better ;)

cjolif commented May 16, 2012

@gseguin right I agree the main.js should be as you suggested, unfortunately it does not work better ;)

@gseguin

This comment has been minimized.

Show comment Hide comment
@gseguin

gseguin May 16, 2012

Member

@cjolif Can you confirm that 8b938e2 fixes the problem?

Member

gseguin commented May 16, 2012

@cjolif Can you confirm that 8b938e2 fixes the problem?

@cjolif

This comment has been minimized.

Show comment Hide comment
@cjolif

cjolif May 18, 2012

this is working perfectly. Thanks!

cjolif commented May 18, 2012

this is working perfectly. Thanks!

@pramodD

This comment has been minimized.

Show comment Hide comment
@pramodD

pramodD Jul 6, 2012

I also have same issue but $.mobile.pushStateEnabled = false; solve it. Thank you guys

pramodD commented Jul 6, 2012

I also have same issue but $.mobile.pushStateEnabled = false; solve it. Thank you guys

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment