<commit_before>import {freeze, unfreeze} from '../../static/js/disable-scroll';

export default function popup() {
    const POPUP_CLASS = '.popup';
    const WRAPPER_CLASS = '.popup__wrapper';
    const CLOSE_BTN_CLASS = '.popup__close';
    const ACTIVE_POPUP_CLASS = 'active';
    const TOGGLE_BTN_CLASS = '.js-toggle-popup';
    const PRELOAD_POPUP = 'js-popup-preload';
    const DATA_ACTION_ATTR = 'action';
    const DATA_ACTION_SHOW = 'show';
    const DATA_ACTION_HIDE = 'hide';
    const DATA_TEMPLATE_URL = 'popup-template';
    const AFTER_HIDE_EVENT = 'afterhide';
    const DATA_ACTION_TOGGLE = 'toggle';
    const DATA_ATTR = 'popup-id';
    const SHOW_EVENT = 'show';
    const HIDE_EVENT = 'hide';
    const AFTER_SHOW_EVENT = 'aftershow';
    const ANIMATION_DURATION = 250;
    const popups = $(POPUP_CLASS);

    if (!popups.length) {
        return;
    }

    const setCaller = function (targetPopup, btn, hide = true) {
        if (!targetPopup.length) {
            return;
        }

        if (hide) {
            const t = targetPopup.data();
            const callerId = targetPopup.attr('data-caller-target');
            const callerTarget = $(`[data-caller-id="${callerId}"]`);

            targetPopup.removeAttr('data-caller-target');
            callerTarget.removeAttr('data-caller-id');

            return;
        }

        // e6b30y3qkggk8eqybe6e80 - generate unique id
        const id = (Math.random() * Date.now())
            .toString(36)
            .replace('.', '')
            .repeat(2)
            .split('')
            .sort(() => 0.5 - Math.random()).join('');

        targetPopup.attr('data-caller-target', id);
        btn.attr('data-caller-id', id);
    }

    const getCurrentPopupButtons = (id) => {
        return $(document)
            .find(TOGGLE_BTN_CLASS)
            .filter(function () {
                const el = $(this);
                const action = el.data(DATA_ACTION_ATTR);

                return (action === DATA_ACTION_SHOW || DATA_ACTION_TOGGLE) && el.data(DATA_ATTR) === id;
            })
            .each(function () {
                $(this).addClass('active');
            });
    };

    const onShow = function (e) {
        const popup = $(this);
        const preload = popup.find('.popup__preload');

        popup.css('pointer-events', 'none');

        if (popup.hasClass(ACTIVE_POPUP_CLASS)) {
            return;
        }

        const activePopup = $('.popup.active');

        if (activePopup.length) {
            popup.css('z-index', Number(activePopup.css('z-index')) + 1);
        }

        let durationShit = ANIMATION_DURATION;

        if (popup.hasClass('js-profile-popup-wr')) {
            durationShit = 0;
        }

        const action = durationShit === '0' ? 'show' : 'fadeIn';

        popup[action](durationShit, () => {
            popup.addClass(ACTIVE_POPUP_CLASS).css('pointer-events', '');

            const btns = getCurrentPopupButtons('#' + popup.attr('id')).addClass('active');
            freeze();

            popup.trigger(AFTER_SHOW_EVENT);

            setTimeout(() => {
                preload.removeClass('is-active');
                setTimeout(() => {
                    $(window).trigger('resize');
                    const t = $('.textarea__control');
                    t.text(t.text().trim());
                    $(document).find('.textarea__control').trigger('change');
                }, 100);
            }, 1500);
        });
    };

    const onHide = function () {
        const popup = $(this);

        if (!popup.hasClass(ACTIVE_POPUP_CLASS)) {
            return;
        }

        setCaller(popup);
<commit_msg>resize<commit_after>import {freeze, unfreeze} from '../../static/js/disable-scroll';

export default function popup() {
    const POPUP_CLASS = '.popup';
    const WRAPPER_CLASS = '.popup__wrapper';
    const CLOSE_BTN_CLASS = '.popup__close';
    const ACTIVE_POPUP_CLASS = 'active';
    const TOGGLE_BTN_CLASS = '.js-toggle-popup';
    const PRELOAD_POPUP = 'js-popup-preload';
    const DATA_ACTION_ATTR = 'action';
    const DATA_ACTION_SHOW = 'show';
    const DATA_ACTION_HIDE = 'hide';
    const DATA_TEMPLATE_URL = 'popup-template';
    const AFTER_HIDE_EVENT = 'afterhide';
    const DATA_ACTION_TOGGLE = 'toggle';
    const DATA_ATTR = 'popup-id';
    const SHOW_EVENT = 'show';
    const HIDE_EVENT = 'hide';
    const AFTER_SHOW_EVENT = 'aftershow';
    const ANIMATION_DURATION = 250;
    const popups = $(POPUP_CLASS);

    if (!popups.length) {
        return;
    }

    const setCaller = function (targetPopup, btn, hide = true) {
        if (!targetPopup.length) {
            return;
        }

        if (hide) {
            const t = targetPopup.data();
            const callerId = targetPopup.attr('data-caller-target');
            const callerTarget = $(`[data-caller-id="${callerId}"]`);

            targetPopup.removeAttr('data-caller-target');
            callerTarget.removeAttr('data-caller-id');

            return;
        }

        // e6b30y3qkggk8eqybe6e80 - generate unique id
        const id = (Math.random() * Date.now())
            .toString(36)
            .replace('.', '')
            .repeat(2)
            .split('')
            .sort(() => 0.5 - Math.random()).join('');

        targetPopup.attr('data-caller-target', id);
        btn.attr('data-caller-id', id);
    }

    const getCurrentPopupButtons = (id) => {
        return $(document)
            .find(TOGGLE_BTN_CLASS)
            .filter(function () {
                const el = $(this);
                const action = el.data(DATA_ACTION_ATTR);

                return (action === DATA_ACTION_SHOW || DATA_ACTION_TOGGLE) && el.data(DATA_ATTR) === id;
            })
            .each(function () {
                $(this).addClass('active');
            });
    };

    const onShow = function (e) {
        const popup = $(this);
        const preload = popup.find('.popup__preload');

        popup.css('pointer-events', 'none');

        if (popup.hasClass(ACTIVE_POPUP_CLASS)) {
            return;
        }

        const activePopup = $('.popup.active');

        if (activePopup.length) {
            popup.css('z-index', Number(activePopup.css('z-index')) + 1);
        }

        let durationShit = ANIMATION_DURATION;

        if (popup.hasClass('js-profile-popup-wr')) {
            durationShit = 0;
        }

        const action = durationShit === '0' ? 'show' : 'fadeIn';

        popup[action](durationShit, () => {
            popup.addClass(ACTIVE_POPUP_CLASS).css('pointer-events', '');

            const btns = getCurrentPopupButtons('#' + popup.attr('id')).addClass('active');
            freeze();

            popup.trigger(AFTER_SHOW_EVENT);

            setTimeout(() => {
                preload.removeClass('is-active');
                setTimeout(() => {
                    $(popup).trigger('resize');
                    const t = $('.textarea__control');
                    t.text(t.text().trim());
                    $(document).find('.textarea__control').trigger('change');
                }, 100);
            }, 1500);
        });
    };

    const onHide = function () {
        const popup = $(this);

        if (!popup.hasClass(ACTIVE_POPUP_CLASS)) {
            return;
        }

        setCaller(popup);

{'fraction_non_alphanumeric': 0.14885496183206107, 'fraction_numerical': 0.007088331515812432, 'mean_word_length': 1.9219434488251692, 'pattern_counts': {'":': 0, '<': 3, '<?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': '1188751', 'n_tokens_mistral': 2279, 'n_tokens_neox': 2178, 'n_words': 390}