]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - jssource/src_files/include/javascript/yui3/build/autocomplete/autocomplete-highlighters-accentfold.js
Release 6.5.0
[Github/sugarcrm.git] / jssource / src_files / include / javascript / yui3 / build / autocomplete / autocomplete-highlighters-accentfold.js
1 /*
2 Copyright (c) 2010, Yahoo! Inc. All rights reserved.
3 Code licensed under the BSD License:
4 http://developer.yahoo.com/yui/license.html
5 version: 3.3.0
6 build: 3167
7 */
8 YUI.add('autocomplete-highlighters-accentfold', function(Y) {
9
10 /**
11  * <p>
12  * Provides pre-built accent-folding result highlighters for AutoComplete.
13  * </p>
14  *
15  * <p>
16  * These highlighters are similar to the ones provided by the
17  * <code>autocomplete-highlighters</code> module, but use accent-aware
18  * comparisons. For example, "resume" and "résumé" will be considered equal when
19  * using the accent-folding highlighters.
20  * </p>
21  *
22  * @module autocomplete
23  * @submodule autocomplete-highlighters-accentfold
24  */
25
26 /**
27  * @class AutoCompleteHighlighters
28  * @static
29  */
30
31 var Highlight = Y.Highlight,
32     YArray    = Y.Array;
33
34 Y.mix(Y.namespace('AutoCompleteHighlighters'), {
35     /**
36      * Accent-folding version of <code>charMatch()</code>.
37      *
38      * @method charMatchFold
39      * @param {String} query Query to match
40      * @param {Array} results Results to highlight
41      * @return {Array} Highlighted results
42      * @static
43      */
44     charMatchFold: function (query, results) {
45         var queryChars = YArray.unique(query.split(''));
46
47         return YArray.map(results, function (result) {
48             return Highlight.allFold(result.text, queryChars);
49         });
50     },
51
52     /**
53      * Accent-folding version of <code>phraseMatch()</code>.
54      *
55      * @method phraseMatchFold
56      * @param {String} query Query to match
57      * @param {Array} results Results to highlight
58      * @return {Array} Highlighted results
59      * @static
60      */
61     phraseMatchFold: function (query, results) {
62         return YArray.map(results, function (result) {
63             return Highlight.allFold(result.text, [query]);
64         });
65     },
66
67     /**
68      * Accent-folding version of <code>startsWith()</code>.
69      *
70      * @method startsWithFold
71      * @param {String} query Query to match
72      * @param {Array} results Results to highlight
73      * @return {Array} Highlighted results
74      * @static
75      */
76     startsWithFold: function (query, results) {
77         return YArray.map(results, function (result) {
78             return Highlight.allFold(result.text, [query], {
79                 startsWith: true
80             });
81         });
82     },
83
84     /**
85      * Accent-folding version of <code>wordMatch()</code>.
86      *
87      * @method wordMatchFold
88      * @param {String} query Query to match
89      * @param {Array} results Results to highlight
90      * @return {Array} Highlighted results
91      * @static
92      */
93     wordMatchFold: function (query, results) {
94         return YArray.map(results, function (result) {
95             return Highlight.wordsFold(result.text, query);
96         });
97     }
98 });
99
100
101 }, '3.3.0' ,{requires:['array-extras', 'highlight-accentfold']});