jquery - Adding javascript code to joomla (view) default.php file does not work -
jquery - Adding javascript code to joomla (view) default.php file does not work -
i want utilize (jquery) jqplot in joomla (3.3) view file - default.php, pls see code below.
however, when calling file frontpage not show chart , console shows error 'uncaught typeerror: undefined not function' @ line of $(document).ready() function.
i suspect embed $(document).ready() function in wrong way in default.php file(?), don't know how prepare this. suggestions?
joomla default.php view file:
<?php // no direct access file defined('_jexec') or die('restricted access'); $document = jfactory::getdocument(); //add jqplot libraries //jhtml::_('jquery.framework); //i tried before - same console error jhtml::_('jquery.framework', false); jhtml::script('jquery.jqplot.min.js'); $document->addstylesheet('media/system/js/jquery.jqplot.min.css'); jhtml::script('jquery.jqplot.min.css'); jhtml::script('jqplot.barrenderer.min.js'); jhtml::script('jqplot.categoryaxisrenderer.min.js'); jhtml::script('jqplot.pointlabels.min.js'); jhtml::script('jqplot.enhancedlegendrenderer.js'); jhtml::script('weqlib.js'); ?> <head> <script type="text/javascript"> $(document).ready(function(){ //here error console displays error var plot1 = $.jqplot ('chart1', [[3,7,9,1,4,6,8,2,5]]); //copied illustration @ http://www.jqplot.com/tests/line-charts.php }); //$(document).ready </script> </head> <!--<h1><?php echo $this->msg; ?></h1>--> <body> <div id="chart1" style="width:600px; height:250px;"> </div> </body>
when defining paths files, should start juri::root
root of joomla site. example:
jhtml::_('script', juri::root() . 'templates/template_name/weqlib.js' );
of course of study alter path ever have files located.
on side note, can utilize next import stylesheet aswell rather using $document->addstylesheet()
:
jhtml::_('stylesheet', juri::root() . 'media/system/js/jquery.jqplot.min.css' );
as jquery function, after importing js files correctly mentioned above, code should work, if doesn't, seek running jquery in noconflict mode changing this:
jhtml::_('jquery.framework', false);
to this:
jhtml::_('jquery.framework');
and 1 time done alter custom script uses jquery
alias:
jquery(document).ready(function() { var plot1 = jquery.jqplot ('chart1', [[3,7,9,1,4,6,8,2,5]]); });
hope helps
jquery joomla jqplot
Comments
Post a Comment