Last active
March 26, 2021 08:20
-
-
Save dmjcomdem/4d2e592ae3f23f60ab40d508773d16c3 to your computer and use it in GitHub Desktop.
Revisions
-
dmjcomdem revised this gist
Mar 26, 2021 . 1 changed file with 0 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,3 @@ // prettier-ignore (function() { function mutationObserver( -
dmjcomdem revised this gist
Mar 26, 2021 . 1 changed file with 2 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,5 @@ console.log(123); // prettier-ignore (function() { function mutationObserver( -
dmjcomdem revised this gist
Mar 26, 2021 . 1 changed file with 2 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -17,6 +17,8 @@ observer.observe(node, options); return observer.disconnect; } console.log(mutationObserver) function resizeHandler(node) { const height = node.firstChild.contentDocument.body.firstChild.offsetHeight; -
dmjcomdem created this gist
Mar 26, 2021 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,57 @@ // prettier-ignore (function() { function mutationObserver( node, callback, options = { childList: true, subtree: true, attributes: true, attributeOldValue: false, characterDataOldValue: false } ) { const observer = new MutationObserver(function([mutation]) { callback(mutation); }); observer.observe(node, options); return observer.disconnect; } function resizeHandler(node) { const height = node.firstChild.contentDocument.body.firstChild.offsetHeight; node.style.width = '100%'; node.style.height = height + 'px'; } function autoResizeIframe(wrapperIframe) { mutationObserver(wrapperIframe, function(mutation) { resizeHandler(mutation.target) window.addEventListener('resize', () => resizeHandler(mutation.target)); }); } mutationObserver(document.body, function(mutation) { if (mutation.target.tagName === 'IAE-TAG') { const iframe = mutation.addedNodes[0]; if (iframe instanceof HTMLIFrameElement) { autoResizeIframe(mutation.target); console.log(iframe); window.addEventListener('message', e => { if (e.data && e.data.startsWith('adserver-content')) { const data = JSON.parse(e.data.replace(/^adserver-content/g, '')); if (data.event === 'addToBasket') { setTimeout(() => { const result = { event: 'addToBasket', message: 'Отправленно в Iframe' }; iframe.contentWindow.postMessage('adserver-content' + JSON.stringify(result),'*'); }, 2000); } } }); } } }); })();