Skip to content

Commit 27192bc

Browse files
Remove jQuery from the webhook editor (go-gitea#29211)
- Switched to plain JavaScript - Tested the webhook editing functionality and it works as before # Demo using JavaScript without jQuery ![action](https://github.com/go-gitea/gitea/assets/20454870/b24c264d-d5e5-4954-8789-e72564a99027) --------- Signed-off-by: Yarden Shoham <[email protected]> Co-authored-by: wxiaoguang <[email protected]>
1 parent c282d37 commit 27192bc

File tree

1 file changed

+27
-29
lines changed

1 file changed

+27
-29
lines changed
+27-29
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,41 @@
1-
import $ from 'jquery';
1+
import {POST} from '../../modules/fetch.js';
22
import {hideElem, showElem, toggleElem} from '../../utils/dom.js';
33

4-
const {csrfToken} = window.config;
5-
64
export function initCompWebHookEditor() {
7-
if ($('.new.webhook').length === 0) {
5+
if (!document.querySelectorAll('.new.webhook').length) {
86
return;
97
}
108

11-
$('.events.checkbox input').on('change', function () {
12-
if ($(this).is(':checked')) {
13-
showElem($('.events.fields'));
14-
}
15-
});
16-
$('.non-events.checkbox input').on('change', function () {
17-
if ($(this).is(':checked')) {
18-
hideElem($('.events.fields'));
19-
}
20-
});
9+
for (const input of document.querySelectorAll('.events.checkbox input')) {
10+
input.addEventListener('change', function () {
11+
if (this.checked) {
12+
showElem('.events.fields');
13+
}
14+
});
15+
}
16+
17+
for (const input of document.querySelectorAll('.non-events.checkbox input')) {
18+
input.addEventListener('change', function () {
19+
if (this.checked) {
20+
hideElem('.events.fields');
21+
}
22+
});
23+
}
2124

2225
const updateContentType = function () {
23-
const visible = $('#http_method').val() === 'POST';
24-
toggleElem($('#content_type').parent().parent(), visible);
26+
const visible = document.getElementById('http_method').value === 'POST';
27+
toggleElem(document.getElementById('content_type').parentNode.parentNode, visible);
2528
};
2629
updateContentType();
27-
$('#http_method').on('change', () => {
28-
updateContentType();
29-
});
30+
31+
document.getElementById('http_method').addEventListener('change', updateContentType);
3032

3133
// Test delivery
32-
$('#test-delivery').on('click', function () {
33-
const $this = $(this);
34-
$this.addClass('loading disabled');
35-
$.post($this.data('link'), {
36-
_csrf: csrfToken
37-
}).done(
38-
setTimeout(() => {
39-
window.location.href = $this.data('redirect');
40-
}, 5000)
41-
);
34+
document.getElementById('test-delivery')?.addEventListener('click', async function () {
35+
this.classList.add('loading', 'disabled');
36+
await POST(this.getAttribute('data-link'));
37+
setTimeout(() => {
38+
window.location.href = this.getAttribute('data-redirect');
39+
}, 5000);
4240
});
4341
}

0 commit comments

Comments
 (0)