/** * Подготавливает legacy-обертку кнопок в карточке до монтирования quantity widget. * Нужна для сохранения совместимости со старыми CSS-правилами кнопок. * * @param {HTMLElement} cardButton - Кнопка заказа в карточке. */function t_catalog__prepareCardQuantityWrapper(cardButton) { if (!(cardButton instanceof HTMLElement)) return; const btnsWrapper = cardButton.closest('.t-catalog__card__btns-wrapper'); if (!(btnsWrapper instanceof HTMLElement)) return; const orderButtonParent = cardButton.parentNode; if ( orderButtonParent instanceof HTMLElement && orderButtonParent.classList.contains('t-catalog__card__btns-wrapper--quantity') ) return; if (btnsWrapper.querySelector('.t-catalog__card__btns-wrapper--quantity')) return; if (btnsWrapper.querySelectorAll('a:not([href^="#order"])').length === 0) return; if (!(btnsWrapper.parentNode instanceof HTMLElement)) return; if (!Element.prototype.matches.call(btnsWrapper.parentNode, 'div[class]')) return; const btnsWrapperQuantity = document.createElement('div'); btnsWrapperQuantity.classList.add('t-catalog__card__btns-wrapper--quantity'); btnsWrapper.appendChild(btnsWrapperQuantity); while (btnsWrapper.firstChild && btnsWrapper.firstChild !== btnsWrapperQuantity) { btnsWrapperQuantity.appendChild(btnsWrapper.firstChild); }}/** * Удаляет quantity widget из товара вместе с контейнером виджета. * Снимает обертку кнопок карточки, созданную t_catalog__prepareCardQuantityWrapper, * чтобы кнопки без степпера лежали так же, как в карточке без количества. * * @param {Element | null} productEl - Корневой DOM-элемент товара. */function t_catalog_removeProductQuantity(productEl) { if (!productEl) return; const quantityContainer = productEl.querySelector('.js-product-quantity-widget'); if (!quantityContainer) return; const containerParent = quantityContainer.parentNode; if (quantityContainer instanceof HTMLElement) t_catalog_unmountComponent(quantityContainer); if (containerParent) containerParent.removeChild(quantityContainer); if ( !(containerParent instanceof HTMLElement) || !containerParent.classList.contains('t-catalog__card__btns-wrapper--quantity') ) return; const btnsWrapper = containerParent.parentNode; if (!(btnsWrapper instanceof HTMLElement) || !btnsWrapper.classList.contains('t-catalog__card__btns-wrapper')) return; while (containerParent.firstChild) { btnsWrapper.insertBefore(containerParent.firstChild, containerParent); } btnsWrapper.removeChild(containerParent);}/** * Initializes routing for opening and closing a product popup using the browser's back and forward buttons. * * @param {string} recid - The ID of the product to open in the popup. * @param {Object} opts - An object containing options for the product popup. * @param {boolean} [opts.isRelevantsShow=false] - Whether to show relevant products in the popup. * @param {string} [opts.recid=null] - The ID of the relevant product to open in the popup. * @param {Object} [opts.productObj=null] - The product object for the product being opened in the popup. */function t_catalog_open_popup_routing_init(recid, opts) { window.onpopstate = function () { if (window.history.state) { if (window.history.state.productData) { var productPopupData = window.history.state.productData; var recidFromHistory = productPopupData.recid, optsFromHistory = productPopupData.opts, productObjFromHistory = productPopupData.productObj, isRelevantsShowFromHistory = productPopupData.isRelevantsShow; t_catalog_openProductPopup( recidFromHistory, optsFromHistory, productObjFromHistory, isRelevantsShowFromHistory,