Skip to content
This repository has been archived by the owner on Dec 23, 2021. It is now read-only.

Commit

Permalink
Reformat svg utils
Browse files Browse the repository at this point in the history
  • Loading branch information
xnkevinnguyen committed Feb 12, 2020
1 parent 06f7555 commit 5e9c90d
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions src/view/components/cpx/Svg_utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,20 @@

// Adapted from : https://github.com/microsoft/pxt/blob/master/pxtsim/svg.ts

// tslint:disable-next-line: no-namespace
namespace svg {
export function addClass(el: SVGElement, cls: string) {
if (el.classList) { el.classList.add(cls); }
else if (el.className.baseVal.indexOf(cls) < 0) {
if (el.classList) {
el.classList.add(cls);
} else if (el.className.baseVal.indexOf(cls) < 0) {
el.className.baseVal += " " + cls;
}
}
}

export function removeClass(el: SVGElement, cls: string) {
if (el.classList) { el.classList.remove(cls); }
else {
if (el.classList) {
el.classList.remove(cls);
} else {
el.className.baseVal = el.className.baseVal
.replace(cls, "")
.replace(/\s{2,}/, " ");
Expand All @@ -24,7 +27,9 @@ namespace svg {
for (const k in props) {
if (k == "title") {
svg.title(el, props[k]);
} else { el.setAttributeNS(null, k, props[k]); }
} else {
el.setAttributeNS(null, k, props[k]);
}
}
}

Expand All @@ -33,7 +38,9 @@ namespace svg {
"http://www.w3.org/2000/svg",
name
);
if (props) { svg.hydrate(newElement, props); }
if (props) {
svg.hydrate(newElement, props);
}
return newElement;
}

Expand Down

0 comments on commit 5e9c90d

Please sign in to comment.