MCPcopy
hub / github.com/ampproject/amphtml / constructor

Method constructor

src/utils/display-observer.js:106–158  ·  view source on GitHub ↗

* @param {!AmpDoc} ampdoc

(ampdoc)

Source from the content-addressed store, hash-verified

104 * @param {!AmpDoc} ampdoc
105 */
106 constructor(ampdoc) {
107 /** @private @const */
108 this.ampdoc_ = ampdoc;
109
110 const {win} = ampdoc;
111 const body = ampdoc.getBody();
112
113 this.observed_ = this.observed_.bind(this);
114 this.containerObserved_ = this.containerObserved_.bind(this);
115
116 /** @private @const {!Array<!ObserverDef>} */
117 this.observers_ = [];
118
119 // Viewport observer is only needed because `position:fixed` elements
120 // are not observable by a documentElement or body's root.
121 this.observers_.push({
122 container: null,
123 root: null,
124 contains: () => true,
125 io: new win.IntersectionObserver(this.observed_, {
126 threshold: DISPLAY_THRESHOLD,
127 }),
128 });
129
130 // Body observer: very close to `display:none` observer.
131 this.observers_.push({
132 container: body,
133 root: body,
134 contains: () => true,
135 io: new win.IntersectionObserver(this.observed_, {
136 root: body,
137 threshold: DISPLAY_THRESHOLD,
138 }),
139 });
140
141 /** @private {boolean} */
142 this.isDocDisplay_ = computeDocIsDisplayed(ampdoc.getVisibilityState());
143
144 /** @private {?UnlistenDef} */
145 this.visibilityUnlisten_ = ampdoc.onVisibilityChanged(() => {
146 const display = computeDocIsDisplayed(ampdoc.getVisibilityState());
147 if (display !== this.isDocDisplay_) {
148 this.isDocDisplay_ = display;
149 this.docVisibilityChanged_();
150 }
151 });
152
153 /** @private @const {!Map<!Element, !Array<!ObserverCallbackDef>>} */
154 this.targetObserverCallbacks_ = new Map();
155
156 /** @private @const {!Map<!Element, !Array<boolean>>} */
157 this.targetObservations_ = new Map();
158 }
159
160 /** @override */
161 dispose() {

Callers

nothing calls this directly

Calls 6

docVisibilityChanged_Method · 0.95
computeDocIsDisplayedFunction · 0.85
getBodyMethod · 0.45
pushMethod · 0.45
getVisibilityStateMethod · 0.45
onVisibilityChangedMethod · 0.45

Tested by

no test coverage detected