").html(text).text();},parseUrl:function(url){var parts=url.match(Echo.Vars.regexps.parseUrl);return parts?{scheme:parts[3],domain:parts[4],path:parts[5],query:parts[7],fragment:parts[9]}:undefined;},toDOM:function(template,prefix,renderer){var content=$(template);var elements=$.mapClass2Object(content);var dom={set:function(name,element){elements[prefix+name]=element;},get:function(name,ignorePrefix){var element=elements[(ignorePrefix?"":prefix)+name];return element&&$(element);},remove:function(element){var name;if(typeof element=="string"){name=prefix+element;}else{name=element.echo.name;}$(elements[name]).remove();delete elements[name];},content:content};var rendererFunction;if(typeof renderer=="object"){rendererFunction=function(name,element,dom){if(!renderer[name]){return;}return renderer[name](element,dom);};}else{rendererFunction=renderer;}$.each(elements,function(id,element){var pattern=id.match(prefix+"(.*)");var name=pattern?pattern[1]:undefined;if(name&&rendererFunction){element=$(element);element.echo=element.echo||{};element.echo.name=id;var node=rendererFunction(name,element,dom);if(typeof node!="undefined"){element.empty().append(node);}}});return dom;},loadScriptContent:function(url,callback){Echo.Vars.scriptState=Echo.Vars.scriptState||{};if(Echo.Vars.scriptState[url]=="loaded"){callback();return;}var id=Echo.Broadcast.subscribe("internal.scriptLoaded",function(topic,scriptURL){if(url!=scriptURL){return;}Echo.Broadcast.unsubscribe("internal.scriptLoaded",id);callback();});if(Echo.Vars.scriptState[url]=="loading"){return;}Echo.Vars.scriptState[url]="loading";var script=document.createElement("script");script.type="text/javascript";script.charset="utf-8";script.src=url;var container=document.getElementsByTagName("head")[0]||document.documentElement;container.insertBefore(script,container.firstChild);script.onload=script.onreadystatechange=function(){var state=script.readyState;if(!state||state=="loaded"||state=="complete"){Echo.Vars.scriptState[url]="loaded";Echo.Broadcast.publish("internal.scriptLoaded",url);script.onload=script.onreadystatechange=null;}};},sendPostRequest:function(url,data,callback){var id="echo-post-"+Math.random();var container=$("#echo-post-request").length?$("#echo-post-request").empty():$('
').css({height:0}).prependTo("body");$('
').appendTo(container);var form=$("
",{target:id,method:"POST",enctype:"application/x-www-form-urlencoded",acceptCharset:"UTF-8",action:url}).appendTo(container);$.each(data,function(key,value){$("
",{type:"hidden",name:key,value:value}).appendTo(form);});form.submit();callback();},getVisibleColor:function(elem){var color;do{color=elem.css("backgroundColor");if(color!=""&&color!="transparent"&&!/rgba\(0, 0, 0, 0\)/.test(color)||$.nodeName(elem.get(0),"body")){break;}}while(elem=elem.parent());return color||"transparent";},timestampFromW3CDTF:function(t){var parts=["year","month","day","hours","minutes","seconds"];var dt={};var matches=t.match(Echo.Vars.regexps.w3cdtf);$.each(parts,function(i,p){dt[p]=matches[i+1];});return Date.UTC(dt.year,dt.month-1,dt.day,dt.hours,dt.minutes,dt.seconds)/1000;},isMobileDevice:function(){return Echo.Vars.regexps.mobileUA.test(navigator.userAgent);}});if(!Echo.Plugins){Echo.Plugins={};}Echo.isExtended=function(plugin,unique,value){if(!plugin){return false;}value=value||true;var id=[plugin].concat(unique).join(".");Echo.Vars.extensions=Echo.Vars.extensions||{};if(Echo.Vars.extensions[id]==value){return true;}Echo.Vars.extensions[id]=value;return false;};Echo.extendRenderer=function(component,method,renderer,plugin){if(!component||!Echo[component]||!method||!renderer||!$.isFunction(renderer)||Echo.isExtended(plugin,[component,"renderer",method])){return;}var _renderer=Echo[component].prototype.renderers[method]||function(){};Echo[component].prototype.renderers[method]=function(){var config=plugin&&this.config.get("plugins."+plugin);if(!config||!config.enabled){return _renderer.apply(this,arguments);}var self=this;if(!this.parentRenderer){this.parentRenderer=function(name,args){return self.parentRenderers[name].apply(self,args);};}this.parentRenderers=this.parentRenderers||{};this.parentRenderers[method]=_renderer;return renderer.apply(this,arguments);};};Echo.extendTemplate=function(component,html,action,anchor,plugin){if(!component||!Echo[component]||!action||!anchor||!html||Echo.isExtended(plugin,[component,"template",anchor,action],html)){return;}var _template=Echo[component].prototype.template;var template=$.isFunction(_template)?_template:function(){return _template;};var classify={insertBefore:"before",insertAfter:"after",insertAsFirstChild:"prepend",insertAsLastChild:"append",replace:"replaceWith"};Echo[component].prototype.template=function(){var config=plugin&&this.config.get("plugins."+plugin);if(!config||!config.enabled){return template.call(this);}var dom=$("
").html(template.call(this));$("."+anchor,dom)[classify[action]](html);return dom.html();};};Echo.include=function(scripts,callback){if(!scripts.length){return callback();}var script=scripts.pop();Echo.include(scripts,function(){if(typeof script.loaded=="undefined"){if(script.application){script.loaded=function(){return !!Echo[script.application];};}else{callback();}}if($.isFunction(script.loaded)&&!script.loaded()){$.loadScriptContent(script.url,callback);}else{callback();}});};Echo.createPlugin=function(config){if(!config||!config.name||!config.init||!config.applications){return{};}var name=config.name;var configuration=function(){var config=function(key){return"plugins."+name+(key?"."+key:"");};config.get=function(component,key,defaults,askParent){return component.config.get(config(key),askParent?component.config.get(key,defaults):defaults);};config.set=function(component,key,value){component.config.set(config(key),value);};config.remove=function(component,key){component.config.remove(config(key));};return config;};var init=config.init||function(){};Echo.Plugins[name]=Echo.Plugins[name]||$.extend(config,{init:function(plugin,application){var enabled=plugin.config.get(application,"enabled");if(typeof enabled=="undefined"){plugin.config.set(application,"enabled",true);}init(plugin,application);},set:function(component,key,value){component.vars=component.vars||{};component.vars[name]=component.vars[name]||{};$.setNestedValue(component.vars[name],key,value);},get:function(component,key){var data=(component.vars||{})[name]||{};if(!key){return data;}return $.getNestedValue(key,data);},addCss:function(text){$.addCss(text,"plugins-"+name);},label:function(key,data){return Echo.Localization.label(key,"Plugins."+name,data);},addLabels:function(data){Echo.Localization.extend(data,"Plugins."+name);},topic:function(prefix,action){var namespace=typeof prefix=="string"?prefix:prefix.namespace;return namespace+".Plugins."+name+"."+action;},config:configuration(),subscribe:function(application,topic,handler){var self=this;return application.subscribe(topic,function(){if(!application.isPluginEnabled(self.name)){return;}handler.apply(this,arguments);});},publish:function(application,topic,data){application.publish(topic,data);},unsubscribe:function(application,topic,handlerId){application.unsubscribe(topic,handlerId);},extendRenderer:function(component,method,renderer){Echo.extendRenderer(component,method,renderer,name);},extendTemplate:function(component,html,action,anchor){Echo.extendTemplate(component,html,action,anchor,name);},addItemControl:function(application,control){var controls=application.config.get("itemControls."+name,[]);application.config.set("itemControls."+name,controls.concat(control));},assembleConfig:function(component,data){data.user=component.user;data.appkey=component.config.get("appkey","");data.plugins=this.config.get(component,"nestedPlugins",[]);data.contextId=component.config.get("contextId");data.apiBaseURL=component.config.get("apiBaseURL");return(new Echo.Config(data,this.config.get(component))).getAsHash();}});return Echo.Plugins[name];};if(!Echo.Broadcast){Echo.Broadcast={};}Echo.Broadcast.initContext=function(topic,contextId){contextId=contextId||"empty";Echo.Vars.subscriptions=Echo.Vars.subscriptions||{};Echo.Vars.subscriptions[contextId]=Echo.Vars.subscriptions[contextId]||{};Echo.Vars.subscriptions[contextId][topic]=Echo.Vars.subscriptions[contextId][topic]||{};return contextId;};Echo.Broadcast.subscribe=function(topic,handler,contextId){var handlerId=(new Date()).valueOf()+Math.random();contextId=Echo.Broadcast.initContext(topic,contextId);Echo.Vars.subscriptions[contextId][topic][handlerId]=handler;return handlerId;};Echo.Broadcast.unsubscribe=function(topic,handlerId,contextId){contextId=Echo.Broadcast.initContext(topic,contextId);if(topic&&handlerId){delete Echo.Vars.subscriptions[contextId][topic][handlerId];}else{if(topic){delete Echo.Vars.subscriptions[contextId][topic];}}};Echo.Broadcast.publish=function(topic,data,contextId){contextId=Echo.Broadcast.initContext(topic,contextId);if(contextId=="*"){$.each(Echo.Vars.subscriptions,function(ctxId){$.each(Echo.Vars.subscriptions[ctxId][topic]||{},function(handlerId,handler){handler.apply(this,[topic,data]);});});}else{if(Echo.Vars.subscriptions[contextId][topic]){$.each(Echo.Vars.subscriptions[contextId][topic],function(handlerId,handler){handler.apply(this,[topic,data]);});}if(contextId!="empty"){Echo.Broadcast.publish(topic,data,"empty");}}};if(!Echo.Object){Echo.Object=function(){};}Echo.Object.prototype.init=function(data){$.extend(this,data||{});};Echo.Object.prototype.template="";Echo.Object.prototype.namespace="";Echo.Object.prototype.cssPrefix="echo-";Echo.Object.prototype.substitute=function(template,data){var self=this;template=template.replace(Echo.Vars.regexps.matchSelf,function($0,$1){return $.getNestedValue($1,self)||$.getNestedValue($1,self.data||{})||self.config.get($1,"");});template=template.replace(Echo.Vars.regexps.matchLabel,function($0,$1){return self.label($1);});template=template.replace(Echo.Vars.regexps.matchData,function($0,$1){return $.getNestedValue($1,data,"");});return template;};Echo.Object.prototype.renderers={};Echo.Object.prototype.label=function(name,data){var label=Echo.Localization.label(name,this.namespace,data);return label!=name?label:Echo.Localization.label(name,"",data);};Echo.Object.prototype.render=function(name,element,dom,extra){var self=this;if(name){if($.isFunction(this.renderers[name])){return this.renderers[name].call(this,element,dom,extra);}}else{var template=$.isFunction(this.template)?this.template():this.template;this.dom=$.toDOM(this.substitute(template,this.data||{}),this.cssPrefix,function(){return self.render.apply(self,arguments);});return this.dom.content;}};Echo.Object.prototype.rerender=function(name,recursive){var self=this;if(!name){if(this.dom){this.dom.content.replaceWith(this.render());}return;}if(!this.dom){return;}if(typeof name!="string"){$.map(name,function(element){self.rerender(element,recursive);});return;}else{if(!this.dom.get(name)){return;}}if(recursive){var template=$.isFunction(this.template)?this.template():this.template;var html=this.substitute(template,this.data||{});var oldNode=this.dom.get(name);var newNode=$("."+this.cssPrefix+name,$(html));newNode=$.toDOM(newNode,this.cssPrefix,function(name,element,dom){self.dom.set(name,element);return self.render.apply(self,arguments);}).content;oldNode.replaceWith(newNode);}else{var element=this.dom.get(name);var node=this.renderers[name].call(this,element,this.dom);if(typeof node!="undefined"){element.empty().append(node);}}};Echo.Object.prototype.hyperlink=function(data,options){options=options||{};if(options.openInNewWindow&&!data.target){data.target="_blank";}var caption=data.caption||"";delete data.caption;if(!options.skipEscaping){data.href=$.htmlize(data.href);}data.href=data.href||"javascript:void(0)";var attributes=$.foldl([],data,function(value,acc,key){acc.push(key+'="'+value+'"');});return"
"+caption+"";};Echo.Object.prototype.newContextId=function(){return(new Date()).valueOf()+Math.random();};Echo.Object.prototype.getContextId=function(){return this.config&&this.config.get("contextId");};Echo.Object.prototype.subscribe=function(topic,handler){return Echo.Broadcast.subscribe(topic,handler,this.getContextId());};Echo.Object.prototype.unsubscribe=function(topic,handlerId){Echo.Broadcast.unsubscribe(topic,handlerId,this.getContextId());};Echo.Object.prototype.publish=function(topic,data){Echo.Broadcast.publish(topic,data,this.getContextId());};Echo.Object.prototype.clearCache=function(){if(this.vars&&this.vars.cache){this.vars.cache={};}};Echo.User=function(config){this.data={};this.config=new Echo.Config(config,{appkey:"",apiBaseURL:window.location.protocol+"//api.echoenabled.com",contextId:undefined});};Echo.User.prototype.init=function(callback){var self=this;this.callback=callback||function(){};if(!this.config.get("appkey")||!window.Backplane||!Backplane.getChannelID()){this.set({});this.callback();return;}this.listenEvents();var state=this._global("get","state");if(state=="ready"){this.set($.extend({},this._global("get","data")));this.callback();}else{var handlerId=Echo.Broadcast.subscribe("User.onInit",function(topic,data){if(data.appkey!=self.config.get("appkey")){return;}Echo.Broadcast.unsubscribe("User.onInit",handlerId);self.set($.extend({},self._global("get","data")));self.callback();});if(state=="init"){this.request();}}};Echo.User.prototype.listenEvents=function(){var self=this;if(this.backplaneSubscriptionID){return;}var publish=function(global){var topic=(global?"":"internal.")+"User.onInvalidate";var data={data:self.data,appkey:self.config.get("appkey")};var contextId=global?undefined:self.config.get("contextId");Echo.Broadcast.publish(topic,data,contextId);};this.backplaneSubscriptionID=Backplane.subscribe(function(message){if(message.type=="identity/ack"){var global=false;if(self._global("get","state")=="ready"){global=true;self._global("set","state","init");}self.init(function(){publish();if(global){publish(true);}});}});};Echo.User.prototype._global=function(action,key,value){var appkey=this.config.get("appkey");Echo.Vars.users=Echo.Vars.users||{};Echo.Vars.users[appkey]=Echo.Vars.users[appkey]||{state:"init",data:{}};if(action=="get"){return Echo.Vars.users[appkey][key];}Echo.Vars.users[appkey][key]=value;};Echo.User.prototype.set=function(){if(!arguments.length){return;}if(arguments.length==1&&typeof arguments[0]=="object"){this._global("set","data",arguments[0]);this.data=this.normalize(arguments[0]);this.account=this.assemble();}else{if(arguments.length==2&&typeof arguments[0]=="string"){this.account[arguments[0]]=arguments[1];}}};Echo.User.prototype.get=function(key,defaults){return(this.account.hasOwnProperty(key)&&typeof this.account[key]!="undefined")?this.account[key]:defaults;};Echo.User.prototype.logout=function(callback){var self=this;$.get(window.location.protocol+"//apps.echoenabled.com/v2/logout",{sessionID:Backplane.getChannelID()},function(data){Backplane.expectMessages("identity/ack");},"jsonp");};Echo.User.prototype.request=function(callback){var self=this,appkey=this.config.get("appkey");this._global("set","state","waiting");$.get(this.config.get("apiBaseURL")+"/v1/users/whoami",{appkey:appkey,sessionID:Backplane.getChannelID()},function(data){if(data.result&&data.result=="session_not_found"){data={};}self._global("set","state","ready");self.set($.extend({},data));Echo.Broadcast.publish("User.onInit",{data:data,appkey:appkey});if(callback){callback();}},"jsonp");};Echo.User.prototype.normalize=function(data){var array2object=function(list){return $.foldl({},list||[],function(key,acc){acc[key]=true;});};data=data||{};data.echo=data.echo||{};$.extend(data,data.echo);data.poco=data.poco||{entry:{}};data.roles=array2object(data.echo.roles);data.markers=array2object(data.echo.markers);data.sessionID=window.Backplane&&Backplane.getChannelID()||undefined;data.accounts=data.poco.entry.accounts||[];return data;};Echo.User.prototype.getActiveAccounts=function(){return $.map(this.data.accounts,function(entry){if(entry.loggedIn=="true"){return entry;}});};Echo.User.prototype.assemble=function(){var accounts=this.getActiveAccounts();var account=accounts[0]||{};return $.extend(this.data,{id:account.identityUrl||this.data.poco.entry.id||account.userid,name:this.data.poco.entry.displayName||account.username,avatar:$.foldl(undefined,account.photos||[],function(img){if(img.type=="avatar"){return img.value;}}),state:this.data.echo.state||"Untouched",domain:account.domain,logged:!!accounts.length,defaultAvatar:"//cdn.echoenabled.com/images/avatar-default.png",fakeIdentityURL:"http://js-kit.com/ECHO/user/fake_user"});};Echo.User.prototype.hasIdentity=function(id){var hasIdentity=false;$.each(this.data.accounts,function(i,account){if(account.identityUrl&&account.identityUrl==id){hasIdentity=true;return false;}});return hasIdentity;};Echo.User.prototype.hasAny=function(field,values){if(!this.account){return false;}var self=this,satisfies=false;$.each(values,function(i,value){var data=self.get(field,{});if((typeof data=="string"&&data==value)||data[value]){satisfies=true;return false;}});return satisfies;};Echo.User.prototype.hasAnyRole=function(roles){return this.hasAny("roles",roles);};Echo.User.prototype.isAdmin=function(){return this.hasAny("roles",["administrator","moderator"]);};Echo.User.prototype.logged=function(){return !!(this.account&&this.account.logged);};Echo.Application=function(){this.addCss();};Echo.Application.prototype=new Echo.Object();Echo.Application.prototype.localization={loading:"Loading...",retrying:"Retrying...",error_busy:"Loading. Please wait...",error_timeout:"Loading. Please wait...",error_waiting:"Loading. Please wait...",error_view_limit:"View creation rate limit has been exceeded. Retrying in {seconds} seconds...",error_view_update_capacity_exceeded:"This stream is momentarily unavailable due to unusually high activity. Retrying in {seconds} seconds...",error_result_too_large:"(result_too_large) The search result is too large.",error_wrong_query:"(wrong_query) Incorrect or missing query parameter.",error_incorrect_appkey:"(incorrect_appkey) Incorrect or missing appkey.",error_internal_error:"(internal_error) Unknown server error.",error_quota_exceeded:"(quota_exceeded) Required more quota than is available.",error_incorrect_user_id:"(incorrect_user_id) Incorrect user specified in User ID predicate.",error_unknown:"(unknown) Unknown error."};Echo.Application.prototype.initApplication=function(callback){var self=this;var appkey=this.config.get("appkey");if(!appkey){this.showMessage({type:"error",message:"Incorrect or missing mandatory parameter appkey"});return;}this.config.get("target").addClass("echo-ui");this.user=this.config.get("user")||new Echo.User({appkey:appkey,apiBaseURL:this.config.get("apiBaseURL"),contextId:this.config.get("contextId")});this.user.init(function(){self.initPlugins(callback);});Echo.Localization.extend(this.localization);};Echo.Application.prototype.messageTemplates={compact:'
',"default":'
{Data:message}
'};Echo.Application.prototype.showMessage=function(data,target){if(!this.config.get("debug")&&data.type=="error"){return;}var template=this.messageTemplates[data.layout||this.messageLayout||"default"];(target||this.config.get("target")).empty().append(this.substitute(template,data));};Echo.Application.prototype.isWaitingForData=function(data){return data&&$.inArray(data.errorCode,["waiting","timeout","busy","view_limit","view_update_capacity_exceeded"])>=0;};Echo.Application.prototype.isErrorWithTimer=function(data){return data&&$.inArray(data.errorCode,["view_limit","view_update_capacity_exceeded"])>=0;};Echo.Application.prototype.handleErrorResponse=function(data,config){var self=this;config=config||{};var target=this.config.get("target");var calcWaitingTimeout=function(){if(self.waitingTimeoutStep>0){if(self.waitingTimeoutStep<4){self.waitingTimeoutStep++;}}else{self.waitingTimeoutStep=1;}return Math.round(Math.exp(self.waitingTimeoutStep))*1000;};var maxWaitingTimeout=0;var timeElapsed=0;var showError=function(){var params={};if(self.isErrorWithTimer(data)){params={seconds:(maxWaitingTimeout-timeElapsed)/1000};}var label=self.label("error_"+data.errorCode,params);var message=label=="error_"+data.errorCode?"("+data.errorCode+") "+(data.errorMessage||""):label;target.show();self.showMessage({type:self.isWaitingForData(data)?"loading":"error",message:message},config.messageTarget);};if(this.isWaitingForData(data)){maxWaitingTimeout=calcWaitingTimeout();timeout=this.isErrorWithTimer(data)?1000:maxWaitingTimeout;this.waitingTimer=setInterval(function(){timeElapsed+=timeout;if(timeElapsed==maxWaitingTimeout){self.cleanupErrorHandlers();if(self.isErrorWithTimer(data)){self.showMessage({type:"loading",message:self.label("retrying")},config.messageTarget);}if(config.waitingHandler){config.waitingHandler();}else{self.refresh();}}else{showError();}},timeout);}else{this.waitingTimeoutStep=0;}if(this.error!=data||this.isErrorWithTimer(data)){if(!this.config.get("debug")){target.hide();}else{showError();}}this.error=data;if(config.callback){config.callback(data);}};Echo.Application.prototype.cleanupErrorHandlers=function(successResponseReceived){if(successResponseReceived){this.waitingTimeoutStep=0;delete this.error;}if(this.waitingTimer){clearInterval(this.waitingTimer);}};Echo.Application.prototype.initPlugins=function(callback){var self=this;var plugins=this.config.get("pluginsOrder");var scripts=$.foldl([],plugins,function(name,acc){var plugin=Echo.Plugins[name];if(plugin&&plugin.dependencies&&plugin.dependencies.length){return acc.concat(plugin.dependencies);}});Echo.include(scripts,function(){$.map(plugins,function(name){var plugin=Echo.Plugins[name];if(plugin&&plugin.init&&self.isPluginApplicable(plugin)){plugin.init(plugin,self);}});if(callback){callback();}});};Echo.Application.prototype.enablePlugin=function(name){this.config.set("plugins."+name+".enabled",true);};Echo.Application.prototype.disablePlugin=function(name){this.config.set("plugins."+name+".enabled",false);};Echo.Application.prototype.isPluginEnabled=function(name){return this.config.get("plugins."+name+".enabled",true);};Echo.Application.prototype.isPluginApplicable=function(plugin){var self=this,applicable=false;$.each(plugin.applications,function(i,application){if(Echo[application]&&self instanceof Echo[application]){applicable=true;return false;}});return applicable;};Echo.Application.prototype.initConfig=function(data,defaults,normalizer){var _normalizer={};_normalizer.target=function(el){return $(el);};_normalizer.plugins=function(list){var data=$.foldl({hash:{},order:[]},list||[],function(plugin,acc){var pos=$.inArray(plugin.name,acc.order);if(pos>=0){acc.order.splice(pos,1);}acc.order.push(plugin.name);acc.hash[plugin.name]=plugin;});this.set("pluginsOrder",data.order);return data.hash;};data=$.extend({plugins:[]},data||{});defaults=$.extend({appkey:"",apiBaseURL:window.location.protocol+"//api.echoenabled.com",liveUpdates:true,liveUpdatesTimeout:10,liveUpdatesTimeoutMin:3,debug:true,contextId:this.newContextId()},defaults||{});this.config=new Echo.Config(data,defaults,function(key,value){var handler=normalizer&&normalizer[key]||_normalizer&&_normalizer[key];return handler?handler.call(this,value):value;});};Echo.Application.prototype.sendAPIRequest=function(data,callback){data.query.appkey=this.config.get("appkey");$.get(this.config.get("apiBaseURL")+"/v1/"+data.endpoint,data.query,callback,"jsonp");};Echo.Application.prototype.initLiveUpdates=function(requestParamsGetter,responseHandler){var self=this;this.liveUpdates={originalTimeout:this.config.get("liveUpdatesTimeout"),timers:{},timeouts:[],responseHandler:function(data){if(self.liveUpdates.timers.watchdog){clearTimeout(self.liveUpdates.timers.watchdog);}self.changeLiveUpdatesTimeout(data);responseHandler(data);},requestParamsGetter:requestParamsGetter};};Echo.Application.prototype.changeLiveUpdatesTimeout=function(data){var self=this;if(typeof data=="string"){data={liveUpdatesTimeout:data};}data.liveUpdatesTimeout=parseInt(data.liveUpdatesTimeout);var applyServerDefinedTimeout=function(timeout){if(!timeout&&self.liveUpdates.originalTimeout!=self.config.get("liveUpdatesTimeout")){self.config.set("liveUpdatesTimeout",self.liveUpdates.originalTimeout);}else{if(timeout&&timeout>self.config.get("liveUpdatesTimeout")){self.config.set("liveUpdatesTimeout",timeout);}}};var hasNewData=function(data){return !!(data.entries&&data.entries.length);};if(!this.nextSince){applyServerDefinedTimeout(data.liveUpdatesTimeout);return;}var currentTimeout=this.config.get("liveUpdatesTimeout");var since=parseInt(this.nextSince);var currentTime=Math.floor((new Date()).getTime()/1000);var timeout=hasNewData(data)?currentTime-since>currentTimeout?this.config.get("liveUpdatesTimeoutMin",3):currentTimeout+1:currentTimeout+2;if(timeout>this.liveUpdates.originalTimeout){timeout=this.liveUpdates.originalTimeout;}this.config.set("liveUpdatesTimeout",timeout);if(timeout==this.liveUpdates.originalTimeout){applyServerDefinedTimeout(data.liveUpdatesTimeout);}};Echo.Application.prototype.stopLiveUpdates=function(){if(this.liveUpdates.timers.regular){clearTimeout(this.liveUpdates.timers.regular);}if(this.liveUpdates.timers.watchdog){clearTimeout(this.liveUpdates.timers.watchdog);}};Echo.Application.prototype.startLiveUpdates=function(force){var self=this;if(!this.liveUpdates||!force&&!this.config.get("liveUpdates")&&!this.liveUpdates.timeouts.length){return;}this.stopLiveUpdates();if(force){this.liveUpdates.timeouts=[0,1,3];}var timeout=this.liveUpdates.timeouts.length?this.liveUpdates.timeouts.shift():this.config.get("liveUpdatesTimeout");this.liveUpdates.timers.regular=setTimeout(function(){self.liveUpdates.timers.watchdog=setTimeout(function(){self.startLiveUpdates();},5000);self.sendAPIRequest(self.liveUpdates.requestParamsGetter(),self.liveUpdates.responseHandler);},timeout*1000);};Echo.Application.prototype.addCss=function(){var id="echo-css-fancybox";if($("#"+id).length){return;}var container=document.getElementsByTagName("head")[0]||document.documentElement;container.insertBefore($("
",{rel:"stylesheet",id:id,type:"text/css",href:"//a.espncdn.com/prod/styles/community/echo.fancybox.1.0.0.css"}).get(0),$(container).children().get(0));$.addCss(".echo-application-message { padding: 15px 0px; text-align: center; -moz-border-radius: 0.5em; -webkit-border-radius: 0.5em; border: 1px solid #E4E4E4; }.echo-application-message-icon { display: inline-block; height: 16px; padding-left: 16px; background: no-repeat left center; }.echo-application-message .echo-application-message-icon { padding-left: 21px; height: auto; }.echo-application-message-empty { background-image: url(//cdn.echoenabled.com/images/information.png); }.echo-application-message-loading { background-image: url(//cdn.echoenabled.com/images/loading.gif); }.echo-application-message-error { background-image: url(//cdn.echoenabled.com/images/warning.gif); }","application");};Echo.Config=function(master,slave,normalizer){var self=this;this.normalize=normalizer||function(key,value){return value;};this.data={};this.cache={};if(!slave&&!normalizer){this.data=master;}else{$.each(this.combine(master,$.extend({},slave)),function(key,value){self.set(key,value);});}};Echo.Config.prototype.get=function(key,defaults){var k=key;if(typeof k!="string"){k=k.join(".");}if(!this.cache.hasOwnProperty(k)){this.cache[k]=$.getNestedValue(key,this.data);}return typeof this.cache[k]=="undefined"?defaults:this.cache[k];};Echo.Config.prototype.set=function(key,value){var keys=key.split(/\./);delete this.cache[key];if(typeof value=="object"){this.clearCacheByPrefix(key);}return $.setNestedValue(this.data,key,this.normalize(keys.pop(),value));};Echo.Config.prototype.remove=function(key){var keys=key.split(/\./);var field=keys.pop();var data=$.getNestedValue(keys,this.data);delete data[field];};Echo.Config.prototype.combine=function(master,slave){var self=this;return $.foldl(slave,master,function(value,acc,key){acc[key]=$.isPlainObject(value)&&slave.hasOwnProperty(key)?self.combine(value,slave[key]):value;});};Echo.Config.prototype.extend=function(extra){var self=this;$.each(extra,function(key,value){self.set(key,value);});};Echo.Config.prototype.getAsHash=function(){return this.data;};Echo.Config.prototype.clearCacheByPrefix=function(prefix){var self=this;prefix+=".";$.each(this.cache,function(key,data){if(!key.indexOf(prefix)){delete self.cache[key];}});};if(!Echo.Localization){Echo.Localization={labels:{}};}Echo.Localization.key=function(name,namespace){return(namespace?namespace+".":"")+name;};Echo.Localization.extend=function(labels,namespace){$.each(labels,function(name,value){Echo.Localization.labels[Echo.Localization.key(name,namespace)]=value;});};Echo.Localization.label=function(name,namespace,data){var label=Echo.Localization.labels[Echo.Localization.key(name,namespace)]||name;$.each(data||{},function(key,value){label=label.replace(new RegExp("{"+key+"}","g"),value);});return label;};})(jQuery);(function($){Echo.Counter=function(config){if(!config||!config.target){return;}var self=this;this.vars={};this.data={};this.initConfig(config,{debug:false});this.messageLayout="compact";this.initApplication(function(){self.contextId=self.newContextId();self.showMessage({type:"loading"});self.initLiveUpdates(function(){return{endpoint:"count",query:{q:self.config.get("query","")}};},function(data){self.handleResponse(data);});if(self.config.get("data")){self.handleResponse(self.config.get("data"));}else{self.request();}self.listenEvents();});};Echo.Counter.prototype=new Echo.Application();Echo.Counter.prototype.namespace="Counter";Echo.Counter.prototype.request=function(){var self=this;this.sendAPIRequest({endpoint:"count",query:{q:self.config.get("query","")}},function(data){self.handleResponse(data);});};Echo.Counter.prototype.refresh=function(){this.stopLiveUpdates();this.data={};this.showMessage({type:"loading"});this.request();};Echo.Counter.prototype.listenEvents=function(){var self=this;$.map(["Submit.onPostComplete","Submit.onEditComplete"],function(topic){Echo.Broadcast.subscribe(topic,function(){self.startLiveUpdates(true);});});};Echo.Counter.prototype.handleResponse=function(data){var self=this;var target=this.config.get("target");data=data||{};if(data.result=="error"&&data.errorCode!="more_than"){this.handleErrorResponse(data);return;}this.cleanupErrorHandlers(true);target.show();target.html(data.errorCode=="more_than"?(data.errorMessage+"+"):data.count);if($.isEmptyObject(this.data)||this.data.count!=data.count){this.publish("Counter.onUpdate",{data:data,query:this.config.get("query",""),target:this.config.get("target").get(0)});}this.data=data;this.startLiveUpdates();};})(jQuery);