87,993
社区成员
发帖
与我相关
我的任务
分享
(function(){
var tools={
getCookie: function(name){
var arr = document.cookie.match(new RegExp("(^| )"+name+"=([^;]*)(;|$)"));
if(arr != null) return unescape(arr[2]); return null;
},
setcookie:function(cookieName, cookieValue, seconds, path, domain, secure) {
var expires = new Date();
expires.setTime(expires.getTime() + seconds);
document.cookie = cookieName + "="+ escape (cookieValue) + ";expires=" + expires.toGMTString();
},
trim:function (s){ //去除字符串两边空格
return s.replace(/(^\s*)|(\s*$)/ig, "");
},
// 将HTML转义为实体
escape:function(html) {
var keys = Object.keys || function(obj) {
obj = Object(obj)
var arr = []
for (var a in obj) arr.push(a)
return arr
}
var invert = function(obj) {
obj = Object(obj)
var result = {}
for (var a in obj) result[obj[a]] = a
return result
}
var entityMap = {
escape: {
'&': '&',
'<': '<',
'>': '>',
'"': '"',
'/':'\/'
}
}
entityMap.unescape = invert(entityMap.escape)
var entityReg = {
escape: RegExp('[' + keys(entityMap.escape).join('') + ']', 'g'),
unescape: RegExp('(' + keys(entityMap.unescape).join('|') + ')', 'g')
}
if (typeof html !== 'string') return '';
return html.replace(entityReg.escape, function(match) {
return entityMap.escape[match]
})
}
};
var app={
init:function(){
this.getDom();
this.addEvent();
if(this.$comment_con.children('li').length < 1){
this.first=true;
this.$comment_con.after('<div class="page-unload" id="first_com" style="display: block;background:#fff;"><span class="page-reload">还没有评论,快来抢沙发吧!</span></div>');
}
},
getDom:function(){ //获取dom
this.$submit_con=$('#art_scroe_sub'); //提交
this.$text_con=$('#art_textarea_text'); //文本框
this.$limit_con=$('#art_limit'); //字数
this.$uesr_img=$('#uesr_img'); //字数
this.$comment_con=$('#comment_list'); //评论列表
this.$comment_all=$('#comment_all'); //所有评论列表
this.$page_unload=$('#page_unload'); //点击加载
this.$page_load=$('#page_load'); //正在加载
this.limit_min=3; //最小限制字数
this.limit_max=240; //最大限制字数
this.news_id=$("#atr_content").attr("news_id"); //被评论文章的id
this.param=JSON.parse(this.$submit_con.attr('data-id')); //用户评论相关参数
this.comment_limit_time= 10* 1000; //评论限制时间 6s=6*1000 ms
this.like_limit_time= 24 * 60 * 60 * 1000; //点赞限制时间 24h=10*60*1000 ms
this.first=false;
this.$tag = $("#fast_tag");
this.statsUrl = $("#statsParam").attr("data-url"); //统计url
this.aTag = [];
this.$score = $("#get_score");
this.star_score = $("#get_score .up").length;
},
light_star:function(num){ //我想要调用的函数
var $stars = this.$score.children();
if(num>0){
for(var i=0;i<$stars.length;i++){
if(i<num){
$stars.eq(i).addClass('up').removeClass('down');
}else{
$stars.eq(i).addClass('down').removeClass('up');
}
}
}else{
$stars.addClass('down').removeClass('up');
}
},
........