diff options
author | Yarden Shoham <git@yardenshoham.com> | 2024-03-23 20:18:45 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-03-23 18:18:45 +0000 |
commit | d9e33959b38d1463f69f6f8807bc50095cf6dbdb (patch) | |
tree | cbe34982b768958f199356f3e3c84ec0431abe95 /web_src | |
parent | b9c57fb78e8e0d80d786d8e1da433b6c7ebf2f1c (diff) | |
download | gitea-d9e33959b38d1463f69f6f8807bc50095cf6dbdb.tar.gz gitea-d9e33959b38d1463f69f6f8807bc50095cf6dbdb.zip |
Remove jQuery from the issue "go to" button (#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 <git@yardenshoham.com>
Diffstat (limited to 'web_src')
-rw-r--r-- | web_src/js/features/common-issue-list.js | 31 |
1 files changed, 14 insertions, 17 deletions
diff --git a/web_src/js/features/common-issue-list.js b/web_src/js/features/common-issue-list.js index 8182f99f29..0c0f6c563d 100644 --- a/web_src/js/features/common-issue-list.js +++ b/web_src/js/features/common-issue-list.js @@ -1,4 +1,3 @@ -import $ from 'jquery'; import {isElemHidden, onInputDebounce, submitEventSubmitter, toggleElem} from '../utils/dom.js'; import {GET} from '../modules/fetch.js'; @@ -30,42 +29,40 @@ export function parseIssueListQuickGotoLink(repoLink, searchText) { } export function initCommonIssueListQuickGoto() { - const $goto = $('#issue-list-quick-goto'); - if (!$goto.length) return; + const goto = document.getElementById('issue-list-quick-goto'); + if (!goto) return; - const $form = $goto.closest('form'); - const $input = $form.find('input[name=q]'); - const repoLink = $goto.attr('data-repo-link'); + const form = goto.closest('form'); + const input = form.querySelector('input[name=q]'); + const repoLink = goto.getAttribute('data-repo-link'); - $form.on('submit', (e) => { + form.addEventListener('submit', (e) => { // if there is no goto button, or the form is submitted by non-quick-goto elements, submit the form directly - let doQuickGoto = !isElemHidden($goto); + let doQuickGoto = !isElemHidden(goto); const submitter = submitEventSubmitter(e); - if (submitter !== $form[0] && submitter !== $input[0] && submitter !== $goto[0]) doQuickGoto = false; + if (submitter !== form && submitter !== input && submitter !== goto) doQuickGoto = false; if (!doQuickGoto) return; // if there is a goto button, use its link e.preventDefault(); - window.location.href = $goto.attr('data-issue-goto-link'); + window.location.href = goto.getAttribute('data-issue-goto-link'); }); const onInput = async () => { - const searchText = $input.val(); - + const searchText = input.value; // try to check whether the parsed goto link is valid let targetUrl = parseIssueListQuickGotoLink(repoLink, searchText); if (targetUrl) { const res = await GET(`${targetUrl}/info`); if (res.status !== 200) targetUrl = ''; } - // if the input value has changed, then ignore the result - if ($input.val() !== searchText) return; + if (input.value !== searchText) return; - toggleElem($goto, Boolean(targetUrl)); - $goto.attr('data-issue-goto-link', targetUrl); + toggleElem(goto, Boolean(targetUrl)); + goto.setAttribute('data-issue-goto-link', targetUrl); }; - $input.on('input', onInputDebounce(onInput)); + input.addEventListener('input', onInputDebounce(onInput)); onInput(); } |