dimsemenov / PhotoSwipe

JavaScript image gallery for mobile and desktop, modular, framework independent
http://photoswipe.com
MIT License
24.28k stars 3.31k forks source link

Adding open image/gallery on spacebar key press #966

Open meredevelopment opened 9 years ago

meredevelopment commented 9 years ago

Hi, I've been checking the a11y of a site that I've used PhotoSwipe on, and I notice that whilst keyboard input is available within a set of images, the initial pop-up state can't be activated with a press of the spacebar. I would love to see this added.

laurosollero commented 9 years ago

It's kinda easy to implement, I wouldn't expect it to be inside the plugin, though. In Vanilla JS:

window.addEventListener("keydown", checkKeyPressed, false);
function checkKeyPressed(e) {
  if (e.keyCode == "0" || e.keyCode == "32") {
    var gallery = new PhotoSwipe( pswpElement, PhotoSwipeUI_Default, items, options);
    gallery.init();
  }
}