Created
June 28, 2011 06:03
-
-
Save haldun/1050583 to your computer and use it in GitHub Desktop.
Fix for turkish locale compare for browsers
This file contains hidden or 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(){ | |
String.prototype.originalLocaleCompare = String.prototype.localeCompare; | |
var alphabet = ["A", "a", "B", "b", "C", "c", "Ç", "ç", "D", "d", "E", "e", | |
"F", "f", "G", "g", "Ğ", "ğ", "H", "h", "I", "ı", "İ", "i", | |
"J", "j", "K", "k", "L", "l", "M", "m", "N", "n", "O", "o", | |
"Ö", "ö", "P", "p", "R", "r", "S", "s", "Ş", "ş", "T", "t", | |
"U", "u", "Ü", "ü", "V", "v", "Y", "y", "Z", "z"]; | |
String.prototype.localeCompare = function(b) { | |
var a = this; | |
if (a == b) { | |
return 0; | |
} | |
for (var i = 0, _len = Math.min(a.length, b.length); i < _len; i++) { | |
var x = a.charAt(i), y = b.charAt(i); | |
if (x === y) { | |
continue; | |
} | |
var ix = alphabet.indexOf(x), iy = alphabet.indexOf(y); | |
if (ix != -1 && iy != -1) { | |
return ix < iy ? -1 : 1; | |
} | |
return x.originalLocaleCompare(y); | |
} | |
}; | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Fixed for IE