Skip to content

Instantly share code, notes, and snippets.

@twfahey1
Last active August 3, 2022 17:49
Show Gist options
  • Save twfahey1/1545dc9c50591031a660dde4b1d4a746 to your computer and use it in GitHub Desktop.
Save twfahey1/1545dc9c50591031a660dde4b1d4a746 to your computer and use it in GitHub Desktop.
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.
});
}
};
(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