immosquare-cookies 0.1.8 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7eb6e162ff2d90f082a12dc39014623c9420dfd1293638d9fb548ec9377a1ffa
4
- data.tar.gz: f00cd0502e661094343daa7ce43784abce66a46159349974c38ac50096058f4a
3
+ metadata.gz: 9c71c141ffaac74579de140de61fc7fe9ec397a3ef0d1850a60d2ac5f9ea9903
4
+ data.tar.gz: 830ce69ed6edbef208c766e12e17923be628271d5834ec8b9825d9e93a7a58b7
5
5
  SHA512:
6
- metadata.gz: 4ed07ec0cc51429ece1d25230e2d1c3930e4a1a9f3d64b75742e8a549a71dab9c07ff2fa0427173d87c96b70087031ca1e8dfdc09814d750bda7c209772b473b
7
- data.tar.gz: a659701fda2b99a631ad8ed753cb028b4330a45848b4cd0bb016284edca020abf5ac591aed473d44a452134c0709ed273b88d5f3ac0846763aa1357a4a24b1de
6
+ metadata.gz: f36d2ff9458ccc55531298db944cda1bc437fa5f1c78a0d8d322ad012d4ed986ba555abbc8e42346ea7183b80f9dddf2c4a697d79b4fc8b6375fdcc0d219e551
7
+ data.tar.gz: 185524731e42c9ba02e7d89c898e63052dae5060bf32d6f4222d505f349850c5052f6c0d0d5cbe2705e3bceec86a28fca2fd63efac69b594d992b7a70983c17a
@@ -1,9 +1,14 @@
1
1
  <%
2
- cookie_name = defined?(key) ? key : "_immosquare_consented"
3
- duration_months = defined?(duration_months) && duration_months.to_i.between?(1, 12) ? duration_months.to_i : 6
2
+ cookie_name = defined?(key) ? key : "_immosquare_consented"
3
+ duration_months = defined?(duration_months) && duration_months.to_i.between?(1, 12) ? duration_months.to_i : 6
4
+ cookies_to_remove = [] if !defined?(cookies_to_remove)
4
5
  %>
5
6
 
6
- <%= content_tag(:div, :id => "immosquare-cookies-container", :data => {:name => cookie_name}) do %>
7
+ <%= content_tag(:div, :id => "immosquare-cookies-container", :data => {
8
+ :name => cookie_name,
9
+ :duration_months => duration_months,
10
+ :cookies_to_remove => cookies_to_remove
11
+ }) do %>
7
12
  <div class="immosquare-cookies-banner">
8
13
  <div class="immosquare-cookies-card">
9
14
  <%# Header %>
@@ -13,16 +18,10 @@ duration_months = defined?(duration_months) && duration_months.to_i.between?(1,
13
18
  <div class="immosquare-cookies-content">
14
19
  <div class="immosquare-cookies-text">
15
20
  <%= content_tag(:div, (defined?(text).present? ? text : t("immosquare-cookies.text", :duration_months => duration_months)).html_safe) %>
16
- <% if defined?(link) %>
17
- <%# Backward compatibility with the :link parameter %>
18
- <%= content_tag(:span, defined?(link_text) ? link_text : t("immosquare-cookies.link_text"), :class => "immosquare-cookies-link-text") %>
19
- <%= link_to(defined?(document_name) ? document_name : t("immosquare-cookies.document_name"), link, :target => defined?(target) ? target : "_blank", :class => "immosquare-cookies-link") %>
20
-
21
- <% elsif defined?(privacy_policy_link) || defined?(cookie_policy_link) %>
22
- <%# New parameters for the two separated links %>
21
+ <% if defined?(privacy_policy_link) || defined?(cookie_policy_link) %>
23
22
  <%= content_tag(:span, defined?(link_text) ? link_text : t("immosquare-cookies.link_text"), :class => "immosquare-cookies-link-text") %>
24
23
  <%= link_to(defined?(privacy_policy) ? privacy_policy : t("immosquare-cookies.privacy_policy"), privacy_policy_link, :target => defined?(target) ? target : "_blank", :class => "immosquare-cookies-link") if defined?(privacy_policy_link) %>
25
- <%= link_to(defined?(cookie_policy) ? cookie_policy : t("immosquare-cookies.cookie_policy"), cookie_policy_link, :target => defined?(target) ? target : "_blank", :class => "immosquare-cookies-link") if defined?(cookie_policy_link) %>
24
+ <%= link_to(defined?(cookie_policy) ? cookie_policy : t("immosquare-cookies.cookie_policy"), cookie_policy_link, :target => defined?(target) ? target : "_blank", :class => "immosquare-cookies-link") if defined?(cookie_policy_link) %>
26
25
  <% end %>
27
26
  </div>
28
27
  </div>
@@ -36,25 +35,58 @@ duration_months = defined?(duration_months) && duration_months.to_i.between?(1,
36
35
  </div>
37
36
 
38
37
  <script>
39
- document.addEventListener("DOMContentLoaded", function() {
40
- const cookieContainer = document.getElementById("immosquare-cookies-container");
41
- const cookieName = cookieContainer.dataset.name;
42
- const cookieDurationMonths = <%= duration_months %>;
43
- const handleCookieConsent = (consentGiven) => {
38
+ document.addEventListener("DOMContentLoaded", () => {
39
+ const cookieContainer = document.getElementById("immosquare-cookies-container");
40
+ const cookieName = cookieContainer.dataset.name;
41
+ const cookieDurationMonths = cookieContainer.dataset.durationMonths;
42
+ const cookiesToRemove = cookieContainer.dataset.cookiesToRemove ? JSON.parse(cookieContainer.dataset.cookiesToRemove) : [];
43
+ const cookies = document.cookie.split(";");
44
+
45
+ // Handle the cookie consent
46
+ const handleCookieConsent = (consentGiven) => {
44
47
  cookieContainer.style.display = "none";
45
- const date = new Date();
46
- date.setTime(date.getTime() + (cookieDurationMonths * 30 * 24 * 60 * 60 * 1000));
47
- const expires = `;expires=${date.toUTCString()}`;
48
- if(!consentGiven){
49
- document.cookie.split(";").forEach(function(c) { document.cookie = c.replace(/^ +/, "").replace(/=.*/, "=;expires=" + new Date().toUTCString() + ";path=/"); });
50
- }
51
- document.cookie = `${cookieName}=${consentGiven}${expires}; path=/`;
52
- if(!consentGiven){
53
- window.location.reload();
48
+ const expiresString = new Date(Date.now() + cookieDurationMonths * 30 * 24 * 60 * 60 * 1000).toUTCString();
49
+
50
+ // Set the cookie for the consent banner
51
+ document.cookie = `${cookieName}=${consentGiven};expires=${expiresString}; path=/`;
52
+
53
+ // Disable the cookies that are not necessary if the user does not consent
54
+ if(!consentGiven && cookiesToRemove && cookiesToRemove.length > 0){
55
+ cookies.forEach(cookie => {
56
+ const cookieParts = cookie.split("=");
57
+ const currentCookieName = cookieParts[0].trim();
58
+ const currentCookieValue = cookieParts[1] ? cookieParts[1].trim() : '';
59
+
60
+ if(cookiesToRemove.includes(currentCookieName)){
61
+ // Delete the cookie by expiring it with both expires and Max-Age
62
+ const expiredDate = 'Thu, 01 Jan 1970 00:00:00 GMT';
63
+ const hostParts = window.location.hostname.split('.');
64
+
65
+ // Build domain variations to try
66
+ const domainVariations = [
67
+ '' // Current domain (no domain attribute)
68
+ ];
69
+
70
+ if (hostParts.length >= 2) {
71
+ domainVariations.push('.' + hostParts.slice(-2).join('.')); // .example.com
72
+ }
73
+
74
+ if (hostParts.length >= 3) {
75
+ domainVariations.push('.' + hostParts.slice(-3).join('.')); // .example.co.uk
76
+ }
77
+
78
+ // Try to delete cookie with each domain variation
79
+ domainVariations.forEach(domain => {
80
+ const domainAttr = domain ? `; domain=${domain}` : '';
81
+ document.cookie = `${currentCookieName}=; expires=${expiredDate}; Max-Age=0; path=/${domainAttr}`;
82
+ });
83
+ }
84
+ })
54
85
  }
55
- };
56
- document.getElementById("immosquare-cookies-refuse").addEventListener("click", function() { handleCookieConsent(false); });
57
- document.getElementById("immosquare-cookies-accept").addEventListener("click", function() { handleCookieConsent(true); });
86
+ };
87
+
88
+ document.getElementById("immosquare-cookies-refuse").addEventListener("click", function() { handleCookieConsent(false); });
89
+ document.getElementById("immosquare-cookies-accept").addEventListener("click", function() { handleCookieConsent(true); });
58
90
  });
59
91
  </script>
60
92
  <% end if cookies && cookies[cookie_name].blank? %>
@@ -1,3 +1,3 @@
1
1
  module ImmosquareCookies
2
- VERSION = "0.1.8".freeze
2
+ VERSION = "2.0.0".freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: immosquare-cookies
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.8
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - immosquare
@@ -9,7 +9,7 @@ bindir: bin
9
9
  cert_chain: []
10
10
  date: 1980-01-02 00:00:00.000000000 Z
11
11
  dependencies: []
12
- description: Immosquare Cookies Consent Banner allows Rails developers to effortlessly
12
+ description: immosquare Cookies Consent Banner allows Rails developers to effortlessly
13
13
  integrate a GDPR-compliant cookie consent prompt into their web applications. With
14
14
  built-in internationalization support and options to customize the banner's appearance
15
15
  and text, it offers a flexible and user-friendly solution for obtaining user consent.