<commit_before>import {
    Component,
    Input,
    ElementRef
} from '@angular/core';

import { ContextMenuItem } from './context-menu-item.model';
import { ContextMenuService } from './context-menu.service';

@Component({
    selector: 'tb-context-menu',
    templateUrl: 'app/shared/context-menu/context-menu.component.html'
})
export class ContextMenu {
    @Input('menu-items') menuItems: Array<ContextMenuItem>;

    isOpen = false;
    animate = true;

    constructor(private el: ElementRef,
                private menuService: ContextMenuService) {
        menuService.registerMenu(this);

        let parentElement = el.nativeElement.parentElement;

        parentElement.oncontextmenu = (event: MouseEvent) => {
            event.preventDefault();
            event.stopPropagation();

            this.onParentContextMenu(event);
        };
    }

    callAction(action: Function) {
        if (action) {
            action();
        }
    }

    private onParentContextMenu(event: MouseEvent) {
        this.menuService.closeAllMenus();
        this.isOpen = true;

        let edgeBuffer = 10;
        let target = this.el.nativeElement.firstElementChild;

        // Set to the event position by default
        target.style.left = event.pageX + 'px';
        target.style.top = event.pageY + 'px';

        // Adjust position if near an edge
        setTimeout(() => {
            let rect = target.getBoundingClientRect();

            let offsetX = (event.pageX + rect.width + edgeBuffer) > window.innerWidth;
            let offsetY = (event.pageY + rect.height + edgeBuffer) > window.innerHeight;

            target.style.left = event.pageX - (offsetX ? rect.width : 0) + 'px';
            target.style.top = event.pageY - (offsetY ? rect.height : 0) + 'px';
        }, 0);
    }
}<commit_msg>Codacy cleanup<commit_after>import {
    Component,
    Input,
    ElementRef
} from '@angular/core';

import { ContextMenuItem } from './context-menu-item.model';
import { ContextMenuService } from './context-menu.service';

@Component({
    selector: 'tb-context-menu',
    templateUrl: 'app/shared/context-menu/context-menu.component.html'
})
export class ContextMenu {
    @Input('menu-items') menuItems: Array<ContextMenuItem>;

    isOpen = false;
    animate = true;

    constructor(private el: ElementRef,
                private menuService: ContextMenuService) {
        menuService.registerMenu(this);

        let parentElement = el.nativeElement.parentElement;

        parentElement.oncontextmenu = (event: MouseEvent) => {
            event.preventDefault();
            event.stopPropagation();

            this.onParentContextMenu(event);
        };
    }

    callAction(action: Function) {
        if (action) {
            action();
        }
    }

    private onParentContextMenu(event: MouseEvent) {
        this.menuService.closeAllMenus();
        this.isOpen = true;

        let edgeBuffer = 10;
        let target = this.el.nativeElement.firstElementChild;

        // Set to the event position by default
        target.style.left = event.pageX + 'px';
        target.style.top = event.pageY + 'px';

        // Adjust position if near an edge
        setTimeout(() => {
            let rect = target.getBoundingClientRect();

            let offsetX = (event.pageX + rect.width + edgeBuffer) > window.innerWidth;
            let offsetY = (event.pageY + rect.height + edgeBuffer) > window.innerHeight;

            target.style.left = event.pageX - (offsetX ? rect.width : 0) + 'px';
            target.style.top = event.pageY - (offsetY ? rect.height : 0) + 'px';
        },
        0);
    }
}
{'fraction_non_alphanumeric': 0.12071330589849108, 'fraction_numerical': 0.0027434842249657062, 'mean_word_length': 2.308529945553539, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 13, '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': '7585276', 'n_tokens_mistral': 1047, 'n_tokens_neox': 1012, 'n_words': 221}