MDL-32843 import YUI 3.5.1
[moodle.git] / lib / yui / 3.5.1 / build / autocomplete-highlighters-accentfold / autocomplete-highlighters-accentfold.js
blob383e3d2ee1e24175f086c9bbdb2cd0af211994f0
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-accentfold', function(Y) {
9 /**
10 Provides pre-built accent-folding result highlighters for AutoComplete.
12 These highlighters are similar to the ones provided by the `autocomplete-
13 highlighters` module, but use accent-aware comparisons. For example, "resume"
14 and "résumé" will be considered equal when using the accent-folding
15 highlighters.
17 @module autocomplete
18 @submodule autocomplete-highlighters-accentfold
19 **/
21 /**
22 @class AutoCompleteHighlighters
23 @static
24 **/
26 var Highlight = Y.Highlight,
27     YArray    = Y.Array;
29 Y.mix(Y.namespace('AutoCompleteHighlighters'), {
30     /**
31     Accent-folding version of `charMatch()`.
33     @method charMatchFold
34     @param {String} query Query to match
35     @param {Array} results Results to highlight
36     @return {Array} Highlighted results
37     @static
38     **/
39     charMatchFold: function (query, results) {
40         var queryChars = YArray.unique(query.split(''));
42         return YArray.map(results, function (result) {
43             return Highlight.allFold(result.text, queryChars);
44         });
45     },
47     /**
48     Accent-folding version of `phraseMatch()`.
50     @method phraseMatchFold
51     @param {String} query Query to match
52     @param {Array} results Results to highlight
53     @return {Array} Highlighted results
54     @static
55     **/
56     phraseMatchFold: function (query, results) {
57         return YArray.map(results, function (result) {
58             return Highlight.allFold(result.text, [query]);
59         });
60     },
62     /**
63     Accent-folding version of `startsWith()`.
65     @method startsWithFold
66     @param {String} query Query to match
67     @param {Array} results Results to highlight
68     @return {Array} Highlighted results
69     @static
70     **/
71     startsWithFold: function (query, results) {
72         return YArray.map(results, function (result) {
73             return Highlight.allFold(result.text, [query], {
74                 startsWith: true
75             });
76         });
77     },
79     /**
80     Accent-folding version of `subWordMatch()`.
82     @method subWordMatchFold
83     @param {String} query Query to match
84     @param {Array} results Results to highlight
85     @return {Array} Highlighted results
86     @static
87     **/
88     subWordMatchFold: function (query, results) {
89         var queryWords = Y.Text.WordBreak.getUniqueWords(query);
91         return YArray.map(results, function (result) {
92             return Highlight.allFold(result.text, queryWords);
93         });
94     },
96     /**
97     Accent-folding version of `wordMatch()`.
99     @method wordMatchFold
100     @param {String} query Query to match
101     @param {Array} results Results to highlight
102     @return {Array} Highlighted results
103     @static
104     **/
105     wordMatchFold: function (query, results) {
106         return YArray.map(results, function (result) {
107             return Highlight.wordsFold(result.text, query);
108         });
109     }
113 }, '3.5.1' ,{requires:['array-extras', 'highlight-accentfold']});