Small Snippet for Pinterest

notarypublic

New Member
This only works in Firefox so far, but I've written a small JS snippet to make navigating between pins easier (using left and right arrow keys, when one pin is opened inside of a lightbox)

Code:
 $(document).on('keypress', function(e) {
if ($('#zoomScroll').length){
//get the appropriate pins
var currentPin = $('#zoom').attr('pin-id');
var currentPinElement = $('#ColumnContainer').find('[data-id="'+currentPin+'"]').first();
var newPin = false;

if(e.keyCode==37){
//left
var previousPin = $(currentPinElement).prev();
console.log('previousPin', previousPin);
if ($(previousPin).attr('data-id')){
$('#zoomScroll').trigger('click');
$(currentPinElement).prev().find('.PinImage').trigger('click');
console.log('left.');
newPin = true;
}
}
else if (e.keyCode==39){
//right
var nextPin = $(currentPinElement).next();
if (nextPin.attr('data-id')){
$('#zoomScroll').trigger('click');
$(currentPinElement).next().find('.PinImage').trigger('click');
newPin = true;
}
}

if (newPin === true){
$('html, body').animate({
scrollTop: currentPinElement.offset().top
}, 0);
}

}
});
 
Top