MCPcopy Create free account
hub / github.com/ampproject/amphtml / getElementType

Function getElementType

src/service/performance-impl.js:66–91  ·  view source on GitHub ↗

* @param {?Node} node * @return {ELEMENT_TYPE_ENUM}

(node)

Source from the content-addressed store, hash-verified

64 * @return {ELEMENT_TYPE_ENUM}
65 */
66function getElementType(node) {
67 if (node == null) {
68 return ELEMENT_TYPE_ENUM.other;
69 }
70 const outer = getOutermostAmpElement(node);
71 const {nodeName} = outer;
72 if (nodeName === 'IMG' || nodeName === 'AMP-IMG') {
73 return ELEMENT_TYPE_ENUM.image;
74 }
75 if (nodeName === 'VIDEO' || nodeName === 'AMP-VIDEO') {
76 return ELEMENT_TYPE_ENUM.video;
77 }
78 if (nodeName === 'AMP-CAROUSEL') {
79 return ELEMENT_TYPE_ENUM.carousel;
80 }
81 if (nodeName === 'AMP-BASE-CAROUSEL') {
82 return ELEMENT_TYPE_ENUM.bcarousel;
83 }
84 if (nodeName === 'AMP-AD') {
85 return ELEMENT_TYPE_ENUM.ad;
86 }
87 if (!nodeName.startsWith('AMP-') && outer.textContent) {
88 return ELEMENT_TYPE_ENUM.text;
89 }
90 return ELEMENT_TYPE_ENUM.other;
91}
92
93/**
94 * Performance holds the mechanism to call `tick` to stamp out important

Callers 2

Calls 1

getOutermostAmpElementFunction · 0.85

Tested by

no test coverage detected