-
Notifications
You must be signed in to change notification settings - Fork 3
/
select2.sortable.min.js
1 lines (1 loc) · 1.13 KB
/
select2.sortable.min.js
1
!function(e){function t(e){return e.prev(".select2-container").find("ul.select2-choices")}function i(t,i){t.sortable({forcePlaceholderSize:!0,items:"li.select2-search-choice",placeholder:"<li> </li>"}),i&&i.bindSortEvent&&i.$select&&t.bind("sortupdate",function(){e(t.find("li.select2-search-choice").get().reverse()).each(function(){var t=e(this).data("select2Data").id,c=i.$select.find('option[value="'+t+'"]')[0];i.$select.prepend(c)})})}function c(e){var c,n;e.select2(),n=t(e),c=new MutationObserver(function(){i(n),c.disconnect()}),e.on("select2-selecting",function(){c.observe(n.get(0),{subtree:!1,childList:!0,attributes:!1})}),i(n,{bindSortEvent:!0,$select:e}),e.data("hasSelect2Sortable",!0)}function n(i,c){var n=t(i),r=n.find(".select2-search-choice");e.each(c,function(t,i){r.each(function(){i==e(this).data("select2Data").id&&e(this).insertBefore(n.find(".select2-search-field"))})}),n.trigger("sortupdate")}e.fn.extend({select2Sortable:function(t){return this.each(function(){var i=e(this);if(i.prop("multiple")){if(!i.data("hasSelect2Sortable")){c(i);var r=i.attr("data-order");r&&n(i,r.split(","))}t&&n(i,t)}}),this}})}(window.jQuery);