Skip to content

Commit

Permalink
patch
Browse files Browse the repository at this point in the history
  • Loading branch information
lbr38 committed Jan 5, 2025
1 parent d893530 commit 913869b
Showing 1 changed file with 21 additions and 12 deletions.
33 changes: 21 additions & 12 deletions www/public/resources/js/functions/task.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ function autorefresh()

// Autorefresh with new steps and content every 2sec
setInterval(function () {
console.log('Start setinterval');
// Retrieve task Id
var taskId = $('#log-refresh-container').attr('task-id');

Expand Down Expand Up @@ -96,16 +95,19 @@ function enableAutoScroll()
*/
function disableAutoScroll()
{
// Set autoscroll cookie to false to disable autoscroll
setCookie('autoscroll', 'false');
// Get current autoscroll status
if (getCookie('autoscroll') == '' || getCookie('autoscroll') == 'true') {
// Set autoscroll cookie to false to disable autoscroll
setCookie('autoscroll', 'false');

$('#autoscroll-btn').find('img').attr('src', '/assets/icons/play.svg');
$('#autoscroll-btn').attr('title', 'Enable auto refresh and scroll');
$('#autoscroll-btn').find('img').attr('src', '/assets/icons/play.svg');
$('#autoscroll-btn').attr('title', 'Enable auto refresh and scroll');

// Restart scroll event listener
scrollEventListener();
// Restart scroll event listener
scrollEventListener();

console.log('Autoscroll disabled');
console.log('Autoscroll disabled');
}
}

/**
Expand Down Expand Up @@ -219,8 +221,10 @@ function scrollEventListener()

/**
* Get latest scroll position from local storage
* Get latest scroll direction from local storage
*/
var lastScrollPosition = localStorage.getItem('lastScrollPosition');
var lastScrollDirection = localStorage.getItem('lastScrollDirection');

/**
* Get current scroll position
Expand All @@ -230,7 +234,7 @@ function scrollEventListener()
/**
* If latest scroll position is null (meaning the page has been refreshed), set it to 0
*/
if (lastScrollPosition == null) {
if (lastScrollPosition == "" || lastScrollPosition == "undefined") {
lastScrollPosition = 0;
}

Expand All @@ -246,11 +250,16 @@ function scrollEventListener()

/**
* Save current scroll position in local storage
* Save current scroll direction in local storage
*/
localStorage.setItem('lastScrollPosition', currentScrollPosition);

if (scroll == 'up') {
console.log('scroll up detected, disabling autoscroll');
localStorage.setItem('lastScrollDirection', scroll);

/**
* If the user is scrolling up and the last scroll was also up, disable autoscroll
* Because it means that the user is really trying to scroll up
*/
if (scroll == 'up' && lastScrollDirection == 'up') {
disableAutoScroll();
}

Expand Down

0 comments on commit 913869b

Please sign in to comment.