Created
September 7, 2012 10:00
-
-
Save oziks/3664787 to your computer and use it in GitHub Desktop.
jQuery contains selector insensitive (case and accented characters)
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
jQuery.expr[':'].contains = function(a, i, m) { | |
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: /[\xC7-\xE7]/g, ch: "c"}, | |
{re: /[\xD1]/g, ch: "N"}, | |
{re: /[\xF1]/g, ch: "n"} | |
]; | |
var element = $(a).text(); | |
var search = m[3]; | |
$.each(rExps, function() { | |
element = element.replace(this.re, this.ch); | |
search = search.replace(this.re, this.ch); | |
}); | |
return element.toUpperCase() | |
.indexOf(search.toUpperCase()) >= 0; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment