gpt4 book ai didi

Javascript JIRA 扩展在悬停时不起作用

转载 作者:行者123 更新时间:2023-12-02 16:27:58 26 4
gpt4 key购买 nike

我开发了一些 Javascript 示例,当您将鼠标悬停在问题链接上时,它会创建一个 JIRA 工具提示(使用 Tipsy AUI 指南 - https://docs.atlassian.com/aui/5.4.0/docs/tooltips.html ),显示票证状态、摘要、受让人和修复版本。主要用在问题搜索页面,防止连续右键->在新选项卡中打开->检查...变得极其繁琐,但也可以用于大多数其他问题链接。

它的目的是在链接悬停时工作,但它并不总是按计划进行。当我第一次将鼠标悬停在任何问题链接上时,它会生成一个工具提示“未定义”。当我第二次将鼠标悬停在任何问题链接上时,它会按预期生成准确的工具提示。将其复制到您的控制台中,我很确定您会看到相同的行为。

我不是 Javascript 专家,所以这可能是我不知道的 Javascript 机制,所以如果有人知道为什么会发生这种情况,请告诉我!

我也将其打包到 JIRA 插件中并看到了相同的结果。

AJS.toInit(function () {

var url,
issue_id,
offset,
x,
y,
jira_data,
html,
fixVersions,
assignee,
domain = document.location;

// build url whatever it might be
url = domain.protocol +'//'+ domain.hostname
if (domain.port !== "") {
url += ':'+domain.port
}

AJS.$(".issue-link, td.issuelinks > a, #ghx-issues-in-epic-table > tbody > tr > td > a").tooltip({

title: function () {

// GETS THE ISSUE ID FROM THE HREF ELEMENT
issue_id = (AJS.$(this).attr("href")).slice((AJS.$(this).attr("href")).lastIndexOf("/"), (AJS.$(this).attr("href")).length);
// QUERIES JIRA API - ALREADY AUTHENTICATED WITH SESSION
jira_data = AJS.$.getJSON(url+'/rest/api/2/issue' + issue_id, function (json) {

})
// AJAX COMPLETE FUNCTION
jira_data.done(function (jira_data) {
// CHECK FOR FixVersoin and Multiple FixVersions
fixVersions = ""
if (jira_data['fields']['fixVersions'] === undefined) {
fixVersions = "None";
} else {
AJS.$.each(jira_data['fields']['fixVersions'], function(index, value) {
fixVersions += value['name'] + " ";
});};
// CHECK FOR UNASSIGNED
if (jira_data['fields']['assignee'] === undefined) {
assignee = "Unassigned";
} else {
assignee = jira_data['fields']['assignee']['displayName'];
};
// BUILD STRING OUTPUT
html = "<span style='text-align:left'>";
html += "<strong>Status: </strong>" + jira_data['fields']['status']['name'] + "</br>"
html +="<strong>Assignee: </strong>" + assignee + "</br>";
html += "<strong>Fix Version: </strong>" +fixVersions+ "</br>";
html += "<strong>Summary: </strong>" + jira_data['fields']['summary'];
html += "</span>"

});
return html;
}, live: true, gravity: AJS.$.fn.tipsy.autoWE, html:true, delayIn: 400, delayOut: 50});


// REMOVE TITLE TAG TO PREVENT OBSTURCTION
AJS.$(".issue-link, td.issuelinks > a, #ghx-issues-in-epic-table > tbody > tr > td > a").removeAttr('title');
AJS.$(".issue-link, td.issuelinks > a, #ghx-issues-in-epic-table > tbody > tr > td > a").parent().removeAttr('title');

});

最佳答案

我重构了你的代码,它工作正常。诀窍是在 ajax 回调函数内填充工具提示。

AJS.toInit(function () {

var url,
issue_id,
offset,
x,
y,
jira_data,
html,
fixVersions,
assignee,
domain = document.location;

// build url whatever it might be
url = domain.protocol +'//'+ domain.hostname
if (domain.port !== "") {
url += ':'+domain.port
}

AJS.$(".issue-link, td.issuelinks > a, #ghx-issues-in-epic-table > tbody > tr > td > a").hover(function () {

console.log('Entro')
// GETS THE ISSUE ID FROM THE HREF ELEMENT
issue_id = (AJS.$(this).attr("href")).slice((AJS.$(this).attr("href")).lastIndexOf("/"), (AJS.$(this).attr("href")).length);
// QUERIES JIRA API - ALREADY AUTHENTICATED WITH SESSION

jira_data = AJS.$.getJSON(url+'/rest/api/2/issue' + issue_id, function (json) {

})
// AJAX COMPLETE FUNCTION
jira_data.done(function (jira_data) {
// CHECK FOR UNASSIGNED
if (jira_data['fields']['assignee'] === undefined) {
assignee = "Unassigned";
} else {
assignee = jira_data['fields']['assignee']['displayName'];
};
// BUILD STRING OUTPUT
html = "<span style='text-align:left'>";
html += "<strong>Summary: </strong>" + jira_data['fields']['summary'] + "</br>";
html += "<strong>Status: </strong>" + jira_data['fields']['status']['name'] + "</br>";
html +="<strong>Asignado: </strong>" + assignee + "</br>";
html += "</span>";
AJS.$(".issue-link, td.issuelinks > a, #ghx-issues-in-epic-table > tbody > tr > td > a").removeAttr('title');
AJS.$(".issue-link, td.issuelinks > a, #ghx-issues-in-epic-table > tbody > tr > td > a").parent().removeAttr('title');
AJS.$(".issue-link, td.issuelinks > a, #ghx-issues-in-epic-table > tbody > tr > td > a").tooltip({title:function () {
return html;
},live: true, gravity: AJS.$.fn.tipsy.autoWE, html:true, delayIn: 400, delayOut: 50});
});
});
});

关于Javascript JIRA 扩展在悬停时不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28541354/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com