|
|
|
@ -139,6 +139,71 @@ var Gogs = {}; |
|
|
|
|
|
|
|
|
|
// Render code view.
|
|
|
|
|
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) { |
|
|
|
|
$list.removeClass('active'); |
|
|
|
|
$list.parents('tr').find('td').removeClass('selected-line'); |
|
|
|
@ -167,7 +232,7 @@ var Gogs = {}; |
|
|
|
|
$.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 $list = $select.parent().siblings('.lines-code').parents().find('td.lines-num > span'); |
|
|
|
|
selectRange( |
|
|
|
@ -178,7 +243,7 @@ var Gogs = {}; |
|
|
|
|
$.deSelect(); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
$('.code-view .lines-code > pre').each(function () { |
|
|
|
|
$('.code-diff .lines-code > pre').each(function () { |
|
|
|
|
var $pre = $(this); |
|
|
|
|
var $lineCode = $pre.parent(); |
|
|
|
|
var $lineNums = $lineCode.siblings('.lines-num'); |
|
|
|
@ -192,7 +257,7 @@ var Gogs = {}; |
|
|
|
|
|
|
|
|
|
$(window).on('hashchange', function (e) { |
|
|
|
|
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; |
|
|
|
|
if (m) { |
|
|
|
|
$first = $list.filter('[rel=' + m[1] + ']'); |
|
|
|
@ -294,7 +359,12 @@ var Gogs = {}; |
|
|
|
|
|
|
|
|
|
function initCore() { |
|
|
|
|
Gogs.renderMarkdown(); |
|
|
|
|
Gogs.renderCodeView(); |
|
|
|
|
|
|
|
|
|
if ($('.code-diff').length == 0) { |
|
|
|
|
Gogs.renderCodeView(); |
|
|
|
|
} else { |
|
|
|
|
Gogs.renderDiffView(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Switch list.
|
|
|
|
|
$('.js-tab-nav').click(function (e) { |
|
|
|
@ -515,7 +585,7 @@ function initRepoSetting() { |
|
|
|
|
$ul.toggleShow(); |
|
|
|
|
} |
|
|
|
|
}).next().next().find('ul').on("click", 'li', function () { |
|
|
|
|
$('#repo-collaborator').val($(this).text()); |
|
|
|
|
$('#repo-collaborator').val($(this).find('.username').text()); |
|
|
|
|
$ul.toggleHide(); |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|