1(function ($) { 2 'use strict'; 3 4 function startListeningForMutations(elements, matcher, callback) { 5 6 const recurse = (parent) => { 7 8 for (let match in matcher) { 9 const parentValue = parent[match]; 10 const matcherValue = matcher[match]; 11 if (!parentValue || (parentValue !== matcherValue && !String(parentValue).includes(matcherValue))) { 12 if (parent.childNodes) { 13 [...parent.childNodes].forEach(recurse); 14 } 15 return; 16 } 17 } 18 callback(parent); 19 }; 20 21 // select the target node 22 var target = $(elements); 23 24 if (target) { 25 // create an observer instance 26 var observer = new MutationObserver(function (mutations) { 27 //loop through the detected mutations(added controls) 28 mutations.forEach(function (mutation) { 29 for (const node of mutation.addedNodes) { 30 recurse(node); 31 } 32 }); 33 }); 34 let obsConfig = { 35 childList: true, 36 characterData: true, 37 attributes: true, 38 subtree: true 39 }; 40 target.each(function () { 41 observer.observe(this, obsConfig); 42 }); 43 44 // later, you can stop observing 45 //observer.disconnect(); 46 } 47 } 48 49 function attachShippingLogos() { 50 const shippingMethods = $("input[type='radio'][value^=woo_lithuaniapost_lpexpress_terminal]"); 51 if (shippingMethods.length > 0) { 52 $(shippingMethods).each(function (index, input) { 53 attachLogo(input); 54 }); 55 return true; 56 } 57 return false; 58 } 59 60 function attachLogo(shippingMethodElement) { 61 const imgUrl = woo_lithuaniapost.shipping_logo_url; 62 if ($(shippingMethodElement).next().filter((index, element) => $(element).prop('nodeName') === 'IMG').length === 0) { 63 $(shippingMethodElement).after("<img style='max-width:45px; max-height:25px; padding-right: 0.1em;' src=" + imgUrl + ">"); 64 } 65 } 66 67 $(document).ready(function () { 68 const elementMatcher = { 69 nodeName: 'INPUT', 70 type: 'radio', 71 value: 'woo_lithuaniapost_lpexpress_terminal' 72 }; 73 startListeningForMutations(document, elementMatcher, function (matchedElement) { 74 attachLogo(matchedElement); 75 }); 76 attachShippingLogos(); 77 }); 78 79})(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.