Trying really hard to understand jQuery BBQ and not doing so well. There are a few things I need to figure out, but I'll try to focus this on what I believe is the most important in hopes that knocking that part out will guide me to solving the others.
I've got a page with three sections that are each hidden. When a user clicks a nav link, the corresponding section expands and others (if active) are hidden. The URL is updated with a hash representing the page. So localhost
becomes localhost/#work
. In my code, this works correctly.
Within the #work
section, there are multiple thumbnails that correspond to different videos and I'm trying to add values into the URL to allow bookmarking and other love, hence using jQuery BBQ. This sort of works, there's a minor issue of the url becoming ugly. localhost
becomes localhost/#work=&misery=
. Ugly, but it is updated correctly (and the section stays open as intended).
Here's the goods:
When a hashchange
event occurs, my super duper hash-bash function runs and checks the URL for the hash value, then opens the appropriate section. How, using jQuery BBQ's .getState()
method, can I pull the videos value from the URL and then click on that thumbnail?
Thanks so much, I know that was long winded but I want to be as clear and descriptive as possible. Please find a jsFiddle below (though I can't get the hashes to show up at all in that environment... ugh!) as well as the raw code.
http://jsfiddle.net/danielredwood/n2KWv/2/
JavaScript:
function navi(){
var hash = window.location.hash,
hspl = hash.split('=')[0],
acti = $('.out')
test = $.bbq.getState();
console.log(test);
if (!$('body').hasClass('work')){
acti.removeClass('out').slideUp(400);
$(hash).addClass('out').slideDown(400);
} else {
if (hspl != '#work') {
$('body').removeClass('work');
acti.removeClass('out').slideUp(400);
$(hash).addClass('out').slideDown(400);
}
}
}
/* Nav */
$(window).bind('hashchange', function(){
navi();
});
/* Thumbnail Clicks */
$('.thumbnail a').click(function(){
$('body').addClass('work');
var name = $(this).attr('id');
$.bbq.pushState(name);
return false;
});