;var js=document.scripts,com_lp_position=js[js.length-1];var com_lp={config:{repid:0},navinfor:{},server:'/e/extend/com_lp/',init:function(template,id,classid,config){var that=this;that.navinfor.id=id;that.navinfor.classid=classid;that.config=$.extend(config,that.config);if($('#'+that.config.render).length){$('#'+that.config.render).html(template);}else{$(com_lp_position).before(template);} that.bindEvent();that.userStatus();that.record.load();},api:{refresh:function(){com_lp.userStatus();com_lp.record.refresh();},islogin:function(){return com_lp.islogin;},toast:function(text,time,ret){com_lp.toast(text,time,ret);},indicator:function(type){if(type!='hide'){com_lp.showIndicator();}else{com_lp.hideIndicator();}}},bindEvent:function(){var that=this;$(document).on('click','.com_lp_load_more_record',function(){that.record.more();});$(document).on("click",'.com_lp_post_dropdow',function(e){e.stopPropagation();e.preventDefault();var name=$(this).attr('data-type')+'_box';var position=$(this).position().left;var box=$(this).parents('.com_lp_post').find('.com_lp_post_'+name);box.css('left',position+'px') box.toggleClass('active');});$(document).on('click','.com_lp_post_submit',function(e){e.stopPropagation();var parent=$(this).parents('.com_lp_post');if(parent.hasClass('com_lp_post_reply')){that.submit(that.config.repid,this);}else{$('.com_lp_post_reply').remove();$('.com_lp_record_item_reply').text('回复');that.submit(0,this);}});$(document).on('click',function(){$('.com_lp_post_dropdown_box').removeClass('active');});$(document).on('click','.com_lp_post_face_box li a',function(e){e.stopPropagation();var tag=$(this).data('tag');that.util.plface(tag,$(this).parents('.com_lp_post').hasClass('com_lp_post_reply'));$('.com_lp_post_face_box').removeClass('active');});$(document).on('click','.com_lp_record_filter a',function(){$('.com_lp_record_filter a').removeClass('active');$(this).addClass('active');var filter=$(this).data('filter');that.record.config.orderby=filter;that.showIndicator();that.record.refresh();});$(document).on('click',".com_lp_record_item_fd",function(){var plid=$(this).parents('.com_lp_record_item').data('plid');that.util.doDigg(plid,0,this)});$(document).on('click',".com_lp_record_item_zc",function(){var plid=$(this).parents('.com_lp_record_item').data('plid');that.util.doDigg(plid,1,this);});$(document).on('click','.com_lp_post_face_tabs a',function(e){e.stopPropagation();var index=$(this).index();var parent=$(this).parents('.com_lp_post_face_box');parent.find('.com_lp_post_face_tabs a').removeClass('active').eq(index).addClass('active');parent.find('.com_lp_post_face_tabs_content ul').removeClass('active').eq(index).addClass('active')});$(document).on('click','.com_lp_record_item_reply',function(e){$('.com_lp_post_submit_wrap span').html('').removeClass('active');var plid=$(this).parents('.com_lp_record_item').data('plid');var at=$(this).attr('title');that.util.reply(plid,this,at);});$(document).on('submit submited','form.com_lp_post',function(e){e.preventDefault();$(this).find('.com_lp_post_submit').trigger('click');})},record:{config:{inner:'.com_lp_record_list',filter:'.com_lp_record_filter',btn:'.com_lp_load_more_record',orderby:0,},load:function(){var obj=$(this.config.inner);var filter=$(this.config.filter);var btn=$(this.config.btn);var info=com_lp.navinfor;var orderby=this.config.orderby;if(!obj.attr('page')){$.getJSON(com_lp.server+'api/record.php?orderby='+orderby+'&id='+info.id+'&classid='+info.classid,function(json){if(json.total>0){obj.html(json.result);obj.attr('page',json.pageIndex).attr('total',json.pageTotal);$("com_lp_record_total").text(json.total);$("com_lp_record_page").text(json.pageTotal);filter.show();if(json.pageTotal>1){btn.show().html('更多精彩评论').removeAttr('disabled');}else{btn.show().html('已加载完毕');}}else{obj.html('

'+json.info+'

');btn.hide();} com_lp.hideIndicator();});}},refresh:function(){$(this.config.inner).removeAttr('page');this.load();},more:function(){var obj=$(this.config.inner),btn=$(this.config.btn),info=com_lp.navinfor;var page=parseInt(obj.attr('page')),nextpage=page+1;var total=parseInt(obj.attr('total'));var orderby=this.config.orderby;if(pagenextpage){btn.show().html('查看下一页').removeAttr('disabled');}else{btn.show().html('已加载完毕')}}else{btn.show('已加载完毕');}});}}},userStatus:function(){var that=this;var b=$('.com_lp_post_userinfo'),usertemp='';$.getJSON(that.server+'api/status.php',function(data){that.islogin=data.islogin;if(that.islogin){usertemp=that.config.membertemp;for(var i in data.data){var reg=new RegExp("\\[!--"+i+"--\\]",'g');usertemp=usertemp.replace(reg,data.data[i]);}}else{usertemp=that.config.logintemp;} b.html(usertemp);});},toast:function(info,time,callback){var t=$('
'+info+'
');$('body').append(t);t.show(0,function(){$(this).addClass('active')});setTimeout(function(){t.removeClass('active');t.fadeOut(function(){$(this).remove()});typeof(callback)=='function'?callback():null;},time*1000||1500);},showIndicator:function(){$('body').append("
");},hideIndicator:function(){$('.com_lp_indicator').remove();},submit:function(repid,senBtn){var that=this,id=that.navinfor.id,classid=that.navinfor.classid,saytext=that.util.dom.pltext(repid),key=that.util.dom.plkey(repid),img=$('.com_lp_post_form_img'),niming=$('input[name="niming"]:checked'),senBtn=$(senBtn),senBtnText=senBtn.html();var formData={enews:'AddPl',id:id,classid:classid,repid:repid,key:key.val(),nomember:that.islogin?0:1,saytext:saytext.val(),niming:niming.val(),img:img.val()};if(!formData.saytext){that.toast('请先说点什么吧');saytext.focus();return false;} if(that.config.showkey&&!formData.key){$('.com_lp_post_submit_wrap span').html('').removeClass('active');var img='/e/ShowKey/?v=pl';senBtn.parent('.com_lp_post_submit_wrap').find('span').html('').addClass('active');setTimeout(function(){that.util.dom.plkey(repid).focus();},100);return false;} $.ajax({url:that.server+'action.php',data:formData,type:'post',dataType:'json',beforeSend:function(){senBtn.html('正在提交...').attr('disabled',true);},success:function(data){that.toast(data.info,0,function(){$(document).trigger('comlp_submited',data);});if(data.status=='success'){saytext.val('');key.val('');that.config.repid=0;that.record.refresh();$('.com_lp_post_submit_wrap span').removeClass('active');}},error:function(data){that.toast(data.responseText);},complete:function(){senBtn.html(senBtnText).removeAttr('disabled');}});},util:{plface:function(tag,isReply){var myField;if(isReply){myField=$('.com_lp_post_reply .com_lp_post_form_saytext')[0];}else{myField=$('.com_lp_post_main .com_lp_post_form_saytext')[0];} if(document.selection){myField.focus();sel=document.selection.createRange();sel.text=tag;myField.focus();} else if(myField.selectionStart||myField.selectionStart=='0'){var startPos=myField.selectionStart;var endPos=myField.selectionEnd;var cursorPos=endPos;myField.value=myField.value.substring(0,startPos) +tag +myField.value.substring(endPos,myField.value.length);cursorPos+=tag.length;myField.focus();myField.selectionStart=cursorPos;myField.selectionEnd=cursorPos;} else{myField.value+=tag;myField.focus();}},doDigg:function(plid,dopl,obj){var that=com_lp;var formData=that.navinfor;formData.plid=plid;formData.dopl=dopl;formData.enews='DoForPl';com_lp.showIndicator();$.ajax({url:that.server+'action.php',data:formData,type:'post',dataType:'json',beforeSend:function(){},success:function(data){if(data.status=='success'){var num=parseInt($(obj).text())+1;$(obj).html(''+num);}else{that.toast(data.info);} $(document).trigger('comlp_doDigg',data);},error:function(data){that.toast(data.responseText);},complete:function(){com_lp.hideIndicator();}});},reply:function(plid,obj,at){com_lp.config.repid=plid;var box=$('.com_lp_record_item[data-plid="'+plid+'"]');$('.com_lp_record_item_reply').text('回复');if(box.find('.com_lp_post_reply').length){$('.com_lp_post_reply').remove();return false;}else{$('.com_lp_post_reply').remove();$(obj).text('取消');} var html=$('.com_lp_post_main').html();box.append('
'+html+'
');box.find('.com_lp_post_form_saytext').attr('placeholder',at);},dom:{plkey:function(repid){return repid?$('.com_lp_post_reply .com_lp_post_submit_wrap input[name="key"]'):$('.com_lp_post_main .com_lp_post_submit_wrap input[name="key"]');},pltext:function(repid){return repid?$('.com_lp_post_reply .com_lp_post_form_saytext'):$('.com_lp_post_main .com_lp_post_form_saytext');}}}};if(window.$){ $(function(){ com_lp.init("
",'21462','5',{"logintemp":"\u767b\u5f55<\/a>","membertemp":"<\/a>","showkey":1,"render":""}); try{ $(document).on('comlp_doDigg',function(event,ret){});$(document).on('comlp_submited',function(event,ret){if(ret.code=='GuestNotToPl'){}});;}catch(e){console.log(e);} }); }else{ console.error('评论模块需要依赖jquery'); }