Last active
April 28, 2018 04:52
-
-
Save savayer/2966ec60351b39f684bf928a70563f9d to your computer and use it in GitHub Desktop.
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
var list = $(".type_data_articles ul.select2-selection__rendered"), | |
list_li = $(".type_data_articles ul.select2-selection__rendered li.select2-selection__choice"), | |
list_b = $(".type_data_articles ul.select2-selection__rendered b"), | |
select2 = $(".type_data_articles .select2_from_array"), | |
select2Backup = $(".type_data_articles .select2_from_array option"); | |
list.sortable({ | |
containment: 'parent', | |
update: function() { | |
var select2val = []; | |
$(".type_data_articles ul.select2-selection__rendered li.select2-selection__choice").each(function() { | |
select2val.push( $(this).children('b').data('id')); | |
}); | |
select2.empty().trigger('change'); | |
for (var i = 0; i < select2val.length; i++) { | |
select2Backup.each(function(index, elem){ | |
if ($(this).attr('value') == select2val[i]) { | |
var option = new Option($(this).text(), $(this).attr('value'), true, true); | |
option.setAttribute('data-category', $(this).attr('data-category')); | |
option.title = $(this).attr('title'); | |
select2.append(option).trigger('change'); | |
return false; | |
} | |
}); | |
} | |
select2Backup.each(function(index, elem){ | |
if (select2val.indexOf( +$(this).attr('value') ) == -1) { | |
var option = new Option($(this).text(), $(this).attr('value'), false, false); | |
option.title = $(this).attr('title'); | |
option.setAttribute('data-category', $(this).data('category')); | |
select2.append(option).trigger('change'); | |
} | |
}); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment