Rich Ajax Application Framework

Creating a Code-Behind Javascript file

Raxan includes a very nice feature that lets you automatically include a JavaScript inside your web page without having to add an extra <script>tag. This makes it much easier and cleaner when working with a lot of script files inside your web page.

To create a code-behind script, you simply create a Javascript file with the same name as the html page you're loading but without the html extension. For example, mywebpage.js will become the code-behind file for the web page mywebpage.html.

To include your code-behind Javascript file inside your web page, you only need to add one script tag and that is the tag that will be used to load the Raxan startup.js file:

<script src="raxan/startup.js" type="text/javascript">/-/</script>

Note the /-/ characters between the tags. These characters will instruct Raxan to automatically load the code-behind file relative to the path of the web page. If your code-behind file is located inside a sub folder (e.g. scripts/), then you can add the folder path as follows:

<script src="raxan/startup.js" type="text/javascript">/scripts/-/</script>

From within your Javascript file you can include just about any other script or CSS file.

Embedding Javascript inside a web page Another cool feature for the framework is the ability to embed your Javascript code inside your web page without having to use a second script block:

<script src="raxan/startup.js" type="text/javascript">
    html.include('jquery');

    html.ready(function(){
        alert('The page is now ready for DOM manipulation');
    });
</script>

In the above example, both the raxan/startup.js and the embedded Javascript codes are executed using only one <script> block.

Loading a Code-Behind script from PHP

To load a code-behind JavaScript script from from php use the loadScriptBehind() method:

<?php

    require_once 'raxan/pdi/autostart.php';

    class NewPage extends RaxanWebPage {

        protected function _init() {
            $this->loadScriptBehind('/-/'); 
            // ... do something ...
        }

    }

?>