1(function( $ ) { 2 3 'use strict'; 4 5 function gbt_cn_onElementInserted(containerSelector, selector, childSelector, callback) { 6 if ("MutationObserver" in window) { 7 var onMutationsObserved = function (mutations) { 8 mutations.forEach(function (mutation) { 9 if (mutation.addedNodes.length) { 10 if ($(mutation.addedNodes).length) { 11 var finalSelector = selector; 12 var ownElement = $(mutation.addedNodes).filter(selector); 13 if (childSelector != '') { 14 ownElement = ownElement.find(childSelector); 15 finalSelector = selector + ' ' + childSelector; 16 } 17 ownElement.each(function (index) { 18 callback($(this), index + 1, ownElement.length, finalSelector,true); 19 }); 20 if (!ownElement.length) { 21 var childElements = $(mutation.addedNodes).find(finalSelector); 22 childElements.each(function (index) { 23 callback($(this), index + 1, childElements.length, finalSelector,true); 24 }); 25 } 26 } 27 } 28 }); 29 }; 30 31 var target = $(containerSelector)[0]; 32 var config = {childList: true, subtree: true}; 33 var MutationObserver = window.MutationObserver || window.WebKitMutationObserver; 34 var observer = new MutationObserver(onMutationsObserved); 35 observer.observe(target, config); 36 } 37 } 38 39 function gbt_cn_onAddedToCart(selector, theclass, callback) { 40 if ("MutationObserver" in window) { 41 var onMutationsObserved = function (mutations) { 42 mutations.forEach( function(mutation) { 43 if(theclass != "") { 44 if ((!mutation.oldValue || !mutation.oldValue.match(theclass) && mutation.oldValue.match('loading')) 45 && mutation.target.classList && mutation.target.classList.contains(theclass)) { 46 callback(); 47 } 48 } else { 49 if (!mutation.oldValue || mutation.oldValue.match('loading')) { 50 callback(); 51 } 52 } 53 }); 54 }; 55 56 var target = selector[0]; 57 var MutationObserver = window.MutationObserver || window.WebKitMutationObserver; 58 var observer = new MutationObserver(onMutationsObserved); 59 var config = {attributes: true, attributeOldValue: true, attributeFilter: ['class']}; 60 observer.observe(target, config); 61 } 62 } 63 64 var gbt_cn = { 65 messages: [], 66 open: false, 67 init: function () { 68 gbt_cn_onElementInserted('body', '.woocommerce-error', '', gbt_cn.readNotice); 69 gbt_cn_onElementInserted('body', '.woocommerce-message', '', gbt_cn.readNotice); 70 gbt_cn_onElementInserted('body', '.woocommerce-info', '', gbt_cn.readNotice); 71 gbt_cn_onElementInserted('body', '.woocommerce-notice', '', gbt_cn.readNotice); 72 gbt_cn_onElementInserted('body', '.wc-block-components-notice-banner', '', gbt_cn.readNotice); 73 74 gbt_cn.checkExistingElements('.woocommerce-error'); 75 gbt_cn.checkExistingElements('.woocommerce-message'); 76 gbt_cn.checkExistingElements('.woocommerce-info'); 77 gbt_cn.checkExistingElements('.woocommerce-notice'); 78 gbt_cn.checkExistingElements('.wc-block-components-notice-banner'); 79 }, 80 checkExistingElements: function (selector) { 81 var element = $(selector); 82 if (element.length) { 83 element.each(function (index) { 84 gbt_cn.readNotice($(this), index + 1, element.length, selector,false); 85 }); 86 } 87 }, 88 readNotice: function (element, index, total, selector, dynamic) { 89 $(".page-notifications").css( 'top', $('.top-headers-wrapper').outerHeight() + $('#wpadminbar').outerHeight() ); 90 var noticeType = selector.match(/-(error|message|info|notice|success)/); 91 noticeType = !noticeType || !noticeType[1] ? 'success' : noticeType[1]; 92 93 if (index <= total) { 94 gbt_cn.storeMessage(element, noticeType, dynamic); 95 } 96 if (index == total) { 97 gbt_cn.clearPopupMessages(); 98 gbt_cn.addMessagesToPopup(); 99 setTimeout(function(){ 100 gbt_cn.openPopup(element); 101 }, 100); 102 setTimeout(function(){ 103 gbt_cn.messages = []; 104 }, 1000); 105 } 106 }, 107 clearPopupMessages: function () { 108 $('#gbt-custom-notification-notice').find('.gbt-custom-notification-content').empty(); 109 }, 110 removeDuplicatedMessages: function () { 111 var obj = {}; 112 for (var i = 0, len = gbt_cn.messages.length; i < len; i++) { 113 obj[gbt_cn.messages[i]['message']] = gbt_cn.messages[i]; 114 } 115 116 gbt_cn.messages = new Array(); 117 for (var key in obj) 118 gbt_cn.messages.push(obj[key]); 119 }, 120 isMessageValid: function (message, dynamic) { 121 var ignored_msg = ["<p></p>", "<ul class=\"msg\"></ul>", "<ul></ul>"]; 122 // Ignored Messages 123 var matches = ignored_msg.filter(function (string_check) { 124 return message.indexOf(string_check) !== -1; 125 }); 126 if (matches.length > 0) { 127 return false; 128 } 129 130 return true; 131 }, 132 storeMessage: function (notice, type, dynamic) { 133 if (gbt_cn.isMessageValid(notice.html(),dynamic)) { 134 gbt_cn.messages.push({message: notice.html(), type: type, dynamic:dynamic}); 135 gbt_cn.removeDuplicatedMessages();
136 } 137 }, 138 getAdditionalIconClass: function (noticeType) { 139 var iconClass = ""; 140 switch (noticeType) { 141 case "success": 142 iconClass = gbt_cn_info.success_icon_class; 143 break; 144 case "error": 145 iconClass = gbt_cn_info.error_icon_class; 146 break; 147 case "info": 148 iconClass = gbt_cn_info.info_icon_class; 149 break; 150 } 151 if (iconClass == "") { 152 iconClass += " " + gbt_cn_info.icon_default_class; 153 } 154 return iconClass; 155 }, 156 addMessagesToPopup: function (notice) { 157 var notification; 158 159 $.each(gbt_cn.messages, function (index, value) { 160 var additional_icon_class = gbt_cn.getAdditionalIconClass(value.type); 161 var dynamicClass = value.dynamic ? 'gbt-cn-dynamic' : 'gbt-cn-static'; 162 163 if(value.message != "") { 164 if(value.message.indexOf('product_notification_background') >= 0) { // build notification for added to cart product 165 notification = $('#gbt-custom-notification-notice .gbt-custom-notification-content').append("<div class='gbt-custom-notification-notice " + value.type + ' ' + dynamicClass + " '>" + value.message + "</div>"); 166 } else { // build default notification 167 $('#gbt-custom-notification-notice .gbt-custom-notification-content').append("<div class='gbt-custom-notification-notice " + value.type + ' ' + dynamicClass + " '><i class='gbt-custom-notification-notice-icon " + additional_icon_class + "'></i><div class='gbt-custom-notification-message'><div>" + value.message + "</div></div></div>"); 168 } 169 } 170 }); 171 }, 172 openPopup: function () { 173 $('.gbt-custom-notification-notice').addClass('open-notice'); 174 175 if( $('.page-notifications').hasClass('slide-out') ) { 176 setTimeout(function(){ 177 $('.gbt-custom-notification-notice').removeClass('open-notice').addClass('close-notice'); 178 }, 2250); 179 } 180 } 181 }; 182 183 document.addEventListener('DOMContentLoaded', function () { 184 gbt_cn.init(); 185 $('body').trigger({ 186 type: 'gbt_cn', 187 obj: gbt_cn 188 }); 189 190 // Close notification on click 191 $(document).on( 'click', '.page-notifications.slide-in .gbt-custom-notification-notice', function(){ 192 $(this).removeClass('open-notice').addClass('close-notice'); 193 }); 194 195 // Simple Product - Build and display notification on ajax add to cart 196 $('body.gbt_custom_notif.single-product').on('click touchend', '.product.product-type-simple .columns > .product_infos .cart .ajax_add_to_cart', function(e){ 197 198 // get product's image 199 if( $('body').find('.product_layout_classic').length > 0 ) { 200 var imgSrc = $('.woocommerce-product-gallery .woocommerce-product-gallery__wrapper > .woocommerce-product-gallery__image img').attr('src') || ""; 201 } else { 202 var imgSrc = $('.woocommerce-product-gallery__wrapper .product_images .product-image:first-child img').attr('src') || ""; 203 } 204 205 // get product's title 206 var prodTitle = $('.product_title').html() || ""; 207 208 gbt_cn_onAddedToCart($(this), 'added', function() { 209 $('#content').prepend('<div class="woocommerce-message"><div class="product_notification_wrapper"><div class="product_notification_background"><img src="'+imgSrc+'" alt="Notification Image" /></div><div class="product_notification_text"><div>' + gbt_cn_info.cartButton + '"' + prodTitle + '" ' + gbt_cn_info.addedToCartMessage +'</div></div></div></div>'); 210 }); 211 }); 212 213 // Archive Page - Build and display notification on ajax add to cart 214 $('body').on('click touchend', '.products .ajax_add_to_cart', function(){ 215 var imgSrc = $(this).parents('.product').find('.product_thumbnail_wrapper img').attr('src') || ""; 216 var prodTitle = $(this).parents('.product').find('.woocommerce-loop-product__title a').html() || ""; 217 218 gbt_cn_onAddedToCart($(this), 'added', function() { 219 $('.st-content').prepend('<div class="woocommerce-message"><div class="product_notification_wrapper"><div class="product_notification_background"><img src="'+imgSrc+'" alt="Notification Image" /></div><div class="product_notification_text"><div>' + gbt_cn_info.cartButton + '"' + prodTitle + '" ' + gbt_cn_info.addedToCartMessage +'</div></div></div></div>'); 220 }); 221 }); 222 223 // Wishlist Page - Build and display notification on add to cart 224 $('body.gbt_custom_notif.woocommerce-wishlist').on('click touchend', '.ajax_add_to_cart', function(){ 225 var imgSrc = $(this).parents('tr').find('.product-thumbnail img').attr('src') || ""; 226 var prodTitle = $(this).parents('tr').find('.product-name a').html() || ""; 227 228 gbt_cn_onAddedToCart($(this), "", function() { 229 $('.st-content').prepend('<div class="woocommerce-message"><div class="product_notification_wrapper"><div class="product_notification_background"><img src="'+imgSrc+'" alt="Notification Image" /></div><div class="product_notification_text"><div>' + gbt_cn_info.cartButton + '"' + prodTitle + '" ' + gbt_cn_info.addedToCartMessage +'</div></div></div></div>'); 230 }); 231 }); 232 }); 233 234} )( jQuery );
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.