gitea

Development moved to Codeberg

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
  10. 10
  11. 11
  12. 12
  13. 13
  14. 14
  15. 15
  16. 16
  17. 17
  18. 18
  19. 19
  20. 20
  21. 21
  22. 22
  23. 23
  24. 24
  25. 25
  26. 26
  27. 27
  28. 28
  29. 29
  30. 30
  31. 31
import $ from 'jquery';
import {hideElem, showElem} from '../utils/dom.js';

export function initUnicodeEscapeButton() {
  $(document).on('click', 'a.escape-button', (e) => {
    e.preventDefault();
    $(e.target).parents('.file-content, .non-diff-file-content').find('.file-code, .file-view').addClass('unicode-escaped');
    hideElem($(e.target));
    showElem($(e.target).siblings('a.unescape-button'));
  });
  $(document).on('click', 'a.unescape-button', (e) => {
    e.preventDefault();
    $(e.target).parents('.file-content, .non-diff-file-content').find('.file-code, .file-view').removeClass('unicode-escaped');
    hideElem($(e.target));
    showElem($(e.target).siblings('a.escape-button'));
  });
  $(document).on('click', 'a.toggle-escape-button', (e) => {
    e.preventDefault();
    const fileContent = $(e.target).parents('.file-content, .non-diff-file-content');
    const fileView = fileContent.find('.file-code, .file-view');
    if (fileView.hasClass('unicode-escaped')) {
      fileView.removeClass('unicode-escaped');
      hideElem(fileContent.find('a.unescape-button'));
      showElem(fileContent.find('a.escape-button'));
    } else {
      fileView.addClass('unicode-escaped');
      showElem(fileContent.find('a.unescape-button'));
      hideElem(fileContent.find('a.escape-button'));
    }
  });
}