logo

pleroma-fe

My custom branche(s) on git.pleroma.social/pleroma/pleroma-fe git clone https://anongit.hacktivis.me/git/pleroma-fe.git/

autosuggest.js (1047B)


  1. const debounceMilliseconds = 500
  2. export default {
  3. props: {
  4. query: { // function to query results and return a promise
  5. type: Function,
  6. required: true
  7. },
  8. filter: { // function to filter results in real time
  9. type: Function
  10. },
  11. placeholder: {
  12. type: String,
  13. default: 'Search...'
  14. }
  15. },
  16. data () {
  17. return {
  18. term: '',
  19. timeout: null,
  20. results: [],
  21. resultsVisible: false
  22. }
  23. },
  24. computed: {
  25. filtered () {
  26. return this.filter ? this.filter(this.results) : this.results
  27. }
  28. },
  29. watch: {
  30. term (val) {
  31. this.fetchResults(val)
  32. }
  33. },
  34. methods: {
  35. fetchResults (term) {
  36. clearTimeout(this.timeout)
  37. this.timeout = setTimeout(() => {
  38. this.results = []
  39. if (term) {
  40. this.query(term).then((results) => { this.results = results })
  41. }
  42. }, debounceMilliseconds)
  43. },
  44. onInputClick () {
  45. this.resultsVisible = true
  46. },
  47. onClickOutside () {
  48. this.resultsVisible = false
  49. }
  50. }
  51. }