autocomplete-filters-accentfold-debug.js revision 4ead18554e0008d06914f75a9b6c2d3a1c590d74
13fdd42f1fc3e519650037a920e6a54c24973866vboxsyncYUI.add('autocomplete-filters-accentfold', function(Y) {
13fdd42f1fc3e519650037a920e6a54c24973866vboxsync
13fdd42f1fc3e519650037a920e6a54c24973866vboxsync/**
13fdd42f1fc3e519650037a920e6a54c24973866vboxsync * <p>
13fdd42f1fc3e519650037a920e6a54c24973866vboxsync * Provides pre-built accent-folding result matching filters for AutoComplete.
1c94c0a63ba68be1a7b2c640e70d7a06464e4fcavboxsync * </p>
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync *
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync * <p>
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync * These filters are similar to the ones provided by the
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync * <code>autocomplete-filters</code> module, but use accent-aware comparisons.
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync * For example, "resume" and "résumé" will be considered equal when using the
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync * accent-folding filters.
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync * </p>
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync *
565c6b62913edd14704b060e3172bba10b1fe12evboxsync * @module autocomplete
1c94c0a63ba68be1a7b2c640e70d7a06464e4fcavboxsync * @submodule autocomplete-filters-accentfold
1c94c0a63ba68be1a7b2c640e70d7a06464e4fcavboxsync */
1c94c0a63ba68be1a7b2c640e70d7a06464e4fcavboxsync
1c94c0a63ba68be1a7b2c640e70d7a06464e4fcavboxsync/**
13fdd42f1fc3e519650037a920e6a54c24973866vboxsync * @class AutoCompleteFilters
66cd15f94910b1afc64c42375d40e01d5d33ad2fvboxsync * @static
66cd15f94910b1afc64c42375d40e01d5d33ad2fvboxsync */
66cd15f94910b1afc64c42375d40e01d5d33ad2fvboxsync
66cd15f94910b1afc64c42375d40e01d5d33ad2fvboxsyncvar AccentFold = Y.Text.AccentFold,
66cd15f94910b1afc64c42375d40e01d5d33ad2fvboxsync WordBreak = Y.Text.WordBreak,
3dc9141e9dc45634498a9b543477bec0bcf5dab8vboxsync YArray = Y.Array,
3dc9141e9dc45634498a9b543477bec0bcf5dab8vboxsync YObject = Y.Object;
3dc9141e9dc45634498a9b543477bec0bcf5dab8vboxsync
3dc9141e9dc45634498a9b543477bec0bcf5dab8vboxsyncY.mix(Y.namespace('AutoCompleteFilters'), {
3dc9141e9dc45634498a9b543477bec0bcf5dab8vboxsync /**
66cd15f94910b1afc64c42375d40e01d5d33ad2fvboxsync * Accent folding version of <code>charMatch()</code>.
66cd15f94910b1afc64c42375d40e01d5d33ad2fvboxsync *
66cd15f94910b1afc64c42375d40e01d5d33ad2fvboxsync * @method charMatchFold
66cd15f94910b1afc64c42375d40e01d5d33ad2fvboxsync * @param {String} query Query to match
66cd15f94910b1afc64c42375d40e01d5d33ad2fvboxsync * @param {Array} results Results to filter
66cd15f94910b1afc64c42375d40e01d5d33ad2fvboxsync * @return {Array} Filtered results
66cd15f94910b1afc64c42375d40e01d5d33ad2fvboxsync * @static
66cd15f94910b1afc64c42375d40e01d5d33ad2fvboxsync */
66cd15f94910b1afc64c42375d40e01d5d33ad2fvboxsync charMatchFold: function (query, results) {
66cd15f94910b1afc64c42375d40e01d5d33ad2fvboxsync if (!query) { return results; }
66cd15f94910b1afc64c42375d40e01d5d33ad2fvboxsync
3dc9141e9dc45634498a9b543477bec0bcf5dab8vboxsync var queryChars = YArray.unique(AccentFold.fold(query).split(''));
66cd15f94910b1afc64c42375d40e01d5d33ad2fvboxsync
66cd15f94910b1afc64c42375d40e01d5d33ad2fvboxsync return YArray.filter(results, function (result) {
66cd15f94910b1afc64c42375d40e01d5d33ad2fvboxsync var text = AccentFold.fold(result.text);
3dc9141e9dc45634498a9b543477bec0bcf5dab8vboxsync
3dc9141e9dc45634498a9b543477bec0bcf5dab8vboxsync return YArray.every(queryChars, function (chr) {
3dc9141e9dc45634498a9b543477bec0bcf5dab8vboxsync return text.indexOf(chr) !== -1;
66cd15f94910b1afc64c42375d40e01d5d33ad2fvboxsync });
66cd15f94910b1afc64c42375d40e01d5d33ad2fvboxsync });
66cd15f94910b1afc64c42375d40e01d5d33ad2fvboxsync },
66cd15f94910b1afc64c42375d40e01d5d33ad2fvboxsync
66cd15f94910b1afc64c42375d40e01d5d33ad2fvboxsync /**
66cd15f94910b1afc64c42375d40e01d5d33ad2fvboxsync * Accent folding version of <code>phraseMatch()</code>.
66cd15f94910b1afc64c42375d40e01d5d33ad2fvboxsync *
66cd15f94910b1afc64c42375d40e01d5d33ad2fvboxsync * @method phraseMatchFold
66cd15f94910b1afc64c42375d40e01d5d33ad2fvboxsync * @param {String} query Query to match
3dc9141e9dc45634498a9b543477bec0bcf5dab8vboxsync * @param {Array} results Results to filter
3dc9141e9dc45634498a9b543477bec0bcf5dab8vboxsync * @return {Array} Filtered results
3dc9141e9dc45634498a9b543477bec0bcf5dab8vboxsync * @static
66cd15f94910b1afc64c42375d40e01d5d33ad2fvboxsync */
66cd15f94910b1afc64c42375d40e01d5d33ad2fvboxsync phraseMatchFold: function (query, results) {
66cd15f94910b1afc64c42375d40e01d5d33ad2fvboxsync if (!query) { return results; }
fa8e26644bdce3fe8590a2fd82433dc8bdf55414vboxsync
fa8e26644bdce3fe8590a2fd82433dc8bdf55414vboxsync query = AccentFold.fold(query);
13fdd42f1fc3e519650037a920e6a54c24973866vboxsync
13fdd42f1fc3e519650037a920e6a54c24973866vboxsync return YArray.filter(results, function (result) {
e7aa635d70dd0cdf083287ec896fe8cca2775466vboxsync return AccentFold.fold(result.text).indexOf(query) !== -1;
e7aa635d70dd0cdf083287ec896fe8cca2775466vboxsync });
e7aa635d70dd0cdf083287ec896fe8cca2775466vboxsync },
13fdd42f1fc3e519650037a920e6a54c24973866vboxsync
13fdd42f1fc3e519650037a920e6a54c24973866vboxsync /**
13fdd42f1fc3e519650037a920e6a54c24973866vboxsync * Accent folding version of <code>startsWith()</code>.
13fdd42f1fc3e519650037a920e6a54c24973866vboxsync *
13fdd42f1fc3e519650037a920e6a54c24973866vboxsync * @method startsWithFold
13fdd42f1fc3e519650037a920e6a54c24973866vboxsync * @param {String} query Query to match
7ca4727ba2f9e3703771a308b11cd551f3fca4fdvboxsync * @param {Array} results Results to filter
7ca4727ba2f9e3703771a308b11cd551f3fca4fdvboxsync * @return {Array} Filtered results
2043260aa6abeee8eb8cf0309cebb97ede45851evboxsync * @static
2043260aa6abeee8eb8cf0309cebb97ede45851evboxsync */
e7aa635d70dd0cdf083287ec896fe8cca2775466vboxsync startsWithFold: function (query, results) {
e7aa635d70dd0cdf083287ec896fe8cca2775466vboxsync if (!query) { return results; }
e7aa635d70dd0cdf083287ec896fe8cca2775466vboxsync
e7aa635d70dd0cdf083287ec896fe8cca2775466vboxsync query = AccentFold.fold(query);
e7aa635d70dd0cdf083287ec896fe8cca2775466vboxsync
2043260aa6abeee8eb8cf0309cebb97ede45851evboxsync return YArray.filter(results, function (result) {
e7aa635d70dd0cdf083287ec896fe8cca2775466vboxsync return AccentFold.fold(result.text).indexOf(query) === 0;
13fdd42f1fc3e519650037a920e6a54c24973866vboxsync });
13fdd42f1fc3e519650037a920e6a54c24973866vboxsync },
13fdd42f1fc3e519650037a920e6a54c24973866vboxsync
13fdd42f1fc3e519650037a920e6a54c24973866vboxsync /**
9868c07279330f31ed91aa986bec707b7e8635a3vboxsync * Accent folding version of <code>subWordMatch()</code>.
9868c07279330f31ed91aa986bec707b7e8635a3vboxsync *
9868c07279330f31ed91aa986bec707b7e8635a3vboxsync * @method subWordMatchFold
9868c07279330f31ed91aa986bec707b7e8635a3vboxsync * @param {String} query Query to match
9868c07279330f31ed91aa986bec707b7e8635a3vboxsync * @param {Array} results Results to filter
6ba8963f8a097b33938cd6fbcd6b63faf6d26889vboxsync * @return {Array} Filtered results
9868c07279330f31ed91aa986bec707b7e8635a3vboxsync * @static
9868c07279330f31ed91aa986bec707b7e8635a3vboxsync */
9868c07279330f31ed91aa986bec707b7e8635a3vboxsync subWordMatchFold: function (query, results) {
13fdd42f1fc3e519650037a920e6a54c24973866vboxsync if (!query) { return results; }
9868c07279330f31ed91aa986bec707b7e8635a3vboxsync
9868c07279330f31ed91aa986bec707b7e8635a3vboxsync var queryWords = WordBreak.getUniqueWords(AccentFold.fold(query));
9868c07279330f31ed91aa986bec707b7e8635a3vboxsync
9868c07279330f31ed91aa986bec707b7e8635a3vboxsync return YArray.filter(results, function (result) {
9868c07279330f31ed91aa986bec707b7e8635a3vboxsync var resultText = AccentFold.fold(result.text);
9868c07279330f31ed91aa986bec707b7e8635a3vboxsync
9868c07279330f31ed91aa986bec707b7e8635a3vboxsync return YArray.every(queryWords, function (queryWord) {
9868c07279330f31ed91aa986bec707b7e8635a3vboxsync return resultText.indexOf(queryWord) !== -1;
9868c07279330f31ed91aa986bec707b7e8635a3vboxsync });
9868c07279330f31ed91aa986bec707b7e8635a3vboxsync });
9868c07279330f31ed91aa986bec707b7e8635a3vboxsync },
9868c07279330f31ed91aa986bec707b7e8635a3vboxsync
13fdd42f1fc3e519650037a920e6a54c24973866vboxsync /**
13fdd42f1fc3e519650037a920e6a54c24973866vboxsync * Accent folding version of <code>wordMatch()</code>.
9868c07279330f31ed91aa986bec707b7e8635a3vboxsync *
9868c07279330f31ed91aa986bec707b7e8635a3vboxsync * @method wordMatchFold
9868c07279330f31ed91aa986bec707b7e8635a3vboxsync * @param {String} query Query to match
9868c07279330f31ed91aa986bec707b7e8635a3vboxsync * @param {Array} results Results to filter
9868c07279330f31ed91aa986bec707b7e8635a3vboxsync * @return {Array} Filtered results
9868c07279330f31ed91aa986bec707b7e8635a3vboxsync * @static
9868c07279330f31ed91aa986bec707b7e8635a3vboxsync */
9868c07279330f31ed91aa986bec707b7e8635a3vboxsync wordMatchFold: function (query, results) {
13fdd42f1fc3e519650037a920e6a54c24973866vboxsync if (!query) { return results; }
13fdd42f1fc3e519650037a920e6a54c24973866vboxsync
9868c07279330f31ed91aa986bec707b7e8635a3vboxsync var queryWords = WordBreak.getUniqueWords(AccentFold.fold(query));
9868c07279330f31ed91aa986bec707b7e8635a3vboxsync
9868c07279330f31ed91aa986bec707b7e8635a3vboxsync return YArray.filter(results, function (result) {
9868c07279330f31ed91aa986bec707b7e8635a3vboxsync // Convert resultWords array to a hash for fast lookup.
9868c07279330f31ed91aa986bec707b7e8635a3vboxsync var resultWords = YArray.hash(WordBreak.getUniqueWords(
9868c07279330f31ed91aa986bec707b7e8635a3vboxsync AccentFold.fold(result.text)));
9868c07279330f31ed91aa986bec707b7e8635a3vboxsync
9868c07279330f31ed91aa986bec707b7e8635a3vboxsync return YArray.every(queryWords, function (word) {
9868c07279330f31ed91aa986bec707b7e8635a3vboxsync return YObject.owns(resultWords, word);
9868c07279330f31ed91aa986bec707b7e8635a3vboxsync });
9868c07279330f31ed91aa986bec707b7e8635a3vboxsync });
13fdd42f1fc3e519650037a920e6a54c24973866vboxsync }
9868c07279330f31ed91aa986bec707b7e8635a3vboxsync});
df409c2a6d13641b0586a36103d015cc8d76da53vboxsync
df409c2a6d13641b0586a36103d015cc8d76da53vboxsync
9868c07279330f31ed91aa986bec707b7e8635a3vboxsync}, '@VERSION@' ,{requires:['array-extras', 'text-accentfold', 'text-wordbreak']});
df409c2a6d13641b0586a36103d015cc8d76da53vboxsync