JIRA task mover plugin

Plugin to allow moving tasks in JIRA

目前为 2018-09-10 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name JIRA task mover plugin
  3. // @description Plugin to allow moving tasks in JIRA
  4. // @version 0.3
  5. // @author Max Schlüssel <lokoxe@gmail.com>
  6. // @namespace https://ghostkernel.org/
  7. // @match *://*/*
  8. // @grant GM_addStyle
  9. // ==/UserScript==
  10.  
  11. (function($) {
  12. 'use strict';
  13.  
  14. GM_addStyle(" \
  15. .issuerow .dragger { \
  16. display: block; \
  17. height: 10px; \
  18. margin-top: 15px; \
  19. margin-right: 5px; \
  20. border: none !important;\
  21. cursor: move; \
  22. background: repeating-linear-gradient(0, \
  23. transparent 0%, \
  24. transparent 2%, #aaa 2%, \
  25. #aaa 3%, transparent 3%);\
  26. } \
  27. .issuerow.dragged { \
  28. background-color: #eee !important; \
  29. } \
  30. ");
  31.  
  32. $(document).ready(function() {
  33. if(!$("body").is("#jira")) {
  34. return;
  35. }
  36.  
  37. var issueRows = $(".issuerow");
  38.  
  39. var draggedRow = null;
  40. var dropSequence = null;
  41. var insertAfter = false;
  42.  
  43. issueRows.each(function() {
  44. var issueRow = $(this);
  45. var dragger = $("<td>");
  46. dragger.addClass("dragger");
  47. issueRow.prepend(dragger);
  48. dropSequence = null;
  49.  
  50. dragger.bind("mousedown.drag", function(e) {
  51. e.preventDefault();
  52. draggedRow = dragger.parent();
  53. draggedRow.addClass("dragged");
  54. });
  55. });
  56.  
  57. $(document).bind("mousemove.drag", function(e) {
  58. e.preventDefault();
  59. if(draggedRow == null) {
  60. return;
  61. }
  62. var el = $(e.target);
  63. var hoveredRow = el.closest(".issuerow");
  64. if(hoveredRow.length > 0) {
  65. if(!draggedRow.is(hoveredRow)) {
  66. draggedRow.detach();
  67. if(e.offsetY < 20) {
  68. insertAfter = false;
  69. draggedRow.insertBefore(hoveredRow);
  70. } else {
  71. insertAfter = true;
  72. draggedRow.insertAfter(hoveredRow);
  73. }
  74. }
  75. dropSequence = draggedRow.index();
  76. }
  77. });
  78.  
  79. $(document).bind("mouseup.drag", function(e) {
  80. e.preventDefault();
  81.  
  82. if(draggedRow != null && dropSequence != null) {
  83. var moveUrl = draggedRow.find(".subtask-reorder a").first().attr("href");
  84. var currentSequence = moveUrl.substring(moveUrl.indexOf("&currentSubTaskSequence=") + "&currentSubTaskSequence=".length, moveUrl.indexOf("&subTaskSequence="));
  85. if(currentSequence != dropSequence) {
  86. var id = moveUrl.substring(moveUrl.indexOf("id=") + "id=".length, moveUrl.indexOf("&currentSubTaskSequence="));
  87. var newLink = "/secure/MoveIssueLink.jspa?id=" + id + "&currentSubTaskSequence=" + currentSequence + "&subTaskSequence=" + dropSequence;
  88. window.location = newLink;
  89. }
  90.  
  91. // Reset dragged row
  92. draggedRow.removeClass("dragged");
  93. draggedRow = null;
  94. }
  95. });
  96. });
  97. })($);