bludit/bl-kernel/js/jquery.sortable.min.js

1 line
1.8 KiB
JavaScript
Executable File

(function(n){var t,i=n();n.fn.sortable=function(r){var u=String(r);return r=n.extend({connectWith:!1},r),this.each(function(){var o,s,h,e,f;if(/^enable|disable|destroy$/.test(u)){e=n(this).children(n(this).data("items")).attr("draggable",u=="enable");u=="destroy"&&e.add(this).removeData("connectWith items").off("dragstart.h5s dragend.h5s selectstart.h5s dragover.h5s dragenter.h5s drop.h5s");return}e=n(this).children(r.items);f=n("<"+(/^ul|ol$/i.test(this.tagName)?"li":/^tbody$/i.test(this.tagName)?"tr":"div")+' class="sortable-placeholder '+r.placeholderClass+'">').html("&nbsp;");e.find(r.handle).mousedown(function(){o=!0}).mouseup(function(){o=!1});n(this).data("items",r.items);i=i.add(f);r.connectWith&&n(r.connectWith).add(this).data("connectWith",r.connectWith);e.attr("draggable","true").on("dragstart.h5s",function(i){if(r.handle&&!o)return!1;o=!1;var u=i.originalEvent.dataTransfer;u.effectAllowed="move";u.setData("Text","dummy");h=(t=n(this)).addClass("sortable-dragging").index();s=t.parent()}).on("dragend.h5s",function(){t&&(t.removeClass("sortable-dragging").show(),i.detach(),h!=t.index()&&t.parent().trigger("sortupdate",{item:t}),t.parent().is(s)||t.parent().trigger("sortconnect",{item:t}),t=null)}).not("a[href], img").on("selectstart.h5s",function(){return this.dragDrop&&this.dragDrop(),!1}).end().add([this,f]).on("dragover.h5s dragenter.h5s drop.h5s",function(u){return!e.is(t)&&r.connectWith!==n(t).parent().data("connectWith")?!0:u.type=="drop"?(u.stopPropagation(),i.filter(":visible").after(t),t.trigger("dragend.h5s"),!1):(u.preventDefault(),u.originalEvent.dataTransfer.dropEffect="move",e.is(this)?(r.forcePlaceholderSize&&f.height(t.outerHeight()),t.hide(),n(this)[f.index()<n(this).index()?"after":"before"](f),i.not(f).detach()):i.is(this)||n(this).children(r.items).length||(i.detach(),n(this).append(f)),!1)})})}})(jQuery);