This is an old revision of the document!
When combining two or more JavaScript modules together, the first thing to consider is the use of CF.userMain function.
This function can only be implemented once in your entire project - see here for more details on this.
As an example, lets say we have two scripts in our project, but both have defined their own CF.userMain() function, like so:
Script1.js
CF.userMain = function() { // iViewer initialization is now complete and the CF environment is fully available // Watch for page flips CF.watch(CF.PageFlipEvent, onPageFlip); // Watch for network status, get initial status CF.watch(CF.NetworkStatusChangeEvent, onNetworkStatusChange); // Watch for important system connects and disconnects CF.watch(CF.ConnectionStatusChangeEvent, "TEST-SYSTEM", onTestSystemConnectionStatusChange, true); CF.watch(CF.ConnectionStatusChangeEvent, "SERVER SYSTEM", onServerSystemConnectionStatusChange, true); // Watch for some crucial join changes CF.watch(CF.JoinChangeEvent, ["d10", "d11", "d12", "a50"], onImportantJoinChange); };
Script2.js
CF.userMain = function() { // Create interlock group for buttons Interlock.create("buttons", "d1","d2","d3","d4"); // Create an interlock group for subpages Interlock.create("subpages", ["d100", "d200", "d300", "d400"]); // Setup a watch callback to display the current selection Interlock.watch("buttons", function(group, currentSelection, previousSelection) { CF.setJoin("s1", "Current selection in group 1 is " + currentSelection); // show the subpage associated with interlock group 1 // do it the lazy way - d1 becomes d100, d2 becomes d200 etc // when we show one of the subpages, the subpages interlock group kicks in and hides the others Interlock.select("subpages", currentSelection+"00"); }); // Set the group initial values Interlock.select("buttons", "d2"); };