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

Reply via email to