| 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 |
/** |
| 14 |
* The `wpParselyOnReady` hook gets called with the `onReady` event of the `window.PARSELY` object. |
| 15 |
* All functions enqueued on that hook will be executed on that event according to their priorities. Those |
| 16 |
* functions should not expect any parameters and shouldn't return any. |
| 17 |
*/ |
| 18 |
const customOnReady = () => window.wpParselyHooks.doAction( 'wpParselyOnReady' ); |
| 19 |
|
| 20 |
// Construct window.PARSELY object. |
| 21 |
if ( typeof window.PARSELY === 'object' ) { |
| 22 |
if ( typeof window.PARSELY.onload !== 'function' ) { |
| 23 |
window.PARSELY.onload = customOnLoad; |
| 24 |
} else { |
| 25 |
const oldOnLoad = window.PARSELY.onload; |
| 26 |
window.PARSELY.onload = function() { |
| 27 |
if ( oldOnLoad ) { |
| 28 |
oldOnLoad(); |
| 29 |
} |
| 30 |
customOnLoad(); |
| 31 |
}; |
| 32 |
} |
| 33 |
|
| 34 |
if ( typeof window.PARSELY.onReady !== 'function' ) { |
| 35 |
window.PARSELY.onReady = customOnReady; |
| 36 |
} else { |
| 37 |
const oldOnReady = window.PARSELY.onReady; |
| 38 |
window.PARSELY.onReady = function() { |
| 39 |
if ( oldOnReady ) { |
| 40 |
oldOnReady(); |
| 41 |
} |
| 42 |
customOnReady(); |
| 43 |
}; |
| 44 |
} |
| 45 |
} else { |
| 46 |
window.PARSELY = { |
| 47 |
onload: customOnLoad, |
| 48 |
onReady: customOnReady, |
| 49 |
}; |
| 50 |
} |
| 51 |
|
| 52 |
// Disable autotrack if it was set as such in settings. |
| 53 |
if ( window.wpParselyDisableAutotrack === true ) { |
| 54 |
window.PARSELY.autotrack = false; |
| 55 |
} |
| 56 |
} |
| 57 |
|
| 58 |
wpParselyInitCustom(); |
| 59 |
|