PluginProbe
Parse.ly / 3.18.0
Parse.ly v3.18.0
3.24.1 3.24.0 3.23.7 3.23.6 3.23.5 3.23.4 3.23.3 3.16.0 3.16.1 3.16.2 3.16.3 3.16.4 3.17.0 3.18.0 3.18.1 3.19.0 3.19.1 3.19.2 3.19.3 3.2.0 3.2.1 3.20.0 3.20.1 3.20.2 3.20.3 All 105 releases
wp-parsely / src / js / lib / loader.ts

loader.ts in Parse.ly 3.18.0, at src/js/lib/loader.ts

59 lines 1.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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