From 5ad847b113409d9cd2638a3e3880519dcf29d02e Mon Sep 17 00:00:00 2001 From: Adam Wathan Date: Thu, 16 Nov 2017 17:30:24 -0500 Subject: [PATCH 1/3] Replace state on initial page load so it's reloadable on popstate --- docs/source/_assets/js/nav.js | 7 +++++++ docs/source/_layouts/documentation.blade.php | 4 ++++ docs/source/_layouts/master.blade.php | 2 +- 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/docs/source/_assets/js/nav.js b/docs/source/_assets/js/nav.js index 4eb26411a..0f58a238b 100644 --- a/docs/source/_assets/js/nav.js +++ b/docs/source/_assets/js/nav.js @@ -1,4 +1,11 @@ $.when($.ready).then(function() { + window.history.replaceState({ + 'href': window.location.href, + 'title': $(document).filter('title').text(), + 'nav': $(document).find('#nav').html(), + 'content': $(document).find('#content').html() + }, '', window.location.href) + $('#nav').on('click', 'a', function (event) { // Allow opening links in new tabs diff --git a/docs/source/_layouts/documentation.blade.php b/docs/source/_layouts/documentation.blade.php index 720f144b8..e1d5936d4 100644 --- a/docs/source/_layouts/documentation.blade.php +++ b/docs/source/_layouts/documentation.blade.php @@ -14,6 +14,10 @@ @endsection +@push('headScripts') + +@endpush + @section('body')
- +
David Hemphill @davidhemphill From 3bc4631924e8e251eacd4895f6a5f3496f12c9f5 Mon Sep 17 00:00:00 2001 From: Adam Wathan Date: Fri, 17 Nov 2017 08:22:06 -0500 Subject: [PATCH 3/3] Only send Google Analytics data if analytics was loaded successfully Prevent errors in local environment and if people are using blockers. --- docs/source/_assets/js/nav.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/docs/source/_assets/js/nav.js b/docs/source/_assets/js/nav.js index 0f58a238b..bfb5a4617 100644 --- a/docs/source/_assets/js/nav.js +++ b/docs/source/_assets/js/nav.js @@ -52,8 +52,10 @@ $.when($.ready).then(function() { }, '', href) // Track on Google Analytics - ga('set', 'page', href) - ga('send', 'pageview') + if (typeof(ga) === 'function') { + ga('set', 'page', href) + ga('send', 'pageview') + } }) }) @@ -66,8 +68,10 @@ $.when($.ready).then(function() { $('#content').html(e.state.content) // Track on Google Analytics - ga('set', 'page', e.state.href) - ga('send', 'pageview') + if (typeof(ga) === 'function') { + ga('set', 'page', e.state.href) + ga('send', 'pageview') + } } }