I'm testing a bit with loading css/js via javascript - and not load any script via an ajax template (i've removed the print $scripts; line in my templates).

I then noticed that behavour is not attaching correctly to a newly loaded page with ajax links (when loaded via ajax) (so load a page with ajax-link class, but these links never trigger the ajax code when not loading the ajax_links_api.js script on the actual ajax request).

The trick seems to be to pass the 'context' to the ajaxLink() function, this way the javascript only needs to be loaded once and ajax-link's inside the target will work, even when not adding any stylesheets on ajax requests.

I've added a trigger class to the readmore link on teasers, these now also work, even when loading the front page via ajax and not adding any scripts. So it's not a huge deal for the current code, but it does fix my issue, because i do not load any scripts via the template files.

Comments

serjas’s picture

Status: Needs review » Active

The problem with context is , it wont attach scripts specific for pages like it breaks ahah image upload on node add form!

serjas’s picture

Anyway i will include context in code. As now ,it affects only ahah image upload. Including $script will solve issue.

serjas’s picture

Status: Active » Needs review

committed to latest dev

serjas’s picture

@Rob C, please try dev version , including context now is not loading all js specific for pages!

serjas’s picture

StatusFileSize
new8.44 KB

Please test attached module . I am going to revert back dev version as it no longer works correctly

serjas’s picture

Status: Needs review » Active
arun ak’s picture

Hi,

I have tried the attached module ajax_links_api.zip. It reduced the loading time but it not attaching my custom js behaviours with ajax content. I mean, it not taking the code from my custom js file that include in my custom module's hook_init(). What I need to do that. Can I specify which js files need to include with ajax content? Please help me.

Thanks and Regards
ARUN AK

serjas’s picture

@arun, including context now is not loading all js specific for pages! i am not sure how we can include this if used context. for example for node add, ahah.js is not attaching because its specific to node add.

Better use 1.83!