By Vidarls on
I'm developing a theme with a dynamic menu, this menu requires javascript to be loaded on page load.
(using phptemplate) code:
<body <?php theme("onload_attribute", "initjsDOMenu()");?> >
is this the correct way of doing onload javascript?
When doing it this way, the collapsible parts i.e. settings menu stops working.
I did see a mention of this being a 4.7 registered bug, but I could not find wheter it was corrected or not.
Please advice
-Olegu
http://www.zbz5.net
Comments
addLoadEvent
Use the Drupal javascript addLoadEvent function:
undefined function
I might be doing something really wrong here but i get this when I try to call addloadevent():
Fatal error: Call to undefined function: addloadevent() in..Same thing with isJsEnabled()
I am making these calls from the template.php file if that makes any difference.
javascript
If you're calling it from your template.php are you enclosing it in script tags? Just so we're clear the snippit I gave you was javascript not PHP.
Aha, javascript...
That clears up alot. Now it works, thank you very much.
I had to manually hardcode the link to drupal.js though. Is that the correct way of doing it? Or are there som theme functions to take care of including native Drupal javascripts?
-Olegu
http://www.zbz5.net
drupal_add_js()
Drupal core adds the link to drupal.js if you are displaying a page that needs it, such as admin/settings. In your case, Drupal core WON'T add it for you. You should use the drupal_add_js() function to add the link. This function will make sure that the link doesn't get added twice, once by Drupal and once by you.
Thank you
Works lika a charm! :D