Significant improvements to links

This commit is contained in:
Sashko Stubailo
2014-10-23 11:26:44 -07:00
parent c6c55c2e23
commit 9ad07f3ca9
2 changed files with 36 additions and 9 deletions

View File

@@ -363,6 +363,7 @@ ol {
}
@nav-width: 270px;
@top-bar-height: 50px;
/* default to no sidebar */
#nav {
@@ -377,9 +378,8 @@ ol {
.main-content {
position: absolute;
width: 100%;
top: 0;
top: @top-bar-height;
bottom: 0;
padding-top: 50px;
z-index: 1;
background: white;
overflow-y: scroll;
@@ -423,7 +423,7 @@ pre {
width: 100%;
top: 0;
left: 0;
height: 50px;
height: @top-bar-height;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.3);
z-index: 2;
margin-left: 0;
@@ -477,6 +477,7 @@ pre {
right: 0;
width: auto;
border-left: 1px solid #ccc;
top: 0;
}
#nav {

View File

@@ -1,13 +1,36 @@
var ignoreWaypoints = false;
var triggeredFromWaypoint = {};
Meteor.startup(function () {
setTimeout(function () {
$('.main-content [id]').waypoint(function() {
if (! ignoreWaypoints) {
triggeredFromWaypoint["#" + this.id] = true;
window.location.replace("#" + this.id);
}
}, { context: $('.main-content') });
}, 2000);
});
Tracker.autorun(function () {
// returns a "location" like object with all of the url parts
var current = Iron.Location.get();
// If the URL changes from a waypoint, do nothing
if (triggeredFromWaypoint[current.hash]) {
triggeredFromWaypoint[current.hash] = false;
return;
}
// If the URL changes, close the sidebar
Session.set("sidebarOpen", false);
// redirect routes with no trailing slash
if (current.path === "/basic") {
Iron.Location.go("/basic/");
window.location.replace("/basic/");
return;
} else if (current.path === "/full") {
Iron.Location.go("/full/");
window.location.replace("/full/");
return;
}
@@ -18,9 +41,9 @@ Tracker.autorun(function () {
} else {
if (current.hash) {
// XXX COMPAT WITH old docs
Iron.Location.go("/full/");
window.location.replace("/full/");
} else {
Iron.Location.go("/basic/");
window.location.replace("/basic/");
}
}
@@ -34,13 +57,16 @@ Tracker.autorun(function () {
} else {
var foundElement = $(current.hash);
if (foundElement.get(0)) {
targetLocation = $(".main-content").scrollTop() + foundElement.offset().top;
targetLocation = $(".main-content").scrollTop() + foundElement.offset().top - $(".main-content").offset().top - 10;
}
}
ignoreWaypoints = true;
$(".main-content").animate({
scrollTop: targetLocation
}, 1000);
}, 1000, function () {
ignoreWaypoints = false;
});
}, 0);
});
}