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

Материал из ЮУГМУ Вики
Нет описания правки
Нет описания правки
Строка 1: Строка 1:
document.addEventListener("DOMContentLoaded", function() {
if (document.readyState !== 'loading') {
  const node = document.getElementById("content");
    console.log('document is already ready, just execute code here');
  const content = document.createElement("ul");
    myInitCode();
  content.classList.add("custom-top-menu");
} else {
    document.addEventListener('DOMContentLoaded', function () {
        console.log('document was not ready, place code here');
        myInitCode();
    });
}


   const items = [
function myInitCode() {
    {
    const node = document.getElementById("content");
      href: "/wiki/Вики-энциклопедия_университета",
    const content = document.createElement("ul");
      title: "Главная",
    content.classList.add("custom-top-menu");
      text: "Главная",
    
      spanText: "Главная"
    const items = [
    },
      {
    {
        href: "/wiki/Вики-энциклопедия_университета",
      href: "/wiki/Правила",
        title: "Главная",
      title: "Правила",
        text: "Главная",
      text: "Правила",
        spanText: "Главная"
      spanText: "Правила"
      },
    },
      {
    {
        href: "/wiki/Правила",
      href: "/wiki/Служебная:Все_страницы",
        title: "Правила",
      title: "Все страницы",
        text: "Правила",
      text: "Статьи",
        spanText: "Правила"
      spanText: "Статьи"
      },
    },
      {
    {
        href: "/wiki/Служебная:Все_страницы",
      href: "/wiki/Служебная:Свежие_правки",
        title: "Все страницы",
      title: "Свежие правки",
        text: "Статьи",
      text: "История правок",
        spanText: "Статьи"
      spanText: "История правок"
      },
    },
      {
    {
        href: "/wiki/Служебная:Свежие_правки",
      href: "/wiki/Инструкции",
        title: "Свежие правки",
      title: "Инструкции",
        text: "История правок",
      text: "Инструкции",
        spanText: "История правок"
      spanText: "Инструкции"
      },
    },
      {
    {
        href: "/wiki/Инструкции",
      href: "/wiki/Контакты",
        title: "Инструкции",
      title: "Заголовок 2",
        text: "Инструкции",
      text: "Контакты",
        spanText: "Инструкции"
      spanText: "Контакты"
      },
    }
      {
  ];
        href: "/wiki/Контакты",
 
        title: "Заголовок 2",
  items.forEach((item) => {
        text: "Контакты",
    const li = document.createElement("li");
        spanText: "Контакты"
    const a = document.createElement("a");
      }
    a.href = item.href;
    ];
    a.title = item.title;
 
    a.textContent = item.text;
    items.forEach((item) => {
    const span = document.createElement("span");
      const li = document.createElement("li");
    span.textContent = item.spanText;
      const a = document.createElement("a");
    a.appendChild(span);
      a.href = item.href;
    li.appendChild(a);
      a.title = item.title;
     content.appendChild(li);
      a.textContent = item.text;
      const span = document.createElement("span");
      span.textContent = item.spanText;
      a.appendChild(span);
      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');
      }
   });
   });
 
}
  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');
    }
});
});

Версия от 14:25, 14 мая 2024

if (document.readyState !== 'loading') {
    console.log('document is already ready, just execute code here');
    myInitCode();
} else {
    document.addEventListener('DOMContentLoaded', function () {
        console.log('document was not ready, place code here');
        myInitCode();
    });
}

function myInitCode() {
    const node = document.getElementById("content");
    const content = document.createElement("ul");
    content.classList.add("custom-top-menu");
  
    const items = [
      {
        href: "/wiki/Вики-энциклопедия_университета",
        title: "Главная",
        text: "Главная",
        spanText: "Главная"
      },
      {
        href: "/wiki/Правила",
        title: "Правила",
        text: "Правила",
        spanText: "Правила"
      },
      {
        href: "/wiki/Служебная:Все_страницы",
        title: "Все страницы",
        text: "Статьи",
        spanText: "Статьи"
      },
      {
        href: "/wiki/Служебная:Свежие_правки",
        title: "Свежие правки",
        text: "История правок",
        spanText: "История правок"
      },
      {
        href: "/wiki/Инструкции",
        title: "Инструкции",
        text: "Инструкции",
        spanText: "Инструкции"
      },
      {
        href: "/wiki/Контакты",
        title: "Заголовок 2",
        text: "Контакты",
        spanText: "Контакты"
      }
    ];
  
    items.forEach((item) => {
      const li = document.createElement("li");
      const a = document.createElement("a");
      a.href = item.href;
      a.title = item.title;
      a.textContent = item.text;
      const span = document.createElement("span");
      span.textContent = item.spanText;
      a.appendChild(span);
      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');
      }
  });
}