/*
Copyright (c) 2010, Yahoo! Inc. All rights reserved.
Code licensed under the BSD License:
http://developer.yahoo.com/yui/license.html
version: 3.3.0
build: 3167
*/
YUI.add('highlight-accentfold', function(Y) {
/**
* Adds accent-folding highlighters to Y.Highlight
.
*
* @module highlight
* @submodule highlight-accentfold
*/
/**
* @class Highlight
* @static
*/
var AccentFold = Y.Text.AccentFold,
Escape = Y.Escape,
EMPTY_OBJECT = {},
Highlight = Y.mix(Y.Highlight, {
// -- Public Static Methods ------------------------------------------------
/**
* Accent-folding version of all()
.
*
* @method allFold
* @param {String} haystack String to apply highlighting to.
* @param {String|Array} needles String or array of strings that should be
* highlighted.
* @param {Object} options (optional) Options object, which may contain
* zero or more of the following properties:
*
*
startsWith
is true
, matches
* must be anchored to the beginning of the string.
* start()
.
*
* @method startFold
* @param {String} haystack String to apply highlighting to.
* @param {String|Array} needles String or array of strings that should be
* highlighted.
* @return {String} Escaped and highlighted copy of haystack.
* @static
*/
startFold: function (haystack, needles) {
return Highlight.allFold(haystack, needles, {startsWith: true});
},
/**
* Accent-folding version of words()
.
*
* @method wordsFold
* @param {String} haystack String to apply highlighting to.
* @param {String|Array} needles String or array of strings containing words
* that should be highlighted. If a string is passed, it will be split
* into words; if an array is passed, it is assumed to have already been
* split.
* @return {String} Escaped and highlighted copy of haystack.
* @static
*/
wordsFold: function (haystack, needles) {
var template = Highlight._TEMPLATE;
return Highlight.words(haystack, AccentFold.fold(needles), {
mapper: function (word, needles) {
if (needles.hasOwnProperty(AccentFold.fold(word))) {
return template.replace(/\{s\}/g, Escape.html(word));
}
return Escape.html(word);
}
});
}
});
}, '3.3.0' ,{requires:['highlight-base', 'text-accentfold']});