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 ===
main();
} else {
document.addEventListener(
}
Linha 12:
function createMarcFieldHelpLink() {
const tagInputs = document.body.querySelectorAll(
tagInputs.forEach(
const marcFieldHelpLink = document.createElement(
marcFieldHelpLink.setAttribute(
marcFieldHelpLink.innerText = `(?)`;
const marcFieldHelpLinkClass = elem.closest(
.querySelector(".marcFieldHelpLink");
marcFieldHelpLinkClass.appendChild(marcFieldHelpLink);
// find the tag value from the chosen dropdown
marcFieldHelpLinkClass.addEventListener(
tagFromDropdown = event.target.closest(
.querySelector(".select2-selection__rendered")
.getAttribute("title");
tagFromDropdown = tagFromDropdown.substring(0, 3);
marcFieldHelpLink.setAttribute(
`Documentação do campo ${tagFromDropdown}`);
// build the URL
if (window.location.href.match(/A\d{6}/) ||
window.location.href.match(/AutRecord/)) {
marcFieldHelpLink.setAttribute(
"http://marc.febab.org/a" + tagFromDropdown);
} else {
marcFieldHelpLink.setAttribute(
`https://www.loc.gov/marc/bibliographic/bd${tagFromDropdown}.html`);
}
});
Linha 39 ⟶ 44:
function createAuthorityLinks() {
const textareas = document.body.querySelectorAll(
textareas.forEach(
let authorityLink = document.createElement(
authorityLink.setAttribute(
authorityLink.setAttribute(
authorityLink.innerText =
authorityLink.style.display =
let createAuthorityLink = elem.closest(
.querySelector(".createAuthorityLink");
createAuthorityLink.appendChild(authorityLink);
elem.addEventListener(
// if already recorded
if (pattern1.test(elem.value)) {
// build the URL for Wikincat aut record edit
authorityLink.innerText =
authorityLink.setAttribute(
elem.value.match(/A\d{6}/));
} else if (pattern2.test(elem.value)) {
// build the URL for BN aut record view
authorityLink.innerText =
authorityLink.setAttribute(
elem.value.match(/\d{9}/));
} else {
Linha 74 ⟶ 80:
// .find(".select2-chosen").text();
// Page forms 4.9.1
.querySelector(
.getAttribute(
tagFromDropdown = tagFromDropdown.substring(0, 3);
// find the tag value from checked radio button
let tagFromRadio = elem.closest(
.querySelector("input[origname='Field[authorityType]']:checked")
.value;
"Pessoa": "100",
"Entidade coletiva": "110",
Linha 162 ⟶ 168:
}
// build the URL
"AutRecord": {
"directOrIndirectGeogSubdiv": directOrIndirectGeogSubdiv,
Linha 195 ⟶ 201:
};
let url = new URL(location.origin +
// function to transform a 3rd level object to URL query strings
const makeUrlParams = (obj) => {
for (
if (typeof value ===
for (
if (typeof value2 ===
for (
url.searchParams.set(`${key}[${key2}][${key3}]`, value3);
}
Linha 215 ⟶ 222:
};
makeUrlParams(autRecordParams);
authorityLink.innerText =
authorityLink.setAttribute("href", url.pathname + url.search);
}
authorityLink.style.display =
});
});
Linha 224 ⟶ 231:
function rmCarriageReturn() {
const textareas = document.body.querySelectorAll(
textareas.forEach(elem => {
elem.value = elem.value.replace(" ", "");
Linha 231 ⟶ 238:
function rmHtmlTags() {
const textareas = document.body.querySelectorAll(
textareas.forEach(elem => {
elem.value = elem.value.replace(/<(?:"[^"]*"['"]*|'[^']*'['"]*|[^'">])+>/g, "");
Linha 238 ⟶ 245:
function rmTxtFromHiddenTexareas() {
const textareas = document.body.querySelectorAll(
textareas.forEach(elem => {
elem.querySelectorAll(
elem.value =
});
});
Linha 247 ⟶ 254:
function normalizeInput() {
const textareas = document.body.querySelectorAll(
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),
//
// https://developer.mozilla.org/en-US/docs/Web/API/MutationObserver
// create an observer instance
let observer = new MutationObserver(function (mutations) {
mutations.forEach
let newNodes = mutation.addedNodes; // DOM NodeList
if (newNodes.length !== 0) { // if there are new nodes added
Linha 286 ⟶ 293:
// select the target node
// configuration of the observer
Linha 299 ⟶ 306:
// when clicking save...
const saveBtn = document.body.querySelector(
saveBtn.addEventListener(
observer.disconnect();
rmTxtFromHiddenTexareas();
| |||