|
4 | 4 | * On success it updates the raw-content on error it resets the checkbox to its original value.
|
5 | 5 | */
|
6 | 6 | 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]`); |
10 | 10 |
|
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; |
15 | 15 |
|
16 |
| - const $rawContent = $container.find('.raw-content'); |
17 |
| - const oldContent = $rawContent.text(); |
| 16 | + const rawContent = container.querySelector('.raw-content'); |
| 17 | + const oldContent = rawContent.textContent; |
18 | 18 | const newContent = oldContent.substring(0, position) + checkboxCharacter + oldContent.substring(position + 1);
|
19 | 19 |
|
20 | 20 | if (newContent !== oldContent) {
|
21 |
| - $checkboxes.prop('disabled', true); |
| 21 | + checkboxes.forEach((cb) => cb.disabled = true); |
22 | 22 |
|
23 | 23 | 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; |
27 | 27 |
|
28 | 28 | await $.post(url, {
|
29 | 29 | _csrf: window.config.csrf,
|
30 | 30 | content: newContent,
|
31 | 31 | context,
|
32 | 32 | });
|
33 | 33 |
|
34 |
| - $rawContent.text(newContent); |
| 34 | + rawContent.textContent = newContent; |
35 | 35 | } catch (e) {
|
36 |
| - $checkbox.prop('checked', !$checkbox.is(':checked')); |
| 36 | + checkbox.checked = !checkbox.checked; |
37 | 37 |
|
38 | 38 | console.error(e);
|
39 | 39 | } finally {
|
40 |
| - $checkboxes.prop('disabled', false); |
| 40 | + checkboxes.forEach((cb) => cb.disabled = false); |
41 | 41 | }
|
42 | 42 | }
|
43 |
| - }); |
| 43 | + })); |
44 | 44 |
|
45 |
| - $checkboxes.prop('disabled', false); |
| 45 | + checkboxes.forEach((cb) => cb.disabled = false); |
46 | 46 | });
|
47 | 47 | }
|
0 commit comments