azicchetti / jquerymobile-router

A router/controller for jquery mobile. Also adds support for client-side parameters in the hash part of the url. The routes handles regexp based routes. This plugin can be used alone or (better) with Backbone.js or Spine.js, because it's originally meant to replace their router with something integrated with jQM.
GNU General Public License v2.0
402 stars 69 forks source link

Hash is removed by JQM nested lists #10

Closed smukkejohan closed 12 years ago

smukkejohan commented 12 years ago

I have a route that catches a query string parameter and builds a JQM nested list. This works fine and the url is bookmarkable but when you navigate to the nested part of the list JQM replaces the existing query string with &ui-page=id. This means that if you reload the page it does not find any data, and it means the url is not bookmarkable. Is there a workaround if I would like refreshable bookmarkable nested list on dynamicly generated pages in JQM?

BTW: Oterwise really nice work og the jqm Router! -Johan

azicchetti commented 12 years ago

Il 01/12/2011 17:03, Johan Bichel Lindegaard ha scritto:

I have a route that catches a query string parameter and builds a JQM nested list. This works fine and the url is bookmarkable but when you navigate to the nested part of the list JQM replaces the existing query string with&ui-page=id. This means that if you reload the page it does not find any data, and it means the url is not bookmarkable. Is there a workaround if I would like refreshable bookmarkable nested list on dynamicly generated pages in JQM?

This was a tough one...

I've patched the code but I want to make sure that I didn't break anything, since this is a thing that should be done by jquery mobile itself. I'll push the file with another name (jquery.mobile.router-test.js) on the git, please test it and let me know. I'm not supporting the configuration parameter $.mobile.subPageUrlKey at the moment, so please use the default "ui-page" identifier.

Could you please fill an issue to the jquery-mobile project? I know that they're planning to include support for hash parameters natively, and this is an important scenario they need to take into account. I will gladly participate to the issue thread aswell, once created.

Cheers, Andrea

smukkejohan commented 12 years ago

Thanks for reacting so quickly to this. The new version doesn't work for me though, still same issue. I am using the default subPageUrlKey. I posted the issue over at jquery mobile as well here: https://github.com/jquery/jquery-mobile/issues/3198.

azicchetti commented 12 years ago

Il 01/12/2011 20:57, Johan Bichel Lindegaard ha scritto:

Thanks for reacting so quickly to this. The new version doesn't work for me though, still same issue. I am using the default subPageUrlKey. I posted the issue over at jquery mobile as well here: https://github.com/jquery/jquery-mobile/issues/3198.

I've seen that you're probably using the parameters in the "wrong" order. Can you please try and swap them, as in:

library?section=cooking

library?section=cooking&ui-page=ecc?

I'm pushing a test file on the git, if you load it with this hash:

index?some=thing

you can see that parameters are preserved during navigation (hopefully).

Cheers, Andrea

smukkejohan commented 12 years ago

There is still an issue, I am getting an error on line 60.

(hasUiPage){
    page+=data.toPage.match(/&ui-page=([0-9-]+)$/)[0];

Uncaught TypeError: cannot read property '0' of null

azicchetti commented 12 years ago

Il 01/12/2011 23:01, Johan Bichel Lindegaard ha scritto:

There is still an issue, I am getting an error on line 60.

 (hasUiPage){
     page+=data.toPage.match(/&ui-page=([0-9-]+)$/)[0];

Uncaught TypeError: cannot read property of '0' of null

Can you please post an example? That line should fail only when ui-page contains something that isn't a number or the "-" sign (i.e: &ui-page=foo-0). Is it possible?

smukkejohan commented 12 years ago

Yes the value is: NCCRootElement-0 The top list id is 'NCCRootElement' and -0 is appended by jqm assumably because the list element I am trying to expand is the first in the list.

azicchetti commented 12 years ago

Il 01/12/2011 23:22, Johan Bichel Lindegaard ha scritto:

Yes the value is: NCCRootElement-0 The top list id is 'NCCRootElement' and -0 is appended by jqm assumably because the list element I am trying to expand is the first in the list.

Woops, fixed!

smukkejohan commented 12 years ago

Ok the parameters are preserved now. But JQM doesn't understand it and loads the top level list again.

azicchetti commented 12 years ago

Il 01/12/2011 23:45, Johan Bichel Lindegaard ha scritto:

Ok the parameters are preserved now. But JQM doesn't understand it and loads the top level list again.

I think that we need a full example to fix this.

I've noticed that even without the router, standard jqm links with &ui-page are not really bookmarkable. They all load the top level list when refreshed.

Am I missing something? Does it work for you? Maybe this is a separate issue with jqm.

smukkejohan commented 12 years ago

Yeah I think you are right. Hope someone will pick it up in the jquery tracker. Not bookmarkable here either: http://jquerymobile.com/demos/1.0/docs/lists/lists-nested.html#&ui-page=0-8