Rename app.js -> item.js

This commit is contained in:
Edward Betts 2019-09-29 17:01:32 +01:00
parent 9ba35cb414
commit 75d48ed28b
2 changed files with 1 additions and 1 deletions

45
static/js/item.js Normal file
View file

@ -0,0 +1,45 @@
var typingTimer;
var doneTypingInterval = 500;
var app = new Vue({
el: '#app',
data: {
prevTerms: '',
searchTerms: '',
hits: [],
new_depicts: [],
},
methods: {
remove(index) {
this.$delete(this.new_depicts, index);
},
add_depicts(hit) {
this.new_depicts.push(hit);
this.hits = [];
this.searchTerms = '';
},
run_search() {
var terms = this.searchTerms;
if (terms == this.prevTerms) {
return; // no change
}
this.prevTerms = terms;
if (terms.length < 3) {
this.hits = [];
return;
}
var vm = this;
fetch(lookup_url + '?terms=' + encodeURI(terms))
.then((res) => res.json())
.then((data) => {
vm.hits = data.hits;
})
},
search(event) {
clearTimeout(typingTimer);
typingTimer = setTimeout(this.run_search, doneTypingInterval);
}
},
});