From ae9aecc2ab4168c1c11c8e8ff701528fb1ff841b Mon Sep 17 00:00:00 2001 From: Andrew Tomaka Date: Fri, 7 Mar 2014 02:08:41 -0500 Subject: [PATCH] Deal with turbolinks $document().ready is only called when the DOM completes loading. Since turbolinks loads new data into the DOM without completely reloading, the ready event is never fired. We can account for this by using the page:load event. --- app/assets/javascripts/pastes.js.coffee | 4 ++-- app/views/pastes/_form.html.erb | 2 +- app/views/pastes/show.html.erb | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/assets/javascripts/pastes.js.coffee b/app/assets/javascripts/pastes.js.coffee index b40f467..cf33fea 100644 --- a/app/assets/javascripts/pastes.js.coffee +++ b/app/assets/javascripts/pastes.js.coffee @@ -1,6 +1,6 @@ # Place all the behaviors and hooks related to the matching controller here. # All this logic will automatically be available in application.js. # You can use CoffeeScript in this file: http://coffeescript.org/ -$(document).ready -> - $("pre code").each (i, e) -> +$(document).on 'ready page:load', -> + $(".highlight pre code").each (i, e) -> hljs.highlightBlock e diff --git a/app/views/pastes/_form.html.erb b/app/views/pastes/_form.html.erb index 51d6578..fd7cde4 100644 --- a/app/views/pastes/_form.html.erb +++ b/app/views/pastes/_form.html.erb @@ -1,7 +1,7 @@ <%= form_for @paste do |f| %>
<%= f.label :content %> - <%= f.text_area :content, class: 'form-control' %> + <%= f.text_area :content, class: 'form-control', rows: 15 %>
<%= f.submit 'Paste it!', class: 'btn btn-primary' %> <% end %> diff --git a/app/views/pastes/show.html.erb b/app/views/pastes/show.html.erb index bd35c5c..c9f47c5 100644 --- a/app/views/pastes/show.html.erb +++ b/app/views/pastes/show.html.erb @@ -1 +1 @@ -
<%= @paste.content %>
+
<%= @paste.content %>