MediaWiki:AddressFromCepJqueryVersion.js e B000002: mudanças entre as páginas

(Diferenças entre páginas)
Ir para navegação Ir para pesquisar
sem sumário de edição
imported>Jaideraf
m (uma edição)
 
imp>Jaider
Sem resumo de edição
 
{{BibRecord
// Adapted from https://viacep.com.br/exemplo/jquery/
|dateEnteredOnFile=191004
$(document).ready(function () {
|recordStatus=n
"use strict";
|typeOfRecord=a
function cleanAddressFields() {
|bibliographicLevel=m
// It cleans values from address fields.
|encodingLevel=4
// "\\" is the scape way of jQuery
|descriptiveCatalogingForm=a
$("[name=User\\[street\\]]").val("");
|multipartResourceRecordLevel= 
$("[name=User\\[neighborhood\\]]").val("");
|controlField007=ta
$("[name=User\\[Has\\ city\\]]").val("");
|typeOfDate=t
$("[name=User\\[state\\]]").val("");
|date1=uuuu
}
|date2=2015
// When CEP field ("postalCode") loses focus.
|placeOfPublication=bl
$("[name=User\\[postalCode\\]]").blur(function () {
|illustrations= 
// A new variable "cep" is made with only digits.
|targetAudience=g
var cep = $(this).val().replace(/\D/g, "");
|formOfItem= 
// Testing if the CEP variable has any value.
|natureOfContents= 
if (cep !== "") {
|governmentPublication= 
// Regular expression to validate CEP.
|conferencePublication= 
var cepValidator = /^[0-9]{8}$/;
|festschrift= 
// Testing CEP validation. If true...
|index= 
if (cepValidator.test(cep)) {
|literaryForm=f
// It fills the address fields with "..." while the web service is busy.
|biography= 
$("[name=User\\[street\\]]").val("...");
|language=por
$("[name=User\\[neighborhood\\]]").val("...");
|modifiedRecord= 
$("[name=User\\[Has\\ city\\]]").val("...");
|catalogingSource=d
$("[name=User\\[state\\]]").val("...");
}}
// It queries the web service viacep.com.br
{{Field
$.getJSON("https://viacep.com.br/ws/" + cep + "/json/?callback=?", function (dados) {
|tag=020
if (!("erro" in dados)) {
|authorityType=Nenhuma
// It updates the address fields with the data from the query.
|ind1=#
$("[name=User\\[street\\]]").val(dados.logradouro);
|ind2=#
$("[name=User\\[neighborhood\\]]").val(dados.bairro);
|data=$a 9788536808246
$("[name=User\\[Has\\ city\\]]").val(dados.localidade);
}}
$("[name=User\\[state\\]]").val(dados.uf);
{{Field
}
|tag=040
else {
|authorityType=Nenhuma
// The CEP searched was not found.
|ind1=#
cleanAddressFields();
|ind2=#
alert("CEP não encontrado.");
|data=$a BR-RjBN $b por $c BR-RjBN $d BR-FlWIK
}
}}
});
{{Field
}
|tag=043
else {
|authorityType=Nenhuma
// The CEP is invalid.
|ind1=#
cleanAddressFields();
|ind2=#
alert("Formato de CEP inválido.");
|data=$a s-bl---
}
}}
}
{{Field
else {
|tag=082
// The CEP is empty, it cleans the form fields.
|authorityType=Nenhuma
cleanAddressFields();
|ind1=0
}
|ind2=4
});
|data=$2 23 $a B869.3
});
}}
{{Field
|tag=100
|authorityType=Pessoa
|ind1=1
|ind2=#
|authorityData100=$a Assis, Machado de, $d 1839-1908 $0 A000001
}}
{{Field
|tag=245
|authorityType=Nenhuma
|ind1=1
|ind2=0
|data=$a Memórias póstumas de Brás Cubas / $c Machado de Assis.
}}
{{Field
|tag=260
|authorityType=Nenhuma
|ind1=#
|ind2=#
|data=$a São Paulo : $b Difusão Cultural do Livro, $c c2015.
}}
{{Field
|tag=300
|authorityType=Nenhuma
|ind1=#
|ind2=#
|data=$a 184 p. ; $c 21 cm
}}
{{Field
|tag=490
|authorityType=Nenhuma
|ind1=1
|ind2=#
|data=$a Grandes nomes da literatura
}}
{{Field
|tag=500
|authorityType=Nenhuma
|ind1=#
|ind2=#
|data=$a Na capa: Texto integral com comentários.
}}
{{Field
|tag=650
|authorityType=Nenhuma
|ind1=0
|ind2=4
|data=$a Ficção brasileira
}}
{{Field
|tag=830
|authorityType=Nenhuma
|ind1=#
|ind2=0
|data=$a Grandes nomes da literatura
}}
{{EndOfRecord}}
Usuário anônimo

Menu de navegação