var up_session = "up"; var upArr = []; var isUp = false; $(function () { bindEvent(); $("#search").click(function () { var kwd = $("#keyword").val(); if (kwd.trim().length == 0) { return; } location.href = "/bookcircle/index.htm?kwd=" + kwd; }); $("#keyword").keypress(function (event) { var key = event.keyCode; if (key == 13) { $("#search").click(); } }); }) function bindEvent() { var apiurl = "/BookCircle/Handler/CommonHandler.ashx"; $("span[data-forward='true']").click(function () { var count = parseInt($(this).attr("data-forwardcount")); var id = $(this).attr("data-id"); var _this = this; $(this).addClass("xzl"); var host = window.location.protocol + "http://" + window.location.host; var url = $("#url2").val().replace("{topicid}", $(this).attr("data-id")); copyToClipboard(host + url); $.post(apiurl, { methodname: "Forward", operationid: id }, function (result) { if (result > 0) { count = count + 1; var html = '' + count; $(_this).html(html); $(_this).attr("data-forwardcount", count); $(_this).addClass("xzl"); } }); alert("已复制链接!"); }); $("span[data-reply='true']").click(function () { var count = parseInt($(this).attr("data-replycount")); var _thisp = this; $(this).addClass("xzl"); var id = $(this).attr("data-id"); if (getCookie("userName") == null) { $("div[data-login-modal='true']").show(); } else { if ($("div[data-reply-box='true'][data-id='" + id + "']").css("display") == "none") { $("div[data-reply-box='true'][data-id='" + id + "']").show(); $("input[data-reply-submit='true'][data-id='" + id + "']").click(function () { var _this = this; var content = $(this).prev().val(); if (content.trim().length == 0) { alert("请输入评论内容!"); return; } var json = {}; json.TopicId = id; json.ReplyContent = content; $.post(apiurl, { methodname: "SubmitReply", replyJson: JSON.stringify(json) }, function (result) { if (result > 0) { alert("回复成功!"); $(_this).prev().val(""); $(_this).parent().hide(); $(_this).unbind("click"); count = count + 1; var html = '' + count; $(_thisp).html(html); $(_thisp).attr("data-replycount", count); $(_thisp).addClass("xzl"); $.get(apiurl, { methodname: "GetReply", id: id }, function (result) { if (result!=null) { $("#allreply").html(""); var html = ""; for (var i = 0; i < result.length; i++) { var item = result[i]; html +=`
` } $("#allreply").html(html); } }); } }); }); } else { $("div[data-reply-box='true'][data-id='" + id + "']").hide(); } } }); $("span[data-support='true']").click(function () { if (isUp) { return; } isUp = true; var _this = $(this); var id = $(this).attr("data-id"); var count = parseInt($(this).attr("data-supportcount")); var _uuid = localStorage.getItem("_uuid"); if (_uuid == null) { _uuid = uuid(); localStorage.setItem("_uuid", _uuid); } $.post(apiurl, { methodname: "UpTopic", operationid: id, uuid: _uuid }, function (result) { if (result == 1) { count = count + 1; var html = '' + count; $(_this).html(html); $(_this).attr("data-supportcount", count); $(_this).addClass("xzl"); var up = {}; upArr = storageGet(up_session); if (upArr == null) { upArr = []; } up.key = id; upArr.push(up); storageSet(up_session, upArr); isUp = false; } else if (result == 2) { count = count - 1; $(_this).attr("data-supportcount", count); var html = '' + count; $(_this).html(html); $(_this).removeClass("xzl"); var up_data = storageGet(up_session); if (up_data) { var index = -1; for (var i = 0; i < up_data.length; i++) { if (up_data[i].key == id) { index = i; } } if (index > -1) { up_data.splice(index, 1); storageSet(up_session, up_data); } } isUp = false; } }); }); $("div[class='panelc'] img").click(function () { imgArr = []; $("#img_big").attr("src", $(this).attr("src")); var imgList = $(this).parent().parent().find("img"); if (imgList.length > 0) { for (var i = 0; i < imgList.length; i++) { imgArr.push($(imgList[i]).attr("src")); } } layer.open({ type: 1, title: false, closeBtn: 0, skin: 'layui-layer-nobg', shadeClose: true, content: $('#div_big_img'), success: function (layero, index) { $(".layui-layer-content").css("overflow", "visible"); $(".layui-layer-shade").css("opacity","0.6"); var left = $(window).width() / 2 - 400; $('#div_big_img').parent().parent().css("left", left + "px"); var openindex = imgArr.indexOf($("#img_big").attr("src")); if (imgArr.length > 1) { if (openindex > 0) { $("#prev_main").show(); } else { $("#prev_main").hide(); } if (openindex == imgArr.length - 1) { $("#next_main").hide(); } else { $("#next_main").show(); } } else { $("#prev_main").hide(); $("#next_main").hide(); } $("#prev_main").unbind("click"); $("#prev_main").click(function () { var index = imgArr.indexOf($("#img_big").attr("src")); $("#img_big").attr("src", imgArr[index - 1]); $("#next_main").show(); if (index - 1 == 0) { $("#prev_main").hide(); return; } }); $("#next_main").unbind("click"); $("#next_main").click(function () { var index = imgArr.indexOf($("#img_big").attr("src")); $("#prev_main").show(); if (index + 1 >= imgArr.length - 1) { $("#next_main").hide(); } if (index >= imgArr.length - 1) { return; } $("#img_big").attr("src", imgArr[index + 1]); }); $("b[data-field='close']").click(function () { layer.closeAll(); }) } }); }); }