mirror of
https://codeberg.org/forgejo/forgejo
synced 2024-11-22 09:54:24 +01:00
fix commit view JS features, reimplement folding (#9968)
* fix commit view JS features, reimplement folding File content folding was not working so I reimplemented it in a saner way. Then I noticed the issue was actually because of missing JS libraries (seen on the console of every commit with error 'SimpleMDE is not defined'). Fixed the libraries. I think the reimplementation is worth to keep. * add .closest polyfill Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
This commit is contained in:
parent
8d51f28ba0
commit
fd094eea95
|
@ -206,6 +206,8 @@ func FileHistory(ctx *context.Context) {
|
||||||
func Diff(ctx *context.Context) {
|
func Diff(ctx *context.Context) {
|
||||||
ctx.Data["PageIsDiff"] = true
|
ctx.Data["PageIsDiff"] = true
|
||||||
ctx.Data["RequireHighlightJS"] = true
|
ctx.Data["RequireHighlightJS"] = true
|
||||||
|
ctx.Data["RequireSimpleMDE"] = true
|
||||||
|
ctx.Data["RequireTribute"] = true
|
||||||
|
|
||||||
userName := ctx.Repo.Owner.Name
|
userName := ctx.Repo.Owner.Name
|
||||||
repoName := ctx.Repo.Repository.Name
|
repoName := ctx.Repo.Repository.Name
|
||||||
|
|
|
@ -80,7 +80,7 @@
|
||||||
</div>
|
</div>
|
||||||
{{else}}
|
{{else}}
|
||||||
<div class="diff-file-box diff-box file-content {{TabSizeClass $.Editorconfig $file.Name}}" id="diff-{{.Index}}">
|
<div class="diff-file-box diff-box file-content {{TabSizeClass $.Editorconfig $file.Name}}" id="diff-{{.Index}}">
|
||||||
<h4 class="ui top attached normal header">
|
<h4 class="diff-file-header ui top attached normal header">
|
||||||
{{$isImage := false}}
|
{{$isImage := false}}
|
||||||
{{if $file.IsDeleted}}
|
{{if $file.IsDeleted}}
|
||||||
{{$isImage = (call $.IsImageFileInBase $file.Name)}}
|
{{$isImage = (call $.IsImageFileInBase $file.Name)}}
|
||||||
|
@ -111,7 +111,7 @@
|
||||||
{{end}}
|
{{end}}
|
||||||
{{end}}
|
{{end}}
|
||||||
</h4>
|
</h4>
|
||||||
<div class="ui attached unstackable table segment">
|
<div class="diff-file-body ui attached unstackable table segment">
|
||||||
{{if ne $file.Type 4}}
|
{{if ne $file.Type 4}}
|
||||||
<div class="file-body file-code code-view has-context-menu code-diff {{if $.IsSplitStyle}}code-diff-split{{else}}code-diff-unified{{end}}">
|
<div class="file-body file-code code-view has-context-menu code-diff {{if $.IsSplitStyle}}code-diff-split{{else}}code-diff-unified{{end}}">
|
||||||
<table>
|
<table>
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
/* exported toggleDeadlineForm, setDeadline, updateDeadline, deleteDependencyModal, cancelCodeComment, onOAuthLoginClick */
|
/* exported toggleDeadlineForm, setDeadline, updateDeadline, deleteDependencyModal, cancelCodeComment, onOAuthLoginClick */
|
||||||
|
|
||||||
import './publicPath.js';
|
import './publicPath.js';
|
||||||
|
import './polyfills.js';
|
||||||
import './gitGraphLoader.js';
|
import './gitGraphLoader.js';
|
||||||
import './semanticDropdown.js';
|
import './semanticDropdown.js';
|
||||||
import initContextPopups from './features/contextPopup';
|
import initContextPopups from './features/contextPopup';
|
||||||
|
@ -2109,17 +2110,12 @@ function initCodeView() {
|
||||||
}
|
}
|
||||||
}).trigger('hashchange');
|
}).trigger('hashchange');
|
||||||
}
|
}
|
||||||
$('.ui.fold-code').on('click', (e) => {
|
$('.fold-code').on('click', ({ target }) => {
|
||||||
const $foldButton = $(e.target);
|
const box = target.closest('.file-content');
|
||||||
if ($foldButton.hasClass('fa-chevron-down')) {
|
const folded = box.dataset.folded !== 'true';
|
||||||
$(e.target).parent().next().slideUp('fast', () => {
|
target.classList.add(`fa-chevron-${folded ? 'right' : 'down'}`);
|
||||||
$foldButton.removeClass('fa-chevron-down').addClass('fa-chevron-right');
|
target.classList.remove(`fa-chevron-${folded ? 'down' : 'right'}`);
|
||||||
});
|
box.dataset.folded = String(folded);
|
||||||
} else {
|
|
||||||
$(e.target).parent().next().slideDown('fast', () => {
|
|
||||||
$foldButton.removeClass('fa-chevron-right').addClass('fa-chevron-down');
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
function insertBlobExcerpt(e) {
|
function insertBlobExcerpt(e) {
|
||||||
const $blob = $(e.target);
|
const $blob = $(e.target);
|
||||||
|
|
17
web_src/js/polyfills.js
Normal file
17
web_src/js/polyfills.js
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
// compat: IE11
|
||||||
|
if (!Element.prototype.matches) {
|
||||||
|
Element.prototype.matches = Element.prototype.msMatchesSelector || Element.prototype.webkitMatchesSelector;
|
||||||
|
}
|
||||||
|
|
||||||
|
// compat: IE11
|
||||||
|
if (!Element.prototype.closest) {
|
||||||
|
Element.prototype.closest = function (s) {
|
||||||
|
let el = this;
|
||||||
|
|
||||||
|
do {
|
||||||
|
if (el.matches(s)) return el;
|
||||||
|
el = el.parentElement || el.parentNode;
|
||||||
|
} while (el !== null && el.nodeType === 1);
|
||||||
|
return null;
|
||||||
|
};
|
||||||
|
}
|
|
@ -2524,3 +2524,11 @@ td.blob-excerpt {
|
||||||
.title_wip_desc {
|
.title_wip_desc {
|
||||||
margin-top: 1em;
|
margin-top: 1em;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.diff-file-box[data-folded="true"] .diff-file-body {
|
||||||
|
visibility: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
.diff-file-box[data-folded="true"] .diff-file-header {
|
||||||
|
border-radius: 0.28571429rem !important;
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue