By igorjava on
I added little js code to my theme page.tmp.php file. I need this js to load for every page.
I know I can also add it to theme js directory where all other js is but don't know how to do it exactly in Drupal way. I am extending work that original developer did for this theme. What I added to my page.tmp.php file works perfect just as i want it but I wonder whats the proper way of doing this.
$(document).bind('keydown',function (e){
if (e.keyCode == 13){
//do something
}
});
Any suggestions
Comments
Add to .info file
Usually the javascript file would be defined in the theme's .info file as descibed here.
Alternatively you could use the drupal_add_js function and add the call to your theme's template.php file. Something like:
Hope that helps
Ed
js
Hi
Thanks for help. But this is only like 4 lines of js code. Is there anything wrong leaving the code as it is inside page.tmp.php
Nothing wrong
No, nothing wrong at all. Really just depends on how you see the site being maintained in the future. If it's just you, no problem, if you ever hand over to another Drupal developer it makes things easier for them to locate different elements (js, css etc) if they are done in a more standard way.
Cheers
Ed
thanks Ed
thanks Ed