Created
February 26, 2012 01:28
-
-
Save 65/1912065 to your computer and use it in GitHub Desktop.
pinterest buttons on every image in a blog post using jquery
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
$().ready(function() { | |
$('.entry-body img').each(function(){ | |
var $permalink = $(this).parents('.entry').find('.permalink').attr('href'); | |
$(this).wrap('<div class="pinme" style="' + $(this).attr('style') + '" />').after('<a href="http://pinterest.com/pin/create/button/?url=' + $permalink + '&media=' + $(this).attr('src') + '&description=' + $(this).attr('alt') + '" class="pin-it-button" count-layout="vertical">Pin It</a>'); | |
}); | |
$('.pinme').hover(function() { | |
$(this).children('iframe').css('display','block'); | |
}, function() { | |
$(this).children('iframe').css('display','none'); | |
}); | |
}); | |
(function() { | |
window.PinIt = window.PinIt || { loaded:false }; | |
if (window.PinIt.loaded) return; | |
window.PinIt.loaded = true; | |
function async_load(){ | |
var s = document.createElement("script"); | |
s.type = "text/javascript"; | |
s.async = true; | |
s.src = "http://assets.pinterest.com/js/pinit.js"; | |
var x = document.getElementsByTagName("script")[0]; | |
x.parentNode.insertBefore(s, x); | |
} | |
if (window.attachEvent) | |
window.attachEvent("onload", async_load); | |
else | |
window.addEventListener("load", async_load, false); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment