From 9685309b09792239af41e4a53939b6b70c7e7052 Mon Sep 17 00:00:00 2001 From: 7000pctAUTO Date: Sat, 31 Jan 2026 17:13:43 +0000 Subject: [PATCH] Add static files (CSS, JS) --- src/docgen/static/script.js | 106 ++++++++++++++++++++++++++++++++++++ 1 file changed, 106 insertions(+) create mode 100644 src/docgen/static/script.js diff --git a/src/docgen/static/script.js b/src/docgen/static/script.js new file mode 100644 index 0000000..7a52d8e --- /dev/null +++ b/src/docgen/static/script.js @@ -0,0 +1,106 @@ +document.addEventListener('DOMContentLoaded', function() { + initializeNavigation(); + initializeEndpointCards(); + initializeSearch(); +}); + +function initializeNavigation() { + const navGroups = document.querySelectorAll('.nav-group'); + navGroups.forEach(group => { + group.classList.add('collapsed'); + }); +} + +function toggleNavGroup(button) { + const group = button.closest('.nav-group'); + group.classList.toggle('collapsed'); +} + +function initializeEndpointCards() { + const cards = document.querySelectorAll('.endpoint-card'); + cards.forEach((card, index) => { + card.dataset.index = index; + }); +} + +function toggleEndpoint(header) { + const card = header.closest('.endpoint-card'); + card.classList.toggle('expanded'); +} + +function initializeSearch() { + const searchInput = document.getElementById('nav-search'); + if (searchInput) { + searchInput.addEventListener('input', function() { + filterNav(this.value); + }); + } +} + +function filterNav(query) { + const lowerQuery = query.toLowerCase(); + const navItems = document.querySelectorAll('.nav-item'); + const navGroups = document.querySelectorAll('.nav-group'); + + navItems.forEach(item => { + const pathEl = item.querySelector('.nav-path'); + const method = item.querySelector('.nav-method'); + if (pathEl && method) { + const text = (pathEl.textContent + ' ' + method.textContent).toLowerCase(); + item.style.display = text.includes(lowerQuery) ? '' : 'none'; + } + }); + + navGroups.forEach(group => { + const visibleItems = group.querySelectorAll('.nav-item:not([style*="display: none"])'); + const items = group.querySelector('.nav-group-items'); + if (items) { + items.style.display = visibleItems.length > 0 ? 'block' : 'none'; + } + }); +} + +function scrollToEndpoint(event, endpointId) { + event.preventDefault(); + const target = document.getElementById('endpoint-' + endpointId); + if (target) { + target.scrollIntoView({ behavior: 'smooth', block: 'center' }); + target.classList.add('highlighted'); + setTimeout(() => target.classList.remove('highlighted'), 2000); + } +} + +function generateCurl(event, method, path) { + event.stopPropagation(); + + let curl = `curl -X ${method} "http://localhost:8080${path}"`; + + const output = event.target.closest('.curl-generator').querySelector('.curl-output'); + const code = output.querySelector('code'); + const copyBtn = event.target.closest('.curl-generator').querySelector('.copy-curl-btn'); + + code.textContent = curl; + output.classList.add('visible'); + copyBtn.style.display = 'inline-block'; +} + +function copyCurl(event) { + event.stopPropagation(); + + const code = event.target.closest('.curl-generator').querySelector('.curl-output code'); + if (code) { + navigator.clipboard.writeText(code.textContent).then(() => { + const originalText = event.target.textContent; + event.target.textContent = 'Copied!'; + setTimeout(() => { + event.target.textContent = originalText; + }, 2000); + }); + } +} + +String.prototype.slugify = function() { + return this.toLowerCase() + .replace(/[^a-z0-9]+/g, '-') + .replace(/(^-|-$)/g, ''); +};