MediaWiki:MarcEditorDynamicLinks.js: mudanças entre as edições

Conteúdo deletado Conteúdo adicionado
Sem resumo de edição
Sem resumo de edição
Linha 1:
// Author: @vitorsilverio
// Author: @jaideraf
if (document.readyState === '"complete'" || (document.readyState !== '"loading'")) {
main();
} else {
document.addEventListener('"DOMContentLoaded'", main);
}
 
Linha 12:
 
function createMarcFieldHelpLink() {
const tagInputs = document.body.querySelectorAll('".tagInput'");
tagInputs.forEach(elemfunction =>(elem) {
const marcFieldHelpLink = document.createElement('"a'");
marcFieldHelpLink.setAttribute('"target'", '"_blank'");
marcFieldHelpLink.innerText = `(?)`;
 
const marcFieldHelpLinkClass = elem.closest('"table'").querySelector('.marcFieldHelpLink');
.querySelector(".marcFieldHelpLink");
marcFieldHelpLinkClass.appendChild(marcFieldHelpLink);
 
// find the tag value from the chosen dropdown
marcFieldHelpLinkClass.addEventListener('"mouseover'", eventfunction =>(event) {
tagFromDropdown = event.target.closest('".instanceMain'").querySelector('.select2-selection__rendered').getAttribute('title');
.querySelector(".select2-selection__rendered")
.getAttribute("title");
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);
"http://marc.febab.org/a" + tagFromDropdown);
} else {
marcFieldHelpLink.setAttribute('"href'", `https://www.loc.gov/marc/bibliographic/bd${tagFromDropdown}.html`);
`https://www.loc.gov/marc/bibliographic/bd${tagFromDropdown}.html`);
}
});
Linha 39 ⟶ 44:
 
function createAuthorityLinks() {
const textareas = document.body.querySelectorAll('"textarea.has-authority-control'");
textareas.forEach(elemfunction =>(elem) {
let 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 autoridade'";
authorityLink.style.display = '"none'";
 
let createAuthorityLink = elem.closest('"table'").querySelector('.createAuthorityLink');
.querySelector(".createAuthorityLink");
 
createAuthorityLink.appendChild(authorityLink);
 
letconst pattern1 = /\$0\sA\d{6}/;
letconst pattern2 = /\$0\s\(BN\)\d{9}/;
 
elem.addEventListener('"focusout'", function () => {
// 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 autoridade na BN'";
authorityLink.setAttribute('"href'",
'"http://acervo.bn.br/sophia_web/autoridade/detalhe/'" +
elem.value.match(/\d{9}/));
} else {
Linha 74 ⟶ 80:
// .find(".select2-chosen").text();
// Page forms 4.9.1
.querySelector('".select2-selection__rendered'")
.getAttribute('"title'");
tagFromDropdown = tagFromDropdown.substring(0, 3);
// find the tag value from checked radio button
 
let tagFromRadio = elem.closest('".instanceMain'")
.querySelector("input[origname='Field[authorityType]']:checked")
.value;
 
letconst authorityTypes = {
"Pessoa": "100",
"Entidade coletiva": "110",
Linha 162 ⟶ 168:
}
// build the URL
letconst autRecordParams = {
"AutRecord": {
"directOrIndirectGeogSubdiv": directOrIndirectGeogSubdiv,
Linha 195 ⟶ 201:
};
 
let url = new URL(location.origin + '"/wiki/Special:FormEdit/AutRecord'");
// function to transform a 3rd level object to URL query strings
const makeUrlParams = (obj) => {
for (constlet [key, value] of Object.entries(obj)) {
if (typeof value === '"object'") {
for (constlet [key2, value2] of Object.entries(value)) {
if (typeof value2 === '"object'") {
for (constlet [key3, value3] of Object.entries(value2)) {
url.searchParams.set(`${key}[${key2}][${key3}]`, value3);
}
Linha 215 ⟶ 222:
};
makeUrlParams(autRecordParams);
authorityLink.innerText = '"Criar autoridade'";
authorityLink.setAttribute("href", url.pathname + url.search);
}
authorityLink.style.display = ''"";
});
});
Linha 224 ⟶ 231:
 
function rmCarriageReturn() {
const textareas = document.body.querySelectorAll('"textarea'");
textareas.forEach(elem => {
elem.value = elem.value.replace("
", "");
Linha 231 ⟶ 238:
 
function rmHtmlTags() {
const textareas = document.body.querySelectorAll('"textarea'");
textareas.forEach(elem => {
elem.value = elem.value.replace(/<(?:"[^"]*"['"]*|'[^']*'['"]*|[^'">])+>/g, "");
Linha 238 ⟶ 245:
 
function rmTxtFromHiddenTexareas() {
const textareas = document.body.querySelectorAll('"span.hiddenByPF'");
textareas.forEach(elem => {
elem.querySelectorAll('"textarea'").forEach(elem => {
elem.value = ''"";
});
});
Linha 247 ⟶ 254:
 
function normalizeInput() {
const textareas = document.body.querySelectorAll('"textarea'");
textareas.forEach(elem => {
let normalizedInput = elem.value;
Linha 270 ⟶ 277:
// é 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), aas funçãofunções
// marcEditorDynamicLinkscreateMarcFieldHelpLink() ée createAuthorityLinks() são novamente chamadachamadas.
// https://developer.mozilla.org/en-US/docs/Web/API/MutationObserver
 
// create an observer instance
let observer = new MutationObserver(function (mutations) {
mutations.forEach(function (mutation) => {
let newNodes = mutation.addedNodes; // DOM NodeList
if (newNodes.length !== 0) { // if there are new nodes added
Linha 286 ⟶ 293:
 
// select the target node
letconst target = document.querySelector(".multipleTemplateList");
 
// configuration of the observer
Linha 299 ⟶ 306:
 
// when clicking save...
const saveBtn = document.body.querySelector('"#wpSave'");
saveBtn.addEventListener('"click'", () => {
observer.disconnect();
rmTxtFromHiddenTexareas();