var mccms = {
android : navigator.userAgent.match(/Android|Linux/i) != null,
ios : navigator.userAgent.match(/iPad|iPhone|iPod/i) != null,
index : null,
layer : layer,
user : {log:-1,nichen:'游客',pic:Mcpath.basepath+'mccms/user.png',vip:0,cion:0,ticket:0,viptime:0},
//默认加载
init : function(){
//会员信息
$.getJSON('//'+Mcpath.url+Mcpath.web+'index.php/api/user/info?callback=?', {t:Math.random()}, function(res) {
if(res.code == 1) mccms.user = res.data;
});
},
//发送短信验证码
code_send : function(_post,_callback){
$.getJSON('//'+Mcpath.url+Mcpath.web+'index.php/api/code/tel_send?callback=?', _post, function(res) {
//回调
if(_callback != null){
_callback(res);
}else{
if(res.code == 1){
mccms.msg(res.msg,1);
}else{
mccms.msg(res.msg);
}
}
});
},
//评论列表
comment : function(_post,_callback){
$.getJSON('//'+Mcpath.url+Mcpath.web+'index.php/api/comment/lists?callback=?', _post, function(res) {
//回调
if(_callback != null){
_callback(res);
}else{
if(res.code == 1){
if(res.html){
if(_POST@['page'] > 1){
$('.comment-wrap').append(res.html);
}else{
$('.comment-wrap').html(res.html);
}
$('.no-comment').hide();
$('.getmore').show();
}else{
if(_POST@['page'] == 1){
$('.no-comment').show();
$('.getmore').hide();
}else{
$('.getmore').html('全部加载完成!!!').data('end','1');
}
}
}
}
});
},
//发表评论
comment_send : function(_post,_callback){
$.getJSON('//'+Mcpath.url+Mcpath.web+'index.php/api/comment/add?callback=?', _post, function(res) {
//回调
if(_callback != null){
_callback(res);
}else{
if(res.code == 1){
mccms.msg(res.msg,1);
}else{
mccms.msg(res.msg);
}
}
});
},
//赞评论
comment_zan : function(_post,_callback){
$.getJSON('//'+Mcpath.url+Mcpath.web+'index.php/api/comment/zan?callback=?', _post, function(res) {
//回调
if(_callback != null){
_callback(res);
}else{
if(res.code == 1){
mccms.msg(res.msg,1);
}else{
mccms.msg(res.msg);
}
}
});
},
//赠送月票
ticket_send : function(_post,_callback){
var index = mccms.layer.open({type: 2,content: '请稍后'});
$.getJSON('//'+Mcpath.url+Mcpath.web+'index.php/api/rend/ticket_send?callback=?', _post, function(res) {
//回调
if(_callback != null){
_callback(res);
}else{
if(res.code == 1){
mccms.msg(res.msg,1);
}else{
mccms.msg(res.msg);
}
}
mccms.layer.close(index);
mccms.layer.close(mccms.index);
});
},
//未读消息
message : function(_callback){
$.getJSON('//'+Mcpath.url+Mcpath.web+'index.php/api/rend/message?callback=?', {t:Math.random()}, function(res) {
//回调
if(_callback != null) _callback(res);
});
},
//礼物打赏
sendgift : function(_post,_callback){
var index = mccms.layer.open({type: 2,content: '请稍后'});
$.getJSON('//'+Mcpath.url+Mcpath.web+'index.php/api/rend/gift_send?callback=?', _post, function(res) {
mccms.layer.close(index);
//回调
if(_callback != null){
_callback(res);
}else{
if(res.code == 1){
mccms.user.cion = res.cion;
mccms.msg(res.msg);
}else{
mccms.msg(res.msg,1);
}
}
});
},
//判断收藏
isfav : function(_post,_callback){
$.getJSON('//'+Mcpath.url+Mcpath.web+'index.php/api/rend/isfav?callback=?', _post, function(res) {
//回调
if(_callback != null){
_callback(res);
}
});
},
//收藏
fav : function(_post,_callback){
$.getJSON('//'+Mcpath.url+Mcpath.web+'index.php/api/rend/favadd?callback=?', _post, function(res) {
//回调
if(_callback != null){
_callback(res);
}else{
if(res.code == 1){
mccms.msg(res.msg,1);
}else{
mccms.msg(res.msg);
}
}
});
},
//登陆
login : function(_name,_pass,_callback){
$.getJSON('//'+Mcpath.url+Mcpath.web+'index.php/api/user/login?callback=?', {name:_name,pass:_pass}, function(res) {
//回调
if(_callback != null){
_callback(res);
}else{
if(res.code == 1){
window.location.reload();
}else{
if(res.pcode == 1){
window.location.href = '//'+Mcpath.url+Mcpath.web+'index.php/user/login';
}else{
mccms.msg(res.msg);
}
}
}
});
},
//退出登陆
logout : function(_callback){
//会员信息
$.getJSON('//'+Mcpath.url+Mcpath.web+'index.php/api/user/logout?callback=?', {t:Math.random()}, function(res) {
//回调
if(_callback != null){
_callback(res);
}else{
if(res.code == 1) window.location.reload();
}
});
},
//写入阅读记录
read : function(_post){
$.getJSON('//'+Mcpath.url+Mcpath.web+'index.php/api/rend/read?callback=?', _post);
},
//提示
msg : function(txt,tps){
if(tps == 1){
layer.open({content:txt,skin:'msg',time: 2});
}else{
layer.open({content:txt,btn:'我知道了'});
}
},
//返回顶部
gotop : function(_id){
var top =$(window).scrollTop();
getTopData();
$(window).scroll(function () {
top =$(window).scrollTop()
getTopData()
});
$(_id).click(function () {
$("html,body").animate({scrollTop:0},500);
});
function getTopData() {
if(top>400){
$(_id).stop().show(100);
}else{
$(_id).stop().hide(100);
}
}
},
//写入缓存
set_cookie : function(name,value,day){
var Days = (day == null || day == '') ? 30 : day;
var exp = new Date();
exp.setTime(exp.getTime() + Days*24*60*60*1000);
document.cookie = name + "="+ escape (value) + ";path=/;expires=" + exp.toGMTString();
},
//读取缓存
get_cookie : function(name){
var arr,reg=new RegExp("(^| )"+name+"=([^;]*)(;|$)");
if(arr=document.cookie.match(reg)){
return unescape(arr[2]);
}else{
return null;
}
},
//删除缓存
del_cookie : function(name){
mccms.set_cookie(name,'',-1);
},
//以万为单位格式化
get_wan: function(num){
if(num > 99999999){
num = num/100000000;
return num.toFixed(1)+"亿";
}else if(num > 999999){
num = num/10000;
return num.toFixed(1)+"万";
}else{
return num;
}
}
};
$(function(){
mccms.init();
})