Dashboard sipadu mbip
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

autocomplete-highlighters-accentfold.js 3.3KB

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