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 = '
' + '' + content + '
'; 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 = '' + '' + ''; } if(data.replyid == null) { reply = ""; }else{ more = data.contentr.length > 20 ? "...":""; reply = '
' + ''+data.authorr + ': ' + data.contentr.substring(0,20) + more +'' + '
'; } html = '
' + avatar + '
' + '回复' + '' + data.time + ' ' + '

' + data.author + '

' + reply + data.content + '
' + '
'; 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('评论读取出错,请重试','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('评论读取出错,请重试','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 = ''; $('#comment-body').before(comment.AlertBox(msg+input,'alert-info')); } }; //comment