<commit_before>const debounce          = require('lodash.debounce');
const setExternalTimer  = require('../../../base/clock').setExternalTimer;
const BinarySocket      = require('../../../base/socket');
const getHighestZIndex  = require('../../../../_common/utility').getHighestZIndex;
const removeDigitTicker = require('../../trade/digit_ticker').remove;

const ViewPopupUI = (() => {
    let $container,
        stream_ids,
        chart_stream_ids,
        triggerOnClose;

    const init = () => {
        $container = null;
    };

    const container = (refresh) => {
        if (refresh) {
            if ($container) {
                $container.remove();
            }
            $container = null;
        }
        if (!$container) {
            const $con = $('<div class="inpage_popup_container" id="sell_popup_container"><a class="close"></a><div class="inpage_popup_content"></div></div>');
            $con.hide();
            const onClose = () => {
                cleanup(true);
                $(document).off('keydown');
                $(window).off('popstate', onClose);
                removeDigitTicker();
            };
            $con.find('a.close').on('click', onClose);
            $(document).on('keydown', (e) => {
                if (e.which === 27) onClose();
            });
            $(window).on('popstate', onClose);
            $container = $con;
        }
        // Reposition on scroll event
        window.addEventListener('scroll', debounce(repositionConfirmation, 100));
        return $container;
    };

    const cleanup = (is_close) => {
        forgetStreams();
        forgetChartStreams();
        setExternalTimer(null);
        closeContainer();
        init();
        if (typeof triggerOnClose === 'function') {
            triggerOnClose();
            if (is_close) {
                triggerOnClose = '';
            }
        }
        $(window).off('resize', () => { repositionConfirmation(); });
        document.removeEventListener('scroll', debounce, true);
    };

    const forgetStreams = () => {
        while (stream_ids && stream_ids.length > 0) {
            const id = stream_ids.pop();
            if (id && id.length > 0) {
                BinarySocket.send({ forget: id });
            }
        }
    };

    const forgetChartStreams = () => {
        while (chart_stream_ids && chart_stream_ids.length > 0) {
            const id = chart_stream_ids.pop();
            if (id && id.length > 0) {
                BinarySocket.send({ forget: id });
            }
        }
    };

    const closeContainer = () => {
        if ($container) {
            $container.hide().remove();
            $('.popup_page_overlay').hide().remove();
            $container = null;
        }
        $('html').removeClass('no-scroll');
    };

    const disableButton = (button) => {
        $('.open_contract_details[disabled]').each(function () {
            enableButton($(this));
        });
        button.attr('disabled', 'disabled');
        button.fadeTo(0, 0.5);
    };

    const enableButton = (button) => {
        button.removeAttr('disabled');
        button.fadeTo(0, 1);
    };

    const showInpagePopup = (data, containerClass, dragHandle) => {
        const con = container(true);
        if (containerClass) {
            con.addClass(containerClass);
        }
        if (data) {
            $('.inpage_popup_content', con).html(data);
        }
        const body = $(document.body);
        con.css('position', 'absolute').css('z-index', getHighestZIndex() + 100);
        body.append(con);
        con.show();
        // $('html').addClass('no-scroll');
        $(document.body).append($('<div/>', { class: 'popup_page_overlay' }));
        $('.popup_page_overlay').click(() => { container().find('a.close').click(); });<commit_msg>Use position:fixed for scroll<commit_after>const setExternalTimer  = require('../../../base/clock').setExternalTimer;
const BinarySocket      = require('../../../base/socket');
const getHighestZIndex  = require('../../../../_common/utility').getHighestZIndex;
const removeDigitTicker = require('../../trade/digit_ticker').remove;

const ViewPopupUI = (() => {
    let $container,
        stream_ids,
        chart_stream_ids,
        triggerOnClose;

    const init = () => {
        $container = null;
    };

    const container = (refresh) => {
        if (refresh) {
            if ($container) {
                $container.remove();
            }
            $container = null;
        }
        if (!$container) {
            const $con = $('<div class="inpage_popup_container" id="sell_popup_container"><a class="close"></a><div class="inpage_popup_content"></div></div>');
            $con.hide();
            const onClose = () => {
                cleanup(true);
                $(document).off('keydown');
                $(window).off('popstate', onClose);
                removeDigitTicker();
            };
            $con.find('a.close').on('click', onClose);
            $(document).on('keydown', (e) => {
                if (e.which === 27) onClose();
            });
            $(window).on('popstate', onClose);
            $container = $con;
        }
        return $container;
    };

    const cleanup = (is_close) => {
        forgetStreams();
        forgetChartStreams();
        setExternalTimer(null);
        closeContainer();
        init();
        if (typeof triggerOnClose === 'function') {
            triggerOnClose();
            if (is_close) {
                triggerOnClose = '';
            }
        }
        $(window).off('resize', () => { repositionConfirmation(); });
    };

    const forgetStreams = () => {
        while (stream_ids && stream_ids.length > 0) {
            const id = stream_ids.pop();
            if (id && id.length > 0) {
                BinarySocket.send({ forget: id });
            }
        }
    };

    const forgetChartStreams = () => {
        while (chart_stream_ids && chart_stream_ids.length > 0) {
            const id = chart_stream_ids.pop();
            if (id && id.length > 0) {
                BinarySocket.send({ forget: id });
            }
        }
    };

    const closeContainer = () => {
        if ($container) {
            $container.hide().remove();
            $('.popup_page_overlay').hide().remove();
            $container = null;
        }
        $('html').removeClass('no-scroll');
    };

    const disableButton = (button) => {
        $('.open_contract_details[disabled]').each(function () {
            enableButton($(this));
        });
        button.attr('disabled', 'disabled');
        button.fadeTo(0, 0.5);
    };

    const enableButton = (button) => {
        button.removeAttr('disabled');
        button.fadeTo(0, 1);
    };

    const showInpagePopup = (data, containerClass, dragHandle) => {
        const con = container(true);
        if (containerClass) {
            con.addClass(containerClass);
        }
        if (data) {
            $('.inpage_popup_content', con).html(data);
        }
        const body = $(document.body);
        con.css('position', 'fixed').css('z-index', getHighestZIndex() + 100);
        body.append(con);
        con.show();
        // $('html').addClass('no-scroll');
        $(document.body).append($('<div/>', { class: 'popup_page_overlay' }));
        $('.popup_page_overlay').click(() => { container().find('a.close').click(); });
{'fraction_non_alphanumeric': 0.17401861594496154, 'fraction_numerical': 0.00418184270875489, 'mean_word_length': 1.8417018014564968, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 53, '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': '134518', 'n_tokens_mistral': 2110, 'n_tokens_neox': 2035, 'n_words': 352}