$(document).ready(function () { $(document).on("click", "#btn-binhluan", function (e) { e.preventDefault(); var thisClick = $(this); var new_id = thisClick.attr("data-new"); var cmt_content = $("#binhluan-cnt").val(); if ($.trim(cmt_content) == "") { $("#binhluan-cnt").val("").focus(); return false; } $.ajax({ headers: { "X-CSRF-TOKEN": $("meta[name=\"csrf-token\"]").attr("content") }, url: "/gui-binh-luan", type: "post", dataType: "json", data: {cmt_content: cmt_content, new_id: new_id}, beforeSend: function () { thisClick.attr("id", "").html("Đang bình luận..."); }, success: function (data) { if (data != false) { if (data.hasOwnProperty("status_code")) { if (data.status_code == "01") { window.location.href= data.data; } if (data.status_code == "02") { alert("Tài khoản chưa được kích hoạt.Hãy liên hệ với admin để được hỗ trợ"); } if (data.status_code == "00") { if (!$("#cmt-list").parent("div").hasClass("box-comment-list")) { $("#cmt-list").parent("div").addClass("box-comment-list") } $("#cmt-list").prepend(data.data); } } $("#binhluan-cnt").val(""); } thisClick.attr("id", "btn-binhluan").html("Gửi bình luận"); }, fail: function () { } }); }); $(document).on("click", "#btn-sent-reply", function (e) { e.preventDefault(); var thisClick = $(this); var id_binhluan = thisClick.attr("data-parent"); var new_id = thisClick.attr("data-new"); var contents = $("#reply-cnt").val(); if ($.trim(contents) == "") { $("#reply-cnt").val("").focus(); return false; } $.ajax({ headers: { "X-CSRF-TOKEN": $("meta[name=\"csrf-token\"]").attr("content") }, url: "/gui-tra-loi-binh-luan", type: "post", dataType: "json", data: {id_binhluan: id_binhluan, contents: contents, new_id: new_id}, beforeSend: function () { thisClick.attr("id", "").html("Đang bình luận..."); }, success: function (data) { if (data != false) { if (data.hasOwnProperty("status_code")) { if (data.status_code == "01") { window.location.href= data.data; } if (data.status_code == "02") { alert("Tài khoản chưa được kích hoạt.Hãy liên hệ với admin để được hỗ trợ"); } if (data.status_code == "00") { thisClick.parents("li").append(data.data); } } $("#reply-cnt").val(""); } thisClick.attr("id", "btn-sent-reply").html("Gửi bình luận"); }, fail: function () { } }); }); $(document).on("click", ".btn-reply", function (e) { e.preventDefault(); var thisClick = $(this); var parent_id = thisClick.attr("data-id"); var new_id = $("#btn-binhluan").attr("data-new"); $.ajax({ headers: { "X-CSRF-TOKEN": $("meta[name=\"csrf-token\"]").attr("content") }, url: "/user/getboxreplycomment", type: "post", dataType: "json", data: {parent_id: parent_id, new_id: new_id}, success: function (data) { if (data) { $(".box-reply-comment").html(""); thisClick.parents("li").find(".box-reply-comment").html(data); } }, fail: function () { } }); }); $(document).on("click", ".btn-like", function (e) { e.preventDefault(); var thisClick = $(this); var id_binhluan = thisClick.attr("data-id"); var is_like = thisClick.attr("data-like"); var textLike = (is_like == 1) ? "Bỏ thích" : "Thích"; var num = thisClick.find(".number").html(); num = (typeof (num) != "undefined") ? parseInt(num) : 0; num = (is_like == 1) ? num + 1 : num - 1; if (num > 0) { textLike += "" + num + ""; } $.ajax({ headers: { "X-CSRF-TOKEN": $("meta[name=\"csrf-token\"]").attr("content") }, url: "/user/likecomment", type: "post", dataType: "json", data: {id_binhluan: id_binhluan, is_like: is_like}, success: function (data) { if (data) { if (is_like == 1) { if (!thisClick.hasClass("active")) { thisClick.addClass("active").html(textLike).attr("data-like", 0); } } else { thisClick.removeClass("active").html(textLike).attr("data-like", 1); } } }, fail: function () { } }); }); $(document).on("click", ".btn-follow", function (e) { e.preventDefault(); var thisClick = $(this); var yourid = parseInt($(this).attr("data-id")); var is_follow = parseInt(thisClick.attr("data-follow")); var textFollow = (is_follow == 1) ? "Bỏ theo dõi" : "Theo dõi"; $.ajax({ url: "/user/followuser", type: "post", dataType: "json", data: { yourid: yourid, is_follow: is_follow, _token: $("meta[name=csrf-token]").attr("content") }, success: function (data) { if (data) { if (is_follow == 1) { if (!$(".btn-follow").hasClass("active")) { if ($(".btn-follow").attr("data-id") == yourid) { $(".btn-follow").addClass("active").html(textFollow).attr("data-follow", 0); } } } else { if ($(".btn-follow").attr("data-id") == yourid) { $(".btn-follow").removeClass("active").html(textFollow).attr("data-follow", 1); } } } }, error: function (error) { } }); }); var offset = 6; var flag = true; $(".box-comment-list").scroll(function () { if ($(this).scrollTop() + $(this).innerHeight() >= $(this)[0].scrollHeight) { if (flag && offset > 0) { $.ajax({ headers: { "X-CSRF-TOKEN": $("meta[name=\"csrf-token\"]").attr("content") }, url: "/tai-binhluan-baiviet.html", type: "POST", dataType: "json", data: {offset: offset, id_baiviet: "id_baiviet; ?>"}, beforeSend: function (xhr) { flag = false; }, success: function (data) { if (data == "" || data == false) { return; } if (data) { $("#cmt-list").append(data); } offset += 6; flag = true; }, error: function (error) { } }); } } }); $(document).on("click", ".btn-yes-tip", function (e) { e.preventDefault(); var id = $(this).attr("data-id"); $.ajax({ url: "/user/paygoitipajax", type: "post", dataType: "json", data: {id: id, _token: $("meta[name=csrf-token]").attr("content")} }).done(function (data) { if (data != false) { var html = "