[development] Drupal.jsEnabled

Blake Senftner bsenftner at earthlink.net
Thu Nov 25 15:42:12 UTC 2010


I'm a bit confused about the usage of the Drupal.jsEnabled variable in javascript.

It is my understanding that Drupal sets this internally, and if Drupal.jsEnabled is true then Drupal calls all the functions under the Drupal.behaviors object - sorta like how non-Drupal sites use an after-the-DOM is loaded wrapper to call their javascript logic.

What I'm confused about is why do I find module developer tutorials (various web sites) where the Drupal / javascript examples are like this:

// --------- this is the start of the file
if (Drupal.jsEnabled) {
   $(document).ready(
      entire content of the javascript logic, all functions, vars and so in inside here
   );
}
// ---------- this is the end of the file
Are such examples simply wrong?

I've been doing this, under the belief that my logic will only be called if javascript is available and only after the DOM is loaded:

// --------- start of file
Drupal.behaviors.myModulesNamespace = function( context ) {
    entire content of the javascript logic, all functions, vars and so in inside here
}
// ---------- end of file
Should I also be wrapping my "entire content of javascript logic" inside an "if (Drupal.jsEnabled)" conditional?

Sincerely,
-Blake

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.drupal.org/pipermail/development/attachments/20101125/e578528e/attachment.html 


More information about the development mailing list