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.
| Comment | File | Size | Author |
|---|---|---|---|
| #5 | ajax_links_api.zip | 8.44 KB | serjas |
| ajax-links-api-ajaxlink-context-fix.patch | 556 bytes | rob c |
Comments
Comment #1
serjas commentedThe problem with context is , it wont attach scripts specific for pages like it breaks ahah image upload on node add form!
Comment #2
serjas commentedAnyway i will include context in code. As now ,it affects only ahah image upload. Including $script will solve issue.
Comment #3
serjas commentedcommitted to latest dev
Comment #4
serjas commented@Rob C, please try dev version , including context now is not loading all js specific for pages!
Comment #5
serjas commentedPlease test attached module . I am going to revert back dev version as it no longer works correctly
Comment #6
serjas commentedComment #7
arun ak commentedHi,
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
Comment #8
serjas commented@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!