PageSourceSearch

https://inssa.com.co/wp-content/plugins/wp-consent-api/assets/js/wp-consent-api.js?ver=1.0.71791431700

js inssa.com.co collected 2026-10-08 03:55:35 UTC 3,951 bytes, 123 lines download raw bytes

1'use strict';
2/**
3 * Set consent_type as passed by localize_script, and trigger a hook so geo ip scripts can alter it as needed.
4 * It's set on document ready, so the consent management plugin can first add an event listener.
5 *
6 *
7 * Edit: chronologically it seems difficult to create a sort of filter for the consent type.
8 * Let's change it so cookiebanners are just required to set it, it it's not available, we use a default, as defined here.
9 *
10 * This way, if a consent management plugin does not define a consenttype, the one passed here will be used, and it will still work.
11 *
12 *
13 */
14
15window.wp_fallback_consent_type = consent_api.consent_type;
16window.waitfor_consent_hook = consent_api.waitfor_consent_hook;
17
18/**
19 * Check if a user has given consent for a specific category.
20 *
21 * @param {string} category The category to check consent against.
22 */
23function wp_has_consent(category) {
24    var consent_type;
25    if (typeof (window.wp_consent_type) !== "undefined"){
26        consent_type = window.wp_consent_type;
27    }  else {
28        consent_type = window.wp_fallback_consent_type
29    }
30
31    var has_consent_level = false;
32    var cookie_value = consent_api_get_cookie(consent_api.cookie_prefix + '_' + category);
33
34    if (!consent_type) {
35        //if consent_type is not set, there's no consent management, we should return true to activate all cookies
36        has_consent_level = true;
37
38    } else if (consent_type.indexOf('optout') !== -1 && cookie_value === '') {
39        //if it's opt out and no cookie is set we should also return true
40        has_consent_level = true;
41
42    } else {
43        //all other situations, return only true if value is allow
44        has_consent_level = (cookie_value === 'allow');
45    }
46
47    return has_consent_level;
48}
49
50/**
51 * Set cookie by consent type.
52 *
53 * @param {string} name The cookie name to set.
54 * @param {string} value The cookie value to set.
55 */
56function consent_api_set_cookie(name, value) {
57    var secure = ";secure";
58    var days = consent_api.cookie_expiration;
59    var date = new Date();
60    date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
61    var expires = ";expires=" + date.toGMTString();
62
63    if (window.location.protocol !== "https:") secure = '';
64
65    document.cookie = name + "=" + value + secure + expires + ";path=/";
66}
67
68/**
69 * Retrieve a cookie by name.
70 *
71 * @param {string} name The name of the cookie to get data from.
72 */
73function consent_api_get_cookie(name) {
74    name = name + "=";
75    var cookies = window.document.cookie.split(';');
76
77    for (var i = 0; i < cookies.length; i++) {
78        var cookie = cookies[i].trim();
79        if (cookie.indexOf(name) == 0)
80            return cookie.substring(name.length, cookie.length);
81    }
82
83    //If we get to this point, that means the cookie wasn't found, we return an empty string.
84    return "";
85}
86
87/**
88 * Set a new consent category value.
89 *
90 * @param {string} category The consent category to update.
91 * @param {string} value The value to update the consent category to.
92 */
93function wp_set_consent(category, value) {
94    var event;
95    if (value !== 'allow' && value !== 'deny') return;
96	var previous_value = consent_api_get_cookie(consent_api.cookie_prefix + '_' + category);
97    consent_api_set_cookie(consent_api.cookie_prefix + '_' + category, value);
98
99    //do not trigger a change event if nothing has changed.
100    if ( previous_value === value ) return;
101
102    var changedConsentCategory = [];
103    changedConsentCategory[category] = value;
104    try {
105        // For modern browsers except IE:
106        event = new CustomEvent('wp_listen_for_consent_change', {detail: changedConsentCategory});
107    } catch (err) {
108        // If IE 11 (or 10 or 9...?)
109        event = document.createEvent('Event');
110        event.initEvent('wp_listen_for_consent_change', true, true);
111        event.detail = changedConsentCategory;
112    }
113    // Dispatch/Trigger/Fire the event
114    document.dispatchEvent(event);
115}
116
117
118
119
120
121
122
123

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.