Created
May 28, 2011 20:06
-
-
Save carlosrberto/997178 to your computer and use it in GitHub Desktop.
jquery selectors tests
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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