Hi all,
I was copying/changing the Tips class a bit so I can use it in a
project.
Basically I load in an html template structure that will be used to
fill Tip data in various spots. For example, the template has a dl
list ready with dt's and the dd's are filled when the Tip renders.
The template has some buttons as well, like a close button and some
app specific ones.
To make the links work correctly in the Tip (= ajaxifying links or
getting a working close button) I have to run some javascript like $
('btnClose').addEvent('click, function(e){ tip.hide(); });
The thing is, the tip html is not injected into the page straight
away, therefore any js in the response (from loading the template)
executed in the Request doesn't work.
Now I can do a couple of things and I wonder what the best (preferred)
option would be:
1. No JS in html requests! It's always ugly. Just plain html and add
all the extra's in the app later. This would mean using the fireEvents
from the Tips class.
2. Send JS with the html request, it's the logical place. If there is
any JS in the response then store the JS code on the element inside
the Tips class. Then when it is injected into the body check if
there's JS code stored and run Browser.exec on it.
3. Send the JS with the html request. Don't wait to insert into the
body when the first Tip is "opened" but insert straight away so the js
is executed immediately.
What would you do?