aboutsummaryrefslogtreecommitdiff
path: root/client/public/stuff.ts
diff options
context:
space:
mode:
authorGravatar Moon Flower <mforoud86@gmail.com> 2026-02-27 23:37:44 +0330
committerGravatar Moon Flower <mforoud86@gmail.com> 2026-02-27 23:37:44 +0330
commit8ee3112ca09fd70a50c2159629b40700beb2d5c3 (patch)
tree42a8d3e5d7898e9d084f77e1345be270be0f5969 /client/public/stuff.ts
parentsmall check (diff)
first client ver
Diffstat (limited to 'client/public/stuff.ts')
-rw-r--r--client/public/stuff.ts58
1 files changed, 58 insertions, 0 deletions
diff --git a/client/public/stuff.ts b/client/public/stuff.ts
new file mode 100644
index 0000000..5d7e882
--- /dev/null
+++ b/client/public/stuff.ts
@@ -0,0 +1,58 @@
+export const sidebar = document.getElementById('sidebar')!
+export const backdrop = document.getElementById('sidebar-backdrop')!
+export const toggle = document.getElementById('sidebar-toggle')!
+export const close = document.getElementById('sidebar-close')!
+
+export const openSidebar = () => {
+ sidebar.classList.add('open')
+ backdrop.classList.add('open')
+ toggle.setAttribute('aria-expanded', 'true')
+ document.body.style.overflow = 'hidden'
+}
+export const closeSidebar = () => {
+ sidebar.classList.remove('open')
+ backdrop.classList.remove('open')
+ toggle.setAttribute('aria-expanded', 'false')
+ document.body.style.overflow = ''
+}
+
+toggle.addEventListener('click', () => sidebar.classList.contains('open') ? closeSidebar() : openSidebar())
+close.addEventListener('click', closeSidebar)
+backdrop.addEventListener('click', closeSidebar)
+document.addEventListener('keydown', e => { if (e.key === 'Escape') closeSidebar() })
+window.addEventListener('resize', () => { if (window.innerWidth > 680) closeSidebar() })
+
+document.querySelectorAll('s-item').forEach(item => {
+ item.addEventListener('click', function () {
+ document.querySelectorAll('s-item').forEach(i => i.removeAttribute('active'))
+ //@ts-expect-error
+ this.setAttribute('active', '')
+ if (window.innerWidth <= 680) closeSidebar()
+ })
+})
+
+export const showModal = () => {
+ document.getElementById('modal-backdrop')!.classList.add('modal-open')
+ document.getElementById('modal-el')!.focus()
+}
+export const hideModal = () => { document.getElementById('modal-backdrop')!.classList.remove('modal-open') }
+export const setModalHTML = (html: string) => {
+ document.getElementById('modal-el')!.innerHTML = html
+ showModal()
+}
+export const getModal = () => document.getElementById('modal-el')
+
+// document.getElementById('modal-backdrop')!.addEventListener('click', e => { if (e.target === document.getElementById('modal-backdrop')) hideModal() })
+
+export const createPillHTML = (label: string, html: string, fullWidth = false) =>
+ `<pill${fullWidth ? ' full' : ''}><p>${label}</p><elm>${html}</elm></pill>`
+
+document.addEventListener('DOMContentLoaded', () => {
+ document.querySelectorAll('input[type="range"]').forEach(slider => {
+ const valEl = slider.parentElement?.querySelector('val')
+ if (valEl) {
+ valEl.textContent = (slider as any).value
+ slider.addEventListener('input', () => valEl.textContent = (slider as any).value)
+ }
+ })
+}) \ No newline at end of file