diff --git a/modules/trustedshopsbbb/views/rich_snippets_2.tpl b/modules/trustedshopsbbb/views/rich_snippets_2.tpl index 8e092c49..49dfac69 100644 --- a/modules/trustedshopsbbb/views/rich_snippets_2.tpl +++ b/modules/trustedshopsbbb/views/rich_snippets_2.tpl @@ -21,11 +21,30 @@ var __ts = document.getElementsByTagName('script')[0]; __ts.parentNode.insertBefore(_ts, __ts); })(); + function onElementInserted(containerSelector, elementSelector, callback) { + var onMutationsObserved = function(mutations) { + mutations.forEach(function(mutation) { + if (mutation.addedNodes.length) { + var elements = $(mutation.addedNodes).find(elementSelector); + for (var i = 0, len = elements.length; i < len; i++) { + callback(elements[i]); + } + } + }); + }; + + 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); + + } $(document).ready(function(){ - setTimeout(function(){ + onElementInserted('#customCheckoutDiv2', 'div', function(element) { $('#customCheckoutDiv2 div[id^=\'tsbadge_\']').css('width','200px'); $('#customCheckoutDiv2 div[id^=\'tsCustomBadge\']').css('width','200px'); - },1200); + }); }); {/literal}