2020-06-10 03:09:43 +02:00
|
|
|
class SearchQuerySend {
|
2020-06-09 04:02:03 +02:00
|
|
|
|
|
|
|
constructor() {
|
2020-06-10 03:09:43 +02:00
|
|
|
// super();
|
2020-06-09 04:02:03 +02:00
|
|
|
this._searchBox = document.querySelector('#searchBox');
|
|
|
|
this._keyUpEvent = this._keyUpEvent.bind(this);
|
|
|
|
this._registerKeyUpEvent();
|
|
|
|
}
|
|
|
|
|
|
|
|
_sendQuery = () => {
|
|
|
|
// Search
|
2020-06-10 03:09:43 +02:00
|
|
|
window.location.href = encodeURI(searchEngineSettings.getSearchQueryPrefix() + this._searchBox.value);
|
2020-06-09 04:02:03 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
_keyUpEvent = event => {
|
2020-06-06 05:34:20 +02:00
|
|
|
if (event.key === 'Tab') return;
|
|
|
|
|
2020-06-04 05:27:00 +02:00
|
|
|
// Number 13 is the "Enter" key on the keyboard
|
|
|
|
if (event.key === 'Enter') {
|
|
|
|
|
|
|
|
// Don't accept empty strings
|
|
|
|
if (searchBox.value < 1) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Cancel the default action, if needed
|
|
|
|
event.preventDefault();
|
|
|
|
|
|
|
|
// Search the web
|
2020-06-09 04:02:03 +02:00
|
|
|
this._sendQuery()
|
2020-06-04 05:27:00 +02:00
|
|
|
};
|
2020-06-09 04:02:03 +02:00
|
|
|
}
|
2020-06-04 05:27:00 +02:00
|
|
|
|
2020-06-09 04:02:03 +02:00
|
|
|
_registerKeyUpEvent = () => {
|
|
|
|
this._searchBox.addEventListener('keyup', this._keyUpEvent);
|
2020-06-04 05:27:00 +02:00
|
|
|
}
|
2020-06-09 04:02:03 +02:00
|
|
|
}
|