Create custom behaviours

Public

Any function defined as a property of Drupal.behaviors will get called when the DOM has loaded.

Get raw version
javascript
  1. (function($) {
  2. Drupal.behaviors.YOURMODULE = {
  3. /* This jQuery code ensures that this element
  4.   is only processed once. It is basically saying:
  5.   1) Find all elements with this class, that do not
  6.   have the processed class on it
  7.   2) Iterate through them
  8.   3) Add the processed class (so that it will not
  9.   be processed again).
  10. */
  11. attach: function(context, settings) {
  12. settings.YOURMODULE = settings.YOURMODULE || Drupal.settings.YOURMODULE;
  13. // Apply the myCustomBehaviour effect to the elements only once.
  14. $('input.myCustomBehavior', context).once('myCustomBehavior', function () {
  15. });
  16. }
  17. };
  18. })(jQuery);