I'm writing an app with three or four views, which are implemented as  
separate HTML pages.  Any of the pages might be the first one loaded.   
Some code needs to be executed regardless of which page loads first,  
and some code is specific to each of the pages.   Currently, I have  
code strewn around in a messy fashion, with things like

document.observe("dom:loaded", function() {
     preloadTreeImages();
     $$('ul.treeroot li').each( function(elem) {
         toggleListItem(elem, true);
     });

     $$('ul.treeroot').each( function(elem) {
         elem.observe('click', respondToClick);
         elem.observe('textInput', respondToTextInput);
     });
});

In particular, I am calling document.observe("dom:loaded", function()  
{...}); from a common.js file which is included in each page, and also  
from a .js file specific to each page, which is legal, but  
undisciplined.


1) is it legal to make calls like
     $$('ul.treeroot').each( function(elem) {
         elem.observe('click', respondToClick);
         elem.observe('textInput', respondToTextInput);
     });
when there might not be any UL elements of class "treeroot"?


2) How should I be organizing code for an app like this?  Can I put  
everything in one .js file and put a <script> tag which references it  
in each html page?


(I'm thinking these questions aren't as clear as they could be, but I  
can't think how to ask them better right now.)


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Prototype & script.aculo.us" group.
To post to this group, send email to prototype-scriptaculous@googlegroups.com
To unsubscribe from this group, send email to 
prototype-scriptaculous+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to