701702if (popup) {703popup.addEventListener('scroll', updateSelectPositionDebounced);704}705}706707function t_form_phonemask__removeWrapPositionUpdateListeners() {708window.removeEventListener('resize', updateSelectPositionDebounced);709document.removeEventListener('scroll', updateSelectPositionDebounced);710711if (popup) {712popup.removeEventListener('scroll', updateSelectPositionDebounced);
} } function t_form_phonemask__updateSelectWrap() { t_form_phonemask__renderSelectOptions(); t_form_phonemask__updateSelectWrapPosition(); t_form_phonemask__setSelectOptionsEvents(); t_form_phonemask__removeWrapPositionUpdateListeners(); if (t_form_phonemask__isAutoscaleFixNeeded()) { t_form_phonemask__fixStylesForSafariAutoscale(); } else { selectWrap.style.position = ''; t_form_phonemask__addWrapPositionUpdateListeners(); } } /** * Toggle select in phone mask */ function t_form_phonemask__toggleSelect() { if (selectWrap.classList.contains('t-input-phonemask__options-wrap_open')) { t_form_phonemask__activeSelectClose(); } else { t_form_phonemask__activeSelectClose(); selectWrap.classList.add('t-input-phonemask__options-wrap_open'); t_form_phonemask__updateSelectWrap(); } } /** * Close select */ function t_form_phonemask__activeSelectClose() { var activeSelect = document.querySelector('.t-input-phonemask__options-wrap_open'); if (activeSelect) activeSelect.classList.remove('t-input-phonemask__options-wrap_open'); t_form_phonemask__removeWrapPositionUpdateListeners(); } /** * Chenge input value */ function t_form_phonemask__changeInputVal() { t_form_phonemask__handleChangeInputValue(inputGroup, this); } /** * Change country option */ function t_form_phonemask__changeOption() { t_form_phonemask__chooseCountry(inputGroup, this); t_form_phonemask__activeSelectClose(); } /** * Get outside click * * @param {MouseEvent} e - event */ function t_form_phonemask__getOutsideClick(e) { var elem = e.target.closest('.t-input-phonemask__options-wrap'); var select = e.target.closest('.t-input-phonemask__select'); if (!elem && !select) { t_form_phonemask__activeSelectClose(); } } /** * Handler key up * * @param {KeyboardEvent} e - event * @returns */ function t_form_phonemask__handlerKeyUp(e) { const activeSelect = document.querySelector('.t-input-phonemask__options-wrap_open'); if (!activeSelect) return; const regExp = /[-[\]/{}()*+?.\\^$|]/g; const itemChosen = activeSelect.querySelector('.t-input-phonemask__options-item_chosen'); const searchCountry = []; if (itemChosen) itemChosen.classList.remove('t-input-phonemask__options-item_chosen'); const isDigitKey = /^[0-9]$/.test(e.key); const isNumpadDigit = e.code && e.code.startsWith('Numpad') && isDigitKey; if (isDigitKey || isNumpadDigit) {