aboutsummaryrefslogtreecommitdiff
path: root/javascript/app/routes/package/search.js
blob: 058f9ecc8eb572eee14c8f8781ed1d972fa88317 (plain) (blame)
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
35
36
import Ember from 'ember';
import {urls} from '../../utils/api-urls';
import {goToDefinition} from '../../utils/go-to-definition';

export default Ember.Route.extend({
  store : Ember.inject.service('store'),
  model (params) {
    return {
      query: params.query,
      url: urls.identifierSearchUrl(this.modelFor('package').id,params.query)+"?per_page=20"
    };
  },
  afterModel () {
    const onmouseup = (event) => {
      // This makes links in documentation clickable
      if(event.target.dataset.location) {
        let location;
        try {
          location = JSON.parse(event.target.dataset.location);
        } catch (e) {
          console.log(e);
        }
        if(location) {
          goToDefinition(this.get('store'),location,event.which);
        }
      }
    };
    this._onmouseup = onmouseup;
    document.addEventListener('mouseup',onmouseup);
  },
  deactivate() {
    if(this._onmouseup) {
      document.removeEventListener('mouseup',this._onmouseup);
    }
  }
});