Be able to use 'reverse' direction, even if you disable back-button handlers (for example when using jqm with backbone.js) #4902

Closed
wants to merge 1 commit into
from

Conversation

Projects
None yet
3 participants
Contributor

mariozaizar commented Aug 28, 2012

Context:

  • jQuery Mobile + backbone.js App.
  • jQuery Mobile bindings/history/routing were disabled to use Backbone's.
  • Back buttons are being used manually (that means using window.history.back directly)

Problem:

  • 1.1.1 won't apply the reverse direction even if you set the link with data-direction="reverse" to the links.

Example:

For example having:
(based on http://coenraets.org/blog/2012/03/using-backbone-js-with-jquery-mobile/ )

  # Disable jQuery Mobile routing and history to use Backbone.
  $.mobile.ajaxEnabled = false
  $.mobile.linkBindingEnabled = false
  $.mobile.hashListeningEnabled = false
  $.mobile.pushStateEnabled = false

  # Enable back buttons by default
  $.mobile.page.prototype.options.addBackBtn = true

This will add the back button, but since all the handlers are disabled, you need to redirect to the last page manually:

($('a[data-rel="back"]')).live('click', function() {
  window.history.back();
});

That will work. But sadly you won't see the default reverse direction for any back button. But it will be fixed by setting the $.mobile.forceReverse = true. So letting the application to use forward direction by default, and reverse for all the back buttons.

($('a[data-rel="back"]')).live('click', function() {
  $.mobile.forceReverse = true;
  window.history.back();
});

That change won't affect any other place than the Back buttons. And the variable is false by default.
I've included the Documentation changes too.

@mariozaizar mariozaizar Include `$.mobile.forceReverse` to be able to set the 'reverse' direc…
…tion, even when the link binding was disabled. Useful when you're using backbone & jquery mobile, so:

```
$.mobile.forceReverse = true;

($('a[data-rel="back"]')).live('click', function() {
  $.mobile.forceReverse = true;
  window.history.back();
});
```
b6b9a5e
Owner

arschmitz commented Aug 6, 2013

this is very old and there are conflicts will be happy to reopen and review if it is updated

arschmitz closed this Aug 6, 2013

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