Commit c06f487e authored by Leo Iannacone's avatar Leo Iannacone

defined page object to scroll up/down window - do not scroll if file is in preview

parent a506e2a6
...@@ -86,6 +86,25 @@ function Page_Distrubion(socket) { ...@@ -86,6 +86,25 @@ function Page_Distrubion(socket) {
return true; return true;
} }
var page = {
go: {
down: function (height) {
if (height === undefined)
height = $('body').offset().top;
debug(2, 'scrolling page down - height', height);
$('html,body').animate({
scrollTop: height
}, 0);
},
up: function () {
debug(2, 'scrolling page up');
$('html,body').animate({
scrollTop: 0
}, 0);
}
}
};
var title = { var title = {
set: function (label) { set: function (label) {
if (label) { if (label) {
...@@ -339,6 +358,13 @@ function Page_Distrubion(socket) { ...@@ -339,6 +358,13 @@ function Page_Distrubion(socket) {
var file_content = $('#file pre'); var file_content = $('#file pre');
if (!current_file_in_preview) { if (!current_file_in_preview) {
file_content.append(new_content); file_content.append(new_content);
if (config.preferences.autoscroll) {
// scroll down if file is covering footer
var file_height = $('#fileOffset').offset().top;
var footerOffset = $('footer').offset().top;
if (file_height > footerOffset)
page.go.down(file_height);
}
} else { } else {
// always show only config.file.num_lines lines in preview // always show only config.file.num_lines lines in preview
var content = file_content.html().replace(/\n$/, '').split('\n'); var content = file_content.html().replace(/\n$/, '').split('\n');
...@@ -347,18 +373,6 @@ function Page_Distrubion(socket) { ...@@ -347,18 +373,6 @@ function Page_Distrubion(socket) {
file_content.html(content); file_content.html(content);
file_content.scrollTop(file_content[0].scrollHeight); file_content.scrollTop(file_content[0].scrollHeight);
} }
if (config.preferences.autoscroll) {
// scroll down if file is covering footer
var file_height = $('#fileOffset').offset().top;
var footerOffset = $('footer').offset().top;
if (file_height > footerOffset) {
debug(2, 'scoll down on new content');
$('html,body').animate({
scrollTop: file_height
}, 0);
}
}
}, },
get: function (force) { get: function (force) {
if (Utils.check_view_file(view)) { if (Utils.check_view_file(view)) {
...@@ -678,9 +692,7 @@ function Page_Distrubion(socket) { ...@@ -678,9 +692,7 @@ function Page_Distrubion(socket) {
view.package = Utils.clone(view.packages[new_view.package.orig_name]); view.package = Utils.clone(view.packages[new_view.package.orig_name]);
view.file = Utils.clone(new_view.file); view.file = Utils.clone(new_view.file);
update.page(old_view); update.page(old_view);
$('html,body').animate({ page.go.up();
scrollTop: 0
}, 0);
debug(1, 'changing view', 'old:', old_view, 'new:', view); debug(1, 'changing view', 'old:', old_view, 'new:', view);
}); });
...@@ -689,11 +701,7 @@ function Page_Distrubion(socket) { ...@@ -689,11 +701,7 @@ function Page_Distrubion(socket) {
populate(); populate();
// Init sticky-package back_on_top on click // Init sticky-package back_on_top on click
$('#sticky-package').on('click', function () { $('#sticky-package').on('click', page.go.up);
$('html,body').animate({
scrollTop: 0
}, 100);
});
// WORKAROUND: // WORKAROUND:
// when page is loaded sidebar has offset().top // when page is loaded sidebar has offset().top
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment