drupal.init.es6.js 952 B

12345678910111213141516171819202122232425262728293031323334
  1. // Allow other JavaScript libraries to use $.
  2. if (window.jQuery) {
  3. jQuery.noConflict();
  4. }
  5. // Class indicating that JS is enabled; used for styling purpose.
  6. document.documentElement.className += ' js';
  7. // JavaScript should be made compatible with libraries other than jQuery by
  8. // wrapping it in an anonymous closure.
  9. (function(Drupal, drupalSettings) {
  10. /**
  11. * Calls callback when document ready.
  12. *
  13. * @param {function} callback
  14. * The function to be called on document ready.
  15. */
  16. const domReady = callback => {
  17. if (document.readyState !== 'loading') {
  18. callback();
  19. } else {
  20. const listener = () => {
  21. callback();
  22. document.removeEventListener('DOMContentLoaded', listener);
  23. };
  24. document.addEventListener('DOMContentLoaded', listener);
  25. }
  26. };
  27. // Attach all behaviors.
  28. domReady(() => {
  29. Drupal.attachBehaviors(document, drupalSettings);
  30. });
  31. })(Drupal, window.drupalSettings);