Skip to content

Commit

Permalink
Some tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
pespantelis committed May 20, 2016
1 parent 37474ea commit aef4efd
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 28 deletions.
5 changes: 3 additions & 2 deletions demo/Typeahead.vue
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,9 @@ export default {
data () {
return {
src: 'https://typeahead-js-twitter-api-proxy.herokuapp.com/demo/search',
limit: 5,
src: 'https://typeahead-js-twitter-api-proxy.herokuapp.com/demo/search'
minChars: 3
}
},
Expand All @@ -52,7 +53,7 @@ export default {



<style>
<style scoped>
.Typeahead {
position: relative;
}
Expand Down
45 changes: 19 additions & 26 deletions src/main.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Vue from 'vue'
import { util } from 'vue'

export default {
data () {
Expand All @@ -11,12 +11,6 @@ export default {
}
},

ready () {
if (! this.onHit) {
this.warn('`onHit` method')
}
},

computed: {
hasItems () {
return this.items.length > 0
Expand All @@ -32,14 +26,9 @@ export default {
},

methods: {
warn (msg) {
Vue.util.warn('Typeahead requires the ' + msg)
},

update () {
if (! this.query) {
this.reset()
return
if (!this.query) {
return this.reset()
}

if (this.minChars && this.query.length < this.minChars) {
Expand All @@ -61,13 +50,11 @@ export default {

fetch () {
if (!this.$http) {
this.warn('`vue-resource` plugin')
return
return util.warn('You need to install the `vue-resource` plugin', this)
}

if (!this.src) {
this.warn('`src` property')
return
return util.warn('You need to set the `src` property', this)
}

let queryParam = {
Expand All @@ -94,25 +81,31 @@ export default {
},

hit () {
if (this.current === -1) return

this.onHit(this.items[this.current])
if (this.current !== -1) {
this.onHit(this.items[this.current])
}
},

up () {
if (this.current > 0)
if (this.current > 0) {
this.current--
else if (this.current == -1)
} else if (this.current == -1) {
this.current = this.items.length - 1
else
} else {
this.current = -1
}
},

down () {
if (this.current < this.items.length-1)
if (this.current < this.items.length-1) {
this.current++
else
} else {
this.current = -1
}
},

onHit () {
util.warn('You need to implement the `onHit` method', this)
}
}
}

0 comments on commit aef4efd

Please sign in to comment.