Skip to content

Instantly share code, notes, and snippets.

@LittleCoding
Created November 10, 2021 21:05
Show Gist options
  • Save LittleCoding/003b059685969b33e9e0958d483eb3a1 to your computer and use it in GitHub Desktop.
Save LittleCoding/003b059685969b33e9e0958d483eb3a1 to your computer and use it in GitHub Desktop.
Basic ES6 JS for Drupal 8/9 project (module, theme)
(($, Drupal, settings) => {
Drupal.myproject = {
preInit(context) {},
init(settings) {},
postInit() {},
};
Drupal.behaviors.myproject = {
attach(context, settings) {
// DOM loaded
Drupal.myproject.preInit(context);
$(document, context).once('myprojectInit').each(() => {
// Page ready -- with single run wrapper
Drupal.myproject.init(settings);
$(window).on('load', () => {
// Page fully loaded
Drupal.myproject.postInit();
});
});
},
};
})(jQuery, Drupal, drupalSettings);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment