diff options
Diffstat (limited to 'theme/javascript/core/navigation.js')
-rwxr-xr-x | theme/javascript/core/navigation.js | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/theme/javascript/core/navigation.js b/theme/javascript/core/navigation.js index 84445b4..8f8b0a6 100755 --- a/theme/javascript/core/navigation.js +++ b/theme/javascript/core/navigation.js @@ -1,21 +1,23 @@ define([ "jQuery", - "utils/analytic", + "core/events", "core/state", "core/search", "core/progress", "core/exercise", "core/quiz" -], function($, analytic, state, search, progress, exercises, quiz) { +], function($, events, state, search, progress, exercises, quiz) { var prev, next; var githubCountStars, githubCountWatch; + var usePushState = !navigator.userAgent.match('CriOS') && (typeof history.pushState !== "undefined"); + var updateHistory = function(url, title) { history.pushState({ path: url }, title, url); }; var handleNavigation = function(url, push) { - if (typeof history.pushState === "undefined") { + if (!usePushState) { // Refresh the page to the new URL if pushState not supported location.href = url; return @@ -23,6 +25,8 @@ define([ return $.get(url) .done(function (html) { + if (push) updateHistory(url, null); + html = html.replace( /<(\/?)(html|head|body)([^>]*)>/ig, function(a,b,c,d){ return '<' + b + 'div' + ( b ? '' : ' data-element="' + c + '"' ) + d + '>'; }); @@ -48,9 +52,7 @@ define([ $('.book-summary .summary').scrollTop(scrollPosition); // Update state - state.update($page); - - if (push) updateHistory(url, null); + state.update($("html")); preparePage(); }) .fail(function () { @@ -108,7 +110,7 @@ define([ } // Send to mixpanel - analytic.track("page.view"); + events.trigger("page.change"); }; var handlePagination = function (e) { |