~webapps/unity-webapps-qml/15.04

« back to all changes in this revision

Viewing changes to src/Ubuntu/UnityWebApps/bindings/content-hub/client/docsbuild/assets/js/api-search.js

  • Committer: CI Train Bot
  • Author(s): Daniel Holbach
  • Date: 2015-04-09 13:29:10 UTC
  • mfrom: (148.1.5 unity-webapps-qml)
  • Revision ID: ci-train-bot@canonical.com-20150409132910-mmui8imfjseapg7f
Add ./update-docs script which generates API docs locally. We can't make this part of the build as not all node dependencies of yuidocsjs are packaged in the archive.
Approved by: PS Jenkins bot, David Barth

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
YUI.add('api-search', function (Y) {
 
2
 
 
3
var Lang   = Y.Lang,
 
4
    Node   = Y.Node,
 
5
    YArray = Y.Array;
 
6
 
 
7
Y.APISearch = Y.Base.create('apiSearch', Y.Base, [Y.AutoCompleteBase], {
 
8
    // -- Public Properties ----------------------------------------------------
 
9
    RESULT_TEMPLATE:
 
10
        '<li class="result {resultType}">' +
 
11
            '<a href="{url}">' +
 
12
                '<h3 class="title">{name}</h3>' +
 
13
                '<span class="type">{resultType}</span>' +
 
14
                '<div class="description">{description}</div>' +
 
15
                '<span class="className">{class}</span>' +
 
16
            '</a>' +
 
17
        '</li>',
 
18
 
 
19
    // -- Initializer ----------------------------------------------------------
 
20
    initializer: function () {
 
21
        this._bindUIACBase();
 
22
        this._syncUIACBase();
 
23
    },
 
24
 
 
25
    // -- Protected Methods ----------------------------------------------------
 
26
    _apiResultFilter: function (query, results) {
 
27
        // Filter components out of the results.
 
28
        return YArray.filter(results, function (result) {
 
29
            return result.raw.resultType === 'component' ? false : result;
 
30
        });
 
31
    },
 
32
 
 
33
    _apiResultFormatter: function (query, results) {
 
34
        return YArray.map(results, function (result) {
 
35
            var raw  = Y.merge(result.raw), // create a copy
 
36
                desc = raw.description || '';
 
37
 
 
38
            // Convert description to text and truncate it if necessary.
 
39
            desc = Node.create('<div>' + desc + '</div>').get('text');
 
40
 
 
41
            if (desc.length > 65) {
 
42
                desc = Y.Escape.html(desc.substr(0, 65)) + ' &hellip;';
 
43
            } else {
 
44
                desc = Y.Escape.html(desc);
 
45
            }
 
46
 
 
47
            raw['class'] || (raw['class'] = '');
 
48
            raw.description = desc;
 
49
 
 
50
            // Use the highlighted result name.
 
51
            raw.name = result.highlighted;
 
52
 
 
53
            return Lang.sub(this.RESULT_TEMPLATE, raw);
 
54
        }, this);
 
55
    },
 
56
 
 
57
    _apiTextLocator: function (result) {
 
58
        return result.displayName || result.name;
 
59
    }
 
60
}, {
 
61
    // -- Attributes -----------------------------------------------------------
 
62
    ATTRS: {
 
63
        resultFormatter: {
 
64
            valueFn: function () {
 
65
                return this._apiResultFormatter;
 
66
            }
 
67
        },
 
68
 
 
69
        resultFilters: {
 
70
            valueFn: function () {
 
71
                return this._apiResultFilter;
 
72
            }
 
73
        },
 
74
 
 
75
        resultHighlighter: {
 
76
            value: 'phraseMatch'
 
77
        },
 
78
 
 
79
        resultListLocator: {
 
80
            value: 'data.results'
 
81
        },
 
82
 
 
83
        resultTextLocator: {
 
84
            valueFn: function () {
 
85
                return this._apiTextLocator;
 
86
            }
 
87
        },
 
88
 
 
89
        source: {
 
90
            value: '/api/v1/search?q={query}&count={maxResults}'
 
91
        }
 
92
    }
 
93
});
 
94
 
 
95
}, '3.4.0', {requires: [
 
96
    'autocomplete-base', 'autocomplete-highlighters', 'autocomplete-sources',
 
97
    'escape'
 
98
]});