Skip to content

Commit

Permalink
Javascript back utils/dom
Browse files Browse the repository at this point in the history
  • Loading branch information
nanaya committed Feb 29, 2024
1 parent a26a92c commit 3c9aa70
Showing 1 changed file with 22 additions and 13 deletions.
35 changes: 22 additions & 13 deletions app/javascript/src/utils/dom.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,26 @@
export escapeHtml = (str) -> str.replace(/[&<>"']/g, (str) => ({
'&': '&amp;',
'<': '&lt;',
'>': '&gt;',
'"': '&quot;',
"'": '&#39;',
})[str])
export function escapeHtml (str) {
return str.replace(/[&<>"']/g, function (str) {
return {
'&': '&amp;',
'<': '&lt;',
'>': '&gt;',
'"': '&quot;',
"'": '&#39;'
}[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;
}

0 comments on commit 3c9aa70

Please sign in to comment.