olivernn / davis.js

RESTful degradable JavaScript routing using pushState
http://davisjs.com
532 stars 58 forks source link

Clarify documentation #29

Open ghost opened 12 years ago

ghost commented 12 years ago

Hi

I'm trying to be successful with Davis.js. Two things are not clear to me:

  1. How to disable the default behavior?
    If I only write Davis() all links are being changed. E.g. when I click on one with href="about.html", it goes no longer to http://example.org/app/about.html, but instead happily goes to http://example.org/about.html.
  2. Is it possible to use Davis.js without jQuery?
olivernn commented 12 years ago

The default behaviour of Davis is to bind to all links and forms. If you had some links, or forms, on you page that you don't want Davis to bind to you can ignore them by changing the selector that Davis uses to find links etc.

Depending on your app you could either explicitly mark all the links you want Davis to bind to with a class or data attribute, or you could do so the other way round, explicitly marking all links you don't want Davis to bind to with a class or data attribute.

var app = Davis(function () {

  // your routes etc here

  this.configure(function () {
    this.linkSelector = 'a:not(.external)'   // if you want to explicitly mark external links
    this.linkSelector = 'a[data-davis=true]' // if you want to explicitly mark davis links
  })
})

This will make davis only listen to links that match those selectors, obviously you should choose whichever makes most sense for your app.

I have been working on allowing davis to be used without jQuery, this is currently not released but I can push the dev branch if you want to try it out. It should be possible to swap jQuery with Zepto with no changes required, if you want to use something different or no library at all then you will have to implement a few of the methods from jQuery or zepto that Davis relies on.

arxpoetica commented 11 years ago

This was helpful. It would be nice to have it more front and center in the documentation. :+1: