Skip to content

Commit 78b5da0

Browse files
committed
fixed MathJax rendering breaking upon collapsing an inline thread
1 parent 9aaa480 commit 78b5da0

1 file changed

Lines changed: 18 additions & 3 deletions

File tree

app/assets/javascripts/comments.js

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ $(() => {
2727
return !!wrapper.querySelector('[data-inline=true]');
2828
};
2929

30+
const afterThreadRender = () => {
31+
window.MathJax && MathJax.typeset();
32+
window.hljs && hljs.highlightAll();
33+
};
34+
3035
/**
3136
* @param {HTMLElement} wrapper
3237
* @param {string} threadId
@@ -42,8 +47,15 @@ $(() => {
4247

4348
wrapper.innerHTML = data;
4449

45-
window.MathJax && MathJax.typeset();
46-
window.hljs && hljs.highlightAll();
50+
if (window.MathJax) {
51+
const titleElem = wrapper.querySelector('.js-thread-title');
52+
53+
if (titleElem && QPixel.DOM.isHTMLElement(titleElem)) {
54+
titleElem.dataset.title = titleElem.textContent;
55+
}
56+
}
57+
58+
afterThreadRender();
4759
}
4860

4961
$(document).on('click', '.js--comment-link', async (ev) => {
@@ -78,13 +90,14 @@ $(() => {
7890
$(document).on('click', '.js-collapse-thread', async (ev) => {
7991
const $tgt = $(ev.target);
8092
const $widget = $tgt.parents('.widget');
93+
const $title = $widget.find('.js-thread-title');
8194
const $embed = $tgt.parents('.post--comments-thread');
8295

8396
const threadId = $widget.data('thread');
8497
const isLocked = $widget.data('locked');
8598
const isDeleted = $widget.data('deleted');
8699
const isArchived = $widget.data('archived');
87-
const threadTitle = $widget.find('.js-thread-title').text();
100+
const threadTitle = $title.data('title') || $title.text();
88101
const replyCount = $widget.data('comments');
89102

90103
const $container = $(`<div class="post--comments-thread is-inline"></div>`);
@@ -111,6 +124,8 @@ $(() => {
111124
$container.append($link);
112125
$container.append(`(${replyCount} comment${replyCount !== 1 ? 's' : ''})`);
113126
$embed[0].outerHTML = $container[0].outerHTML;
127+
128+
afterThreadRender();
114129
});
115130

116131
$(document).on('click', '.js-comment-edit', async (evt) => {

0 commit comments

Comments
 (0)