Skip to content

Instantly share code, notes, and snippets.

@levmyshkin
Last active November 19, 2021 13:16
Show Gist options
  • Save levmyshkin/3e7c78e878615dfe214451220c5c9e6d to your computer and use it in GitHub Desktop.
Save levmyshkin/3e7c78e878615dfe214451220c5c9e6d to your computer and use it in GitHub Desktop.
Drupal javascript behavior example
(function (Drupal, drupalSettings, once) {
Drupal.behaviors.myBehavior = {
attach: function (context, settings) {
// Using once() to apply the myCustomBehaviour effect when you want to run just one function.
once('myCustomBehavior', 'input.myCustomBehavior', context).forEach(function (element) {
element.classList.add('processed');
});
}
};
} (Drupal, drupalSettings, once));
foobar:
js:
js/foobar.js: {}
dependencies:
- core/drupal
- core/jquery
- core/once
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment