~andreserl/maas/packaging_precise_rebase

« back to all changes in this revision

Viewing changes to debian/extras/jslibs/yui/autocomplete-highlighters/autocomplete-highlighters-debug.js

  • Committer: Andres Rodriguez
  • Date: 2013-03-20 18:12:30 UTC
  • mfrom: (145.2.22 precise.sru)
  • Revision ID: andreserl@ubuntu.com-20130320181230-6l5guc0nhlv2z4p7
Re-base againts latest quantal released branch towards SRU

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
YUI 3.5.1 (build 22)
 
3
Copyright 2012 Yahoo! Inc. All rights reserved.
 
4
Licensed under the BSD License.
 
5
http://yuilibrary.com/license/
 
6
*/
 
7
YUI.add('autocomplete-highlighters', function(Y) {
 
8
 
 
9
/**
 
10
Provides pre-built result highlighters for AutoComplete.
 
11
 
 
12
@module autocomplete
 
13
@submodule autocomplete-highlighters
 
14
@class AutoCompleteHighlighters
 
15
@static
 
16
**/
 
17
 
 
18
var YArray    = Y.Array,
 
19
    Highlight = Y.Highlight,
 
20
 
 
21
Highlighters = Y.mix(Y.namespace('AutoCompleteHighlighters'), {
 
22
    // -- Public Methods -------------------------------------------------------
 
23
 
 
24
    /**
 
25
    Highlights any individual query character that occurs anywhere in a result.
 
26
    Case-insensitive.
 
27
 
 
28
    @method charMatch
 
29
    @param {String} query Query to match
 
30
    @param {Array} results Results to highlight
 
31
    @return {Array} Highlighted results
 
32
    @static
 
33
    **/
 
34
    charMatch: function (query, results, caseSensitive) {
 
35
        // The caseSensitive parameter is only intended for use by
 
36
        // charMatchCase(). It's intentionally undocumented.
 
37
 
 
38
        var queryChars = YArray.unique((caseSensitive ? query :
 
39
                query.toLowerCase()).split(''));
 
40
 
 
41
        return YArray.map(results, function (result) {
 
42
            return Highlight.all(result.text, queryChars, {
 
43
                caseSensitive: caseSensitive
 
44
            });
 
45
        });
 
46
    },
 
47
 
 
48
    /**
 
49
    Case-sensitive version of `charMatch()`.
 
50
 
 
51
    @method charMatchCase
 
52
    @param {String} query Query to match
 
53
    @param {Array} results Results to highlight
 
54
    @return {Array} Highlighted results
 
55
    @static
 
56
    **/
 
57
    charMatchCase: function (query, results) {
 
58
        return Highlighters.charMatch(query, results, true);
 
59
    },
 
60
 
 
61
    /**
 
62
    Highlights the complete query as a phrase anywhere within a result. Case-
 
63
    insensitive.
 
64
 
 
65
    @method phraseMatch
 
66
    @param {String} query Query to match
 
67
    @param {Array} results Results to highlight
 
68
    @return {Array} Highlighted results
 
69
    @static
 
70
    **/
 
71
    phraseMatch: function (query, results, caseSensitive) {
 
72
        // The caseSensitive parameter is only intended for use by
 
73
        // phraseMatchCase(). It's intentionally undocumented.
 
74
 
 
75
        return YArray.map(results, function (result) {
 
76
            return Highlight.all(result.text, [query], {
 
77
                caseSensitive: caseSensitive
 
78
            });
 
79
        });
 
80
    },
 
81
 
 
82
    /**
 
83
    Case-sensitive version of `phraseMatch()`.
 
84
 
 
85
    @method phraseMatchCase
 
86
    @param {String} query Query to match
 
87
    @param {Array} results Results to highlight
 
88
    @return {Array} Highlighted results
 
89
    @static
 
90
    **/
 
91
    phraseMatchCase: function (query, results) {
 
92
        return Highlighters.phraseMatch(query, results, true);
 
93
    },
 
94
 
 
95
    /**
 
96
    Highlights the complete query as a phrase at the beginning of a result.
 
97
    Case-insensitive.
 
98
 
 
99
    @method startsWith
 
100
    @param {String} query Query to match
 
101
    @param {Array} results Results to highlight
 
102
    @return {Array} Highlighted results
 
103
    @static
 
104
    **/
 
105
    startsWith: function (query, results, caseSensitive) {
 
106
        // The caseSensitive parameter is only intended for use by
 
107
        // startsWithCase(). It's intentionally undocumented.
 
108
 
 
109
        return YArray.map(results, function (result) {
 
110
            return Highlight.all(result.text, [query], {
 
111
                caseSensitive: caseSensitive,
 
112
                startsWith   : true
 
113
            });
 
114
        });
 
115
    },
 
116
 
 
117
    /**
 
118
    Case-sensitive version of `startsWith()`.
 
119
 
 
120
    @method startsWithCase
 
121
    @param {String} query Query to match
 
122
    @param {Array} results Results to highlight
 
123
    @return {Array} Highlighted results
 
124
    @static
 
125
    **/
 
126
    startsWithCase: function (query, results) {
 
127
        return Highlighters.startsWith(query, results, true);
 
128
    },
 
129
 
 
130
    /**
 
131
    Highlights portions of results in which words from the query match either
 
132
    whole words or parts of words in the result. Non-word characters like
 
133
    whitespace and certain punctuation are ignored. Case-insensitive.
 
134
 
 
135
    @method subWordMatch
 
136
    @param {String} query Query to match
 
137
    @param {Array} results Results to highlight
 
138
    @return {Array} Highlighted results
 
139
    @static
 
140
    **/
 
141
    subWordMatch: function (query, results, caseSensitive) {
 
142
        // The caseSensitive parameter is only intended for use by
 
143
        // subWordMatchCase(). It's intentionally undocumented.
 
144
 
 
145
        var queryWords = Y.Text.WordBreak.getUniqueWords(query, {
 
146
            ignoreCase: !caseSensitive
 
147
        });
 
148
 
 
149
        return YArray.map(results, function (result) {
 
150
            return Highlight.all(result.text, queryWords, {
 
151
                caseSensitive: caseSensitive
 
152
            });
 
153
        });
 
154
    },
 
155
 
 
156
    /**
 
157
    Case-sensitive version of `subWordMatch()`.
 
158
 
 
159
    @method subWordMatchCase
 
160
    @param {String} query Query to match
 
161
    @param {Array} results Results to highlight
 
162
    @return {Array} Highlighted results
 
163
    @static
 
164
    **/
 
165
    subWordMatchCase: function (query, results) {
 
166
        return Highlighters.subWordMatch(query, results, true);
 
167
    },
 
168
 
 
169
    /**
 
170
    Highlights individual words in results that are also in the query. Non-word
 
171
    characters like punctuation are ignored. Case-insensitive.
 
172
 
 
173
    @method wordMatch
 
174
    @param {String} query Query to match
 
175
    @param {Array} results Results to highlight
 
176
    @return {Array} Highlighted results
 
177
    @static
 
178
    **/
 
179
    wordMatch: function (query, results, caseSensitive) {
 
180
        // The caseSensitive parameter is only intended for use by
 
181
        // wordMatchCase(). It's intentionally undocumented.
 
182
 
 
183
        return YArray.map(results, function (result) {
 
184
            return Highlight.words(result.text, query, {
 
185
                caseSensitive: caseSensitive
 
186
            });
 
187
        });
 
188
    },
 
189
 
 
190
    /**
 
191
    Case-sensitive version of `wordMatch()`.
 
192
 
 
193
    @method wordMatchCase
 
194
    @param {String} query Query to match
 
195
    @param {Array} results Results to highlight
 
196
    @return {Array} Highlighted results
 
197
    @static
 
198
    **/
 
199
    wordMatchCase: function (query, results) {
 
200
        return Highlighters.wordMatch(query, results, true);
 
201
    }
 
202
});
 
203
 
 
204
 
 
205
}, '3.5.1' ,{requires:['array-extras', 'highlight-base']});