Using JavaScript
Introduction
JavaScript is an interpreted programming language which is executed by most modern web browsers. The JavaScript code itself can be either directly inside a HTML file, or can be in a file by itself, and then referenced by the HTML file. Writing a JavaScript function is much like other languages such as Perl, Python, or C. Below is an example of a very simple JavaScript function:
function display_dialog(message) {
alert(message)
}
This function will simply display a dialog containing the text passed to the function. This function in itself is not a lot of use in the real world, so let's expand it to be a genuinely useful function:
function check_age(age) {
if (age < 18) {
alert("Sorry, you are too young to access this service.")
window.close()
}
}
The function has had it's name change to 'check_age', takes a single argument of a person's age. It then checks if the age supplied is less than 18. If it is, then an alert is shown and the current browser window is closed.
Using JavaScript in Flux
Flux is supplied with many JavaScript functions already written for you, so it's quite possible you will never have to write any JavaScript functions at all! If you want to use one of the pre-supplied JavaScript functions in your website, all you need to do know is decide how you want the function to be called. To attach a function to a CSS container, double-click the container to display the 'Element Attributes' palette. Now select the tab called 'Actions', this will display all the actions available for the current container. Select the action you want, such as 'onClick' which runs the function when the user clicks on the container using his/her mouse. Now click the '+' button to add a function to the action. A sheet will drop down from the palette showing all available JavaScript functions, select the one you want and edit the call in the 'Function Call' field. Alternatively, check the checkbox 'JavaScript call is not based on a stored function' and use a built-in JavaScript function such as:
alert("Hello!")
Now click OK.
There is now a JavaScript call attached to the 'onClick' action of the selected container. To test it you should preview the page in a web browser by choosing a web browser from the 'Page > Preview' menu. Please note that some JavaScripts require a 'real' web browser to work correctly, and the built-in preview function of Flux may not represent the true behaviour of the function.
Importing JavaScript from external files
First, make sure the external JavaScript file (with .js extension) is in the 'javascript' folder in your project folder.
Then, in Page Attributes, select the 'JavaScript Includes' tab, and drag the required files from the left to right column to include them in your web page.