1/** 2 * The admin class for the badges admin page. 3 */ 4class KTBadges { 5 /** 6 * The badges. 7 */ 8 badges = []; 9 10 /** 11 * The main constructor. 12 */ 13 constructor() { 14 const self = this; 15 this.initBadges(); 16 } 17 18 initBadges(e) { 19 const self = this; 20 this.badges = document.querySelectorAll(".kt-woo-badge"); 21 this.badges.forEach((badge) => { 22 const attachedPostId = badge.dataset?.["attachedPostId"]; 23 24 self.placeBadge(badge); 25 }); 26 } 27 28 placeBadge(badge) { 29 if (badge) { 30 const pagetype = badge.dataset?.["pageType"]; 31 if (pagetype == "loop") { 32 const loopWrapper = badge.closest( 33 ".product.has-post-thumbnail" 34 ); 35 if (loopWrapper) { 36 const imgContainer = loopWrapper.querySelector( 37 ".woocommerce-loop-product__link, .wc-block-grid__product-image > a, .product_item_link" 38 ); 39 if (imgContainer) { 40 imgContainer.appendChild(badge); 41 badge.classList.add("kt-woo-badge-active"); 42 } 43 } 44 } else if (pagetype == "kadence-wootemplate-blocks-gallery") { 45 const wrapper = badge.previousElementSibling; 46 if (wrapper) { 47 const imgContainer = 48 wrapper.querySelector(".product_image"); 49 if (imgContainer) { 50 imgContainer.appendChild(badge); 51 badge.classList.add("kt-woo-badge-active"); 52 } 53 } 54 } else if (pagetype == "kadence-wootemplate-blocks-image") { 55 const wrapper = badge.previousElementSibling; 56 if (wrapper) { 57 const imgContainer = wrapper.querySelector( 58 ".woocommerce-product-gallery__image, .woocommerce-loop-image-link" 59 ); 60 if (imgContainer) { 61 imgContainer.appendChild(badge); 62 badge.classList.add("kt-woo-badge-active"); 63 } 64 } 65 } else if (pagetype == "woocommerce-single-product") { 66 const wrapper = badge.previousElementSibling; 67 if (wrapper) { 68 const imgContainer = wrapper.querySelector( 69 ".wc-block-components-product-image" 70 ); 71 if (imgContainer) { 72 imgContainer.appendChild(badge); 73 badge.classList.add("kt-woo-badge-active"); 74 } 75 } 76 } else if (pagetype == "woocommerce_blocks_product_grid") { 77 const loopWrapper = badge.closest( 78 ".loop-entry, .wc-block-grid__product" 79 ); 80 if (loopWrapper) { 81 const imgContainer = loopWrapper.querySelector( 82 ".woocommerce-loop-image-link, .wc-block-grid__product-image" 83 ); 84 if (imgContainer) { 85 imgContainer.appendChild(badge); 86 badge.classList.add("kt-woo-badge-active"); 87 } 88 } 89 } else if (pagetype == "woocommerce-product-image") { 90 const loopWrapper = badge.closest(".product"); 91 if (loopWrapper) { 92 const imgContainer = loopWrapper.querySelector( 93 ".woocommerce-loop-product__link, .wc-block-grid__product-image > a" 94 ); 95 if (imgContainer) { 96 imgContainer.appendChild(badge); 97 badge.classList.add("kt-woo-badge-active"); 98 } 99 } 100 } else { 101 const wrapper = document.querySelector(".product"); 102 if (wrapper) { 103 const imgContainer = wrapper.querySelector( 104 ".product_image, .woocommerce-product-gallery__image" 105 ); 106 if (imgContainer) { 107 imgContainer.appendChild(badge); 108 badge.classList.add("kt-woo-badge-active"); 109 } 110 } 111 } 112 } 113 } 114} 115 116const init = () => { 117 window.KTBadgeAdminInstance = new KTBadges(); 118 119 document.addEventListener("kadenceJSInitReload", function () { 120 window.KTBadgeAdminInstance.initBadges(); 121 }); 122 document.addEventListener("kb-query-loaded", function () { 123 window.KTBadgeAdminInstance.initBadges(); 124 }); 125 document.addEventListener("kt-quickview-load", function () { 126 window.KTBadgeAdminInstance.initBadges(); 127 }); 128}; 129 130if ("loading" === document.readyState) { 131 // The DOM has not yet been loaded. 132 document.addEventListener("DOMContentLoaded", init); 133} else { 134 // The DOM has already been loaded. 135 init(); 136}
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.