Skip to content
This repository has been archived by the owner on Oct 26, 2022. It is now read-only.

Commit

Permalink
Dynamic event handling based on JIRA version
Browse files Browse the repository at this point in the history
Dynamically handle events based on JIRA version.
- `>= 8.0.0`: use `JIRA.ViewIssueTabs.onTabReady()`
- `< 8.0.0`: bind `JIRA.Events.NEW_CONTENT_ADDED`
  • Loading branch information
siavashs committed Oct 31, 2020
1 parent 32f239f commit 3d12bb2
Showing 1 changed file with 35 additions and 25 deletions.
60 changes: 35 additions & 25 deletions src/main/resources/js/event.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,39 @@
// Highlight new content dynamically for older versions of JIRA
JIRA.bind(JIRA.Events.NEW_CONTENT_ADDED, function (e, context, reason) {
switch(reason) {
case "pageLoad":
case "panelRefreshed":
console.debug("Prism captured event: JIRA.Events.NEW_CONTENT_ADDED, reason:", reason);
AJS.toInit(function(){
if (JIRA.Version.isGreaterThanOrEqualTo("8.0.0")) {
console.debug("Prism detected JIRA >= 8.0.0");
// Highlight (new) content in issue tabs
JIRA.ViewIssueTabs.onTabReady(function() {
console.debug("Prism captured event: JIRA.ViewIssueTabs.onTabReady");
/* Set a timeout since JIRA navigator fires this event too early,
resulting in code style to be lost!
*/
setTimeout(function(){
console.time('Prism.highlightAllUnder');
Prism.highlightAllUnder(e.target);
console.timeEnd('Prism.highlightAllUnder');
console.time('Prism.highlightAll');
Prism.highlightAll();
console.timeEnd('Prism.highlightAll');
}, 1000);
break;
default:
console.debug("Prism ignored reason:", reason)
}
});
});

// Highlight (new) content in issue tabs
JIRA.ViewIssueTabs.onTabReady(function() {
/* Set a timeout since JIRA navigator fires this event too early,
resulting in code style to be lost!
*/
console.debug("Prism captured event: JIRA.ViewIssueTabs.onTabReady");
setTimeout(function(){
console.time('Prism.highlightAll');
Prism.highlightAll();
console.timeEnd('Prism.highlightAll');
}, 1000);
} else {
console.debug("Prism detected JIRA < 8.0.0");
// Highlight new content dynamically for older versions of JIRA
JIRA.bind(JIRA.Events.NEW_CONTENT_ADDED, function (e, context, reason) {
switch(reason) {
case "pageLoad":
case "panelRefreshed":
console.debug("Prism captured event: JIRA.Events.NEW_CONTENT_ADDED, reason:", reason);
/* Set a timeout since JIRA navigator fires this event too early,
resulting in code style to be lost!
*/
setTimeout(function(){
console.time('Prism.highlightAllUnder');
Prism.highlightAllUnder(e.target);
console.timeEnd('Prism.highlightAllUnder');
}, 1000);
break;
default:
console.debug("Prism ignored reason:", reason)
}
});
}
});

0 comments on commit 3d12bb2

Please sign in to comment.