Quote:
Originally Posted by rnd me
if the crazy function is called addEvent, it's not crazy at all.
|
it's not that function. i'll have to find it, it's in J Keith's Bulletproof Ajax, but it's a fairly large function written out that somehow allows you to tack on more than one function onload. but what's the problem with calling one function that contains many others? ridigness was mentioned, though i don't fully understand how, but i'll look more into using addEvent.
let me explain a bit about what my large encompassing function executed onload does, at least partially:
1. loop over all tags and find any given specific classes and assign functionality to them. for example, i set a class of "clearText" on certain HTML elements which does nothing but gives me a hook that i can assign a function to which will take default text in a form field (like "Enter search terms") and remove that (value='') onclick. having the class eliminates me from having to identify each of these form fields by specific id, but the downside is i have to search all tags on every page to hunt for one that may exist.
2. form validation for various forms throughout the site. unfortunately, the script won't limit itself to a particular form, but rather there is all the code for every form on the site, which right now luckily isn't too many.
3. so on and so forth.
i guess my main concern more down the road will be having to execute this whole function for every page as the file size is growing. i think it's still 12KB uncompressed, but it will get bigger. so right now, all the js functions for my site are in one function that gets loaded every time. i do check for objects before running blocks of code, but i would guess this doesn't help in terms of time spent parsing the file. does code wrapped around a conditional that fails get parsed? (ex. if this form's ID is found on this page, execute this). a basic question i should know

or is the main problem with a large file just the fact that the whole thing has to be downloaded from the server regardless of whether it all gets parsed or not?
Quote:
Originally Posted by rnd me
using something like addEvent, i can add tasks to be done upon load from any file, script tag, or even in the middle of another function.
|
can you explain more of using addEvent?
i guess in sum, the only improvement i can see for me would be somehow to only call the functions a particular page needs out of my currently container function that is called onload. but no idea how to do this. the good news is my script works fine, and i've gotten it very small with lots of reused code, but just curious how to make it better.
can someone else state how they handle this? you have "unobtrusive" js functions called onload, yet you only want to call the relevant functions per page. i guess i should do some more online research, too.