fix chrome reverting video pause toggles

pausing a video with spacebar while video is focused would first
get handled by the js hotkey, and then chrome would ignore our
hint that bubbling should cease and undo it anyways
This commit is contained in:
ed 2025-09-03 19:37:24 +00:00
parent e798a9a53a
commit bfcb6eac41

View file

@ -44,6 +44,7 @@ window.baguetteBox = (function () {
loopA = null, loopA = null,
loopB = null, loopB = null,
url_ts = null, url_ts = null,
un_pp = 0,
resume_mp = false; resume_mp = false;
var onFSC = function (e) { var onFSC = function (e) {
@ -337,6 +338,9 @@ window.baguetteBox = (function () {
rotn(e.shiftKey ? -1 : 1); rotn(e.shiftKey ? -1 : 1);
else if (kl == "y") else if (kl == "y")
dlpic(); dlpic();
else
return;
return ev(e);
} }
function anim() { function anim() {
@ -460,6 +464,7 @@ window.baguetteBox = (function () {
var k = (e.key || e.code) + ''; var k = (e.key || e.code) + '';
if (k == "Space" || k == "Spacebar" || k == " ") { if (k == "Space" || k == "Spacebar" || k == " ") {
un_pp = Date.now();
return ev(e); return ev(e);
} }
} }
@ -786,8 +791,7 @@ window.baguetteBox = (function () {
image.setAttribute('playsinline', '1'); image.setAttribute('playsinline', '1');
// ios ignores poster // ios ignores poster
image.onended = vidEnd; image.onended = vidEnd;
image.onplay = function () { show_buttons(1); }; image.onplay = image.onpause = ppHandler;
image.onpause = function () { show_buttons(); };
} }
image.alt = thumbnailElement ? thumbnailElement.alt || '' : ''; image.alt = thumbnailElement ? thumbnailElement.alt || '' : '';
if (options.titleTag && imageCaption) if (options.titleTag && imageCaption)
@ -802,6 +806,15 @@ window.baguetteBox = (function () {
callback(); callback();
} }
function ppHandler() {
var now = Date.now();
if (now - un_pp < 50) {
un_pp = 0;
return playpause(); // browser undid space hotkey
}
show_buttons(this.paused ? 1 : 0);
}
function showNextImage(e) { function showNextImage(e) {
ev(e); ev(e);
return show(currentIndex + 1); return show(currentIndex + 1);