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

Method connectedCallback

src/custom-element.js:1148–1226  ·  view source on GitHub ↗

* Called when the element is first connected to the DOM. * * This callback is guarded by checks to see if the element is still * connected. Chrome and Safari can trigger connectedCallback even when * the node is disconnected. See #12849, https://crbug.com/821195, and * http

()

Source from the content-addressed store, hash-verified

1146 * @final
1147 */
1148 connectedCallback() {
1149 if (!isTemplateTagSupported() && this.isInTemplate_ === undefined) {
1150 this.isInTemplate_ = !!query.closestAncestorElementBySelector(
1151 this,
1152 'template'
1153 );
1154 }
1155 if (this.isInTemplate_) {
1156 return;
1157 }
1158
1159 if (this.isConnected_ || !dom.isConnectedNode(this)) {
1160 return;
1161 }
1162 this.isConnected_ = true;
1163
1164 if (!this.everAttached) {
1165 this.classList.add(
1166 'i-amphtml-element',
1167 'i-amphtml-notbuilt',
1168 'amp-notbuilt'
1169 );
1170 }
1171
1172 if (!this.ampdoc_) {
1173 // Ampdoc can now be initialized.
1174 const win = getWin(this);
1175 const ampdocService = Services.ampdocServiceFor(win);
1176 const ampdoc = ampdocService.getAmpDoc(this);
1177 this.ampdoc_ = ampdoc;
1178 elementConnectedCallback(ampdoc, this, this.implClass_);
1179 }
1180 if (!this.resources_) {
1181 // Resources can now be initialized since the ampdoc is now available.
1182 this.resources_ = Services.resourcesForDoc(this.ampdoc_);
1183 }
1184 this.getResources().add(this);
1185
1186 if (this.everAttached) {
1187 const reconstruct = this.reconstructWhenReparented();
1188 if (reconstruct) {
1189 this.reset_();
1190 }
1191 if (this.isUpgraded()) {
1192 if (reconstruct && !this.R1()) {
1193 this.getResources().upgraded(this);
1194 }
1195 this.connected_();
1196 this.dispatchCustomEventForTesting(AmpEvents_Enum.ATTACHED);
1197 }
1198 if (this.implClass_ && this.R1()) {
1199 this.upgradeOrSchedule_();
1200 }
1201 } else {
1202 this.everAttached = true;
1203
1204 try {
1205 this.layout_ = applyStaticLayout(this);

Callers

nothing calls this directly

Calls 15

getResourcesMethod · 0.95
reset_Method · 0.95
isUpgradedMethod · 0.95
R1Method · 0.95
connected_Method · 0.95
upgradeOrSchedule_Method · 0.95
initMediaAttrs_Method · 0.95
markUnresolvedMethod · 0.95
toggleLoadingMethod · 0.95
getWinFunction · 0.90

Tested by

no test coverage detected