diff options
author | Samy Pessé <samypesse@gmail.com> | 2014-05-01 14:05:14 +0200 |
---|---|---|
committer | Samy Pessé <samypesse@gmail.com> | 2014-05-01 14:05:14 +0200 |
commit | c2ea126c5fa634b3a8f8a5f6cf61749c4d2585ad (patch) | |
tree | 6ee16acced3d0f88c00a81ec9068c58b3e79b1ba /theme/javascript/core | |
parent | b668dba4791a93e04c7c220e3ae1bfcfd04166e5 (diff) | |
download | gitbook-c2ea126c5fa634b3a8f8a5f6cf61749c4d2585ad.zip gitbook-c2ea126c5fa634b3a8f8a5f6cf61749c4d2585ad.tar.gz gitbook-c2ea126c5fa634b3a8f8a5f6cf61749c4d2585ad.tar.bz2 |
Fix #182: Replace all book body when page changes
Diffstat (limited to 'theme/javascript/core')
-rwxr-xr-x | theme/javascript/core/navigation.js | 17 |
1 files changed, 8 insertions, 9 deletions
diff --git a/theme/javascript/core/navigation.js b/theme/javascript/core/navigation.js index e614392..7eac392 100755 --- a/theme/javascript/core/navigation.js +++ b/theme/javascript/core/navigation.js @@ -28,7 +28,7 @@ define([ .done(function (html) { // Push url to history if (push) history.pushState({ path: url }, null, url); - + // Replace html content html = html.replace( /<(\/?)(html|head|body)([^>]*)>/ig, function(a,b,c,d){ return '<' + b + 'div' + ( b ? '' : ' data-element="' + c + '"' ) + d + '>'; @@ -36,6 +36,7 @@ define([ var $page = $(html); var $pageHead = $page.find("[data-element=head]"); + var $pageBody = $page.find('.book'); // Merge heads var headContent = $pageHead.html() @@ -45,13 +46,11 @@ define([ }); $("head").html(headContent); - // Update header, body - $('.book-header').html($page.find('.book-header').html()); - $('.book-body').html($page.find('.book-body').html()); - - // Update summary + // Merge body var scrollPosition = $('.book-summary .summary').scrollTop(); - $('.book-summary').html($page.find('.book-summary').html()); + $pageBody.toggleClass("with-summary", $(".book").hasClass("with-summary")) + + $(".book").replaceWith($pageBody); $('.book-summary .summary').scrollTop(scrollPosition); // Update state @@ -134,7 +133,7 @@ define([ if (url) handleNavigation(url, true); }; - + var init = function() { // Prevent cache so that using the back button works @@ -157,7 +156,7 @@ define([ $(document).on('click', ".navigation-prev", handlePagination); $(document).on('click', ".navigation-next", handlePagination); $(document).on('click', ".summary [data-path] a", handlePagination); - + $(window).resize(updateNavigationPosition); // Prepare current page |