mirror of
https://github.com/gitbucket/gitbucket.git
synced 2025-11-13 08:55:50 +01:00
implove source-line-num performance.
and Stop scroll when click line number.
This commit is contained in:
@@ -104,35 +104,41 @@ $(window).load(function(){
|
|||||||
updateHighlighting();
|
updateHighlighting();
|
||||||
}).hashchange();
|
}).hashchange();
|
||||||
|
|
||||||
|
var pre = $('pre.prettyprint');
|
||||||
function updateSourceLineNum(){
|
function updateSourceLineNum(){
|
||||||
$('.source-line-num').remove();
|
$('.source-line-num').remove();
|
||||||
var pre = $('pre.prettyprint');
|
var pos = pre.find('ol.linenums').position();
|
||||||
$('pre.prettyprint ol.linenums li').each(function(i, e){
|
$('<div class="source-line-num">').css({
|
||||||
var p = $(e).position();
|
height:pre.height(),
|
||||||
var left = pre.position().left
|
width:'48px',
|
||||||
pre.append($('<div class="source-line-num">')
|
|
||||||
.data('line', (i + 1))
|
|
||||||
.css({
|
|
||||||
cursor:'pointer',
|
cursor:'pointer',
|
||||||
position: 'absolute',
|
position: 'absolute',
|
||||||
top : p.top + 'px',
|
top : pos.top + 'px',
|
||||||
width : (p.left - left) + 'px',
|
left : pos.left + 'px'
|
||||||
left : left,
|
}).click(function(e){
|
||||||
height : '16px'
|
$(window).hashchange(function(){})
|
||||||
}));
|
var pos = $(this).data("pos");
|
||||||
});
|
if(!pos){
|
||||||
$('div.source-line-num').click(function(e){
|
pos = $('ol.linenums li').map(function(){ return {id:$(this).attr("id"),top:$(this).position().top} }).toArray();
|
||||||
var line = $(e.target).data('line');
|
$(this).data("pos",pos);
|
||||||
|
}
|
||||||
|
for(var i=0;i<pos.length-1;i++){
|
||||||
|
if(pos[i+1].top>e.pageY){
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var line = pos[i].id.replace(/^L/,'');
|
||||||
var hash = location.hash;
|
var hash = location.hash;
|
||||||
if(e.shiftKey == true && hash.match(/#L\d+(-L\d+)?/)){
|
if(e.shiftKey == true && hash.match(/#L\d+(-L\d+)?/)){
|
||||||
var lines = hash.split('-');
|
var lines = hash.split('-');
|
||||||
location.hash = lines[0] + '-L' + line;
|
location.hash = lines[0] + '-L' + line;
|
||||||
} else {
|
} else {
|
||||||
|
var p = $("#L"+line).attr('id',"");
|
||||||
location.hash = '#L' + line;
|
location.hash = '#L' + line;
|
||||||
|
p.attr('id','L'+line);
|
||||||
}
|
}
|
||||||
});
|
}).appendTo(pre);
|
||||||
}
|
}
|
||||||
updateSourceLineNum();
|
|
||||||
var repository = $('.blame-action').data('repository');
|
var repository = $('.blame-action').data('repository');
|
||||||
$('.blame-action').click(function(e){
|
$('.blame-action').click(function(e){
|
||||||
if(history.pushState && $('pre.prettyprint.no-renderable').length){
|
if(history.pushState && $('pre.prettyprint.no-renderable').length){
|
||||||
@@ -146,13 +152,13 @@ $(window).load(function(){
|
|||||||
var m = /^\/(blame|blob)(\/.*)$/.exec(location.pathname.substring(repository.length));
|
var m = /^\/(blame|blob)(\/.*)$/.exec(location.pathname.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]);
|
||||||
var pre = $('pre.prettyprint');
|
|
||||||
if(pre.parents("td").find(".blame").length){
|
if(pre.parents("td").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;
|
||||||
}
|
}
|
||||||
if(mode=='blob'){
|
if(mode=='blob'){
|
||||||
|
updateSourceLineNum();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$('.blame-action').addClass("active");
|
$('.blame-action').addClass("active");
|
||||||
@@ -214,15 +220,20 @@ 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){
|
||||||
$(window).scrollTop($('#' + lines[0]).offset().top - 40);
|
$(window).scrollTop($('#' + lines[0]).offset().top - 40);
|
||||||
|
}
|
||||||
} else if(lines.length > 1){
|
} else if(lines.length > 1){
|
||||||
var start = parseInt(lines[0].substr(1));
|
var start = parseInt(lines[0].substr(1));
|
||||||
var end = parseInt(lines[1].substr(1));
|
var end = parseInt(lines[1].substr(1));
|
||||||
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){
|
||||||
$(window).scrollTop($('#L' + start).offset().top - 40);
|
$(window).scrollTop($('#L' + start).offset().top - 40);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
updateHighlighting.scrolling = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
@@ -1332,6 +1332,14 @@ h6 a.markdown-anchor-link {
|
|||||||
/****************************************************************************/
|
/****************************************************************************/
|
||||||
/* blame */
|
/* blame */
|
||||||
/****************************************************************************/
|
/****************************************************************************/
|
||||||
|
.blobview pre.blob{
|
||||||
|
padding-left: 0;
|
||||||
|
}
|
||||||
|
.blobview ol.linenums{
|
||||||
|
margin-left: 0;
|
||||||
|
padding-left: 50px;
|
||||||
|
}
|
||||||
|
|
||||||
div.container.blame-container{
|
div.container.blame-container{
|
||||||
width:1270px;
|
width:1270px;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user