storybook-1.x-dev/src/assets/js/attach-behaviors.js
src/assets/js/attach-behaviors.js
/**
* @file
* Ensures that behaviors will attach, even in decoupled contexts, where
* document.readyState is not a good indicator of DOM state.
*/
(function (Drupal, drupalSettings) {
/**
* Calls callback when document ready.
*
* @param {function} callback
* The function to be called on document ready.
*/
const domReady = (callback) => {
const listener = () => {
callback();
document.removeEventListener('DOMContentLoaded', listener);
};
document.addEventListener('DOMContentLoaded', listener);
};
// Attach all behaviors.
domReady(() => {
Drupal.attachBehaviors(document, drupalSettings);
});
})(Drupal, window.drupalSettings);
