CodeIgniter User Guide Version 2.0.0


Javascript Class

Rewrite this paragraph: jQuery is a fast, concise, JavaScript Library that simplifies how you traverse HTML documents, handle events, perform animations, and add Ajax interactions to your web pages. CodeIgniter provides a library to help you with certain common functions that you may want to use within jQuery. Please note that CodeIgniter does not require the jQuery library to run, and that any scripting library will work equally well. The jQuery library is simply presented as a convenience if you choose to use it.

Initializing the Class

To initialize the jQuery class manually in your controller constructor, use the $this->load->library function. Currently, the only available library is jQuery, which will automatically be loaded like this:

$this->load->library('javascript');

The Javascript class also accepts parameters, js_library_driver (string) default 'jquery' and autoload (bool) default TRUE. You may override the defaults if you wish by sending an associative array:

$this->load->library('javascript', array('js_library_driver' => 'scripto', 'autoload' => FALSE));

Again, presently only 'jquery' is available. You may wish to set autoload to FALSE, though, if you do not want the jQuery library to automatically include a script tag for the main jQuery script file. This is useful if you are loading it from a location outside of CodeIgniter, or already have the script tag in your markup.

Once loaded, the jQuery library object will be available using: $this->javascript

Setup and Configuration

Set these variables in your view

As a javascript library, your files must be available to your application. For your convenience, the needed files to run this library are available for download from our site.

As javascript is a client side language, the library must be able to write content into your final output. This generally means a view. You'll need to include the following variables in the <head> sections of your output.

<?php echo $library_src;?>
<?php echo $script_head;?>

$library_src, is where the actual library file will be loaded, as well as any subsequent plugin script calls; $script_head is where specific events, functions and other commands will be rendered.

Set the path to the librarys with config items

There are some configuration items in javascript library. These can either be set in system/application/config.php, within its own confg/javascript.php file, or within any controller usings the set_item() function.

An image to be used as an "ajax loader", or progress indicator. Without one, the simple text message of "loading" will appear when Ajax calls need to be made.

$config['javascript_location'] = 'http://localhost/codeigniter/themes/js/jquery/');
$config['javascript_ajax_img'] = 'images/ajax-loader.gif';

If you keep your files in the same directories they were downloaded from, then you need not set this configuration items.

For information on outputting events, effects, etc., refer to the jQuery Class documentation.