Project_Bank / script.js
Kshitij2604's picture
Upload 30 files
102fe5c verified
document.addEventListener('DOMContentLoaded', function() {
// Initialize tooltips
var tooltipTriggerList = [].slice.call(document.querySelectorAll('[data-bs-toggle="tooltip"]'));
var tooltipList = tooltipTriggerList.map(function (tooltipTriggerEl) {
return new bootstrap.Tooltip(tooltipTriggerEl);
});
// Add fade-in animation to main content
document.querySelector('main').classList.add('fade-in');
// Password visibility toggle
const togglePasswordButtons = document.querySelectorAll('.toggle-password');
if (togglePasswordButtons) {
togglePasswordButtons.forEach(button => {
button.addEventListener('click', function() {
const passwordInput = document.querySelector(this.getAttribute('data-target'));
const type = passwordInput.getAttribute('type') === 'password' ? 'text' : 'password';
passwordInput.setAttribute('type', type);
// Toggle icon
this.querySelector('i').classList.toggle('fa-eye');
this.querySelector('i').classList.toggle('fa-eye-slash');
});
});
}
// Confirm delete prompts
const deleteButtons = document.querySelectorAll('.btn-delete');
if (deleteButtons) {
deleteButtons.forEach(button => {
button.addEventListener('click', function(e) {
if (!confirm('Are you sure you want to delete this item? This action cannot be undone.')) {
e.preventDefault();
}
});
});
}
// Table row highlight on hover
const tableRows = document.querySelectorAll('tbody tr');
if (tableRows) {
tableRows.forEach(row => {
row.addEventListener('mouseenter', function() {
this.classList.add('highlight');
});
row.addEventListener('mouseleave', function() {
this.classList.remove('highlight');
});
});
}
// Search input focus effect
const searchInputs = document.querySelectorAll('input[type="search"], input[name="search"]');
if (searchInputs) {
searchInputs.forEach(input => {
input.addEventListener('focus', function() {
this.parentElement.classList.add('search-focus');
});
input.addEventListener('blur', function() {
this.parentElement.classList.remove('search-focus');
});
});
}
// Form validation
const forms = document.querySelectorAll('.needs-validation');
if (forms) {
Array.from(forms).forEach(form => {
form.addEventListener('submit', event => {
if (!form.checkValidity()) {
event.preventDefault();
event.stopPropagation();
}
form.classList.add('was-validated');
}, false);
});
}
});