Created
June 28, 2014 13:04
-
-
Save JonMidhir/2d7ebdad1b6dfe39bd98 to your computer and use it in GitHub Desktop.
From Part 1 of Rails: Building a single-page Backbone app without sacrificing Turbolinks. https://medium.com/p/3e22841cf834
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
window.MyApp = | |
Models: {} | |
Collections: {} | |
Views: {} | |
Routers: {} | |
initialize: -> | |
new MyApp.Routers.Items() | |
Backbone.history.start() | |
shouldLoadApp = -> $('#items').size() > 0 | |
$(document).on 'page:before-change', -> | |
if Backbone.History.started and Turbolinks?.supported | |
locHref = window.location.href | |
title = window.title | |
window.history.replaceState {turbolinks: true, url: locHref}, title, locHref | |
$(document).on 'page:change', -> | |
MyApp.initialize() if shouldLoadApp() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment