category.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. "use strict";
  2. var loading = false,
  3. dnd_successful = false;
  4. function dragend_process(t) {
  5. t.style.display = 'none';
  6. if (loading) {
  7. window.setTimeout(function() {
  8. dragend_process(t);
  9. }, 50);
  10. }
  11. if (!dnd_successful) {
  12. t.style.display = 'block';
  13. t.style.opacity = 1.0;
  14. } else {
  15. t.parentNode.removeChild(t);
  16. }
  17. }
  18. function init_draggable() {
  19. if (!(window.$ && window.url_freshrss)) {
  20. if (window.console) {
  21. console.log('FreshRSS waiting for JS…');
  22. }
  23. window.setTimeout(init_draggable, 50);
  24. return;
  25. }
  26. $.event.props.push('dataTransfer');
  27. var draggable = '[draggable="true"]',
  28. dropzone = '[dropzone="move"]';
  29. $('.drop-section').on('dragstart', draggable, function(e) {
  30. e.dataTransfer.effectAllowed = 'move';
  31. e.dataTransfer.setData('text/html', e.target.outerHTML);
  32. e.dataTransfer.setData('text', e.target.getAttribute('data-feed-id'));
  33. e.target.style.opacity = 0.3;
  34. dnd_successful = false;
  35. });
  36. $('.drop-section').on('dragend', draggable, function(e) {
  37. dragend_process(e.target);
  38. });
  39. $('.drop-section').on('dragenter', dropzone, function(e) {
  40. $(this).addClass('drag-hover');
  41. e.preventDefault();
  42. });
  43. $('.drop-section').on('dragleave', dropzone, function(e) {
  44. var pos_this = $(this).position(),
  45. scroll_top = $(document).scrollTop(),
  46. top = pos_this.top,
  47. left = pos_this.left,
  48. right = left + $(this).width(),
  49. bottom = top + $(this).height(),
  50. mouse_x = e.originalEvent.screenX,
  51. mouse_y = e.originalEvent.clientY + scroll_top;
  52. if (left <= mouse_x && mouse_x <= right &&
  53. top <= mouse_y && mouse_y <= bottom) {
  54. // HACK because dragleave is triggered when hovering children!
  55. return;
  56. }
  57. $(this).removeClass('drag-hover');
  58. });
  59. $('.drop-section').on('dragover', dropzone, function(e) {
  60. e.dataTransfer.dropEffect = "move";
  61. e.preventDefault();
  62. return false;
  63. });
  64. $('.drop-section').on('drop', dropzone, function(e) {
  65. var feed_id = e.dataTransfer.getData('text'),
  66. cat_id = e.target.parentNode.getAttribute('data-cat-id');
  67. loading = true;
  68. $.ajax({
  69. type: 'POST',
  70. url: './?c=feed&a=move',
  71. data : {
  72. f_id: feed_id,
  73. c_id: cat_id
  74. }
  75. }).success(function() {
  76. $(e.target).after(e.dataTransfer.getData('text/html'));
  77. dnd_successful = true;
  78. }).complete(function() {
  79. loading = false;
  80. });
  81. $(this).removeClass('drag-hover');
  82. e.preventDefault();
  83. });
  84. }
  85. if (document.readyState && document.readyState !== 'loading') {
  86. init_draggable();
  87. } else if (document.addEventListener) {
  88. document.addEventListener('DOMContentLoaded', function () {
  89. init_draggable();
  90. }, false);
  91. }