Skip to content

Commit ab3eede

Browse files
committed
Fix for loop context with async fetch call
1 parent 22850a0 commit ab3eede

File tree

1 file changed

+43
-43
lines changed

1 file changed

+43
-43
lines changed

assets/javascripts/changeset_statuses.js

Lines changed: 43 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -2,64 +2,64 @@ window.addEventListener('load', function() {
22
var revisionLinks = document.querySelectorAll('#issue-changesets a[href*="/revisions/"]:not([href$="diff"])');
33

44
for (i = 0; i < revisionLinks.length; ++i) {
5-
var revisionLink = revisionLinks[i];
5+
(function(revisionLink) {
6+
fetch(revisionLink.href +'/status.json', {
7+
headers: {
8+
'X-Requested-With': 'XMLHttpRequest'
9+
}
10+
})
11+
.then(function(response) {
12+
return response.json();
13+
})
14+
.then(function(data) {
15+
if (! data.state) {
16+
return;
17+
}
618

7-
fetch(revisionLink.href +'/status.json', {
8-
headers: {
9-
'X-Requested-With': 'XMLHttpRequest'
10-
}
11-
})
12-
.then(function(response) {
13-
return response.json();
14-
})
15-
.then(function(data) {
16-
if (! data.state) {
17-
return;
18-
}
19+
var details = document.createElement('details');
1920

20-
var details = document.createElement('details');
21+
details.className = 'changeset-status__popover';
22+
details.setAttribute('role', 'menu');
2123

22-
details.className = 'changeset-status__popover';
23-
details.setAttribute('role', 'menu');
24+
details.innerHTML = '<summary aria-haspopup="menu" class="changeset-status changeset-status--'+ data.state +'">•</summary>' +
25+
'<div class="changeset-status__popup"><ul></ul></div>';
2426

25-
details.innerHTML = '<summary aria-haspopup="menu" class="changeset-status changeset-status--'+ data.state +'">•</summary>' +
26-
'<div class="changeset-status__popup"><ul></ul></div>';
27+
var ul = details.querySelector('ul');
2728

28-
var ul = details.querySelector('ul');
29+
data.statuses.forEach(function(status) {
30+
var li = document.createElement('li');
31+
li.innerHTML = '<span class="changeset-status changeset-status--'+ status.state +'">•</span> <strong></strong>'
2932

30-
data.statuses.forEach(function(status) {
31-
var li = document.createElement('li');
32-
li.innerHTML = '<span class="changeset-status changeset-status--'+ status.state +'">•</span> <strong></strong>'
33+
var strong = li.querySelector('strong');
3334

34-
var strong = li.querySelector('strong');
35+
if (status.target_url) {
36+
var a = document.createElement('a');
3537

36-
if (status.target_url) {
37-
var a = document.createElement('a');
38+
a.setAttribute('href', status.target_url);
39+
a.setAttribute('target', '_blank');
40+
a.setAttribute('rel', 'noopener noreferrer');
3841

39-
a.setAttribute('href', status.target_url);
40-
a.setAttribute('target', '_blank');
41-
a.setAttribute('rel', 'noopener noreferrer');
42+
a.innerText = status.context;
4243

43-
a.innerText = status.context;
44+
strong.appendChild(a);
45+
} else {
46+
strong.innerText = status.context;
47+
}
4448

45-
strong.appendChild(a);
46-
} else {
47-
strong.innerText = status.context;
48-
}
49+
if (status.description) {
50+
var em = document.createElement('em');
4951

50-
if (status.description) {
51-
var em = document.createElement('em');
52+
em.setAttribute('title', status.description);
53+
em.innerText = status.description;
5254

53-
em.setAttribute('title', status.description);
54-
em.innerText = status.description;
55+
li.appendChild(em);
56+
}
5557

56-
li.appendChild(em);
57-
}
58+
ul.appendChild(li);
59+
});
5860

59-
ul.appendChild(li);
61+
revisionLink.parentNode.insertBefore(details, revisionLink);
6062
});
61-
62-
revisionLink.parentNode.insertBefore(details, revisionLink);
63-
});
63+
})(revisionLinks[i]);
6464
}
6565
});

0 commit comments

Comments
 (0)