product.querySelectorAll('.js-product-edition-option-variants'),
8814 function (editionOption) { 8815 editionOption.removeEventListener('change', editionOptionEvent); 8817 var el_control = editionOption.closest('.js-product-edition-option'); 8818 var el_custom_ui = el_control.querySelector('.t-product__option-variants_custom'); 8820 editionOption.addEventListener('change', editionOptionEvent); 8825 Array.prototype.forEach.call( 8826 product.querySelectorAll('.t-product__option-variants_custom'), 8827 function (variantCustom) { 8828 var el_input = variantCustom.querySelectorAll('.t-product__option-input'); 8829 var el_option = variantCustom.querySelectorAll('.t-product__option-item'); 8830 var el_select_hidden = variantCustom.parentNode.querySelector( 8831 '.t-product__option-variants_regular .js-product-edition-option-variants' 8834 Array.prototype.forEach.call(el_input, function (optionInput) { 8835 optionInput.addEventListener('change', function () { 8836 var value = this.value.replace(/&/g, '&'); 8837 el_select_hidden.value = value; 8838 t_triggerEvent(el_select_hidden, 'change'); 8840 Array.prototype.forEach.call(el_option, removeActiveClass); 8842 this.parentNode.classList.add('t-product__option-item_active'); 8848 // If custom dropdown exists, add events 8849 Array.prototype.forEach.call( 8850 product.querySelectorAll('.t-product__option-selected_select'), 8851 function (customDropdown) { 8852 // Toggle dropdown visibility 8853 var customDropdownClickEvent = function () { 8854 if (this.nextElementSibling.classList.contains('t-product__option-variants_custom')) { 8855 this.nextElementSibling.classList.toggle('t-product__option-variants_hidden'); 8857 // TODO: rewrite this part to call t_lazyload_update() only once per custom dropdown 8858 if (window.lazy === 'y') { 8859 t_lazyload_update(); 8862 customDropdown.removeEventListener('click', customDropdownClickEvent); 8863 customDropdown.addEventListener('click', customDropdownClickEvent); 8865 // Update selected option values 8866 var el_select_custom = customDropdown.parentNode.querySelector('.t-product__option-variants_custom'); 8867 var el_option = el_select_custom.querySelectorAll('.t-product__option-item'); 8869 var optionClickEvent = function () { 8870 Array.prototype.forEach.call(el_option, function (option) { 8871 option.classList.remove('t-product__option-item_active'); 8873 this.classList.add('t-product__option-item_active'); 8874 this.closest('.t-product__option-variants_custom').classList.add('t-product__option-variants_hidden'); 8876 var value = this.querySelector('.t-product__option-title').textContent; 8877 var el_text = this.closest('.t-product__option').querySelector('.t-product__option-selected-title'); 8878 el_text.textContent = value; 8880 // If dropdown type is color, update color in select 8881 var el_selected_color = this.closest('.t-product__option').querySelector( 8882 '.t-product__option-selected.t-product__option-selected_color' 8887 if (el_selected_color) { 8888 var color = this.querySelector('.t-product__option-checkmark_color').style.backgroundColor; 8889 el_checkmark = el_selected_color.querySelector('.t-product__option-selected-checkmark'); 8890 el_checkmark.style.backgroundColor = color; 8893 // If dropdown type is image, update image in select 8894 var el_selected_image = this.closest('.t-product__option').querySelector( 8895 '.t-product__option-selected.t-product__option-selected_image' 8898 if (el_selected_image) { 8899 var imageUrl = this.querySelector('.t-product__option-checkmark_image').style.backgroundImage; 8900 var imageUrlLazyload = this.querySelector('.t-product__option-checkmark_image').getAttribute(