PageSourceSearch

https://ecampus.ufam.edu.br/ecampus/js/cookies.js

js ufam.edu.br collected 2026-09-24 08:54:20 UTC 4,200 bytes, 112 lines download raw bytes

1// Funções auxiliares para cookies
2function setCookie(name, value, days) {
3    var expires = "";
4    if (days) {
5        var date = new Date();
6        date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
7        expires = "; expires=" + date.toUTCString();
8    }
9    document.cookie = name + "=" + (value || "") + expires + "; path=/";
10}
11
12function getCookie(name) {
13    var nameEQ = name + "=";
14    var ca = document.cookie.split(';');
15    for (var i = 0; i < ca.length; i++) {
16        var c = ca[i];
17        while (c.charAt(0) == ' ') c = c.substring(1, c.length);
18        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
19    }
20    return null;
21}
22
23$(document).ready(function() {
24    // Verificar consentimento existente
25    var cookieConsent = getCookie('cookie_consent');
26    var performanceCookies = getCookie('performance_cookies');
27    // Se não tiver consentimento, mostrar banner
28    if(localStorage.getItem('cookie_consent') === 'declined') {
29        return
30    }
31    if (!cookieConsent) {
32        $('#cookie-banner').fadeIn();
33    } else {
34        // Se já tiver consentimento, mostrar apenas o botão flutuante
35        $('#cookie-float-btn').fadeIn();
36        // Set the initial state of the performance cookies checkbox if consent already exists
37        if (performanceCookies === 'true') {
38            $('#performance-cookies').attr('checked', true);
39        } else {
40            $('#performance-cookies').attr('checked', false);
41        }
42    }
43
44    // Aceitar todos os cookies
45    $('#accept-all-cookies-btn').click(function() {
46        setCookie('cookie_consent', 'all', 365);
47        setCookie('performance_cookies', 'true', 365);
48        $('#cookie-banner').fadeOut();
49        $('#cookie-float-btn').fadeIn();
50        $('#performance-cookies').attr('checked', true); // Ensure checkbox is checked when "Accept All" is clicked
51        // TODO: Call function to activate performance scripts, if any
52    });
53
54    let isModalOpen = false;
55
56    // Abrir configurações
57    $('#cookie-settings-btn').click(function() {
58        // When opening settings, update the state of the performance cookies checkbox
59        var currentPerformanceConsent = getCookie('performance_cookies');
60        if (currentPerformanceConsent === 'true') {
61            $('#performance-cookies').attr('checked', true);
62        } else {
63            $('#performance-cookies').attr('checked', false);
64        }
65        $('#cookie-settings-modal').fadeIn()
66        isModalOpen = true;
67    });
68
69    $(document).mouseup(function(e) {
70        if(isModalOpen && !($('#cookie-settings-modal').has(e.target).length || $('#cookie-settings-modal')[0] === e.target)) {
71            $('#cookie-settings-modal').fadeOut();
72            isModalOpen = false;
73        }
74    })
75
76    $('#decline-all-cookies-btn').click(function() {
77        localStorage.setItem('cookie_consent', 'declined');
78        $('#cookie-settings-modal').fadeOut();
79        $('#cookie-banner').fadeOut();
80    })
81
82    // Fechar modal
83    $('#close-settings-modal').click(function() {
84        $('#cookie-settings-modal').fadeOut();
85    });
86
87    // Salvar configurações personalizadas
88    $('#save-cookie-settings').click(function() {
89        var performanceChecked = $('#performance-cookies').is(':checked');
90
91        setCookie('cookie_consent', 'custom', 365);
92        setCookie('performance_cookies', performanceChecked ? 'true' : 'false', 365);
93
94        $('#cookie-banner').fadeOut();
95        $('#cookie-settings-modal').fadeOut();
96        $('#cookie-float-btn').fadeIn();
97
98        // TODO: Call function to (de)activate performance scripts based on 'performanceChecked'
99    });
100
101    // Botão flutuante - reabrir configurações
102    $('#cookie-float-btn button').click(function() {
103        // When re-opening from the floating button, update the state of the performance cookies checkbox
104        var currentPerformanceConsent = getCookie('performance_cookies');
105        if (currentPerformanceConsent === 'true') {
106            $('#performance-cookies').attr('checked', true);
107        } else {
108            $('#performance-cookies').attr('checked', false);
109        }
110        $('#cookie-settings-modal').fadeIn();
111    });
112});

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.