wip
This commit is contained in:
parent
5473beb35d
commit
22a800e5e6
7 changed files with 271 additions and 111 deletions
56
app/static/js/utils.js
Normal file
56
app/static/js/utils.js
Normal file
|
@ -0,0 +1,56 @@
|
|||
/**
|
||||
* Utility functions for Vim Docs application
|
||||
*/
|
||||
|
||||
// Debounce function to limit how often a function can run
|
||||
function debounce(func, wait) {
|
||||
let timeout;
|
||||
return function() {
|
||||
const context = this;
|
||||
const args = arguments;
|
||||
clearTimeout(timeout);
|
||||
timeout = setTimeout(() => func.apply(context, args), wait);
|
||||
};
|
||||
}
|
||||
|
||||
// Helper function to show notifications
|
||||
function showNotification(message, type = 'success') {
|
||||
const notification = document.createElement('div');
|
||||
const icon = type === 'success' ? 'mdi-check-circle' : 'mdi-alert-circle';
|
||||
const bgColor = type === 'success' ? 'bg-primary/90' : 'bg-red-500/90';
|
||||
|
||||
notification.className = `fixed bottom-4 right-4 ${bgColor} text-white px-4 py-2 rounded-md shadow-lg transform translate-y-0 opacity-100 transition-all duration-300 flex items-center`;
|
||||
notification.innerHTML = `<i class="mdi ${icon} mr-2"></i><span>${message}</span>`;
|
||||
|
||||
document.body.appendChild(notification);
|
||||
|
||||
setTimeout(() => {
|
||||
notification.classList.add('translate-y-16', 'opacity-0');
|
||||
setTimeout(() => notification.remove(), 300);
|
||||
}, 3000);
|
||||
}
|
||||
|
||||
// Helper function to get CSRF token from meta tag
|
||||
function getCsrfToken() {
|
||||
return document.querySelector('meta[name="csrf-token"]').getAttribute('content');
|
||||
}
|
||||
|
||||
// Toggle element visibility
|
||||
function toggleVisibility(element, show) {
|
||||
if (show) {
|
||||
element.classList.remove('hidden');
|
||||
} else {
|
||||
element.classList.add('hidden');
|
||||
}
|
||||
}
|
||||
|
||||
// Load preference from localStorage with default value
|
||||
function getPreference(key, defaultValue) {
|
||||
const value = localStorage.getItem(key);
|
||||
return value !== null ? value : defaultValue;
|
||||
}
|
||||
|
||||
// Save preference to localStorage
|
||||
function savePreference(key, value) {
|
||||
localStorage.setItem(key, value);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue