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