Welcome Guest, Not a member yet? Register   Sign In
jQuery modules dynamic inclusion - how would you do it?
#1

[eluser]Ki[/eluser]
Modern sites rely on jQuery to make them snappy and cool, however it is resource intensive to include any and all possible jQuery plugins into all pages.
So lets say that on one page you need an image handling plugin, on another page a table plugin and on all pages another kind of plugin. And each one has their own config that is initialized on page load.
I may not have the best approach, but I load all my pages through a master view that loads header, footer and content. After the footer I load jQuery plugins dynamically. I have an array such as
array(
"controller1"=>array('module1', 'module2'),
"controller1"=>array('module1', 'module2')
)
in the footer, i check if controller matches a controller in array and that loads all js modules for that controller.

Anybody has a better way?
#2

[eluser]vitoco[/eluser]
to me, the list of jquery files to include is defined in the function/method.

class controller_01 extends Controller
{

function f1()
{
....
// load the resources, and in the view get them
$this->output->add_js(
'jquery.js',
'plugin_01.js' ,
'plugin_02.js'
);
....
}
}
#3

[eluser]Ki[/eluser]
add_js is not a native function of the output class.
#4

[eluser]vitoco[/eluser]
it's not, it's a custom function in MY_Output, if you want it, i'll post all the code involved in the process of define from the controller what js ( and css ) are loaded in the view

Saludos




Theme © iAndrew 2016 - Forum software by © MyBB