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

Function srcsetFromElement

src/core/dom/srcset.js:24–39  ·  view source on GitHub ↗
(element)

Source from the content-addressed store, hash-verified

22 * @return {Srcset<SrcsetSourceDef>}
23 */
24export function srcsetFromElement(element) {
25 const srcsetAttr = element.getAttribute('srcset');
26 if (srcsetAttr) {
27 return parseSrcset(srcsetAttr);
28 }
29 // We can't push `src` via `parseSrcset` because URLs in `src` are not always
30 // RFC compliant and can't be easily parsed as an `srcset`. For instance,
31 // they sometimes contain space characters.
32 const srcAttr = element.getAttribute('src');
33 userAssert(
34 srcAttr,
35 'Either non-empty "srcset" or "src" attribute must be specified: %s',
36 element
37 );
38 return srcsetFromSrc(srcAttr);
39}
40
41/**
42 * Creates a Srcset from a `src` attribute value.

Callers 6

testFunction · 0.90
test-srcset.jsFile · 0.90
initMethod · 0.90
init_Method · 0.90
getThumbnailSrcset_Method · 0.90

Calls 4

userAssertFunction · 0.90
parseSrcsetFunction · 0.85
srcsetFromSrcFunction · 0.85
getAttributeMethod · 0.80

Tested by 1

testFunction · 0.72