Welcome Guest, Not a member yet? Register   Sign In
Autoloading external files - extended view library
#1

[eluser]Nanodeath[/eluser]
Hi all,

I've created a little MY_Loader class that does some nifty stuff that I'll share if anyone wants it. As for what it does, I'll just cut to the chase.

It affects loading views only. If you load a view "my_view", then it automatically checks to see if there's a "my_view.js" and a "my_view.css" in a location of your choice and loads those if found. Additionally, there's a "dependencies" file in which you can specify what additional css and js files should be loaded for specific views or all views in your application. These files can be loaded every time or conditionally. For example, here's my dependencies file:

Code:
$dep['all']['js'][] = "../jquery.js";
$dep['all']['js'][] = "../interface.js";
$dep['all']['js'][] = array("../jquery.simplemodal.js", '!$CI->session->userdata(\'username\')');
$dep['all']['js'][] = array("login_modal.js", '!$CI->session->userdata(\'username\')');

$dep['learn_index']['js'][] = '../ui.tabs.js';
$dep['learn_index']['css'][] = 'http://dev.jquery.com/view/trunk/themes/flora/flora.all.css';

All views load jquery.js and interface.js in my case, and if the user is not logged in, the modal js files are loaded. For the learn_index view, learn_index.js and learn_index.css are loaded, along with ui.tabs.js and that flora.all.css.

I'm exploring a couple other ideas, like allowing the dev to pass variables to the load->view with a special prefix that can be used in the conditions in the dependencies file, or making a separate file that consolidates as much external javascript as is feasible into one dynamic file.

Anyone want this when I'm done with it, have comments, ideas, etc..? It's meant to just be a lightweight little helper. I like it because if I want to create custom javascript for one of my views, I don't have to modify the view, just create a file.


Messages In This Thread
Autoloading external files - extended view library - by El Forum - 02-08-2008, 10:30 PM
Autoloading external files - extended view library - by El Forum - 02-08-2008, 10:39 PM
Autoloading external files - extended view library - by El Forum - 02-08-2008, 11:28 PM



Theme © iAndrew 2016 - Forum software by © MyBB