|
1 |
| -import $ from 'jquery'; |
2 | 1 | import {isElemHidden, onInputDebounce, submitEventSubmitter, toggleElem} from '../utils/dom.js';
|
3 | 2 | import {GET} from '../modules/fetch.js';
|
4 | 3 |
|
@@ -30,42 +29,40 @@ export function parseIssueListQuickGotoLink(repoLink, searchText) {
|
30 | 29 | }
|
31 | 30 |
|
32 | 31 | 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; |
35 | 34 |
|
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'); |
39 | 38 |
|
40 |
| - $form.on('submit', (e) => { |
| 39 | + form.addEventListener('submit', (e) => { |
41 | 40 | // 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); |
43 | 42 | 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; |
45 | 44 | if (!doQuickGoto) return;
|
46 | 45 |
|
47 | 46 | // if there is a goto button, use its link
|
48 | 47 | e.preventDefault();
|
49 |
| - window.location.href = $goto.attr('data-issue-goto-link'); |
| 48 | + window.location.href = goto.getAttribute('data-issue-goto-link'); |
50 | 49 | });
|
51 | 50 |
|
52 | 51 | const onInput = async () => {
|
53 |
| - const searchText = $input.val(); |
54 |
| - |
| 52 | + const searchText = input.value; |
55 | 53 | // try to check whether the parsed goto link is valid
|
56 | 54 | let targetUrl = parseIssueListQuickGotoLink(repoLink, searchText);
|
57 | 55 | if (targetUrl) {
|
58 | 56 | const res = await GET(`${targetUrl}/info`);
|
59 | 57 | if (res.status !== 200) targetUrl = '';
|
60 | 58 | }
|
61 |
| - |
62 | 59 | // if the input value has changed, then ignore the result
|
63 |
| - if ($input.val() !== searchText) return; |
| 60 | + if (input.value !== searchText) return; |
64 | 61 |
|
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); |
67 | 64 | };
|
68 | 65 |
|
69 |
| - $input.on('input', onInputDebounce(onInput)); |
| 66 | + input.addEventListener('input', onInputDebounce(onInput)); |
70 | 67 | onInput();
|
71 | 68 | }
|
0 commit comments