From 3c9aa7042e473f1ed7c76d966e4b2f5c7911b51a Mon Sep 17 00:00:00 2001 From: nanaya Date: Fri, 1 Mar 2024 00:31:59 +0900 Subject: [PATCH] Javascript back utils/dom --- app/javascript/src/utils/dom.js | 35 +++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/app/javascript/src/utils/dom.js b/app/javascript/src/utils/dom.js index 9670fbd07..276025ec8 100644 --- a/app/javascript/src/utils/dom.js +++ b/app/javascript/src/utils/dom.js @@ -1,17 +1,26 @@ -export escapeHtml = (str) -> str.replace(/[&<>"']/g, (str) => ({ - '&': '&', - '<': '<', - '>': '>', - '"': '"', - "'": ''', -})[str]) +export function escapeHtml (str) { + return str.replace(/[&<>"']/g, function (str) { + return { + '&': '&', + '<': '<', + '>': '>', + '"': '"', + "'": ''' + }[str]; + }); +} -export hideEl = (el) -> el.style.display = 'none' +export function hideEl (el) { + el.style.display = 'none'; +} -export showEl = (el) -> el.style.display = '' +export function showEl (el) { + el.style.display = ''; +} -export stringToDom = (str) -> - container = document.createElement('div') - container.innerHTML = str +export function stringToDom (str) { + const container = document.createElement('div'); + container.innerHTML = str; - container.firstChild + return container.firstChild; +}