0
Welcome Guest! Login
0 items Join Now

Where? - Linked javascript files

  • Where? - Linked javascript files

    Posted 14 years 8 months ago
    • Hi all,

      Where is the best place to link a javascript file using a gantry template. I have been trying to find where the header file is loaded from but to no avail.?

      Thanks in advance.
    • Last Edit: 14 years 8 months ago by Mark Fisher.
  • Re: Where? - Linked javascript files

    Posted 14 years 8 months ago
    • Open your template index.php at:
      <Joomla Root>/templates/<your template name>/index.php

      Find below codes:
       
      <?php 
           $gantry->displayHead();
           $gantry->addStyles(array('template.css','joomla.css','overlays.css','typography.css'));
       

      Change the codes to:
       
      <?php 
           $gantry->displayHead();
           $gantry->addStyles(array('template.css','joomla.css','overlays.css','typography.css'));
           $gantry->addScripts(array('yourscript.js'));
       

      Then put "yourscript.js" file to js folder at:
      <Joomla Root>/templates/<your template name>/js/
  • Re: Where? - Linked javascript files

    Posted 14 years 8 months ago
    • Thanks Arifin I will give it a try!
  • Re: Where? - Linked javascript files

    Posted 14 years 8 months ago
    • Works in that the .js is linked correctly in the header but the javascript functions no longer work. I previously linked the js in the article content itself and worked fine. It is the jQuery script I need working.

      Any simple reason why this no longer works having the scripts loaded from the header?

      Thanks
    • Last Edit: 14 years 8 months ago by Mark Fisher.
  • Re: Where? - Linked javascript files

    Posted 14 years 8 months ago
    • Mark Fisher wrote:
      Works in that the .js is linked correctly in the header but the javascript functions no longer work. I previously linked the js in the article content itself and worked fine. It is the jQuery script I need working.

      .....
      Unfortunately, since jQuery conflicts with Mootools, it will simply not working except your jQuery is coded with no-conflict. For more information, please visit this link:
      api.jquery.com/jQuery.noConflict/
  • Re: Where? - Linked javascript files

    Posted 14 years 8 months ago
    • Thanks Arifin,

      I have tried using the no-conflict routine but having problems. I am not very experienced with javascript.

      Could you give me some advice please?

      My attempt to use no-conflict inside a Joomla article with the js linked in the header which did not work:
      <script type="text/javascript">
        $.noConflict();
        jQuery(document).ready(function($) {
          // Code that uses jQuery's $ can follow here.
      $(function() {
          $("#accordion").accordion({
            autoHeight: false,
            navigation: true
          });
        });
        // Code that uses other library's $ can follow here.
      </script>
       

      My orginal code inside the same article which kinda worked but with some strange articfacts in the Rocketheme template going on:
       
      <script type="text/javascript" src="includes/js/jquery-1.4.2.min.js"></script>
      <script type="text/javascript" src="includes/js/jquery-ui-1.8.2.custom.min.js"></script>
       
       
      <script type="text/javascript">
        $(function() {
          $("#accordion").accordion({
            autoHeight: false,
            navigation: true
          });
        });
      </script>
       


      Thanks
    • Last Edit: 14 years 8 months ago by Mark Fisher.
    • Roeland_A!'s Avatar
    • Roeland_A!
    • Preeminent Rocketeer
    • Posts: 10193
    • Thanks: 71

    Re: Where? - Linked javascript files

    Posted 14 years 8 months ago
    • If you want to give it your best shot, then try, and this may seem trivial, but you really need to load all mootools related js first, and after all those load jquery.
      That will give you a bigger chance of success.
    • *Karma comes in many forms, my personal favourite is the random saucepan from the sky* J.Spencer 17-02-2009
  • Re: Where? - Linked javascript files

    Posted 14 years 8 months ago
    • Thanks for your input guys, I will give it a shot!

Time to create page: 0.056 seconds