[ Index ] |
PHP Cross Reference of Unnamed Project |
[Summary view] [Print] [Text view]
1 /* 2 YUI 3.17.2 (build 9c3c78e) 3 Copyright 2014 Yahoo! Inc. All rights reserved. 4 Licensed under the BSD License. 5 http://yuilibrary.com/license/ 6 */ 7 8 YUI.add('autocomplete-filters-accentfold', function (Y, NAME) { 9 10 /** 11 Provides pre-built accent-folding result matching filters for AutoComplete. 12 13 These filters are similar to the ones provided by the `autocomplete-filters` 14 module, but use accent-aware comparisons. For example, "resume" and "résumé" 15 will be considered equal when using the accent-folding filters. 16 17 @module autocomplete 18 @submodule autocomplete-filters-accentfold 19 **/ 20 21 /** 22 @class AutoCompleteFilters 23 @static 24 **/ 25 26 var AccentFold = Y.Text.AccentFold, 27 WordBreak = Y.Text.WordBreak, 28 YArray = Y.Array, 29 YObject = Y.Object; 30 31 Y.mix(Y.namespace('AutoCompleteFilters'), { 32 /** 33 Accent folding version of `charMatch()`. 34 35 @method charMatchFold 36 @param {String} query Query to match 37 @param {Array} results Results to filter 38 @return {Array} Filtered results 39 @static 40 **/ 41 charMatchFold: function (query, results) { 42 if (!query) { return results; } 43 44 var queryChars = YArray.unique(AccentFold.fold(query).split('')); 45 46 return YArray.filter(results, function (result) { 47 var text = AccentFold.fold(result.text); 48 49 return YArray.every(queryChars, function (chr) { 50 return text.indexOf(chr) !== -1; 51 }); 52 }); 53 }, 54 55 /** 56 Accent folding version of `phraseMatch()`. 57 58 @method phraseMatchFold 59 @param {String} query Query to match 60 @param {Array} results Results to filter 61 @return {Array} Filtered results 62 @static 63 **/ 64 phraseMatchFold: function (query, results) { 65 if (!query) { return results; } 66 67 query = AccentFold.fold(query); 68 69 return YArray.filter(results, function (result) { 70 return AccentFold.fold(result.text).indexOf(query) !== -1; 71 }); 72 }, 73 74 /** 75 Accent folding version of `startsWith()`. 76 77 @method startsWithFold 78 @param {String} query Query to match 79 @param {Array} results Results to filter 80 @return {Array} Filtered results 81 @static 82 **/ 83 startsWithFold: function (query, results) { 84 if (!query) { return results; } 85 86 query = AccentFold.fold(query); 87 88 return YArray.filter(results, function (result) { 89 return AccentFold.fold(result.text).indexOf(query) === 0; 90 }); 91 }, 92 93 /** 94 Accent folding version of `subWordMatch()`. 95 96 @method subWordMatchFold 97 @param {String} query Query to match 98 @param {Array} results Results to filter 99 @return {Array} Filtered results 100 @static 101 **/ 102 subWordMatchFold: function (query, results) { 103 if (!query) { return results; } 104 105 var queryWords = WordBreak.getUniqueWords(AccentFold.fold(query)); 106 107 return YArray.filter(results, function (result) { 108 var resultText = AccentFold.fold(result.text); 109 110 return YArray.every(queryWords, function (queryWord) { 111 return resultText.indexOf(queryWord) !== -1; 112 }); 113 }); 114 }, 115 116 /** 117 Accent folding version of `wordMatch()`. 118 119 @method wordMatchFold 120 @param {String} query Query to match 121 @param {Array} results Results to filter 122 @return {Array} Filtered results 123 @static 124 **/ 125 wordMatchFold: function (query, results) { 126 if (!query) { return results; } 127 128 var queryWords = WordBreak.getUniqueWords(AccentFold.fold(query)); 129 130 return YArray.filter(results, function (result) { 131 // Convert resultWords array to a hash for fast lookup. 132 var resultWords = YArray.hash(WordBreak.getUniqueWords( 133 AccentFold.fold(result.text))); 134 135 return YArray.every(queryWords, function (word) { 136 return YObject.owns(resultWords, word); 137 }); 138 }); 139 } 140 }); 141 142 143 }, '3.17.2', {"requires": ["array-extras", "text-accentfold", "text-wordbreak"]});
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Aug 11 10:00:09 2016 | Cross-referenced by PHPXref 0.7.1 |