Created
December 14, 2012 22:08
-
-
Save denniskuczynski/4289111 to your computer and use it in GitHub Desktop.
Script to allow MiniProfiler to work with Rails using the Turbolinks gem
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
# Store detached versions of body tags inserted by MiniProfiler when fetching a new page with Turbolinks | |
storeMiniProfileBodyTags =-> | |
if $('#mini-profiler').length and not window.MiniProfileBodyTags | |
window.MiniProfileBodyTags = {} | |
window.MiniProfileBodyTags.Container = $('.profiler-results').detach() | |
window.MiniProfileBodyTags.Templates = $('script[type="text/x-jquery-tmpl"]').detach() | |
# Copy detached tags back into the body when changing pages with Turbolinks | |
migrateMiniProfileBodyTags =-> | |
if window.MiniProfileBodyTags | |
$body = $('body') | |
$body.append(window.MiniProfileBodyTags.Container) | |
$body.append(window.MiniProfileBodyTags.Templates) | |
# doc.ready init | |
$ -> | |
$(document).bind('page:change', migrateMiniProfileBodyTags) | |
$(document).bind('page:fetch', storeMiniProfileBodyTags) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment