0

I found a responsive menu code here and I want to add it to my Drupal 7 site. I have no experience with JavaScript, but I thought that if i just copy the script into mytheme/js/menu.js, call it in mytheme.info, and add the HTML to a block, I will have the script up and running.

The HTML part works fine, but the JavaScript part isn't working.

Why doesn't my JavaScript code work?

  • I have checked the provided link and I think, its for single page website. Do you want to create single page website? – Jayendra Kainthola Jun 29 '13 at 11:44
  • yes, thats what im trying to do. but for some reason the js doesnt do anything. – Yinon Bitton Jun 29 '13 at 12:35
1

Well adding JavaScript can be done through drupal_add_js().

You can add the JavaScript code in your template.php file.

  1. Create a cool.js file where you copy the JavaScript code
  2. Put the file in your themes/MYTHEME/js folder
  3. In your template.php file, create a page preprocess function

    function MYTHEME_preprocess_page(&$vars) {
      drupal_add_js(drupal_get_path('theme', 'MYTHEME') . "/js/cool.js", array("preprocess" => True));    
    }
    
  4. Clear the cache

  5. Load your page and check the page source code to see if cool.js is being loaded; use ctrl+f to see if the file is present there

  6. If the effect is still not coming, then verify the IDs in the HTML are correct

  • i tried doing that, and this is what i got upon loading the page: Parse error: syntax error, unexpected $end in /home2/engeeoco/public_html/sites/all/themes/engeeo/template.php on line 16 – Yinon Bitton Jun 29 '13 at 11:28
  • You might have done something wrong in template.php. Please check your template.php code again. Sounds like you have not closed your function with }. – Sandesh Yadav Jun 29 '13 at 11:32
  • hihi.. how embarrassing. yes i have no clue in php. anyway, site loads fine now, but still no java effect. you can see it here: engeeo.com – Yinon Bitton Jun 29 '13 at 11:35
  • I dint get you. Do you mean, you corrected the error ? – Sandesh Yadav Jun 29 '13 at 11:36
  • i corrected the error, but now the javascript doesnt have any effect – Yinon Bitton Jun 29 '13 at 11:37
0

You can use Singe page website module to create single page website in the drupal 7.

You can check example for implementation of the module.

I have also checked your site engeego and I found that there is some javascript issue.

If you include javascript in drupal 7 theme, you need to enclose this into below function.

(function($) {

    //your code

})(jQuery);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.