Last active
August 3, 2022 17:49
-
-
Save twfahey1/1545dc9c50591031a660dde4b1d4a746 to your computer and use it in GitHub Desktop.
Drupal behavior javascript - https://www.drupal.org/docs/7/api/javascript-api/managing-javascript-in-drupal-7
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Drupal.behaviors.mybehavior = { | |
attach: function (context, settings) { | |
$('#some_element', context).once('mybehavior', function () { | |
// Code here will only be applied to $('#some_element') | |
// a single time. | |
}); | |
} | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function ($, Drupal, once) { | |
Drupal.behaviors.myModuleBehavior = { | |
attach: function (context, settings) { | |
once('myCustomBehavior', 'input.myCustomBehavior', context).forEach(function (element) { | |
// Apply the myCustomBehaviour effect to the elements only once. | |
}); | |
} | |
}; | |
})(jQuery, Drupal, once); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment