Last active
March 12, 2020 07:55
-
-
Save mebusw/d7fbbf8600fc66dbe7f9970595fc5b23 to your computer and use it in GitHub Desktop.
Liking componet for Tencent coding on UPerform website https://www.uperform.cn/tencent-coding-agile-devops-tools/
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> | |
console.log("like") | |
function refresh_like() { | |
$.get("https://operation.coding.net/api/v1/cooperation/like", function(res){ | |
if (res.code === 0) { | |
$("#liking-1").html(res.data.list[2].like) | |
$("#liking-2").html(res.data.list[3].like) | |
$("#liking-3").html(res.data.list[0].like) | |
} | |
}) | |
} | |
$(document).ready(function(){ | |
refresh_like() | |
var curr_cookie = $.cookie("coding-liking") || "000" | |
if (('001' & curr_cookie) !== 0) { | |
$("#liking-icon-3").removeClass("icon-heart-empty-fa").addClass("icon-heart-fa").data("liked", "yes") | |
} | |
if (('010' & curr_cookie) !== 0) { | |
$("#liking-icon-2").removeClass("icon-heart-empty-fa").addClass("icon-heart-fa").data("liked", "yes") | |
} | |
if (('100' & curr_cookie) !== 0) { | |
$("#liking-icon-1").removeClass("icon-heart-empty-fa").addClass("icon-heart-fa").data("liked", "yes") | |
} | |
$(".trigger-scan-to-group-chat").hover(function(){ | |
$(".scan-to-group-chat > div").animate({right:"50px"}); | |
},function(){ | |
$(".scan-to-group-chat > div").animate({right:"-180px"}); | |
}) | |
}) | |
$(".liking-icon").click(function(e){ | |
console.log(e) | |
if ($("#liking-icon-"+e.target.dataset.id).data("liked") == "yes") return; | |
$.post("https://operation.coding.net/api/v1/cooperation/like", {"id": e.target.dataset.id}, function(res) { | |
refresh_like() | |
var id_bit = [8,4,2,1][e.target.dataset.id] | |
var cookie_bit = parseInt($.cookie("coding-liking") || "000", 2) | |
var or_binary = (id_bit | cookie_bit).toString(2) | |
console.log(or_binary) | |
$.cookie("coding-liking", or_binary) | |
$("#liking-icon-"+e.target.dataset.id).removeClass("icon-heart-empty-fa").addClass("icon-heart-fa").data("liked", "yes") | |
}) | |
}) | |
//{"code":0,"data":{"list":[{"name":"敏捷管理最佳实践","like":3},{"name":"敏捷咨询与培训服务","like":2},{"name":"敏捷管理工具共创","like":1},{"name":"敏捷及 DevOps 成熟度评估","like":3}]},"msg":"请求成功"} | |
//参数:id(按设计图上从左到右依次为 1、2、3) | |
$(".the_content").css('display','none') // hide some empty bar | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment