Skip to content

Instantly share code, notes, and snippets.

@carlosrberto
Created May 28, 2011 20:06
Show Gist options
  • Save carlosrberto/997178 to your computer and use it in GitHub Desktop.
Save carlosrberto/997178 to your computer and use it in GitHub Desktop.
jquery selectors tests
function normalizeAccents(s){
// cache para ganho de performance
if ( !! normalizeAccents.cache[s] ) return normalizeAccents.cache[s];
var r=s.toLowerCase();
//r = r.replace(new RegExp("\\s", 'g'),"");
r = r.replace(new RegExp("[àáâãäå]", 'g'),"a");
r = r.replace(new RegExp("æ", 'g'),"ae");
r = r.replace(new RegExp("ç", 'g'),"c");
r = r.replace(new RegExp("[èéêë]", 'g'),"e");
r = r.replace(new RegExp("[ìíîï]", 'g'),"i");
r = r.replace(new RegExp("ñ", 'g'),"n");
r = r.replace(new RegExp("[òóôõö]", 'g'),"o");
r = r.replace(new RegExp("œ", 'g'),"oe");
r = r.replace(new RegExp("[ùúûü]", 'g'),"u");
r = r.replace(new RegExp("[ýÿ]", 'g'),"y");
//r = r.replace(new RegExp("\\W", 'g'),"");
return normalizeAccents.cache[s] = r;
};
normalizeAccents.cache = {}
// seletor jQuery customizado para retornar elementos de acordo com o texto contido nele, insensitivo e ignora acentuação
jQuery.expr[ ':' ].icontains = function( a,i,m ){
return normalizeAccents(jQuery(a).text()).match( new RegExp( "\\b" + normalizeAccents( m[ 3 ] ), "gi" ) );
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment