From c6c55c2e231d613cf4bf40526174cc968e9f45af Mon Sep 17 00:00:00 2001 From: Sashko Stubailo Date: Thu, 23 Oct 2014 11:00:01 -0700 Subject: [PATCH] Links are doing pretty well! --- docs/client/layout.js | 2 +- docs/client/links.js | 44 +++++++++++++++++++++++++++++++------------ 2 files changed, 33 insertions(+), 13 deletions(-) diff --git a/docs/client/layout.js b/docs/client/layout.js index 72c159f086..b5736b426f 100644 --- a/docs/client/layout.js +++ b/docs/client/layout.js @@ -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/"); } }); diff --git a/docs/client/links.js b/docs/client/links.js index f80ce42c43..b8f80f6ce8 100644 --- a/docs/client/links.js +++ b/docs/client/links.js @@ -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); + }); + } }); \ No newline at end of file