Skip to content

Commit 898b90b

Browse files
yardenshohamsilverwind
authored andcommitted
Remove jQuery from the issue "go to" button (go-gitea#30028)
- Switched to plain JavaScript - Tested the "go to" button functionality and it works as before # Demo using JavaScript without jQuery ![demo](https://github.com/go-gitea/gitea/assets/20454870/76add18f-3294-4117-98b7-a97f576370e2) Signed-off-by: Yarden Shoham <[email protected]>
1 parent 5122007 commit 898b90b

File tree

1 file changed

+14
-17
lines changed

1 file changed

+14
-17
lines changed

web_src/js/features/common-issue-list.js

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import $ from 'jquery';
21
import {isElemHidden, onInputDebounce, submitEventSubmitter, toggleElem} from '../utils/dom.js';
32
import {GET} from '../modules/fetch.js';
43

@@ -30,42 +29,40 @@ export function parseIssueListQuickGotoLink(repoLink, searchText) {
3029
}
3130

3231
export function initCommonIssueListQuickGoto() {
33-
const $goto = $('#issue-list-quick-goto');
34-
if (!$goto.length) return;
32+
const goto = document.getElementById('issue-list-quick-goto');
33+
if (!goto) return;
3534

36-
const $form = $goto.closest('form');
37-
const $input = $form.find('input[name=q]');
38-
const repoLink = $goto.attr('data-repo-link');
35+
const form = goto.closest('form');
36+
const input = form.querySelector('input[name=q]');
37+
const repoLink = goto.getAttribute('data-repo-link');
3938

40-
$form.on('submit', (e) => {
39+
form.addEventListener('submit', (e) => {
4140
// if there is no goto button, or the form is submitted by non-quick-goto elements, submit the form directly
42-
let doQuickGoto = !isElemHidden($goto);
41+
let doQuickGoto = !isElemHidden(goto);
4342
const submitter = submitEventSubmitter(e);
44-
if (submitter !== $form[0] && submitter !== $input[0] && submitter !== $goto[0]) doQuickGoto = false;
43+
if (submitter !== form && submitter !== input && submitter !== goto) doQuickGoto = false;
4544
if (!doQuickGoto) return;
4645

4746
// if there is a goto button, use its link
4847
e.preventDefault();
49-
window.location.href = $goto.attr('data-issue-goto-link');
48+
window.location.href = goto.getAttribute('data-issue-goto-link');
5049
});
5150

5251
const onInput = async () => {
53-
const searchText = $input.val();
54-
52+
const searchText = input.value;
5553
// try to check whether the parsed goto link is valid
5654
let targetUrl = parseIssueListQuickGotoLink(repoLink, searchText);
5755
if (targetUrl) {
5856
const res = await GET(`${targetUrl}/info`);
5957
if (res.status !== 200) targetUrl = '';
6058
}
61-
6259
// if the input value has changed, then ignore the result
63-
if ($input.val() !== searchText) return;
60+
if (input.value !== searchText) return;
6461

65-
toggleElem($goto, Boolean(targetUrl));
66-
$goto.attr('data-issue-goto-link', targetUrl);
62+
toggleElem(goto, Boolean(targetUrl));
63+
goto.setAttribute('data-issue-goto-link', targetUrl);
6764
};
6865

69-
$input.on('input', onInputDebounce(onInput));
66+
input.addEventListener('input', onInputDebounce(onInput));
7067
onInput();
7168
}

0 commit comments

Comments
 (0)