Last active
October 31, 2015 09:06
-
-
Save tozevv/5a2ba4b49b5ad9ab022c to your computer and use it in GitHub Desktop.
Add href to linked issues in JIRA agile cards. Copy and paste into "Announce" section of JIRA config.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script language="javascript"> | |
(function(jQuery) { | |
var observeDOM = (function(){ | |
var MutationObserver = window.MutationObserver || window.WebKitMutationObserver, | |
eventListenerSupported = window.addEventListener; | |
return function(obj, callback){ | |
if( MutationObserver ){ | |
// define a new observer | |
var obs = new MutationObserver(function(mutations, observer){ | |
if( mutations[0].addedNodes.length || mutations[0].removedNodes.length ) | |
callback(); | |
}); | |
// have the observer observe foo for changes in children | |
obs.observe( obj, { childList:true, subtree:true }); | |
} | |
else if( eventListenerSupported ){ | |
obj.addEventListener('DOMNodeInserted', callback, false); | |
obj.addEventListener('DOMNodeRemoved', callback, false); | |
} | |
} | |
})(); | |
var setLinks = function() { | |
console.log("Setting links"); | |
var time = (new Date()).getTime(); | |
var allIssueLinks = jQuery(".ghx-extra-field[data-tooltip*='Linked Issues: '] > .ghx-extra-field-content:not(:contains('None'))") | |
allIssueLinks.each(function(i, issueLinks) { | |
var jIssueLinks = jQuery(issueLinks) | |
var issueKeys = jIssueLinks.html().split(",") | |
var target = jIssueLinks.parent(); | |
target.html(""); | |
jQuery.each(issueKeys, function(i, issueKey) { | |
issueKey = issueKey.trim(); | |
if(i > 0) { | |
target.append(jQuery(document.createTextNode(', '))); | |
} | |
target.append(jQuery("<a class='link-title'>").attr("href", "/jira/browse/" + issueKey).text(issueKey) | |
.wrap("<div class='ghx-key'>")); | |
}) | |
target.find("a").click(function(e) { | |
console.log("clicked", jQuery(this).attr('href')); | |
window.location = jQuery(this).attr('href'); | |
e.preventDefault(); | |
return false; | |
}) | |
}) | |
console.log("Setting links for Story Cards took:", ((new Date()).getTime() - time), "ms"); | |
}; | |
observeDOM(jQuery("html")[0], function() { setLinks(); }); | |
})(jQuery); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment