Skip to content

Commit

Permalink
Added a hover-pause to the waterfall and moderation UI (#249)
Browse files Browse the repository at this point in the history
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
csharpfritz and github-actions[bot] authored Oct 19, 2023
1 parent 14203cb commit 2624f4e
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 4 deletions.
3 changes: 2 additions & 1 deletion src/TagzApp.Web/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
"Description": "YouTube is a free video sharing website that makes it easy to watch online videos. You can even create and upload your own videos to share with others."
},
"twitchchat": {
"ChannelName": "csharpfritz"
"ChannelName": "csharpfritz",
"Activated": true
},
"twitter": {
"Activated": false,
Expand Down
49 changes: 46 additions & 3 deletions src/TagzApp.Web/wwwroot/js/site.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
};

var paused = false;
var rolloverPause = false;
var pauseQueue = [];
var pauseTimeout;
const waterfallMaxEntries = 100;
const moderationMaxEntries = 500;

Expand Down Expand Up @@ -351,10 +353,40 @@
}
}

function PauseOnRollover(ev) {
// pause updates
window.clearTimeout(pauseTimeout);
if (!paused) {
paused = true;
rolloverPause = true;
FormatPauseButton();
}

ev.srcElement.addEventListener('mouseleave', function (ev) {
// resume updates if we mouse out
if (rolloverPause) {
pauseTimeout = window.setTimeout(() => {
paused = false;
rolloverPause = false;
FormatPauseButton();
ResumeFromPause();
}, 1500);
}
});
}

function showModerationPanel(ev) {
var hovered = ev.target.closest('article');
if (hovered.querySelector('#moderationAction')) return;

// pause updates
window.clearTimeout(pauseTimeout);
if (!paused) {
paused = true;
rolloverPause = true;
FormatPauseButton();
}

var hoverPanel = document
.getElementById('moderationAction')
.cloneNode(true);
Expand Down Expand Up @@ -392,6 +424,17 @@
hovered.insertBefore(hoverPanel, hovered.firstElementChild);

hoverPanel.addEventListener('mouseleave', function (ev) {
// resume updates if we mouse out
if (rolloverPause) {
pauseTimeout = window.setTimeout(() => {
paused = false;
rolloverPause = false;
FormatPauseButton();
ResumeFromPause();
}, 1500);
}

// cleanup the moderation overlay
ev.target.closest('#moderationAction').remove();
var panels = document.querySelectorAll('.active_panel');
panels.forEach(function (panel) {
Expand Down Expand Up @@ -470,7 +513,7 @@
if (document.querySelector('.currentModerators')) {
FormatMessageForModeration(content);
} else {
FormatMessage(content);
FormatMessage(content, null, null, PauseOnRollover);
}
});

Expand Down Expand Up @@ -499,7 +542,7 @@
AddMessageToPauseQueue(content);
return;
}
FormatMessage(content);
FormatMessage(content, null, null, PauseOnRollover);
});

connection.on('RemoveMessage', (provider, providerId) => {
Expand All @@ -521,7 +564,7 @@
.invoke('GetExistingContentForTag', tags)
.then(function (result) {
result.forEach(function (content) {
FormatMessage(content);
FormatMessage(content, null, null, PauseOnRollover);
});
window.Masonry.resizeAllGridItems();
});
Expand Down

0 comments on commit 2624f4e

Please sign in to comment.