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.

Comments

remi’s picture

I 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

remi’s picture

StatusFileSize
new666 bytes

I 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.

zroger’s picture

Version: 6.x-1.2 » 6.x-1.x-dev
Status: Active » Fixed

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.