{"size": 1635, "ext": "js", "max_stars_repo_path": "src/web/pacman.js", "max_stars_repo_name": "PaddeK/verdaccio-pacman", "max_stars_repo_stars_event_min_datetime": "2020-10-15T18:29:55.000Z", "max_stars_repo_stars_event_max_datetime": "2020-10-16T10:20:21.000Z", "max_issues_repo_path": "src/web/pacman.js", "max_issues_repo_name": "PaddeK/verdaccio-pacman", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/web/pacman.js", "max_forks_repo_name": "PaddeK/verdaccio-pacman", "max_forks_repo_forks_event_min_datetime": "2021-12-14T01:58:06.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-14T01:58:06.000Z"}
{"max_stars_count": 2, "max_issues_count": null, "max_forks_count": 1, "avg_line_length": 29.1964285714, "max_line_length": 104, "alphanum_fraction": 0.6134556575}
/* global document, location, XMLHttpRequest, ZingGrid */

import TagType from './TagType.js';
import ListGrid from './ListGrid.js';
import PackageGrid from './PackageGrid.js';

class Pacman
{
    constructor ()
    {
        const
            options = JSON.parse((document.querySelector('#pacman-options') || {}).value || '{}'),
            button = document.createElement('button'),
            toolbarLeftSide = document.querySelector(options.selectorPacmanBtn),
            homeButton = document.querySelector(options.selectorHomeBtn);

        this._options = options;

        button.setAttribute('class', 'pacman open');
        button.addEventListener('click', this._load.bind(this));

        options.injectMode === 'prepend' && toolbarLeftSide.prepend(button);
        options.injectMode === 'append' && toolbarLeftSide.append(button);

        homeButton.addEventListener('click', () => location.assign('/'));
    }

    /**
     * @private
     */
    _load ()
    {
        const xhr = new XMLHttpRequest();

        xhr.addEventListener('load', this._inject.bind(this, xhr));
        xhr.open('GET', '/-/pacman/web/index.html');
        xhr.send();
    }

    /**
     * @param {object} xhr
     * @return {Promise}
     * @private
     */
    async _inject (xhr)
    {
        document.querySelector('div.container.content').innerHTML = xhr.responseText;

        ZingGrid.registerCellType(TagType.TYPE, {renderer: TagType.renderer.bind(null, this._options)});

        new ListGrid(document, '#main', '#child', this._options);
        new PackageGrid(document, '#main', '#child', this._options);
    }
}

new Pacman();