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

Материал из ЮУГМУ Вики
Нет описания правки
Нет описания правки
 
(не показано 70 промежуточных версий этого же участника)
Строка 1: Строка 1:
if (document.readyState !== 'loading') {
// Get the select element and the forms
  console.log('document is already ready, just execute code here');
var currentPageHref = decodeURI(window.location.href);
  myInitCode();
var test = 'Вики-энциклопедия_университета:Главная';
} else {
if (currentPageHref .indexOf(test) > -1) {
   document.addEventListener('DOMContentLoaded', function () {
var forms = document.querySelectorAll('.createbox');
    console.log('document was not ready, place code here');
var select = document.createElement('select');
    myInitCode();
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);
}
}
function myInitCode() {
 
  var node = document.getElementById("content");
// Add event listener to the select element
  var content = document.createElement("ul");
select.addEventListener('change', function(e) {
  content.classList.add("custom-top-menu");
  var value = e.target.value;
  var items = [{
 
    href: "/wiki/Вики-энциклопедия_университета",
   var form;
    title: "Главная",
   for (var i = 0; i < forms.length; i++) {
    text: "Главная",
     form = forms[i];
  }, {
     var preloadInput = form.querySelector('input[name="preload"]');
    href: "/wiki/Вики-энциклопедия_университета:Правила",
 
    title: "Правила",
     if (preloadInput) {
    text: "Правила",
       preloadInput.value = value;
  }, {
    href: "/wiki/Служебная:Все_страницы",
    title: "Все страницы",
    text: "Статьи",
  }, {
    href: "/wiki/Служебная:Свежие_правки",
    title: "Свежие правки",
    text: "История правок",
  }, {
    href: "/wiki/Вики-энциклопедия_университета:Инструкции",
    title: "Инструкции",
    text: "Инструкции",
  }, {
    href: "/wiki/Вики-энциклопедия_университета:Контакты",
    title: "Заголовок 2",
    text: "Контакты",
  }];
  items.forEach(function (item) {
    var li = document.createElement("li");
    var a = document.createElement("a");
    a.href = item.href;
    a.title = item.title;
    a.textContent = item.text;
    li.appendChild(a);
    content.appendChild(li);
   });
   node.parentNode.insertBefore(content, node);
  var currentPageHref = decodeURI(window.location.href);
  var links = document.querySelectorAll('.custom-top-menu a');
  links.forEach(function (link) {
     var linkhref = link.getAttribute('href').trim();
     console.log(currentPageHref + '=' + linkhref);
     if (currentPageHref.indexOf(linkhref) > -1) {
       link.closest('li').classList.add('a-current');
     }
     }
   });
   }
});
var form = document.querySelector('.createbox');
form.insertBefore(select, form.querySelector('input[name="veaction"]'));
}
}

Текущая версия от 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"]'));
}