• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Loader extension - JavaScript and CSS loading functionality

#1
[eluser]Marfo[/eluser]
Hi!

This is my first CI extension/library whatever, so behave Smile.

Usage:

Controller
Code:
$this->load->set_script_path('js/');
$this->load->set_css_path('css/');

$this->load->set_script_extension('.js'); //Not necessary. Default is .js
$this->load->set_css_extension('.css'); //Not necessary. Default is .css

$this->load->script(array('jquery', 'scripts'));
$this->load->css(array('styles', 'ie'));

//Or you can set the extension in the script/css method like this
$this->load->script(array('jquery', 'scripts'), '.js');
$this->load->css(array('styles', 'ie'), '.js');
//Or like this
$this->load->script(array('jquery.js', 'scripts.php'), false);
$this->load->css(array('styles.css', 'ie.css'), false);

$this->load->view('welcome_message');

view/welcome_message
Code:
echo $loader_scripts;
//Or
echo $loader_css;
//Or
echo $this->output('scripts/css'); //empty will return both scripts and css

Or in the controller:
Code:
$data['scripts'] = $this->output('scripts');
$data['css'] = $this->output('css');

$this->load->view('welcome_message', $data);

Useful or crap?

#2
[eluser]Phil Sturgeon[/eluser]
This seems pretty confusing:

Code:
$this->output('scripts/css');

I would prefer:

Code:
$this->output('scripts', 'css');
// or
$this->output(array('scripts', 'css'));

Otherwise it looks like you are writing a path.

Also, shouldn't the following be in a config file?

Code:
$this->load->set_script_path('js/');
$this->load->set_css_path('css/');

Good stuff though mate, not seen anyone put this asset handling into the loader before. It's an interesting angle on a library-heavy problem.

#3
[eluser]Marfo[/eluser]
[quote author="Phil Sturgeon" date="1258137598"]This seems pretty confusing:
Code:
$this->output('scripts/css');

I would prefer:

Code:
$this->output('scripts', 'css');
// or
$this->output(array('scripts', 'css'));
[/quote]

Maybe I could explain that better:

Code:
$this->load->output('script'); //Returns only scripts
$this->load->output('css'); //Returns only css
$this->load->output(); //Returns both

I used the slash so that I didn't have to repeat the code so many times :red: .

[quote author="Phil Sturgeon" date="1258137598"]
Also, shouldn't the following be in a config file?

Code:
$this->load->set_script_path('js/');
$this->load->set_css_path('css/');
[/quote]

It could also be in a config file, but I want to be able to change the path in between.

Code:
$this->load->set_script_path('js/');
$this->load->scripts('script');
$this->load->set_script_path('other/js/folder/');
$this->load->scripts('other_script');

Thanks for the feedback mate Smile

#4
[eluser]Phil Sturgeon[/eluser]
I guess that may be a feature you intended, but it would be great having the default in a config file so it wouldn't need to be set globally in a MY_Controller or repeated a whole bunch of times in your controllers.

#5
[eluser]Marfo[/eluser]
Update with the config option Smile. Config file included.

#6
[eluser]Zack Kitzmiller[/eluser]
I sort of took my own stab at this. http://ellislab.com/forums/viewthread/137755/


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.