1
0
mirror of https://github.com/chinchang/web-maker.git synced 2025-07-22 22:41:12 +02:00

improve add external lib modal ux

This commit is contained in:
Kushagra Gour
2017-12-11 17:55:24 +05:30
parent c232a167ef
commit 75e941f1e1
4 changed files with 47 additions and 21 deletions

View File

@@ -1,9 +1,10 @@
// textarea-autocomplete.js
(function() {
class TextareaAutoComplete {
constructor(textarea, filter) {
constructor(textarea, options) {
this.t = textarea;
this.filter = filter;
this.filter = options.filter;
this.selectedCallback = options.selectedCallback;
var wrap = document.createElement('div');
wrap.classList.add('btn-group');
textarea.parentElement.insertBefore(wrap, textarea);
@@ -128,17 +129,25 @@
event.preventDefault();
} else if (event.keyCode === 13 && this.isShowingSuggestions) {
selectedItemElement = this.list.querySelector('.selected');
this.replaceCurrentLine(selectedItemElement.dataset.url);
this.selectSuggestion(selectedItemElement.dataset.url);
this.closeSuggestions();
}
}
onListMouseDown(event) {
var target = event.target;
if (target.parentElement.dataset.url) {
this.replaceCurrentLine(target.parentElement.dataset.url);
this.closeSuggestions();
this.selectSuggestion(target.parentElement.dataset.url);
}
}
selectSuggestion(value) {
if (this.selectedCallback) {
this.selectedCallback.call(null, value);
} else {
this.replaceCurrentLine(value);
}
this.closeSuggestions();
}
}
window.TextareaAutoComplete = TextareaAutoComplete;