查看此处和Google主题小组关于此主题的各种帖子,我正在尝试使用ciceron theme中的脚本重现心脏(如)按钮,但到目前为止我还没有成功。
以下是我的代码。我错过了什么?有人设法解决了吗?
在<head>
:
<script type="text/javascript" src="http://static.tumblr.com/53unaru/y8wlgzkbt/jquery.ui.totop.js"></script>
<script type="text/javascript">
$('a.like-link').click(function() {
var post = $(this).closest('.post');
var id = post.attr('id');
var oauth = post.attr('rel').slice(-8);
var like = 'http://www.tumblr.com/like/'+oauth+'?id='+id;
$('#likeit').attr('src', like);
$(this).addClass('liked'); return
false;})
</script>
在<head>
的CSS部分:
#likeit {height: 0; width: 0; visibility: hidden;}
在<body>
:
<iframe id="likeit"></iframe>
in {Block:post}:
<a href="#" class="like-link">Like</a>
答案 0 :(得分:5)
我已经更新了我的Tumblr教程,使其剪切和粘贴:http://like-button.tumblr.com
你错过了oAuth密钥。每个帖子都有一个唯一的ID,必须发送给喜欢。您可以在{ReblogURL}
变量(未记录的)变量的末尾找到它。这是最后八个字符。在您的示例中,它从帖子的rel
属性中抓取它:
var oauth = post.attr('rel').slice(-8);
在</head>
之前,将以下代码块剪切并粘贴到您的主题中。这将在每个帖子上给你一个类似按钮,看起来像默认的Tumblr灰色心脏。当您将鼠标悬停在它上面并单击它时,它将变为红色。如果再次单击它,它将再次变为灰色并删除Like。
<style>
.my-like {
background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABMAAAARCAYAAAA/mJfHAAABH0lEQVQ4y62T30vCUBiGv/9YuhBLkCA08FdogRFFYFEUhhZNCCQoSESiIOii68pl5qV6s8Eb7+SMHXNs6S7ejZ3zvA+ccT4BICofvS88dJ7w8vqG8WQC754K17lPjrx3z3l8D4YoVaqIrWbcJNbzaHefNZjfXPdy5b0jsO/IRqMxUpmSBnhz2bx1QL79GPbpEePmzhdSyW8fBDL0SK68HwiGCT2S3NiKREaPzP7QRRNPZSHpwm4kMnqkYbQikdEjZv8HK2ubS4nY75mD6WU8qzeXkrHvToBlWSjuHC4kYo99V8bwBnM0/iMiz542myq2bSPskcmR/zPos7lvP8Lv/nGd+/N6c2Xq2KcXhiY6qV1rxwotU3n/NHF8fgW+g9hfsHJlJUYljcgAAAAASUVORK5CYII=) !important;
height:17px;
width:19px;
cursor:pointer;
display:inline-block;
vertical-align:top;
}
.my-liked, .my-like:hover {
background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABMAAAARCAYAAAA/mJfHAAABSklEQVQ4y2P4//8/Awy/O3fu/905c/4/2779/69Pn/4jy8Hwz/fv/z/buvX/vfnz/7+/eBFFDZj4cOXK/8O+Pv+36+rA8W4zs/8Ply1DUXx/4cL/u0yMUdQdCQ76/+nWLbA6hq+PH//fbW6OogAZ3+zvByu81t6OU80ea6v/P16//s9wqboKpyIYPhYeTlDN1abG/wz7HR0JKiQGH3Bz+8+ww0CfKobtMjb6z0ANg+CGgQKPKt50dfnPcL6wkCqGXaoo/8/w5tgxyg3T0wUnYHBiPJuZSZFhF8pK/8NzACjrgKKWHINAOef3168Iw0D429OnGFmKEAZlJVDKR8mbMAyy4XRqClEGnc3J+f/nxw/MjI6OQflxh6EBzvR0Z9o0rCUKVsNA+MuD+/9PJiSgGHQmPf0/KDhw6cFpGAy/OnAAbOibEyf+E1ILAFBjDrchm7KrAAAAAElFTkSuQmCC) !important;
height:17px;
width:19px;
cursor:pointer;
display:inline-block;
vertical-align:top;
}
</style>
<script>
window.onload = function () {
document.body.insertAdjacentHTML( 'beforeEnd', '<iframe id="my-like-frame" style="display:none;"></iframe>' );
document.addEventListener( 'click', function ( event ) {
var myLikeLink = event.target;
if( myLikeLink.className.indexOf( 'my-like' ) > -1 ) {
var myLikeFrame = document.getElementById( 'my-like-frame' ),
liked = ( myLikeLink.className == 'my-liked' ),
command = liked ? 'unlike' : 'like',
reblog = myLikeLink.getAttribute( 'data-reblog' ),
postId = myLikeLink.getAttribute( 'data-id' ),
oauth = reblog.slice( -8 ),
likeUrl = 'http://www.tumblr.com/' + command + '/' + oauth + '?id=' + postId;
myLikeFrame.src = likeUrl;
liked ? myLikeLink.className = 'my-like'
: myLikeLink.className = 'my-liked';
};
}, false );
};
</script>
然后将以下按钮代码剪切并粘贴到主题中您希望类似按钮的位置(这必须位于{block:Posts}
区域内)。
<div class="my-like" data-reblog="{ReblogURL}" data-id="{PostID}"></div>