Created
November 3, 2021 18:46
-
-
Save LittleCoding/c80578c359767bceeb9a3fbf7f2582d5 to your computer and use it in GitHub Desktop.
Basic 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
window.Drupal = window.Drupal || { behaviors: {}, locale: {} }; | |
(function ($, Drupal, settings) { | |
'use strict'; | |
Drupal.myproject = { | |
preInit: function() {}, | |
init: function(settings) {}, | |
postInit: function() {} | |
}; | |
Drupal.behaviors.myproject = { | |
attach: function (context, settings) { | |
// DOM loaded | |
Drupal.myproject.preInit(); | |
$(document, context).once('myprojectInit').each( function() { | |
// Page ready -- with single run wrapper | |
Drupal.myproject.init(settings); | |
$(window).on('load', function() { | |
// 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