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

     1  import $ from 'jquery';
     2  import {hideElem, showElem} from '../utils/dom.js';
     3  
     4  export function initUnicodeEscapeButton() {
     5    $(document).on('click', '.escape-button', (e) => {
     6      e.preventDefault();
     7      $(e.target).parents('.file-content, .non-diff-file-content').find('.file-code, .file-view').addClass('unicode-escaped');
     8      hideElem($(e.target));
     9      showElem($(e.target).siblings('.unescape-button'));
    10    });
    11    $(document).on('click', '.unescape-button', (e) => {
    12      e.preventDefault();
    13      $(e.target).parents('.file-content, .non-diff-file-content').find('.file-code, .file-view').removeClass('unicode-escaped');
    14      hideElem($(e.target));
    15      showElem($(e.target).siblings('.escape-button'));
    16    });
    17    $(document).on('click', '.toggle-escape-button', (e) => {
    18      e.preventDefault();
    19      const fileContent = $(e.target).parents('.file-content, .non-diff-file-content');
    20      const fileView = fileContent.find('.file-code, .file-view');
    21      if (fileView.hasClass('unicode-escaped')) {
    22        fileView.removeClass('unicode-escaped');
    23        hideElem(fileContent.find('.unescape-button'));
    24        showElem(fileContent.find('.escape-button'));
    25      } else {
    26        fileView.addClass('unicode-escaped');
    27        showElem(fileContent.find('.unescape-button'));
    28        hideElem(fileContent.find('.escape-button'));
    29      }
    30    });
    31  }