views/autocomplete: remove unused nodes
This commit is contained in:
parent
f2833b6e76
commit
d2b9cece28
1 changed files with 22 additions and 3 deletions
|
@ -61,9 +61,27 @@ class AutoCompleteControl {
|
|||
this.results = [];
|
||||
this.activeResult = -1;
|
||||
|
||||
this.mutationObserver = new MutationObserver(
|
||||
mutations => {
|
||||
for (let mutation of mutations) {
|
||||
for (let node of mutation.removedNodes) {
|
||||
if (node.contains(input)) {
|
||||
this.uninstall();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
this.install();
|
||||
}
|
||||
|
||||
uninstall() {
|
||||
window.clearTimeout(this.showTimeout);
|
||||
this.mutationObserver.disconnect();
|
||||
document.body.removeChild(this.suggestionDiv);
|
||||
}
|
||||
|
||||
install() {
|
||||
if (!this.input) {
|
||||
throw new Error('Input element was not found');
|
||||
|
@ -75,6 +93,9 @@ class AutoCompleteControl {
|
|||
this.input.setAttribute('data-autocomplete', true);
|
||||
this.input.setAttribute('autocomplete', 'off');
|
||||
|
||||
this.mutationObserver.observe(
|
||||
document.body, {childList: true, subtree: true});
|
||||
|
||||
this.input.addEventListener(
|
||||
'keydown',
|
||||
e => {
|
||||
|
@ -154,9 +175,7 @@ class AutoCompleteControl {
|
|||
}
|
||||
|
||||
hide() {
|
||||
if (this.showTimeout) {
|
||||
window.clearTimeout(this.showTimeout);
|
||||
}
|
||||
window.clearTimeout(this.showTimeout);
|
||||
this.suggestionDiv.style.display = 'none';
|
||||
this.isVisible = false;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue