gallery: add hotkey list button

This commit is contained in:
ed 2021-07-17 01:14:14 +02:00
parent 629f537d06
commit c7cb64bfef
2 changed files with 66 additions and 13 deletions

View file

@ -22,7 +22,7 @@ window.baguetteBox = (function () {
afterHide: null, afterHide: null,
onChange: null, onChange: null,
}, },
overlay, slider, btnPrev, btnNext, btnVmode, btnClose, overlay, slider, btnPrev, btnNext, btnHelp, btnVmode, btnClose,
currentGallery = [], currentGallery = [],
currentIndex = 0, currentIndex = 0,
isOverlayVisible = false, isOverlayVisible = false,
@ -174,8 +174,9 @@ window.baguetteBox = (function () {
'<button id="bbox-prev" class="bbox-btn" type="button" aria-label="Previous">&lt;</button>' + '<button id="bbox-prev" class="bbox-btn" type="button" aria-label="Previous">&lt;</button>' +
'<button id="bbox-next" class="bbox-btn" type="button" aria-label="Next">&gt;</button>' + '<button id="bbox-next" class="bbox-btn" type="button" aria-label="Next">&gt;</button>' +
'<div id="bbox-btns">' + '<div id="bbox-btns">' +
'<button id="bbox-help" type="button">?</button>' +
'<button id="bbox-vmode" type="button" tt="a"></button>' + '<button id="bbox-vmode" type="button" tt="a"></button>' +
'<button id="bbox-close" type="button" aria-label="Close">&times;</button>' + '<button id="bbox-close" type="button" aria-label="Close">X</button>' +
'</div></div>' '</div></div>'
); );
overlay = ctr.firstChild; overlay = ctr.firstChild;
@ -185,11 +186,45 @@ window.baguetteBox = (function () {
slider = ebi('bbox-slider'); slider = ebi('bbox-slider');
btnPrev = ebi('bbox-prev'); btnPrev = ebi('bbox-prev');
btnNext = ebi('bbox-next'); btnNext = ebi('bbox-next');
btnHelp = ebi('bbox-help');
btnVmode = ebi('bbox-vmode'); btnVmode = ebi('bbox-vmode');
btnClose = ebi('bbox-close'); btnClose = ebi('bbox-close');
bindEvents(); bindEvents();
} }
function halp() {
if (ebi('bbox-halp'))
return;
var list = [
['<b># hotkey</b>', '<b># operation</b>'],
['escape', 'close'],
['left, J', 'previous file'],
['right, L', 'next file'],
['home', 'first file'],
['end', 'last file'],
['space, P, K', 'video: play / pause'],
['U', 'video: seek 10sec back'],
['P', 'video: seek 10sec ahead'],
['M', 'video: toggle mute'],
['R', 'video: toggle loop'],
['C', 'video: toggle auto-next'],
['F', 'video: toggle fullscreen'],
],
d = mknod('table'),
html = ['<tbody>'];
for (var a = 0; a < list.length; a++)
html.push('<tr><td>' + list[a][0] + '</td><td>' + list[a][1] + '</td></tr>');
d.innerHTML = html.join('\n') + '</tbody>';
d.setAttribute('id', 'bbox-halp');
d.onclick = function () {
overlay.removeChild(d);
};
overlay.appendChild(d);
}
function keyDownHandler(e) { function keyDownHandler(e) {
if (e.ctrlKey || e.altKey || e.metaKey || e.isComposing) if (e.ctrlKey || e.altKey || e.metaKey || e.isComposing)
return; return;
@ -310,6 +345,7 @@ window.baguetteBox = (function () {
bind(btnNext, 'click', showNextImage); bind(btnNext, 'click', showNextImage);
bind(btnClose, 'click', hideOverlay); bind(btnClose, 'click', hideOverlay);
bind(btnVmode, 'click', tglVmode); bind(btnVmode, 'click', tglVmode);
bind(btnHelp, 'click', halp);
bind(slider, 'contextmenu', contextmenuHandler); bind(slider, 'contextmenu', contextmenuHandler);
bind(overlay, 'touchstart', touchstartHandler, nonPassiveEvent); bind(overlay, 'touchstart', touchstartHandler, nonPassiveEvent);
bind(overlay, 'touchmove', touchmoveHandler, passiveEvent); bind(overlay, 'touchmove', touchmoveHandler, passiveEvent);
@ -323,6 +359,7 @@ window.baguetteBox = (function () {
unbind(btnNext, 'click', showNextImage); unbind(btnNext, 'click', showNextImage);
unbind(btnClose, 'click', hideOverlay); unbind(btnClose, 'click', hideOverlay);
unbind(btnVmode, 'click', tglVmode); unbind(btnVmode, 'click', tglVmode);
unbind(btnHelp, 'click', halp);
unbind(slider, 'contextmenu', contextmenuHandler); unbind(slider, 'contextmenu', contextmenuHandler);
unbind(overlay, 'touchstart', touchstartHandler, nonPassiveEvent); unbind(overlay, 'touchstart', touchstartHandler, nonPassiveEvent);
unbind(overlay, 'touchmove', touchmoveHandler, passiveEvent); unbind(overlay, 'touchmove', touchmoveHandler, passiveEvent);
@ -435,6 +472,10 @@ window.baguetteBox = (function () {
if (options.bodyClass && document.body.classList) if (options.bodyClass && document.body.classList)
document.body.classList.remove(options.bodyClass); document.body.classList.remove(options.bodyClass);
var h = ebi('bbox-halp');
if (h)
h.parentNode.removeChild(h);
if (options.afterHide) if (options.afterHide)
options.afterHide(); options.afterHide();

View file

@ -1249,8 +1249,7 @@ html.light #bbox-overlay figcaption a {
.bbox-btn { .bbox-btn {
position: fixed; position: fixed;
} }
.bbox-btn, #bbox-overlay button {
#bbox-btns>button {
cursor: pointer; cursor: pointer;
outline: none; outline: none;
padding: 0 .3em; padding: 0 .3em;
@ -1258,20 +1257,18 @@ html.light #bbox-overlay figcaption a {
border: 0; border: 0;
border-radius: 15%; border-radius: 15%;
background: rgba(50, 50, 50, 0.5); background: rgba(50, 50, 50, 0.5);
color: #ddd; color: rgba(255,255,255,0.7);
font: 1.6em sans-serif;
transition: background-color .3s ease; transition: background-color .3s ease;
line-height: 1em; transition: color .3s ease;
font-size: 1.4em;
line-height: 1.4em;
vertical-align: top; vertical-align: top;
} }
.bbox-btn:focus, #bbox-overlay button:focus,
.bbox-btn:hover { #bbox-overlay button:hover {
color: rgba(255,255,255,0.9);
background: rgba(50, 50, 50, 0.9); background: rgba(50, 50, 50, 0.9);
} }
button#bbox-vmode {
font-size: 1em;
line-height: 1.6em;
}
#bbox-next { #bbox-next {
right: 1%; right: 1%;
} }
@ -1283,6 +1280,21 @@ button#bbox-vmode {
right: 2%; right: 2%;
position: fixed; position: fixed;
} }
#bbox-halp {
color: #fff;
background: #333;
position: absolute;
top: 0;
left: 0;
z-index: 20;
padding: .4em;
}
#bbox-halp td {
padding: .2em .5em;
}
#bbox-halp td:first-child {
text-align: right;
}
.bbox-spinner { .bbox-spinner {
width: 40px; width: 40px;
height: 40px; height: 40px;