MediaWiki:MarcEditorDynamicLinks.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
 
(3 revisões intermediárias pelo mesmo usuário não estão sendo mostradas)
Linha 1: Linha 1:
/* jshint esversion: 8 */
/* jshint esversion: 10 */
function main() {
function main() {
// calling main functions
// calling main functions
// makeMarcFieldHelpLink();
makeMarcFieldHelpLink();
// authorityLinks();
authorityLinks();
// rmCarriageReturn();
setIndicators();
// rmHtmlTags();
rmCarriageReturn();
rmHtmlTags();

// when clicking adding field...
// const addBtn = document.body.querySelector('.multipleTemplateAdder');
// addBtn.addEventListener('click', () => {
// makeMarcFieldHelpLink();
// console.log('adding btm');
// });


// Como instâncias do formulário são criadas pelo botão "Adicionar campo",
// Como instâncias do formulário são criadas pelo botão "Adicionar campo",
Linha 27: Linha 21:
if (newNodes.length !== 0) {
if (newNodes.length !== 0) {
// if there are new nodes added
// if there are new nodes added
console.log('observer before:', newNodes.length);
makeMarcFieldHelpLink();
makeMarcFieldHelpLink();
authorityLinks();
authorityLinks();
console.log('observer after');
setIndicators();
}
}
});
});
Linha 59: Linha 52:
}
}


document.addEventListener('DOMContentLoaded', function (event) {
// if (document.readyState === 'complete' || document.readyState !== 'loading') {
// main();
// console.log(document.readyState);
// } else {
// document.addEventListener('DOMContentLoaded', main);
// console.log('DOMContentLoaded');
// }

document.addEventListener("DOMContentLoaded", function(event) {
makeMarcFieldHelpLink();
authorityLinks();
main();
main();
});
});
Linha 75: Linha 58:
// for no obvious reason to me, the first call to the "main" function is not
// for no obvious reason to me, the first call to the "main" function is not
// occurring, so wait 3 seconds and call it anyway.
// occurring, so wait 3 seconds and call it anyway.
// setTimeout(main, 3000);
setTimeout(main, 3000);

Edição atual tal como às 22h24min de 20 de março de 2024

/* jshint esversion: 10 */
function main() {
  // calling main functions
  makeMarcFieldHelpLink();
  authorityLinks();
  setIndicators();
  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
  // makeMarcFieldHelpLink() e authorityLinks() 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
        makeMarcFieldHelpLink();
        authorityLinks();
        setIndicators();
      }
    });
  });

  // 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();
  });
}

document.addEventListener('DOMContentLoaded', function (event) {
  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.
setTimeout(main, 3000);