var trends ={
load:function(){ //第一次加载
var url = $('.teaching .tab a[class="cur"]').attr('url');
$('.loading-btn').hide();
$('.teaching ul').html('正在加载数据...');
$.get(url+'&page=1',function(data){
if(data.length>0){
$('.teaching ul').html(data);
$('.loading-btn').attr('page','1');
$('.loading-btn').show();
}else{
$('.teaching ul').html('还没有动态');
$('.loading-btn').hide();
}
});
},
append:function(obj){//追加数据
var url = $('.teaching .tab a[class="cur"]').attr('url');
if($(obj).html()=='点击加载更多' || $(obj).html()=='已经到底了'){
page = parseInt($(obj).attr('page'))+1;
$(obj).attr('page',page);
$(obj).html('正在加载数据...');
$.get(url+'&page='+page,function(data){
$(obj).parent().hide();
$('.teaching > ul').append(data);
});
}
},
showComment:function(obj){//显示评论框
var replayBox = $(obj).parents(".txt").find(".replay-box");
$(".replay-box textarea").keyup(maxLimit).keydown(maxLimit);//调用方法
if(replayBox.css('display')=='none'){
replayBox.slideDown(500);
//获取评论
var replay_lists = '';
var t = $(obj);
t.parents(".txt").find(".replay-lists").html('<p>正在加载评论...</p>');
var tid = $(obj).parents("li").attr('tid'); //动态id
var type = $(obj).parents("li").attr('objecttype'); //取出动态类型,如文章,相册
var objectid = $(obj).parents("li").attr('objectid');
var objectpid = $(obj).parents("li").attr('objectpid'); //对象父ID
$.get("<?php echo U('common/commentnew/Query')?>",{type: type,objectid: objectid,objectpid: objectpid,style:'trends'},function(data){
if(data.length>0){
t.parents(".txt").find(".replay-lists").html(data);
}else{
t.parents(".txt").find(".replay-lists").html('');
}
});
var typeArray = {album:'1',post:'2',resource:'3',app:'4'}
$.get("<?php echo U('center/person/Trends/Laudlist')?>",{object_id:objectid,type:typeArray[type]},function(data){
$(obj).parents(".txt").find(".forwardUsers").html(data);
});
}else{
replayBox.slideUp(500);
}
return false
},
appendComment:function(obj){//追加
if($(obj).html()=='点击加载更多'){
page = parseInt($(obj).attr('page'))+1;
$(obj).attr('page',page);
$(obj).html('正在加载数据...');
var tid = $(obj).parents("li").attr('tid'); //动态id
var type = $(obj).parents("li").attr('objecttype'); //取出动态类型,如文章,相册
var objectid = $(obj).parents("li").attr('objectid');
var objectpid = $(obj).parents("li").attr('objectpid'); //对象父ID
$.get("<?php echo U('common/commentnew/Query')?>",{type: type,objectid: objectid,objectpid: objectpid,page:page,style:'trends'},function(data){
if(data.length>0){
$(obj).parents(".commentLoading").before(data);
$(obj).html('点击加载更多');
}else{
$(obj).html('已经到底了');
}
});
}
},
submitComment:function(obj){//发表评论
var t = $(obj);
var content = $(obj).parents(".replay-box").find('textarea').val();
if(content==''){
art.tips({content:'评论内容不可为空!',type:'2'});
return false;
}
t.addClass('loading');
t.attr('disabled','disabled');
var objectid = $(obj).parents("li").attr('objectid');
var objectpid = $(obj).parents("li").attr('objectpid'); //对象父ID
var type = $(obj).parents("li").attr('objecttype'); //取出动态类型,如文章,相册
$.post("<?php echo U('common/commentnew/Publish')?>",{ objectid: objectid,objectpid: objectpid,type: type,content: content},function(data){
if(data=='-1'){
art.tips({content:'评论失败!',type:'2'});
}else if(data=='-2'){
art.tips({content:'您的发言太快了~',type:'2'});
}else{
$.get("<?php echo U('common/commentnew/QueryOne')?>",{id:data,type:type,style:'trends'},function(html){
t.parents(".txt").find(".replay-lists").prepend(html);
});
//发表成功,新增一条到页面
art.tips({content:'评论成功!'});
//页面评论数+1
var commentCountObj = $(obj).parents("li").find('.commentCount em');
commentCountObj.html(parseInt(commentCountObj.html())+1);
commentCountObj.parent().show();
$(obj).parents(".replay-box").find('textarea').val('');
$(obj).parents(".replay-box").find('.max_num').text(140);
t.removeClass('loading');
t.removeAttr('disabled');
}
});
},
showReply:function(obj){//显示回复框
if($(obj).parents(".con").find(".review-replay-box").length >0){
$(obj).parents(".con").find(".review-replay-box").hide(300);
}else{
$('.review-replay-box textarea').val("回复 @"+$(obj).attr('username')+":");
$(obj).parents(".con").append($('.review-replay-box'));
$(obj).parents(".con").find(".review-replay-box").show(300);
}
},
submitReply:function(obj){//发表回复
var t = $(obj);
var content = $(obj).parents(".review-replay-box").find('textarea').val();
if(content==''){
art.tips({content:'回复内容不可为空!',type:'2'});
return false;
}
t.addClass('loading');
t.attr('disabled','disabled');
var objectid = $(obj).parents("li").attr('objectid');
var objectpid = $(obj).parents("li").attr('objectpid'); //对象父ID
var type = $(obj).parents("li").attr('objecttype'); //取出动态类型,如文章,相册
$.post("<?php echo U('common/commentnew/Publish')?>",{objectid: objectid,objectpid: objectpid,type: type,content: content},function(data){
if(data=='-1'){
art.tips({content:'评论失败!',type:'2'});
}else if(data=='-2'){
art.tips({content:'您的发言太快了~',type:'2'});
}else{
t.parents(".review-replay-box").hide(300);
//发表成功,新增一条到页面
$.get("<?php echo U('common/commentnew/QueryOne')?>",{id:data,type:type,style:'trends'},function(html){
t.parents(".txt").find(".replay-lists").prepend(html);
});
art.tips({content:'回复成功!'});
//页面评论数+1
var commentCountObj = t.parents("li").find('.commentCount em');
commentCountObj.html(parseInt(commentCountObj.html())+1);
t.parents(".review-replay-box").find('textarea').val('');
t.removeClass('loading');
t.removeAttr('disabled');
}
});
},
showForward:function(obj){//显示转发框
var tid = $(obj).attr('tid');
var userid = $(obj).attr('userid');
var curUserid = "<?php echo $this->userid;?>";
if(curUserid!=userid){
$('#forwardBox').attr('tid',tid);
$('#forwardBox').find('textarea').val('');
art.show({
id :'forwardBox',
title:'转发',
content :'forwardBox',
lock : true
})
$('#forwardBox').find('.max_num').text(140);
}else{
art.tips({content:'自己不能转发自己的动态',type:'2'});
}
},
submitForward:function(obj){//发表转发
var title = $('#forwardBox').find('textarea').val();
var t = $(obj);
var tid = $('#forwardBox').attr('tid');
t.addClass('loading');
t.attr('disabled','disabled');
$.post("<?php echo U('center/person/Trends/SubmitForward')?>",{ tid: tid,title: title},function(data){
if(data=='-1'){
art.tips({content:'转发失败!',type:'2'});
}else{
art.tips({content:'转发成功!'});
//页面评论数+1
var forwardCountObj = $('.teaching li[tid="'+tid+'"]').find('.forwardCount em');
forwardCountObj.html(parseInt(forwardCountObj.html())+1);
forwardCountObj.parent().show();
art.dialog.get('forwardBox').close();
}
t.removeClass('loading');
t.removeAttr('disabled');
})
},
laud :function(obj){
var object_id = $(obj).parents("li").attr('objectid');
var category_id = $(obj).parents("li").attr('objectpid');
var type = $(obj).parents("li").attr('objecttype');
var typeArray = {album:'1',post:'2',resource:'3',app:'4'}
if(object_id != ""){
$.ajax({
type: "POST",
url: "<?php echo Yii::app()->createUrl('center/person/UserLaud/AddLaud')?>",
data: "category_id="+category_id+"&object_id="+object_id+"&type="+typeArray[type], //取出动态类型,如文章,相册
success: function(data){
if(data == "2"){
art.tips({content:'您已赞过',type:'2'});
return false;
}else if(data=='1'){
art.tips({content:'谢谢支持!',type:'1'});
var countObj = $(obj).find('em');
countObj.html(parseInt(countObj.html())+1);
countObj.parent().show();
return false;
}
}
});
}
}
}
jquery 延迟加载
最新推荐文章于 2019-12-12 11:39:06 发布
该博客介绍了使用jQuery实现动态加载数据的功能,包括首次加载、追加数据、显示和隐藏评论框、追加评论、发表评论、显示回复、发表回复、显示转发框和转发操作。同时,涉及到评论系统的加载和交互,如加载更多评论、限制输入字数等。
摘要由CSDN通过智能技术生成