Skip to content

Keyboard navigation not working properly #184

@randomd00d

Description

@randomd00d

Keyboard shortcuts are turned on (!0). When I try to go to the next image, prettyPhoto simply reloads the same image.

I've done a bit of digging around, and logging responses. It would seem that the array pp_images which should store links for img elements is not being filled beyond the first such element found - this can be seen by inspecting the document, and removing display:none from .pp_nav while the lightbox is open.

I've tried to override a part of what prettyphoto is doing in the background, by disabling keyboard shortcuts, and using this hacky solution:

	$(document).ready(function() {
		var gallery = 'nothing';
		var arrLinks = [];
		var imgLink = '';
		var elemIndex;
		var heading = 0;
		$('a[class="prettyphoto"]').each(function() {
			imgLink = $(this).attr('href');
			if(imgLink) {
				arrLinks.push(imgLink);
			}
		});
		var arrLen = arrLinks.length;

		$('body').keyup(function(e) {
			e.preventDefault();
			var keyCode = e.keyCode || e.which;
			if(keyCode===37) {
				heading = -1;
			} else if(keyCode===39) {
				heading = 1;
			} else if(keyCode===27) {
				$(document).find('.pp_pic_holder').remove()
			}

			var prettyOpen = $('.pp_pic_holder');
			if(prettyOpen[0]) {
				console.log(arrLen);
				console.log(prettyOpen[0]);
				imgLink = $('#fullResImage').attr('src');
				elemIndex = arrLinks.indexOf(imgLink);
				replacePhoto(elemIndex,heading,arrLinks,arrLen);
			}
		});

		function replacePhoto(elemIndex,heading,arrLinks,arrLen) {
			var newIndex = arrLinks[elemIndex+heading];
			if(newIndex===0 && heading==-1) {
				newIndex = arrLen - 1;
			} else if(newIndex==arrLen) {
				newIndex = 0;
			}
			$('#fullResImage').attr('src',newIndex);
			console.log($('#fullResImage').attr('src'));
		}
	});

Unfortunately, this doesn't work. The logging occurs, but nothing what I'd expect - prettyPhoto still reloads the same image, and never goes on to open the following or the previous one.

If the project is not dead, I'd appreciate any help on discovering (and solving) why the array isn't being filled with img links.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions