code.gitea.io/gitea@v1.22.3/web_src/js/features/repo-unicode-escape.js (about)

     1  import {hideElem, queryElemSiblings, showElem, toggleElem} from '../utils/dom.js';
     2  
     3  export function initUnicodeEscapeButton() {
     4    document.addEventListener('click', (e) => {
     5      const btn = e.target.closest('.escape-button, .unescape-button, .toggle-escape-button');
     6      if (!btn) return;
     7  
     8      e.preventDefault();
     9  
    10      const fileContent = btn.closest('.file-content, .non-diff-file-content');
    11      const fileView = fileContent?.querySelectorAll('.file-code, .file-view');
    12      if (btn.matches('.escape-button')) {
    13        for (const el of fileView) el.classList.add('unicode-escaped');
    14        hideElem(btn);
    15        showElem(queryElemSiblings(btn, '.unescape-button'));
    16      } else if (btn.matches('.unescape-button')) {
    17        for (const el of fileView) el.classList.remove('unicode-escaped');
    18        hideElem(btn);
    19        showElem(queryElemSiblings(btn, '.escape-button'));
    20      } else if (btn.matches('.toggle-escape-button')) {
    21        const isEscaped = fileView[0]?.classList.contains('unicode-escaped');
    22        for (const el of fileView) el.classList.toggle('unicode-escaped', !isEscaped);
    23        toggleElem(fileContent.querySelectorAll('.unescape-button'), !isEscaped);
    24        toggleElem(fileContent.querySelectorAll('.escape-button'), isEscaped);
    25      }
    26    });
    27  }