westdc-zf1/public/js/voice-view.js

154 lines
4.4 KiB
JavaScript
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

var commentBtn = $('#comment-submit');
var slider;
$(document).ready(function(e) {
comment.Load(0);
if(_this.slider)
{
$('ul.image-gallery-slider').slidesjs({
navigation: true,
start: 1,
play: {
auto: true,
interval: 5000,
},
pagination: {
active: false
}
});
}
commentBtn.click(function(){
$.ajax({
type:"POST",
url:"/voice/comment/" + _this.vid,
data:$('#comment-form').serialize(),
success:function(data){
if(typeof(data) != 'object')
{
comment.Alert('服务器掉链子啦,请稍后再试','alert-danger');
return false;
}
if( ! $.isEmptyObject(data.error))
{
comment.Alert(data.error,'alert-danger');
return false;
}
comment.posted(data);
},
timeout: 10000,
error: function(){
comment.Alert("处理中发生错误,请重试或稍后再试",'alert-danger');
},
beforeSend: function(){
commentBtn.attr('disabled','disabled');
commentBtn.hide();
$('#comment-progress').show();
},
complete: function(){
commentBtn.removeAttr('disabled');
commentBtn.show();
$('#comment-progress').hide();
}
});
});
});
var comment = {
Alert : function(content,type){
$('#comment-ctl-msg').remove();
$('#comment-body').after(comment.AlertBox(content,type));
},
AlertBox : function(content,type){
html = '<div class="alert alert-dismissable '+ type +'" id="comment-ctl-msg">'
+ '<button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>'
+ content
+ '</div>';
return html;
},
posted : function(data){
$('#comment-body').val('');
$('#comment-list').children('.alert').remove();
if($('#comment-list').children('.comments').length < 1)
{
$('#comment-list').append(comment.mediabox(data));
}else{
$('#comment-list').children('.comments').last().after(comment.mediabox(data));
}
},
mediabox : function(data){
if($.isEmptyObject(data.avatar))
{
avatar = "";
}else{
avatar = '<a class="pull-left" href="#">'
+ '<img class="media-object" src="' + data.avatar + '" alt="">'
+ '</a>';
}
if(data.replyid == null)
{
reply = "";
}else{
more = data.contentr.length > 20 ? "...":"";
reply = '<blockquote>'
+ '<small>'+data.authorr + ': ' + data.contentr.substring(0,20) + more +'</small>'
+ '</blockquote>';
}
html = '<div class="media comments" id="comment-list-'+data.id+'">'
+ avatar
+ '<div class="media-body">'
+ '<span class="pull-right"><a href="javascript:void(0);" onclick="comment.reply('+data.id+')">回复</a></span>'
+ '<span class="pull-right">' + data.time + ' </span>'
+ '<h4 class="media-heading">' + data.author + '</h4>'
+ reply
+ data.content
+ '</div>'
+ '</div>';
return html;
},
Load : function(page){
$.ajax({
type:"POST",
url:"/voice/comment/" + _this.vid,
data:"page="+page,
success:function(data){
if(typeof(data) != 'object')
{
$('#comment-list').html(comment.AlertBox('评论读取出错,<a href="javascript:void(0);" onclick="comment.Load(0)">请重试</a>','alert-danger'));
return false;
}
if(data.comments.length >0)
{
comment.Append(data);
}else{
$('#comment-list').html(comment.AlertBox('暂时还没有人发表意见哦','alert-info'));
}
},
timeout: 10000,
error: function(){
$('#comment-list').html(comment.AlertBox('评论读取出错,<a href="javascript:void(0);" onclick="comment.Load(0)">请重试</a>','alert-danger'));
},
beforeSend: function(){
$('#comment-list').remove('.alert');
$('#comment-list').remove('.comments');
$('#comment-fetch-progress').show();
},
complete: function(){
$('#comment-fetch-progress').hide();
}
});
},
Append : function(data)
{
html = "";
for(i in data.comments)
{
html += comment.mediabox(data.comments[i]);
}
html += data.paginator;
$('#comment-list').html(html);
},
reply : function(id){
$('#comment-body').prevAll('.alert').remove();
msg = '回复 ' + $('#comment-list-'+id).find('.media-heading').text();
input = '<input type="hidden" name="reply" value="'+id+'" />';
$('#comment-body').before(comment.AlertBox(msg+input,'alert-info'));
}
}; //comment