diff --git a/assets/js/sections/common.js b/assets/js/sections/common.js index ec30538d6..a0715ca28 100644 --- a/assets/js/sections/common.js +++ b/assets/js/sections/common.js @@ -1377,6 +1377,24 @@ function showToast(title, text, type = 'bg-success text-white', delay = 3000) { toastEl.addEventListener('hidden.bs.toast', () => toastEl.remove()); } +function hexToRgba(hex, alpha = 1) { + if (!hex) return null; + // Remove the leading "#" + hex = hex.replace(/^#/, ''); + + // Expand short form (#f0a → #ff00aa) + if (hex.length === 3) { + hex = hex.split('').map(c => c + c).join(''); + } + + const num = parseInt(hex, 16); + const r = (num >> 16) & 255; + const g = (num >> 8) & 255; + const b = num & 255; + + return `rgba(${r}, ${g}, ${b}, ${alpha})`; +} + /** * Cookie Management Utilities */