|
43 | 43 | {/capture} |
44 | 44 |
|
45 | 45 | <script data-relocate="true"> |
46 | | - require(['WoltLabSuite/Core/Template'], (Template) => { |
47 | | - $(function() { |
48 | | - $('.jsDeleteButton').click(function (event) { |
49 | | - $(event.target).parent().parent().remove(); |
| 46 | + require(['WoltLabSuite/Core/Template', 'WoltLabSuite/Core/Dom/Util'], (Template, { hide, show }) => { |
| 47 | + document.querySelectorAll('.jsDeleteButton').forEach((btn) => { |
| 48 | + btn.addEventListener('click', () => { |
| 49 | + btn.closest('.section').remove(); |
50 | 50 | }); |
51 | | - |
52 | | - var attributeNo = {if !$attributes|count}0{else}{assign var='lastAttribute' value=$attributes|end}{$lastAttribute->attributeNo+1}{/if}; |
53 | | - var attributeTemplate = new Template('{unsafe:$attributeTemplate|encodeJS}'); |
54 | | - |
55 | | - $('.jsAddButton').click(function (event) { |
56 | | - var $html = $($.parseHTML(attributeTemplate.fetch({ attributeNo: attributeNo++ }))); |
57 | | - $html.find('.jsDeleteButton').click(function (event) { |
58 | | - $(event.target).parent().parent().remove(); |
| 51 | + }); |
| 52 | +
|
| 53 | + let attributeNo = {if !$attributes|count}0{else}{assign var='lastAttribute' value=$attributes|end}{$lastAttribute->attributeNo+1}{/if}; |
| 54 | + const attributeTemplate = new Template('{unsafe:$attributeTemplate|encodeJS}'); |
| 55 | +
|
| 56 | + document.querySelectorAll('.jsAddButton').forEach((btn) => { |
| 57 | + btn.addEventListener('click', () => { |
| 58 | + const html = attributeTemplate.fetch({ attributeNo: attributeNo++ }); |
| 59 | + const tempDiv = document.createElement('div'); |
| 60 | + tempDiv.innerHTML = html; |
| 61 | + const section = tempDiv.firstElementChild; |
| 62 | + section.querySelectorAll('.jsDeleteButton').forEach((delBtn) => { |
| 63 | + delBtn.addEventListener('click', () => { |
| 64 | + delBtn.closest('.section').remove(); |
| 65 | + }); |
59 | 66 | }); |
60 | | - $('#attributeFieldset').append($html); |
| 67 | + document.getElementById('attributeFieldset').appendChild(section); |
61 | 68 | }); |
62 | | - |
63 | | - var $buttonSettings = $('.jsButtonSetting'); |
64 | | - var $showButton = $('#showButton'); |
65 | | - function toggleButtonSettings() { |
66 | | - if ($showButton.is(':checked')) { |
67 | | - $buttonSettings.show(); |
68 | | - } |
69 | | - else { |
70 | | - $buttonSettings.hide(); |
71 | | - } |
| 69 | + }); |
| 70 | +
|
| 71 | + const buttonSettings = document.querySelectorAll('.jsButtonSetting'); |
| 72 | + const showButton = document.getElementById('showButton'); |
| 73 | + function toggleButtonSettings() { |
| 74 | + if (showButton.checked) { |
| 75 | + buttonSettings.forEach(el => show(el)); |
| 76 | + } else { |
| 77 | + buttonSettings.forEach(el => hide(el)); |
72 | 78 | } |
73 | | - |
74 | | - $showButton.change(toggleButtonSettings); |
| 79 | + } |
| 80 | +
|
| 81 | + if (showButton) { |
| 82 | + showButton.addEventListener('change', toggleButtonSettings); |
75 | 83 | toggleButtonSettings(); |
76 | | - }); |
| 84 | + } |
77 | 85 | }); |
78 | 86 | </script> |
79 | 87 |
|
|
0 commit comments