views:

168

answers:

2

Hi All!

I'm using jQuery Address to load in my content, but it's doing it twice on the init. I set it up so that if you go to the main category it loads the first image, but it's doing it twice and I'm not sure how to stop it. A fresh pair of eyes would be appreciated!

$.address.init(function(event) {
    $('#carousel-clip a').address();
    if(!event.pathNames[0]) {
        var url = $('#carousel-clip ul li:first a').attr('href').replace('#!/','');
        $.address.path(url);
    }
}).change(function(event) { 
    if(event.pathNames[0]) {
        $.getJSON(location.pathname + 'image/' + event.pathNames[0] + '/', function(data, textStatus, XMLHttpRequest) { handler(data); });
    }
});

You can see it working here: http://bit.ly/cKftwA

Thanks!

Darren.

+2  A: 

I fixed it for me, it turns out document.ready() was running twice. Pretty stupid mistake ugh.

asperous.us
+3  A: 

The Problem is, that both $.address.path and the onHashChange-Event call the change-function directly. So $.address.path calls the change-function twice, since it changes the hash and therefore triggers an onHashChange-Event. You can circumvent this by replacing this:

$.address.path(url[1]);

with that:

window.location = window.location + '#' + url[1]; 

This is a bit dirty but it should work.

Baju