mirror of
https://github.com/PR0M3TH3AN/bitvid.git
synced 2026-11-05 04:12:25 +00:00
Improve zap popover responsiveness
This commit is contained in:
1 parent
4aab79f485
commit
a0cc19c16f
2 files changed
+50
-1
No files matched your search
+45
-1
@@ -936,7 +936,26 @@ function isZapControlsOpen() {
|
||||
|
||||
function openZapControls({ focus = false } = {}) {
|
||||
const zapButton = getChannelZapButton();
|
||||
if (!zapButton || !zapPopover) {
|
||||
if (!zapButton) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!zapPopover || zapPopoverTrigger !== zapButton) {
|
||||
const initialized = setupZapButton({ force: true });
|
||||
if (!initialized || !zapPopover || zapPopoverTrigger !== zapButton) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof zapPopover?.preload === "function") {
|
||||
try {
|
||||
zapPopover.preload();
|
||||
} catch (error) {
|
||||
devLogger.warn("[zap] Failed to preload zap popover before opening", error);
|
||||
}
|
||||
}
|
||||
|
||||
if (!zapPopover) {
|
||||
return false;
|
||||
}
|
||||
zapShouldFocusOnOpen = focus;
|
||||
@@ -2473,6 +2492,31 @@ function setupZapButton({ force = false } = {}) {
|
||||
zapPopover = popover;
|
||||
zapPopoverTrigger = zapButton;
|
||||
|
||||
const warmZapPopover = () => {
|
||||
if (!zapPopover || zapPopoverTrigger !== zapButton) {
|
||||
return;
|
||||
}
|
||||
if (typeof zapPopover.preload === "function") {
|
||||
try {
|
||||
zapPopover.preload();
|
||||
} catch (error) {
|
||||
devLogger.warn("[zap] Failed to preload zap popover", error);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
warmZapPopover();
|
||||
|
||||
if (zapButton.dataset.zapPopoverWarmBound !== "true") {
|
||||
const handleWarm = () => {
|
||||
warmZapPopover();
|
||||
};
|
||||
zapButton.addEventListener("pointerenter", handleWarm, { once: true });
|
||||
zapButton.addEventListener("pointerdown", handleWarm, { once: true });
|
||||
zapButton.addEventListener("focus", handleWarm, { once: true });
|
||||
zapButton.dataset.zapPopoverWarmBound = "true";
|
||||
}
|
||||
|
||||
if (zapButton.dataset.initialized !== "true") {
|
||||
zapButton.addEventListener("click", handleZapButtonClick);
|
||||
zapButton.dataset.initialized = "true";
|
||||
|
||||
@@ -671,6 +671,10 @@ export function createPopover(trigger, render, options = {}) {
|
||||
return panel;
|
||||
}
|
||||
|
||||
function preload() {
|
||||
return Boolean(ensurePanel());
|
||||
}
|
||||
|
||||
async function updatePosition() {
|
||||
if (!anchor || !panel) {
|
||||
return;
|
||||
@@ -918,6 +922,7 @@ export function createPopover(trigger, render, options = {}) {
|
||||
update: updatePosition,
|
||||
isOpen: () => isOpen,
|
||||
getPanel: () => panel,
|
||||
preload,
|
||||
};
|
||||
|
||||
return api;
|
||||
|
||||
Reference in new issue
Block a user