|
167 | 167 | }); |
168 | 168 | } |
169 | 169 |
|
| 170 | + /** |
| 171 | + * Append the given HTML string at the end of the given child target node. |
| 172 | + */ |
| 173 | + parseHtmlAndAppendChild(targetNode, html) { |
| 174 | + new DOMParser() |
| 175 | + .parseFromString(html, 'text/html') |
| 176 | + .querySelector('body') |
| 177 | + .childNodes |
| 178 | + .forEach(function(node) { |
| 179 | + targetNode.appendChild(node); |
| 180 | + } |
| 181 | + ) |
| 182 | + } |
| 183 | + |
170 | 184 | /** |
171 | 185 | * Actually updates the UI by altering the DOM by adding our stuff. |
172 | 186 | */ |
173 | 187 | updateMergeRequestsNodes(mergeRequestsDetails) { |
174 | 188 | let self = this; |
175 | 189 |
|
176 | 190 | mergeRequestsDetails.forEach(function(mergeRequest) { |
177 | | - let branchesInfoNode = document.createElement('div'); |
178 | | - |
179 | | - branchesInfoNode.classList.add('issuable-info'); |
180 | | - branchesInfoNode.innerHTML = '<span class="project-ref-path has-tooltip" title="Source branch">' + |
181 | | - '<a class="ref-name" href="' + self.baseProjectUrl + '/-/commits/' + mergeRequest.source_branch + '">' + mergeRequest.source_branch + '</a>' + |
182 | | - '</span>' + |
183 | | - ' <i class="fa fa-long-arrow-right" aria-hidden="true"></i> ' + |
184 | | - '<span class="project-ref-path has-tooltip" title="Target branch">' + |
185 | | - '<a class="ref-name" href="' + self.baseProjectUrl + '/-/commits/' + mergeRequest.target_branch + '">' + mergeRequest.target_branch + '</a>' + |
186 | | - '</span>'; |
187 | | - |
188 | | - document |
189 | | - .querySelector('.mr-list .merge-request[data-iid="' + mergeRequest.iid + '"] .issuable-main-info') |
190 | | - .appendChild(branchesInfoNode); |
| 191 | + let infoDiv = document |
| 192 | + .querySelector('.mr-list .merge-request[data-iid="' + mergeRequest.iid + '"] .issuable-main-info'); |
| 193 | + |
| 194 | + let html = '<div class="issuable-info"><span class="project-ref-path has-tooltip" title="Source branch">' + |
| 195 | + '<a class="ref-name" href="' + self.baseProjectUrl + '/-/commits/' + mergeRequest.source_branch + '">' + mergeRequest.source_branch + '</a>' + |
| 196 | + '</span>' + |
| 197 | + ' <i class="fa fa-long-arrow-right" aria-hidden="true"></i> ' + |
| 198 | + '<span class="project-ref-path has-tooltip" title="Target branch">' + |
| 199 | + '<a class="ref-name" href="' + self.baseProjectUrl + '/-/commits/' + mergeRequest.target_branch + '">' + mergeRequest.target_branch + '</a>' + |
| 200 | + '</span></div>'; |
| 201 | + |
| 202 | + self.parseHtmlAndAppendChild( |
| 203 | + infoDiv, |
| 204 | + html |
| 205 | + ); |
191 | 206 | }); |
192 | 207 | } |
193 | 208 | } |
|
0 commit comments