main.js
7.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
/**
* 评论
*/
comment = {
/**
* 展示回复按钮
* @param comment_id
* @param article_id
*/
reply_show:function(comment_id,article_id){
var com_id = '#reply_'+comment_id+"_"+article_id;
if($(com_id).is(":hidden")){
$(com_id).show(); //如果元素为隐藏,则将它显现
$(com_id + ' [name="comment"]').val('回复:');
$(com_id + ' [name="comment"]').focus();
}else{
$(com_id).hide(); //如果元素为显现,则将其隐藏
}
},
/**
* 回复保存
* @param comment_id
* @param article_id
* @param reply_userid
* @param create_id
* @param article_title
*/
reply_submit:function(comment_id,article_id,reply_userid,create_id,article_title){
var comment_content = $("#reply_"+comment_id+"_"+article_id+" [name='comment']").val();
if(comment_content==''){
alert('发布内容不能为空!');
return;
} else if (comment_content.length > 400) {
alert('发布内容长度不能大于400!');
return;
}
// 去除回复提示
var tmpContent = "回复:";
if(comment_content.indexOf(tmpContent) == 0){
comment_content = comment_content.substr(tmpContent.length);
}
comment.oper_save(comment_content,article_id,reply_userid,create_id,article_title,comment_id);
$('#reply_'+comment_id+"_"+article_id).hide();
},
/**
* 删除评论
*/
reply_del:function(comment_id,article_id) {
if(window.confirm('你确定要删除该评论吗?')){
jQuery.ajax({
type:'POST',
url:jflyfox.BASE_PATH + 'front/comment/del',
data:"model.id=" + comment_id + "&model.article_id=" + article_id,
success:function(data){
if(data.status==1){
$('#comment_'+comment_id+'_'+article_id).remove();
var count = parseInt($('[name="count_comment"]').val());
$('[name="count_comment"]').val(count - 1);
$('#count_comment_show').html("评论(" + (count - 1) + ")");
} else {
alert('删除失败:'+data.msg);
}
$('[name="comment"]').val('');
},
error:function(html){
var flag = (typeof console != 'undefined');
if(flag) console.log("服务器忙,提交数据失败,代码:" +html.status+ ",请联系管理员!");
alert("服务器忙,提交数据失败,请联系管理员!");
}
});
}
}
/**
* 保存评论: 内容 文章id 回复人id 文章创建人id 文章题目
*/
,oper_save:function(comment_content,article_id,reply_userid,create_id , article_title, fatherId){
article_title = article_title || '';
fatherId = fatherId || 0;
// var urlParams = "model.content=" + comment_content + "&model.article_id=" + article_id
// + "&model.reply_userid=" + reply_userid+ "&model.create_id=" + create_id + "&model.fatherId=" + fatherId;
var urlParams = {
"model.content":comment_content,
"model.article_id":article_id,
"model.reply_userid":reply_userid,
"model.create_id":create_id,
"model.fatherId":fatherId
};
jQuery.ajax({
type:'POST',
url:jflyfox.BASE_PATH + 'front/comment/save',
data:urlParams,
success:function(data){
if(data.status==1){
var createTime = data.create_time;
var comment_id = data.comment_id;
var title_url = data.title_url||'';
var username = data.create_name;
var reply_username = data.reply_username;
title_url = (title_url=='')?(jflyfox.BASE_PATH + 'static/images/user/user.png'):title_url;
var htmlText = '<li class="media" id=comment_'+ comment_id + '_' + article_id + '>';
htmlText += '<a class="media-left" href="#"><img alt="" width="48" height="48" alt="头像" class="img-circle img_radius" src="'+title_url+'" /></a>';
htmlText += '<div class="media-body">';
// 回复头
htmlText += '<div>';
if(article_title != ''){
htmlText += '<a href="front/article/'+ article_id +'#article_comment" target="_blank">'+article_title+'</a>';
htmlText += '<span class="comment-txt">文章中</span>';
}
htmlText += '<a href="#">'+username+'</a>';
if(reply_userid > 0 ) {
htmlText += '<span class="comment-txt">回复</span>';
htmlText += '<a href="#">' + reply_username + '</a>';
}
htmlText += '</div>';
// 回复内容
htmlText += '<div>'+comment_content+'</div>';
// 回复底部
htmlText += '<div class="row"><div class="col-md-8">';
htmlText += '<span class="comment-time">'+createTime+'</span>';
htmlText += '</div><div class="col-md-4 text-right">';
htmlText += '<a href="javascript:comment.oper_del(' + comment_id + ',' + article_id +');" style="float: right;"><i class="fa fa-remove"></i> 删除</a>';
htmlText += '</div></div></li>';
$('.comment-reply-list').prepend(htmlText);
var count = parseInt($('[name="count_comment"]').val());
$('[name="count_comment"]').val(count + 1);
$('#count_comment_show').html("评论(" + (count + 1) + ")");
} else {
alert('保存失败:'+data.msg);
}
$('[name="comment"]').val('');
},
error:function(html){
var flag = (typeof console != 'undefined');
if(flag) console.log("服务器忙,提交数据失败,代码:" +html.status+ ",请联系管理员!");
alert("服务器忙,提交数据失败,请联系管理员!");
}
});
}
,count:function(){
if ($("#mymessage").length <= 0){
return;
}
jQuery.ajax({
type:'POST',
url:jflyfox.BASE_PATH + 'front/comment/count',
success:function(data){
if(data.status==1){
if(data.count > 0 ){
$('#mymessage').hide();
$('#mymessage').html('我的消息('+data.count+')');
$('#mymessage').css('font-weight','bold');
$('#mymessage').css('color','green');
$('#mymessage').show(500);
} else {
// 如果已经读过,那么恢复初始化
if($('#mymessage').text() != '我的消息') {
$('#mymessage').text('我的消息');
$('#mymessage').css('font-weight','');
$('#mymessage').css('color','#454545');
}
}
} else {
console_log('获取评论失败:'+data.msg);
}
},
error:function(html){
var flag = (typeof console != 'undefined');
if(flag) console.log("服务器忙,提交数据失败,代码:" +html.status+ ",请联系管理员!");
// alert("服务器忙,提交数据失败,请联系管理员!");
}
});
// 压力太大了就改大点
window.setTimeout('comment.count()',600*1000);
}
};
/**
* 文章喜欢
*/
articlelike = {
click:function(article_id){
if($('#articlelike_'+article_id).hasClass('glyphicon-heart-empty')){
articlelike.yes(article_id);
} else {
articlelike.no(article_id);
}
}
/**
* 喜欢
*
* @param article_id
*/
,yes:function(article_id){
jQuery.ajax({
type:'POST',
url:jflyfox.BASE_PATH + 'front/articlelike/yes/'+article_id,
success:function(data){
if(data.status==1){
$('#articlelike_'+article_id).removeClass('glyphicon-heart-empty').addClass('glyphicon-heart');
$('#articlelike_'+article_id).attr("title","取消喜欢");
} else {
alert('失败:'+data.msg);
}
},
error:function(html){
var flag = (typeof console != 'undefined');
if(flag) console.log("服务器忙,提交数据失败,代码:" +html.status+ ",请联系管理员!");
alert("服务器忙,提交数据失败,请联系管理员!");
}
});
}
/**
* 取消喜欢
*
* @param article_id
*/
,no:function(article_id){
jQuery.ajax({
type:'POST',
url:jflyfox.BASE_PATH + 'front/articlelike/no/'+article_id,
success:function(data){
if(data.status==1){
$('#articlelike_'+article_id).removeClass('glyphicon-heart').addClass('glyphicon-heart-empty');
$('#articlelike_'+article_id).attr("title","喜欢");
} else {
alert('失败:'+data.msg);
}
},
error:function(html){
var flag = (typeof console != 'undefined');
if(flag) console.log("服务器忙,提交数据失败,代码:" +html.status+ ",请联系管理员!");
alert("服务器忙,提交数据失败,请联系管理员!");
}
});
}
};