PageSourceSearch

https://www.avelgem.be/modules/custom/drk_core/js/klaro-jobsolutions-loader.js?v=1.x

js avelgem.be collected 2026-10-02 11:28:06 UTC 2,518 bytes, 81 lines download raw bytes

1/**
2 * @file
3 * Fixes DOMContentLoaded timing for JobSolutions iframe-embed.js after Klaro consent.
4 *
5 * Klaro blocks iframe-embed.js (from jobsolutions.be) until consent is given.
6 * When consent is granted and the script re-executes, its internal
7 * DOMContentLoaded promise never resolves because the event already fired.
8 * This loader patches document.addEventListener before Klaro re-enables the
9 * script, so the DOMContentLoaded listener fires immediately and
10 * iframe-embed.js can initialize the vacancy iframe properly.
11 */
12
13(function (Drupal, once) {
14
15  'use strict';
16
17  var origAddEventListener = document.addEventListener;
18
19  Drupal.drkJobSolutionsLoader = {
20    loaded: false,
21    revoked: false,
22
23    /**
24     * Patch DOMContentLoaded so iframe-embed.js can initialize after consent.
25     *
26     * Called by the Klaro callback BEFORE Klaro re-enables the blocked script.
27     * Patches document.addEventListener so that when iframe-embed.js registers
28     * its DOMContentLoaded listener, it resolves immediately.
29     */
30    load: function () {
31      this.revoked = false;
32
33      if (this.loaded) {
34        return;
35      }
36      this.loaded = true;
37
38      if (document.readyState === 'loading') {
39        return;
40      }
41
42      // Temporarily patch addEventListener: when iframe-embed.js adds a
43      // DOMContentLoaded listener after the DOM is already loaded, fire it
44      // immediately instead of waiting for an event that will never come.
45      document.addEventListener = function (type, listener, options) {
46        if (type === 'DOMContentLoaded') {
47          setTimeout(listener, 0);
48          return;
49        }
50        return origAddEventListener.call(document, type, listener, options);
51      };
52
53      // Restore the original after iframe-embed.js has had time to execute
54      // and register its listener.
55      setTimeout(function () {
56        document.addEventListener = origAddEventListener;
57      }, 5000);
58    },
59
60    /**
61     * Called by Klaro callback_code when consent is revoked.
62     */
63    revoke: function () {
64      this.revoked = true;
65    }
66  };
67
68  // When Klaro is not active for the current user, apply the same patch
69  // as a safety net (e.g. BigPipe timing issues).
70  Drupal.behaviors.drkJobSolutionsAutoLoad = {
71    attach: function (context, settings) {
72      if (!once('drk-jobsolutions-auto-load', 'body', context).length) {
73        return;
74      }
75      if (!settings.klaro) {
76        Drupal.drkJobSolutionsLoader.load();
77      }
78    }
79  };
80
81})(Drupal, once);

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.