summaryrefslogtreecommitdiff
path: root/index.js
blob: fbe9ba99a1bf5ce5e12810d655e5a8747de86fcb (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
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

function main() {
    runCarousel();
    runPosts();

    // -- Note! We require a black background to properly see the WebGL, so we handle that here.
    var bodyElement = document.querySelector('body');
    var themeButtonList = document.querySelectorAll('#theme_selector > button');
    themeButtonList.forEach(function(themeButton) {
        if (themeButton.id !== 'theme_button_default') {
            themeButton.addEventListener('click', function() {
                bodyElement.style.background = 'black';  
            });
        }
        else {
            themeButton.addEventListener('click', function() {
                bodyElement.style.background = 'white';  
            });
        }
    })
}

function runCarousel() {
    var carouselContainer = document.getElementById("carousel"),
        imageContainer = document.getElementById('image_container'),
        leftButton = document.getElementById('carousel_left'),
        rightButton = document.getElementById('carousel_right');

    // Carousel logic
    var carouselPosition = 0,
        numImages = imageContainer.children.length;
    
    function onCarouselRight() {
        carouselPosition = (carouselPosition + 1);

        if (carouselPosition === numImages) {
            carouselPosition = 0;
        }
        updateCarousel();
    }
    
    function onCarouselLeft() {
        carouselPosition = (carouselPosition - 1);
        if (carouselPosition < 0) {
            carouselPosition = numImages - 1;
        }
        updateCarousel();
    }

    function onImageClicked() {
        
    }

    function updateCarousel() {
        var children = imageContainer.children,
            numChildren = imageContainer.children.length,
            selectedChildPosition = -(carouselPosition * 240);
        imageContainer.style.transform = 'translate(' + selectedChildPosition + 'px, 0)';
        for (var i = 0; i < children.length; i++) {
            var image = children[i];
            if (i !== carouselPosition) {
                if (i === (carouselPosition - 1) % numImages) {
                    image.style.opacity = 0.3;
                } else if (i !== 0 && i === (carouselPosition + 1) % numImages) {
                    image.style.opacity = 0.3;
                } else {
                    image.style.opacity = 0;
                }
            } else {
                image.style.opacity = 1;
            }
        }

        rightButton.style.visibility = (carouselPosition === numImages - 1) ? 'hidden' : 'visible';
        leftButton.style.visibility = (carouselPosition === 0) ? 'hidden' : 'visible';
    }

    updateCarousel();

    leftButton.addEventListener('click', onCarouselLeft);
    rightButton.addEventListener('click', onCarouselRight);
}

function runPosts() {
    
}

main();