From 9ad07f3ca9845895beb6334530245177ee4cb2e0 Mon Sep 17 00:00:00 2001 From: Sashko Stubailo Date: Thu, 23 Oct 2014 11:26:44 -0700 Subject: [PATCH] Significant improvements to links --- docs/client/docs.less | 7 ++++--- docs/client/links.js | 38 ++++++++++++++++++++++++++++++++------ 2 files changed, 36 insertions(+), 9 deletions(-) diff --git a/docs/client/docs.less b/docs/client/docs.less index e1a734b072..d6b8e91f85 100644 --- a/docs/client/docs.less +++ b/docs/client/docs.less @@ -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 { diff --git a/docs/client/links.js b/docs/client/links.js index b8f80f6ce8..40bf5e9197 100644 --- a/docs/client/links.js +++ b/docs/client/links.js @@ -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); }); }