Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save jindrichsirucek/04ba2649b3fdc5dc5a44d8ccc87e043a to your computer and use it in GitHub Desktop.
Save jindrichsirucek/04ba2649b3fdc5dc5a44d8ccc87e043a to your computer and use it in GitHub Desktop.
function sortUlozenkaSelect()
{
function localeCompareSupportsLocales() {
try {
'foo'.localeCompare('bar', 'i');
} catch (e) {
return e.name === 'RangeError';
}
return false;
}
var localParamSupport = localeCompareSupportsLocales();
var options = $("select[name='specify_3'] option").not(':first'); // Collect options
options.detach().sort(function(a,b) { // Detach from select, then Sort
var at = $(a).text();
var bt = $(b).text();
return localParamSupport ? at.localeCompare(bt,"cs"): at.localeCompare(bt);
});
options.appendTo("select[name='specify_3']");
}
sortUlozenkaSelect();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment