Created
November 10, 2021 21:05
-
-
Save LittleCoding/003b059685969b33e9e0958d483eb3a1 to your computer and use it in GitHub Desktop.
Basic ES6 JS for Drupal 8/9 project (module, theme)
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
(($, 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