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

Method inViewport_

src/service/loading-indicator.js:79–102  ·  view source on GitHub ↗

* @param {!IntersectionObserverEntry} record * @private

(record)

Source from the content-addressed store, hash-verified

77 * @private
78 */
79 inViewport_(record) {
80 const {boundingClientRect, isIntersecting, target} = record;
81 const {height, width} = boundingClientRect;
82 const element = /** @type {!AmpElement} */ (target);
83
84 const show = isIntersecting && width > MIN_SIZE && height > MIN_SIZE;
85
86 let state = this.states_.get(element);
87 const isCurrentlyShown = (state && state.shown) || false;
88 if (show === isCurrentlyShown) {
89 // Loading state is the same.
90 return;
91 }
92
93 if (show && !state) {
94 state = this.createLoaderState_(element, width, height);
95 this.states_.set(element, state);
96 }
97 if (state) {
98 state.shown = show;
99 state.container.classList.toggle('amp-hidden', !show);
100 state.loader.classList.toggle('amp-active', show);
101 }
102 }
103
104 /**
105 * @param {!AmpElement} element

Callers

nothing calls this directly

Calls 4

createLoaderState_Method · 0.95
getMethod · 0.45
setMethod · 0.45
toggleMethod · 0.45

Tested by

no test coverage detected