(function( $ ) { 'use strict'; function gbt_cn_onElementInserted(containerSelector, selector, childSelector, callback) { if ("MutationObserver" in window) { var onMutationsObserved = function (mutations) { mutations.forEach(function (mutation) { if (mutation.addedNodes.length) { if ($(mutation.addedNodes).length) { var finalSelector = selector; var ownElement = $(mutation.addedNodes).filter(selector); if (childSelector != '') { ownElement = ownElement.find(childSelector); finalSelector = selector + ' ' + childSelector; } ownElement.each(function (index) { callback($(this), index + 1, ownElement.length, finalSelector,true); }); if (!ownElement.length) { var childElements = $(mutation.addedNodes).find(finalSelector); childElements.each(function (index) { callback($(this), index + 1, childElements.length, finalSelector,true); }); } } } }); }; var target = $(containerSelector)[0]; var config = {childList: true, subtree: true}; var MutationObserver = window.MutationObserver || window.WebKitMutationObserver; var observer = new MutationObserver(onMutationsObserved); observer.observe(target, config); } } function gbt_cn_onAddedToCart(selector, theclass, callback) { if ("MutationObserver" in window) { var onMutationsObserved = function (mutations) { mutations.forEach( function(mutation) { if(theclass != "") { if ((!mutation.oldValue || !mutation.oldValue.match(theclass) && mutation.oldValue.match('loading')) && mutation.target.classList && mutation.target.classList.contains(theclass)) { callback(); } } else { if (!mutation.oldValue || mutation.oldValue.match('loading')) { callback(); } } }); }; var target = selector[0]; var MutationObserver = window.MutationObserver || window.WebKitMutationObserver; var observer = new MutationObserver(onMutationsObserved); var config = {attributes: true, attributeOldValue: true, attributeFilter: ['class']}; observer.observe(target, config); } } var gbt_cn = { messages: [], open: false, init: function () { gbt_cn_onElementInserted('body', '.woocommerce-error', '', gbt_cn.readNotice); gbt_cn_onElementInserted('body', '.woocommerce-message', '', gbt_cn.readNotice); gbt_cn_onElementInserted('body', '.woocommerce-info', '', gbt_cn.readNotice); gbt_cn_onElementInserted('body', '.woocommerce-notice', '', gbt_cn.readNotice); gbt_cn_onElementInserted('body', '.wc-block-components-notice-banner', '', gbt_cn.readNotice); gbt_cn.checkExistingElements('.woocommerce-error'); gbt_cn.checkExistingElements('.woocommerce-message'); gbt_cn.checkExistingElements('.woocommerce-info'); gbt_cn.checkExistingElements('.woocommerce-notice'); gbt_cn.checkExistingElements('.wc-block-components-notice-banner'); }, checkExistingElements: function (selector) { var element = $(selector); if (element.length) { element.each(function (index) { gbt_cn.readNotice($(this), index + 1, element.length, selector,false); }); } }, readNotice: function (element, index, total, selector, dynamic) { $(".page-notifications").css( 'top', $('.top-headers-wrapper').outerHeight() + $('#wpadminbar').outerHeight() ); var noticeType = selector.match(/-(error|message|info|notice|success)/); noticeType = !noticeType || !noticeType[1] ? 'success' : noticeType[1]; if (index <= total) { gbt_cn.storeMessage(element, noticeType, dynamic); } if (index == total) { gbt_cn.clearPopupMessages(); gbt_cn.addMessagesToPopup(); setTimeout(function(){ gbt_cn.openPopup(element); }, 100); setTimeout(function(){ gbt_cn.messages = []; }, 1000); } }, clearPopupMessages: function () { $('#gbt-custom-notification-notice').find('.gbt-custom-notification-content').empty(); }, removeDuplicatedMessages: function () { var obj = {}; for (var i = 0, len = gbt_cn.messages.length; i < len; i++) { obj[gbt_cn.messages[i]['message']] = gbt_cn.messages[i]; } gbt_cn.messages = new Array(); for (var key in obj) gbt_cn.messages.push(obj[key]); }, isMessageValid: function (message, dynamic) { var ignored_msg = ["
", "