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

Method setup

src/service/fixed-layer.js:150–206  ·  view source on GitHub ↗

* Must be always called after DOMReady. * @return {boolean}

()

Source from the content-addressed store, hash-verified

148 * @return {boolean}
149 */
150 setup() {
151 const viewer = Services.viewerForDoc(this.ampdoc);
152 if (!getMode().localDev && !viewer.isEmbedded()) {
153 // FixedLayer is not needed for standalone documents.
154 return false;
155 }
156
157 const root = this.ampdoc.getRootNode();
158 const stylesheets = root.styleSheets;
159 if (!stylesheets) {
160 return true;
161 }
162
163 this.fixedSelectors_.length = 0;
164 this.stickySelectors_.length = 0;
165
166 for (let i = 0; i < stylesheets.length; i++) {
167 const stylesheet = stylesheets[i];
168 // Rare but may happen if the document is being concurrently disposed.
169 if (!stylesheet) {
170 dev().error(TAG, 'Aborting setup due to null stylesheet.');
171 return true;
172 }
173 const {disabled, ownerNode} = stylesheet;
174 if (
175 disabled ||
176 !ownerNode ||
177 ownerNode.tagName != 'STYLE' ||
178 ownerNode.hasAttribute('amp-boilerplate') ||
179 ownerNode.hasAttribute('amp-runtime') ||
180 ownerNode.hasAttribute('amp-extension')
181 ) {
182 continue;
183 }
184 // Don't dereference cssRules early to avoid "Cannot access rules"
185 // DOMException due to reading a CORS stylesheet e.g. font.
186 this.discoverSelectors_(stylesheet.cssRules);
187 }
188
189 this.scanNode_(root);
190
191 if (this.elements_.length > 0) {
192 this.observeHiddenMutations();
193 }
194
195 const platform = Services.platformFor(this.ampdoc.win);
196 if (this.elements_.length > 0 && !this.transfer_ && platform.isIos()) {
197 user().warn(
198 TAG,
199 'Please test this page inside of an AMP Viewer such' +
200 " as Google's because the fixed or sticky positioning might have" +
201 ' slightly different layout.'
202 );
203 }
204
205 return true;
206 }
207

Callers 1

createFixedLayerMethod · 0.45

Calls 11

discoverSelectors_Method · 0.95
scanNode_Method · 0.95
getModeFunction · 0.90
devFunction · 0.90
userFunction · 0.90
isIosMethod · 0.80
warnMethod · 0.80
isEmbeddedMethod · 0.45
getRootNodeMethod · 0.45
errorMethod · 0.45

Tested by

no test coverage detected