So, I tried something similar to what I had in mind and was able to
get it working. I'll put it here in case anyone wants it:

#####  ORIGINAL CODE  #####
highlight: function(value, term) {
        return value.replace(new RegExp("(?![^&;]+;)(?!<[^<>]*)(" +
term.replace(/([\^\$\(\)\[\]\{\}\*\.\+\?\|\\])/gi, "\\$1") + ")(?![^<>]
*>)(?![^&;]+;)", "gi"), "<strong>$1</strong>");
}

#####  MODIFIED CODE WITH ACCENTS-INSENSITIVE SUPPORT  #####
highlight : function(value, term)
{
        // Strip accents from 'term' for an accents-insensitive search
        term = stripAccents(term);

        var value_no_accents = stripAccents(value);
        var everything_except_term = value_no_accents.split(new RegExp(term,
"gi"));
        var highlighted_value = '';
        var current_position = 0;

        for (var n in everything_except_term)
        {
                // Get the part with accents, since they were stripped to make 
the
comparisson using RegExp, and add it to the final value
                var part_no_accents = everything_except_term[n];
                var part = value.substr(current_position,
part_no_accents.length);  //--- this one with accents!!!
                highlighted_value += part;

                // Add the part length to the current position
                current_position += part.length;

                // If its not the last part, add the accented and highlighted 
term
to the final value
                if (n < everything_except_term.length - 1)
                {
                        // Get the term with the original accentuation and add 
it
highlighted to the final value
                        var termo_local = value.substr(current_position, 
term.length);
                        highlighted_value += "<strong>" + termo_local + 
"</strong>";

                        // Update the current position
                        current_position += term.length;
                }
        }

        return highlighted_value;
}

Where the function to strip accents (Credits: 
http://scripterlative.com/?noaccent)
is:

function stripAccents(str)
{
        var rExps=[
        {re:/[\xC0-\xC6]/g, ch:'A'},
        {re:/[\xE0-\xE6]/g, ch:'a'},
        {re:/[\xC8-\xCB]/g, ch:'E'},
        {re:/[\xE8-\xEB]/g, ch:'e'},
        {re:/[\xCC-\xCF]/g, ch:'I'},
        {re:/[\xEC-\xEF]/g, ch:'i'},
        {re:/[\xD2-\xD6]/g, ch:'O'},
        {re:/[\xF2-\xF6]/g, ch:'o'},
        {re:/[\xD9-\xDC]/g, ch:'U'},
        {re:/[\xF9-\xFC]/g, ch:'u'},
        {re:/[\xD1]/g, ch:'N'},
        {re:/[\xF1]/g, ch:'n'} ];

        for(var i=0, len=rExps.length; i<len; i++)
                str=str.replace(rExps[i].re, rExps[i].ch);

        return str;
}

I'll send and e-mail to the plugin creator suggesting the inclusion of
an "ignoreAccents" option, which would toggle beetwen the original and
the modified code.

That's it. Thanks again for the help!

Reply via email to