diff options
author | Samy Pessé <samypesse@gmail.com> | 2014-04-14 16:16:34 +0200 |
---|---|---|
committer | Samy Pessé <samypesse@gmail.com> | 2014-04-14 16:16:34 +0200 |
commit | 8c4cfed6092f69df81e1999944638595e03edb9c (patch) | |
tree | d813d0a6600beed2aeff367aac374d81c895a51c /theme/javascript/core/navigation.js | |
parent | 1ff7e88cea6b33cb403ce9cc0450a0a326fb1998 (diff) | |
download | gitbook-8c4cfed6092f69df81e1999944638595e03edb9c.zip gitbook-8c4cfed6092f69df81e1999944638595e03edb9c.tar.gz gitbook-8c4cfed6092f69df81e1999944638595e03edb9c.tar.bz2 |
Add complete refresh of head and body on page navigation
Diffstat (limited to 'theme/javascript/core/navigation.js')
-rwxr-xr-x | theme/javascript/core/navigation.js | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/theme/javascript/core/navigation.js b/theme/javascript/core/navigation.js index 6e775cf..2a6d1df 100755 --- a/theme/javascript/core/navigation.js +++ b/theme/javascript/core/navigation.js @@ -17,15 +17,19 @@ define([ return } - console.log("load url", url); return $.get(url) - .done(function (data) { - var $newPage = $(data); - var title = data.match("<title>(.*?)</title>")[1]; - - $('title').text(title); - $('.book-body').html($newPage.find('.book-body').html()); - $('.book-summary').html($newPage.find('.book-summary').html()); + .done(function (html) { + html = html.replace( /<(\/?)(html|head|body)([^>]*)>/ig, function(a,b,c,d){ + return '<' + b + 'div' + ( b ? '' : ' data-element="' + c + '"' ) + d + '>'; + }); + + var $page = $(html); + var $pageHead = $page.find("[data-element=head]"); + + $("head").html($pageHead.html()); + $('.book-header').html($page.find('.book-header').html()); + $('.book-body').html($page.find('.book-body').html()); + $('.book-summary').html($page.find('.book-summary').html()); if (push) updateHistory(url, null); preparePage(); |