Skip to content

Commit

Permalink
Add Turbolinks (barryclark#40)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
bruncun authored and nielsenramon committed Feb 14, 2017
1 parent 99dff42 commit e83e4a9
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 21 deletions.
33 changes: 19 additions & 14 deletions _assets/javascripts/application.js
Original file line number Diff line number Diff line change
@@ -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 });
1 change: 1 addition & 0 deletions _assets/javascripts/vendor.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
//= require vendor/jquery-throttle-debounce.js
//= require fluidbox
//= require scrollreveal
//= require turbolinks5/dist/turbolinks.js
//= require vendor/retina.js
12 changes: 6 additions & 6 deletions _layouts/post.html
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,14 @@ <h1>{{ page.title }}</h1>

<div class="article-share">
{% assign page_title = page.title | truncate '110' %}
<a href="" title="Share on Twitter" onclick="window.open('https://twitter.com/home?status={{ page_title }} - {{ page.url | absolute_url }} {% if site.social.twitter %}by @{{ site.social.twitter }}{% endif %}', 'newwindow', 'width=500, height=225'); return false;">
<span class="icon icon-social-twitter"></span>
<a href="" title="Share on Twitter" onclick="window.open('https://twitter.com/home?status={{ page_title }} - {{ page.url | absolute_url }} {% if site.social.twitter %}by @{{ site.social.twitter }}{% endif %}', 'newwindow', 'width=500, height=225'); return false;" data-turbolinks="false">
<svg enable-background="new 0 0 128 128" width="15px" version="1.1" viewBox="0 0 128 128" xml:space="preserve" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"><g id="_x37__stroke"><g id="Twitter"><rect clip-rule="evenodd" fill="none" fill-rule="evenodd" height="128" width="128"/><path clip-rule="evenodd" d="M128,23.294 c-4.703,2.142-9.767,3.59-15.079,4.237c5.424-3.328,9.587-8.606,11.548-14.892c-5.079,3.082-10.691,5.324-16.687,6.526 c-4.778-5.231-11.608-8.498-19.166-8.498c-14.493,0-26.251,12.057-26.251,26.927c0,2.111,0.225,4.16,0.676,6.133 C41.217,42.601,21.871,31.892,8.91,15.582c-2.261,3.991-3.554,8.621-3.554,13.552c0,9.338,4.636,17.581,11.683,22.412 c-4.297-0.131-8.355-1.356-11.901-3.359v0.331c0,13.051,9.053,23.937,21.074,26.403c-2.201,0.632-4.523,0.948-6.92,0.948 c-1.69,0-3.343-0.162-4.944-0.478c3.343,10.694,13.035,18.483,24.53,18.691c-8.986,7.227-20.315,11.533-32.614,11.533 c-2.119,0-4.215-0.123-6.266-0.37c11.623,7.627,25.432,12.088,40.255,12.088c48.309,0,74.717-41.026,74.717-76.612 c0-1.171-0.023-2.342-0.068-3.49C120.036,33.433,124.491,28.695,128,23.294" fill-rule="evenodd" id="Twitter_1_"/></g></g></svg>
</a>
<a href="" title="Share on Facebook" onclick="window.open('https://www.facebook.com/sharer/sharer.php?u={{ page.url | absolute_url }}', 'newwindow', 'width=500, height=500'); return false;">
<span class="icon icon-social-facebook"></span>
<a href="" title="Share on Facebook" onclick="window.open('https://www.facebook.com/sharer/sharer.php?u={{ page.url | absolute_url }}', 'newwindow', 'width=500, height=500'); return false;" data-turbolinks="false">
<svg enable-background="new 0 0 128 128" width="15px" version="1.1" viewBox="0 0 128 128" xml:space="preserve" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"><g id="_x31__stroke"><g id="Facebook_1_"><rect fill="none" height="128" width="128"/><path clip-rule="evenodd" d="M68.369,128H7.065C3.162,128,0,124.836,0,120.935 V7.065C0,3.162,3.162,0,7.065,0h113.871C124.837,0,128,3.162,128,7.065v113.87c0,3.902-3.163,7.065-7.064,7.065H88.318V78.431 h16.638l2.491-19.318H88.318V46.78c0-5.593,1.553-9.404,9.573-9.404l10.229-0.004V20.094c-1.769-0.235-7.841-0.761-14.906-0.761 c-14.749,0-24.846,9.003-24.846,25.535v14.246H51.688v19.318h16.681V128z" fill-rule="evenodd" id="Facebook"/></g></g></svg>
</a>
<a href="" title="Share on Google+" onclick="window.open('https://plus.google.com/share?url={{ page.url | absolute_url }}', 'newwindow', 'width=550, height=400'); return false;">
<span class="icon icon-social-googleplus"></span>
<a href="" title="Share on Google+" onclick="window.open('https://plus.google.com/share?url={{ page.url | absolute_url }}', 'newwindow', 'width=550, height=400'); return false;" data-turbolinks="false">
<svg enable-background="new 0 0 128 128" version="1.1" viewBox="0 0 128 128" width="15px" xml:space="preserve" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"><g id="_x35__stroke"><g id="Google_Plus"><rect clip-rule="evenodd" fill="none" fill-rule="evenodd" height="128" width="128"/><path clip-rule="evenodd" d="M40.654,55.935v16.13 c0,0,15.619-0.021,21.979-0.021C59.189,82.5,53.834,88.194,40.654,88.194c-13.338,0-23.748-10.832-23.748-24.194 s10.41-24.194,23.748-24.194c7.052,0,11.607,2.483,15.784,5.944c3.344-3.35,3.065-3.828,11.573-11.877 c-7.222-6.586-16.822-10.6-27.357-10.6C18.201,23.273,0,41.507,0,64c0,22.493,18.201,40.727,40.654,40.727 c33.561,0,41.763-29.275,39.044-48.792H40.654z M113.912,56.742V42.628h-10.063v14.113H89.358v10.081h14.491v14.517h10.063V66.823 H128V56.742H113.912z" fill-rule="evenodd" id="Google_Plus_1_"/></g></g></svg>
</a>
</div>

Expand Down
3 changes: 2 additions & 1 deletion bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}

0 comments on commit e83e4a9

Please sign in to comment.