Do you like Turbolinks? It's easy and fast way to improve user experience of surfing on your website.
But if you have a large codebase with lots of $(el).bind(...) Turbolinks will surprise you. Most part of your JavaScripts will stop working in usual way. It's because the nodes on which you bind events no longer exist.
I wrote jquery.turbolinks to solve this problem in my project. It's easy to use: just require it immediately after jquery.js. Your other scripts should be loaded after jquery.turbolinks.js, and turbolinks.js should be after your other scripts.
Sponsored by Evil Martians.
This project is a member of the OSS Manifesto.
Gemfile:
gem 'jquery-turbolinks'JavaScript manifest file:
//= require jquery.turbolinksAnd it just works!
By default ready function is bound to page:load event.
If you want to change it use $.setReadyEvent function:
$.setReadyEvent('page:change');By default right after trigger page:fetch $.isReady is set to false. And after page:load is set to true.
If you want to change default behaviour you can use $.setFetchEvent:
$.setReadyEvent('custom_loading_event');This project uses Semantic Versioning for release numbering.
- Set $.isReady to false after
page:fetch#6; - add
$.setFetchEventfunction; - remove all delegated events after trigger fetch event #8.
- Add turbolinks as dependency (kudos to @gbchaosmaster);
- run callback after adding to waiting list if
$.isReady#6.
- Pass jQuery object to each callback #4
- Change event:
page:change->page:load(kudos to @davydotcom); - added ability to change ready event via
$.setReadyEvent
- First, initial release
Idea and code by @kossnocorp.