summaryrefslogtreecommitdiff
path: root/data/extensions/jid1-KtlZuoiikVfFew@jetpack/node_modules/pathfinder/docs/awesomebar.md
blob: dcfbb1fd7bfdf42bb67579300b35a2e409cefd80 (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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<!-- contributed by Erik Vold [erikvvold@gmail.com]  -->


The `awesomebar` API provides a simple way to create AwesomeBar suggestions.

## Example ##

    // add github search
    AwesomeBarSuggestion({
      icon: self.data.url("github_16.png"),
      matches: /^(?:@[\w\d_-]+|github\s)/i,
      onSearch: function(query, suggest) {
        query = query.trim();
        if (/^github\s/i.test(query)) {
          query = query.replace(/^github\s/i, "");
          suggest({
            title: 'Search Github for: ' + query,
            favicon: self.data.url("github_16.png"),
            url: 'https://github.com/search?q=' + encodeURIComponent(query)
          }, true);
        } else {
          var username = query.match(/^@([\w\d_-]+)/)[1];
          suggest({
            title: 'Github user: ' + username,
            label: "View user profile for @" + username,
            favicon: self.data.url("github_16.png"),
            url: 'https://github.com/' + username
          }, true);
        }
      }
    });

<api name="AwesomeBarSuggestion">
@class
  A `AwesomeBarSuggestion` constructor is exported, which allows one to create a
  AwesomeBar suggestions.

<api name="AwesomeBarSuggestion">
@constructor
  Creates a AwesomeBar suggestion handler.

@param options {object}
  Options for the AwesomeBar suggester, with the following parameters:

@prop matches {string}
  A regular expression which is tested againsted the location bar input string.

@prop [icon] {string}
  A URL for a 16x16 icon image.

@prop onSearch {function}
  Function that is invoked when the match pattern matches the location bar input
  string.  If will receive too arguments, `query` which is the input string, and
  `suggest` which is a function that can be made to return suggestions.
</api>

<api name="destroy">
@method
  Removes the AwesomeBar suggester.
</api>
</api>