Skip to content
Snippets Groups Projects
Commit 11bf7961 authored by Henrik Askjer's avatar Henrik Askjer
Browse files

Merge branch 'fix_premature_autocomplete' into 'master'

Replace blur()

See merge request spraksamlingane/beta.ordbok.uib.no!42
parents 757c0111 245b59b1
No related branches found
No related tags found
No related merge requests found
......@@ -50,33 +50,35 @@
return axios.get(self.endpoint + 'suggest?q=' + encodeURIComponent(q))
.then(
function(response) {
let hits = []
if (q == self.search) {
response.data.forEach((item, i) => {
let match = encodeURIComponent(item.match)
if (self.loading) {
let hits = []
if (q == self.search) {
response.data.forEach((item, i) => {
let match = encodeURIComponent(item.match)
if (! hits[0] || hits[0].word != match) {
hits.splice(0, 0, {q: encodeURIComponent(q), lang_set: new Set(), word: match, articles: []})
}
hits[0].lang_set.add(item.dictionary == 'bob' ? 'bm' : 'nn')
hits[0].articles.push(item)
});
hits.forEach(function (hit) {
if (hit.lang_set) {
hit.label = decodeURIComponent(hit.word)
}
});
hits.reverse()
hits = hits.slice(0, 9)
}
hits.sort( (h1, h2) => {
let val1 = h1.label.length * 10 + (h1.label[0].toLowerCase() === h1.label[0] ? 0 : 1)
let val2 = h2.label.length * 10 + (h2.label[0].toLowerCase() === h2.label[0] ? 0 : 1)
return val1 - val2
})
if (! hits[0] || hits[0].word != match) {
hits.splice(0, 0, {q: encodeURIComponent(q), lang_set: new Set(), word: match, articles: []})
}
hits[0].lang_set.add(item.dictionary == 'bob' ? 'bm' : 'nn')
hits[0].articles.push(item)
});
hits.forEach(function (hit) {
if (hit.lang_set) {
hit.label = decodeURIComponent(hit.word)
}
});
hits.reverse()
hits = hits.slice(0, 9)
}
hits.sort( (h1, h2) => {
let val1 = h1.label.length * 10 + (h1.label[0].toLowerCase() === h1.label[0] ? 0 : 1)
let val2 = h2.label.length * 10 + (h2.label[0].toLowerCase() === h2.label[0] ? 0 : 1)
return val1 - val2
})
self.items = hits
self.loading = false
self.items = hits
self.loading = false
}
})
}, 100)
}
......@@ -90,13 +92,15 @@
}
},
select(item) {
if (typeof item === 'string') {
item = {"q": encodeURIComponent(item)}
if (item) {
if (typeof item === 'string') {
item = {"q": encodeURIComponent(item)}
}
this.loading = false
this.$emit('submit', item)
let self = this
setTimeout(() => self.$refs.autocomplete.$refs.input.select(), 1)
}
this.$emit('submit', item)
this.$refs.autocomplete.blur()
let self = this
setTimeout(() => self.$refs.autocomplete.$refs.input.select(), 1)
}
},
methods: {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment