{Util.error(‘Unknown button: ‘+buttons[i]);}
buttons[i]=button;}}
this._buttons=buttons;this._dirty();return this;},setButtonsMessage:Dialog._basicMutator(‘_buttons_message’),setStackable:Dialog._basicMutator(‘_is_stackable’),setHandler:function(handler){this._handler=handler;return this;},setPostURI:function(post_uri){this.setHandler(this._postForm.bind(this,post_uri));return this;},setModal:function(modal){if(modal===undefined){modal=true;}
if(this._showing&&this._modal&&!modal){Util.error(“At the moment we don’t support un-modal-ing a modal dialog”);}
this._modal=modal;return this;},setContentWidth:function(width){this._content_width=width;this._dirty();return this;},setCloseHandler:function(close_handler){this._close_handler=call_or_eval.bind(null,null,close_handler);return this;},setAsync:function(async_request){var handler=function(response){if(this._async_request!=async_request){return;}
this._async_request=null;var payload=response.getPayload();if(typeof(payload)==’string’){this.setBody(payload);}else if(payload.body||payload.title){for(var propertyName in payload){var mutator=this[‘set’+propertyName.substr(0,1).toUpperCase()
+propertyName.substr(1)];if(!mutator){Util.error(“Unknown Dialog property: “+propertyName);}
mutator.call(this,payload[propertyName]);}}else{this.hide();if(payload.closeHandler){call_or_eval(null,payload.closeHandler);}}}.bind(this);var hide=bind(this,’hide’);async_request.setHandler(chain(async_request.getHandler(),handler)).setErrorHandler(chain(hide,async_request.getErrorHandler())).setTransportErrorHandler(chain(hide,async_request.getTransportErrorHandler())).send();this._async_request=async_request;return this;},_dirty:function(){if(!this._is_dirty){this._is_dirty=true;bind(this,’_update’).defer();}},_update:function(){this._is_dirty=false;if(!this._showing){return;}
if(this._autohide&&!this._async_request&&!this._autohide_timeout){this._autohide_timeout=setTimeout(bind(this,’hide’),this._autohide);}
if(this._body){var html=[];if(this._title){html.push(‘
‘+this._title+’
‘);}
html.push(”);if(this._summary){html.push(”);html.push(this._summary);html.push(”);}
html.push(”);html.push(this._body);html.push(”);if(this._buttons||this._buttons_message){html.push(”);if(this._buttons_message){html.push(”);html.push(this._buttons_message);html.push(”);}
if(this._buttons){this._buttons.forEach(function(button){html.push(‘‘);},this);}
html.push(”);}
html.push(”);this._pd.show_dialog(html.join(”));}else{var title=this._title||tx(‘sh:loading’);this._pd.show_loading_title(title);}
if(this._modal){this._pd.make_modal();}
if(this._content_width){this._pd.popup.childNodes[0].style.width=(this._content_width+42)+’px’;}
this._pd.is_stackable=this._is_stackable;this._pd.close_handler=this._close_handler;},handleButton:function(button){if(typeof(button)==’string’){button=Dialog._findButton(this._buttons,button);}
if(!button){Util.error(‘Huh? How did this button get here?’);return;}
if(call_or_eval(button,button.handler)===false){return;}
if(button!=Dialog.CANCEL){if(call_or_eval(this,this._handler,{button:button})===false){return;}}
this.hide();},_postForm:function(post_uri,button){var data=this._getFormData();data[button.name]=button.label;var async_request=new AsyncRequest().setURI(post_uri).setData(data);var followup_dialog=new Dialog(this._className).setModal(this._modal).setTitle(this._title).setAsync(async_request);bind(followup_dialog,’show’).defer();},_getFormData:function(){var dialog_content_divs=DOM.scry(this._pd.content,’div.dialog_content’);if(dialog_content_divs.length!=1){Util.error(dialog_content_divs.length
+” dialog_content divs in this dialog? Weird.”);}
return serialize_form(dialog_content_divs[0]);}});Dialog._findButton=function(buttons,name){for(var i=0;i
var channelMsg=response.getPayload();if(channelMsg.t==’refresh’){this.warn(‘iframex: got refresh from channel’);this._onRequestError(ChannelRebuildReasons.Refresh);return;}else if(channelMsg.t==’refreshDelay’){this.warn(‘iframex: got refreshDelay from channel’);this._onRequestError(ChannelRebuildReasons.RefreshDelay);return;}else if(channelMsg.t==’continue’){}else if(channelMsg.t==’msg’){var channel=channelMsg.c;for(var i=0;i
try{this._load(presenceState);}catch(e){this.error(‘presence: got load exception: ‘+e.toString());this._load(this._getCookieData());}},_load:function(presenceState){this.syncPaused++;this.stateUpdateTime=verifyNumber(presenceState.ut);this.popoutTime=verifyNumber(presenceState.pt);this.popoutWidth=verifyNumber(presenceState.w);this.popoutHeight=verifyNumber(presenceState.h);if(!this.popoutWidth){this.popoutWidth=this.defWidth;}
if(!this.popoutWidth){this.popoutWidth=this.defHeight;}
this.popoutWidth=Math.max(this.popoutWidth,this.minWidth);this.popoutHeight=Math.max(this.popoutHeight,this.minHeight);this.poppedOut=verifyBool(presenceState.p);if(this.poppedOut){if(this.inPopoutWindow){if(!this.heartbeat){this.heartbeat=setInterval(this._popoutHeartbeat.bind(this),this.popoutHeartbeatTime);}}else{this.setHolderClass(‘popped_out’);}}else{if(this.inPopoutWindow){if(!this.loaded){this.poppedOut=true;setTimeout(this.doSync.bind(this),1);}else{if(!this.popinClicked){window.close();}else{}}}else{this.justPoppedOut=true;}}
if(!this.inPopoutWindow&&!this.cookiePoller){this.cookiePoller=setInterval(this._pollCookie.bind(this),this.cookiePollTime);}
this.virtPopoutWidth=this.popoutWidth;this.virtPopoutHeight=this.popoutHeight;this.state=presenceState;for(var i=0;i
if(this.poppedOut&&!this.inPopoutWindow){var cookiePopoutTime=verifyNumber(presenceState.pt);var diff=(new Date()).getTime()-cookiePopoutTime;var diffAllowance=this.popoutHeartbeatTime+this.popoutHeartbeatAllowance;if(this.justPoppedOut){if(cookiePopoutTime==myPopoutTime){diffAllowance+=this.popoutHeartbeatFirstAllowance;}else{this.justPoppedOut=false;}}
this.popoutTime=cookiePopoutTime;if(diff>diffAllowance){this.poppedOut=false;this.doSync();}}},_popoutHeartbeat:function(){this._pollCookie();if(this.poppedOut){presenceCookieManager.store();}},_getCookieData:function(){var presenceState={p:this.poppedOut?1:0,w:this.popoutWidth,h:this.popoutHeight,ut:this.stateUpdateTime,pt:this.inPopoutWindow?(new Date()).getTime():this.popoutTime};for(var i=0;i
this.stateUpdateTime=(new Date()).getTime();presenceCookieManager.store();this._load(this.state);},pauseSync:function(){this.syncPaused++;},resumeSync:function(){this.syncPaused–;this.doSync();},handleMsg:function(channel,obj){if(typeof obj==’string’){if(obj==’shutdown’){this.connectionShutdown();}else if(obj==’restart’){if(this.isShutdown){this.restart();}}
return;}
if(this.isShutdown){return false;}
var handled=false;for(var i=0;i
add_css_class_name(this.holder,className);},_loadHolderClass:function(){if(!this.poppedOut&&!this.inPopoutWindow&&this.holder.className!=”){this.setHolderClass(statusControl.visibility||chatDisplay.numTabs>0?’full’:”);}},renderLoginLink:function(){return this.renderLink(this.loginURL,’log in’);},getErrorDescription:function(asyncResponse){var error=asyncResponse.getError();var desc=asyncResponse.getErrorDescription();if(!desc){desc=tx(‘pr01’);}
if(error==kError_Async_NotLoggedIn){desc=tx(‘pr02’,{‘login’:this.renderLoginLink()});}
return desc;},showAsyncError:function(asyncResponse,title){if(typeof title==’undefined’||!title){var chat=tx(‘chd01’);title=tx(‘pr03’);}
var desc=this.getErrorDescription(asyncResponse);new ErrorDialog().showError(title,desc);},showTransportError:function(asyncResponse,title){if(typeof title==’undefined’||!title){var chat=tx(‘chd01’);title=tx(‘pr03’);}
var desc=tx(‘pr04’,{‘Chat’:tx(‘chd01’)});new ErrorDialog().showError(title,desc);this.warn(“presence: got async transport error: “+asyncResponse.getErrorDescription());},checkLoginError:function(asyncResponse){var error=asyncResponse.getError();if(error==kError_Async_NotLoggedIn||error==kError_Async_LoginChanged||error==kError_Login_GenericError){this.loginShutdown();return true;}
return false;},checkMaintenanceError:function(asyncResponse){if(asyncResponse.getError()==1356007){this.maintenanceShutdown();return true;}
return false;},loginShutdown:function(){var reason=tx(‘pr02’,{‘login’:this.renderLoginLink()});this.shutdown(false,reason,true);},connectionShutdown:function(shouldDelay){var reason=tx(‘pr04’,{‘Chat’:tx(‘chd01’)});this.shutdown(shouldDelay,reason);},maintenanceShutdown:function(){var reason=tx(‘pr10’,{‘Chat’:tx(‘chd01’)});this.shutdown(false,reason);channelManager.stop();},versionShutdown:function(){var reason=tx(‘pr08’,{‘Chat’:tx(‘chd01’)});this.shutdown(false,reason);channelManager.stop();},shutdown:function(shouldDelay,reason,isAlert){this.isRestarting=false;this.isShuttingDown=true;var now=(new Date()).getTime();this.shutdownTime=now;if(!shouldDelay){this._shutdown(reason,isAlert,0);}else{setTimeout(this._shutdown.bind(this,reason,isAlert,now),this.shutdownDelay);}},_shutdown:function(reason,isAlert,shutdownTime){if(!this.isShuttingDown&&shutdownTime==this.shutdownTime){return;}
if(shutdownTime&&this.isShutdown){return;}
if(typeof reason!=’string’||!reason){reason=tx(‘pr05’,{‘Chat’:tx(‘chd01′)});}
if(!this.inPopoutWindow){CSS.addClass(this.holder,’error’);if(isAlert){CSS.addClass(this.errorBar,’alert’);set_inner_html($(‘presence_error_alert_reason’),reason);}else{CSS.removeClass(this.errorBar,’alert’);set_inner_html($(‘presence_error_reason’),reason);}}else{if(this.shutdownErrorDialog){this.shutdownErrorDialog.hide();}
this.shutdownErrorDialog=new ErrorDialog().show_prompt(tx(‘pr03’),”+
reason+”);}
if(this.isShutdown){return;}
this.warn(“presence: shutting down”);this.isShutdown=true;if(this.isDark){this._darkStop();}
for(var i=0;i
presenceCookieManager.register(‘ch’,this._getCookieInfo.bind(this));if(ua.firefox()){onbeforeunloadRegister(this._onUnload.bind(this));}else{onunloadRegister(this._onUnload.bind(this));}},sendiFrameMessage:function(msg){if(!this.postMessage){return;}
var msgStr=JSON.encode(msg);try{this.postMessage(msgStr);}catch(e){presence.error(‘channel: error sending message “‘+msgStr+'” to iframe: ‘+e.toString());}},handleiFrameMessage:function(iframeMsg){if(iframeMsg.type==’init’){this.iframeLoaded();}else if(iframeMsg.type==’channelMsg’){this.handleChannelMsg(iframeMsg.channel,iframeMsg.seq,iframeMsg.msg);}},_onUnload:function(){this.shouldClearSubdomain=true;presence.doSync();},addChannel:function(channel,seq,msgHandler,startHandler,shutdownHandler,restartHandler){this.channels[channel]={‘currentSeq’:seq,’nextSeq’:0,’msgHandler’:msgHandler,’startHandler’:startHandler,’shutdownHandler’:shutdownHandler,’restartHandler’:restartHandler};},isLowestSubdomain:function(){var channelData=presenceCookieManager.getSubCookie(‘ch’);if(!channelData||!channelData.sub){return true;}
for(var i=0;i
