Przejdź do zawartości

MediaWiki:Common.js: Różnice pomiędzy wersjami

Z Horyzont Zdarzeń
Anulowanie wersji 1983 autorstwa Lockey (dyskusja)
Znacznik: Anulowanie edycji
Anulowanie wersji 1971 autorstwa Lockey (dyskusja)
Znacznik: Anulowanie edycji
 
(Nie pokazano 2 pośrednich wersji utworzonych przez tego samego użytkownika)
Linia 1: Linia 1:
// === Przycisk "Wróć na górę" z SVG ===
// === Nowy przycisk "Wróć na górę" z SVG ===
$(document).ready(function () {
const scrollButton = document.createElement("button");
    const scrollButton = document.createElement("button");
scrollButton.id = "scrollTopBtn";
    scrollButton.id = "scrollTopBtn";
scrollButton.title = "Wróć na górę";
    scrollButton.title = "Wróć na górę";
scrollButton.innerHTML = `
    scrollButton.innerHTML = `
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" fill="none" stroke="#1a1a1a" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-arrow-up">
    <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" fill="none" stroke="#1a1a1a" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-arrow-up">
    <line x1="12" y1="19" x2="12" y2="5"></line>
        <line x1="12" y1="19" x2="12" y2="5"></line>
    <polyline points="5 12 12 5 19 12"></polyline>
        <polyline points="5 12 12 5 19 12"></polyline>
</svg>
    </svg>
`;
    `;
document.body.appendChild(scrollButton);
    document.body.appendChild(scrollButton);


    // Scroll to top
// Pokaż/ukryj w zależności od scrolla
     scrollButton.addEventListener("click", () => {
window.onscroll = function() {
         window.scrollTo({ top: 0, behavior: 'smooth' });
     const btn = document.getElementById("scrollTopBtn");
    });
    if (document.body.scrollTop > 300 || document.documentElement.scrollTop > 300) {
        btn.style.display = "flex";
        btn.style.alignItems = "center";
        btn.style.justifyContent = "center";
    } else {
         btn.style.display = "none";
    }
};
 
// Akcja kliknięcia
scrollButton.onclick = function() {
    window.scrollTo({ top: 0, behavior: 'smooth' });
};


    // Scroll behavior
$(document).ready(function() {
    window.addEventListener("scroll", () => {
    var scrollBtn = document.getElementById("scrollTopBtn");
        const btn = document.getElementById("scrollTopBtn");
        const footer = document.querySelector(".mw-footer");
        const footerHeight = footer ? footer.offsetHeight : 0;
        const windowHeight = window.innerHeight;
        const bodyHeight = document.body.scrollHeight;
        const scrollY = window.pageYOffset || document.documentElement.scrollTop;


        // Pokaż/ukryj przycisk
    window.addEventListener("scroll", function() {
         btn.style.display = scrollY > 300 ? "flex" : "none";
         var footerHeight = document.querySelector(".mw-footer") ? document.querySelector(".mw-footer").offsetHeight : 0;
        var windowHeight = window.innerHeight;
        var bodyHeight = document.body.scrollHeight;
        var scrollY = window.scrollY;


         // Wylicz przesunięcie, ale nie pozwól zejść niżej niż 40px
         // Czy jesteśmy blisko stopki?
         const overlap = scrollY + windowHeight - (bodyHeight - footerHeight);
         if (scrollY + windowHeight > bodyHeight - footerHeight) {
        btn.style.bottom = overlap > 0 ? `${Math.max(40, overlap + 20)}px` : "40px";
            scrollBtn.style.bottom = (footerHeight + 20) + "px"; // przesuń w górę
     }, { passive: true });
        } else {
            scrollBtn.style.bottom = "100px"; // normalnie
        }
     });
 
    // Pokaż przycisk po scrollu
    window.addEventListener("scroll", function() {
        if (document.documentElement.scrollTop > 200) {
            scrollBtn.style.display = "block";
        } else {
            scrollBtn.style.display = "none";
        }
    });
});
});

Aktualna wersja na dzień 21:36, 4 maj 2025

// === Nowy przycisk "Wróć na górę" z SVG ===
const scrollButton = document.createElement("button");
scrollButton.id = "scrollTopBtn";
scrollButton.title = "Wróć na górę";
scrollButton.innerHTML = `
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" fill="none" stroke="#1a1a1a" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-arrow-up">
    <line x1="12" y1="19" x2="12" y2="5"></line>
    <polyline points="5 12 12 5 19 12"></polyline>
</svg>
`;
document.body.appendChild(scrollButton);

// Pokaż/ukryj w zależności od scrolla
window.onscroll = function() {
    const btn = document.getElementById("scrollTopBtn");
    if (document.body.scrollTop > 300 || document.documentElement.scrollTop > 300) {
        btn.style.display = "flex";
        btn.style.alignItems = "center";
        btn.style.justifyContent = "center";
    } else {
        btn.style.display = "none";
    }
};

// Akcja kliknięcia
scrollButton.onclick = function() {
    window.scrollTo({ top: 0, behavior: 'smooth' });
};

$(document).ready(function() {
    var scrollBtn = document.getElementById("scrollTopBtn");

    window.addEventListener("scroll", function() {
        var footerHeight = document.querySelector(".mw-footer") ? document.querySelector(".mw-footer").offsetHeight : 0;
        var windowHeight = window.innerHeight;
        var bodyHeight = document.body.scrollHeight;
        var scrollY = window.scrollY;

        // Czy jesteśmy blisko stopki?
        if (scrollY + windowHeight > bodyHeight - footerHeight) {
            scrollBtn.style.bottom = (footerHeight + 20) + "px"; // przesuń w górę
        } else {
            scrollBtn.style.bottom = "100px"; // normalnie
        }
    });

    // Pokaż przycisk po scrollu
    window.addEventListener("scroll", function() {
        if (document.documentElement.scrollTop > 200) {
            scrollBtn.style.display = "block";
        } else {
            scrollBtn.style.display = "none";
        }
    });
});