mirror of
https://github.com/meteor/meteor.git
synced 2026-05-02 03:01:46 -04:00
Links are doing pretty well!
This commit is contained in:
@@ -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/");
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user