Skip to content

Commit

Permalink
FIX: insertAdjacentHTML is a better choice here
Browse files Browse the repository at this point in the history
  • Loading branch information
jjaffeux committed Jun 1, 2020
1 parent 13f14c3 commit b4bf9b2
Showing 1 changed file with 4 additions and 9 deletions.
13 changes: 4 additions & 9 deletions assets/javascripts/initializers/add-holiday-flair.js.es6
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,12 @@ function applyFlairOnMention(element, username) {
if (!element) return;

const href = `${Discourse.BaseUri}/u/${username}`;

const mentions = element.querySelectorAll(
`a.mention[href="${href}"]:not(.on-holiday)`
);

const parser = new DOMParser();
const doc = parser.parseFromString(iconHTML("calendar-alt"), "text/html");
const iconDocument = doc.body.firstChild;
const mentions = element.querySelectorAll(`a.mention[href="${href}"]`);

mentions.forEach(mention => {
mention.appendChild(iconDocument);
if (!mention.querySelector(".d-icon-calendar-alt")) {
mention.insertAdjacentHTML("beforeend", iconHTML("calendar-alt"));
}
mention.classList.add("on-holiday");
});
}
Expand Down

0 comments on commit b4bf9b2

Please sign in to comment.