Giter VIP home page Giter VIP logo

Comments (14)

azicchetti avatar azicchetti commented on August 26, 2024

Hi raldred,
thanks for digging into this problem.
As far as I can remember, even 1.0.1 triggers pagebeforechange twice and the router tries to discard the second call by using the property _jqmrouter_handled [in previous versions I was using a different approach that wasn't supporting explicit $.mobile.changePage's with a jquery object as the first argument].

I've done a couple of experiments (jquery 1.7.1 and jqm rc1) and everything seems consistent to me with the previous 1.0.1 version, so I'm probably missing something important (for instance, I haven't tried a programmatic $.mobile.changePage).
Would you mind sharing your example?

Thank you

from jquerymobile-router.

raldred avatar raldred commented on August 26, 2024

Hi Andrea, thanks for getting back to me about this.
I've prepared a couple of examples, the same except the version of jqm, both using the current master of mobile router.

To replicate..
Click "Section 1"
Click "Chunk 1"
Click "Back"

In the 1.1.0 RC1 example clicking "Back" will cause the #section page to transition twice.

1.1.0 RC1
http://jsfiddle.net/robaldred/BJvHf/

1.0.1
http://jsfiddle.net/robaldred/ufnGy/

(Tested with Chrome Mac 17.0.963.65)

from jquerymobile-router.

azicchetti avatar azicchetti commented on August 26, 2024

A quick followup until I have more time to dig into the problem.

It seems that the 1.1.0 version will support parameters in the hash part of the url natively (this is very good news!) and so the

if ( u.hash.indexOf("?") !== -1 ) {
...
}

branch in the router is no longer needed.
Removing it apparently fixes the problem.
It would be great if you had a little time to confirm it.

Thanks!

from jquerymobile-router.

raldred avatar raldred commented on August 26, 2024

Hi again,
Interesting, that is pretty good news.

I've altered the router to remove the addon support for parameters.
the pagebeforechange now looks like....

$(document).bind("pagebeforechange", function( e, data ) {
  var toPage=( typeof data.toPage === "string" ) ? data.toPage : data.toPage.jqmData("url")||"";

  if ( data.options.hasOwnProperty("_jqmrouter_handled") ){ return; }
  data.options._jqmrouter_handled = true;

  var u = $.mobile.path.parseUrl( toPage );
  previousUrl=nextUrl;
  nextUrl=u;

  $.mobile.changePage(toPage, data.options);
  e.preventDefault();
});

It seems to work correctly, however I might need to do some further testing.

from jquerymobile-router.

azicchetti avatar azicchetti commented on August 26, 2024

Uhm, try deleting the last two lines (I think the problem here was the changePage. Basically, that part of the router code is now in jquery mobile itself, so we need to remove it to avoid duplicates)

      $.mobile.changePage(toPage, data.options);
      e.preventDefault();

from jquerymobile-router.

raldred avatar raldred commented on August 26, 2024

great stuff, that works aswell.
So i literally just have

$(document).bind("pagebeforechange", function( e, data ) {
  var toPage=( typeof data.toPage === "string" ) ? data.toPage : data.toPage.jqmData("url")||"";

  if ( data.options.hasOwnProperty("_jqmrouter_handled") ){ return; }
  data.options._jqmrouter_handled = true;

  var u = $.mobile.path.parseUrl( toPage );
  previousUrl=nextUrl;
  nextUrl=u;
});

from jquerymobile-router.

azicchetti avatar azicchetti commented on August 26, 2024

yep, that should be it!
I'm taking a few days to properly examine jquery mobile sources before pushing a patch, so please use your own version in the meanwhile.

from jquerymobile-router.

raldred avatar raldred commented on August 26, 2024

Sure thing, thanks for your help, really appreciate your work on the plugin, it's been a great addition to my app.

from jquerymobile-router.

raldred avatar raldred commented on August 26, 2024

Hey, just found an issue with the modifications we made.
We need the following 3 lines back in:

  data.options.dataUrl = u.href;
  $.mobile.changePage(toPage, data.options);
  e.preventDefault();

Without these browsing to and from the same path with different params does not change the browser hash or the jquery history to reflect the new params.

from jquerymobile-router.

azicchetti avatar azicchetti commented on August 26, 2024

You mean browsing from #page?foo=bar to #page?bar=foo ?

If we put back those lines we may have problems with ajax pages, actually I guess it would break them completely.

I think that with a simple check on the active page we may fix this bug without too much effort, but it would be better if it was fixed in jquery mobile itself, since it seems a problem in their newly added code to support parameters in the hash.

Do you mind making a super-simple test page without the router and submit the bug report (if it still applies!) to jquery mobile guys?
If they won't fix it, I'll hopefully make a patch before the final 1.1.0 is released

from jquerymobile-router.

raldred avatar raldred commented on August 26, 2024

Ahh damn, it also breaks dialogs. I'll try but im not entirely sure what the issue with jqm's internals are, dont suppose you could point me to the section youve been looking at?

from jquerymobile-router.

raldred avatar raldred commented on August 26, 2024

Ok, dirty, but for the time being this works for my particular application (Dialogs & Ajax pages also work fine).
Also, im using the jqm simpledialog2 plugin which works aswell now.

  if(u.href != "") {
    data.options.dataUrl = u.href;
    $.mobile.changePage(toPage, data.options);
    e.preventDefault();
  }

from jquerymobile-router.

azicchetti avatar azicchetti commented on August 26, 2024

I'm supposing that the problem we're talking about is browsing from #page?foo=bar to #page?bar=foo, is it correct?

I think the problem with jqm is that they've added support for hash parameters in the url but they forgot to enable same page transitions.

Try replacing your #section page with this one:

<div id="section" data-role="page" data-add-back-btn="true">
    <div data-role="header"><h1>Section</h1></div>
    <div data-role="content">
        <ul data-role="listview">
            <li><a href="#section?id=2">Same page id=2</a></li>
            <li><a href="#section?id=3">Same page id=3</a></li>
            <li><a href="#section?id=4">Same page id=4</a></li>
        </ul>
    </div>
</div>

Don't load the jqm router.
You'll notice that clicking any of the "same page" links won't do anything (this is the jqm bug, I suppose).

Now, try loading the original jqm-router version (the unpatched one). Links are now working as expected.
jQuery mobile should handle this scenario natively

from jquerymobile-router.

azicchetti avatar azicchetti commented on August 26, 2024

Hi,
I've pushed a fix to support jqm 1.1.0rc2.

It turns out that the 'native' support for hash parameters is a side effect of a jquery selector used in the loadPage() function of jQM.
Since I'm scared by this, I'm keeping the code we removed a couple of weeks ago in the router, because it feels more safe and sound.

Hopefully the handler won't be called twice with the latest fix.

from jquerymobile-router.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.