mirror of
https://github.com/go-gitea/gitea.git
synced 2024-12-24 19:23:43 +08:00
00e2b339b6
<details> ![image](https://github.com/user-attachments/assets/98aef2fb-791e-4b4a-b2ac-e880f8a52040) ![image](https://github.com/user-attachments/assets/532673ae-c4cf-4d84-a5c6-93e6eacd341c) ![image](https://github.com/user-attachments/assets/2a241a3d-b7f6-44ca-89d9-9d68386fbf3e) ![image](https://github.com/user-attachments/assets/1251e43d-41f2-42d1-a23b-3182e3812c3d) </details> --------- Co-authored-by: silverwind <me@silverwind.io>
29 lines
1.4 KiB
TypeScript
29 lines
1.4 KiB
TypeScript
import {addDelegatedEventListener, hideElem, queryElemSiblings, showElem, toggleElem} from '../utils/dom.ts';
|
|
|
|
export function initUnicodeEscapeButton() {
|
|
// buttons might appear on these pages: file view (code, rendered markdown), diff (commit, pr conversation, pr diff), blame, wiki
|
|
addDelegatedEventListener(document, 'click', '.escape-button, .unescape-button, .toggle-escape-button', (btn, e) => {
|
|
e.preventDefault();
|
|
|
|
const unicodeContentSelector = btn.getAttribute('data-unicode-content-selector');
|
|
const container = unicodeContentSelector ?
|
|
document.querySelector(unicodeContentSelector) :
|
|
btn.closest('.file-content, .non-diff-file-content');
|
|
const fileView = container.querySelector('.file-code, .file-view') ?? container;
|
|
if (btn.matches('.escape-button')) {
|
|
fileView.classList.add('unicode-escaped');
|
|
hideElem(btn);
|
|
showElem(queryElemSiblings(btn, '.unescape-button'));
|
|
} else if (btn.matches('.unescape-button')) {
|
|
fileView.classList.remove('unicode-escaped');
|
|
hideElem(btn);
|
|
showElem(queryElemSiblings(btn, '.escape-button'));
|
|
} else if (btn.matches('.toggle-escape-button')) {
|
|
const isEscaped = fileView.classList.contains('unicode-escaped');
|
|
fileView.classList.toggle('unicode-escaped', !isEscaped);
|
|
toggleElem(container.querySelectorAll('.unescape-button'), !isEscaped);
|
|
toggleElem(container.querySelectorAll('.escape-button'), isEscaped);
|
|
}
|
|
});
|
|
}
|