~ubuntu-branches/ubuntu/trusty/moodle/trusty-proposed

« back to all changes in this revision

Viewing changes to lib/yui/3.4.1/build/autocomplete-filters/autocomplete-filters-debug.js

  • Committer: Package Import Robot
  • Author(s): Thijs Kinkhorst
  • Date: 2013-07-19 08:52:46 UTC
  • mfrom: (1.1.10)
  • Revision ID: package-import@ubuntu.com-20130719085246-yebwditc2exoap2r
Tags: 2.5.1-1
* New upstream version: 2.5.1.
  - Fixes security issues:
    CVE-2013-2242 CVE-2013-2243 CVE-2013-2244 CVE-2013-2245
    CVE-2013-2246
* Depend on apache2 instead of obsolete apache2-mpm-prefork.
* Use packaged libphp-phpmailer (closes: #429339), adodb,
  HTMLPurifier, PclZip.
* Update debconf translations, thanks Salvatore Merone, Pietro Tollot,
  Joe Hansen, Yuri Kozlov, Holger Wansing, Américo Monteiro,
  Adriano Rafael Gomes, victory, Michał Kułach.
  (closes: #716972, #716986, #717080, #717108, #717278)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
YUI 3.4.1 (build 4118)
3
 
Copyright 2011 Yahoo! Inc. All rights reserved.
4
 
Licensed under the BSD License.
5
 
http://yuilibrary.com/license/
6
 
*/
7
 
YUI.add('autocomplete-filters', function(Y) {
8
 
 
9
 
/**
10
 
 * Provides pre-built result matching filters for AutoComplete.
11
 
 *
12
 
 * @module autocomplete
13
 
 * @submodule autocomplete-filters
14
 
 * @class AutoCompleteFilters
15
 
 * @static
16
 
 */
17
 
 
18
 
var YArray     = Y.Array,
19
 
    YObject    = Y.Object,
20
 
    WordBreak  = Y.Text.WordBreak,
21
 
 
22
 
Filters = Y.mix(Y.namespace('AutoCompleteFilters'), {
23
 
    // -- Public Methods -------------------------------------------------------
24
 
 
25
 
    /**
26
 
     * Returns an array of results that contain all of the characters in the
27
 
     * query, in any order (not necessarily consecutive). Case-insensitive.
28
 
     *
29
 
     * @method charMatch
30
 
     * @param {String} query Query to match
31
 
     * @param {Array} results Results to filter
32
 
     * @return {Array} Filtered results
33
 
     * @static
34
 
     */
35
 
    charMatch: function (query, results, caseSensitive) {
36
 
        // The caseSensitive parameter is only intended for use by
37
 
        // charMatchCase(). It's intentionally undocumented.
38
 
 
39
 
        if (!query) { return results; }
40
 
 
41
 
        var queryChars = YArray.unique((caseSensitive ? query :
42
 
                query.toLowerCase()).split(''));
43
 
 
44
 
        return YArray.filter(results, function (result) {
45
 
            result = result.text;
46
 
 
47
 
            if (!caseSensitive) {
48
 
                result = result.toLowerCase();
49
 
            }
50
 
 
51
 
            return YArray.every(queryChars, function (chr) {
52
 
                return result.indexOf(chr) !== -1;
53
 
            });
54
 
        });
55
 
    },
56
 
 
57
 
    /**
58
 
     * Case-sensitive version of <code>charMatch()</code>.
59
 
     *
60
 
     * @method charMatchCase
61
 
     * @param {String} query Query to match
62
 
     * @param {Array} results Results to filter
63
 
     * @return {Array} Filtered results
64
 
     * @static
65
 
     */
66
 
    charMatchCase: function (query, results) {
67
 
        return Filters.charMatch(query, results, true);
68
 
    },
69
 
 
70
 
    /**
71
 
     * Returns an array of results that contain the complete query as a phrase.
72
 
     * Case-insensitive.
73
 
     *
74
 
     * @method phraseMatch
75
 
     * @param {String} query Query to match
76
 
     * @param {Array} results Results to filter
77
 
     * @return {Array} Filtered results
78
 
     * @static
79
 
     */
80
 
    phraseMatch: function (query, results, caseSensitive) {
81
 
        // The caseSensitive parameter is only intended for use by
82
 
        // phraseMatchCase(). It's intentionally undocumented.
83
 
 
84
 
        if (!query) { return results; }
85
 
 
86
 
        if (!caseSensitive) {
87
 
            query = query.toLowerCase();
88
 
        }
89
 
 
90
 
        return YArray.filter(results, function (result) {
91
 
            return (caseSensitive ? result.text : result.text.toLowerCase()).indexOf(query) !== -1;
92
 
        });
93
 
    },
94
 
 
95
 
    /**
96
 
     * Case-sensitive version of <code>phraseMatch()</code>.
97
 
     *
98
 
     * @method phraseMatchCase
99
 
     * @param {String} query Query to match
100
 
     * @param {Array} results Results to filter
101
 
     * @return {Array} Filtered results
102
 
     * @static
103
 
     */
104
 
    phraseMatchCase: function (query, results) {
105
 
        return Filters.phraseMatch(query, results, true);
106
 
    },
107
 
 
108
 
    /**
109
 
     * Returns an array of results that start with the complete query as a
110
 
     * phrase. Case-insensitive.
111
 
     *
112
 
     * @method startsWith
113
 
     * @param {String} query Query to match
114
 
     * @param {Array} results Results to filter
115
 
     * @return {Array} Filtered results
116
 
     * @static
117
 
     */
118
 
    startsWith: function (query, results, caseSensitive) {
119
 
        // The caseSensitive parameter is only intended for use by
120
 
        // startsWithCase(). It's intentionally undocumented.
121
 
 
122
 
        if (!query) { return results; }
123
 
 
124
 
        if (!caseSensitive) {
125
 
            query = query.toLowerCase();
126
 
        }
127
 
 
128
 
        return YArray.filter(results, function (result) {
129
 
            return (caseSensitive ? result.text : result.text.toLowerCase()).indexOf(query) === 0;
130
 
        });
131
 
    },
132
 
 
133
 
    /**
134
 
     * Case-sensitive version of <code>startsWith()</code>.
135
 
     *
136
 
     * @method startsWithCase
137
 
     * @param {String} query Query to match
138
 
     * @param {Array} results Results to filter
139
 
     * @return {Array} Filtered results
140
 
     * @static
141
 
     */
142
 
    startsWithCase: function (query, results) {
143
 
        return Filters.startsWith(query, results, true);
144
 
    },
145
 
 
146
 
    /**
147
 
     * Returns an array of results in which all the words of the query match
148
 
     * either whole words or parts of words in the result. Non-word characters
149
 
     * like whitespace and certain punctuation are ignored. Case-insensitive.
150
 
     *
151
 
     * This is basically a combination of <code>wordMatch()</code> (by ignoring
152
 
     * whitespace and word order) and <code>phraseMatch()</code> (by allowing
153
 
     * partial matching instead of requiring the entire word to match).
154
 
     *
155
 
     * Example use case: Trying to find personal names independently of name
156
 
     * order (Western or Eastern order) and supporting immediate feedback by
157
 
     * allowing partial occurences. So queries like "J. Doe", "Doe, John", and
158
 
     * "J. D." would all match "John Doe".
159
 
     *
160
 
     * @method subWordMatch
161
 
     * @param {String} query Query to match
162
 
     * @param {Array} results Results to filter
163
 
     * @return {Array} Filtered results
164
 
     * @static
165
 
     */
166
 
    subWordMatch: function (query, results, caseSensitive) {
167
 
        // The caseSensitive parameter is only intended for use by
168
 
        // subWordMatchCase(). It's intentionally undocumented.
169
 
 
170
 
        if (!query) { return results; }
171
 
 
172
 
        var queryWords = WordBreak.getUniqueWords(query, {
173
 
            ignoreCase: !caseSensitive
174
 
        });
175
 
 
176
 
        return YArray.filter(results, function (result) {
177
 
            var resultText = caseSensitive ? result.text :
178
 
                    result.text.toLowerCase();
179
 
 
180
 
            return YArray.every(queryWords, function (queryWord) {
181
 
                return resultText.indexOf(queryWord) !== -1;
182
 
            });
183
 
        });
184
 
    },
185
 
 
186
 
    /**
187
 
     * Case-sensitive version of <code>subWordMatch()</code>.
188
 
     *
189
 
     * @method subWordMatchCase
190
 
     * @param {String} query Query to match
191
 
     * @param {Array} results Results to filter
192
 
     * @return {Array} Filtered results
193
 
     * @static
194
 
     */
195
 
    subWordMatchCase: function (query, results) {
196
 
        return Filters.subWordMatch(query, results, true);
197
 
    },
198
 
 
199
 
    /**
200
 
     * Returns an array of results that contain all of the words in the query,
201
 
     * in any order. Non-word characters like whitespace and certain punctuation
202
 
     * are ignored. Case-insensitive.
203
 
     *
204
 
     * @method wordMatch
205
 
     * @param {String} query Query to match
206
 
     * @param {Array} results Results to filter
207
 
     * @return {Array} Filtered results
208
 
     * @static
209
 
     */
210
 
    wordMatch: function (query, results, caseSensitive) {
211
 
        // The caseSensitive parameter is only intended for use by
212
 
        // wordMatchCase(). It's intentionally undocumented.
213
 
 
214
 
        if (!query) { return results; }
215
 
 
216
 
        var options    = {ignoreCase: !caseSensitive},
217
 
            queryWords = WordBreak.getUniqueWords(query, options);
218
 
 
219
 
        return YArray.filter(results, function (result) {
220
 
            // Convert resultWords array to a hash for fast lookup.
221
 
            var resultWords = YArray.hash(WordBreak.getUniqueWords(result.text,
222
 
                                options));
223
 
 
224
 
            return YArray.every(queryWords, function (word) {
225
 
                return YObject.owns(resultWords, word);
226
 
            });
227
 
        });
228
 
    },
229
 
 
230
 
    /**
231
 
     * Case-sensitive version of <code>wordMatch()</code>.
232
 
     *
233
 
     * @method wordMatchCase
234
 
     * @param {String} query Query to match
235
 
     * @param {Array} results Results to filter
236
 
     * @return {Array} Filtered results
237
 
     * @static
238
 
     */
239
 
    wordMatchCase: function (query, results) {
240
 
        return Filters.wordMatch(query, results, true);
241
 
    }
242
 
});
243
 
 
244
 
 
245
 
}, '3.4.1' ,{requires:['array-extras', 'text-wordbreak']});