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

Method toggleFallback

src/custom-element.js:1972–1999  ·  view source on GitHub ↗

* Hides or shows the fallback, if available. This function must only * be called inside a mutate context. * @param {boolean} show * @package @final

(show)

Source from the content-addressed store, hash-verified

1970 * @package @final
1971 */
1972 toggleFallback(show) {
1973 assertNotTemplate(this);
1974 const resourceState = this.getResource_().getState();
1975 // Do not show fallback before layout
1976 if (
1977 !this.R1() &&
1978 show &&
1979 (resourceState == ResourceState_Enum.NOT_BUILT ||
1980 resourceState == ResourceState_Enum.NOT_LAID_OUT ||
1981 resourceState == ResourceState_Enum.READY_FOR_LAYOUT)
1982 ) {
1983 return;
1984 }
1985 // This implementation is notably less efficient then placeholder
1986 // toggling. The reasons for this are: (a) "not supported" is the state of
1987 // the whole element, (b) some relayout is expected and (c) fallback
1988 // condition would be rare.
1989 this.classList.toggle('amp-notsupported', show);
1990 if (show == true) {
1991 const fallbackElement = this.getFallback();
1992 if (fallbackElement) {
1993 Services.ownersForDoc(this.getAmpDoc()).scheduleLayout(
1994 this,
1995 fallbackElement
1996 );
1997 }
1998 }
1999 }
2000
2001 /**
2002 * An implementation can call this method to signal to the element that

Callers

nothing calls this directly

Calls 8

getResource_Method · 0.95
R1Method · 0.95
getFallbackMethod · 0.95
getAmpDocMethod · 0.95
assertNotTemplateFunction · 0.85
getStateMethod · 0.45
toggleMethod · 0.45
scheduleLayoutMethod · 0.45

Tested by

no test coverage detected