the-glorious-startpage/js/show-search-box.js

70 lines
1.7 KiB
JavaScript
Raw Normal View History

2020-06-09 04:02:03 +02:00
class SearchBoxShow {
constructor() {
2020-06-04 03:54:39 +02:00
2020-06-09 04:02:03 +02:00
this._searchBox = document.querySelector('#searchBox');
this._searchBoxContainer = document.querySelector('#searchBoxContainer');
this._centeredBoxOverlay = document.querySelector('#centeredBoxOverlay');
2020-06-04 03:54:39 +02:00
2020-06-09 04:02:03 +02:00
this._searchBoxVisility = false;
2020-06-04 03:54:39 +02:00
2020-06-09 04:02:03 +02:00
this.showSearchBox = this.showSearchBox.bind(this);
this.hideSearchBox = this.hideSearchBox.bind(this);
this.toggleSearchBox = this.toggleSearchBox.bind(this);
}
2020-06-04 03:54:39 +02:00
2020-06-09 04:02:03 +02:00
getSearchBoxVisibility = () => {
return this._searchBoxVisility;
}
2020-06-06 01:31:43 +02:00
2020-06-09 04:02:03 +02:00
showSearchBox = () => {
this._searchBoxContainer.classList.add('showSearchBox');
2020-06-04 03:54:39 +02:00
2020-06-09 04:02:03 +02:00
// Focus
this._searchBox.focus();
2020-06-04 03:54:39 +02:00
2020-06-09 04:02:03 +02:00
this._searchBoxVisility = !this._searchBoxVisility;
2020-06-06 01:31:43 +02:00
2020-06-09 04:02:03 +02:00
// Toggle overlay
this._centeredBoxOverlay.classList.toggle('showOverlay');
}
2020-06-06 01:31:43 +02:00
2020-06-09 04:02:03 +02:00
hideSearchBox = () => {
this._searchBoxContainer.classList.remove('showSearchBox');
2020-06-06 05:13:45 +02:00
2020-06-09 04:02:03 +02:00
// Toggle overlay
this._centeredBoxOverlay.classList.toggle('showOverlay');
this._searchBox.value = '';
2020-06-04 03:54:39 +02:00
2020-06-09 04:02:03 +02:00
// Hide suggestions
2020-06-09 06:21:57 +02:00
autoSuggestion.hideSuggestions();
2020-06-04 03:54:39 +02:00
2020-06-09 04:02:03 +02:00
this._searchBoxVisility = !this._searchBoxVisility;
}
2020-06-04 03:54:39 +02:00
2020-06-09 04:02:03 +02:00
toggleSearchBox = () => {
2020-06-04 03:54:39 +02:00
2020-06-09 04:02:03 +02:00
// If profile anim is still running,
// Return to avoid spam
if (profileImage.getProfileAnimationStatus()) return;
2020-06-04 03:54:39 +02:00
2020-06-09 04:02:03 +02:00
// Rotate profile
profileImage.rotateProfile();
if (this._searchBoxVisility) {
// Hide search box
this.hideSearchBox();
} else {
// Show search box
this.showSearchBox();
}
console.log('toggle searchbox');
2020-06-04 03:54:39 +02:00
}
2020-06-09 04:02:03 +02:00
}