Last active
December 27, 2015 10:18
-
-
Save MiguelMadero/7309675 to your computer and use it in GitHub Desktop.
Turbo Link Hack for CoffeeScript
This file contains 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
// stupid dirty hack until we get rid of turbolinks and its twisted tricks that break | |
// the web :() | |
(function() { | |
var hackForTurboLinks = function(App) { | |
var initialized, reset, rootElementSelector; | |
App.deferReadiness(); | |
rootElementSelector = App.rootElement; | |
initialized = false; | |
reset = function() { | |
if ($(rootElementSelector).length) { | |
initialized = true; | |
return App.reset(); // Designed for tests, but works for this hack too | |
} | |
}; | |
// page:load is needed on a clean browser refresh | |
// because turbolinks won't call page:change | |
$(document).one('page:load', function() { | |
if (!initialized) { | |
return reset(); | |
} | |
}); | |
return $(document).on('page:change', reset); | |
}; | |
hackForTurboLinks(App); | |
}).call(this); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment