mirror of
https://github.com/gitbucket/gitbucket.git
synced 2025-11-05 04:56:02 +01:00
Fix broken blame
This commit is contained in:
@@ -104,36 +104,38 @@ $(window).load(function(){
|
|||||||
function updateSourceLineNum(){
|
function updateSourceLineNum(){
|
||||||
$('.source-line-num').remove();
|
$('.source-line-num').remove();
|
||||||
var pos = pre.find('ol.linenums').position();
|
var pos = pre.find('ol.linenums').position();
|
||||||
$('<div class="source-line-num">').css({
|
if(pos){
|
||||||
height:pre.height(),
|
$('<div class="source-line-num">').css({
|
||||||
width:'48px',
|
height : pre.height(),
|
||||||
cursor:'pointer',
|
width : '48px',
|
||||||
position: 'absolute',
|
cursor : 'pointer',
|
||||||
top : pos.top + 'px',
|
position: 'absolute',
|
||||||
left : pos.left + 'px'
|
top : pos.top + 'px',
|
||||||
}).click(function(e){
|
left : pos.left + 'px'
|
||||||
$(window).hashchange(function(){})
|
}).click(function(e){
|
||||||
var pos = $(this).data("pos");
|
$(window).hashchange(function(){})
|
||||||
if(!pos){
|
var pos = $(this).data("pos");
|
||||||
pos = $('ol.linenums li').map(function(){ return {id:$(this).attr("id"),top:$(this).position().top} }).toArray();
|
if(!pos){
|
||||||
$(this).data("pos",pos);
|
pos = $('ol.linenums li').map(function(){ return { id: $(this).attr("id"), top: $(this).position().top} }).toArray();
|
||||||
}
|
$(this).data("pos",pos);
|
||||||
for(var i=0;i<pos.length-1;i++){
|
|
||||||
if(pos[i+1].top>e.pageY){
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
for(var i = 0; i < pos.length-1; i++){
|
||||||
var line = pos[i].id.replace(/^L/,'');
|
if(pos[i + 1].top > e.pageY){
|
||||||
var hash = location.hash;
|
break;
|
||||||
if(e.shiftKey == true && hash.match(/#L\d+(-L\d+)?/)){
|
}
|
||||||
var lines = hash.split('-');
|
}
|
||||||
location.hash = lines[0] + '-L' + line;
|
var line = pos[i].id.replace(/^L/,'');
|
||||||
} else {
|
var hash = location.hash;
|
||||||
var p = $("#L"+line).attr('id',"");
|
if(e.shiftKey == true && hash.match(/#L\d+(-L\d+)?/)){
|
||||||
location.hash = '#L' + line;
|
var lines = hash.split('-');
|
||||||
p.attr('id','L'+line);
|
location.hash = lines[0] + '-L' + line;
|
||||||
}
|
} else {
|
||||||
}).appendTo(pre);
|
var p = $("#L"+line).attr('id',"");
|
||||||
|
location.hash = '#L' + line;
|
||||||
|
p.attr('id','L'+line);
|
||||||
|
}
|
||||||
|
}).appendTo(pre);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
var repository = $('.blame-action').data('repository');
|
var repository = $('.blame-action').data('repository');
|
||||||
$('.blame-action').click(function(e){
|
$('.blame-action').click(function(e){
|
||||||
@@ -147,9 +149,9 @@ $(window).load(function(){
|
|||||||
function updateBlame(){
|
function updateBlame(){
|
||||||
var m = /^\/(blame|blob)(\/.*)$/.exec(location.href.substring(repository.length));
|
var m = /^\/(blame|blob)(\/.*)$/.exec(location.href.substring(repository.length));
|
||||||
var mode = m[1];
|
var mode = m[1];
|
||||||
$('.blame-action').toggleClass("active", mode=='blame').attr('href', repository + (m[1]=='blame'?'/blob':'/blame')+m[2]);
|
$('.blame-action').toggleClass("active", mode=='blame').attr('href', repository + (m[1] == 'blame' ? '/blob' : '/blame') + m[2]);
|
||||||
if(pre.parents("td").find(".blame").length){
|
if(pre.parents("div.box-content-bottom").find(".blame").length){
|
||||||
pre.parents("div.container").toggleClass("blame-container", mode=='blame');
|
pre.parents("div.container").toggleClass("blame-container", mode == 'blame');
|
||||||
updateSourceLineNum();
|
updateSourceLineNum();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -159,45 +161,45 @@ $(window).load(function(){
|
|||||||
}
|
}
|
||||||
$(document.body).toggleClass('no-box-shadow',document.body.style.boxShadow===undefined);
|
$(document.body).toggleClass('no-box-shadow',document.body.style.boxShadow===undefined);
|
||||||
$('.blame-action').addClass("active");
|
$('.blame-action').addClass("active");
|
||||||
var base = $('<div class="blame">').css({height:pre.height()}).prependTo(pre.parents("td")[0]);
|
var base = $('<div class="blame">').css({height: pre.height()}).prependTo(pre.parents("div.box-content-bottom"));
|
||||||
base.parents("div.container").addClass("blame-container");
|
base.parents("div.container").addClass("blame-container");
|
||||||
updateSourceLineNum();
|
updateSourceLineNum();
|
||||||
$.get($('.blame-action').data('url')).done(function(data){
|
$.get($('.blame-action').data('url')).done(function(data){
|
||||||
var blame = data.blame;
|
var blame = data.blame;
|
||||||
var index = [];
|
var index = [];
|
||||||
for(var i=0;i<blame.length;i++){
|
for(var i = 0; i < blame.length; i++){
|
||||||
for(var j=0;j<blame[i].lines.length;j++){
|
for(var j = 0; j < blame[i].lines.length; j++){
|
||||||
index[blame[i].lines[j]]=blame[i];
|
index[blame[i].lines[j]] = blame[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var blame, lastDiv, now=new Date().getTime();
|
var blame, lastDiv, now = new Date().getTime();
|
||||||
|
|
||||||
$('pre.prettyprint ol.linenums li').each(function(i, e){
|
$('pre.prettyprint ol.linenums li').each(function(i, e){
|
||||||
var p=$(e).position();
|
var p = $(e).position();
|
||||||
var h=$(e).height();
|
var h = $(e).height();
|
||||||
if(blame == index[i]){
|
if(blame == index[i]){
|
||||||
lastDiv.css("min-height",(p.top+h+1) - lastDiv.position().top);
|
lastDiv.css("min-height",(p.top + h + 1) - lastDiv.position().top);
|
||||||
}else{
|
}else{
|
||||||
$(e).addClass('blame-sep')
|
$(e).addClass('blame-sep')
|
||||||
blame = index[i];
|
blame = index[i];
|
||||||
var sha = $('<div class="blame-sha">')
|
var sha = $('<div class="blame-sha">')
|
||||||
.append($('<a>').attr("href",data.root+'/commit/'+blame.id).text(blame.id.substr(0,7)));
|
.append($('<a>').attr("href", data.root + '/commit/' + blame.id).text(blame.id.substr(0,7)));
|
||||||
if(blame.prev){
|
if(blame.prev){
|
||||||
sha.append($('<br />'))
|
sha.append($('<br />'))
|
||||||
.append($('<a class="muted-link">').text('prev').attr("href",data.root+'/blame/'+blame.prev+'/'+(blame.prevPath||data.path)));
|
.append($('<a class="muted-link">').text('prev').attr("href", data.root + '/blame/' + blame.prev + '/' + (blame.prevPath || data.path)));
|
||||||
}
|
}
|
||||||
lastDiv = $('<div class="blame-info">')
|
lastDiv = $('<div class="blame-info">')
|
||||||
.addClass('heat'+Math.min(10,Math.max(1,Math.ceil((now-blame.commited)/(24*3600*1000*70)))))
|
.addClass('heat' + Math.min(10, Math.max(1, Math.ceil((now - blame.commited) / (24 * 3600 * 1000 * 70)))))
|
||||||
.toggleClass('blame-last',blame.id==data.last)
|
.toggleClass('blame-last', blame.id == data.last)
|
||||||
.data('line', (i + 1))
|
.data('line', (i + 1))
|
||||||
.css({
|
.css({
|
||||||
"top" : p.top + 'px',
|
"top" : p.top + 'px',
|
||||||
"min-height" : h+'px'
|
"min-height" : h + 'px'
|
||||||
})
|
})
|
||||||
.append(sha)
|
.append(sha)
|
||||||
.append($(blame.avatar).addClass('avatar').css({"float":"left"}))
|
.append($(blame.avatar).addClass('avatar').css({"float": "left"}))
|
||||||
.append($('<div class="blame-commit-title">').text(blame.message))
|
.append($('<div class="blame-commit-title">').text(blame.message))
|
||||||
.append($('<div class="muted">').html(blame.author+ " authed "+blame.authed))
|
.append($('<div class="muted">').html(blame.author + " authed " + blame.authed))
|
||||||
.appendTo(base);
|
.appendTo(base);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -207,6 +209,8 @@ $(window).load(function(){
|
|||||||
updateBlame();
|
updateBlame();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
var scrolling = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Hightlight lines which are specified by URL hash.
|
* Hightlight lines which are specified by URL hash.
|
||||||
*/
|
*/
|
||||||
@@ -217,7 +221,7 @@ function updateHighlighting(){
|
|||||||
var lines = hash.substr(1).split('-');
|
var lines = hash.substr(1).split('-');
|
||||||
if(lines.length == 1){
|
if(lines.length == 1){
|
||||||
$('#' + lines[0]).addClass('highlight');
|
$('#' + lines[0]).addClass('highlight');
|
||||||
if(!updateHighlighting.scrolling){
|
if(!scrolling){
|
||||||
$(window).scrollTop($('#' + lines[0]).offset().top - 40);
|
$(window).scrollTop($('#' + lines[0]).offset().top - 40);
|
||||||
}
|
}
|
||||||
} else if(lines.length > 1){
|
} else if(lines.length > 1){
|
||||||
@@ -226,11 +230,11 @@ function updateHighlighting(){
|
|||||||
for(var i = start; i <= end; i++){
|
for(var i = start; i <= end; i++){
|
||||||
$('#L' + i).addClass('highlight');
|
$('#L' + i).addClass('highlight');
|
||||||
}
|
}
|
||||||
if(!updateHighlighting.scrolling){
|
if(!scrolling){
|
||||||
$(window).scrollTop($('#L' + start).offset().top - 40);
|
$(window).scrollTop($('#L' + start).offset().top - 40);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
updateHighlighting.scrolling = true;
|
scrolling = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
@@ -1755,9 +1755,12 @@ h6 a.markdown-anchor-link {
|
|||||||
padding-left: 50px;
|
padding-left: 50px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
div.container.blame-container{
|
div.container.blame-container{
|
||||||
width:1270px;
|
width:1270px;
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
.line-age-legend {
|
.line-age-legend {
|
||||||
display: none;
|
display: none;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user