PageChangeWithTurbolinks

February 14, 2013
Rails 4 Turbolinks will mess with any Javascript hooking into the document/window ready event. This isn't news to those paying attention, but I wasn't until I ran across it while overhauling my site and my wiki (ClWiki) that runs it. There's an easy solution, however. Turbolinks provides some custom events that you can hook your ready code into. In my case, I had some Javascript to control element focus while searching the wiki and merely had to add one line:

$(document).ready(findFocus);
$(document).on('page:change', findFocus);


comments powered by Disqus