RoadFlow2.1 临时演示

roadui.dragsort.js 2.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. ; RoadUI.DragSort = function (elements)
  2. {
  3. var container = elements;
  4. $(container).children().off("mousedown").mousedown(function (e)
  5. {
  6. if (e.which != 1 || $(e.target).is("input, textarea") || window.dragsort_only) return;
  7. e.preventDefault();
  8. var x = e.pageX;
  9. var y = e.pageY;
  10. var _this = $(this);
  11. var w = _this.width();
  12. var h = _this.height();
  13. var w2 = w / 2;
  14. var h2 = h / 2;
  15. var p = _this.offset();
  16. var left = p.left;
  17. var top = p.top;
  18. window.dragsort_only = true;
  19. // 添加虚线框
  20. _this.before('<div id="roadui_dragsort_dasheddiv"></div>');
  21. var wid = $("#roadui_dragsort_dasheddiv");
  22. wid.css({ "border": "1px dashed #e8e8e8", "height": h + 2, "width": w, "padding": "4px 0 0 10px", "margin": "5px 0", "list-style": "none" });
  23. _this.css({ "width": w, "height": h, "position": "absolute", "opacity": 0.8, "z-index": 999, "left": left, "top": top });
  24. $(document).mousemove(function (e)
  25. {
  26. e.preventDefault();
  27. // 移动选中块
  28. var l = left + e.pageX - x;
  29. var t = top + e.pageY - y;
  30. _this.css({ "left": l, "top": t });
  31. var ml = l + w2;
  32. var mt = t + h2;
  33. $(container).children().not(_this).not(wid).each(function (i)
  34. {
  35. var obj = $(this);
  36. var p = obj.offset();
  37. var a1 = p.left;
  38. var a2 = p.left + obj.width();
  39. var a3 = p.top;
  40. var a4 = p.top + obj.height();
  41. if (a1 < ml && ml < a2 && a3 < mt && mt < a4)
  42. {
  43. if (!obj.next("#roadui_dragsort_dasheddiv").length)
  44. {
  45. wid.insertAfter(this);
  46. } else
  47. {
  48. wid.insertBefore(this);
  49. }
  50. return;
  51. }
  52. });
  53. });
  54. $(document).mouseup(function ()
  55. {
  56. $(document).off('mouseup').off('mousemove');
  57. $(container).each(function ()
  58. {
  59. var obj = $(this).children();
  60. var len = obj.length;
  61. if (len == 1 && obj.is(_this))
  62. {
  63. $("<div></div>").appendTo(this).attr("class", "roadui_dragsort_block").css({ "height": 100 });
  64. } else if (len == 2 && obj.is(".roadui_dragsort_block"))
  65. {
  66. $(this).children(".roadui_dragsort_block").remove();
  67. }
  68. });
  69. var p = wid.offset();
  70. _this.animate({ "left": p.left, "top": p.top }, 100, function ()
  71. {
  72. _this.removeAttr("style");
  73. wid.replaceWith(_this);
  74. window.dragsort_only = null;
  75. });
  76. });
  77. });
  78. }