hmm, after typing I thought it would be silly to have "specific-tip- close-js-code" in the html template. the html template used for the tip has no direct relation with the tip (it could be used on another place as well)...
still valid questions: - Should I inject the basic Tip html structure into the body straight away to allow auto exec. of the js code from the ajax response. Or should I store any js coming from the response and execute that when the Tip is injected into the body (the first time a trigger for a Tip is clicked)... - How dirty is js code in html requests in general? or is it normal practice... On Dec 30, 12:55 pm, Rolf -nl <plentyofr...@gmail.com> wrote: > 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?