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