PageSourceSearch

https://lesfranciscaines.fr/modules/contrib/tacjs/js/tacjs.js?tlpthi

js lesfranciscaines.fr collected 2026-10-02 07:08:08 UTC 4,684 bytes, 135 lines download raw bytes

1/**
2 * @file
3 * Init tarteaucitron.js script.
4 */
5/* global tarteaucitron */
6((Drupal, drupalSettings, tarteaucitron) => {
7  /**
8   * Init tarteaucitron.js script.
9   *
10   * @type {Drupal~behavior}
11   *
12   * @prop {Drupal~behaviorAttach} attach
13   *   Attaches the script.
14   */
15  Drupal.behaviors.tacjs = {
16    attach: function attach() {
17      if (window.alreadyLaunch) return;
18
19      // Drupal tacjs configuration is required.
20      if (!drupalSettings.tacjs) return;
21
22      // Set base URL for TacJS Log
23      tarteaucitron.baseUrl = drupalSettings.path.baseUrl;
24
25      // Add custom texts to tarteaucitron.
26      window.tarteaucitronCustomText = drupalSettings.tacjs.texts;
27
28      // Add users identification to tarteaucitron.
29      // Undefined user causes javascript errors #3326860 #3323411.
30      tarteaucitron.user = drupalSettings.tacjs.user || {};
31
32      // Set expiration time in day(s)
33      if (drupalSettings.tacjs.expire) {
34        window.tarteaucitronExpireInDay = true;
35        window.tarteaucitronForceExpire = drupalSettings.tacjs.expire;
36      }
37
38      // Workaround for #3120915: convert multiplegtagUa into a Array
39      // See https://www.drupal.org/project/tacjs/issues/3120915
40      if (tarteaucitron.user.multiplegtagUa) {
41        tarteaucitron.user.multiplegtagUa =
42          tarteaucitron.user.multiplegtagUa.split(', ');
43      }
44
45      // Workaround for #3204238: convert googleFonts into a Array
46      // See https://www.drupal.org/project/tacjs/issues/3204238
47      if (tarteaucitron.user.googleFonts) {
48        tarteaucitron.user.googleFonts =
49          tarteaucitron.user.googleFonts.split(', ');
50      }
51
52      // Add enabled services to tarteaucitron services.
53      Object.keys(drupalSettings.tacjs.services)
54        .filter((service) => {
55          // Filter enabled services.
56          return drupalSettings.tacjs.services[service].status;
57        })
58        .forEach((service) => {
59          const s = drupalSettings.tacjs.services[service];
60          const lang = drupalSettings.path.currentLanguage;
61          const slanguages = s.languages;
62          const { needConsent, readMore, readmoreLink } = s;
63          const languages = [];
64
65          // Check service
66          if (!tarteaucitron.services[service]) return;
67
68          // Check service languages
69          if (slanguages) {
70            Object.keys(slanguages)
71              .filter((language) => {
72                return slanguages[language];
73              })
74              .forEach((language) => {
75                languages.push(language);
76              });
77          }
78
79          // Check languages
80          if (languages.length !== 0 && !languages.includes(lang)) return;
81
82          // Set consent.
83          if (needConsent !== undefined) {
84            tarteaucitron.services[service].needConsent = needConsent;
85          }
86
87          // Set "Read more" link.
88          if (readmoreLink) {
89            tarteaucitron.services[service].readmoreLink = readmoreLink;
90          }
91
92          // Set "Read more" text.
93          if (readMore) {
94            tarteaucitron.services[service].readmoreText = readMore;
95          }
96
97          (tarteaucitron.job = tarteaucitron.job || []).push(service);
98        });
99
100      // Insert "Read more" texts in Tarte au citron dialog.
101      const tacLoad = tarteaucitron.events.load;
102      tarteaucitron.events.load = () => {
103        if (tacLoad) {
104          // Call original load listener.
105          tacLoad();
106        }
107        // Implementation inspired from a TarteAuCitron GitHub comment:
108        // https://github.com/AmauriC/tarteaucitron.js/pull/1136#issuecomment-1632161267
109        tarteaucitron.job.forEach((serviceName) => {
110          const service = tarteaucitron.services[serviceName];
111          if (service.readmoreText) {
112            const precedingElement = document.querySelector(
113              `#${serviceName}Line .tarteaucitronH3`,
114            );
115            if (precedingElement) {
116              const readmoreElt = document.createElement('span');
117              readmoreElt.classList.add('tarteaucitronReadmoreText');
118              readmoreElt.textContent = service.readmoreText;
119              precedingElement.insertAdjacentElement('afterend', readmoreElt);
120            }
121          }
122        });
123      };
124
125      // Initiate tarteaucitron
126      tarteaucitron.init(drupalSettings.tacjs.dialog);
127
128      // Window onload event sometimes occurs before tacjs init is called.
129      if (document.readyState === 'complete') {
130        // Ressources fully loaded, load event already fired, force call.
131        tarteaucitron.initEvents.loadEvent(!window.addEventListener);
132      }
133    },
134  };
135})(Drupal, drupalSettings, tarteaucitron);

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.