MCPcopy
hub / github.com/ashutosh1919/masterPortfolio / replaceForPosition

Function replaceForPosition

src/assets/font-awesome/js/all.js:13531–13631  ·  view source on GitHub ↗
(node, position)

Source from the content-addressed store, hash-verified

13529 }
13530
13531 function replaceForPosition(node, position) {
13532 var pendingAttribute = ""
13533 .concat(DATA_FA_PSEUDO_ELEMENT_PENDING)
13534 .concat(position.replace(":", "-"));
13535 return new picked(function (resolve, reject) {
13536 if (node.getAttribute(pendingAttribute) !== null) {
13537 // This node is already being processed
13538 return resolve();
13539 }
13540
13541 var children = toArray(node.children);
13542 var alreadyProcessedPseudoElement = children.filter(function (c) {
13543 return c.getAttribute(DATA_FA_PSEUDO_ELEMENT) === position;
13544 })[0];
13545 var styles = WINDOW.getComputedStyle(node, position);
13546 var fontFamily = styles
13547 .getPropertyValue("font-family")
13548 .match(FONT_FAMILY_PATTERN);
13549 var fontWeight = styles.getPropertyValue("font-weight");
13550
13551 if (alreadyProcessedPseudoElement && !fontFamily) {
13552 // If we've already processed it but the current computed style does not result in a font-family,
13553 // that probably means that a class name that was previously present to make the icon has been
13554 // removed. So we now should delete the icon.
13555 node.removeChild(alreadyProcessedPseudoElement);
13556 return resolve();
13557 } else if (fontFamily) {
13558 var content = styles.getPropertyValue("content");
13559 var prefix = ~[
13560 "Solid",
13561 "Regular",
13562 "Light",
13563 "Duotone",
13564 "Brands",
13565 ].indexOf(fontFamily[1])
13566 ? STYLE_TO_PREFIX[fontFamily[1].toLowerCase()]
13567 : FONT_WEIGHT_TO_PREFIX[fontWeight];
13568 var hexValue = toHex(
13569 content.length === 3 ? content.substr(1, 1) : content
13570 );
13571 var iconName = byUnicode(prefix, hexValue);
13572 var iconIdentifier = iconName; // Only convert the pseudo element in this :before/:after position into an icon if we haven't
13573 // already done so with the same prefix and iconName
13574
13575 if (
13576 iconName &&
13577 (!alreadyProcessedPseudoElement ||
13578 alreadyProcessedPseudoElement.getAttribute(DATA_PREFIX) !==
13579 prefix ||
13580 alreadyProcessedPseudoElement.getAttribute(DATA_ICON) !==
13581 iconIdentifier)
13582 ) {
13583 node.setAttribute(pendingAttribute, iconIdentifier);
13584
13585 if (alreadyProcessedPseudoElement) {
13586 // Delete the old one, since we're replacing it with a new one
13587 node.removeChild(alreadyProcessedPseudoElement);
13588 }

Callers 1

replaceFunction · 0.70

Calls 10

resolveFunction · 0.70
toArrayFunction · 0.70
toHexFunction · 0.70
byUnicodeFunction · 0.70
blankMetaFunction · 0.70
findIconFunction · 0.70
makeInlineSvgAbstractFunction · 0.70
_objectSpreadFunction · 0.70
emptyCanonicalIconFunction · 0.70
toHtmlFunction · 0.70

Tested by

no test coverage detected