Skip to content

Commit f2f7fef

Browse files
committed
Handle edge case where a page doesn’t have a nav
If a page is loaded and it doesn’t have a nav, then we won’t try to replace the current nav.
1 parent 99e4031 commit f2f7fef

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

static/canjs.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ var $articleContainer,
7575
setInterval(function() {
7676
toggleNav();
7777
}, 200);
78-
78+
7979
scrollToCurrentMenuItem();
8080
})();
8181

@@ -216,9 +216,9 @@ function navigate(href, updateLocation) {
216216
return xhr;
217217
},
218218
success: function(content) {
219-
219+
220220
if(updateLocation !== false){
221-
window.history.pushState(null, null, href);
221+
window.history.pushState(null, null, href);
222222
}
223223

224224
// Google Analytics
@@ -241,10 +241,12 @@ function navigate(href, updateLocation) {
241241

242242
//if any page doesn't have a nav, replacing it won't work,
243243
//and the nav will be gone for any subsequent page visits
244-
if($navReplace && $navReplace.length){
245-
$navReplace.replaceWith($nav);
246-
}else{
247-
$(".bottom-left").append($nav);
244+
if ($nav && $nav.length) {
245+
if ($navReplace && $navReplace.length) {
246+
$navReplace.replaceWith($nav);
247+
} else {
248+
$(".bottom-left").append($nav);
249+
}
248250
}
249251
$("article").replaceWith($article);
250252
$(".breadcrumb").replaceWith($breadcrumb);
@@ -496,4 +498,4 @@ function buildTOC() {
496498

497499
toc += Array(level - baseLevel + 1).join('</li></ol>') + "</li></ol>";
498500
$tableOfContents.append(toc);
499-
}
501+
}

0 commit comments

Comments
 (0)