cleaned up JS
This commit is contained in:
parent
186026fa6d
commit
cdd0c13cdc
7 changed files with 82 additions and 75 deletions
|
@ -169,77 +169,9 @@
|
|||
</div>
|
||||
</form>
|
||||
|
||||
<!-- JavaScript Functions -->
|
||||
<script>
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
const customSearchWrapper = document.querySelector('.wrapper.custom-search-page');
|
||||
const searchTypeIcons = document.querySelector('.search-type-icons');
|
||||
const resultsWrapper = document.querySelector('.wrapper.custom-search-page .autocomplete');
|
||||
|
||||
// Check if we are on the correct page
|
||||
if (customSearchWrapper && resultsWrapper) {
|
||||
|
||||
// Function to move buttons without affecting the page flow
|
||||
function adjustSearchIconsPosition() {
|
||||
const autocompleteHeight = resultsWrapper.offsetHeight;
|
||||
if (autocompleteHeight > 0) {
|
||||
// Use transform to move the buttons down
|
||||
searchTypeIcons.style.transform = `translateY(${autocompleteHeight + 20}px)`;
|
||||
} else {
|
||||
// Reset the buttons position when no suggestions
|
||||
searchTypeIcons.style.transform = 'translateY(0)';
|
||||
}
|
||||
}
|
||||
|
||||
// Observer to detect changes in the autocomplete content and adjust position
|
||||
const observer = new MutationObserver(() => {
|
||||
adjustSearchIconsPosition();
|
||||
});
|
||||
|
||||
// Start observing the autocomplete for content changes
|
||||
observer.observe(resultsWrapper, { childList: true, subtree: true });
|
||||
|
||||
// Optionally adjust when window resizes (for responsive changes)
|
||||
window.addEventListener('resize', adjustSearchIconsPosition);
|
||||
|
||||
// Adjust initially on load in case suggestions are already present
|
||||
adjustSearchIconsPosition();
|
||||
}
|
||||
});
|
||||
|
||||
</script>
|
||||
<script>
|
||||
function openNav() {
|
||||
document.getElementById("mySidenav").style.width = "250px";
|
||||
document.body.classList.add('menu-open');
|
||||
}
|
||||
|
||||
function closeNav() {
|
||||
document.getElementById("mySidenav").style.width = "0";
|
||||
document.body.classList.remove('menu-open');
|
||||
}
|
||||
|
||||
function setTheme(theme) {
|
||||
window.location.href = '/search?theme=' + theme;
|
||||
}
|
||||
|
||||
function updateLanguage(langCode) {
|
||||
// Send AJAX request to update language settings
|
||||
const xhr = new XMLHttpRequest();
|
||||
xhr.open('POST', '/updateSettings', true);
|
||||
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
|
||||
xhr.onload = function () {
|
||||
if (this.status >= 200 && this.status < 300) {
|
||||
location.reload();
|
||||
} else {
|
||||
console.error('Failed to update language.');
|
||||
}
|
||||
};
|
||||
xhr.send(encodeURI('site_lang=' + langCode));
|
||||
}
|
||||
</script>
|
||||
|
||||
<!-- Include autocomplete.js -->
|
||||
<!-- Included JavaScript Functions -->
|
||||
<script defer src="/static/js/buttonsmove.js"></script>
|
||||
<script defer src="/static/js/sidemenu.js"></script>
|
||||
<script defer src="/static/js/autocomplete.js"></script>
|
||||
</body>
|
||||
</html>
|
Loading…
Add table
Add a link
Reference in a new issue