Created
September 14, 2017 16:28
-
-
Save jeremiahlangner/440ddef22553018bab5b109033d222fc to your computer and use it in GitHub Desktop.
client-bs-ss-plugin-2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script> | |
/* Allow keyboard arrow-key based page-turns while lightboxed. | |
* Code: Jeremiah Langner; http://jeremiahlangner.me */ | |
var images = document.getElementsByClassName("thumb-image"); | |
window.onkeyup = function(e) { | |
var key = e.keyCode ? e.keyCode : e.which; | |
// User presses up key on keyboard. | |
if (key == 38 || key == 37) { | |
pageUp(); | |
// User presses down key on keyboard. | |
} else if (key == 40 || key == 39) { | |
pageDown(); | |
} | |
}; | |
function pageUp() { | |
var lightBox = document.querySelector('.sqs-lightbox-padder'); | |
if (lightBox) { | |
var currentPageSource = lightBox.getElementsByTagName('img')[0].getAttribute('data-src'); | |
for(i=0; i<images.length; i++) { | |
console.log(i); | |
if (images[i].getAttribute('data-src') == currentPageSource) { | |
console.log('found an image'); | |
console.log(i); | |
if(i !== 0) { | |
var nextPageSource = images[i-1].getAttribute('data-src'); | |
lightBox.getElementsByTagName('img')[0].setAttribute('src', nextPageSource); | |
lightBox.getElementsByTagName('img')[0].setAttribute('data-src', nextPageSource); | |
} | |
} | |
} | |
} | |
} | |
function pageDown() { | |
var lightBox = document.querySelector('.sqs-lightbox-padder'); | |
if (lightBox) { | |
var currentPageSource = lightBox.getElementsByTagName('img')[0].getAttribute('data-src'); | |
for(i=0; i<images.length; i++) { | |
console.log(i); | |
if (images[i].getAttribute('data-src') == currentPageSource) { | |
console.log('found an image'); | |
console.log(i); | |
if(i !== images.length-1) { | |
var nextPageSource = images[i+1].getAttribute('data-src'); | |
lightBox.getElementsByTagName('img')[0].setAttribute('src', nextPageSource); | |
lightBox.getElementsByTagName('img')[0].setAttribute('data-src', nextPageSource); | |
} | |
} | |
} | |
} | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment