提交 4f9cb42b 编写于 作者: S Samy Pesse

Fix GitbookIO/gitbook#1312: don't use ajax navigation when page is not a valid gitbook page

上级 1fbcb406
......@@ -67,10 +67,7 @@ function handleNavigation(relativeUrl, push) {
prevUri = uri;
return loading.show($.get(uri)
.done(function (html) {
// Push url to history
if (push) history.pushState({ path: uri }, null, uri);
.then(function (html) {
// Replace html content
html = html.replace( /<(\/?)(html|head|body)([^>]*)>/ig, function(a,b,c,d){
return '<' + b + 'div' + ( b ? '' : ' data-element="' + c + '"' ) + d + '>';
......@@ -80,6 +77,20 @@ function handleNavigation(relativeUrl, push) {
var $pageHead = $page.find('[data-element=head]');
var $pageBody = $page.find('.book');
if ($pageBody.length === 0) {
return $.Deferred(function (deferred) {
var err = new Error('Invalid gitbook page, redirecting...');;
deferred.reject(err);
}).promise();
}
// Push url to history
if (push) {
history.pushState({
path: uri
}, null, uri);
}
// Merge heads
// !! Warning !!: we only update necessary portions to avoid strange behavior (page flickering etc ...)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册