Let’s see two examples to understand my problem better.
Example #1: User installs a new WP plugin, e.g.: Google maps shortcode, which outputs the div of the map and some scripts after that to start the map. When I call this page (where the google map shortcode is placed) the scripts won’t (always) work.
Example #2: User installs a ToolTip plugin. But this plugin won’t print any scripts after the shortcode, instead it prints its own script in the head and executes it when the document is ready, e.g.: $(‘a.icon’).toolTip(); This script also won’t work because first I need the content elements from the AJAX call, I can apply the function after that only. Of course if I put it into success callback, it works. But should the user put every new JS function into this callback function? How should I handle this well?
Extra info which may help: I use jQuery.load() function and I only get the #content div from the loaded pages, not the whole page.
Idea as possible solution #1 (not tested yet): get script tags from AJAX loaded content and eval() them?
AJAX WP themes are very tricky.
Best thing to do is offer an option to disable the ajax behavior to a normal page load. So users that only want the theme functionality should use the ajax loading and users who have multiple plugins should use normal page load.
I always offer an option to always load scripts in my plugins ( so scripts will not load only when the shortcode is parsed, but always, in the head section ) . But this is not enough sometimes ( for your example of document ready ) . So I see no other solution for this.
ZoomIt: this option is already there..
subsolar saidI think this solution sometimes adds duplicated JS instances/listeners which eventually will increase the cpu usage and lag of the site more and more on every click/eval(); or i’m wrong but nevertheless i’m also curious for the best solution
While searching for possible solutions. Had someone tested this ?