InfoboxCharacter.js

```
(function() {
    /\*značky\*/
    function CutieMark(elem) { //konstruktor
        this.cutieMark = elem;
    }
    CutieMark.prototype.hide = function() { //schování
        this.cutieMark.style.display = 'none';
    };
    CutieMark.prototype.show = function() { //zobrazování
        this.cutieMark.style.display = 'inline-block';
    };
    /\*skupina značek\*/
    function CutieGroup(infobox) {
        //určování značek
        var cutieMarksEl = infobox.getElementsByClassName('ib1\_cm');
        this.cutieMarks = [];
        for (var i = 0; i < cutieMarksEl.length; i++) {
            this.cutieMarks[i] = new CutieMark(cutieMarksEl[i]);
        }
        //určování tlačítek
        var buttonsEl = infobox.getElementsByClassName('ib1\_cmButton');
        if (buttonsEl.length > 0) {
            this.nextButton = buttonsEl[1];
            this.nextButton.addEventListener("click", this.next.bind(this));
            this.prevButton = buttonsEl[0];
            this.prevButton.addEventListener("click", this.prev.bind(this));
        }
        this.MAX\_MARK = this.cutieMarks.length - 1;
        this.curentMark = 0;
    }
    CutieGroup.prototype.next = function() {
        this.cutieMarks[this.curentMark].hide();
        if (this.curentMark < this.MAX\_MARK) {
            this.curentMark++;
        } else {
            this.curentMark = 0;
        }
        this.cutieMarks[this.curentMark].show();
    };
    CutieGroup.prototype.prev = function() {
        this.cutieMarks[this.curentMark].hide();
        if (this.curentMark !== 0) {
            this.curentMark--;
        } else {
            this.curentMark = this.MAX\_MARK;
        }
        this.cutieMarks[this.curentMark].show();
    };
    /\*infobox\*/
    function Infobox(elem) { //konstruktor
        this.infobox = elem;
        this.name = this.infobox.dataset.name;
        this.bgColor = this.infobox.dataset.bgcolor;
        this.fontColor = this.infobox.dataset.fontcolor;
        this.cm = new CutieGroup(this.infobox);
    }
    Infobox.prototype.hide = function() { //schování
        this.infobox.style.display = 'none';
    };
    Infobox.prototype.show = function() { //zobrazování
        this.infobox.style.display = 'block';
    };
    /\*Blok infoboxů\*/
    function InfoboxBlock(elem) {//konstruktor
        this.infoboxBlock = elem;
        //určování infoboxů
        this.infoboxes = [];
        var infoboxesEl = this.infoboxBlock.getElementsByClassName('ib1\_infoboxCharacter');
        for (var i = 0; infoboxesEl[i]; i++) {
            this.infoboxes[i] = new Infobox(infoboxesEl[i]);
        }
        //určování parametrů slidera
        this.IB\_NUM = this.infoboxes.length;
        this.activeInfobox = 0;
        this.nextInfobox = 1;
        this.prevInfobox = this.IB\_NUM;
        //určování řídicích tlačítek
        var controlButtonsEl = this.infoboxBlock.getElementsByClassName('ib1\_cb\_block');
        this.nextButton, this.prevButton, this.switchButton;
        if (this.IB\_NUM > 2) {
            this.prevButton = controlButtonsEl[0].firstChild;
            this.prevButton.addEventListener("click", this.prev.bind(this));
            this.nextButton = controlButtonsEl[0].lastChild;
            this.nextButton.addEventListener("click", this.next.bind(this));
        } else if (this.IB\_NUM > 1) {
            this.switchButton = controlButtonsEl[0].firstChild;
            this.switchButton.addEventListener("click", this.ibSwitch.bind(this));
        }
    }
    InfoboxBlock.prototype.next = function() { //napřed
            this.infoboxes[this.activeInfobox].hide();
            this.infoboxes[this.nextInfobox].show();
            this.prevInfobox = this.activeInfobox;
            this.activeInfobox = this.nextInfobox;
            if (this.nextInfobox == this.IB\_NUM - 1) {
                this.nextInfobox = 0;
            } else {
                this.nextInfobox++;
            }
            this.updateButton(this.nextButton, this.nextInfobox);
            this.updateButton(this.prevButton, this.prevInfobox);
        };
        InfoboxBlock.prototype.prev = function() { //nazpět
            this.infoboxes[this.activeInfobox].hide();
            this.infoboxes[this.prevInfobox].show();
            this.nextInfobox = this.activeInfobox;
            this.activeInfobox = this.prevInfobox;
            if (this.prevInfobox == 0) {
                this.prevInfobox = this.IB\_NUM - 1;
            } else {
                this.prevInfobox--;
            }
            this.updateButton(this.nextButton, this.nextInfobox);
            this.updateButton(this.prevButton, this.prevInfobox);
        };
        InfoboxBlock.prototype.ibSwitch = function() { //varianta pro 2 ib
            this.infoboxes[this.activeInfobox].hide();
            this.updateButton(this.switchButton, this.activeInfobox);
            this.activeInfobox = Math.abs(this.activeInfobox - 1);
            this.infoboxes[this.activeInfobox].show();
        };
        InfoboxBlock.prototype.updateButton = function(elem, number) { //obnovování tlačítek
            elem.innerHTML = this.infoboxes[number].name;
            elem.style.backgroundColor = this.infoboxes[number].bgColor;
            elem.style.color = this.infoboxes[number].fontColor;
        };
    /\*Stránka\*/
    // určování bloků infoboxů
    var ibBlocks = [];
    var ibBlocksEl = document.getElementsByClassName('ib1\_ibBlock');
    for (var i = 0; ibBlocksEl[i]; i++) {
        ibBlocks[i] = new InfoboxBlock(ibBlocksEl[i]);
    }
})();

```