PageSourceSearch

https://thetriumphofdavid.com/themes/bootstrap5/js/cookie.js?_=1777897953

js thetriumphofdavid.com collected 2026-10-08 19:44:46 UTC 4,156 bytes, 149 lines download raw bytes

1/*global VuFind, CookieConsent */
2
3VuFind.register('cookie', function cookie() {
4  let consentConfig = null;
5  var _COOKIE_DOMAIN = false;
6  var _COOKIE_PATH = '/';
7  var _COOKIE_SAMESITE = 'Lax';
8  
9  /**
10   * Set the domain for the cookie
11   * @param {string} domain The domain to set
12   */
13  function setDomain(domain) {
14    _COOKIE_DOMAIN = domain;
15  }
16
17  /**
18   * Set the path for the cookie
19   * @param {string} path The path to set
20   */
21  function setCookiePath(path) {
22    _COOKIE_PATH = path;
23  }
24
25  /**
26   * Set the samesite attribute for the cookie
27   * @param {string} sameSite The samesite attribute to set.
28   */
29  function setCookieSameSite(sameSite) {
30    _COOKIE_SAMESITE = sameSite;
31  }
32
33  /**
34   * Get all the cookie parameters
35   * @returns {object} Return the cookie parameters
36   */
37  function _getCookieParams() {
38    return { path: _COOKIE_PATH, domain: _COOKIE_DOMAIN, SameSite: _COOKIE_SAMESITE };
39  }
40
41  /**
42   * Get the value of a cookie
43   * @param {string} name The name of the cookie
44   * @returns {string|undefined} Return the value of the cookie
45   */
46  function get(name) {
47    return window.Cookies.get(name);
48  }
49
50  /**
51   * Set a cookie
52   * @param {string} name  The name of a cookie
53   * @param {string} value The value of the cookie
54   * @returns {string|undefined} Return the value of the cookie (or undefined if setting failed)
55   */
56  function set(name, value) {
57    return window.Cookies.set(name, value, _getCookieParams());
58  }
59
60  /**
61   * Remove a cookie.
62   * @param {string} name The name of the cookie to remove.
63   * @returns {boolean} Return true if the cookie was removed.
64   */
65  function remove(name) {
66    return window.Cookies.remove(name, _getCookieParams());
67  }
68
69  /**
70   * Update the status of services
71   */
72  function updateServiceStatus() {
73    Object.entries(consentConfig.controlledVuFindServices).forEach(([category, services]) => {
74      // Matomo:
75      if (window._paq && services.indexOf('matomo') !== -1) {
76        if (CookieConsent.acceptedCategory(category)) {
77          window._paq.push(['setCookieConsentGiven']);
78        }
79      }
80    });
81  }
82
83  /**
84   * Set up the cookie consent dialog and its event handlers.
85   * @param {object} _config The configuration object for cookie consent.
86   */
87  function setupConsent(_config) {
88    consentConfig = _config;
89    consentConfig.consentDialog.onFirstConsent = function onFirstConsent() {
90      VuFind.emit('cookie-consent-first-done');
91    };
92    consentConfig.consentDialog.onConsent = function onConsent() {
93      updateServiceStatus();
94      VuFind.emit('cookie-consent-done');
95    };
96    consentConfig.consentDialog.onChange = function onChange() {
97      updateServiceStatus();
98      VuFind.emit('cookie-consent-changed');
99    };
100    CookieConsent.run(consentConfig.consentDialog);
101    VuFind.emit('cookie-consent-initialized');
102  }
103
104  /**
105   * Check if a specific cookie category has been accepted by the user.
106   * @param {string} category The category name.
107   * @returns {boolean} Return whether the category is accepted or not
108   */
109  function isCategoryAccepted(category) {
110    return CookieConsent.acceptedCategory(category);
111  }
112
113  /**
114   * Check if a specific service is allowed.
115   * @param {string} serviceName The name of the service.
116   * @returns {boolean} Return whether the service is allowed.
117   */
118  function isServiceAllowed(serviceName) {
119    for (const [category, services] of Object.entries(consentConfig.controlledVuFindServices)) {
120      if (services.indexOf(serviceName) !== -1
121        && CookieConsent.acceptedCategory(category)
122      ) {
123        return true;
124      }
125    }
126    return false;
127  }
128
129  /**
130   * Return the full consent configuration object.
131   * @returns {object|null} The consent configuration.
132   */
133  function getConsentConfig() {
134    return consentConfig;
135  }
136
137  return {
138    setDomain: setDomain,
139    setCookiePath: setCookiePath,
140    setCookieSameSite: setCookieSameSite,
141    get: get,
142    set: set,
143    remove: remove,
144    setupConsent: setupConsent,
145    isCategoryAccepted: isCategoryAccepted,
146    isServiceAllowed: isServiceAllowed,
147    getConsentConfig: getConsentConfig
148  };
149});

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.