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

replace jquery
imported>Jaideraf
(teste)
imported>Jaideraf
(replace jquery)
// make collapsible CSS clickable (space or enter to click)
// from: https://alligator.io/css/collapsible/
"use strict";
let myCollapsibleLabels = document.querySelectorAll(".lbl-toggle");
 
Array.from(myCollapsibleLabels).forEach(label => {
label.addEventListener("keydown", e => {
// 32 === spacebar
// 13 === enter
if (e.which === 32 || e.which === 13) {
e.preventDefault();
label.click();
}
});
});
///////////////////////////////////////////////////////////////////
let tag = "";
let tagFromDropdown = "";
 
function createMarcFieldHelpLink() {
const tagInputs = document.body.querySelectorAll('.tagInput');
tagInputs.forEach((elem) => {
const marcFieldHelpLink = document.createElement('a');
marcFieldHelpLink.setAttribute('target', '_blank');
marcFieldHelpLink.innerText = `(?)`;
 
const marcFieldHelpLinkClass = elem.closest('table').querySelector('.marcFieldHelpLink');
marcFieldHelpLinkClass.appendChild(marcFieldHelpLink);
 
// find the tag value from the chosen dropdown
marcFieldHelpLinkClass.addEventListener('mouseover', (event) => {
tagFromDropdown = event.target.closest('.instanceMain').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);
} "1":else {
marcFieldHelpLink.setAttribute('href', `https://www.loc.gov/marc/bibliographic/bd${tagFromDropdown}.html`);
},
});
});
}
 
function createAuthorityLinks() {
$("textarea").each(function () {
"use strict";
$("textarea").each(function() {
let authorityLink = $("<a>", {
title: "Abre uma nova aba para criar ou editar um registro de autoridade",
authorityLink.hide();
$(this).closest("table").find(".createAuthorityLink").html(authorityLink);
$(this).focusout(function () {
// if already recorded
if (pattern1.test($(this).val())) {
// build the URL for Wikincat aut record edit
authorityLink.text("Editar autoridade");
authorityLink.attr("href", "/wiki/Special:FormEdit/AutRecord/Autoridade:" +
$(this).val().match(/A\d{6}/));
} else if (pattern2.test($(this).val())) {
// build the URL for BN aut record view
authorityLink.text("Ver autoridade na BN");
authorityLink.attr("href", "http://acervo.bn.br/sophia_web/autoridade/detalhe/" +
$(this).val().match(/\d{9}/));
} else {
// find the tag value from the chosen dropdown
tagFromDropdown = $(this).closest(".instanceMain")
// PageForms 4.8
// .find(".select2-chosen").text();
// Page forms 4.9.1
.find(".select2-selection__rendered").attr("title");
tagFromDropdown = tagFromDropdown.substring(0, 3);
 
// find the tag value from checked radio button
let tagFromRadio = $(this).closest(".instanceMain")
.find("input[origname='Field[authorityType]']:checked").val();
let authorityTypes = {
"Pessoa": "100",
// declare the indicators default values
let ind1 = $(this).closest(".instanceMain")
.find("select[origname='Field[ind1]'] option:selected").val();
let ind2 = $(this).closest(".instanceMain")
.find("select[origname='Field[ind2]'] option:selected").val();
 
// declare the 008 field default values
let directOrIndirectGeogSubdiv = "", // 06
kindOfRecord = "", // 09
descriptiveCatalogingRules = "c", // 10
subjectHeadingSystem = "n", // 11
typeOfSeries = "n", // 12
numberedOrUnnumberedSeries = "n", // 13
headingUseMainOrAddedEntry = "a", // 14
headingUseSubjectAddedEntry = "a", // 15
headingUseSeriesAddedEntry = "b", // 16
typeOfSubjectSubdivision = "n", // 17
undifferentiatedPersonalName = "n", // 32
levelOfEstablishment = "a"; // 33
 
// set the 008 field and indicadors specific values
tagFromDropdown === "630" ||
tagFromDropdown === "730") {
ind2 = ind1; // an inverted value happens here, see and
ind1 = ""; // compare bib. and auth. 130 MARC definitions
}
ind1 = "";
authorityLink.text("Criar autoridade");
authorityLink.attr("href", "/wiki/Special:FormEdit/AutRecord?" +
decodeURIComponent($.param({
"AutRecord": {
"directOrIndirectGeogSubdiv": directOrIndirectGeogSubdiv,
"kindOfRecord": kindOfRecord,
"descriptiveCatalogingRules": descriptiveCatalogingRules,
"subjectHeadingSystem": subjectHeadingSystem,
"typeOfSeries": typeOfSeries,
"numberedOrUnnumberedSeries": numberedOrUnnumberedSeries,
"headingUseMainOrAddedEntry": headingUseMainOrAddedEntry,
"headingUseSubjectAddedEntry": headingUseSubjectAddedEntry,
"headingUseSeriesAddedEntry": headingUseSeriesAddedEntry,
"typeOfSubjectSubdivision": typeOfSubjectSubdivision,
"undifferentiatedPersonalName": undifferentiatedPersonalName,
"levelOfEstablishment": levelOfEstablishment
},
"Field": {
"1": {
"tag": "040",
"data": encodeURIComponent("$a BR-FlWIK $b por $c BR-FlWIK $d BR-FlUSC")
},
"2": {
"tag": tag,
"ind1": encodeURIComponent(ind1),
"ind2": encodeURIComponent(ind2),
"data": encodeURIComponent($(this).val())
},
"3Field": {
"tag1": "670",{
"datatag": "$a+040",
"data": encodeURIComponent("$a BR-FlWIK $b por $c BR-FlWIK $d BR-FlUSC")
},
"Field2": {
"tag": tag,
"ind1": encodeURIComponent(ind1),
"ind2": encodeURIComponent(ind2),
"data": encodeURIComponent($(this).val())
},
"23": {
"tag": "040670",
"data": "$a+"
}
}
})));
})));
}
authorityLink.show();
}
 
$(document).ready(function () {
"use strict";
// remove carriage return
$("span.inputSpan").find("textarea").each(function () {
let input = $(this).val();
input = input.replace("&#13;", "")
// remove any html tags
.replace(/<(?:"[^"]*"['"]*|'[^']*'['"]*|[^'">])+>/g, "");
$(this).val(input);
});
 
// calls main functions
createMarcFieldHelpLinkscreateMarcFieldHelpLink();
createAuthorityLinks();
 
 
// 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
createMarcFieldHelpLinkscreateMarcFieldHelpLink();
createAuthorityLinks();
}
 
// when save, remove text form hidden textareas
$("#wpSave").click(function () {
observer.disconnect();
$("span.hiddenByPF").find("textarea").val("");
$("textarea").each(function () {
let input = $(this).val();
// normalize input
let normalizedInput = input
// "$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");
$(this).val(normalizedInput);
});
Usuário anônimo