diff options
Diffstat (limited to 'theme/javascript/core/navigation.js')
-rwxr-xr-x | theme/javascript/core/navigation.js | 76 |
1 files changed, 48 insertions, 28 deletions
diff --git a/theme/javascript/core/navigation.js b/theme/javascript/core/navigation.js index 853950d..747bd03 100755 --- a/theme/javascript/core/navigation.js +++ b/theme/javascript/core/navigation.js @@ -1,38 +1,23 @@ define([ "jQuery", - "core/progress" -], function($, progress) { + "core/progress", + "core/exercise", + "core/quiz" +], function($, progress, exercises, quiz) { var prev, next; - // Prevent cache so that using the back button works - // See: http://stackoverflow.com/a/15805399/983070 - $.ajaxSetup({ - cache: false - }); - - // Recreate first page when the page loads. - history.replaceState({ path: window.location.href }, ''); - - // Back Button Hijacking :( - window.onpopstate = function (event) { - if (event.state === null) { - return; - } - - return handleNavigation(event.state.path, false); - }; - - function updateHistory (url, title) { + var updateHistory = function(url, title) { history.pushState({ path: url }, title, url); - } + }; - function handleNavigation (url, push) { + var handleNavigation = function(url, push) { if (typeof history.pushState === "undefined") { // Refresh the page to the new URL if pushState not supported location.href = url; return } + console.log("load url", url); return $.get(url) .done(function (data) { var $newPage = $(data); @@ -43,12 +28,21 @@ define([ $('.book-summary').html($newPage.find('.book-summary').html()); if (push) updateHistory(url, null); - progress.show(); + preparePage(); }) .fail(function () { location.href = url; }); - } + }; + + var preparePage = function() { + // Bind exercises/quiz + exercises.init(); + quiz.init(); + + // Show progress + progress.show(); + }; var handlePagination = function (e) { e.stopPropagation(); @@ -68,11 +62,37 @@ define([ if (url) handleNavigation(url, true); }; - $(document).on('click', ".navigation-prev", handlePagination); - $(document).on('click', ".navigation-next", handlePagination); - $(document).on('click', ".summary [data-path] a", handlePagination); + + + var init = function() { + // Prevent cache so that using the back button works + // See: http://stackoverflow.com/a/15805399/983070 + $.ajaxSetup({ + cache: false + }); + + // Recreate first page when the page loads. + history.replaceState({ path: window.location.href }, ''); + + // Back Button Hijacking :( + window.onpopstate = function (event) { + if (event.state === null) { + return; + } + + return handleNavigation(event.state.path, false); + }; + + $(document).on('click', ".navigation-prev", handlePagination); + $(document).on('click', ".navigation-next", handlePagination); + $(document).on('click', ".summary [data-path] a", handlePagination); + + // Prepare current page + preparePage(); + }; return { + init: init, goNext: goNext, goPrev: goPrev }; |