From 309d8bfca96c3fd8eec42ce1838317b84fe30d2f Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Mon, 13 Feb 2023 14:08:17 +0800 Subject: [PATCH 1/4] fix --- web_src/js/jquery.js | 71 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) diff --git a/web_src/js/jquery.js b/web_src/js/jquery.js index 892e2763cbbf..f54bd9992a3a 100644 --- a/web_src/js/jquery.js +++ b/web_src/js/jquery.js @@ -1,3 +1,74 @@ import $ from 'jquery'; window.$ = window.jQuery = $; + +function getComputedStyleProperty(el, prop) { + const cs = el ? window.getComputedStyle(el) : null; + return cs ? cs[prop] : null; +} + +const defaultDisplayMap = {}; +function getDefaultDisplay(el) { + let display = defaultDisplayMap[el.nodeName]; + if (display) return display; + + const temp = el.ownerDocument.body.appendChild(el.ownerDocument.createElement(el.nodeName)); + display = getComputedStyleProperty(el, 'display'); + temp.parentNode.removeChild(temp); + + display = display === 'none' ? 'block' : display; + defaultDisplayMap[el.nodeName] = display; + return display; +} + +function showHide(elements, show) { + for (const el of elements) { + if (!el || !el.classList) continue; + if (show) { + // at the moment, there are various hiding-methods in Gitea + // in the future, after they are all refactored by "gt-hidden" class, we can remove all others + el.removeAttribute('hidden'); + el.classList.remove('hide', 'gt-hidden'); + if (el.style.display === 'none') el.style.removeProperty('display'); + + if (getComputedStyleProperty(el, 'display') === 'none') { + // after removing all "hidden" related classes/attributes, if the element is still hidden, + // maybe it already has another class with "display: none", so we need to set the "display: xxx" to its style + el.style.display = getDefaultDisplay(el); + } + } else { + el.classList.add('gt-hidden'); + } + } + return elements; +} + +function warnDeprecated(fn) { + if (!window.config?.runModeIsProd) { + console.warn(`jQuery.${fn}() is deprecated, add/remove Gitea specialized helper "gt-hidden" class instead`); + } +} + +window.jQuery.fn.extend({ + show () { + warnDeprecated('show'); + return showHide(this, true); + }, + hide () { + warnDeprecated('hide'); + return showHide(this, false); + }, + toggle (state) { + warnDeprecated('toggle'); + if (typeof state === 'boolean') { + return showHide(this, state); + } + return this.each(function () { + if (getComputedStyleProperty(this, 'display') === 'none') { + $(this).show(); + } else { + $(this).hide(); + } + }); + } +}); From c6c3afcd8c593c8b495a06a7c1d6c56ab06faca7 Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Tue, 14 Feb 2023 02:29:10 +0800 Subject: [PATCH 2/4] refactor `.hide` class --- .../repo/issue/view_content/comments.tmpl | 8 +++---- web_src/js/features/repo-issue.js | 24 +++++++++---------- web_src/js/jquery.js | 6 +++-- web_src/less/_base.less | 9 +------ web_src/less/_review.less | 1 - web_src/less/helpers.less | 4 +++- 6 files changed, 24 insertions(+), 28 deletions(-) diff --git a/templates/repo/issue/view_content/comments.tmpl b/templates/repo/issue/view_content/comments.tmpl index 90646045d0fa..79ab934f55e5 100644 --- a/templates/repo/issue/view_content/comments.tmpl +++ b/templates/repo/issue/view_content/comments.tmpl @@ -485,7 +485,7 @@
{{if or $invalid $resolved}} - -