I am working on my website that allows people to post content (similar to a twitter) and am trying to make it more streamline via jQuery/Ajax. There is many categories that people can choose to post in and each is organized by the main category, or section if you will.
Every time a user clicks on a section in the navigation panel to the left, that item moves up to the top of the list and expands downward displaying all of the categories in that section. Another thing that happens is the main content area fades out and in with the new content (the user posts) belonging to that section and categories. This has been going great so far and looks awesome!
However, say you click on a section and category to see all of the posts in that specific category. Then you click on a post to go inside of the post and see all the information, comments, etc.. Now, you want to go back to where you were so you hit your back button. When doing this right now it is going back and displaying the main page details again, not the category you had previously selected to look through.
I have added the following code to display which category is select (example: "/#/community") and to also check the hash then fire the "click" event to trigger that category to be shown once again.
last_known_hash = location.hash;
window.setInterval(function() {
if(last_known_hash != location.hash) {
$('#categories-panel a[name="'+ location.hash.substring(2) +'"]').click();
last_known_hash = location.hash;
}
}, 500);
Upon clicking back it does still show the "#/community" in the URL, however it does not fire the click. This is odd because if you type in the "#/community" into the URL it does work properly. So I am not really sure on why it's not being triggered properly on clicking "back". I'm not sure if this is the best/right way to go about doing this, but it's all I could think of at the moment. Maybe do a session instead? As always, any help would be appreciated :)
P.S. I know the click event works on it's own as when I run it in firebug it works perfectly.
SUMMARY: When someone clicks "back" in their browser, I need it to go to where they were last, Example: sitehere.com/#/community - and then fire a click event to display the "community" category content once again.