Paste: ttttt
Author: | no |
Mode: | javascript |
Date: | Sun, 30 Jun 2013 18:24:55 |
Plain Text |
Share.prototype={
constructor:Share,init:function(){
if(this.user.is_login&&!this.user.no_un){
this.initDatas();
this.fillLikeForums()
}
this.bindEvents();
this.bindListeners();
this.picObj=new Pics(this.dataObj);
this.picObj.init();
this.initInputs()
}
,bindEvents:function(){
this.bindFnameEvent();
this.bindLikedForumsClickEvent();
this.bindTitleEvent();
this.bindContentEvent();
this.bindSummaryEvent();
this.bindSubmitEvent()
}
,bindListeners:function(){
this.on("FORUM_NOT_NULL",this.checkFname);
this.on("TITLE_NOT_NULL",this.checkTitle);
this.on("FORUM_NOT_EXIST",this.isFnameExist);
this.on("POST_DATA",this.postData)
}
,initDatas:function(){
var c=null;
var d=this.dataObj.like_forum||{};
for(var b=0,a=d.length;
b<a;
b++){
c=d[b];
this.likeForums[c.forum_name]=c
}
}
,initInputs:function(){
if($.trim(this.fname.val())!==""){
this.fnameTip.hide();
this.fireEvent("FORUM_NOT_EXIST")
}
if($.trim(this.content.val())!==""){
this.contentTip.hide()
}
}
,showForumname:function(d){
var e=10;
if($.tb.getByteLength(d)<=e){
return d
}
for(var b=Math.floor(e/2),a=$.tb.getByteLength(d);
b<a;
b++){
var c=d.substring(0,b);
if($.tb.getByteLength(c)>=e){
return c+"..."
}
}
return d
}
,fillLikeForums:function(){
var f=this.user.like_forum,j=$("#j_liked_forums"),k=new Array(),c=new Array(),h=0,d=0,b="";
for(var e=0,g=f.length;
e<g;
e++){
b=this.showForumname(f[e].forum_name);
h=b.getByteLength()*6+7*2+6;
d+=h;
if(d+46<440){
k.push('<a href="#" data-field="{fid:\''+f[e].forum_id+"',fname:'"+f[e].forum_name+"',canSendPic:"+f[e].can_send_pics+'}" class="liked_forums_item"><span>'+b+"</span></a>")
}
else{
if(d<1200){
c.push('<a href="#" data-field="{fid:\''+f[e].forum_id+"',fname:'"+f[e].forum_name+"',canSendPic:"+f[e].can_send_pics+'}" class="liked_forums_item"><span>'+b+"</span></a>")
}
}
}
j.html(k.join(""));
if(c.length>0){
var a=$('<span class="expand_forum">\u5c55\u5f00<img width="7" height="4" src="/tb/static-ucenter/img/expand.png"/></span>');
a.bind("click",function(){
a.remove();
j.append(c.join(""))
});
j.append(a)
}
}
,checkFname:function(){
var b=$.trim(this.fname.val()),a=this.errConfig.FORUM_NOT_NULL;
a.needCheck=false;
if(b===""){
this.fnameError.text(a.msg).show();
this.fname.focus();
return false
}
else{
this.fnameError.hide();
return true
}
}
,checkTitle:function(){
var b=$.trim(this.title.val()),a=this.errConfig.TITLE_NOT_NULL;
a.needCheck=false;
if(b===""){
this.titleTip.text(a.msg).show();
return false
}
else{
this.titleTip.hide();
return true
}
}
,isFnameExist:function(d){
var a=this,b=this.errConfig.FORUM_NOT_EXIST,c=$.trim(this.fname.val());
if(a.checkFname()){
$.tb.post("/f/commit/share/fnameShareApi",{
fname:c
}
,function(e){
if(e&&e.no===0){
a.fnameError.hide();
a.setForumObj(e.data.fid,c,e.data.can_send_pics);
a.canPost=true
}
else{
a.fnameError.text(b.msg).show();
a.canPost=false
}
if(d&&a.canPost){
a.fireEvent("POST_DATA")
}
})
}
}
,setForumObj:function(c,a,b){
if($("#j_pic_checkbox").attr("checked")){
this.picObj.canSendPics(b)
}
this.forumObj={
fid:c,fname:a
}
}
,checkInputs:function(){
var b=this,d=null,c=["FORUM_NOT_NULL","TITLE_NOT_NULL"];
for(var e=0,a=c.length;
e<a;
e++){
d=this.errConfig[c[e]];
if(d.needCheck){
if(!this.fireEvent(c[e])){
b.canPost=false;
break
}
}
}
d=this.errConfig.FORUM_NOT_EXIST;
if(d.needCheck){
b.fireEvent("FORUM_NOT_EXIST",true)
}
else{
b.postData()
}
}
,getSummary:function(){
var a=new Array(),d=this.dataObj;
a.push(d.summary);
var b=this.picObj.getPostHtml();
if(b.length>0){
a.push("<br/>");
a.push(b)
}
if(d.videos.video_r.length>0){
var f=d.videos.pkey||"",e=d.videos.video_r,c=d.videos.video_s||"";
a.push("<br/>");
a.push('<embed allowfullscreen="true" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" wmode="transparent" play="true" loop="false" menu="false" allowscriptaccess="never" scale="noborder" src="'+e+'" pkey="'+f+'" vsrc="'+c+'" class="BDE_Flash" width="500" height="450">')
}
return a.join("")
}
,bindFnameEvent:function(){
var a=this,b=null;
a.fname.bind("blur",function(){
a.fireEvent("FORUM_NOT_NULL");
b=a.errConfig.FORUM_NOT_NULL;
b.needCheck=false;
a.fireEvent("FORUM_NOT_EXIST");
b=a.errConfig.FORUM_NOT_EXIST
});
a.fnameTip.bind("click",function(){
a.fname.focus()
});
a.fname.bind("focus",function(){
a.fnameTip.hide()
})
}
,bindLikedForumsClickEvent:function(){
var a=this;
$("#j_liked_forums").delegate("a","click",function(){
var b=$.json.decode($(this).attr("data-field"));
a.setForumObj(b.fid,b.fname,b.canSendPic);
a.fname.val(b.fname);
a.fnameTip.hide();
a.fnameError.hide();
return false
})
}
,bindTitleEvent:function(){
var a=this;
a.title.bind("blur",function(){
a.fireEvent("TITLE_NOT_NULL")
});
a.title.bind("input",function(){
var b=this.value;
if(b.getByteLength()==60){
return false
}
if(b.getByteLength()>60){
this.value=b.subByte(60)
}
return true
});
a.title.bind("propertychange",function(){
var b=this.value;
if(b.getByteLength()==60){
return false
}
if(b.getByteLength()>60){
this.value=b.subByte(60)
}
return true
})
}
,bindContentEvent:function(){
var a=this;
a.contentTip.bind("click",function(){
a.content.focus()
});
a.content.bind("focus",function(){
a.contentTip.hide()
});
a.content.bind("input",function(){
var b=this.value;
if(b.getByteLength()==4000){
return false
}
if(b.getByteLength()>4000){
this.value=b.subByte(4000)
}
return true
});
a.content.bind("propertychange",function(){
var b=this.value;
if(b.getByteLength()==4000){
return false
}
if(b.getByteLength()>4000){
this.value=b.subByte(4000)
}
return true
})
}
,bindSummaryEvent:function(){
$("#j_summary").find(".j_bottom_arrow").bind("click",function(){
var a=$.tb.subByte(self.dataObj.summary,280);
$("#j_summary_text").text(a);
$(this).hide();
return false
})
}
,bindSubmitEvent:function(){
var b=this,a=$("#j_submit");
a.hover(function(){
$(this).addClass("btn_submit_hover")
}
,function(){
$(this).removeClass("btn_submit_hover btn_submit_active")
});
a.bind("click",function(){
$(this).addClass("btn_submit_active");
if(PageData.validUrl!==0){
ErrorDialog.showErr(9010);
return
}
if(b.user.is_login){
if(b.user.no_un){
TbCom.process("User","buildUnameFrame");
return
}
}
else{
_.Module.use("common/component/LoginDialog",["","userBar"]);
return
}
b.checkInputs()
})
}
,postData:function(){
var a=this;
url="/f/commit/share/commitShareApi";
if(!a.canPost){
return
}
var b={
fid:a.forumObj.fid||"",fname:a.forumObj.fname||"",ie:"utf-8",title:a.title.val(),content:a.content.val(),summary:a.getSummary(),refer_url:'\u8f6c\u81ea\uff1a<a href="'+a.dataObj.refer_url+'" target="_blank">'+a.dataObj.refer_url+"</a>",vcode:a.vcodeObj.vcode||"",vcode_md5:a.vcodeObj.vcode_md5||"",tbs:PageData.tbs,new_vcode:1,tag:11
};
$.tb.post(url,b,function(c){
a.vcodeObj.vcode="";
a.vcodeObj.vcode_md5="";
if(c){
if(c.no==0){
ErrorDialog.showSuccess(b.fname)
}
else{
if(c.no==4010){
ErrorDialog.showBindPhone(c.no,b.fid,a.user.is_login)
}
else{
if(c.no==40){
if(a.captchaDialog){
a.captchaDialog.setTip(c.data.vcode.str_reason);
a.captchaDialog.updateCaptchaImg(c.data.vcode.captcha_vcode_str,c.data.vcode.captcha_code_type);
a.captchaDialog.show();
a.captchaDialog.focus()
}
else{
_.Module.use("common/component/CaptchaDialog",{
message:c.data.vcode.str_reason,vCode:c.data.vcode.captcha_vcode_str,vCodeType:c.data.vcode.captcha_code_type,forumName:a.forumObj.fname,forumId:a.forumObj.fid,isAnonymous:0,postType:"thread",paramsCallback:function(){
var d={
content:a.content.val(),title:a.title.val()
};
return d
}
}
,function(d){
a.captchaDialog=d;
d.bind("onclose",function(){
submitBtn=$("#j_submit");
submitBtn.removeClass("btn_submit_hover btn_submit_active");
d.hide();
return false
});
d.bind("onaccept",function(){
a.vcodeObj.vcode=d.getInputValue();
a.vcodeObj.vcode_md5=d.getVCode();
a.postData()
});
d.show()
})
}
}
else{
ErrorDialog.showErr(c.no,b.fid,a.user.is_login)
}
}
}
}
else{
ErrorDialog.showErr(-2)
}
})
}
,on:function(a,b){
this.eventObj[a]=b
}
,fireEvent:function(a){
if(typeof this.eventObj[a]==="function"){
return this.eventObj[a].apply(this,Array.prototype.slice.call(arguments,1))
}
}
};
New Annotation