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

Материал из ЮУГМУ Вики
Нет описания правки
Нет описания правки
 
(не показано 25 промежуточных версий этого же участника)
Строка 1: Строка 1:
// Get the select element and the forms
// Get the select element and the forms
 
var currentPageHref = decodeURI(window.location.href);
var test = 'Вики-энциклопедия_университета:Главная';
if (currentPageHref .indexOf(test) > -1) {
var forms = document.querySelectorAll('.createbox');
var select = document.createElement('select');
var select = document.createElement('select');
select.id = 'select-template';
select.id = 'select-template';
select.className = 'mw-ui-input mw-ui-input-inline mw-inputbox-centered';
select.className = 'mw-ui-input mw-ui-input-inline mw-inputbox-centered';
var forms = document.querySelectorAll('.createbox');
 


// Create the select options
// Create the select options
var options = [
var options = [
   { value: 'Личность:', text: 'Шаблон: Личность' },
   { value: 'Шаблон:Личность', text: 'Шаблон: Личность' },
   { value: 'Подразделение:', text: 'Шаблон: Подразделение' }
  { value: 'Шаблон:Структура', text: 'Шаблон: Структура' },
   { value: 'Шаблон:Событие', text: 'Шаблон: Событие' }
];
];
var opt;
var opt;
Строка 16: Строка 20:
   opt.value = options[i].value;
   opt.value = options[i].value;
   opt.text = options[i].text;
   opt.text = options[i].text;
  console.log(opt.text);
   select.appendChild(opt);
   select.appendChild(opt);
}
}
Строка 27: Строка 30:
   for (var i = 0; i < forms.length; i++) {
   for (var i = 0; i < forms.length; i++) {
     form = forms[i];
     form = forms[i];
     var prefixInput = form.querySelector('input[name="prefix"]');
     var preloadInput = form.querySelector('input[name="preload"]');


     if (prefixInput) {
     if (preloadInput) {
       prefixInput.value = value;
       preloadInput.value = value;
     }
     }
   }
   }
});
});
 
var form = document.querySelector('.createbox');
var createbuttons = document.getElementById('create-buttons');
form.insertBefore(select, form.querySelector('input[name="veaction"]'));
var parent = createbuttons.querySelector('form.createbox');
}
var child = createbuttons.querySelector('div.mw-inputbox-centered');
parent.insertBefore(select, child);

Текущая версия от 16:31, 19 мая 2024

// Get the select element and the forms
var currentPageHref = decodeURI(window.location.href);
var test = 'Вики-энциклопедия_университета:Главная';
if (currentPageHref .indexOf(test) > -1) {
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"]'));
}