From e83e4a968677853849733dfd173f9a57ae8f82bd Mon Sep 17 00:00:00 2001 From: bruncun Date: Tue, 14 Feb 2017 08:58:42 -0500 Subject: [PATCH] Add Turbolinks (#40) * Add turbolinks * Restructure scripts to work with Turbolinks * Replace manual turbo links asset with bower asset * Move JS back to footer to prevent Google PageSpeed penalty * Replace social onclick props with "_blank"-targeted links to prevent Turbolinks conflict * Add no opener no referrer to "_blank" links for security * Satisfy whitespace police * Revert share links and add turbo links compatibility --- _assets/javascripts/application.js | 33 +++++++++++++++++------------- _assets/javascripts/vendor.js | 1 + _layouts/post.html | 12 +++++------ bower.json | 3 ++- 4 files changed, 28 insertions(+), 21 deletions(-) diff --git a/_assets/javascripts/application.js b/_assets/javascripts/application.js index 803c9402b9529..2d0b54b2d99a0 100644 --- a/_assets/javascripts/application.js +++ b/_assets/javascripts/application.js @@ -1,20 +1,25 @@ //= require_self -// Initialize fluidbox - -$(function () { +$(document).on('turbolinks:load', function (event) { + // Initialize fluidbox $('.fluidbox-trigger').fluidbox(); -}) -// Initialize scrollreveal + // Track page views on Turbolinks + if (typeof ga === 'function') { + ga('set', 'location', event.data.url) + ga('send', 'pageview') + } -window.sr = ScrollReveal({ reset: true }); -sr.reveal('.reveal', { - distance: '0', - duration: 500, - easing: 'ease-in-out', - origin: 'top', - scale: 1, - reset: false, - viewFactor: 0 + // Initialize scrollreveal + sr.reveal('.reveal', { + distance: '0', + duration: 500, + easing: 'ease-in-out', + origin: 'top', + scale: 1, + reset: false, + viewFactor: 0 + }); }); + +window.sr = ScrollReveal({ reset: true }); diff --git a/_assets/javascripts/vendor.js b/_assets/javascripts/vendor.js index 820cf0e57436c..9798c80f56d35 100644 --- a/_assets/javascripts/vendor.js +++ b/_assets/javascripts/vendor.js @@ -2,4 +2,5 @@ //= require vendor/jquery-throttle-debounce.js //= require fluidbox //= require scrollreveal +//= require turbolinks5/dist/turbolinks.js //= require vendor/retina.js diff --git a/_layouts/post.html b/_layouts/post.html index 0a049ec150ff1..af6a8ad5d7747 100644 --- a/_layouts/post.html +++ b/_layouts/post.html @@ -38,14 +38,14 @@

{{ page.title }}

{% assign page_title = page.title | truncate '110' %} - - + + - - + + - - + +
diff --git a/bower.json b/bower.json index 28627b8743e02..21811219c9a95 100644 --- a/bower.json +++ b/bower.json @@ -3,6 +3,7 @@ "dependencies": { "jquery": "~3.1.1", "fluidbox": "~2.0.4", - "scrollreveal": "~3.3.2" + "scrollreveal": "~3.3.2", + "turbolinks5": "5.0.0" } }