This commit is contained in:
106
src/docgen/static/script.js
Normal file
106
src/docgen/static/script.js
Normal file
@@ -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, '');
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user