B000003 e MediaWiki:MarcEditorDynamicLinks.js: mudanças entre as páginas

(Diferenças entre páginas)
Ir para navegação Ir para pesquisar
testing and updating
imported>Jaideraf
Sem resumo de edição
 
(testing and updating)
 
// Author: @vitorsilverio
{{BibRecord
// Author: @jaideraf
|dateEnteredOnFile=090616
/*jshint esversion: 6 */
|itemType=01
function main() {
|recordStatus=n
let tag = '';
|typeOfRecord=a
let tagFromDropdown = '';
|bibliographicLevel=m
 
|encodingLevel= 
function createMarcFieldHelpLink() {
|descriptiveCatalogingForm=a
const tagInputs = document.body.querySelectorAll('.tagInput');
|multipartResourceRecordLevel= 
tagInputs.forEach((elem) => {
|typeOfDate=s
const marcFieldHelpLink = document.createElement('a');
|date1=2010
marcFieldHelpLink.setAttribute('target', '_blank');
|placeOfPublication=flu
marcFieldHelpLink.innerText = '(?)';
|illustrations=a
 
|targetAudience= 
const marcFieldHelpLinkClass = elem.closest('table')
|formOfItem=r
.querySelector('.marcFieldHelpLink');
|natureOfContents=b
marcFieldHelpLinkClass.innerHTML = "";
|governmentPublication= 
marcFieldHelpLinkClass.appendChild(marcFieldHelpLink);
|conferencePublication= 
 
|festschrift= 
// find the tag value from the chosen dropdown
|index=1
marcFieldHelpLinkClass.addEventListener('mouseover', (event) => {
|literaryForm= 
tagFromDropdown = event.target.closest('.instanceMain')
|biography= 
.querySelector('.pf-string-type--value')
|language=eng
.getAttribute('title') || '00x';
|modifiedRecord= 
tagFromDropdown = tagFromDropdown.substring(0, 3);
|catalogingSource=d
marcFieldHelpLink.setAttribute(
}}
'title',
{{Field
`Documentação do campo ${tagFromDropdown}`
|tag=020
);
|authorityType=Nenhuma
// build the URL
|ind1=#
if (window.location.href.match(/A\d{6}/)
|ind2=#
|| window.location.href.match(/AutRecord/)) {
|data=$a 9781420090505
marcFieldHelpLink.setAttribute(
}}
'href',
{{Field
`http://marc.febab.org/a${tagFromDropdown}`
|tag=035
);
|authorityType=Nenhuma
} else {
|ind1=#
marcFieldHelpLink.setAttribute(
|ind2=#
'href',
|data=$a UN003441201
`https://www.loc.gov/marc/bibliographic/bd${tagFromDropdown}.html`
}}
);
{{Field
}
|tag=035
});
|authorityType=Nenhuma
});
|ind1=#
}
|ind2=#
 
|data=$a (DLC)UN003441201
function createAuthorityLinks() {
}}
const textareas = document.body.querySelectorAll('textarea.has-authority-control');
{{Field
textareas.forEach((elem) => {
|tag=035
const authorityLink = document.createElement('a');
|authorityType=Nenhuma
authorityLink.setAttribute('title', 'Abre uma nova aba para criar ou editar um registro de autoridade');
|ind1=#
authorityLink.setAttribute('target', '_blank');
|ind2=#
authorityLink.innerText = 'Criar registro de autoridade';
|data=$a (BR-SpUEP)000673591UEP01
authorityLink.style.display = 'none';
}}
 
{{Field
const createAuthorityLink = elem.closest('table')
|tag=040
.querySelector('.createAuthorityLink');
|authorityType=Nenhuma
createAuthorityLink.innerHTML = "";
|ind1=#
createAuthorityLink.appendChild(authorityLink);
|ind2=#
 
|data=$a BIBLIODATA $b por $d BR-FlWIK
const pattern1 = /\$0\sA\d{6}/;
}}
const pattern2 = /\$0\s\(BN\)\d{9}/;
{{Field
 
|tag=082
elem.addEventListener('focusout', () => {
|authorityType=Nenhuma
// if already recorded
|ind1=0
if (pattern1.test(elem.value)) {
|ind2=4
// build the URL for Wikincat aut record edit
|data=$a 412.285
authorityLink.innerText = 'Editar autoridade';
}}
authorityLink.setAttribute(
{{Field
'href',
|tag=100
`/wiki/Special:FormEdit/AutRecord/Autoridade:${
|authorityType=Nenhuma
elem.value.match(/A\d{6}/)}`
|ind1=1
);
|ind2=#
} else if (pattern2.test(elem.value)) {
|data=$a Hitzler, Pascal
// build the URL for BN aut record view
}}
authorityLink.innerText = 'Ver registro de autoridade na BN';
{{Field
authorityLink.setAttribute(
|tag=245
'href',
|authorityType=Nenhuma
`http://acervo.bn.br/sophia_web/autoridade/detalhe/${
|ind1=1
elem.value.match(/\d{9}/)}`
|ind2=0
);
|data=$a Foundations of Semantic Web technologies / $c Pascal Hitzler, Markus Krötzsch, Sebastian Rudolph
} else {
}}
// find the tag value from the chosen dropdown
{{Field
tagFromDropdown = elem.closest('.instanceMain')
|tag=260
// PageForms 4.8
|authorityType=Nenhuma
// .find(".select2-chosen").text();
|ind1=#
// Page forms 4.9.1
|ind2=#
.querySelector('.select2-selection__rendered')
|data=$a Boca Raton : $b CRC Press, $c c2010.
.getAttribute('title') || '00x';
}}
tagFromDropdown = tagFromDropdown.substring(0, 3);
{{Field
// find the tag value from checked radio button
|tag=300
 
|authorityType=Nenhuma
const tagFromRadio = elem.closest('.instanceMain')
|ind1=#
.querySelector('input[origname=\'Field[authorityType]\']:checked')
|ind2=#
.value;
|data=$a 427 p. : $b il.
 
}}
const authorityTypes = {
{{Field
'Pessoa': '100',
|tag=490
'Entidade coletiva': '110',
|authorityType=Nenhuma
'Evento': '111',
|ind1=1
'Título uniforme': '130',
|ind2=#
'Tópico': '150',
|data=$a Chapman & Hall/CRC textbooks in computing
'Local': '151'
}}
};
{{Field
 
|tag=504
if (tagFromRadio in authorityTypes) {
|authorityType=Nenhuma
tag = authorityTypes[tagFromRadio];
|ind1=#
}
|ind2=#
 
|data=$a Inclui bibliografia e índice.
// declare the indicators default values
}}
let ind1 = elem.closest('.instanceMain')
{{Field
.querySelector('select[origname=\'Field[ind1]\'] option:checked')
|tag=650
.value;
|authorityType=Nenhuma
let ind2 = elem.closest('.instanceMain')
|ind1=#
.querySelector('select[origname=\'Field[ind2]\'] option:checked')
|ind2=7
.value;
|data=$a Web semântica
 
}}
// declare the 008 field default values
{{Field
let directOrIndirectGeogSubdiv = ''; // 06
|tag=700
let kindOfRecord = ''; // 09
|authorityType=Nenhuma
let descriptiveCatalogingRules = 'c'; // 10
|ind1=1
let subjectHeadingSystem = 'n'; // 11
|ind2=#
let typeOfSeries = 'n'; // 12
|data=$a KrötzsCH, Markus
let numberedOrUnnumberedSeries = 'n'; // 13
}}
let headingUseMainOrAddedEntry = 'a'; // 14
{{Field
let headingUseSubjectAddedEntry = 'a'; // 15
|tag=700
let headingUseSeriesAddedEntry = 'b'; // 16
|authorityType=Nenhuma
let typeOfSubjectSubdivision = 'n'; // 17
|ind1=1
let undifferentiatedPersonalName = 'n'; // 32
|ind2=#
let levelOfEstablishment = 'a'; // 33
|data=$a Rudolph, Sebastian
 
}}
// set the 008 field and indicadors specific values
{{Field
if (tag === '100') {
|tag=830
undifferentiatedPersonalName = 'a';
|authorityType=Nenhuma
ind2 = '';
|ind1=#
}
|ind2=1
if (tag === '110') {
|data=$a Chapman & Hall/CRC textbooks in computing
// in case of autocomplete of 260
}}
if (tagFromDropdown === '260') {
{{Field
directOrIndirectGeogSubdiv = 'n';
|tag=856
kindOfRecord = 'b';
|authorityType=Nenhuma
headingUseMainOrAddedEntry = 'b';
|ind1=4
headingUseSubjectAddedEntry = 'b';
|ind2=2
levelOfEstablishment = 'n';
|data=$u https://covers.openlibrary.org/b/isbn/9781420090505-M.jpg $y Imagem
ind1 = '1';
}}
}
{{EndOfRecord}}
ind2 = '';
}
if (tag === '111') {
ind1 = '2';
ind2 = '';
}
if (tag === '130') {
typeOfSeries = 'a';
numberedOrUnnumberedSeries = 'b';
headingUseSeriesAddedEntry = 'a';
if (tagFromDropdown === '130'
|| tagFromDropdown === '630'
|| tagFromDropdown === '730') {
ind2 = ind1; // an inverted value happens here, see and
ind1 = ''; // compare bib. and auth. 130 MARC definitions
}
ind1 = '';
}
if (tag === '150' || tag === '151') {
descriptiveCatalogingRules = 'n';
subjectHeadingSystem = 'z';
headingUseMainOrAddedEntry = 'b';
ind1 = ''; // 150 and 151 indicators must be empty in
ind2 = ''; // authority MARC records
if (tag === '151') {
typeOfSubjectSubdivision = 'd';
}
}
// build the URL
const autRecordParams = {
AutRecord: {
directOrIndirectGeogSubdiv,
kindOfRecord,
descriptiveCatalogingRules,
subjectHeadingSystem,
typeOfSeries,
numberedOrUnnumberedSeries,
headingUseMainOrAddedEntry,
headingUseSubjectAddedEntry,
headingUseSeriesAddedEntry,
typeOfSubjectSubdivision,
undifferentiatedPersonalName,
levelOfEstablishment
},
Field: {
'1': {
tag: '040',
data: '$a BR-FlWIK $b por $c BR-FlWIK $d BR-FlUSC'
},
'2': {
tag,
ind1,
ind2,
data: elem.value
},
'3': {
tag: '670',
data: '$a '
}
}
};
 
const url = new URL(`${window.location.origin}/wiki/Special:FormEdit/AutRecord`);
// function to transform a 3rd level object to URL query strings
const makeUrlParams = (obj) => {
for (const [key, value] of Object.entries(obj)) {
if (typeof value === 'object') {
for (const [key2, value2] of Object.entries(value)) {
if (typeof value2 === 'object') {
for (const [key3, value3] of Object.entries(value2)) {
url.searchParams.set(`${key}[${key2}][${key3}]`, value3);
}
} else {
url.searchParams.set(`${key}[${key2}]`, value2);
}
}
} else {
url.searchParams.set(key, value);
}
}
};
makeUrlParams(autRecordParams);
authorityLink.innerText = 'Criar registro de autoridade';
authorityLink.setAttribute('href', url.pathname + url.search);
}
authorityLink.style.display = '';
});
});
}
 
function rmCarriageReturn() {
const textareas = document.body.querySelectorAll('textarea');
textareas.forEach((textarea) => {
const element = textarea;
element.value = element.value.replace('
', '');
});
}
 
function rmHtmlTags() {
const textareas = document.body.querySelectorAll('textarea');
textareas.forEach((textarea) => {
const element = textarea;
element.value = element.value.replace(/<(?:"[^"]*"['"]*|'[^']*'['"]*|[^'">])+>/g, '');
});
}
 
function rmTxtFromHiddenTexareas() {
const textareas = document.body.querySelectorAll('span.hiddenByPF');
textareas.forEach((elem) => {
elem.querySelectorAll('textarea').forEach((textarea) => {
const element = textarea;
element.value = '';
});
});
}
 
function normalizeInput() {
const textareas = document.body.querySelectorAll('textarea');
textareas.forEach((textarea) => {
const normalizedInput = textarea;
normalizedInput.value = normalizedInput.value
// "$a Bar \n$b Baz" > " $a Bar $b Baz"
.replace(/\s*(\$[a-z0-8])\s*/g, ' $1 ')
// "$a Bar\nFoo" > "$a Bar Foo" ou "$a Bar Foo" > "$a Bar Foo"
.replace(/\n|\s\s+|\t/g, ' ')
// replace "|" by "%7C" (Ex.: http://viaf.org/processed/WKP|Q2484404)
.replace('|', '%7C');
});
}
 
// calls main functions
createMarcFieldHelpLink();
createAuthorityLinks();
rmCarriageReturn();
rmHtmlTags();
 
// Como instâncias do formulário são criadas pelo botão "Adicionar campo",
// é necessário observar o DOM a partir da classe ".multipleTemplateList".
// Toda vez que o DOM é alterado (mais especificamente, quando uma nova
// child de ".multipleTemplateList" é criada), as funções
// createMarcFieldHelpLink() e createAuthorityLinks() são novamente chamadas.
// https://developer.mozilla.org/en-US/docs/Web/API/MutationObserver
 
// create an observer instance
const observer = new MutationObserver((mutations) => {
mutations.forEach((mutation) => {
const newNodes = mutation.addedNodes; // DOM NodeList
if (newNodes.length !== 0) { // if there are new nodes added
createMarcFieldHelpLink();
createAuthorityLinks();
}
});
});
 
// select the target node
const target = document.querySelector('.multipleTemplateList');
 
// configuration of the observer
const config = {
childList: true,
attributes: false,
subtree: false,
};
 
// pass in the target node, as well as the observer options
observer.observe(target, config);
 
// when clicking save...
const saveBtn = document.body.querySelector('#wpSave');
saveBtn.addEventListener('click', () => {
observer.disconnect();
rmTxtFromHiddenTexareas();
rmCarriageReturn();
rmHtmlTags();
normalizeInput();
});
}
 
if (document.readyState === 'complete' || (document.readyState !== 'loading')) {
main();
} else {
document.addEventListener('DOMContentLoaded', main);
}

Menu de navegação