Links are doing pretty well!

This commit is contained in:
Sashko Stubailo
2014-10-23 11:00:01 -07:00
parent ae7a0c6bb0
commit c6c55c2e23
2 changed files with 33 additions and 13 deletions

View File

@@ -5,7 +5,7 @@ Template.registerHelper("fullApi", function () {
Template.basicOrFullSelect.events({
"change .basic-or-full": function (event) {
Session.set("fullApi", event.target.value === "full");
Iron.Location.go(Session.equals("fullApi", true) ? "/full" : "/basic");
Iron.Location.go(Session.equals("fullApi", true) ? "/full/" : "/basic/");
}
});

View File

@@ -2,26 +2,46 @@ Tracker.autorun(function () {
// returns a "location" like object with all of the url parts
var current = Iron.Location.get();
console.log(current);
// redirect routes with no trailing slash
if (current.path === "/basic") {
Session.set("fullApi", false);
Iron.Location.go("/basic/");
return;
} else if (current.path === "/full") {
Iron.Location.go("/full/");
return;
}
if (current.path === "/basic/") {
Session.set("fullApi", false);
} else if (current.path === "/full/") {
Session.set("fullApi", true);
} else {
if (current.hash) {
// XXX COMPAT WITH old docs
Iron.Location.go("/full");
Iron.Location.go("/full/");
} else {
Iron.Location.go("/basic");
Iron.Location.go("/basic/");
}
}
Tracker.afterFlush(function () {
setTimeout(function () {
console.log($(".main-content").offset(), $(current.hash).offset());
$(".main-content").animate({
scrollTop: $(".main-content").scrollTop() + $(current.hash).offset().top
}, 1000);
}, 0);
});
if (current.hash) {
Tracker.afterFlush(function () {
setTimeout(function () {
var targetLocation;
if (current.hash === "#top") {
targetLocation = 0;
} else {
var foundElement = $(current.hash);
if (foundElement.get(0)) {
targetLocation = $(".main-content").scrollTop() + foundElement.offset().top;
}
}
$(".main-content").animate({
scrollTop: targetLocation
}, 1000);
}, 0);
});
}
});