Burocratas, emailconfirmed, Administradores da interface, Administradores (Semantic MediaWiki), Curadores (Semantic MediaWiki), Editores (Semantic MediaWiki), Supressores, Administradores
992
edições
Sem resumo de edição Etiqueta: Revertido |
Sem resumo de edição Etiqueta: Reversão manual |
||
/*jshint esversion: 6 */
function main() {
.querySelector('.oo-ui-inputWidget-input')
.getAttribute('title') || '00x';
tagFromDropdown = tagFromDropdown.substring(0, 3);
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 createAuthorityLinks() {
const inputs = document.body.querySelectorAll('.instanceMain div table .oo-ui-inputWidget-input');
inputs.forEach((elem) => {
const authorityLink = document.createElement('a');
authorityLink.setAttribute('title', 'Abre uma nova aba para criar ou editar um registro de autoridade');
authorityLink.setAttribute('target', '_blank');
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')
const authorityTypes = {
'Entidade coletiva': '
'Evento': '111',
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;
.querySelector('select[origname=\'Field[ind2]\'] option:checked')
// declare the 008 field default values
let directOrIndirectGeogSubdiv = ''; // 06
let descriptiveCatalogingRules = 'c'; // 10
let headingUseMainOrAddedEntry = 'a'; // 14
let headingUseSubjectAddedEntry = 'a'; // 15
let typeOfSubjectSubdivision = 'n'; // 17
let undifferentiatedPersonalName = 'n'; // 32
let levelOfEstablishment = 'a'; // 33
// set the 008 field and indicadors specific values
if (tag
if (tag === '110') {
// in case of
if (tagFromDropdown === '260')
directOrIndirectGeogSubdiv = 'n';
levelOfEstablishment = '
ind1 = '1';
}
ind2 = '';
}
if
ind1 = '2';
ind2 =
}
if (tag === '130') {
typeOfSeries =
numberedOrUnnumberedSeries = 'b';
headingUseSeriesAddedEntry = 'a';
}
if (tag === '150'
ind1 = ''; // 150 and 151 indicators must be empty in
if
}
// build the
const
headingUseSeriesAddedEntry,
Field:
},
'3':
tag:
data: '$a
}
}
};
const url = new URL(`${window.location.origin}/wiki/Special:FormEdit/AutRecord`);
// function
for (const [key, value]
for (const [key2, value2]
for (const
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);
}
});
});
}
function rmCarriageReturn() {
const textareas
textareas.forEach((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.
|