From 5b3c889b7cd3c54b46bef6cabffc3522aac43610 Mon Sep 17 00:00:00 2001 From: Abdulrehman-Jafer <121712508+Abdulrehman-Jafer@users.noreply.github.com> Date: Thu, 23 Mar 2023 17:03:23 +0500 Subject: [PATCH] web: migrate css.js to typescript (#2165) Signed-off-by: Abdulrehman-Jafer --- apps/web/src/utils/{css.js => css.ts} | 36 +++++++++++++-------------- 1 file changed, 18 insertions(+), 18 deletions(-) rename apps/web/src/utils/{css.js => css.ts} (60%) diff --git a/apps/web/src/utils/css.js b/apps/web/src/utils/css.ts similarity index 60% rename from apps/web/src/utils/css.js rename to apps/web/src/utils/css.ts index 241c77d9d..7e11fe7dc 100644 --- a/apps/web/src/utils/css.js +++ b/apps/web/src/utils/css.ts @@ -17,14 +17,16 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ -export function removeCss(id) { - var link = document.getElementById(id); - link.remove(); +export function removeCss(id: string) { + const link = document.getElementById(id); + if(link){ + link.remove(); + } } -export function injectCssSrc(id, src) { - var head = document.head; - var link = document.createElement("link"); +export function injectCssSrc(id: string, src: string) { + const head = document.head; + const link = document.createElement("link"); link.id = id; link.type = "text/css"; @@ -34,32 +36,30 @@ export function injectCssSrc(id, src) { head.appendChild(link); } -export function injectCss(rule) { - let variableCss = document.getElementById("variables"); - let head = document.getElementsByTagName("head")[0]; +export function injectCss(rule: string) { + const variableCss = document.getElementById("variables"); + const head = document.getElementsByTagName("head")[0]; if (variableCss) { head.removeChild(variableCss); } - let css = document.createElement("style"); + const css = document.createElement("style"); css.type = "text/css"; css.id = "variables"; - // Support for IE - if (css.styleSheet) css.styleSheet.cssText = rule; - // Support for the rest - else css.appendChild(document.createTextNode(rule)); + css.appendChild(document.createTextNode(rule)); head.insertBefore(css, getRootStylesheet()); } function getRootStylesheet() { - for (let sty of document.getElementsByTagName("style")) { + for (const sty of document.getElementsByTagName("style")) { if (sty.innerHTML.includes("#root")) { return sty; } } + return null; } -export function changeSvgTheme(newAccent) { - var nodes = document.querySelectorAll('*[fill="#0560ff"]'); - for (var n = 0; n < nodes.length; ++n) +export function changeSvgTheme(newAccent: string) { + const nodes = document.querySelectorAll('*[fill="#0560ff"]'); + for (let n = 0; n < nodes.length; ++n) nodes[n].setAttribute("fill", newAccent); }