Отследить отправку формы
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
<script src="https://code.jquery.com/jquery-3.7.1.js"></script> <script> document.addEventListener('DOMContentLoaded', ()=>{ var observeObject = function () { var _class = { init: function (selector, callback) { var element = document.querySelector(selector); try { var observer = new MutationObserver(function (mutations) { mutations.forEach(function (mutation) { callback(mutation.target, mutation.attributeName, mutation.oldValue); }); }); observer.observe(element, { attributes: true, //subtree: true, attributeOldValue: true }); } catch (z) { element.addEventListener('DOMAttrModified', function (e) { callback(e.target, e.attrName, e.prevValue); }, false); } } }; return _class; }(); /* А тут инициализируем отслеживание в элементе, передавая селектор */ $(function () { //.t-popup observeObject.init('#form808554124', function (target, name, oldValue) { /* ссылка на Node, имя атрибута, предыдущее значение */ if (oldValue !== null) { if (oldValue.indexOf("js-send-form-success") === -1) { // открытие попапа console.log('попап открыт'); if (document.querySelector('#form808554124').classList.contains('js-send-form-success')) { alert("Form senders"); } } else { // закрытие попапа console.log('попап закрыт'); } } }); }); }); </script> |
Отслеживаниеналичие товара в корзине по артиркулу
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
var observeObject = function () { var _class = { init: function (selector, callback) { var element = document.querySelector(selector); try { var observer = new MutationObserver(function (mutations) { mutations.forEach(function (mutation) { callback(mutation.target, mutation.attributeName, mutation.oldValue); }); }); observer.observe(element, { attributes: true, //subtree: true, attributeOldValue: true }); } catch (z) { element.addEventListener('DOMAttrModified', function (e) { callback(e.target, e.attrName, e.prevValue); }, false); } } }; return _class; }(); /* А тут инициализируем отслеживание в элементе, передавая селектор */ $(function () { //.t-popup observeObject.init('.t-body', function (target, name, oldValue) { /* ссылка на Node, имя атрибута, предыдущее значение */ if (oldValue !== null) { if (oldValue.indexOf("t-body_popupshowed") === -1) { // открытие попапа console.log('попап открыт'); if (document.querySelector('body').classList.contains('t-body_popupshowed')) { var $parent = $(target).eq(-1).find('.t-store__prod-popup__container'), articul = $parent.find('.js-product-sku').text(), $containerPoup = $parent.find('.t-store__product-popup'); if (articul.trim().toLowerCase() === productArticul) { $parent.addClass('active'); if (!$containerPoup.next().hasClass('constructor')) { $containerPoup.after($('#vue').html()); window.initVue(); } } else { $parent.removeClass('active').find('.constructor').remove(); } } } else { // закрытие попапа console.log('попап закрыт'); $('.constructor').remove(); } } }); }); |
