MediaWiki:MarcEditorDynamicLinks.js e MediaWiki:IndicatorsHint.js: mudanças entre as páginas
(Diferenças entre páginas)
Ir para navegação
Ir para pesquisar
Sem resumo de edição Etiqueta: Reversão manual |
(Criou página com '→jshint esversion: 10: const indicatorsByTags = { '022': { ind1: [ '# - Nível não especificado', '0 - Recurso contínuo de interesse internacional', '1 - Recurso contínuo sem interesse internacional', ], }, '041': { ind1: [ '# - Informação não fornecida', '0 - Não é tradução/não inclui tradução', '1 - É ou inclui tradução', ], ind2: [ '# - Código MARC para idiomas', '7 - Fonte...') |
||
Linha 1: | Linha 1: | ||
/* jshint esversion: 10 */ |
|||
// Author: @vitorsilverio |
|||
const indicatorsByTags = { |
|||
// Author: @jaideraf |
|||
'022': { |
|||
/*jshint esversion: 6 */ |
|||
ind1: [ |
|||
function main() { |
|||
'# - Nível não especificado', |
|||
let tag = ''; |
|||
'0 - Recurso contínuo de interesse internacional', |
|||
'1 - Recurso contínuo sem interesse internacional', |
|||
], |
|||
}, |
|||
'041': { |
|||
ind1: [ |
|||
'# - Informação não fornecida', |
|||
'0 - Não é tradução/não inclui tradução', |
|||
'1 - É ou inclui tradução', |
|||
], |
|||
ind2: [ |
|||
'# - Código MARC para idiomas', |
|||
'7 - Fonte especificada no subcampo $2', |
|||
], |
|||
}, |
|||
'045': { |
|||
ind1: [ |
|||
'# - subcampos $b ou $c não estão presentes', |
|||
'0 - data/período únicos', |
|||
'1 - data/período múltiplos', |
|||
'2 - extensão de datas/períodos', |
|||
], |
|||
}, |
|||
'080': { |
|||
ind1: ['# - Informação não fornecida', '0 - Completa', '1 - Abreviada'], |
|||
}, |
|||
'082': { |
|||
ind1: [ |
|||
'0 - Edição completa', |
|||
'1 - Edição abreviada', |
|||
'7 - Outra edição especificada no subcampo $2', |
|||
], |
|||
ind2: [ |
|||
'# - Informação não fornecida', |
|||
'0 - Atribuído pela LC', |
|||
'4 - Atribuído por outra agência', |
|||
], |
|||
}, |
|||
100: { |
|||
ind1: ['1 - Sobrenome', '0 - Prenome', '3 - Nome de família'], |
|||
}, |
|||
245: { |
|||
ind1: [ |
|||
'0 - Entrada principal para o título (sem entrada principal para uma autoria)', |
|||
'1 - Entrada secundária para o título (entrada principal para uma autoria)', |
|||
], |
|||
ind2: [ |
|||
'0 - Caracteres a serem desprezados', |
|||
'1 - Caracteres a serem desprezados', |
|||
'2 - Caracteres a serem desprezados', |
|||
'3 - Caracteres a serem desprezados', |
|||
'4 - Caracteres a serem desprezados', |
|||
'5 - Caracteres a serem desprezados', |
|||
'6 - Caracteres a serem desprezados', |
|||
'7 - Caracteres a serem desprezados', |
|||
'8 - Caracteres a serem desprezados', |
|||
'9 - Caracteres a serem desprezados', |
|||
], |
|||
}, |
|||
260: { |
|||
ind1: [ |
|||
'# - Não se aplica/nenhuma informação fornecida/editor mais antigo', |
|||
'2 - Editor intermediário', |
|||
'3 - Editor atual', |
|||
], |
|||
}, |
|||
650: { |
|||
ind1: [ |
|||
'# - Nenhuma informação fornecida', |
|||
'0 - Nível não especificado', |
|||
'1 - Primário', |
|||
'2 - Secundário', |
|||
], |
|||
ind2: [ |
|||
'4 - Fonte não especificada', |
|||
'0 - Library of Congress Subject Headings (LCSH)', |
|||
"1 - LC subject headings for children's literature", |
|||
'2 - Medical Subject Headings', |
|||
'3 - National Agricultural Library subject authority file', |
|||
'5 - Canadian Subject Headings', |
|||
'6 - Répertoire de vedettes-matière', |
|||
'7 - Fonte especificada no subcampo 2', |
|||
], |
|||
}, |
|||
700: { |
|||
ind1: ['1 - Sobrenome', '0 - Prenome', '3 - Nome de família'], |
|||
ind2: ['# - Nenhuma informação fornecida', '2 - Entrada analítica'], |
|||
}, |
|||
}; |
|||
function setIndOptions(event, ind) { |
|||
const { target } = event; |
|||
let tagFromDropdown = ''; |
let tagFromDropdown = ''; |
||
tagFromDropdown = |
|||
target |
|||
.closest('.instanceMain') |
|||
.querySelector('.oo-ui-inputWidget-input') |
|||
.getAttribute('title') ?? ' '; |
|||
tagFromDropdown = tagFromDropdown.substring(0, 3); |
|||
if (tagFromDropdown in indicatorsByTags) { |
|||
function createMarcFieldHelpLink() { |
|||
target.innerHTML = ''; |
|||
const tagInputs = document.body.querySelectorAll('.tagInput'); |
|||
const indArr = indicatorsByTags[tagFromDropdown][ind] ?? ['# - Indefinido']; |
|||
tagInputs.forEach((elem) => { |
|||
const marcFieldHelpLink = document.createElement('a'); |
|||
marcFieldHelpLink.setAttribute('target', '_blank'); |
|||
marcFieldHelpLink.innerText = '(?)'; |
|||
for (let i = 0; i < indArr.length; i += 1) { |
|||
const marcFieldHelpLinkClass = elem.closest('table') |
|||
. |
const option = document.createElement('option'); |
||
option.setAttribute('value', indArr[i][0]); |
|||
marcFieldHelpLinkClass.innerHTML = ""; |
|||
option.innerText = indArr[i]; |
|||
marcFieldHelpLinkClass.appendChild(marcFieldHelpLink); |
|||
target.appendChild(option); |
|||
} |
|||
// find the tag value from the chosen dropdown |
|||
} else { |
|||
marcFieldHelpLinkClass.addEventListener('mouseover', (event) => { |
|||
target.innerHTML = ''; |
|||
tagFromDropdown = event.target.closest('.instanceMain') |
|||
const option = document.createElement('option'); |
|||
.querySelector('.oo-ui-inputWidget-input') |
|||
option.setAttribute('value', '#'); |
|||
option.innerText = '# - Indefinido'; |
|||
tagFromDropdown = tagFromDropdown.substring(0, 3); |
|||
target.appendChild(option); |
|||
marcFieldHelpLink.setAttribute( |
|||
'title', |
|||
`Documentação do campo ${tagFromDropdown}` |
|||
); |
|||
// build the URL |
|||
if (window.location.href.match(/A\d{6}/) |
|||
|| window.location.href.match(/AutRecord/)) { |
|||
marcFieldHelpLink.setAttribute( |
|||
'href', |
|||
`http://marc.febab.org/a${tagFromDropdown}` |
|||
); |
|||
} else { |
|||
marcFieldHelpLink.setAttribute( |
|||
'href', |
|||
`https://www.loc.gov/marc/bibliographic/bd${tagFromDropdown}.html` |
|||
); |
|||
} |
|||
}); |
|||
}); |
|||
} |
} |
||
} |
|||
function setIndicators() { |
|||
const inds1 = document.body.querySelectorAll('[origname="Field[ind1]"'); |
|||
const inds2 = document.body.querySelectorAll('[origname="Field[ind2]"'); |
|||
inputs.forEach((elem) => { |
|||
inds1.forEach((ind1Elem) => { |
|||
const authorityLink = document.createElement('a'); |
|||
ind1Elem.addEventListener('focusin', (event) => { |
|||
authorityLink.setAttribute('title', 'Abre uma nova aba para criar ou editar um registro de autoridade'); |
|||
setIndOptions(event, 'ind1'); |
|||
authorityLink.innerText = 'Criar registro de autoridade'; |
|||
authorityLink.style.display = 'none'; |
|||
const createAuthorityLink = elem.closest('table') |
|||
.querySelector('.createAuthorityLink'); |
|||
createAuthorityLink.innerHTML = ""; |
|||
createAuthorityLink.appendChild(authorityLink); |
|||
const pattern1 = /\$0\sA\d{6}/; |
|||
const pattern2 = /\$0\s\(BN\)\d{9}/; |
|||
elem.addEventListener('focusout', () => { |
|||
// if already recorded |
|||
if (pattern1.test(elem.value)) { |
|||
// build the URL for Wikincat aut record edit |
|||
authorityLink.innerText = 'Editar autoridade'; |
|||
authorityLink.setAttribute( |
|||
'href', |
|||
`/wiki/Special:FormEdit/AutRecord/Autoridade:${ |
|||
elem.value.match(/A\d{6}/)}` |
|||
); |
|||
} else if (pattern2.test(elem.value)) { |
|||
// build the URL for BN aut record view |
|||
authorityLink.innerText = 'Ver registro de autoridade na BN'; |
|||
authorityLink.setAttribute( |
|||
'href', |
|||
`http://acervo.bn.gov.br/sophia_web/autoridade/detalhe/${ |
|||
elem.value.match(/\d{9}/)}` |
|||
); |
|||
} else { |
|||
// find the tag value from the chosen dropdown |
|||
tagFromDropdown = elem.closest('.instanceMain') |
|||
.querySelector('.oo-ui-inputWidget-input') |
|||
.getAttribute('title') || '00x'; |
|||
tagFromDropdown = tagFromDropdown.substring(0, 3); |
|||
// find the tag value from checked radio button |
|||
const tagFromRadio = elem.closest('.instanceMain') |
|||
.querySelector('input[origname=\'Field[authorityType]\']:checked') |
|||
.value; |
|||
const authorityTypes = { |
|||
'Pessoa': '100', |
|||
'Entidade coletiva': '110', |
|||
'Evento': '111', |
|||
'Título uniforme': '130', |
|||
'Tópico': '150', |
|||
'Local': '151' |
|||
}; |
|||
if (tagFromRadio in authorityTypes) { |
|||
tag = authorityTypes[tagFromRadio]; |
|||
} |
|||
// declare the indicators default values |
|||
let ind1 = elem.closest('.instanceMain') |
|||
.querySelector('select[origname=\'Field[ind1]\'] option:checked') |
|||
.value; |
|||
let ind2 = elem.closest('.instanceMain') |
|||
.querySelector('select[origname=\'Field[ind2]\'] option:checked') |
|||
.value; |
|||
// declare the 008 field default values |
|||
let directOrIndirectGeogSubdiv = ''; // 06 |
|||
let kindOfRecord = ''; // 09 |
|||
let descriptiveCatalogingRules = 'c'; // 10 |
|||
let subjectHeadingSystem = 'n'; // 11 |
|||
let typeOfSeries = 'n'; // 12 |
|||
let numberedOrUnnumberedSeries = 'n'; // 13 |
|||
let headingUseMainOrAddedEntry = 'a'; // 14 |
|||
let headingUseSubjectAddedEntry = 'a'; // 15 |
|||
let headingUseSeriesAddedEntry = 'b'; // 16 |
|||
let typeOfSubjectSubdivision = 'n'; // 17 |
|||
let undifferentiatedPersonalName = 'n'; // 32 |
|||
let levelOfEstablishment = 'a'; // 33 |
|||
// set the 008 field and indicadors specific values |
|||
if (tag === '100') { |
|||
undifferentiatedPersonalName = 'a'; |
|||
ind2 = ''; |
|||
} |
|||
if (tag === '110') { |
|||
// in case of autocomplete of 260 |
|||
if (tagFromDropdown === '260') { |
|||
directOrIndirectGeogSubdiv = 'n'; |
|||
kindOfRecord = 'b'; |
|||
headingUseMainOrAddedEntry = 'b'; |
|||
headingUseSubjectAddedEntry = 'b'; |
|||
levelOfEstablishment = 'n'; |
|||
ind1 = '1'; |
|||
} |
|||
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 = ''; |
|||
}); |
|||
}); |
}); |
||
} |
}); |
||
inds2.forEach((elem) => { |
|||
elem.addEventListener('focusin', (event) => { |
|||
function rmCarriageReturn() { |
|||
setIndOptions(event, 'ind2'); |
|||
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 rmTxtFromHiddenFields() { |
|||
const spans = document.body.querySelectorAll('span.hiddenByPF'); |
|||
spans.forEach((elem) => { |
|||
elem.querySelectorAll('.input.oo-ui-inputWidget-input').forEach((input) => { |
|||
const element = input; |
|||
element.value = ''; |
|||
}); |
|||
elem.querySelectorAll('textarea').forEach((input) => { |
|||
const element = input; |
|||
element.value = ''; |
|||
}); |
|||
}); |
|||
} |
|||
function normalizeInput() { |
|||
const instanceMains = document.body.querySelectorAll('.instanceMain div table'); |
|||
instanceMains.forEach((instanceMain) => { |
|||
instanceMain.querySelectorAll('.oo-ui-inputWidget-input').forEach((input) => { |
|||
const normalizedInput = input; |
|||
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'); |
|||
}); |
|||
instanceMain.querySelectorAll('textarea').forEach((textarea) => { |
|||
const normalizedInput = textarea; |
|||
textarea.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(); |
|||
rmTxtFromHiddenFields(); |
|||
rmCarriageReturn(); |
|||
rmHtmlTags(); |
|||
normalizeInput(); |
|||
}); |
}); |
||
} |
} |
||
if (document.readyState === 'complete' || (document.readyState !== 'loading')) { |
|||
main(); |
|||
} else { |
|||
document.addEventListener('DOMContentLoaded', main); |
|||
} |
|||
// for no obvious reason to me, the first call to the "main" function is not |
|||
// occurring, so wait 3 seconds and call it anyway. |
|||
setTimeout(main, 3000); |
Edição das 22h23min de 20 de março de 2024
/* jshint esversion: 10 */
const indicatorsByTags = {
'022': {
ind1: [
'# - Nível não especificado',
'0 - Recurso contínuo de interesse internacional',
'1 - Recurso contínuo sem interesse internacional',
],
},
'041': {
ind1: [
'# - Informação não fornecida',
'0 - Não é tradução/não inclui tradução',
'1 - É ou inclui tradução',
],
ind2: [
'# - Código MARC para idiomas',
'7 - Fonte especificada no subcampo $2',
],
},
'045': {
ind1: [
'# - subcampos $b ou $c não estão presentes',
'0 - data/período únicos',
'1 - data/período múltiplos',
'2 - extensão de datas/períodos',
],
},
'080': {
ind1: ['# - Informação não fornecida', '0 - Completa', '1 - Abreviada'],
},
'082': {
ind1: [
'0 - Edição completa',
'1 - Edição abreviada',
'7 - Outra edição especificada no subcampo $2',
],
ind2: [
'# - Informação não fornecida',
'0 - Atribuído pela LC',
'4 - Atribuído por outra agência',
],
},
100: {
ind1: ['1 - Sobrenome', '0 - Prenome', '3 - Nome de família'],
},
245: {
ind1: [
'0 - Entrada principal para o título (sem entrada principal para uma autoria)',
'1 - Entrada secundária para o título (entrada principal para uma autoria)',
],
ind2: [
'0 - Caracteres a serem desprezados',
'1 - Caracteres a serem desprezados',
'2 - Caracteres a serem desprezados',
'3 - Caracteres a serem desprezados',
'4 - Caracteres a serem desprezados',
'5 - Caracteres a serem desprezados',
'6 - Caracteres a serem desprezados',
'7 - Caracteres a serem desprezados',
'8 - Caracteres a serem desprezados',
'9 - Caracteres a serem desprezados',
],
},
260: {
ind1: [
'# - Não se aplica/nenhuma informação fornecida/editor mais antigo',
'2 - Editor intermediário',
'3 - Editor atual',
],
},
650: {
ind1: [
'# - Nenhuma informação fornecida',
'0 - Nível não especificado',
'1 - Primário',
'2 - Secundário',
],
ind2: [
'4 - Fonte não especificada',
'0 - Library of Congress Subject Headings (LCSH)',
"1 - LC subject headings for children's literature",
'2 - Medical Subject Headings',
'3 - National Agricultural Library subject authority file',
'5 - Canadian Subject Headings',
'6 - Répertoire de vedettes-matière',
'7 - Fonte especificada no subcampo 2',
],
},
700: {
ind1: ['1 - Sobrenome', '0 - Prenome', '3 - Nome de família'],
ind2: ['# - Nenhuma informação fornecida', '2 - Entrada analítica'],
},
};
function setIndOptions(event, ind) {
const { target } = event;
let tagFromDropdown = '';
tagFromDropdown =
target
.closest('.instanceMain')
.querySelector('.oo-ui-inputWidget-input')
.getAttribute('title') ?? ' ';
tagFromDropdown = tagFromDropdown.substring(0, 3);
if (tagFromDropdown in indicatorsByTags) {
target.innerHTML = '';
const indArr = indicatorsByTags[tagFromDropdown][ind] ?? ['# - Indefinido'];
for (let i = 0; i < indArr.length; i += 1) {
const option = document.createElement('option');
option.setAttribute('value', indArr[i][0]);
option.innerText = indArr[i];
target.appendChild(option);
}
} else {
target.innerHTML = '';
const option = document.createElement('option');
option.setAttribute('value', '#');
option.innerText = '# - Indefinido';
target.appendChild(option);
}
}
function setIndicators() {
const inds1 = document.body.querySelectorAll('[origname="Field[ind1]"');
const inds2 = document.body.querySelectorAll('[origname="Field[ind2]"');
inds1.forEach((ind1Elem) => {
ind1Elem.addEventListener('focusin', (event) => {
setIndOptions(event, 'ind1');
});
});
inds2.forEach((elem) => {
elem.addEventListener('focusin', (event) => {
setIndOptions(event, 'ind2');
});
});
}