beezee / djax

Dynamic pjax, responds to layout changes across requested pages
http://beezee.github.com/djax.html
171 stars 27 forks source link

Reinitialize or Remove djax? #21

Open mattfordham opened 11 years ago

mattfordham commented 11 years ago

I am loading some content in via AJAX (not using djax). This content contains links that I'd like to have djax do its thing with. Is there are way to reinitialize or remove/add-back djax? If I just call the djax method a second time, all the events fire twice. Any ideas?

beezee commented 11 years ago

There's actually a small adjustment to the initialization code required to allow this to work simply, but will require some testing. I'll do my best to get to this shortly, but if you have time and interest, lines 197 to 201 would become something closer to this:

$(this).find('a').filter(function () {
        return this.hostname === location.hostname;
}).addClass('dJAX_internal')

$(this).on('click', '.dJAX_internal', function (event) {
        if (this.hostname !== location.hostname)
            return;
        event.preventDefault();
        return self.attachClick(this, event);
});

That should use delegated events to trigger djax nav on links with the dJAX_internal class, which means you can add that class to your links loaded in via ajax (not djax) and djax should pick them up. The extra conditional check to ensure the link is internal will prevent a mis-assigned class from breaking an external link.

Let me know if you get a chance to try this out, otherwise I'll update this thread when I get a chance to dig into it myself.

AdamWagner commented 11 years ago

Dealing with the same scenario. I changed the lines you suggested. Functions as desired so far! More testing needed. Thanks for posting the adjustment.

beezee commented 11 years ago

Glad to hear Adam and thanks for the update. Let me know if you run into any issues with this otherwise I'll try and get it into the master branch in the next few weeks

beezee commented 11 years ago

@AdamWagner do you have your changed copy up on Github? If so would be happy to merge a pull request

AdamWagner commented 11 years ago

No, but I'll branch + apply changes, then pull.

Adam Wagner Copilot

On Sunday, June 16, 2013 at 7:44 AM, beezee wrote:

@AdamWagner (https://github.com/AdamWagner) do you have your changed copy up on Github? If so would be happy to merge a pull request

— Reply to this email directly or view it on GitHub (https://github.com/beezee/djax/issues/21#issuecomment-19513222).