src/myams/resources/js/ext/jquery-select2-sortable.min.js
changeset 5 c9c69b13d884
parent 0 f05d7aea098a
equal deleted inserted replaced
4:440e5d8fae8f 5:c9c69b13d884
     1 !function(e){e.fn.extend({select2SortableOrder:function(){var t=this.filter("[multiple]");return t.each(function(){var t=e(this);if("object"!=typeof t.data("select2"))return!1;var s,r=t.siblings(".select2-container");if("hidden"===t.attr("type")){var i=r.data("select2"),o=i.opts.separator,l=[];e.each(i.data(),function(){l.push(this.id)}),t.val(l.join(o))}else{var n=[];t.find("optgroup").each(function(e,t){n.push(t)}),t.find("option").each(function(t,s){var r=this;void 0===e(this).parent("optgroup").prop("label")&&(""===this.value||this.selected||n.push(r))}),(s=e(r.find('.select2-choices li[class!="select2-search-field"]').map(function(){if(this){var s=e(this).data("select2Data").id;return t.find('option[value="'+s+'"]')[0]}}))).push.apply(s,n),t.children().remove(),t.append(s)}}),t},select2Sortable:function(){var t=Array.prototype.slice.call(arguments,0),s=this.filter("[multiple]");if(0===t.length||"object"==typeof t[0]){var r=e.extend({bindOrder:"formSubmit",sortableOptions:{placeholder:"ui-state-highlight",items:"li:not(.select2-search-field)",tolerance:"pointer"}},t[0]);"object"!=typeof s.data("select2")&&s.select2(),s.each(function(){var t=e(this),s=t.siblings(".select2-container").find(".select2-choices");switch(s.sortable(r.sortableOptions),r.bindOrder){case"sortableStop":s.on("sortstop.select2sortable",function(e,s){t.select2SortableOrder()}),t.on("change",function(t){e(this).select2SortableOrder()});break;default:t.closest("form").unbind("submit.select2sortable").on("submit.select2sortable",function(){t.select2SortableOrder()})}})}else if(t[0],!0){if(-1==e.inArray(t[0],["destroy"]))throw"Unknown method: "+t[0];"destroy"===t[0]&&s.select2SortableDestroy()}return s},select2SortableDestroy:function(){var t=this.filter("[multiple]");return t.each(function(){var t=e(this),s=t.parent().find(".select2-choices");t.closest("form").unbind("submit.select2sortable"),s.unbind("sortstop.select2sortable"),s.sortable("destroy")}),t}})}(jQuery);
     1 !function(e){e.fn.extend({select2SortableOrder:function(){var t=this.filter("[multiple]");return t.each((function(){var t=e(this);if("object"!=typeof t.data("select2"))return!1;var s,r=t.siblings(".select2-container");if("hidden"===t.attr("type")){var i=r.data("select2"),o=i.opts.separator,l=[];e.each(i.data(),(function(){l.push(this.id)})),t.val(l.join(o))}else{var n=[];t.find("optgroup").each((function(e,t){n.push(t)})),t.find("option").each((function(t,s){void 0===e(this).parent("optgroup").prop("label")&&(""===this.value||this.selected||n.push(this))})),(s=e(r.find('.select2-choices li[class!="select2-search-field"]').map((function(){if(this){var s=e(this).data("select2Data").id;return t.find('option[value="'+s+'"]')[0]}})))).push.apply(s,n),t.children().remove(),t.append(s)}})),t},select2Sortable:function(){var t=Array.prototype.slice.call(arguments,0),s=this.filter("[multiple]"),r=["destroy"];if(0===t.length||"object"==typeof t[0]){var i={bindOrder:"formSubmit",sortableOptions:{placeholder:"ui-state-highlight",items:"li:not(.select2-search-field)",tolerance:"pointer"}},o=e.extend(i,t[0]);"object"!=typeof s.data("select2")&&s.select2(),s.each((function(){var t=e(this),s=t.siblings(".select2-container").find(".select2-choices");switch(s.sortable(o.sortableOptions),o.bindOrder){case"sortableStop":s.on("sortstop.select2sortable",(function(e,s){t.select2SortableOrder()})),t.on("change",(function(t){e(this).select2SortableOrder()}));break;default:t.closest("form").unbind("submit.select2sortable").on("submit.select2sortable",(function(){t.select2SortableOrder()}))}}))}else{if(t[0],-1==e.inArray(t[0],r))throw"Unknown method: "+t[0];"destroy"===t[0]&&s.select2SortableDestroy()}return s},select2SortableDestroy:function(){var t=this.filter("[multiple]");return t.each((function(){var t=e(this),s=t.parent().find(".select2-choices");t.closest("form").unbind("submit.select2sortable"),s.unbind("sortstop.select2sortable"),s.sortable("destroy")})),t}})}(jQuery);