MediaWiki:AddressFromCep.js e B000064: mudanças entre as páginas

(Diferenças entre páginas)
Ir para navegação Ir para pesquisar
sem sumário de edição
imp>Jaider
(version without jQuery)
 
imported>Bastrosy
Sem resumo de edição
 
{{BibRecord
// Adapted from https://viacep.com.br/exemplo/javascript/
|dateEnteredOnFile=230911
function cleanAddressesFields() {
|itemType=03
// It cleans values from addresses fields.
|recordStatus=n
document.getElementById("input_6").value = ("");
|typeOfRecord=i
document.getElementById("input_7").value = ("");
|bibliographicLevel=m
document.getElementById("input_8").value = ("");
|encodingLevel= 
document.getElementById("input_9").value = ("");
|descriptiveCatalogingForm=a
}
|multipartResourceRecordLevel= 
function myCallback(dados) {
|typeOfDate=s
if (!("erro" in dados)) {
|date2=2008
// It updates the addresses fields with the data from the query.
|placeOfPublication=spb
document.getElementById("input_6").value = (dados.logradouro);
|illustrations= 
document.getElementById("input_7").value = (dados.bairro);
|targetAudience=g
document.getElementById("input_8").value = (dados.localidade);
|formOfItem=q
document.getElementById("input_9").value = (dados.uf);
|natureOfContents= 
}
|governmentPublication= 
else {
|conferencePublication= 
// The CEP searched was not found.
|festschrift= 
cleanAddressesFields();
|index= 
alert("CEP não encontrado.");
|literaryForm=1
}
|biography=d
}
|language=por
function searchCep(value) {
|modifiedRecord= 
// A new variable "cep" is made with only digits.
|catalogingSource=d
let cep = value.replace(/\D/g, "");
}}
// Testing if the CEP variable has any value.
{{Field
if (cep !== "") {
|tag=020
// Regular expression to validate CEP.
|authorityType=Nenhuma
let cepValidator = /^[0-9]{8}$/;
|ind1=#
// Testing CEP validation. If true...
|ind2=#
if (cepValidator.test(cep)) {
|data=$a 9788561559120
// It fills the address fields with "..." while the web service is busy.
}}
document.getElementById("input_6").value = "...";
{{Field
document.getElementById("input_7").value = "...";
|tag=040
document.getElementById("input_8").value = "...";
|authorityType=Nenhuma
document.getElementById("input_9").value = "...";
|ind1=#
// It creates a javaScript element.
|ind2=#
let script = document.createElement("script");
|data=$a BR-FlWIK $b por $c BR-FlWIK $d BR-FlUSC
// It sincronizes with callback.
}}
script.src = "https://viacep.com.br/ws/" + cep + "/json/?callback=myCallback";
{{Field
// It inserts the script into the document and load the contents.
|tag=080
document.body.appendChild(script);
|authorityType=Nenhuma
}
|ind1=#
else {
|ind2=#
// The CEP is invalid.
|data=$a 820(73)-31
cleanAddressesFields();
}}
alert("Formato de CEP inválido.");
{{Field
}
|tag=090
}
|authorityType=Nenhuma
else {
|ind1=#
// The CEP is empty, it cleans the form fields.
|ind2=#
cleanAddressesFields();
|data=$a 820(73)-31 $b Y19q
}
}}
{{Field
document.getElementById("input_4").setAttribute("onblur", "searchCep(this.value)");
|tag=100
|authorityType=Pessoa
|ind1=1
|ind2=#
|authorityData100=$a Yalom, Irvin D., $d 1931- $0 (BN)000195618
}}
{{Field
|tag=245
|authorityType=Nenhuma
|ind1=1
|ind2=#
|data=$a Quando Nietzche chorou $h [gravação de som (audiolivro)] / $c Irvin D. Yalom ; na voz de José Wilker
}}
{{Field
|tag=260
|authorityType=Nenhuma
|ind1=#
|ind2=#
|data=$a Jurubatuba, SP : $b Plugme, $c [2008?]
}}
{{Field
|tag=300
|authorityType=Nenhuma
|ind1=#
|ind2=#
|data=$a CD MP3 (18 horas)
}}
{{EndOfRecord}}
Usuário anônimo

Menu de navegação