MCPcopy Index your code
hub / github.com/ampproject/amphtml / getTargetRect

Method getTargetRect

ads/inabox/position-observer.js:117–141  ·  view source on GitHub ↗

* Get the element's layout rect relative to the viewport. Attempt to walk up * the DOM and add the offset of all nested parent iframes since * getBoundingClientRect() is only relative to the immediate window. Assumes * that all parent frames are friendly and can be inspected (because the

(element)

Source from the content-addressed store, hash-verified

115 * @return {!LayoutRectDef}
116 */
117 getTargetRect(element) {
118 let targetRect = layoutRectFromDomRect(
119 element./*OK*/ getBoundingClientRect()
120 );
121 const parentWin = element.ownerDocument.defaultView;
122 for (
123 let j = 0, tempWin = parentWin;
124 j < 10 &&
125 // win can be null if the ad iframe is already destroyed
126 tempWin &&
127 tempWin != this.win_ &&
128 tempWin != this.win_.top;
129 j++, tempWin = tempWin.parent
130 ) {
131 const parentFrameRect = layoutRectFromDomRect(
132 tempWin.frameElement./*OK*/ getBoundingClientRect()
133 );
134 targetRect = moveLayoutRect(
135 targetRect,
136 parentFrameRect.left,
137 parentFrameRect.top
138 );
139 }
140 return targetRect;
141 }
142}
143
144/**

Callers 4

getPositionEntry_Method · 0.95
handleSendPositions_Method · 0.80

Calls 2

layoutRectFromDomRectFunction · 0.90
moveLayoutRectFunction · 0.90

Tested by

no test coverage detected