PageSourceSearch

https://protestors.com.br/Scripts/Sistema/CEP.js

js protestors.com.br collected 2026-10-04 23:54:58 UTC 3,657 bytes, 107 lines download raw bytes

1function CEP(url, urlEstado, urlCidade, logradouroID, bairroID, estadoID, cidadeID, hiddenCidadeID, numeroID) {
2    this.url = url;
3    this.urlEstado = urlEstado;
4    this.urlCidade = urlCidade;
5    this.logradouroID = logradouroID;
6    this.bairroID = bairroID;
7    this.estadoID = estadoID;
8    this.cidadeID = cidadeID;
9    this.hiddenCidadeID = hiddenCidadeID;
10    this.numeroID = numeroID;
11}
12
13CEP.prototype = {
14    constructor: CEP,
15    BuscarCEP: function (cep) {
16        var self = this;
17
18        LoadingShow();
19
20        $.ajax({
21            url: this.url,
22            data: { cep: cep },
23            success: function (retorno) {
24
25                if (JSON.parse(retorno) == null) {
26                    LoadingHide();
27                    return;
28                }
29                
30                $('#' + self.logradouroID).val(JSON.parse(retorno).Logradouro);
31                $('#' + self.bairroID).val(JSON.parse(retorno).Bairro);
32                
33                var estadoID = self.ObterEstadoPelaSigla(JSON.parse(retorno).Estado);
34                var cidadeID = self.ObterEstadoCidadePeloNomeEhEstado(JSON.parse(retorno).Cidade, estadoID);
35
36                $('#' + self.hiddenCidadeID).val(cidadeID);
37                $('#' + self.estadoID).val(estadoID).trigger('change');
38                $('#' + self.cidadeID).val(cidadeID).trigger('change');
39
40                LoadingHide();
41
42                $('#' + self.numeroID).focus();
43            },
44            error: function (xhr, ajaxOptions, thrownError) {
45                LoadingHide();
46                alert(xhr.responseText);
47                alert(thrownError);
48            }
49        });
50    },
51    ObterEstadoPelaSigla: function (sigla) {
52        var self = this;
53        var enderecoID;
54        $.ajax({
55            url: this.urlEstado,
56            data: { siglaEstado: sigla },
57            async: false,
58            success: function (response) {
59                enderecoID = JSON.parse(response).Id;
60            },
61            error: function (xhr, ajaxOptions, thrownError) {
62                alert(xhr.responseText);
63                alert(thrownError);
64            }
65        });
66
67        return enderecoID;
68    },
69    ObterEstadoCidadePeloNomeEhEstado: function (cidade, estadoID) {
70        var self = this;
71        var cidadeID;
72        $.ajax({
73            url: this.urlCidade,
74            data: { cidade: cidade, estadoID: estadoID },
75            async: false,
76            success: function (retorno) {
77                cidadeID = JSON.parse(retorno).Id;
78            },
79            error: function (xhr, ajaxOptions, thrownError) {
80                alert(xhr.responseText);
81                alert(thrownError);
82            }
83        });
84        return cidadeID;
85    }
86}
87
88$(document).on("blur", ".input-cep", function () {
89    var $this = $(this);
90
91    if ($this.val().trim() == "" || $this.val().trim() == "_____-___")
92        return;
93
94    var cep = new CEP('/Cidade/BuscaCEP',
95        '/Cidade/ObterEstadoPelaSigla',
96        '/Cidade/ObterCidadePeloNomeEhEstado',
97        $this.closest("#divEndereco").find(".input-logradouro:first").attr("id"),
98        $this.closest("#divEndereco").find(".input-bairro:first").attr("id"),
99        $this.closest("#divEndereco").find(".input-estado:first").attr("id"),
100        $this.closest("#divEndereco").find(".input-cidade:first").attr("id"),
101        $this.closest("#divEndereco").find(".cidade-hidden:first").attr("id"),
102        $this.closest("#divEndereco").find(".input-numero:first").attr("id"));
103
104    cep.BuscarCEP($this.val());
105
106    
107});

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.