Added initial version.
This commit is contained in:
parent
a8b3ece110
commit
736631e798
6 changed files with 200 additions and 2 deletions
41
js/00-functions.js
Normal file
41
js/00-functions.js
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
// helper function to be able to change the event listener
|
||||
function updateState() {
|
||||
states.search = this.value;
|
||||
}
|
||||
|
||||
// checks if the pressed key equals to return key
|
||||
function updateStateOnReturnKey(e) {
|
||||
if (e.keyCode === 13) {
|
||||
updateState.call(this);
|
||||
}
|
||||
}
|
||||
|
||||
// removes the old event listener and applies the new one
|
||||
function changeEvent(newEvent) {
|
||||
// remove the old listener
|
||||
switch (states.event) {
|
||||
case "onenterkey":
|
||||
this.removeEventListener("keyup", updateStateOnReturnKey);
|
||||
break;
|
||||
default:
|
||||
this.removeEventListener(states.event, updateState);
|
||||
break;
|
||||
}
|
||||
states.event = newEvent;
|
||||
// add the new listener
|
||||
switch (newEvent) {
|
||||
case "onenterkey":
|
||||
this.addEventListener("keyup", updateStateOnReturnKey);
|
||||
break;
|
||||
default:
|
||||
this.addEventListener(states.event, updateState);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// updates the search field if the state does not match the value
|
||||
function updateSearchInput(state) {
|
||||
if (this.value !== state) {
|
||||
this.value = state;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue