Skip to content

Commit

Permalink
AdagioRtdProvider: move safeFrame related code inside Core utils.js
Browse files Browse the repository at this point in the history
  • Loading branch information
osazos committed Jun 12, 2024
1 parent abd00fa commit 61fbec9
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 12 deletions.
21 changes: 9 additions & 12 deletions modules/adagioRtdProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
deepAccess,
deepSetValue,
generateUUID,
getSafeframeGeometry,
getUniqueIdentifierStr,
getWindowSelf,
getWindowTop,
Expand Down Expand Up @@ -429,16 +430,14 @@ function getSlotPosition(adUnit) {
const position = { x: 0, y: 0 };

if (isSafeFrameWindow()) {
const ws = getWindowSelf();
const { self } = getSafeframeGeometry() || {};

const sfGeom = (typeof ws.$sf.ext.geom === 'function') ? ws.$sf.ext.geom() : null;

if (!sfGeom || !sfGeom.self) {
if (!self) {
return '';
}

position.x = Math.round(sfGeom.self.t);
position.y = Math.round(sfGeom.self.l);
position.x = Math.round(self.t);
position.y = Math.round(self.l);
} else {
try {
// window.top based computing
Expand Down Expand Up @@ -514,16 +513,14 @@ function getViewPortDimensions() {
const viewportDims = { w: 0, h: 0 };

if (isSafeFrameWindow()) {
const ws = getWindowSelf();

const sfGeom = (typeof ws.$sf.ext.geom === 'function') ? ws.$sf.ext.geom() : null;
const { win } = getSafeframeGeometry() || {};

if (!sfGeom || !sfGeom.win) {
if (!win) {
return '';
}

viewportDims.w = Math.round(sfGeom.win.w);
viewportDims.h = Math.round(sfGeom.win.h);
viewportDims.w = Math.round(win.w);
viewportDims.h = Math.round(win.h);
} else {
// window.top based computing
const wt = getWindowTop();
Expand Down
15 changes: 15 additions & 0 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -661,6 +661,21 @@ export function isSafeFrameWindow() {
return !!(ws.$sf && ws.$sf.ext);
}

/**
* Returns the result of calling the function $sf.ext.geom() if it exists
* @see https://iabtechlab.com/wp-content/uploads/2016/03/SafeFrames_v1.1_final.pdf — 5.4 Function $sf.ext.geom
* @returns {Object | undefined} geometric information about the container
*/
export function getSafeframeGeometry() {
try {
const ws = getWindowSelf();
return (typeof ws.$sf.ext.geom === 'function') ? ws.$sf.ext.geom() : undefined;
} catch (e) {
logError('Error getting SafeFrame geometry', e);
return undefined;
}
}

export function isSafariBrowser() {
return /^((?!chrome|android|crios|fxios).)*safari/i.test(navigator.userAgent);
}
Expand Down

0 comments on commit 61fbec9

Please sign in to comment.