\ \
回复 引用 删除
\
@' + data.parent_comment_username + '\
' + data.parent_comment_content + '
' + cont + '
\
\\';
} else { var tr = '
#
' + {{ forloop.counter }} + ' 楼 ' + createTime + ' {{ user_obj }}\\ \
\\' + cont + '\
}
$(".contcont").append(tr);
alert(cont)
editor.html("");
parent_comment_id = null;
} else {
location.href = "/login/"
}
}
})
}); function foo() {
$(".diggnum_error").html("")
}
{# 点赞踩踩,每次进来都会写cookie,前端获取到执行响应的操作#}
$(".diggit").click(function () { if ($(".infos").attr("user_username")){
$.ajax({
url: "/blog/up_count/",
type: "POST",
data: {
csrfmiddlewaretoken: $("[name='csrfmiddlewaretoken']").val(),
article_id:{{ article_obj.nid }}
},
success: function (data) {
data = JSON.parse(data); if (data["state"]) { var val = parseInt($("#digg_count").html()) + 1;
$("#digg_count").html(val)
$(".diggnum_error").html("请不要重复点赞").css("color", "red");
setTimeout(foo, 3000)
}else{
location.href="/login/"
}
});
$(".buryit").click(function () { if ($(".infos").attr("user_username")){
url: "/blog/down_count/",
data = JSON.parse(data);
{# console.log(data);#} if (data["state"]) { var val = parseInt($("#bury_count").html()) + 1;
$("#bury_count").html(val)
$(".diggnum_error").html("去你大爷的,").css("color", "red")
{# 回复按钮功能#}
{# var parent_comment_id = null;#}
{# $(".contcont").on("click", ".reply", function () {#}
{# var parent_user_username = $(this).attr("comment_username");#}
{# editor.sync();#}
{# editor.focus();#}
{# editor.appendHtml("@" + parent_user_username + "
")#}
{# parent_comment_id = $(this).attr("comment_id");#}
{# alert(parent_comment_id)#}
{##}
{# })#}
$(".comment_tree_list").on("click", ".reply", function () { var parent_user_username = $(this).attr("comment_username");
editor.sync();
editor.focus();
editor.appendHtml("@" + parent_user_username + "
")
parent_comment_id = $(this).attr("comment_id");
alert(parent_comment_id)
})
{# 获取到评论树#}
$.ajax({
url: "/blog/commentTree/{{ article_obj.nid }}/",
success: function (data) { var data = JSON.parse(data); var s = showCommentTree(data);
$(".comment_tree_list").append(s);
{# 评论树相关样添加式慢慢#} var numb = 0; function showCommentTree(comment_list) { var html = "";
numb +=1;
$.each(comment_list, function (i, comment_dict) { var count = comment_dict["content"]; var user = comment_dict["user__username"]; var parent_comment_id = comment_dict["parent_comment_id"]; var createTime = new Date().Format("yyyy-MM-dd hh:mm"); var comment_str = '
' +
'' +
'
#
'+numb+'楼'+createTime+'__'+user+'' +
<a class="reply" id="reply" comment_id=
'+parent_comment_id+' comment_username='+user+'>回复 引用 删除 ' +
''+count+'';
{# var comment_str = '
<a href="/blog/
' + comment_dict["user__username"] +#}
{# '/"><img class="media-object" src="/media/' + comment_dict["user__avatar"] + '" width="30" height="30" alt="...">' +#}
{# '
#' + comment_dict["nid"] + '楼 ' +#}
{# comment_dict["comment_data"] + '<a href="/blog/
' + comment_dict["user__username"] + '/"> ' +#}
{# comment_dict["user__username"] + '<a class="reply_comment_btn pull-right" comment_id="' + comment_dict["nid"] +#}
{# '" conmment_username="' + comment_dict["user__username"] + '">回复
' + comment_dict["content"] +#}
{# '';#}
{# 如果他有子列表,继续执行该函数#} if (comment_dict["chidren_commentList"]) { var s = showCommentTree(comment_dict["chidren_commentList"]);
comment_str += s;
comment_str += "";
html += comment_str;
{# alert(html)#}
}); return html
} script>{% endblock %}
{% block page %}
{% endblock %}<script>
{# 建楼层用的#} var nb = parseInt($(".nb:last").text()) + 1;
{# 格式化时间#}
Date.prototype.Format = function (fmt) { //author: meizz
var o = { "M+": this.getMonth() + 1, //月份
"d+": this.getDate(), //日
"h+": this.getHours(), //小时
"m+": this.getMinutes(), //分
"s+": this.getSeconds(), //秒
"q+": Math.floor((this.getMonth() + 3) / 3), //季度
"S": this.getMilliseconds() //毫秒 }; if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length)); for (var k in o) if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length))); return fmt;
}; var createTime = new Date().Format("yyyy年MM月dd日 hh:mm");
{# 提交评论#}
$(".submit").click(function () { if ($("#comment_content").val().charAt(0) != "@") {
parent_comment_id = null
} if (parent_comment_id) {
{# 这里是直接回复回复#}
alert("评论回复");
{# var index = $("#comment_content").val().indexOf("\n");#} var index = editor.html().indexOf("\n")
alert(index)
{# 找到换行符第一次出现的地方 #}
{# cont = $("#comment_content").val().slice(index + 1);#}
cont = editor.html().slice(index+1)
{# 截取换行符第一次出现的地方的下一个点到结束 #}
alert(cont)
} else {
{# 这里只是单纯的回复#}
alert("单纯的回复");
{# cont = $("#comment_content").val()#}
cont = editor.html()
{# 当前输入的内容#}
url: "/blog/{{ current_user }}/com/",
type: "POST",
data: {
csrfmiddlewaretoken: $("[name='csrfmiddlewaretoken']").val(),
article_id:{{ article_obj.nid }},
text: cont,
parent_comment_id: parent_comment_id,
},
success: function (data) {
data = JSON.parse(data); if (data["success"]) {
{# if有父级评论#} if (parent_comment_id) { var tr = '
' + nb + ' 楼 ' + createTime + ' {{ user_obj }}\\ \
\\
@
' + data.parent_comment_username + '\
' + data.parent_comment_content + '\' + cont + '\
} else { var tr = '
$(".contcont").append(tr);
$(".comment_content").val("");
parent_comment_id = null;
} else {
alert($.session.get("urls"));
location.href = "/login/"
}); function foo() {
$(".diggnum_error").html("")
}
{# 正常用户#}
$(".diggit").click(function () {
url: "/blog/up_count/",
article_id:{{ article_obj.nid }}
data = JSON.parse(data); if (data["state"]) { var val = parseInt($("#digg_count").html()) + 1;
$("#digg_count").html(val)
$(".diggnum_error").html("请不要重复点赞").css("color", "red");
setTimeout(foo, 3000)
});
$(".buryit").click(function () {
url: "/blog/down_count/",
data = JSON.parse(data);
{# console.log(data);#} if (data["state"]) { var val = parseInt($("#bury_count").html()) + 1;
$("#bury_count").html(val)
$(".diggnum_error").html("去你大爷的,").css("color", "red")
{# 游客进来之后吧当前的url写到session中,跳转到login页面#}
$("#wu_diggnum").click(function () {
$.session.set("urls", window.location.href);
alert(window.location.href)
location.href = "/login/"
{# 回复按钮功能#} var parent_comment_id = null;
$(".contcont").on("click", ".reply", function () {
{# alert(parent_comment_id);#} var parent_user_username = $(this).attr("comment_username");
alert(parent_user_username)
{# location.href = "#comment_content";#}
{# $(".comment_content").focus();#}
editor.focus()
{# $(".comment_content").val("@" + parent_user_username + "\n");#}
editor.html("@" + parent_user_username + "\n")
parent_comment_id = $(this).attr("comment_id");
alert(parent_comment_id)
{# alert(parent_comment_id);#}
})
{# 获取到评论树#}
$.ajax({
url: "/blog/commentTree/{{ article_obj.nid }}/",
success: function (data) { var data = JSON.parse(data); var s = showCommentTree(data);
$(".comment_tree_list").append(s);
}) function showCommentTree(comment_list) { var html = "";
$.each(comment_list, function (i, comment_dict) { var val = comment_dict["content"]; var comment_str = '
' + val + '
'; if (comment_dict["chidren_commentList"]) { var s = showCommentTree(comment_dict["chidren_commentList"]);
comment_str += s;
{# alert(comment_str)#}
comment_str += "";
html += comment_str;
{# alert(html)#}
}); return html
}script>