kanban.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. function KANBAN_DEF() {
  2. }
  3. KANBAN_DEF.prototype = (function () {
  4. function allowDrop(ev) {
  5. ev.preventDefault();
  6. }
  7. function drag(ev) {
  8. ev.dataTransfer.setData("data-id", ev.target.id);
  9. }
  10. function drop(ev) {
  11. var landId = ev.target.id;
  12. var land = document.getElementById(landId);
  13. var landAttribute = land.getAttribute("data-kanban", 0);
  14. var isChild = (landAttribute !== "task") ? true : false;
  15. var elementId = ev.dataTransfer.getData("data-id");
  16. var element = document.getElementById(elementId);
  17. if (isChild && element != undefined && element != "") {
  18. ev.target.appendChild(element);
  19. ev.preventDefault();
  20. }
  21. }
  22. return {
  23. onload: function () {
  24. var cols = document.querySelectorAll('#kanban .tasks');
  25. [].forEach.call(cols, function(col) {
  26. col.addEventListener('dragover', kanban.ondragover, false);
  27. col.addEventListener('drop', kanban.ondrop, false);
  28. });
  29. var tasks = document.querySelectorAll('#kanban .task');
  30. [].forEach.call(tasks, function(task) {
  31. //TODO: could remove the element ids from the markup and add them in here instead
  32. task.addEventListener('dragstart', kanban.ondragstart, false);
  33. });
  34. },
  35. ondrop: function (event) {
  36. drop(event);
  37. },
  38. ondragover: function (event) {
  39. allowDrop(event);
  40. },
  41. ondragstart: function (event) {
  42. drag(event);
  43. }
  44. };
  45. })();
  46. var kanban = new KANBAN_DEF();
  47. window.onload = function(){
  48. kanban.onload();
  49. }