Last active
June 12, 2023 15:37
-
-
Save philippbosch/5018940 to your computer and use it in GitHub Desktop.
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
<h2>Installation</h2> | |
<p> | |
Drag and drop the following link to your bookmarks bar:<br> | |
<a href="javascript:(function() { var elem=document.createElement('script'); elem.setAttribute('src', 'https://gist.github.com/philippbosch/5018940/raw/pinterest-slideshow.js?t='+(new Date().getTime())); document.body.appendChild(elem); }())">Slideshow</a> | |
</p> |
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
(function() { | |
if (location.host != 'pinterest.com' || location.pathname.split('/').length != 4) { | |
alert('Please use this bookmarklet on a Pinterest user\'s board page.'); | |
return; | |
} | |
if (!jQuery || !$) { | |
// No jQuery! | |
return; | |
} | |
var $style = $('<style/>'); | |
var css = '#the-pinterest-slideshow-overlay { position: fixed; top: 0; left: 0; right: 0; bottom: 0; z-index: 99999999; background: #000; }'; | |
css += '#the-pinterest-slideshow-overlay img { position: absolute; top: 50%; left: 50%; }'; | |
$style.text(css); | |
$style.appendTo('body'); | |
var $pins = $('.pin[data-closeup-url]'); | |
var urls = $pins.map(function(i, p) { return $(p).data('closeup-url'); }); | |
var $overlay = $('<div id="the-pinterest-slideshow-overlay"/>'); | |
var $img = $('<img>'); | |
$img.appendTo($overlay); | |
$overlay.hide().appendTo('body'); | |
var currentPinNum = -1; | |
function previousPin() { | |
if (currentPinNum == 0) return; | |
currentPinNum--; | |
displayPin($pins.eq(currentPinNum)); | |
} | |
function nextPin() { | |
if (currentPinNum == $pins.length-1) return; | |
currentPinNum++; | |
displayPin($pins.eq(currentPinNum)); | |
} | |
function displayPin($pin) { | |
$img.fadeOut($img.attr('src') == '' ? 0 : 250, function() { | |
$img.one('load', function() { | |
$img.css('margin-left', '-' + ($pin.data('width')/2) + 'px'); | |
$img.css('margin-top', '-' + ($pin.data('height')/2) + 'px'); | |
$img.fadeIn(250); | |
}); | |
$img.attr('src', $pin.data('closeup-url')); | |
$img.data('$pin', $pin); | |
}); | |
} | |
function showSlideshow(callback) { | |
$overlay.css('opacity',0).show().animate({'opacity': 1}, 500, callback); | |
} | |
function hideSlideshow(callback) { | |
$overlay.animate({'opacity': 0}, 500, function() { | |
$overlay.hide(); | |
if (callback) callback(); | |
}); | |
} | |
$img.on('click', function(e) { | |
var $pin = $pins.eq(currentPinNum); | |
console.log($pin, $pin.data(), currentPinNum); | |
hideSlideshow(function() { | |
// location.href = '/pin/' + $pin.data('id') + '/'; | |
}); | |
}); | |
$(document).on('keydown', function(e) { | |
switch(e.keyCode) { | |
case 37: // previous | |
previousPin(); | |
break; | |
case 39: // next | |
nextPin(); | |
break; | |
case 27: // exit | |
hideSlideshow(); | |
break; | |
} | |
}); | |
showSlideshow(nextPin); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment