-
Notifications
You must be signed in to change notification settings - Fork 6
/
jsxc.min.js
2 lines (2 loc) · 223 KB
/
jsxc.min.js
1
2
var jsxc=null,RTC=null,RTCPeerconnection=null;!function($){"use strict";(jsxc={version:"3.4.1",master:!1,role_allocation:!1,to:[],toBusy:null,toNotification:null,toNotificationDelay:500,keepaliveInterval:null,restoreCompleted:!1,triggeredFromBox:!1,triggeredFromElement:!1,triggeredFromLogout:!1,ls:[],storageNotConform:null,toSNC:null,bid:null,currentState:null,currentUIState:null,CONST:{NOTIFICATION_DEFAULT:"default",NOTIFICATION_GRANTED:"granted",NOTIFICATION_DENIED:"denied",STATUS:["offline","dnd","xa","away","chat","online"],SOUNDS:{MSG:"incomingMessage.wav",CALL:"Rotary-Phone6.mp3",NOTICE:"Ping1.mp3"},REGEX:{JID:new RegExp("\\b[^\"&'\\/:<>@\\s]+@[\\w-_.]+\\b","ig"),URL:new RegExp(/(https?:\/\/|www\.)[^\s<>'"]+/gi),GEOURI:new RegExp(/geo:(-?\d+(?:\.\d+)?),(-?\d+(?:\.\d+)?)(?:,-?\d+(?:\.\d+)?)?(?:;crs=[\w-]+)?(?:;u=(\d+(?:\.\d+)?))?(?:;[\w-]+=(?:[\w-_.!~*'()]|%[\da-f][\da-f])+)*/)},NS:{CARBONS:"urn:xmpp:carbons:2",FORWARD:"urn:xmpp:forward:0",HINTS:"urn:xmpp:hints"},HIDDEN:"hidden",SHOWN:"shown",STATE:{INITIATING:0,PREVCONFOUND:1,SUSPEND:2,TRYTOINTERCEPT:3,INTERCEPTED:4,ESTABLISHING:5,READY:6},UISTATE:{INITIATING:0,READY:1}},getFormattedTime:function(unixtime){var msgDate=new Date(parseInt(unixtime)),day=("0"+msgDate.getDate()).slice(-2),month=("0"+(msgDate.getMonth()+1)).slice(-2),year=msgDate.getFullYear(),hours=("0"+msgDate.getHours()).slice(-2),minutes=("0"+msgDate.getMinutes()).slice(-2),dateNow=new Date,date="function"==typeof msgDate.toLocaleDateString?msgDate.toLocaleDateString():day+"."+month+"."+year,time="function"==typeof msgDate.toLocaleTimeString?msgDate.toLocaleTimeString():hours+":"+minutes;return dateNow.setHours(0,0,0,0),msgDate.setHours(0,0,0,0),dateNow.getTime()!==msgDate.getTime()?date+" "+time:time},debug:function(msg,data,level){if(level&&(msg="["+level+"] "+msg),data){var d;!0===jsxc.storage.getItem("debug")&&console.log(msg,data);try{d=$("<span>").prepend($(data).clone()).html()}catch(err){try{d=JSON.stringify(data)}catch(err2){d="see js console"}}jsxc.log=jsxc.log+"$ "+msg+": "+d+"\n"}else console.log(msg),jsxc.log=jsxc.log+"$ "+msg+"\n"},warn:function(msg,data){jsxc.debug(msg,data,"WARN")},error:function(msg,data){jsxc.debug(msg,data,"ERROR")},log:"",init:function(options){if(jsxc.runMigrations(),jsxc.changeState(jsxc.CONST.STATE.INITIATING),options&&options.loginForm&&"boolean"==typeof options.loginForm.attachIfFound&&!options.loginForm.ifFound&&(options.loginForm.ifFound=options.loginForm.attachIfFound?"attach":"pause"),options&&$.extend(!0,jsxc.options,options),jsxc.storage.hasSupport()){var lang;jsxc.options.get=function(key){if(jsxc.bid){var local=jsxc.storage.getUserItem("options")||{};return void 0!==local[key]?local[key]:jsxc.options[key]}return jsxc.options[key]},jsxc.options.set=function(key,value){jsxc.storage.updateItem("options",key,value,!0)},jsxc.storageNotConform=jsxc.storage.getItem("storageNotConform"),null===jsxc.storageNotConform&&(jsxc.storageNotConform=2),lang=null!==jsxc.storage.getItem("lang")?jsxc.storage.getItem("lang"):jsxc.options.autoLang&&navigator.languages&&0<navigator.languages.length?navigator.languages[0]:jsxc.options.autoLang&&navigator.language?navigator.language:jsxc.options.defaultLang;var availableLanguages=Object.keys(window.jsxcLanguageResources);if(availableLanguages.indexOf(lang)<0){var languagePrefix=lang.slice(0,2);if(-1<availableLanguages.indexOf(languagePrefix))lang=languagePrefix;else{var prefixMatch=availableLanguages.filter(function(l){return l.slice(0,2)===languagePrefix});0<prefixMatch.length&&(lang=prefixMatch[0])}}window.i18next.init({lng:lang,fallbackLng:"en",resources:window.jsxcLanguageResources,returnNull:!1,debug:!0===jsxc.storage.getItem("debug"),interpolation:{prefix:"__",suffix:"__"}},function(){window.jqueryI18next.init(window.i18next,$,{tName:"t",i18nName:"i18next",handleName:"localize"})}),!0===jsxc.storage.getItem("debug")&&(jsxc.options.otr.debug=!0),window.addEventListener("storage",jsxc.storage.onStorage,!1),$(document).on("attached.jsxc",jsxc.registerLogout),$(document).on("disconnected.jsxc",jsxc.relogin);var isStorageAttachParameters=jsxc.storage.getItem("rid")&&jsxc.storage.getItem("sid")&&jsxc.storage.getItem("jid"),isOptionsAttachParameters=jsxc.options.xmpp.rid&&jsxc.options.xmpp.sid&&jsxc.options.xmpp.jid,isForceLoginForm=jsxc.options.loginForm&&"force"===jsxc.options.loginForm.ifFound&&jsxc.isLoginForm();if(!isStorageAttachParameters&&!isOptionsAttachParameters||isForceLoginForm){if(jsxc.relogin())return;jsxc.prepareNewConnection()}else(!jsxc.isLoginForm()||jsxc.options.loginForm&&"attach"===jsxc.options.loginForm.ifFound)&&(jsxc.changeState(jsxc.CONST.STATE.PREVCONFOUND),void 0===jsxc.storage.getItem("alive")?jsxc.onMaster():jsxc.checkMaster())}else jsxc.error("Browser doesn't support localStorage. JSXC will be disabled.")},runMigrations:function(){var lastUsedVersion=jsxc.storage.getItem("version");if(!lastUsedVersion){var keys=Object.keys(localStorage).filter(function(key){var isKeepMatch=key.match(/^jsxc:[^:]+:(key|history|msg|priv_fingerprint):?/);return key.match(/^jsxc:/)&&!isKeepMatch||key.match(/^strophe\.caps\./)});keys.forEach(function(key){localStorage.removeItem(key)}),jsxc.debug("I turned out your storage and deleted "+keys.length+" entries.")}lastUsedVersion!==jsxc.version&&jsxc.storage.setItem("version",jsxc.version)},prepareNewConnection:function(){if(jsxc.storage.removeItem("rid"),jsxc.storage.removeItem("sid"),!jsxc.isLoginForm())return jsxc.changeState(jsxc.CONST.STATE.SUSPEND),void(jsxc.options.displayRosterMinimized()&&(jsxc.storage.setUserItem("roster","hidden"),jsxc.gui.roster.init(),jsxc.gui.roster.noConnection()));jsxc.changeState(jsxc.CONST.STATE.TRYTOINTERCEPT),"function"==typeof jsxc.options.formFound&&jsxc.options.formFound.call();var form=jsxc.options.loginForm.form=$(jsxc.options.loginForm.form),events=form.data("events")||{submit:[]},submits=[];$.each(events.submit,function(index,val){submits.push(val.handler)}),form.data("submits",submits),form.off("submit"),form.submit(function(ev){return ev.preventDefault(),jsxc.prepareLogin(function(settings){if(!1!==settings){var enabled=settings.loginForm&&settings.loginForm.enable||settings.xmpp&&settings.xmpp.onlogin;if(enabled="true"===enabled||!0===enabled)return jsxc.options.loginForm.triggered=!0,void jsxc.xmpp.login(jsxc.options.xmpp.jid,jsxc.options.xmpp.password)}jsxc.submitLoginForm()}),!1}),jsxc.changeState(jsxc.CONST.STATE.INTERCEPTED)},start:function(){var args=arguments;return jsxc.role_allocation&&!jsxc.master?(jsxc.debug("There is an other master tab"),!1):jsxc.xmpp.conn&&jsxc.xmpp.conn.authenticated?(jsxc.debug("We are already connected and authenticated"),!1):jsxc.currentState!==jsxc.CONST.STATE.INTERCEPTED&&jsxc.currentState!==jsxc.CONST.STATE.SUSPEND?(jsxc.busy||jsxc.debug("I am currently busy and will try again later. Please be patient."),jsxc.busy=!0,void setTimeout(function(){jsxc.start.apply(jsxc,args)},400)):(jsxc.busy=!1,3===args.length&&$(document).one("attached.jsxc",function(){jsxc.xmpp.onRidChange(jsxc.xmpp.conn._proto.rid),jsxc.onMaster()}),void jsxc.checkMaster(function(){jsxc.xmpp.login.apply(this,args)}))},relogin:function(){jsxc.debug("Try to relogin");var jid=jsxc.storage.getItem("jid");if(jsxc.bid=jsxc.bid||(jid?jsxc.jidToBid(jid):null),!jsxc.bid||jsxc.storage.getUserItem("forcedLogout"))return jsxc.debug("Logout was forced or I found no valid jid"),!1;var xmppOptions=jsxc.options.get("xmpp");if(xmppOptions.url&&(xmppOptions.jid||xmppOptions.username&&xmppOptions.domain)&&xmppOptions.password)return xmppOptions.jid=xmppOptions.jid||xmppOptions.username+"@"+xmppOptions.domain,jsxc.start(xmppOptions.jid,xmppOptions.password),!0;var loadSettingsAllKnowing=jsxc.storage.getUserItem("loadSettingsAllKnowing");return xmppOptions.url&&loadSettingsAllKnowing?(jsxc.options.loadSettings(null,null,function(settings){jsxc._prepareLogin(null,null,function(settings){function reloginFailed(){jsxc.debug("Could not relogin."),removeReloginHandler(),jsxc.storage.removeUserItem("loadSettingsAllKnowing"),jsxc.prepareNewConnection()}function removeReloginHandler(){$(document).off("connfail.jsxc",reloginFailed),$(document).off("authfail.jsxc",reloginFailed),$(document).off("connected.jsxc",removeReloginHandler)}!1!==settings&&jsxc.options.xmpp.jid&&jsxc.options.xmpp.password?($(document).on("connfail.jsxc",reloginFailed),$(document).on("authfail.jsxc",reloginFailed),$(document).on("connected.jsxc",removeReloginHandler),jsxc.start(jsxc.options.xmpp.jid,jsxc.options.xmpp.password),delete jsxc.options.xmpp.password):reloginFailed()},settings)}),!0):(jsxc.debug("I am not able to relogin"),!1)},registerLogout:function(){if(null!==jsxc.options.logoutElement&&0<$(jsxc.options.logoutElement).length){var logout=function(ev){ev.stopPropagation(),ev.preventDefault(),jsxc.options.logoutElement=$(this),jsxc.triggeredFromLogout=!0,jsxc.xmpp.logout()};jsxc.options.logoutElement=$(jsxc.options.logoutElement),jsxc.options.logoutElement.off("click",null,logout).one("click",logout)}},isLoginForm:function(){return jsxc.options.loginForm.form&&jsxc.el_exists(jsxc.options.loginForm.form)&&jsxc.el_exists(jsxc.options.loginForm.jid)&&jsxc.el_exists(jsxc.options.loginForm.pass)},prepareLogin:function(username,password,cb){var settings;"function"==typeof username&&(cb=username,username=null),username=username||$(jsxc.options.loginForm.jid).val(),password=password||$(jsxc.options.loginForm.pass).val(),jsxc.triggeredFromBox||"dialog"!==jsxc.options.loginForm.onConnecting&&void 0!==jsxc.options.loginForm.onConnecting||jsxc.gui.showWaitAlert($.t("Logging_in")),"function"==typeof jsxc.options.loadSettings?void 0!==(settings=jsxc.options.loadSettings.call(this,username,password,function(s){jsxc._prepareLogin(username,password,cb,s)}))&&jsxc._prepareLogin(username,password,cb,settings):jsxc._prepareLogin(username,password,cb)},_prepareLogin:function(username,password,cb,loadedSettings){if(!1===loadedSettings)return jsxc.warn("No settings provided"),void cb(!1);var settings=$.extend(!0,{},jsxc.options);loadedSettings?settings=$.extend(!0,settings,loadedSettings):loadedSettings={},"string"==typeof settings.xmpp.username&&(username=settings.xmpp.username),"string"==typeof settings.xmpp.password&&(password=settings.xmpp.password,delete settings.xmpp.password);var jid,resource=settings.xmpp.resource?"/"+settings.xmpp.resource:"",domain=settings.xmpp.domain;jid=username.match(/@(.*)$/)?username.match(/\/(.*)$/)?username:username+resource:username+"@"+domain+resource,"function"==typeof jsxc.options.loginForm.preJid&&(jid=jsxc.options.loginForm.preJid(jid)),jsxc.bid=jsxc.jidToBid(jid),settings.xmpp.username=jid.split("@")[0],settings.xmpp.domain=jid.split("@")[1].split("/")[0],settings.xmpp.resource=jid.split("@")[1].split("/")[1]||"",loadedSettings.xmpp||(loadedSettings.xmpp={}),jsxc.storage.setUserItem("loadSettingsAllKnowing",!!((loadedSettings.xmpp.jid||loadedSettings.xmpp.username&&loadedSettings.xmpp.domain)&&loadedSettings.xmpp.password)),$.each(loadedSettings,function(key){var old=jsxc.options.get(key),val=settings[key];val=$.extend(!0,old,val),jsxc.options.set(key,val)}),jsxc.options.xmpp.jid=jid,jsxc.options.xmpp.password=password,cb(settings)},onSlave:function(){jsxc.debug("I am the slave."),jsxc.role_allocation=!0,jsxc.bid=jsxc.jidToBid(jsxc.storage.getItem("jid")),jsxc.gui.init(),$("#jsxc_roster").removeClass("jsxc_noConnection"),jsxc.registerLogout(),jsxc.gui.avatar.update($("#jsxc_roster > .jsxc_bottom"),jsxc.jidToBid(jsxc.storage.getItem("jid")),"own"),jsxc.gui.restore()},onMaster:function(){jsxc.debug("I am master."),jsxc.master=!0,jsxc.storage.setItem("alive",0),jsxc.storage.setItem("alive_busy",0),jsxc.startKeepAlive(),jsxc.role_allocation=!0,jsxc.xmpp.login()},checkMaster:function(cb){jsxc.debug("check master"),cb=cb&&"function"==typeof cb?cb:jsxc.onMaster,void 0===jsxc.storage.getItem("alive")?cb.call():(jsxc.to.push(window.setTimeout(cb,1e3)),jsxc.keepAlive("slave"))},masterActions:function(){if(jsxc.xmpp.conn&&jsxc.xmpp.conn.authenticated){var noti=jsxc.storage.getUserItem("notification");noti="number"==typeof noti?noti:2,jsxc.options.notification&&0<noti&&jsxc.notification.hasSupport()?jsxc.notification.hasPermission()?jsxc.notification.init():jsxc.notification.prepareRequest():jsxc.options.notification=!1,jsxc.options.get("otr").enable&&jsxc.otr.createDSA(),jsxc.gui.avatar.update($("#jsxc_roster > .jsxc_bottom"),jsxc.jidToBid(jsxc.storage.getItem("jid")),"own")}},startKeepAlive:function(){jsxc.keepaliveInterval=window.setInterval(jsxc.keepAlive,jsxc.options.timeout-1e3)},keepAlive:function(role){var next=parseInt(jsxc.storage.getItem("alive"))+1;role=role||"master",jsxc.storage.setItem("alive",next+":"+role)},keepBusyAlive:function(){jsxc.toBusy&&window.clearTimeout(jsxc.toBusy),jsxc.keepaliveInterval&&window.clearInterval(jsxc.keepaliveInterval),jsxc.storage.ink("alive_busy"),jsxc.toBusy=window.setTimeout(jsxc.startKeepAlive,jsxc.options.busyTimeout-1e3)},random:function(max){return Math.floor(Math.random()*max)},el_exists:function(selector){return 0<$(selector).length},jidToCid:function(jid){return jsxc.warn("jsxc.jidToCid is deprecated!"),Strophe.getBareJidFromJid(jid).replace("@","-").replace(/\./g,"-").toLowerCase()},jidToBid:function(jid){return Strophe.unescapeNode(Strophe.getBareJidFromJid(jid).toLowerCase())},restoreRoster:function(){var buddies=jsxc.storage.getUserItem("buddylist");if(!buddies||0===buddies.length)return jsxc.debug("No saved buddylist."),void jsxc.gui.roster.empty();$.each(buddies,function(index,value){jsxc.gui.roster.add(value)}),jsxc.gui.roster.loaded=!0,$(document).trigger("cloaded.roster.jsxc")},restoreWindows:function(){var windows=jsxc.storage.getUserItem("windowlist");null!==windows&&$.each(windows,function(index,bid){var win=jsxc.storage.getUserItem("window",bid);if(!win)return jsxc.debug("Associated window-element is missing: "+bid),!0;jsxc.gui.window.init(bid),win.minimize?jsxc.gui.window.hide(bid):jsxc.gui.window.show(bid),jsxc.gui.window.setText(bid,win.text)})},submitLoginForm:function(){var form=$(jsxc.options.loginForm.form).off("submit"),submits=form.data("submits")||[];$.each(submits,function(index,val){form.submit(val)}),0<form.find("#submit").length?form.find("#submit").click():form.get(0)&&"function"==typeof form.get(0).submit?form.submit():0<form.find('[type="submit"]').length?form.find('[type="submit"]').click():jsxc.warn("Could not submit login form.")},escapeHTML:function(text){return(text=text.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">")).replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">")},removeHTML:function(text){return $("<span>").html(text).text()},switchEvents:function(obj){var ns=Math.random().toString(36).substr(2,12),self=this;return $.each(obj,function(key,val){$(document).one(key+"."+ns,function(){$(document).off("."+ns),val.apply(self,arguments)})}),ns},isHidden:function(){var hidden=!1;return void 0!==document.hidden?hidden=document.hidden:void 0!==document.webkitHidden?hidden=document.webkitHidden:void 0!==document.mozHidden?hidden=document.mozHidden:void 0!==document.msHidden&&(hidden=document.msHidden),hidden&&jsxc.master?jsxc.storage.ink("hidden",0):hidden||jsxc.master||jsxc.storage.ink("hidden"),hidden},hasFocus:function(){var focus=!0;return"function"==typeof document.hasFocus&&(focus=document.hasFocus()),!focus&&jsxc.master?jsxc.storage.ink("focus",0):focus&&!jsxc.master&&jsxc.storage.ink("focus"),focus},exec:function(fnName,fnParams){var i,fnList=fnName.split("."),fn=jsxc[fnList[0]];for(i=1;i<fnList.length;i++)fn=fn[fnList[i]];if("function"==typeof fn)return fn.apply(null,fnParams)},hashStr:function(str){var i,hash=0;if(0===str.length)return hash;for(i=0;i<str.length;i++)hash=(hash<<5)-hash+str.charCodeAt(i),hash|=0;return hash},isExtraSmallDevice:function(){return $(window).width()<500},changeState:function(state){jsxc.currentState=state,jsxc.debug("State changed to "+Object.keys(jsxc.CONST.STATE)[state]),$(document).trigger("stateChange.jsxc",state)},changeUIState:function(state){jsxc.currentUIState=state,jsxc.debug("UI State changed to "+Object.keys(jsxc.CONST.UISTATE)[state]),$(document).trigger("stateUIChange.jsxc",state)},getLastMsg:function(bid){for(var history=jsxc.storage.getUserItem("history",bid)||[],i=0;history.length>i;){var message=new jsxc.Message(history[i]);if(message.direction!==jsxc.Message.SYS)return{text:message.msg,date:message.stamp};i++}},enableDebugMode:function(){jsxc.storage.setItem("debug",!0)},disableDebugMode:function(){jsxc.storage.setItem("debug",!1)},deleteAllData:function(){if(!jsxc.storage.getItem("debug"))return jsxc.warn("This action is only available in debug mode."),0;var prefix=jsxc.storage.PREFIX+jsxc.storage.SEP,prefixRegex=new RegExp("^"+prefix),keys=Object.keys(localStorage),count=0;return $.each(keys,function(index,key){prefixRegex.test(key)&&key!==prefix+"debug"&&(localStorage.removeItem(key),count++)}),count}}).xmpp={conn:null,login:function(){if(jsxc.xmpp.conn&&jsxc.xmpp.conn.authenticated)jsxc.debug("Connection already authenticated.");else{var jid=null,password=null,sid=null,rid=null;switch(arguments.length){case 2:jid=arguments[0],password=arguments[1];break;case 3:jid=arguments[0],sid=arguments[1],rid=arguments[2];break;default:sid=jsxc.storage.getItem("sid"),rid=jsxc.storage.getItem("rid"),null!==sid&&null!==rid?jid=jsxc.storage.getItem("jid"):(sid=jsxc.options.xmpp.sid||null,rid=jsxc.options.xmpp.rid||null,jid=jsxc.options.xmpp.jid)}if(jid){jsxc.bid||(jsxc.bid=jsxc.jidToBid(jid));var url=jsxc.options.get("xmpp").url;if(url){jsxc.xmpp.conn&&jsxc.xmpp.conn.connected||($(document).on("connected.jsxc",jsxc.xmpp.connected),$(document).on("attached.jsxc",jsxc.xmpp.attached),$(document).on("disconnected.jsxc",jsxc.xmpp.disconnected),$(document).on("connfail.jsxc",jsxc.xmpp.onConnfail),$(document).on("authfail.jsxc",jsxc.xmpp.onAuthFail),Strophe.addNamespace("RECEIPTS","urn:xmpp:receipts"),Strophe.addNamespace("VERSION","jabber:iq:version")),jsxc.xmpp.conn=new Strophe.Connection(url),!0===jsxc.storage.getItem("debug")&&(jsxc.xmpp.conn.xmlInput=function(data){console.log("<",data)},jsxc.xmpp.conn.xmlOutput=function(data){console.log(">",data)}),jsxc.xmpp.conn.nextValidRid=jsxc.xmpp.onRidChange;var callback=function(status,condition){switch(jsxc.debug(Object.getOwnPropertyNames(Strophe.Status)[status]+": "+condition),status){case Strophe.Status.CONNECTING:$(document).trigger("connecting.jsxc");break;case Strophe.Status.CONNECTED:jsxc.bid=jsxc.jidToBid(jsxc.xmpp.conn.jid.toLowerCase()),$(document).trigger("connected.jsxc");break;case Strophe.Status.ATTACHED:$(document).trigger("attached.jsxc");break;case Strophe.Status.DISCONNECTED:$(document).trigger("disconnected.jsxc");break;case Strophe.Status.CONNFAIL:$(document).trigger("connfail.jsxc",condition);break;case Strophe.Status.AUTHFAIL:$(document).trigger("authfail.jsxc")}};jsxc.xmpp.conn.caps&&(jsxc.xmpp.conn.caps.node="http://jsxc.org/"),jsxc.changeState(jsxc.CONST.STATE.ESTABLISHING),sid&&rid?(jsxc.debug("Try to attach"),jsxc.debug("SID: "+sid),jsxc.xmpp.conn.attach(jid,sid,rid,callback)):(jsxc.debug("New connection"),jsxc.xmpp.conn.caps&&jsxc.xmpp.conn._addSysHandler(function(stanza){var from=jsxc.xmpp.conn.domain,c=stanza.querySelector("c"),ver=c.getAttribute("ver"),node=c.getAttribute("node"),_jidNodeIndex=JSON.parse(localStorage.getItem("strophe.caps._jidNodeIndex"))||{};jsxc.xmpp.conn.caps._jidVerIndex[from]=ver,_jidNodeIndex[from]=node,localStorage.setItem("strophe.caps._jidVerIndex",JSON.stringify(jsxc.xmpp.conn.caps._jidVerIndex)),localStorage.setItem("strophe.caps._jidNodeIndex",JSON.stringify(_jidNodeIndex))},Strophe.NS.CAPS),jsxc.xmpp.conn.connect(jid,password||jsxc.options.xmpp.password,callback))}else jsxc.warn("xmpp.url required for login")}else jsxc.warn("Jid required for login")}},logout:function(complete){if(jsxc.storage.setUserItem("forcedLogout",!0),jsxc.triggeredFromElement="boolean"!=typeof complete||complete,!jsxc.master)return jsxc.storage.removeItem("sid"),!0;if(jsxc.storage.removeUserItem("windowlist"),jsxc.storage.removeUserItem("unreadMsg"),jsxc.gui.favicon&&jsxc.gui.favicon.badge(0),$("body").click(),!jsxc.xmpp.conn||!jsxc.xmpp.conn.authenticated)return!0;$.each(jsxc.storage.getUserItem("otrlist")||{},function(i,val){jsxc.otr.create(val)});var numOtr=Object.keys(jsxc.otr.objects||{}).length+1,disReady=function(){--numOtr<=0&&(jsxc.xmpp.conn.flush(),setTimeout(function(){jsxc.xmpp.conn.disconnect()},600))};return $.each(jsxc.otr.objects||{},function(key,obj){obj.msgstate===OTR.CONST.MSGSTATE_ENCRYPTED?obj.endOtr.call(obj,function(){obj.init.call(obj),jsxc.otr.backup(key),disReady()}):disReady()}),disReady(),!1},connected:function(){jsxc.xmpp.conn.pause(),jsxc.xmpp.initNewConnection(),jsxc.xmpp.saveSessionParameter();var rosterVerSupport=0<$(jsxc.xmpp.conn.features).find('[xmlns="urn:xmpp:features:rosterver"]').length;if(jsxc.storage.setUserItem("rosterVerSupport",rosterVerSupport),jsxc.storage.removeUserItem("forcedLogout"),jsxc.options.loginForm.triggered)switch(jsxc.options.loginForm.onConnected||"submit"){case"submit":return void jsxc.submitLoginForm();case!1:return}jsxc.gui.dialog.close(),jsxc.xmpp.conn.resume(),jsxc.onMaster(),jsxc.changeState(jsxc.CONST.STATE.READY),$(document).trigger("attached.jsxc")},attached:function(){$("#jsxc_roster").removeClass("jsxc_noConnection"),Strophe.addNamespace("VERSION","jabber:iq:version"),jsxc.xmpp.conn.addHandler(jsxc.xmpp.onRosterChanged,"jabber:iq:roster","iq","set"),jsxc.xmpp.conn.addHandler(jsxc.xmpp.onChatMessage,null,"message","chat"),jsxc.xmpp.conn.addHandler(jsxc.xmpp.onErrorMessage,null,"message","error"),jsxc.xmpp.conn.addHandler(jsxc.xmpp.onHeadlineMessage,null,"message","headline"),jsxc.xmpp.conn.addHandler(jsxc.xmpp.onReceived,null,"message"),jsxc.xmpp.conn.addHandler(jsxc.xmpp.onPresence,null,"presence"),jsxc.xmpp.conn.addHandler(jsxc.xmpp.onVersionRequest,Strophe.NS.VERSION,"iq","get"),jsxc.gui.init();var caps=jsxc.xmpp.conn.caps,domain=jsxc.xmpp.conn.domain;if(caps){var conditionalEnable=function(){};if(jsxc.options.get("carbons").enable&&(conditionalEnable=function(){jsxc.xmpp.conn.caps.hasFeatureByJid(domain,jsxc.CONST.NS.CARBONS)&&jsxc.xmpp.carbons.enable()},$(document).on("caps.strophe",function onCaps(ev,from){from===domain&&(conditionalEnable(),$(document).off("caps.strophe",onCaps))})),void 0===caps._knownCapabilities[caps._jidVerIndex[domain]]){var _jidNodeIndex=JSON.parse(localStorage.getItem("strophe.caps._jidNodeIndex"))||{};jsxc.debug("Request server capabilities"),caps._requestCapabilities(jsxc.xmpp.conn.domain,_jidNodeIndex[domain],caps._jidVerIndex[domain])}else conditionalEnable()}if(jsxc.storage.getUserItem("rosterLoaded")!==jsxc.xmpp.conn._proto.sid){$(document).one("cloaded.roster.jsxc",jsxc.xmpp.sendPres),$("#jsxc_roster > p:first").remove();var queryAttr={xmlns:"jabber:iq:roster"};jsxc.storage.getUserItem("rosterVerSupport")&&(queryAttr.ver=jsxc.storage.getUserItem("rosterVer")||"");var iq=$iq({type:"get"}).c("query",queryAttr);jsxc.xmpp.conn.sendIQ(iq,jsxc.xmpp.onRoster)}else jsxc.xmpp.sendPres(),jsxc.restoreCompleted||jsxc.gui.restore();jsxc.xmpp.saveSessionParameter(),jsxc.masterActions(),jsxc.changeState(jsxc.CONST.STATE.READY)},saveSessionParameter:function(){var nomJid=Strophe.getBareJidFromJid(jsxc.xmpp.conn.jid).toLowerCase()+"/"+Strophe.getResourceFromJid(jsxc.xmpp.conn.jid);jsxc.storage.setItem("sid",jsxc.xmpp.conn._proto.sid),jsxc.storage.setItem("jid",nomJid)},initNewConnection:function(){jsxc.storage.removeUserItem("windowlist"),jsxc.storage.removeUserItem("own"),jsxc.storage.removeUserItem("avatar","own"),jsxc.storage.removeUserItem("otrlist"),jsxc.storage.removeUserItem("unreadMsg"),jsxc.storage.removeUserItem("features"),jsxc.storage.removeUserElement("options","RTCPeerConfig"),jsxc.storage.removeUserElement("options","httpUpload")},sendPres:function(){jsxc.xmpp.conn.disco&&(jsxc.xmpp.conn.disco.addIdentity("client","web","JSXC",""),jsxc.xmpp.conn.disco.addFeature(Strophe.NS.DISCO_INFO),jsxc.xmpp.conn.disco.addFeature(Strophe.NS.RECEIPTS),jsxc.xmpp.conn.disco.addFeature(Strophe.NS.VERSION));var pres=$pres();jsxc.xmpp.conn.caps&&pres.c("c",jsxc.xmpp.conn.caps.generateCapsAttrs()).up();var presState=jsxc.storage.getUserItem("presence")||"online";"online"!==presState&&pres.c("show").t(presState).up();var priority=jsxc.options.get("priority");if(priority&&void 0!==priority[presState]&&0!==parseInt(priority[presState])&&pres.c("priority").t(priority[presState]).up(),jsxc.debug("Send presence",pres.toString()),jsxc.xmpp.conn.send(pres),jsxc.storage.getUserItem("features"))$(document).trigger("features.jsxc");else{jsxc.xmpp.conn.flush();var barJid=Strophe.getBareJidFromJid(jsxc.xmpp.conn.jid);jsxc.xmpp.conn.disco.info(barJid,void 0,function(stanza){var features=$(stanza).find("feature").map(function(){return $(this).attr("var")});jsxc.storage.setUserItem("features",features.toArray()),$(document).trigger("features.jsxc")})}},disconnected:function(){jsxc.debug("disconnected"),jsxc.storage.removeItem("sid"),jsxc.storage.removeItem("rid"),jsxc.storage.removeItem("hidden"),jsxc.storage.removeUserItem("avatar","own"),jsxc.storage.removeUserItem("otrlist"),jsxc.storage.removeUserItem("features"),$(document).off("connected.jsxc",jsxc.xmpp.connected),$(document).off("attached.jsxc",jsxc.xmpp.attached),$(document).off("disconnected.jsxc",jsxc.xmpp.disconnected),$(document).off("connfail.jsxc",jsxc.xmpp.onConnfail),$(document).off("authfail.jsxc",jsxc.xmpp.onAuthFail),jsxc.xmpp.conn=null,$("#jsxc_windowList").remove(),jsxc.triggeredFromElement?($(document).trigger("toggle.roster.jsxc",["hidden",0]),jsxc.gui.roster.ready=!1,$("#jsxc_roster").remove(),jsxc.triggeredFromLogout&&(window.location=jsxc.options.logoutElement.attr("href"))):jsxc.gui.roster.noConnection(),window.clearInterval(jsxc.keepaliveInterval),jsxc.restoreCompleted=!1,jsxc.role_allocation=!1,jsxc.master=!1,jsxc.storage.removeItem("alive"),jsxc.changeState(jsxc.CONST.STATE.SUSPEND)},onConnfail:function(ev,condition){jsxc.debug("XMPP connection failed: "+condition),jsxc.options.loginForm.triggered&&jsxc.submitLoginForm()},onAuthFail:function(){if(jsxc.options.loginForm.triggered)switch(jsxc.options.loginForm.onAuthFail||"ask"){case"ask":jsxc.gui.showAuthFail();break;case"submit":jsxc.submitLoginForm();break;case"quiet":case!1:return}},onRoster:function(iq){if(jsxc.debug("Load roster",iq),jsxc.storage.setUserItem("rosterLoaded",jsxc.xmpp.conn._proto.sid),0===$(iq).find("query").length){jsxc.debug("Use cached roster");var buddylist=jsxc.storage.getUserItem("buddylist")||[];return $.each(buddylist,function(index,buddy){jsxc.storage.removeUserItem("res",buddy),jsxc.storage.updateUserItem("buddy",buddy,"status",0),jsxc.storage.updateUserItem("buddy",buddy,"res",[]),jsxc.storage.updateUserItem("buddy",buddy,"rnd",Math.random())}),void jsxc.restoreRoster()}var buddies=[];$(iq).find("item").each(function(){var jid=$(this).attr("jid");if(/^[^"&'\/:<>@\s]+@[\w-_.]+$/i.test(jid)){var name=$(this).attr("name")||jid,bid=jsxc.jidToBid(jid),sub=$(this).attr("subscription");buddies.push(bid),jsxc.storage.removeUserItem("res",bid),jsxc.storage.saveBuddy(bid,{jid:jid,name:name,status:0,sub:sub,res:[],rnd:Math.random()}),jsxc.gui.roster.add(bid)}else jsxc.warn(jid+" is no valid JID.")}),0===buddies.length&&jsxc.gui.roster.empty(),jsxc.storage.setUserItem("buddylist",buddies),$(iq).find("query").attr("ver")&&jsxc.storage.setUserItem("rosterVer",$(iq).find("query").attr("ver")),jsxc.xmpp.bookmarks.load(),jsxc.gui.roster.loaded=!0,jsxc.debug("Roster loaded"),$(document).trigger("cloaded.roster.jsxc"),jsxc.changeUIState(jsxc.CONST.UISTATE.READY)},onRosterChanged:function(iq){var iqSender=$(iq).attr("from"),ownBareJid=Strophe.getBareJidFromJid(jsxc.xmpp.conn.jid);return!(!iqSender||iqSender===ownBareJid)||(jsxc.debug("onRosterChanged",iq),1!==$(iq).find("item").length?jsxc.warn("Roster pushes must contain only one item element"):($(iq).find("item").each(function(){var jid=$(this).attr("jid");if(/^[^"&'\/:<>@\s]+@[\w-_.]+$/i.test(jid)){var name=$(this).attr("name")||jid,bid=jsxc.jidToBid(jid),sub=$(this).attr("subscription");if("remove"===sub)jsxc.gui.roster.purge(bid);else{var bl=jsxc.storage.getUserItem("buddylist");bl.indexOf(bid)<0&&(bl.push(bid),jsxc.storage.setUserItem("buddylist",bl)),"updated"===jsxc.storage.saveBuddy(bid,{jid:jid,name:name,sub:sub})?(jsxc.gui.update(bid),jsxc.gui.roster.reorder(bid)):jsxc.gui.roster.add(bid)}if("from"===sub||"both"===sub){var notice,notices=jsxc.storage.getUserItem("notices"),noticeKey=null;for(noticeKey in notices)"gui.showApproveDialog"===(notice=notices[noticeKey]).fnName&¬ice.fnParams[0]===jid&&(jsxc.debug("Remove notice with key "+noticeKey),jsxc.notice.remove(noticeKey))}}else jsxc.warn(jid+" is no valid JID.")}),$(iq).find("query").attr("ver")&&jsxc.storage.setUserItem("rosterVer",$(iq).find("query").attr("ver")),jsxc.storage.getUserItem("buddylist")&&0!==jsxc.storage.getUserItem("buddylist").length?$("#jsxc_roster > p:first").remove():jsxc.gui.roster.empty()),!0)},onPresence:function(presence){jsxc.debug("onPresence",presence);var ptype=$(presence).attr("type"),from=$(presence).attr("from"),jid=Strophe.getBareJidFromJid(from).toLowerCase(),r=Strophe.getResourceFromJid(from),bid=jsxc.jidToBid(jid),data=jsxc.storage.getUserItem("buddy",bid)||{},res=jsxc.storage.getUserItem("res",bid)||{},status=null,xVCard=$(presence).find('x[xmlns="vcard-temp:x:update"]');if(jid===Strophe.getBareJidFromJid(jsxc.storage.getItem("jid")))return!0;if("error"===ptype){$(document).trigger("error.presence.jsxc",[from,presence]);var error=$(presence).find("error");return jsxc.error("[XMPP] "+error.attr("code")+" "+error.find(">:first-child").prop("tagName")),!0}if("subscribe"===ptype)return-1<jsxc.storage.getUserItem("buddylist").indexOf(bid)?(jsxc.debug("Auto approve contact request, because he is already in our contact list."),jsxc.xmpp.resFriendReq(jid,!0),"to"!==data.sub&&jsxc.xmpp.addBuddy(jid,data.name)):(jsxc.storage.setUserItem("friendReq",{jid:jid,approve:-1}),jsxc.notice.add({msg:$.t("Friendship_request"),description:$.t("from")+" "+jid,type:"contact"},"gui.showApproveDialog",[jid])),!0;if("unavailable"===ptype||"unsubscribed"===ptype)status=jsxc.CONST.STATUS.indexOf("offline");else{var show=$(presence).find("show").text();status=""===show?jsxc.CONST.STATUS.indexOf("online"):jsxc.CONST.STATUS.indexOf(show)}0===status?delete res[r]:r&&(res[r]=status);var maxVal=[],max=0,prop=null;for(prop in res)res.hasOwnProperty(prop)&&max<=res[prop]&&(max!==res[prop]&&(maxVal=[],max=res[prop]),maxVal.push(prop));if(0===data.status&&0<max&&jsxc.notification.notify({title:data.name,msg:$.t("has_come_online"),source:bid}),"groupchat"!==data.type&&(data.status=max),data.res=maxVal,data.jid=jid,0<xVCard.length&&"groupchat"!==data.type){var photo=xVCard.find("photo");0<photo.length&&photo.text()!==data.avatar&&(jsxc.storage.removeUserItem("avatar",data.avatar),data.avatar=photo.text())}return 0<jsxc.gui.window.get(bid).length&&jsxc.gui.window.get(bid).data("jid",jid),jsxc.storage.setUserItem("buddy",bid,data),jsxc.storage.setUserItem("res",bid,res),jsxc.debug("Presence ("+from+"): "+jsxc.CONST.STATUS[status]),jsxc.gui.update(bid),jsxc.gui.roster.reorder(bid),$(document).trigger("presence.jsxc",[from,status,presence]),!0},onChatMessage:function(stanza){var message,carbon,forwarded=$(stanza).find('forwarded[xmlns="'+jsxc.CONST.NS.FORWARD+'"]'),originalSender=$(stanza).attr("from");if(0<forwarded.length){if(message=forwarded.find("> message"),forwarded=!0,0===(carbon=$(stanza).find('> [xmlns="'+jsxc.CONST.NS.CARBONS+'"]')).length)carbon=!1;else if(originalSender!==Strophe.getBareJidFromJid(jsxc.xmpp.conn.jid))return!0;jsxc.debug("Incoming forwarded message",message)}else message=stanza,carbon=forwarded=!1,jsxc.debug("Incoming message",message);var htmlBody=$(message).find('body[xmlns="'+Strophe.NS.XHTML+'"]').first(),body=$(message).find(">body").first().text()||htmlBody.text();if(!body||body.match(/\?OTR/i)&&forwarded)return!0;var bid,type=$(message).attr("type"),from=$(message).attr("from"),mid=$(message).attr("id"),delay=$(message).find('delay[xmlns="urn:xmpp:delay"]'),stamp=0<delay.length?new Date(delay.attr("stamp")):new Date;if(stamp=stamp.getTime(),carbon){var direction="sent"===carbon.prop("tagName")?jsxc.Message.OUT:jsxc.Message.IN;return bid=jsxc.jidToBid("out"===direction?$(message).attr("to"):from),jsxc.gui.window.postMessage({bid:bid,direction:direction,msg:body,encrypted:!1,forwarded:forwarded,stamp:stamp}),!0}forwarded&&(body=from+" "+$.t("to")+" "+$(stanza).attr("to")+'"'+body+'"',from=$(stanza).attr("from"));var jid=Strophe.getBareJidFromJid(from);bid=jsxc.jidToBid(jid);var data=jsxc.storage.getUserItem("buddy",bid),request=$(message).find("request[xmlns='urn:xmpp:receipts']");if(null===data){0===(jsxc.storage.getUserItem("chat",bid)||[]).length&&jsxc.notice.add({msg:$.t("Unknown_sender"),description:$.t("You_received_a_message_from_an_unknown_sender_")+" ("+bid+")."},"gui.showUnknownSender",[bid]);var msg=jsxc.removeHTML(body);return msg=jsxc.escapeHTML(msg),new jsxc.Message({bid:bid,msg:msg,direction:jsxc.Message.IN,encrypted:!1,forwarded:forwarded,stamp:stamp}).save(),!0}var win=jsxc.gui.window.init(bid);"chat"===type&&(win.data("jid",from),jsxc.storage.updateUserItem("buddy",bid,{jid:from})),$(document).trigger("message.jsxc",[from,body]),jsxc.master&&!jsxc.otr.objects[bid]&&jsxc.otr.create(bid),forwarded||null===mid||!request.length||null===data||"both"!==data.sub&&"from"!==data.sub||"chat"!==type||jsxc.xmpp.conn.send($msg({to:from}).c("received",{xmlns:"urn:xmpp:receipts",id:mid}));var attachment=jsxc.xmpp.getAttachmentFromHtmlBody(htmlBody);return attachment&&(body=null),jsxc.otr.objects.hasOwnProperty(bid)&&body?jsxc.otr.objects[bid].receiveMsg(body,{_uid:mid,stamp:stamp,forwarded:forwarded,attachment:attachment}):jsxc.gui.window.postMessage({_uid:mid,bid:bid,direction:jsxc.Message.IN,msg:body,encrypted:!1,forwarded:forwarded,stamp:stamp,attachment:attachment}),!0},onErrorMessage:function(message){var bid=jsxc.jidToBid($(message).attr("from"));return 0!==jsxc.gui.window.get(bid).length&&$(message).attr("id")&&(0<$(message).find("item-not-found").length?jsxc.gui.window.postMessage({bid:bid,direction:jsxc.Message.SYS,msg:$.t("message_not_send_item-not-found")}):0<$(message).find("forbidden").length?jsxc.gui.window.postMessage({bid:bid,direction:jsxc.Message.SYS,msg:$.t("message_not_send_forbidden")}):0<$(message).find("not-acceptable").length?jsxc.gui.window.postMessage({bid:bid,direction:jsxc.Message.SYS,msg:$.t("message_not_send_not-acceptable")}):0<$(message).find("remote-server-not-found").length?jsxc.gui.window.postMessage({bid:bid,direction:jsxc.Message.SYS,msg:$.t("message_not_send_remote-server-not-found")}):0<$(message).find("service-unavailable").length?0===$(message).find('[xmlns="'+Strophe.NS.CHATSTATES+'"]').length&&jsxc.gui.window.postMessage({bid:bid,direction:jsxc.Message.SYS,msg:$.t("message_not_send_resource-unavailable")}):jsxc.gui.window.postMessage({bid:bid,direction:jsxc.Message.SYS,msg:$.t("message_not_send")}),jsxc.debug("error message for "+bid,$(message).find("error")[0])),!0},onHeadlineMessage:function(stanza){var from=(stanza=$(stanza)).attr("from"),domain=Strophe.getDomainFromJid(from);if(domain!==from){if(!jsxc.storage.getUserItem("buddy",jsxc.jidToBid(from)))return!0}else if(domain!==Strophe.getDomainFromJid(jsxc.xmpp.conn.jid))return!0;var subject=stanza.find("subject:first").text()||$.t("Notification"),body=stanza.find("body:first").text();return jsxc.notice.add({msg:subject,description:body,type:domain===from?"announcement":null},"gui.showNotification",[subject,body,from]),!0},onVersionRequest:function(stanza){var from=(stanza=$(stanza)).attr("from"),id=stanza.attr("id"),iq=$iq({type:"result",to:from,id:id}).c("query",{xmlns:Strophe.NS.VERSION}).c("name").t("JSXC").up().c("version").t(jsxc.version);return jsxc.xmpp.conn.sendIQ(iq),!0},onRidChange:function(rid){jsxc.storage.setItem("rid",rid)},getAttachmentFromHtmlBody:function(htmlBody){if(1===htmlBody.length){var attachment,httpUploadElement=htmlBody.find("a[data-type][data-name][data-size]");if(1===httpUploadElement.length)attachment={type:httpUploadElement.attr("data-type"),name:httpUploadElement.attr("data-name"),size:httpUploadElement.attr("data-size")},httpUploadElement.attr("data-thumbnail")&&httpUploadElement.attr("data-thumbnail").match(/^\s*data:[a-z]+\/[a-z0-9-+.*]+;base64,[a-z0-9=+/]+$/i)&&(attachment.thumbnail=httpUploadElement.attr("data-thumbnail")),httpUploadElement.attr("href")&&httpUploadElement.attr("href").match(/^https:\/\//)&&(attachment.data=httpUploadElement.attr("href")),attachment.type.match(/^[a-z]+\/[a-z0-9-+.*]+$/i)&&attachment.name.match(/^[\s\w.,-]+$/i)&&attachment.size.match(/^\d+$/i)||(attachment=void 0,jsxc.warn("Invalid file type, name or size."));else if(1===htmlBody.find(">a").length){var thumbnail,linkElement=htmlBody.find(">a"),metaString="";if(1===linkElement.find(">img").length){var imgElement=linkElement.find(">img"),src=imgElement.attr("src")||"";metaString=(imgElement.attr("alt")||"").replace(/^Preview:/,""),src.match(/^\s*data:[a-z]+\/[a-z0-9-+.*]+;base64,[a-z0-9=+/]+$/i)&&(thumbnail=src)}else metaString=linkElement.text();var metaMatch=metaString.match(/^([a-z]+\/[a-z0-9-+.*]+)\|(\d+)\|([\s\w.,-]+)/);metaMatch?(attachment={type:metaMatch[1],size:metaMatch[2],name:metaMatch[3]},thumbnail&&(attachment.thumbnail=thumbnail),linkElement.attr("href")&&linkElement.attr("href").match(/^https?:\/\//)&&(attachment.data=linkElement.attr("href"))):jsxc.warn("Invalid file type, name or size.")}return attachment}},resFriendReq:function(from,approve){jsxc.master?(jsxc.xmpp.conn.send($pres({to:from,type:approve?"subscribed":"unsubscribed"})),jsxc.storage.removeUserItem("friendReq"),jsxc.gui.dialog.close()):jsxc.storage.updateUserItem("friendReq","approve",approve)},addBuddy:function(username,alias){var bid=jsxc.jidToBid(username);if(jsxc.master){var iq=$iq({type:"set"}).c("query",{xmlns:"jabber:iq:roster"}).c("item",{jid:username,name:alias||""});jsxc.xmpp.conn.sendIQ(iq),jsxc.xmpp.conn.send($pres({to:username,type:"subscribe"})),jsxc.storage.removeUserItem("add",bid)}else jsxc.storage.setUserItem("add",bid,{username:username,alias:alias||null})},removeBuddy:function(jid){var bid=jsxc.jidToBid(jid),iq=$iq({type:"set"}).c("query",{xmlns:"jabber:iq:roster"}).c("item",{jid:Strophe.getBareJidFromJid(jid),subscription:"remove"});jsxc.xmpp.conn.sendIQ(iq),jsxc.gui.roster.purge(bid)},onReceived:function(stanza){var received=$(stanza).find("received[xmlns='urn:xmpp:receipts']");if(received.length){var receivedId=received.attr("id");new jsxc.Message(receivedId).received()}return!0},sendMessage:function(message){var bid=message.bid,msg=message.msg,isMucBid=0<=(jsxc.xmpp.conn.muc&&jsxc.xmpp.conn.muc.roomNames?jsxc.xmpp.conn.muc.roomNames:[]).indexOf(bid);jsxc.otr.objects.hasOwnProperty(bid)&&!isMucBid?jsxc.otr.objects[bid].sendMsg(msg,message):jsxc.xmpp._sendMessage(jsxc.gui.window.get(bid).data("jid"),msg,message)},_sendMessage:function(jid,msg,message){var data=jsxc.storage.getUserItem("buddy",jsxc.jidToBid(jid))||{},isBar=Strophe.getBareJidFromJid(jid)===jid,type=data.type||"chat";message=message||{};var xmlMsg=$msg({to:jid,type:type,id:message._uid});message.type===jsxc.Message.HTML&&msg===message.msg&&message.htmlMsg?(xmlMsg.c("body").t(msg),xmlMsg.up().c("html",{xmlns:Strophe.NS.XHTML_IM}).c("body",{xmlns:Strophe.NS.XHTML}).h(message.htmlMsg).up()):xmlMsg.c("body").t(msg),jsxc.xmpp.carbons.enabled&&msg.match(/^\?OTR/)&&xmlMsg.up().c("private",{xmlns:jsxc.CONST.NS.CARBONS}),msg.match(/^\?OTR/)&&xmlMsg.up().c("no-permanent-store",{xmlns:jsxc.CONST.NS.HINTS}),"chat"===type&&(isBar||jsxc.xmpp.conn.caps.hasFeatureByJid(jid,Strophe.NS.RECEIPTS))&&xmlMsg.up().c("request",{xmlns:"urn:xmpp:receipts"}),jsxc.xmpp.conn.chatstates&&!jsxc.xmpp.chatState.isDisabled()&&xmlMsg.up().c("active",{xmlns:Strophe.NS.CHATSTATES}),jsxc.xmpp.conn.send(xmlMsg)},loadVcard:function(bid,cb,error_cb){jsxc.master?jsxc.xmpp.conn.vcard.get(cb,bid,error_cb):(jsxc.storage.setUserItem("vcard",bid,"request:"+(new Date).getTime()),$(document).one("loaded.vcard.jsxc",function(ev,result){result&&"success"===result.state?cb($(result.data).get(0)):error_cb()}))},getCapabilitiesByJid:function(jid){if(jsxc.xmpp.conn)return jsxc.xmpp.conn.caps.getCapabilitiesByJid(jid);var jidVerIndex=JSON.parse(localStorage.getItem("strophe.caps._jidVerIndex"))||{},knownCapabilities=JSON.parse(localStorage.getItem("strophe.caps._knownCapabilities"))||{};return jidVerIndex[jid]?knownCapabilities[jidVerIndex[jid]]:null},hasFeatureByJid:function(jid,feature,cb){var conn=jsxc.xmpp.conn;if(cb=cb||function(){},!feature)return!1;$.isArray(feature)||(feature=$.makeArray(feature));var check=function(knownCapabilities){if(!knownCapabilities)return null;var i;for(i=0;i<feature.length;i++)if(knownCapabilities.features.indexOf(feature[i])<0)return!1;return!0};if(conn.caps._jidVerIndex[jid]&&conn.caps._knownCapabilities[conn.caps._jidVerIndex[jid]]){var hasFeature=check(conn.caps._knownCapabilities[conn.caps._jidVerIndex[jid]]);return cb(hasFeature),hasFeature}return $(document).on("strophe.caps",function(ev,j,capabilities){j===jid&&(cb(check(capabilities)),$(document).off(ev))}),null}},jsxc.xmpp.carbons={enabled:!1,enable:function(cb){var iq=$iq({type:"set"}).c("enable",{xmlns:jsxc.CONST.NS.CARBONS});jsxc.xmpp.conn.sendIQ(iq,function(){jsxc.xmpp.carbons.enabled=!0,jsxc.debug("Carbons enabled"),cb&&cb.call(this)},function(stanza){jsxc.warn("Could not enable carbons",stanza)})},disable:function(cb){var iq=$iq({type:"set"}).c("disable",{xmlns:jsxc.CONST.NS.CARBONS});jsxc.xmpp.conn.sendIQ(iq,function(){jsxc.xmpp.carbons.enabled=!1,jsxc.debug("Carbons disabled"),cb&&cb.call(this)},function(stanza){jsxc.warn("Could not disable carbons",stanza)})},refresh:function(err){if(!1!==err)return jsxc.options.get("carbons").enable?jsxc.xmpp.carbons.enable():jsxc.xmpp.carbons.disable()}},jsxc.gui={emotions:[["O:-) O:)","innocent"],[">:-( >:( >:-( >:(","angry"],[":-) :)","slight_smile"],[":-D :D","grin"],[":-( :(","disappointed"],[";-) ;)","wink"],[":-P :P","stuck_out_tongue"],["=-O","astonished"],[":kiss: :-*","kissing_heart"],["8-) :cool:","sunglasses"],[":-X :X","zipper_mouth"],[":yes:","thumbsup"],[":no:","thumbsdown"],[":beer:","beer"],[":coffee:","coffee"],[":devil:","smiling_imp"],[":kiss: :kissing:","kissing"],["@->-- @->--","rose"],[":music:","musical_note"],[":love:","heart_eyes"],[":heart:","heart"],[":brokenheart:","broken_heart"],[":zzz:","zzz"],[":wait:","hand_splayed"]],favicon:null,regShortNames:null,emoticonList:{core:{":klaus:":["klaus"],":jabber:":["jabber"],":xmpp:":["xmpp"],":jsxc:":["jsxc"],":owncloud:":["owncloud"],":nextcloud:":["nextcloud"]},emojione:emojione.emojioneList},queryActions:{message:function(jid,params){var bid=jsxc.jidToBid(jid);jsxc.storage.getUserItem("buddy",bid)||jsxc.storage.saveBuddy(bid,{jid:jid,name:bid,status:0,sub:"none",res:[],rnd:Math.random()});var win=jsxc.gui.window.open(bid);params&&"string"==typeof params.body&&win.find(".jsxc_textinput").val(params.body)},remove:function(jid){jsxc.gui.showRemoveDialog(jsxc.jidToBid(jid))},subscribe:function(jid,params){jsxc.gui.showContactDialog(jid),params&&(params.name,1)&&$("#jsxc_alias").val(params.name)},vcard:function(jid){jsxc.gui.showVcard(jid)},join:function(jid,params){var password=params&¶ms.password?params.password:null;jsxc.muc.showJoinChat(jid,password)}},init:function(){if(!(0<$("#jsxc_windowList").length)){jsxc.changeUIState(jsxc.CONST.UISTATE.INITIATING),jsxc.gui.regShortNames=new RegExp(emojione.regShortNames.source+"|("+Object.keys(jsxc.gui.emoticonList.core).join("|")+")","gi"),$("body").append($(jsxc.gui.template.get("windowList"))),$(window).resize(jsxc.gui.updateWindowListSB),$("#jsxc_windowList").resize(jsxc.gui.updateWindowListSB),$("#jsxc_windowListSB .jsxc_scrollLeft").click(function(){jsxc.gui.scrollWindowListBy(-200)}),$("#jsxc_windowListSB .jsxc_scrollRight").click(function(){jsxc.gui.scrollWindowListBy(200)}),$("#jsxc_windowList").on("wheel",function(ev){$("#jsxc_windowList").data("isOver")&&jsxc.gui.scrollWindowListBy(0<ev.originalEvent.wheelDelta?200:-200)}),jsxc.gui.tooltip("#jsxc_windowList");var fo=jsxc.options.get("favicon");fo&&fo.enable&&(jsxc.gui.favicon=new Favico({animation:"pop",bgColor:fo.bgColor,textColor:fo.textColor}),jsxc.gui.favicon.badge(jsxc.storage.getUserItem("unreadMsg")||0)),jsxc.el_exists("#jsxc_roster")||jsxc.gui.roster.init(),$.each(jsxc.gui.emotions,function(i,val){var reg=val[0].replace(/(\/|\||\*|\.|\+|\?|\^|\$|\(|\)|\[|\]|\{|\})/g,"\\$1");reg="("+reg.split(" ").join("|")+")",jsxc.gui.emotions[i][2]=new RegExp(reg,"g")}),jsxc.gui.windowTemplate=$(jsxc.gui.template.get("chatWindow")),jsxc.gui.buddyTemplate=$(jsxc.gui.template.get("rosterBuddy"))}},tooltip:function(selector){$(selector).tooltip({show:{delay:600},content:function(){return $(this).attr("title").replace(/\n/g,"<br />")}})},update:function(bid){var data=jsxc.storage.getUserItem("buddy",bid);if(data){var ri=jsxc.gui.roster.getItem(bid),we=jsxc.gui.window.get(bid),ue=ri.add(we),spot=$('.jsxc_spot[data-bid="'+bid+'"]');switch(ri.data(data),jsxc.gui.updatePresence(bid,jsxc.CONST.STATUS[data.status]),ue.find(".jsxc_name:first").add(spot).text(data.name).attr("title",bid+" "+$.t("is_",{status:$.t(jsxc.CONST.STATUS[data.status])})),data.msgstate){case 0:we.find(".jsxc_transfer").removeClass("jsxc_enc jsxc_fin").attr("title",$.t("your_connection_is_unencrypted")),we.find(".jsxc_settings .jsxc_verification").addClass("jsxc_disabled"),we.find(".jsxc_settings .jsxc_transfer").text($.t("start_private"));break;case 1:we.find(".jsxc_transfer").addClass("jsxc_enc").attr("title",$.t("your_connection_is_encrypted")),we.find(".jsxc_settings .jsxc_verification").removeClass("jsxc_disabled"),we.find(".jsxc_settings .jsxc_transfer").text($.t("close_private"));break;case 2:we.find(".jsxc_settings .jsxc_verification").addClass("jsxc_disabled"),we.find(".jsxc_transfer").removeClass("jsxc_enc").addClass("jsxc_fin").attr("title",$.t("your_buddy_closed_the_private_connection")),we.find(".jsxc_settings .jsxc_transfer").text($.t("close_private"))}data.trust?we.find(".jsxc_transfer").addClass("jsxc_trust").attr("title",$.t("your_buddy_is_verificated")):we.find(".jsxc_transfer").removeClass("jsxc_trust"),data.sub&&"both"!==data.sub?ue.addClass("jsxc_oneway"):ue.removeClass("jsxc_oneway");var info=Strophe.getBareJidFromJid(data.jid)+"\n";info+=$.t("Subscription")+": "+$.t(data.sub)+"\n",info+=$.t("Status")+": "+$.t(jsxc.CONST.STATUS[data.status]),ri.find(".jsxc_name").attr("title",info),jsxc.gui.avatar.update(ri.add(we.find(".jsxc_bar")),data.jid,data.avatar),$(document).trigger("update.gui.jsxc",[bid])}else jsxc.debug("No data for "+bid)},updateWindowListSB:function(){$("#jsxc_windowList>ul").width()>$("#jsxc_windowList").width()?$("#jsxc_windowListSB > div").removeClass("jsxc_disabled"):($("#jsxc_windowListSB > div").addClass("jsxc_disabled"),$("#jsxc_windowList>ul").css("right","0px"))},scrollWindowListBy:function(offset){var scrollWidth=$("#jsxc_windowList>ul").width(),width=$("#jsxc_windowList").width(),el=$("#jsxc_windowList>ul"),right=parseInt(el.css("right"))-offset,padding=$("#jsxc_windowListSB").width();scrollWidth<width||(0<right&&(right=0),right<width-scrollWidth-padding&&(right=width-scrollWidth-padding),el.css("right",right+"px"))},getWindow:function(bid){return jsxc.warn("jsxc.gui.getWindow is deprecated!"),jsxc.gui.window.get(bid)},toggleList:function(el){var self=el||$(this);self.disableSelection(),self.addClass("jsxc_list");var ul=self.find("ul"),slideUp=null;slideUp=function(){self.removeClass("jsxc_opened"),$("body").off("click",null,slideUp)},$(this).click(function(){return self.hasClass("jsxc_opened")?$("body").off("click",null,slideUp):($("body").click(),$("body").one("click",slideUp)),window.clearTimeout(ul.data("timer")),self.toggleClass("jsxc_opened"),!1}).mouseleave(function(){ul.data("timer",window.setTimeout(slideUp,2e3))}).mouseenter(function(){window.clearTimeout(ul.data("timer"))})},showLoginBox:function(){$(document).one("complete.dialog.jsxc",function(){setTimeout(function(){0===$("#jsxc_username").val().length?$("#jsxc_username").focus():$("#jsxc_password").focus()},50)}),jsxc.gui.dialog.open(jsxc.gui.template.get("loginBox"));var alert=$("#jsxc_dialog").find(".jsxc_alert");function onAuthFail(){alert.show(),jsxc.gui.dialog.resize(),removeHandler(),$("#jsxc_dialog").find("button").trigger("btnfinished.jsxc"),$("#jsxc_dialog").find("input").one("keypress",function(){alert.hide(),jsxc.gui.dialog.resize()})}function removeHandler(){$(document).off("authfail.jsxc",null,onAuthFail),$(document).off("connfail.jsxc",null,onAuthFail),$(document).off("connected.jsxc",null,removeHandler)}alert.hide(),$("#jsxc_dialog").find("form").submit(function(ev){ev.preventDefault(),$(this).find("button[data-jsxc-loading-text]").trigger("btnloading.jsxc"),jsxc.options.loginForm.form=$(this),jsxc.options.loginForm.jid=$(this).find("#jsxc_username"),jsxc.options.loginForm.pass=$(this).find("#jsxc_password"),jsxc.triggeredFromBox=!0,jsxc.options.loginForm.triggered=!1,jsxc.prepareLogin(function(settings){!1===settings?onAuthFail():($(document).on("authfail.jsxc",onAuthFail),$(document).on("connfail.jsxc",onAuthFail),$(document).on("connected.jsxc",removeHandler),jsxc.xmpp.login())})})},showFingerprints:function(bid){jsxc.gui.dialog.open(jsxc.gui.template.get("fingerprintsDialog",bid))},showVerification:function(bid){0<$("#jsxc_dialog").length?setTimeout(function(){jsxc.gui.showVerification(bid)},3e3):jsxc.storage.getUserItem("buddy",bid).msgstate===OTR.CONST.MSGSTATE_ENCRYPTED?(jsxc.gui.dialog.open(jsxc.gui.template.get("authenticationDialog",bid),{name:"smp"}),$("#jsxc_dialog > div:gt(0)").hide(),$("#jsxc_dialog > div:eq(0) button").click(function(){$(this).siblings().removeClass("active"),$(this).addClass("active"),$(this).get(0).blur(),$("#jsxc_dialog > div:gt(0)").hide(),$("#jsxc_dialog > div:eq("+($(this).index()+1)+")").show().find("input:first").focus()}),$("#jsxc_dialog > div:eq(1) .jsxc_submit").click(function(){jsxc.master&&(jsxc.otr.objects[bid].trust=!0),jsxc.storage.updateUserItem("buddy",bid,"trust",!0),jsxc.gui.dialog.close("smp"),jsxc.storage.updateUserItem("buddy",bid,"trust",!0),jsxc.gui.window.postMessage({bid:bid,direction:jsxc.Message.SYS,msg:$.t("conversation_is_now_verified")}),jsxc.gui.update(bid)}),$("#jsxc_dialog > div:eq(2) .jsxc_submit").click(function(){var div=$("#jsxc_dialog > div:eq(2)"),sec=div.find("#jsxc_secret2").val(),quest=div.find("#jsxc_quest").val();""!==sec&&""!==quest?(jsxc.master?jsxc.otr.sendSmpReq(bid,sec,quest):jsxc.storage.setUserItem("smp",bid,{sec:sec,quest:quest}),jsxc.gui.dialog.close("smp"),jsxc.gui.window.postMessage({bid:bid,direction:jsxc.Message.SYS,msg:$.t("authentication_query_sent")})):div.find('input[value=""]').addClass("jsxc_invalid").keyup(function(){$(this).val().match(/.*/)&&$(this).removeClass("jsxc_invalid")})}),$("#jsxc_dialog > div:eq(3) .jsxc_submit").click(function(){var div=$("#jsxc_dialog > div:eq(3)"),sec=div.find("#jsxc_secret").val();""!==sec?(jsxc.master?jsxc.otr.sendSmpReq(bid,sec):jsxc.storage.setUserItem("smp",bid,{sec:sec,quest:null}),jsxc.gui.dialog.close("smp"),jsxc.gui.window.postMessage({bid:bid,direction:"sys",msg:$.t("authentication_query_sent")})):div.find("#jsxc_secret").addClass("jsxc_invalid").keyup(function(){$(this).val().match(/.*/)&&$(this).removeClass("jsxc_invalid")})})):jsxc.warn("Connection not encrypted")},showApproveDialog:function(from){jsxc.gui.dialog.open(jsxc.gui.template.get("approveDialog"),{noClose:!0}),$("#jsxc_dialog .jsxc_their_jid").text(Strophe.getBareJidFromJid(from)),$("#jsxc_dialog .jsxc_deny").click(function(ev){ev.stopPropagation(),jsxc.xmpp.resFriendReq(from,!1),jsxc.gui.dialog.close()}),$("#jsxc_dialog .jsxc_approve").click(function(ev){ev.stopPropagation();var data=jsxc.storage.getUserItem("buddy",jsxc.jidToBid(from));jsxc.xmpp.resFriendReq(from,!0),data&&"from"!==data.sub||jsxc.gui.showContactDialog(from)})},showContactDialog:function(username){jsxc.gui.dialog.open(jsxc.gui.template.get("contactDialog")),username&&$("#jsxc_username").val(username),$("#jsxc_username").keyup(function(){if("function"==typeof jsxc.options.getUsers){var val=$(this).val();$("#jsxc_userlist").empty(),""!==val&&jsxc.options.getUsers.call(this,val,function(list){$("#jsxc_userlist").empty(),$.each(list||{},function(uid,displayname){var option=$("<option>");option.attr("data-username",uid),option.attr("data-alias",displayname),option.attr("value",uid).appendTo("#jsxc_userlist"),uid!==displayname&&option.clone().attr("value",displayname).appendTo("#jsxc_userlist")})})}}),$("#jsxc_username").on("input",function(){var val=$(this).val(),option=$("#jsxc_userlist").find('option[data-username="'+val+'"], option[data-alias="'+val+'"]');0<option.length&&($("#jsxc_username").val(option.attr("data-username")),$("#jsxc_alias").val(option.attr("data-alias")))}),$("#jsxc_dialog form").submit(function(ev){ev.preventDefault();var username=$("#jsxc_username").val(),alias=$("#jsxc_alias").val();return username.match(/@(.*)$/)||(username+="@"+Strophe.getDomainFromJid(jsxc.storage.getItem("jid"))),username&&username.match(jsxc.CONST.REGEX.JID)?(jsxc.xmpp.addBuddy(username,alias),jsxc.gui.dialog.close()):$("#jsxc_username").addClass("jsxc_invalid").keyup(function(){$(this).val().match(jsxc.CONST.REGEX.JID)&&$(this).removeClass("jsxc_invalid")}),!1})},showRemoveDialog:function(bid){jsxc.gui.dialog.open(jsxc.gui.template.get("removeDialog",bid));var data=jsxc.storage.getUserItem("buddy",bid);$("#jsxc_dialog .jsxc_remove").click(function(ev){ev.stopPropagation(),jsxc.master?jsxc.xmpp.removeBuddy(data.jid):jsxc.storage.setUserItem("deletebuddy",bid,{jid:data.jid}),jsxc.gui.dialog.close()})},showWaitAlert:function(msg){jsxc.gui.dialog.open(jsxc.gui.template.get("waitAlert",null,msg),{noClose:!0})},showAlert:function(msg){jsxc.gui.dialog.open(jsxc.gui.template.get("alert",null,msg))},showAuthFail:function(){jsxc.gui.dialog.open(jsxc.gui.template.get("authFailDialog")),!1!==jsxc.options.loginForm.triggered&&$("#jsxc_dialog .jsxc_cancel").hide(),$("#jsxc_dialog .jsxc_retry").click(function(){jsxc.gui.dialog.close()}),$("#jsxc_dialog .jsxc_cancel").click(function(){jsxc.submitLoginForm()})},showConfirmDialog:function(msg,confirm,dismiss){jsxc.gui.dialog.open(jsxc.gui.template.get("confirmDialog",null,msg),{noClose:!0}),confirm&&$("#jsxc_dialog .jsxc_confirm").click(confirm),dismiss&&$("#jsxc_dialog .jsxc_dismiss").click(dismiss)},showAboutDialog:function(){jsxc.gui.dialog.open(jsxc.gui.template.get("aboutDialog")),$("#jsxc_dialog .jsxc_debuglog").click(function(){jsxc.gui.showDebugLog()})},showDebugLog:function(){var key,userInfo="<h3>User information</h3>";if(navigator)for(key in navigator)"string"==typeof navigator[key]&&(userInfo+="<b>"+key+":</b> "+navigator[key]+"<br />");$.fn&&$.fn.jquery&&(userInfo+="<b>jQuery:</b> "+$.fn.jquery+"<br />"),window.screen&&(userInfo+="<b>Height:</b> "+window.screen.height+"<br />",userInfo+="<b>Width:</b> "+window.screen.width+"<br />"),userInfo+="<b>jsxc version:</b> "+jsxc.version+"<br />",jsxc.gui.dialog.open('<div class="jsxc_log">'+userInfo+"<h3>Log</h3><pre>"+jsxc.escapeHTML(jsxc.log)+"</pre></div>")},showVcard:function(jid){var bid=jsxc.jidToBid(jid);jsxc.gui.dialog.open(jsxc.gui.template.get("vCard",bid));var data=jsxc.storage.getUserItem("buddy",bid);if(data&&data.res){var i,j,res,identities,cap,client,identity=null;for(i=0;i<data.res.length;i++){for(res=data.res[i],identities=[],null!==(cap=jsxc.xmpp.getCapabilitiesByJid(bid+"/"+res))&&null!==cap.identities&&(identities=cap.identities),client="",j=0;j<identities.length;j++)"client"===(identity=identities[j]).category&&(""!==client&&(client+=",\n"),client+=identity.name+" ("+identity.type+")");var status=jsxc.storage.getUserItem("res",bid)[res];$("#jsxc_dialog ul.jsxc_vCard").append('<li class="jsxc_sep"><strong>'+$.t("Resource")+":</strong> "+res+"</li>"),$("#jsxc_dialog ul.jsxc_vCard").append("<li><strong>"+$.t("Client")+":</strong> "+client+"</li>"),$("#jsxc_dialog ul.jsxc_vCard").append("<li><strong>"+$.t("Status")+":</strong> "+$.t(jsxc.CONST.STATUS[status])+"</li>")}}var printProp=function(el,depth){var content="";if(el.each(function(){var item=$(this),children=$(this).children();content+="<li>";var prop=$.t(item[0].tagName);" "!==prop&&(content+="<strong>"+prop+":</strong> "),"PHOTO"===item[0].tagName||(0<children.length?(content+="<ul>",content+=printProp(children,depth+1),content+="</ul>"):""!==item.text()&&(content+=jsxc.escapeHTML(item.text()))),content+="</li>",0===depth&&0<$("#jsxc_dialog ul.jsxc_vCard").length&&(0<$("#jsxc_dialog ul.jsxc_vCard li.jsxc_sep:first").length?$("#jsxc_dialog ul.jsxc_vCard li.jsxc_sep:first").before(content):$("#jsxc_dialog ul.jsxc_vCard").append(content),content="")}),0<depth)return content},failedToLoad=function(){if(0!==$("#jsxc_dialog ul.jsxc_vCard").length){$("#jsxc_dialog p").remove();var content="<p>";content+=$.t("Sorry_your_buddy_doesnt_provide_any_information"),content+="</p>",$("#jsxc_dialog").append(content)}};jsxc.xmpp.loadVcard(bid,function(stanza){if(0!==$("#jsxc_dialog ul.jsxc_vCard").length){$("#jsxc_dialog p").remove();var photo=$(stanza).find("vCard > PHOTO");if(0<photo.length){var img=photo.find("BINVAL").text(),src="data:"+photo.find("TYPE").text()+";base64,"+img;0<photo.find("EXTVAL").length&&(src=photo.find("EXTVAL").text()),src=src.replace(/[\t\r\n\f]/gi,"");var img_el=$('<img class="jsxc_vCard" alt="avatar" />');img_el.attr("src",src),$("#jsxc_dialog h3").before(img_el)}0===$(stanza).find("vCard").length||1===$(stanza).find("vcard > *").length&&1===photo.length?failedToLoad():printProp($(stanza).find("vcard > *"),0)}},failedToLoad)},showSettings:function(){jsxc.gui.dialog.open(jsxc.gui.template.get("settings")),"false"!==jsxc.options.get("xmpp").overwrite&&!1!==jsxc.options.get("xmpp").overwrite||$(".jsxc_fieldsetXmpp").parent().hide(),$("#jsxc_dialog form").each(function(){$(this).find('input[type!="submit"]').each(function(){var id=this.id.split("-"),prop=id[0],key=id[1],type=this.type,data=jsxc.options.get(prop);data&&void 0!==data[key]&&("checkbox"===type?"false"!==data[key]&&!1!==data[key]&&(this.checked="checked"):$(this).val(data[key]))})}),$("#jsxc_dialog form").submit(function(){var self=$(this),data={};self.find('input[type!="submit"]').each(function(){var val,id=this.id.split("-"),prop=id[0],key=id[1];val="checkbox"===this.type?this.checked:$(this).val(),data[prop]||(data[prop]={}),data[prop][key]=val}),$.each(data,function(key,val){jsxc.options.set(key,val)});return jsxc.options.saveSettinsPermanent.call(this,data,function(success){"string"==typeof self.attr("data-onsubmit")&&jsxc.exec(self.attr("data-onsubmit"),[success]),setTimeout(function(){success?self.find('button[type="submit"]').switchClass("btn-primary","btn-success"):self.find('button[type="submit"]').switchClass("btn-primary","btn-danger"),setTimeout(function(){self.find('button[type="submit"]').switchClass("btn-danger btn-success","btn-primary")},2e3)},200)}),!1})},showRequestNotification:function(){jsxc.switchEvents({"notificationready.jsxc":function(){jsxc.gui.dialog.close(),jsxc.notification.init(),jsxc.storage.setUserItem("notification",1)},"notificationfailure.jsxc":function(){jsxc.gui.dialog.close(),jsxc.options.notification=!1,jsxc.storage.setUserItem("notification",0)}}),jsxc.gui.showConfirmDialog($.t("Should_we_notify_you_"),function(){jsxc.gui.dialog.open(jsxc.gui.template.get("pleaseAccept"),{noClose:!0}),jsxc.notification.requestPermission()},function(){$(document).trigger("notificationfailure.jsxc")})},showUnknownSender:function(bid){var confirmationText=$.t("You_received_a_message_from_an_unknown_sender_",{sender:bid});jsxc.gui.showConfirmDialog(confirmationText,function(){jsxc.gui.dialog.close(),jsxc.storage.saveBuddy(bid,{jid:bid,name:bid,status:0,sub:"none",res:[]}),jsxc.gui.window.open(bid)},function(){jsxc.storage.removeUserItem("chat",bid)})},showSelectionDialog:function(header,msg,primary,option,primaryLabel,optionLabel){var opt;opt=1===arguments.length&&"object"==typeof header&&null!==header?header:{header:header,msg:msg,primary:{label:primaryLabel,cb:primary},option:{label:optionLabel,cb:option}};var dialog=jsxc.gui.dialog.open(jsxc.gui.template.get("selectionDialog"),{noClose:!0});opt.header?dialog.find("h3").text(opt.header):dialog.find("h3").hide(),opt.msg?dialog.find("p").text(opt.msg):dialog.find("p").hide(),opt.primary&&opt.primary.label&&dialog.find(".btn-primary").text(opt.primary.label),opt.option&&opt.option.label&&dialog.find(".btn-default").text(opt.option.label),opt.primary&&opt.primary.cb&&dialog.find(".btn-primary").click(opt.primary.cb),opt.option&&opt.option.cb&&dialog.find(".btn-default").click(opt.option.cb)},showNotification:function(subject,body,from){var dialog=jsxc.gui.dialog.open(jsxc.gui.template.get("notification"));dialog.find("h3").text(subject),dialog.find(".jsxc_msg").text(body),from?dialog.find(".jsxc_meta").text($.t("from")+" "+from):dialog.find(".jsxc_meta").hide()},changePresence:function(pres,external){!0!==external&&jsxc.storage.setUserItem("presence",pres),jsxc.master&&jsxc.xmpp.sendPres(),$("#jsxc_presence > span").text($("#jsxc_presence .jsxc_inner ul .jsxc_"+pres).text()),jsxc.gui.updatePresence("own",pres)},updatePresence:function(bid,pres){"own"===bid&&("dnd"===pres?($("#jsxc_menu .jsxc_muteNotification").addClass("jsxc_disabled"),jsxc.notification.muteSound(!0)):($("#jsxc_menu .jsxc_muteNotification").removeClass("jsxc_disabled"),jsxc.options.get("muteNotification")||jsxc.notification.unmuteSound(!0))),$('[data-bid="'+bid+'"]').each(function(){var el=$(this);el.attr("data-status",pres),el.hasClass("jsxc_statusIndicator")||(el=el.find(".jsxc_statusIndicator")),el.attr("data-status",pres),el.removeClass("jsxc_"+jsxc.CONST.STATUS.join(" jsxc_")).addClass("jsxc_"+pres)})},unreadMsg:function(bid){var winData=jsxc.storage.getUserItem("window",bid)||{},count=winData&&winData.unread||0;count=!0===count?1:count+1,winData.unread=count,jsxc.storage.setUserItem("window",bid,winData);var total=jsxc.storage.getUserItem("unreadMsg")||0;total++,jsxc.storage.setUserItem("unreadMsg",total),jsxc.gui.favicon&&jsxc.gui.favicon.badge(total),jsxc.gui._unreadMsg(bid,count)},_unreadMsg:function(bid,count){var win=jsxc.gui.window.get(bid);if("number"!=typeof count){var winData=jsxc.storage.getUserItem("window",bid);count=!0===(count=winData&&winData.unread||1)?1:count}var el=jsxc.gui.roster.getItem(bid).add(win);el.addClass("jsxc_unreadMsg"),el.find(".jsxc_unread").text(count)},readMsg:function(bid){var win=jsxc.gui.window.get(bid),winData=jsxc.storage.getUserItem("window",bid),count=winData&&winData.unread||0;count=!0===count?0:count;var el=jsxc.gui.roster.getItem(bid).add(win);if(el.removeClass("jsxc_unreadMsg"),el.find(".jsxc_unread").text(0),0<count){var total=jsxc.storage.getUserItem("unreadMsg")||0;total-=count,jsxc.storage.setUserItem("unreadMsg",total),jsxc.gui.favicon&&jsxc.gui.favicon.badge(total),jsxc.storage.updateUserItem("window",bid,"unread",0)}},detectUriScheme:function(container){(container=$(container||"body")).find("a[href^='xmpp:']").each(function(){var action,element=$(this),href=element.attr("href").replace(/^xmpp:/,""),jid=href.split("?")[0],params={};if(element.attr("data-bid",jsxc.jidToBid(jid)),jsxc.gui.update(jsxc.jidToBid(jid)),href.indexOf("?")<0)action="message";else{var i,key,value,pairs=href.substring(href.indexOf("?")+1).split(";");for(action=pairs[0],i=1;i<pairs.length;i++)key=pairs[i].split("=")[0],value=0<pairs[i].indexOf("=")?pairs[i].substring(pairs[i].indexOf("=")+1):null,params[decodeURIComponent(key)]=decodeURIComponent(value)}"function"==typeof jsxc.gui.queryActions[action]&&(element.addClass("jsxc_uriScheme jsxc_uriScheme_"+action),element.off("click").click(function(ev){return ev.stopPropagation(),jsxc.xmpp.conn&&jsxc.xmpp.conn.connected?jsxc.gui.queryActions[action].call(jsxc,jid,params):jsxc.gui.showNotification($.t("no_connection"),$.t("You_have_to_go_online_")),!1}))})},detectEmail:function(container){(container=$(container||"body")).find('a[href^="mailto:"],a[href^="xmpp:"]').each(function(){var spot=$("<span>X</span>").addClass("jsxc_spot"),href=$(this).attr("href").replace(/^ *(mailto|xmpp):/,"").trim();if(""!==href&&href!==Strophe.getBareJidFromJid(jsxc.storage.getItem("jid"))){var bid=jsxc.jidToBid(href),self=$(this),s=self.prev();s.hasClass("jsxc_spot")||(s=spot.clone().attr("data-bid",bid),self.before(s)),s.off("click"),jsxc.storage.getUserItem("buddy",bid)?(jsxc.gui.update(bid),s.click(function(){return jsxc.gui.window.open(bid),!1})):s.click(function(){return jsxc.gui.showContactDialog(href),!1})}})},detectGeoUri:function(container){function decimalToDms(deg){var d=Math.floor(deg),minfloat=60*(deg-d),m=Math.floor(minfloat),secfloat=60*(minfloat-m),s=Math.round(10*secfloat)/10;return 60===s&&(m++,s=0),60===m&&(d++,m=0),d+"°"+m+"'"+s+'"'}(container=$(container)).find('a[href^="geo:"]').each(function(){var matches=$(this).attr("href").match(jsxc.CONST.REGEX.GEOURI),latitude=matches[1],longitude=matches[2],accuracy=matches[3],osmUrl="https://www.openstreetmap.org/?mlat="+latitude+"&mlon="+longitude+"#map=16/"+latitude+"/"+longitude,label="OSM: "+function(latitude,longitude){return decimalToDms(latitude)+(0<latitude?"N":"S")+" "+decimalToDms(longitude)+(0<longitude?"E":"W")}(latitude,longitude);accuracy&&(label+=" (±"+Math.round(10*accuracy)/10+"m)"),$(this).addClass("jsxc_location"),$(this).attr("title",matches[0]),$(this).attr("href",osmUrl),$(this).attr("target","_blank"),$(this).text(label)})},avatarPlaceholder:function(el,seed,text){text=text||seed;var options=jsxc.options.get("avatarplaceholder")||{},hash=jsxc.hashStr(seed),hue=Math.abs(hash)%360,saturation=options.saturation||90,lightness=options.lightness||65;el.css({"background-color":"hsl("+hue+", "+saturation+"%, "+lightness+"%)",color:"#fff","font-weight":"bold","text-align":"center","line-height":el.height()+"px","font-size":.6*el.height()+"px"}),"string"==typeof text&&0<text.length&&el.text(text[0].toUpperCase())},shortnameToImage:function(str){str=str.replace(jsxc.gui.regShortNames,function(shortname){if(!(void 0!==shortname&&""!==shortname&&(shortname in jsxc.gui.emoticonList.emojione||shortname in jsxc.gui.emoticonList.core)))return shortname;var src,filename;jsxc.gui.emoticonList.core[shortname]?(filename=jsxc.gui.emoticonList.core[shortname][jsxc.gui.emoticonList.core[shortname].length-1].replace(/^:([^:]+):$/,"$1"),src=jsxc.options.root+"/img/emotions/"+filename+".svg"):jsxc.gui.emoticonList.emojione[shortname]&&(filename=jsxc.gui.emoticonList.emojione[shortname].fname,src=jsxc.options.root+"/lib/emojione/assets/svg/"+filename+".svg");var div=$("<span>");return div.addClass("jsxc_emoticon"),div.css("background-image","url("+src+")"),div.attr("title",shortname),div.prop("outerHTML")});var obj=$("<div>"+str+"</div>");return 1===obj.find(".jsxc_emoticon").length&&0===obj.text().replace(/ /,"").length&&1===obj.find("*").length&&(obj.find(".jsxc_emoticon").addClass("jsxc_large"),str=obj.prop("outerHTML")),str},restore:function(){jsxc.restoreRoster(),jsxc.restoreWindows(),jsxc.restoreCompleted=!0,$(document).trigger("restoreCompleted.jsxc"),jsxc.changeUIState(jsxc.CONST.UISTATE.READY)}},jsxc.gui.roster={ready:!1,loaded:!1,init:function(){$(jsxc.options.rosterAppend+":first").append($(jsxc.gui.template.get("roster"))),jsxc.options.get("hideOffline")&&($("#jsxc_menu .jsxc_hideOffline").text($.t("Show_offline")),$("#jsxc_buddylist").addClass("jsxc_hideOffline")),$("#jsxc_menu .jsxc_settings").click(function(){jsxc.gui.showSettings()}),$("#jsxc_menu .jsxc_hideOffline").click(function(){var hideOffline=!jsxc.options.get("hideOffline");hideOffline?$("#jsxc_buddylist").addClass("jsxc_hideOffline"):$("#jsxc_buddylist").removeClass("jsxc_hideOffline"),$(this).text(hideOffline?$.t("Show_offline"):$.t("Hide_offline")),jsxc.options.set("hideOffline",hideOffline)}),jsxc.options.get("muteNotification")&&jsxc.notification.muteSound(),$("#jsxc_menu .jsxc_muteNotification").click(function(){"dnd"!==jsxc.storage.getUserItem("presence")&&(!jsxc.options.get("muteNotification")?jsxc.notification.muteSound():jsxc.notification.unmuteSound())}),$("#jsxc_roster .jsxc_addBuddy").click(function(){jsxc.gui.showContactDialog()}),$("#jsxc_roster .jsxc_onlineHelp").click(function(){window.open(jsxc.options.onlineHelp,"onlineHelp")}),$("#jsxc_roster .jsxc_about").click(function(){jsxc.gui.showAboutDialog()}),$("#jsxc_toggleRoster").click(function(){jsxc.gui.roster.toggle()}),$("#jsxc_presence li").click(function(){var pres=$(this).data("pres");"offline"===pres?jsxc.xmpp.logout(!1):jsxc.gui.changePresence(pres)}),$("#jsxc_buddylist").slimScroll({distance:"3px",height:$("#jsxc_roster").height()-31+"px",width:$("#jsxc_buddylist").width()+"px",color:"#fff",opacity:"0.5"}),$("#jsxc_roster > .jsxc_bottom > div").each(function(){jsxc.gui.toggleList.call($(this))});var rosterState=jsxc.storage.getUserItem("roster")||(jsxc.options.get("loginForm").startMinimized?"hidden":"shown");$("#jsxc_roster").addClass("jsxc_state_"+rosterState),$("#jsxc_windowList").addClass("jsxc_roster_"+rosterState);var pres=jsxc.storage.getUserItem("presence")||"online";$("#jsxc_presence > span").text($("#jsxc_presence .jsxc_"+pres).text()),jsxc.gui.updatePresence("own",pres),jsxc.gui.tooltip("#jsxc_roster"),jsxc.notice.load(),jsxc.gui.roster.ready=!0,$(document).trigger("ready.roster.jsxc",[rosterState]),$(document).trigger("ready-roster-jsxc",[rosterState])},add:function(bid){var data=jsxc.storage.getUserItem("buddy",bid),bud=jsxc.gui.buddyTemplate.clone().attr("data-bid",bid).attr("data-type",data.type||"chat");$("#jsxc_roster > p").remove(),jsxc.gui.roster.insert(bid,bud),bud.click(function(){jsxc.gui.window.open(bid)}),bud.find(".jsxc_msg").click(function(){return jsxc.gui.window.open(bid),!1}),bud.find(".jsxc_rename").click(function(){return jsxc.gui.roster.rename(bid),!1}),"groupchat"!==data.type&&bud.find(".jsxc_delete").click(function(){return jsxc.gui.showRemoveDialog(bid),!1});bud.find(".jsxc_more").click(function(){return bud.trigger("extra.jsxc"),$("body").click(),bud.find(".jsxc_menu").hasClass("jsxc_open")||(bud.find(".jsxc_menu").addClass("jsxc_open"),$("body").one("click",function(){bud.find(".jsxc_menu").removeClass("jsxc_open")})),!1}),bud.find(".jsxc_vcard").click(function(){return jsxc.gui.showVcard(data.jid),!1}),jsxc.gui.update(bid),$("#jsxc_buddylist").slimScroll({scrollTo:"0px"});for(var history=jsxc.storage.getUserItem("history",bid)||[],i=0;history.length>i;){var message=new jsxc.Message(history[i]);if(message.direction!==jsxc.Message.SYS){jsxc.gui.window.setLastMsg(bid,message.msg);break}i++}$(document).trigger("add.roster.jsxc",[bid,data,bud])},getItem:function(bid){return $("#jsxc_buddylist > li[data-bid='"+bid+"']")},insert:function(bid,li){var data=jsxc.storage.getUserItem("buddy",bid),listElements=$("#jsxc_buddylist > li"),insert=!1;data.name||(data.name=bid);var status="both"===data.sub?data.status:-1;listElements.each(function(){var thisStatus="both"===$(this).data("sub")?$(this).data("status"):-1;if($(this).data("name").toLowerCase()>data.name.toLowerCase()&&thisStatus===status||thisStatus<status)return $(this).before(li),!(insert=!0)}),insert||li.appendTo("#jsxc_buddylist")},reorder:function(bid){jsxc.gui.roster.insert(bid,jsxc.gui.roster.remove(bid))},remove:function(bid){return jsxc.gui.roster.getItem(bid).detach()},purge:function(bid){jsxc.master&&(jsxc.storage.removeUserItem("buddy",bid),jsxc.storage.removeUserItem("otr",bid),jsxc.storage.removeUserItem("otr_version_"+bid),jsxc.storage.removeUserItem("chat",bid),jsxc.storage.removeUserItem("window",bid),jsxc.storage.removeUserElement("buddylist",bid),jsxc.storage.removeUserElement("windowlist",bid)),jsxc.gui.window._close(bid),jsxc.gui.roster.remove(bid)},rename:function(bid){var name=jsxc.gui.roster.getItem(bid).find(".jsxc_name"),options=jsxc.gui.roster.getItem(bid).find(".jsxc_lastmsg, .jsxc_more"),input=$('<input type="text" name="name"/>');$("body").click(),options.hide(),name=name.replaceWith(input),input.val(name.text()),input.keypress(function(ev){13===ev.which&&(options.css("display",""),input.replaceWith(name),jsxc.gui.roster._rename(bid,$(this).val()),$("html").off("click"))}),input.click(function(){return!1}),$("html").one("click",function(){options.css("display",""),input.replaceWith(name),jsxc.gui.roster._rename(bid,input.val())})},_rename:function(bid,newname){if(jsxc.master){var d=jsxc.storage.getUserItem("buddy",bid)||{};if("chat"===d.type){var iq=$iq({type:"set"}).c("query",{xmlns:"jabber:iq:roster"}).c("item",{jid:Strophe.getBareJidFromJid(d.jid),name:newname});jsxc.xmpp.conn.sendIQ(iq)}else"groupchat"===d.type&&jsxc.xmpp.bookmarks.add(bid,newname,d.nickname,d.autojoin)}jsxc.storage.updateUserItem("buddy",bid,"name",newname),jsxc.gui.update(bid)},toggle:function(state){var duration,roster=$("#jsxc_roster"),wl=$("#jsxc_windowList");return state||(state=jsxc.storage.getUserItem("roster")===jsxc.CONST.HIDDEN?jsxc.CONST.SHOWN:jsxc.CONST.HIDDEN),"shown"===state&&jsxc.isExtraSmallDevice()&&jsxc.gui.window.hide(),jsxc.storage.setUserItem("roster",state),roster.removeClass("jsxc_state_hidden jsxc_state_shown").addClass("jsxc_state_"+state),wl.removeClass("jsxc_roster_hidden jsxc_roster_shown").addClass("jsxc_roster_"+state),duration=1e3*parseFloat(roster.css("transitionDuration")||0),setTimeout(function(){jsxc.gui.updateWindowListSB()},duration),$(document).trigger("toggle.roster.jsxc",[state,duration]),duration},noConnection:function(){$("#jsxc_roster").addClass("jsxc_noConnection"),$("#jsxc_buddylist").empty(),$("#jsxc_roster > p").remove(),$("<p>"+$.t("no_connection")+"</p>").append(" <a>"+$.t("relogin")+"</a>").click(function(){jsxc.storage.removeUserItem("forcedLogout"),jsxc.relogin()||jsxc.gui.showLoginBox()}).appendTo("#jsxc_roster")},empty:function(){var text=$("<p>"+$.t("Your_roster_is_empty_add_")+"</p>"),link=text.find("a");link.click(function(){jsxc.gui.showContactDialog()}),text.append(link),text.append("."),$("#jsxc_roster").prepend(text)}},jsxc.gui.dialog={open:function(data,o){var opt=$.extend({name:""},o),src=$('<div data-name="'+opt.name+'" id="jsxc_dialog" />').append(data);return $.magnificPopup.open({items:{src:src},type:"inline",modal:opt.noClose,callbacks:{beforeClose:function(){$(document).trigger("cleanup.dialog.jsxc")},afterClose:function(){$(document).trigger("close.dialog.jsxc")},open:function(){$("#jsxc_dialog .jsxc_close").click(function(ev){ev.preventDefault(),jsxc.gui.dialog.close()}),$("#jsxc_dialog form").each(function(){$(this).find("button[data-jsxc-loading-text]").each(function(){var btn=$(this);btn.on("btnloading.jsxc",function(){btn.prop("disabled")||(btn.prop("disabled",!0),btn.data("jsxc_value",btn.text()),btn.text(btn.attr("data-jsxc-loading-text")))}),btn.on("btnfinished.jsxc",function(){btn.prop("disabled")&&(btn.prop("disabled",!1),btn.text(btn.data("jsxc_value")))})})}),jsxc.gui.dialog.resize(),$(document).trigger("complete.dialog.jsxc")}}}),$("#jsxc_dialog")},close:function(name){jsxc.debug("close dialog"),"string"==typeof name&&0<name.length&&!jsxc.el_exists("#jsxc_dialog[data-name="+name+"]")||$.magnificPopup.close()},resize:function(){}},jsxc.gui.window={init:function(bid){if(0<jsxc.gui.window.get(bid).length)return jsxc.gui.window.get(bid);var win=jsxc.gui.windowTemplate.clone().attr("data-bid",bid).appendTo("#jsxc_windowList > ul"),data=jsxc.storage.getUserItem("buddy",bid);win.data("jid",data.jid);var textinputBlurTimeout;function resizeTextarea(){$(this).data("originalHeight")||$(this).data("originalHeight",$(this).outerHeight()),$(this).outerHeight()<this.scrollHeight-1&&$(this).val()&&$(this).height(1.5*$(this).data("originalHeight"))}if(win.find(".jsxc_more").click(function(){return win.trigger("extra.jsxc"),$("body").click(),win.find(".jsxc_menu").hasClass("jsxc_open")||(win.find(".jsxc_menu").addClass("jsxc_open"),$("body").one("click",function(){win.find(".jsxc_menu").removeClass("jsxc_open")})),!1}),win.find(".jsxc_menu").click(function(){$("body").click()}),win.find(".jsxc_verification").click(function(){jsxc.gui.showVerification(bid)}),win.find(".jsxc_fingerprints").click(function(){jsxc.gui.showFingerprints(bid)}),win.find(".jsxc_transfer").click(function(){jsxc.otr.toggleTransfer(bid)}),win.find(".jsxc_bar").click(function(){jsxc.gui.window.toggle(bid)}),win.find(".jsxc_close").click(function(){jsxc.gui.window.close(bid)}),win.find(".jsxc_clear").click(function(){jsxc.gui.window.clear(bid)}),win.find(".jsxc_sendFile").click(function(){$("body").click(),$(this).hasClass("jsxc_disabled")||jsxc.gui.window.sendFile(bid)}),win.find(".jsxc_sendLocation").click(function(){$("body").click(),jsxc.gui.window.sendLocation(bid)}),win.find(".jsxc_tools").click(function(){return!1}),win.find(".jsxc_textinput").keyup(function(ev){var body=$(this).val();13===ev.which&&!ev.shiftKey&&body||resizeTextarea.call(this),13!==ev.which&&jsxc.xmpp.chatState.startComposing(bid),13!==ev.which||ev.shiftKey||(body="",jsxc.xmpp.chatState.endComposing(bid)),jsxc.storage.updateUserItem("window",bid,"text",body),27===ev.which&&jsxc.gui.window.close(bid)}).keypress(function(ev){13===ev.which&&!ev.shiftKey&&$(this).val()&&(jsxc.gui.window.postMessage({bid:bid,direction:jsxc.Message.OUT,msg:$(this).val()}),$(this).css("height","").val(""),ev.preventDefault())}).focus(function(){textinputBlurTimeout&&clearTimeout(textinputBlurTimeout),jsxc.gui.readMsg(bid),resizeTextarea.call(this)}).blur(function(){var self=$(this);textinputBlurTimeout=setTimeout(function(){self.css("height","")},1200)}).mouseenter(function(){$("#jsxc_windowList").data("isOver",!0)}).mouseleave(function(){$("#jsxc_windowList").data("isOver",!1)}),win.find(".jsxc_textarea").click(function(){"function"!=typeof getSelection||getSelection().toString()||win.find(".jsxc_textinput").focus()}),win.find(".jsxc_textarea").slimScroll({height:"234px",distance:"3px"}),win.find(".jsxc_name").disableSelection(),win.find(".slimScrollDiv").resizable({handles:"w, nw, n",minHeight:234,minWidth:250,resize:function(event,ui){jsxc.gui.window.resize(win,ui)},start:function(){win.removeClass("jsxc_normal")},stop:function(){win.addClass("jsxc_normal")}}),win.find(".jsxc_window").css("bottom",-1*win.find(".jsxc_fade").height()),$.inArray(bid,jsxc.storage.getUserItem("windowlist"))<0){var wl=jsxc.storage.getUserItem("windowlist")||[];wl.push(bid),jsxc.storage.setUserItem("windowlist",wl),jsxc.storage.setUserItem("window",bid,{minimize:!0,text:"",unread:0}),jsxc.gui.window.hide(bid)}else jsxc.storage.getUserItem("window",bid).unread&&jsxc.gui._unreadMsg(bid);return $.each(jsxc.gui.emotions,function(i,val){var ins=val[0].split(" ")[0],li=$("<li>");li.append(jsxc.gui.shortnameToImage(":"+val[1]+":")),li.find("div").attr("title",ins),li.click(function(){win.find(".jsxc_textinput").val(win.find(".jsxc_textinput").val()+ins),win.find(".jsxc_textinput").focus()}),win.find(".jsxc_emoticons ul").prepend(li)}),jsxc.gui.toggleList.call(win.find(".jsxc_emoticons")),jsxc.gui.window.restoreChat(bid),jsxc.gui.update(bid),jsxc.gui.updateWindowListSB(),jsxc.master&&!jsxc.otr.objects[bid]?jsxc.otr.create(bid):jsxc.otr.enable(bid),$(document).trigger("init.window.jsxc",[win]),win},resize:function(win,ui,outer){var bid;if("object"==typeof win)bid=win.attr("data-bid");else{if("string"!=typeof win)return void jsxc.warn("jsxc.gui.window.resize has to be called either with bid or window object.");bid=win,win=jsxc.gui.window.get(bid)}win.attr("data-default-height")||win.attr("data-default-height",win.find(".ui-resizable").height()),win.attr("data-default-width")||win.attr("data-default-width",win.find(".ui-resizable").width());var outer_height_diff=outer?win.find(".jsxc_window").outerHeight()-win.find(".ui-resizable").height():0;ui=$.extend({size:{width:parseInt(win.attr("data-default-width")),height:parseInt(win.attr("data-default-height"))+outer_height_diff}},ui||{}),outer&&(ui.size.height-=outer_height_diff),win.find(".slimScrollDiv").css({width:ui.size.width,height:ui.size.height}),win.width(ui.size.width),win.find(".jsxc_textarea").slimScroll({height:ui.size.height}),$(document).trigger("resize.window.jsxc",[win,bid,ui.size])},fullsize:function(bid){var win=jsxc.gui.window.get(bid),size=jsxc.options.viewport.getSize();size.width-=10,size.height-=win.find(".jsxc_bar").outerHeight()+win.find(".jsxc_textinput").outerHeight(),jsxc.gui.window.resize(win,{size:size})},get:function(id){return $("li.jsxc_windowItem[data-bid='"+jsxc.jidToBid(id)+"']")},open:function(bid){var win=jsxc.gui.window.init(bid);return jsxc.gui.window.show(bid),jsxc.gui.window.highlight(bid),win},close:function(bid){0!==jsxc.gui.window.get(bid).length?(jsxc.storage.removeUserElement("windowlist",bid),jsxc.storage.removeUserItem("window",bid),jsxc.storage.getUserItem("buddylist").indexOf(bid)<0&&(jsxc.storage.removeUserItem("buddy",bid),jsxc.storage.removeUserItem("chat",bid)),jsxc.gui.window._close(bid)):jsxc.warn("Want to close a window, that is not open.")},_close:function(bid){jsxc.gui.window.get(bid).remove(),jsxc.gui.updateWindowListSB()},toggle:function(bid){var win=jsxc.gui.window.get(bid);0!==win.parents("#jsxc_windowList").length&&(win.hasClass("jsxc_min")?jsxc.gui.window.show(bid):jsxc.gui.window.hide(bid),jsxc.gui.updateWindowListSB())},show:function(bid){return jsxc.storage.updateUserItem("window",bid,"minimize",!1),jsxc.gui.window._show(bid)},_show:function(bid){var win=jsxc.gui.window.get(bid),duration=0;jsxc.isExtraSmallDevice()&&(0<=parseFloat($("#jsxc_roster").css("right"))&&(duration=jsxc.gui.roster.toggle()),jsxc.gui.window.hide(),jsxc.gui.window.fullsize(bid)),win.removeClass("jsxc_min").addClass("jsxc_normal"),win.find(".jsxc_window").css("bottom","0"),setTimeout(function(){var padding=$("#jsxc_windowListSB").width(),innerWidth=$("#jsxc_windowList>ul").width(),outerWidth=$("#jsxc_windowList").width()-padding;if(outerWidth<innerWidth){var offset=parseInt($("#jsxc_windowList>ul").css("right")),width=win.outerWidth(!0),right=innerWidth-win.position().left-width+offset,left=outerWidth-(innerWidth-win.position().left)-offset;left<0&&jsxc.gui.scrollWindowListBy(-1*left),right<0&&jsxc.gui.scrollWindowListBy(right)}},duration),jsxc.gui.window.scrollDown(bid),jsxc.restoreCompleted&&win.find(".jsxc_textinput").focus(),win.trigger("show.window.jsxc")},hide:function(bid){var hide=function(bid){jsxc.storage.updateUserItem("window",bid,"minimize",!0),jsxc.gui.window._hide(bid)};bid?hide(bid):$("#jsxc_windowList > ul > li").each(function(){var el=$(this);el.hasClass("jsxc_min")||hide(el.attr("data-bid"))})},_hide:function(bid){var win=jsxc.gui.window.get(bid);win.removeClass("jsxc_normal").addClass("jsxc_min"),win.find(".jsxc_window").css("bottom",-1*win.find(".jsxc_fade").height()),win.trigger("hidden.window.jsxc")},highlight:function(bid){var el=jsxc.gui.window.get(bid).find(" .jsxc_bar");el.is(":animated")||el.effect("highlight",{color:"orange"},2e3)},scrollDown:function(bid){var chat=jsxc.gui.window.get(bid).find(".jsxc_textarea");0!==chat.length&&chat.slimScroll({scrollTo:chat.get(0).scrollHeight+"px"})},postMessage:function(message){"object"!=typeof message||message instanceof jsxc.Message||(message=new jsxc.Message(message));var data=jsxc.storage.getUserItem("buddy",message.bid);!message.htmlMsg&&message.msg&&(message.htmlMsg=message.msg),void 0===message.msg&&(message.msg=""),message.msg=jsxc.removeHTML(message.msg),message.msg=jsxc.escapeHTML(message.msg),message.direction===jsxc.Message.OUT&&data.msgstate===OTR.CONST.MSGSTATE_FINISHED&&!0!==message.forwarded&&(message.direction=jsxc.Message.SYS,message.msg=$.t("your_message_wasnt_send_please_end_your_private_conversation")),message.direction===jsxc.Message.OUT&&data.msgstate===OTR.CONST.MSGSTATE_FINISHED&&(message.direction="sys",message.msg=$.t("unencrypted_message_received")+" "+message.msg),message.encrypted="boolean"==typeof message.encrypted?message.encrypted:data.msgstate===OTR.CONST.MSGSTATE_ENCRYPTED;try{message.save()}catch(err){jsxc.warn("Unable to save message.",err),message=new jsxc.Message({msg:"Unable to save that message. Please clear some chat histories.",direction:jsxc.Message.SYS})}return"in"!==message.direction||jsxc.gui.window.get(message.bid).find(".jsxc_textinput").is(":focus")||(jsxc.gui.unreadMsg(message.bid),$(document).trigger("postmessagein.jsxc",[message.bid,message.htmlMsg])),message.direction===jsxc.Message.OUT&&jsxc.master&&!0!==message.forwarded&&message.htmlMsg&&jsxc.xmpp.sendMessage(message),jsxc.gui.window._postMessage(message),"out"===message.direction&&"?"===message.msg&&!1!==jsxc.options.get("theAnswerToAnything")&&(void 0===jsxc.options.get("theAnswerToAnything")||100*Math.random()%42<1)&&(jsxc.options.set("theAnswerToAnything",!0),jsxc.gui.window.postMessage(new jsxc.Message({bid:message.bid,direction:jsxc.Message.SYS,msg:"42"}))),message},_postMessage:function(message,restore){var bid=message.bid,win=jsxc.gui.window.get(bid),msg=message.msg,direction=message.direction,uid=message._uid;win.find(".jsxc_textinput").is(":not(:focus)")&&direction===jsxc.Message.IN&&!restore&&jsxc.gui.window.highlight(bid),msg=(msg=(msg=msg.replace(jsxc.CONST.REGEX.URL,function(url){return'<a href="'+(url.match(/^https?:\/\//i)?url:"http://"+url)+'" target="_blank">'+url+"</a>"})).replace(new RegExp("(xmpp:)?("+jsxc.CONST.REGEX.JID.source+")(\\?[^\\s]+\\b)?","i"),function(match,protocol,jid,action){return"xmpp:"===protocol?("string"==typeof action&&(jid+=action),'<a href="xmpp:'+jid+'">xmpp:'+jid+"</a>"):'<a href="mailto:'+jid+'" target="_blank">mailto:'+jid+"</a>"})).replace(jsxc.CONST.REGEX.GEOURI,function(uri){var a=$("<a>");return a.attr("href",uri),a.attr("target","_blank"),a.text(uri),$("<wrapper>").append(a).html()}),$.each(jsxc.gui.emotions,function(i,val){msg=msg.replace(val[2],":"+val[1]+":")}),msg=(msg=jsxc.gui.shortnameToImage(msg)).replace(/(\r\n|\r|\n)/g,"<br />");var bidData=jsxc.storage.getUserItem("buddy",bid)||{};"in"===direction&&(msg=msg.replace(/^\/me /,'<i title="/me">'+jsxc.removeHTML(bidData.name||bid)+"</i> ")),msg.match(/^\?OTR([:,|?]|[?v0-9x]+)/)&&(msg='<i title="'+msg+'">'+$.t("Unreadable_OTR_message")+"</i>");var msgDiv=$("<div>"),msgTsDiv=$("<div>");if(msgDiv.addClass("jsxc_chatmessage jsxc_"+direction),msgDiv.attr("id",uid.replace(/:/g,"-")),msgDiv.html("<div>"+msg+"</div>"),msgTsDiv.addClass("jsxc_timestamp"),msgTsDiv.text(jsxc.getFormattedTime(message.stamp)),message.isReceived()?msgDiv.addClass("jsxc_received"):msgDiv.removeClass("jsxc_received"),message.forwarded?msgDiv.addClass("jsxc_forwarded"):msgDiv.removeClass("jsxc_forwarded"),message.encrypted?msgDiv.addClass("jsxc_encrypted"):msgDiv.removeClass("jsxc_encrypted"),message.error?msgDiv.addClass("jsxc_error"):msgDiv.removeClass("jsxc_error"),msgDiv.attr("title",message.error),msgDiv.attr("data-error-msg",message.error),message.attachment&&message.attachment.name){var attachment=$("<div>");attachment.addClass("jsxc_attachment"),attachment.addClass("jsxc_"+message.attachment.type.replace(/\//,"-")),attachment.addClass("jsxc_"+message.attachment.type.replace(/^([^/]+)\/.*/,"$1")),!1===message.attachment.persistent&&attachment.addClass("jsxc_notPersistent"),message.attachment.data&&attachment.addClass("jsxc_data"),message.attachment.type.match(/^image\//)&&message.attachment.thumbnail?$('<img alt="preview">').attr("src",message.attachment.thumbnail).attr("title",message.attachment.name).appendTo(attachment):attachment.text(message.attachment.name),message.attachment.data&&((attachment=$("<a>").append(attachment)).attr("href",message.attachment.data),attachment.attr("download",message.attachment.name),message.attachment.data===message.msg&&msgDiv.find("div").first().empty()),msgDiv.find("div").first().append(attachment)}"sys"===direction?jsxc.gui.window.get(bid).find(".jsxc_textarea").append('<div class="jsxc_clear"/>'):void 0!==message.stamp&&msgDiv.append(msgTsDiv),"sys"!==direction&&jsxc.gui.window.setLastMsg(bid,msg);var currentMessageElement=jsxc.Message.getDOM(uid);if(0<currentMessageElement.length?(currentMessageElement.attr("data-queryId")&&msgDiv.attr("data-queryId",currentMessageElement.attr("data-queryId")),currentMessageElement.replaceWith(msgDiv)):win.find(".jsxc_textarea").append(msgDiv),"object"==typeof message.sender&&null!==message.sender){var title="",avatarDiv=$("<div>");if(avatarDiv.addClass("jsxc_avatar").prependTo(msgDiv),"string"==typeof message.sender.jid){msgDiv.attr("data-bid",jsxc.jidToBid(message.sender.jid));var data=jsxc.storage.getUserItem("buddy",jsxc.jidToBid(message.sender.jid))||{};jsxc.gui.avatar.update(msgDiv,jsxc.jidToBid(message.sender.jid),data.avatar),title=jsxc.jidToBid(message.sender.jid)}"string"==typeof message.sender.name&&(msgDiv.attr("data-name",message.sender.name),"string"!=typeof message.sender.jid&&jsxc.gui.avatarPlaceholder(avatarDiv,message.sender.name),""!==title&&(title="\n"+title),title=message.sender.name+title,msgTsDiv.text(msgTsDiv.text()+" "+message.sender.name)),avatarDiv.attr("title",jsxc.escapeHTML(title)),0<msgDiv.prev().length&&msgDiv.prev().find(".jsxc_avatar").attr("title")===avatarDiv.attr("title")&&avatarDiv.css("visibility","hidden")}jsxc.gui.detectUriScheme(win),jsxc.gui.detectEmail(win),jsxc.gui.detectGeoUri(win),message.forwarded||jsxc.gui.window.scrollDown(bid)},setText:function(bid,text){jsxc.gui.window.get(bid).find(".jsxc_textinput").val(text)},setLastMsg:function(bid,msg){var lastMsgTextElement=$('[data-bid="'+bid+'"]').find(".jsxc_lastmsg .jsxc_text");lastMsgTextElement.html(msg),lastMsgTextElement.find("a").each(function(){$(this).replaceWith("<span>"+$(this).text()+"</span>")})},restoreChat:function(bid){var chat=jsxc.storage.getUserItem("chat",bid);if(chat){for(;null!==chat&&0<chat.length;){var c=chat.pop();c.bid=bid,c._uid=c.uid,delete c.uid;var message=new jsxc.Message(c);message.save(),jsxc.gui.window._postMessage(message,!0)}jsxc.storage.removeUserItem("chat",bid)}for(var history=jsxc.storage.getUserItem("history",bid);null!==history&&0<history.length;){var uid=history.pop();jsxc.gui.window._postMessage(new jsxc.Message(uid),!0)}},clear:function(bid){jsxc.storage.removeUserItem("chat",bid),(jsxc.storage.getUserItem("history",bid)||[]).map(function(id){jsxc.storage.removeUserItem("msg",id)}),jsxc.storage.setUserItem("history",bid,[]);var buddyData=jsxc.storage.getUserItem("buddy",bid)||{};delete buddyData.lastArchiveUid,delete buddyData.archiveExhausted,jsxc.storage.setUserItem("buddy",bid,buddyData);var win=jsxc.gui.window.get(bid);0<win.length&&(win.find(".jsxc_textarea").empty(),win.find(".jsxc_textarea").scroll())},receivedMessage:function(bid,uid){jsxc.warn("Using deprecated receivedMessage."),new jsxc.Message(uid).received()},updateProgress:function(message,sent,size){var div=message.getDOM(),span=div.find(".jsxc_timestamp span");0===span.length&&(div.find(".jsxc_timestamp").append("<span>"),span=div.find(".jsxc_timestamp span")),span.text(" "+Math.round(sent/size*100)+"%"),sent===size&&span.remove()},showOverlay:function(bid,content,allowClose){var win=jsxc.gui.window.get(bid);win.find(".jsxc_overlay .jsxc_body").empty().append(content),win.find(".jsxc_overlay .jsxc_close").off("click").click(function(){jsxc.gui.window.hideOverlay(bid)}),!0!==allowClose?win.find(".jsxc_overlay .jsxc_close").hide():win.find(".jsxc_overlay .jsxc_close").show(),win.addClass("jsxc_showOverlay")},hideOverlay:function(bid){jsxc.gui.window.get(bid).removeClass("jsxc_showOverlay")},selectResource:function(bid,text,cb,res){if(res=res||jsxc.storage.getUserItem("res",bid)||[],cb=cb||function(){},0<res.length){var i,li,content=$("<div>"),list=$("<ul>");for(i=0;i<res.length;i++)(li=$("<li>")).append($("<a>").text(res[i])),li.appendTo(list);list.find("a").click(function(ev){ev.preventDefault(),jsxc.gui.window.hideOverlay(bid),cb({status:"selected",result:$(this).text()})}),text&&$("<p>").text(text).appendTo(content),list.appendTo(content),jsxc.gui.window.showOverlay(bid,content)}else cb({status:"unavailable"})},smpRequest:function(bid,question){var content=$("<div>"),p=$("<p>");p.text($.t("smpRequestReceived")),p.appendTo(content);var abort=$("<button>");abort.text($.t("Abort")),abort.click(function(){jsxc.gui.window.hideOverlay(bid),jsxc.storage.removeUserItem("smp",bid),jsxc.master&&jsxc.otr.objects[bid]&&jsxc.otr.objects[bid].sm.abort()}),abort.appendTo(content);var verify=$("<button>");verify.text($.t("Verify")),verify.addClass("jsxc_btn jsxc_btn-primary"),verify.click(function(){jsxc.gui.window.hideOverlay(bid),jsxc.otr.onSmpQuestion(bid,question)}),verify.appendTo(content),jsxc.gui.window.showOverlay(bid,content)},sendFile:function(jid){jsxc.fileTransfer.startGuiAction(jid)},sendLocation:function(bid){navigator&&navigator.geolocation&&navigator.geolocation.getCurrentPosition&&navigator.geolocation.getCurrentPosition(function(position){var coords=position.coords,geouri="geo:"+coords.latitude+","+coords.longitude+";u="+coords.accuracy;jsxc.gui.window.postMessage({bid:bid,direction:jsxc.Message.OUT,msg:geouri})},function(error){jsxc.debug("Couldnt get location",error),jsxc.gui.window.postMessage({bid:bid,direction:jsxc.Message.SYS,msg:$.t("error_location_not_provided")})})}},jsxc.gui.template={},jsxc.gui.template.get=function(name,bid,msg){var ph={my_priv_fingerprint:jsxc.storage.getUserItem("priv_fingerprint")?jsxc.storage.getUserItem("priv_fingerprint").replace(/(.{8})/g,"$1 "):$.t("not_available"),my_jid:jsxc.storage.getItem("jid")||"",my_node:Strophe.getNodeFromJid(jsxc.storage.getItem("jid")||"")||"",root:jsxc.options.root,app_name:jsxc.options.app_name,version:jsxc.version};if(bid){var data=jsxc.storage.getUserItem("buddy",bid);$.extend(ph,{bid_priv_fingerprint:data&&data.fingerprint?data.fingerprint.replace(/(.{8})/g,"$1 "):$.t("not_available"),bid_jid:bid,bid_name:data&&data.name?jsxc.escapeHTML(data.name):bid})}msg&&$.extend(ph,{msg:msg});var ret=jsxc.gui.template[name];return"string"==typeof ret?(ret=ret.replace(/\{\{root\}\}/g,ph.root),(ret=$("<div>"+ret+"</div>")).find("[data-var]").each(function(){var key=$(this).attr("data-var"),val="string"==typeof ph[key]?ph[key]:"(Unknown placeholder: "+key+")";"INPUT"===$(this).prop("tagName").toUpperCase()?$(this).val(val):$(this).text(val)}),(ret=ret.find(">*")).localize(ph),ret):(jsxc.debug("Template not available: "+name),name)},jsxc.fileTransfer={},jsxc.fileTransfer.formatByte=function(byte){var i,s=["","KB","MB","GB","TB"];for(i=1;i<s.length&&!(byte<1024);i++)byte/=1024;return Math.round(10*byte)/10+s[i-1]},jsxc.fileTransfer.startGuiAction=function(jid){var bid=jsxc.jidToBid(jid);Strophe.getResourceFromJid(jid)||jsxc.xmpp.httpUpload.ready?jsxc.fileTransfer.showFileSelection(jid):jsxc.fileTransfer.isWebrtcCapable(bid)?jsxc.fileTransfer.selectResource(bid,jsxc.fileTransfer.startGuiAction):jsxc.gui.window.postMessage({bid:bid,direction:jsxc.Message.SYS,msg:$.t("No_proper_file_transfer_method_available")})},jsxc.fileTransfer.selectResource=function(bid,success_cb,error_cb){var jid=jsxc.gui.window.get(bid).data("jid"),res=Strophe.getResourceFromJid(jid),fileCapableRes=jsxc.webrtc.getCapableRes(jid,jsxc.webrtc.reqFileFeatures),resources=Object.keys(jsxc.storage.getUserItem("res",bid))||[];null===res&&1===resources.length&&1===fileCapableRes.length?(res=fileCapableRes[0],success_cb(jid=bid+"/"+res)):0<=fileCapableRes.indexOf(res)?success_cb(bid+"/"+res):fileCapableRes.indexOf(res)<0&&jsxc.gui.window.selectResource(bid,$.t("Your_contact_uses_multiple_clients_"),function(data){"unavailable"===data.status?(jsxc.gui.window.hideOverlay(bid),"function"==typeof error_cb&&error_cb()):"selected"===data.status&&success_cb(bid+"/"+data.result)},fileCapableRes)},jsxc.fileTransfer.showFileSelection=function(jid){var bid=jsxc.jidToBid(jid),msg=$('<div><div><label><input type="file" name="files" /><label></div></div>');msg.addClass("jsxc_chatmessage"),jsxc.gui.window.showOverlay(bid,msg,!0),msg.find("label").click(),msg.find('[type="file"]').change(function(ev){var file=ev.target.files[0];file&&jsxc.fileTransfer.fileSelected(jid,msg,file)})},jsxc.fileTransfer.showFileTooLarge=function(bid,file){var maxSize=jsxc.fileTransfer.formatByte(jsxc.options.get("httpUpload").maxSize),fileSize=jsxc.fileTransfer.formatByte(file.size);jsxc.gui.window.postMessage({bid:bid,direction:jsxc.Message.SYS,msg:$.t("File_too_large")+" ("+fileSize+" > "+maxSize+")"}),jsxc.gui.window.hideOverlay(bid)},jsxc.fileTransfer.fileSelected=function(jid,msg,file){var bid=jsxc.jidToBid(jid),maxSize=(jsxc.options.get("httpUpload")||{}).maxSize||-1;if("webrtc"!==file.transportMethod&&jsxc.xmpp.httpUpload.ready&&0<=maxSize&&file.size>maxSize)return jsxc.debug("File too large for http upload."),void(jsxc.fileTransfer.isWebrtcCapable(bid)?(file.transportMethod="webrtc",jsxc.fileTransfer.selectResource(bid,function(jid){jsxc.fileTransfer.fileSelected(jid,msg,file)},function(){jsxc.fileTransfer.showFileTooLarge(bid,file)})):jsxc.fileTransfer.showFileTooLarge(bid,file));!jsxc.xmpp.httpUpload.ready&&Strophe.getResourceFromJid(jid)&&(file.transportMethod="webrtc");var attachment=$("<div>");if(attachment.addClass("jsxc_attachment"),attachment.addClass("jsxc_"+file.type.replace(/\//,"-")),attachment.addClass("jsxc_"+file.type.replace(/^([^/]+)\/.*/,"$1")),msg.empty().append(attachment),FileReader&&file.type.match(/^image\//)){var img=$('<img alt="preview">').attr("title",file.name);img.attr("src",jsxc.options.get("root")+"/img/loading.gif"),img.appendTo(attachment);var reader=new FileReader;reader.onload=function(){img.attr("src",reader.result)},reader.readAsDataURL(file)}else attachment.text(file.name+" ("+file.size+" byte)");$("<button>").addClass("jsxc_btn jsxc_btn-primary").text($.t("Send")).click(function(){jsxc.gui.window.hideOverlay(bid),msg.remove();var message=jsxc.gui.window.postMessage({bid:bid,direction:"out",attachment:{name:file.name,size:file.size,type:file.type,data:file.type.match(/^image\//)?img.attr("src"):null}});"webrtc"===file.transportMethod?jsxc.webrtc.sendFile(jid,file).sender.on("progress",function(sent,size){jsxc.gui.window.updateProgress(message,sent,size),sent===size&&message.received()}):jsxc.xmpp.httpUpload.sendFile(file,message)}).appendTo(msg),$("<button>").addClass("jsxc_btn jsxc_btn-default").text($.t("Abort")).click(function(){jsxc.gui.window.hideOverlay(bid)}).appendTo(msg)},jsxc.fileTransfer.updateIcons=function(bid){var win=jsxc.gui.window.get(bid);if(win&&0!==win.length&&jsxc.xmpp.conn)if(jsxc.debug("Update file transfer icons for "+bid),jsxc.xmpp.httpUpload.ready)win.find(".jsxc_sendFile").removeClass("jsxc_disabled");else if(jsxc.fileTransfer.isWebrtcCapable(bid)){var jid=win.data("jid"),res=Strophe.getResourceFromJid(jid),fileCapableRes=jsxc.webrtc.getCapableRes(bid,jsxc.webrtc.reqFileFeatures),resources=Object.keys(jsxc.storage.getUserItem("res",bid)||{})||[];-1<fileCapableRes.indexOf(res)||null===res&&1===fileCapableRes.length&&1===resources.length?win.find(".jsxc_sendFile").removeClass("jsxc_disabled"):win.find(".jsxc_sendFile").addClass("jsxc_disabled")}else win.find(".jsxc_sendFile").addClass("jsxc_disabled")},jsxc.fileTransfer.isWebrtcCapable=function(bid){return!jsxc.muc.isGroupchat(bid)},$(document).on("update.gui.jsxc",function(ev,bid){jsxc.fileTransfer.updateIcons(bid)}),jsxc.gui.avatar={queue:[],PLACEHOLDER:0,DELAY:300,CHUNKSIZE:20,timeout:null,lastRun:0},jsxc.gui.avatar.update=function(el,jid,aid){var self=jsxc.gui.avatar;if(void 0!==aid){var avatarSrc=jsxc.storage.getUserItem("avatar",aid);if(jsxc.master||avatarSrc||(avatarSrc=self.PLACEHOLDER),null!==avatarSrc)self.set(jid,el,avatarSrc);else{var handler_cb=function(stanza){var src=jsxc.gui.avatar.getPhotoFromVcard(stanza);jsxc.storage.setUserItem("avatar",aid,src),self.set(jid,el,src)},error_cb=function(msg){jsxc.warn("Could not load vcard.",msg),jsxc.storage.setUserItem("avatar",aid,self.PLACEHOLDER),self.set(jid,el,self.PLACEHOLDER)},args=[];args=Strophe.getBareJidFromJid(jid)===Strophe.getBareJidFromJid(jsxc.xmpp.conn.jid)?[handler_cb,error_cb]:[handler_cb,Strophe.getBareJidFromJid(jid),error_cb],jsxc.gui.avatar.queueAction(jid,jsxc.xmpp.conn.vcard.get,args,jsxc.xmpp.conn.vcard)}}else self.set(jid,el,self.PLACEHOLDER)},jsxc.gui.avatar.getPhotoFromVcard=function(stanza){jsxc.debug("vCard",stanza);var src,vCard=$(stanza).find("vCard > PHOTO");if(0===vCard.length)jsxc.debug("No photo provided"),src="0";else if(0<vCard.find("EXTVAL").length)src=vCard.find("EXTVAL").text();else{var img=vCard.find("BINVAL").text();src="data:"+vCard.find("TYPE").text()+";base64,"+img}return src=src.replace(/[\t\r\n\f]/gi,"")},jsxc.gui.avatar.set=function(jid,el,src){if(src===jsxc.gui.avatar.PLACEHOLDER||"0"===src)return"function"==typeof jsxc.options.defaultAvatar?void jsxc.gui.avatar.queueAction(jid,function(){jsxc.options.defaultAvatar.call(el,jid)}):void jsxc.gui.avatarPlaceholder(el.find(".jsxc_avatar"),jid);el.find(".jsxc_avatar").removeAttr("style"),el.find(".jsxc_avatar").css({"background-image":"url("+src+")","text-indent":"999px"})},jsxc.gui.avatar.queueAction=function(jid,fn,args,context){var self=jsxc.gui.avatar,bid=jsxc.jidToBid(jid),state=(jsxc.storage.getUserItem("buddy",bid)||{}).status,index=self.queue.indexOf(bid);-1<index&&self.queue.splice(index,1);var action={fn:fn,args:args||[],context:context||this};0===state?self.queue.push(action):self.queue.unshift(action),jsxc.gui.avatar.processQueue()},jsxc.gui.avatar.processQueue=function(){var self=jsxc.gui.avatar,currentTime=(new Date).getTime();if(currentTime-self.lastRun<self.DELAY)self.timeout||(self.timeout=setTimeout(self.processQueue,self.DELAY));else{var i,action;for(self.lastRun=currentTime,i=0;i<self.CHUNKSIZE;i++)0<self.queue.length&&(action=self.queue.shift()).fn.apply(action.context,action.args);0<self.queue.length?self.timeout=setTimeout(self.processQueue,self.DELAY):self.timeout=null}},jsxc.Message=function(){this._uid=null,this._received=!1,this.encrypted=null,this.forwarded=!1,this.stamp=(new Date).getTime(),this.type=jsxc.Message.PLAIN,"string"==typeof arguments[0]&&0<arguments[0].length&&1===arguments.length?(this._uid=arguments[0],this.load(this._uid)):"object"==typeof arguments[0]&&null!==arguments[0]&&$.extend(this,arguments[0]),this._uid||(this._uid=(new Date).getTime()+":msg")},jsxc.Message.prototype.load=function(uid){var data=jsxc.storage.getUserItem("msg",uid);data||jsxc.debug("Could not load message with uid "+uid),$.extend(this,data)},jsxc.Message.prototype.save=function(){var history,data;if(this.bid&&((history=jsxc.storage.getUserItem("history",this.bid)||[]).indexOf(this._uid)<0?history.length>jsxc.options.get("numberOfMsg")&&jsxc.Message.delete(history.pop()):history=null),Image&&this.attachment&&this.attachment.type.match(/^image\//i)&&this.attachment.data&&!this.attachment.thumbnail){var sHeight,sWidth,sx,sy,canvas=$("<canvas>").get(0);canvas.width=100,canvas.height=100;var ctx=canvas.getContext("2d"),img=new Image;img.src=this.attachment.data,img.height>img.width?(sHeight=img.width,sWidth=img.width,sx=0,sy=(img.height-img.width)/2):(sHeight=img.height,sWidth=img.height,sx=(img.width-img.height)/2,sy=0),ctx.drawImage(img,sx,sy,sWidth,sHeight,0,0,100,100),this.attachment.thumbnail=canvas.toDataURL("image/jpeg",.3),"out"===this.direction&&(this.attachment.data=null)}return this.attachment&&this.attachment.size>jsxc.options.maxStorableSize&&"in"===this.direction&&(jsxc.debug("Attachment to large to store"),data=this.attachment.data,this.attachment.data=null,this.attachment.persistent=!1),jsxc.storage.setUserItem("msg",this._uid,this),history&&(history.unshift(this._uid),jsxc.storage.setUserItem("history",this.bid,history)),data&&this.attachment&&(this.attachment.data=data),this},jsxc.Message.prototype.delete=function(){jsxc.Message.delete(this._uid)},jsxc.Message.prototype.getDOM=function(){return jsxc.Message.getDOM(this._uid)},jsxc.Message.prototype.received=function(){this._received=!0,this.save(),this.getDOM().addClass("jsxc_received")},jsxc.Message.prototype.isReceived=function(){return this._received},jsxc.Message.delete=function(uid){var data=jsxc.storage.getUserItem("msg",uid);if(data&&(jsxc.storage.removeUserItem("msg",uid),data.bid)){var history=jsxc.storage.getUserItem("history",data.bid)||[];history=$.grep(history,function(el){return el!==uid}),jsxc.storage.setUserItem("history",data.bid,history)}},jsxc.Message.getDOM=function(uid){return $("#"+uid.replace(/:/g,"-"))},jsxc.Message.IN="in",jsxc.Message.OUT="out",jsxc.Message.SYS="sys",jsxc.Message.HTML="html",jsxc.Message.PLAIN="plain",jsxc.muc={conn:null,CONST:{AFFILIATION:{ADMIN:"admin",MEMBER:"member",OUTCAST:"outcast",OWNER:"owner",NONE:"none"},ROLE:{MODERATOR:"moderator",PARTICIPANT:"participant",VISITOR:"visitor",NONE:"none"},ROOMSTATE:{INIT:0,ENTERED:1,EXITED:2,AWAIT_DESTRUCTION:3,DESTROYED:4},ROOMCONFIG:{INSTANT:"instant"}},init:function(o){var self=jsxc.muc;self.conn=jsxc.xmpp.conn;var options=o||jsxc.options.get("muc");if(!options||"string"!=typeof options.server)return jsxc.debug("Discover muc service"),void setTimeout(function(){self.conn.disco.items(Strophe.getDomainFromJid(self.conn.jid),null,function(items){$(items).find("item").each(function(){var jid=$(this).attr("jid"),discovered=!1;return self.conn.disco.info(jid,null,function(info){var mucFeature=$(info).find('feature[var="'+Strophe.NS.MUC+'"]'),mucIdentity=$(info).find('identity[category="conference"][type="text"]');0<mucFeature.length&&0<mucIdentity.length&&(jsxc.debug("muc service found",jid),jsxc.options.set("muc",{server:jid,name:$(info).find("identity").attr("name")}),discovered=!0,self.init())}),!discovered})})},1e3);jsxc.gui.roster.ready?self.initMenu():$(document).one("ready.roster.jsxc",jsxc.muc.initMenu),$(document).off("presence.jsxc",jsxc.muc.onPresence),$(document).off("error.presence.jsxc",jsxc.muc.onPresenceError),$(document).on("presence.jsxc",jsxc.muc.onPresence),$(document).on("error.presence.jsxc",jsxc.muc.onPresenceError),self.conn.addHandler(self.onGroupchatMessage,null,"message","groupchat"),self.conn.muc.roomNames=jsxc.storage.getUserItem("roomNames")||[]},initMenu:function(){var li=$("<li>").attr("class","jsxc_joinChat jsxc_groupcontacticon").text($.t("Join_chat"));li.click(jsxc.muc.showJoinChat),0===$("#jsxc_menu .jsxc_joinChat").length&&$("#jsxc_menu ul .jsxc_about").before(li)},showJoinChat:function(r,p){var serverInputTimeout,self=jsxc.muc,dialog=jsxc.gui.dialog.open(jsxc.gui.template.get("joinChat"));dialog.find(".jsxc_join").hide(),"string"==typeof r&&dialog.find("#jsxc_room").val(r),"string"==typeof p&&dialog.find("#jsxc_password").val(p),dialog.find("#jsxc_server").val(jsxc.options.get("muc").server),dialog.find("#jsxc_server").on("input",function(){var self=$(this);serverInputTimeout&&(clearTimeout(serverInputTimeout),dialog.find(".jsxc_inputinfo.jsxc_room").hide()),dialog.find(".jsxc_inputinfo.jsxc_server").hide().text(""),dialog.find("#jsxc_server").removeClass("jsxc_invalid"),self.val()&&self.val().match(/^[.-0-9a-zA-Z]+$/i)&&(dialog.find(".jsxc_inputinfo.jsxc_room").show().addClass("jsxc_waiting"),serverInputTimeout=setTimeout(function(){loadRoomList(self.val())},1800))}).trigger("input");var error_handler=function(event,condition,room){var msg;switch(condition){case"not-authorized":msg=$.t("A_password_is_required");break;case"registration-required":msg=$.t("You_are_not_on_the_member_list");break;case"forbidden":msg=$.t("You_are_banned_from_this_room");break;case"conflict":msg=$.t("Your_desired_nickname_");break;case"service-unavailable":msg=$.t("The_maximum_number_");break;case"item-not-found":msg=$.t("This_room_is_locked_");break;case"not-allowed":msg=$.t("You_are_not_allowed_to_create_");break;default:jsxc.warn("Unknown muc error condition: "+condition),msg=$.t("Error")+": "+condition}var roomIndex=self.conn.muc.roomNames.indexOf(room);-1<roomIndex&&(self.conn.muc.roomNames.splice(roomIndex,1),delete self.conn.muc.rooms[room]),$("<p>").addClass("jsxc_warning").text(msg).appendTo(dialog.find(".jsxc_msg"))};function loadRoomList(server){server?self.conn.muc.listRooms(server,function(stanza){$("#jsxc_roomlist option:last").remove(),$(stanza).find("item").each(function(){var r=$("<option>"),rjid=$(this).attr("jid").toLowerCase(),rnode=Strophe.getNodeFromJid(rjid),rname=$(this).attr("name")||rnode;r.text(rname),r.attr("data-jid",rjid),r.attr("value",rnode),$("#jsxc_roomlist select").append(r)});var set=$(stanza).find('set[xmlns="http://jabber.org/protocol/rsm"]');if(0<set.length){var count=set.find("count").text()||"?";dialog.find(".jsxc_inputinfo").show().removeClass("jsxc_waiting").text($.t("Could_load_only",{count:count}))}else dialog.find(".jsxc_inputinfo").hide()},function(stanza){var errTextMsg=$(stanza).find("error text").text()||null;jsxc.warn("Could not load rooms",errTextMsg),errTextMsg&&dialog.find(".jsxc_inputinfo.jsxc_server").show().text(errTextMsg),$(stanza).find("error remote-server-not-found")&&dialog.find("#jsxc_server").addClass("jsxc_invalid"),dialog.find(".jsxc_inputinfo.jsxc_room").hide()}):dialog.find(".jsxc_inputinfo").hide()}$(document).on("error.muc.jsxc",error_handler),$(document).on("close.dialog.jsxc",function(){$(document).off("error.muc.jsxc",error_handler)}),dialog.find("#jsxc_nickname").attr("placeholder",Strophe.getNodeFromJid(self.conn.jid)),dialog.find("#jsxc_bookmark").change(function(){$(this).prop("checked")?($("#jsxc_autojoin").prop("disabled",!1),$("#jsxc_autojoin").parent(".checkbox").removeClass("disabled")):($("#jsxc_autojoin").prop("disabled",!0).prop("checked",!1),$("#jsxc_autojoin").parent(".checkbox").addClass("disabled"))}),dialog.find(".jsxc_continue").click(function(ev){ev.preventDefault();var room=$("#jsxc_room").val()?jsxc.jidToBid($("#jsxc_room").val()):null,nickname=$("#jsxc_nickname").val()||Strophe.getNodeFromJid(self.conn.jid),server=dialog.find("#jsxc_server").val();if(!room||!room.match(/^[^"&\'\/:<>@\s]+$/i))return $("#jsxc_room").addClass("jsxc_invalid").keyup(function(){$(this).val()&&$(this).removeClass("jsxc_invalid")}),!1;if(dialog.find("#jsxc_server").hasClass("jsxc_invalid"))return!1;if(room.match(/@(.*)$/)||(room+="@"+server),jsxc.xmpp.conn.muc.roomNames.indexOf(room)<0){var discoReceived=function(roomName,subject){jsxc.gui.dialog.resize(),dialog.find(".jsxc_continue").hide(),dialog.find(".jsxc_join").show().effect("highlight",{color:"green"},4e3),dialog.find(".jsxc_join").click(function(ev){ev.preventDefault();var bookmark=$("#jsxc_bookmark").prop("checked"),autojoin=$("#jsxc_autojoin").prop("checked"),password=$("#jsxc_password").val()||null;return jsxc.gui.window.clear(room),jsxc.storage.setUserItem("member",room,{}),self.join(room,nickname,password,roomName,subject,bookmark,autojoin),!1})};dialog.find(".jsxc_msg").append($("<p>").text($.t("Loading_room_information")).addClass("jsxc_waiting")),jsxc.gui.dialog.resize(),self.conn.disco.info(room,null,function(stanza){dialog.find(".jsxc_msg").html("<p>"+$.t("This_room_is")+"</p>");var table=$("<table>");$(stanza).find("feature").each(function(){var feature=$(this).attr("var");if(""!==feature&&i18next.exists(feature)){var tr=$("<tr>");$("<td>").text($.t(feature+".keyword")).appendTo(tr),$("<td>").text($.t(feature+".description")).appendTo(tr),tr.appendTo(table)}"muc_passwordprotected"===feature&&(dialog.find("#jsxc_password").parents(".form-group").removeClass("jsxc_hidden"),dialog.find("#jsxc_password").attr("required","required"),dialog.find("#jsxc_password").addClass("jsxc_invalid"))}),dialog.find(".jsxc_msg").append(table);var roomName=$(stanza).find("identity").attr("name"),subject=$(stanza).find('field[var="muc#roominfo_subject"]').attr("label");discoReceived(roomName,subject)},function(){dialog.find(".jsxc_msg").empty(),$("<p>").text($.t("Room_not_found_")).appendTo(dialog.find(".jsxc_msg")),discoReceived()})}else $("<p>").addClass("jsxc_warning").text($.t("You_already_joined_this_room")).appendTo(dialog.find(".jsxc_msg"));return!1}),dialog.find("input").keydown(function(ev){if(13!==ev.which)return dialog.find(".jsxc_warning").remove(),void(dialog.find(".jsxc_continue").is(":hidden")&&"jsxc_password"!==$(this).attr("id")&&(dialog.find(".jsxc_continue").show(),dialog.find(".jsxc_join").hide().off("click"),dialog.find(".jsxc_msg").empty(),dialog.find("#jsxc_password").parents(".form-group").addClass("jsxc_hidden"),dialog.find("#jsxc_password").attr("required",""),dialog.find("#jsxc_password").removeClass("jsxc_invalid"),jsxc.gui.dialog.resize()));dialog.find(".jsxc_continue").is(":hidden")?dialog.find(".jsxc_join").click():dialog.find(".jsxc_continue").click()})},showRoomConfiguration:function(room){var self=jsxc.muc;self.conn.muc.configure(room,function(stanza){var form=Strophe.x.Form.fromXML(stanza);window.f=form,self._showRoomConfiguration(room,form)},function(){jsxc.debug("Could not load room configuration")})},_showRoomConfiguration:function(room,config){var self=jsxc.muc,form=jsxc.gui.dialog.open(jsxc.muc.helper.formToHTML(config)).find("form");form.find('[type="checkbox"]').change(function(){$(this).val(this.checked?1:0)});var submit=$("<button>");submit.addClass("btn btn-primary"),submit.attr("type","submit"),submit.text($.t("Save"));var cancel=$("<button>");cancel.addClass("btn btn-default"),cancel.attr("type","button"),cancel.text($.t("Cancel"));var formGroup=$("<div>");formGroup.addClass("form-group"),$("<div>").addClass("col-sm-offset-6 col-sm-6").appendTo(formGroup),formGroup.find(">div").append(cancel),formGroup.find(">div").append(submit),form.append(formGroup),form.submit(function(ev){ev.preventDefault();var config=Strophe.x.Form.fromHTML(form.get(0));return self.conn.muc.saveConfiguration(room,config,function(){jsxc.storage.updateUserItem("buddy",room,"config",config),jsxc.debug("Room configuration saved.")},function(){jsxc.warn("Could not save room configuration.")}),jsxc.gui.dialog.close(),!1}),cancel.click(function(){self.conn.muc.cancelConfigure(room),jsxc.gui.dialog.close()})},join:function(room,nickname,password,roomName,subject,bookmark,autojoin){var self=jsxc.muc;jsxc.storage.setUserItem("buddy",room,{jid:room,name:roomName||room,sub:"both",type:"groupchat",state:self.CONST.ROOMSTATE.INIT,subject:subject,bookmarked:bookmark||!1,autojoin:autojoin||!1,nickname:nickname,config:null}),jsxc.xmpp.conn.muc.join(room,nickname,null,null,null,password),bookmark&&jsxc.xmpp.bookmarks.add(room,roomName,nickname,autojoin)},leave:function(room){if(jsxc.master){var self=jsxc.muc,own=jsxc.storage.getUserItem("ownNicknames")||{};(jsxc.storage.getUserItem("buddy",room)||{}).state===self.CONST.ROOMSTATE.ENTERED?self.conn.muc.leave(room,own[room],function(){self.onExited(room)}):self.onExited(room)}else jsxc.tab.execMaster("muc.leave",room)},onExited:function(room){var self=jsxc.muc,own=jsxc.storage.getUserItem("ownNicknames")||{},roomdata=jsxc.storage.getUserItem("buddy",room)||{};jsxc.storage.setUserItem("roomNames",self.conn.muc.roomNames),delete own[room],jsxc.storage.setUserItem("ownNicknames",own),jsxc.storage.removeUserItem("member",room),jsxc.storage.removeUserItem("chat",room),jsxc.gui.window.close(room),jsxc.storage.updateUserItem("buddy",room,"state",self.CONST.ROOMSTATE.EXITED),roomdata.bookmarked||jsxc.gui.roster.purge(room)},destroy:function(room,handler_cb,error_cb){if(jsxc.master){var self=jsxc.muc,roomdata=jsxc.storage.getUserItem("buddy",room);jsxc.storage.updateUserItem("buddy",room,"state",self.CONST.ROOMSTATE.AWAIT_DESTRUCTION),jsxc.gui.window.postMessage({bid:room,direction:jsxc.Message.SYS,msg:$.t("This_room_will_be_closed")});var iq=$iq({to:room,type:"set"}).c("query",{xmlns:Strophe.NS.MUC_OWNER}).c("destroy");jsxc.muc.conn.sendIQ(iq.tree(),handler_cb,error_cb),roomdata.bookmarked&&jsxc.xmpp.bookmarks.delete(room)}else jsxc.tab.execMaster("muc.destroy",room)},close:function(room){var self=jsxc.muc,roomdata=jsxc.storage.getUserItem("buddy",room)||{};self.emptyMembers(room);var roomIndex=self.conn.muc.roomNames.indexOf(room);-1<roomIndex&&(self.conn.muc.roomNames.splice(roomIndex,1),delete self.conn.muc.rooms[room]),jsxc.storage.setUserItem("roomNames",self.conn.muc.roomNames),roomdata.state===self.CONST.ROOMSTATE.AWAIT_DESTRUCTION&&self.onExited(room),jsxc.storage.getUserItem("budy",room)&&(roomdata.state=self.CONST.ROOMSTATE.DESTROYED,jsxc.storage.setUserItem("buddy",room,roomdata))},initWindow:function(event,win){var self=jsxc.muc;if(jsxc.xmpp.conn||!jsxc.master){var data=win.data(),bid=jsxc.jidToBid(data.jid),roomdata=jsxc.storage.getUserItem("buddy",bid);if("groupchat"===roomdata.type){win.addClass("jsxc_groupchat");var ownNickname=(jsxc.storage.getUserItem("ownNicknames")||{})[bid],mlIcon=$('<div class="jsxc_members"></div>');win.find(".jsxc_tools > .jsxc_settings").after(mlIcon);var ml=$('<div class="jsxc_memberlist"><ul></ul></div>');win.find(".jsxc_fade").prepend(ml),ml.on("wheel",function(ev){jsxc.muc.scrollMemberListBy(bid,0<ev.originalEvent.wheelDelta?50:-50)});var toggleMl=function(ev){ev&&ev.preventDefault();var slimOptions={},ul=ml.find("ul:first"),slimHeight=null;if(ml.toggleClass("jsxc_expand"),ml.hasClass("jsxc_expand")){$("body").click(),$("body").one("click",toggleMl),ul.mouseleave(function(){ul.data("timer",window.setTimeout(toggleMl,2e3))}).mouseenter(function(){window.clearTimeout(ul.data("timer"))}).css("left","0px");var maxHeight=.8*win.find(".jsxc_textarea").height(),innerHeight=ml.find("ul").height()+3;slimOptions={distance:"3px",height:(slimHeight=maxHeight<innerHeight?maxHeight:innerHeight)+"px",width:"100%",color:"#fff",opacity:"0.5"},ml.css("height",slimHeight+"px")}else slimOptions={destroy:!0},ul.attr("style",""),ml.css("height",""),window.clearTimeout(ul.data("timer")),$("body").off("click",null,toggleMl),ul.off("mouseleave mouseenter");return ul.slimscroll(slimOptions),!1};mlIcon.click(toggleMl),win.on("resize",function(){jsxc.muc.scrollMemberListBy(bid,0)});var destroy=$("<a>");destroy.attr("href","#"),destroy.text($.t("Destroy")),destroy.addClass("jsxc_destroy"),destroy.hide(),destroy.click(function(){self.destroy(bid)}),win.find(".jsxc_settings ul").append($("<li>").append(destroy));var configure=$("<a>");if(configure.attr("href","#"),configure.text($.t("Configure")),configure.addClass("jsxc_configure"),configure.hide(),configure.click(function(){self.showRoomConfiguration(bid)}),self.conn&&win.find(".jsxc_settings ul").append($("<li>").append(configure)),roomdata.state>self.CONST.ROOMSTATE.INIT){var member=jsxc.storage.getUserItem("member",bid)||{};$.each(member,function(nickname,val){self.insertMember(bid,nickname,val),nickname===ownNickname&&val.affiliation===self.CONST.AFFILIATION.OWNER&&destroy.show(),nickname!==ownNickname||val.affiliation!==self.CONST.AFFILIATION.OWNER&&val.affiliation!==self.CONST.AFFILIATION.OWNER||configure.show()})}var leave=$("<a>");leave.attr("href","#"),leave.text($.t("Leave")),leave.addClass("jsxc_leave"),leave.click(function(){self.leave(bid)}),win.find(".jsxc_settings ul").append($("<li>").append(leave))}}else $(document).one("attached.jsxc",function(){self.initWindow(null,win)})},onPresence:function(event,from,status,presence){var self=jsxc.muc,room=jsxc.jidToBid(from),roomdata=jsxc.storage.getUserItem("buddy",room),xdata=$(presence).find('x[xmlns^="'+Strophe.NS.MUC+'"]');if(self.conn.muc.roomNames.indexOf(room)<0||0===xdata.length)return!0;var res=Strophe.getResourceFromJid(from)||"",nickname=Strophe.unescapeNode(res),own=jsxc.storage.getUserItem("ownNicknames")||{},member=jsxc.storage.getUserItem("member",room)||{},codes=[];if(xdata.find("status").each(function(){var code=$(this).attr("code");jsxc.debug("[muc][code]",code),codes.push(code)}),roomdata.state===self.CONST.ROOMSTATE.INIT){if(roomdata.status=jsxc.CONST.STATUS.indexOf("online"),jsxc.storage.setUserItem("buddy",room,roomdata),jsxc.storage.setUserItem("roomNames",jsxc.xmpp.conn.muc.roomNames),0===jsxc.gui.roster.getItem(room).length){var bl=jsxc.storage.getUserItem("buddylist");bl.push(room),jsxc.storage.setUserItem("buddylist",bl),jsxc.gui.roster.add(room)}0<$("#jsxc_dialog").length&&(jsxc.gui.dialog.close(),jsxc.gui.window.open(room))}var jid=xdata.find("item").attr("jid")||null;if(0===status)if(0<xdata.find("destroy").length)member={},jsxc.gui.window.postMessage({bid:room,direction:jsxc.Message.SYS,msg:$.t("This_room_has_been_closed")}),self.close(room);else{delete member[nickname],self.removeMember(room,nickname);var newNickname=xdata.find("item").attr("nick");-1<codes.indexOf("303")&&newNickname?(newNickname=Strophe.unescapeNode(newNickname),member[newNickname]={},jsxc.gui.window.postMessage({bid:room,direction:jsxc.Message.SYS,msg:$.t("is_now_known_as",{oldNickname:nickname,newNickname:newNickname,escapeInterpolation:!0})})):(0===codes.length||1===codes.length&&-1<codes.indexOf("110"))&&jsxc.gui.window.postMessage({bid:room,direction:jsxc.Message.SYS,msg:$.t("left_the_building",{nickname:nickname,escapeInterpolation:!0})})}else!member[nickname]&&own[room]&&jsxc.gui.window.postMessage({bid:room,direction:jsxc.Message.SYS,msg:$.t("entered_the_room",{nickname:nickname,escapeInterpolation:!0})}),member[nickname]={jid:jid,status:status,roomJid:from,affiliation:xdata.find("item").attr("affiliation"),role:xdata.find("item").attr("role")},self.insertMember(room,nickname,member[nickname]);return jsxc.storage.setUserItem("member",room,member),$.each(codes,function(index,code){"function"==typeof self.onStatus[code]&&self.onStatus[code].call(this,room,nickname,member[nickname]||{},xdata),$(document).trigger("status.muc.jsxc",[code,room,nickname,member[nickname]||{},presence])}),!0},onPresenceError:function(event,from,presence){var self=jsxc.muc,xdata=$(presence).find('x[xmlns="'+Strophe.NS.MUC+'"]'),room=jsxc.jidToBid(from);if(0===xdata.length||self.conn.muc.roomNames.indexOf(room)<0)return!0;var condition=$(presence).find("error").children()[0].tagName;return jsxc.debug("[muc][error]",condition),$(document).trigger("error.muc.jsxc",[condition,room]),!0},onStatus:{110:function(room,nickname,data){var self=jsxc.muc,own=jsxc.storage.getUserItem("ownNicknames")||{};own[room]=nickname,jsxc.storage.setUserItem("ownNicknames",own),data.affiliation===self.CONST.AFFILIATION.OWNER&&jsxc.gui.window.get(room).find(".jsxc_destroy").show();var roomdata=jsxc.storage.getUserItem("buddy",room);roomdata.state===self.CONST.ROOMSTATE.INIT&&(roomdata.state=self.CONST.ROOMSTATE.ENTERED,jsxc.storage.setUserItem("buddy",room,roomdata))},170:function(room){jsxc.gui.window.postMessage({bid:room,direction:jsxc.Message.SYS,msg:$.t("Room_logging_is_enabled")})},171:function(room){jsxc.gui.window.postMessage({bid:room,direction:jsxc.Message.SYS,msg:$.t("Room_logging_is_disabled")})},172:function(room){jsxc.gui.window.postMessage({bid:room,direction:jsxc.Message.SYS,msg:$.t("Room_is_now_non-anoymous")})},173:function(room){jsxc.gui.window.postMessage({bid:room,direction:jsxc.Message.SYS,msg:$.t("Room_is_now_semi-anonymous")})},201:function(room){var self=jsxc.muc,roomdata=jsxc.storage.getUserItem("buddy",room)||{};roomdata.autojoin&&roomdata.config===self.CONST.ROOMCONFIG.INSTANT?self.conn.muc.createInstantRoom(room):roomdata.autojoin&&void 0!==roomdata.config&&null!==roomdata.config?self.conn.muc.saveConfiguration(room,roomdata.config,function(){jsxc.debug("Cached room configuration saved.")},function(){jsxc.warn("Could not save cached room configuration.")}):jsxc.gui.showSelectionDialog({header:$.t("Room_creation"),msg:$.t("Do_you_want_to_change_the_default_room_configuration"),primary:{label:$.t("Default"),cb:function(){jsxc.gui.dialog.close(),self.conn.muc.createInstantRoom(room),jsxc.storage.updateUserItem("buddy",room,"config",self.CONST.ROOMCONFIG.INSTANT)}},option:{label:$.t("Change"),cb:function(){self.showRoomConfiguration(room)}}})},301:function(room,nickname,data,xdata){(jsxc.storage.getUserItem("ownNicknames")||{})[room]===nickname?(jsxc.muc.close(room),jsxc.gui.window.postMessage({bid:room,direction:jsxc.Message.SYS,msg:$.t("muc_removed_banned")}),jsxc.muc.postReason(room,xdata)):jsxc.gui.window.postMessage({bid:room,direction:jsxc.Message.SYS,msg:$.t("muc_removed_info_banned",{nickname:nickname,escapeInterpolation:!0})})},307:function(room,nickname,data,xdata){(jsxc.storage.getUserItem("ownNicknames")||{})[room]===nickname?(jsxc.muc.close(room),jsxc.gui.window.postMessage({bid:room,direction:jsxc.Message.SYS,msg:$.t("muc_removed_kicked")}),jsxc.muc.postReason(room,xdata)):jsxc.gui.window.postMessage({bid:room,direction:jsxc.Message.SYS,msg:$.t("muc_removed_info_kicked",{nickname:nickname,escapeInterpolation:!0})})},321:function(room,nickname){(jsxc.storage.getUserItem("ownNicknames")||{})[room]===nickname?(jsxc.muc.close(room),jsxc.gui.window.postMessage({bid:room,direction:jsxc.Message.SYS,msg:$.t("muc_removed_affiliation")})):jsxc.gui.window.postMessage({bid:room,direction:jsxc.Message.SYS,msg:$.t("muc_removed_info_affiliation",{nickname:nickname,escapeInterpolation:!0})})},322:function(room,nickname){(jsxc.storage.getUserItem("ownNicknames")||{})[room]===nickname?(jsxc.muc.close(room),jsxc.gui.window.postMessage({bid:room,direction:jsxc.Message.SYS,msg:$.t("muc_removed_membersonly")})):jsxc.gui.window.postMessage({bid:room,direction:jsxc.Message.SYS,msg:$.t("muc_removed_info_membersonly",{nickname:nickname,escapeInterpolation:!0})})},332:function(room){jsxc.muc.close(room),jsxc.gui.window.postMessage({bid:room,direction:jsxc.Message.SYS,msg:$.t("muc_removed_shutdown")})}},postReason:function(room,xdata){var actor={name:xdata.find("actor").attr("nick"),jid:xdata.find("actor").attr("jid")},reason=xdata.find("reason").text();""!==reason&&(reason=$.t("Reason")+": "+reason,"string"==typeof actor.name||"string"==typeof actor.jid?jsxc.gui.window.postMessage({bid:room,direction:jsxc.Message.IN,msg:reason,sender:actor}):jsxc.gui.window.postMessage({bid:room,direction:jsxc.Message.SYS,msg:reason}))},insertMember:function(room,nickname,memberdata){var win=jsxc.gui.window.get(room),jid=memberdata.jid,ownBid=jsxc.jidToBid(jsxc.storage.getItem("jid")),m=win.find('.jsxc_memberlist li[data-nickname="'+nickname+'"]');if(0===m.length){var title=jsxc.escapeHTML(nickname);if((m=$('<li><div class="jsxc_avatar"></div><div class="jsxc_name"/></li>')).attr("data-nickname",nickname),win.find(".jsxc_memberlist ul").append(m),"string"==typeof jid){m.find(".jsxc_name").text(jsxc.jidToBid(jid)),title=title+"\n"+jsxc.jidToBid(jid);var data=jsxc.storage.getUserItem("buddy",jsxc.jidToBid(jid));null!==data&&"object"==typeof data?jsxc.gui.avatar.update(m,jsxc.jidToBid(jid),data.avatar):jsxc.jidToBid(jid)===ownBid&&jsxc.gui.avatar.update(m,jsxc.jidToBid(jid),"own")}else m.find(".jsxc_name").text(nickname),jsxc.gui.avatarPlaceholder(m.find(".jsxc_avatar"),nickname);m.attr("title",title)}},removeMember:function(room,nickname){var m=jsxc.gui.window.get(room).find('.jsxc_memberlist li[data-nickname="'+nickname+'"]');0<m.length&&m.remove()},scrollMemberListBy:function(room,offset){var win=jsxc.gui.window.get(room);if(!win.find(".jsxc_memberlist").hasClass("jsxc_expand")){var el=win.find(".jsxc_memberlist ul:first"),scrollWidth=el.width(),width=win.find(".jsxc_memberlist").width(),left=parseInt(el.css("left"));left=isNaN(left)?0-offset:left-offset,scrollWidth<width||0<left?left=0:left<width-scrollWidth&&(left=width-scrollWidth),el.css("left",left+"px")}},emptyMembers:function(room){jsxc.gui.window.get(room).find(".jsxc_memberlist").empty(),jsxc.storage.setUserItem("member",room,{})},onGroupchatMessage:function(message){var id=$(message).attr("id");if(id&&jsxc.el_exists(jsxc.Message.getDOM(id)))return!0;var from=$(message).attr("from"),htmlBodyElement=$(message).find('body[xmlns="'+Strophe.NS.XHTML+'"]').first(),body=$(message).find("body:first").text(),room=jsxc.jidToBid(from),nickname=Strophe.unescapeNode(Strophe.getResourceFromJid(from));if(""!==body){var delay=$(message).find('delay[xmlns="urn:xmpp:delay"]'),stamp=0<delay.length?new Date(delay.attr("stamp")):new Date;stamp=stamp.getTime();var member=jsxc.storage.getUserItem("member",room)||{},sender={};member[sender.name=nickname]&&"string"==typeof member[nickname].jid&&(sender.jid=member[nickname].jid),jsxc.gui.window.init(room);var attachment=jsxc.xmpp.getAttachmentFromHtmlBody(htmlBodyElement);attachment&&(body=null),jsxc.gui.window.postMessage({bid:room,direction:jsxc.Message.IN,msg:body,stamp:stamp,sender:sender,attachment:attachment})}var subject=$(message).find("subject");if(0<subject.length){var roomdata=jsxc.storage.getUserItem("buddy",room);roomdata.subject=subject.text(),jsxc.storage.setUserItem("buddy",room,roomdata),jsxc.gui.window.postMessage({bid:room,direction:jsxc.Message.SYS,msg:$.t("changed_subject_to",{nickname:nickname,subject:subject.text()})})}return!0},onAddRoster:function(event,room,data,bud){var self=jsxc.muc;if("groupchat"===data.type){var bo=$("<a>");$("<span>").addClass("jsxc_icon jsxc_bookmarkicon").appendTo(bo),$("<span>").text($.t("Bookmark")).appendTo(bo),bo.addClass("jsxc_bookmarkOptions"),bo.click(function(ev){return ev.preventDefault(),jsxc.xmpp.bookmarks.showDialog(room),!1}),bud.find(".jsxc_menu ul").append($("<li>").append(bo)),data.bookmarked&&bud.addClass("jsxc_bookmarked"),bud.off("click").click(function(){var data=jsxc.storage.getUserItem("buddy",room);data.state===self.CONST.ROOMSTATE.INIT||data.state===self.CONST.ROOMSTATE.EXITED?(self.showJoinChat(),$("#jsxc_room").val(Strophe.getNodeFromJid(data.jid)),$("#jsxc_nickname").val(data.nickname),$("#jsxc_bookmark").prop("checked",data.bookmarked),$("#jsxc_autojoin").prop("checked",data.autojoin),$("#jsxc_dialog .jsxc_bookmark").hide()):jsxc.gui.window.open(room)}),bud.find(".jsxc_delete").click(function(){return data.bookmarked&&jsxc.xmpp.bookmarks.delete(room),self.leave(room),!1})}},helper:{formToHTML:function(form){if(form instanceof Strophe.x.Form){var i,html=$("<form>");if(html.attr("data-type",form.type),html.addClass("form-horizontal"),form.title&&html.append("<h3>"+form.title+"</h3>"),form.instructions&&html.append("<p>"+form.instructions+"</p>"),0<form.fields.length)for(i=0;i<form.fields.length;i++)html.append(jsxc.muc.helper.fieldToHtml(form.fields[i]));return $("<div>").append(html).html()}},fieldToHtml:function(field){var el,val,opt,i,o,j,txt,line,_ref2,self=field||this;field=null;var id="Strophe.x.Field-"+self.type+"-"+self.var,html=$("<div>");if(html.addClass("form-group"),self.label){var label=$("<label>");label.attr("for",id),label.addClass("col-sm-6 control-label"),label.text(self.label),label.appendTo(html)}switch(self.type.toLowerCase()){case"list-single":case"list-multi":for(el=$("<select>"),"list-multi"===self.type&&el.attr("multiple","multiple"),i=0;i<self.options.length;i++)if(opt=self.options[i]){for(o=$(opt.toHTML()),j=0;j<self.values.length;j++)self.values[j].toString()===opt.value.toString()&&o.attr("selected","selected");o.appendTo(el)}break;case"text-multi":case"jid-multi":el=$("<textarea>"),(txt=function(){var i,_results;for(_results=[],i=0;i<self.values.length;i++)line=self.values[i],_results.push(line);return _results}.call(this).join("\n"))&&el.text(txt);break;case"text-single":case"boolean":case"text-private":case"hidden":case"fixed":case"jid-single":switch(el=$("<input>"),self.values&&el.attr("value",self.values[0]),self.type.toLowerCase()){case"text-single":el.attr("type","text"),el.attr("placeholder",self.desc),el.addClass("form-control");break;case"boolean":el.attr("type","checkbox"),!(val=null!=(_ref2=self.values[0])&&"function"==typeof _ref2.toString?_ref2.toString():void 0)||"true"!==val&&"1"!==val||el.attr("checked","checked");break;case"text-private":el.attr("type","password"),el.addClass("form-control");break;case"hidden":el.attr("type","hidden");break;case"fixed":el.attr("type","text").attr("readonly","readonly"),el.addClass("form-control");break;case"jid-single":el.attr("type","email"),el.addClass("form-control")}break;default:el=$("<input type='text'>")}el.attr("id",id),el.attr("name",self.var),self.required&&el.attr("required",self.required);var inner=el;return(el=$("<div>")).addClass("col-sm-6"),el.append(inner),html.append(el),html.get(0)}},isGroupchat:function(jid){var bid=jsxc.jidToBid(jid);return"groupchat"===(jsxc.storage.setUserItem("buddy",bid)||{}).type}},$(document).on("init.window.jsxc",jsxc.muc.initWindow),$(document).on("add.roster.jsxc",jsxc.muc.onAddRoster),$(document).on("attached.jsxc",function(){jsxc.muc.init()}),$(document).one("connected.jsxc",function(){jsxc.storage.removeUserItem("roomNames"),jsxc.storage.removeUserItem("ownNicknames")}),jsxc.notice={_num:0,load:function(){$("#jsxc_notice ul li").remove(),$("#jsxc_notice > span").text(""),jsxc.notice._num=0;var saved=jsxc.storage.getUserItem("notices")||[],key=null;for(key in saved)if(saved.hasOwnProperty(key)){var val=saved[key];jsxc.notice.add(val,val.fnName,val.fnParams,key)}},add:function(data,fnName,fnParams,id){var nid=id||Date.now(),list=$("#jsxc_notice ul"),notice=$("<li/>"),msg=data.msg,description=data.description;notice.click(function(){return jsxc.notice.remove(nid),jsxc.exec(fnName,fnParams),!1}),data.type&¬ice.addClass("jsxc_"+data.type+"icon"),notice.text(msg),notice.attr("title",description||""),notice.attr("data-nid",nid),list.append(notice),$("#jsxc_notice > span").text(++jsxc.notice._num);var saved=jsxc.storage.getUserItem("notices")||{};if(id||(saved[nid]={msg:msg,description:description,type:data.type,fnName:fnName,fnParams:fnParams},jsxc.storage.setUserItem("notices",saved),jsxc.notification.notify(msg,description||"",null,!0,jsxc.CONST.SOUNDS.NOTICE)),3<Object.keys(saved).length&&0===list.find(".jsxc_closeAll").length){var closeAll=$("<li>");closeAll.addClass("jsxc_closeAll jsxc_deleteicon jsxc_warning"),closeAll.text($.t("Close_all")),closeAll.prependTo(list),closeAll.click(jsxc.notice.removeAll)}else Object.keys(saved).length<=3&&0!==list.find(".jsxc_closeAll").length&&list.find(".jsxc_closeAll").remove()},remove:function(nid){$("#jsxc_notice li[data-nid="+nid+"]").remove(),$("#jsxc_notice > span").text(--jsxc.notice._num||"");var s=jsxc.storage.getUserItem("notices")||{};delete s[nid],jsxc.storage.setUserItem("notices",s),Object.keys(s).length<=3&&0!==$("#jsxc_notice .jsxc_closeAll").length&&$("#jsxc_notice .jsxc_closeAll").remove()},removeAll:function(){jsxc.notice._num=0,jsxc.storage.setUserItem("notices",{}),$("#jsxc_notice ul").empty(),$("#jsxc_notice > span").text("")},has:function(fnName){var saved=jsxc.storage.getUserItem("notices")||[],has=!1;return $.each(saved,function(index,val){if(val.fnName===fnName)return!(has=!0)}),has}},jsxc.notification={audio:null,init:function(){$(document).on("postmessagein.jsxc",function(event,bid,msg){msg=msg&&msg.match(/^\?OTR/)?$.t("Encrypted_message"):msg;var data=jsxc.storage.getUserItem("buddy",bid);jsxc.notification.notify({title:$.t("New_message_from",{name:data.name}),msg:msg,soundFile:jsxc.CONST.SOUNDS.MSG,source:bid})}),$(document).on("callincoming.jingle",function(){jsxc.notification.playSound(jsxc.CONST.SOUNDS.CALL,!0,!0)}),$(document).on("accept.call.jsxc reject.call.jsxc",function(){jsxc.notification.stopSound()})},notify:function(title,msg,d,force,soundFile,loop,source){var o;if(jsxc.options.notification&&jsxc.notification.hasPermission()&&(o=null!==title&&"object"==typeof title?title:{title:title,msg:msg,duration:d,force:force,soundFile:soundFile,loop:loop,source:source},!jsxc.hasFocus()||o.force)){var icon=o.icon||jsxc.options.root+"/img/XMPP_logo.png";if("string"==typeof o.source){var data=jsxc.storage.getUserItem("buddy",o.source),src=jsxc.storage.getUserItem("avatar",data.avatar);"string"==typeof src&&"0"!==src&&(icon=src)}jsxc.toNotification=setTimeout(function(){"string"==typeof o.soundFile&&jsxc.notification.playSound(o.soundFile,o.loop,o.force);var popup=new Notification($.t(o.title),{body:$.t(o.msg),icon:icon}),duration=o.duration||jsxc.options.popupDuration;0<duration&&setTimeout(function(){popup.close()},duration)},jsxc.toNotificationDelay)}},hasSupport:function(){if(window.webkitNotifications){var permission;switch(window.Notification=function(title,opt){var popup=window.webkitNotifications.createNotification(null,title,opt.body);return popup.show(),popup.close=function(){popup.cancel()},popup},window.webkitNotifications.checkPermission()){case 0:permission=jsxc.CONST.NOTIFICATION_GRANTED;break;case 2:permission=jsxc.CONST.NOTIFICATION_DENIED;break;default:permission=jsxc.CONST.NOTIFICATION_DEFAULT}return window.Notification.permission=permission,window.Notification.requestPermission=function(func){window.webkitNotifications.requestPermission(func)},!0}return!!window.Notification},prepareRequest:function(){jsxc.notice.has("gui.showRequestNotification")||$(document).one("postmessagein.jsxc",function(){setTimeout(function(){jsxc.notice.add({msg:$.t("Notifications")+"?",description:$.t("Should_we_notify_you_")},"gui.showRequestNotification")},1e3)})},requestPermission:function(){window.Notification.requestPermission(function(status){window.Notification.permission!==status&&(window.Notification.permission=status),jsxc.notification.hasPermission()?$(document).trigger("notificationready.jsxc"):$(document).trigger("notificationfailure.jsxc")})},hasPermission:function(){return window.Notification.permission===jsxc.CONST.NOTIFICATION_GRANTED},playSound:function(soundFile,loop,force){if(jsxc.master&&!jsxc.options.get("muteNotification")&&"dnd"!==jsxc.storage.getUserItem("presence")&&(!jsxc.hasFocus()||force)){jsxc.notification.stopSound();var audio=new Audio(jsxc.options.root+"/sound/"+soundFile);audio.loop=loop||!1,audio.play(),jsxc.notification.audio=audio}},stopSound:function(){var audio=jsxc.notification.audio;null!=audio&&(audio.pause(),jsxc.notification.audio=null)},muteSound:function(external){$("#jsxc_menu .jsxc_muteNotification").text($.t("Unmute")),!0!==external&&jsxc.options.set("muteNotification",!0)},unmuteSound:function(external){$("#jsxc_menu .jsxc_muteNotification").text($.t("Mute")),!0!==external&&jsxc.options.set("muteNotification",!1)}},jsxc.options={app_name:"web applications",timeout:3e3,busyTimeout:15e3,otr:{enable:!0,ERROR_START_AKE:!1,debug:!1,SEND_WHITESPACE_TAG:!1,WHITESPACE_START_AKE:!0},xmpp:{url:null,jid:null,domain:null,password:null,sid:null,rid:null,overwrite:!1,onlogin:null},priority:{online:0,chat:0,away:0,xa:0,dnd:0},formFound:null,loginForm:{enable:!0,form:null,jid:null,pass:null,preJid:function(jid){return jid},onConnecting:"dialog",onConnected:"submit",onAuthFail:"submit",attachIfFound:!0,ifFound:"attach",startMinimized:!1},logoutElement:null,numberOfMsg:10,defaultLang:"en",autoLang:!0,rosterAppend:"body",notification:!0,popupDuration:6e3,root:"",displayRosterMinimized:function(){return!1},hideOffline:!1,muteNotification:!1,defaultAvatar:null,loadSettings:null,saveSettinsPermanent:function(data,cb){cb(!0)},carbons:{enable:!0},getUsers:null,favicon:{enable:!0,bgColor:"#E59400",textColor:"#fff"},turnCredentialsPath:null,RTCPeerConfig:{ttl:3600,url:null,withCredentials:!1,iceServers:[{urls:"stun:stun.stunprotocol.org"}]},onlineHelp:"http://www.jsxc.org/manual.html",viewport:{getSize:function(){var w=$(window).width()-$("#jsxc_windowListSB").width(),h=$(window).height();return"shown"===jsxc.storage.getUserItem("roster")&&(w-=$("#jsxc_roster").outerWidth(!0)),{width:w,height:h}}},maxStorableSize:1e6,fileTransfer:{httpUpload:{enable:!0}},chatState:{enable:!0},screenMediaExtension:{firefox:"",chrome:""},mam:{enable:!1,max:30}},jsxc.otr={objects:{},dsaFallback:null,receiveMessage:function(d){var bid=d.bid;jsxc.otr.objects[bid].msgstate!==OTR.CONST.MSGSTATE_PLAINTEXT&&jsxc.otr.backup(bid),jsxc.otr.objects[bid].msgstate===OTR.CONST.MSGSTATE_PLAINTEXT||d.encrypted?jsxc.gui.window.postMessage({_uid:d._uid,bid:bid,direction:jsxc.Message.IN,msg:d.msg,encrypted:d.encrypted,forwarded:d.forwarded,stamp:d.stamp,attachment:d.attachment}):jsxc.gui.window.postMessage({bid:bid,direction:jsxc.Message.SYS,msg:$.t("Received_an_unencrypted_message")+". ["+d.msg+"]",encrypted:d.encrypted,forwarded:d.forwarded,stamp:d.stamp})},sendMessage:function(jid,msg,message){0!==jsxc.otr.objects[jsxc.jidToBid(jid)].msgstate&&jsxc.otr.backup(jsxc.jidToBid(jid)),jsxc.xmpp._sendMessage(jid,msg,message)},create:function(bid){if(!jsxc.otr.objects.hasOwnProperty(bid)&&jsxc.options.otr.priv){var ol=jsxc.storage.getUserItem("otrlist")||[];ol.indexOf(bid)<0&&(ol.push(bid),jsxc.storage.setUserItem("otrlist",ol)),jsxc.otr.objects[bid]=new OTR(jsxc.options.otr),jsxc.options.otr.SEND_WHITESPACE_TAG&&(jsxc.otr.objects[bid].SEND_WHITESPACE_TAG=!0),jsxc.options.otr.WHITESPACE_START_AKE&&(jsxc.otr.objects[bid].WHITESPACE_START_AKE=!0),jsxc.otr.objects[bid].on("status",function(status){var data=jsxc.storage.getUserItem("buddy",bid);if(null!==data){switch(status){case OTR.CONST.STATUS_SEND_QUERY:jsxc.gui.window.postMessage({bid:bid,direction:jsxc.Message.SYS,msg:$.t("trying_to_start_private_conversation")});break;case OTR.CONST.STATUS_AKE_SUCCESS:data.fingerprint=jsxc.otr.objects[bid].their_priv_pk.fingerprint(),data.msgstate=OTR.CONST.MSGSTATE_ENCRYPTED;var msg_state=jsxc.otr.objects[bid].trust?"Verified":"Unverified",msg=$.t(msg_state+"_private_conversation_started");jsxc.gui.window.postMessage({bid:bid,direction:"sys",msg:msg});break;case OTR.CONST.STATUS_END_OTR:data.fingerprint=null,jsxc.otr.objects[bid].msgstate===OTR.CONST.MSGSTATE_PLAINTEXT?(data.msgstate=OTR.CONST.MSGSTATE_PLAINTEXT,jsxc.gui.window.postMessage({bid:bid,direction:jsxc.Message.SYS,msg:$.t("private_conversation_aborted")})):(data.msgstate=OTR.CONST.MSGSTATE_FINISHED,jsxc.gui.window.postMessage({bid:bid,direction:jsxc.Message.SYS,msg:$.t("your_buddy_closed_the_private_conversation_you_should_do_the_same")}));break;case OTR.CONST.STATUS_SMP_HANDLE:jsxc.keepBusyAlive()}jsxc.storage.setUserItem("buddy",bid,data),jsxc.gui.update(bid)}}),jsxc.otr.objects[bid].on("smp",function(type,data){switch(type){case"question":jsxc.gui.window.postMessage({bid:bid,direction:jsxc.Message.SYS,msg:$.t("Authentication_request_received")}),jsxc.gui.window.smpRequest(bid,data),jsxc.storage.setUserItem("smp",bid,{data:data||null});break;case"trust":jsxc.otr.objects[bid].trust=data,jsxc.storage.updateUserItem("buddy",bid,"trust",data),jsxc.otr.backup(bid),jsxc.gui.update(bid),data?jsxc.gui.window.postMessage({bid:bid,direction:jsxc.Message.SYS,msg:$.t("conversation_is_now_verified")}):jsxc.gui.window.postMessage({bid:bid,direction:jsxc.Message.SYS,msg:$.t("authentication_failed")}),jsxc.storage.removeUserItem("smp",bid),jsxc.gui.dialog.close("smp");break;case"abort":jsxc.gui.window.hideOverlay(bid),jsxc.gui.window.postMessage({bid:bid,direction:jsxc.Message.SYS,msg:$.t("Authentication_aborted")});break;default:jsxc.debug("[OTR] sm callback: Unknown type: "+type)}}),jsxc.otr.objects[bid].on("ui",function(msg,encrypted,meta){jsxc.otr.receiveMessage({_uid:meta._uid,bid:bid,msg:msg,encrypted:!0===encrypted,stamp:meta.stamp,forwarded:meta.forwarded,attachment:meta.attachment})}),jsxc.otr.objects[bid].on("io",function(msg,message){var jid=jsxc.gui.window.get(bid).data("jid")||jsxc.otr.objects[bid].jid;jsxc.otr.objects[bid].jid=jid,jsxc.otr.sendMessage(jid,msg,message)}),jsxc.otr.objects[bid].on("error",function(err){"Received an unencrypted message."!==err&&jsxc.gui.window.postMessage({bid:bid,direction:jsxc.Message.SYS,msg:"[OTR] "+$.t(err)}),jsxc.error("[OTR] "+err)}),jsxc.otr.restore(bid)}},onSmpQuestion:function(bid,data){jsxc.gui.showVerification(bid),$("#jsxc_dialog select").prop("selectedIndex",data?2:3).change(),$("#jsxc_dialog > div:eq(0)").hide(),data?($("#jsxc_dialog > div:eq(2)").find("#jsxc_quest").val(data).prop("disabled",!0),$("#jsxc_dialog > div:eq(2)").find(".jsxc_submit").text($.t("Answer")),$("#jsxc_dialog > div:eq(2)").find(".jsxc_explanation").text($.t("onsmp_explanation_question")),$("#jsxc_dialog > div:eq(2)").show()):($("#jsxc_dialog > div:eq(3)").find(".jsxc_explanation").text($.t("onsmp_explanation_secret")),$("#jsxc_dialog > div:eq(3)").show()),$("#jsxc_dialog .jsxc_close").click(function(){jsxc.storage.removeUserItem("smp",bid),jsxc.master&&jsxc.otr.objects[bid].sm.abort()})},sendSmpReq:function(bid,sec,quest){jsxc.keepBusyAlive(),jsxc.otr.objects[bid].smpSecret(sec,quest||"")},toggleTransfer:function(bid){"function"==typeof OTR&&(0===jsxc.storage.getUserItem("buddy",bid).msgstate?jsxc.otr.goEncrypt(bid):jsxc.otr.goPlain(bid))},goEncrypt:function(bid){jsxc.master?jsxc.otr.objects.hasOwnProperty(bid)&&jsxc.otr.objects[bid].sendQueryMsg():jsxc.storage.updateUserItem("buddy",bid,"transferReq",1)},goPlain:function(bid,cb){jsxc.master?jsxc.otr.objects.hasOwnProperty(bid)&&(jsxc.otr.objects[bid].endOtr.call(jsxc.otr.objects[bid],cb),jsxc.otr.objects[bid].init.call(jsxc.otr.objects[bid]),jsxc.otr.backup(bid)):jsxc.storage.updateUserItem("buddy",bid,"transferReq",0)},backup:function(bid){var o=jsxc.otr.objects[bid],r={};if(null!==o){var i,savekey=["jid","our_instance_tag","msgstate","authstate","fragment","their_y","their_old_y","their_keyid","their_instance_tag","our_dh","our_old_dh","our_keyid","sessKeys","storedMgs","oldMacKeys","trust","transmittedRS","ssid","receivedPlaintext","authstate","send_interval"];for(i=0;i<savekey.length;i++)r[savekey[i]]=JSON.stringify(o[savekey[i]]);null!==o.their_priv_pk&&(r.their_priv_pk=JSON.stringify(o.their_priv_pk.packPublic())),o.ake.otr_version&&""!==o.ake.otr_version&&(r.otr_version=JSON.stringify(o.ake.otr_version)),jsxc.storage.setUserItem("otr",bid,r)}},restore:function(bid){var o=jsxc.otr.objects[bid],d=jsxc.storage.getUserItem("otr",bid);if(null!==o||null!==d){var key;for(key in d)if(d.hasOwnProperty(key)){var val=JSON.parse(d[key]);"their_priv_pk"===key&&null!==val&&(val=DSA.parsePublic(val)),"otr_version"===key&&null!==val?o.ake.otr_version=val:o[key]=val}1===(jsxc.otr.objects[bid]=o).msgstate&&null!==o.their_priv_pk&&o._smInit.call(jsxc.otr.objects[bid])}jsxc.otr.enable(bid)},createDSA:function(){if(!jsxc.options.otr.priv){if("function"!=typeof OTR)return jsxc.warn("OTR support disabled"),OTR={},void(OTR.CONST={MSGSTATE_PLAINTEXT:0,MSGSTATE_ENCRYPTED:1,MSGSTATE_FINISHED:2});if(null===jsxc.storage.getUserItem("key")){var msg=$.t("Creating_your_private_key_"),worker=null;if(Worker){var scriptPath=$("script").map(function(){var matches=($(this).attr("src")||"").match(/(.+\/)jsxc\.(min\.)?js$/);if(matches)return matches[1]});0===scriptPath.length?(jsxc.debug("Could not determine script path for web worker."),scriptPath[0]=jsxc.options.root+"/"):1!==scriptPath.length&&jsxc.debug("We found multiple ("+scriptPath.length+") script paths.");try{worker=new Worker(scriptPath[0]+"lib/jsxc.otr.webworker.js")}catch(err){jsxc.warn("Couldn't create web-worker.",err)}}jsxc.otr.dsaFallback=null===worker,jsxc.otr.dsaFallback?(jsxc.xmpp.conn.pause(),jsxc.gui.dialog.open(jsxc.gui.template.get("waitAlert",null,msg),{noClose:!0}),jsxc.debug("DSA key creation started in fallback mode."),setTimeout(function(){var dsa=new DSA;jsxc.otr.DSAready(dsa)},500)):(worker.onmessage=function(e){var type=e.data.type,val=e.data.val;"debug"===type?jsxc.debug(val):"data"===type&&jsxc.otr.DSAready(DSA.parsePrivate(val))},jsxc.debug("DSA key creation started."),worker.postMessage({imports:[],seed:BigInt.getSeed(),debug:!0}))}else jsxc.debug("DSA key loaded"),jsxc.options.otr.priv=DSA.parsePrivate(jsxc.storage.getUserItem("key")),jsxc.otr._createDSA()}},_createDSA:function(){jsxc.storage.setUserItem("priv_fingerprint",jsxc.options.otr.priv.fingerprint()),$.each(jsxc.storage.getUserItem("windowlist")||[],function(index,val){jsxc.otr.create(val)})},DSAready:function(dsa){jsxc.storage.setUserItem("key",dsa.packPrivate()),jsxc.options.otr.priv=dsa,jsxc.otr.dsaFallback&&(jsxc.xmpp.conn.resume(),jsxc.gui.dialog.close()),jsxc.otr._createDSA()},enable:function(bid){jsxc.gui.window.get(bid).find(".jsxc_otr").removeClass("jsxc_disabled")}},jsxc.storage={PREFIX:"jsxc",SEP:":",hasSupport:function(){if("undefined"==typeof localStorage||null===localStorage)return!1;try{localStorage.setItem("jsxc:storage:test","jsxc"),localStorage.removeItem("jsxc:storage:test")}catch(err){return jsxc.warn("Can not save any data. Probably your quota exceeded or you use Safari in private Mode:",err?err.message:void 0),!1}return!0},getPrefix:function(uk){var self=jsxc.storage;return uk&&!jsxc.bid&&jsxc.warn("Unable to create user prefix"),self.PREFIX+self.SEP+(uk&&jsxc.bid?jsxc.bid+self.SEP:"")},setItem:function(key,value,uk){0<jsxc.storageNotConform&&"rid"!==key&&(1<jsxc.storageNotConform&&null===jsxc.toSNC&&(jsxc.toSNC=window.setTimeout(function(){jsxc.storageNotConform=0,jsxc.storage.setItem("storageNotConform",0)},1e3)),jsxc.ls.push(JSON.stringify({key:key,value:value}))),"object"==typeof value&&(value=JSON.stringify(value,function(key,val){if(!(val instanceof jQuery))return val}));try{localStorage.setItem(jsxc.storage.getPrefix(uk)+key,value)}catch(err){jsxc.error("An error occured while saving data.",err?err.message:void 0)}},setUserItem:function(type,key,value){var self=jsxc.storage;return 2===arguments.length?(value=key,key=type,type=""):3===arguments.length&&(key=type+self.SEP+key),jsxc.storage.setItem(key,value,!0)},getItem:function(key,uk){key=jsxc.storage.getPrefix(uk)+key;var value=localStorage.getItem(key);try{return JSON.parse(value)}catch(e){return value}},getUserItem:function(type,key){var self=jsxc.storage;return 1===arguments.length?key=type:2===arguments.length&&(key=type+self.SEP+key),jsxc.storage.getItem(key,!0)},removeItem:function(key,uk){jsxc.storageNotConform&&"rid"!==key&&jsxc.ls.push(JSON.stringify({key:jsxc.storage.prefix+key,value:""})),localStorage.removeItem(jsxc.storage.getPrefix(uk)+key)},removeUserItem:function(type,key){var self=jsxc.storage;1===arguments.length?key=type:2===arguments.length&&(key=type+self.SEP+key),jsxc.storage.removeItem(key,!0)},updateItem:function(key,variable,value,uk){var data=jsxc.storage.getItem(key,uk)||{};"object"==typeof variable?$.each(variable,function(key,val){void 0===data[key]&&jsxc.debug("Variable "+key+" doesn't exist in "+variable+". It was created."),data[key]=val}):(void 0===data[variable]&&jsxc.debug("Variable "+variable+" doesn't exist. It was created."),data[variable]=value),jsxc.storage.setItem(key,data,uk)},updateUserItem:function(type,key,variable,value){var self=jsxc.storage;return 4===arguments.length||3===arguments.length&&"object"==typeof variable?key=type+self.SEP+key:(value=variable,variable=key,key=type),jsxc.storage.updateItem(key,variable,value,!0)},ink:function(key,uk){jsxc.storage.setItem(key,Number(jsxc.storage.getItem(key,uk))+1,uk)},removeElement:function(key,name,uk){var item=jsxc.storage.getItem(key,uk);$.isArray(item)?item=$.grep(item,function(e){return e!==name}):"object"==typeof item&&null!==item&&delete item[name],jsxc.storage.setItem(key,item,uk)},removeUserElement:function(type,key,name){var self=jsxc.storage;return 2===arguments.length?(name=key,key=type):3===arguments.length&&(key=type+self.SEP+key),jsxc.storage.removeElement(key,name,!0)},onStorage:function(e){if(e.key!==jsxc.storage.PREFIX+jsxc.storage.SEP+"rid"&&e.key){var re=new RegExp("^"+jsxc.storage.PREFIX+jsxc.storage.SEP+"(?:[^"+jsxc.storage.SEP+"]+@[^"+jsxc.storage.SEP+"]+"+jsxc.storage.SEP+")?(.*)","i"),key=e.key.replace(re,"$1");if(0<jsxc.storageNotConform&&0<jsxc.ls.length){var val=e.newValue;try{val=JSON.parse(val)}catch(err){}var index=$.inArray(JSON.stringify({key:key,value:val}),jsxc.ls);if(0<=index)return 1<jsxc.storageNotConform&&(window.clearTimeout(jsxc.toSNC),jsxc.storageNotConform=1,jsxc.storage.setItem("storageNotConform",1)),void jsxc.ls.splice(index,1)}if(e.oldValue!==e.newValue){var n,o,bid=key.replace(new RegExp("[^"+jsxc.storage.SEP+"]+"+jsxc.storage.SEP+"(.*)","i"),"$1");if(jsxc.master&&"alive"===key)return jsxc.debug("Master request."),e.newValue&&e.newValue.match(/:master$/)?void jsxc.warn("Master request from master. Something went wrong... :-("):void jsxc.keepAlive();if(!jsxc.master&&("alive"===key||"alive_busy"===key))return jsxc.to=$.grep(jsxc.to,function(timeout){return window.clearTimeout(timeout),!1}),void 0===e.newValue||null===e.newValue?void jsxc.xmpp.disconnected():(jsxc.to.push(window.setTimeout(jsxc.checkMaster,("alive"===key?jsxc.options.timeout:jsxc.options.busyTimeout)+jsxc.random(60))),void(jsxc.role_allocation||jsxc.onSlave()));if(jsxc.master&&"sid"===key&&!e.newValue&&jsxc.xmpp.logout(!1),key.match(/^notices/)&&jsxc.notice.load(),key.match(/^presence/)&&jsxc.gui.changePresence(e.newValue,!0),key.match(/^options/)&&e.newValue&&(void 0!==(n=JSON.parse(e.newValue)).muteNotification&&n.muteNotification?jsxc.notification.muteSound(!0):jsxc.notification.unmuteSound(!0)),key.match(/^hidden/)&&(jsxc.master?clearTimeout(jsxc.toNotification):jsxc.isHidden()),key.match(/^focus/)&&(jsxc.master?clearTimeout(jsxc.toNotification):jsxc.hasFocus()),key.match(new RegExp("^history"+jsxc.storage.SEP))){var uid,el,message,history=JSON.parse(e.newValue);for(jsxc.master||jsxc.gui.window.get(bid).find(".jsxc_textarea").empty();0<history.length;)uid=history.pop(),0===(el=(message=new jsxc.Message(uid)).getDOM()).length?(jsxc.master&&message.direction===jsxc.Message.OUT&&jsxc.xmpp.sendMessage(message),jsxc.gui.window._postMessage(message,!0)):message.isReceived()&&el.addClass("jsxc_received")}else{if(key.match(new RegExp("^window"+jsxc.storage.SEP)))return e.newValue?e.oldValue?(n=JSON.parse(e.newValue),o=JSON.parse(e.oldValue),n.minimize!==o.minimize&&(n.minimize?jsxc.gui.window._hide(bid):jsxc.gui.window._show(bid)),jsxc.gui.window.setText(bid,n.text),void(n.unread!==o.unread&&(0===n.unread?jsxc.gui.readMsg(bid):jsxc.gui._unreadMsg(bid,n.unread)))):void jsxc.gui.window.open(bid):void jsxc.gui.window._close(bid);if(key.match(/^unreadMsg/)&&jsxc.gui.favicon&&jsxc.gui.favicon.badge(parseInt(e.newValue)||0),key.match(new RegExp("^smp"+jsxc.storage.SEP))){if(!e.newValue)return jsxc.gui.dialog.close("smp"),jsxc.gui.window.hideOverlay(bid),void(jsxc.master&&jsxc.otr.objects[bid].sm.abort());void 0!==(n=JSON.parse(e.newValue)).data?jsxc.gui.window.smpRequest(bid,n.data):jsxc.master&&n.sec&&(jsxc.gui.dialog.close("smp"),jsxc.gui.window.hideOverlay(bid),jsxc.otr.sendSmpReq(bid,n.sec,n.quest))}if(!jsxc.master&&key.match(new RegExp("^buddy"+jsxc.storage.SEP))){if(!e.newValue)return void jsxc.gui.roster.purge(bid);if(0===jsxc.gui.roster.getItem(bid).length)return void jsxc.gui.roster.add(bid);n=JSON.parse(e.newValue),o=JSON.parse(e.oldValue),jsxc.gui.update(bid),o.status===n.status&&o.sub===n.sub||jsxc.gui.roster.reorder(bid)}jsxc.master&&key.match(new RegExp("^deletebuddy"+jsxc.storage.SEP))&&e.newValue&&(n=JSON.parse(e.newValue),jsxc.xmpp.removeBuddy(n.jid),jsxc.storage.removeUserItem(key)),jsxc.master&&key.match(new RegExp("^buddy"+jsxc.storage.SEP))&&(n=JSON.parse(e.newValue),(o=JSON.parse(e.oldValue)).transferReq!==n.transferReq&&(jsxc.storage.updateUserItem("buddy",bid,"transferReq",-1),0===n.transferReq&&jsxc.otr.goPlain(bid),1===n.transferReq&&jsxc.otr.goEncrypt(bid)),o.name!==n.name&&jsxc.gui.roster._rename(bid,n.name)),"friendReq"===key&&(n=JSON.parse(e.newValue),jsxc.master&&0<=n.approve&&jsxc.xmpp.resFriendReq(n.jid,n.approve)),jsxc.master&&key.match(new RegExp("^add"+jsxc.storage.SEP))&&(n=JSON.parse(e.newValue),jsxc.xmpp.addBuddy(n.username,n.alias)),"roster"===key&&jsxc.gui.roster.toggle(e.newValue),jsxc.master&&key.match(new RegExp("^vcard"+jsxc.storage.SEP))&&null!==e.newValue&&e.newValue.match(/^request:/)&&jsxc.xmpp.loadVcard(bid,function(stanza){jsxc.storage.setUserItem("vcard",bid,{state:"success",data:$("<div>").append(stanza).html()})},function(){jsxc.storage.setUserItem("vcard",bid,{state:"error"})}),jsxc.master||!key.match(new RegExp("^vcard"+jsxc.storage.SEP))||null===e.newValue||e.newValue.match(/^request:/)||(void 0!==(n=JSON.parse(e.newValue)).state&&$(document).trigger("loaded.vcard.jsxc",n),jsxc.storage.removeUserItem("vcard",bid)),"_cmd"===key&&e.newValue&&(n=JSON.parse(e.newValue)||{},jsxc.storage.removeUserItem("_cmd"),n.cmd&&n.target===jsxc.tab.CONST[jsxc.master?"MASTER":"SLAVE"]&&(jsxc.debug("Execute tab cmd: "+n.cmd),jsxc.exec(n.cmd,n.params)))}}}},saveBuddy:function(bid,data){return jsxc.storage.getUserItem("buddy",bid)?(jsxc.storage.updateUserItem("buddy",bid,data),"updated"):(jsxc.storage.setUserItem("buddy",bid,$.extend({jid:"",name:"",status:0,sub:"none",msgstate:0,transferReq:-1,trust:!1,fingerprint:null,res:[],type:"chat"},data)),"created")}},jsxc.tab={CONST:{MASTER:"master",SLAVE:"slave"},exec:function(target,cmd,params){1===(params=Array.prototype.slice.call(arguments,2)).length&&$.isArray(params[0])&&(params=params[0]),target===jsxc.tab.CONST[jsxc.master?"MASTER":"SLAVE"]&&(jsxc.exec(cmd,params),jsxc.master)||jsxc.storage.setUserItem("_cmd",{target:target,cmd:cmd,params:params,rnd:Math.random()})},execMaster:function(){var args=Array.prototype.slice.call(arguments);args.unshift(jsxc.tab.CONST.MASTER),jsxc.tab.exec.apply(this,args)},execSlave:function(){var args=Array.prototype.slice.call(arguments);args.unshift(jsxc.tab.CONST.SLAVE),jsxc.tab.exec.apply(this,args)}},jsxc.webrtc={conn:null,localStream:null,remoteStream:null,last_caller:null,AUTO_ACCEPT:!1,reqVideoFeatures:["urn:xmpp:jingle:apps:rtp:video","urn:xmpp:jingle:apps:rtp:audio","urn:xmpp:jingle:transports:ice-udp:1","urn:xmpp:jingle:apps:dtls:0"],reqFileFeatures:["urn:xmpp:jingle:1","urn:xmpp:jingle:apps:file-transfer:3"],chatJids:{},CONST:{NS:{EXTDISCO:"urn:xmpp:extdisco:2"}},init:function(){var self=jsxc.webrtc;if(self.conn=jsxc.xmpp.conn,self.conn.jingle){var manager=self.conn.jingle.manager;$(document).on("message.jsxc",self.onMessage),$(document).on("presence.jsxc",self.onPresence),$(document).on("mediafailure.jingle",self.onMediaFailure),manager.on("incoming",$.proxy(self.onIncoming,self)),manager.on("terminated",$.proxy(self.onTerminated,self)),manager.on("ringing",$.proxy(self.onCallRinging,self)),manager.on("receivedFile",$.proxy(self.onReceivedFile,self)),manager.on("sentFile",function(sess,metadata){jsxc.debug("sent "+metadata.hash)}),manager.on("peerStreamAdded",$.proxy(self.onRemoteStreamAdded,self)),manager.on("peerStreamRemoved",$.proxy(self.onRemoteStreamRemoved,self)),manager.on("log:*",function(level,msg){jsxc.debug("[JINGLE]["+level+"]",msg)}),self.conn.caps&&$(document).on("caps.strophe",self.onCaps),self.setupIceServers()}else jsxc.error("No jingle plugin found!")},onConnected:function(){jsxc.storage.removeUserItem("iceValidity")},onDisconnected:function(){var self=jsxc.webrtc;$(document).off("message.jsxc",self.onMessage),$(document).off("presence.jsxc",self.onPresence),$(document).off("mediafailure.jingle",self.onMediaFailure),$(document).off("caps.strophe",self.onCaps)},setupIceServers:function(){var self=jsxc.webrtc,ttl=(jsxc.storage.getUserItem("iceValidity")||0)-(new Date).getTime();jsxc.storage.getUserItem("iceConfig")&&(jsxc.storage.removeUserItem("iceConfig"),ttl=-1);var url=jsxc.options.get("RTCPeerConfig").url||jsxc.options.turnCredentialsPath,peerConfig=jsxc.options.get("RTCPeerConfig"),domain=self.conn.domain;0<ttl?(self.conn.jingle.setICEServers(peerConfig.iceServers),window.setTimeout(jsxc.webrtc.setupIceServers,ttl+500)):jsxc.xmpp.conn.caps.hasFeatureByJid(domain,self.CONST.NS.EXTDISCO)?self.getIceServersByExternalDisco():"string"==typeof url&&0<url.length?self.getIceServersByUrl(url):self.conn.jingle.setICEServers(peerConfig.iceServers)},getIceServersByExternalDisco:function(){var self=jsxc.webrtc,iq=$iq({type:"get",to:jsxc.xmpp.conn.domain}).c("services",{xmlns:self.CONST.NS.EXTDISCO});jsxc.xmpp.conn.sendIQ(iq,function(res){jsxc.debug("ice servers receiving by xmpp extdisco");var iceServers=[],minTtl=86400;$(res).find(">services>service").each(function(idx,el){var serverItem={};switch((el=$(el)).attr("type")){case"stun":case"stuns":serverItem.urls=el.attr("type")+":"+el.attr("host"),el.attr("port")&&(serverItem.urls+=":"+el.attr("port"));break;case"turn":case"turns":el.attr("username")&&(serverItem.username=el.attr("username")),serverItem.urls=el.attr("type")+":"+el.attr("host"),el.attr("port")&&"3478"!==el.attr("port")&&(serverItem.urls+=":"+el.attr("port")),el.attr("transport")&&"udp"!==el.attr("transport")&&(serverItem.urls+="?transport="+el.attr("transport")),el.attr("password")&&(serverItem.credential=el.attr("password")),el.attr("ttl")&&el.attr("ttl")<minTtl&&(minTtl=el.attr("ttl"))}serverItem.urls&&iceServers.push(serverItem)}),0<iceServers.length?jsxc.webrtc.setIceServers(iceServers,minTtl):jsxc.warn("Found no valid ICE server configuration")},function(err){console.warn("getting turn credentials failed",err)})},getIceServersByUrl:function(url){var self=jsxc.webrtc;$.ajax(url,{async:!0,xhrFields:{withCredentials:jsxc.options.get("RTCPeerConfig").withCredentials},success:function(data){var ttl=data.ttl||3600,iceServers=data.iceServers;if(!iceServers&&data.url&&(jsxc.warn("Received RTCPeer configuration is deprecated. Use now RTCPeerConfig.url."),iceServers=[{urls:data.url}],data.username&&(iceServers[0].username=data.username),data.credential&&(iceServers[0].credential=data.credential)),iceServers&&0<iceServers.length){var url=iceServers[0].url&&0<iceServers[0].url.length;iceServers[0].urls&&0<iceServers[0].urls.length||url?self.setIceServers(iceServers,ttl):jsxc.warn("No valid url found in first ice object.")}},dataType:"json"})},setIceServers:function(iceServers,ttl){jsxc.debug("set ice servers");var peerConfig=jsxc.options.get("RTCPeerConfig");peerConfig.iceServers=iceServers,jsxc.options.set("RTCPeerConfig",peerConfig),jsxc.webrtc.conn.jingle.setICEServers(iceServers),jsxc.storage.setUserItem("iceValidity",(new Date).getTime()+1e3*ttl),window.setTimeout(jsxc.webrtc.setupIceServers,ttl+500)},getCapableRes:function(jid,features){var self=jsxc.webrtc,bid=jsxc.jidToBid(jid),res=Object.keys(jsxc.storage.getUserItem("res",bid)||{})||[];if(!features)return res;"string"==typeof features&&(features=[features]);var available=[];return $.each(res,function(i,r){self.conn.caps.hasFeatureByJid(bid+"/"+r,features)&&available.push(r)}),available},initWindow:function(event,win){var self=jsxc.webrtc;if(!win.hasClass("jsxc_groupchat"))if(jsxc.debug("webrtc.initWindow"),self.conn){var div=$("<div>").addClass("jsxc_video");win.find(".jsxc_tools .jsxc_settings").after(div);var screenMediaExtension=jsxc.options.get("screenMediaExtension")||{},browserDetails=self.conn.jingle.RTC.browserDetails||{},browser=browserDetails.browser,version=browserDetails.version;if(screenMediaExtension[browser]||jsxc.storage.getItem("debug")||"firefox"===browser&&52<=version){var a=$("<a>");a.text($.t("Share_screen")),a.addClass("jsxc_shareScreen jsxc_video"),a.attr("href","#"),win.find(".jsxc_settings .jsxc_menu li:last").after($("<li>").append(a))}self.updateIcon(win.data("bid"))}else $(document).one("attached.jsxc",function(){self.initWindow(null,win)})},updateIcon:function(bid){jsxc.debug("Update icon",bid);var self=jsxc.webrtc;if(bid!==jsxc.jidToBid(self.conn.jid)){var win=jsxc.gui.window.get(bid),jid=win.data("jid"),ls=jsxc.storage.getUserItem("buddy",bid);if("string"!=typeof jid){if(!ls||"string"!=typeof ls.jid)return void jsxc.debug("[webrtc] Could not update icon, because could not find jid for "+bid);jid=ls.jid}var res=Strophe.getResourceFromJid(jid),el=win.find(".jsxc_video"),capableRes=self.getCapableRes(jid,self.reqVideoFeatures),targetRes=res;null===targetRes&&($.each(jsxc.storage.getUserItem("buddy",bid).res||[],function(index,val){if(-1<capableRes.indexOf(val))return targetRes=val,!1}),jid=jid+"/"+targetRes),el.off("click"),-1<capableRes.indexOf(targetRes)?(el.click(function(){$(this).hasClass("jsxc_shareScreen")?self.startScreenSharing(jid):self.startCall(jid)}),el.removeClass("jsxc_disabled"),el.attr("title",$.t("Start_video_call"))):(el.addClass("jsxc_disabled"),el.attr("title",$.t("Video_call_not_possible")))}},onMessage:function(e,from){var self=jsxc.webrtc,bid=jsxc.jidToBid(from);jsxc.debug("webrtc.onmessage",from),self.chatJids[bid]!==from&&(self.updateIcon(bid),self.chatJids[bid]=from)},onPresence:function(ev,jid,status,presence){var self=jsxc.webrtc;0===$(presence).find('c[xmlns="'+Strophe.NS.CAPS+'"]').length&&(jsxc.debug("webrtc.onpresence",jid),self.updateIcon(jsxc.jidToBid(jid)))},setStatus:function(txt,d){var status=$(".jsxc_webrtc .jsxc_status"),duration=null==d?4e3:d;if(jsxc.debug("[Webrtc]",txt),status.html()&&(txt=status.html()+"<br />"+txt),status.html(txt),status.css({"margin-left":"-"+status.width()/2+"px",opacity:0,display:"block"}),status.stop().animate({opacity:1}),clearTimeout(status.data("timeout")),0!==duration){var to=setTimeout(function(){status.stop().animate({opacity:0},function(){status.html("")})},duration);status.data("timeout",to)}},onCaps:function(event,jid){var self=jsxc.webrtc;jsxc.gui.roster.loaded?self.updateIcon(jsxc.jidToBid(jid)):$(document).on("cloaded.roster.jsxc",function(){self.updateIcon(jsxc.jidToBid(jid))})},onMediaFailure:function(ev,err){var msg;switch(err=err||{},jsxc.webrtc.setStatus("media failure"),err.name){case"NotAllowedError":case"PERMISSION_DENIED":msg=$.t("PermissionDeniedError");break;case"HTTPS_REQUIRED":case"EXTENSION_UNAVAILABLE":msg=$.t(err.name);break;default:msg=$.t(err.name)!==err.name?$.t(err.name):$.t("UNKNOWN_ERROR")}jsxc.gui.window.postMessage({bid:jsxc.jidToBid(jsxc.webrtc.last_caller),direction:jsxc.Message.SYS,msg:$.t("Media_failure")+": "+msg+" ("+err.name+")."}),jsxc.gui.dialog.close(),jsxc.debug("media failure: "+err.name)},onIncoming:function(session){var self=jsxc.webrtc,type=session.constructor?session.constructor.name:null;if("FileTransferSession"===type)self.onIncomingFileTransfer(session);else if("MediaSession"===type){var reqMedia=!1;$.each(session.pc.remoteDescription.contents,function(){"both"===this.senders&&(reqMedia=!0)}),(session.call=reqMedia)?self.onIncomingCall(session):self.onIncomingStream(session)}else jsxc.warn("Unknown session type.")},onIncomingStream:function(session){jsxc.debug("incoming stream from "+session.peerID);var self=jsxc.webrtc,bid=jsxc.jidToBid(session.peerID);if(session.on("change:connectionState",$.proxy(self.onIceConnectionStateChanged,self)),self.postScreenMessage(bid,$.t("Incoming_stream"),session.sid),jsxc.notification.notify($.t("Incoming_stream"),$.t("from_sender",{sender:bid})),session.ring(),jsxc.webrtc.last_caller=session.peerID,jsxc.webrtc.AUTO_ACCEPT)acceptIncomingStream(session);else{var dialog=jsxc.gui.dialog.open(jsxc.gui.template.get("incomingCall",bid),{noClose:!0});dialog.find(".jsxc_accept").click(function(){$(document).trigger("accept.call.jsxc"),acceptIncomingStream(session)}),dialog.find(".jsxc_reject").click(function(){jsxc.gui.dialog.close(),$(document).trigger("reject.call.jsxc"),session.decline()})}function acceptIncomingStream(session){jsxc.gui.dialog.close(),jsxc.gui.showVideoWindow(session.peerID),session.accept()}},onIncomingFileTransfer:function(session){jsxc.debug("incoming file transfer from "+session.peerID);var buddylist=jsxc.storage.getUserItem("buddylist")||[],bid=jsxc.jidToBid(session.peerID);if(-1<buddylist.indexOf(bid)){session.accept();var message=jsxc.gui.window.postMessage({_uid:session.sid+":msg",bid:bid,direction:jsxc.Message.IN,attachment:{name:session.receiver.metadata.name,type:session.receiver.metadata.type||"application/octet-stream"}});session.receiver.on("progress",function(sent,size){jsxc.gui.window.updateProgress(message,sent,size)})}},onIncomingCall:function(session){jsxc.debug("incoming call from "+session.peerID);var self=jsxc.webrtc,bid=jsxc.jidToBid(session.peerID);if(session.on("change:connectionState",$.proxy(self.onIceConnectionStateChanged,self)),self.postCallMessage(bid,$.t("Incoming_call"),session.sid),jsxc.notification.notify($.t("Incoming_call"),$.t("from_sender",{sender:bid})),session.ring(),jsxc.webrtc.last_caller=session.peerID,jsxc.webrtc.AUTO_ACCEPT)self.acceptIncomingCall(session);else{var dialog=jsxc.gui.dialog.open(jsxc.gui.template.get("incomingCall",bid),{noClose:!0});dialog.find(".jsxc_accept").click(function(){self.acceptIncomingCall(session)}),dialog.find(".jsxc_reject").click(function(){jsxc.gui.dialog.close(),$(document).trigger("reject.call.jsxc"),session.decline()})}},acceptIncomingCall:function(session){$(document).trigger("accept.call.jsxc");var self=jsxc.webrtc;jsxc.switchEvents({"mediaready.jingle":function(ev,stream){self.setStatus("Accept call"),self.localStream=stream,self.conn.jingle.localStream=stream,jsxc.gui.showVideoWindow(session.peerID).find(".jsxc_videoContainer").addClass("jsxc_establishing"),session.addStream(stream),session.accept()},"mediafailure.jingle":function(){session.decline()}}),self.reqUserMedia()},onTerminated:function(session,reason){var self=jsxc.webrtc;"MediaSession"===(session.constructor?session.constructor.name:null)&&self.onCallTerminated(session,reason)},onCallTerminated:function(session,reason){var self=jsxc.webrtc;self.setStatus("call terminated "+session.peerID+(reason&&reason.condition?reason.condition:""));var bid=jsxc.jidToBid(session.peerID);self.localStream&&("function"==typeof self.localStream.getTracks?self.localStream.getTracks().forEach(function(track){track.stop()}):"function"==typeof self.localStream.stop?self.localStream.stop():jsxc.warn("Could not stop local stream"));$(".jsxc_remotevideo").length&&($(".jsxc_remotevideo")[0].src=""),$(".jsxc_localvideo").length&&($(".jsxc_localvideo")[0].src=""),self.conn.jingle.localStream=null,self.localStream=null,self.remoteStream=null,jsxc.gui.closeVideoWindow(),jsxc.gui.dialog.close(),$(document).trigger("reject.call.jsxc"),$(document).off("error.jingle");var msg=(reason&&reason.condition?": "+$.t("jingle_reason_"+reason.condition):"")+".";session.call?(msg=$.t("Call_terminated")+msg,jsxc.webrtc.postCallMessage(bid,msg,session.sid)):(msg=$.t("Stream_terminated")+msg,jsxc.webrtc.postScreenMessage(bid,msg,session.sid))},onCallRinging:function(){this.setStatus("ringing...",0),$(".jsxc_videoContainer").removeClass("jsxc_establishing").addClass("jsxc_ringing")},onRemoteStreamAdded:function(session,stream){var self=jsxc.webrtc;self.setStatus("Remote stream for session "+session.sid+" added.");var isVideoDevice=0<(self.remoteStream=stream).getVideoTracks().length,isAudioDevice=0<stream.getAudioTracks().length;self.setStatus(isVideoDevice?"Use remote video device.":"No remote video device"),self.setStatus(isAudioDevice?"Use remote audio device.":"No remote audio device"),$(".jsxc_remotevideo").length&&(self.attachMediaStream($("#jsxc_webrtc .jsxc_remotevideo"),stream),$("#jsxc_webrtc .jsxc_"+(isVideoDevice?"remotevideo":"noRemoteVideo")).addClass("jsxc_deviceAvailable"))},attachMediaStream:function(element,stream){(element instanceof jQuery?element.get(0):element).srcObject=stream,$(element).show()},onRemoteStreamRemoved:function(session){this.setStatus("Remote stream for "+session.jid+" removed.")},onIceConnectionStateChanged:function(session,state){var self=jsxc.webrtc;jsxc.debug("connection state for "+session.sid,state),"connected"===state?$("#jsxc_webrtc .jsxc_deviceAvailable").show():"failed"===state?(jsxc.gui.window.postMessage({bid:jsxc.jidToBid(session.peerID),direction:jsxc.Message.SYS,msg:$.t("ICE_connection_failure")}),session.end("failed-transport"),$(document).trigger("callterminated.jingle")):"interrupted"===state&&self.setStatus($.t("Connection_interrupted"))},startCall:function(jid,um){var self=jsxc.webrtc;null!==Strophe.getResourceFromJid(jid)?(self.last_caller=jid,jsxc.switchEvents({"mediaready.jingle":function(ev,stream){jsxc.debug("media ready for outgoing call"),self.initiateOutgoingCall(jid,stream)},"mediafailure.jingle":function(){jsxc.gui.dialog.close()}}),self.reqUserMedia(um)):jsxc.debug("We need a full jid")},initiateOutgoingCall:function(jid,stream){var self=jsxc.webrtc;self.localStream=stream,self.conn.jingle.localStream=stream,jsxc.gui.showVideoWindow(jid).find(".jsxc_videoContainer").addClass("jsxc_establishing"),self.setStatus("Initiate call"),$(document).one("error.jingle",function(ev,sid,error){error&&"offer"!==error.source||setTimeout(function(){jsxc.gui.showAlert("Sorry, we couldn't establish a connection. Maybe your buddy is offline.")},500)});var session=self.conn.jingle.initiate(jid);session.call=!0,session.on("change:connectionState",$.proxy(self.onIceConnectionStateChanged,self)),self.postCallMessage(jsxc.jidToBid(jid),$.t("Call_started"),session.sid)},hangUp:function(reason,text){jsxc.webrtc.conn.jingle.manager&&!$.isEmptyObject(jsxc.webrtc.conn.jingle.manager.peers)?jsxc.webrtc.conn.jingle.terminate(null,reason,text):jsxc.gui.closeVideoWindow(),$(document).trigger("callterminated.jingle")},startScreenSharing:function(jid){var self=this;null!==Strophe.getResourceFromJid(jid)?(self.last_caller=jid,jsxc.switchEvents({"mediaready.jingle":function(ev,stream){self.initiateScreenSharing(jid,stream)},"mediafailure.jingle":function(ev,err){jsxc.gui.dialog.close();var browser=self.conn.jingle.RTC.webrtcDetectedBrowser,screenMediaExtension=jsxc.options.get("screenMediaExtension")||{};screenMediaExtension[browser]&&("EXTENSION_UNAVAILABLE"===err.name||"NotAllowedError"===err.name&&"firefox"===browser)&&setTimeout(function(){jsxc.gui.window.postMessage({bid:jsxc.jidToBid(jid),direction:jsxc.Message.SYS,msg:$.t("Install_extension")+screenMediaExtension[browser]})},500)}}),self.reqUserMedia(["screen"])):jsxc.debug("We need a full jid")},initiateScreenSharing:function(jid,stream){var self=jsxc.webrtc,bid=jsxc.jidToBid(jid);jsxc.webrtc.localStream=stream,jsxc.webrtc.conn.jingle.localStream=stream,jsxc.gui.showMinimizedVideoWindow().addClass("jsxc_establishing"),self.setStatus("Initiate stream"),$(document).one("error.jingle",function(e,sid,error){error&&"offer"!==error.source||setTimeout(function(){jsxc.gui.showAlert("Sorry, we couldn't establish a connection. Maybe your buddy is offline.")},500)});var constraints,browser=self.conn.jingle.RTC.webrtcDetectedBrowser;constraints=self.conn.jingle.RTC.webrtcDetectedVersion<33&&"firefox"===browser||"chrome"===browser?{mandatory:{OfferToReceiveAudio:!1,OfferToReceiveVideo:!1}}:{offerToReceiveAudio:!1,offerToReceiveVideo:!1};var session=self.conn.jingle.initiate(jid,void 0,constraints);session.call=!1,session.on("change:connectionState",$.proxy(self.onIceConnectionStateChanged,self)),session.on("accepted",function(){self.onSessionAccepted(session)}),self.postScreenMessage(bid,$.t("Stream_started"),session.sid)},onSessionAccepted:function(session){var self=jsxc.webrtc;$(".jsxc_videoContainer").removeClass("jsxc_ringing"),self.postScreenMessage(jsxc.jidToBid(session.peerID),$.t("Connection_accepted"),session.sid)},reqUserMedia:function(um){function filterUserMedia(devices){var availableDevices=devices.map(function(device){return device.kind});(um=um.filter(function(el){return-1!==availableDevices.indexOf(el)||-1!==availableDevices.indexOf(el+"input")})).length?jsxc.webrtc.getUserMedia(um):jsxc.warn("No audio/video device available.")}this.localStream?$(document).trigger("mediaready.jingle",[this.localStream]):(um=um||["video","audio"],jsxc.gui.dialog.open(jsxc.gui.template.get("allowMediaAccess"),{noClose:!0}),0<=um.indexOf("screen")?jsxc.webrtc.getScreenMedia():"undefined"!=typeof navigator&&void 0!==navigator.mediaDevices&&void 0!==navigator.mediaDevices.enumerateDevices?navigator.mediaDevices.enumerateDevices().then(filterUserMedia).catch(function(err){jsxc.warn(err.name+": "+err.message)}):"undefined"!=typeof MediaStreamTrack&&void 0!==MediaStreamTrack.getSources?MediaStreamTrack.getSources(filterUserMedia):jsxc.webrtc.getUserMedia(um))},getUserMedia:function(um){var self=jsxc.webrtc,constraints={};-1<um.indexOf("video")&&(constraints.video=!0),-1<um.indexOf("audio")&&(constraints.audio=!0);try{self.conn.jingle.getUserMedia(constraints,self.userMediaCallback)}catch(e){jsxc.error("GUM failed: ",e),$(document).trigger("mediafailure.jingle")}},userMediaCallback:function(err,stream){err?(jsxc.warn("Failed to get access to local media. Error ",err),$(document).trigger("mediafailure.jingle",[err])):stream&&(jsxc.debug("onUserMediaSuccess"),$(document).trigger("mediaready.jingle",[stream]))},getScreenMedia:function(){var self=jsxc.webrtc;jsxc.debug("get screen media"),self.conn.jingle.getScreenMedia(self.screenMediaCallback)},screenMediaCallback:function(err,stream){err?$(document).trigger("mediafailure.jingle",[err]):stream&&(jsxc.debug("onScreenMediaSuccess"),$(document).trigger("mediaready.jingle",[stream]))},screenMediaAvailable:function(){var browser=jsxc.webrtc.conn.jingle.RTC.webrtcDetectedBrowser;return!!sessionStorage.getScreenMediaJSExtensionId&&"chrome"===browser||"firefox"===browser},snapshot:function(video){video||jsxc.debug("Missing video element"),$(".jsxc_snapshotbar p").remove();var canvas=$("<canvas/>").css("display","none").appendTo("body").attr({width:video.width(),height:video.height()}).get(0);canvas.getContext("2d").drawImage(video[0],0,0);var img=$("<img/>"),url=null;try{url=canvas.toDataURL("image/jpeg")}catch(err){return void jsxc.warn("Error",err)}img[0].src=url;var link=$("<a/>").attr({target:"_blank",href:url});link.append(img),$(".jsxc_snapshotbar").append(link),canvas.remove()},sendFile:function(jid,file){jsxc.debug("Send file via webrtc");var self=jsxc.webrtc;if(Strophe.getResourceFromJid(jid)){var sess=self.conn.jingle.manager.createFileTransferSession(jid);return sess.on("change:sessionState",function(){jsxc.debug("Session state",sess.state)}),sess.on("change:connectionState",function(){jsxc.debug("Connection state",sess.connectionState)}),sess.start(file),sess}jsxc.warn("Require full jid to send file via webrtc")},onReceivedFile:function(sess,file,metadata){if(jsxc.debug("file received",metadata),FileReader){var type,reader=new FileReader;if(metadata.type)type=metadata.type;else{var ext=metadata.name.replace(/.+\.([a-z0-9]+)$/i,"$1").toLowerCase();switch(ext){case"jpg":case"jpeg":case"png":case"gif":case"svg":type="image/"+ext.replace(/^jpg$/,"jpeg");break;case"mp3":case"wav":type="audio/"+ext;break;case"pdf":type="application/pdf";break;case"txt":type="text/"+ext;break;default:type="application/octet-stream"}}reader.onload=function(ev){jsxc.gui.window.postMessage({_uid:sess.sid+":msg",bid:jsxc.jidToBid(sess.peerID),direction:jsxc.Message.IN,attachment:{name:metadata.name,type:type,size:metadata.size,data:ev.target.result}})},file.type||(file=new File([file],metadata.name,{type:type})),reader.readAsDataURL(file)}}},jsxc.webrtc.postCallMessage=function(bid,msg,uid){jsxc.gui.window.postMessage({_uid:uid,bid:bid,direction:jsxc.Message.SYS,msg:":telephone_receiver: "+msg})},jsxc.webrtc.postScreenMessage=function(bid,msg,uid){jsxc.gui.window.postMessage({_uid:uid,bid:bid,direction:jsxc.Message.SYS,msg:":computer: "+msg})},jsxc.gui.showMinimizedVideoWindow=function(){var self=jsxc.webrtc;jsxc.gui.dialog.close();var videoContainer=$("<div/>");videoContainer.addClass("jsxc_videoContainer jsxc_minimized"),videoContainer.appendTo("body");var videoElement=$('<video class="jsxc_localvideo" autoplay=""></video>');return videoElement.appendTo(videoContainer),videoElement[0].muted=!0,videoElement[0].volume=0,self.localStream&&self.attachMediaStream(videoElement,self.localStream),videoContainer.append('<div class="jsxc_controlbar"><div><div class="jsxc_hangUp jsxc_videoControl"></div></div></div></div>'),videoContainer.find(".jsxc_hangUp").click(function(){jsxc.webrtc.hangUp("success")}),videoContainer.click(function(){videoContainer.find(".jsxc_controlbar").toggleClass("jsxc_visible")}),videoContainer},jsxc.gui.showVideoWindow=function(jid){var self=jsxc.webrtc;jsxc.gui.dialog.close(),$("body").append(jsxc.gui.template.get("videoWindow")),$("#jsxc_webrtc .jsxc_localvideo")[0].muted=!0,$("#jsxc_webrtc .jsxc_localvideo")[0].volume=0;var rv=$("#jsxc_webrtc .jsxc_remotevideo"),lv=$("#jsxc_webrtc .jsxc_localvideo");self.localStream&&self.attachMediaStream(lv,self.localStream);var w_dialog=$("#jsxc_webrtc").width(),w_remote=rv.width();if(w_dialog<w_remote){var scale=w_dialog/w_remote,new_h=rv.height()*scale,new_w=w_dialog,vc=$("#jsxc_webrtc .jsxc_videoContainer");rv.height(new_h),rv.width(new_w),vc.height(new_h),vc.width(new_w),lv.height(lv.height()*scale),lv.width(lv.width()*scale)}self.remoteStream&&(self.attachMediaStream(rv,self.remoteStream),$("#jsxc_webrtc .jsxc_"+(0<self.remoteStream.getVideoTracks().length?"remotevideo":"noRemoteVideo")).addClass("jsxc_deviceAvailable"));var win=jsxc.gui.window.open(jsxc.jidToBid(jid));return win.find(".slimScrollDiv").resizable("disable"),jsxc.gui.window.resize(win,{size:{width:$("#jsxc_webrtc .jsxc_chatarea").width(),height:$("#jsxc_webrtc .jsxc_chatarea").height()}},!0),$("#jsxc_webrtc .jsxc_chatarea ul").append(win.detach()),$("#jsxc_webrtc .jsxc_hangUp").click(function(){jsxc.webrtc.hangUp("success")}),$("#jsxc_webrtc .jsxc_fullscreen").click(function(){$.support.fullscreen&&($(document).one("disabled.fullscreen",function(){lv.removeAttr("style")}),$("#jsxc_webrtc .jsxc_videoContainer").fullscreen())}),$("#jsxc_webrtc .jsxc_videoContainer").click(function(){$("#jsxc_webrtc .jsxc_controlbar").toggleClass("jsxc_visible")}),$("#jsxc_webrtc")},jsxc.gui.closeVideoWindow=function(){var win=$("#jsxc_webrtc .jsxc_chatarea > ul > li");0<win.length&&($("#jsxc_windowList > ul").prepend(win.detach()),win.find(".slimScrollDiv").resizable("enable"),jsxc.gui.window.resize(win)),$("#jsxc_webrtc, .jsxc_videoContainer").remove()},$.extend(jsxc.CONST,{KEYCODE_ENTER:13,KEYCODE_ESC:27}),$(document).ready(function(){$(document).on("init.window.jsxc",jsxc.webrtc.initWindow),$(document).on("attached.jsxc",jsxc.webrtc.init),$(document).on("disconnected.jsxc",jsxc.webrtc.onDisconnected),$(document).on("connected.jsxc",jsxc.webrtc.onConnected)}),jsxc.xmpp.bookmarks={},jsxc.xmpp.bookmarks.remote=function(){return jsxc.xmpp.conn.caps&&jsxc.xmpp.hasFeatureByJid(jsxc.xmpp.conn.domain,Strophe.NS.PUBSUB+"#publish")},jsxc.xmpp.bookmarks.load=function(){var caps=jsxc.xmpp.conn.caps,ver=caps._jidVerIndex[jsxc.xmpp.conn.domain];ver&&caps._knownCapabilities[ver]||$(document).on("caps.strophe",function(ev,from){from===jsxc.xmpp.conn.domain&&(jsxc.xmpp.bookmarks.load(),$(document).off(ev))}),jsxc.xmpp.bookmarks.remote()?jsxc.xmpp.bookmarks.loadFromRemote():jsxc.xmpp.bookmarks.loadFromLocal()},jsxc.xmpp.bookmarks.loadFromLocal=function(){jsxc.debug("Load bookmarks from local storage");var bookmarks=jsxc.storage.getUserItem("bookmarks")||[],bl=jsxc.storage.getUserItem("buddylist")||[];$.each(bookmarks,function(){var roomdata=jsxc.storage.getUserItem("buddy",this)||{};bl.push(this),jsxc.gui.roster.add(this),roomdata.autojoin&&(jsxc.debug("auto join "+this),jsxc.xmpp.conn.muc.join(this,roomdata.nickname))}),jsxc.storage.setUserItem("buddylist",bl)},jsxc.xmpp.bookmarks.loadFromRemote=function(){jsxc.debug("Load bookmarks from pubsub");var bookmarks=jsxc.xmpp.conn.bookmarks;bookmarks.get(function(stanza){var bl=jsxc.storage.getUserItem("buddylist");$(stanza).find("conference").each(function(){var conference=$(this),room=conference.attr("jid"),roomName=conference.attr("name")||room,autojoin=conference.attr("autojoin")||!1,nickname=conference.find("nick").text();nickname=0<nickname.length?nickname:Strophe.getNodeFromJid(jsxc.xmpp.conn.jid),"true"===autojoin?autojoin=!0:"false"===autojoin&&(autojoin=!1);var data=jsxc.storage.getUserItem("buddy",room)||{};data=$.extend(data,{jid:room,name:roomName,sub:"both",status:0,type:"groupchat",state:jsxc.muc.CONST.ROOMSTATE.INIT,subject:null,bookmarked:!0,autojoin:autojoin,nickname:nickname}),jsxc.storage.setUserItem("buddy",room,data),bl.push(room),jsxc.gui.roster.add(room),autojoin&&(jsxc.debug("auto join "+room),jsxc.xmpp.conn.muc.join(room,nickname))}),jsxc.storage.setUserItem("buddylist",bl)},function(stanza){var err=jsxc.xmpp.bookmarks.parseErr(stanza);"item-not-found"===err.reasons[0]?(jsxc.debug("create bookmark node"),bookmarks.createBookmarksNode(function(){jsxc.debug("Bookmark node created.")},function(){jsxc.debug("Could not create bookmark node.")})):jsxc.debug("[XMPP] Could not create bookmark: "+err.type,err.reasons)})},jsxc.xmpp.bookmarks.parseErr=function(stanza){var error=$(stanza).find("error");return{type:error.attr("type"),reasons:error.children().map(function(){return $(this).prop("tagName")})}},jsxc.xmpp.bookmarks.delete=function(room,soft){soft||jsxc.gui.roster.purge(room),jsxc.xmpp.bookmarks.remote()?jsxc.xmpp.bookmarks.deleteFromRemote(room,soft):jsxc.xmpp.bookmarks.deleteFromLocal(room,soft)},jsxc.xmpp.bookmarks.deleteFromRemote=function(room,soft){jsxc.xmpp.conn.bookmarks.delete(room,function(){jsxc.debug("Bookmark deleted "+room),soft&&(jsxc.gui.roster.getItem(room).removeClass("jsxc_bookmarked"),jsxc.storage.updateUserItem("buddy",room,"bookmarked",!1),jsxc.storage.updateUserItem("buddy",room,"autojoin",!1))},function(stanza){var err=jsxc.xmpp.bookmarks.parseErr(stanza);jsxc.debug("[XMPP] Could not delete bookmark: "+err.type,err.reasons)})},jsxc.xmpp.bookmarks.deleteFromLocal=function(room,soft){var bookmarks=jsxc.storage.getUserItem("bookmarks"),index=bookmarks.indexOf(room);-1<index&&bookmarks.splice(index,1),jsxc.storage.setUserItem("bookmarks",bookmarks),soft&&(jsxc.gui.roster.getItem(room).removeClass("jsxc_bookmarked"),jsxc.storage.updateUserItem("buddy",room,"bookmarked",!1),jsxc.storage.updateUserItem("buddy",room,"autojoin",!1))},jsxc.xmpp.bookmarks.add=function(room,alias,nick,autojoin){jsxc.xmpp.bookmarks.remote()?jsxc.xmpp.bookmarks.addToRemote(room,alias,nick,autojoin):jsxc.xmpp.bookmarks.addToLocal(room,alias,nick,autojoin)},jsxc.xmpp.bookmarks.addToRemote=function(room,alias,nick,autojoin){jsxc.xmpp.conn.bookmarks.add(room,alias,nick,autojoin,function(){jsxc.debug("New bookmark created",room),jsxc.gui.roster.getItem(room).addClass("jsxc_bookmarked"),jsxc.storage.updateUserItem("buddy",room,"bookmarked",!0),jsxc.storage.updateUserItem("buddy",room,"autojoin",autojoin),jsxc.storage.updateUserItem("buddy",room,"nickname",nick)},function(){jsxc.warn("Could not create bookmark",room)})},jsxc.xmpp.bookmarks.addToLocal=function(room,alias,nick,autojoin){jsxc.gui.roster.getItem(room).addClass("jsxc_bookmarked"),jsxc.storage.updateUserItem("buddy",room,"bookmarked",!0),jsxc.storage.updateUserItem("buddy",room,"autojoin",autojoin),jsxc.storage.updateUserItem("buddy",room,"nickname",nick);var bookmarks=jsxc.storage.getUserItem("bookmarks")||[];bookmarks.indexOf(room)<0&&(bookmarks.push(room),jsxc.storage.setUserItem("bookmarks",bookmarks))},jsxc.xmpp.bookmarks.showDialog=function(room){var dialog=jsxc.gui.dialog.open(jsxc.gui.template.get("bookmarkDialog")),data=jsxc.storage.getUserItem("buddy",room);$("#jsxc_room").val(room),$("#jsxc_nickname").val(data.nickname),$("#jsxc_bookmark").change(function(){$(this).prop("checked")?($("#jsxc_nickname").prop("disabled",!1),$("#jsxc_autojoin").prop("disabled",!1),$("#jsxc_autojoin").parent(".checkbox").removeClass("disabled")):($("#jsxc_nickname").prop("disabled",!0),$("#jsxc_autojoin").prop("disabled",!0).prop("checked",!1),$("#jsxc_autojoin").parent(".checkbox").addClass("disabled"))}),$("#jsxc_bookmark").prop("checked",data.bookmarked),$("#jsxc_autojoin").prop("checked",data.autojoin),$("#jsxc_bookmark").change(),dialog.find("form").submit(function(ev){ev.preventDefault();var bookmarked=$("#jsxc_bookmark").prop("checked"),autojoin=$("#jsxc_autojoin").prop("checked"),nickname=$("#jsxc_nickname").val();return bookmarked?jsxc.xmpp.bookmarks.add(room,data.name,nickname,autojoin):data.bookmarked&&jsxc.xmpp.bookmarks.delete(room,!0),jsxc.gui.dialog.close(),!1})},jsxc.xmpp.chatState={conn:null,toComposingNotificationDelay:900},jsxc.xmpp.chatState.init=function(){var self=jsxc.xmpp.chatState;jsxc.xmpp.conn&&jsxc.xmpp.connected?($(document).off("composing.chatstates",jsxc.xmpp.chatState.onComposing),$(document).off("paused.chatstates",jsxc.xmpp.chatState.onPaused),$(document).off("active.chatstates",jsxc.xmpp.chatState.onActive),self.isDisabled()?jsxc.debug("chat state notification disabled"):(self.conn=jsxc.xmpp.conn,$(document).on("composing.chatstates",jsxc.xmpp.chatState.onComposing),$(document).on("paused.chatstates",jsxc.xmpp.chatState.onPaused),$(document).on("active.chatstates",jsxc.xmpp.chatState.onActive))):$(document).on("attached.jsxc",self.init)},jsxc.xmpp.chatState.onComposing=function(ev,jid){var self=jsxc.xmpp.chatState,bid=jsxc.jidToBid(jid),data=jsxc.storage.getUserItem("buddy",bid)||null;if(data&&!jsxc.xmpp.chatState.isDisabled()&&("groupchat"!==data.type||Strophe.getResourceFromJid(jid)!==Strophe.getNodeFromJid(self.conn.jid))){var user="groupchat"===data.type?Strophe.getResourceFromJid(jid):data.name,win=jsxc.gui.window.get(bid);if(0!==win.length){var usersComposing=win.data("composing")||[];-1===usersComposing.indexOf(user)&&(usersComposing.push(user),win.data("composing",usersComposing));var msg=self._genComposingMsg(data.type,usersComposing);jsxc.xmpp.chatState.setStatus(win,msg)}}},jsxc.xmpp.chatState.onPaused=function(ev,jid){var self=jsxc.xmpp.chatState,bid=jsxc.jidToBid(jid),data=jsxc.storage.getUserItem("buddy",bid)||null;if(data&&!jsxc.xmpp.chatState.isDisabled()){var user="groupchat"===data.type?Strophe.getResourceFromJid(jid):data.name,win=jsxc.gui.window.get(bid);if(0!==win.length){var composingMsg,usersComposing=win.data("composing")||[];0<=usersComposing.indexOf(user)&&(usersComposing.splice(usersComposing.indexOf(user),1),win.data("composing",usersComposing)),0!==usersComposing.length&&(composingMsg=self._genComposingMsg(data.type,usersComposing)),jsxc.xmpp.chatState.setStatus(win,composingMsg)}}},jsxc.xmpp.chatState.onActive=function(ev,jid){jsxc.xmpp.chatState.onPaused(ev,jid)},jsxc.xmpp.chatState.startComposing=function(bid){var self=jsxc.xmpp.chatState;if(jsxc.xmpp.conn&&jsxc.xmpp.conn.chatstates&&!jsxc.xmpp.chatState.isDisabled()){var win=jsxc.gui.window.get(bid),timeout=win.data("composing-timeout"),type=win.hasClass("jsxc_groupchat")?"groupchat":"chat";timeout?clearTimeout(timeout):jsxc.xmpp.conn.chatstates.sendComposing(bid,type),timeout=setTimeout(function(){self.pauseComposing(bid,type),win.data("composing-timeout",null)},self.toComposingNotificationDelay),win.data("composing-timeout",timeout)}},jsxc.xmpp.chatState.pauseComposing=function(bid,type){jsxc.xmpp.chatState.isDisabled()||jsxc.xmpp.conn.chatstates.sendPaused(bid,type)},jsxc.xmpp.chatState.endComposing=function(bid){var win=jsxc.gui.window.get(bid);win.data("composing-timeout")&&clearTimeout(win.data("composing-timeout"))},jsxc.xmpp.chatState._genComposingMsg=function(chatType,usersComposing){return usersComposing&&0!==usersComposing.length?"groupchat"===chatType?1<usersComposing.length?usersComposing.join(", ")+$.t("_are_composing"):usersComposing[0]+$.t("_is_composing"):$.t("_is_composing"):(jsxc.debug("usersComposing array is empty?"),"")},jsxc.xmpp.chatState.setStatus=function(win,msg){var statusMsgElement=win.find(".jsxc_status-msg");statusMsgElement.text(msg||""),statusMsgElement.attr("title",msg||""),msg?(statusMsgElement.addClass("jsxc_composing"),win.addClass("jsxc_status-msg-show")):(statusMsgElement.removeClass("jsxc_composing"),win.removeClass("jsxc_status-msg-show"))},jsxc.xmpp.chatState.isDisabled=function(){return!(jsxc.options.get("chatState")||{}).enable},$(document).on("attached.jsxc",jsxc.xmpp.chatState.init),jsxc.xmpp.httpUpload={conn:null,ready:!1,CONST:{NS:{HTTPUPLOAD:"urn:xmpp:http:upload"}}},jsxc.xmpp.httpUpload.init=function(o){var self=jsxc.xmpp.httpUpload;self.conn=jsxc.xmpp.conn;var fileTransferOptions=jsxc.options.get("fileTransfer")||{},options=o||jsxc.options.get("httpUpload");if(!fileTransferOptions.httpUpload.enable)return jsxc.debug("http upload disabled"),void jsxc.options.set("httpUpload",!1);if(options&&options.server)self.ready=!0;else{var caps=jsxc.xmpp.conn.caps,domain=jsxc.xmpp.conn.domain;if(!caps||!domain||void 0===caps._knownCapabilities[caps._jidVerIndex[domain]])return jsxc.debug("Waiting for server capabilities"),void $(document).on("caps.strophe",function onCaps(ev,from){from===domain&&(self.init(),$(document).off("caps.strophe",onCaps))});self.discoverUploadService()}},jsxc.xmpp.httpUpload.discoverUploadService=function(){var self=jsxc.xmpp.httpUpload,domain=self.conn.domain;jsxc.debug("discover http upload service"),jsxc.xmpp.conn.caps.hasFeatureByJid(domain,self.CONST.NS.HTTPUPLOAD)&&self.queryItemForUploadService(domain),self.conn.disco.items(domain,null,function(items){$(items).find("item").each(function(){var jid=$(this).attr("jid");if(self.ready)return!1;self.queryItemForUploadService(jid)})})},jsxc.xmpp.httpUpload.queryItemForUploadService=function(jid,cb){var self=jsxc.xmpp.httpUpload;jsxc.debug("query "+jid+" for upload service"),self.conn.disco.info(jid,null,function(info){var httpUploadFeature=$(info).find('feature[var="'+self.CONST.NS.HTTPUPLOAD+'"]'),httpUploadMaxSize=$(info).find('field[var="max-file-size"]');0<httpUploadFeature.length&&(jsxc.debug("http upload service found on "+jid),jsxc.options.set("httpUpload",{server:jid,name:$(info).find("identity").attr("name"),maxSize:parseInt(httpUploadMaxSize.text())||-1}),self.ready=!0,"function"==typeof cb&&cb.call(info))})},jsxc.xmpp.httpUpload.sendFile=function(file,message){jsxc.debug("Send file via http upload");var self=jsxc.xmpp.httpUpload;message.encrypted=!1,self.requestSlot(file,function(data){data?data.error?(jsxc.warn('The xmpp server responded with an error of the type "'+data.error.type+'"'),message.getDOM().remove(),jsxc.gui.window.postMessage({bid:message.bid,direction:jsxc.Message.SYS,msg:data.error.text}),message.delete()):data.get&&data.put&&(jsxc.debug("slot received, start upload to "+data.put),self.uploadFile(data.put,file,message,function(){var attachment=message.attachment,metaString=attachment.type+"|"+attachment.size+"|"+attachment.name,a=$("<a>");if(a.attr("href",data.get),attachment.data=data.get,attachment.thumbnail){var img=$("<img>");img.attr("alt","Preview:"+metaString),img.attr("src",attachment.thumbnail),a.prepend(img)}else a.text(metaString);message.msg=data.get,message.htmlMsg=$("<span>").append(a).html(),message.type=jsxc.Message.HTML,jsxc.gui.window.postMessage(message)})):jsxc.warn("Unknown error occured. Please check the debug log.")})},jsxc.xmpp.httpUpload.uploadFile=function(url,file,message,success_cb){$.ajax({url:url,type:"PUT",contentType:"application/octet-stream",data:file,processData:!1,xhr:function(){var xhr=$.ajaxSettings.xhr();return xhr.upload.onprogress=function(ev){ev.lengthComputable&&jsxc.gui.window.updateProgress(message,ev.loaded,ev.total)},xhr},success:function(){jsxc.debug("file successful uploaded"),jsxc.gui.window.updateProgress(message,1,1),success_cb&&success_cb()},error:function(){jsxc.warn("error while uploading file to "+url),message.error="Could not upload file",jsxc.gui.window.postMessage(message)}})},jsxc.xmpp.httpUpload.requestSlot=function(file,cb){var self=jsxc.xmpp.httpUpload,options=jsxc.options.get("httpUpload");if(options&&options.server){var iq=$iq({to:options.server,type:"get"}).c("request",{xmlns:self.CONST.NS.HTTPUPLOAD}).c("filename").t(file.name).up().c("size").t(file.size);self.conn.sendIQ(iq,function(stanza){self.successfulRequestSlotCB(stanza,cb)},function(stanza){self.failedRequestSlotCB(stanza,cb)})}else jsxc.warn("could not request upload slot, because I am not aware of a server or http upload is disabled")},jsxc.xmpp.httpUpload.successfulRequestSlotCB=function(stanza,cb){var self=jsxc.xmpp.httpUpload,slot=$(stanza).find('slot[xmlns="'+self.CONST.NS.HTTPUPLOAD+'"]');0<slot.length?cb({put:slot.find("put").text(),get:slot.find("get").text()}):self.failedRequestSlotCB(stanza,cb)},jsxc.xmpp.httpUpload.failedRequestSlotCB=function(stanza,cb){if($(stanza).find("error").length<=0)return jsxc.warn("response does not contain a slot element"),void cb();var error={type:$(stanza).find("error").attr("type")||"unknown",text:$(stanza).find("error text").text()};$(stanza).find("error not-acceptable")?error.reason="not-acceptable":$(stanza).find("error resource-constraint")?error.reason="resource-constraint":$(stanza).find("error not-allowed")&&(error.reason="not-allowed"),cb({error:error})},$(document).on("stateUIChange.jsxc",function(ev,state){state===jsxc.CONST.UISTATE.INITIATING&&jsxc.xmpp.httpUpload.init()}),jsxc.xmpp.mam={conn:null},jsxc.xmpp.mam.init=function(){jsxc.xmpp.mam.conn=jsxc.xmpp.conn},jsxc.xmpp.mam.isEnabled=function(){var mamOptions=jsxc.options.get("mam")||{},features=jsxc.storage.getUserItem("features")||[],hasFeatureMam1=0<=features.indexOf("urn:xmpp:mam:1"),hasFeatureMam2=0<=features.indexOf("urn:xmpp:mam:2");return hasFeatureMam1&&!hasFeatureMam2&&Strophe.addNamespace("MAM","urn:xmpp:mam:1"),(hasFeatureMam1||hasFeatureMam2)&&mamOptions.enable},jsxc.xmpp.mam.nextMessages=function(bid){var self=jsxc.xmpp.mam,buddyData=jsxc.storage.getUserItem("buddy",bid)||{},lastArchiveUid=buddyData.lastArchiveUid,queryId=self.conn.getUniqueId(),mamOptions=jsxc.options.get("mam")||{},history=jsxc.storage.getUserItem("history",bid)||[];if(buddyData.archiveExhausted)jsxc.debug("No more archived messages.");else{var queryOptions={queryid:queryId,before:lastArchiveUid||"",with:bid,onMessage:function(){var args=Array.from(arguments);return args.unshift(bid),self.onMessage.apply(this,args),!0},onComplete:function(){var args=Array.from(arguments);return args.unshift(bid),self.onComplete.apply(this,args),!0}},oldestMessageId=history[history.length-1];if(oldestMessageId&&!lastArchiveUid){var oldestMessage=new jsxc.Message(oldestMessageId);queryOptions.end=new Date(oldestMessage.stamp).toISOString()}mamOptions.max&&(queryOptions.max=mamOptions.max),self.conn.mam.query(void 0,queryOptions)}},jsxc.xmpp.mam.onMessage=function(bid,stanza){var result=(stanza=$(stanza)).find('result[xmlns="'+Strophe.NS.MAM+'"]'),queryId=result.attr("queryid");if(1===result.length){var forwarded=result.find('forwarded[xmlns="'+jsxc.CONST.NS.FORWARD+'"]'),message=forwarded.find("message"),messageId=$(message).attr("id");if(1===message.length){var from=message.attr("from"),to=message.attr("to");if(jsxc.jidToBid(from)===bid||jsxc.jidToBid(to)===bid){var delay=forwarded.find('delay[xmlns="urn:xmpp:delay"]'),stamp=0<delay.length?new Date(delay.attr("stamp")):new Date;stamp=stamp.getTime();var body=$(message).find("body:first").text();if(!body||body.match(/\?OTR/i))return!0;var direction=jsxc.jidToBid(to)===bid?jsxc.Message.OUT:jsxc.Message.IN,textarea=jsxc.gui.window.get(bid).find(".jsxc_textarea");if(0===textarea.find('[id="'+messageId+'"]').length){var pseudoChatElement=$("<div>");pseudoChatElement.attr("id",messageId.replace(/:/g,"-")),pseudoChatElement.attr("data-queryId",queryId);var lastMessage=textarea.find('[data-queryId="'+queryId+'"]').last(),history=jsxc.storage.getUserItem("history",bid)||[];history.indexOf(messageId)<0&&(0===lastMessage.length?(textarea.prepend(pseudoChatElement),history.push(messageId)):(lastMessage.after(pseudoChatElement),history.splice(history.indexOf(lastMessage.attr("id").replace(/-/g,":")),0,messageId))),jsxc.storage.setUserItem("history",bid,history)}jsxc.gui.window.postMessage({_uid:messageId,bid:bid,direction:direction,msg:body,encrypted:!1,forwarded:!0,stamp:stamp})}}}},jsxc.xmpp.mam.onComplete=function(bid,stanza){var fin=(stanza=$(stanza)).find('fin[xmlns="'+Strophe.NS.MAM+'"]'),buddyData=jsxc.storage.getUserItem("buddy",bid)||{},win=jsxc.gui.window.get(bid);buddyData.archiveExhausted="true"===fin.attr("complete"),buddyData.lastArchiveUid=fin.find("first").text(),buddyData.archiveExhausted&&win.find(".jsxc_fade").removeClass("jsxc_mam-enable"),jsxc.storage.setUserItem("buddy",bid,buddyData)},jsxc.xmpp.mam.initWindow=function(ev,win){var self=jsxc.xmpp.mam;jsxc.xmpp.conn||!jsxc.master?jsxc.master&&($(document).on("features.jsxc",function(){jsxc.xmpp.mam.addLoadButton(win)}),null!==jsxc.storage.getUserItem("features")&&jsxc.xmpp.mam.addLoadButton(win)):$(document).one("attached.jsxc",function(){self.initWindow(null,win)})},jsxc.xmpp.mam.addLoadButton=function(win){if(jsxc.xmpp.mam.isEnabled()){var bid=win.attr("data-bid"),element=$("<div>");element.addClass("jsxc_mam-load-more"),element.appendTo(win.find(".slimScrollDiv")),element.click(function(){jsxc.xmpp.mam.nextMessages(bid)}),element.text($.t("Load_older_messages")),win.find(".jsxc_textarea").scroll(function(){var buddyData=jsxc.storage.getUserItem("buddy",bid)||{};this.scrollTop<42&&!buddyData.archiveExhausted?element.addClass("jsxc_show"):element.removeClass("jsxc_show"),buddyData.archiveExhausted||win.find(".jsxc_fade").addClass("jsxc_mam-enable")}),win.find(".jsxc_textarea").scroll()}},$(document).on("attached.jsxc",jsxc.xmpp.mam.init),$(document).on("init.window.jsxc",jsxc.xmpp.mam.initWindow),jsxc.gui.template.aboutDialog='<h3>JavaScript XMPP Chat</h3>\n<p>\n <b>Version: </b><span data-var="version" />\n <br /> <a href="http://jsxc.org/" target="_blank">www.jsxc.org</a>\n</p>\n<p>\n <i>Released under the MIT license</i>\n</p>\n<p>\n Real-time chat app for <span data-var="app_name" /> and more.\n <br /> Requires an external <a href="https://xmpp.org/xmpp-software/servers/" target="_blank">XMPP server</a>.\n</p>\n<p class="jsxc_credits">\n <b>Credits: </b> <a href="http://www.beepzoid.com/old-phones/" target="_blank">David English (Ringtone)</a>,\n <a href="https://soundcloud.com/freefilmandgamemusic/ping-1?in=freefilmandgamemusic/sets/free-notification-sounds-and" target="_blank">CameronMusic (Ping)</a>,\n <a href="http://www.picol.org/">Picol (Fullscreen icon)</a>, <a href="http://www.jabber.org/">Jabber Software Foundation (Jabber lightbulb logo)</a>\n</p>\n<p class="jsxc_libraries">\n <b>Libraries: </b>\n <a href="http://strophe.im/strophejs/">strophe.js</a> (multiple), <a href="https://github.com/strophe/strophejs-plugins">strophe.js/muc</a> (MIT), <a href="https://github.com/strophe/strophejs-plugins">strophe.js/disco</a> (MIT), <a href="https://github.com/strophe/strophejs-plugins">strophe.js/caps</a> (MIT), <a href="https://github.com/strophe/strophejs-plugins">strophe.js/vcard</a> (MIT), <a href="https://github.com/strophe/strophejs-plugins/tree/master/bookmarks">strophe.js/bookmarks</a> (MIT), <a href="https://github.com/strophe/strophejs-plugins/tree/master/dataforms">strophe.js/x</a> (MIT), <a href="https://github.com/strophe/strophejs-plugins/tree/master/chatstates">strophe.js/chatstates</a> (MIT), <a href="https://github.com/strophe/strophejs-plugin-mam">strophe.js/mam</a> (MIT), <a href="https://github.com/strophe/strophejs-plugin-rsm">strophe.js/rsm</a> (MIT), <a href="https://github.com/sualko/strophe.jinglejs">strophe.jinglejs</a> (MIT), <a href="https://github.com/neoatlantis/node-salsa20">Salsa20</a> (AGPL3), <a href="www.leemon.com">bigint</a> (public domain), <a href="code.google.com/p/crypto-js">cryptojs</a> (code.google.com/p/crypto-js/wiki/license), <a href="http://git.io/ee">eventemitter</a> (MIT), <a href="https://arlolra.github.io/otr/">otr.js</a> (MPL v2.0), <a href="http://i18next.com/">i18next</a> (MIT), <a href="http://i18next.com/">jquery-i18next</a> (MIT), <a href="http://dimsemenov.com/plugins/magnific-popup/">Magnific Popup</a> (MIT), <a href="https://github.com/ejci/favico.js">favico.js</a> (MIT), <a href="http://emojione.com">emoji one</a> (CC-BY 4.0)\n</p>\n\n<button class="btn btn-default pull-right jsxc_debuglog">Show debug log</button>\n',jsxc.gui.template.alert='<h3 data-i18n="Alert"></h3>\n<div class="alert alert-info">\n <strong data-i18n="Info"></strong> <span data-var="msg" />\n</div>\n',jsxc.gui.template.allowMediaAccess='<p data-i18n="Please_allow_access_to_microphone_and_camera"></p>\n',jsxc.gui.template.approveDialog='<h3 data-i18n="Subscription_request"></h3>\n<p>\n <span data-i18n="You_have_a_request_from"></span> <b class="jsxc_their_jid"></b>.\n</p>\n\n<button class="btn btn-primary jsxc_approve pull-right" data-i18n="Approve"></button>\n<button class="btn btn-default jsxc_deny pull-right" data-i18n="Deny"></button>\n',jsxc.gui.template.authenticationDialog='<h3>Verification</h3>\n<p data-i18n="Authenticating_a_buddy_helps_"></p>\n<div>\n <p data-i18n="[html]How_do_you_want_to_authenticate_your_buddy"></p>\n\n <div class="btn-group" role="group">\n <button class="btn btn-default" data-i18n="Manual"></button>\n <button class="btn btn-default" data-i18n="Question"></button>\n <button class="btn btn-default" data-i18n="Secret"></button>\n </div>\n</div>\n<hr />\n<div class="jsxc_hidden">\n <p data-i18n="To_verify_the_fingerprint_" class="jsxc_explanation"></p>\n <p>\n <strong data-i18n="Your_fingerprint"></strong>\n <br /> <span class="jsxc_uppercase"><span data-var="my_priv_fingerprint"/></span>\n </p>\n <p>\n <strong data-i18n="Buddy_fingerprint"></strong>\n <br /> <span class="jsxc_uppercase"><span data-var="bid_priv_fingerprint"/></span>\n </p>\n <div class="jsxc_right">\n <button class="btn btn-default jsxc_close" data-i18n="Close"></button>\n <button class="btn btn-primary jsxc_submit" data-i18n="Compared"></button>\n </div>\n</div>\n<div class="form-horizontal jsxc_hidden">\n <p data-i18n="To_authenticate_using_a_question_" class="jsxc_explanation"></p>\n <div class="form-group">\n <label class="col-sm-4 control-label" for="jsxc_quest" data-i18n="Question"></label>\n <div class="col-sm-8">\n <input type="text" name="quest" id="jsxc_quest" class="form-control" />\n </div>\n </div>\n <div class="form-group">\n <label class="col-sm-4 control-label" for="jsxc_secret2" data-i18n="Secret"></label>\n <div class="col-sm-8">\n <input type="text" name="secret2" id="jsxc_secret2" class="form-control" />\n </div>\n </div>\n <div class="form-group">\n <div class="col-sm-offset-4 col-sm-8">\n <button class="btn btn-default jsxc_close" data-i18n="Close"></button>\n <button class="btn btn-primary jsxc_submit" data-i18n="Ask"></button>\n </div>\n </div>\n</div>\n<div class="form-horizontal jsxc_hidden">\n <p class="jsxc_explanation" data-i18n="To_authenticate_pick_a_secret_"></p>\n <div class="form-group">\n <label class="col-sm-4 control-label" for="jsxc_secret" data-i18n="Secret"></label>\n <div class="col-sm-8">\n <input type="text" name="secret" id="jsxc_secret" class="form-control" />\n </div>\n </div>\n <div class="form-group">\n <div class="col-sm-offset-4 col-sm-8">\n <button class="btn btn-default jsxc_close" data-i18n="Close"></button>\n <button class="btn btn-primary jsxc_submit" data-i18n="Compare"></button>\n </div>\n </div>\n</div>\n',jsxc.gui.template.authFailDialog='<h3 data-i18n="Login_failed"></h3>\n<p data-i18n="Sorry_we_cant_authentikate_"></p>\n\n<button class="btn btn-primary jsxc_retry pull-right" data-i18n="Continue_without_chat"></button>\n<button class="btn btn-default jsxc_cancel pull-right" data-i18n="Retry"></button>\n',jsxc.gui.template.bookmarkDialog='<h3 data-i18n="Edit_bookmark"></h3>\n<form class="form-horizontal">\n <div class="form-group">\n <label class="col-sm-4 control-label" for="jsxc_room" data-i18n="Room"></label>\n <div class="col-sm-8">\n <input type="text" id="jsxc_room" class="form-control" required="required" readonly="readonly" />\n </div>\n </div>\n <div class="form-group">\n <label class="col-sm-4 control-label" for="jsxc_nickname" data-i18n="Nickname"></label>\n <div class="col-sm-8">\n <input type="text" disabled="disabled" required="required" name="nickname" id="jsxc_nickname" class="form-control" />\n </div>\n </div>\n <div class="form-group">\n <div class="col-sm-offset-4 col-sm-8">\n <div class="checkbox">\n <label>\n <input id="jsxc_bookmark" type="checkbox"><span data-i18n="Bookmark"></span>\n </label>\n </div>\n </div>\n </div>\n <div class="form-group">\n <div class="col-sm-offset-4 col-sm-8">\n <div class="checkbox disabled">\n <label>\n <input disabled="disabled" id="jsxc_autojoin" type="checkbox"><span data-i18n="Auto-join"></span>\n </label>\n </div>\n </div>\n </div>\n <div class="form-group">\n <div class="col-sm-offset-4 col-sm-8">\n <button type="button" class="btn btn-default jsxc_close" data-i18n="Close"></button>\n <button type="submit" class="btn btn-primary jsxc_submit" data-i18n="Save"></button>\n </div>\n </div>\n</form>\n',jsxc.gui.template.chatWindow='<li class="jsxc_windowItem">\n <div class="jsxc_window">\n <div class="jsxc_bar">\n <div class="jsxc_avatar jsxc_statusIndicator"></div>\n <div class="jsxc_tools">\n <div class="jsxc_settings">\n <div class="jsxc_more"></div>\n <div class="jsxc_inner jsxc_menu">\n <ul>\n <li>\n <a class="jsxc_verification" href="#">\n <span data-i18n="Authentication"></span>\n </a>\n </li>\n <li>\n <a class="jsxc_clear" href="#">\n <span data-i18n="clear_history"></span>\n </a>\n </li>\n <li>\n <a class="jsxc_sendFile" href="#">\n <span data-i18n="Send_file"></span>\n </a>\n </li>\n <li>\n <a class="jsxc_sendLocation" href="#">\n <span data-i18n="Send_location"></span>\n </a>\n </li>\n </ul>\n </div>\n </div>\n <div class="jsxc_close">×</div>\n </div>\n <div class="jsxc_caption">\n <div class="jsxc_name" />\n <div class="jsxc_lastmsg">\n <span class="jsxc_unread" />\n <span class="jsxc_text" />\n </div>\n <div class="jsxc_status-msg" />\n </div>\n </div>\n <div class="jsxc_fade">\n <div class="jsxc_overlay">\n <div>\n <div class="jsxc_body" />\n <div class="jsxc_close" />\n </div>\n </div>\n <div class="jsxc_textarea" />\n <div class="jsxc_emoticons">\n <div class="jsxc_inner">\n <ul>\n <li class="jsxc_clear"></li>\n </ul>\n </div>\n </div>\n <div class="jsxc_transfer jsxc_otr jsxc_disabled" />\n <textarea class="jsxc_textinput" data-i18n="[placeholder]Message"></textarea>\n </div>\n </div>\n</li>\n',jsxc.gui.template.confirmDialog='<p data-var="msg"></p>\n\n<button class="jsxc_btn jsxc_btn-primary jsxc_confirm pull-right" data-i18n="Confirm"></button>\n<button class="jsxc_btn jsxc_btn-default jsxc_dismiss jsxc_close pull-right" data-i18n="Dismiss"></button>\n',jsxc.gui.template.contactDialog='<h3 data-i18n="Add_buddy"></h3>\n<p class=".jsxc_explanation" data-i18n="Type_in_the_full_username_"></p>\n<form class="form-horizontal">\n <div class="form-group">\n <label class="col-sm-4 control-label" for="jsxc_username" data-i18n="Username"></label>\n <div class="col-sm-8">\n <input type="text" name="username" id="jsxc_username" class="form-control" list="jsxc_userlist" pattern="^[^\\x22&\'\\\\/:<>@\\s]+(@[.\\-_\\w]+)?" required="required" />\n </div>\n </div>\n <datalist id="jsxc_userlist"></datalist>\n <div class="form-group">\n <label class="col-sm-4 control-label" for="jsxc_alias" data-i18n="Alias"></label>\n <div class="col-sm-8">\n <input type="text" name="alias" id="jsxc_alias" class="form-control" />\n </div>\n </div>\n <div class="form-group">\n <div class="col-sm-offset-4 col-sm-8">\n <button class="btn btn-default jsxc_close" type="button" data-i18n="Close"></button>\n <button class="btn btn-primary" type="submit" data-i18n="Add"></button>\n </div>\n </div>\n</form>\n',jsxc.gui.template.fingerprintsDialog='<div>\n <p class="jsxc_maxWidth" data-i18n="A_fingerprint_"></p>\n <p>\n <strong data-i18n="Your_fingerprint"></strong>\n <br /> <span class="jsxc_uppercase" data-var="my_priv_fingerprint"></span>\n </p>\n <p>\n <strong data-i18n="Buddy_fingerprint"></strong>\n <br /> <span class="jsxc_uppercase" data-var="bid_priv_fingerprint"></span>\n </p>\n</div>\n',jsxc.gui.template.incomingCall='<h3 data-i18n="Incoming_call"></h3>\n<p>\n <span data-i18n="Do_you_want_to_accept_the_call_from"></span> <span data-var="bid_name" />?\n</p>\n\n<button class="jsxc_btn jsxc_btn-primary jsxc_accept pull-right" data-i18n="Accept"></button>\n<button class="jsxc_btn jsxc_btn-default jsxc_reject pull-right" data-i18n="Reject"></button>\n',jsxc.gui.template.joinChat='<h3 data-i18n="Join_chat"></h3>\n<p class=".jsxc_explanation" data-i18n="muc_explanation"></p>\n<div class="form-horizontal">\n <div class="form-group">\n <label class="col-sm-4 control-label" for="jsxc_server" data-i18n="Server"></label>\n <div class="col-sm-8">\n <input type="text" name="server" id="jsxc_server" class="form-control" required="required" pattern="^[.-0-9a-zA-Z]+" />\n <p class="jsxc_inputinfo jsxc_server jsxc_hidden"></p>\n </div>\n </div>\n <div class="form-group">\n <label class="col-sm-4 control-label" for="jsxc_room" data-i18n="Room"></label>\n <div class="col-sm-8">\n <input type="text" name="room" id="jsxc_room" class="form-control" autocomplete="off" list="jsxc_roomlist" required="required" pattern="^[^\\x22&\'\\/:<>@\\s]+" />\n <p class="jsxc_inputinfo jsxc_room" data-i18n="Rooms_are_loaded"></p>\n </div>\n </div>\n <datalist id="jsxc_roomlist">\n <p>\n <label for="jsxc_roomlist_select"></label>\n <select id="jsxc_roomlist_select">\n <option></option>\n <option>workaround</option>\n </select>\n </p>\n </datalist>\n <div class="form-group">\n <label class="col-sm-4 control-label" for="jsxc_nickname" data-i18n="Nickname"></label>\n <div class="col-sm-8">\n <input type="text" name="nickname" id="jsxc_nickname" class="form-control" />\n </div>\n </div>\n <div class="form-group jsxc_hidden">\n <label class="col-sm-4 control-label" for="jsxc_password" data-i18n="Password"></label>\n <div class="col-sm-8">\n <input type="text" name="password" id="jsxc_password" class="form-control" />\n </div>\n </div>\n <div class="form-group jsxc_bookmark">\n <div class="col-sm-offset-4 col-sm-8">\n <div class="checkbox">\n <label>\n <input id="jsxc_bookmark" type="checkbox"><span data-i18n="Bookmark"></span>\n </label>\n </div>\n </div>\n </div>\n <div class="form-group jsxc_bookmark">\n <div class="col-sm-offset-4 col-sm-8">\n <div class="checkbox disabled">\n <label>\n <input disabled="disabled" id="jsxc_autojoin" type="checkbox"><span data-i18n="Auto-join"></span>\n </label>\n </div>\n </div>\n </div>\n <div class="jsxc_msg"></div>\n <div class="form-group">\n <div class="col-sm-offset-4 col-sm-8">\n <button class="btn btn-default jsxc_close" data-i18n="Close"></button>\n <button class="btn btn-primary jsxc_continue" data-i18n="Continue"></button>\n <button class="btn btn-success jsxc_join" data-i18n="Join"></button>\n </div>\n </div>\n</div>\n',jsxc.gui.template.loginBox='<h3 data-i18n="Login"></h3>\n<form class="form-horizontal">\n <div class="form-group">\n <label class="col-sm-4 control-label" for="jsxc_username" data-i18n="Username"></label>\n <div class="col-sm-8">\n <input type="text" name="username" id="jsxc_username" class="form-control" required="required" data-var="my_node" />\n </div>\n </div>\n <div class="form-group">\n <label class="col-sm-4 control-label" for="jsxc_password" data-i18n="Password"></label>\n <div class="col-sm-8">\n <input type="password" name="password" required="required" class="form-control" id="jsxc_password" />\n </div>\n </div>\n <div class="jsxc_alert jsxc_alert-warning" data-i18n="Sorry_we_cant_authentikate_"></div>\n <div class="form-group">\n <div class="col-sm-offset-4 col-sm-9">\n <button type="reset" class="btn btn-default jsxc_close" name="clear" data-i18n="Cancel" />\n <button type="submit" class="btn btn-primary" name="commit" data-i18n="[data-jsxc-loading-text]Connecting...;Connect" />\n </div>\n </div>\n</form>\n',jsxc.gui.template.notification='<h3></h3>\n\n<p class="jsxc_msg"></p>\n\n<p class="jsxc_meta"></p>\n',jsxc.gui.template.pleaseAccept='<p data-i18n="Please_accept_"></p>\n',jsxc.gui.template.removeDialog='<h3 data-i18n="Remove_buddy"></h3>\n<p class="jsxc_maxWidth" data-i18n="[html]You_are_about_to_remove_"></p>\n\n<button class="btn btn-primary jsxc_remove pull-right" data-i18n="Remove"></button>\n<button class="btn btn-default jsxc_cancel jsxc_close pull-right" data-i18n="Cancel"></button>\n',jsxc.gui.template.roster='<div id="jsxc_roster">\n <ul id="jsxc_buddylist"></ul>\n <div class="jsxc_bottom jsxc_presence jsxc_rosteritem" data-bid="own">\n <div id="jsxc_avatar" class="jsxc_avatar jsxc_statusIndicator" />\n <div id="jsxc_menu">\n <span></span>\n <div class="jsxc_inner">\n <ul>\n <li class="jsxc_settings jsxc_settingsicon" data-i18n="Settings"></li>\n <li class="jsxc_muteNotification" data-i18n="Mute"></li>\n <li class="jsxc_hideOffline" data-i18n="Hide_offline"></li>\n <li class="jsxc_addBuddy jsxc_contacticon" data-i18n="Add_buddy"></li>\n <li class="jsxc_onlineHelp jsxc_helpicon" data-i18n="Online_help"></li>\n <li class="jsxc_about" data-i18n="About"></li>\n </ul>\n </div>\n </div>\n <div id="jsxc_notice">\n <span></span>\n <div class="jsxc_inner">\n <ul></ul>\n </div>\n </div>\n <div id="jsxc_presence">\n <span data-i18n="Offline">Offline</span>\n <div class="jsxc_inner">\n <ul>\n <li data-pres="online" class="jsxc_online" data-i18n="Online"></li>\n <li data-pres="chat" class="jsxc_chat" data-i18n="Chatty"></li>\n <li data-pres="away" class="jsxc_away" data-i18n="Away"></li>\n <li data-pres="xa" class="jsxc_xa" data-i18n="Extended_away"></li>\n <li data-pres="dnd" class="jsxc_dnd" data-i18n="dnd"></li>\n <li data-pres="offline" class="jsxc_offline" data-i18n="Offline"></li>\n </ul>\n </div>\n </div>\n </div>\n <div id="jsxc_toggleRoster"></div>\n</div>\n',jsxc.gui.template.rosterBuddy='<li class="jsxc_rosteritem">\n <div class="jsxc_avatar jsxc_statusIndicator"></div>\n <div class="jsxc_more" />\n <div class="jsxc_caption">\n <div class="jsxc_name" />\n <div class="jsxc_lastmsg">\n <span class="jsxc_unread" />\n <span class="jsxc_text" />\n </div>\n </div>\n <div class="jsxc_menu">\n <ul>\n <li><a class="jsxc_rename" href="#"><span class="jsxc_icon jsxc_editicon"></span><span data-i18n="rename_buddy"></span></a></li>\n <li><a class="jsxc_vcard" href=""><span class="jsxc_icon jsxc_infoicon"></span><span data-i18n="get_info"></span></a></li>\n <li><a class="jsxc_delete" href=""><span class="jsxc_icon jsxc_deleteicon"></span><span data-i18n="delete_buddy"></span></a></li>\n </ul>\n </div>\n</li>\n',jsxc.gui.template.selectionDialog='<h3></h3>\n<p></p>\n\n<button class="btn btn-primary pull-right" data-i18n="Confirm"></button>\n<button class="btn btn-default pull-right" data-i18n="Dismiss"></button>\n',jsxc.gui.template.settings='<form class="form-horizontal col-sm-6">\n <fieldset class="jsxc_fieldsetXmpp jsxc_fieldset">\n <h3 data-i18n="Login_options"></h3>\n <p data-i18n="setting-explanation-xmpp"></p>\n <div class="form-group">\n <label class="col-sm-6 control-label" for="xmpp-url" data-i18n="BOSH_url"></label>\n <div class="col-sm-6">\n <input type="text" id="xmpp-url" class="form-control" readonly="readonly" />\n </div>\n </div>\n <div class="form-group">\n <label class="col-sm-6 control-label" for="xmpp-username" data-i18n="Username"></label>\n <div class="col-sm-6">\n <input type="text" id="xmpp-username" class="form-control" />\n </div>\n </div>\n <div class="form-group">\n <label class="col-sm-6 control-label" for="xmpp-domain" data-i18n="Domain"></label>\n <div class="col-sm-6">\n <input type="text" id="xmpp-domain" class="form-control" />\n </div>\n </div>\n <div class="form-group">\n <label class="col-sm-6 control-label" for="xmpp-resource" data-i18n="Resource"></label>\n <div class="col-sm-6">\n <input class="form-control" type="text" id="xmpp-resource" class="form-control" />\n </div>\n </div>\n <div class="form-group">\n <div class="col-sm-offset-6 col-sm-6">\n <button class="btn btn-primary jsxc_continue" type="submit" data-i18n="Save"></button>\n </div>\n </div>\n </fieldset>\n</form>\n\n<form class="form-horizontal col-sm-6">\n <fieldset class="jsxc_fieldsetPriority jsxc_fieldset">\n <h3 data-i18n="Priority"></h3>\n <p data-i18n="setting-explanation-priority"></p>\n <div class="form-group">\n <label class="col-sm-6 control-label" for="priority-online" data-i18n="Online"></label>\n <div class="col-sm-6">\n <input type="number" value="0" id="priority-online" class="form-control" min="-128" max="127" step="1" required="required" />\n </div>\n </div>\n <div class="form-group">\n <label class="col-sm-6 control-label" for="priority-chat" data-i18n="Chatty"></label>\n <div class="col-sm-6">\n <input type="number" value="0" id="priority-chat" class="form-control" min="-128" max="127" step="1" required="required" />\n </div>\n </div>\n <div class="form-group">\n <label class="col-sm-6 control-label" for="priority-away" data-i18n="Away"></label>\n <div class="col-sm-6">\n <input type="number" value="0" id="priority-away" class="form-control" min="-128" max="127" step="1" required="required" />\n </div>\n </div>\n <div class="form-group">\n <label class="col-sm-6 control-label" for="priority-xa" data-i18n="Extended_away"></label>\n <div class="col-sm-6">\n <input type="number" value="0" id="priority-xa" class="form-control" min="-128" max="127" step="1" required="required" />\n </div>\n </div>\n <div class="form-group">\n <label class="col-sm-6 control-label" for="priority-dnd" data-i18n="dnd"></label>\n <div class="col-sm-6">\n <input type="number" value="0" id="priority-dnd" class="form-control" min="-128" max="127" step="1" required="required" />\n </div>\n </div>\n <div class="form-group">\n <div class="col-sm-offset-6 col-sm-6">\n <button class="btn btn-primary jsxc_continue" type="submit" data-i18n="Save"></button>\n </div>\n </div>\n </fieldset>\n</form>\n\n<form class="form-horizontal col-sm-6">\n <fieldset class="jsxc_fieldsetLoginForm jsxc_fieldset">\n <h3 data-i18n="On_login"></h3>\n <p data-i18n="setting-explanation-login"></p>\n <div class="form-group">\n <div class="col-sm-12">\n <div class="checkbox">\n <label>\n <input type="checkbox" id="loginForm-enable"><span data-i18n="On_login"></span>\n </label>\n </div>\n </div>\n </div>\n <div class="form-group">\n <div class="col-sm-12">\n <button class="btn btn-primary jsxc_continue" type="submit" data-i18n="Save"></button>\n </div>\n </div>\n </fieldset>\n</form>\n\n<form class="form-horizontal col-sm-6">\n <fieldset class="jsxc_fieldsetMam jsxc_fieldset">\n <h3 class="jsxc_experimental" data-i18n="Message_history"></h3>\n <p data-i18n="setting-mam-enable"></p>\n <div class="form-group">\n <div class="col-sm-12">\n <div class="checkbox">\n <label>\n <input type="checkbox" id="mam-enable"><span data-i18n="Enable"></span>\n </label>\n </div>\n </div>\n </div>\n <div class="form-group">\n <div class="col-sm-12">\n <button class="btn btn-primary jsxc_continue" type="submit" data-i18n="Save"></button>\n </div>\n </div>\n </fieldset>\n</form>\n\n<form class="form-horizontal col-sm-6" data-onsubmit="xmpp.carbons.refresh">\n <fieldset class="jsxc_fieldsetCarbons jsxc_fieldset">\n <h3 data-i18n="Carbon_copy"></h3>\n <p data-i18n="setting-explanation-carbon"></p>\n <div class="form-group">\n <div class="col-sm-12">\n <div class="checkbox">\n <label>\n <input type="checkbox" id="carbons-enable"><span data-i18n="Enable"></span>\n </label>\n </div>\n </div>\n </div>\n <div class="form-group">\n <div class="col-sm-12">\n <button class="btn btn-primary jsxc_continue" type="submit" data-i18n="Save"></button>\n </div>\n </div>\n </fieldset>\n</form>\n\n<form class="form-horizontal col-sm-6" data-onsubmit="xmpp.chatState.init">\n <fieldset class="jsxc_fieldsetCarbons jsxc_fieldset">\n <h3 data-i18n="Chat_state_notifications"></h3>\n <p data-i18n="setting-explanation-chat-state"></p>\n <div class="form-group">\n <div class="col-sm-12">\n <div class="checkbox">\n <label>\n <input type="checkbox" id="chatState-enable"><span data-i18n="Enable"></span>\n </label>\n </div>\n </div>\n </div>\n <div class="form-group">\n <div class="col-sm-12">\n <button class="btn btn-primary jsxc_continue" type="submit" data-i18n="Save"></button>\n </div>\n </div>\n </fieldset>\n</form>\n',jsxc.gui.template.vCard='<h3>\n <span data-i18n="Info_about"></span> <span data-var="bid_name"></span>\n</h3>\n<ul class="jsxc_vCard"></ul>\n<p>\n <img src="{{root}}/img/loading.gif" alt="wait" width="32px" height="32px" /> <span data-i18n="Please_wait"></span>...\n</p>\n',jsxc.gui.template.videoWindow='<div id="jsxc_webrtc">\n <div class="jsxc_chatarea">\n <ul></ul>\n </div>\n <div class="jsxc_videoContainer">\n <video class="jsxc_localvideo" autoplay></video>\n <video class="jsxc_remotevideo" autoplay></video>\n <div class="jsxc_status"></div>\n <div class="jsxc_noRemoteVideo">\n <div>\n <div></div>\n <p data-i18n="No_video_signal"></p>\n <div></div>\n </div>\n </div>\n <div class="jsxc_controlbar jsxc_visible">\n <div>\n <div class="jsxc_hangUp jsxc_videoControl" />\n <div class="jsxc_fullscreen jsxc_videoControl" />\n </div>\n </div>\n </div>\n <div class="jsxc_multi">\n <div class="jsxc_snapshotbar">\n <p>No pictures yet!</p>\n </div>\n \x3c!--<div class="jsxc_chatarea">\n <ul></ul>\n </div>--\x3e\n <div class="jsxc_infobar"></div>\n </div>\n</div>\n',jsxc.gui.template.waitAlert='<h3 data-var="msg"></h3>\n\n<div class="progress">\n <div class="progress-bar progress-bar-striped active" data-i18n="Please_wait">\n </div>\n</div>\n',jsxc.gui.template.windowList='<div id="jsxc_windowList">\n <ul></ul>\n</div>\n<div id="jsxc_windowListSB">\n <div class="jsxc_scrollLeft jsxc_disabled"><</div>\n <div class="jsxc_scrollRight jsxc_disabled">></div>\n</div>\n'}(jQuery);
//# sourceMappingURL=jsxc.min.js.map