(function() { $(function() { function createScript(url) { var head = document.getElementsByTagName("head")[0], script = document.createElement("script"); script.src = url; script.charset = "utf-8"; head.appendChild(script) } function voteInit() { if (typeof __pkeys != "undefined" && typeof __pValue != "undefined") { var sUrl1 = "http://data.3g.sina.com.cn/api/count/count.php?act=show&type=1&pkey=" + __pkeys + "&p=" + __pValue + "&channel=" + __domain + "&jsonpcallback=showSup", sUrl3 = "http://data.3g.sina.com.cn/api/count/count.php?act=add&type=1&pkey=" + __pkeys + "&p=" + __pValue + "&channel=" + __domain + "&jsonpcallback=actSup", sUrl5 = "http://data.3g.sina.com.cn/api/count/count.php?act=add&type=1&pkey=" + __pkeys + "&p=" + __pValue + "&channel=" + __domain + "&jsonpcallback=actSup_f", timer; if ($(".art_op_sup").length > 0) { createScript(sUrl1) } $(".j_vote_btn").on("click", function() { var clickObj = $(this); if (clickObj.hasClass("on") || clickObj.data("loading") == "yes") { return } else { clickObj.data("loading", "yes"); if (clickObj.hasClass("art_op_sup")) { createScript(sUrl3) } else { createScript(sUrl5) } } }) } } window.showSup = function(data) { $(".j_vote_btn").each(function() { if (data.status == 0) { if ($(this).hasClass("art_op_sup")) { if (data.count == 0) { $(this).html("赞") } else { $(this).html(""+data.count) } } } else { if ($(this).hasClass("art_op_sup")) { $(this).html("赞") } } }) }; window.actSup = function(data) { if (data.status == 0) { $(".j_vote_btn").each(function() { if ($(this).hasClass("art_op_sup")) { clickObj = $(this); clickObj.addClass("on"); var currentNum = clickObj.text() == "赞" ? 0 : parseInt(clickObj.text()); var countval = currentNum + 1; clickObj.html(""+countval); clickObj.next().css("opacity", 1); clickObj.data("loading", "no"); clickObj_f = $("#j_float_btns").find(".j_vote_btn").eq(0); clickObj_f.addClass("on"); clickObj_f.data("loading", "no"); var timer = setTimeout(function() { clickObj.next().css("opacity", 0) }, 1000) } }) } else { alert("点赞失败!") } }; window.actSup_f = function(data) { if (data.status == 0) { $(".j_vote_btn").each(function() { if (!$(this).hasClass("art_op_sup")) { $(this).addClass("on"); $(this).data("loading", "no"); if ($(".art_op_sup").length > 0) { clickObj = $(".art_op_sup").eq(0); clickObj.addClass("on"); var currentNum = clickObj.text() == "赞" ? 0 : parseInt(clickObj.text()); clickObj.text(currentNum + 1); clickObj.data("loading", "no") } } }) } else { alert("点赞失败!") } }; var scrolltop = document.body.scrollTop || document.documentElement.scrollTop; if (navigator.userAgent.indexOf("Android 2.2") == -1) { window.onscroll = function() { var st = document.body.scrollTop || document.documentElement.scrollTop; if (st < scrolltop && st != 0) { $("#j_float_btns").removeClass("hide") } else { $("#j_float_btns").addClass("hide") } scrolltop = st } } setTimeout(function() { voteInit() }, 300) }) })();