thybag / PJAX-Standalone

A standalone implementation of Pushstate AJAX, for non-jquery webpages.
203 stars 42 forks source link

Pass the url of the <a> that was clicked into event callbacks #6

Closed JonDum closed 10 years ago

JonDum commented 10 years ago

I found myself wanting to load a specific script with requirejs for certain pages, but I couldn't do this before because pjax wouldn't pass the url that was clicked into the event callbacks.

Now, you can do this just by using beforeSend or complete or whatever because it will pass the url into these callbacks.

thybag commented 10 years ago

Hello,

Just to update on this, for now I'd rather stay with the current events model, just for backwards compatibility, although I do see the benefits in being able to set true callbacks. When i get time I'll have a more through look as i expect this is probably something that would be possible to configure via an option.

Thanks, Carl

thybag commented 10 years ago

Hello,

I've just pushed a change in to the develop branch which may solve your issue. https://github.com/thybag/PJAX-Standalone/tree/develop

The event object, accessible within the beforeSend, complete callbacks should now contain an additional attribute called "data" holding the PJAX settings at the time the event was fired (including among other things the loaded url)

pjax.connect({
    'container': 'content',
    'success': function(event){
        var url = (typeof event.data !== 'undefined') ? event.data.url : '';
         console.log("Sucessfully loaded "+ url);
    }
});
JonDum commented 10 years ago

Cool. That works fine.