forked from typecho-fans/plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlike-js.php
38 lines (36 loc) · 1.7 KB
/
like-js.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
<?php if (!defined('__TYPECHO_ROOT_DIR__')) exit;
$jqueryScriptUrl = Helper::options()->pluginUrl . '/AnotherLike/js/jquery.js';
$macaroonScriptUrl = Helper::options()->pluginUrl . '/AnotherLike/js/jquery.fs.macaroon.js';
$settings = Helper::options()->plugin('AnotherLike');
if($settings->jquery){
echo '<script type="text/javascript" src="'.$jqueryScriptUrl.'"></script>';
}
?>
<script type="text/javascript" src="<?php echo $macaroonScriptUrl; ?>"></script>
<script>
$(function() {
var th = $(".<?php echo $settings->likeClass; ?>");
var id = th.attr('data-pid');
var cookies = $.macaroon('_syan_like') || "";
if (-1 !== cookies.indexOf("," + id + ",")) {
th.find('div.fave').toggleClass("done");
}});
$(".<?php echo $settings->likeClass; ?>").on("click", function(){
var th = $(this);
var id = th.attr('data-pid');
var cookies = $.macaroon('_syan_like') || "";
if (!id || !/^\d{1,10}$/.test(id)) return;
if (-1 !== cookies.indexOf("," + id + ",")) return alert("您已经赞过了!");
cookies ? cookies.length >= 160 ? (cookies = cookies.substring(0, cookies.length - 1), cookies = cookies.substr
(1).split(","), cookies.splice(0, 1), cookies.push(id), cookies = cookies.join(","), $.macaroon("_syan_like", "," + cookies +
",")) : $.macaroon("_syan_like", cookies + id + ",") : $.macaroon("_syan_like", "," + id + ",");
$.post('<?php Helper::options()->index('/action/like?up'); ?>',{
cid:id
},function(data){
// th.addClass('actived');
th.find('div.fave').toggleClass("active");
var zan = th.find('p.likeCount').text();
th.find('p.likeCount').text(parseInt(zan) + 1);
},'json');
});
</script>