wip
This commit is contained in:
Vendored
+5
-38
@@ -26,51 +26,18 @@ var __webpack_exports__ = {};
|
||||
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
||||
/* harmony export */ "default": () => (/* binding */ domReady)
|
||||
/* harmony export */ });
|
||||
/**
|
||||
* @typedef {() => void} Callback
|
||||
*
|
||||
* TODO: Remove this typedef and inline `() => void` type.
|
||||
*
|
||||
* This typedef is used so that a descriptive type is provided in our
|
||||
* automatically generated documentation.
|
||||
*
|
||||
* An in-line type `() => void` would be preferable, but the generated
|
||||
* documentation is `null` in that case.
|
||||
*
|
||||
* @see https://github.com/WordPress/gutenberg/issues/18045
|
||||
*/
|
||||
|
||||
/**
|
||||
* Specify a function to execute when the DOM is fully loaded.
|
||||
*
|
||||
* @param {Callback} callback A function to execute after the DOM is ready.
|
||||
*
|
||||
* @example
|
||||
* ```js
|
||||
* import domReady from '@wordpress/dom-ready';
|
||||
*
|
||||
* domReady( function() {
|
||||
* //do something after DOM loads.
|
||||
* } );
|
||||
* ```
|
||||
*
|
||||
* @return {void}
|
||||
*/
|
||||
function domReady(callback) {
|
||||
if (typeof document === 'undefined') {
|
||||
if (typeof document === "undefined") {
|
||||
return;
|
||||
}
|
||||
if (document.readyState === 'complete' ||
|
||||
// DOMContentLoaded + Images/Styles/etc loaded, so we call directly.
|
||||
document.readyState === 'interactive' // DOMContentLoaded fires at this point, so we call directly.
|
||||
) {
|
||||
if (document.readyState === "complete" || // DOMContentLoaded + Images/Styles/etc loaded, so we call directly.
|
||||
document.readyState === "interactive") {
|
||||
return void callback();
|
||||
}
|
||||
|
||||
// DOMContentLoaded has not fired yet, delay callback until then.
|
||||
document.addEventListener('DOMContentLoaded', callback);
|
||||
document.addEventListener("DOMContentLoaded", callback);
|
||||
}
|
||||
|
||||
|
||||
(window.wp = window.wp || {}).domReady = __webpack_exports__["default"];
|
||||
/******/ })()
|
||||
;
|
||||
Reference in New Issue
Block a user