Skip to content

Commit ecdab58

Browse files
committed
update script.js to fix issue #123
1 parent 475863f commit ecdab58

File tree

1 file changed

+75
-3
lines changed

1 file changed

+75
-3
lines changed

script.js

Lines changed: 75 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ let libraryForm = document.getElementById("libraryForm");
44
let name = document.getElementById("bookName");
55
let author = document.getElementById("author");
66
let isbn = document.getElementById("isbnno");
7-
let edition = document.getElementById("edition");
8-
let publicationD = document.getElementById("publicationdate");
7+
let edition = document.getElementById("publicationdate");
98
let read = document.getElementById("read-toggle");
109

1110
let url = document.getElementById("bookurl");
@@ -691,4 +690,77 @@ mybutton.addEventListener("click", backToTop);
691690
function backToTop() {
692691
document.body.scrollTop = 0;
693692
document.documentElement.scrollTop = 0;
694-
}
693+
}
694+
695+
// --- Filter Dropdown Fix ---
696+
// Add event listeners to filter menu items to set filter type
697+
698+
document.addEventListener("DOMContentLoaded", function () {
699+
// Filter dropdown logic
700+
const filterMenuItems = document.querySelectorAll('.dropdown .menu ul li');
701+
const filterDropdown = document.getElementById('filter-books');
702+
let currentFilter = 'all';
703+
704+
// If filter-books select doesn't exist, create a hidden one for logic
705+
if (!filterDropdown) {
706+
const select = document.createElement('select');
707+
select.id = 'filter-books';
708+
select.style.display = 'none';
709+
select.innerHTML = `
710+
<option value="all">All</option>
711+
<option value="book">Name</option>
712+
<option value="bookauthor">Author</option>
713+
<option value="bookType">Type</option>
714+
`;
715+
document.body.appendChild(select);
716+
}
717+
718+
// Attach click event to menu items
719+
filterMenuItems.forEach((item) => {
720+
item.addEventListener('click', function (e) {
721+
e.preventDefault();
722+
let text = this.textContent.trim().toLowerCase();
723+
let value = 'all';
724+
if (text === 'name') value = 'book';
725+
else if (text === 'author') value = 'bookauthor';
726+
else if (text === 'type') value = 'bookType';
727+
else value = 'all';
728+
document.getElementById('filter-books').value = value;
729+
currentFilter = value;
730+
filterBooks();
731+
});
732+
});
733+
734+
// --- Search Bar Fix ---
735+
// Keep search bar open after typing
736+
const searchBox = document.querySelector('.search_box');
737+
const searchInput = document.getElementById('searchText');
738+
if (searchBox && searchInput) {
739+
searchInput.addEventListener('focus', function () {
740+
searchBox.classList.add('active');
741+
searchInput.style.width = '240px';
742+
searchInput.style.opacity = '1';
743+
searchInput.style.padding = '10px 20px';
744+
});
745+
searchInput.addEventListener('blur', function () {
746+
// Do not close the search bar on blur if there is text
747+
if (searchInput.value.trim() !== '') {
748+
searchInput.style.width = '240px';
749+
searchInput.style.opacity = '1';
750+
searchInput.style.padding = '10px 20px';
751+
} else {
752+
searchInput.style.width = '';
753+
searchInput.style.opacity = '';
754+
searchInput.style.padding = '';
755+
}
756+
});
757+
// Prevent form submission from closing the bar
758+
const searchBtn = searchBox.querySelector('button');
759+
if (searchBtn) {
760+
searchBtn.addEventListener('mousedown', function (e) {
761+
e.preventDefault();
762+
searchInput.focus();
763+
});
764+
}
765+
}
766+
});

0 commit comments

Comments
 (0)