{"size": 2156, "ext": "js", "max_stars_repo_path": "themes/theme-media/gallery.js", "max_stars_repo_name": "leafcutter-cms/addon-media", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "themes/theme-media/gallery.js", "max_issues_repo_name": "leafcutter-cms/addon-media", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "themes/theme-media/gallery.js", "max_forks_repo_name": "leafcutter-cms/addon-media", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 37.8245614035, "max_line_length": 78, "alphanum_fraction": 0.5607606679}
window.addEventListener('DOMContentLoaded', (event) => {
    var wireMedia = function (data, thumbs, content) {
        var thumb = document.createElement('img');
        thumb.src = data.thumb;
        thumb.alt = data.alt;
        thumb.classList.add('thumbnail');
        thumbs.append(thumb);
        thumb.onclick = function (e) {
            var ts = thumbs.getElementsByClassName('thumbnail');
            for (let i = 0; i < ts.length; i++) {
                ts[i].classList.remove('active');
            }
            thumb.classList.add('active');
            content.innerHTML = data.html;
        }
    }
    var populateGallery = function (gallery, data) {
        var thumbs = document.createElement('div');
        thumbs.classList.add('gallery-thumbs');
        gallery.append(thumbs);
        var content = gallery.getElementsByClassName('gallery-content')[0];
        content.innerHTML = '';
        // loop through data
        for (let i = 0; i < data.length; i++) {
            wireMedia(data[i], thumbs, content);
        }
        // click first thumb
        thumbs.getElementsByClassName('thumbnail')[0].classList.add('active');
        content.innerHTML = data[0].html
    }
    var buildGallery = function (gallery) {
        gallery.classList.add('active');
        gallery.classList.add('loading');
        // load data
        var request = new XMLHttpRequest();
        request.open('GET', gallery.getAttribute('data-gallery-json'));
        request.onload = function () {
            if (this.status >= 200 && this.status < 400) {
                populateGallery(gallery, JSON.parse(this.response));
            } else {
                gallery.classList.add('error');
                gallery.classList.remove('loading');
            }
        };
        request.onerror = function () {
            gallery.classList.add('error');
            gallery.classList.remove('loading');
        }
        request.send();
    };

    var galleries = document.getElementsByClassName('media-gallery');
    for (let i = 0; i < galleries.length; i++) {
        buildGallery(galleries[i]);
        const gallery = galleries[i];
    }
});