public/ng/js: script fix on #901
This commit is contained in:
parent
e0329c0eb5
commit
7140f50637
|
@ -1630,6 +1630,10 @@ The register and sign-in page style
|
||||||
background-color: #d1ffd6 !important;
|
background-color: #d1ffd6 !important;
|
||||||
border-color: #b4e2b4 !important;
|
border-color: #b4e2b4 !important;
|
||||||
}
|
}
|
||||||
|
.diff-file-box .code-diff tbody tr.add-code td.selected-line,
|
||||||
|
.diff-file-box .code-diff tbody tr.add-code td.selected-line pre {
|
||||||
|
background-color: #ffffdd !important;
|
||||||
|
}
|
||||||
.diff-file-box .code-diff tbody tr:hover td,
|
.diff-file-box .code-diff tbody tr:hover td,
|
||||||
.diff-file-box .code-diff tbody tr:hover pre {
|
.diff-file-box .code-diff tbody tr:hover pre {
|
||||||
background-color: #FFF8D2 !important;
|
background-color: #FFF8D2 !important;
|
||||||
|
|
|
@ -139,6 +139,71 @@ var Gogs = {};
|
||||||
|
|
||||||
// Render code view.
|
// Render code view.
|
||||||
Gogs.renderCodeView = function () {
|
Gogs.renderCodeView = function () {
|
||||||
|
function selectRange($list, $select, $from) {
|
||||||
|
$list.removeClass('active');
|
||||||
|
if ($from) {
|
||||||
|
var a = parseInt($select.attr('rel').substr(1));
|
||||||
|
var b = parseInt($from.attr('rel').substr(1));
|
||||||
|
var c;
|
||||||
|
if (a != b) {
|
||||||
|
if (a > b) {
|
||||||
|
c = a;
|
||||||
|
a = b;
|
||||||
|
b = c;
|
||||||
|
}
|
||||||
|
var classes = [];
|
||||||
|
for (i = a; i <= b; i++) {
|
||||||
|
classes.push('.L' + i);
|
||||||
|
}
|
||||||
|
$list.filter(classes.join(',')).addClass('active');
|
||||||
|
$.changeHash('#L' + a + '-' + 'L' + b);
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$select.addClass('active');
|
||||||
|
$.changeHash('#' + $select.attr('rel'));
|
||||||
|
}
|
||||||
|
|
||||||
|
$(document).on('click', '.lines-num span', function (e) {
|
||||||
|
var $select = $(this);
|
||||||
|
var $list = $select.parent().siblings('.lines-code').find('ol.linenums > li');
|
||||||
|
selectRange($list, $list.filter('[rel=' + $select.attr('rel') + ']'), (e.shiftKey ? $list.filter('.active').eq(0) : null));
|
||||||
|
$.deSelect();
|
||||||
|
});
|
||||||
|
|
||||||
|
$('.code-view .lines-code > pre').each(function () {
|
||||||
|
var $pre = $(this);
|
||||||
|
var $lineCode = $pre.parent();
|
||||||
|
var $lineNums = $lineCode.siblings('.lines-num');
|
||||||
|
if ($lineNums.length > 0) {
|
||||||
|
var nums = $pre.find('ol.linenums > li').length;
|
||||||
|
for (var i = 1; i <= nums; i++) {
|
||||||
|
$lineNums.append('<span id="L' + i + '" rel="L' + i + '">' + i + '</span>');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
$(window).on('hashchange', function (e) {
|
||||||
|
var m = window.location.hash.match(/^#(L\d+)\-(L\d+)$/);
|
||||||
|
var $list = $('.code-view ol.linenums > li');
|
||||||
|
var $first;
|
||||||
|
if (m) {
|
||||||
|
$first = $list.filter('.' + m[1]);
|
||||||
|
selectRange($list, $first, $list.filter('.' + m[2]));
|
||||||
|
$("html, body").scrollTop($first.offset().top - 200);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
m = window.location.hash.match(/^#(L\d+)$/);
|
||||||
|
if (m) {
|
||||||
|
$first = $list.filter('.' + m[1]);
|
||||||
|
selectRange($list, $first);
|
||||||
|
$("html, body").scrollTop($first.offset().top - 200);
|
||||||
|
}
|
||||||
|
}).trigger('hashchange');
|
||||||
|
};
|
||||||
|
|
||||||
|
// Render diff view.
|
||||||
|
Gogs.renderDiffView = function () {
|
||||||
function selectRange($list, $select, $from) {
|
function selectRange($list, $select, $from) {
|
||||||
$list.removeClass('active');
|
$list.removeClass('active');
|
||||||
$list.parents('tr').find('td').removeClass('selected-line');
|
$list.parents('tr').find('td').removeClass('selected-line');
|
||||||
|
@ -167,7 +232,7 @@ var Gogs = {};
|
||||||
$.changeHash('#' + $select.attr('rel'));
|
$.changeHash('#' + $select.attr('rel'));
|
||||||
}
|
}
|
||||||
|
|
||||||
$(document).on('click', '.lines-num span', function (e) {
|
$(document).on('click', '.code-diff .lines-num span', function (e) {
|
||||||
var $select = $(this);
|
var $select = $(this);
|
||||||
var $list = $select.parent().siblings('.lines-code').parents().find('td.lines-num > span');
|
var $list = $select.parent().siblings('.lines-code').parents().find('td.lines-num > span');
|
||||||
selectRange(
|
selectRange(
|
||||||
|
@ -178,7 +243,7 @@ var Gogs = {};
|
||||||
$.deSelect();
|
$.deSelect();
|
||||||
});
|
});
|
||||||
|
|
||||||
$('.code-view .lines-code > pre').each(function () {
|
$('.code-diff .lines-code > pre').each(function () {
|
||||||
var $pre = $(this);
|
var $pre = $(this);
|
||||||
var $lineCode = $pre.parent();
|
var $lineCode = $pre.parent();
|
||||||
var $lineNums = $lineCode.siblings('.lines-num');
|
var $lineNums = $lineCode.siblings('.lines-num');
|
||||||
|
@ -192,7 +257,7 @@ var Gogs = {};
|
||||||
|
|
||||||
$(window).on('hashchange', function (e) {
|
$(window).on('hashchange', function (e) {
|
||||||
var m = window.location.hash.match(/^#(L\d+)\-(L\d+)$/);
|
var m = window.location.hash.match(/^#(L\d+)\-(L\d+)$/);
|
||||||
var $list = $('.code-view td.lines-num > span');
|
var $list = $('.code-diff td.lines-num > span');
|
||||||
var $first;
|
var $first;
|
||||||
if (m) {
|
if (m) {
|
||||||
$first = $list.filter('[rel=' + m[1] + ']');
|
$first = $list.filter('[rel=' + m[1] + ']');
|
||||||
|
@ -294,7 +359,12 @@ var Gogs = {};
|
||||||
|
|
||||||
function initCore() {
|
function initCore() {
|
||||||
Gogs.renderMarkdown();
|
Gogs.renderMarkdown();
|
||||||
Gogs.renderCodeView();
|
|
||||||
|
if ($('.code-diff').length == 0) {
|
||||||
|
Gogs.renderCodeView();
|
||||||
|
} else {
|
||||||
|
Gogs.renderDiffView();
|
||||||
|
}
|
||||||
|
|
||||||
// Switch list.
|
// Switch list.
|
||||||
$('.js-tab-nav').click(function (e) {
|
$('.js-tab-nav').click(function (e) {
|
||||||
|
@ -515,7 +585,7 @@ function initRepoSetting() {
|
||||||
$ul.toggleShow();
|
$ul.toggleShow();
|
||||||
}
|
}
|
||||||
}).next().next().find('ul').on("click", 'li', function () {
|
}).next().next().find('ul').on("click", 'li', function () {
|
||||||
$('#repo-collaborator').val($(this).text());
|
$('#repo-collaborator').val($(this).find('.username').text());
|
||||||
$ul.toggleHide();
|
$ul.toggleHide();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
File diff suppressed because one or more lines are too long
|
@ -105,10 +105,10 @@
|
||||||
{{range $k, $line := $section.Lines}}
|
{{range $k, $line := $section.Lines}}
|
||||||
<tr class="{{DiffLineTypeToStr .Type}}-code nl-{{$i}} ol-{{$i}}">
|
<tr class="{{DiffLineTypeToStr .Type}}-code nl-{{$i}} ol-{{$i}}">
|
||||||
<td class="lines-num lines-num-old">
|
<td class="lines-num lines-num-old">
|
||||||
<span rel="L{{Add $i 1}}{{$j}}{{$k}}">{{if $line.LeftIdx}}{{$line.LeftIdx}}{{end}}</span>
|
<span rel="diff-{{Add $i 1}}L{{$j}}{{$k}}">{{if $line.LeftIdx}}{{$line.LeftIdx}}{{end}}</span>
|
||||||
</td>
|
</td>
|
||||||
<td class="lines-num lines-num-new">
|
<td class="lines-num lines-num-new">
|
||||||
<span rel="L{{Add $i 1}}{{$j}}{{$k}}">{{if $line.RightIdx}}{{$line.RightIdx}}{{end}}</span>
|
<span rel="diff-{{Add $i 1}}L{{$j}}{{$k}}">{{if $line.RightIdx}}{{$line.RightIdx}}{{end}}</span>
|
||||||
</td>
|
</td>
|
||||||
|
|
||||||
<td class="lines-code">
|
<td class="lines-code">
|
||||||
|
|
Loading…
Reference in New Issue