| 1 |
import { createHooks } from '@wordpress/hooks'; |
| 2 |
|
| 3 |
window.wpParselyHooks = createHooks(); |
| 4 |
|
| 5 |
export function wpParselyInitCustom() { |
| 6 |
/** |
| 7 |
* The `wpParselyOnLoad` hook gets called with the `onLoad` event of the `window.PARSELY` object. |
| 8 |
* All functions enqueued on that hook will be executed on that event according to their priorities. Those |
| 9 |
* functions should not expect any parameters and shouldn't return any. |
| 10 |
*/ |
| 11 |
const customOnLoad = () => window.wpParselyHooks.doAction( 'wpParselyOnLoad' ); |
| 12 |
|
| 13 |
if ( typeof window.PARSELY === 'object' ) { |
| 14 |
if ( typeof window.PARSELY.onload !== 'function' ) { |
| 15 |
window.PARSELY.onload = customOnLoad; |
| 16 |
return; |
| 17 |
} |
| 18 |
|
| 19 |
const oldOnLoad = window.PARSELY.onload; |
| 20 |
window.PARSELY.onload = function() { |
| 21 |
if ( oldOnLoad ) { |
| 22 |
oldOnLoad(); |
| 23 |
} |
| 24 |
customOnLoad(); |
| 25 |
}; |
| 26 |
return; |
| 27 |
} |
| 28 |
|
| 29 |
window.PARSELY = { |
| 30 |
onload: customOnLoad, |
| 31 |
}; |
| 32 |
} |
| 33 |
|
| 34 |
wpParselyInitCustom(); |
| 35 |
|