[eluser]Adam Liszkai[/eluser]
Hi Developers!
I read many places that CodeIgniter javascript library does not currently viable. I looked for, looking in the code and I think I found a few hours after the hang of it. First of all, a place I had to write in the code:
/codeigniter/system/libaries/javascript/jquery.php in a rows 946-962
Original:
Code:
if (count($this->jquery_code_for_compile) == 0 )
{
// no inline references, let's just return
return ;
}
// Inline references
$script = '$(document).ready(function() {' . "\n";
$script .= implode('', $this->jquery_code_for_compile);
$script .= '});';
$output = ($script_tags === FALSE) ? $script : $this->inline($script);
$this->CI->load->vars(array($view_var => $output));
}
And the correction:
Code:
if (count($this->jquery_code_for_compile) == 0 )
{
// no inline references, let's just return
return ;
}
// Inline references
$script = '$(document).ready(function() {' . "\n";
$script .= implode('', $this->jquery_code_for_compile);
$script .= '});';
$output = ($script_tags === FALSE) ? $script : $this->inline($script);
$this->CI->load->vars(array($view_var => $output));
return $script;
}
I added "return $script;" after "$this->CI->load->vars(array($view_var => $output));"
In my class the code looks:
Code:
/* ... more code, but not important here ... */
$this->jquery->_document_ready('alert("Jquery class work!!");'."\n\r");
$header['jquery_libaries'] = array(
$this->jquery->script(JAVASCRIPTS.'jquery.min.js'),
$this->jquery->script(JAVASCRIPTS.'jquery-ui.min.js'),
$this->jquery->script(JAVASCRIPTS.'jquery.easing.min.js')
);
$header['script_head'] = $this->jquery->_compile();
/* ... more code, but not important here ... */
$this->load->view('header', $header);
/* ... more code, but not important here ... */
I define JAVASCRIPTS to "http://localhost/liszkaiadam-hu/subdomains/jquery/" because in the near future i will use in my page and the javascripts have their own separate vhost.
My header view file:
Code:
/* ... more code, but not important here ... */
echo('<!-- $jquery_libaries -->'."\n\r");
foreach($jquery_libaries as $script)
{
echo($script);
}
echo("\n\r");
echo('<!-- $script_head -->'."\n\r");
echo('< script type="text/javascript">'."\n\r");
echo($script_head."\n\r");
echo('</ script>'."\n\r");
/* ... more code, but not important here ... */
And the output is:
Code:
<!-- $jquery_libaries -->
< script type="text/javascript" charset="utf-8" src="http://lo.../jquery.min.js" ></ script>
< script type="text/javascript" charset="utf-8" src="http://lo.../jquery-ui.min.js"></ script>
< script type="text/javascript" charset="utf-8" src="http://lo.../jquery.easing.min.js"></ script>
<!-- $script_head -->
< script type="text/javascript">
$(document).ready(function() {
alert("Jquery class work!!");
});
</ script>
Here I hit a space is opening and closing the scrtipt tag to actually load as well as shortened the src :)
So I solved this problem for me, the javascript library automatically loaded in autoload config file, the jquery is loaded it automatically.
I apologize for my English, I never learned a books or from teachers.
Cheers!