PageSourceSearch

https://cetic.br/docs-assets/js/main.js?ver=1779974961

js cetic.br collected 2026-09-24 08:26:42 UTC 20,678 bytes, 724 lines download raw bytes

1var languages = ["pt", "en", "es"];
2var pubsetoriais = {};
3// on dom ready
4$(document).ready(function () {
5  $("#panoramas-setoriais .btn-tag").click(function (e) {
6    e.preventDefault();
7    var temaId = $(this).attr("data-id");
8    filterTemasPanorama(temaId);
9  });
10
11  $("#estudos-setoriais .btn-tag").click(function (e) {
12    e.preventDefault();
13    var temaId = $(this).attr("data-id");
14    filterTemasEstudos(temaId);
15  });
16  $('[data-toggle="tooltip"]').tooltip();
17
18  var url = location.pathname;
19  url.indexOf(1);
20  url.toLowerCase();
21  first = url.split("/")[1];
22
23  if (first == "pesquisa") {
24    $(".btn-unidades a").first().addClass("btn-cetic-active");
25    $(".btn-unidades a").first().addClass("btn-lg");
26  }
27
28  $('.btn-unidades a[href="' + url + '"]').removeClass("btn-cetic");
29  $('.btn-unidades a[href="' + url + '"]').addClass("btn-cetic-active");
30
31  $('a.btn-cetic-escolas-rurais[href="' + url + '"]').addClass(
32    "btn-cetic-escolas-rurais-active",
33  );
34  $('a.btn-cetic-escolas-rurais[href="' + url + '"]').removeClass(
35    "btn-cetic-active",
36  );
37  $('a.btn-cetic-escolas-rurais[href="' + url + '"]').removeClass(
38    "btn-cetic-escolas-rurais",
39  );
40
41  $('.btn-unidades a[href="' + url + '"]').removeClass("btn-md");
42  $('.btn-unidades a[href="' + url + '"]').addClass("btn-lg");
43
44  $("*[id*=seta-up-microdados]").each(function () {
45    $(this).hide();
46  });
47
48  $("blockquote").click(function (event) {
49    var block = $(this).attr("id");
50    var down = $(this).find(".down");
51    var up = $(this).find(".up");
52
53    if ($(down).is(":visible")) {
54      $(down).hide();
55      $(up).show();
56    } else {
57      $(down).show();
58      $(up).hide();
59    }
60  });
61
62  // $(".email").hide();
63  // $("#checkbox").click(function(){
64  //     if($('#checkbox').is(':checked')){
65  //       $(".email").show();
66  //     } else {
67  //       $(".email").hide();
68  //     }
69  //  	});
70
71  $("#buttonSearch").hover(function () {
72    $(".input-search").animate({ width: "show" }, 400);
73  });
74  $("#buttonSearch").focus(function () {
75    $(".input-search").animate({ width: "show" }, 400);
76  });
77
78  // Envio do formulário
79  $("#MensagemAddForm").on("submit", function (e) {
80    e.preventDefault();
81
82    var form = $(this);
83
84    grecaptcha.enterprise.ready(function () {
85      grecaptcha.enterprise
86        .execute("6Lep62ktAAAAAKlTKA5zGL_ZsFLv12JFlEv8ve3A", {
87          action: "contato",
88        })
89        .then(function (token) {
90          var input = $("#g-recaptcha-response");
91
92          if (!input.length) {
93            $("<input>", {
94              type: "hidden",
95              id: "g-recaptcha-response",
96              name: "g-recaptcha-response",
97            }).appendTo(form);
98
99            input = $("#g-recaptcha-response");
100          }
101
102          input.val(token);
103
104          $.ajax({
105            url: "https://busca.cgi.br/mensagens/enviacetic",
106            type: "POST",
107            data: form.serialize(),
108            dataType: "json",
109            crossDomain: true,
110
111            success: function (response) {
112              console.log(response);
113
114              if (response.success) {
115                form.html(
116                  "<h1>Mensagem enviada com sucesso</h1><br><br>" +
117                    '<a href="/contato" class="btn-primary button" style="padding:15px">' +
118                    "Enviar nova mensagem" +
119                    "</a>",
120                );
121              } else {
122                alert(response.message);
123              }
124            },
125
126            error: function (xhr, status, error) {
127              console.error("Status:", xhr.status);
128              console.error("Erro:", error);
129              console.error("Resposta:", xhr.responseText);
130
131              alert("Não foi possível enviar a mensagem.");
132            },
133          });
134        });
135    });
136  });
137
138  $("#FeedbackAddForm").submit(function () {
139    var dados = $(this).serialize();
140
141    //console.log(dados); debugger;
142
143    $.ajax({
144      crossDomain: true,
145      async: false,
146      type: "POST",
147      data: dados,
148      dataType: "jsonp",
149      url: "https://busca.cgi.br/mensagens/enviafeedback",
150      success: function (data, textStatus, errorThrown) {
151        $("#FeedbackAddForm")[0].reset();
152        $("#FeedbackAddForm").hide();
153        $("#alert-success").append(
154          '<div class="alert alert-success"><strong>Feedback enviado com sucesso!</strong></div>',
155        );
156      },
157    });
158    return false;
159  });
160
161  // class exists
162  if ($(".confirm_delete").length) {
163    // add click handler
164    $(".confirm_delete").click(function () {
165      // ask for confirmation
166      var result = confirm("Tem certeza que deseja excluir?");
167
168      // show loading image
169      $(".ajax_loader").show();
170      $("#flashMessage").fadeOut();
171
172      // get parent row
173      var row = $(this).parents("tr");
174
175      // do ajax request
176      if (result) {
177        $.ajax({
178          type: "POST",
179          url: $(this).attr("href"),
180          data: "ajax=1",
181          dataType: "json",
182          success: function (response) {
183            // hide loading image
184            $(".ajax_loader").hide();
185
186            // hide table row on success
187            if (response.success == true) {
188              row.fadeOut();
189              var tipo = response.tipo;
190              var html = $("#" + tipo + "_div").html();
191              $("#" + tipo + "_remove").html(html);
192            }
193
194            // show respsonse message
195            if (response.msg) {
196              alert(response.msg);
197              $("#ajax_msg").html(response.msg).show();
198            } else {
199              $("#ajax_msg")
200                .html(
201                  "<p id='flashMessage' class='flash_bad'>An unexpected error has occured, please refresh and try again</p>",
202                )
203                .show();
204            }
205          },
206        });
207      }
208      return false;
209    });
210  }
211
212  $("#addInteressadoMicrodado").submit(function () {
213    var dados = $(this).serialize();
214
215    $.ajax({
216      crossDomain: true,
217      async: false,
218      type: "POST",
219      data: dados,
220      dataType: "jsonp",
221      url: "https://busca.cgi.br/busca/salva_interessado_microdados",
222    });
223
224    return (window.location.href = "http://cetic.br");
225  });
226
227  $(".download").click(function (event) {
228    var arquivo = $(this);
229    var arr = arquivo.attr("href").split("/");
230
231    params = {
232      arquivo_nome: arquivo.attr("title"),
233      arquivo_link: arquivo.attr("href"),
234      arquivo_id: arr[5],
235      data: new Date().toLocaleString(),
236    };
237
238    downloads_arquivos.apply(this, params);
239  });
240
241  $("#setPT").click(function (event) {
242    event.preventDefault();
243    var pathname = window.location.pathname;
244
245    var params = pathname.split("/");
246    if (params[1] == "es" || params[1] == "en") {
247      // está em espanhol ou ingles
248      params.shift(); //remove branco
249      params.shift(); //remove es
250      window.location.href = "/pt/" + params.join("/");
251    } else {
252      return;
253    }
254  });
255  $("#setEN").click(function (event) {
256    event.preventDefault();
257    var pathname = window.location.pathname;
258
259    var params = pathname.split("/");
260    var newurl;
261    if (params[1] == "es" || params[1] == "pt") {
262      // está em espanhol
263      params.shift(); //remove branco
264      params.shift(); //remove es
265      window.location.href = "/en/" + params.join("/");
266    } else if (params[1] != "en") {
267      //está em pt
268      params.shift(); //remove branco
269      window.location.href = "/en/" + params.join("/");
270    } else {
271      return;
272    }
273  });
274
275  $("#setES").click(function (event) {
276    event.preventDefault();
277    var pathname = window.location.pathname;
278
279    var params = pathname.split("/");
280    var newurl;
281    if (params[1] == "en" || params[1] == "pt") {
282      // está em ingles
283      params.shift(); //remove branco
284      params.shift(); //remove es
285      window.location.href = "/es/" + params.join("/");
286    } else if (params[1] != "es") {
287      //está em pt
288      params.shift(); //remove branco
289      window.location.href = "/es/" + params.join("/");
290    } else {
291      return;
292    }
293  });
294
295  var today = new Date();
296  year = today.getFullYear();
297  $("#header-eventos-ano").text(`Eventos ${year}`);
298
299  $(".filter-buttons button").click(function () {
300    $(".filter-buttons button").removeClass("active");
301    $(this).addClass("active");
302
303    var selectedTitle = $(this).attr("data-title");
304
305    if (selectedTitle === "todos") {
306      $(".pesquisa-card").fadeIn();
307    } else {
308      $(".pesquisa-card").each(function () {
309        var cardTitle = $(this).attr("data-title");
310        if (cardTitle === selectedTitle) {
311          $(this).fadeIn();
312        } else {
313          $(this).fadeOut();
314        }
315      });
316    }
317  });
318
319  $('a[href^="#"]').on("click", function (e) {
320    e.preventDefault();
321
322    const alvo = $(this).attr("href");
323    const destino = $(alvo);
324
325    if (destino.length) {
326      $("html, body").animate(
327        {
328          scrollTop: destino.offset().top,
329        },
330        600,
331      ); // 600ms de duração
332    }
333  });
334
335  //filtros indices publicacoes
336  const $filtros = $("#temas-tags-filter .filter-btn");
337  const $botao = $("#ver-mais");
338
339  // Esconde os itens após o 6º (index 5)
340  $filtros.slice(6, -1).hide(); // -1 para não pegar o botão "Ver mais"
341
342  $botao.on("click", function (e) {
343    e.preventDefault();
344    const escondidos = $filtros.slice(6, -1);
345
346    if (escondidos.is(":visible")) {
347      escondidos.fadeToggle(200);
348      $botao.text("... Ver mais");
349    } else {
350      escondidos.fadeToggle(200);
351      $botao.text("Ver menos");
352    }
353  });
354
355  //MENU DE PESQUISAS SCROLL
356  const $w = $(".nav-scroll-wrapper"),
357    $s = $("#pesquisa-nav-scroll");
358  if (!$w.length || !$s.length) return;
359
360  const update = () => {
361    const sw = $s[0].scrollWidth,
362      cw = $s.innerWidth(),
363      sl = $s.scrollLeft();
364    $w.toggleClass("is-scrollable", sw > cw + 2)
365      .toggleClass("at-start", sl <= 2)
366      .toggleClass("at-end", sl + cw >= sw - 2);
367  };
368
369  const scrollBy = (px) =>
370    $s.stop().animate({ scrollLeft: $s.scrollLeft() + px }, 250);
371
372  $w.find(".nav-scroll-btn.left").click(() => scrollBy(-$s.innerWidth() * 0.6));
373  $w.find(".nav-scroll-btn.right").click(() => scrollBy($s.innerWidth() * 0.6));
374  $s.attr("tabindex", 0).keydown((e) => {
375    if (e.key === "ArrowLeft") scrollBy(-120);
376    if (e.key === "ArrowRight") scrollBy(120);
377  });
378
379  $s.on("scroll", update);
380  $(window).on("resize", update);
381  update();
382  //MENU DE PESQUISAS SCROLL
383}
383);
384
385//filtros indices publicacoes
386
387function downloads_arquivos() {
388  jQuery.ajax({
389    dataType: "jsonp",
390    type: "GET",
391    data: {
392      nome_arquivo: params.arquivo_nome,
393      link_arquivo: params.arquivo_link,
394      arquivo_id: params.arquivo_id,
395    },
396    url: "https://busca.cgi.br/mensagens/downloads_arquivos_cetic",
397  });
398
399  // Submenu para Bootstrap 4
400  (function ($) {
401    // Abre/fecha submenus ao clicar no item com .dropdown-toggle
402    $(document).on("click", ".dropdown-menu .dropdown-toggle", function (e) {
403      e.preventDefault();
404      e.stopPropagation();
405
406      var $sub = $(this).next(".dropdown-menu");
407
408      // Fecha outros submenus abertos no mesmo nível
409      if (!$sub.hasClass("show")) {
410        $(this)
411          .closest(".dropdown-menu")
412          .find(".dropdown-menu.show")
413          .removeClass("show");
414      }
415
416      $sub.toggleClass("show");
417    });
418
419    // Ao fechar o dropdown principal, garantir que tudo feche
420    $(".dropdown").on("hidden.bs.dropdown", function () {
421      $(this).find(".dropdown-menu.show").removeClass("show");
422    });
423  })(jQuery);
424}
425
426function get_url_extension(url) {
427  return url.split(/\#|\?/)[0].split(".").pop().trim();
428}
429
430function tratarURLsByLanguage() {
431  let pathname = window.location.pathname;
432  let params = pathname.split("/");
433
434  if (!languages.includes(params[1])) {
435    return false;
436  }
437
438  $('[href*="/"]').each(function (i, e) {
439    let me = $(e);
440
441    let href = me.attr("href");
442
443    if (
444      href.substr(0, 1) == "/" &&
445      (href.search(/\..*/) == -1 || href.slice(-1) == "/")
446    ) {
447      var language = href.split("/");
448
449      if (language && language.length >= 2) {
450        if (!languages.includes(language[1])) {
451          me.attr("href", "/" + params[1] + href);
452        }
453      }
454    }
455  });
456}
457
458async function filterTemasEstudos(temaId) {
459  const data = await loadPanoramas("estudos");
460  const pubs = data
461    .filter((pub) => pub.Tag.some((tema) => tema.id == temaId))
462    .slice(0, 6);
463
464  // Limpa o elemento antes de adicionar novos itens
465  const elementSetor = $("#estudos-setoriais-items");
466  elementSetor.empty();
467
468  // Limpa o elemento antes de adicionar novos itens
469  for (const pub of pubs) {
470    const item = `
471    <div class="col-md-4 mb-4">
472      <div class="card card-models p-4 shadow-sm rounded-lg border-0 h-100">
473       <div class="d-flex flex-wrap gap-1 mb-2">
474         <h2 class="title-tema">${pub.Publicacao.titulo}</h2>
475       </div>
476      <hr>
477      <p class="mb-1 font-weight-bold"><a href="/publicacao/${pub.Publicacao.codigo}" class="text-dark"><i class="fa-solid fa-arrow-right"></i> Veja o Relatório completo</a></p>
478      </div>
479    </div>
480    `;
481
482    elementSetor.append(item);
483  }
484}
485
486async function filterTemasPanorama(temaId) {
487  const data = await loadPanoramas("panoramas");
488
489  const pubs = data
490    .filter((pub) => pub.Tag.some((tema) => tema.id == temaId))
491    .slice(0, 6);
492
493  const panoramaElementItems = $("#panoramas-setoriais-items");
494  panoramaElementItems.empty();
495  for (const pub of pubs) {
496    const item = `
497    <div class="col-md-4 mb-4">
498      <div class="card card-models p-4 shadow-sm rounded-lg border-0 h-100">
499       <div class="d-flex flex-wrap gap-1 mb-2">
500         <h2 class="title-tema">${pub.Publicacao.titulo}</h2>
501       </div>
502      <hr>
503      <p class="mb-1 font-weight-bold"><a href="/publicacao/${pub.Publicacao.codigo}" class="text-dark"><i class="fa-solid fa-arrow-right"></i> Veja o Relatório completo</a></p>
504      </div>
505    </div>
506      `;
507
508    panoramaElementItems.append(item);
509  }
510}
511
512async function loadPanoramas(tipo = "panoramas") {
513  const language = window.location.pathname.split("/")[1];
514  if (!languages.includes(language)) {
515    language = "pt";
516  }
517  const urls = {
518    panoramas: {
519      url: "/setoriais/panoramas_setoriais.json",
520      backend: "/publicacoes/jsonPublicacoesSetoriasPanorama",
521    },
522    estudos: {
523      url: "/setoriais/estudos_setoriais.json",
524      backend: "/publicacoes/jsonPublicacoesSetoriasEstudos",
525    },
526  };
527
528  // Verifica se já existe o JSON carregado para o tipo especificado
529  if (pubsetoriais[tipo]) {
530    return pubsetoriais[tipo];
531  }
532
533  // Busca um JSON com os dados do tipo especificado
534  // Se não achar, procura no backend
535  const { url, backend } = urls[tipo];
536  let response = await fetch(`/${language}${url}`);
537  if (!response.ok) {
538    response = await fetch(`/${language}${backend}`);
539
540    if (!response.ok) {
541      return [];
542    }
543  }
544
545  const data = await response.json();
546  pubsetoriais[tipo] = data;
547  return data;
548}
549
550// TABLE FIXA
551
552$(document).ready(function () {
553  const $wrapper = $(".table-responsive");
554  const $table = $wrapper.find("table");
555
556  // Marca as linhas com cabeçalho que devem ser fixas no topo
557  $table.find("tr").each(function () {
558    const $tr = $(this);
559    if (
560      $tr.find("th").filter((_, el) => {
561        const txt = $(el).text().trim();
562        return txt.includes("Percentual (%)") || txt.includes("TOTAL");
563      }).length > 0
564    ) {
565      $tr.addClass("fixed-column");
566      $tr.find("th, td").addClass("content-cell-percentual-total");
567    }
568  });
569
570  // Achar texto "Percentual (%)" ou "TOTAL" e aplicar classes específicas
571  $table.find("th").each(function () {
572    const $th = $(this);
573    const txt = $th.text().trim();
574    if (txt.includes("Percentual (%)")) {
575      $th.addClass("head-top-cell-percentual");
576    } else if (txt.includes("TOTAL")) {
577      $th.addClass("head-top-cell-total").addClass("th-total");
578    }
579  });
580
581  // Marca as 3 primeiras linhas de cabeçalho (mesmo sem classe) como fixas
582  $table.find("tr").each(function (index) {
583    const $tr = $(this);
584    const onlyTh = $tr.children().filter("th").length === $tr.children().length;
585    const isCabecalho = onlyTh && $tr.find("th.head-top").length > 0;
586
587    if (isCabecalho && !$tr.hasClass("fixed-column") && index <= 2) {
588      $tr.addClass("fixed-column fixed-column-no-title");
589      $tr.find("th, td").addClass("content-cell-percentual-total");
590    }
591  });
592
593  // Corrige colunas da esquerda com rowspan
594  $table.find("tr").each(function () {
595    const $cells = $(this).find("th, td");
596    const $primeira = $cells.eq(0);
597    const rowspan = parseInt($primeira.attr("rowspan")) || 1;
598    if (rowspan > 1) {
599      for (let i = 1; i < rowspan; i++) {
600        const $nextRow = $table.find("tr").eq($(this).index() + i);
601        $nextRow.find("th, td").eq(0).addClass("fixed-column");
602      }
603    }
604  });
605
606  // Marcar células fixas laterais (grupo)
607  $table.find("tr").each(function () {
608    const $ths = $(this).find("th.grupo");
609    if ($ths.length >= 2) {
610      $ths.eq(0).addClass("th-fixed-column-x");
611      $ths.eq(1).addClass("th-fixed-column-x");
612    }
613  });
614
615  // Limpeza de estilos inline e alturas antigas
616  $table.find("th, td, tr").removeAttr("style");
617  $table.find("tr").removeAttr("height");
618
619  // Marcar células flexíveis
620  $table.find("th, td").each(function () {
621    const $cell = $(this);
622    const colspan = parseInt($cell.attr("colspan")) || 0;
623    const rowspan = parseInt($cell.attr("rowspan")) || 0;
624    if (colspan > 0 || rowspan > 0) {
625      $cell.addClass("flexivel-cell");
626    }
627  });
628
629  $table.find("th.flexivel-cell").each(function () {
630    const $th = $(this);
631    const colspan = parseInt($th.attr("colspan")) || 0;
632    const rowspan = parseInt($th.attr("rowspan")) || 0;
633    if (colspan > 0 && rowspan > 0) {
634      $th.addClass("flexivel-cell-rowspan-colspan-th");
635    } else if (colspan > 0) {
636      $th.addClass("flexivel-cell-colspan");
637    } else if (rowspan > 0) {
638      $th.addClass("flexivel-cell-rowspan");
639    }
640  });
641
642  $table.find("tr").each(function () {
643    const $tr = $(this);
644    const hasFlexivelCellRowspanColspan =
645      $tr.find("th.flexivel-cell-rowspan-colspan").length > 0;
646    const hasNoTd = $tr.find("td").length === 0;
647    if (hasFlexivelCellRowspanColspan && hasNoTd) {
648      $tr.addClass("fixed-column");
649    }
650  });
651
652  $table.find("td").each(function () {
653    const $td = $(this);
654    if (!$td.attr("class")) {
655      $td.addClass("conteudo-celula");
656    }
657  });
658
659  $table.find("tr").each(function () {
660    const $tr = $(this);
661    const hasGroupHeader =
662      $tr.find(
663        "th.grupo.bold.fixed-column.flexivel-cell.flexivel-cell-rowspan-colspan",
664      ).length > 0;
665    if (
666      !hasGroupHeader &&
667      !$tr.attr("class") &&
668      $tr.find("td.conteudo-celula").length > 0
669    ) {
670      $tr.addClass("tr-conteudo-linha");
671    }
672  });
673
674  // Marcar rowspan/colspan combinados
675  $table.find("th").each(function () {
676    const $th = $(this);
677    const rowspan = parseInt($th.attr("rowspan")) || 1;
678    const colspan = parseInt($th.attr("colspan")) || 1;
679    if (rowspan > 1 && colspan > 1) {
680      $th.addClass("th-rowspan-colspan");
681    } else if (rowspan > 1) {
682      $th.addClass("th-rowspan");
683    } else if (colspan > 1) {
684      $th.addClass("th-colspan");
685    }
686  });
687
688  // FINAL: aplicar top incremental para todas as linhas fixas no topo
689  let acumuladoTop = 0;
690
691  // Verifica se existe pelo menos uma linha com fixed-column-no-title
692  const temCabecalhoSecundario =
693    $table.find("tr.fixed-column-no-title").length > 0;
694
695  $table.find("tr").each(function () {
696    const $tr = $(this);
697
698    if ($tr.hasClass("fixed-column")) {
699      // Aplica o top para todas fixas
700      $tr.find("th, td").css("top", acumuladoTop + "px");
701
702      // Se for linha de TOTAL, ajusta conforme cenário
703      if ($tr.find("th.head-top-cell-total").length > 0) {
704        $tr.find("td.content-cell-percentual-total").addClass("td-total");
705
706        if (!temCabecalhoSecundario) {
707          // 🔹 Sem fixed-column-no-title: baseia apenas na altura da "Percentual (%)"
708          const alturaPercentual = $table
709            .find("th.head-top-cell-percentual")
710            .first()
711            .outerHeight(true);
712          $tr
713            .find("th.th-total, td.td-total")
714            .css("top", alturaPercentual + "px");
715        } else {
716          // 🔹 Com fixed-column-no-title: usa acumulado normalmente
717          $tr.find("th.th-total, td.td-total").css("top", acumuladoTop + "px");
718        }
719      }
720
721      acumuladoTop += $tr.outerHeight(true);
722    }
723  });
724});

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.