Перейти к содержанию

MediaWiki:Common.js: различия между версиями

нет описания правки
Нет описания правки
Нет описания правки
Строка 10: Строка 10:
}
}
// Get the select element and the forms
// Get the select element and the forms
const select = document.getElementById('select');
var select = document.getElementById('select');
const forms = document.querySelectorAll('.createbox');
var forms = document.querySelectorAll('.createbox');


// Create the select options
// Create the select options
const options = [
var options = [
   { value: 'Личность:', text: 'Статья про личность...' },
   { value: 'Личность:', text: 'Статья про личность...' },
   { value: 'Подразделение:', text: 'Статья про подразделение...' }
   { value: 'Подразделение:', text: 'Статья про подразделение...' }
];
];
options.forEach((option) => {
var opt;
   const opt = document.createElement('option');
for (var i = 0; i < options.length; i++) {
   opt.value = option.value;
   opt = document.createElement('option');
   opt.text = option.text;
   opt.value = options[i].value;
   opt.text = options[i].text;
   select.appendChild(opt);
   select.appendChild(opt);
});
}


// Add event listener to the select element
// Add event listener to the select element
select.addEventListener('change', (e) => {
select.addEventListener('change', function(e) {
   const value = e.target.value;
   var value = e.target.value;
   forms.forEach((form) => {
   var form;
     const prefixInput = form.querySelector('input[name="prefix"]');
  for (var i = 0; i < forms.length; i++) {
    form = forms[i];
     var prefixInput = form.querySelector('input[name="prefix"]');
     if (prefixInput) {
     if (prefixInput) {
       prefixInput.value = value;
       prefixInput.value = value;
     }
     }
   });
   }
   // Hide all forms except the one that matches the selected value
   // Hide all forms except the one that matches the selected value
   forms.forEach((form) => {
   for (var i = 0; i < forms.length; i++) {
     const prefixInput = form.querySelector('input[name="prefix"]');
    form = forms[i];
     var prefixInput = form.querySelector('input[name="prefix"]');
     if (prefixInput && prefixInput.value === value) {
     if (prefixInput && prefixInput.value === value) {
       form.style.display = 'block';
       form.style.display = 'block';
Строка 42: Строка 46:
       form.style.display = 'none';
       form.style.display = 'none';
     }
     }
   });
   }
});
});