PageSourceSearch

https://www.rs.gov.br/matriz_common/versions/2.1.5/js/procergs/jquery.matrizCalendarioEventos.js?2.1.5.161.6+8

js www.rs.gov.br collected 2026-09-24 19:28:23 UTC 3,876 bytes, 113 lines download raw bytes

1matriz.ui = matriz.ui || {};
2matriz.ui.CalendarioEventos = function (options) {
3    
4    var $calendario = $(options.datepicker.container);
5    
6    var eventos = [];
7
8    this.init = function () {
9        $calendario.datepicker({
10            todayHighlight: true,
11            format: matriz.utils.internationalization.translate("dd/mm/yyyy", "localization"),
12            language: $("html").attr("lang")
13        }).on("show render", function (e) {
14            atualizaEventos(e.date);
15        }).datepicker("show");
16    };
17    
18    function atualizaEventos(date) {
19        $calendario.addClass("disabled").removeClass("active");
20        
21        if (!eventos.length) {
22            var parametros = '';
23            if ($("#codigoExternoCalendarioEvento").length) {
24                parametros = '?codigoexterno=' + $("#codigoExternoCalendarioEvento").val();
25            }
26            matriz.utils.ajax({
27                url: "/_service/site/listevento" + parametros
28            }).done(function (response) {
29                eventos = response.itens;
30                redesenhaEventos(date);
31            });
32        } else {
33            redesenhaEventos(date);
34        }
35    }
36    
37    function redesenhaEventos(date) {
38        var dateNow = (new Date(date));
39        var dateOldMonth = (new Date(date)).addMonths(-1);
40        var dateNewMonth = (new Date(date)).addMonths(1);
41        
42        $calendario.find(".day").removeClass("active").each(function (dayIndex, dayElement) {
43            var $dayElement = $(dayElement);
44            var calendarioDate;
45
46            if ($dayElement.hasClass("old")) {
47                calendarioDate = dateOldMonth;
48            } else if ($dayElement.hasClass("new")) {
49                calendarioDate = dateNewMonth;
50            } else {
51                calendarioDate = dateNow;
52            }
53
54            calendarioDate.setDate(parseInt($dayElement.text()));
55
56            if (dataPossuiEvento(calendarioDate)) {
57                addLinkEvento($dayElement, calendarioDate);
58            } else {
59                $dayElement.addClass("disabled");
60            }
61        });
62    }
63    
64    function dataPossuiEvento(date) {
65        var calendarioDate = date.toLocaleDateString();
66
67        for (var eventoID in eventos) {
68            var evento = eventos[eventoID];
69            var eventoDate = new Date(evento.timestamp * 1000);
70
71            for (var dia = 0; dia <= evento.dias; dia++) {
72                if (eventoDate.toLocaleDateString() === calendarioDate) {
73                    return true;
74                }
75
76                eventoDate = eventoDate.addDays(1);
77            }
78        }
79
80        return false;
81    }
82
83    function addLinkEvento($element, date) {
84        var urlAmigavelConteudoPai = "eventos";
85        if ($("#urlAmigavelConteudoPai").length) {
86            urlAmigavelConteudoPai = $("#urlAmigavelConteudoPai").val();
87        }
88        $element.empty();
89        $element.addClass("day_event");
90        $("<a>")
91                .attr("href", "/" + urlAmigavelConteudoPai + "?datahoraini=".concat(encodeURIComponent(date.toLocaleDateString())).concat("&ordem=EVENTOSANTIGOS"))
92                .text(parseInt(date.getDate()))
93                .on("click", function (e) {
94                    e.stopPropagation();
95                    location.href = this.href;
96                    return false;
97                }).appendTo($element);
98    }
99};
100
101$.fn.matrizCalendarioEventos = function () {
102    if (this.length > 0) {
103        $(this).each(function (idx, container) {
104            var calendarioEventos = new matriz.ui.CalendarioEventos({
105                "datepicker": {
106                    "container": container
107                }
108            });
109            calendarioEventos.init();
110        });
111    }
112    return this;
113};

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.