Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
(function(I,D,E){var A="Push";
var H=D.Event.RICH_NAMESPACE;
var M=D.Event.EVENT_NAMESPACE_SEPARATOR;
var B="dataAvailable"+M+H+M+A;
var G="subscribed"+M+H+M+A;
var N="error"+M+H+M+A;
var C=function(O){return B+M+O
};
var L=function(O){return G+M+O
};
var J=function(O){return N+M+O
};
D.Push=(function(){var P={};
var R={};
var U={};
var Z={};
var S=null;
var Y=null;
var Q=null;
var O=/^(<!--[^>]+-->\s*)+/;
var T=/<([^>]*)>/g;
var X=-1;
var b=function(d){var c=d;
if(d.charAt(0)=="/"){c=location.protocol+"//"+location.host+d
}return c
};
var W=function(c){var d=c.responseBody.replace(O,"");
if(d){var f;
while(f=T.exec(d)){if(!f[1]){continue
}var e=E.parseJSON("{"+f[1]+"}");
if(e.number<=X){continue
}D.Event.fire(document,C(e.topic),e.data);
X=e.number
}}};
var a=function(){var e={};
var c=function(k){var i=E.parseJSON(k);
for(var h in i.failures){D.Event.fire(document,J(h),i.failures[h])
}if(i.sessionId){Q=i.sessionId;
E.atmosphere.subscribe((Y||S)+"?__richfacesPushAsync=1&pushSessionId="+Q,W,{transport:D.Push.transport,fallbackTransport:D.Push.fallbackTransport,logLevel:D.Push.logLevel});
for(var j in e){U[j]=true;
D.Event.fire(document,L(j))
}}};
var g=new Array();
for(var d in Z){g.push(d);
if(!U[d]){e[d]=true
}}var f={pushTopic:g};
if(Q){f.forgetPushSessionId=Q
}E.ajax({data:f,dataType:"text",success:c,traditional:true,type:"POST",url:S})
};
var V=function(){E.atmosphere.unsubscribe()
};
return{increaseSubscriptionCounters:function(c){if(isNaN(Z[c]++)){Z[c]=1;
P[c]=true
}},decreaseSubscriptionCounters:function(c){if(--Z[c]==0){delete Z[c];
R[c]=true;
U[c]=false
}},setPushResourceUrl:function(c){S=b(c)
},setPushHandlerUrl:function(c){Y=b(c)
},updateConnection:function(){if(E.isEmptyObject(Z)){V()
}else{if(!E.isEmptyObject(P)||!E.isEmptyObject(R)){V();
a()
}}P={};
R={}
}}
}());
E(document).ready(D.Push.updateConnection);
D.Push.transport="long-polling";
D.Push.fallbackTransport=undefined;
D.Push.logLevel="info";
var F=function(O){if(O.type=="event"){if(O.status!="success"){return 
}}else{if(O.type!="error"){return 
}}D.Push.updateConnection()
};
I.ajax.addOnEvent(F);
I.ajax.addOnError(F);
D.ui=D.ui||{};
D.ui.Push=D.BaseComponent.extendClass({name:A,init:function(P,O){K.constructor.call(this,P);
this.attachToDom();
this.__address=O.address;
this.__handlers={};
if(O.ondataavailable){this.__bindDataHandler(O.ondataavailable)
}if(O.onsubscribed){this.__bindSubscribedHandler(O.onsubscribed)
}if(O.onerror){this.__bindErrorHandler(O.onerror)
}D.Push.increaseSubscriptionCounters(this.__address)
},__bindDataHandler:function(P){var O=C(this.__address);
this.__handlers.data=D.Event.bind(document,O,$.proxy(P,document.getElementById(this.id)),this)
},__unbindDataHandler:function(){if(this.__handlers.data){var O=C(this.__address);
D.Event.unbind(document,O,this.__handlers.data);
this.__handlers.data=null
}},__bindSubscribedHandler:function(P){var O=L(this.__address);
this.__handlers.subscribed=D.Event.bind(document,O,$.proxy(P,document.getElementById(this.id)),this)
},__unbindSubscribedHandler:function(){if(this.__handlers.subscribed){var O=L(this.__address);
D.Event.unbind(document,O,this.__handlers.subscribed);
this.__handlers.subscribed=null
}},__bindErrorHandler:function(P){var O=J(this.__address);
this.__handlers.error=D.Event.bind(document,O,$.proxy(P,document.getElementById(this.id)),this)
},__unbindErrorHandler:function(){if(this.__handlers.error){var O=J(this.__address);
D.Event.unbind(document,O,this.__handlers.error);
this.__handlers.error=null
}},destroy:function(){this.__unbindDataHandler();
this.__unbindErrorHandler();
this.__unbindSubscribedHandler();
D.Push.decreaseSubscriptionCounters(this.__address);
K.destroy.call(this)
}});
var K=D.ui.Push.$super
}(jsf,window.RichFaces,jQuery));
New to GrepCode? Check out our FAQ X