mirror of
				https://gitee.com/gitea/gitea
				synced 2025-11-04 16:40:24 +08:00 
			
		
		
		
	Refactor hiding-methods, remove jQuery show/hide, remove .hide class, remove inline style=display:none (#22950)
				
					
				
			Close #22847 This PR: * introduce Gitea's own `showElem` and related functions * remove jQuery show/hide * remove .hide class * remove inline style=display:none From now on: do not use: * "[hidden]" attribute: it's too weak, can not be applied to an element with "display: flex" * ".hidden" class: it has been polluted by Fomantic UI in many cases * inline style="display: none": it's difficult to tweak * jQuery's show/hide/toggle: it can not show/hide elements with "display: xxx !important" only use: * this ".gt-hidden" class * showElem/hideElem/toggleElem functions in "utils/dom.js" cc: @silverwind , this is the all-in-one PR
This commit is contained in:
		@@ -1,17 +1,18 @@
 | 
			
		||||
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');
 | 
			
		||||
    $(e.target).hide();
 | 
			
		||||
    $(e.target).siblings('a.unescape-button').show();
 | 
			
		||||
    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');
 | 
			
		||||
    $(e.target).hide();
 | 
			
		||||
    $(e.target).siblings('a.escape-button').show();
 | 
			
		||||
    hideElem($(e.target));
 | 
			
		||||
    showElem($(e.target).siblings('a.escape-button'));
 | 
			
		||||
  });
 | 
			
		||||
  $(document).on('click', 'a.toggle-escape-button', (e) => {
 | 
			
		||||
    e.preventDefault();
 | 
			
		||||
@@ -19,12 +20,12 @@ export function initUnicodeEscapeButton() {
 | 
			
		||||
    const fileView = fileContent.find('.file-code, .file-view');
 | 
			
		||||
    if (fileView.hasClass('unicode-escaped')) {
 | 
			
		||||
      fileView.removeClass('unicode-escaped');
 | 
			
		||||
      fileContent.find('a.unescape-button').hide();
 | 
			
		||||
      fileContent.find('a.escape-button').show();
 | 
			
		||||
      hideElem(fileContent.find('a.unescape-button'));
 | 
			
		||||
      showElem(fileContent.find('a.escape-button'));
 | 
			
		||||
    } else {
 | 
			
		||||
      fileView.addClass('unicode-escaped');
 | 
			
		||||
      fileContent.find('a.unescape-button').show();
 | 
			
		||||
      fileContent.find('a.escape-button').hide();
 | 
			
		||||
      showElem(fileContent.find('a.unescape-button'));
 | 
			
		||||
      hideElem(fileContent.find('a.escape-button'));
 | 
			
		||||
    }
 | 
			
		||||
  });
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user