Reading the documentation about the JavaScript API in Drupal 6, I found it is suggested to load JavaScript code for a module using the API rather than the jQuery's normal $(function() { /* code */ }) or $(document).ready(function() { /* code */ }).
I have a small change to simplemenu.js to use Drupal's API to run the module's JavaScript when the page is loaded and its DOM is ready.
Line 3 changed from:
$(document).ready(function() {
to:
Drupal.behaviors.simplemenuBehavior = function() {
And line 51 changed from:
});
to
};
I can confirm the modified code works using Drupal 6.10. Attached is a patch file with those changes for testing.
| Comment | File | Size | Author |
|---|---|---|---|
| #2 | simplemenu_390968_use_drupal_js_api.patch | 666 bytes | remi |
| simplemenu_6.x-1.2_use_drupal_js_api.patch | 659 bytes | remi |
Comments
Comment #1
remi commentedI forgot to add a link to the documentation I was ready about the JavaScript API in Drupal 6.
Here it is: http://drupal.org/node/205296
Comment #2
remi commentedI also forgot one minor detail about the code (not that it affects the good behavior of the modifications specified in the patch file). The anonymous function can accept one argument, "context". I attached an updated patch file.
Comment #3
zroger commentedcommitted: http://drupal.org/cvs?commit=191386
thanks remi