From ecf486b5084424df71a44c77a195c8acba18feed Mon Sep 17 00:00:00 2001 From: Jonathan Reinink Date: Thu, 26 Oct 2017 08:43:30 -0400 Subject: [PATCH] Integrate poor man's Turbolinks with Vue --- docs/source/_layouts/master.blade.php | 76 ++++----------------------- docs/source/js/nav.js | 55 +++++++++++++++++++ 2 files changed, 64 insertions(+), 67 deletions(-) create mode 100644 docs/source/js/nav.js diff --git a/docs/source/_layouts/master.blade.php b/docs/source/_layouts/master.blade.php index ff1d8cb7e..cba9cb55a 100644 --- a/docs/source/_layouts/master.blade.php +++ b/docs/source/_layouts/master.blade.php @@ -14,73 +14,12 @@ {{-- --}} - - - if (event.metaKey) { - return - } - - // Prevent following link - event.preventDefault() - - // Get desired link - var href = $(this).attr('href') - - // Make Ajax request to get the page content - $.ajax({ - method: 'GET', - url: href, - cache: false, - dataType: 'html', - }).done(function(html) { - - // Parse the HTML response - var title = $(html).filter('title').text() - var nav = $(html).find('.nav').html() - var content = $(html).find('.content').html() - - // Update the page - $('title').text(title) - $('.nav').html(nav) - $('.content').html(content) - - // Rerun PrismJS - Prism.highlightAll(); - - // Scroll to the top of the page - $(document).scrollTop(0) - - // Add page load to brower history - window.history.pushState({ - "title": title, - "nav": $(html).find('.nav').html(), - "content": $(html).find('.content').html() - }, '', href) - }) - }) - - // Load page history (for back/forward nav) - window.onpopstate = function(e) { - if(e.state){ - - // Update the page - $('title').text(e.state.title) - $('.nav').html(e.state.nav) - $('.content').html(e.state.content) - - // Rerun PrismJS - Prism.highlightAll(); - } - }; - }); - -
+
@@ -97,7 +36,7 @@
-
-
- @yield('body') +
+
+ @yield('body') +
+ +
- diff --git a/docs/source/js/nav.js b/docs/source/js/nav.js new file mode 100644 index 000000000..c47e73e1f --- /dev/null +++ b/docs/source/js/nav.js @@ -0,0 +1,55 @@ +$.when($.ready).then(function() { + $('#nav').on('click', 'a', function (event) { + + // Allow opening links in new tabs + if (event.metaKey) { + return + } + + // Prevent following link + event.preventDefault() + + // Get desired link + var href = $(this).attr('href') + + // Make Ajax request to get the page content + $.ajax({ + method: 'GET', + url: href, + cache: false, + dataType: 'html', + }).done(function(html) { + + // Parse the HTML response + var title = $(html).filter('title').text() + var nav = $(html).find('#nav').html() + var content = $(html).find('#content').html() + + // Update the page + $('title').text(title) + $('#nav').html(nav) + $('#content').html(content) + + // Scroll to the top of the page + $(document).scrollTop(0) + + // Add page load to brower history + window.history.pushState({ + "title": title, + "nav": $(html).find('#nav').html(), + "content": $(html).find('#content').html() + }, '', href) + }) + }) + + // Load page history (for back/forward nav) + window.onpopstate = function(e) { + if(e.state){ + + // Update the page + $('title').text(e.state.title) + $('#nav').html(e.state.nav) + $('#content').html(e.state.content) + } + } +})