Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function sortSelectOptions(selectElement) {
- $(selectElement).each(function(){
- var options = $(this).find('option').toArray();
- options.sort(function(a, b) {
- if (a.value === "") return -1;
- return a.text.localeCompare(b.text);
- });
- $(this).empty().append(options);
- if ($(this).find('option[selected="selected"]').length === 0) {
- $(this).find('option[value=""]').attr('selected', 'selected');
- }
- });
- }
- function sortNewSelectOptions(selectElement) {
- $(selectElement).each(function(){
- var options = $(this).find('option').toArray();
- options.sort(function(a, b) {
- if (a.value === "") return -1;
- return a.text.localeCompare(b.text);
- });
- $(this).empty().append(options);
- $(this).find('option[value=""]').attr('selected', 'selected');
- });
- }
- $(function() {
- sortSelectOptions('select[name^="post_dice"]');
- });
- $(document).on('click', '[href^="javascript:add_dice"]', function() {
- setTimeout(function() {
- $('select[name^="post_dice"][value=""]').each(function() {
- sortNewSelectOptions(this);
- });
- }, 100);
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement