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

De Wikincat
Ir para navegação Ir para pesquisar
Sem resumo de edição
Sem resumo de edição
 
Linha 1: Linha 1:
/* jshint esversion: 10 */
/* jshint esversion: 10 */
function setIndOptions(event, ind) {
function findTagFromDropdown(event) {
const { target } = event;
const { target } = event;
let tagFromDropdown = '';
let tagFromDropdown = '';
Linha 8: Linha 8:
.querySelector('[mappingtemplate$="Record/tags"]')
.querySelector('[mappingtemplate$="Record/tags"]')
.getAttribute('title') ?? ' ';
.getAttribute('title') ?? ' ';
tagFromDropdown = tagFromDropdown.substring(0, 3);
return tagFromDropdown.substring(0, 3);
}

function setIndOptions(event, ind) {
const { target } = event;
const tagFromDropdown = findTagFromDropdown(event);


if (tagFromDropdown in indicatorsByTags) {
if (tagFromDropdown in indicatorsByTags) {
Linha 26: Linha 31:
option.innerText = '# - Indefinido';
option.innerText = '# - Indefinido';
target.appendChild(option);
target.appendChild(option);
}
}

function setPlaceholder(event) {
const { target } = event;
const tagFromDropdown = findTagFromDropdown(event);

if (tagFromDropdown in indicatorsByTags) {
const placeholder =
indicatorsByTags[tagFromDropdown].placeholder ?? '$a ... $b ... $c ...';
target.setAttribute('placeholder', placeholder);
}
}
}
}
Linha 32: Linha 48:
const inds1 = document.body.querySelectorAll('[origname="Field[ind1]"');
const inds1 = document.body.querySelectorAll('[origname="Field[ind1]"');
const inds2 = document.body.querySelectorAll('[origname="Field[ind2]"');
const inds2 = document.body.querySelectorAll('[origname="Field[ind2]"');
const textareas = document.body.querySelectorAll('textarea');

inds1.forEach((ind1Elem) => {
inds1.forEach((ind1Elem) => {
ind1Elem.addEventListener('focusin', (event) => {
ind1Elem.addEventListener('focusin', (event) => {
Linha 40: Linha 58:
elem.addEventListener('focusin', (event) => {
elem.addEventListener('focusin', (event) => {
setIndOptions(event, 'ind2');
setIndOptions(event, 'ind2');
});
});
textareas.forEach((elem) => {
elem.addEventListener('focusin', (event) => {
setPlaceholder(event);
});
});
});
});

Edição atual tal como às 18h10min de 22 de março de 2024

/* jshint esversion: 10 */
function findTagFromDropdown(event) {
  const { target } = event;
  let tagFromDropdown = '';
  tagFromDropdown =
    target
      .closest('.instanceMain')
      .querySelector('[mappingtemplate$="Record/tags"]')
      .getAttribute('title') ?? '   ';
  return tagFromDropdown.substring(0, 3);
}

function setIndOptions(event, ind) {
  const { target } = event;
  const tagFromDropdown = findTagFromDropdown(event);

  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 setPlaceholder(event) {
  const { target } = event;
  const tagFromDropdown = findTagFromDropdown(event);

  if (tagFromDropdown in indicatorsByTags) {
    const placeholder =
      indicatorsByTags[tagFromDropdown].placeholder ?? '$a ... $b ... $c ...';
    target.setAttribute('placeholder', placeholder);
  }
}

function setIndicators() {
  const inds1 = document.body.querySelectorAll('[origname="Field[ind1]"');
  const inds2 = document.body.querySelectorAll('[origname="Field[ind2]"');
  const textareas = document.body.querySelectorAll('textarea');

  inds1.forEach((ind1Elem) => {
    ind1Elem.addEventListener('focusin', (event) => {
      setIndOptions(event, 'ind1');
    });
  });
  inds2.forEach((elem) => {
    elem.addEventListener('focusin', (event) => {
      setIndOptions(event, 'ind2');
    });
  });
  textareas.forEach((elem) => {
    elem.addEventListener('focusin', (event) => {
      setPlaceholder(event);
    });
  });
}