Skip to content

Commit a9a85a3

Browse files
KN4CK3Rsilverwind
authored andcommitted
Replaced jQuery with vanilla javascript.
1 parent 035c60e commit a9a85a3

File tree

1 file changed

+18
-18
lines changed

1 file changed

+18
-18
lines changed

web_src/js/markup/tasklist.js

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,44 +4,44 @@
44
* On success it updates the raw-content on error it resets the checkbox to its original value.
55
*/
66
export default function initMarkupTasklist() {
7-
$(`.render-content.markup[data-can-edit='true']`).parent().each((_, container) => {
8-
const $container = $(container);
9-
const $checkboxes = $container.find(`.task-list-item input:checkbox`);
7+
document.querySelectorAll(`.render-content.markup[data-can-edit='true']`).forEach((el) => {
8+
const container = el.parentNode;
9+
const checkboxes = container.querySelectorAll(`.task-list-item input[type=checkbox]`);
1010

11-
$checkboxes.on('change', async (ev) => {
12-
const $checkbox = $(ev.target);
13-
const checkboxCharacter = $checkbox.is(':checked') ? 'x' : ' ';
14-
const position = parseInt($checkbox.data('source-position')) + 1;
11+
checkboxes.forEach((cb) => cb.addEventListener('change', async (ev) => {
12+
const checkbox = ev.target;
13+
const checkboxCharacter = checkbox.checked ? 'x' : ' ';
14+
const position = parseInt(checkbox.dataset.sourcePosition) + 1;
1515

16-
const $rawContent = $container.find('.raw-content');
17-
const oldContent = $rawContent.text();
16+
const rawContent = container.querySelector('.raw-content');
17+
const oldContent = rawContent.textContent;
1818
const newContent = oldContent.substring(0, position) + checkboxCharacter + oldContent.substring(position + 1);
1919

2020
if (newContent !== oldContent) {
21-
$checkboxes.prop('disabled', true);
21+
checkboxes.forEach((cb) => cb.disabled = true);
2222

2323
try {
24-
const $contentZone = $container.find('.edit-content-zone');
25-
const url = $contentZone.data('update-url');
26-
const context = $contentZone.data('context');
24+
const contentZone = container.querySelector('.edit-content-zone');
25+
const url = contentZone.dataset.updateUrl;
26+
const context = contentZone.dataset.context;
2727

2828
await $.post(url, {
2929
_csrf: window.config.csrf,
3030
content: newContent,
3131
context,
3232
});
3333

34-
$rawContent.text(newContent);
34+
rawContent.textContent = newContent;
3535
} catch (e) {
36-
$checkbox.prop('checked', !$checkbox.is(':checked'));
36+
checkbox.checked = !checkbox.checked;
3737

3838
console.error(e);
3939
} finally {
40-
$checkboxes.prop('disabled', false);
40+
checkboxes.forEach((cb) => cb.disabled = false);
4141
}
4242
}
43-
});
43+
}));
4444

45-
$checkboxes.prop('disabled', false);
45+
checkboxes.forEach((cb) => cb.disabled = false);
4646
});
4747
}

0 commit comments

Comments
 (0)