<commit_before>class ContextMenu {
    constructor (player) {
        this.player = player;

        [...this.player.template.menuItem].map((item, index) => {
            if (this.player.options.contextmenu[index].click) {
                item.addEventListener('click', () => {
                    this.player.options.contextmenu[index].click(this.player);
                    this.hide();
                });
            }
            return item;
        });

        this.player.container.addEventListener('contextmenu', (e) => {
            const event = e || window.event;
            event.preventDefault();

            const clientRect = this.player.container.getBoundingClientRect();
            this.show(event.clientX - clientRect.left, event.clientY - clientRect.top);

            this.player.template.mask.addEventListener('click', () => {
                this.hide();
            });
        });
    }

    show (x, y) {
        this.player.template.menu.classList.add('dplayer-menu-show');

        const clientRect = this.player.container.getBoundingClientRect();
        if (x + this.player.template.menu.offsetWidth >= clientRect.width) {
            this.player.template.menu.style.right = clientRect.width - x + 'px';
            this.player.template.menu.style.left = 'initial';
        }
        else {
            this.player.template.menu.style.left = x + 'px';
            this.player.template.menu.style.right = 'initial';
        }
        if (y + this.player.template.menu.offsetHeight >= clientRect.height) {
            this.player.template.menu.style.bottom = clientRect.height - y + 'px';
            this.player.template.menu.style.top = 'initial';
        }
        else {
            this.player.template.menu.style.top = y + 'px';
            this.player.template.menu.style.bottom = 'initial';
        }

        this.player.template.mask.classList.add('dplayer-mask-show');

        this.player.events.trigger('contextmenu_show');
    }

    hide () {
        this.player.template.mask.classList.remove('dplayer-mask-show');
        this.player.template.menu.classList.remove('dplayer-menu-show');

        this.player.events.trigger('contextmenu_hide');
    }
}

export default ContextMenu;<commit_msg>Fix es5 compatibility<commit_after>class ContextMenu {
    constructor (player) {
        this.player = player;

        Array.prototype.slice.call(this.player.template.menuItem).forEach((item, index) => {
            if (this.player.options.contextmenu[index].click) {
                item.addEventListener('click', () => {
                    this.player.options.contextmenu[index].click(this.player);
                    this.hide();
                });
            }
        });

        this.player.container.addEventListener('contextmenu', (e) => {
            const event = e || window.event;
            event.preventDefault();

            const clientRect = this.player.container.getBoundingClientRect();
            this.show(event.clientX - clientRect.left, event.clientY - clientRect.top);

            this.player.template.mask.addEventListener('click', () => {
                this.hide();
            });
        });
    }

    show (x, y) {
        this.player.template.menu.classList.add('dplayer-menu-show');

        const clientRect = this.player.container.getBoundingClientRect();
        if (x + this.player.template.menu.offsetWidth >= clientRect.width) {
            this.player.template.menu.style.right = clientRect.width - x + 'px';
            this.player.template.menu.style.left = 'initial';
        }
        else {
            this.player.template.menu.style.left = x + 'px';
            this.player.template.menu.style.right = 'initial';
        }
        if (y + this.player.template.menu.offsetHeight >= clientRect.height) {
            this.player.template.menu.style.bottom = clientRect.height - y + 'px';
            this.player.template.menu.style.top = 'initial';
        }
        else {
            this.player.template.menu.style.top = y + 'px';
            this.player.template.menu.style.bottom = 'initial';
        }

        this.player.template.mask.classList.add('dplayer-mask-show');

        this.player.events.trigger('contextmenu_show');
    }

    hide () {
        this.player.template.mask.classList.remove('dplayer-mask-show');
        this.player.template.menu.classList.remove('dplayer-menu-show');

        this.player.events.trigger('contextmenu_hide');
    }
}

export default ContextMenu;

{'fraction_non_alphanumeric': 0.1421579532814238, 'fraction_numerical': 0.0002224694104560623, 'mean_word_length': 2.0053475935828877, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2843799', 'n_tokens_mistral': 1251, 'n_tokens_neox': 1230, 'n_words': 157}