dom-ready.js 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /******/ (function() { // webpackBootstrap
  2. /******/ "use strict";
  3. /******/ // The require scope
  4. /******/ var __webpack_require__ = {};
  5. /******/
  6. /************************************************************************/
  7. /******/ /* webpack/runtime/define property getters */
  8. /******/ !function() {
  9. /******/ // define getter functions for harmony exports
  10. /******/ __webpack_require__.d = function(exports, definition) {
  11. /******/ for(var key in definition) {
  12. /******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
  13. /******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
  14. /******/ }
  15. /******/ }
  16. /******/ };
  17. /******/ }();
  18. /******/
  19. /******/ /* webpack/runtime/hasOwnProperty shorthand */
  20. /******/ !function() {
  21. /******/ __webpack_require__.o = function(obj, prop) { return Object.prototype.hasOwnProperty.call(obj, prop); }
  22. /******/ }();
  23. /******/
  24. /************************************************************************/
  25. var __webpack_exports__ = {};
  26. /* harmony export */ __webpack_require__.d(__webpack_exports__, {
  27. /* harmony export */ "default": function() { return /* binding */ domReady; }
  28. /* harmony export */ });
  29. /**
  30. * @typedef {() => void} Callback
  31. *
  32. * TODO: Remove this typedef and inline `() => void` type.
  33. *
  34. * This typedef is used so that a descriptive type is provided in our
  35. * automatically generated documentation.
  36. *
  37. * An in-line type `() => void` would be preferable, but the generated
  38. * documentation is `null` in that case.
  39. *
  40. * @see https://github.com/WordPress/gutenberg/issues/18045
  41. */
  42. /**
  43. * Specify a function to execute when the DOM is fully loaded.
  44. *
  45. * @param {Callback} callback A function to execute after the DOM is ready.
  46. *
  47. * @example
  48. * ```js
  49. * import domReady from '@wordpress/dom-ready';
  50. *
  51. * domReady( function() {
  52. * //do something after DOM loads.
  53. * } );
  54. * ```
  55. *
  56. * @return {void}
  57. */
  58. function domReady(callback) {
  59. if (typeof document === 'undefined') {
  60. return;
  61. }
  62. if (document.readyState === 'complete' || // DOMContentLoaded + Images/Styles/etc loaded, so we call directly.
  63. document.readyState === 'interactive' // DOMContentLoaded fires at this point, so we call directly.
  64. ) {
  65. return void callback();
  66. } // DOMContentLoaded has not fired yet, delay callback until then.
  67. document.addEventListener('DOMContentLoaded', callback);
  68. }
  69. (window.wp = window.wp || {}).domReady = __webpack_exports__["default"];
  70. /******/ })()
  71. ;