File size: 3,456 Bytes
9201528
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
(function () {
  var root = document.documentElement;
  var themeToggle = document.getElementById('theme-toggle');
  var navToggle = document.getElementById('nav-toggle');
  var navList = document.getElementById('nav-list');
  var year = document.getElementById('year');

  try {
    var saved = localStorage.getItem('theme');
    if (saved) {
      root.setAttribute('data-theme', saved);
      if (saved === 'dark') themeToggle.textContent = 'โ˜€๏ธ';
    } else {
      var prefersDark = window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches;
      root.setAttribute('data-theme', prefersDark ? 'dark' : 'light');
      themeToggle.textContent = prefersDark ? 'โ˜€๏ธ' : '๐ŸŒ™';
    }
  } catch (e) {}

  if (themeToggle) {
    themeToggle.addEventListener('click', function () {
      var current = root.getAttribute('data-theme') === 'dark' ? 'dark' : 'light';
      var next = current === 'dark' ? 'light' : 'dark';
      root.setAttribute('data-theme', next);
      themeToggle.textContent = next === 'dark' ? 'โ˜€๏ธ' : '๐ŸŒ™';
      try { localStorage.setItem('theme', next); } catch (e) {}
    });
  }

  if (navToggle && navList) {
    navToggle.addEventListener('click', function () {
      var isOpen = navList.classList.contains('open');
      navList.classList.toggle('open');
      navToggle.setAttribute('aria-expanded', String(!isOpen));
    });
    navList.querySelectorAll('a').forEach(function (a) {
      a.addEventListener('click', function () { navList.classList.remove('open'); navToggle.setAttribute('aria-expanded', 'false'); });
    });
  }

  if (year) {
    year.textContent = String(new Date().getFullYear());
  }

  // Smooth scroll for in-page anchors
  document.querySelectorAll('a[href^="#"]').forEach(function (a) {
    a.addEventListener('click', function (e) {
      var id = a.getAttribute('href');
      if (id.length > 1) {
        var el = document.querySelector(id);
        if (el) {
          e.preventDefault();
          el.scrollIntoView({ behavior: 'smooth' });
        }
      }
    });
  });

  // Reveal-on-scroll
  var observer = new IntersectionObserver(function (entries) {
    entries.forEach(function (entry) {
      if (entry.isIntersecting) {
        entry.target.classList.add('visible');
        observer.unobserve(entry.target);
      }
    });
  }, { threshold: 0.1 });
  document.querySelectorAll('[data-reveal]').forEach(function (el) { observer.observe(el); });

  // Skills horizontal scroll with arrows
  var skillsContainer = document.getElementById('skills-container');
  var left = document.getElementById('skills-left');
  var right = document.getElementById('skills-right');
  function scrollByAmount(amount) {
    if (!skillsContainer) return;
    skillsContainer.scrollBy({ left: amount, behavior: 'smooth' });
  }
  if (left) left.addEventListener('click', function () { scrollByAmount(-300); });
  if (right) right.addEventListener('click', function () { scrollByAmount(300); });

  // Back to top button
  var backToTop = document.getElementById('back-to-top');
  if (backToTop) {
    window.addEventListener('scroll', function () {
      if (window.scrollY > 600) backToTop.classList.add('show'); else backToTop.classList.remove('show');
    });
    backToTop.addEventListener('click', function () { window.scrollTo({ top: 0, behavior: 'smooth' }); });
  }
})();