diff options
author | Kerwin Bryant <kerwin612@qq.com> | 2024-11-26 09:24:56 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-11-26 09:24:56 +0800 |
commit | 25cacaf0aa56bece904c84638fbe126a826c1cd8 (patch) | |
tree | 0d86f72ee63a68ba1f9d11f6a8cadb41f0b2c3c3 /web_src/js | |
parent | 703be6bf307ed19ce8dc8cd311d24aeb6e5b9861 (diff) | |
download | gitea-25cacaf0aa56bece904c84638fbe126a826c1cd8.tar.gz gitea-25cacaf0aa56bece904c84638fbe126a826c1cd8.zip |
Fixed Issue of Review Menu Shown Behind (#32631)
Fixed #31144
---------
Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
Diffstat (limited to 'web_src/js')
-rw-r--r-- | web_src/js/features/repo-diff.ts | 12 | ||||
-rw-r--r-- | web_src/js/features/repo-unicode-escape.ts | 12 | ||||
-rw-r--r-- | web_src/js/utils/dom.ts | 4 |
3 files changed, 20 insertions, 8 deletions
diff --git a/web_src/js/features/repo-diff.ts b/web_src/js/features/repo-diff.ts index 0d489665a2..f39de96f5b 100644 --- a/web_src/js/features/repo-diff.ts +++ b/web_src/js/features/repo-diff.ts @@ -18,6 +18,7 @@ import { } from '../utils/dom.ts'; import {POST, GET} from '../modules/fetch.ts'; import {fomanticQuery} from '../modules/fomantic/base.ts'; +import {createTippy} from '../modules/tippy.ts'; const {pageData, i18n} = window.config; @@ -140,12 +141,22 @@ export function initRepoDiffConversationNav() { }); } +function initDiffHeaderPopup() { + for (const btn of document.querySelectorAll('.diff-header-popup-btn:not([data-header-popup-initialized])')) { + btn.setAttribute('data-header-popup-initialized', ''); + const popup = btn.nextElementSibling; + if (!popup?.matches('.tippy-target')) throw new Error('Popup element not found'); + createTippy(btn, {content: popup, theme: 'menu', placement: 'bottom', trigger: 'click', interactive: true, hideOnClick: true}); + } +} + // Will be called when the show more (files) button has been pressed function onShowMoreFiles() { initRepoIssueContentHistory(); initViewedCheckboxListenerFor(); countAndUpdateViewedFiles(); initImageDiff(); + initDiffHeaderPopup(); } export async function loadMoreFiles(url) { @@ -221,6 +232,7 @@ export function initRepoDiffView() { initDiffFileList(); initDiffCommitSelect(); initRepoDiffShowMore(); + initDiffHeaderPopup(); initRepoDiffFileViewToggle(); initViewedCheckboxListenerFor(); initExpandAndCollapseFilesButton(); diff --git a/web_src/js/features/repo-unicode-escape.ts b/web_src/js/features/repo-unicode-escape.ts index 7a9bca7a37..0c7d2e8592 100644 --- a/web_src/js/features/repo-unicode-escape.ts +++ b/web_src/js/features/repo-unicode-escape.ts @@ -1,13 +1,13 @@ -import {hideElem, queryElemSiblings, showElem, toggleElem} from '../utils/dom.ts'; +import {addDelegatedEventListener, hideElem, queryElemSiblings, showElem, toggleElem} from '../utils/dom.ts'; export function initUnicodeEscapeButton() { - document.addEventListener('click', (e) => { - const btn = e.target.closest('.escape-button, .unescape-button, .toggle-escape-button'); - if (!btn) return; - + addDelegatedEventListener(document, 'click', '.escape-button, .unescape-button, .toggle-escape-button', (btn, e) => { e.preventDefault(); - const fileContent = btn.closest('.file-content, .non-diff-file-content'); + const fileContentElemId = btn.getAttribute('data-file-content-elem-id'); + const fileContent = fileContentElemId ? + document.querySelector(`#${fileContentElemId}`) : + btn.closest('.file-content, .non-diff-file-content'); const fileView = fileContent?.querySelectorAll('.file-code, .file-view'); if (btn.matches('.escape-button')) { for (const el of fileView) el.classList.add('unicode-escaped'); diff --git a/web_src/js/utils/dom.ts b/web_src/js/utils/dom.ts index 4bbb0c414a..a4c7c0e4c6 100644 --- a/web_src/js/utils/dom.ts +++ b/web_src/js/utils/dom.ts @@ -2,10 +2,10 @@ import {debounce} from 'throttle-debounce'; import type {Promisable} from 'type-fest'; import type $ from 'jquery'; -type ElementArg = Element | string | NodeListOf<Element> | Array<Element> | ReturnType<typeof $>; +type ArrayLikeIterable<T> = ArrayLike<T> & Iterable<T>; // for NodeListOf and Array +type ElementArg = Element | string | ArrayLikeIterable<Element> | ReturnType<typeof $>; type ElementsCallback<T extends Element> = (el: T) => Promisable<any>; type ElementsCallbackWithArgs = (el: Element, ...args: any[]) => Promisable<any>; -type ArrayLikeIterable<T> = ArrayLike<T> & Iterable<T>; // for NodeListOf and Array function elementsCall(el: ElementArg, func: ElementsCallbackWithArgs, ...args: any[]) { if (typeof el === 'string' || el instanceof String) { |