aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-web/src/main/js/apps/api-documentation/search-view.js
blob: 6eb9efe74e4cf2cf8fc166892b46c65bb6152e47 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import _ from 'underscore';
import Marionette from 'backbone.marionette';
import Template from './templates/api-documentation-search.hbs';

export default Marionette.ItemView.extend({
  template: Template,

  ui: {
    input: '.search-box-input'
  },

  events: {
    'keyup @ui.input': 'onChange',
    'search @ui.input': 'onChange'
  },

  initialize: function () {
    this.query = '';
    this.debouncedFilter = _.debounce(this.filter, 250);
  },

  onChange: function () {
    var query = this.ui.input.val();
    if (query === this.query) {
      return;
    }
    this.query = this.ui.input.val();
    this.debouncedFilter(query);
  },

  filter: function (query) {
    this.options.state.set({ query: query });
  }
});