Files
keyAjansPortfolyo/static/js/app.js
T

95 lines
2.7 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/* Tema anahtarı + slider'lar + flash otomatik kapanma */
(function () {
"use strict";
// ---- Dark / light tema ----
var root = document.documentElement;
var stored = null;
try { stored = localStorage.getItem("key-theme"); } catch (e) {}
if (stored === "dark" || stored === "light") {
root.setAttribute("data-theme", stored);
} else {
root.setAttribute("data-theme", "light");
}
var toggle = document.getElementById("themeToggle");
if (toggle) {
toggle.addEventListener("click", function () {
var next = root.getAttribute("data-theme") === "dark" ? "light" : "dark";
root.setAttribute("data-theme", next);
try { localStorage.setItem("key-theme", next); } catch (e) {}
});
}
// ---- Slider'lar ----
document.querySelectorAll(".slider").forEach(function (slider) {
var images = Array.prototype.slice.call(slider.querySelectorAll(".slides img"));
if (images.length === 0) return;
var current = 0;
var interval = parseInt(slider.getAttribute("data-interval") || "4000", 10);
var timer = null;
var dotsBox = slider.querySelector(".dots");
images.forEach(function (_, i) {
var d = document.createElement("span");
d.setAttribute("role", "button");
d.setAttribute("aria-label", "Görsel " + (i + 1));
d.addEventListener("click", function (ev) {
ev.stopPropagation();
go(i);
restart();
});
dotsBox.appendChild(d);
});
var dots = Array.prototype.slice.call(dotsBox.children);
function show() {
images.forEach(function (img, i) {
img.classList.toggle("active", i === current);
});
dots.forEach(function (d, i) {
d.classList.toggle("active", i === current);
});
}
function go(i) {
current = (i + images.length) % images.length;
show();
}
function next() { go(current + 1); }
function prev() { go(current - 1); }
function restart() {
if (timer) clearInterval(timer);
timer = setInterval(next, interval);
}
slider.querySelector(".next").addEventListener("click", function (ev) {
ev.stopPropagation();
next();
restart();
});
slider.querySelector(".prev").addEventListener("click", function (ev) {
ev.stopPropagation();
prev();
restart();
});
slider.addEventListener("mouseenter", function () {
if (timer) clearInterval(timer);
});
slider.addEventListener("mouseleave", restart);
show();
restart();
});
// ---- Flash mesajları ----
setTimeout(function () {
document.querySelectorAll(".flash").forEach(function (el) {
el.style.transition = "opacity .8s ease";
el.style.opacity = "0";
setTimeout(function () { el.remove(); }, 800);
});
}, 5000);
})();