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

Материал из ЮУГМУ Вики
Нет описания правки
Нет описания правки
Строка 1: Строка 1:
// Get the select element and the forms
// Get the select element and the forms
var currentPageHref = decodeURI(window.location.href);
var currentPageHref = decodeURI(window.location.href);
var test = 'test';
var test = 'Главная';
if (test.indexOf(currentPageHref ) > -1) {
if (test.indexOf(currentPageHref ) > -1) {
console.log('yes');
console.log('yes');

Версия от 16:29, 19 мая 2024

// Get the select element and the forms
var currentPageHref = decodeURI(window.location.href);
var test = 'Главная';
if (test.indexOf(currentPageHref ) > -1) {
console.log('yes');
}
if (typeof(document.querySelectorAll('.createbox')) != 'undefined' && (document.querySelectorAll('.createbox')) != null) {
var forms = document.querySelectorAll('.createbox');
var select = document.createElement('select');
select.id = 'select-template';
select.className = 'mw-ui-input mw-ui-input-inline mw-inputbox-centered';


// Create the select options
var options = [
  { value: 'Шаблон:Личность', text: 'Шаблон: Личность' },
  { value: 'Шаблон:Структура', text: 'Шаблон: Структура' },
  { value: 'Шаблон:Событие', text: 'Шаблон: Событие' }
];
var opt;
for (var i = 0; i < options.length; i++) {
  opt = document.createElement('option');
  opt.value = options[i].value;
  opt.text = options[i].text;
  select.appendChild(opt);
}

// Add event listener to the select element
select.addEventListener('change', function(e) {
  var value = e.target.value;

  var form;
  for (var i = 0; i < forms.length; i++) {
    form = forms[i];
    var preloadInput = form.querySelector('input[name="preload"]');

    if (preloadInput) {
      preloadInput.value = value;
    }
  }
});
var form = document.querySelector('.createbox');
form.insertBefore(select, form.querySelector('input[name="veaction"]'));
}