Custom Behaviors

Component ID

2094199

Component name

Custom Behaviors

Component type

module

Maintenance status

Development status

Component security advisory coverage

not-covered

Component created

Component changed

Component body

A very small module that extends the functionality of the object Drupal.behaviors. Allows other developers to define and invoke custom behaviors from very specific events that make their modules.

This function is like Drupal.attachBehaviors() but the developer can define
the name of the function to execute and when do it.

Example:

Drupal.behaviors.SomeModule = {
   attach: function(context, settings) {
     $('body', context).click(function() {
       // Here define the new function to execute on each object
       // Drupal.behaivors.
       Drupal.invokeBehaviors('bodyClicked', [variable1, variable2, context, settings]);
     });
   }
  }

Another module:

Drupal.behaviors.AnotherModule = {
    attach: function(context, settings) {
      ... Do something or not.
    },
    bodyClicked: function(variable1, variable2, context, settings) {
      ... Do something when the user click on the body element.
    }
  }
 };