Skip to content

Commit a93f192

Browse files
committed
fix checkboxes after comment edit
1 parent 2e16e95 commit a93f192

File tree

3 files changed

+21
-12
lines changed

3 files changed

+21
-12
lines changed

web_src/js/index.js

+8-8
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,10 @@ import initServiceWorker from './features/serviceworker.js';
1919
import initTableSort from './features/tablesort.js';
2020
import {createCodeEditor, createMonaco} from './features/codeeditor.js';
2121
import {initMarkupAnchors} from './markup/anchors.js';
22-
import initMarkupTasklist from './markup/tasklist.js';
2322
import {initNotificationsTable, initNotificationCount} from './features/notification.js';
2423
import {initStopwatch} from './features/stopwatch.js';
25-
import {renderMarkupContent} from './markup/content.js';
2624
import {showLineButton} from './code/linebutton.js';
25+
import {initMarkupContent, initCommentContent} from './markup/content.js';
2726
import {stripTags, mqBinarySearch} from './utils.js';
2827
import {svg, svgs} from './svg.js';
2928

@@ -53,7 +52,7 @@ function initCommentPreviewTab($form) {
5352
}, (data) => {
5453
const $previewPanel = $form.find(`.tab[data-tab="${$tabMenu.data('preview')}"]`);
5554
$previewPanel.html(data);
56-
renderMarkupContent();
55+
initMarkupContent();
5756
});
5857
});
5958

@@ -83,7 +82,7 @@ function initEditPreviewTab($form) {
8382
}, (data) => {
8483
const $previewPanel = $form.find(`.tab[data-tab="${$tabMenu.data('preview')}"]`);
8584
$previewPanel.html(data);
86-
renderMarkupContent();
85+
initMarkupContent();
8786
});
8887
});
8988
}
@@ -1109,7 +1108,8 @@ async function initRepository() {
11091108
dz.emit('submit');
11101109
dz.emit('reload');
11111110
}
1112-
renderMarkupContent();
1111+
initMarkupContent();
1112+
initCommentContent();
11131113
});
11141114
});
11151115
} else {
@@ -1482,7 +1482,7 @@ function initWikiForm() {
14821482
wiki: true
14831483
}, (data) => {
14841484
preview.innerHTML = `<div class="markup ui segment">${data}</div>`;
1485-
renderMarkupContent();
1485+
initMarkupContent();
14861486
});
14871487
};
14881488

@@ -2734,7 +2734,7 @@ $(document).ready(async () => {
27342734
searchRepositories();
27352735

27362736
initMarkupAnchors();
2737-
initMarkupTasklist();
2737+
initCommentContent();
27382738
initCommentForm();
27392739
initInstall();
27402740
initArchiveLinks();
@@ -2792,7 +2792,7 @@ $(document).ready(async () => {
27922792
initServiceWorker(),
27932793
initNotificationCount(),
27942794
initStopwatch(),
2795-
renderMarkupContent(),
2795+
initMarkupContent(),
27962796
initGithook(),
27972797
initImageDiff(),
27982798
]);

web_src/js/markup/content.js

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
import {renderMermaid} from './mermaid.js';
2+
import {initMarkupTasklist} from './tasklist.js';
23

3-
export async function renderMarkupContent() {
4+
// code that runs for all markup content
5+
export async function initMarkupContent() {
46
await renderMermaid(document.querySelectorAll('code.language-mermaid'));
57
}
8+
9+
// code that only runs for comments
10+
export async function initCommentContent() {
11+
initMarkupTasklist();
12+
}

web_src/js/markup/tasklist.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
/**
22
* Attaches `input` handlers to markdown rendered tasklist checkboxes in comments.
3+
* The code assumes the checkbox will be initially disabled by the markdown renderer.
4+
*
35
* When a checkbox value changes, the corresponding [ ] or [x] in the markdown string
46
* is set accordingly and sent to the server. On success it updates the raw-content on
57
* error it resets the checkbox to its original value.
68
*/
79

810
const preventListener = (e) => e.preventDefault();
911

10-
export default function initMarkupTasklist() {
11-
for (const el of document.querySelectorAll(`.markup[data-can-edit='true']`) || []) {
12+
export function initMarkupTasklist() {
13+
for (const el of document.querySelectorAll(`.markup[data-can-edit=true]`) || []) {
1214
const container = el.parentNode;
13-
const checkboxes = el.querySelectorAll(`.task-list-item input[type=checkbox]`);
15+
const checkboxes = el.querySelectorAll(`.task-list-item input[type=checkbox][disabled]`);
1416

1517
for (const checkbox of checkboxes) {
1618
checkbox.addEventListener('input', async () => {

0 commit comments

Comments
 (0)