* Called when an element is disconnected from DOM, or when an ampDoc is * being disconnected (the element itself may still be connected to ampDoc). * * This callback is guarded by checks to see if the element is still * connected. See #12849, https://crbug.com/821195, and *
(pretendDisconnected)
| 1374 | * of DOM isConnected. |
| 1375 | */ |
| 1376 | disconnect(pretendDisconnected) { |
| 1377 | if (this.isInTemplate_ || !this.isConnected_) { |
| 1378 | return; |
| 1379 | } |
| 1380 | if (!pretendDisconnected && dom.isConnectedNode(this)) { |
| 1381 | return; |
| 1382 | } |
| 1383 | |
| 1384 | // This path only comes from Resource#disconnect, which deletes the |
| 1385 | // Resource instance tied to this element. Therefore, it is no longer |
| 1386 | // an AMP Element. But, DOM queries for i-amphtml-element assume that |
| 1387 | // the element is tied to a Resource. |
| 1388 | if (pretendDisconnected) { |
| 1389 | this.classList.remove('i-amphtml-element'); |
| 1390 | } |
| 1391 | |
| 1392 | this.isConnected_ = false; |
| 1393 | this.getResources().remove(this); |
| 1394 | if (this.impl_) { |
| 1395 | this.impl_.detachedCallback(); |
| 1396 | } |
| 1397 | if (this.R1()) { |
| 1398 | this.unmount(); |
| 1399 | } |
| 1400 | this.toggleLoading(false); |
| 1401 | this.disposeMediaAttrs_(); |
| 1402 | } |
| 1403 | |
| 1404 | /** |
| 1405 | * Dispatches a custom event only in testing environment. |
no test coverage detected