Skip to content

Commit 23265d5

Browse files
committed
Replace jQuery Code with plain JavaScript
1 parent 1e63ea8 commit 23265d5

2 files changed

Lines changed: 50 additions & 35 deletions

File tree

wcfsetup/install/files/acp/templates/bbcodeAdd.tpl

Lines changed: 34 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -43,37 +43,45 @@
4343
{/capture}
4444

4545
<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();
5050
});
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+
});
5966
});
60-
$('#attributeFieldset').append($html);
67+
document.getElementById('attributeFieldset').appendChild(section);
6168
});
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));
7278
}
73-
74-
$showButton.change(toggleButtonSettings);
79+
}
80+
81+
if (showButton) {
82+
showButton.addEventListener('change', toggleButtonSettings);
7583
toggleButtonSettings();
76-
});
84+
}
7785
});
7886
</script>
7987

wcfsetup/install/files/acp/templates/paidSubscriptionAdd.tpl

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,23 @@
11
{include file='header' pageTitle='wcf.acp.paidSubscription.'|concat:$action}
22

33
<script data-relocate="true">
4-
$(function() {
5-
$('#subscriptionLengthPermanent').change(function() {
6-
if ($('#subscriptionLengthPermanent').is(':checked')) {
7-
$('#subscriptionLengthDL, #isRecurringDL').hide();
8-
}
9-
else {
10-
$('#subscriptionLengthDL, #isRecurringDL').show();
4+
require(['WoltLabSuite/Core/Dom/Util'], ({ show, hide }) => {
5+
const subscriptionLengthPermanent = document.getElementById('subscriptionLengthPermanent');
6+
const subscriptionLengthDL = document.getElementById('subscriptionLengthDL');
7+
const isRecurringDL = document.getElementById('isRecurringDL');
8+
9+
function toggleSubscriptionElements() {
10+
if (subscriptionLengthPermanent.checked) {
11+
hide(subscriptionLengthDL);
12+
hide(isRecurringDL);
13+
} else {
14+
show(subscriptionLengthDL);
15+
show(isRecurringDL);
1116
}
12-
});
13-
$('#subscriptionLengthPermanent').change();
17+
}
18+
19+
subscriptionLengthPermanent.addEventListener('change', toggleSubscriptionElements);
20+
toggleSubscriptionElements();
1421
});
1522
</script>
1623

0 commit comments

Comments
 (0)