Last active
December 15, 2015 19:08
-
-
Save rstacruz/5308599 to your computer and use it in GitHub Desktop.
Simpler refactor of jQuery.Turbolinks
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
# Simpler refactor of jQuery.Turbolinks | |
# https://github.com/kossnocorp/jquery.turbolinks/blob/master/src/jquery.turbolinks.coffee | |
# https://github.com/kossnocorp/jquery.turbolinks | |
$ = window.jQuery or require?('jquery') | |
$document = $(document) | |
# Trigger the stored `ready` events on first load. | |
$ -> $document.trigger 'turbo:ready' | |
# Override `$(function)` and `$(document).ready(function)` by | |
# registering callbacks under a new event called `turbo:ready`. | |
$.fn.ready = (callback) -> | |
$document.on 'turbo:ready', callback | |
# Hook onto the events that Turbolinks triggers. | |
$document.on 'page:load.turbo', -> | |
$.isReady = true | |
$document.trigger 'turbo:ready' | |
$document.on 'page:fetch.turbo', -> | |
$.isReady = false |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment