summaryrefslogtreecommitdiffstats
path: root/themes/danix-xyz-hacker/assets/js/not-found-page.js
blob: cec60bd469b1f851276fe9536995c58dfdbfbbef (plain)
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
document.addEventListener('alpine:init', () => {
  Alpine.data('notFoundPage', () => ({
    showEasterEgg: false,
    searchQuery: '',
    filteredArticles: [],
    allArticles: window.articlesData || [],

    filterArticles(query) {
      this.searchQuery = query.toLowerCase();
      if (!this.searchQuery) {
        this.filteredArticles = [];
        return;
      }
      this.filteredArticles = this.allArticles.filter(article =>
        article.title.toLowerCase().includes(this.searchQuery) ||
        article.content.toLowerCase().includes(this.searchQuery)
      ).slice(0, 5);
    },

    toggleEasterEgg() {
      console.log('toggleEasterEgg called, current state:', this.showEasterEgg);
      this.showEasterEgg = !this.showEasterEgg;
      console.log('new state:', this.showEasterEgg);
    },

    goToRandomArticle() {
      if (this.allArticles.length > 0) {
        const randomArticle = this.allArticles[Math.floor(Math.random() * this.allArticles.length)];
        window.location.href = randomArticle.url;
      }
    }
  }));

  Alpine.data('notFoundNav', () => {
    const isItalian = window.location.pathname.startsWith('/it/');
    return {
      get homeLink() {
        return isItalian ? '/it/' : '/';
      },
      get articlesLink() {
        return isItalian ? '/it/articles/' : '/articles/';
      },
      get contactLink() {
        return isItalian ? '/it/is/here/' : '/is/here/';
      },
      goHome() {
        window.location.href = this.homeLink;
      },
      goArticles() {
        window.location.href = this.articlesLink;
      },
      goContact() {
        window.location.href = this.contactLink;
      }
    };
  });

  console.log('notFoundPage Alpine component registered');
});