MediaWiki:Vector.js: различия между версиями
Aylong (обсуждение | вклад) Нет описания правки Метка: ручная отмена |
Aylong (обсуждение | вклад) Нет описания правки Метка: отменено |
||
| Строка 1: | Строка 1: | ||
function loadPage(url) { | function loadPage(url) { | ||
var xhr = new XMLHttpRequest(); | var xhr = new XMLHttpRequest(); | ||
| Строка 5: | Строка 4: | ||
if (xhr.readyState === XMLHttpRequest.DONE) { | if (xhr.readyState === XMLHttpRequest.DONE) { | ||
if (xhr.status === 200) { | if (xhr.status === 200) { | ||
document. | document.documentElement.innerHTML = xhr.responseText; | ||
window.history.pushState({}, '', url); | window.history.pushState({}, '', url); | ||
} | } | ||
} | } | ||
| Строка 25: | Строка 21: | ||
}); | }); | ||
window.addEventListener('popstate', function(event) { | window.addEventListener('popstate', function(event) { | ||
loadPage(window.location.href); | loadPage(window.location.href); | ||
}); | }); | ||
function toggleTheme() { | |||
function | var isLightTheme = document.documentElement.classList.toggle('light'); | ||
localStorage.setItem("isLightTheme", isLightTheme); | |||
} | } | ||
$(document).ready(function() { | |||
function | |||
var container = document.getElementById("p-personal"); | var container = document.getElementById("p-personal"); | ||
if (container) { | if (container) { | ||
| Строка 43: | Строка 36: | ||
checkbox.type = "checkbox"; | checkbox.type = "checkbox"; | ||
checkbox.id = "theme-toggle"; | checkbox.id = "theme-toggle"; | ||
var label = document.createElement("label"); | var label = document.createElement("label"); | ||
label.htmlFor = "theme-toggle"; | label.htmlFor = "theme-toggle"; | ||
label.id = "theme-button"; | label.id = "theme-button"; | ||
container.parentNode.insertBefore(checkbox, container); | container.parentNode.insertBefore(checkbox, container); | ||
container.parentNode.insertBefore(label, container); | container.parentNode.insertBefore(label, container); | ||
| Строка 62: | Строка 55: | ||
toggleTheme(); | toggleTheme(); | ||
}); | }); | ||
} | }); | ||
Версия от 21:28, 4 мая 2024
function loadPage(url) {
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function() {
if (xhr.readyState === XMLHttpRequest.DONE) {
if (xhr.status === 200) {
document.documentElement.innerHTML = xhr.responseText;
window.history.pushState({}, '', url);
}
}
};
xhr.open('GET', url, true);
xhr.send();
}
document.addEventListener('click', function(event) {
var link = event.target.closest('a');
if (link && link.href && link.href.indexOf(window.location.origin) !== -1) {
event.preventDefault();
loadPage(link.href);
}
});
window.addEventListener('popstate', function(event) {
loadPage(window.location.href);
});
function toggleTheme() {
var isLightTheme = document.documentElement.classList.toggle('light');
localStorage.setItem("isLightTheme", isLightTheme);
}
$(document).ready(function() {
var container = document.getElementById("p-personal");
if (container) {
var checkbox = document.createElement("input");
checkbox.type = "checkbox";
checkbox.id = "theme-toggle";
var label = document.createElement("label");
label.htmlFor = "theme-toggle";
label.id = "theme-button";
container.parentNode.insertBefore(checkbox, container);
container.parentNode.insertBefore(label, container);
}
var isLightTheme = localStorage.getItem("isLightTheme");
if (isLightTheme === "true") {
document.documentElement.classList.add('light');
} else {
document.documentElement.classList.remove('light');
}
$("#theme-toggle").change(function() {
toggleTheme();
});
});