Skip to content

Commit 9ae1c4a

Browse files
committed
propagate mime down to javascript
1 parent 8039365 commit 9ae1c4a

File tree

3 files changed

+13
-8
lines changed

3 files changed

+13
-8
lines changed

templates/repo/diff/box.tmpl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,9 +200,9 @@
200200
<div id="diff-rendered-{{$file.NameHash}}" class="file-body file-code {{if $.IsSplitStyle}}code-diff-split{{else}}code-diff-unified{{end}} gt-overflow-x-scroll">
201201
<table class="chroma gt-w-100">
202202
{{if $isImage}}
203-
{{template "repo/diff/image_diff" dict "file" . "root" $ "blobBase" $blobBase "blobHead" $blobHead}}
203+
{{template "repo/diff/image_diff" dict "file" . "root" $ "blobBase" $blobBase "blobHead" $blobHead "stBase" $stBase "stHead" $stHead}}
204204
{{else}}
205-
{{template "repo/diff/csv_diff" dict "file" . "root" $ "blobBase" $blobBase "blobHead" $blobHead}}
205+
{{template "repo/diff/csv_diff" dict "file" . "root" $ "blobBase" $blobBase "blobHead" $blobHead "stBase" $stBase "stHead" $stHead}}
206206
{{end}}
207207
</table>
208208
</div>

templates/repo/diff/image_diff.tmpl

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
{{if or .blobBase .blobHead}}
22
<tr>
33
<td colspan="2">
4-
<div class="image-diff" data-path-before="{{.root.BeforeRawPath}}/{{PathEscapeSegments .file.OldName}}" data-path-after="{{.root.RawPath}}/{{PathEscapeSegments .file.Name}}">
4+
<div class="image-diff"
5+
data-path-before="{{.root.BeforeRawPath}}/{{PathEscapeSegments .file.OldName}}"
6+
data-path-after="{{.root.RawPath}}/{{PathEscapeSegments .file.Name}}"
7+
data-mime-before="{{.stBase.GetMimeType}}"
8+
data-mime-after="{{.stHead.GetMimeType}}"
9+
>
510
<div class="ui secondary pointing tabular top attached borderless menu new-menu">
611
<div class="new-menu-inner">
712
<a class="item active" data-tab="diff-side-by-side-{{.file.Index}}">{{ctx.Locale.Tr "repo.diff.image.side_by_side"}}</a>

web_src/js/features/imagediff.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,17 +74,17 @@ export function initImageDiff() {
7474

7575
// the container may be hidden by "viewed" checkbox, so use the parent's width for reference
7676
const diffContainerWidth = Math.max($container.closest('.diff-file-box').width() - 300, 100);
77-
const pathAfter = $container.data('path-after');
78-
const pathBefore = $container.data('path-before');
7977

8078
const imageInfos = [{
8179
loaded: false,
82-
path: pathAfter,
80+
path: this.getAttribute('data-path-after'),
81+
mime: this.getAttribute('data-mime-after'),
8382
$image: $container.find('img.image-after'),
8483
$boundsInfo: $container.find('.bounds-info-after')
8584
}, {
8685
loaded: false,
87-
path: pathBefore,
86+
path: this.getAttribute('data-path-before'),
87+
mime: this.getAttribute('data-mime-before'),
8888
$image: $container.find('img.image-before'),
8989
$boundsInfo: $container.find('.bounds-info-before')
9090
}];
@@ -101,7 +101,7 @@ export function initImageDiff() {
101101
});
102102
info.$image.attr('src', info.path);
103103

104-
if (parseUrl(info.path).pathname.toLowerCase().endsWith('.svg')) {
104+
if (info.mime === 'image/svg+xml') {
105105
const resp = await GET(info.path);
106106
const text = await resp.text();
107107
const bounds = getDefaultSvgBoundsIfUndefined(text, info.path);

0 commit comments

Comments
 (0)