mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-11-30 09:41:11 -05:00
22aedc6c96
Backport: https://codeberg.org/forgejo/forgejo/pulls/2669 (cherry picked from commit1d3240887c
) (cherry picked from commit781a37fbe1
) (cherry picked from commit8309f008c2
) (cherry picked from commitfae8d9f70d
) (cherry picked from commit6721cba75b
) (cherry picked from commit562e5cdf32
) (cherry picked from commitd789d33229
) (cherry picked from commit8218e80bfc
) (cherry picked from commit10bca456a9
) (cherry picked from commitdb6f6281fc
) (cherry picked from commited8e8a792e
) (cherry picked from commitd6428f92ce
) (cherry picked from commit069d87b80f
) (cherry picked from commit2b6546adc9
) (cherry picked from commit4c7cb0a5d2
) (cherry picked from commit7e0014dd13
) (cherry picked from commit16a8658878
) (cherry picked from commit6e98bacbbd
)
27 lines
1.3 KiB
JavaScript
27 lines
1.3 KiB
JavaScript
import {hideElem, queryElemSiblings, showElem, toggleElem} from '../utils/dom.js';
|
|
|
|
export function initUnicodeEscapeButton() {
|
|
document.addEventListener('click', (e) => {
|
|
const btn = e.target.closest('.escape-button, .unescape-button, .toggle-escape-button');
|
|
if (!btn) return;
|
|
|
|
e.preventDefault();
|
|
|
|
const fileContent = btn.closest('.file-content, .non-diff-file-content, .file-preview-box');
|
|
const fileView = fileContent?.querySelectorAll('.file-code, .file-view, .file-preview');
|
|
if (btn.matches('.escape-button')) {
|
|
for (const el of fileView) el.classList.add('unicode-escaped');
|
|
hideElem(btn);
|
|
showElem(queryElemSiblings(btn, '.unescape-button'));
|
|
} else if (btn.matches('.unescape-button')) {
|
|
for (const el of fileView) el.classList.remove('unicode-escaped');
|
|
hideElem(btn);
|
|
showElem(queryElemSiblings(btn, '.escape-button'));
|
|
} else if (btn.matches('.toggle-escape-button')) {
|
|
const isEscaped = fileView[0]?.classList.contains('unicode-escaped');
|
|
for (const el of fileView) el.classList.toggle('unicode-escaped', !isEscaped);
|
|
toggleElem(fileContent.querySelectorAll('.unescape-button'), !isEscaped);
|
|
toggleElem(fileContent.querySelectorAll('.escape-button'), isEscaped);
|
|
}
|
|
});
|
|
}
|