Welcome Guest, Not a member yet? Register   Sign In
jLoad - Javascript loader library
#1

[eluser]fatnic[/eluser]
OK. Not sure if this has been done before but here it is anyway. jLoad is basically a library to help load required javascript files quickly into a view.

You can download the zip here

First you need the jLoad config file. Here is where you set the path to your javascript files, set autoloading files and groups of files.
Code:
// Javascript path
$config['javascript_path'] = base_url().'js/';
// Files to autoload when library loaded
$config['javascript_autoload'] = array('jquery-1.2.6.pack');
// Groups of files for quick loading
$config['jload_img_zoom'] = array('jquery.fancybox-1.0.0', 'image_zoom');

Then to use the library ensure you place the following in the head of your view file.
Code:
<?php if (isset($javascript)) echo $javascript; ?>

Then in your controller you can use
Code:
// Load the library (autoloading scripts added)
$this->load->library('jload');
// Add a single (or list) of scripts
$this->jload->add('script1', 'script2');
// Or an array
$this->jload->add(array('script1', 'script2'));
// Or add a defined group with one call
$this->jload->group('img_zoom');
// then generate the script tags
$data['javascript'] = $this->jload->generate();

Now all the required script tags will automatically be inserted into your view.

Anyway, like I said, this has probably been done before but it's something I needed and cooked up quickly. Thought I would share. Smile

Feel free to comment or suggest some ways to make it better. I've not been using CI long and could do with some tips.

Cheers.


Messages In This Thread
jLoad - Javascript loader library - by El Forum - 09-03-2008, 09:16 AM
jLoad - Javascript loader library - by El Forum - 09-04-2008, 03:15 AM
jLoad - Javascript loader library - by El Forum - 09-04-2008, 03:30 AM
jLoad - Javascript loader library - by El Forum - 09-06-2008, 02:58 AM
jLoad - Javascript loader library - by El Forum - 09-06-2008, 05:28 AM



Theme © iAndrew 2016 - Forum software by © MyBB