example.js 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. $(document).ready(function(){
  2. 'use strict';
  3. var url1;
  4. dragula([$('left-defaults'), $('right-defaults'),$('test1'),$('test2')],{
  5. //alert(1);
  6. revertOnSpill: true,
  7. direction: 'horizontal',
  8. moves: function (el, container, handle) {
  9. return true; // elements are always draggable by default
  10. },
  11. accepts: function (el, target, source, sibling) {
  12. //console.log(source.id);
  13. if(source.id=='left-defaults' && target.id=='right-defaults'){
  14. url1=drag_url+"/"+el.id+"/no";
  15. return true;
  16. } else if(source.id=='right-defaults' && target.id=='left-defaults'){
  17. url1=drag_url+"/"+el.id+"/no";
  18. return true;
  19. } else if(source.id=='right-defaults' && target.id=='test1'){
  20. url1=drag_url+"/"+el.id+'/yes';
  21. return true;
  22. } else if(source.id=='test1' && target.id=='test2'){
  23. url1=drag_url+"/"+el.id+'/no';
  24. return true;
  25. } else if(source.id=='test2' && target.id=='test1'){
  26. url1=drag_url+"/"+el.id+'/no';
  27. return true;
  28. }
  29. },
  30. invalid: function (el,target) {
  31. return false; // don't prevent any drags from initiating by default
  32. }
  33. }).on('drop',function (el) {
  34. //var url=drag_url+"/"+el.id+"/no";
  35. var hr = new XMLHttpRequest();
  36. hr.open("GET",url1 , true);
  37. hr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  38. // Access the onreadystatechange event for the XMLHttpRequest object
  39. hr.onreadystatechange = function() {
  40. if(hr.readyState == 4 && hr.status == 200) {
  41. var return_data = hr.responseText;
  42. alert(return_data);
  43. }
  44. }
  45. hr.send();
  46. });
  47. /*dragula([$('test1'), $('test2')],{
  48. revertOnSpill: true,
  49. direction: 'horizontal',
  50. moves: function (el, container, handle) {
  51. return true; // elements are always draggable by default
  52. },
  53. accepts: function (el, target, source, sibling) {
  54. //console.log(source.id);
  55. if(source.id=='test1' && target.id=='test2'){
  56. return true;
  57. } else if(source.id=='test2' && target.id=='test1'){
  58. return true;
  59. } else if(source.id=='right-defaults' && target.id=='test1'){
  60. return true;
  61. }
  62. },
  63. invalid: function (el,target) {
  64. return false; // don't prevent any drags from initiating by default
  65. }
  66. }).on('drop',function (el) {
  67. var url=drag_url+"/"+el.id+"/no";
  68. var hr = new XMLHttpRequest();
  69. hr.open("GET",url , true);
  70. hr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  71. // Access the onreadystatechange event for the XMLHttpRequest object
  72. hr.onreadystatechange = function() {
  73. if(hr.readyState == 4 && hr.status == 200) {
  74. var return_data = hr.responseText;
  75. alert(return_data);
  76. }
  77. }
  78. hr.send();
  79. });
  80. /*dragula([$('right-defaults'), $('test1')],{
  81. revertOnSpill: true,
  82. direction: 'horizontal',
  83. moves: function (el, container, handle) {
  84. return true; // elements are always draggable by default
  85. },
  86. accepts: function (el, target, source, sibling) {
  87. //console.log(source.id);
  88. if(source.id=='right-defaults' && target.id=='test1'){
  89. return true;
  90. }
  91. },
  92. invalid: function (el,target) {
  93. return false; // don't prevent any drags from initiating by default
  94. }
  95. }).on('drop',function (el) {
  96. var url=drag_url+"/"+el.id+'/yes';
  97. var hr = new XMLHttpRequest();
  98. hr.open("GET",url , true);
  99. hr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  100. // Access the onreadystatechange event for the XMLHttpRequest object
  101. hr.onreadystatechange = function() {
  102. if(hr.readyState == 4 && hr.status == 200) {
  103. var return_data = hr.responseText;
  104. alert(return_data);
  105. }
  106. }
  107. hr.send();
  108. });*/
  109. var sortable = $('sortable');
  110. dragula([$('left-copy'), $('right-copy')], { copy: true });
  111. dragula([$('left-events'), $('right-events')])
  112. .on('drag', function (el) {
  113. el.className = el.className.replace('ex-moved', '');
  114. })
  115. .on('drop', function (el) {
  116. el.className += ' ex-moved';
  117. var droppedElId = $(el).attr('id');
  118. alert(droppedElId);
  119. })
  120. .on('over', function (el, container) {
  121. container.className += ' ex-over';
  122. })
  123. .on('out', function (el, container) {
  124. container.className = container.className.replace('ex-over', '');
  125. });
  126. dragula([$('left-rollbacks'), $('right-rollbacks')], { revertOnSpill: true });
  127. dragula([$('left-lovehandles'), $('right-lovehandles')], {
  128. moves: function (el, container, handle) {
  129. return handle.classList.contains('handle');
  130. }
  131. });
  132. dragula([$('left-rm-spill'), $('right-rm-spill')], { removeOnSpill: true });
  133. dragula([$('left-copy-1tomany'), $('right-copy-1tomany')], {
  134. copy: function (el, source) {
  135. return source === $('left-copy-1tomany');
  136. },
  137. accepts: function (el, target) {
  138. return target !== $('left-copy-1tomany');
  139. }
  140. });
  141. dragula([sortable]);
  142. crossvent.add(sortable, 'click', clickHandler);
  143. function clickHandler (e) {
  144. var target = e.target;
  145. if (target === sortable) {
  146. return;
  147. }
  148. target.innerHTML += ' [click!]';
  149. setTimeout(function () {
  150. target.innerHTML = target.innerHTML.replace(/ \[click!\]/g, '');
  151. }, 500);
  152. }
  153. function $ (id) {
  154. return document.getElementById(id);
  155. }
  156. })