Drag2.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. var Drag={
  2. "obj":null,
  3. "init":function(handle, dragBody, e){
  4. if (e == null) {
  5. handle.onmousedown=Drag.start;
  6. }
  7. handle.root = dragBody;
  8. if(isNaN(parseInt(handle.root.style.left)))handle.root.style.left="0px";
  9. if(isNaN(parseInt(handle.root.style.top)))handle.root.style.top="0px";
  10. handle.root.onDragStart=new Function();
  11. handle.root.onDragEnd=new Function();
  12. handle.root.onDrag=new Function();
  13. if (e !=null) {
  14. var handle=Drag.obj=handle;
  15. e=Drag.fixe(e);
  16. var top=parseInt(handle.root.style.top);
  17. var left=parseInt(handle.root.style.left);
  18. handle.root.onDragStart(left,top,e.pageX,e.pageY);
  19. handle.lastMouseX=e.pageX;
  20. handle.lastMouseY=e.pageY;
  21. document.onmousemove=Drag.drag;
  22. document.onmouseup=Drag.end;
  23. }
  24. },
  25. "start":function(e){
  26. var handle=Drag.obj=this;
  27. e=Drag.fixEvent(e);
  28. var top=parseInt(handle.root.style.top);
  29. var left=parseInt(handle.root.style.left);
  30. handle.root.onDragStart(left,top,e.pageX,e.pageY);
  31. handle.lastMouseX=e.pageX;
  32. handle.lastMouseY=e.pageY;
  33. handle.offsetX = e.offsetX;
  34. handle.offsetY = e.offsetY;
  35. var spanAll=$(handle.root.parentNode).find("span[class='icons icon-checked']");
  36. for(var i=0;i<spanAll.length;i++){
  37. var itemDiv=spanAll[i].parentNode;
  38. var top=parseInt(itemDiv.style.top);
  39. var left=parseInt(itemDiv.style.left);
  40. itemDiv.onDragStart(left,top,e.pageX,e.pageY);
  41. var h3=$(itemDiv).find("h3")[0];
  42. h3.lastMouseX=e.pageX;
  43. h3.lastMouseY=e.pageY;
  44. h3.offsetX = e.offsetX;
  45. h3.offsetY = e.offsetY;
  46. }
  47. document.onmousemove=Drag.drag;
  48. document.onmouseup=Drag.end;
  49. return false;
  50. },
  51. "drag":function(e){
  52. e=Drag.fixEvent(e);
  53. var handle=Drag.obj;
  54. var mouseY=e.pageY;
  55. var mouseX=e.pageX;
  56. handle.root.style.left=mouseX+(mouseX-handle.lastMouseX)-handle.offsetX +"px";
  57. handle.root.style.top=mouseY+(mouseY-handle.lastMouseY)-16+"px";
  58. //console.info("mouseY:"+(mouseX)+"lastMouseY:"+handle.lastMouseY);
  59. var top=parseInt(handle.root.style.top);
  60. var left=parseInt(handle.root.style.left);
  61. var currentLeft,currentTop;
  62. currentLeft=left+mouseX-handle.lastMouseX;
  63. currentTop=top+mouseY-handle.lastMouseY;
  64. handle.lastMouseX=mouseX;
  65. handle.lastMouseY=mouseY;
  66. handle.root.onDrag(currentLeft,currentTop+handle.root.column.scrollTop,e.pageX,e.pageY);
  67. var spanAll=$(handle.root.parentNode).find("span[class='icons icon-checked']");
  68. for(var i=0;i<spanAll.length;i++){
  69. var itemDiv=spanAll[i].parentNode;
  70. var h3=$(itemDiv).find("h3")[0];
  71. itemDiv.style.left=mouseX+(mouseX-h3.lastMouseX)-h3.offsetX +"px";
  72. itemDiv.style.top=mouseY+(mouseY-h3.lastMouseY)-16+"px";
  73. var top=parseInt(itemDiv.style.top);
  74. var left=parseInt(itemDiv.style.left);
  75. var currentLeft,currentTop;
  76. currentLeft=left+mouseX-h3.lastMouseX;
  77. currentTop=top+mouseY-h3.lastMouseY;
  78. h3.lastMouseX=mouseX;
  79. h3.lastMouseY=mouseY;
  80. itemDiv.onDrag(currentLeft,currentTop+itemDiv.column.scrollTop,e.pageX,e.pageY);
  81. }
  82. return false;
  83. },
  84. "end":function(e){
  85. var divlist = document.getElementById("second").getElementsByTagName("div");
  86. for(var i=0;i<divlist.length;i++){
  87. var classname = $(divlist[i]).attr("class");
  88. var tdname = $(divlist[i]).attr("tdname");
  89. //console.info("class:"+classname+";n:"+tdname);
  90. if((classname=="column"||$(divlist[i]).hasClass("column"))&&tdname=="1"){
  91. var childs = $(divlist[i]).find("div");
  92. //var childs = divlist[i].childNodes;
  93. console.info("length:"+childs.length);
  94. if(childs.length-1<1){
  95. divlist[i].style.height = 50+"px";
  96. }else{
  97. divlist[i].style.height="auto";
  98. }
  99. }
  100. }
  101. e=Drag.fixEvent(e);
  102. var mouseY=e.pageY;
  103. var mouseX=e.pageX;
  104. document.onmousemove=null;
  105. document.onmouseup=null;
  106. var spanAll=$(Drag.obj.root.parentNode).find("span[class='icons icon-checked']");
  107. for(var i=0;i<spanAll.length;i++){
  108. var itemDiv=spanAll[i].parentNode;
  109. itemDiv.onDragEnd(parseInt(Drag.obj.root.style.left),parseInt(Drag.obj.root.style.top),mouseX,mouseY);
  110. }
  111. Drag.obj.root.onDragEnd(parseInt(Drag.obj.root.style.left),parseInt(Drag.obj.root.style.top),mouseX,mouseY);
  112. Drag.obj=null;
  113. },
  114. "fixEvent":function(e){
  115. if(typeof e=="undefined")e=window.event;
  116. return e;
  117. }
  118. };