Reputation: 6577
I try to detect how the user got to the route. There are 3 cases I guess:
Is there any way to detect the 3 cases or - which would be enough for me - to detect if the user came to the route by the 2nd case ?
Why ? In my project I have a List-Layout. When I am scrolling down and clicking on a Link in this List the new Template will be rendered but the window has now a scrollTop Value because of the scrolling in the list.
I fixed this with this:
Router.configure({
onAfterAction : function () {
jQuery(window).scrollTop(0);
}
});
With this fix after every page load the page will be scrolled to the top (like its normal).
But:
When I clicked on a link in the list and then I click on the "Back" button in my Browser (history.back) the page will also be scrolled to the top (because of my fix) - without the fix the page will be automatically jump to the last position.
Because of this I need something like this:
Router.configure({
onAfterAction : function () {
var historyBack;
historyBack = CheckIfHistoryBackWasClicked();
if (!historyBack) jQuery(window).scrollTop(0);
}
});
Anyone any idea ?
Upvotes: 1
Views: 320
Reputation: 941
Try to add a click
event handler to your links and set a scrollToTop
session variable there:
"click a": function(e) {
Session.set("scrollToTop", true);
return true;
}
Then, do something like this:
Router.configure({
onAfterAction : function () {
if (Session.get("scrollToTop") == true) {
jQuery(window).scrollTop(0);
Session.set("scrollToTop", false);
}
}
});
Upvotes: 1