Last active
December 31, 2015 13:09
-
-
Save mariemosley/7991109 to your computer and use it in GitHub Desktop.
Pin it button centered below the first image of every post in Blogger. Requires jQuery (1.7.1 earliest version tested). Only recommended for blogs that center the first image. This code skips images under 300px wide. Change the 300 in line 9 to another number if you'd like to change that.
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> | |
$(document).ready(function() { | |
$('.entry-content').each(function() { | |
var image = $(this).find('img').first(); | |
var permalink = image.parents('.post-outer').find('.timestamp-link').attr('href') || $(location).attr('href'); | |
var title = image.parents('.post-outer').find('.entry-title').text(); | |
var width = image.width(); | |
if (width >= 300) { | |
$('.separator a').removeAttr('imageanchor style'); | |
$('<div class=\'pinit-button\'><a href="http://pinterest.com/pin/create/button/?url=' + permalink + '&media=' + image.attr('src') + '&description=' + title + '" class="pin-it-button" count-layout="none"></a></div>').insertAfter(image); | |
} | |
}); | |
}); | |
(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); | |
})(); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment