19

I've been enjoying using Backbone JS for a iPad HTML5 project... But I'm quickly running into a issue of needing iPad-ish transitions, form elements etc. After looking around, it seems jQuery Mobile is the most established. We use jQuery anyhow.

But one thing I quickly ran into was the hash events/ajax stuff of the two libraries quickly didn't work. Because jQuery Mobile takes care of loading in pages, and doing the transitions etc, it was not letting my Backbone Controller routes work as they did before. It seemed that the two aren't actually that compatible?

After some work though, I have a basic workaround... Using the page loading events stuff in jQuery Mobile to see the active page it's on and then fire the correct Backbone View that goes with that page. Basically doing away completely with Backbone's hash listening/routes/controller.

But this still doesn't seem right? How can Backbone JS and jQuery Mobile work seamlessly together? How do I do this right, moving forward?

littlejim84
  • 8,301
  • 14
  • 50
  • 73

4 Answers4

8

I think I found a solution when I asked the same question.

Disable the hash change controller in JQuery mobile UI and replace with backbone.js

There looks to be an option to disable JQuery hash change listening on a recent checking.

https://github.com/jquery/jquery-mobile/commit/3162428558efd9960739ef8f00a7ead0dbf6d3ec

I have not tried it yet though. If it works please let us know.

Brad

Community
  • 1
  • 1
bradgonesurfing
  • 28,325
  • 12
  • 101
  • 188
  • That is very interesting and is actually exactly what I was after. Thank you! – littlejim84 Apr 13 '11 at 09:48
  • @littlejim84 did you get a chance to try out the above suggestion. I'm stepping out soon to make another mobile app and would really like to know if the above works well. – bradgonesurfing May 08 '11 at 14:58
  • Note that you have to set linkBindingEnabled to false in version 1.0 http://jquerymobile.com/demos/1.0/docs/api/globalconfig.html – Andreas Köberle Dec 07 '11 at 20:40
4

It seems that the JQuery Mobile team has made a conscious decision to not support the sort of dynamic applications the Backbone.js targets. From the alpha 4 release notes:

After 1.0 is out, the project be focusing on ... dynamic applications, expanded widget set, and ... A more detailed roadmap is underway and we’ll share it as we get closer to our 1.0 release.

Further evidence for this is the removal of the autoInitialize option as they went from alpha 3 to alpha 4: issue 1391

So for now, we need workarounds. An alternative answer is to help fix outstanding JQM bugs and push it closer to 1.0, so we can get dynamic application features into JQM ASAP.

Mike McKay
  • 2,132
  • 26
  • 32
1

i prefer something more integrated w/ jquery mobile, so i usually replace backbone's router with this one: github.com/azicchetti/jquerymobile-router . works nicely

petermaury
  • 11
  • 1
0

Found this and it worked perfectly for me: Redirect from mobile site (jQuery mobile) to main site styles linger

I was redirecting to the main site and it kept throwing "Backbone history started" errors

Community
  • 1
  • 1
Brandon
  • 1,359
  • 3
  • 19
  • 37