Last active
November 19, 2021 13:16
-
-
Save levmyshkin/3e7c78e878615dfe214451220c5c9e6d to your computer and use it in GitHub Desktop.
Drupal javascript behavior example
This file contains 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, 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)); |
This file contains 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
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