Skip to content

Commit fd094ee

Browse files
silverwindlunny
authored andcommitted
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 <[email protected]>
1 parent 8d51f28 commit fd094ee

File tree

5 files changed

+36
-13
lines changed

5 files changed

+36
-13
lines changed

routers/repo/commit.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,8 @@ func FileHistory(ctx *context.Context) {
206206
func Diff(ctx *context.Context) {
207207
ctx.Data["PageIsDiff"] = true
208208
ctx.Data["RequireHighlightJS"] = true
209+
ctx.Data["RequireSimpleMDE"] = true
210+
ctx.Data["RequireTribute"] = true
209211

210212
userName := ctx.Repo.Owner.Name
211213
repoName := ctx.Repo.Repository.Name

templates/repo/diff/box.tmpl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@
8080
</div>
8181
{{else}}
8282
<div class="diff-file-box diff-box file-content {{TabSizeClass $.Editorconfig $file.Name}}" id="diff-{{.Index}}">
83-
<h4 class="ui top attached normal header">
83+
<h4 class="diff-file-header ui top attached normal header">
8484
{{$isImage := false}}
8585
{{if $file.IsDeleted}}
8686
{{$isImage = (call $.IsImageFileInBase $file.Name)}}
@@ -111,7 +111,7 @@
111111
{{end}}
112112
{{end}}
113113
</h4>
114-
<div class="ui attached unstackable table segment">
114+
<div class="diff-file-body ui attached unstackable table segment">
115115
{{if ne $file.Type 4}}
116116
<div class="file-body file-code code-view has-context-menu code-diff {{if $.IsSplitStyle}}code-diff-split{{else}}code-diff-unified{{end}}">
117117
<table>

web_src/js/index.js

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
/* exported toggleDeadlineForm, setDeadline, updateDeadline, deleteDependencyModal, cancelCodeComment, onOAuthLoginClick */
44

55
import './publicPath.js';
6+
import './polyfills.js';
67
import './gitGraphLoader.js';
78
import './semanticDropdown.js';
89
import initContextPopups from './features/contextPopup';
@@ -2109,17 +2110,12 @@ function initCodeView() {
21092110
}
21102111
}).trigger('hashchange');
21112112
}
2112-
$('.ui.fold-code').on('click', (e) => {
2113-
const $foldButton = $(e.target);
2114-
if ($foldButton.hasClass('fa-chevron-down')) {
2115-
$(e.target).parent().next().slideUp('fast', () => {
2116-
$foldButton.removeClass('fa-chevron-down').addClass('fa-chevron-right');
2117-
});
2118-
} else {
2119-
$(e.target).parent().next().slideDown('fast', () => {
2120-
$foldButton.removeClass('fa-chevron-right').addClass('fa-chevron-down');
2121-
});
2122-
}
2113+
$('.fold-code').on('click', ({ target }) => {
2114+
const box = target.closest('.file-content');
2115+
const folded = box.dataset.folded !== 'true';
2116+
target.classList.add(`fa-chevron-${folded ? 'right' : 'down'}`);
2117+
target.classList.remove(`fa-chevron-${folded ? 'down' : 'right'}`);
2118+
box.dataset.folded = String(folded);
21232119
});
21242120
function insertBlobExcerpt(e) {
21252121
const $blob = $(e.target);

web_src/js/polyfills.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// compat: IE11
2+
if (!Element.prototype.matches) {
3+
Element.prototype.matches = Element.prototype.msMatchesSelector || Element.prototype.webkitMatchesSelector;
4+
}
5+
6+
// compat: IE11
7+
if (!Element.prototype.closest) {
8+
Element.prototype.closest = function (s) {
9+
let el = this;
10+
11+
do {
12+
if (el.matches(s)) return el;
13+
el = el.parentElement || el.parentNode;
14+
} while (el !== null && el.nodeType === 1);
15+
return null;
16+
};
17+
}

web_src/less/_repository.less

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2524,3 +2524,11 @@ td.blob-excerpt {
25242524
.title_wip_desc {
25252525
margin-top: 1em;
25262526
}
2527+
2528+
.diff-file-box[data-folded="true"] .diff-file-body {
2529+
visibility: hidden;
2530+
}
2531+
2532+
.diff-file-box[data-folded="true"] .diff-file-header {
2533+
border-radius: 0.28571429rem !important;
2534+
}

0 commit comments

Comments
 (0)