Javascript

This page is a work in progress

Fiz allows serveral ways to add Javascript to a web page. You can either add static Javascript files or generate dynamic javascript as the page is rendering. A discussion of Fiz's approach to Ajax is not covered here.

Adding Javascript files

A Javascript file can be added to the page being rendered by calling the Html object's includeJsFile method. Don't worry about adding the same Javascript file twice; Fiz will detect this and the page will only be loaded once.

Javascript dependencies

Often Javascript files will depend on other Javascript files being loaded first. To manage dependencies, you can add special comment lines to your Javascript files to mark what dependencies it has. To do so, add a comment to the top of your Javascript file that looks like

// Fiz:include path/to/script.js

Whenever a Javascript file with that comment is loaded, so is path/to/script.js. You can add as many of these lines as are necessary.

Dynanic Javascript generation

Sometimes you need to dynamically generate your Javascript, perhaps depending on dataset parameters or data requests. You can build up your Javascript using Templates. Make sure to use Javascript quoting when appropriate. Once you're ready to add it to the page, pass it to the Html's evalJavascript method. The method will add your Javascript to the page, and arrange for it to be run when the page has finished loading.