Skip to content

Commit

Permalink
Improve resize logic for native (#193)
Browse files Browse the repository at this point in the history
  • Loading branch information
dgirardi authored Aug 28, 2023
1 parent a323706 commit 5e8a24f
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/nativeAssetManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ export function newNativeAssetManager(win, nativeTag) {
} else if ((data.hasOwnProperty('adTemplate') && data.adTemplate)||(hasPbNativeData() && win.pbNativeData.hasOwnProperty('adTemplate'))) {
const template = (hasPbNativeData() && win.pbNativeData.hasOwnProperty('adTemplate') && win.pbNativeData.adTemplate) || data.adTemplate;
const newHtml = replace(template, data);

renderAd(newHtml, data);
} else {
const newHtml = replace(body, data);
Expand All @@ -366,7 +366,7 @@ export function newNativeAssetManager(win, nativeTag) {
if (!currentParentWindow.frames || !currentParentWindow.frames.length) return null;
for (let idx = 0; idx < currentParentWindow.frames.length; idx++)
if (currentParentWindow.frames[idx] === currentWindow) {
if (!currentParentWindow.document) return null;
if (!currentParentWindow.document) return null;
for (let frameElement of currentParentWindow.document.getElementsByTagName('iframe')) {
if (!frameElement.contentWindow) return null;
if (frameElement.contentWindow === currentWindow) {
Expand All @@ -385,7 +385,7 @@ export function newNativeAssetManager(win, nativeTag) {
if (!isSafeFrame(window)) {
let iframeContainer = getCurrentFrameContainer(win);
if (iframeContainer && iframeContainer.children && iframeContainer.children[0]) {
const iframe = iframeContainer.children[0];
const iframe = iframeContainer.children[0];
if (iframe.width === '1' && iframe.height === '1') {
let width = iframeContainer.getBoundingClientRect().width;
win.document.body.style.width = `${width}px`;
Expand All @@ -400,7 +400,8 @@ export function newNativeAssetManager(win, nativeTag) {
callback && callback();
win.removeEventListener('message', replaceAssets);
stopListening();
requestHeightResize(bid.adId, (document.body.clientHeight || document.body.offsetHeight), document.body.clientWidth);
const resize = () => requestHeightResize(bid.adId, (document.body.clientHeight || document.body.offsetHeight), document.body.clientWidth);
document.readyState === 'complete' ? resize() : window.onload = resize;

if (typeof window.postRenderAd === 'function') {
window.postRenderAd(bid);
Expand Down Expand Up @@ -441,7 +442,7 @@ export function newNativeAssetManager(win, nativeTag) {
if (ortb.link) {
html = html.replaceAll("##hb_native_linkurl##", ortb.link.url);
}

return html;
}

Expand Down

0 comments on commit 5e8a24f

Please sign in to comment.