Welcome to mirror list, hosted at ThFree Co, Russian Federation.

update_description.js « utils « show « issues « javascripts « assets « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: aeb547b91947e011965bab17eb3689537ccb86f2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
/**
 * Function that replaces the open attribute for the <details> element.
 *
 * @param {String} descriptionHtml - The html string passed back from the server as a result of polling
 * @param {Array} details - All detail nodes inside of the issue description.
 */

const updateDescription = (descriptionHtml = '', details) => {
  let detailNodes = details;

  if (!details.length) {
    detailNodes = [];
  }

  const placeholder = document.createElement('div');
  // eslint-disable-next-line no-unsanitized/property
  placeholder.innerHTML = descriptionHtml;

  const newDetails = placeholder.getElementsByTagName('details');

  if (newDetails.length !== detailNodes.length) {
    return descriptionHtml;
  }

  Array.from(newDetails).forEach((el, i) => {
    /*
     * <details> has an open attribute that can have a value, "", "true", "false"
     * and will show the dropdown, which is why we are setting the attribute
     * explicitly to true.
     */
    if (detailNodes[i].open) el.setAttribute('open', true);
  });

  return placeholder.innerHTML;
};

export default updateDescription;